/* ==========================================================================
   Theming
   Every color in this file comes from the tokens below (the only exceptions
   are effects drawn on the always-dark instrument screens), so a theme or
   skin only ever has to override tokens.

   Modes:  <html data-theme="dark|light">   set before first paint by index.html
   Skins:  <html data-skin="name">          set from the mdp_skin filter in PHP

   To restyle the app for another site (for example Vehicle Intelligence
   Platform), ship a skin stylesheet through the mdp_skin_stylesheet filter
   and override tokens for both modes:
     [data-skin="vip"]                     { --green: ...; --font... }
     [data-skin="vip"][data-theme="light"] { --bg: ...; --panel: ... }
   "Instrument screens" (live traces, spectrograms, viewfinder) stay dark in
   both modes on purpose, like a meter's display; see --screen.
   ========================================================================== */
:root {
  --bg: #0a0e13;
  --bg2: #10161d;
  --panel: #131b24;
  --panel2: #18222d;
  --line: rgba(140, 170, 200, 0.14);
  --text: #e8f1fa;
  --muted: #8ea3b8;
  --dim: #5f7387;
  --green: #39f2a6;
  --cyan: #4cc9ff;
  --amber: #ffb648;
  --red: #ff5f5f;
  --violet: #a98bff;
  /* Soft fills behind chips, icons and notices. */
  --tint-green: rgba(57, 242, 166, 0.12);
  --tint-cyan: rgba(76, 201, 255, 0.12);
  --tint-amber: rgba(255, 182, 72, 0.12);
  --tint-red: rgba(255, 95, 95, 0.12);
  --tint-violet: rgba(169, 139, 255, 0.14);
  --glow: rgba(57, 242, 166, 0.35);
  --halo-a: rgba(57, 242, 166, 0.08);
  --halo-b: rgba(76, 201, 255, 0.06);
  /* The big green buttons and orb. */
  --primary-a: #43f7b0;
  --primary-b: #22d68d;
  --on-primary: #04140d;
  --orb-think-a: #7ad8ff;
  --orb-think-b: #2aa7e0;
  --orb-speak-a: #c2b0ff;
  --orb-speak-b: #8a6cf2;
  --notice-amber: #ffd79a;
  --notice-info: #bfe8ff;
  --notice-error: #ffc2c2;
  --user-msg: #d9ffef;
  --well: rgba(255, 255, 255, 0.03);
  --scrim: rgba(4, 6, 9, 0.88);
  --shadow: rgba(0, 0, 0, 0.5);
  --screen: #05080b;
  --screen-line: rgba(140, 170, 200, 0.14);
  --screen-text: #8ea3b8;
  --screen-text-hi: #e8f1fa;
  --radius: 18px;
  --mono: ui-monospace, "SF Mono", "Cascadia Mono", Menlo, Consolas, monospace;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  color-scheme: dark;
}
/* Light: bright white with bold color, like a speed-test app. Accent colors
   are deepened so text and outlines stay readable on white. */
:root[data-theme="light"] {
  --bg: #f5f8fb;
  --bg2: #ffffff;
  --panel: #ffffff;
  --panel2: #eef3f8;
  --line: rgba(20, 45, 75, 0.12);
  --text: #0d1824;
  --muted: #4f6478;
  --dim: #7d8fa1;
  --green: #00a866;
  --cyan: #0b8fd0;
  --amber: #c87600;
  --red: #d93a3f;
  --violet: #6c4ce6;
  --tint-green: rgba(0, 168, 102, 0.1);
  --tint-cyan: rgba(11, 143, 208, 0.1);
  --tint-amber: rgba(200, 118, 0, 0.11);
  --tint-red: rgba(217, 58, 63, 0.1);
  --tint-violet: rgba(108, 76, 230, 0.1);
  --glow: rgba(0, 168, 102, 0.28);
  --halo-a: rgba(57, 242, 166, 0.16);
  --halo-b: rgba(76, 201, 255, 0.12);
  --primary-a: #2ee89f;
  --primary-b: #10c47f;
  --on-primary: #02180e;
  --notice-amber: #7a4a00;
  --notice-info: #0a5a85;
  --notice-error: #9b1c20;
  --user-msg: #04402a;
  --well: #f5f8fb;
  --scrim: rgba(235, 241, 247, 0.9);
  --shadow: rgba(20, 45, 75, 0.16);
  color-scheme: light;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text); font-family: var(--sans); font-size: 16px; line-height: 1.45; }
body { overscroll-behavior-y: none; }
body::before {
  content: ""; position: fixed; inset: 0; pointer-events: none; z-index: 0;
  background:
    radial-gradient(900px 500px at 50% -10%, var(--halo-a), transparent 60%),
    radial-gradient(700px 500px at 110% 110%, var(--halo-b), transparent 60%);
}
#app { position: relative; z-index: 1; min-height: 100%; max-width: 680px; margin: 0 auto; padding: max(14px, env(safe-area-inset-top)) 16px calc(28px + env(safe-area-inset-bottom)); }
button { font: inherit; color: inherit; }
a { color: var(--cyan); }
h1, h2, h3 { margin: 0; line-height: 1.15; letter-spacing: -0.01em; }
p { margin: 0; }
.mono { font-family: var(--mono); }
.muted { color: var(--muted); }
.dim { color: var(--dim); }
.small { font-size: 0.85rem; }
.hidden { display: none !important; }
.row { display: flex; gap: 10px; align-items: center; }
.row.wrap { flex-wrap: wrap; }
.grow { flex: 1; }
.stack > * + * { margin-top: 12px; }
.center { text-align: center; }

/* ---------- Boot ---------- */
.boot { min-height: 80vh; display: grid; place-items: center; align-content: center; gap: 18px; color: var(--muted); }
.boot-ring { width: 54px; height: 54px; border-radius: 50%; border: 3px solid var(--tint-green); border-top-color: var(--green); animation: spin 0.9s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- Top bar ---------- */
.topbar { display: flex; align-items: center; gap: 10px; min-height: 44px; margin-bottom: 8px; }
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; letter-spacing: 0.02em; font-size: 0.95rem; }
.brand img { width: 30px; height: 30px; }
.brand small { display: block; font-weight: 500; color: var(--muted); font-size: 0.72rem; letter-spacing: 0.08em; text-transform: uppercase; }
.iconbtn { width: 44px; height: 44px; border-radius: 12px; border: 1px solid var(--line); background: var(--panel); display: grid; place-items: center; cursor: pointer; flex: none; }
.iconbtn:active { transform: scale(0.96); }
.iconbtn[disabled] { opacity: 0.35; pointer-events: none; }
.iconbtn { font-size: 1.3rem; font-weight: 600; }
.iconbtn svg { width: 22px; height: 22px; }

/* ---------- Buttons ---------- */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-height: 52px; padding: 0 20px; border-radius: 14px; border: 1px solid var(--line); background: var(--panel2); font-weight: 600; cursor: pointer; text-decoration: none; color: var(--text); transition: transform 0.08s, background 0.2s; }
.btn:active { transform: scale(0.98); }
.btn.primary { background: linear-gradient(180deg, var(--primary-a), var(--primary-b)); color: var(--on-primary); border: none; box-shadow: 0 8px 28px var(--glow); }
.btn.ghost { background: transparent; }
.btn.block { width: 100%; }
.btn.small { min-height: 40px; padding: 0 14px; font-size: 0.9rem; border-radius: 11px; }
.btn[disabled] { opacity: 0.45; pointer-events: none; }
.btn svg { width: 20px; height: 20px; }
.linkbtn { background: none; border: none; color: var(--muted); text-decoration: underline; text-underline-offset: 3px; cursor: pointer; padding: 8px; font-size: 0.9rem; }

/* ---------- Home hero ---------- */
.hero { text-align: center; padding: 18px 0 8px; }
.hero h1 { font-size: clamp(1.7rem, 7vw, 2.4rem); }
.hero h1 .accent { color: var(--green); }
.hero p { color: var(--muted); max-width: 440px; margin: 10px auto 0; }
.start-wrap { position: relative; width: 230px; height: 230px; margin: 26px auto 14px; }
.start-wrap canvas { position: absolute; inset: 0; width: 100%; height: 100%; }
.start-btn { position: absolute; inset: 38px; border-radius: 50%; border: none; cursor: pointer; background: radial-gradient(circle at 50% 35%, var(--primary-a), var(--primary-b) 70%); color: var(--on-primary); font-weight: 800; font-size: 1.35rem; letter-spacing: 0.04em; box-shadow: 0 0 0 10px var(--tint-green), 0 0 60px var(--glow); display: grid; place-items: center; }
.start-btn small { display: block; font-size: 0.72rem; font-weight: 600; letter-spacing: 0.06em; opacity: 0.7; margin-top: 2px; }
.start-btn:active { transform: scale(0.97); }
.pulse::after { content: ""; position: absolute; inset: 0; border-radius: 50%; border: 2px solid var(--glow); animation: pulse 2.4s ease-out infinite; }
@keyframes pulse { from { transform: scale(1); opacity: 0.9; } to { transform: scale(1.35); opacity: 0; } }
.steps-hint { display: flex; justify-content: center; gap: 18px; color: var(--muted); font-size: 0.82rem; margin-bottom: 8px; }
.steps-hint span { display: flex; align-items: center; gap: 6px; }
.steps-hint i { width: 8px; height: 8px; border-radius: 50%; display: inline-block; }

/* ---------- Sections & cards ---------- */
.section-title { display: flex; align-items: baseline; justify-content: space-between; margin: 28px 0 12px; }
.section-title h2 { font-size: 1.05rem; text-transform: uppercase; letter-spacing: 0.1em; color: var(--muted); font-weight: 700; }
.card { background: linear-gradient(180deg, var(--panel), var(--bg2)); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; }
.card + .card { margin-top: 12px; }
.machines { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 12px; }
.mcard { position: relative; background: linear-gradient(180deg, var(--panel), var(--bg2)); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px; cursor: pointer; text-align: left; display: block; width: 100%; }
.mcard canvas { width: 100%; aspect-ratio: 1; display: block; }
.mcard h3 { font-size: 0.95rem; margin-top: 6px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.mcard p { font-size: 0.78rem; color: var(--muted); }
.mcard .photo { position: absolute; top: 10px; right: 10px; width: 38px; height: 38px; border-radius: 10px; object-fit: cover; border: 1px solid var(--line); }
.empty { text-align: center; color: var(--muted); padding: 22px 12px; border: 1px dashed var(--line); border-radius: var(--radius); font-size: 0.92rem; }

.chip { display: inline-flex; align-items: center; gap: 6px; font-size: 0.75rem; font-weight: 700; letter-spacing: 0.06em; text-transform: uppercase; padding: 4px 10px; border-radius: 999px; background: var(--tint-cyan); color: var(--cyan); }
.chip::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: currentColor; }
.chip.healthy { background: var(--tint-green); color: var(--green); }
.chip.watch { background: var(--tint-amber); color: var(--amber); }
.chip.concern { background: var(--tint-red); color: var(--red); }
.chip.plain::before { display: none; }

.footer-links { display: flex; flex-wrap: wrap; justify-content: center; gap: 6px 16px; margin-top: 34px; }
.notice { border-radius: 14px; padding: 12px 14px; font-size: 0.9rem; background: var(--tint-amber); border: 1px solid var(--tint-amber); border-left: 3px solid var(--amber); color: var(--notice-amber); }
.notice.info { background: var(--tint-cyan); border-color: var(--tint-cyan); border-left-color: var(--cyan); color: var(--notice-info); }
.notice.error { background: var(--tint-red); border-color: var(--tint-red); border-left-color: var(--red); color: var(--notice-error); }

/* ---------- Flow ---------- */
.progress { display: flex; gap: 6px; flex: 1; }
.progress div { flex: 1; height: 4px; border-radius: 4px; background: var(--line); position: relative; overflow: hidden; }
.progress div.done { background: var(--green); }
.progress div.active::after { content: ""; position: absolute; inset: 0; background: var(--green); animation: grow 1.6s ease-in-out infinite alternate; transform-origin: left; }
@keyframes grow { from { transform: scaleX(0.15); } to { transform: scaleX(0.85); } }
.step-label { font-family: var(--mono); font-size: 0.75rem; letter-spacing: 0.14em; text-transform: uppercase; color: var(--green); }
.step h2 { font-size: clamp(1.45rem, 6vw, 1.9rem); margin-top: 6px; }
.step .lead { color: var(--muted); margin-top: 8px; font-size: 1.02rem; }
.say { font-size: 1.08rem; line-height: 1.5; }

.viewfinder { position: relative; border-radius: 22px; overflow: hidden; background: var(--screen); aspect-ratio: 4 / 3; max-height: 44vh; width: 100%; margin: 18px 0; display: grid; place-items: center; border: 1px solid var(--line); }
.viewfinder img { width: 100%; height: 100%; object-fit: cover; }
.viewfinder .corners::before, .viewfinder .corners::after { content: ""; position: absolute; width: 40px; height: 40px; border: 3px solid var(--green); }
.viewfinder .corners::before { top: 14px; left: 14px; border-right: none; border-bottom: none; border-radius: 8px 0 0 0; }
.viewfinder .corners::after { bottom: 14px; right: 14px; border-left: none; border-top: none; border-radius: 0 0 8px 0; }
.viewfinder .placeholder { color: var(--dim); text-align: center; padding: 20px; }
.viewfinder .placeholder svg { width: 54px; height: 54px; opacity: 0.6; }
.scanline { position: absolute; left: 0; right: 0; height: 30%; background: linear-gradient(180deg, transparent, rgba(57, 242, 166, 0.28), transparent); animation: scan 1.6s ease-in-out infinite alternate; }
@keyframes scan { from { top: -30%; } to { top: 100%; } }
.scan-label { position: absolute; bottom: 12px; left: 12px; right: 12px; font-family: var(--mono); font-size: 0.8rem; color: var(--green); background: rgba(5, 8, 11, 0.7); padding: 6px 10px; border-radius: 8px; }

.idcard { margin-top: 4px; }
.idcard h3 { font-size: 1.35rem; }
.idcard .kind { color: var(--muted); margin-top: 2px; }
.specs { display: grid; grid-template-columns: repeat(auto-fit, minmax(130px, 1fr)); gap: 8px; margin-top: 14px; }
.spec { background: var(--well); border: 1px solid var(--line); border-radius: 12px; padding: 10px 12px; }
.spec b { display: block; font-family: var(--mono); font-size: 1.05rem; color: var(--text); }
.spec span { font-size: 0.72rem; text-transform: uppercase; letter-spacing: 0.08em; color: var(--muted); }

.instrument { position: relative; border-radius: 22px; background: var(--screen); border: 1px solid var(--line); overflow: hidden; margin: 18px 0; height: 240px; }
.instrument canvas.live { position: absolute; inset: 0; width: 100%; height: 100%; }
.instrument .grid { position: absolute; inset: 0; background-image: linear-gradient(var(--screen-line) 1px, transparent 1px), linear-gradient(90deg, var(--screen-line) 1px, transparent 1px); background-size: 100% 25%, 12.5% 100%; opacity: 0.5; }
.instrument .readout { position: absolute; top: 10px; left: 12px; right: 12px; display: flex; justify-content: space-between; font-family: var(--mono); font-size: 0.78rem; color: var(--screen-text); }
.instrument .readout b { color: var(--screen-text-hi); }
.instrument .overlay, .instrument .overlay .muted { color: var(--screen-text-hi); }
.instrument .overlay { position: absolute; inset: 0; display: grid; place-items: center; text-align: center; background: rgba(5, 8, 11, 0.55); }
.big-count { font-family: var(--mono); font-size: 4.2rem; font-weight: 700; color: var(--green); text-shadow: 0 0 30px var(--glow); }

.ring { width: 64px; height: 64px; }
.ring circle { fill: none; stroke-width: 5; }
.ring .bg { stroke: var(--line); }
.ring .fg { stroke: var(--green); stroke-linecap: round; transform: rotate(-90deg); transform-origin: center; transition: stroke-dashoffset 0.1s linear; }

.result-img { width: 100%; border-radius: 14px; border: 1px solid var(--line); display: block; margin-top: 12px; background: var(--screen); }
.readouts { display: grid; grid-template-columns: repeat(auto-fit, minmax(120px, 1fr)); gap: 8px; margin-top: 12px; }

.print-hero { position: relative; width: min(300px, 78vw); aspect-ratio: 1; margin: 6px auto 0; }
.print-hero canvas { width: 100%; height: 100%; }
.print-hero .label { position: absolute; bottom: -4px; left: 0; right: 0; text-align: center; font-family: var(--mono); font-size: 0.72rem; letter-spacing: 0.14em; text-transform: uppercase; color: var(--dim); }
.headline { font-size: clamp(1.4rem, 6vw, 1.85rem); margin-top: 14px; }
.findings { list-style: none; padding: 0; margin: 14px 0 0; }
.findings li { display: grid; grid-template-columns: 34px 1fr; gap: 10px; padding: 12px 0; border-top: 1px solid var(--line); }
.findings li:first-child { border-top: none; }
.sense { width: 34px; height: 34px; border-radius: 10px; display: grid; place-items: center; background: var(--tint-cyan); color: var(--cyan); }
.sense svg { width: 18px; height: 18px; }
.sense.sound { background: var(--tint-green); color: var(--green); }
.sense.vibration { background: var(--tint-violet); color: var(--violet); }
.findings b { display: block; }
.findings span { color: var(--muted); font-size: 0.92rem; }
.compare-bar { height: 10px; border-radius: 10px; background: var(--line); overflow: hidden; margin-top: 8px; }
.compare-bar div { height: 100%; background: linear-gradient(90deg, var(--amber), var(--green)); border-radius: 10px; }
.actions { display: grid; gap: 10px; margin-top: 20px; }
.actions.two { grid-template-columns: 1fr 1fr; }

/* ---------- Chat ---------- */
.chat { display: flex; flex-direction: column; min-height: calc(100vh - 80px); min-height: calc(100dvh - 80px); }
.msgs { flex: 1; display: flex; flex-direction: column; gap: 10px; padding: 8px 0 16px; }
.msg { max-width: 86%; padding: 12px 14px; border-radius: 18px; font-size: 1rem; line-height: 1.45; }
.msg.assistant { background: var(--panel2); border: 1px solid var(--line); border-bottom-left-radius: 6px; align-self: flex-start; }
.msg.user { background: var(--tint-green); color: var(--user-msg); border-bottom-right-radius: 6px; align-self: flex-end; }
.msg.system { align-self: center; color: var(--muted); font-size: 0.85rem; background: none; }
.msg img { max-width: 100%; border-radius: 10px; margin-top: 8px; display: block; }
.capture-req { border: 1px solid var(--tint-cyan); border-left: 3px solid var(--cyan); background: var(--tint-cyan); border-radius: 16px; padding: 14px; align-self: stretch; }
.dock { position: sticky; bottom: 0; padding: 12px 0 calc(6px + env(safe-area-inset-bottom)); background: linear-gradient(180deg, transparent, var(--bg) 30%); display: grid; justify-items: center; gap: 8px; }
.orb { width: 92px; height: 92px; border-radius: 50%; border: none; cursor: pointer; display: grid; place-items: center; background: radial-gradient(circle at 50% 35%, var(--primary-a), var(--primary-b) 70%); color: var(--on-primary); box-shadow: 0 0 40px var(--glow); position: relative; }
.orb svg { width: 34px; height: 34px; }
.orb.listening { animation: breathe 1.1s ease-in-out infinite; }
.orb.thinking { background: radial-gradient(circle at 50% 35%, var(--orb-think-a), var(--orb-think-b) 70%); box-shadow: 0 0 40px var(--tint-cyan); }
.orb.thinking::after { content: ""; position: absolute; inset: -6px; border-radius: 50%; border: 3px solid transparent; border-top-color: var(--cyan); animation: spin 0.9s linear infinite; }
.orb.speaking { background: radial-gradient(circle at 50% 35%, var(--orb-speak-a), var(--orb-speak-b) 70%); box-shadow: 0 0 40px var(--tint-violet); }
@keyframes breathe { 50% { transform: scale(1.07); box-shadow: 0 0 70px var(--glow); } }
.orb-label { font-family: var(--mono); font-size: 0.78rem; letter-spacing: 0.12em; text-transform: uppercase; color: var(--muted); min-height: 1.2em; }
.textline { display: flex; gap: 8px; width: 100%; }
.textline input { flex: 1; min-height: 46px; border-radius: 12px; border: 1px solid var(--line); background: var(--panel); color: var(--text); padding: 0 12px; font: inherit; }

/* ---------- Detail ---------- */
.detail-head { display: grid; grid-template-columns: 1fr; gap: 14px; text-align: center; }
.detail-head img.photo { width: 100%; max-height: 240px; object-fit: cover; border-radius: var(--radius); border: 1px solid var(--line); }
.timeline { list-style: none; margin: 0; padding: 0; }
.timeline li { padding: 14px 0; border-top: 1px solid var(--line); display: grid; grid-template-columns: 1fr auto; gap: 4px 10px; cursor: pointer; }
.timeline li:first-child { border-top: none; }
.timeline .when { color: var(--muted); font-size: 0.82rem; }
.kv { display: grid; grid-template-columns: auto 1fr; gap: 6px 14px; font-size: 0.9rem; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; font-family: var(--mono); word-break: break-word; }
pre.log { white-space: pre-wrap; word-break: break-word; font-size: 0.72rem; background: var(--well); border: 1px solid var(--line); border-radius: 12px; padding: 10px; max-height: 300px; overflow: auto; }
select, input[type=number], input[type=text] { min-height: 44px; border-radius: 12px; border: 1px solid var(--line); background: var(--panel); color: var(--text); padding: 0 12px; font: inherit; }
label.check { display: flex; gap: 8px; align-items: center; font-size: 0.92rem; }

.fb { display: flex; align-items: center; gap: 8px; margin-top: 14px; }
.fb.compact { margin-top: 6px; gap: 4px; }
.fbbtn { width: 40px; height: 40px; border-radius: 12px; border: 1px solid var(--line); background: transparent; color: var(--muted); display: grid; place-items: center; cursor: pointer; }
.fb.compact .fbbtn { width: 30px; height: 30px; border-radius: 9px; }
.fbbtn svg { width: 18px; height: 18px; }
.fb.compact .fbbtn svg { width: 14px; height: 14px; }
.fbbtn.on.up { color: var(--green); border-color: var(--green); background: var(--tint-green); }
.fbbtn.on.down { color: var(--red); border-color: var(--red); background: var(--tint-red); }
.fb.nudge .fbbtn[data-fb="down"] { animation: breathe 1.4s ease-in-out infinite; color: var(--amber); border-color: var(--amber); }
.fb-note { margin-top: 8px; }
.msg-wrap { display: flex; flex-direction: column; align-self: flex-start; max-width: 86%; }
.msg-wrap .msg { max-width: 100%; }
.toast { position: fixed; left: 50%; bottom: calc(24px + env(safe-area-inset-bottom)); transform: translateX(-50%); background: var(--panel2); border: 1px solid var(--line); padding: 12px 18px; border-radius: 14px; z-index: 50; box-shadow: 0 10px 40px var(--shadow); max-width: calc(100% - 32px); animation: rise 0.25s ease-out; }
@keyframes rise { from { transform: translate(-50%, 12px); opacity: 0; } }
.modal { position: fixed; inset: 0; z-index: 40; background: var(--scrim); backdrop-filter: blur(6px); overflow: auto; }
.modal-inner { max-width: 680px; margin: 0 auto; padding: max(14px, env(safe-area-inset-top)) 16px calc(28px + env(safe-area-inset-bottom)); }

@media (min-width: 720px) {
  .detail-head { grid-template-columns: 1fr 1fr; text-align: left; align-items: center; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
