/* Partie de styles.css : encart des nouveaux sondages et tableau des sondages.
   Chargée après les parties précédentes, dans l'ordre de scripts/app_sources.js
   (STYLESHEETS) : l'ordre de la cascade est celui de l'ancien fichier unique. */

/* Encart « Nouveau sondage » entre la barre de choix et le graphique : liste
   courte des sondages mis en ligne depuis moins de 72 h, chacun ouvrant sa fiche. */
.new-polls {
  display: flex;
  align-items: center;
  gap: 12px 22px;
  flex-wrap: wrap;
  margin-bottom: 28px;
  padding: 16px 20px;
  border: 2px solid var(--stormy-teal);
  border-radius: 2px;
  background: var(--panel);
}

.new-polls[hidden] {
  display: none;
}

/* Au second tour, la mosaïque suit l'encart avec le même écart que le graphique. */
.new-polls + .duel-mosaic-panel {
  margin-top: 0;
}

.new-polls h2 {
  display: inline-flex;
  align-items: center;
  gap: 9px;
  font-size: 1.05rem;
  white-space: nowrap;
}

/* Pastille « en direct » devant le titre. */
.new-polls h2::before {
  content: "";
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: var(--tomato-jam);
  box-shadow: 0 0 0 4px rgba(196, 69, 54, 0.16);
}

.new-polls-list {
  display: grid;
  flex: 1 1 100%;
  grid-template-columns: repeat(auto-fill, minmax(210px, 1fr));
  gap: 10px;
  margin: 0;
  padding: 0;
  list-style: none;
}

/* Chaque carte se lit de haut en bas : quand (date relative), qui (sondeur),
   puis le terrain en discret ; la flèche signale qu'elle ouvre la fiche. */
.new-poll {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  width: 100%;
  height: 100%;
  padding: 12px 12px 12px 16px;
  border: 1px solid var(--line);
  border-radius: 2px;
  background: var(--surface);
  color: var(--ink);
  cursor: pointer;
  font: inherit;
  text-align: left;
}

.new-poll:hover {
  border-color: var(--accent-ink);
}

.new-poll:focus-visible {
  outline: 2px solid var(--stormy-teal);
  outline-offset: 2px;
}

.new-poll-text {
  display: grid;
  gap: 2px;
  min-width: 0;
}

.new-poll-age {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  color: var(--accent-ink);
  font-size: 0.78rem;
  font-weight: 700;
  line-height: 1.3;
}

/* Moins de 24 h : pastille rouge, comme celle du titre. */
.new-poll.is-fresh .new-poll-age::before {
  content: "";
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--tomato-jam);
}

.new-poll-pollster {
  overflow: hidden;
  font-size: 1.12rem;
  font-weight: 750;
  line-height: 1.2;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.new-poll-period {
  color: var(--muted);
  font-size: 0.78rem;
  line-height: 1.3;
}

.new-poll-cta {
  display: inline-grid;
  flex: none;
  place-items: center;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: rgba(46, 107, 98, 0.10);
  color: var(--accent-ink);
  font-size: 1rem;
  font-weight: 700;
  transition: transform 0.15s ease, background-color 0.15s ease, color 0.15s ease;
}

.new-poll:hover .new-poll-cta,
.new-poll:focus-visible .new-poll-cta {
  background: var(--stormy-teal);
  color: #fff;
  transform: translateX(2px);
}

/* « Voir tous les sondages » : pilule secondaire,
  simplement poussée à droite du titre de l’encart. */
.new-polls-all {
  flex: none;
  margin-left: auto;
  text-decoration: none;
}

.polls-table-panel {
  margin-top: 64px;
  border: 2px solid var(--stormy-teal);
  border-radius: 2px;
  background: var(--panel);
}

.polls-table-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 22px 28px;
  flex-wrap: wrap;
  padding: 30px 28px 0;
}

.polls-table-head p {
  margin-top: 6px;
  color: var(--muted);
  font-size: 0.9rem;
  line-height: 1.45;
}

.polls-table-tools {
  display: flex;
  align-items: flex-end;
  gap: 18px;
  flex-wrap: wrap;
}

.polls-toggle {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 42px;
  color: var(--heading);
  font-size: 0.84rem;
  font-weight: 600;
  cursor: pointer;
}

.polls-toggle input {
  width: 16px;
  height: 16px;
  margin: 0;
  accent-color: var(--accent-ink);
  cursor: pointer;
}

.polls-sort {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.polls-sort button {
  padding: 0 12px;
  white-space: nowrap;
}

.polls-table-wrap {
  margin-top: 22px;
  max-height: 62vh;
  overflow: auto;
}

.polls-table {
  border-collapse: separate;
  border-spacing: 0;
  width: 100%;
  font-size: 0.82rem;
}

.polls-table th,
.polls-table td {
  border-bottom: 1px solid rgba(var(--ink-rgb), 0.12);
  white-space: nowrap;
}

.polls-table thead th {
  position: sticky;
  top: 0;
  z-index: 2;
  background: var(--soft);
  color: var(--heading);
  font-weight: 700;
  text-align: center;
  padding: 8px 4px;
  border-bottom: 2px solid var(--line-strong);
  vertical-align: bottom;
}

/* Colonne « Sondage » figée à gauche : fond opaque pour masquer les scores
   qui défilent dessous, largeur minimale (width: 1 %). */
.polls-table .polls-th-meta,
.polls-table .polls-td-meta {
  position: sticky;
  left: 0;
  width: 1%;
  text-align: left;
  box-shadow: inset -1px 0 0 rgba(var(--ink-rgb), 0.14);
}

.polls-table thead .polls-th-meta {
  z-index: 3;
  padding-left: 12px;
}

.polls-table tbody .polls-td-meta {
  z-index: 1;
  max-width: 9.5rem;
  background: var(--panel);
  padding: 7px 10px 7px 12px;
  vertical-align: top;
}

.polls-td-meta > span {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
}

.polls-meta-sondeur {
  font-weight: 650;
  color: var(--heading);
  line-height: 1.25;
}

.polls-meta-date {
  margin-top: 1px;
  color: var(--ink);
  font-size: 0.76rem;
  line-height: 1.3;
}

.polls-meta-details {
  display: flex !important;
  gap: 6px;
  margin-top: 1px;
  color: var(--muted);
  font-size: 0.7rem;
  line-height: 1.3;
  font-variant-numeric: tabular-nums;
}

.polls-th-candidate {
  font-weight: 650;
  min-width: 46px;
}

.polls-th-candidate span:last-child {
  display: block;
  line-height: 1.1;
}

.polls-th-dot {
  display: inline-block;
  width: 8px;
  height: 8px;
  margin-bottom: 3px;
  border-radius: 50%;
}

.polls-table tbody td {
  padding: 6px 4px;
  vertical-align: middle;
}

.polls-table tbody tr.polls-poll-start td {
  border-top: 1px solid rgba(var(--ink-rgb), 0.16);
}

.polls-source-link {
  color: var(--accent-ink);
  text-decoration: none;
}

.polls-source-link:hover {
  text-decoration: underline;
}

.polls-td-score {
  text-align: center;
  font-variant-numeric: tabular-nums;
  color: var(--ink);
}

.polls-td-score.is-empty {
  color: var(--line);
}

.polls-td-score.is-rank-1 {
  font-weight: 750;
}

.polls-td-score.is-rank-2 {
  font-weight: 680;
}

@media (max-width: 640px) {
  .polls-table {
    font-size: 0.74rem;
  }

  .polls-table thead th {
    padding: 7px 2px;
  }

  .polls-table tbody td {
    padding: 5px 2px;
  }

  .polls-th-candidate {
    min-width: 38px;
  }

  .polls-table tbody .polls-td-meta {
    max-width: 6.6rem;
    padding: 6px 6px 6px 8px;
  }

  .polls-table thead .polls-th-meta {
    padding-left: 8px;
  }

  .polls-meta-date {
    font-size: 0.7rem;
  }

  .polls-meta-details {
    font-size: 0.64rem;
    flex-wrap: wrap;
    gap: 0 5px;
  }
}

@media (max-width: 860px) {
  .polls-table-head {
    padding: 22px 16px 0;
  }

  p.panel-lede {
    font-size: 0.97rem;
  }

}

@media (max-width: 1280px) {
  .controls {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .legend {
    flex-wrap: wrap;
  }

}

@media (max-width: 860px) {
  .shell {
    width: min(100% - 24px, 1360px);
    padding: 18px 0 24px;
  }

  .topbar,
  .chart-head,
  .comparison-head {
    display: block;
  }

  .topbar {
    margin-bottom: 22px;
  }

  .source {
    margin-top: 10px;
    text-align: left;
    white-space: normal;
  }

  .freshness {
    max-width: none;
    text-align: left;
  }

  .top-actions {
    align-items: flex-start;
    margin-top: 18px;
  }

  .election-control {
    width: 112px;
  }

  .round-modebar {
    min-height: 56px;
    margin-bottom: 22px;
    padding: 13px 16px;
  }

  .filters-card {
    margin: 16px 16px 0;
    padding: 16px;
  }

  .chart-actions {
    width: min(100%, 390px);
    margin-top: 18px;
    padding-top: 0;
  }

  .action-button {
    margin-top: 16px;
  }

  .duel-mosaic-head {
    display: block;
  }

  .duel-mosaic-head .comparison-actions {
    margin-top: 10px;
  }

  /* Les boutons passent sous le titre, à gauche : le menu s'ouvre vers la droite. */
  .duel-mosaic-settings-menu {
    right: auto;
    left: 0;
  }

  .filters-head {
    margin-bottom: 15px;
  }

  .nowcast-panel,
  .nowcast-score-panel {
    padding: 20px 16px;
  }

  .nowcast-scenarios-cta {
    grid-template-columns: 1fr;
    margin-bottom: 38px;
    padding: 0 16px;
  }

  .nowcast-scenarios-link {
    grid-column: 1;
  }

  .nowcast-head {
    display: block;
  }

  /* Le bouton d'export reste à droite du titre, comme sur ordinateur. */
  .nowcast-panel > .nowcast-head {
    display: flex;
    align-items: flex-start;
    gap: 12px;
  }

  .nowcast-overview {
    grid-template-columns: 1fr;
    grid-template-rows: none;
    grid-auto-flow: row;
  }

  .nowcast-overview-column {
    display: block;
    min-width: 0;
  }

  /* L'évolution passe sous la liste quand les deux colonnes ne tiennent plus. */
  .nowcast-overview-column.is-history {
    margin-top: 8px;
  }

  .nowcast-overview-list {
    min-height: 0;
    gap: 9px;
    border: 0;
    background: transparent;
    padding: 0;
  }

  .nowcast-overview-row {
    border: 1px solid var(--line);
    border-radius: 3px;
    background: var(--panel);
    padding: 12px 13px 10px;
  }

  .nowcast-overview-row + .nowcast-overview-row {
    border-top: 1px solid var(--line);
  }

  .nowcast-overview-gauge {
    height: 7px;
    margin: 10px 0 8px;
  }

  .controls {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  svg {
    height: 560px;
  }

  .comparison-row {
    grid-template-columns: 13px minmax(100px, 0.48fr) minmax(170px, 1fr) 34px;
  }

  .comparison-modal-card {
    max-height: calc(100vh - 32px);
    padding: 18px;
  }

}

@media (max-width: 560px) {
  h1 {
    font-size: 2rem;
  }

  .controls {
    grid-template-columns: 1fr;
  }

  .scenario-notice {
    font-size: 0.82rem;
  }

  .chart-head {
    padding: 22px 16px 0;
  }

  .chart-actions {
    grid-template-columns: minmax(108px, 0.58fr) minmax(200px, 1.42fr);
    gap: 8px;
  }

  .legend-panel {
    padding: 16px;
  }

  .legend-head {
    gap: 12px;
  }

  .legend-item {
    min-height: 29px;
    padding: 4px 8px;
  }

  .comparison-head,
  .comparison-controls {
    padding-left: 16px;
    padding-right: 16px;
  }

  .comparison-row {
    grid-template-columns: 13px minmax(0, 1fr) 34px;
  }

  .comparison-row .control:nth-of-type(2) {
    grid-column: 2 / 4;
  }

  .comparison-swatch {
    grid-row: 1 / 3;
  }

  .comparison-row > .icon-button {
    grid-column: 3;
    grid-row: 1;
  }

  .comparison-modal {
    padding: 12px;
  }

  .comparison-modal-head,
  .comparison-modal-actions {
    display: grid;
  }

  .comparison-modal-actions .action-button {
    width: 100%;
  }

  .chart-wrap {
    min-height: 500px;
  }

  .time-range-editor {
    margin: 0 16px 16px;
    padding: 13px 12px 10px;
  }

  .time-range-editor-head {
    display: block;
  }

  .time-range-editor output {
    display: block;
    margin-top: 7px;
    white-space: normal;
  }

  svg {
    height: 500px;
    min-height: 500px;
  }

}

@media (max-width: 360px) {
  .chart-actions {
    grid-template-columns: 1fr;
  }

}
