/* LiFeTime — "instrument panel" theme.
   Industrial dark, carbon + blueprint grid, energy-green accent, mono numerals. */

@font-face { font-family: 'Archivo'; src: url('../../vendor/fonts/archivo-500.woff2') format('woff2'); font-weight: 500; font-display: swap; }
@font-face { font-family: 'Archivo'; src: url('../../vendor/fonts/archivo-700.woff2') format('woff2'); font-weight: 700; font-display: swap; }
@font-face { font-family: 'Chivo Mono'; src: url('../../vendor/fonts/chivomono-400.woff2') format('woff2'); font-weight: 400; font-display: swap; }
@font-face { font-family: 'Chivo Mono'; src: url('../../vendor/fonts/chivomono-600.woff2') format('woff2'); font-weight: 600; font-display: swap; }

:root {
  color-scheme: dark;
  --bg: #07090b;
  --surface: #0e1216;
  --surface-2: #161c22;
  --line: #232c34;
  --text: #e7edf2;
  --muted: #7e8c98;
  --ok: #ff7a18;       /* primary accent / healthy / high SOC (orange) */
  --warn: #f5c542;     /* caution / mid SOC (amber-yellow) */
  --bad: #ff5468;      /* fault / low SOC */
  --accent: #ff7a18;
  --accent-dim: #7a3a0c;
  --radius: 14px;
  --gap: 14px;
  --sans: 'Archivo', ui-sans-serif, system-ui, sans-serif;
  --mono: 'Chivo Mono', ui-monospace, 'SF Mono', monospace;
  --shadow: 0 10px 30px rgba(0, 0, 0, .5);
  --grid: rgba(255, 122, 24, .05);
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background:
    linear-gradient(var(--grid) 1px, transparent 1px) 0 0 / 28px 28px,
    linear-gradient(90deg, var(--grid) 1px, transparent 1px) 0 0 / 28px 28px,
    radial-gradient(120% 80% at 50% -10%, #0f1620 0%, var(--bg) 60%);
  color: var(--text);
  font-family: var(--sans);
  font-size: 16px;
  line-height: 1.4;
  padding-bottom: 76px; /* room for bottom nav */
  -webkit-font-smoothing: antialiased;
}
h1, h2, h3 { font-weight: 700; letter-spacing: -.01em; margin: 0 0 .5rem; }
.muted { color: var(--muted); }
button, input, select { font-family: inherit; }

/* App bar */
.appbar {
  position: sticky; top: 0; z-index: 5;
  display: flex; align-items: baseline; gap: .6rem;
  padding: .8rem 1rem;
  background: linear-gradient(180deg, rgba(7, 9, 11, .92), rgba(7, 9, 11, .6));
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--line);
}
.appbar h1 { font-size: 1.15rem; margin: 0; letter-spacing: .14em; text-transform: uppercase; }
.appbar h1::before { content: '▸ '; color: var(--accent); }

main#view { padding: 1rem; max-width: 760px; margin: 0 auto; }

/* Bottom nav */
.bottomnav {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 5;
  display: flex; border-top: 1px solid var(--line);
  background: rgba(10, 13, 16, .96); backdrop-filter: blur(10px);
}
.bottomnav a {
  flex: 1; text-align: center; padding: 1rem .5rem;
  color: var(--muted); text-decoration: none; font-size: .82rem;
  letter-spacing: .08em; text-transform: uppercase;
}
.bottomnav a:active { color: var(--text); }

/* Grid of tiles */
.grid { display: grid; gap: var(--gap); grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); }
.toolbar { display: flex; gap: .5rem; margin-bottom: var(--gap); }
.empty { color: var(--muted); text-align: center; padding: 3rem 1rem; border: 1px dashed var(--line); border-radius: var(--radius); }

/* Tiles */
.tile {
  display: flex; flex-direction: column; align-items: center; gap: .5rem;
  background: linear-gradient(180deg, var(--surface-2), var(--surface));
  border: 1px solid var(--line); border-radius: var(--radius);
  padding: 1rem .8rem; color: var(--text); text-align: center;
  cursor: pointer; box-shadow: var(--shadow); transition: border-color .15s, transform .1s;
}
.tile:active { transform: scale(.985); }
.tile:hover { border-color: var(--accent-dim); }
.tile--pack { border-left: 3px solid var(--accent); }
.tile__title { font-weight: 700; font-size: .95rem; display: flex; align-items: center; gap: .35rem; }
.tile__foot { font-size: .72rem; color: var(--muted); display: flex; gap: .4rem; align-items: center; }
.tile--mini { padding: .6rem; }
.tile--battery { border-left: 3px solid var(--line); }

/* Controls section */
.controls { display: flex; flex-wrap: wrap; gap: .5rem; }

/* Toolbar / view title */
.toolbar { display: flex; align-items: center; justify-content: space-between; margin-bottom: var(--gap); }
.view-title { margin: 0; font-size: 1.1rem; letter-spacing: .04em; }

/* Dense list rows (dashboard / packs) */
.list { display: flex; flex-direction: column; gap: .5rem; }
.lrow {
  display: flex; align-items: center; gap: .7rem;
  background: linear-gradient(180deg, var(--surface-2), var(--surface));
  border: 1px solid var(--line); border-left: 3px solid var(--line); border-radius: 12px;
  padding: .7rem .9rem; color: var(--text); text-align: left; cursor: pointer;
  transition: border-color .15s, transform .08s;
}
.lrow:active { transform: scale(.99); }
.lrow:hover { border-left-color: var(--accent); }
.lrow__name { display: flex; flex-direction: column; min-width: 0; flex: 1; }
.lrow__btn { padding: .45rem .8rem; font-size: .82rem; }
.lrow__name b { font-size: .98rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.lrow__name small { color: var(--muted); font-size: .7rem; }
.lrow__soc { font-family: var(--mono); font-variant-numeric: tabular-nums; line-height: 1; text-align: right; }
.lrow__soc b { font-size: 1.7rem; font-weight: 600; }
.lrow__soc small { font-size: .8rem; color: var(--muted); }
.lrow__stat { font-family: var(--mono); font-variant-numeric: tabular-nums; text-align: right; line-height: 1; min-width: 3.4ch; }
.lrow__stat b { font-size: 1.15rem; font-weight: 600; display: block; }
.lrow__stat small { font-size: .65rem; color: var(--muted); }
.is-charge { color: var(--ok); }
.is-discharge { color: var(--warn); }

/* Detail hero + tabs */
.hero__stats { display: flex; flex-wrap: wrap; gap: .25rem 1rem; font-family: var(--mono); font-variant-numeric: tabular-nums; }
.tabs { display: flex; gap: .25rem; border-bottom: 1px solid var(--line); margin: 1rem 0 .5rem; }
.tab {
  flex: 1; background: none; border: 0; border-bottom: 2px solid transparent; color: var(--muted);
  padding: .6rem .3rem; font-size: .78rem; letter-spacing: .08em; text-transform: uppercase; cursor: pointer;
}
.tab.is-active { color: var(--text); border-bottom-color: var(--accent); }
.tab-body { min-height: 40vh; }

/* SOC ring (conic gauge) */
.soc-ring {
  --size: 92px; width: var(--size); height: var(--size); border-radius: 50%;
  display: grid; place-items: center; position: relative;
  mask: radial-gradient(farthest-side, transparent 58%, #000 60%);
  -webkit-mask: radial-gradient(farthest-side, transparent 58%, #000 60%);
}
.soc-ring__val {
  font-family: var(--mono); font-weight: 600; font-size: 1.25rem;
  font-variant-numeric: tabular-nums; -webkit-mask: none; mask: none;
}

/* Stats */
.stat { display: flex; flex-direction: column; gap: .1rem; align-items: center; }
.stat__label { font-size: .68rem; letter-spacing: .08em; text-transform: uppercase; color: var(--muted); }
.stat__val { font-family: var(--mono); font-variant-numeric: tabular-nums; font-size: 1.02rem; }

/* Chips */
.chip { display: inline-block; font-size: .72rem; padding: .15rem .5rem; border-radius: 999px; border: 1px solid var(--line); color: var(--muted); }
.chip.health-ok { color: var(--ok); border-color: var(--accent-dim); }
.chip.health-warn { color: var(--warn); border-color: #6b521a; }
.chip.health-bad { color: var(--bad); border-color: #6b2530; background: rgba(255, 84, 104, .08); }

/* Status dot */
.status-dot { width: .6rem; height: .6rem; border-radius: 50%; display: inline-block; background: var(--muted); }
.status-dot.live { background: var(--ok); box-shadow: 0 0 8px var(--ok); animation: pulse 2s infinite; }
.status-dot.stale { background: var(--warn); }
.status-dot.error { background: var(--bad); }
.status-dot.connecting { background: var(--accent); animation: pulse 1s infinite; }
.status-dot.disconnected { background: var(--muted); }
@keyframes pulse { 0%, 100% { opacity: 1; } 50% { opacity: .35; } }

/* Buttons */
.btn {
  background: var(--surface-2); color: var(--text); border: 1px solid var(--line);
  border-radius: 10px; padding: .6rem 1rem; font-size: .9rem; cursor: pointer;
  letter-spacing: .02em; transition: border-color .15s, background .15s;
}
.btn:hover { border-color: var(--accent-dim); }
.btn--accent { background: var(--accent); color: #2a1503; border-color: var(--accent); font-weight: 700; }
.btn--warn { border-color: #6b521a; color: var(--warn); }
.btn--danger { border-color: #6b2530; color: var(--bad); }

/* Detail view */
.view-head { display: flex; align-items: center; gap: .8rem; margin-bottom: 1rem; }
.view-head h2 { margin: 0; font-size: 1.1rem; display: flex; align-items: center; gap: .4rem; }
.view-head__title { display: flex; flex-direction: column; min-width: 0; }
.view-head__title small { font-size: .72rem; }
.hero { display: flex; flex-wrap: wrap; align-items: center; gap: 1rem; padding: 1.2rem; background: linear-gradient(180deg, var(--surface-2), var(--surface)); border: 1px solid var(--line); border-radius: var(--radius); margin-bottom: 1rem; }
.hero__soc { font-family: var(--mono); font-weight: 600; font-size: 2.6rem; font-variant-numeric: tabular-nums; color: var(--accent); }

section { margin: 1.2rem 0; }
section h3 { font-size: .8rem; letter-spacing: .1em; text-transform: uppercase; color: var(--muted); border-bottom: 1px solid var(--line); padding-bottom: .3rem; }
table { width: 100%; border-collapse: collapse; }
td { padding: .35rem .2rem; border-bottom: 1px solid var(--surface-2); }
td:last-child { text-align: right; font-family: var(--mono); font-variant-numeric: tabular-nums; }

/* Cell grid */
.cell-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(84px, 1fr)); gap: .5rem; }
.cell { background: var(--surface); border: 1px solid var(--line); border-radius: 10px; padding: .5rem; display: flex; flex-direction: column; gap: .15rem; }
.cell .n { font-size: .7rem; color: var(--muted); }
.cell .v { font-family: var(--mono); font-variant-numeric: tabular-nums; font-size: 1.15rem; font-weight: 600; }
.cell.low { border-color: var(--warn); box-shadow: inset 0 0 0 1px rgba(255, 176, 32, .2); }
.cell.high { border-color: var(--ok); box-shadow: inset 0 0 0 1px rgba(52, 226, 155, .2); }

/* Member strip, warnings, banners */
.member-strip { display: grid; grid-template-columns: repeat(auto-fill, minmax(110px, 1fr)); gap: .5rem; }
.warnings { margin: .5rem 0; padding-left: 1.1rem; color: var(--warn); font-size: .85rem; }
.banner { padding: .6rem .9rem; border-radius: 10px; margin-bottom: 1rem; font-size: .88rem; }
.banner--warn { background: rgba(255, 176, 32, .1); border: 1px solid #6b521a; color: var(--warn); }

/* Forms */
.row { display: flex; align-items: center; gap: .5rem; margin: .4rem 0; flex-wrap: wrap; }
.inp { background: var(--surface); border: 1px solid var(--line); border-radius: 10px; padding: .55rem .7rem; color: var(--text); }
.pack-form { display: flex; flex-direction: column; gap: .4rem; margin-top: .6rem; padding: .8rem; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); }
.legal { color: var(--muted); font-size: .72rem; margin-top: 2rem; }

/* Dialog */
.dialog__backdrop { position: fixed; inset: 0; background: rgba(3, 5, 7, .7); display: grid; place-items: center; z-index: 50; padding: 1rem; }
.dialog { background: var(--surface-2); border: 1px solid var(--line); border-radius: var(--radius); padding: 1.2rem; max-width: 360px; box-shadow: var(--shadow); }
.dialog__row { display: flex; gap: .6rem; justify-content: flex-end; margin-top: 1rem; }

/* uPlot dark fit */
.uplot { font-family: var(--mono); }

/* Toast (transient feedback for connect/errors) */
.toast {
  position: fixed; left: 50%; bottom: 84px; transform: translateX(-50%) translateY(16px);
  background: var(--surface-2); border: 1px solid var(--line); color: var(--text);
  padding: .6rem 1rem; border-radius: 10px; font-size: .85rem; max-width: 90%;
  opacity: 0; pointer-events: none; transition: opacity .2s, transform .2s;
  z-index: 60; box-shadow: var(--shadow);
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

.control-row { display: flex; align-items: center; justify-content: space-between; padding: 12px 4px; border-bottom: 1px solid var(--surface-2); }
.control-row__label { font-size: 1.05rem; }
.toggle { min-width: 84px; padding: 10px 16px; border-radius: 999px; font-weight: 700; letter-spacing: 0.04em; border: 1px solid var(--surface-2); }
.toggle.is-on { background: var(--ok); color: var(--bg); }
.toggle.is-off { background: var(--surface-2); color: var(--text); }
.toggle.is-unknown { opacity: 0.6; }
