:root {
  --bg-primary:     #1a1a2e;
  --bg-section:     #16213e;
  --bg-input:       #0f3460;
  --bg-active:      #e94560;
  --bg-frank:       #1a2e1a;
  --bg-frank-active:#2e7d32;

  --text-primary:   #f0f0f0;
  --text-secondary: #a0a0b0;
  --text-on-active: #ffffff;

  --migraine-0:     #2e7d32;
  --migraine-1:     #558b2f;
  --migraine-2:     #f9a825;
  --migraine-3:     #ef6c00;
  --migraine-4:     #c62828;
  --migraine-5:     #7b1fa2;

  --stress-1:       #2e7d32;
  --stress-2:       #7cb342;
  --stress-3:       #f9a825;
  --stress-4:       #ef6c00;
  --stress-5:       #c62828;

  --med-accent:     #00838f;
  --med-accent-bg:  #002b2e;
  --med-accent-dim: rgba(0,131,143,0.18);

  --tap-min:        56px;
  --tap-min-wide:   72px;
  --font-base:      18px;
  --font-large:     24px;
  --font-xlarge:    36px;
  --radius:         12px;
  --section-gap:    16px;
  --bottombar-height: 80px;
}

*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html, body {
  height: 100%;
  overflow: hidden;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  font-size: var(--font-base);
  line-height: 1.4;
  color: var(--text-primary);
  background: var(--bg-primary);
}

/* ── HEADER ─────────────────────────────────── */
#app-header {
  position: sticky;
  top: 0;
  z-index: 100;
  display: flex;
  height: 56px;
  background: var(--bg-section);
}

.tab-btn {
  flex: 1;
  border: none;
  cursor: pointer;
  font-size: var(--font-large);
  font-weight: 600;
  background: var(--bg-section);
  color: var(--text-secondary);
  height: 56px;
  min-height: var(--tap-min);
}

.tab-btn.active {
  background: var(--bg-active);
  color: var(--text-on-active);
}

/* ── MAIN CONTENT ───────────────────────────── */
#app-content {
  height: calc(100vh - 56px - var(--bottombar-height));
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

.tab-panel {
  display: none;
  max-width: 480px;
  margin: 0 auto;
  padding: var(--section-gap);
  padding-bottom: calc(var(--section-gap) * 2);
}

.tab-panel.active {
  display: block;
}

/* ── SECTION COMPONENT ──────────────────────── */
.tracker-section {
  background: var(--bg-section);
  border-radius: var(--radius);
  margin-bottom: var(--section-gap);
  overflow: hidden;
}

.section-header {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 0 16px;
  height: var(--tap-min);
  cursor: pointer;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}

.section-arrow {
  font-size: 14px;
  color: var(--text-secondary);
  display: inline-block;
  width: 16px;
}

.section-arrow.collapsed {
  transform: rotate(-90deg);
}

.section-title {
  flex: 1;
  font-size: var(--font-large);
  font-weight: 700;
  letter-spacing: 0.05em;
  color: var(--text-primary);
}

.section-check {
  color: #2e7d32;
  font-size: var(--font-large);
  font-weight: 700;
}

.section-check.hidden { display: none; }

.section-body {
  padding: 12px 16px 16px;
}

.section-body.hidden { display: none; }

/* ── BUTTON GROUP ───────────────────────────── */
.btn-group {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  margin-bottom: 12px;
}

.btn-group label {
  display: block;
  font-size: var(--font-base);
  color: var(--text-secondary);
  margin-bottom: 6px;
  font-weight: 600;
  letter-spacing: 0.05em;
}

.btn-group-row {
  display: flex;
  gap: 6px;
  width: 100%;
}

.btn {
  flex: 1;
  min-height: var(--tap-min);
  min-width: 44px;
  border: 2px solid transparent;
  border-radius: var(--radius);
  background: var(--bg-input);
  color: var(--text-primary);
  font-size: var(--font-base);
  font-weight: 600;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  padding: 0 8px;
}

.btn:hover {
  filter: brightness(1.1);
}

.btn.active {
  border-color: var(--text-primary);
  background: var(--bg-active);
  color: var(--text-on-active);
}

/* ── BOTTOM BAR ─────────────────────────────── */
#bottom-bar {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  min-height: var(--bottombar-height);
  background: var(--bg-section);
  border-top: 1px solid var(--bg-input);
  display: flex;
  align-items: flex-end;
  padding: 0 16px 12px;
  gap: 12px;
  z-index: 200;
}

#event-time-block {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.time-row {
  display: flex;
  align-items: center;
  gap: 10px;
}

.time-display {
  font-size: var(--font-xlarge);
  font-weight: 700;
  color: var(--text-primary);
  cursor: pointer;
  line-height: 1;
  -webkit-tap-highlight-color: transparent;
}

.time-display.frozen {
  border-bottom: 2px solid var(--bg-active);
}

.time-adjust-row {
  display: flex;
  gap: 6px;
}

.time-adj-btn {
  flex: 1;
  min-height: 44px;
  background: var(--bg-input);
  border: 2px solid transparent;
  border-radius: var(--radius);
  color: var(--text-primary);
  font-size: var(--font-base);
  font-weight: 700;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

.time-adj-btn:active {
  background: var(--bg-active);
  color: var(--text-on-active);
}

.date-display {
  font-size: var(--font-base);
  color: var(--text-secondary);
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

.date-adjust-row {
  display: flex;
  align-items: center;
  gap: 8px;
}

.date-adj-btn {
  min-height: 44px;
  padding: 0 16px;
  background: var(--bg-input);
  border: 2px solid transparent;
  border-radius: var(--radius);
  color: var(--text-primary);
  font-size: var(--font-base);
  font-weight: 700;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  white-space: nowrap;
}

.date-adj-btn:active {
  background: var(--bg-active);
  color: var(--text-on-active);
}

.reset-link {
  font-size: 14px;
  color: var(--bg-active);
  cursor: pointer;
  text-decoration: underline;
  white-space: nowrap;
}

.reset-link.hidden { display: none; }

.bottom-actions {
  display: flex;
  gap: 8px;
  align-items: flex-end;
  flex-shrink: 0;
}

#log-btn {
  min-width: 64px;
  min-height: 56px;
  background: var(--bg-input);
  color: var(--text-primary);
  border: 2px solid transparent;
  border-radius: var(--radius);
  font-size: var(--font-large);
  font-weight: 700;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  padding: 0 14px;
}

#log-btn.active {
  background: var(--bg-section);
  border-color: var(--text-secondary);
}

#save-btn {
  min-width: 72px;
  min-height: 56px;
  background: var(--bg-active);
  color: var(--text-on-active);
  border: none;
  border-radius: var(--radius);
  font-size: var(--font-large);
  font-weight: 700;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  padding: 0 16px;
}

#save-btn.success {
  background: #2e7d32;
}

#save-btn.error {
  background: var(--migraine-4);
}

.date-cal-btn {
  flex: 1;
}

/* ── CALENDAR OVERLAY ───────────────────────── */
.date-cal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.65);
  z-index: 300;
  display: flex;
  align-items: flex-end;
  justify-content: center;
}

.date-cal-overlay.hidden { display: none; }

.date-cal {
  background: var(--bg-section);
  border-radius: var(--radius) var(--radius) 0 0;
  width: 100%;
  max-width: 480px;
  padding: 20px 16px calc(var(--bottombar-height) + 24px);
}

.date-cal-nav {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 20px;
}

.date-cal-nav button {
  background: var(--bg-input);
  border: none;
  border-radius: var(--radius);
  color: var(--text-primary);
  font-size: var(--font-large);
  font-weight: 700;
  width: 56px;
  height: 56px;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

#cal-month-year {
  font-size: var(--font-large);
  font-weight: 700;
  color: var(--text-primary);
}

.date-cal-weekdays {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 4px;
  margin-bottom: 8px;
  text-align: center;
}

.date-cal-weekdays span {
  font-size: 15px;
  font-weight: 700;
  color: var(--text-secondary);
  padding: 4px 0;
}

.date-cal-grid {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 4px;
}

.cal-day, .cal-empty {
  aspect-ratio: 1;
  border-radius: var(--radius);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: var(--font-large);
  font-weight: 600;
}

.cal-day {
  background: var(--bg-input);
  border: 2px solid transparent;
  color: var(--text-primary);
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

.cal-empty { background: none; }

.cal-day.today { border-color: var(--text-secondary); }

.cal-day.selected {
  background: var(--bg-active);
  color: var(--text-on-active);
  border-color: var(--text-primary);
}

/* ── TOAST ──────────────────────────────────── */
#toast-container {
  position: fixed;
  top: 64px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 500;
  display: flex;
  flex-direction: column;
  gap: 8px;
  pointer-events: none;
  max-width: 480px;
  width: calc(100% - 32px);
}

.toast {
  padding: 12px 20px;
  border-radius: var(--radius);
  font-size: var(--font-base);
  font-weight: 600;
  color: #fff;
  text-align: center;
}

.toast.success { background: #2e7d32; }
.toast.error   { background: var(--migraine-4); }
.toast.info    { background: var(--bg-input); color: var(--text-primary); }

/* ── ERROR SCREEN ───────────────────────────── */
#error-screen {
  display: none;
  position: fixed;
  inset: 0;
  background: var(--bg-primary);
  z-index: 9999;
  justify-content: center;
  align-items: center;
  text-align: center;
  padding: 32px;
}

#error-screen.visible {
  display: flex;
}

#error-screen h1 {
  font-size: var(--font-xlarge);
  color: var(--migraine-4);
  margin-bottom: 16px;
}

#error-screen p {
  font-size: var(--font-large);
  color: var(--text-secondary);
}

/* ── MODAL ──────────────────────────────────── */
.modal-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.7);
  z-index: 400;
  justify-content: center;
  align-items: flex-start;
  padding-top: 60px;
}

.modal-overlay.visible {
  display: flex;
}

.modal {
  background: var(--bg-section);
  border-radius: var(--radius);
  width: calc(100% - 32px);
  max-width: 480px;
  max-height: 80vh;
  overflow-y: auto;
  padding: 20px;
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 16px;
}

.modal-title {
  font-size: var(--font-large);
  font-weight: 700;
}

.modal-close {
  background: none;
  border: none;
  color: var(--text-secondary);
  font-size: var(--font-large);
  cursor: pointer;
  min-width: 44px;
  min-height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* ── LOG OVERLAY ────────────────────────────── */
.log-overlay {
  position: fixed;
  top: 56px;
  bottom: var(--bottombar-height);
  left: 0;
  right: 0;
  z-index: 150;
  background: var(--bg-primary);
  display: flex;
  flex-direction: column;
}

.log-overlay.hidden { display: none; }

.log-date-heading {
  padding: 14px 16px 10px;
  font-size: var(--font-large);
  font-weight: 700;
  color: var(--text-primary);
  border-bottom: 1px solid var(--bg-input);
  flex-shrink: 0;
}

.log-entries {
  flex: 1;
  overflow-y: scroll;
  scrollbar-gutter: stable;
  padding: 8px 0;
  max-width: 480px;
  width: 100%;
  margin: 0 auto;
}

.log-entry {
  display: flex;
  gap: 14px;
  padding: 10px 16px;
  border-bottom: 1px solid var(--bg-section);
}

.log-time {
  font-size: var(--font-base);
  font-weight: 700;
  color: var(--text-secondary);
  min-width: 38px;
  flex-shrink: 0;
  font-variant-numeric: tabular-nums;
}

.log-items {
  flex: 1;
  font-size: var(--font-base);
  color: var(--text-primary);
  line-height: 1.5;
}

.log-empty,
.log-loading {
  padding: 32px 16px;
  color: var(--text-secondary);
  font-size: var(--font-base);
  text-align: center;
}

.log-nav {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 16px;
  border-top: 1px solid var(--bg-input);
  flex-shrink: 0;
  max-width: 480px;
  width: 100%;
  margin: 0 auto;
}

.log-nav-btn {
  min-width: 64px;
  min-height: 52px;
  background: var(--bg-input);
  border: 2px solid transparent;
  border-radius: var(--radius);
  color: var(--text-primary);
  font-size: var(--font-large);
  font-weight: 700;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

.log-nav-btn:disabled {
  color: var(--text-secondary);
  opacity: 0.4;
  cursor: default;
}

/* ── INPUTS ─────────────────────────────────── */
.text-input,
.search-input,
textarea {
  width: 100%;
  min-height: var(--tap-min);
  background: var(--bg-input);
  border: 2px solid transparent;
  border-radius: var(--radius);
  color: var(--text-primary);
  font-size: var(--font-base);
  padding: 8px 12px;
  font-family: inherit;
}

.text-input:focus,
.search-input:focus,
textarea:focus {
  outline: none;
  border-color: var(--bg-active);
}

textarea {
  min-height: 90px;
  resize: vertical;
}

.text-input::placeholder,
.search-input::placeholder,
textarea::placeholder {
  color: var(--text-secondary);
}

/* ── LABEL ──────────────────────────────────── */
.field-label {
  display: block;
  font-size: var(--font-base);
  font-weight: 600;
  color: var(--text-secondary);
  letter-spacing: 0.05em;
  margin-bottom: 6px;
  margin-top: 12px;
}

.field-label:first-child { margin-top: 0; }

/* ── UTILITY ────────────────────────────────── */
.hidden { display: none !important; }

.chip-list {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 8px;
}

.chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: var(--bg-input);
  border-radius: 20px;
  padding: 6px 12px;
  font-size: var(--font-base);
  min-height: 40px;
}

.chip-remove {
  background: none;
  border: none;
  color: var(--text-secondary);
  cursor: pointer;
  font-size: 18px;
  padding: 0;
  line-height: 1;
  min-width: 24px;
  min-height: 24px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.grid-3 {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 6px;
}

.nova-badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 8px;
  font-size: 14px;
  font-weight: 700;
}

.nova-1 { background: #2e7d32; color: #fff; }
.nova-2 { background: #7cb342; color: #fff; }
.nova-3 { background: #ef6c00; color: #fff; }
.nova-4 { background: #c62828; color: #fff; }
