:root {
  color-scheme: light;
  --page: #f9f9f7;
  --surface: #fcfcfb;
  --text-primary: #0b0b0b;
  --text-secondary: #52514e;
  --text-muted: #898781;
  --grid: #e1e0d9;
  --axis: #c3c2b7;
  --border: rgba(11, 11, 11, 0.1);
  --accent: #2a78d6;
  --accent-wash: rgba(42, 120, 214, 0.1);
  --accent-band: rgba(42, 120, 214, 0.18);
  --critical: #d03b3b;
  --good: #0ca30c;
  --shadow: 0 1px 2px rgba(11, 11, 11, 0.04);
  /* Rosa dos ventos: rampa sequencial azul (claro → escuro = mais rápido) */
  --ws-0: #86b6ef;
  --ws-1: #5598e7;
  --ws-2: #2a78d6;
  --ws-3: #1c5cab;
  --ws-4: #104281;
  --radius: 12px;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --page: #0d0d0d;
    --surface: #1a1a19;
    --text-primary: #ffffff;
    --text-secondary: #c3c2b7;
    --text-muted: #898781;
    --grid: #2c2c2a;
    --axis: #383835;
    --border: rgba(255, 255, 255, 0.1);
    --accent: #3987e5;
    --accent-wash: rgba(57, 135, 229, 0.12);
    --accent-band: rgba(57, 135, 229, 0.22);
    --shadow: none;
    --ws-0: #184f95;
    --ws-1: #256abf;
    --ws-2: #3987e5;
    --ws-3: #6da7ec;
    --ws-4: #9ec5f4;
  }
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --page: #0d0d0d;
  --surface: #1a1a19;
  --text-primary: #ffffff;
  --text-secondary: #c3c2b7;
  --text-muted: #898781;
  --grid: #2c2c2a;
  --axis: #383835;
  --border: rgba(255, 255, 255, 0.1);
  --accent: #3987e5;
  --accent-wash: rgba(57, 135, 229, 0.12);
  --accent-band: rgba(57, 135, 229, 0.22);
  --shadow: none;
  --ws-0: #184f95;
  --ws-1: #256abf;
  --ws-2: #3987e5;
  --ws-3: #6da7ec;
  --ws-4: #9ec5f4;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

body {
  margin: 0;
  background: var(--page);
  color: var(--text-primary);
  font: 14px/1.45 var(--font);
  -webkit-font-smoothing: antialiased;
}

.wrap {
  width: 100%;
  max-width: 1100px;
  margin: 0 auto;
  padding-inline: 20px;
}

.muted { color: var(--text-muted); }

/* ---- Top bar ------------------------------------------------------------ */
.topbar {
  --header-bg: #262262;
  position: sticky;
  top: 0;
  z-index: 10;
  color-scheme: dark; /* controles nativos (lista do select) no tema escuro sobre o fundo do header */
  background: var(--header-bg);
  color: #ffffff;
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
}
.topbar .subtitle { color: rgba(255, 255, 255, 0.72); }
.topbar .field-label { color: rgba(255, 255, 255, 0.62); }
.topbar select,
.topbar .btn {
  background: rgba(255, 255, 255, 0.08);
  border-color: rgba(255, 255, 255, 0.22);
  color: #ffffff;
}
.topbar select option { background: var(--header-bg); color: #ffffff; }
.topbar .btn:hover:not(:disabled),
.topbar select:hover:not(:disabled) {
  background: rgba(255, 255, 255, 0.14);
  border-color: rgba(255, 255, 255, 0.4);
}
.topbar select:focus-visible,
.topbar .btn:focus-visible { outline: 2px solid #ffffff; outline-offset: 2px; }

.topbar-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
  padding-block: 12px;
}

.brand { display: flex; align-items: center; gap: 12px; }
.brand-mark {
  width: 28px; height: 28px; border-radius: 8px;
  background: linear-gradient(135deg, #5598e7, #2a78d6);
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.18);
}
.brand h1 { margin: 0; font-size: 16px; font-weight: 650; letter-spacing: -0.01em; }
.subtitle { margin: 0; font-size: 12px; color: var(--text-secondary); }

.controls { display: flex; align-items: flex-end; gap: 8px; flex-wrap: wrap; }
.field { display: flex; flex-direction: column; gap: 2px; }
.field-label { font-size: 11px; color: var(--text-muted); }

select, .btn {
  height: 34px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  color: var(--text-primary);
  font: inherit;
  padding: 0 10px;
}
select { min-width: 220px; max-width: 100%; cursor: pointer; }
.btn { display: inline-flex; align-items: center; gap: 6px; cursor: pointer; }
.btn:hover:not(:disabled), select:hover:not(:disabled) { border-color: var(--axis); }
.btn:disabled, select:disabled { opacity: 0.6; cursor: default; }
.btn.is-loading svg { animation: spin 0.9s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* Botão de tema: mostra só o ícone do modo ativo */
.btn-icon svg { display: none; }
.btn-icon[data-theme="system"] .icon-auto,
.btn-icon[data-theme="light"] .icon-sun,
.btn-icon[data-theme="dark"] .icon-moon { display: block; }

/* ---- Disclaimer --------------------------------------------------------- */
.disclaimer {
  display: flex;
  gap: 10px;
  align-items: flex-start;
  margin-top: 20px;
  padding: 12px 16px;
  border: 1px solid var(--border);
  border-left: 3px solid var(--accent);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text-secondary);
}
.disclaimer svg { flex: none; margin-top: 2px; color: var(--accent); }
.disclaimer p { margin: 0; font-size: 13px; line-height: 1.55; text-wrap: pretty; }
.disclaimer strong { color: var(--text-primary); font-weight: 600; }

/* ---- Station info ------------------------------------------------------- */
.station-info {
  margin-top: 16px;
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 1px;
  background: var(--border);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}
.info-item { background: var(--surface); padding: 12px 16px; min-width: 0; }
.info-label { font-size: 11px; color: var(--text-muted); }
.info-value {
  font-size: 15px; font-weight: 600; margin-top: 2px;
  overflow-wrap: anywhere;
}
.badge { display: inline-flex; align-items: center; gap: 6px; }
.badge-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--text-muted); }

/* ---- Condições atuais --------------------------------------------------- */
.current {
  margin-top: 16px;
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 16px;
}
.current.has-rose { grid-template-columns: minmax(0, 1fr) minmax(0, 360px); }

.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 16px;
  min-width: 0;
}
.panel-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 8px 16px;
  flex-wrap: wrap;
  margin-bottom: 12px;
}

.tiles {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(170px, 1fr));
  gap: 10px;
}
.tile {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 12px 14px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--page);
  color: inherit;
  text-decoration: none;
  min-width: 0;
  transition: border-color 0.15s;
}
.tile:hover { border-color: var(--axis); }
.tile:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.tile-label { font-size: 12px; color: var(--text-secondary); }
.tile-value { display: flex; align-items: baseline; gap: 4px; margin-top: 2px; }
.tile-number { font-size: 28px; font-weight: 600; line-height: 1.1; letter-spacing: -0.01em; }
.tile-unit { font-size: 13px; color: var(--text-muted); }
.tile-sub { font-size: 11px; color: var(--text-muted); margin-top: auto; padding-top: 4px; }

/* Rosa dos ventos */
.rose-card { display: flex; flex-direction: column; }
.rose-card .stat-value.is-hero { font-size: 18px; }
.rose-box { position: relative; width: 100%; max-width: 320px; margin: 0 auto; }
.rose-svg { display: block; width: 100%; height: auto; overflow: visible; }
.rose-grid circle { fill: none; stroke: var(--grid); stroke-width: 1; }
.rose-grid line { stroke: var(--grid); stroke-width: 1; }
.rose-seg { stroke: var(--surface); stroke-width: 1.5; stroke-linejoin: round; transition: opacity 0.12s; }
.rose-hit { fill: transparent; cursor: default; }
.rose-sectors.is-hovering .rose-sector:not(.is-active) .rose-seg { opacity: 0.35; }
.rose-cardinal { font-size: 11px; fill: var(--text-muted); }
.rose-cardinal.is-main { font-size: 12px; font-weight: 600; fill: var(--text-secondary); }
.rose-ring-label {
  font-size: 9px; fill: var(--text-muted);
  paint-order: stroke; stroke: var(--surface); stroke-width: 3px; stroke-linejoin: round;
  pointer-events: none;
}
.rose-labels { pointer-events: none; }
.rose-current { fill: var(--text-primary); pointer-events: none; }

.ws-0 { fill: var(--ws-0); background: var(--ws-0); }
.ws-1 { fill: var(--ws-1); background: var(--ws-1); }
.ws-2 { fill: var(--ws-2); background: var(--ws-2); }
.ws-3 { fill: var(--ws-3); background: var(--ws-3); }
.ws-4 { fill: var(--ws-4); background: var(--ws-4); }

.rose-legend { justify-content: center; margin-top: 10px; gap: 6px 12px; }
.key-swatch { width: 10px; height: 10px; border-radius: 3px; flex: none; }
.key-marker {
  width: 0; height: 0; flex: none;
  border-left: 5px solid transparent; border-right: 5px solid transparent;
  border-top: 8px solid var(--text-primary);
}

.rose-tip {
  position: absolute; top: 0; left: 0;
  pointer-events: none;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 10px;
  font-size: 12px;
  color: var(--text-secondary);
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.12);
  white-space: nowrap;
  z-index: 2;
}
.tip-title { color: var(--text-primary); font-weight: 600; margin-bottom: 4px; }
.tip-line { display: flex; align-items: center; gap: 6px; }

@media (max-width: 860px) {
  .current.has-rose { grid-template-columns: minmax(0, 1fr); }
}

/* ---- Parameter nav ------------------------------------------------------ */
.param-nav {
  display: flex; flex-wrap: wrap; gap: 6px;
  margin-top: 16px;
}
.param-nav a {
  font-size: 12px;
  padding: 4px 10px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text-secondary);
  text-decoration: none;
}
.param-nav a:hover { color: var(--text-primary); border-color: var(--axis); }
.param-nav a.is-empty { color: var(--text-muted); border-style: dashed; }

/* ---- Status ------------------------------------------------------------- */
.status:empty { display: none; }
.status {
  margin-top: 20px;
  padding: 16px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text-secondary);
}
.status.is-error { border-color: color-mix(in srgb, var(--critical) 45%, transparent); }
.status strong { color: var(--text-primary); }
.status code {
  font-size: 12px; padding: 1px 5px; border-radius: 4px;
  background: var(--page); border: 1px solid var(--border);
}

/* ---- Charts (empilhados) ------------------------------------------------ */
.charts {
  display: flex;
  flex-direction: column;
  gap: 16px;
  margin-top: 16px;
}

.chart-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 16px 16px 8px;
  scroll-margin-top: 90px;
}

.chart-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 12px 24px;
  flex-wrap: wrap;
  margin-bottom: 8px;
}
.chart-title { margin: 0; font-size: 15px; font-weight: 600; }
.chart-unit { color: var(--text-muted); font-weight: 400; margin-left: 4px; }
.chart-sub { margin: 2px 0 0; font-size: 12px; color: var(--text-secondary); }

.stats { display: flex; gap: 20px; flex-wrap: wrap; }
.stat { min-width: 56px; }
.stat-label { font-size: 11px; color: var(--text-muted); }
.stat-value { font-size: 15px; font-weight: 600; white-space: nowrap; }
.stat-value.is-hero { font-size: 22px; line-height: 1.15; }

.legend { display: flex; gap: 14px; flex-wrap: wrap; margin: 2px 0 6px; font-size: 12px; color: var(--text-secondary); }
.legend-item { display: inline-flex; align-items: center; gap: 6px; }
.key-line { width: 14px; height: 2px; border-radius: 2px; background: var(--accent); }
.key-band { width: 14px; height: 10px; border-radius: 3px; background: var(--accent-band); }

.chart-box { position: relative; height: 220px; }
.chart-empty {
  display: grid; place-items: center;
  height: 72px;
  color: var(--text-muted);
  font-size: 13px;
  border-top: 1px solid var(--grid);
}

.footer {
  display: flex; justify-content: space-between; gap: 12px; flex-wrap: wrap;
  padding-block: 24px 40px;
  font-size: 12px; color: var(--text-secondary);
}

@media (max-width: 560px) {
  .wrap { padding-inline: 16px; }
  .controls, .field, select { width: 100%; }
  select { min-width: 0; }
  .btn { width: 100%; justify-content: center; }
  .chart-box { height: 190px; }
  .stats { gap: 14px; }
  .tiles { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
  .tile { padding: 10px 12px; }
  .tile-number { font-size: 22px; }
}
