/* Plaid dashboard, v2 look: black grid, glowing cyan data, Space Grotesk + JetBrains Mono. */
:root {
  --bg: #04060A;
  --panel: rgba(10, 16, 24, 0.88);
  --line: rgba(79, 227, 255, 0.16);
  --line-soft: rgba(79, 227, 255, 0.10);
  --grid: rgba(79, 227, 255, 0.045);
  --cyan: #4FE3FF;
  --cyan-hi: #A8F2FF;
  --violet: #B3A8FF;
  --green: #5CF2B0;
  --amber: #FFB547;
  --red: #FF5C7A;
  --text: #EAF2F8;
  --text-2: #C9D4DF;
  --muted: #8A97A6;
  --track: #132131;
  --sans: 'Space Grotesk', system-ui, sans-serif;
  --mono: 'JetBrains Mono', ui-monospace, monospace;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; }
body {
  background-color: var(--bg);
  background-image: linear-gradient(var(--grid) 1px, transparent 1px), linear-gradient(90deg, var(--grid) 1px, transparent 1px);
  background-size: 24px 24px;
  background-attachment: fixed;
  color: var(--text);
  font-family: var(--sans);
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}
a { color: var(--cyan); }
a:hover { color: var(--cyan-hi); }
button { font: inherit; color: inherit; }
svg text { font-family: var(--sans); }
svg .m { font-family: var(--mono); }

#app { max-width: 560px; margin: 0 auto; padding: max(16px, env(safe-area-inset-top)) 16px calc(96px + env(safe-area-inset-bottom)); display: flex; flex-direction: column; gap: 12px; }

.k { font-family: var(--mono); font-size: 10.5px; letter-spacing: 0.14em; text-transform: uppercase; color: var(--muted); }
.t { font-size: 12.5px; color: var(--muted); line-height: 1.45; }
.mono { font-family: var(--mono); }
.glow { text-shadow: 0 0 22px rgba(79, 227, 255, 0.55); }
.cyan { color: var(--cyan); } .amber { color: var(--amber); } .green { color: var(--green); } .violet { color: var(--violet); } .red { color: var(--red); }

.pn { background: var(--panel); border: 1px solid var(--line); border-radius: 18px; padding: 16px; display: flex; flex-direction: column; gap: 8px; min-width: 0; }
.pn.warn { border-color: rgba(255, 181, 71, 0.45); }
.row { display: flex; justify-content: space-between; align-items: center; gap: 10px; }
.row.end { align-items: flex-end; }
.grid2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
.grid3 { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; }
.grid4 { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 6px; }
.big { font-weight: 700; letter-spacing: -0.03em; line-height: 1; }
.stack { display: flex; flex-direction: column; gap: 2px; }
.center { text-align: center; }
.chart { width: 100%; height: auto; display: block; }

.head { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; }
.head h1 { margin: 0; font-size: 22px; font-weight: 700; letter-spacing: -0.01em; }
.badge { font-family: var(--mono); font-size: 10px; font-weight: 700; letter-spacing: 0.1em; color: var(--amber); border: 1px solid var(--amber); border-radius: 4px; padding: 3px 6px; white-space: nowrap; }

.live { width: 8px; height: 8px; border-radius: 50%; background: var(--green); box-shadow: 0 0 10px var(--green); animation: pulse 1.6s infinite; flex: none; }
.live.off { background: var(--muted); box-shadow: none; animation: none; }
@keyframes pulse { 0%, 100% { opacity: 1; } 50% { opacity: 0.35; } }
@media (prefers-reduced-motion: reduce) { .live, .pulse { animation: none; } }

/* Source chips: exact field + channel + age */
.srcs { display: flex; flex-wrap: wrap; gap: 4px; }
body.hide-src .srcs { display: none; }
.src { font-family: var(--mono); font-size: 10px; color: var(--cyan); border: 1px solid rgba(79, 227, 255, 0.35); border-radius: 4px; padding: 1px 5px; white-space: nowrap; }
.src.api { color: var(--violet); border-color: rgba(179, 168, 255, 0.4); }
.src.ble { color: var(--green); border-color: rgba(92, 242, 176, 0.4); }
.src.sample { color: var(--amber); border-color: rgba(255, 181, 71, 0.4); }
.src.stale { opacity: 0.55; }
.src.none { color: var(--muted); border-color: rgba(138, 151, 166, 0.35); }

.seg-bar { display: flex; gap: 3px; }
.seg { flex: 1; height: 22px; border-radius: 2px; background: #142030; }
.seg.on { background: var(--cyan); box-shadow: 0 0 8px rgba(79, 227, 255, 0.6); }
.seg.limit { box-shadow: inset 2px 0 0 var(--text); }

.st { display: grid; grid-template-columns: 62px minmax(0, 1fr) auto; gap: 8px; font-family: var(--mono); font-size: 11.5px; padding: 3px 0; color: var(--text-2); }
.st .f { color: var(--cyan); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.st .ts { color: var(--muted); }

.list-row { display: flex; justify-content: space-between; align-items: center; gap: 10px; padding: 10px 0; border-top: 1px solid var(--line-soft); font-size: 14px; }
.list-row:first-of-type { border-top: none; }
.trip { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 4px 10px; padding: 12px 0; border-top: 1px solid var(--line-soft); text-decoration: none; color: var(--text); }

.insight { display: flex; gap: 12px; align-items: center; text-decoration: none; color: var(--text); min-height: 44px; }
.insight svg { flex: none; }

.bigbtn:active { transform: scale(0.96); }
.bigbtn[aria-busy='true'] { opacity: 0.5; }
.bigbtn { flex: 1; min-height: 56px; border-radius: 16px; border: 1px solid rgba(79, 227, 255, 0.35); background: rgba(79, 227, 255, 0.06); color: var(--cyan); font: 600 13px var(--mono); letter-spacing: 0.1em; text-transform: uppercase; display: flex; align-items: center; justify-content: center; gap: 10px; cursor: pointer; padding: 0 12px; }
.bigbtn.ghost { color: var(--text-2); border-color: var(--line); background: transparent; }

.switch { display: flex; gap: 6px; border: 1px solid var(--line); border-radius: 14px; padding: 4px; background: var(--panel); }
.switch a { flex: 1; min-height: 44px; display: flex; align-items: center; justify-content: center; border-radius: 12px; text-decoration: none; font-family: var(--mono); font-size: 11px; letter-spacing: 0.14em; text-transform: uppercase; color: var(--muted); border: 1px solid transparent; }
.switch a.on { background: rgba(79, 227, 255, 0.10); color: var(--cyan); border-color: rgba(79, 227, 255, 0.35); }

.th { display: grid; grid-template-columns: 96px minmax(0, 1fr) 52px; gap: 10px; align-items: center; font-family: var(--mono); font-size: 11px; color: var(--text-2); }
.bar { height: 6px; border-radius: 3px; background: var(--track); overflow: hidden; }
.bar > div { height: 6px; border-radius: 3px; background: var(--cyan); }

.dock { position: fixed; left: 12px; right: 12px; bottom: max(12px, env(safe-area-inset-bottom)); max-width: 536px; margin: 0 auto; display: flex; border: 1px solid rgba(79, 227, 255, 0.18); border-radius: 24px; background: rgba(10, 16, 24, 0.96); backdrop-filter: blur(10px); padding: 4px; z-index: 10; }
.tab { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px; font-family: var(--mono); font-size: 9.5px; letter-spacing: 0.08em; text-transform: uppercase; color: var(--muted); text-decoration: none; min-height: 52px; border-radius: 20px; }
.tab.on { color: var(--cyan); background: rgba(79, 227, 255, 0.08); }

.toast { position: fixed; left: 50%; bottom: 96px; transform: translateX(-50%); background: rgba(10, 16, 24, 0.97); border: 1px solid var(--line); border-radius: 12px; padding: 10px 14px; font-size: 13px; z-index: 20; max-width: calc(100% - 32px); }
.toast.err { border-color: rgba(255, 92, 122, 0.6); color: var(--red); }

input, select { font: inherit; color: var(--text); background: rgba(4, 6, 10, 0.8); border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; min-height: 44px; width: 100%; }
label { display: flex; flex-direction: column; gap: 6px; font-size: 13px; color: var(--text-2); }
.check { flex-direction: row; align-items: center; gap: 10px; }
.check input { width: 20px; min-height: 20px; }
pre { font-family: var(--mono); font-size: 11px; color: var(--text-2); white-space: pre-wrap; word-break: break-all; margin: 0; max-height: 320px; overflow: auto; }
.empty { padding: 18px 4px; text-align: center; color: var(--muted); font-size: 13px; }

/* Car browser, parked: full-screen three-column dashboard (also used on wide screens). */
body.wide #app { max-width: none; padding: 20px 28px; height: 100vh; }
body.wide .dock { display: none; }
.car { display: grid; grid-template-columns: 330px minmax(0, 1fr) 330px; gap: 20px; flex: 1; min-height: 0; }
.car .pn { padding: 20px; gap: 10px; border-radius: 20px; }
.car .k { font-size: 12px; }
.kv { display: flex; justify-content: space-between; align-items: baseline; padding: 9px 0; border-top: 1px solid var(--line-soft); font-size: 18px; }
.car-top { display: flex; justify-content: space-between; align-items: center; gap: 18px; }
.car-nav { display: flex; gap: 8px; }
.car-nav a { font-family: var(--mono); font-size: 12px; letter-spacing: 0.1em; text-transform: uppercase; color: var(--muted); text-decoration: none; padding: 10px 14px; border: 1px solid var(--line); border-radius: 12px; }

/* Car browser, driving: glance view. */
.glance { display: grid; grid-template-columns: minmax(0, 1fr) minmax(280px, 420px); gap: 24px; flex: 1; min-height: 0; }
.glance .pn { padding: 26px; border-radius: 24px; }
.glance .k { font-size: 14px; }
.glance-main { display: grid; grid-template-columns: auto minmax(0, 1fr); align-items: center; gap: 32px; }
.glance-ring { width: min(340px, 45vh); height: auto; }

@media (max-width: 1100px) {
  .car { grid-template-columns: 1fr 1fr; }
  .car > :nth-child(2) { grid-column: 1 / -1; order: -1; }
}
@media (max-width: 760px) {
  .glance { grid-template-columns: 1fr; }
  .glance-main { grid-template-columns: 1fr; justify-items: center; }
}

/* Software and Alerts screens */
.tile { text-decoration: none; color: var(--text); gap: 6px; min-height: 96px; }
.tile:hover { border-color: rgba(79, 227, 255, 0.4); color: var(--text); }
.bigbtn.slim { flex: none; min-height: 44px; padding: 0 18px; }
.bigbtn[disabled] { opacity: 0.4; cursor: not-allowed; }
.update { display: flex; flex-direction: column; gap: 10px; padding: 14px; border: 1px solid rgba(255, 181, 71, 0.45); border-radius: 14px; background: rgba(255, 181, 71, 0.05); }
.update .bigbtn { color: var(--amber); border-color: rgba(255, 181, 71, 0.5); background: rgba(255, 181, 71, 0.08); }
.note { display: flex; flex-direction: column; gap: 10px; padding: 14px 0; border-top: 1px solid var(--line-soft); }
.note.first { border-top: none; }
.note h2 { margin: 0; font-size: 17px; font-weight: 600; letter-spacing: -0.01em; }
.note img { width: 100%; border-radius: 12px; border: 1px solid var(--line); }
.note .body { font-size: 14px; line-height: 1.55; color: var(--text-2); }
.note .body p { margin: 0 0 8px; }
.ver { font-family: var(--mono); font-size: 11px; color: var(--cyan); border: 1px solid rgba(79, 227, 255, 0.35); border-radius: 6px; padding: 2px 7px; white-space: nowrap; box-shadow: 0 0 10px rgba(79, 227, 255, 0.15); }
.day { padding: 10px 0 2px; color: var(--cyan); }
.alert { display: grid; grid-template-columns: 46px minmax(0, 1fr); gap: 10px; padding: 10px 0; border-top: 1px solid var(--line-soft); }
.alert .ts { font-family: var(--mono); font-size: 12px; color: var(--muted); padding-top: 2px; }
.alert .code { font-family: var(--mono); font-size: 11px; color: var(--text-2); overflow-wrap: anywhere; }
.aud { font-family: var(--mono); font-size: 10px; letter-spacing: 0.06em; text-transform: uppercase; color: var(--cyan); border: 1px solid rgba(79, 227, 255, 0.3); border-radius: 4px; padding: 1px 6px; display: inline-flex; align-items: center; gap: 5px; }
.aud.svc { color: var(--violet); border-color: rgba(179, 168, 255, 0.4); }
.aud.live-tag { color: var(--amber); border-color: rgba(255, 181, 71, 0.5); }
.aud.live-tag .live { background: var(--amber); box-shadow: 0 0 8px var(--amber); }
.aud.ended { color: var(--muted); border-color: rgba(138, 151, 166, 0.35); }

/* Signal history: tappable stream rows and chips, and the sheet they open. */
button.st { background: none; border: 0; border-top: 1px solid transparent; text-align: left; cursor: pointer; min-height: 34px; align-items: center; padding: 6px 4px; margin: 0 -4px; width: calc(100% + 8px); border-radius: 8px; }
button.st:hover, button.st:focus-visible { background: rgba(79, 227, 255, 0.07); outline: none; }
button.st:focus-visible { box-shadow: 0 0 0 1px rgba(79, 227, 255, 0.6); }
.st .chev { color: var(--cyan); opacity: 0.6; margin-left: 4px; }
.src[data-action] { cursor: pointer; }
.src[data-action]:hover, .src[data-action]:focus-visible { background: rgba(79, 227, 255, 0.10); outline: none; }

body.sheet-open { overflow: hidden; }
.sheet-bg { position: fixed; inset: 0; background: rgba(2, 4, 8, 0.72); backdrop-filter: blur(3px); z-index: 30; }
.sheet { position: fixed; left: 0; right: 0; bottom: 0; z-index: 31; max-width: 560px; margin: 0 auto; max-height: 88vh; overflow-y: auto; border-radius: 22px 22px 0 0; border-bottom: none; padding: 18px 16px calc(20px + env(safe-area-inset-bottom)); gap: 12px; background: rgba(8, 13, 20, 0.98); box-shadow: 0 -12px 40px rgba(79, 227, 255, 0.12); }
/* Animate only on open: live updates re-render the sheet every second. */
.sheet-bg.enter { animation: fade 0.18s ease-out; }
.sheet.enter { animation: rise 0.22s ease-out; }
.sheet::before { content: ''; align-self: center; width: 40px; height: 4px; border-radius: 2px; background: rgba(79, 227, 255, 0.3); margin: -8px 0 2px; }
.sheet-field { font-size: 18px; font-weight: 700; overflow-wrap: anywhere; }
.sheet-x { flex: none; width: 44px; height: 44px; border-radius: 50%; border: 1px solid var(--line); background: transparent; color: var(--muted); cursor: pointer; font-size: 16px; }
.sheet-x:hover, .sheet-x:focus-visible { color: var(--cyan); border-color: rgba(79, 227, 255, 0.5); outline: none; }
.sheet .switch a { min-height: 40px; }
.sheet .stat { padding: 10px; border-radius: 12px; gap: 4px; }
.sheet .st { grid-template-columns: 110px minmax(0, 1fr) auto; border-top: 1px solid var(--line-soft); padding: 6px 0; }
.legend { display: flex; flex-wrap: wrap; gap: 6px 14px; font-family: var(--mono); font-size: 11px; color: var(--text-2); }
.legend i { display: inline-block; width: 9px; height: 9px; border-radius: 2px; margin-right: 6px; vertical-align: -1px; }
.legend b { color: var(--muted); font-weight: 500; }
body.wide .sheet { bottom: auto; top: 50%; transform: translateY(-50%); max-width: 640px; border-radius: 22px; border-bottom: 1px solid var(--line); }
body.wide .sheet.enter { animation: fade 0.18s ease-out; }
body.wide .sheet::before { display: none; }
@keyframes rise { from { transform: translateY(24px); opacity: 0; } to { transform: none; opacity: 1; } }
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }
@media (prefers-reduced-motion: reduce) { .sheet, .sheet-bg { animation: none; } }
