/* ==========================================================================
   FHVitals SDK Demo — styles
   A compact, modern health-app look. Vanilla CSS, no build step.
   ========================================================================== */

:root {
  --bg: #0e1512;
  --surface: #16211c;
  --surface-2: #1e2d26;
  --line: #294036;
  --text: #eaf3ee;
  --muted: #8fa89b;
  --accent: #21c98a;
  --accent-2: #16a874;
  --danger: #ff6b6b;
  --radius: 16px;
  --shadow: 0 10px 30px rgba(0, 0, 0, .35);
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
  height: 100%;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background:
    radial-gradient(1200px 600px at 50% -10%, #1a2b23 0%, transparent 60%),
    var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
  display: flex;
  justify-content: center;
}

.app {
  width: 100%;
  max-width: 460px;
  height: 100dvh;
  position: relative;
  overflow-x: hidden; /* clip the scan stage's negative-margin bleed */
  overflow-y: auto;   /* but let tall screens (results) scroll */
}

/* --- Screens ------------------------------------------------------------- */
.screen {
  display: none;
  flex-direction: column;
  padding: 22px 20px 28px;
  min-height: 100dvh;
}
.screen.is-active { display: flex; }

/* --- Header / brand ------------------------------------------------------ */
.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 26px;
}
.brand { display: flex; align-items: center; gap: 9px; }
.brand-dot {
  width: 12px; height: 12px; border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 0 4px rgba(33, 201, 138, .18);
}
.brand-name { font-weight: 700; letter-spacing: .2px; }
.version {
  font-size: 12px; color: var(--muted);
  border: 1px solid var(--line); border-radius: 999px;
  padding: 3px 10px;
}

/* --- Typography ---------------------------------------------------------- */
.title { font-size: 26px; line-height: 1.15; font-weight: 750; letter-spacing: -.3px; }
.subtitle { color: var(--muted); margin-top: 8px; font-size: 14.5px; line-height: 1.5; }
.footnote { color: var(--muted); font-size: 12px; line-height: 1.5; margin-top: 16px; }

/* --- Card / form --------------------------------------------------------- */
.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 18px;
  margin-top: 20px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.field { display: flex; flex-direction: column; gap: 7px; }
.field label { font-size: 13px; font-weight: 600; color: #cfe0d8; }
.field label .unit { color: var(--muted); font-weight: 500; }
.hint { color: var(--muted); font-size: 11.5px; line-height: 1.4; }

input[type="number"], input[type="text"] {
  background: var(--surface-2);
  border: 1px solid var(--line);
  color: var(--text);
  border-radius: 10px;
  padding: 12px 13px;
  font-size: 15px;
  width: 100%;
  transition: border-color .15s, box-shadow .15s;
}
input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(33, 201, 138, .16);
}

.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }

/* --- Segmented control --------------------------------------------------- */
.segmented {
  display: flex;
  gap: 6px;
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 4px;
}
.seg {
  flex: 1;
  border: none;
  background: transparent;
  color: var(--muted);
  font-size: 13px;
  font-weight: 600;
  padding: 9px 6px;
  border-radius: 7px;
  cursor: pointer;
  transition: background .15s, color .15s;
}
.seg:hover { color: var(--text); }
.seg.is-selected {
  background: var(--accent);
  color: #08130d;
}

/* --- Buttons ------------------------------------------------------------- */
.btn {
  border: none;
  border-radius: 12px;
  padding: 15px;
  font-size: 15.5px;
  font-weight: 700;
  cursor: pointer;
  transition: transform .05s, filter .15s;
}
.btn:active { transform: translateY(1px); }
.btn-primary {
  background: linear-gradient(180deg, var(--accent), var(--accent-2));
  color: #06120c;
  margin-top: 6px;
}
.btn-primary:hover { filter: brightness(1.05); }
.btn-primary:disabled { opacity: .55; cursor: default; filter: none; }

/* --- Scan stage ---------------------------------------------------------- */
.scan-stage {
  position: relative;
  flex: 1;
  margin: -22px -20px 0;
  background: #05090a;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}
#live_canvas {
  max-width: 100%;
  max-height: 100%;
  display: block;
}

.face-guide {
  position: absolute; inset: 0;
  display: flex; align-items: center; justify-content: center;
  pointer-events: none;
}
.face-oval {
  width: 58%;
  aspect-ratio: 3 / 4;
  border: 2px dashed rgba(255, 255, 255, .55);
  border-radius: 50%;
  box-shadow: 0 0 0 2000px rgba(4, 8, 9, .32);
}

.scan-overlay {
  position: absolute;
  top: 22px;
  left: 0; right: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  pointer-events: none;
}

.progress-ring { position: relative; width: 86px; height: 86px; }
.progress-ring svg { width: 100%; height: 100%; transform: rotate(-90deg); }
.ring-track { fill: none; stroke: rgba(255, 255, 255, .18); stroke-width: 8; }
.ring-fill {
  fill: none;
  stroke: var(--accent);
  stroke-width: 8;
  stroke-linecap: round;
  stroke-dasharray: 339.29;   /* 2 * pi * r (r=54) */
  stroke-dashoffset: 339.29;
  transition: stroke-dashoffset .4s ease;
}
.ring-label {
  position: absolute; inset: 0;
  display: flex; align-items: center; justify-content: center;
  font-weight: 750; font-size: 22px;
}
.ring-pct { font-size: 13px; color: var(--muted); margin-left: 1px; }

.scan-status {
  background: rgba(6, 12, 9, .72);
  backdrop-filter: blur(6px);
  border: 1px solid var(--line);
  color: var(--text);
  font-size: 13px;
  font-weight: 600;
  padding: 6px 14px;
  border-radius: 999px;
  min-height: 30px;
  display: flex; align-items: center;
}
.scan-status.is-warning { color: var(--danger); border-color: rgba(255, 107, 107, .5); }

.btn-cancel {
  position: absolute; top: 18px; right: 16px;
  width: 38px; height: 38px;
  border-radius: 50%;
  border: 1px solid var(--line);
  background: rgba(6, 12, 9, .6);
  color: var(--text);
  font-size: 15px;
  cursor: pointer;
}

/* --- Live vitals strip --------------------------------------------------- */
.live-vitals {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin: 16px -20px -28px;
  padding: 18px 20px 26px;
  background: var(--surface);
  border-top: 1px solid var(--line);
}
.live-vital { display: flex; flex-direction: column; gap: 3px; }
.lv-label { font-size: 12px; color: var(--muted); }
.lv-value { display: flex; align-items: baseline; gap: 5px; }
.lv-value b { font-size: 24px; font-weight: 750; letter-spacing: -.5px; }
.lv-value i { font-style: normal; font-size: 12px; color: var(--muted); }

/* --- Results ------------------------------------------------------------- */
.result-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  margin: 22px 0;
}
.result-card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 15px 16px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.result-card.span-2 { grid-column: span 2; }
.rc-label { font-size: 12.5px; color: var(--muted); display: flex; align-items: center; gap: 6px; }
.rc-value { display: flex; align-items: baseline; gap: 6px; }
.rc-value b { font-size: 27px; font-weight: 750; letter-spacing: -.5px; }
.rc-value i { font-style: normal; font-size: 13px; color: var(--muted); }
.rc-icon { font-size: 14px; }

.again-note { color: var(--muted); font-size: 12px; text-align: center; margin-top: 12px; }

/* --- All-measurements table + raw JSON ----------------------------------- */
.raw-block {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  margin-bottom: 14px;
  overflow: hidden;
}
.raw-block > summary {
  cursor: pointer;
  list-style: none;
  padding: 14px 16px;
  font-size: 14px;
  font-weight: 650;
  display: flex;
  align-items: center;
  gap: 8px;
  user-select: none;
}
.raw-block > summary::-webkit-details-marker { display: none; }
.raw-block > summary::before {
  content: "▸";
  color: var(--accent);
  transition: transform .15s;
}
.raw-block[open] > summary::before { transform: rotate(90deg); }
.count-pill {
  margin-left: auto;
  font-size: 11.5px;
  font-weight: 600;
  color: var(--muted);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 2px 9px;
}

.measure-table { padding: 0 16px 12px; }
.measure-row {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 8px 0;
  border-top: 1px solid var(--line);
  font-size: 13px;
}
.mr-key { color: var(--muted); font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 12px; word-break: break-all; }
.mr-val { font-weight: 650; text-align: right; white-space: nowrap; }

.raw-json-wrap { position: relative; padding: 0 16px 16px; }
.raw-json {
  background: #0a1310;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 14px;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 12px;
  line-height: 1.5;
  color: #b9d4c8;
  max-height: 340px;
  overflow: auto;
  white-space: pre;
}
.btn-copy {
  position: absolute;
  top: 8px; right: 24px;
  z-index: 1;
  background: var(--surface-2);
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 5px 12px;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
}
.btn-copy:hover { border-color: var(--accent); }
