/* ── Variables ─────────────────────────────────────────────────────────────── */
:root {
  --bg:           #EEF2FF;
  --surface:      #FFFFFF;
  --surface2:     #F8F9FF;
  --surface3:     #F0F3FE;
  --border:       #DFE2F4;
  --primary:      #1480D0;
  --primary-dim:  #0F68B0;
  --secondary:    #4B55AD;
  --pink:         #E2498A;
  --success:      #2E7D32;
  --success-bg:   #E8F5E9;
  --danger:       #C62828;
  --danger-bg:    #FFEBEE;
  --warning:      #E65100;
  --text:         #191B23;
  --text2:        #555B6E;
  --muted:        #6B7280;
  --radius:       12px;
  --radius-sm:    8px;
  --shadow-sm:    0 1px 4px rgba(20,128,208,.08);
  --shadow-md:    0 4px 20px rgba(20,128,208,.14);
}

/* ── Reset / Base ──────────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

body {
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, sans-serif;
  font-size: 14px;
  min-height: 100vh;
  padding-bottom: 60px;
}

/* ── Header ────────────────────────────────────────────────────────────────── */
header {
  background: linear-gradient(135deg, #1480D0 0%, #4B55AD 100%);
  padding: 18px 40px;
  position: sticky; top: 0; z-index: 100;
  box-shadow: 0 2px 12px rgba(20,128,208,.25);
}
.header-inner {
  max-width: 1100px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
}
header h1 {
  font-size: 1.3rem;
  font-weight: 700;
  color: #fff;
  letter-spacing: -.01em;
}
header h1 span.brand-pink { color: #F7C0D8; }
header p { color: rgba(255,255,255,.65); font-size: .78rem; margin-top: 3px; }

.health-badge {
  font-size: .75rem;
  padding: 5px 14px;
  border-radius: 20px;
  background: rgba(255,255,255,.18);
  border: 1px solid rgba(255,255,255,.3);
  color: rgba(255,255,255,.85);
  white-space: nowrap;
}
.health-badge.ok  { background: rgba(46,125,50,.25); border-color: rgba(46,125,50,.5); color: #A5D6A7; }
.health-badge.err { background: rgba(198,40,40,.25); border-color: rgba(198,40,40,.5); color: #EF9A9A; }

/* ── Nav ────────────────────────────────────────────────────────────────────── */
nav {
  max-width: 1100px;
  margin: 0 auto;
  display: flex;
  gap: 4px;
  padding: 16px 40px 0;
}
.tab-btn {
  background: none;
  border: 1px solid transparent;
  border-bottom: none;
  color: var(--muted);
  cursor: pointer;
  font-size: .82rem;
  font-weight: 500;
  padding: 10px 22px;
  border-radius: var(--radius-sm) var(--radius-sm) 0 0;
  transition: all .15s;
}
.tab-btn:hover  { color: var(--text); background: var(--surface); }
.tab-btn.active { color: var(--primary); background: var(--surface); border-color: var(--border); border-bottom-color: var(--surface); font-weight: 600; }

/* ── Main / Panels ─────────────────────────────────────────────────────────── */
main {
  max-width: 1100px;
  margin: 0 auto;
  padding: 32px 40px;
}
.tab-panel { display: none; }
.tab-panel.active { display: block; }

/* ── Cards ──────────────────────────────────────────────────────────────────── */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 28px;
  box-shadow: var(--shadow-sm);
}
.card h2 {
  font-size: .95rem;
  font-weight: 700;
  margin-bottom: 22px;
  color: var(--secondary);
  text-transform: uppercase;
  letter-spacing: .05em;
  font-size: .8rem;
}
.result-card { min-height: 200px; }
.result-card.hidden { display: none; }

/* 2-col grid on wide screens */
.panel-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 24px;
}
@media (max-width: 768px) {
  .panel-grid { grid-template-columns: 1fr; }
  nav, main, header { padding-left: 16px; padding-right: 16px; }
}

/* ── Form fields ────────────────────────────────────────────────────────────── */
.field { margin-bottom: 18px; }
.field label {
  display: block;
  font-size: .75rem;
  font-weight: 600;
  color: var(--muted);
  margin-bottom: 6px;
  letter-spacing: .04em;
  text-transform: uppercase;
}
.field input[type="text"],
.field input[type="number"],
.field select {
  width: 100%;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-size: .9rem;
  padding: 10px 14px;
  outline: none;
  transition: border-color .15s, box-shadow .15s;
}
.field input:focus,
.field select:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(20,128,208,.08);
}
.field select { cursor: pointer; }
.field select option { background: var(--surface); }

.field-row { display: flex; gap: 16px; }
.field-row .field { flex: 1; }

.select-row { display: flex; gap: 8px; align-items: center; }
.select-row select { flex: 1; }

.muted { color: var(--muted); font-size: .8em; }
.center { text-align: center; }

/* ── FMR selector ───────────────────────────────────────────────────────────── */
.fmr-row { display: flex; gap: 6px; }
.fmr-btn {
  flex: 1;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--muted);
  cursor: pointer;
  font-size: .8rem;
  font-weight: 600;
  padding: 8px 10px;
  text-align: center;
  transition: all .15s;
  line-height: 1.3;
}
.fmr-btn span { display: block; font-size: .68rem; font-weight: 400; margin-top: 2px; }
.fmr-btn:hover  { border-color: var(--primary); color: var(--text); }
.fmr-btn.active { background: var(--primary); border-color: var(--primary); color: #fff; }
.fmr-btn.active span { color: rgba(255,255,255,.8); }

/* ── Capture box ───────────────────────────────────────────────────────────── */
.capture-box {
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  margin-bottom: 20px;
}

.source-toggle {
  display: flex;
  border-bottom: 1px solid var(--border);
}
.src-btn {
  flex: 1;
  background: none;
  border: none;
  color: var(--muted);
  cursor: pointer;
  font-size: .82rem;
  font-weight: 500;
  padding: 12px;
  transition: all .15s;
  border-bottom: 2px solid transparent;
}
.src-btn:hover { color: var(--text); background: var(--surface3); }
.src-btn.active { color: var(--primary); border-bottom-color: var(--primary); background: var(--surface3); font-weight: 600; }

/* Camera */
.camera-panel { position: relative; }
.camera-panel video {
  width: 100%;
  aspect-ratio: 4/3;
  background: #111;
  display: block;
  object-fit: cover;
}
.snap-btn {
  position: absolute;
  bottom: 14px;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(20,128,208,.92);
  border: none;
  border-radius: 24px;
  color: #fff;
  cursor: pointer;
  font-size: .82rem;
  font-weight: 600;
  padding: 10px 22px;
  backdrop-filter: blur(4px);
  transition: background .15s;
  white-space: nowrap;
}
.snap-btn:hover { background: var(--primary); }

/* File drop */
.file-panel {
  display: block;
  cursor: pointer;
  padding: 32px 20px;
  text-align: center;
}
.file-panel:hover .file-drop { border-color: var(--primary); }
.file-drop {
  border: 2px dashed var(--border);
  border-radius: var(--radius);
  padding: 28px 16px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  transition: border-color .15s;
}
.file-icon { font-size: 2rem; }
.visually-hidden { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0,0,0,0); }

/* Preview */
.preview-panel {
  position: relative;
  background: #111;
}
.preview-panel img {
  width: 100%;
  aspect-ratio: 4/3;
  object-fit: cover;
  display: block;
}
.retake-btn {
  position: absolute;
  bottom: 14px;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(255,255,255,.9);
  border: 1px solid var(--border);
  border-radius: 24px;
  color: var(--text2);
  cursor: pointer;
  font-size: .8rem;
  padding: 8px 18px;
  backdrop-filter: blur(4px);
  transition: all .15s;
  white-space: nowrap;
}
.retake-btn:hover { color: var(--primary); border-color: var(--primary); }
.hidden { display: none !important; }

/* ── Buttons ────────────────────────────────────────────────────────────────── */
.btn-primary {
  width: 100%;
  background: linear-gradient(135deg, #1480D0 0%, #4B55AD 100%);
  border: none;
  border-radius: var(--radius-sm);
  color: #fff;
  cursor: pointer;
  font-size: .9rem;
  font-weight: 600;
  padding: 13px;
  transition: opacity .15s, box-shadow .15s;
  box-shadow: 0 2px 10px rgba(20,128,208,.3);
}
.btn-primary:hover:not(:disabled) { opacity: .9; box-shadow: 0 4px 16px rgba(20,128,208,.4); }
.btn-primary:disabled { opacity: .45; cursor: not-allowed; box-shadow: none; }

.btn-secondary {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--secondary);
  cursor: pointer;
  font-size: .8rem;
  font-weight: 500;
  padding: 8px 16px;
  transition: all .15s;
}
.btn-secondary:hover { border-color: var(--primary); color: var(--primary); }

.btn-icon {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--muted);
  cursor: pointer;
  font-size: 1.1rem;
  line-height: 1;
  padding: 9px 13px;
  transition: all .15s;
}
.btn-icon:hover { color: var(--primary); border-color: var(--primary); }

.btn-danger {
  background: none;
  border: 1px solid rgba(198,40,40,.3);
  border-radius: 6px;
  color: var(--danger);
  cursor: pointer;
  font-size: .75rem;
  padding: 4px 10px;
  transition: all .15s;
}
.btn-danger:hover { background: var(--danger-bg); }

/* ── Loading spinner ────────────────────────────────────────────────────────── */
.spinner {
  width: 20px; height: 20px;
  border: 2px solid var(--border);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin .7s linear infinite;
  display: inline-block;
  vertical-align: middle;
  margin-right: 8px;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ── Result card internals ──────────────────────────────────────────────────── */

/* Decision badge (MATCH / NO_MATCH) */
.decision-badge {
  border-radius: var(--radius);
  font-size: 1.5rem;
  font-weight: 800;
  letter-spacing: .06em;
  padding: 20px 24px;
  text-align: center;
  margin-bottom: 20px;
}
.decision-badge.match   { background: var(--success-bg); border: 2px solid rgba(46,125,50,.4); color: var(--success); }
.decision-badge.nomatch { background: var(--danger-bg);  border: 2px solid rgba(198,40,40,.4); color: var(--danger);  }

/* Score bar */
.score-section { margin-bottom: 20px; }
.score-section label {
  font-size: .72rem;
  font-weight: 600;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: .05em;
  display: block;
  margin-bottom: 8px;
}
.score-track {
  position: relative;
  height: 12px;
  background: var(--surface3);
  border-radius: 6px;
  overflow: visible;
  margin-bottom: 6px;
  border: 1px solid var(--border);
}
.score-fill {
  height: 100%;
  border-radius: 6px;
  transition: width .4s ease;
}
.score-fill.match   { background: linear-gradient(90deg, #1480D0, #4B55AD); }
.score-fill.nomatch { background: linear-gradient(90deg, #C62828, #E57373); }

.threshold-marker {
  position: absolute;
  top: -4px;
  width: 2px;
  height: 20px;
  background: var(--warning);
  border-radius: 1px;
}
.threshold-marker::after {
  content: 'T';
  position: absolute;
  top: -16px;
  left: 50%;
  transform: translateX(-50%);
  font-size: .62rem;
  color: var(--warning);
  font-weight: 700;
}
.score-nums {
  display: flex;
  justify-content: space-between;
  font-size: .75rem;
  color: var(--muted);
}
.score-nums span { font-weight: 600; }
.score-nums .score-val { color: var(--text); }

/* KV pairs */
.kv-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-bottom: 16px;
}
.kv {
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 10px 14px;
}
.kv .k { font-size: .7rem; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; margin-bottom: 4px; }
.kv .v { font-size: .88rem; font-weight: 600; font-family: 'JetBrains Mono','Fira Mono','Courier New',monospace; word-break: break-all; }
.kv .v.green  { color: var(--success); }
.kv .v.purple { color: var(--secondary); }

/* Copy row */
.copy-row {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 10px 14px;
  margin-bottom: 16px;
  font-family: 'JetBrains Mono','Fira Mono','Courier New',monospace;
  font-size: .78rem;
  word-break: break-all;
}
.copy-row .id-text { flex: 1; color: var(--primary); }
.copy-btn {
  background: none;
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--muted);
  cursor: pointer;
  font-size: .72rem;
  padding: 4px 10px;
  white-space: nowrap;
  flex-shrink: 0;
  transition: all .15s;
}
.copy-btn:hover  { color: var(--text); border-color: var(--primary); }
.copy-btn.copied { color: var(--success); border-color: var(--success); }

/* Error box */
.error-box {
  background: var(--danger-bg);
  border: 1px solid rgba(198,40,40,.3);
  border-radius: var(--radius);
  padding: 16px 20px;
  margin-bottom: 16px;
}
.error-box .err-code   { font-size: .75rem; color: var(--danger); font-weight: 700; text-transform: uppercase; margin-bottom: 6px; }
.error-box .err-detail { font-size: .85rem; color: var(--text); }

/* ── Hits table (Identify) ──────────────────────────────────────────────────── */
.stats-row {
  display: flex;
  gap: 12px;
  margin-bottom: 20px;
  flex-wrap: wrap;
}
.stat-chip {
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 20px;
  font-size: .75rem;
  padding: 5px 12px;
  color: var(--muted);
}
.stat-chip strong { color: var(--primary); }

.hits-table {
  width: 100%;
  border-collapse: collapse;
}
.hits-table th {
  font-size: .7rem;
  text-transform: uppercase;
  letter-spacing: .05em;
  color: var(--muted);
  padding: 8px 12px;
  text-align: left;
  border-bottom: 1px solid var(--border);
  background: var(--surface2);
}
.hits-table td {
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  font-size: .84rem;
}
.hits-table tr:last-child td { border-bottom: none; }
.hits-table .rank { color: var(--muted); font-size: .8rem; }
.hits-table .atpn { font-weight: 600; color: var(--primary); }
.hits-table .tid  { font-family: monospace; font-size: .72rem; color: var(--muted); }
.score-pill {
  background: var(--surface3);
  border-radius: 12px;
  display: inline-block;
  font-weight: 700;
  padding: 3px 10px;
  border: 1px solid var(--border);
}
.score-pill.hi { color: var(--success); }
.score-pill.lo { color: var(--warning); }

.no-hits {
  text-align: center;
  padding: 40px 20px;
  color: var(--muted);
  font-size: .9rem;
}

/* ── Subjects table ─────────────────────────────────────────────────────────── */
.subjects-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 20px;
}
.subj-table {
  width: 100%;
  border-collapse: collapse;
}
.subj-table th {
  font-size: .7rem;
  text-transform: uppercase;
  letter-spacing: .05em;
  color: var(--muted);
  padding: 8px 12px;
  text-align: left;
  border-bottom: 1px solid var(--border);
  background: var(--surface2);
}
.subj-table td {
  padding: 12px;
  border-bottom: 1px solid var(--border);
  font-size: .84rem;
  vertical-align: middle;
}
.subj-table tr:last-child td { border-bottom: none; }
.subj-table tr:hover td { background: var(--surface2); }
.subj-table .atpn { font-weight: 600; color: var(--primary); }
.subj-table .mono { font-family: monospace; font-size: .75rem; color: var(--muted); }

/* ── Misc ───────────────────────────────────────────────────────────────────── */
.section-label {
  font-size: .72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .06em;
  color: var(--muted);
  margin-bottom: 12px;
}
.loading-row {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 40px 20px;
  color: var(--muted);
}
