@import url('https://fonts.googleapis.com/css2?family=Oswald:wght@400;500;600;700&family=IBM+Plex+Sans:wght@400;500;600&display=swap');

:root {
  --bg: #18181a;
  --surface: #221f1c;
  --surface-2: #2b2825;
  --line: #3a3632;
  --text: #ede9e3;
  --text-dim: #9c968c;
  --accent: #ff5a36;
  --accent-dim: #ff5a3626;
  --steel: #4fa8c9;
  --gold: #d9a34a;
  --good: #5db56a;
  --bad: #d6534a;

  --grad-thin: #e6357a;
  --grad-normal: #4caf6d;
  --grad-fat: #e8c43a;
  --grad-obese: #d64545;

  --font-display: 'Oswald', sans-serif;
  --font-body: 'IBM Plex Sans', sans-serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-body);
  -webkit-tap-highlight-color: transparent;
}

body {
  min-height: 100dvh;
  display: flex;
  justify-content: center;
}

#app {
  width: 100%;
  max-width: 480px;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  position: relative;
  padding-bottom: 78px;
}

/* ---------- Top bar ---------- */
.topbar {
  padding: 22px 20px 14px;
  display: flex;
  align-items: baseline;
  justify-content: space-between;
}

.topbar h1 {
  font-family: var(--font-display);
  font-size: 26px;
  font-weight: 600;
  letter-spacing: 0.3px;
  margin: 0;
}

.topbar .tagline {
  font-size: 12px;
  color: var(--text-dim);
  margin-top: 2px;
}

/* ---------- Views ---------- */
.view { display: none; padding: 0 20px 24px; animation: fade-in 0.25s ease; }
.view.active { display: block; }

@keyframes fade-in {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: translateY(0); }
}

/* ---------- Cards ---------- */
.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 18px;
  margin-bottom: 14px;
}

.card h2, .card h3 {
  font-family: var(--font-display);
  font-weight: 500;
  margin: 0 0 12px;
  letter-spacing: 0.2px;
}

.card h2 { font-size: 18px; }
.card h3 { font-size: 15px; color: var(--text-dim); }

/* ---------- Hero stat ---------- */
.hero {
  padding: 24px 20px 20px;
}

.hero-empty {
  text-align: center;
  padding: 40px 12px;
  color: var(--text-dim);
}

.hero-empty .big-icon { font-size: 40px; margin-bottom: 10px; }

.hero-date { color: var(--text-dim); font-size: 13px; margin-bottom: 14px; }

.hero-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 10px;
}

.stat-tile {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 14px 16px;
}

.stat-tile .label {
  font-size: 12px;
  color: var(--text-dim);
}

.stat-tile .value {
  font-family: var(--font-display);
  font-size: 30px;
  line-height: 1.1;
  margin-top: 4px;
}

.stat-tile .value span.unit {
  font-size: 14px;
  color: var(--text-dim);
  font-family: var(--font-body);
  margin-left: 3px;
}

.stat-tile .delta { font-size: 12px; margin-top: 6px; }
.delta.up { color: var(--bad); }
.delta.down { color: var(--good); }
.delta.flat { color: var(--text-dim); }

/* body-type gradient strip, lifted straight from the scale report's own scale */
.type-strip {
  margin-top: 16px;
  border-radius: 10px;
  overflow: hidden;
}

.type-track {
  height: 10px;
  border-radius: 6px;
  background: linear-gradient(90deg,
    var(--grad-thin), var(--grad-normal) 33%, var(--grad-fat) 62%, var(--grad-obese));
  position: relative;
}

.type-marker {
  position: absolute;
  top: -5px;
  width: 3px;
  height: 20px;
  background: var(--text);
  border-radius: 2px;
  transform: translateX(-1.5px);
}

.type-label {
  margin-top: 8px;
  font-size: 13px;
  color: var(--text-dim);
}

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  border: none;
  border-radius: 12px;
  padding: 14px 18px;
  font-family: var(--font-body);
  font-weight: 600;
  font-size: 15px;
  cursor: pointer;
  width: 100%;
}

.btn-primary { background: var(--accent); color: #1a1a1a; }
.btn-secondary { background: var(--surface-2); color: var(--text); border: 1px solid var(--line); }
.btn-ghost { background: transparent; color: var(--text-dim); border: 1px dashed var(--line); }
.btn-danger { background: transparent; color: var(--bad); border: 1px solid var(--bad); }
.btn:active { transform: scale(0.98); }
.btn-row { display: flex; gap: 10px; }
.btn-row .btn { flex: 1; }

/* ---------- Scan view ---------- */
.scan-video-wrap {
  position: relative;
  border-radius: 16px;
  overflow: hidden;
  background: #000;
  aspect-ratio: 3/4;
  border: 1px solid var(--line);
}

#qr-video { width: 100%; height: 100%; object-fit: cover; }

.scan-reticle {
  position: absolute;
  inset: 14%;
  border: 2px solid var(--accent);
  border-radius: 18px;
  box-shadow: 0 0 0 999px rgba(0,0,0,0.35);
}

.scan-status {
  position: absolute;
  bottom: 14px; left: 14px; right: 14px;
  text-align: center;
  font-size: 13px;
  color: #fff;
  background: rgba(0,0,0,0.5);
  padding: 8px 10px;
  border-radius: 10px;
}

.divider-word {
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--text-dim);
  font-size: 12px;
  margin: 18px 0;
}
.divider-word::before, .divider-word::after {
  content: "";
  flex: 1;
  height: 1px;
  background: var(--line);
}

.hidden-input { display: none; }

.ocr-progress {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  padding: 30px 10px;
}

.spinner {
  width: 36px; height: 36px;
  border-radius: 50%;
  border: 3px solid var(--line);
  border-top-color: var(--accent);
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.thumb-preview {
  width: 100%;
  border-radius: 12px;
  border: 1px solid var(--line);
  margin-bottom: 12px;
}

/* ---------- Forms ---------- */
.field { margin-bottom: 12px; }
.field label {
  display: block;
  font-size: 12px;
  color: var(--text-dim);
  margin-bottom: 6px;
}
.field input, .field select {
  width: 100%;
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 11px 12px;
  color: var(--text);
  font-family: var(--font-body);
  font-size: 15px;
}
.field input:focus, .field select:focus {
  outline: none;
  border-color: var(--accent);
}
.field-row { display: flex; gap: 10px; }
.field-row .field { flex: 1; }
.field-hint { font-size: 11px; color: var(--text-dim); margin-top: 4px; }

details.raw-ocr {
  margin: 6px 0 16px;
  font-size: 12px;
  color: var(--text-dim);
}
details.raw-ocr summary { cursor: pointer; }
details.raw-ocr pre {
  white-space: pre-wrap;
  word-break: break-word;
  background: var(--surface-2);
  padding: 10px;
  border-radius: 8px;
  margin-top: 8px;
  max-height: 200px;
  overflow-y: auto;
}

/* ---------- History ---------- */
.history-item {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 14px 16px;
  margin-bottom: 10px;
  cursor: pointer;
}
.history-item .row-top {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 8px;
}
.history-item .row-top .date {
  font-family: var(--font-display);
  font-size: 16px;
}
.history-item .row-top .sn { font-size: 11px; color: var(--text-dim); }
.history-mini-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
  text-align: center;
}
.history-mini-grid div .v { font-family: var(--font-display); font-size: 17px; }
.history-mini-grid div .l { font-size: 10px; color: var(--text-dim); }

.empty-state {
  text-align: center;
  padding: 50px 16px;
  color: var(--text-dim);
}

/* ---------- Chart view ---------- */
.chart-select-row { margin-bottom: 14px; }
.chart-canvas-wrap { height: 260px; margin-bottom: 6px; }

/* ---------- Bottom nav ---------- */
.bottomnav {
  position: fixed;
  bottom: 0; left: 0; right: 0;
  display: flex;
  justify-content: center;
  background: rgba(24,24,26,0.92);
  backdrop-filter: blur(10px);
  border-top: 1px solid var(--line);
  z-index: 20;
}

.bottomnav-inner {
  width: 100%;
  max-width: 480px;
  display: flex;
}

.navbtn {
  flex: 1;
  background: none;
  border: none;
  color: var(--text-dim);
  padding: 10px 4px 14px;
  font-family: var(--font-body);
  font-size: 11px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  cursor: pointer;
}
.navbtn .icon { font-size: 20px; }
.navbtn.active { color: var(--accent); }

/* ---------- Detail modal ---------- */
.modal-backdrop {
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.6);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  z-index: 40;
}
.modal-sheet {
  width: 100%;
  max-width: 480px;
  max-height: 85vh;
  overflow-y: auto;
  background: var(--surface);
  border-radius: 20px 20px 0 0;
  padding: 20px;
  border: 1px solid var(--line);
}
.modal-sheet h2 { font-family: var(--font-display); margin-top: 0; }
.detail-row {
  display: flex;
  justify-content: space-between;
  padding: 8px 0;
  border-bottom: 1px solid var(--line);
  font-size: 14px;
}
.detail-row .k { color: var(--text-dim); }
.section-tag {
  font-size: 11px;
  color: var(--accent);
  text-transform: uppercase;
  letter-spacing: 0.6px;
  margin: 16px 0 4px;
}

.toast {
  position: fixed;
  bottom: 90px; left: 50%;
  transform: translateX(-50%);
  background: var(--surface-2);
  border: 1px solid var(--line);
  color: var(--text);
  padding: 10px 16px;
  border-radius: 10px;
  font-size: 13px;
  z-index: 50;
  opacity: 0;
  transition: opacity 0.25s;
  pointer-events: none;
}
.toast.show { opacity: 1; }
