/* ── Variables ─────────────────────────────────────────────── */
:root {
  --brand:          #2563eb;
  --brand-dark:     #1d4ed8;
  --text-primary:   #111827;
  --text-secondary: #6b7280;
  --text-muted:     #9ca3af;
  --danger:         #dc2626;
  --border:         #e5e7eb;
  --bg:             #f9fafb;
  --white:          #ffffff;
  --radius:         12px;
  --shadow:         0 1px 3px rgba(0,0,0,.08), 0 1px 2px rgba(0,0,0,.05);
}

/* ── Reset ─────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
body {
  font-family: 'Noto Sans TC', system-ui, sans-serif;
  font-size: 15px;
  color: var(--text-primary);
  background: var(--bg);
  line-height: 1.6;
  min-height: 100vh;
}
button { font-family: inherit; }
input, textarea, select { font-family: inherit; }

/* ── Layout ────────────────────────────────────────────────── */
.app-wrap        { min-height: 100vh; display: flex; flex-direction: column; }
.container       { max-width: 900px; margin: 0 auto; padding: 0 1.25rem; }
.container--narrow { max-width: 520px; margin: 0 auto; padding: 0 1.25rem; }

/* ── Header ────────────────────────────────────────────────── */
.site-header {
  background: var(--white);
  border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 100;
  padding: .75rem 0;
}
.header-inner {
  display: flex; align-items: center; justify-content: space-between;
}
.logo {
  display: flex; align-items: center; gap: 10px;
  text-decoration: none; color: var(--text-primary);
  font-weight: 600; font-size: 15px;
}
.logo-mark {
  width: 32px; height: 32px;
  background: var(--brand);
  border-radius: 8px;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
}
.logo-mark svg { width: 16px; height: 16px; fill: white; }
.header-nav { display: flex; gap: 1.25rem; }
.header-nav a {
  text-decoration: none;
  color: var(--text-secondary);
  font-size: 14px;
  transition: color .15s;
}
.header-nav a:hover { color: var(--brand); }

/* ── Screens ───────────────────────────────────────────────── */
.screen { display: none; }
.screen.active { display: block; }

/* ── Page sections ─────────────────────────────────────────── */
.page-hero    { padding: 2rem 0; }
.page-section { padding: 2rem 0; }
.page-hero h1 { font-size: 26px; font-weight: 700; line-height: 1.3; }
h2 { font-size: 20px; font-weight: 700; }
h3 { font-size: 16px; font-weight: 600; }

/* ── Cards ─────────────────────────────────────────────────── */
.card {
  background: var(--white);
  border-radius: var(--radius);
  padding: 1.25rem;
}
.card-surface {
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
}

/* ── Buttons ───────────────────────────────────────────────── */
.btn {
  display: inline-flex; align-items: center; justify-content: center;
  gap: 6px; padding: .6rem 1.25rem;
  border-radius: 10px; font-size: 14px; font-weight: 500;
  cursor: pointer; border: 1.5px solid transparent;
  text-decoration: none; line-height: 1.4;
  transition: background .15s, color .15s, border-color .15s, opacity .15s;
  white-space: nowrap;
}
.btn:disabled { opacity: .5; cursor: not-allowed; pointer-events: none; }
.btn-block  { width: 100%; }
.btn-lg     { padding: .8rem 1.5rem; font-size: 15px; }
.btn-sm     { padding: .35rem .875rem; font-size: 13px; border-radius: 8px; }

.btn-primary { background: var(--brand); color: #fff; border-color: var(--brand); }
.btn-primary:hover:not(:disabled) { background: var(--brand-dark); border-color: var(--brand-dark); }

.btn-outline { background: transparent; color: var(--brand); border-color: var(--brand); }
.btn-outline:hover:not(:disabled) { background: #eff6ff; }

.btn-ghost { background: transparent; color: var(--text-secondary); border-color: var(--border); }
.btn-ghost:hover:not(:disabled) { background: var(--bg); }

.btn-danger { background: var(--danger); color: #fff; border-color: var(--danger); }
.btn-danger:hover:not(:disabled) { background: #b91c1c; }

/* ── Option cards ──────────────────────────────────────────── */
.option-list  { display: flex; flex-direction: column; gap: 10px; margin-bottom: 1.25rem; }
.option-card {
  display: flex; align-items: center; gap: 14px;
  padding: 1rem 1.125rem;
  background: var(--white);
  border: 1.5px solid var(--border);
  border-radius: var(--radius);
  cursor: pointer; text-align: left; width: 100%;
  transition: border-color .15s, background .15s;
}
.option-card:hover   { border-color: var(--brand); background: #eff6ff; }
.option-card.selected { border-color: var(--brand); background: #eff6ff; }

.oc-icon  { font-size: 22px; color: var(--brand); flex-shrink: 0; }
.oc-title { display: block; font-size: 14px; font-weight: 600; margin-bottom: 2px; }
.oc-desc  { display: block; font-size: 12px; color: var(--text-secondary); line-height: 1.5; }

/* ── Progress bar ──────────────────────────────────────────── */
.progress-wrap {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 1.5rem;
}
.progress-track {
  flex: 1; height: 6px; background: #e5e7eb;
  border-radius: 100px; overflow: hidden; margin-right: .75rem;
}
.progress-fill { height: 100%; background: var(--brand); border-radius: 100px; transition: width .4s; }
.progress-label { font-size: 12px; color: var(--text-muted); white-space: nowrap; }

/* ── Forms ─────────────────────────────────────────────────── */
.form-group   { margin-bottom: 1.25rem; }
.form-label   { display: block; font-size: 13px; font-weight: 500; margin-bottom: 6px; }
.form-input, .form-textarea {
  width: 100%; padding: .6rem .875rem;
  border: 1.5px solid var(--border); border-radius: 10px;
  font-size: 14px; background: var(--white); color: var(--text-primary);
  transition: border-color .15s; outline: none;
}
.form-input:focus, .form-textarea:focus { border-color: var(--brand); }
.form-textarea { resize: vertical; min-height: 120px; }
.form-error { font-size: 12px; color: var(--danger); margin-top: 5px; display: none; }

/* ── Severity selector ─────────────────────────────────────── */
.severity-row { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 6px; }
.sev-btn {
  padding: .45rem 1rem; border-radius: 8px; font-size: 13px;
  border: 1.5px solid var(--border); background: var(--white);
  cursor: pointer; transition: border-color .15s, background .15s;
}
.sev-btn:hover  { border-color: var(--brand); }
.sev-btn.active { border-color: var(--brand); background: #eff6ff; color: var(--brand); font-weight: 600; }

/* ── Alerts ────────────────────────────────────────────────── */
.alert {
  display: flex; align-items: flex-start; gap: 10px;
  padding: .875rem 1rem; border-radius: var(--radius);
  font-size: 13px; line-height: 1.55; margin-bottom: 1rem;
}
.alert i { flex-shrink: 0; font-size: 16px; margin-top: 1px; }
.alert-info    { background: #eff6ff; color: #1e40af; border: 1px solid #bfdbfe; }
.alert-warning { background: #fffbeb; color: #92400e; border: 1px solid #fde68a; }
.alert-danger  { background: #fef2f2; color: var(--danger); border: 1px solid #fecaca; }
.alert-hidden  { display: none !important; }

/* ── Code display ──────────────────────────────────────────── */
.code-display {
  background: var(--white); border: 1.5px solid var(--border);
  border-radius: var(--radius); padding: 1.5rem;
  text-align: center; margin-bottom: 1.25rem;
}
.code-label {
  font-size: 12px; color: var(--text-muted); margin-bottom: .5rem; letter-spacing: .03em;
}
.code-value {
  font-family: 'Courier New', monospace;
  font-size: 24px; font-weight: 700;
  letter-spacing: .08em; color: var(--brand); margin-bottom: 1rem;
}
.code-actions { display: flex; justify-content: center; gap: 8px; }

/* ── Tabs ──────────────────────────────────────────────────── */
.tab-bar {
  display: flex; border-bottom: 2px solid var(--border);
  margin-bottom: 1.25rem;
}
.tab-btn {
  padding: .6rem 1.25rem; font-size: 14px; font-weight: 500;
  background: none; border: none; border-bottom: 2px solid transparent;
  margin-bottom: -2px; cursor: pointer; color: var(--text-secondary);
  transition: color .15s;
}
.tab-btn.active { color: var(--brand); border-bottom-color: var(--brand); }
.tab-panel         { display: none; }
.tab-panel.active  { display: block; }

/* ── Stats grid ────────────────────────────────────────────── */
.stats-grid {
  display: grid; grid-template-columns: repeat(3, 1fr); gap: 1rem;
  margin-bottom: 1.5rem;
}
.stat-card {
  background: var(--white); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 1.25rem; text-align: center;
}
.stat-card.urgent { border-color: #fecaca; background: #fef2f2; }
.stat-value       { font-size: 28px; font-weight: 700; color: var(--brand); }
.stat-card.urgent .stat-value { color: var(--danger); }
.stat-label       { font-size: 12px; color: var(--text-muted); margin-top: 4px; }

/* ── Divider ───────────────────────────────────────────────── */
.divider { height: 1px; background: var(--border); margin: 1.5rem 0; }

/* ── Text utilities ────────────────────────────────────────── */
.text-muted    { color: var(--text-muted); }
.text-small    { font-size: 13px; }
.text-center   { text-align: center; }

/* ── Monospace / code input ────────────────────────────────── */
.mono, .code-input {
  font-family: 'Courier New', monospace;
  letter-spacing: .05em;
}

/* ── Spinner ───────────────────────────────────────────────── */
@keyframes spin { to { transform: rotate(360deg); } }
.spinner {
  display: inline-block; width: 16px; height: 16px;
  border: 2px solid currentColor; border-right-color: transparent;
  border-radius: 50%; animation: spin .6s linear infinite;
  vertical-align: middle;
}

/* ── Modal ─────────────────────────────────────────────────── */
.modal-overlay {
  position: fixed; inset: 0;
  background: rgba(0, 0, 0, .45);
  display: flex; align-items: center; justify-content: center;
  z-index: 200; padding: 1.25rem;
}
.modal-hidden { display: none !important; }
.modal-box {
  background: var(--white); border-radius: 16px;
  padding: 1.75rem; width: 100%; max-width: 440px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, .25);
}

/* ── Responsive ────────────────────────────────────────────── */
/* ── Learn cards ───────────────────────────────────────────── */
.learn-card {
  border: 1.5px solid var(--border);
  border-radius: var(--radius);
  background: var(--white);
  overflow: hidden;
}
.learn-card-header {
  display: flex; align-items: center; justify-content: space-between;
  width: 100%; padding: .875rem 1rem;
  background: none; border: none; cursor: pointer; text-align: left;
  transition: background .15s;
}
.learn-card-header:hover { background: var(--bg); }
.learn-icon {
  width: 36px; height: 36px; border-radius: 8px;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0; font-size: 18px;
}
.learn-chevron { color: var(--text-muted); transition: transform .25s; font-size: 16px; }
.learn-card.learn-open .learn-chevron { transform: rotate(180deg); }
.learn-body {
  max-height: 0; overflow: hidden;
  transition: max-height .3s ease, padding .3s ease;
  padding: 0 1rem;
}
.learn-card.learn-open .learn-body {
  max-height: 600px;
  padding: 0 1rem 1rem;
}
.learn-list {
  font-size: 13px; color: var(--text-secondary);
  padding-left: 1.25rem; line-height: 1.85; margin-bottom: .75rem;
}
.learn-key {
  display: flex; gap: 8px; align-items: flex-start;
  background: #eff6ff; border: 1px solid #bfdbfe; border-radius: 8px;
  padding: .625rem .875rem; font-size: 12px; color: #1e40af; line-height: 1.55;
}
.learn-key i { flex-shrink: 0; margin-top: 1px; }

/* ── Precheck ──────────────────────────────────────────────── */
.pc-check, .pc-radio {
  display: flex; align-items: flex-start; gap: 10px;
  padding: .625rem .875rem;
  border: 1.5px solid var(--border); border-radius: 10px;
  cursor: pointer; font-size: 13px;
  transition: border-color .15s, background .15s;
}
.pc-check:hover, .pc-radio:hover { border-color: var(--brand); background: #eff6ff; }
.pc-check input, .pc-radio input { margin-top: 2px; flex-shrink: 0; accent-color: var(--brand); }

/* ── Score ring ─────────────────────────────────────────────── */
.pc-score-ring {
  display: inline-flex; flex-direction: column; align-items: center;
  justify-content: center;
  width: 110px; height: 110px; border-radius: 50%;
  border: 8px solid var(--border);
  margin-bottom: .5rem; transition: border-color .3s;
}
.pc-ring-high { border-color: #fca5a5; }
.pc-ring-mid  { border-color: #fcd34d; }
.pc-ring-low  { border-color: #86efac; }
.pc-score-num { font-size: 32px; font-weight: 700; line-height: 1; }
.pc-score-max { font-size: 12px; color: var(--text-muted); }

/* ── Timeline ──────────────────────────────────────────────── */
.timeline { position: relative; padding-left: 4px; }
.tl-item  { position: relative; padding-left: 22px; padding-bottom: 1rem; }
.tl-item:not(:last-child)::before {
  content: ''; position: absolute; left: 5px; top: 14px; bottom: 0;
  width: 2px; background: var(--border);
}
.tl-dot {
  position: absolute; left: 0; top: 5px;
  width: 12px; height: 12px; border-radius: 50%;
  background: var(--brand); border: 2px solid var(--white);
  box-shadow: 0 0 0 1.5px var(--brand);
}
.tl-card {
  background: var(--bg); border: 1px solid var(--border);
  border-radius: 10px; padding: .75rem .875rem;
}
.tl-head {
  display: flex; justify-content: space-between; align-items: center;
  flex-wrap: wrap; gap: 4px;
  font-size: 12px; color: var(--text-secondary); margin-bottom: .5rem;
}
.tl-date    { color: var(--text-muted); }
.tl-medical { color: #2563eb; font-weight: 600; }
.tl-behavior {
  font-size: 13px; line-height: 1.65; color: var(--text-primary);
  margin-bottom: .5rem; white-space: pre-wrap;
}
.tl-meta {
  font-size: 12px; color: var(--text-secondary);
  margin-bottom: 3px; display: flex; align-items: center; gap: 5px;
}
.tl-meta i { color: var(--text-muted); font-size: 14px; flex-shrink: 0; }
.tl-attachments { display: flex; flex-wrap: wrap; gap: 6px; margin-top: .5rem; }
.tl-att {
  display: inline-flex; align-items: center; gap: 4px;
  background: #eff6ff; color: #1e40af; border-radius: 6px;
  padding: 2px 8px; font-size: 11px;
}
.tl-hash {
  font-family: monospace; font-size: 10px; color: var(--text-muted);
  margin-top: .5rem; word-break: break-all;
}

@media (max-width: 600px) {
  .stats-grid   { grid-template-columns: 1fr; }
  .severity-row { flex-direction: column; }
  .page-hero h1 { font-size: 22px; }
  .code-value   { font-size: 20px; }
}
