/* Neige Haut-Doubs — Styles mobile-first, mode sombre, palette daltonisme Okabe-Ito
 * Zéro requête externe (polices système uniquement). Contraste WCAG AA/AAA.
 */

:root {
  --bg: #0b1220;
  --surface: #131d31;
  --surface-2: #1b2842;
  --surface-3: #223252;
  --border: #2a3b5c;
  --border-strong: #405985;

  --text: #f1f5f9;
  --text-muted: #b8c7dc;
  --text-dim: #93a8c7;

  /* Palette Okabe-Ito adaptée fond sombre */
  --oi-sky: #56B4E9;
  --oi-orange: #E69F00;
  --oi-green: #009E73;
  --oi-vermilion: #D55E00;
  --oi-vermilion-text: #ff9c63;
  --oi-purple: #CC79A7;
  --oi-yellow: #F0E442;
  --oi-blue: #0072B2;

  --radius: 12px;
  --radius-sm: 8px;
  --max-w: 960px;
  --font-sans: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --font-mono: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
}

*, *::before, *::after {
  box-sizing: border-box;
}

html {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-sans);
  font-size: 16px;
  line-height: 1.5;
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  min-height: 100dvh;
  background: var(--bg);
  color: var(--text);
  display: flex;
  flex-direction: column;
}

[hidden] {
  display: none !important;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.skip-link {
  position: absolute;
  left: -9999px;
  top: 0;
  z-index: 100;
  padding: 0.75rem 1rem;
  background: var(--oi-yellow);
  color: #0b1220;
  font-weight: 700;
  text-decoration: none;
  border-radius: 0 0 var(--radius-sm) 0;
}
.skip-link:focus {
  left: 0;
}

:focus-visible {
  outline: 3px solid var(--oi-yellow);
  outline-offset: 2px;
}

/* Header */
.site-header {
  position: sticky;
  top: 0;
  z-index: 20;
  background: rgba(11, 18, 32, 0.94);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border);
}

.header-inner,
.nav-bar,
.alerts-region,
.main-container,
.site-footer {
  width: 100%;
  max-width: var(--max-w);
  margin: 0 auto;
  padding-inline: 0.875rem;
}

.header-inner {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.65rem;
  padding-block: 0.65rem 0.5rem;
}

.brand {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  min-width: 0;
}

.brand-icon {
  flex: 0 0 auto;
  border-radius: 8px;
}

.brand-title {
  margin: 0;
  font-size: 1.05rem;
  font-weight: 700;
  letter-spacing: -0.01em;
  line-height: 1.2;
}

.brand-sub {
  margin: 0;
  font-size: 0.75rem;
  color: var(--text-dim);
}

.header-controls {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex: 1 1 auto;
  justify-content: flex-end;
}

.point-picker {
  flex: 0 1 220px;
  min-width: 140px;
}

.select-control {
  width: 100%;
  min-height: 44px;
  padding: 0.5rem 2rem 0.5rem 0.75rem;
  background-color: var(--surface);
  color: var(--text);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  font: inherit;
  font-size: 0.94rem;
  font-weight: 600;
  cursor: pointer;
}

.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 44px;
  min-height: 44px;
  padding: 0.5rem;
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  cursor: pointer;
}
.icon-btn:hover {
  background: var(--surface-2);
}
.icon-btn.is-loading svg {
  animation: spin 0.9s linear infinite;
}
@keyframes spin {
  to { transform: rotate(360deg); }
}

.nav-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  padding-bottom: 0.5rem;
}

.tab-list {
  display: inline-flex;
  gap: 0.35rem;
  background: var(--surface);
  padding: 3px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
}

.tab-btn {
  min-height: 44px;
  padding: 0.45rem 0.95rem;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--text-muted);
  font: inherit;
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
}
.tab-btn:hover {
  color: var(--text);
}
.tab-btn.is-active {
  background: var(--surface-3);
  color: var(--text);
  box-shadow: inset 0 0 0 1px var(--oi-sky);
}

.status-pill {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.3rem 0.65rem;
  border-radius: 999px;
  font-size: 0.8rem;
  font-weight: 600;
}
.status-pill--offline {
  background: rgba(230, 159, 0, 0.16);
  color: var(--oi-orange);
  border: 1px solid var(--oi-orange);
}

/* Alerts & Banners */
.alerts-region {
  padding-top: 0.65rem;
}

.banners-stack {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.banner {
  padding: 0.75rem 0.9rem;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  border-left-width: 4px;
  background: var(--surface);
  margin-bottom: 0.5rem;
}
.banner:last-child {
  margin-bottom: 0;
}

.banner--danger {
  border-color: rgba(213, 94, 0, 0.55);
  border-left-color: var(--oi-vermilion);
  background: rgba(213, 94, 0, 0.14);
}
.banner--warn {
  border-color: rgba(230, 159, 0, 0.45);
  border-left-color: var(--oi-orange);
  background: rgba(230, 159, 0, 0.11);
}
.banner--info {
  border-color: rgba(86, 180, 233, 0.38);
  border-left-color: var(--oi-sky);
  background: rgba(86, 180, 233, 0.1);
}

.banner-head {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem;
  font-weight: 700;
  font-size: 0.92rem;
}

.banner-tag {
  display: inline-block;
  padding: 0.1rem 0.5rem;
  border-radius: 4px;
  font-size: 0.78rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  background: var(--oi-vermilion);
  color: #ffffff;
}
.banner--warn .banner-tag {
  background: var(--oi-orange);
  color: #0b1220;
}
.banner--info .banner-tag {
  background: var(--oi-sky);
  color: #0b1220;
}

.banner-body {
  margin: 0.3rem 0 0;
  font-size: 0.88rem;
  color: var(--text);
}

/* Main layout & Cards */
.main-container {
  flex: 1 0 auto;
  padding-block: 0.75rem 1.75rem;
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.95rem 1rem;
  margin-bottom: 0.85rem;
}

.state-card {
  text-align: center;
  padding: 2rem 1rem;
  color: var(--text-muted);
}

.btn-secondary {
  min-height: 44px;
  padding: 0.5rem 0.95rem;
  background: var(--surface-2);
  color: var(--text);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  font: inherit;
  font-size: 0.88rem;
  font-weight: 600;
  cursor: pointer;
}
.btn-secondary:hover {
  background: var(--surface-3);
}

/* Hero Card */
.hero-top {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-start;
  justify-content: space-between;
  gap: 0.5rem;
}

.point-title {
  margin: 0;
  font-size: 1.35rem;
  font-weight: 750;
  letter-spacing: -0.015em;
}

.point-meta {
  margin: 0.15rem 0 0;
  font-size: 0.85rem;
  color: var(--text-muted);
}

.dz-badges {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
}

.chip {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  padding: 0.2rem 0.55rem;
  border-radius: 6px;
  font-size: 0.78rem;
  font-weight: 600;
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--text-muted);
}
.chip--active {
  border-color: var(--oi-sky);
  color: var(--text);
}
.chip--warn {
  border-color: var(--oi-orange);
  color: var(--oi-orange);
}
.chip--danger {
  border-color: var(--oi-vermilion);
  color: var(--oi-vermilion-text);
}
.chip--ok {
  border-color: var(--oi-green);
  color: #4ce0b3;
}

.headline {
  margin: 0.75rem 0 0.85rem;
  font-size: 1.05rem;
  font-weight: 600;
  color: var(--text);
  line-height: 1.45;
  padding-left: 0.75rem;
  border-left: 3px solid var(--oi-sky);
}

.runs-meta {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(210px, 1fr));
  gap: 0.5rem;
  margin: 0;
  padding-top: 0.7rem;
  border-top: 1px solid var(--border);
}

.run-item {
  background: var(--surface-2);
  border-radius: var(--radius-sm);
  padding: 0.5rem 0.65rem;
}
.run-item dt {
  font-size: 0.74rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-dim);
}
.run-item dd {
  margin: 0.15rem 0 0;
  font-size: 0.84rem;
  color: var(--text);
}

/* KPI Grid */
.kpi-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.65rem;
  margin-bottom: 0.85rem;
}

.kpi-card {
  margin-bottom: 0;
  padding: 0.8rem 0.85rem;
}

.kpi-label {
  margin: 0;
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--text-muted);
}

.kpi-value {
  margin: 0.25rem 0 0.15rem;
  font-size: 1.35rem;
  font-weight: 750;
  line-height: 1.2;
}
.kpi-value--sky { color: var(--oi-sky); }
.kpi-value--orange { color: var(--oi-orange); }
.kpi-value--green { color: #36d6a8; }
.kpi-value--danger { color: var(--oi-vermilion-text); }

.kpi-sub {
  margin: 0;
  font-size: 0.78rem;
  color: var(--text-dim);
}

/* Controls & Legends */
.controls-card {
  padding-block: 0.75rem;
}

.controls-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.65rem;
}

.horizon-group {
  display: inline-flex;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 3px;
  gap: 3px;
}

.horizon-btn {
  min-width: 58px;
  min-height: 44px;
  padding: 0.4rem 0.85rem;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--text-muted);
  font: inherit;
  font-size: 0.92rem;
  font-weight: 700;
  cursor: pointer;
}
.horizon-btn:hover {
  color: var(--text);
}
.horizon-btn.is-active {
  background: var(--oi-sky);
  color: #0b1220;
}

.toggle-control {
  display: inline-flex;
  align-items: center;
  gap: 0.55rem;
  min-height: 44px;
  padding: 0.35rem 0.75rem;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 0.88rem;
  font-weight: 600;
  cursor: pointer;
  user-select: none;
}
.toggle-control input {
  width: 20px;
  height: 20px;
  accent-color: var(--oi-purple);
  cursor: pointer;
}

.legend-strip {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.45rem 0.9rem;
  margin-top: 0.65rem;
  font-size: 0.78rem;
  color: var(--text-muted);
}

.legend-caption {
  font-weight: 700;
  color: var(--text);
}

.legend-item {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
}

.swatch {
  display: inline-block;
  width: 14px;
  height: 10px;
  border-radius: 2px;
  flex: 0 0 auto;
}
.swatch--p1090 { background: rgba(86, 180, 233, 0.24); border: 1px solid rgba(86, 180, 233, 0.5); }
.swatch--p2080 { background: rgba(86, 180, 233, 0.46); }
.swatch--p50 { height: 3px; background: var(--oi-sky); }
.swatch--arome { height: 3px; background: var(--oi-orange); }
.swatch--native { height: 0; border-top: 2px dashed var(--oi-purple); }
.swatch--night { background: #09101d; border: 1px solid var(--border); }
.swatch--powder { background: var(--oi-sky); }
.swatch--heavy { background: var(--oi-purple); }
.swatch--rain { background: var(--oi-blue); }
.swatch--conf-high { background: var(--oi-green); }
.swatch--conf-med { background: var(--oi-orange); }
.swatch--conf-low { background: var(--oi-vermilion); }
.swatch--inv { background: var(--oi-yellow); width: 8px; height: 8px; border-radius: 50%; }

/* Chart & Bands */
.section-head {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-start;
  justify-content: space-between;
  gap: 0.4rem;
  margin-bottom: 0.55rem;
}

.section-title {
  margin: 0;
  font-size: 1.02rem;
  font-weight: 700;
}

.section-hint {
  margin: 0.15rem 0 0;
  font-size: 0.8rem;
  color: var(--text-dim);
}

.tz-badge {
  font-size: 0.75rem;
  font-weight: 600;
  padding: 0.2rem 0.5rem;
  border-radius: 6px;
  background: var(--surface-2);
  color: var(--text-muted);
  border: 1px solid var(--border);
}

.svg-wrap {
  width: 100%;
  border-radius: var(--radius-sm);
  background: #0e1729;
  border: 1px solid var(--border);
  overflow: hidden;
  touch-action: pan-y;
}
.svg-wrap svg {
  display: block;
  width: 100%;
  height: auto;
  user-select: none;
  -webkit-user-select: none;
}

/* Hourly Inspector */
.inspector {
  margin-top: 0.75rem;
  padding: 0.75rem 0.85rem;
  background: var(--surface-2);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
}

.inspector-head {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.4rem;
  padding-bottom: 0.5rem;
  margin-bottom: 0.6rem;
  border-bottom: 1px solid var(--border);
}

.inspector-time {
  font-weight: 700;
  font-size: 0.95rem;
  color: var(--oi-yellow);
}

.inspector-flags {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
}

.inspector-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.5rem 0.75rem;
}

.ins-cell {
  min-width: 0;
}

.ins-label {
  display: block;
  font-size: 0.74rem;
  color: var(--text-dim);
}

.ins-val {
  display: block;
  font-size: 0.88rem;
  font-weight: 600;
  color: var(--text);
}

.inspector-probs {
  margin-top: 0.6rem;
  padding-top: 0.55rem;
  border-top: 1px solid var(--border);
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem 0.65rem;
  font-size: 0.8rem;
  color: var(--text-muted);
}

.bands-legends {
  margin-bottom: 0.6rem;
}
.bands-legends .legend-strip {
  margin-top: 0.3rem;
}

/* Limits & Method */
.limits-head {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  margin-bottom: 0.55rem;
}

.clean-list {
  margin: 0.35rem 0 0;
  padding-left: 1.15rem;
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
  color: var(--text-muted);
  font-size: 0.9rem;
}
.clean-list strong {
  color: var(--text);
}

.method-card h2 {
  margin: 0 0 0.5rem;
  font-size: 1.25rem;
}
.method-card h3 {
  margin: 0 0 0.45rem;
  font-size: 1.02rem;
  color: var(--oi-sky);
}
.method-card p {
  margin: 0 0 0.55rem;
  font-size: 0.92rem;
  color: var(--text-muted);
}
.method-card code {
  font-family: var(--font-mono);
  font-size: 0.84em;
  background: var(--surface-2);
  color: var(--text);
  padding: 0.08rem 0.32rem;
  border-radius: 4px;
}

.method-callout {
  margin-top: 0.75rem;
  padding: 0.65rem 0.8rem;
  border-radius: var(--radius-sm);
  background: var(--surface-2);
  border-left: 3px solid var(--oi-sky);
  font-size: 0.86rem;
  color: var(--text);
}

.table-wrap {
  overflow-x: auto;
  margin-top: 0.4rem;
}

.params-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.85rem;
}
.params-table th,
.params-table td {
  text-align: left;
  padding: 0.5rem 0.6rem;
  border-bottom: 1px solid var(--border);
}
.params-table th {
  color: var(--text);
  background: var(--surface-2);
  font-weight: 700;
}
.params-table td {
  color: var(--text-muted);
}

/* Footer */
.site-footer {
  padding-block: 1rem 1.5rem;
  border-top: 1px solid var(--border);
  font-size: 0.8rem;
  color: var(--text-dim);
}
.site-footer p {
  margin: 0.2rem 0;
}
.footer-sub {
  color: var(--text-dim);
}

/* Breakpoints tablette & desktop */
@media (min-width: 640px) {
  .kpi-grid {
    grid-template-columns: repeat(4, minmax(0, 1fr));
  }
  .inspector-grid {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }
  .header-inner {
    flex-wrap: nowrap;
  }
}

@media (min-width: 840px) {
  .inspector-grid {
    grid-template-columns: repeat(4, minmax(0, 1fr));
  }
}

@media (prefers-reduced-motion: reduce) {
  .icon-btn.is-loading svg {
    animation: none;
  }
}
