/* AEROSENSTROL — field-notes design language, modernised. System fonts only (works offline). */
:root {
  --bg: #f4f1e8; --surface: #fffdf7; --surface-2: #f8f5ec; --line: #e2dccb; --line-strong: #cfc7b2;
  --ink: #16302a; --ink-2: #4a5a52; --ink-3: #7b857d;
  --brand: #193d31; --brand-ink: #e8efd2; --accent: #2f6b4f; --accent-soft: #e3ecdf;
  --good: #2f7a4f; --good-soft: #e2f0e4; --warn: #a86a12; --warn-soft: #f7ecd6; --bad: #b23a2c; --bad-soft: #f7e1dc;
  --info: #2d5f86; --info-soft: #e1ebf3;
  --c-temp: #c2562e; --c-rh: #2d6f9a; --c-co2: #6b5aa8; --c-lux: #b08a14;
  --radius: 18px; --radius-sm: 12px; --shadow: 0 1px 2px rgba(22,48,42,.05), 0 8px 24px -12px rgba(22,48,42,.18);
  --serif: "Iowan Old Style", "Palatino Linotype", Palatino, Georgia, serif;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --mono: ui-monospace, "Cascadia Mono", Consolas, monospace;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #101814; --surface: #16211c; --surface-2: #1b2822; --line: #26362e; --line-strong: #34483d;
    --ink: #e9efe6; --ink-2: #b4c0b6; --ink-3: #85938a; --brand: #24533f; --brand-ink: #e8efd2;
    --accent: #7fc29a; --accent-soft: #1f3a2c; --good: #6fc08d; --good-soft: #1b3326; --warn: #e2a64a; --warn-soft: #3a2d16;
    --bad: #ef8270; --bad-soft: #3d1f1a; --info: #7db3dc; --info-soft: #18293a; color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #101814; --surface: #16211c; --surface-2: #1b2822; --line: #26362e; --line-strong: #34483d;
  --ink: #e9efe6; --ink-2: #b4c0b6; --ink-3: #85938a; --brand: #24533f; --brand-ink: #e8efd2;
  --accent: #7fc29a; --accent-soft: #1f3a2c; --good: #6fc08d; --good-soft: #1b3326; --warn: #e2a64a; --warn-soft: #3a2d16;
  --bad: #ef8270; --bad-soft: #3d1f1a; --info: #7db3dc; --info-soft: #18293a; color-scheme: dark;
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--ink); font: 16px/1.5 var(--sans); -webkit-tap-highlight-color: transparent; }
body { min-height: 100vh; }
a { color: var(--accent); }
h1, h2, h3 { font-family: var(--serif); font-weight: 600; letter-spacing: -.01em; margin: 0; }
h1 { font-size: clamp(28px, 6vw, 40px); line-height: 1.1; }
h2 { font-size: 22px; }
h3 { font-size: 18px; }
p { margin: 0; }
button, input, select, textarea { font: inherit; color: inherit; }
:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }
.mono { font-family: var(--mono); }
.muted { color: var(--ink-3); }
.small { font-size: 14px; }
.eyebrow { font: 600 12px/1 var(--sans); letter-spacing: .14em; text-transform: uppercase; color: var(--ink-3); }

/* ---------- shell ---------- */
.shell { display: grid; grid-template-columns: 1fr; min-height: 100vh; }
.sidebar { display: none; }
main { padding: 20px 16px calc(112px + env(safe-area-inset-bottom)); max-width: 1180px; width: 100%; margin: 0 auto; outline: none; }
.tabbar { position: fixed; inset: auto 0 0 0; display: grid; grid-template-columns: repeat(5, 1fr); background: var(--surface);
  border-top: 1px solid var(--line); padding: 6px 4px calc(6px + env(safe-area-inset-bottom)); z-index: 20; box-shadow: 0 -6px 18px -12px rgba(22,48,42,.35); }
.tabbar a { display: grid; justify-items: center; align-content: center; gap: 3px; min-height: 60px; padding: 6px 2px; border-radius: 14px;
  text-decoration: none; color: var(--ink-3); font-size: 12.5px; font-weight: 600; touch-action: manipulation; }
.tabbar a svg { width: 26px; height: 26px; }
.tabbar a[aria-current="page"] { color: var(--accent); background: var(--accent-soft); }
.tabbar a:active { background: var(--surface-2); }
.native .tabbar { padding-bottom: 6px; }
.native main { padding-bottom: 104px; }
.native #toast { bottom: 96px; }
.native .sheet { padding-bottom: 22px; }
@media (min-width: 900px) {
  .shell { grid-template-columns: 248px 1fr; }
  .sidebar { display: flex; flex-direction: column; position: sticky; top: 0; height: 100vh; padding: 24px 16px; background: var(--surface); border-right: 1px solid var(--line); }
  .tabbar { display: none; }
  main { padding: 36px 40px 48px; }
}
.brand { display: flex; gap: 12px; align-items: center; text-decoration: none; color: var(--ink); margin: 0 8px 28px; }
.brand b { display: block; font-size: 15px; letter-spacing: .06em; }
.brand small { color: var(--ink-3); font-size: 12px; }
#nav-side a { display: flex; gap: 12px; align-items: center; padding: 11px 12px; border-radius: 12px; color: var(--ink-2); text-decoration: none; font-weight: 500; margin-bottom: 2px; }
#nav-side a svg { width: 20px; height: 20px; }
#nav-side a:hover { background: var(--surface-2); }
#nav-side a[aria-current="page"] { background: var(--accent-soft); color: var(--ink); }
.side-foot { margin-top: auto; padding: 12px; font-size: 13px; color: var(--ink-3); }

/* ---------- page header ---------- */
.page-head { display: flex; gap: 16px; align-items: flex-end; justify-content: space-between; flex-wrap: wrap; margin-bottom: 20px; }
.page-head .eyebrow { margin-bottom: 8px; }
.page-head .actions { display: flex; gap: 8px; flex-wrap: wrap; }

/* ---------- surfaces ---------- */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); }
.card-pad { padding: 18px; }
@media (min-width: 600px) { .card-pad { padding: 22px; } }
.card-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; padding: 18px 18px 0; }
.stack { display: grid; gap: 16px; }
.grid-2 { display: grid; gap: 16px; }
@media (min-width: 760px) { .grid-2 { grid-template-columns: 1fr 1fr; } }
.grid-3 { display: grid; gap: 16px; }
@media (min-width: 900px) { .grid-3 { grid-template-columns: repeat(3, 1fr); } }
.row { display: flex; align-items: center; gap: 12px; }
.spread { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.divider { border: 0; border-top: 1px solid var(--line); margin: 0; }

/* ---------- banner ---------- */
.banner { display: flex; gap: 14px; align-items: flex-start; padding: 16px 18px; border-radius: var(--radius); border: 1px solid transparent; }
.banner svg { flex: none; width: 24px; height: 24px; margin-top: 2px; }
.banner b { display: block; }
.banner.good { background: var(--good-soft); color: var(--ink); border-color: color-mix(in srgb, var(--good) 25%, transparent); }
.banner.good svg { color: var(--good); }
.banner.warn { background: var(--warn-soft); border-color: color-mix(in srgb, var(--warn) 30%, transparent); }
.banner.warn svg { color: var(--warn); }
.banner.bad { background: var(--bad-soft); border-color: color-mix(in srgb, var(--bad) 30%, transparent); }
.banner.bad svg { color: var(--bad); }
.banner.info { background: var(--info-soft); border-color: color-mix(in srgb, var(--info) 25%, transparent); }
.banner.info svg { color: var(--info); }

/* ---------- chips ---------- */
.chip { display: inline-flex; align-items: center; gap: 6px; padding: 4px 10px; border-radius: 999px; font-size: 13px; font-weight: 600; background: var(--surface-2); color: var(--ink-2); border: 1px solid var(--line); white-space: nowrap; }
.chip::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: currentColor; opacity: .9; }
.chip.plain::before { display: none; }
.chip.good { color: var(--good); background: var(--good-soft); border-color: transparent; }
.chip.warn { color: var(--warn); background: var(--warn-soft); border-color: transparent; }
.chip.bad { color: var(--bad); background: var(--bad-soft); border-color: transparent; }
.chip.info { color: var(--info); background: var(--info-soft); border-color: transparent; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }

/* ---------- metrics ---------- */
.device-card .card-head h3 { font-size: 20px; }
.metrics { display: grid; grid-template-columns: 1fr 1fr; gap: 1px; background: var(--line); border-top: 1px solid var(--line); margin-top: 16px; border-radius: 0 0 var(--radius) var(--radius); overflow: hidden; }
@media (min-width: 700px) { .metrics.m4 { grid-template-columns: repeat(4, 1fr); } }
.metric { background: var(--surface); padding: 14px 18px 16px; }
.metric .label { display: flex; align-items: center; gap: 6px; font-size: 13px; color: var(--ink-3); font-weight: 500; }
.metric .label i { width: 8px; height: 8px; border-radius: 50%; }
.metric .value { font: 600 34px/1.1 var(--sans); letter-spacing: -.02em; margin-top: 6px; font-variant-numeric: tabular-nums; }
.metric .value small { font-size: 15px; font-weight: 500; color: var(--ink-3); margin-left: 3px; }
.metric .hint { font-size: 13px; margin-top: 2px; }
.metric.stale .value { color: var(--ink-3); }
.hint.good { color: var(--good); } .hint.warn { color: var(--warn); } .hint.bad { color: var(--bad); }

/* ---------- insights ---------- */
.insight { border-top: 1px solid var(--line); }
.insight-head { display: flex; justify-content: space-between; align-items: center; gap: 10px; flex-wrap: wrap; padding: 14px 18px 0; }
.spark { padding: 6px 12px 0; }
.spark .chart { height: 150px; }
.seg-sm { flex-wrap: nowrap; overflow-x: auto; max-width: 100%; scrollbar-width: none; }
.seg-sm button { padding: 5px 10px; min-height: 32px; font-size: 13px; white-space: nowrap; flex: none; }
.facts { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; padding: 12px 18px 16px; }
@media (min-width: 560px) { .facts { grid-template-columns: repeat(3, 1fr); } }
@media (min-width: 900px) { .facts { grid-template-columns: repeat(6, 1fr); } }
.card > .facts { padding-top: 0; }
.fact { background: var(--surface-2); border: 1px solid var(--line); border-radius: 12px; padding: 10px 12px; display: grid; gap: 2px; }
.fact span { font-size: 12px; color: var(--ink-3); font-weight: 600; }
.fact b { font-size: 20px; font-variant-numeric: tabular-nums; }
.fact small { font-size: 12px; color: var(--ink-3); }
.fact .good { color: var(--good); } .fact .warn { color: var(--warn); } .fact .bad { color: var(--bad); }
.insight p svg { width: 14px; height: 14px; vertical-align: -2px; }

/* ---------- buttons & forms ---------- */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-height: 44px; padding: 10px 18px; border-radius: 12px; border: 1px solid var(--line-strong);
  background: var(--surface); color: var(--ink); font-weight: 600; cursor: pointer; text-decoration: none; }
.btn svg { width: 20px; height: 20px; }
.btn:hover { background: var(--surface-2); }
.btn.primary { background: var(--brand); color: var(--brand-ink); border-color: var(--brand); }
.btn.primary:hover { filter: brightness(1.08); }
.btn.danger { color: var(--bad); border-color: color-mix(in srgb, var(--bad) 40%, transparent); }
.btn.ghost { border-color: transparent; background: transparent; }
.btn.block { width: 100%; }
.btn[disabled] { opacity: .5; cursor: not-allowed; }
.btn.sm { min-height: 36px; padding: 6px 12px; font-size: 14px; }
.field { display: grid; gap: 6px; }
.field > span { font-size: 14px; font-weight: 600; color: var(--ink-2); }
.field small { color: var(--ink-3); font-size: 13px; }
input[type=text], input[type=email], input[type=password], input[type=number], select, textarea {
  width: 100%; min-height: 46px; padding: 10px 14px; border-radius: 12px; border: 1px solid var(--line-strong); background: var(--surface); }
input:focus, select:focus { border-color: var(--accent); outline: none; box-shadow: 0 0 0 3px var(--accent-soft); }
.code-input { font-family: var(--mono); letter-spacing: .08em; text-transform: uppercase; }
.code-input::placeholder { text-transform: none; letter-spacing: 0; font-family: var(--sans); }
.seg { display: inline-flex; background: var(--surface-2); border: 1px solid var(--line); border-radius: 12px; padding: 3px; gap: 2px; flex-wrap: wrap; }
.seg button { border: 0; background: transparent; padding: 7px 14px; border-radius: 9px; font-weight: 600; font-size: 14px; color: var(--ink-2); cursor: pointer; min-height: 36px; }
.seg button[aria-pressed="true"] { background: var(--surface); color: var(--ink); box-shadow: var(--shadow); }
.switch { position: relative; width: 52px; height: 30px; flex: none; }
.switch input { opacity: 0; width: 100%; height: 100%; margin: 0; cursor: pointer; position: absolute; z-index: 1; }
.switch span { position: absolute; inset: 0; border-radius: 999px; background: var(--line-strong); transition: .2s; }
.switch span::after { content: ""; position: absolute; top: 3px; left: 3px; width: 24px; height: 24px; border-radius: 50%; background: #fff; transition: .2s; box-shadow: 0 1px 3px rgba(0,0,0,.25); }
.switch input:checked + span { background: var(--accent); }
.switch input:checked + span::after { transform: translateX(22px); }

/* ---------- lists ---------- */
.list { display: grid; }
.list-item { display: flex; align-items: center; gap: 14px; padding: 14px 18px; border-top: 1px solid var(--line); }
.list-item:first-child { border-top: 0; }
.list-item .grow { flex: 1; min-width: 0; }
.list-item > svg { width: 22px; height: 22px; flex: none; color: var(--accent); }
button.list-item { font: inherit; color: inherit; }
button.list-item:hover { background: var(--surface-2); }
.chip svg { width: 14px; height: 14px; }
.list-item .title { font-weight: 600; }
.list-item .sub { font-size: 14px; color: var(--ink-3); overflow: hidden; text-overflow: ellipsis; }
.icon-bubble { width: 42px; height: 42px; border-radius: 12px; display: grid; place-items: center; background: var(--accent-soft); color: var(--accent); flex: none; }
.icon-bubble svg { width: 22px; height: 22px; }
.kv { display: grid; grid-template-columns: auto 1fr; gap: 8px 16px; font-size: 14px; }
.kv dt { color: var(--ink-3); }
.kv dd { margin: 0; text-align: right; font-family: var(--mono); font-size: 13px; overflow-wrap: anywhere; }

/* ---------- control ---------- */
.relay { display: grid; gap: 14px; }
.relay .state { font: 600 28px/1 var(--sans); }
.relay .state.on { color: var(--good); }
.relay .btns { display: flex; gap: 8px; flex-wrap: wrap; }

/* ---------- chart ---------- */
.chart { width: 100%; height: 240px; display: block; }
.chart text { fill: var(--ink-3); font: 11px var(--sans); }
.chart .grid { stroke: var(--line); stroke-width: 1; }
.chart .line { fill: none; stroke-width: 2.25; stroke-linejoin: round; stroke-linecap: round; }
.chart .area { opacity: .12; }
.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 1px; background: var(--line); border-top: 1px solid var(--line); }
.stats div { background: var(--surface); padding: 12px 16px; }
.stats b { display: block; font-size: 20px; font-variant-numeric: tabular-nums; }
.stats span { font-size: 12px; color: var(--ink-3); text-transform: uppercase; letter-spacing: .08em; }

/* ---------- sheet / dialog ---------- */
.sheet-backdrop { position: fixed; inset: 0; background: rgba(10, 20, 16, .45); z-index: 40; display: grid; align-items: end; justify-items: center; animation: fade .15s; }
@media (min-width: 700px) { .sheet-backdrop { align-items: center; } }
.sheet { width: 100%; max-width: 560px; max-height: 92vh; overflow: auto; background: var(--surface); border-radius: 22px 22px 0 0; padding: 22px 18px calc(22px + env(safe-area-inset-bottom)); animation: up .2s ease-out; }
@media (min-width: 700px) { .sheet { border-radius: 22px; padding: 28px; } }
.sheet-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; margin-bottom: 16px; }
.steps { display: flex; gap: 6px; margin-bottom: 16px; }
.steps i { height: 4px; flex: 1; border-radius: 4px; background: var(--line); }
.steps i.on { background: var(--accent); }
@keyframes fade { from { opacity: 0; } }
@keyframes up { from { transform: translateY(24px); opacity: 0; } }
.scanner { position: relative; border-radius: 16px; overflow: hidden; background: #000; aspect-ratio: 1; max-height: 52vh; margin: 0 auto; width: 100%; }
.scanner video { width: 100%; height: 100%; object-fit: cover; display: block; }
.scanner::after { content: ""; position: absolute; inset: 18%; border: 3px solid rgba(255,255,255,.9); border-radius: 18px; box-shadow: 0 0 0 999px rgba(0,0,0,.35); }
.pin { font: 700 34px/1 var(--mono); letter-spacing: .18em; text-align: center; padding: 14px; border-radius: 14px; background: var(--surface-2); border: 1px dashed var(--line-strong); }

/* ---------- loading screen ---------- */
.loader { position: fixed; inset: 0; z-index: 60; display: grid; place-content: center; justify-items: center; gap: 6px; background: var(--bg);
  transition: opacity .35s ease, visibility .35s; }
.loader.hidden { opacity: 0; visibility: hidden; pointer-events: none; }
.loader.overlay { background: color-mix(in srgb, var(--bg) 88%, transparent); backdrop-filter: blur(6px); }
.loader-mark { position: relative; width: 88px; height: 88px; margin-bottom: 18px; animation: breathe 2.4s ease-in-out infinite; }
.loader-mark svg { position: relative; border-radius: 24px; box-shadow: 0 12px 30px -14px rgba(25,61,49,.7); }
.loader-ring { position: absolute; inset: -10px; border-radius: 32px; border: 2px solid var(--accent); opacity: 0; animation: ring 2.4s ease-out infinite; }
.loader .draw { stroke-dasharray: 1; stroke-dashoffset: 1; animation: draw 2.4s ease-in-out infinite; }
.loader .d2 { animation-delay: .15s; } .loader .d3 { animation-delay: .3s; } .loader .d4 { animation-delay: .45s; }
.loader-brand { font: 700 13px/1 var(--sans); letter-spacing: .28em; color: var(--ink); }
.loader-text { font-size: 14px; color: var(--ink-3); min-height: 1.5em; }
@keyframes draw { 0% { stroke-dashoffset: 1; } 45%, 80% { stroke-dashoffset: 0; } 100% { stroke-dashoffset: -1; } }
@keyframes breathe { 0%, 100% { transform: scale(1); } 50% { transform: scale(1.04); } }
@keyframes ring { 0% { opacity: .55; transform: scale(.9); } 100% { opacity: 0; transform: scale(1.25); } }
@media (prefers-reduced-motion: reduce) { .loader-mark, .loader-ring, .loader .draw { animation: none; stroke-dashoffset: 0; } }

/* ---------- toast ---------- */
#toast { position: fixed; left: 50%; bottom: calc(88px + env(safe-area-inset-bottom)); transform: translateX(-50%) translateY(20px); opacity: 0; pointer-events: none;
  background: var(--ink); color: var(--bg); padding: 12px 18px; border-radius: 14px; font-weight: 500; max-width: calc(100vw - 32px); transition: .2s; z-index: 50; }
#toast.show { opacity: 1; transform: translateX(-50%); }
@media (min-width: 900px) { #toast { bottom: 28px; } }

/* ---------- empty / auth ---------- */
.empty { text-align: center; padding: 40px 20px; display: grid; gap: 12px; justify-items: center; }
.empty > svg { width: 48px; height: 48px; color: var(--ink-3); }
.auth { max-width: 440px; margin: 6vh auto 0; }
.auth .logo { width: 64px; height: 64px; margin-bottom: 20px; }
.btn.google { background: #fff; color: #1f1f1f; border-color: #dadce0; min-height: 50px; }
.btn.google:hover { background: #f7f8f8; }
.or { display: flex; align-items: center; gap: 12px; color: var(--ink-3); font-size: 13px; margin: 18px 0; }
.or::before, .or::after { content: ""; flex: 1; border-top: 1px solid var(--line); }
.skeleton { background: linear-gradient(90deg, var(--surface-2), var(--line), var(--surface-2)); background-size: 200% 100%; animation: shimmer 1.2s infinite; border-radius: 8px; min-height: 18px; }
@keyframes shimmer { to { background-position: -200% 0; } }
table.data { width: 100%; border-collapse: collapse; font-size: 14px; font-variant-numeric: tabular-nums; }
table.data th, table.data td { text-align: right; padding: 10px 14px; border-top: 1px solid var(--line); }
table.data th:first-child, table.data td:first-child { text-align: left; }
table.data th { color: var(--ink-3); font-weight: 600; font-size: 12px; text-transform: uppercase; letter-spacing: .06em; border-top: 0; }
.table-wrap { overflow-x: auto; }
@media print { .sidebar, .tabbar, .no-print, #toast { display: none !important; } main { padding: 0; } .card { box-shadow: none; } }
