/* CSS Variables for theming */
:root {
  --bg-primary: #f2f2f7;
  --bg-secondary: #ffffff;
  --bg-tertiary: #fbfbfd;
  --text-primary: #1d1d1f;
  --text-secondary: #515154;
  --text-tertiary: #86868b;
  --border-color: rgba(0,0,0,0.04);
  --border-strong: rgba(0,0,0,0.06);
  --shadow-light: rgba(0,0,0,0.04);
  --shadow-medium: rgba(0,0,0,0.08);
  --panel-bg: #ffffff;
  --card-bg: #fbfbfd;
  --app-badge-bg: #f2f2f7;
  --language-indicator-bg: #f2f2f7;
  --stat-card-bg: rgba(255,255,255,0.1);
  --app-sentiment-bg: #ffffff;
  --sentiment-bar-bg: rgba(0,0,0,0.06);

  /* Sentiment colors - NEVER CHANGE */
  --sentiment-positive: #34c759;
  --sentiment-neutral: #ff9500;
  --sentiment-negative: #ff3b30;
  --sentiment-mixed: #007aff;

  /* Rating colors - Gradient from red (1 star) to green (5 stars) */
  --rating-1-star: #ff3b30;
  --rating-2-star: #ff9500;
  --rating-3-star: #ffcc02;
  --rating-4-star: #afd135;
  --rating-5-star: #34c759;
}

/* Dark mode */
@media (prefers-color-scheme: dark) {
  :root {
    --bg-primary: #1c1c1e;
    --bg-secondary: #2c2c2e;
    --bg-tertiary: #3a3a3c;
    --text-primary: #ffffff;
    --text-secondary: #f2f2f7;
    --text-tertiary: #98989d;
    --border-color: rgba(255,255,255,0.08);
    --border-strong: rgba(255,255,255,0.12);
    --shadow-light: rgba(0,0,0,0.3);
    --shadow-medium: rgba(0,0,0,0.5);
    --panel-bg: #2c2c2e;
    --card-bg: #3a3a3c;
    --app-badge-bg: #48484a;
    --language-indicator-bg: #48484a;
    --stat-card-bg: rgba(255,255,255,0.05);
    --app-sentiment-bg: #2c2c2e;
    --sentiment-bar-bg: rgba(255,255,255,0.1);
  }
}

/* Base styles */
* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

body {
  background: var(--bg-primary);
  color: var(--text-primary);
  font-family: -apple-system, BlinkMacSystemFont, 'SF Pro Display', 'Segoe UI', system-ui, sans-serif;
  overflow: hidden;
}

/* Container and grid layout - Layout 2 colonnes pour écran statique */
.container {
  display: grid;
  grid-template-columns: 1fr 450px;
  grid-template-rows: 1fr;
  height: 100vh;
  overflow: hidden;
  gap: 20px;
  padding: 20px;
}

/* Panel styles */
.panel {
  background: var(--panel-bg);
  border-radius: 16px;
  padding: 24px;
  border: 1px solid var(--border-color);
  box-shadow: 0 4px 16px var(--shadow-light);
  overflow: hidden;
}

.panel h2 {
  margin-bottom: 20px;
  color: var(--text-primary);
  font-size: 28px;
  font-weight: 600;
  text-align: center;
  letter-spacing: -0.02em;
}

/* Right panels container - Stack vertical pour ratings + sentiment */
.right-panels {
  display: flex;
  flex-direction: column;
  gap: 8px;
  min-height: 100%;
  overflow: visible;
}

.right-panels .ratings-panel {
  flex: 0 0 auto;
  overflow: visible;
  padding: 16px;
  max-height: none;
}

.right-panels .sentiment-panel {
  flex: 1;
  overflow: hidden;
  padding: 16px;
  min-height: 300px;
}

.right-panels .panel h2 {
  font-size: 20px;
  margin-bottom: 12px;
}

/* Reviews panel */
.reviews-panel {
  display: flex;
  flex-direction: column;
  height: 100%;
}

#reviews {
  flex: 1;
  overflow: hidden;
  column-count: auto;
  column-width: 300px;
  column-gap: 16px;
  padding-right: 10px;
}

/* Review cards */
.review {
  background: var(--card-bg);
  border-radius: 12px;
  padding: 16px;
  color: var(--text-primary);
  border: 1px solid var(--border-color);
  box-shadow: 0 1px 4px var(--shadow-light);
  transition: all 0.2s ease;
  word-wrap: break-word;
  overflow-wrap: break-word;
  hyphens: auto;
  break-inside: avoid;
  margin-bottom: 16px;
  display: inline-block;
  width: 100%;
}

/* Styles spécifiques pour reviews avec sentiment - barres colorées sur le côté */
.review.sentiment-neutral {
  border-left: 4px solid #ff9500;
  box-shadow: 0 1px 4px rgba(255, 149, 0, 0.1);
}

.review.sentiment-positive {
  border-left: 4px solid #34c759;
  box-shadow: 0 1px 4px rgba(52, 199, 89, 0.1);
}

.review.sentiment-negative {
  border-left: 4px solid #ff3b30;
  box-shadow: 0 1px 4px rgba(255, 59, 48, 0.1);
}

.review.sentiment-mixed {
  border-left: 4px solid #007aff;
  box-shadow: 0 1px 4px rgba(0, 122, 255, 0.1);
}

.review:hover {
  transform: translateY(-1px);
}

.review.sentiment-neutral:hover {
  box-shadow: 0 4px 16px rgba(255, 149, 0, 0.15);
}

.review.sentiment-positive:hover {
  box-shadow: 0 4px 16px rgba(52, 199, 89, 0.15);
}

.review.sentiment-negative:hover {
  box-shadow: 0 4px 16px rgba(255, 59, 48, 0.15);
}

.review.sentiment-mixed:hover {
  box-shadow: 0 4px 16px rgba(0, 122, 255, 0.15);
}

.review:hover:not(.sentiment-neutral):not(.sentiment-positive):not(.sentiment-negative):not(.sentiment-mixed) {
  box-shadow: 0 4px 16px var(--shadow-medium);
}

.app-badge {
  background: var(--app-badge-bg);
  color: var(--text-primary);
  padding: 6px 10px;
  border-radius: 8px;
  font-size: 13px;
  font-weight: 500;
  margin-bottom: 12px;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  border: 1px solid var(--border-strong);
}

.app-badge svg {
  display: inline-block;
  vertical-align: middle;
  flex-shrink: 0;
  opacity: 0.8;
}

.review-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 8px;
}

.author {
  font-weight: 600;
  color: var(--text-primary);
  font-size: 15px;
}

.date {
  font-size: 13px;
  color: var(--text-tertiary);
}

.rating-container {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 10px;
}

.rating {
  font-weight: 500;
  font-size: 14px;
  color: #ff9500; /* Couleur par défaut pour les étoiles pleines */
}

.rating .empty-stars {
  color: #d1d1d6; /* Couleur grise pour les étoiles vides */
}

.language-indicator {
  background: var(--language-indicator-bg);
  color: var(--sentiment-mixed);
  padding: 3px 8px;
  border-radius: 6px;
  font-size: 11px;
  font-weight: 500;
  border: 1px solid rgba(0,122,255,0.1);
}

.body {
  line-height: 1.5;
  color: var(--text-secondary);
  font-size: 14px;
}

/* Adaptation dynamique des tuiles selon la longueur du contenu */
.review.short-content {
  padding: 14px;
}

.review.medium-content {
  padding: 16px;
}

.review.long-content {
  padding: 18px;
}

/* Loading and message states */
.loading, .message, .error {
  text-align: center;
  padding: 40px;
  font-size: 1.2em;
  color: var(--text-secondary);
}

.error {
  color: var(--sentiment-negative);
}

/* AppBot unavailable states */
.appbot-unavailable, .appbot-partial-failure {
  text-align: center;
  padding: 40px 30px;
  background: var(--card-bg);
  border-radius: 12px;
  margin: 20px;
  column-span: all;
  break-inside: avoid;
  max-width: 500px;
  margin: 20px auto;
}

.appbot-unavailable {
  border: 2px solid var(--sentiment-negative);
}

.appbot-partial-failure {
  border: 2px solid var(--sentiment-neutral);
}

.unavailable-icon, .partial-failure-icon {
  font-size: 3.5em;
  margin-bottom: 20px;
  opacity: 0.8;
}

.unavailable-title, .partial-failure-title {
  font-size: 1.5em;
  font-weight: 600;
  color: var(--text-primary);
  margin-bottom: 15px;
  letter-spacing: -0.02em;
}

.unavailable-message, .partial-failure-message {
  font-size: 1.1em;
  color: var(--text-secondary);
  line-height: 1.6;
  margin-bottom: 20px;
  max-width: 400px;
  margin-left: auto;
  margin-right: auto;
}

.unavailable-retry {
  font-size: 0.95em;
  color: var(--text-tertiary);
  font-style: italic;
  opacity: 0.8;
}

/* Ratings panel */
.ratings-panel {
  display: flex;
  flex-direction: column;
}

.ratings-by-app {
  flex: 1;
  overflow: visible;
}

/* App ratings items */
.app-ratings-item {
  background: var(--app-sentiment-bg);
  border-radius: 8px;
  padding: 10px;
  margin-bottom: 8px;
  border: 1px solid var(--border-color);
  box-shadow: 0 1px 3px var(--shadow-light);
}

.app-ratings-item .app-info {
  margin-bottom: 8px;
}

.app-ratings-item .app-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 4px;
}

.app-ratings-item .app-name {
  font-weight: 600;
  font-size: 14px;
  color: var(--text-primary);
}

.app-ratings-item .app-average {
  font-weight: 800;
  font-size: 20px;
  color: #ffd700;
  margin-left: 8px;
  text-shadow: 0 1px 3px rgba(0, 0, 0, 0.5);
  filter: drop-shadow(0 1px 2px rgba(255, 215, 0, 0.4));
}

/* Couleurs dynamiques selon la note */
.app-average.rating-excellent {
  color: #00e676 !important;
  text-shadow: 0 1px 3px rgba(0, 0, 0, 0.5);
  filter: drop-shadow(0 1px 2px rgba(0, 230, 118, 0.4));
}

.app-average.rating-good {
  color: #ffd700 !important;
  text-shadow: 0 1px 3px rgba(0, 0, 0, 0.5);
  filter: drop-shadow(0 1px 2px rgba(255, 215, 0, 0.4));
}

.app-average.rating-average {
  color: #ff9500 !important;
  text-shadow: 0 1px 3px rgba(0, 0, 0, 0.5);
  filter: drop-shadow(0 1px 2px rgba(255, 149, 0, 0.4));
}

.app-average.rating-poor {
  color: #ff5252 !important;
  text-shadow: 0 1px 3px rgba(0, 0, 0, 0.5);
  filter: drop-shadow(0 1px 2px rgba(255, 82, 82, 0.4));
}

.app-ratings-item .app-meta {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 10px;
  color: var(--text-tertiary);
}

.app-ratings-source {
  font-size: 9px;
  color: var(--text-tertiary);
  font-style: italic;
  margin-top: 2px;
  opacity: 0.8;
}

/* Rating bars */
.rating-bar-container {
  margin-bottom: 4px;
}

.rating-bar-label {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 10px;
  margin-bottom: 2px;
  color: var(--text-secondary);
}

.rating-bar {
  height: 4px;
  background: var(--sentiment-bar-bg);
  border-radius: 2px;
  overflow: hidden;
}

.rating-bar-fill {
  height: 100%;
  border-radius: 3px;
  transition: width 0.3s ease;
}

.rating-bar-fill.rating-5-star { background: var(--rating-5-star); }
.rating-bar-fill.rating-4-star { background: var(--rating-4-star); }
.rating-bar-fill.rating-3-star { background: var(--rating-3-star); }
.rating-bar-fill.rating-2-star { background: var(--rating-2-star); }
.rating-bar-fill.rating-1-star { background: var(--rating-1-star); }

/* Error states for ratings */
.app-ratings-item.error {
  background: rgba(255, 59, 48, 0.1);
  border-color: rgba(255, 59, 48, 0.2);
}

.app-ratings-item.no-data {
  opacity: 0.6;
}

.app-ratings-error,
.app-ratings-empty {
  text-align: center;
  color: var(--text-tertiary);
  font-style: italic;
  padding: 12px;
}

/* Sentiment panel */
.sentiment-panel {
  display: flex;
  flex-direction: column;
}

.sentiment-period {
  text-align: center;
  margin-bottom: 20px;
  font-size: 0.9em;
  opacity: 0.8;
}

/* Global sentiment (hidden by default) */
#globalSentiment {
  display: none;
}

.sentiment-chart {
  width: 100%;
  max-width: 300px;
  margin: 0 auto 20px;
}

/* Style spécifique pour le mode timeline */
.sentiment-panel[data-mode="timeline"] {
  display: flex;
  flex-direction: column;
  height: 100%;
  padding: 20px;
}

.sentiment-panel[data-mode="timeline"] h2 {
  margin: 0 0 20px 0;
  text-align: center;
  flex-shrink: 0;
}

#globalSentiment[data-mode="timeline"] {
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  flex: 1; /* Prend tout l'espace restant et centre le graphique */
}

#globalSentiment[data-mode="timeline"] .sentiment-chart {
  max-width: none;
  margin: 0;
  display: block;
  width: 100%; /* Utilise toute la largeur */
}

.sentiment-legend {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 10px;
  margin-bottom: 20px;
}

.legend-item {
  display: flex;
  align-items: center;
  gap: 5px;
  font-size: 0.9em;
}

.legend-color {
  width: 12px;
  height: 12px;
  border-radius: 2px;
}

/* Couleurs pour les légendes et graphiques uniquement */
.legend-color.sentiment-positive { background-color: #34c759; }
.legend-color.sentiment-neutral { background-color: #ff9500; }
.legend-color.sentiment-negative { background-color: #ff3b30; }
.legend-color.sentiment-mixed { background-color: #007aff; }

.sentiment-stats {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 10px;
}

.stat-card {
  background: var(--stat-card-bg);
  border-radius: 8px;
  padding: 15px;
  text-align: center;
}

.stat-value {
  font-size: 1.5em;
  font-weight: bold;
  margin-bottom: 5px;
}

.stat-positive { color: #34c759; }
.stat-neutral { color: #ff9500; }
.stat-negative { color: #ff3b30; }
.stat-mixed { color: #007aff; }

/* Sentiment by app */
.sentiment-by-app {
  flex: 1;
  overflow-y: auto;
}

#sentimentAppList {
  display: flex;
  flex-direction: column;
  gap: 15px;
}

.app-sentiment-item {
  background: var(--app-sentiment-bg);
  border-radius: 8px;
  padding: 10px;
  border: 1px solid var(--border-strong);
  box-shadow: 0 1px 3px var(--shadow-light);
}

.app-info {
  margin-bottom: 15px;
}

.app-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 5px;
}

.app-name {
  font-weight: 600;
  font-size: 16px;
  color: var(--text-primary);
}

.app-platform {
  font-size: 12px;
  color: var(--text-tertiary);
  font-weight: 400;
  margin-left: 6px;
}

.app-period {
  font-size: 11px;
  color: var(--text-tertiary);
  font-style: italic;
  opacity: 0.8;
}

.app-meta {
  display: flex;
  justify-content: space-between;
  font-size: 13px;
  color: var(--text-tertiary);
}

.app-store {
  text-transform: capitalize;
}

.app-total {
  font-weight: bold;
}

/* Trend arrows */
.trend-arrow {
  font-size: 1.2em;
  font-weight: bold;
}

.trend-arrow.up, .trend-arrow.strongly-up {
  color: #34c759;
}

.trend-arrow.down, .trend-arrow.strongly-down {
  color: #ff3b30;
}

.trend-arrow.stable {
  color: #ff9500;
}

.trend-arrow.neutral {
  color: #999;
}

/* Sentiment bars */
.app-sentiment-visual {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.sentiment-bar-container {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.sentiment-bar-label {
  display: flex;
  justify-content: space-between;
  font-size: 10px;
  color: var(--text-secondary);
}

.sentiment-value {
  font-weight: bold;
}

.sentiment-bar {
  height: 4px;
  background: var(--sentiment-bar-bg);
  border-radius: 2px;
  overflow: hidden;
}

.sentiment-bar-fill {
  height: 100%;
  border-radius: 2px;
  transition: width 0.3s ease;
}

.sentiment-bar-fill.sentiment-positive {
  background: #34c759;
}

.sentiment-bar-fill.sentiment-neutral {
  background: #ff9500;
}

.sentiment-bar-fill.sentiment-negative {
  background: #ff3b30;
}

.sentiment-bar-fill.sentiment-mixed {
  background: #007aff;
}

/* Error states for apps */
.app-sentiment-item.error {
  border-color: var(--sentiment-negative);
  background: rgba(255, 59, 48, 0.05);
}

.app-sentiment-error {
  color: var(--sentiment-negative);
  font-style: italic;
  text-align: center;
  padding: 20px;
}

.app-sentiment-item.no-data {
  opacity: 0.6;
}

.app-sentiment-empty {
  color: var(--text-tertiary);
  font-style: italic;
  text-align: center;
  padding: 20px;
}

/* Responsive design */
@media (max-width: 1600px) {
  .container {
    grid-template-columns: 1fr 400px;
  }
}

@media (max-width: 1200px) {
  .container {
    grid-template-columns: 1fr 350px;
  }

  .right-panels .panel h2 {
    font-size: 20px;
    margin-bottom: 16px;
  }

  .app-ratings-item,
  .app-sentiment-item {
    padding: 12px;
    margin-bottom: 12px;
  }
}

@media (max-width: 900px) {
  .container {
    grid-template-columns: 1fr;
    grid-template-rows: 1fr 1fr;
    gap: 15px;
    padding: 15px;
  }

  .right-panels {
    grid-row: 2;
    flex-direction: row;
    gap: 15px;
  }

  #reviews {
    column-width: 250px;
    column-gap: 12px;
  }

  .sentiment-stats {
    grid-template-columns: repeat(4, 1fr);
    gap: 8px;
  }

  .stat-card {
    padding: 10px;
  }

  .stat-value {
    font-size: 1.2em;
  }
}

@media (max-width: 600px) {
  .container {
    padding: 10px;
    gap: 10px;
  }

  .right-panels {
    flex-direction: column;
  }

  #reviews {
    column-width: 100%;
    column-count: 1;
    column-gap: 0;
  }

  .panel {
    padding: 15px;
  }

  .appbot-unavailable, .appbot-partial-failure {
    margin: 10px;
    padding: 30px 20px;
    max-width: 100%;
  }

  .unavailable-icon, .partial-failure-icon {
    font-size: 3em;
    margin-bottom: 15px;
  }

  .unavailable-title, .partial-failure-title {
    font-size: 1.3em;
    margin-bottom: 12px;
  }

  .unavailable-message, .partial-failure-message {
    font-size: 1rem;
    margin-bottom: 15px;
  }
  
  .panel h2 {
    font-size: 1.3em;
  }
  
  .review {
    padding: 12px;
  }
  
  .sentiment-stats {
    grid-template-columns: repeat(2, 1fr);
  }
}