/* MegaMeteo -----------------------------------------------------------------
   Palette roles are declared once and swapped per theme, so every rule below is
   written against a role rather than a raw colour. The categorical series
   colours are the three validated slots (blue / orange / aqua); the estimate is
   deliberately NOT a fourth hue but the page's own ink, because it is the
   headline rather than a peer of the three group means.
--------------------------------------------------------------------------- */

:root {
  color-scheme: light;

  --surface:          #fcfcfb;
  --surface-raised:   #ffffff;
  --surface-sunken:   #f4f3f0;
  --border:           #e2e0da;
  --border-strong:    #cbc8bf;

  --text-primary:     #0b0b0b;
  --text-secondary:   #52514e;
  --text-muted:       #86847d;

  /* Categorical slots 1-3, validated all-pairs in both modes. */
  --series-local:     #2a78d6;
  --series-regional:  #eb6834;
  --series-global:    #1baf7a;
  --series-estimate:  #0b0b0b;
  --band-fill:        rgba(11, 11, 11, 0.09);

  --grid:             #eceae4;

  /* Diverging temperature ramp for the ROW tint: blue <-> red around a neutral
     middle, four narrow steps per arm. These sit close to the surface on
     purpose -- they are a background cue behind numbers, not a mark. */
  --t-cold-4:  #dbe9fa;
  --t-cold-3:  #e7f0fc;
  --t-cold-2:  #f0f6fd;
  --t-cold-1:  #f7fafe;
  --t-neutral: transparent;
  --t-warm-1:  #fdf9f7;
  --t-warm-2:  #fdf2ef;
  --t-warm-3:  #fbe9e4;
  --t-warm-4:  #f8ddd6;

  --night-veil: rgba(26, 32, 56, 0.05);
  --now-accent: #2a78d6;
}

@media (prefers-color-scheme: dark) {
  :root:where(:not([data-theme="light"])) {
    color-scheme: dark;

    --surface:        #1a1a19;
    --surface-raised: #232320;
    --surface-sunken: #141413;
    --border:         #35342f;
    --border-strong:  #4a4842;

    --text-primary:   #ffffff;
    --text-secondary: #c3c2b7;
    --text-muted:     #8f8d84;

    --series-local:    #3987e5;
    --series-regional: #d95926;
    --series-global:   #199e70;
    --series-estimate: #ffffff;
    --band-fill:       rgba(255, 255, 255, 0.10);

    --grid:            #2b2a27;

    --t-cold-4:  #1c3047;
    --t-cold-2:  #1c2734;
    --t-cold-3:  #1d2b3d;
    --t-cold-1:  #20262c;
    --t-neutral: transparent;
    --t-warm-1:  #272422;
    --t-warm-2:  #2d2521;
    --t-warm-3:  #32261f;
    --t-warm-4:  #38281f;

    --night-veil: rgba(120, 150, 220, 0.06);
    --now-accent: #3987e5;
  }
}

:root[data-theme="dark"] {
  color-scheme: dark;

  --surface:        #1a1a19;
  --surface-raised: #232320;
  --surface-sunken: #141413;
  --border:         #35342f;
  --border-strong:  #4a4842;

  --text-primary:   #ffffff;
  --text-secondary: #c3c2b7;
  --text-muted:     #8f8d84;

  --series-local:    #3987e5;
  --series-regional: #d95926;
  --series-global:   #199e70;
  --series-estimate: #ffffff;
  --band-fill:       rgba(255, 255, 255, 0.10);

  --grid:            #2b2a27;

  --t-cold-4:  #1c3047;
  --t-cold-3:  #1d2b3d;
  --t-cold-2:  #1c2734;
  --t-cold-1:  #20262c;
  --t-neutral: transparent;
  --t-warm-1:  #272422;
  --t-warm-2:  #2d2521;
  --t-warm-3:  #32261f;
  --t-warm-4:  #38281f;

  --night-veil: rgba(120, 150, 220, 0.06);
  --now-accent: #3987e5;
}

body {
  background: var(--surface);
  color: var(--text-primary);
  font-size: 15px;
}

a { color: var(--series-local); }

/* --- Chrome --------------------------------------------------------------- */

.mm-navbar {
  background: var(--surface-raised);
  border-bottom: 1px solid var(--border);
}
.mm-navbar .navbar-brand { color: var(--text-primary); font-weight: 600; }
.mm-navbar .nav-link { color: var(--text-secondary); }
.mm-navbar .nav-link:hover { color: var(--text-primary); }
.mm-navbar .nav-link.active {
  color: var(--text-primary);
  font-weight: 600;
  box-shadow: inset 0 -2px 0 var(--now-accent);
}
.mm-theme-toggle { color: var(--text-secondary); border-color: var(--border-strong); }

.mm-main { max-width: 1800px; padding: 1.25rem 1rem 3rem; }

.mm-header { margin: 0.5rem 0 1.25rem; }
.mm-place { font-weight: 300; letter-spacing: -0.02em; margin-bottom: 0.25rem; }
.mm-place-meta {
  color: var(--text-muted);
  font-size: 0.85rem;
  display: flex; flex-wrap: wrap; gap: 0.75rem;
  justify-content: center;
}
.mm-place-meta span::before { content: "·"; margin-right: 0.75rem; color: var(--border-strong); }
.mm-place-meta span:first-child::before { content: none; margin: 0; }

.mm-alert { font-size: 0.9rem; }

.mm-tabs {
  border-bottom-color: var(--border);
  flex-wrap: nowrap;
  overflow-x: auto;
  scrollbar-width: none;
}
.mm-tabs::-webkit-scrollbar { display: none; }
.mm-tabs .nav-link { white-space: nowrap; }
.mm-tabs .nav-link { color: var(--text-secondary); border: none; padding: 0.6rem 1rem; }
.mm-tabs .nav-link:hover { color: var(--text-primary); }
.mm-tabs .nav-link.active {
  color: var(--text-primary);
  background: transparent;
  border-bottom: 2px solid var(--now-accent);
  font-weight: 600;
}
.mm-tab-content { padding-top: 1.25rem; }

.mm-section-title { font-size: 1.05rem; font-weight: 600; margin: 1.75rem 0 0.25rem; }
.mm-section-note { color: var(--text-muted); font-size: 0.85rem; margin-bottom: 0.75rem; }

.mm-freshness {
  margin-top: 2rem; color: var(--text-muted); font-size: 0.8rem;
  display: flex; flex-wrap: wrap; gap: 1.25rem;
}

.mm-footer {
  border-top: 1px solid var(--border);
  padding: 1.25rem 1rem;
  color: var(--text-muted);
  font-size: 0.8rem;
}
.mm-placeholder { padding: 4rem 1rem; text-align: center; }

/* --- The estimated summary ------------------------------------------------ */

.mm-hero {
  background: var(--surface-raised);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 1.25rem 1.5rem;
  display: grid;
  gap: 1rem;
}
.mm-hero-main { display: flex; align-items: center; gap: 1.25rem; }
.mm-hero-icon { font-size: 3.5rem; color: var(--text-secondary); line-height: 1; }
.mm-hero-temp { font-size: 2.75rem; font-weight: 300; line-height: 1.05; }
.mm-hero-condition { font-size: 1.05rem; color: var(--text-secondary); }
.mm-hero-apparent { font-size: 0.9rem; color: var(--text-muted); }
.mm-hero-facts {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(190px, 1fr));
  gap: 0.5rem 1.5rem;
}
.mm-fact { display: flex; align-items: baseline; gap: 0.5rem; font-size: 0.9rem; }
.mm-fact i { color: var(--text-muted); width: 1.1rem; }
.mm-fact-label { color: var(--text-secondary); flex: 1; }
.mm-fact-value { font-variant-numeric: tabular-nums; font-weight: 600; }
.mm-hero-note { margin: 0; font-size: 0.8rem; color: var(--text-muted); }

/* --- Tables --------------------------------------------------------------- */

/* Scrolling in both axes inside this box is what makes the header row stick.
   A horizontal-only container (Bootstrap's .table-responsive) clips vertically,
   so `position: sticky; top: 0` on the header had nothing to stick to while the
   page scrolled past it. Capping the height gives it one. */
.mm-table-wrap {
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface-raised);
  overflow: auto;
  max-height: min(78vh, 900px);
  overscroll-behavior: contain;
}
.mm-table { margin: 0; color: var(--text-primary); --bs-table-bg: transparent; }
.mm-table thead th {
  position: sticky; top: 0; z-index: 3;
  /* The header sits on an opaque ground: rows scroll underneath it. */
  background: var(--surface-sunken);
  border-bottom: 1px solid var(--border-strong);
  font-size: 0.72rem; font-weight: 600;
  text-transform: uppercase; letter-spacing: 0.03em;
  color: var(--text-secondary);
  white-space: nowrap; vertical-align: bottom;
  padding: 0.5rem 0.6rem;
}
.mm-col-agency { display: block; font-size: 0.64rem; color: var(--text-muted); font-weight: 500; text-transform: none; }
.mm-col-model { display: block; color: var(--text-primary); text-transform: none; font-size: 0.78rem; }
/* The grid spacing is the single most useful thing to know about a model when
   comparing it with its neighbours: it says how much detail the column can
   possibly hold. */
.mm-col-res {
  display: block;
  font-size: 0.62rem;
  font-weight: 500;
  color: var(--text-muted);
  text-transform: none;
  font-variant-numeric: tabular-nums;
}

/* Model columns are ruled by scope, so a reader can see at a glance which
   family a column belongs to without reading the header. */
.mm-table th.mm-col-local    { box-shadow: inset 0 3px 0 var(--series-local); }
.mm-table th.mm-col-regional { box-shadow: inset 0 3px 0 var(--series-regional); }
.mm-table th.mm-col-global   { box-shadow: inset 0 3px 0 var(--series-global); }

.mm-table td, .mm-table th { border-color: var(--border); vertical-align: top; }
.mm-table tbody td { padding: 0.15rem; }

/* The first column and the estimate stay put while the models scroll past. */
.mm-sticky-col {
  position: sticky; left: 0; z-index: 2;
  background: var(--surface-raised);
  border-right: 1px solid var(--border-strong);
  white-space: nowrap; min-width: 6.5rem;
  padding: 0.4rem 0.6rem;
}
/* Without this the columns sliding underneath just stop mid-glyph; the shadow
   says they are passing behind rather than being clipped. */
.mm-col-estimate { box-shadow: 6px 0 6px -6px rgba(0, 0, 0, 0.18); }
.mm-table thead .mm-sticky-col { z-index: 4; background: var(--surface-sunken); }
.mm-row-label { display: block; font-weight: 600; font-variant-numeric: tabular-nums; }
.mm-row-sub { display: block; font-size: 0.7rem; color: var(--text-muted); }

.mm-col-estimate {
  position: sticky; left: 6.5rem; z-index: 2;
  width: 8rem;
  background: var(--surface-raised);
  border-right: 2px solid var(--border-strong);
}
.mm-table thead .mm-col-estimate { z-index: 4; background: var(--surface-sunken); }

.mm-row-now { outline: 2px solid var(--now-accent); outline-offset: -2px; }
.mm-day-boundary > * { border-top: 2px solid var(--border-strong) !important; }
.mm-night td, .mm-night .mm-sticky-col { background-image: linear-gradient(var(--night-veil), var(--night-veil)); }

.mm-row { cursor: pointer; }
.mm-row:hover td { filter: brightness(0.985); }
.mm-row:focus-visible { outline: 2px solid var(--now-accent); outline-offset: -2px; }

/* --- Forecast cells ------------------------------------------------------- */

/* A fixed layout is what keeps 26 columns the same width instead of letting
   "Harmonie AROME Europe" set the width for everyone. It also means EVERY
   column needs a declared width -- an undeclared one collapses, which is how the
   two pinned columns ended up overlapping the first model. */
.mm-table-matrix { table-layout: fixed; }
.mm-table-matrix th.mm-sticky-col   { width: 6.5rem; min-width: 6.5rem; }
/* Day labels ("dimanche 13 sept.") need far more room than hour labels. */
.mm-table-days th.mm-sticky-col     { width: 9.5rem; min-width: 9.5rem; }
.mm-table-days .mm-col-estimate     { left: 9.5rem; }
.mm-table-matrix th.mm-col-estimate { width: 8rem;   min-width: 8rem; }
.mm-table-matrix thead th:not(.mm-sticky-col):not(.mm-col-estimate) { width: 7.5rem; }
/* Long names such as "Harmonie AROME Europe" would otherwise set the column
   width and leave the table ragged; the full name stays in the header tooltip. */
.mm-col-model, .mm-col-agency, .mm-col-res {
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}

.mm-cell {
  border-radius: 6px;
  padding: 0.25rem 0.35rem;
  font-variant-numeric: tabular-nums;
  line-height: 1.3;
}
.mm-cell-top { display: flex; align-items: baseline; gap: 0.3rem; flex-wrap: wrap; }
.mm-cell-icon { font-size: 1.1rem; color: var(--text-secondary); }
.mm-cell-temp { font-size: 1.05rem; font-weight: 600; }
.mm-cell-line { font-size: 0.72rem; color: var(--text-secondary); white-space: nowrap; }
.mm-cell-apparent { color: var(--text-muted); }
.mm-gust { color: var(--text-muted); }
.mm-dry { color: var(--text-muted); }
.mm-prob { color: var(--series-local); font-weight: 600; }
.mm-arrow { font-size: 0.85rem; }
.mm-spread { font-size: 0.68rem; color: var(--text-muted); font-weight: 500; white-space: nowrap; }

/* An absent forecast is a hairline dash, not a filled block: with a dozen
   short-range models over 14 days the blocks became the loudest thing on the
   page, which is the opposite of what "no data" should look like. */
.mm-cell-empty {
  color: var(--border-strong);
  text-align: center;
  padding: 0.25rem 0.35rem;
  display: block;
}
.mm-cell-estimate { box-shadow: inset 0 0 0 1px var(--border-strong); }
.mm-low-confidence { box-shadow: inset 0 0 0 1px var(--series-regional); }

/* The bucket sets a row-level variable rather than painting directly, so the
   sticky first and estimate columns pick up the same tint instead of punching
   an untinted hole through every row. */
.t-cold-4  { --row-tint: var(--t-cold-4); }
.t-cold-3  { --row-tint: var(--t-cold-3); }
.t-cold-2  { --row-tint: var(--t-cold-2); }
.t-cold-1  { --row-tint: var(--t-cold-1); }
.t-neutral { --row-tint: var(--surface-raised); }
.t-warm-1  { --row-tint: var(--t-warm-1); }
.t-warm-2  { --row-tint: var(--t-warm-2); }
.t-warm-3  { --row-tint: var(--t-warm-3); }
.t-warm-4  { --row-tint: var(--t-warm-4); }

.mm-table-matrix tbody tr > * { background: var(--row-tint, var(--surface-raised)); }

/* --- Expanded detail, rendered as rows of the table it belongs to ---------- */

.mm-detail-line > * {
  background: var(--surface-sunken) !important;
  border-top: none;
}
.mm-detail-line:first-of-type > * { border-top: 1px solid var(--border-strong); }
/* Variable names ("Température ressentie") are far longer than the hour labels
   the column is sized for, and the spread is longer than a temperature, so both
   pinned cells wrap here instead of spilling under the next column. */
.mm-detail-line .mm-sticky-col { white-space: normal; }
.mm-detail-line .mm-row-label {
  font-weight: 500;
  font-size: 0.72rem;
  line-height: 1.2;
  color: var(--text-secondary);
  white-space: normal;
}
.mm-detail-line td { padding: 0.15rem 0.4rem; overflow: hidden; }
/* Text values ("Partiellement nuageux") are far wider than the numbers the
   columns are sized for, and would otherwise print straight over the next one. */
.mm-detail-value {
  display: block;
  font-variant-numeric: tabular-nums;
  font-size: 0.8rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
/* Weather conditions are the one row whose values are prose: "Principalement
   nuageux" does not fit a column sized for "18,4 °C", and an ellipsis there
   hides exactly the word that distinguishes one model's forecast from the
   next. Those rows wrap instead of clipping. */
.mm-detail-wrap .mm-detail-value {
  white-space: normal;
  overflow: visible;
  overflow-wrap: break-word;
  text-overflow: clip;
  line-height: 1.15;
}
.mm-detail-line .mm-col-estimate .mm-detail-value { font-weight: 600; }
.mm-detail-spread {
  display: block;
  font-size: 0.66rem;
  line-height: 1.2;
  color: var(--text-muted);
  white-space: normal;
}

/* The "Actuel" table is the same shape as an expanded row, so it shares the
   styling rather than defining its own. */
.mm-table-vars .mm-detail-line > * { background: var(--surface-raised) !important; }
.mm-table-vars .mm-detail-line:nth-child(even) > * { background: var(--surface-sunken) !important; }
.mm-table-vars th.mm-sticky-col   { width: 13rem; min-width: 13rem; }
.mm-table-vars .mm-detail-line .mm-row-label { font-size: 0.82rem; color: var(--text-primary); }
.mm-table-vars .mm-col-estimate   { left: 13rem; }

/* The mobile cards have no row to tint, so the card body carries it. */
.mm-card-body.t-cold-4  { background: var(--t-cold-4); }
.mm-card-body.t-cold-3  { background: var(--t-cold-3); }
.mm-card-body.t-cold-2  { background: var(--t-cold-2); }
.mm-card-body.t-cold-1  { background: var(--t-cold-1); }
.mm-card-body.t-warm-1  { background: var(--t-warm-1); }
.mm-card-body.t-warm-2  { background: var(--t-warm-2); }
.mm-card-body.t-warm-3  { background: var(--t-warm-3); }
.mm-card-body.t-warm-4  { background: var(--t-warm-4); }

/* --- Consensus cards (the default on narrow screens) ---------------------- */

.mm-cards { margin: 0; display: grid; gap: 0.4rem; }
.mm-card {
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface-raised);
  overflow: hidden;
}
.mm-card-now { border-color: var(--now-accent); }
.mm-card.mm-night { background-image: linear-gradient(var(--night-veil), var(--night-veil)); }
.mm-card-head {
  width: 100%;
  display: grid;
  grid-template-columns: 5.5rem 1fr auto;
  align-items: center;
  gap: 0.75rem;
  padding: 0.6rem 0.8rem;
  background: none; border: none; text-align: left;
  color: inherit;
}
.mm-card-when { display: flex; flex-direction: column; }
.mm-card-time { font-size: 1.05rem; font-weight: 600; font-variant-numeric: tabular-nums; }
.mm-card-rel { font-size: 0.7rem; color: var(--text-muted); }
.mm-card-body {
  display: flex; align-items: baseline; flex-wrap: wrap; gap: 0.4rem 0.6rem;
  border-radius: 8px; padding: 0.3rem 0.5rem;
}
.mm-card-icon { font-size: 1.4rem; color: var(--text-secondary); }
.mm-card-temp { font-size: 1.35rem; font-weight: 600; font-variant-numeric: tabular-nums; }
.mm-card-detail { font-size: 0.8rem; color: var(--text-secondary); }
.mm-card-models { font-size: 0.7rem; color: var(--text-muted); }
.mm-card-chevron { color: var(--text-muted); transition: transform 0.15s ease; }
.mm-card-head[aria-expanded="true"] .mm-card-chevron { transform: rotate(180deg); }
.mm-card-panel { padding: 0 0.8rem 0.8rem; }

/* --- Model filter chips --------------------------------------------------- */

.mm-model-filter { display: flex; flex-wrap: wrap; gap: 0.4rem; margin-bottom: 0.6rem; }
.mm-chip {
  border: 1px solid var(--border-strong);
  background: var(--surface-raised);
  color: var(--text-secondary);
  border-radius: 999px;
  padding: 0.2rem 0.7rem;
  font-size: 0.78rem;
}
.mm-chip[aria-pressed="true"] { color: var(--text-primary); border-color: currentColor; font-weight: 600; }
.mm-chip-local[aria-pressed="true"]    { box-shadow: inset 0 -2px 0 var(--series-local); }
.mm-chip-regional[aria-pressed="true"] { box-shadow: inset 0 -2px 0 var(--series-regional); }
.mm-chip-global[aria-pressed="true"]   { box-shadow: inset 0 -2px 0 var(--series-global); }
.mm-chip-count { color: var(--text-muted); }

/* --- Card detail (mobile) -------------------------------------------------- */

.mm-detail-readings {
  margin: 0.2rem 0 0; display: grid;
  grid-template-columns: 1fr auto; gap: 0 0.75rem;
  font-size: 0.82rem;
}
.mm-detail-readings dt { color: var(--text-secondary); font-weight: 400; }
.mm-detail-readings dd { margin: 0; text-align: right; font-variant-numeric: tabular-nums; }

/* --- Charts --------------------------------------------------------------- */

.mm-charts { margin-top: 2rem; }
.mm-chart-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 1rem;
}
@media (max-width: 991.98px) {
  .mm-chart-grid { grid-template-columns: 1fr; }
}
.mm-chart-card {
  background: var(--surface-raised);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 0.9rem 1rem 0.6rem;
}
.mm-chart-title { font-size: 0.85rem; font-weight: 600; margin-bottom: 0.1rem; }
.mm-chart-unit { font-size: 0.72rem; color: var(--text-muted); }
.mm-chart-canvas { position: relative; height: 260px; margin-top: 0.5rem; }

/* --- View switch ---------------------------------------------------------- */

.mm-view-switch { margin-bottom: 0.75rem; }
.mm-view-switch .btn { color: var(--text-secondary); border-color: var(--border-strong); }
.mm-view-switch .btn[aria-pressed="true"] {
  color: var(--text-primary); font-weight: 600;
  background: var(--surface-sunken);
}
.mm-view[hidden] { display: none !important; }

/* Wide screens lead with the full matrix; narrow ones lead with the estimate,
   because 25 columns cannot be made readable on a phone. The switch overrides
   either default and the choice is remembered. */
@media (max-width: 991.98px) {
  .mm-main { padding: 1rem 0.5rem 2rem; }
  .mm-place { font-size: 2rem; }
  .mm-hero { padding: 1rem; }
  .mm-hero-temp { font-size: 2.25rem; }
  .mm-chart-canvas { height: 200px; }
  .mm-detail-groups { grid-template-columns: 1fr; }
  .mm-col-estimate { position: static; }
}

@media (prefers-reduced-motion: reduce) {
  .mm-card-chevron { transition: none; }
}
