/* ===== DESIGN TOKENS ===== */
:root {
  --bg: #eef3f7;
  --bg-card: #ffffff;
  --bg-card-alt: #f5f9fc;
  --primary: #4a7c89;
  --primary-dark: #3a6270;
  --primary-light: #7aadb8;
  --accent: #6b8f71;
  --accent-light: #9bbfa0;
  --warn: #c0804a;
  --warn-bg: #fdf3eb;
  --danger: #a05050;
  --danger-bg: #fdf0f0;
  --text: #2d3748;
  --text-mid: #4a5568;
  --text-muted: #718096;
  --border: #d1dde6;
  --border-light: #e8eff4;
  --shadow: 0 2px 8px rgba(74, 124, 137, 0.10);
  --shadow-lg: 0 4px 20px rgba(74, 124, 137, 0.15);
  --radius: 12px;
  --radius-sm: 8px;
  --radius-lg: 20px;
  --font: 'Segoe UI', system-ui, -apple-system, sans-serif;
  --nav-h: 64px;
  --header-h: 56px;
}

/* ===== RESET & BASE ===== */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 16px; -webkit-text-size-adjust: 100%; }
body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  min-height: 100dvh;
  overscroll-behavior: none;
  -webkit-font-smoothing: antialiased;
}
button { cursor: pointer; font-family: var(--font); }
input, select, textarea { font-family: var(--font); font-size: 1rem; }
a { color: var(--primary); text-decoration: none; }

/* ===== APP SHELL ===== */
#app {
  display: flex;
  flex-direction: column;
  min-height: 100dvh;
  max-width: 480px;
  margin: 0 auto;
  position: relative;
}

/* ===== HEADER ===== */
.app-header {
  height: var(--header-h);
  background: var(--primary);
  color: white;
  display: flex;
  align-items: center;
  padding: 0 16px;
  gap: 12px;
  position: sticky;
  top: 0;
  z-index: 100;
  box-shadow: 0 2px 8px rgba(0,0,0,0.15);
}
.app-header h1 {
  font-size: 1.1rem;
  font-weight: 600;
  flex: 1;
}
.btn-back {
  background: none;
  border: none;
  color: white;
  font-size: 1.4rem;
  padding: 4px 8px 4px 0;
  line-height: 1;
}
.header-icon {
  font-size: 1.3rem;
  opacity: 0.9;
}

/* ===== BOTTOM NAV ===== */
.bottom-nav {
  height: var(--nav-h);
  background: var(--bg-card);
  border-top: 1px solid var(--border);
  display: flex;
  align-items: stretch;
  position: sticky;
  bottom: 0;
  z-index: 100;
  box-shadow: 0 -2px 12px rgba(0,0,0,0.08);
}
.nav-item {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 0.68rem;
  font-weight: 500;
  padding: 6px 4px;
  transition: color 0.15s;
  -webkit-tap-highlight-color: transparent;
}
.nav-item .nav-icon { font-size: 1.45rem; line-height: 1; }
.nav-item.active { color: var(--primary); }
.nav-item.active .nav-icon { transform: scale(1.1); }

/* ===== SCREEN CONTAINER ===== */
.screen {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  padding-bottom: 24px;
  display: none;
}
.screen.active { display: block; }

/* ===== FATIGUE GATE (full overlay) ===== */
#screen-fatigue-gate {
  position: fixed;
  inset: 0;
  z-index: 999;
  background: var(--bg);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 32px 24px;
  text-align: center;
}
#screen-fatigue-gate.hidden { display: none; }
.gate-title {
  font-size: 1.4rem;
  font-weight: 600;
  color: var(--primary);
  margin-bottom: 8px;
}
.gate-sub {
  color: var(--text-mid);
  margin-bottom: 32px;
  line-height: 1.5;
}
.scale-row {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  justify-content: center;
  margin-bottom: 20px;
}
.scale-btn {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  border: 2px solid var(--border);
  background: var(--bg-card);
  font-size: 1rem;
  font-weight: 600;
  color: var(--text-mid);
  transition: all 0.15s;
}
.scale-btn:hover { border-color: var(--primary); color: var(--primary); }
.scale-btn.selected { background: var(--primary); border-color: var(--primary); color: white; }
.scale-btn.high { border-color: var(--warn); }
.scale-btn.high.selected { background: var(--warn); border-color: var(--warn); }
.scale-labels {
  display: flex;
  justify-content: space-between;
  width: 100%;
  max-width: 360px;
  color: var(--text-muted);
  font-size: 0.78rem;
  margin-bottom: 28px;
}

/* ===== CARDS ===== */
.card {
  background: var(--bg-card);
  border-radius: var(--radius);
  padding: 16px;
  box-shadow: var(--shadow);
  margin-bottom: 14px;
}
.card-title {
  font-size: 1rem;
  font-weight: 600;
  color: var(--primary);
  margin-bottom: 8px;
  display: flex;
  align-items: center;
  gap: 8px;
}
.card-sub {
  font-size: 0.85rem;
  color: var(--text-muted);
  line-height: 1.5;
}

/* ===== SECTION HEADERS ===== */
.section-header {
  font-size: 0.78rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: var(--text-muted);
  margin: 20px 0 10px;
}
.section-header:first-child { margin-top: 4px; }

/* ===== BUTTONS ===== */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 13px 22px;
  border-radius: var(--radius-sm);
  font-size: 0.97rem;
  font-weight: 600;
  border: none;
  transition: all 0.15s;
  -webkit-tap-highlight-color: transparent;
}
.btn-primary {
  background: var(--primary);
  color: white;
}
.btn-primary:hover, .btn-primary:active { background: var(--primary-dark); }
.btn-accent {
  background: var(--accent);
  color: white;
}
.btn-outline {
  background: transparent;
  border: 2px solid var(--primary);
  color: var(--primary);
}
.btn-ghost {
  background: transparent;
  color: var(--text-mid);
  font-weight: 500;
  font-size: 0.9rem;
  text-decoration: underline;
  padding: 8px 0;
}
.btn-warn {
  background: var(--warn);
  color: white;
}
.btn-danger {
  background: var(--danger);
  color: white;
}
.btn-full { width: 100%; }
.btn-sm { padding: 8px 14px; font-size: 0.85rem; }

/* ===== FORM ELEMENTS ===== */
.form-group { margin-bottom: 18px; }
.form-label {
  display: block;
  font-size: 0.88rem;
  font-weight: 600;
  color: var(--text-mid);
  margin-bottom: 6px;
}
.form-input {
  width: 100%;
  padding: 11px 14px;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 0.97rem;
  color: var(--text);
  background: var(--bg-card);
  transition: border-color 0.15s;
}
.form-input:focus {
  outline: none;
  border-color: var(--primary);
}
.form-hint {
  font-size: 0.8rem;
  color: var(--text-muted);
  margin-top: 5px;
  line-height: 1.4;
}
select.form-input { appearance: none; background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath d='M1 1l5 5 5-5' stroke='%23718096' stroke-width='1.5' fill='none' stroke-linecap='round'/%3E%3C/svg%3E"); background-repeat: no-repeat; background-position: right 14px center; padding-right: 36px; }

/* ===== QUESTIONNAIRE ===== */
.q-item {
  background: var(--bg-card-alt);
  border-radius: var(--radius-sm);
  padding: 14px;
  margin-bottom: 10px;
  border: 1.5px solid var(--border-light);
}
.q-text {
  font-size: 0.93rem;
  color: var(--text);
  line-height: 1.45;
  margin-bottom: 12px;
}
.q-scale {
  display: flex;
  gap: 6px;
}
.q-opt {
  flex: 1;
  padding: 10px 4px;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg-card);
  font-size: 0.8rem;
  color: var(--text-mid);
  text-align: center;
  cursor: pointer;
  transition: all 0.15s;
  line-height: 1.2;
}
.q-opt:hover { border-color: var(--primary-light); }
.q-opt.selected {
  background: var(--primary);
  border-color: var(--primary);
  color: white;
  font-weight: 600;
}
.q-opt-val { font-size: 1.1rem; font-weight: 700; display: block; }

/* ===== PROGRESS BAR ===== */
.progress-bar-wrap {
  background: var(--border-light);
  border-radius: 99px;
  height: 6px;
  margin-bottom: 20px;
  overflow: hidden;
}
.progress-bar-fill {
  height: 100%;
  background: var(--primary);
  border-radius: 99px;
  transition: width 0.3s ease;
}
.progress-label {
  font-size: 0.8rem;
  color: var(--text-muted);
  text-align: right;
  margin-bottom: 6px;
}

/* ===== STATUS CHIPS ===== */
.chip {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 4px 10px;
  border-radius: 99px;
  font-size: 0.78rem;
  font-weight: 600;
}
.chip-primary { background: #ddeef2; color: var(--primary-dark); }
.chip-accent { background: #ddeee0; color: #3d6641; }
.chip-warn { background: var(--warn-bg); color: #8a5a28; }
.chip-danger { background: var(--danger-bg); color: var(--danger); }

/* ===== ALERT BOXES ===== */
.alert {
  padding: 14px 16px;
  border-radius: var(--radius-sm);
  font-size: 0.9rem;
  line-height: 1.5;
  margin-bottom: 16px;
  display: flex;
  gap: 10px;
  align-items: flex-start;
}
.alert-icon { font-size: 1.1rem; flex-shrink: 0; margin-top: 1px; }
.alert-warn { background: var(--warn-bg); color: #6b4020; border-left: 4px solid var(--warn); }
.alert-info { background: #ddeef2; color: #2a5560; border-left: 4px solid var(--primary); }
.alert-ok { background: #ddeee0; color: #2e4f32; border-left: 4px solid var(--accent); }

/* ===== HOME SCREEN GRID ===== */
.home-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  margin-bottom: 16px;
}
.home-tile {
  background: var(--bg-card);
  border-radius: var(--radius);
  padding: 18px 14px;
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  gap: 8px;
  border: none;
  cursor: pointer;
  transition: box-shadow 0.15s, transform 0.15s;
  -webkit-tap-highlight-color: transparent;
}
.home-tile:active { transform: scale(0.97); box-shadow: var(--shadow-lg); }
.home-tile-icon { font-size: 2rem; }
.home-tile-label { font-size: 0.82rem; font-weight: 600; color: var(--text); line-height: 1.3; }
.home-tile-status { font-size: 0.73rem; color: var(--text-muted); }
.home-tile.tile-accent { border-top: 3px solid var(--accent); }
.home-tile.tile-primary { border-top: 3px solid var(--primary); }
.home-tile.tile-warn { border-top: 3px solid var(--warn); }

/* ===== NASA LEAN TEST ===== */
.nasa-grid {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 8px;
  margin-bottom: 12px;
}
.nasa-cell {
  background: var(--bg-card-alt);
  border: 1.5px solid var(--border-light);
  border-radius: var(--radius-sm);
  padding: 8px;
  text-align: center;
}
.nasa-cell-label { font-size: 0.72rem; color: var(--text-muted); margin-bottom: 4px; }
.nasa-cell input {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 6px 4px;
  text-align: center;
  font-size: 0.9rem;
  background: white;
}
.nasa-result-card {
  background: linear-gradient(135deg, #ddeef2, #ddeee0);
  border-radius: var(--radius);
  padding: 18px;
  margin-top: 16px;
}
.nasa-result-title {
  font-weight: 700;
  color: var(--primary-dark);
  margin-bottom: 12px;
}
.nasa-metric {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  padding: 6px 0;
  border-bottom: 1px solid rgba(74,124,137,0.15);
  font-size: 0.9rem;
}
.nasa-metric:last-child { border-bottom: none; }
.nasa-metric-val { font-weight: 700; color: var(--primary); font-size: 1.1rem; }
.nasa-interp { margin-top: 12px; font-size: 0.87rem; color: var(--text-mid); line-height: 1.5; font-style: italic; }

/* ===== MED LIST ===== */
.med-item {
  background: var(--bg-card);
  border-radius: var(--radius-sm);
  padding: 13px 14px;
  margin-bottom: 8px;
  border: 1.5px solid var(--border-light);
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 10px;
}
.med-name { font-weight: 600; font-size: 0.95rem; color: var(--text); }
.med-detail { font-size: 0.8rem; color: var(--text-muted); margin-top: 2px; }
.med-actions { display: flex; gap: 6px; flex-shrink: 0; }
.btn-icon {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  border: 1.5px solid var(--border);
  background: var(--bg-card);
  font-size: 0.9rem;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-mid);
  cursor: pointer;
  transition: all 0.15s;
}
.btn-icon:hover { border-color: var(--danger); color: var(--danger); }

/* ===== DIVIDER ===== */
.divider { height: 1px; background: var(--border-light); margin: 16px 0; }

/* ===== MODAL ===== */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.45);
  z-index: 500;
  display: flex;
  align-items: flex-end;
  justify-content: center;
}
.modal-overlay.hidden { display: none; }
.modal-sheet {
  background: var(--bg-card);
  border-radius: var(--radius-lg) var(--radius-lg) 0 0;
  width: 100%;
  max-width: 480px;
  max-height: 90dvh;
  overflow-y: auto;
  padding: 24px 20px 32px;
}
.modal-handle {
  width: 40px;
  height: 5px;
  background: var(--border);
  border-radius: 99px;
  margin: 0 auto 20px;
}
.modal-title {
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--text);
  margin-bottom: 16px;
}

/* ===== SLEEP TRACKER ===== */
.sleep-goal-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 14px;
  background: var(--bg-card);
  border-radius: var(--radius-sm);
  border: 1.5px solid var(--border-light);
  margin-bottom: 8px;
}
.sleep-goal-check {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  border: 2px solid var(--border);
  background: white;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  cursor: pointer;
  font-size: 1rem;
  transition: all 0.15s;
}
.sleep-goal-check.done { background: var(--accent); border-color: var(--accent); color: white; }
.sleep-goal-text { flex: 1; font-size: 0.9rem; color: var(--text); }

/* ===== EMPTY STATE ===== */
.empty-state {
  text-align: center;
  padding: 40px 20px;
  color: var(--text-muted);
}
.empty-state-icon { font-size: 3rem; margin-bottom: 12px; }
.empty-state-text { font-size: 0.92rem; line-height: 1.5; }

/* ===== UTILITIES ===== */
.mt-8 { margin-top: 8px; }
.mt-12 { margin-top: 12px; }
.mt-16 { margin-top: 16px; }
.mt-24 { margin-top: 24px; }
.mb-4 { margin-bottom: 4px; }
.text-center { text-align: center; }
.text-muted { color: var(--text-muted); font-size: 0.88rem; }
.flex-row { display: flex; align-items: center; gap: 10px; }
.flex-1 { flex: 1; }
.bold { font-weight: 700; }
.hidden { display: none !important; }

/* ===== ANIMATIONS ===== */
@keyframes fadeIn { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }
.fade-in { animation: fadeIn 0.25s ease forwards; }

/* ===== SCROLLBAR ===== */
::-webkit-scrollbar { width: 4px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 99px; }
