/* md-charts.css — tema i estils de la llibreria de gràfics (MDCharts, basada en D3).
 * Els components llegeixen els colors d'aquestes variables (mai literals dins del JS, vegeu core.js · theme()).
 * Tema fosc: segueix prefers-color-scheme, o es força amb <html data-theme="dark|light">.
 * El web de l'Observatori encara no té tema fosc: layout.php fixa data-theme="light". */

:root {
  --md-fg: var(--ink, #1e2124);
  --md-muted: var(--muted, #5d6468);
  --md-grid: #e6ecee;
  --md-axis: #9fb0b6;
  --md-series-muted: #c5cfd3;
  --md-accent: var(--accent, #ef7d00);
  --md-band: #fde4b8;
  --md-good: #2e9e5b;
  --md-bad: #ec5b56;
  --md-surface: var(--white, #ffffff);
  --md-hl: var(--deep, #2f5a63);
  --md-line: var(--line, #e1e2dd);
  --md-map-sea: transparent;
  --md-map-land: #f5f7f8;
  --md-map-ctx: #dde2e6;
  --md-map-on: var(--blue, #5b8b9a);
  --md-map-edge: #ffffff;
  --md-map-line: #94a6ad;
  --md-nodata: #e9edef;
  --md-font: -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --md-fg: #e7e9e8; --md-muted: #9aa1a5; --md-grid: #262a2e; --md-axis: #5f666b; --md-series-muted: #555b60;
    --md-accent: #ff9933; --md-band: #4a3517; --md-good: #4cc07a; --md-bad: #ff7b74; --md-surface: #1b1e21;
    --md-hl: #8fd3e0; --md-line: #2c3034; --md-map-sea: #20262a; --md-map-land: #1b1e21; --md-map-ctx: #343a3f;
    --md-map-on: #5b8b9a; --md-map-edge: #1b1e21; --md-map-line: #6d7b81; --md-nodata: #2b3034;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --md-fg: #e7e9e8; --md-muted: #9aa1a5; --md-grid: #262a2e; --md-axis: #5f666b; --md-series-muted: #555b60;
  --md-accent: #ff9933; --md-band: #4a3517; --md-good: #4cc07a; --md-bad: #ff7b74; --md-surface: #1b1e21;
  --md-hl: #8fd3e0; --md-line: #2c3034; --md-map-sea: #20262a; --md-map-land: #1b1e21; --md-map-ctx: #343a3f;
  --md-map-on: #5b8b9a; --md-map-edge: #1b1e21; --md-map-line: #6d7b81; --md-nodata: #2b3034;
  color-scheme: dark;
}

/* Marc: títol / subtítol / font en HTML al voltant del gràfic */
.md-fig { margin: 0; color: var(--md-fg); font-family: var(--md-font); min-width: 0; }
.md-fig.md-surface { background: var(--md-surface); border: 1px solid var(--md-line); border-radius: 4px; padding: 16px; }
.md-head { display: grid; gap: 4px; margin-bottom: 12px; }
.md-bar { width: 48px; height: 5px; background: var(--md-accent); margin-bottom: 6px; }
.md-title { margin: 0; font-size: 19px; line-height: 1.2; font-weight: 700; text-wrap: balance; }
.md-sub { margin: 0; font-size: 14px; line-height: 1.4; color: var(--md-muted); }
.md-plot { position: relative; width: 100%; }
.md-plot svg { display: block; width: 100%; overflow: visible; font-family: var(--md-font); }
.md-source { margin: 8px 0 0; font-size: 12px; line-height: 1.4; color: var(--md-muted); }
.md-tools { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 10px; }
.md-btn {
  font: 600 12px/1 var(--md-font); color: var(--md-muted); background: transparent; cursor: pointer;
  border: 1px solid var(--md-line); border-radius: 999px; padding: 7px 11px;
}
.md-btn:hover, .md-btn:focus-visible { color: var(--md-fg); border-color: var(--md-accent); outline: none; }
.md-btn[aria-pressed="true"] { color: var(--md-fg); border-color: var(--md-hl); }

/* Taula de dades: oculta visualment però disponible per a lectors de pantalla; visible amb «Veure dades» */
.md-data { margin-top: 10px; }
.md-data.md-sr { position: absolute; width: 1px; height: 1px; margin: -1px; padding: 0; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }
.md-data .md-table-wrap { max-height: 320px; overflow: auto; border: 1px solid var(--md-line); }
.md-data table { border-collapse: collapse; width: 100%; font-size: 13px; font-variant-numeric: tabular-nums; }
.md-data caption { text-align: left; font-weight: 600; padding: 6px 0; color: var(--md-muted); }
.md-data th, .md-data td { padding: 5px 10px; border-bottom: 1px solid var(--md-line); text-align: right; }
.md-data th:first-child, .md-data td:first-child { text-align: left; }
.md-data thead th { position: sticky; top: 0; background: var(--md-surface); }

/* Tooltip compartit (un sol element per pàgina) */
#md-tip {
  position: fixed; z-index: 1000; left: 0; top: 0; pointer-events: none; max-width: 260px;
  background: var(--md-surface); color: var(--md-fg); border: 1px solid var(--md-line); border-radius: 3px;
  box-shadow: 0 4px 14px rgba(0, 0, 0, .18); padding: 8px 10px; font: 14px/1.4 var(--md-font);
}
#md-tip[hidden] { display: none; }

/* Elements dels gràfics */
.md-svg text { font-family: var(--md-font); }
.md-fade { transition: opacity .25s ease; }
@media (prefers-reduced-motion: reduce) { .md-fade { transition: none; } }

/* Mapes */
.md-map .md-sea { fill: var(--md-map-sea); }
.md-map .md-land { fill: var(--md-map-land); }
.md-map a { outline: none; cursor: pointer; }
.md-map .md-shape { fill: var(--md-map-on); stroke: var(--md-map-edge); stroke-width: .8; vector-effect: non-scaling-stroke; stroke-linejoin: round; transition: fill .15s; }
.md-map .md-ctx { fill: var(--md-map-ctx); stroke: var(--md-map-edge); stroke-width: .8; vector-effect: non-scaling-stroke; stroke-linejoin: round; transition: fill .15s; }
.md-map .md-ctx.md-far { fill: var(--md-nodata); }
.md-map .md-nodata { fill: url(#md-hatch); }
.md-map a:hover .md-shape, .md-map a:focus-visible .md-shape { fill: var(--md-hl) !important; }
.md-map a:hover .md-ctx { fill: var(--md-series-muted); }
.md-map a:focus-visible path { stroke: var(--md-accent); stroke-width: 3; }
.md-map .md-hi { stroke: var(--md-accent); stroke-width: 2.5; }
.md-map .md-line { fill: none; stroke: var(--md-map-line); stroke-width: 1.5; vector-effect: non-scaling-stroke; pointer-events: none; }
.md-map .md-lbl { fill: #fff; stroke: var(--md-hl); font-weight: 650; paint-order: stroke; stroke-linejoin: round; pointer-events: none; }
.md-map .md-legend text { fill: var(--md-fg); }
.md-map .md-hatch-line { stroke: var(--md-series-muted); }

/* Controls del component (control de temps, canvi de periodicitat) */
.md-controls { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 16px; margin-top: 8px; }
.md-controls[hidden] { display: none; }
.md-slider { display: flex; align-items: center; gap: 10px; font-size: 13px; color: var(--md-muted); flex: 1 1 260px; min-width: 0; }
.md-slider input[type=range] { flex: 1; min-width: 80px; accent-color: var(--md-accent); }
.md-slider output { color: var(--md-fg); font-variant-numeric: tabular-nums; white-space: nowrap; }
.md-seg { display: inline-flex; }
.md-seg .md-btn { border-radius: 0; margin-left: -1px; }
.md-seg .md-btn:first-child { border-radius: 999px 0 0 999px; margin-left: 0; }
.md-seg .md-btn:last-child { border-radius: 0 999px 999px 0; }

.md-zoombtns { display: flex; gap: 6px; }
.md-map.md-grab { cursor: grab; }

/* Control d'interval: un sol lliscador amb dos puntets */
.md-range { display: flex; align-items: center; gap: 12px; flex: 1 1 320px; font-size: 13px; }
.md-range output { color: var(--md-fg); font-variant-numeric: tabular-nums; white-space: nowrap; min-width: 3.2em; }
.md-range .md-range-lo { text-align: right; }
.md-dual { position: relative; flex: 1; height: 24px; min-width: 120px; }
.md-dual-trk, .md-dual-fil { position: absolute; top: 50%; height: 4px; margin-top: -2px; border-radius: 2px; }
.md-dual-trk { left: 0; right: 0; background: var(--md-grid); }
.md-dual-fil { background: var(--md-accent); }
.md-dual input[type=range] { position: absolute; left: 0; top: 0; width: 100%; height: 24px; margin: 0; background: none; pointer-events: none; -webkit-appearance: none; appearance: none; }
.md-dual input[type=range]::-webkit-slider-runnable-track { background: none; height: 24px; }
.md-dual input[type=range]::-moz-range-track { background: none; }
.md-dual input[type=range]::-webkit-slider-thumb { -webkit-appearance: none; pointer-events: auto; width: 16px; height: 16px; margin-top: 4px; border-radius: 50%; background: var(--md-surface); border: 2px solid var(--md-accent); cursor: grab; }
.md-dual input[type=range]::-moz-range-thumb { pointer-events: auto; width: 12px; height: 12px; border-radius: 50%; background: var(--md-surface); border: 2px solid var(--md-accent); cursor: grab; }
.md-dual input[type=range]:focus-visible::-webkit-slider-thumb { outline: 2px solid var(--md-hl); outline-offset: 2px; }

/* Controls de zoom i avís dins del mapa */
.md-fig { position: relative; }
.md-controls.md-inmap { position: absolute; left: 10px; right: 10px; top: 10px; margin: 0; justify-content: space-between; pointer-events: none; z-index: 2; }
.md-inmap > * { pointer-events: auto; }
.md-zoomhint { font-size: 11.5px; color: var(--md-muted); background: color-mix(in srgb, var(--md-surface) 85%, transparent); padding: 3px 8px; border-radius: 999px; }
.md-controls.md-inmap { bottom: auto; height: auto; align-items: flex-start; }
