@import url('https://fonts.googleapis.com/css2?family=Space+Grotesk:wght@500;600;700&family=Inter:wght@400;500;600;700&display=swap');

:root {
  --bg: #eff2f1;
  --surface: #ffffff;
  --ink: #1e2a28;
  --ink-soft: #5b6b68;
  --line: #dde3e1;
  --teal: #2f6f62;
  --teal-dark: #204d43;
  --rust: #b5533c;
  --sage: #5c8567;
  --amber: #c79b3b;
  --radius: 10px;
  --nav-h: 64px;
  --topmenu-h: 52px;
  --topbar-h: 56px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior-y: none;
}

h1, h2, h3, .display {
  font-family: 'Space Grotesk', 'Inter', sans-serif;
  font-weight: 600;
  margin: 0;
  color: var(--ink);
}

button {
  font-family: inherit;
  cursor: pointer;
}

input, select, textarea {
  font-family: inherit;
  font-size: 16px; /* prevents iOS zoom-on-focus */
}

#app {
  max-width: 480px;
  margin: 0 auto;
  min-height: 100vh;
  background: var(--bg);
  display: flex;
  flex-direction: column;
  position: relative;
  padding-top: var(--topmenu-h);
  padding-bottom: var(--nav-h);
}

/* ---------- Top bar ---------- */
.topbar {
  height: var(--topbar-h);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 16px;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
  position: sticky;
  top: 0;
  z-index: 20;
}
.topbar h1 { font-size: 18px; }
.topbar .icon-btn { background: none; border: none; padding: 6px; color: var(--teal-dark); }

/* ---------- Top main menu ---------- */
.topmenu {
  position: fixed;
  top: 0; left: 0; right: 0;
  max-width: 480px;
  margin: 0 auto;
  height: var(--topmenu-h);
  background: var(--surface);
  border-bottom: 1px solid var(--line);
  display: flex;
  z-index: 35;
}
.topmenu-btn {
  flex: 1;
  background: none;
  border: none;
  font-weight: 600;
  font-size: 13px;
  color: var(--ink-soft);
  border-bottom: 2px solid transparent;
}
.topmenu-btn.active { color: var(--teal); border-bottom-color: var(--teal); }

.mainview { display: none; }
.mainview.active { display: block; }

.section-header {
  font-family: 'Space Grotesk', sans-serif;
  font-size: 18px;
  font-weight: 600;
  padding: 14px 16px 6px;
}

.today-heading {
  font-size: 14px;
  color: var(--ink-soft);
}
.today-heading-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 16px 0;
}
.today-jump-btn {
  background: none;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 3px 10px;
  font-size: 12px;
  color: var(--teal-dark);
  font-weight: 600;
}

.subview { display: none; padding: 10px 16px 24px; }
.subview.active { display: block; }

/* ---------- Date strip (lightweight calendar) ---------- */
.date-strip {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 10px 12px;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
  overflow-x: auto;
  scrollbar-width: none;
  position: sticky;
  top: var(--topmenu-h);
  z-index: 20;
}
.date-strip::-webkit-scrollbar { display: none; }
.date-chip {
  flex: 0 0 auto;
  width: 46px;
  padding: 8px 0;
  text-align: center;
  border-radius: var(--radius);
  border: 1px solid transparent;
  background: transparent;
  color: var(--ink-soft);
}
.date-chip .dow { display: block; font-size: 11px; text-transform: uppercase; letter-spacing: .03em; }
.date-chip .dnum { display: block; font-size: 16px; font-weight: 600; margin-top: 2px; color: var(--ink); }
.date-chip.today { border-color: var(--teal); }
.date-chip.selected { background: var(--teal); }
.date-chip.selected .dow, .date-chip.selected .dnum { color: #fff; }
.date-chip.has-data::after {
  content: '';
  display: block;
  width: 4px; height: 4px;
  border-radius: 50%;
  background: var(--amber);
  margin: 4px auto 0;
}
.date-jump { background: none; border: none; color: var(--teal-dark); font-size: 13px; padding: 4px 8px; white-space: nowrap; }

/* ---------- Views ---------- */
.view { display: none; flex: 1; padding: 14px 16px 24px; }
.view.active { display: block; }

.section {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px;
  margin-bottom: 14px;
}
.section-title {
  font-size: 13px;
  text-transform: uppercase;
  letter-spacing: .04em;
  color: var(--ink-soft);
  margin-bottom: 10px;
  font-weight: 600;
}

.accent-left { border-left: 3px solid var(--teal); }
.accent-left.warn { border-left-color: var(--rust); }
.accent-left.good { border-left-color: var(--sage); }

/* Stat row */
.stat-row { display: flex; gap: 10px; }
.stat {
  flex: 1;
  text-align: center;
  padding: 10px 4px;
}
.stat .big { font-family: 'Space Grotesk', sans-serif; font-size: 24px; font-weight: 700; }
.stat .label { font-size: 11px; color: var(--ink-soft); text-transform: uppercase; letter-spacing: .03em; }

/* Form elements */
.field { margin-bottom: 12px; }
.field label { display: block; font-size: 13px; color: var(--ink-soft); margin-bottom: 4px; }
.field input, .field select, .field textarea {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfbfa;
  color: var(--ink);
}
.field textarea { resize: vertical; min-height: 60px; }
.inline-fields { display: flex; gap: 10px; }
.inline-fields .field { flex: 1; }

.btn {
  display: inline-block;
  padding: 10px 18px;
  border-radius: 8px;
  border: none;
  background: var(--teal);
  color: #fff;
  font-weight: 600;
  font-size: 14px;
  text-align: center;
}
.btn:active { background: var(--teal-dark); }
.btn.secondary { background: transparent; color: var(--teal-dark); border: 1px solid var(--teal); }
.btn.danger { background: var(--rust); }
.btn.full { width: 100%; }
.btn.small { padding: 6px 12px; font-size: 13px; }

.banner {
  background: #fff7e8;
  border: 1px solid var(--amber);
  color: #6b5219;
  border-radius: 8px;
  padding: 10px 12px;
  font-size: 13px;
  margin-bottom: 12px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
}

/* ---------- Body map ---------- */
.bodymap-toggle {
  display: flex;
  gap: 6px;
  margin-bottom: 10px;
}
.bodymap-toggle button {
  flex: 1;
  padding: 8px;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--ink-soft);
  font-weight: 600;
}
.bodymap-toggle button.active {
  background: var(--teal);
  border-color: var(--teal);
  color: #fff;
}
.bodymap-wrap { display: flex; justify-content: center; padding: 4px 0 10px; }
.bodymap-image-wrap {
  position: relative;
  width: 100%;
  max-width: 300px;
}
.bodymap-image-wrap img { width: 100%; display: block; }
.bodymap-missing-msg { display: none; }
.bodymap-image-wrap.bodymap-missing img { display: none; }
.bodymap-image-wrap.bodymap-missing {
  min-height: 320px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #f3efe8;
  border: 1px dashed var(--line);
  border-radius: 12px;
}
.bodymap-image-wrap.bodymap-missing .bodymap-missing-msg {
  display: block;
  text-align: center;
  font-size: 12px;
  color: var(--ink-soft);
  padding: 16px;
}
.bodymap-image-wrap.bodymap-missing .bodypart { display: none; }
.bodypart {
  position: absolute;
  background: transparent;
  border: 1px solid transparent;
  cursor: pointer;
  transition: background .15s ease, border-color .15s ease;
}
.bodypart:hover { background: rgba(47,111,98,0.18); border-color: rgba(47,111,98,0.4); }
.bodypart.score-0 { background: transparent; }
.bodypart.score-low { background: rgba(92,133,103,0.5); border-color: rgba(74,56,42,0.4); }
.bodypart.score-mid { background: rgba(199,155,59,0.55); border-color: rgba(74,56,42,0.4); }
.bodypart.score-high { background: rgba(181,83,60,0.6); border-color: rgba(74,56,42,0.4); }
.legend { display: flex; gap: 14px; justify-content: center; font-size: 11px; color: var(--ink-soft); flex-wrap: wrap; }
.legend .dot { width: 9px; height: 9px; border-radius: 50%; display: inline-block; margin-right: 4px; vertical-align: middle; }

.ache-list-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 8px 0;
  border-bottom: 1px solid var(--line);
}
.ache-list-item:last-child { border-bottom: none; }
.ache-score-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 26px; height: 26px;
  border-radius: 50%;
  color: #fff;
  font-size: 12px;
  font-weight: 700;
  margin-right: 8px;
}

/* ---------- Supplements ---------- */
.supp-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 0;
  border-bottom: 1px solid var(--line);
}
.supp-row:last-child { border-bottom: none; }
.supp-row .name { font-weight: 500; }
.supp-row .dose { font-size: 12px; color: var(--ink-soft); }
.time-group { margin-bottom: 4px; }
.time-group-label {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: .03em;
  color: var(--teal-dark);
  font-weight: 700;
  padding: 10px 0 2px;
}
.time-group:first-child .time-group-label { padding-top: 0; }
.day-picker { display: flex; gap: 6px; flex-wrap: wrap; }
.day-chip {
  display: flex; align-items: center; gap: 4px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 6px 8px;
  font-size: 12px;
}
.day-chip input { margin: 0; }
.toggle {
  width: 44px; height: 26px;
  border-radius: 13px;
  background: var(--line);
  position: relative;
  border: none;
  flex-shrink: 0;
}
.toggle.on { background: var(--teal); }
.toggle .knob {
  position: absolute;
  top: 2px; left: 2px;
  width: 22px; height: 22px;
  border-radius: 50%;
  background: #fff;
  transition: left .15s ease;
}
.toggle.on .knob { left: 20px; }

/* ---------- Blood results ---------- */
.blood-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 0;
  border-bottom: 1px solid var(--line);
}
.blood-row:last-child { border-bottom: none; }
.blood-val { font-family: 'Space Grotesk', sans-serif; font-weight: 700; font-size: 16px; }
.flag-badge {
  font-size: 11px;
  font-weight: 600;
  padding: 2px 8px;
  border-radius: 10px;
  margin-left: 6px;
}
.flag-normal { background: #e4efe6; color: var(--sage); }
.flag-low, .flag-high { background: #f6e6e1; color: var(--rust); }
.info-btn { background: none; border: none; color: var(--ink-soft); font-size: 13px; padding: 2px 6px; }

/* ---------- Bottom nav ---------- */
.bottomnav {
  position: fixed;
  bottom: 0; left: 0; right: 0;
  max-width: 480px;
  margin: 0 auto;
  height: var(--nav-h);
  background: var(--surface);
  border-top: 1px solid var(--line);
  display: flex;
  z-index: 30;
}
.navbtn {
  flex: 1;
  background: none;
  border: none;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  color: var(--ink-soft);
  font-size: 11px;
  font-weight: 500;
}
.navbtn.active { color: var(--teal); }
.navbtn svg { width: 22px; height: 22px; }

/* ---------- Modal / bottom sheet ---------- */
.sheet-overlay {
  position: fixed; inset: 0;
  background: rgba(20, 30, 28, 0.45);
  z-index: 40;
  display: none;
}
.sheet-overlay.open { display: block; }
.sheet {
  position: fixed;
  left: 0; right: 0; bottom: 0;
  max-width: 480px;
  margin: 0 auto;
  background: var(--surface);
  border-radius: 16px 16px 0 0;
  padding: 18px 18px calc(18px + env(safe-area-inset-bottom));
  z-index: 41;
  transform: translateY(100%);
  transition: transform .2s ease;
  max-height: 85vh;
  overflow-y: auto;
}
.sheet.open { transform: translateY(0); }
.sheet-handle {
  width: 36px; height: 4px;
  background: var(--line);
  border-radius: 2px;
  margin: 0 auto 14px;
}
.sheet h3 { margin-bottom: 12px; }

/* Score slider */
.score-slider-wrap { text-align: center; margin: 14px 0; }
.score-value {
  font-family: 'Space Grotesk', sans-serif;
  font-size: 40px;
  font-weight: 700;
}
input[type=range] { width: 100%; accent-color: var(--teal); }

/* Auth screens */
.auth-screen {
  display: flex;
  flex-direction: column;
  justify-content: center;
  min-height: 100vh;
  padding: 32px 24px;
  max-width: 420px;
  margin: 0 auto;
}
.auth-screen h1 { font-size: 26px; margin-bottom: 4px; }
.auth-screen .sub { color: var(--ink-soft); margin-bottom: 24px; font-size: 14px; }
.auth-error { color: var(--rust); font-size: 13px; margin-top: 8px; }
.auth-switch { text-align: center; margin-top: 16px; font-size: 14px; color: var(--ink-soft); }
.auth-switch a { color: var(--teal-dark); font-weight: 600; text-decoration: none; }

.empty-state { text-align: center; padding: 30px 10px; color: var(--ink-soft); font-size: 14px; }

.chart-wrap { position: relative; height: 180px; margin-bottom: 6px; }

.pending-user-row {
  display: flex; justify-content: space-between; align-items: center;
  padding: 10px 0; border-bottom: 1px solid var(--line);
}
