/* ============================================================
   Direction A — « COCKPIT »
   Supervision instrumentée. Dense, mono, flux d'énergie.
   Thème sombre par défaut + clair via [data-theme="light"].
   ============================================================ */

@import url('https://fonts.googleapis.com/css2?family=Space+Grotesk:wght@400;500;600;700&family=JetBrains+Mono:wght@400;500;600;700&display=swap');

:root {
  --font: "Space Grotesk", system-ui, sans-serif;
  --mono: "JetBrains Mono", ui-monospace, monospace;

  /* dark (defaut) */
  --bg: #0c0f14;
  --bg-grad: radial-gradient(120% 80% at 80% -10%, #141a24 0%, #0c0f14 55%);
  --surface: #141922;
  --surface-2: #1a212c;
  --surface-3: #212a37;
  --line: #28323f;
  --line-soft: #1d242f;
  --text: #eef3f8;
  --text-2: #aeb9c6;
  --muted: #6c7787;

  --solar: #f6b73c;
  --conso: #ff7a5c;
  --grid:  #5b9bff;
  --surplus: #2fd6ad;
  --ok: #43d17f;
  --warn: #f6b73c;
  --danger: #ff5a6e;

  --solar-soft: rgba(246,183,60,.14);
  --conso-soft: rgba(255,122,92,.14);
  --grid-soft: rgba(91,155,255,.14);
  --surplus-soft: rgba(47,214,173,.14);
  --danger-soft: rgba(255,90,110,.14);

  --radius: 14px;
  --radius-sm: 10px;
  --radius-lg: 20px;
  --shadow: 0 18px 40px rgba(0,0,0,.35);
  --rail-w: 230px;
}

[data-theme="light"] {
  --bg: #eef1f5;
  --bg-grad: radial-gradient(120% 80% at 80% -10%, #ffffff 0%, #e9edf2 55%);
  --surface: #ffffff;
  --surface-2: #f4f6f9;
  --surface-3: #eaeef3;
  --line: #dde3ea;
  --line-soft: #e7ebf0;
  --text: #131820;
  --text-2: #475266;
  --muted: #8893a3;

  --solar: #c98a0a;
  --conso: #d9532e;
  --grid: #2f6fe0;
  --surplus: #0e9e7c;
  --ok: #1c9c54;
  --danger: #d6354b;

  --solar-soft: rgba(201,138,10,.12);
  --conso-soft: rgba(217,83,46,.12);
  --grid-soft: rgba(47,111,224,.12);
  --surplus-soft: rgba(14,158,124,.12);
  --danger-soft: rgba(214,53,75,.12);
  --shadow: 0 16px 34px rgba(40,55,80,.12);
}

* { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  font-family: var(--font);
  background: var(--bg-grad), var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
  letter-spacing: -.01em;
}

button { font: inherit; color: inherit; cursor: pointer; }

.date-nav-mobile {
  font: inherit; font-family: var(--mono); font-size: 13px;
  color: var(--text); background: var(--surface-2);
  border: 1px solid var(--line); border-radius: var(--radius-sm);
  padding: 7px 10px; cursor: pointer;
  color-scheme: dark;
}

.num { font-family: var(--mono); font-feature-settings: "tnum" 1; letter-spacing: -.02em; }

/* ---------- shell ---------- */
.app {
  display: grid;
  grid-template-columns: var(--rail-w) 1fr;
  min-height: 100dvh;
}

.rail {
  position: sticky; top: 0;
  height: 100dvh;
  border-right: 1px solid var(--line-soft);
  background: color-mix(in srgb, var(--surface) 70%, transparent);
  backdrop-filter: blur(14px);
  padding: 20px 14px;
  display: flex; flex-direction: column; gap: 6px;
}

.brand { display: flex; align-items: center; gap: 11px; padding: 6px 8px 18px; }
.brand-mark {
  width: 38px; height: 38px; border-radius: 11px; flex: 0 0 auto;
  display: grid; place-items: center; color: #0c0f14; font-weight: 700;
  background: linear-gradient(135deg, var(--solar), var(--surplus));
  font-family: var(--mono); font-size: 15px;
}
.brand b { display: block; font-size: 14px; font-weight: 600; letter-spacing: -.02em; }
.brand span { display: block; font-size: 11px; color: var(--muted); margin-top: 2px; }

.nav { display: flex; flex-direction: column; gap: 2px; margin-top: 4px; }
.nav a {
  display: flex; align-items: center; gap: 11px;
  padding: 10px 11px; border-radius: 11px;
  color: var(--text-2); text-decoration: none; font-size: 13.5px; font-weight: 500;
  border: 1px solid transparent;
}
.nav a svg { width: 18px; height: 18px; opacity: .85; flex: 0 0 auto; }
.nav a:hover { background: var(--surface-2); color: var(--text); }
.nav a.active {
  background: var(--surface-2); color: var(--text);
  border-color: var(--line);
}
.nav a.active svg { color: var(--solar); opacity: 1; }
.nav .nav-badge {
  margin-left: auto; font-family: var(--mono); font-size: 10px; font-weight: 600;
  background: var(--danger-soft); color: var(--danger);
  padding: 2px 6px; border-radius: 999px;
}

.rail-foot { margin-top: auto; }
.health {
  border: 1px solid var(--line); border-radius: 12px; background: var(--surface-2);
  padding: 12px;
}
.health-row { display: flex; align-items: center; gap: 8px; font-size: 12px; }
.health-row + .health-row { margin-top: 7px; }
.health-row b { font-weight: 600; }
.health-row span { color: var(--muted); margin-left: auto; font-family: var(--mono); }

/* ---------- main ---------- */
.main { min-width: 0; display: flex; flex-direction: column; }

.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: 14px;
  padding: 16px 24px;
  background: color-mix(in srgb, var(--bg) 78%, transparent);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--line-soft);
}
.topbar h1 { margin: 0; font-size: 19px; font-weight: 600; letter-spacing: -.02em; }
.topbar .sub { font-size: 12px; color: var(--muted); margin-top: 1px; }
.topbar .spacer { flex: 1; }

.conn {
  display: inline-flex; align-items: center; gap: 8px;
  font-size: 12px; font-weight: 600; color: var(--ok);
  background: color-mix(in srgb, var(--ok) 12%, transparent);
  border: 1px solid color-mix(in srgb, var(--ok) 28%, transparent);
  padding: 6px 11px; border-radius: 999px; white-space: nowrap;
}
.clock { font-family: var(--mono); font-size: 13px; color: var(--text-2); }

.icon-btn {
  width: 38px; height: 38px; border-radius: 11px;
  border: 1px solid var(--line); background: var(--surface-2);
  display: grid; place-items: center;
}
.icon-btn:hover { background: var(--surface-3); }
.icon-btn svg { width: 18px; height: 18px; }

.view { padding: 22px 24px 40px; display: none; }
.view.active { display: block; }

/* ---------- live dot ---------- */
.dot { width: 8px; height: 8px; border-radius: 50%; background: currentColor; flex: 0 0 auto; }
.dot.live { position: relative; }
.dot.live::after {
  content: ""; position: absolute; inset: -4px; border-radius: 50%;
  border: 1px solid currentColor; opacity: .6;
  animation: ping 2s ease-out infinite;
}
@keyframes ping { 0% { transform: scale(.6); opacity: .7 } 100% { transform: scale(1.8); opacity: 0 } }

.flash { animation: flash .6s ease; }
@keyframes flash { 0% { color: var(--solar) } 100% { color: inherit } }

/* ---------- cards ---------- */
.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
}
.card.soft { background: var(--surface-2); }
.pad { padding: 18px; }
.card-h { display: flex; align-items: center; gap: 12px; margin-bottom: 14px; }
.card-h h2 { margin: 0; font-size: 14px; font-weight: 600; }
.card-h .hint { font-size: 11.5px; color: var(--muted); }
.card-h .spacer { flex: 1; }
.kicker { font-family: var(--mono); font-size: 10.5px; letter-spacing: .12em; text-transform: uppercase; color: var(--muted); }

.grid { display: grid; gap: 16px; }
.cols-2 { grid-template-columns: 1fr 1fr; }
.cols-3 { grid-template-columns: repeat(3, 1fr); }
.cols-4 { grid-template-columns: repeat(4, 1fr); }
.live-layout { grid-template-columns: minmax(0, 1.5fr) minmax(320px, .9fr); align-items: start; }

/* ---------- KPI tile ---------- */
.kpi { padding: 16px; border-radius: var(--radius); border: 1px solid var(--line); background: var(--surface); position: relative; overflow: hidden; }
.kpi .label { display: flex; align-items: center; gap: 7px; font-size: 11.5px; color: var(--muted); font-weight: 500; }
.kpi .swatch { width: 9px; height: 9px; border-radius: 3px; }
.kpi .val { font-size: 30px; font-weight: 600; margin-top: 10px; line-height: 1; }
.kpi .val .unit { font-size: 14px; color: var(--muted); font-weight: 500; margin-left: 3px; }
.kpi .meta { font-size: 11.5px; color: var(--muted); margin-top: 8px; display: flex; align-items: center; gap: 6px; }
.kpi .spark { margin-top: 12px; opacity: .9; }
.kpi.accent-solar { box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--solar) 26%, transparent); }

/* ---------- flux d'énergie ---------- */
.flux {
  padding: 20px;
  background:
    radial-gradient(90% 120% at 50% -20%, var(--solar-soft), transparent 60%),
    var(--surface);
  border: 1px solid var(--line); border-radius: var(--radius);
}
.flux-stage { position: relative; height: 300px; }
.flux-node {
  position: absolute; width: 128px; padding: 12px; border-radius: 13px;
  background: var(--surface-2); border: 1px solid var(--line); text-align: center;
}
.flux-node .nlabel { font-size: 10.5px; color: var(--muted); text-transform: uppercase; letter-spacing: .08em; font-family: var(--mono); }
.flux-node .nval { font-size: 21px; font-weight: 600; margin-top: 5px; }
.flux-node .nval .unit { font-size: 11px; color: var(--muted); }
.flux-node.solar { top: 0; left: 0; border-color: color-mix(in srgb, var(--solar) 40%, var(--line)); }
.flux-node.grid { bottom: 0; left: 0; border-color: color-mix(in srgb, var(--grid) 40%, var(--line)); }
.flux-node.house { top: 50%; right: 0; transform: translateY(-50%); width: 150px; border-color: color-mix(in srgb, var(--conso) 40%, var(--line)); }
.flux-node .ico { width: 16px; height: 16px; }
.flux-svg { position: absolute; inset: 0; width: 100%; height: 100%; overflow: visible; pointer-events: none; }
.flow-path { fill: none; stroke-width: 3; stroke-linecap: round; opacity: .55; }
.flow-dash { fill: none; stroke-width: 3; stroke-linecap: round; stroke-dasharray: 2 14; animation: flow 1.1s linear infinite; }
@keyframes flow { to { stroke-dashoffset: -16; } }

/* ---------- regulateur / actions ---------- */
.ctrl { display: flex; align-items: center; gap: 14px; padding: 14px; border: 1px solid var(--line); border-radius: var(--radius-sm); background: var(--surface-2); }
.ctrl .body { min-width: 0; }
.ctrl b { font-size: 13.5px; font-weight: 600; display: block; }
.ctrl span { font-size: 11.5px; color: var(--muted); display: block; margin-top: 2px; }
.ctrl .spacer { flex: 1; }
.gauge-ring { --p: 62; width: 52px; height: 52px; border-radius: 50%; flex: 0 0 auto;
  background: conic-gradient(var(--solar) calc(var(--p) * 1%), var(--surface-3) 0);
  display: grid; place-items: center; }
.gauge-ring .inner { width: 40px; height: 40px; border-radius: 50%; background: var(--surface); display: grid; place-items: center; font-family: var(--mono); font-size: 12px; font-weight: 600; }

.toggle { width: 48px; height: 28px; border-radius: 999px; background: var(--surface-3); border: 1px solid var(--line); padding: 3px; flex: 0 0 auto; transition: background .2s; }
.toggle .knob { width: 20px; height: 20px; border-radius: 50%; background: var(--text-2); transition: transform .2s, background .2s; }
.toggle.on { background: color-mix(in srgb, var(--ok) 80%, transparent); }
.toggle.on .knob { transform: translateX(20px); background: #fff; }

/* ---------- segmented ---------- */
.seg { display: inline-flex; padding: 3px; gap: 2px; border-radius: 999px; background: var(--surface-2); border: 1px solid var(--line); }
.seg button { border: 0; background: transparent; color: var(--muted); padding: 6px 12px; border-radius: 999px; font-size: 12px; font-weight: 600; }
.seg button.active { background: var(--text); color: var(--bg); }

/* ---------- listes capteurs ---------- */
.rows { display: flex; flex-direction: column; gap: 8px; }
.row {
  display: grid; grid-template-columns: 34px 1fr auto auto; gap: 12px; align-items: center;
  padding: 12px; border: 1px solid var(--line); border-radius: var(--radius-sm); background: var(--surface-2);
}
.tag { width: 34px; height: 34px; border-radius: 9px; display: grid; place-items: center; font-family: var(--mono); font-size: 10px; font-weight: 700; }
.tag.ble { background: var(--grid-soft); color: var(--grid); }
.tag.mqtt { background: var(--surplus-soft); color: var(--surplus); }
.tag.rf { background: var(--solar-soft); color: var(--solar); }
.row .main b { font-size: 13.5px; font-weight: 600; }
.row .main span { font-size: 11.5px; color: var(--muted); display: block; margin-top: 2px; }
.row .rval { font-family: var(--mono); font-weight: 600; font-size: 14px; text-align: right; }

.badge { display: inline-flex; align-items: center; gap: 6px; padding: 5px 9px; border-radius: 999px; font-size: 11px; font-weight: 600; white-space: nowrap; }
.badge.ok { background: color-mix(in srgb, var(--ok) 14%, transparent); color: var(--ok); }
.badge.warn { background: var(--solar-soft); color: var(--solar); }
.badge.bad { background: var(--danger-soft); color: var(--danger); }

/* ---------- mini stats ---------- */
.chips { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; }
.chip { padding: 13px; border-radius: var(--radius-sm); border: 1px solid var(--line); background: var(--surface-2); }
.chip b { font-size: 22px; font-weight: 600; font-family: var(--mono); }
.chip span { display: block; font-size: 11px; color: var(--muted); margin-top: 3px; }

.legend { display: flex; gap: 16px; flex-wrap: wrap; }
.legend span { display: inline-flex; align-items: center; gap: 7px; font-size: 11.5px; color: var(--text-2); }
.legend i { width: 11px; height: 11px; border-radius: 3px; }

/* ---------- agenda ---------- */
.agenda { display: flex; flex-direction: column; gap: 10px; }
.ag-item { display: grid; grid-template-columns: 52px 1fr; gap: 13px; padding: 12px; border: 1px solid var(--line); border-radius: var(--radius-sm); background: var(--surface-2); }
.ag-date { text-align: center; border-radius: 10px; background: var(--surface-3); padding: 8px 4px; }
.ag-date b { font-family: var(--mono); font-size: 18px; font-weight: 700; display: block; }
.ag-date span { font-size: 10px; color: var(--muted); text-transform: uppercase; }
.ag-item .at b { font-size: 13.5px; }
.ag-item .at span { display: block; font-size: 11.5px; color: var(--muted); margin-top: 3px; }

/* ---------- alarme ---------- */
.alarm-hero { display: grid; grid-template-columns: auto 1fr auto; gap: 18px; align-items: center; padding: 20px; }
.alarm-shield { width: 64px; height: 64px; border-radius: 18px; display: grid; place-items: center; background: var(--surface-2); border: 1px solid var(--line); }
.alarm-shield svg { width: 30px; height: 30px; color: var(--muted); }
.alarm-hero.armed { background: var(--danger-soft); }
.alarm-hero.armed .alarm-shield { border-color: color-mix(in srgb, var(--danger) 45%, transparent); }
.alarm-hero.armed .alarm-shield svg { color: var(--danger); }
.alarm-hero h2 { margin: 0; font-size: 20px; font-weight: 600; }
.alarm-hero p { margin: 4px 0 0; font-size: 12.5px; color: var(--muted); }
.alarm-modes { display: flex; gap: 8px; }
.mode-btn { padding: 9px 14px; border-radius: 11px; border: 1px solid var(--line); background: var(--surface-2); font-size: 12.5px; font-weight: 600; color: var(--text-2); }
.mode-btn.active { background: var(--text); color: var(--bg); border-color: var(--text); }

/* ---------- topbar mobile + bottom nav ---------- */
.topbar-mobile, .bottom-nav, .date-nav-mobile { display: none; }

@media (max-width: 1080px) {
  .app { grid-template-columns: 1fr; }
  .rail { display: none; }
  .live-layout, .cols-4, .cols-3, .cols-2 { grid-template-columns: 1fr; }
  .chips { grid-template-columns: repeat(2, 1fr); }
}

@media (max-width: 760px) {
  .topbar { display: none; }
  .topbar-mobile {
    display: flex; align-items: center; gap: 12px;
    position: sticky; top: 0; z-index: 30; padding: 13px 16px;
    background: color-mix(in srgb, var(--bg) 86%, transparent);
    backdrop-filter: blur(12px); border-bottom: 1px solid var(--line-soft);
  }
  .topbar-mobile h1 { margin: 0; font-size: 16px; font-weight: 600; }
  .topbar-mobile .sub { font-size: 11px; color: var(--muted); }
  .topbar-mobile .spacer { flex: 1; }
  .view { padding: 16px 14px 96px; }
  .pad { padding-left: 4px; padding-right: 4px; }

  .date-nav-desktop { display: none !important; }
  .date-nav-mobile  { display: block; }

  .alarm-hero { grid-template-columns: auto 1fr; }
  .alarm-modes { grid-column: 1 / -1; }
  .mode-btn { flex: 1; min-height: 44px; font-size: 13px; }
  .grid { gap: 10px; }
  .cols-2.keep-2, .cols-4.keep-2 { grid-template-columns: 1fr 1fr; }
  .flux-stage { height: 340px; }
  .flux-node { width: 108px; }
  .flux-node.house { width: 122px; }
  .kpi .val { font-size: 26px; }

  .bottom-nav {
    display: grid; grid-template-columns: repeat(5, 1fr);
    position: fixed; left: 10px; right: 10px; bottom: 10px; z-index: 40;
    padding: 7px; gap: 2px;
    background: color-mix(in srgb, var(--surface) 92%, transparent);
    border: 1px solid var(--line); border-radius: 18px;
    backdrop-filter: blur(16px); box-shadow: var(--shadow);
  }
  .bottom-nav a {
    display: flex; flex-direction: column; align-items: center; gap: 3px;
    padding: 7px 2px; border-radius: 12px; text-decoration: none;
    color: var(--muted); font-size: 10px; font-weight: 600;
  }
  .bottom-nav a svg { width: 21px; height: 21px; }
  .bottom-nav a.active { color: var(--text); background: var(--surface-3); }
  .bottom-nav a.active svg { color: var(--solar); }
}
