@font-face { font-family: "Titillium Web"; font-weight: 400; src: url(/vendor/fonts/titillium-web-latin-400-normal.woff2) format("woff2"); font-display: swap; }
@font-face { font-family: "Titillium Web"; font-weight: 600; src: url(/vendor/fonts/titillium-web-latin-600-normal.woff2) format("woff2"); font-display: swap; }
@font-face { font-family: "Titillium Web"; font-weight: 700; src: url(/vendor/fonts/titillium-web-latin-700-normal.woff2) format("woff2"); font-display: swap; }
@font-face { font-family: "Titillium Web"; font-weight: 900; src: url(/vendor/fonts/titillium-web-latin-900-normal.woff2) format("woff2"); font-display: swap; }

:root {
  --tarmac: #15151c;
  --pit: #1d1d26;
  --pit-2: #262631;
  --line: #34343f;
  --kerb: #e10600;
  --kerb-dark: #a30400;
  --chalk: #f4f4f6;
  --mist: #9a9aa8;
  --watch: #27b5e8;
  --strap: #ff3b30;
  --flag-green: #13b26b;
  --flag-yellow: #ffd200;
  --flag-red: #e10600;
  --flag-grey: #6b6b78;
  --radius-s: 6px;
  --radius-l: 14px;
  --nav-h: 64px;
  --safe-b: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
[hidden] { display: none !important; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--tarmac);
  color: var(--chalk);
  font-family: "Titillium Web", system-ui, sans-serif;
  font-size: 15px;
  line-height: 1.45;
  font-variant-numeric: tabular-nums;
  overscroll-behavior-y: none;
}
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--watch); }
:focus-visible { outline: 2px solid var(--flag-yellow); outline-offset: 2px; }

/* ------------------------------------------------ top bar */
.topbar {
  position: sticky; top: 0; z-index: 1001;
  display: flex; align-items: center; gap: 12px;
  padding: 10px 16px 10px 0;
  background: var(--tarmac);
  border-bottom: 1px solid var(--line);
}
.brand {
  display: flex; align-items: center; gap: 10px;
  padding: 6px 18px 6px 16px;
  background: var(--kerb);
  clip-path: polygon(0 0, 100% 0, calc(100% - 14px) 100%, 0 100%);
  font-weight: 900; font-size: 18px; letter-spacing: .02em; font-style: italic; white-space: nowrap; flex: none;
}
.brand .chk { width: 18px; height: 18px; background:
  conic-gradient(#fff 25%, #000 0 50%, #fff 0 75%, #000 0) 0 0 / 9px 9px; border-radius: 2px; }
.topbar .driver-name { font-weight: 700; font-size: 16px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.topbar .spacer { flex: 1; }
.sim-switch { display: flex; align-items: center; gap: 8px; font-size: 13px; color: var(--mist); cursor: pointer; user-select: none; }
.sim-switch input { display: none; }
.sim-switch .track { width: 38px; height: 22px; border-radius: 11px; background: var(--pit-2); border: 1px solid var(--line); position: relative; transition: background .2s; }
.sim-switch .track::after { content: ""; position: absolute; top: 2px; left: 2px; width: 16px; height: 16px; border-radius: 50%; background: var(--mist); transition: transform .2s, background .2s; }
.sim-switch input:checked + .track { background: #4a3b00; border-color: var(--flag-yellow); }
.sim-switch input:checked + .track::after { transform: translateX(16px); background: var(--flag-yellow); }

.sim-banner {
  position: sticky; top: 59px; z-index: 1001;
  display: none; align-items: center; gap: 10px; padding: 6px 16px; font-size: 13px; font-weight: 700; color: #1a1400;
  background: repeating-linear-gradient(-45deg, var(--flag-yellow) 0 14px, #e8bf00 14px 28px);
}
body.sim .sim-banner { display: flex; }
.sim-banner span { flex: 1; }
.sim-banner button { border: 0; border-radius: 4px; background: #1a1400; color: var(--flag-yellow); font-weight: 700; padding: 4px 10px; cursor: pointer; }

/* ------------------------------------------------ layout */
main { padding: 16px 16px calc(var(--nav-h) + 24px + var(--safe-b)); max-width: 1180px; margin: 0 auto; }
h1 { font-size: 26px; font-weight: 900; font-style: italic; margin: 4px 0 14px; line-height: 1.1; }
h2 { font-size: 18px; font-weight: 700; margin: 22px 0 10px; }
h3 { font-size: 15px; font-weight: 700; margin: 0 0 8px; color: var(--chalk); }
.muted { color: var(--mist); }
.small { font-size: 13px; }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.grow { flex: 1; }
.grid-2 { display: grid; grid-template-columns: 1fr; gap: 14px; }
@media (min-width: 900px) { .grid-2 { grid-template-columns: 1fr 1fr; } }

.panel { background: var(--pit); border: 1px solid var(--line); border-radius: var(--radius-l); padding: 14px; position: relative; overflow: hidden; }
.panel.watch { border-top: 3px solid var(--watch); }
.panel.strap { border-top: 3px solid var(--strap); }
.panel + .panel { margin-top: 14px; }
.grid-2 > .panel + .panel { margin-top: 0; }
.panel-head { display: flex; align-items: center; gap: 10px; margin-bottom: 10px; }
.panel-head h3 { margin: 0; flex: 1; }

/* ------------------------------------------------ bottom nav */
.nav {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 1000;
  height: calc(var(--nav-h) + var(--safe-b)); padding-bottom: var(--safe-b);
  display: grid; grid-template-columns: repeat(5, 1fr);
  background: #101016; border-top: 1px solid var(--line);
}
.nav a { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  color: var(--mist); text-decoration: none; font-size: 12px; font-weight: 600; position: relative; }
.nav a svg { width: 22px; height: 22px; stroke: currentColor; fill: none; stroke-width: 1.8; }
.nav a.on { color: var(--chalk); }
.nav a.on::before { content: ""; position: absolute; top: 0; left: 22%; right: 22%; height: 3px; background: var(--kerb); }

/* ------------------------------------------------ controls */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-height: 42px; padding: 0 16px;
  border-radius: var(--radius-s); border: 1px solid var(--line); background: var(--pit-2); cursor: pointer; font-weight: 600; text-decoration: none; color: var(--chalk); }
.btn:hover { border-color: #55556a; }
.btn.primary { background: var(--kerb); border-color: var(--kerb); }
.btn.primary:hover { background: var(--kerb-dark); }
.btn.ghost { background: transparent; }
.btn.small { min-height: 34px; padding: 0 12px; font-size: 13px; }
.btn[disabled] { opacity: .5; pointer-events: none; }
.btn svg { width: 16px; height: 16px; stroke: currentColor; fill: none; stroke-width: 2; }

.field { display: flex; flex-direction: column; gap: 4px; margin-bottom: 12px; }
.field label { font-size: 13px; color: var(--mist); }
input, select, textarea { background: var(--tarmac); border: 1px solid var(--line); border-radius: var(--radius-s); padding: 10px 12px; min-height: 42px; width: 100%; }
textarea { min-height: 80px; resize: vertical; }

.seg { display: inline-flex; background: var(--tarmac); border: 1px solid var(--line); border-radius: var(--radius-s); padding: 3px; gap: 3px; }
.seg button { border: 0; background: transparent; padding: 7px 14px; border-radius: 4px; cursor: pointer; font-weight: 600; color: var(--mist); }
.seg button.on { background: var(--pit-2); color: var(--chalk); box-shadow: inset 0 -2px 0 var(--kerb); }
.seg button.on.watch { box-shadow: inset 0 -2px 0 var(--watch); }

.chips { display: flex; gap: 8px; overflow-x: auto; padding-bottom: 4px; scrollbar-width: none; }
.chip { flex: none; padding: 7px 14px; border-radius: 999px; border: 1px solid var(--line); background: var(--pit); cursor: pointer; font-weight: 600; white-space: nowrap; }
.chip.on { background: var(--chalk); color: var(--tarmac); border-color: var(--chalk); }
.chip .dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; background: var(--flag-green); margin-right: 6px; vertical-align: 1px; animation: blink 1.4s infinite; }
@keyframes blink { 50% { opacity: .25; } }

.tabs { display: flex; gap: 2px; overflow-x: auto; border-bottom: 1px solid var(--line); margin: 6px 0 16px; scrollbar-width: none; }
.tabs button { flex: none; border: 0; background: none; padding: 10px 14px; color: var(--mist); font-weight: 600; cursor: pointer; border-bottom: 3px solid transparent; }
.tabs button.on { color: var(--chalk); border-bottom-color: var(--kerb); }

.badge { display: inline-flex; align-items: center; gap: 5px; font-size: 12px; font-weight: 700; padding: 2px 8px; border-radius: 4px; background: var(--pit-2); color: var(--mist); }
.badge.watch { background: rgba(39,181,232,.15); color: var(--watch); }
.badge.strap { background: rgba(255,59,48,.15); color: var(--strap); }
.badge.live { background: var(--kerb); color: #fff; }
.badge.sim { background: var(--flag-yellow); color: #1a1400; }

/* ------------------------------------------------ the flag bar (signature element) */
.flag {
  display: flex; align-items: stretch; height: 54px; border-radius: var(--radius-s); overflow: hidden;
  background: var(--tarmac); border: 1px solid var(--line);
}
.flag .cloth { width: 74px; flex: none; position: relative; background: var(--flag-grey);
  clip-path: polygon(0 0, 100% 0, calc(100% - 16px) 100%, 0 100%); }
.flag .cloth::after { content: ""; position: absolute; inset: 0; background: linear-gradient(100deg, rgba(255,255,255,.25), transparent 40%, rgba(0,0,0,.18) 70%, transparent); }
.flag .txt { display: flex; flex-direction: column; justify-content: center; padding: 0 12px; min-width: 0; }
.flag .txt b { font-size: 19px; font-weight: 900; font-style: italic; line-height: 1.1; }
.flag .txt span { font-size: 12.5px; color: var(--mist); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.flag.green .cloth { background: var(--flag-green); }
.flag.yellow .cloth { background: var(--flag-yellow); }
.flag.red .cloth { background: var(--flag-red); animation: wave 1s ease-in-out infinite; }
.flag.baseline .cloth { background: conic-gradient(#fff 25%, #111 0 50%, #fff 0 75%, #111 0) 0 0 / 14px 14px; }
.flag.no_signal .cloth { background: repeating-linear-gradient(45deg, #444 0 8px, #2a2a2a 8px 16px); }
@keyframes wave { 50% { opacity: .65; } }
@media (prefers-reduced-motion: reduce) { .flag.red .cloth, .chip .dot { animation: none; } }

/* ------------------------------------------------ big numbers */
.hero-num { display: flex; align-items: baseline; gap: 8px; margin: 10px 0 4px; }
.hero-num .v { font-size: 64px; font-weight: 900; font-style: italic; line-height: .9; letter-spacing: -.02em; }
.hero-num .u { font-size: 16px; color: var(--mist); font-weight: 600; }
.hero-num .heart { width: 22px; height: 22px; fill: var(--strap); align-self: center; }
.panel.watch .hero-num .heart { fill: var(--watch); }
.beat { animation: beat .35s ease-out; }
@keyframes beat { 30% { transform: scale(1.25); } }

.tiles { display: grid; grid-template-columns: repeat(3, 1fr); gap: 1px; background: var(--line); border: 1px solid var(--line); border-radius: var(--radius-s); overflow: hidden; margin-top: 10px; }
.tile { background: var(--pit); padding: 9px 10px; min-width: 0; }
.tile .k { font-size: 12px; color: var(--mist); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tile .v { font-size: 20px; font-weight: 700; white-space: nowrap; }
.tile .v small { font-size: 12px; color: var(--mist); font-weight: 600; margin-left: 2px; }

.kpis { display: grid; grid-template-columns: repeat(2, 1fr); gap: 1px; background: var(--line); border: 1px solid var(--line); border-radius: var(--radius-l); overflow: hidden; }
@media (min-width: 700px) { .kpis { grid-template-columns: repeat(4, 1fr); } }
.kpis .tile { padding: 12px 14px; }
.kpis .tile .v { font-size: 24px; font-style: italic; font-weight: 900; }

/* ------------------------------------------------ ECG monitor */
.ecg-wrap { position: relative; margin-top: 12px; border-radius: var(--radius-s); overflow: hidden; border: 1px solid #3a2020; background: #120a0b; }
.ecg-wrap canvas { display: block; width: 100%; height: 170px; }
.ecg-wrap .tag { position: absolute; top: 6px; left: 8px; font-size: 12px; color: #f19a96; font-weight: 600; }
.ecg-wrap .lo { position: absolute; inset: 0; display: none; align-items: center; justify-content: center; background: rgba(18,10,11,.75); font-weight: 700; color: var(--flag-yellow); }
.ecg-wrap.off .lo { display: flex; }

.chart { width: 100%; height: 260px; }
.chart.tall { height: 380px; }
.chart.short { height: 170px; }
.map { width: 100%; height: 320px; border-radius: var(--radius-s); overflow: hidden; background: #222; isolation: isolate; position: relative; z-index: 0; }
.map.tall { height: 460px; }
.leaflet-container { background: #1a1a20; font-family: inherit; }

/* ------------------------------------------------ lists */
.list { display: flex; flex-direction: column; gap: 8px; }
.item { display: flex; align-items: center; gap: 12px; padding: 12px 14px; background: var(--pit); border: 1px solid var(--line); border-radius: var(--radius-s); cursor: pointer; text-decoration: none; color: inherit; }
.item:hover { border-color: #55556a; }
.item .src { width: 4px; align-self: stretch; border-radius: 2px; background: var(--strap); }
.item .src.watch { background: var(--watch); }
.item .main { flex: 1; min-width: 0; }
.item .main b { display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.item .meta { font-size: 13px; color: var(--mist); }
.empty { padding: 30px 16px; text-align: center; color: var(--mist); border: 1px dashed var(--line); border-radius: var(--radius-l); }

table.data { width: 100%; border-collapse: collapse; font-size: 14px; }
table.data th, table.data td { padding: 8px 10px; border-bottom: 1px solid var(--line); text-align: left; }
table.data th { color: var(--mist); font-weight: 600; font-size: 13px; }
table.data td.num { text-align: right; font-weight: 600; }
.table-scroll { overflow-x: auto; }

/* ------------------------------------------------ AI */
.ai-text { line-height: 1.6; }
.ai-text h4 { margin: 14px 0 6px; font-size: 16px; }
.ai-text ul { padding-left: 20px; margin: 6px 0; }
.chat { display: flex; flex-direction: column; gap: 10px; min-height: 40vh; }
.msg { max-width: 88%; padding: 10px 14px; border-radius: 14px; white-space: normal; }
.msg.user { align-self: flex-end; background: var(--kerb); border-bottom-right-radius: 4px; }
.msg.assistant { align-self: flex-start; background: var(--pit); border: 1px solid var(--line); border-bottom-left-radius: 4px; }
.chat-input { position: sticky; bottom: calc(var(--nav-h) + var(--safe-b) + 8px); display: flex; gap: 8px; margin-top: 14px; background: var(--tarmac); padding-top: 8px; }
.chat-input textarea { min-height: 46px; height: 46px; }
.typing { display: inline-flex; gap: 4px; }
.typing i { width: 7px; height: 7px; border-radius: 50%; background: var(--mist); animation: blink 1s infinite; }
.typing i:nth-child(2) { animation-delay: .2s; } .typing i:nth-child(3) { animation-delay: .4s; }

/* ------------------------------------------------ login */
.login { min-height: 100vh; display: grid; place-items: center; padding: 24px 16px;
  background: repeating-linear-gradient(90deg, var(--kerb) 0 34px, var(--chalk) 34px 68px) top / 100% 10px no-repeat, var(--tarmac); }
.agree { display: grid; gap: 1px; background: var(--line); border: 1px solid var(--line); border-radius: var(--radius-s); overflow: hidden; }
.agree .r { background: var(--pit); padding: 10px 12px; display: grid; grid-template-columns: 1fr 1fr 1fr 1fr; gap: 4px 10px; }
.agree .r b { grid-column: 1 / -1; font-size: 15px; }
.agree .r .k { font-size: 12px; color: var(--mist); }
.agree .r .v { font-weight: 700; font-size: 15px; white-space: nowrap; }
.login .box { width: 100%; max-width: 380px; }
.login .title { font-size: 40px; font-weight: 900; font-style: italic; line-height: 1; margin: 18px 0 6px; }
.login .sub { color: var(--mist); margin: 0 0 26px; }
.err { color: #ff8a84; font-size: 14px; min-height: 20px; margin-bottom: 8px; }

.toast { z-index: 1100 !important; position: fixed; left: 50%; bottom: calc(var(--nav-h) + 20px + var(--safe-b)); transform: translateX(-50%); background: var(--chalk); color: var(--tarmac); padding: 10px 16px; border-radius: 8px; font-weight: 600; z-index: 100; box-shadow: 0 6px 24px rgba(0,0,0,.4); }
.spinner { width: 22px; height: 22px; border: 3px solid var(--line); border-top-color: var(--kerb); border-radius: 50%; animation: spin .8s linear infinite; display: inline-block; vertical-align: middle; }
@keyframes spin { to { transform: rotate(360deg); } }
.loading { padding: 40px; text-align: center; color: var(--mist); }

.legend { display: flex; gap: 14px; font-size: 13px; color: var(--mist); flex-wrap: wrap; }
.legend i { display: inline-block; width: 12px; height: 3px; vertical-align: middle; margin-right: 5px; }
