:root {
  --bg: #f6f7f9; --surface: #ffffff; --text: #16191d; --muted: #5f6873; --line: #e3e6ea;
  --accent: #1f6feb; --accent-ink: #ffffff; --good: #1a7f4b; --bad: #c2410c; --warn-bg: #fff7e6;
  --ok-bg: #eaf6ef; --err-bg: #fdecec; --chip: #eef2f7; --radius: 10px;
  --c1: #1f6feb; --c2: #9aa4b1; --c3: #2f9e6e; --c4: #e8890c; --c5: #8b5cf6;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1216; --surface: #171b21; --text: #e6e9ee; --muted: #9aa3ae; --line: #2a3038;
    --accent: #4c8dff; --accent-ink: #0b0d10; --good: #4cc38a; --bad: #ff8a5c; --warn-bg: #2d2412;
    --ok-bg: #12291d; --err-bg: #331718; --chip: #222831;
    --c1: #4c8dff; --c2: #6b7480; --c3: #4cc38a; --c4: #f5a524; --c5: #a78bfa;
    color-scheme: dark;
  }
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--text);
  font: 15px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, Roboto, sans-serif; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 24px; margin: 0 0 4px; letter-spacing: -0.01em; }
h2 { font-size: 15px; margin: 0 0 12px; font-weight: 600; }
code, pre { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 13px; }
code { background: var(--chip); padding: 1px 5px; border-radius: 4px; }
.muted { color: var(--muted); }
.small { font-size: 13px; }

.top { display: flex; align-items: center; gap: 24px; padding: 12px 24px; background: var(--surface);
  border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 5; flex-wrap: wrap; }
.brand { font-weight: 700; color: var(--text); }
.top nav { display: flex; gap: 4px; flex-wrap: wrap; }
.top nav a { color: var(--muted); padding: 6px 10px; border-radius: 8px; }
.top nav a.on, .top nav a:hover { color: var(--text); background: var(--chip); text-decoration: none; }
.logout { margin-left: auto; display: flex; align-items: center; gap: 10px; }
.who { color: var(--muted); font-size: 13px; }

main { max-width: 1200px; margin: 0 auto; padding: 24px; }
main.narrow { max-width: 420px; padding-top: 12vh; }
.pagehead { display: flex; justify-content: space-between; align-items: flex-end; gap: 16px; margin-bottom: 16px; flex-wrap: wrap; }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px 20px; margin-bottom: 16px; }
.grid2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; }
.grid2 .card { margin: 0; }
.grid2 canvas { width: 100% !important; height: 220px !important; }
.vo2-card { margin-top: 16px; }
.vo2-card canvas { width: 100% !important; height: 240px !important; }
@media (max-width: 860px) { .grid2 { grid-template-columns: 1fr; } }

.seg { display: inline-flex; background: var(--chip); border-radius: 8px; padding: 3px; }
.seg a { padding: 4px 10px; border-radius: 6px; color: var(--muted); font-size: 13px; }
.seg a.on { background: var(--surface); color: var(--text); box-shadow: 0 1px 2px rgba(0,0,0,.08); text-decoration: none; }

.kpis { display: grid; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: 12px; margin-bottom: 6px; }
.kpi { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 14px; border-top: 3px solid var(--line); }
.kpi.good { border-top-color: var(--good); }
.kpi.bad { border-top-color: var(--bad); }
.kpi-label { color: var(--muted); font-size: 12px; }
.kpi-value { font-size: 26px; font-weight: 650; font-variant-numeric: tabular-nums; }
.kpi-value .unit { font-size: 13px; color: var(--muted); margin-left: 3px; font-weight: 400; }
.kpi-sub { font-size: 12px; color: var(--muted); min-height: 18px; }
.kpi.bad .kpi-sub { color: var(--bad); }
.kpi.good .kpi-sub { color: var(--good); }

table { width: 100%; border-collapse: collapse; font-size: 14px; }
th, td { text-align: left; padding: 7px 8px; border-bottom: 1px solid var(--line); white-space: nowrap; }
th { color: var(--muted); font-weight: 500; font-size: 12px; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
.scroll { overflow-x: auto; }
.actions { display: flex; gap: 12px; align-items: flex-start; }

.alerts { list-style: none; padding: 0; margin: 0; }
.alerts li { padding: 6px 0; border-bottom: 1px solid var(--line); display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.alerts .date { font-variant-numeric: tabular-nums; color: var(--muted); width: 96px; }
.tag { background: var(--err-bg); color: var(--bad); border-radius: 999px; padding: 1px 9px; font-size: 12px; }

input, textarea, select { font: inherit; color: var(--text); background: var(--surface); border: 1px solid var(--line);
  border-radius: 8px; padding: 8px 10px; }
input:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
textarea { width: 100%; resize: vertical; }
label { display: flex; flex-direction: column; gap: 4px; font-size: 13px; color: var(--muted); }
label.check { flex-direction: row; align-items: center; gap: 6px; }
.stack { display: flex; flex-direction: column; gap: 12px; }
.narrowform { max-width: 360px; }
.row { display: flex; gap: 10px; align-items: center; justify-content: space-between; margin-top: 10px; }
.row.wrap { flex-wrap: wrap; justify-content: flex-start; }
form.inline, details.inline { display: inline; }
button { font: inherit; cursor: pointer; border-radius: 8px; border: 1px solid var(--line); background: var(--surface); color: var(--text); padding: 8px 14px; }
button.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); font-weight: 600; }
button.primary:disabled { opacity: .6; cursor: wait; }
button.danger { background: var(--bad); border-color: var(--bad); color: #fff; }
button.ghost { background: transparent; }
button.link, summary.link { background: none; border: 0; padding: 0; color: var(--accent); cursor: pointer; }
.danger, summary.danger { color: var(--bad); }
button.link.danger { color: var(--bad); }
button.chip { background: var(--chip); border: 0; border-radius: 999px; padding: 6px 12px; margin: 3px 4px 3px 0; font-size: 14px; }

.flash { padding: 10px 14px; border-radius: 8px; margin-bottom: 14px; background: var(--ok-bg); }
.flash.error { background: var(--err-bg); color: var(--bad); }
.flash.warn { background: var(--warn-bg); }
.pre { background: var(--chip); border-radius: 8px; padding: 12px; overflow-x: auto; white-space: pre-wrap; word-break: break-word; margin: 8px 0; }

.chat { display: flex; flex-direction: column; gap: 12px; }
.msg { max-width: 860px; padding: 12px 16px; border-radius: 12px; }
.msg.user { align-self: flex-end; background: var(--accent); color: var(--accent-ink); }
.msg.user .txt { white-space: pre-wrap; }
.msg.assistant { background: var(--surface); border: 1px solid var(--line); }
.msg .meta { color: var(--muted); font-size: 12px; margin-top: 6px; }
.md p { margin: 0 0 10px; } .md ul, .md ol { margin: 0 0 10px; padding-left: 22px; }
.md h1, .md h2, .md h3 { font-size: 16px; margin: 14px 0 6px; }
.md table { margin: 8px 0; } .md th, .md td { white-space: normal; }
.chat.busy .ask { position: static; }
#pending { display: flex; flex-direction: column; gap: 12px; }
#pending[hidden], .hints[hidden] { display: none; }
.msg.thinking { color: var(--muted); display: flex; align-items: center; gap: 10px; }
.dots { display: inline-flex; gap: 4px; }
.dots i { width: 6px; height: 6px; border-radius: 50%; background: var(--muted); animation: blink 1.2s infinite ease-in-out; }
.dots i:nth-child(2) { animation-delay: .2s; } .dots i:nth-child(3) { animation-delay: .4s; }
@keyframes blink { 0%, 80%, 100% { opacity: .25; } 40% { opacity: 1; } }
@media (prefers-reduced-motion: reduce) { .dots i { animation: none; opacity: .6; } }
button { transition: transform .08s ease, filter .12s ease, background-color .12s ease, box-shadow .12s ease; }
button:hover:not(:disabled) { filter: brightness(.96); }
button.primary:hover:not(:disabled), button.danger:hover:not(:disabled) { filter: brightness(1.08); }
button:active:not(:disabled) { transform: scale(.96); filter: brightness(.9); }
button.chip:hover:not(:disabled) { background: color-mix(in srgb, var(--accent) 12%, var(--chip)); filter: none; }
button.chip:active:not(:disabled) { background: color-mix(in srgb, var(--accent) 22%, var(--chip)); }
button.link:active:not(:disabled) { transform: none; filter: none; opacity: .7; }
button:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
button:disabled { opacity: .6; cursor: default; }
@media (prefers-reduced-motion: reduce) { button { transition: none; } button:active:not(:disabled) { transform: none; } }
.ask { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px; position: sticky; bottom: 12px; }
.revoke { text-align: right; }

.watch-status .ws-head { display: flex; align-items: center; gap: 14px; flex-wrap: wrap; }
.ws-action { margin-left: auto; }
.ws-state { font-size: 18px; font-weight: 600; }
.ws-dot { width: 12px; height: 12px; border-radius: 50%; background: var(--c2); flex: none; }
.state-idle .ws-dot, .state-ready .ws-dot, .state-done .ws-dot { background: var(--good); }
.state-connecting .ws-dot, .state-copying .ws-dot, .state-building .ws-dot, .state-uploading .ws-dot {
  background: var(--accent); animation: blink 1.2s infinite ease-in-out; }
.state-error .ws-dot { background: var(--bad); }
.state-offline .ws-state { color: var(--muted); }
.ws-progress { margin-top: 14px; }
.bar { height: 8px; background: var(--chip); border-radius: 999px; overflow: hidden; }
.bar .fill { height: 100%; background: var(--accent); transition: width .4s ease; }
.ws-message { margin: 12px 0 0; }
.ws-connect { margin: 12px 0 0; display: flex; align-items: center; gap: 8px; font-size: 14px; }
.ws-connect[hidden] { display: none; }
.ws-cdot { width: 8px; height: 8px; border-radius: 50%; background: var(--c2); flex: none; }
.ws-connect.tone-ok .ws-cdot { background: var(--good); }
.ws-connect.tone-busy .ws-cdot { background: var(--accent); animation: blink 1.2s infinite ease-in-out; }
.ws-connect.tone-warn { color: var(--bad); }
.ws-connect.tone-warn .ws-cdot { background: var(--bad); }
.ws-connect.tone-muted { color: var(--muted); }
.ws-hint { margin: 12px 0 0; }
details.card summary { cursor: pointer; }
details.card[open] summary { margin-bottom: 10px; }
.steps li { margin-bottom: 8px; }
.login h1 { margin-bottom: 6px; }
.empty ol { padding-left: 20px; }
.danger-zone { border-color: color-mix(in srgb, var(--bad) 35%, var(--line)); }

@media (max-width: 600px) {
  main { padding: 16px; }
  .top { padding: 10px 16px; gap: 10px; }
  .logout { margin-left: 0; }
}

/* ── sign-in page: split screen, dark data panel + form ─────────────────── */
body.auth-page { background: var(--surface); }
main.auth { max-width: none; padding: 0; min-height: 100dvh; display: grid; grid-template-columns: minmax(0, 1.15fr) minmax(0, 1fr); }
.auth-hero {
  --hero-text: #f3f5f8; --hero-muted: #c9d3df; --hero-accent: #4c8dff;
  position: relative; overflow: hidden; color: var(--hero-text);
  display: grid; grid-template-rows: auto 1fr auto; padding: 40px 48px 0;
  background: #0b1322;
}
.auth-hero > :not(.auth-slides) { position: relative; z-index: 1; }
/* Photos (Unsplash License): Venti Views H9xlJ23Vx8U, hannahcarr I079C4gOe8s, Jakub Kriz 3FFEdm8TOek */
.auth-slides { position: absolute; inset: 0; z-index: 0; }
.auth-slides::after { content: ""; position: absolute; inset: 0; pointer-events: none;
  background:
    linear-gradient(90deg, rgb(9 15 27 / .55) 0%, rgb(9 15 27 / .22) 45%, rgb(9 15 27 / 0) 70%),
    linear-gradient(180deg, rgb(9 15 27 / .25) 0%, rgb(9 15 27 / 0) 20%, rgb(9 15 27 / 0) 70%, rgb(9 15 27 / .7) 100%); }
.auth-slide { position: absolute; inset: 0; background: 50% 50% / cover no-repeat; opacity: 0; transition: opacity 1.2s ease; }
.auth-slide.on { opacity: 1; }
.auth-slide:nth-child(1) { background-position: 50% 6%; filter: brightness(.88); }
.auth-slide:nth-child(2) { background-size: 140% auto; background-position: 0% 58%; }
.auth-slide:nth-child(3) { background-size: 140% auto; background-position: 5% 80%; filter: brightness(1.7) saturate(1.15); }
.auth-foot { position: absolute !important; left: 48px; right: 24px; bottom: 18px; display: flex; align-items: center; gap: 16px; }
.auth-dots { display: flex; gap: 6px; }
.auth-dots button { width: 28px; height: 18px; padding: 0; border: 0; background: none; cursor: pointer; position: relative; border-radius: 0; }
.auth-dots button::before, .auth-dots button i { content: ""; position: absolute; left: 0; right: 0; top: 7px; height: 3px; border-radius: 3px; }
.auth-dots button::before { background: rgb(255 255 255 / .3); }
.auth-dots button i { background: #fff; transform: scaleX(0); transform-origin: left; }
.auth-dots button.done i { transform: scaleX(1); }
.auth-dots button.on i { animation: auth-progress var(--slide-ms, 7000ms) linear forwards; }
.auth-dots button:active { transform: none; filter: none; }
.auth-dots button:focus-visible { outline: 2px solid #fff; outline-offset: 2px; }
.auth-credit { margin: 0 0 0 auto; font-size: 11px; color: rgb(238 242 247 / .6); }
.auth-credit a { color: inherit; }
@keyframes auth-progress { from { transform: scaleX(0); } to { transform: scaleX(1); } }
.auth-brand { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 16px; letter-spacing: -0.01em; }
.auth-mark { width: 30px; height: 30px; flex: none; }
.auth-mark rect { fill: var(--hero-accent); }
.auth-mark path { fill: none; stroke: #fff; stroke-width: 2.4; stroke-linecap: round; stroke-linejoin: round; }
.auth-pitch { align-self: center; max-width: 30rem; padding: 48px 0; }
.auth-pitch h1 { font-size: clamp(32px, 3.6vw, 50px); line-height: 1.06; font-weight: 800; letter-spacing: -0.03em; margin: 0 0 18px; }
.auth-pitch p { color: var(--hero-muted); font-size: 17px; line-height: 1.55; margin: 0; max-width: 26rem; }
.auth-pitch h1 { text-shadow: 0 2px 24px rgb(9 15 27 / .55), 0 1px 3px rgb(9 15 27 / .4); }
.auth-pitch p { text-shadow: 0 1px 14px rgb(9 15 27 / .75), 0 1px 2px rgb(9 15 27 / .5); }
.auth-trace { display: block; width: calc(100% + 96px); margin: 0 -48px; height: 150px; color: var(--hero-accent); }
.auth-trace .line { fill: none; stroke: var(--hero-accent); stroke-width: 2.5; vector-effect: non-scaling-stroke; }

.auth-panel { display: grid; place-items: center; padding: 48px 32px; background: var(--surface); }
.auth-form { width: 100%; max-width: 360px; }
.auth-form h2 { font-size: 28px; font-weight: 750; letter-spacing: -0.02em; margin: 0 0 6px; }
.auth-form > .muted { margin: 0 0 24px; }
.auth-form .flash { margin-bottom: 16px; }
.auth-fields { display: flex; flex-direction: column; gap: 16px; }
.auth-fields label { gap: 6px; font-size: 13px; font-weight: 550; color: var(--text); }
.auth-fields input { height: 46px; padding: 0 14px; border-radius: 10px; background: var(--bg); font-size: 16px;
  transition: border-color .15s ease, background-color .15s ease; }
.auth-fields input:hover { border-color: color-mix(in srgb, var(--accent) 35%, var(--line)); }
.auth-fields input:focus { background: var(--surface); }
.auth-submit { height: 48px; margin-top: 6px; border-radius: 10px; font-size: 16px; }
.auth-note { margin: 22px 0 0; font-size: 13px; color: var(--muted); }

@media (prefers-reduced-motion: no-preference) {
  .auth-slide.on { animation: auth-zoom 9s ease-out both; }
  .auth-trace .line { stroke-dasharray: 1; stroke-dashoffset: 1; animation: auth-draw 1.6s cubic-bezier(.16, 1, .3, 1) .15s forwards; }
  .auth-trace .area { opacity: 0; animation: auth-fade 1.2s ease .7s forwards; }
  .auth-pitch { animation: auth-rise .7s cubic-bezier(.16, 1, .3, 1) both; }
}
@keyframes auth-draw { to { stroke-dashoffset: 0; } }
@keyframes auth-zoom { from { transform: scale(1.06); } to { transform: scale(1); } }
@keyframes auth-fade { to { opacity: 1; } }
@keyframes auth-rise { from { opacity: 0; transform: translateY(12px); } }
@media (prefers-reduced-motion: reduce) { .auth-slide { transition: none; } .auth-dots button.on i { animation: none; transform: scaleX(1); } }

@media (max-width: 860px) {
  main.auth { grid-template-columns: 1fr; grid-template-rows: auto 1fr; }
  .auth-hero { padding: 20px 16px 0; }
  .auth-pitch { padding: 28px 0 8px; }
  .auth-pitch h1 { font-size: 28px; margin-bottom: 10px; }
  .auth-pitch p { font-size: 15px; }
  .auth-trace { width: calc(100% + 32px); margin: 0 -16px; height: 72px; }
  .auth-foot { left: 16px; right: 16px; bottom: 8px; }
  .auth-trace { margin-bottom: 20px; }
  .auth-panel { place-items: start center; padding: 32px 16px 40px; }
}

/* ── (i) "what is this" chips on dashboard tiles and charts ─────────────── */
.kpi, .card.has-info { position: relative; }
.kpi .kpi-label { padding-right: 22px; }
.card.has-info h2 { padding-right: 28px; }
.info-btn {
  position: absolute; top: 9px; right: 9px; width: 20px; height: 20px; padding: 0; border-radius: 50%;
  border: 1px solid var(--line); background: var(--surface); color: var(--muted);
  font: italic 600 12px/18px Georgia, "Times New Roman", serif; text-align: center; cursor: pointer;
}
.card.has-info .info-btn { top: 16px; right: 16px; }
.info-btn::after { content: ""; position: absolute; inset: -8px; }  /* 36px touch target */
.info-btn:hover:not(:disabled), .info-btn[aria-expanded="true"] { color: var(--accent); border-color: var(--accent); filter: none; }
.info-chip {
  position: fixed; z-index: 30; padding: 12px 14px; border-radius: var(--radius);
  background: var(--surface); color: var(--text); border: 1px solid var(--line);
  box-shadow: 0 10px 30px rgb(15 23 42 / .14), 0 2px 6px rgb(15 23 42 / .08);
  font-size: 13.5px; line-height: 1.5;
}
.info-chip[hidden] { display: none; }
.info-chip b { display: block; font-size: 14px; margin-bottom: 4px; }
.info-chip p { margin: 0; }
.info-chip p + p { margin-top: 8px; font-size: 12.5px; }
@media (prefers-color-scheme: dark) { .info-chip { box-shadow: 0 10px 30px rgb(0 0 0 / .5); } }
@media (prefers-reduced-motion: no-preference) {
  .info-chip:not([hidden]) { animation: chip-in .14s ease-out; }
}
@keyframes chip-in { from { opacity: 0; transform: translateY(-4px); } }
