/* VanMonitor PWA — palette et composants repris de la maquette validee.
   Theme sombre assume : la page peint son propre fond, sans dependre de l'hote. */

:root {
  --bg: #08090c;
  --bg-grad: #0d1015;
  --rail: #0b0d11;
  --surface: #12151b;
  --surface-hi: #171b22;
  --border: #232830;
  --border-soft: #1a1e25;

  --text: #f1f3f6;
  --text-dim: #8992a1;
  --text-faint: #565e6a;

  --battery: #3d8bff;
  --battery-glow: rgba(61, 139, 255, .16);
  --solar: #ff9d2e;
  --solar-glow: rgba(255, 157, 46, .16);
  --water: #22d3ee;
  --water-glow: rgba(34, 211, 238, .16);
  --temp: #ff5c7a;
  --temp-glow: rgba(255, 92, 122, .16);
  --system: #a78bfa;
  --system-glow: rgba(167, 139, 250, .16);
  --good: #34d399;
  --good-glow: rgba(52, 211, 153, .14);
  --warn: #ffb84d;
  --bad: #ff5c7a;
  --grey-tank: #858b90;

  --font-display: 'Chakra Petch', ui-sans-serif, system-ui, sans-serif;
  --font-body: 'Manrope', ui-sans-serif, system-ui, sans-serif;

  --radius-card: 22px;
  --rail-w: 236px;
}

* { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  background:
    radial-gradient(1100px 620px at 14% -8%, rgba(61, 139, 255, .10), transparent 60%),
    radial-gradient(900px 560px at 100% 0%, rgba(255, 157, 46, .07), transparent 55%),
    linear-gradient(180deg, var(--bg-grad), var(--bg) 40%);
  background-attachment: fixed;
  color: var(--text);
  font-family: var(--font-body);
  font-variant-numeric: tabular-nums;
  -webkit-font-smoothing: antialiased;
  overflow-wrap: break-word;
}

h1, h2, h3 { font-family: var(--font-display); font-weight: 600; margin: 0; text-wrap: balance; }
button, input, select { font: inherit; color: inherit; }

:focus-visible { outline: 2px solid var(--battery); outline-offset: 2px; border-radius: 8px; }

/* ---------- ossature ---------- */

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

.rail {
  background: var(--rail);
  border-right: 1px solid var(--border-soft);
  padding: 24px 16px calc(16px + env(safe-area-inset-bottom));
  display: flex;
  flex-direction: column;
  gap: 28px;
}

.brand { display: flex; align-items: center; gap: 10px; padding: 0 6px; }

.brand-mark {
  width: 34px; height: 34px;
  border-radius: 10px;
  background: linear-gradient(135deg, var(--battery), #1c5fce);
  display: grid; place-items: center;
  box-shadow: 0 6px 18px -4px var(--battery-glow);
  flex-shrink: 0;
}
.brand-mark svg { width: 18px; height: 18px; }
.brand-name { font-family: var(--font-display); font-size: 17px; font-weight: 600; letter-spacing: .2px; }
.brand-name b { color: var(--battery); font-weight: 700; }

.nav { display: flex; flex-direction: column; gap: 4px; }

.nav-item {
  display: flex; align-items: center; gap: 13px;
  padding: 11px 14px;
  border: 1px solid transparent;
  border-radius: 12px;
  background: none;
  color: var(--text-dim);
  font-size: 14px; font-weight: 600;
  text-align: left;
  cursor: pointer;
}
.nav-item svg { width: 19px; height: 19px; flex-shrink: 0; opacity: .85; }
.nav-item:hover { color: var(--text); }
.nav-item[aria-current='page'] {
  background: linear-gradient(135deg, rgba(61, 139, 255, .16), rgba(61, 139, 255, .04));
  border-color: rgba(61, 139, 255, .35);
  color: var(--text);
  box-shadow: 0 8px 20px -10px var(--battery-glow);
}
.nav-item[aria-current='page'] svg { opacity: 1; color: var(--battery); }

.rail-foot {
  margin-top: auto;
  border-top: 1px solid var(--border-soft);
  padding-top: 16px;
  display: flex; flex-direction: column; gap: 4px;
}
.rail-foot .k { font-size: 11px; color: var(--text-faint); text-transform: uppercase; letter-spacing: 1.2px; }
.rail-foot .v { font-size: 13px; color: var(--text-dim); }

.main {
  padding: 28px 34px calc(40px + env(safe-area-inset-bottom));
  max-width: 1500px;
  width: 100%;
  /* Sans cela, un seul enfant insecable impose sa largeur minimale a la
     colonne de grille, et toute la page deborde a droite. */
  min-width: 0;
}

/* ---------- entete ---------- */

.topbar {
  display: flex; align-items: flex-end; justify-content: space-between;
  gap: 16px; flex-wrap: wrap;
  margin-bottom: 24px;
}
.eyebrow {
  color: var(--battery);
  font-size: 11.5px; font-weight: 700;
  letter-spacing: 2.2px; text-transform: uppercase;
  margin: 0 0 6px;
}
.topbar h1 { font-size: 30px; }
.sub { color: var(--text-dim); font-size: 13.5px; margin: 6px 0 0; }
.topbar-actions { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; justify-content: flex-end; }

.pill {
  display: inline-flex; align-items: center; gap: 8px;
  padding: 8px 14px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text-dim);
  font-size: 12.5px; font-weight: 700; letter-spacing: .3px;
  white-space: nowrap;
}
.pill[data-state='online'] { background: var(--good-glow); border-color: rgba(52, 211, 153, .35); color: #7ef0c4; }
.pill[data-state='pending'] { background: rgba(255, 184, 77, .12); border-color: rgba(255, 184, 77, .35); color: var(--warn); }
.pill[data-state='offline'] { background: rgba(255, 92, 122, .12); border-color: rgba(255, 92, 122, .35); color: var(--bad); }

.dot { width: 7px; height: 7px; border-radius: 50%; background: currentColor; flex-shrink: 0; }
.pill[data-state='online'] .dot { box-shadow: 0 0 0 4px var(--good-glow); }
.pill[data-state='pending'] .dot { animation: pulse 1.4s ease-in-out infinite; }

@keyframes pulse { 50% { opacity: .35; } }
@media (prefers-reduced-motion: reduce) { * { animation: none !important; transition: none !important; } }

/* Fraicheur des donnees : information distincte de l'etat du lien,
   volontairement discrete pour ne pas concurrencer le voyant de connexion. */
.data-age { font-size: 12px; font-weight: 700; color: var(--text-faint); white-space: nowrap; }
.data-age[data-state='fresh'] { color: var(--text-dim); }
.data-age[data-state='stale'] { color: var(--warn); }

.icon-btn {
  width: 42px; height: 42px;
  display: grid; place-items: center;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
}
.icon-btn:hover { border-color: #3a4553; }
.icon-btn svg { width: 19px; height: 19px; }
.icon-btn.spinning svg { animation: spin .9s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- bandeau de configuration ---------- */

.banner {
  display: flex; align-items: center; gap: 12px;
  padding: 16px;
  margin-bottom: 18px;
  border: 1px solid rgba(61, 139, 255, .35);
  border-radius: 16px;
  background: rgba(61, 139, 255, .10);
  color: var(--battery);
  font-size: 13.5px; font-weight: 600;
}
.banner svg { width: 22px; height: 22px; flex-shrink: 0; }
.banner button {
  margin-left: auto;
  padding: 9px 16px;
  border: 0; border-radius: 11px;
  background: linear-gradient(135deg, var(--battery), #1c5fce);
  color: #fff; font-weight: 800; font-size: 13px;
  cursor: pointer; white-space: nowrap;
}

/* ---------- grille de cartes ---------- */

.grid {
  display: grid;
  grid-template-columns: 1.35fr 1fr 1fr;
  gap: 18px;
  align-items: start;
}
.span-2 { grid-column: span 2; }
.span-3 { grid-column: span 3; }

.card {
  position: relative;
  overflow: hidden;
  padding: 22px;
  border: 1px solid var(--border);
  border-radius: var(--radius-card);
  background: linear-gradient(165deg, var(--surface-hi), var(--surface));
}
.card::before {
  content: '';
  position: absolute; inset: 0;
  border-radius: inherit;
  background: radial-gradient(420px 160px at 100% 0%, var(--glow, transparent), transparent 70%);
  pointer-events: none;
}
.card > * { position: relative; }

.card-battery { --glow: var(--battery-glow); }
.card-solar   { --glow: var(--solar-glow); }
.card-water   { --glow: var(--water-glow); }
.card-temp    { --glow: var(--temp-glow); }
.card-system  { --glow: var(--system-glow); }
.card-circuit { --glow: var(--good-glow); }

.card-head { display: flex; align-items: center; gap: 12px; margin-bottom: 18px; }
.icon-chip {
  width: 38px; height: 38px;
  border-radius: 12px;
  display: grid; place-items: center;
  background: var(--chip-bg); color: var(--chip-fg);
  flex-shrink: 0;
}
.icon-chip svg { width: 19px; height: 19px; }
.card-title { font-size: 15.5px; font-weight: 700; margin: 0; }
.card-sub { font-size: 12px; color: var(--text-dim); margin: 2px 0 0; }
.card-head .pill { margin-left: auto; }

/* batterie */
.battery-body { display: flex; align-items: center; gap: 26px; flex-wrap: wrap; }
.battery-figures { flex: 1; min-width: 140px; }
.stat-num { font-size: 44px; font-weight: 800; line-height: 1; display: flex; align-items: baseline; gap: 6px; }
.stat-num small { font-size: 16px; color: var(--text-dim); font-weight: 700; }
.flow { font-size: 12.5px; font-weight: 700; margin-top: 8px; }

.ring-wrap { position: relative; width: 118px; height: 118px; flex-shrink: 0; }
.ring-wrap svg { transform: rotate(-90deg); }
.ring-track { stroke: var(--border); }
.ring-center { position: absolute; inset: 0; display: grid; place-content: center; text-align: center; }
.ring-center .n { font-size: 26px; font-weight: 800; }
.ring-center .u { font-size: 9.5px; color: var(--text-dim); letter-spacing: 1px; text-transform: uppercase; }

.readouts { display: flex; flex-wrap: wrap; gap: 22px; margin-top: 20px; }
.readout .l { font-size: 10.5px; color: var(--text-faint); text-transform: uppercase; letter-spacing: 1.1px; margin-bottom: 4px; }
.readout .v { font-size: 19px; font-weight: 800; }
.readout .v span { font-size: 11px; color: var(--text-dim); font-weight: 700; }
.readout .note { font-size: 10px; color: var(--text-faint); margin-top: 2px; }

/* solaire */
.solar-watts { font-size: 38px; font-weight: 800; color: var(--solar); display: flex; align-items: baseline; gap: 6px; }
.solar-watts small { font-size: 15px; color: var(--text-dim); font-weight: 700; }

/* reservoirs */
.tanks { display: flex; gap: 18px; justify-content: space-evenly; flex-wrap: wrap; }
.tank { display: flex; flex-direction: column; align-items: center; gap: 9px; }
.tank-tube {
  width: 34px; height: 88px;
  border-radius: 17px;
  background: var(--bg);
  border: 1px solid var(--border);
  position: relative; overflow: hidden;
}
.tank-fill { position: absolute; left: 0; right: 0; bottom: 0; transition: height .4s ease; }
.tank .pct { font-size: 13px; font-weight: 800; }
.tank .name { font-size: 11px; color: var(--text-dim); text-align: center; }

/* temperatures */
.temp-rows { display: flex; flex-direction: column; }
.temp-row { display: flex; align-items: center; gap: 12px; padding: 7px 0; }
.temp-row .l { flex: 1; font-size: 13px; color: var(--text-dim); min-width: 0; }
.temp-bar { flex: 1.4; height: 6px; border-radius: 4px; background: var(--bg); overflow: hidden; }
.temp-bar i { display: block; height: 100%; border-radius: 4px; background: linear-gradient(90deg, var(--warn), var(--temp)); transition: width .4s ease; }
.temp-row .v { font-size: 15px; font-weight: 800; white-space: nowrap; }
.temp-row .v span { font-size: 11px; color: var(--text-dim); font-weight: 700; }

/* systeme */
.sys-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; }
.sys-tile { background: var(--bg); border: 1px solid var(--border-soft); border-radius: 14px; padding: 12px 14px; }
.sys-tile .l { font-size: 10px; color: var(--text-faint); text-transform: uppercase; letter-spacing: 1px; margin-bottom: 4px; }
.sys-tile .v { font-size: 15px; font-weight: 800; }

/* lignes cle/valeur */
.kv-list { display: flex; flex-direction: column; }
.kv-row {
  display: flex; align-items: center; justify-content: space-between; gap: 16px;
  padding: 12px 2px;
  border-bottom: 1px solid var(--border-soft);
  font-size: 13.5px;
}
.kv-row:last-child { border-bottom: none; }
.kv-row .name { color: var(--text-dim); min-width: 0; }
.kv-row .val { font-weight: 800; text-align: right; }

.empty { font-size: 12.5px; color: var(--text-dim); }

/* ---------- reglages ---------- */

.form-card { max-width: 760px; }
.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 16px; }
.field label { font-size: 10.5px; color: var(--text-faint); text-transform: uppercase; letter-spacing: 1.1px; }
.field input, .field select {
  padding: 12px 14px;
  min-height: 46px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--bg);
  color: var(--text);
  font-weight: 600;
}
.field input:focus, .field select:focus { border-color: var(--battery); outline: none; }
.field .hint { font-size: 11.5px; color: var(--text-faint); }

.row2 { display: grid; grid-template-columns: 3fr 1fr; gap: 12px; }
.row3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; }

.switch-row {
  display: flex; align-items: center; justify-content: space-between; gap: 16px;
  padding: 14px 0;
  border-bottom: 1px solid var(--border-soft);
}
.switch-row:last-of-type { border-bottom: none; }
.switch-row h3 { font-family: var(--font-body); font-size: 14px; font-weight: 800; }
.switch-row p { margin: 3px 0 0; font-size: 12px; color: var(--text-dim); }

.switch { position: relative; width: 48px; height: 28px; flex-shrink: 0; }
.switch input { position: absolute; opacity: 0; width: 100%; height: 100%; margin: 0; cursor: pointer; }
.switch span {
  position: absolute; inset: 0;
  background: var(--border); border-radius: 999px;
  transition: background .2s ease;
  pointer-events: none;
}
.switch span::after {
  content: ''; position: absolute;
  top: 3px; left: 3px; width: 22px; height: 22px;
  background: var(--text); border-radius: 50%;
  transition: transform .2s ease;
}
.switch input:checked + span { background: #1c5fce; }
.switch input:checked + span::after { transform: translateX(20px); background: var(--battery); }
.switch input:focus-visible + span { outline: 2px solid var(--battery); outline-offset: 2px; }

.btn {
  padding: 13px 20px;
  border: 0; border-radius: 12px;
  background: linear-gradient(135deg, var(--battery), #1c5fce);
  color: #fff; font-weight: 800; font-size: 14px;
  cursor: pointer;
  min-height: 46px;
}
.btn:disabled { opacity: .5; cursor: default; }
.btn-ghost { background: none; border: 1px solid var(--border); color: var(--text); font-weight: 700; }

.form-actions { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; margin-top: 4px; }
.form-feedback { font-size: 12.5px; font-weight: 700; }
.form-feedback[data-kind='ok'] { color: var(--good); }
.form-feedback[data-kind='error'] { color: var(--bad); }

.topic-preview {
  display: flex; align-items: center; gap: 10px;
  padding: 13px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--bg);
  font-size: 12px;
  color: #7cc4ff;
  word-break: break-all;
}

/* ---------- diagnostic ---------- */

.log {
  max-height: 340px; overflow-y: auto;
  display: flex; flex-direction: column; gap: 2px;
  font-size: 12px;
}
.log-row { display: grid; grid-template-columns: 72px 1fr; gap: 12px; padding: 5px 0; }
.log-row time { font-weight: 700; color: var(--battery); }
.log-row span { color: var(--text-dim); }

pre.raw {
  max-height: 340px; overflow: auto;
  margin: 0; padding: 14px;
  border: 1px solid var(--border); border-radius: 13px;
  background: var(--bg);
  font-size: 11.5px; line-height: 1.5;
  color: var(--text-dim);
  white-space: pre-wrap; word-break: break-word;
}

/* ---------- barre de navigation mobile ---------- */

.tabbar {
  display: none;
  position: sticky; bottom: 0;
  grid-template-columns: repeat(4, 1fr);
  gap: 6px;
  padding: 8px 8px calc(8px + env(safe-area-inset-bottom));
  background: var(--rail);
  border-top: 1px solid var(--border-soft);
}
.tabbar .nav-item { flex-direction: column; gap: 4px; padding: 8px 4px; font-size: 11px; text-align: center; }
.tabbar .nav-item svg { width: 21px; height: 21px; }

/* ---------- adaptatif ---------- */

@media (max-width: 1180px) {
  .grid { grid-template-columns: 1fr 1fr; }
  .span-2, .span-3 { grid-column: span 2; }
}

@media (max-width: 860px) {
  .shell { grid-template-columns: 1fr; }
  .rail { display: none; }
  .tabbar { display: grid; }
  .main { padding: 20px 16px 24px; }
  .grid { grid-template-columns: 1fr; }
  .span-2, .span-3 { grid-column: span 1; }
  .row2, .row3 { grid-template-columns: 1fr; }
  .topbar h1 { font-size: 26px; }

  /* En portrait, la mention de fraicheur peut se replier sur sa propre ligne
     plutot que de pousser la pastille et le bouton hors de l'ecran. */
  .data-age { white-space: normal; }
  .battery-body { gap: 18px; }
  .readouts { gap: 18px; }
}

[hidden] { display: none !important; }
