/* ============ Tokens ============ */
:root {
  --bg-outside: #dfe5e2;
  --bg: #f2f5f3;
  --surface: #ffffff;
  --surface-2: #e9efec;
  --text: #13201b;
  --text-2: #5b6b64;
  --text-3: #93a19b;
  --line: #dde5e1;
  --brand: #1f9d6b;
  --brand-2: #45c08c;
  --brand-soft: #d9f2e6;
  --brand-ink: #0b3d29;
  --warn: #e8a317;
  --warn-soft: #fdf1d6;
  --danger: #d6453d;
  --danger-soft: #fbe3e1;
  --info: #2f7fd8;
  --meter-bg: #0f1714;
  --meter-digit: #f3f7f5;
  --meter-red: #e5483f;
  --radius: 18px;
  --radius-sm: 12px;
  --shadow: 0 1px 2px rgba(16, 32, 26, .05), 0 6px 20px rgba(16, 32, 26, .06);
  --font: "Manrope", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --mono: "JetBrains Mono", ui-monospace, "Cascadia Mono", Consolas, monospace;
  --nav-h: 68px;
  color-scheme: light;
}

:root[data-theme="dark"] {
  --bg-outside: #050807;
  --bg: #0d1311;
  --surface: #151d1a;
  --surface-2: #1d2724;
  --text: #e8efec;
  --text-2: #a3b2ac;
  --text-3: #6d7c76;
  --line: #24302c;
  --brand: #3bc387;
  --brand-2: #5ad8a0;
  --brand-soft: #173326;
  --brand-ink: #c8f3df;
  --warn-soft: #3a2e12;
  --danger-soft: #3a1a18;
  --meter-bg: #000;
  --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 6px 20px rgba(0, 0, 0, .25);
  color-scheme: dark;
}

/* ============ Base ============ */
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg-outside);
  font-family: var(--font);
  color: var(--text);
  font-size: 15px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
}
button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; border: 0; background: none; padding: 0; }
a { color: var(--brand); text-decoration: none; }
svg { width: 20px; height: 20px; flex: none; }
h1, h2, h3, p { margin: 0; }
.num { font-family: var(--mono); font-variant-numeric: tabular-nums; letter-spacing: -.02em; }

/* Phone shell: max 567px wide, centred on desktop */
.phone {
  position: relative;
  max-width: 567px;
  min-height: 100vh;
  min-height: 100dvh;
  margin: 0 auto;
  background: var(--bg);
  overflow-x: hidden;
}
@media (min-width: 600px) {
  .phone { box-shadow: 0 0 0 1px var(--line), 0 20px 60px rgba(0,0,0,.12); }
}
.app { min-height: 100vh; min-height: 100dvh; display: flex; flex-direction: column; }
.page { flex: 1; display: flex; flex-direction: column; animation: pageIn .22s ease-out; }
@keyframes pageIn { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }
.content { padding: 8px 16px 24px; display: flex; flex-direction: column; gap: 14px; }
.content.has-nav { padding-bottom: calc(var(--nav-h) + 24px); }

/* ============ Top bar ============ */
.topbar {
  position: sticky; top: 0; z-index: 10;
  display: grid; grid-template-columns: 44px 1fr 44px; align-items: center;
  height: 56px; padding: 0 6px;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(10px);
}
.topbar h1 { font-size: 17px; font-weight: 700; text-align: center; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.icon-btn {
  width: 44px; height: 44px; border-radius: 50%;
  display: grid; place-items: center; color: var(--text);
}
.icon-btn:active { background: var(--surface-2); }
.icon-btn svg { width: 22px; height: 22px; }

/* ============ Cards ============ */
.card {
  background: var(--surface); border-radius: var(--radius);
  padding: 16px; box-shadow: var(--shadow);
}
.card-title { font-size: 13px; font-weight: 700; color: var(--text-2); text-transform: uppercase; letter-spacing: .06em; margin-bottom: 10px; }
.row { display: flex; align-items: center; gap: 12px; }
.row.between { justify-content: space-between; }
.muted { color: var(--text-2); }
.faint { color: var(--text-3); font-size: 13px; }
.section-label { font-size: 13px; font-weight: 700; color: var(--text-2); padding: 6px 4px 0; }

/* ============ Buttons & inputs ============ */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  height: 52px; padding: 0 20px; border-radius: 14px;
  font-weight: 700; font-size: 16px; width: 100%;
  background: var(--brand); color: #fff;
  transition: transform .08s, opacity .15s;
}
.btn svg { width: 20px; height: 20px; flex: none; }
.btn:active { transform: scale(.98); }
.btn:disabled { opacity: .45; pointer-events: none; }
.btn.secondary { background: var(--surface-2); color: var(--text); }
.btn.ghost { background: transparent; color: var(--brand); }
.btn.danger { background: var(--danger-soft); color: var(--danger); }
.btn.sm { height: 38px; font-size: 14px; border-radius: 11px; width: auto; padding: 0 14px; }

.field { display: flex; flex-direction: column; gap: 6px; }
.field label { font-size: 13px; font-weight: 600; color: var(--text-2); }
.input {
  height: 52px; padding: 0 14px; border-radius: 14px;
  border: 1.5px solid var(--line); background: var(--surface); outline: none;
  font-size: 16px; width: 100%;
}
.input:focus { border-color: var(--brand); }
.input.big { height: 68px; font-family: var(--mono); font-size: 30px; font-weight: 700; text-align: center; letter-spacing: .02em; }
.input-suffix { position: relative; }
.input-suffix span { position: absolute; right: 16px; top: 50%; transform: translateY(-50%); color: var(--text-3); font-weight: 700; }
.hint { font-size: 13px; color: var(--text-3); }
.error-text { font-size: 13px; color: var(--danger); font-weight: 600; }

/* Toggle switch */
.switch { position: relative; display: inline-block; vertical-align: middle; width: 50px; height: 30px; flex: none; }
.switch input { opacity: 0; width: 0; height: 0; position: absolute; }
.switch span {
  position: absolute; inset: 0; border-radius: 99px; background: var(--line); transition: .2s;
}
.switch span::after {
  content: ""; position: absolute; left: 3px; top: 3px; width: 24px; height: 24px;
  border-radius: 50%; background: #fff; box-shadow: 0 1px 3px rgba(0,0,0,.2); transition: .2s;
}
.switch input:checked + span { background: var(--brand); }
.switch input:checked + span::after { transform: translateX(20px); }

/* Segmented control */
.segmented { display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; background: var(--surface-2); padding: 4px; border-radius: 13px; }
.segmented button { height: 38px; border-radius: 10px; font-weight: 700; font-size: 14px; color: var(--text-2); }
.segmented button.active { background: var(--surface); color: var(--text); box-shadow: var(--shadow); }

/* List rows */
.list { background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden; }
.list-item {
  display: flex; align-items: center; gap: 12px; padding: 14px 16px; min-height: 56px; width: 100%; text-align: left;
}
.list-item + .list-item { border-top: 1px solid var(--line); }
.list-item .grow { flex: 1; min-width: 0; }
.list-item .title { font-weight: 600; }
.list-item .sub { font-size: 13px; color: var(--text-3); }
.list-item .value { color: var(--text-2); font-weight: 600; }
.chev { color: var(--text-3); width: 18px; height: 18px; }
.ico-box { width: 38px; height: 38px; border-radius: 11px; display: grid; place-items: center; background: var(--brand-soft); color: var(--brand); flex: none; }
.ico-box svg { width: 20px; height: 20px; }

/* Pills / badges */
.pill { display: inline-flex; align-items: center; gap: 6px; height: 26px; padding: 0 10px; border-radius: 99px; font-size: 12px; font-weight: 700; background: var(--surface-2); color: var(--text-2); }
.pill.ok { background: var(--brand-soft); color: var(--brand); }
.pill.warn { background: var(--warn-soft); color: var(--warn); }
.pill.off { background: var(--danger-soft); color: var(--danger); }
.dot { width: 7px; height: 7px; border-radius: 50%; background: currentColor; }
.dot.live { animation: pulse 1.6s infinite; }
@keyframes pulse { 0%,100% { opacity: 1; } 50% { opacity: .3; } }

/* ============ Meter odometer (signature component) ============ */
.odo {
  display: inline-flex; gap: 3px; padding: 8px; border-radius: 12px;
  background: var(--meter-bg); box-shadow: inset 0 2px 6px rgba(0,0,0,.6);
}
.odo span {
  display: grid; place-items: center; width: 30px; height: 44px; border-radius: 5px;
  font-family: var(--mono); font-weight: 700; font-size: 26px; color: var(--meter-digit);
  background: linear-gradient(#1d2622, #0a0f0d 48%, #1d2622);
  box-shadow: inset 0 0 0 1px rgba(255,255,255,.06);
}
.odo span.dec { background: linear-gradient(#5b1714, #2a0806 48%, #5b1714); color: #ffd9d6; }
.odo.sm span { width: 22px; height: 32px; font-size: 18px; }
@media (max-width: 360px) { .odo span { width: 25px; height: 38px; font-size: 22px; } }

/* Units hero card */
.units-hero {
  background: radial-gradient(120% 140% at 0% 0%, #1d3b2f 0%, #0f1714 60%);
  color: #eaf3ef; border-radius: 22px; padding: 18px; box-shadow: var(--shadow);
  display: flex; flex-direction: column; gap: 14px; position: relative; overflow: hidden;
}
.units-hero .label { font-size: 12px; font-weight: 700; letter-spacing: .1em; text-transform: uppercase; color: #8fb5a5; }
.units-hero .meta { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.units-hero .meta div { background: rgba(255,255,255,.06); border-radius: 12px; padding: 10px; }
.units-hero .meta b { display: block; font-family: var(--mono); font-size: 16px; }
.units-hero .meta small { font-size: 11px; color: #8fb5a5; font-weight: 600; }
.units-hero .btn.secondary { background: rgba(255,255,255,.1); color: #fff; }

.setup-card {
  border: 2px dashed var(--brand); background: var(--brand-soft); color: var(--brand-ink);
  border-radius: 20px; padding: 18px; display: flex; flex-direction: column; gap: 10px;
}

/* ============ Breaker dashboard ============ */
.totals { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.total-tile { background: var(--surface); border-radius: var(--radius); padding: 14px; box-shadow: var(--shadow); }
.total-tile .big { font-family: var(--mono); font-size: 28px; font-weight: 700; line-height: 1.1; }
.total-tile .lbl { font-size: 12px; color: var(--text-2); font-weight: 600; display: flex; align-items: center; gap: 4px; margin-top: 4px; }
.total-tile .hour { margin-top: 10px; font-size: 13px; color: var(--brand); font-weight: 700; }

.live-carousel { display: flex; overflow-x: auto; scroll-snap-type: x mandatory; gap: 12px; scrollbar-width: none; margin: 0 -16px; padding: 0 16px; }
.live-carousel::-webkit-scrollbar { display: none; }
.live-slide {
  flex: 0 0 100%; scroll-snap-align: center;
  background: linear-gradient(135deg, var(--brand) 0%, #157a52 100%); color: #fff;
  border-radius: 22px; padding: 18px; display: grid; grid-template-columns: 1fr 1fr; gap: 18px 12px;
}
.live-slide .k { font-size: 13px; opacity: .85; font-weight: 600; }
.live-slide .v { font-family: var(--mono); font-size: 28px; font-weight: 700; }
.live-slide .v small { font-size: 14px; opacity: .8; margin-left: 2px; }
.dots { display: flex; justify-content: center; gap: 6px; }
.dots i { width: 6px; height: 6px; border-radius: 99px; background: var(--line); transition: .2s; }
.dots i.on { width: 18px; background: var(--brand); }

.stat-trio { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.stat-trio .card { padding: 12px; text-align: center; }
.stat-trio b { font-family: var(--mono); font-size: 20px; display: block; }
.stat-trio small { font-size: 12px; color: var(--text-2); font-weight: 600; }

/* Bottom action bar (device page) */
.action-bar {
  position: fixed; bottom: 0; left: 50%; transform: translateX(-50%);
  width: 100%; max-width: 567px; height: var(--nav-h); z-index: 20;
  display: grid; grid-template-columns: repeat(4, 1fr);
  background: var(--surface); border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom);
}
.action-bar button { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px; font-size: 12px; font-weight: 700; color: var(--text-2); }
.action-bar button svg { width: 24px; height: 24px; }
.action-bar button.on { color: var(--brand); }
.action-bar button.off { color: var(--danger); }

/* Bottom tab nav (home) */
.tabbar {
  position: fixed; bottom: 0; left: 50%; transform: translateX(-50%);
  width: 100%; max-width: 567px; height: var(--nav-h); z-index: 20;
  display: grid; grid-template-columns: repeat(3, 1fr);
  background: var(--surface); border-top: 1px solid var(--line);
}
.tabbar a { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px; font-size: 12px; font-weight: 700; color: var(--text-3); }
.tabbar a svg { width: 24px; height: 24px; }
.tabbar a.active { color: var(--brand); }

/* ============ Chart ============ */
.chart { width: 100%; height: 190px; display: block; }
.chart .bar { fill: var(--brand-2); opacity: .55; transition: opacity .15s; }
.chart .bar.sel { opacity: 1; fill: var(--brand); }
.chart .axis { fill: var(--text-3); font-size: 10px; font-family: var(--mono); }
.chart .grid { stroke: var(--line); stroke-dasharray: 3 4; }
.chart-tip { display: flex; align-items: baseline; gap: 8px; min-height: 26px; }
.chart-tip b { font-family: var(--mono); font-size: 18px; }

.stats-hero { display: flex; align-items: baseline; gap: 8px; }
.stats-hero b { font-family: var(--mono); font-size: 44px; font-weight: 700; letter-spacing: -.03em; }
.date-nav { display: grid; grid-template-columns: 48px 1fr 48px; align-items: center; background: var(--surface); border-radius: 14px; box-shadow: var(--shadow); height: 52px; }
.date-nav span { text-align: center; font-weight: 700; }
.date-nav button { height: 100%; display: grid; place-items: center; color: var(--text-2); }
.date-nav button:disabled { opacity: .3; }

/* ============ Home ============ */
.greeting h2 { font-size: 24px; font-weight: 800; letter-spacing: -.02em; }
.device-card { display: flex; align-items: center; gap: 14px; padding: 14px 16px; }
.device-card .ico-box { width: 48px; height: 48px; border-radius: 14px; }
.device-card .ico-box svg { width: 26px; height: 26px; }
.device-card .name { font-weight: 700; font-size: 16px; }
.add-tile { border: 1.5px dashed var(--line); background: transparent; box-shadow: none; color: var(--text-2); justify-content: center; font-weight: 700; }

/* ============ Auth ============ */
.auth { flex: 1; display: flex; flex-direction: column; padding: 32px 20px 24px; gap: 20px; }
.brand-mark { display: flex; align-items: center; gap: 10px; font-weight: 800; font-size: 22px; letter-spacing: -.02em; }
.brand-mark .logo { width: 44px; height: 44px; border-radius: 13px; background: var(--meter-bg); display: grid; place-items: center; color: var(--brand-2); }
.auth h2 { font-size: 28px; font-weight: 800; letter-spacing: -.03em; line-height: 1.15; }
.auth .spacer { flex: 1; }
.auth-hero { padding: 18px 0 4px; }

/* ============ Pairing ============ */
.steps { display: flex; gap: 6px; }
.steps i { flex: 1; height: 4px; border-radius: 99px; background: var(--line); }
.steps i.on { background: var(--brand); }
.type-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.type-grid button { background: var(--surface); border-radius: 16px; padding: 16px 8px; display: flex; flex-direction: column; align-items: center; gap: 8px; font-size: 13px; font-weight: 700; box-shadow: var(--shadow); border: 2px solid transparent; }
.type-grid button.sel { border-color: var(--brand); }
.type-grid button svg { width: 30px; height: 30px; color: var(--brand); }
.radar { position: relative; width: 200px; height: 200px; margin: 20px auto; display: grid; place-items: center; }
.radar::before, .radar::after { content: ""; position: absolute; inset: 0; border-radius: 50%; border: 2px solid var(--brand); animation: ripple 2s infinite ease-out; opacity: 0; }
.radar::after { animation-delay: 1s; }
@keyframes ripple { from { transform: scale(.3); opacity: .8; } to { transform: scale(1); opacity: 0; } }
.radar .core { width: 84px; height: 84px; border-radius: 50%; background: var(--brand); color: #fff; display: grid; place-items: center; font-family: var(--mono); font-size: 22px; font-weight: 700; }
.success-ico { width: 84px; height: 84px; border-radius: 50%; background: var(--brand-soft); color: var(--brand); display: grid; place-items: center; margin: 24px auto 8px; }
.success-ico svg { width: 42px; height: 42px; }

/* ============ Units history timeline ============ */
.timeline { display: flex; flex-direction: column; }
.tl-item { display: grid; grid-template-columns: 18px 1fr auto; gap: 12px; padding: 10px 0; position: relative; }
.tl-item::before { content: ""; position: absolute; left: 8px; top: 0; bottom: 0; width: 2px; background: var(--line); }
.tl-item:first-child::before { top: 18px; }
.tl-item:last-child::before { bottom: calc(100% - 18px); }
.tl-item .node { width: 18px; height: 18px; border-radius: 50%; background: var(--surface); border: 3px solid var(--brand); margin-top: 2px; position: relative; z-index: 1; }
.tl-item .node.old { border-color: var(--text-3); }

/* ============ Sheets / modal / toast ============ */
.sheet-backdrop { position: fixed; inset: 0; background: rgba(5, 12, 9, .5); z-index: 50; animation: fade .2s; display: flex; justify-content: center; align-items: flex-end; }
.sheet {
  width: 100%; max-width: 567px; background: var(--bg); border-radius: 24px 24px 0 0;
  padding: 10px 18px calc(22px + env(safe-area-inset-bottom)); display: flex; flex-direction: column; gap: 14px;
  animation: up .25s ease-out; max-height: 92vh; overflow-y: auto;
}
.sheet .grab { width: 40px; height: 5px; border-radius: 99px; background: var(--line); margin: 0 auto 4px; }
.sheet h3 { font-size: 20px; font-weight: 800; letter-spacing: -.02em; }
@keyframes fade { from { opacity: 0; } }
@keyframes up { from { transform: translateY(40px); opacity: 0; } }
.toast-root { position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(var(--nav-h) + 16px); z-index: 60; width: calc(100% - 32px); max-width: 535px; display: flex; flex-direction: column; gap: 8px; pointer-events: none; }
.toast { background: var(--text); color: var(--bg); padding: 12px 16px; border-radius: 14px; font-weight: 600; font-size: 14px; animation: up .2s; box-shadow: var(--shadow); }

.empty { text-align: center; padding: 30px 10px; color: var(--text-3); }
.callout { display: flex; gap: 10px; padding: 12px 14px; border-radius: 14px; background: var(--warn-soft); color: var(--text); font-size: 13px; }
.callout.info { background: var(--brand-soft); }
.callout svg { width: 18px; height: 18px; flex: none; margin-top: 1px; color: var(--warn); }
.callout.info svg { color: var(--brand); }

.days { display: flex; gap: 6px; }
.days button { flex: 1; height: 38px; border-radius: 10px; background: var(--surface-2); font-weight: 700; font-size: 13px; color: var(--text-2); }
.days button.on { background: var(--brand); color: #fff; }

.compare { display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; gap: 8px; text-align: center; }
.compare b { font-family: var(--mono); font-size: 18px; display: block; }
.compare small { font-size: 12px; color: var(--text-3); font-weight: 600; }
.total-tile .lbl svg { width: 14px; height: 14px; }

/* Cycle progress bar: solid = used, faint = projected */
.bar-track { position: relative; height: 12px; border-radius: 99px; background: var(--surface-2); overflow: hidden; }
.bar-track i { position: absolute; left: 0; top: 0; bottom: 0; border-radius: 99px; background: var(--brand); }
.bar-track i.proj { opacity: .25; }
.bar-track.warn i { background: var(--warn); }
.bar-track.danger i { background: var(--danger); }

/* ============ Energy slider (Units <-> kWh) ============ */
.energy-hero { gap: 12px; }
.seg-dark { display: inline-flex; background: rgba(255,255,255,.08); border-radius: 11px; padding: 3px; }
.seg-dark button { height: 32px; padding: 0 16px; border-radius: 8px; font-weight: 700; font-size: 13px; color: #9dbcaf; }
.seg-dark button.active { background: #eaf3ef; color: #0f1714; }
.live-strip { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.live-strip > div { background: rgba(69,192,140,.12); border: 1px solid rgba(69,192,140,.25); border-radius: 12px; padding: 8px 10px; }
.live-strip > div > span { display: block; font-size: 11px; font-weight: 700; color: #8fb5a5; text-transform: uppercase; letter-spacing: .06em; }
.live-strip b { font-family: var(--mono); font-size: 20px; color: #fff; white-space: nowrap; }
.live-strip small { font-size: 12px; color: #8fb5a5; margin-left: 3px; }
.hero-track { display: flex; overflow-x: auto; scroll-snap-type: x mandatory; scrollbar-width: none; margin: 0 -18px; }
.hero-track::-webkit-scrollbar { display: none; }
.hero-track > section { flex: 0 0 100%; scroll-snap-align: start; padding: 0 18px; display: flex; flex-direction: column; gap: 12px; cursor: pointer; min-width: 0; }
.kwh-big { display: flex; align-items: baseline; gap: 6px; min-height: 60px; }
.kwh-big b { font-family: var(--mono); font-size: 42px; font-weight: 700; letter-spacing: -.03em; line-height: 1.2; }
.kwh-big small { color: #8fb5a5; font-weight: 700; }
.energy-hero .dots i { background: rgba(255,255,255,.2); }
.energy-hero .dots i.on { background: var(--brand-2); }
@media (max-width: 380px) { .live-strip b { font-size: 17px; } .kwh-big b { font-size: 34px; } }

.precise { font-size: 12px; color: #8fb5a5; font-weight: 600; }
.precise b, .precise span { font-family: var(--mono); color: #cfe3da; }
