/* Frank tab uses green accent */
body.frank-active {
  background: var(--bg-frank);
}

/* ── FRANK SUB-TAB NAV ──────────────────────── */
.frank-subtabs {
  display: flex;
  gap: 6px;
  margin-bottom: var(--section-gap);
  flex-wrap: wrap;
}

.frank-med-btn {
  min-height: var(--tap-min);
  padding: 0 14px;
  background: var(--med-accent-dim);
  border: 2px solid var(--med-accent);
  border-radius: var(--radius);
  color: var(--med-accent);
  font-size: var(--font-base);
  font-weight: 700;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  white-space: nowrap;
}

.frank-subtab-btn {
  flex: 1;
  min-height: var(--tap-min);
  background: var(--bg-section);
  border: 2px solid transparent;
  border-radius: var(--radius);
  color: var(--text-secondary);
  font-size: var(--font-base);
  font-weight: 600;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

.frank-subtab-btn.active {
  background: var(--bg-frank-active);
  color: #fff;
  border-color: var(--bg-frank-active);
}

.frank-subpanel {
  display: none;
}

.frank-subpanel.active {
  display: block;
}

/* ── INGREDIENT BUILDER ─────────────────────── */
.ingredient-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 0;
  border-bottom: 1px solid var(--bg-input);
}

.ingredient-row:last-child {
  border-bottom: none;
}

.ingredient-name {
  flex: 1;
  font-size: var(--font-base);
  font-weight: 600;
}

.qty-input {
  width: 72px;
  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: 0 8px;
  text-align: right;
}

.qty-input:focus {
  outline: none;
  border-color: var(--bg-frank-active);
}

.unit-select {
  background: var(--bg-input);
  border: 2px solid transparent;
  border-radius: var(--radius);
  color: var(--text-primary);
  font-size: var(--font-base);
  height: var(--tap-min);
  padding: 0 6px;
  min-width: 80px;
  cursor: pointer;
}

.unit-select:focus {
  outline: none;
  border-color: var(--bg-frank-active);
}

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

/* ── NUTRITION TOTALS ───────────────────────── */
.nutrition-totals {
  background: var(--bg-input);
  border-radius: var(--radius);
  padding: 12px 16px;
  margin: 12px 0;
}

.nutrition-totals-title {
  font-size: var(--font-base);
  font-weight: 700;
  color: var(--text-secondary);
  letter-spacing: 0.05em;
  margin-bottom: 8px;
}

.nutrition-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 4px 16px;
}

.nutrition-item {
  font-size: var(--font-base);
  color: var(--text-primary);
}

.nutrition-label {
  color: var(--text-secondary);
  font-size: 16px;
}

/* ── TEMPLATE LIST ──────────────────────────── */
.template-list-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 12px;
  background: var(--bg-input);
  border-radius: var(--radius);
  margin-bottom: 8px;
  min-height: var(--tap-min);
}

.template-list-name {
  flex: 1;
  font-size: var(--font-base);
  font-weight: 600;
}

.template-list-type {
  font-size: 14px;
  color: var(--text-secondary);
  min-width: 60px;
}

.edit-btn {
  min-height: 44px;
  min-width: 60px;
  background: var(--bg-section);
  border: 2px solid var(--bg-frank-active);
  border-radius: var(--radius);
  color: var(--bg-frank-active);
  font-size: var(--font-base);
  font-weight: 600;
  cursor: pointer;
  padding: 0 12px;
}

/* ── INGREDIENT LIST ────────────────────────── */
.ingredient-list-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 12px;
  background: var(--bg-input);
  border-radius: var(--radius);
  margin-bottom: 8px;
  min-height: var(--tap-min);
}

.ingredient-list-name {
  flex: 1;
  font-size: var(--font-base);
  font-weight: 600;
}

.ingredient-list-meta {
  font-size: 14px;
  color: var(--text-secondary);
  text-align: right;
}

/* ── FRANK ACTION BUTTONS ───────────────────── */
.frank-action-row {
  display: flex;
  gap: 8px;
  margin-top: 12px;
}

.frank-primary-btn {
  flex: 1;
  min-height: var(--tap-min);
  background: var(--bg-frank-active);
  border: none;
  border-radius: var(--radius);
  color: #fff;
  font-size: var(--font-base);
  font-weight: 700;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  padding: 0 12px;
}

.frank-secondary-btn {
  flex: 1;
  min-height: var(--tap-min);
  background: var(--bg-input);
  border: 2px solid var(--bg-frank-active);
  border-radius: var(--radius);
  color: var(--bg-frank-active);
  font-size: var(--font-base);
  font-weight: 700;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  padding: 0 12px;
}

.frank-danger-btn {
  min-height: var(--tap-min);
  background: var(--bg-input);
  border: 2px solid var(--migraine-4);
  border-radius: var(--radius);
  color: var(--migraine-4);
  font-size: var(--font-base);
  font-weight: 700;
  cursor: pointer;
  padding: 0 16px;
}

/* ── TEMPLATE SELECTOR ──────────────────────── */
.template-load-row {
  display: flex;
  gap: 8px;
  margin-bottom: 12px;
}

.template-select {
  flex: 1;
  background: var(--bg-input);
  border: 2px solid transparent;
  border-radius: var(--radius);
  color: var(--text-primary);
  font-size: var(--font-base);
  height: var(--tap-min);
  padding: 0 12px;
  cursor: pointer;
}

.template-select:focus {
  outline: none;
  border-color: var(--bg-frank-active);
}

/* ── SECTION DIVIDER ────────────────────────── */
.section-divider {
  font-size: 14px;
  font-weight: 700;
  color: var(--text-secondary);
  letter-spacing: 0.1em;
  text-transform: uppercase;
  margin: 16px 0 8px;
  display: flex;
  align-items: center;
  gap: 8px;
}

.section-divider::before,
.section-divider::after {
  content: '';
  flex: 1;
  height: 1px;
  background: var(--bg-input);
}

/* ── OFF SEARCH MODAL ───────────────────────── */
.off-result-item {
  padding: 12px;
  border-bottom: 1px solid var(--bg-input);
  cursor: pointer;
  min-height: 64px;
  -webkit-tap-highlight-color: transparent;
}

.off-result-item:hover {
  background: var(--bg-input);
  border-radius: var(--radius);
}

.off-result-name {
  font-size: var(--font-base);
  font-weight: 600;
  margin-bottom: 4px;
}

.off-result-meta {
  font-size: 14px;
  color: var(--text-secondary);
}

/* ── EDIT FORM ──────────────────────────────── */
.edit-form {
  background: var(--bg-section);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: var(--section-gap);
}

.edit-form-title {
  font-size: var(--font-large);
  font-weight: 700;
  margin-bottom: 16px;
  color: var(--text-primary);
}

.form-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.form-row .field-label { margin-top: 0; }

/* ── TAG CHIPS ──────────────────────────────── */
.tag-input-row {
  display: flex;
  gap: 8px;
  align-items: center;
  margin-top: 8px;
}

.add-tag-btn {
  min-height: 44px;
  min-width: 44px;
  background: var(--bg-input);
  border: 2px solid var(--bg-frank-active);
  border-radius: var(--radius);
  color: var(--bg-frank-active);
  font-size: var(--font-large);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* ── MEDICINE CRUD OVERLAY ──────────────────── */
.med-overlay {
  position: fixed;
  top: 56px;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 250;
  background: var(--med-accent-bg);
  display: flex;
  flex-direction: column;
}
.med-overlay.hidden { display: none; }

.med-ov-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px;
  background: rgba(0,0,0,0.3);
  border-bottom: 2px solid var(--med-accent);
  flex-shrink: 0;
}

.med-ov-title {
  font-size: var(--font-large);
  font-weight: 700;
  color: var(--med-accent);
  letter-spacing: 0.06em;
}

.med-new-btn {
  min-height: 44px;
  padding: 0 18px;
  background: var(--med-accent);
  border: none;
  border-radius: var(--radius);
  color: #fff;
  font-size: var(--font-base);
  font-weight: 700;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

/* Scrollable content area */
.med-scroll-view {
  flex: 1;
  overflow-y: auto;
  padding: 12px 16px;
  max-width: 480px;
  width: 100%;
  margin: 0 auto;
}

/* Medicine list */
.med-list-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 16px;
  background: rgba(0,131,143,0.08);
  border: 1px solid rgba(0,131,143,0.25);
  border-radius: var(--radius);
  margin-bottom: 8px;
}

.med-list-info { flex: 1; min-width: 0; }

.med-list-name {
  display: block;
  font-size: var(--font-base);
  font-weight: 700;
  color: var(--text-primary);
}

.med-list-doses {
  display: block;
  font-size: 14px;
  color: var(--text-secondary);
  margin-top: 3px;
}

.med-edit-btn {
  min-height: 44px;
  padding: 0 16px;
  background: var(--med-accent-dim);
  border: 2px solid var(--med-accent);
  border-radius: var(--radius);
  color: var(--med-accent);
  font-size: var(--font-base);
  font-weight: 700;
  cursor: pointer;
  flex-shrink: 0;
  -webkit-tap-highlight-color: transparent;
}

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

/* Form view */
.med-form-title {
  font-size: var(--font-large);
  font-weight: 700;
  color: var(--med-accent);
  margin-bottom: 16px;
}

/* Override text-input focus color inside overlay */
#med-overlay .text-input:focus {
  border-color: var(--med-accent);
}

/* Override type buttons active color */
#mof-type-btns .btn.active {
  background: var(--med-accent);
  border-color: var(--med-accent);
  color: #fff;
}

/* Doses */
.mof-doses-list {
  background: rgba(0,0,0,0.2);
  border-radius: var(--radius);
  overflow: hidden;
  margin-bottom: 4px;
}

.mof-dose-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  border-bottom: 1px solid rgba(0,131,143,0.15);
}
.mof-dose-row:last-child { border-bottom: none; }

.mof-dose-value,
.mof-dose-unit {
  min-height: 44px;
  background: var(--bg-input);
  border: 2px solid transparent;
  border-radius: var(--radius);
  color: var(--text-primary);
  font-size: var(--font-base);
  padding: 0 8px;
}
.mof-dose-value { width: 80px; }
.mof-dose-unit  { width: 64px; }

.mof-dose-value:focus,
.mof-dose-unit:focus {
  outline: none;
  border-color: var(--med-accent);
}

.mof-dose-default-label {
  display: flex;
  align-items: center;
  gap: 6px;
  flex: 1;
  font-size: 14px;
  color: var(--text-secondary);
  cursor: pointer;
}
.mof-dose-default-label input {
  accent-color: var(--med-accent);
  width: 18px; height: 18px;
}

.mof-dose-remove {
  background: none;
  border: none;
  color: var(--migraine-4);
  font-size: var(--font-large);
  cursor: pointer;
  min-width: 32px;
  min-height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.mof-delete-btn {
  width: 100%;
  min-height: var(--tap-min);
  margin-top: 24px;
  background: none;
  border: 2px solid var(--migraine-4);
  border-radius: var(--radius);
  color: var(--migraine-4);
  font-size: var(--font-base);
  font-weight: 700;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

/* ── MILESTONE OVERLAY (light-blue accent) ──── */
#milestone-overlay {
  --med-accent:     #0288d1;
  --med-accent-bg:  #0d2233;
  --med-accent-dim: rgba(79,195,247,0.18);
}
#milestone-overlay .text-input:focus { border-color: var(--milestone); }
#milestone-overlay input[type="date"] { color-scheme: dark; }
.msf-note { resize: vertical; line-height: 1.35; }

/* ── AGENDA OVERLAY (its own indigo accent) ─── */
#agenda-overlay {
  --med-accent:     #5c6bc0;
  --med-accent-bg:  #1a1d36;
  --med-accent-dim: rgba(92,107,192,0.18);
}
#agenda-overlay .text-input:focus { border-color: var(--med-accent); }
#agenda-overlay input[type="date"] { color-scheme: dark; }

.agenda-list-row {
  background: rgba(92,107,192,0.08);
  border: 1px solid rgba(92,107,192,0.25);
  border-left: 4px solid var(--text-secondary);
}
.agenda-list-row.state-upcoming { border-left-color: #5c6bc0; }
.agenda-list-row.state-late     { border-left-color: var(--migraine-4); }
.agenda-list-row.state-done     { border-left-color: var(--bg-frank-active); opacity: 0.8; }

/* ── LOG: missed scheduled medication (catch-up) ─ */
.log-missed {
  max-width: 480px;
  width: 100%;
  margin: 4px auto 0;
  padding: 8px 16px 24px;
  border-top: 2px solid var(--bg-section);
}
.log-missed-title {
  font-size: 14px;
  font-weight: 700;
  letter-spacing: 0.05em;
  color: var(--migraine-4);
  margin: 8px 0;
}

/* ── STATISTICS OVERLAY ─────────────────────── */
.stats-loading {
  color: var(--text-secondary);
  font-size: var(--font-large);
  font-weight: 700;
  text-align: center;
  padding: 48px 0;
}

.stats-chart {
  width: 100%;
  margin-top: 4px;
}
.stats-chart svg {
  display: block;
  width: 100%;
  height: auto;
}

.stats-toggle-row {
  display: flex;
  gap: 6px;
  margin-top: 20px;
}

.stats-toggle {
  flex: 1;
  min-width: 0;
  min-height: 72px;
  border: 2px solid var(--bg-input);
  border-radius: var(--radius);
  background: var(--bg-input);
  color: var(--text-secondary);
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  padding: 6px 2px;
}
.stats-toggle .icon { width: 20px; height: 20px; }
.st-label {
  font-size: 11px;
  font-weight: 700;
  line-height: 1.1;
  text-align: center;
  letter-spacing: 0.02em;
}
.stats-toggle.active {
  background: var(--med-accent);
  border-color: var(--med-accent);
  color: var(--text-on-active);
}
.stats-toggle:disabled {
  opacity: 0.35;
  cursor: default;
}

/* Milestones table (between chart and buttons) */
.stats-ms { margin-top: 10px; }
.stats-ms-row {
  display: grid;
  grid-template-columns: 22px auto 1fr;
  column-gap: 8px;
  align-items: start;
  padding: 6px 0;
  border-bottom: 1px solid rgba(160,160,176,0.2);
  font-size: 15px;
}
.stats-ms-row:last-child { border-bottom: none; }
.stats-ms-num {
  width: 20px; height: 20px;
  border-radius: 50%;
  background: var(--milestone);
  color: var(--bg-primary);
  font-size: 12px;
  font-weight: 700;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.stats-ms-date  { color: var(--text-secondary); white-space: nowrap; }
.stats-ms-text  { display: flex; flex-direction: column; min-width: 0; overflow-wrap: anywhere; }
.stats-ms-label { color: var(--text-primary); font-weight: 600; }
.stats-ms-note  { color: var(--text-secondary); font-size: 13px; }
.stats-ms-empty { color: var(--text-secondary); font-size: 15px; margin: 4px 0 0; }

/* Navigation row: icon-only action buttons, same widths as the toggles above */
.stats-nav-row { margin-top: 6px; }
.stats-toggle.stats-nav { min-height: 52px; }
.stats-toggle.stats-nav .icon { width: 26px; height: 26px; }
.stats-toggle.stats-nav:not(:disabled):active {
  background: var(--med-accent);
  border-color: var(--med-accent);
  color: var(--text-on-active);
}

/* Schedule sub-form (retractable) */
.mof-schedule {
  margin-top: 20px;
  border-top: 1px solid rgba(0, 131, 143, 0.3);
  padding-top: 12px;
}

.mof-sched-header {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 48px;
  cursor: pointer;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}

.mof-sched-title {
  font-size: var(--font-large);
  font-weight: 700;
  letter-spacing: 0.05em;
  color: var(--med-accent);
}

.mof-sched-summary {
  flex: 1;
  text-align: right;
  font-size: 14px;
  color: var(--text-secondary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.mof-sched-body.hidden { display: none; }
.mof-sched-body { padding-top: 8px; }

.mof-sched-freq {
  font-size: var(--font-base);
  font-weight: 600;
  margin-bottom: 8px;
}

.mof-sched-dose-row {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  margin-bottom: 8px;
}
.mof-sched-dose-row .dose-select { width: auto; min-width: 90px; }

/* DAYS row: seven compact weekday toggles */
.mof-sched-weekdays { gap: 4px; }
.mof-sched-weekdays .slot-pick {
  min-width: 0;
  padding: 0;
  font-size: 13px;
  letter-spacing: 0.02em;
}

.mof-sched-delete {
  width: 100%;
  min-height: var(--tap-min);
  margin-top: 16px;
  background: none;
  border: 2px solid var(--migraine-4);
  border-radius: var(--radius);
  color: var(--migraine-4);
  font-size: var(--font-base);
  font-weight: 700;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
.mof-sched-delete.hidden { display: none; }

/* Footer — mirrors the main bottom bar exactly */
.med-ov-footer {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  padding: 0 16px 12px;
  min-height: var(--bottombar-height);
  background: rgba(0,0,0,0.4);
  border-top: 1px solid var(--med-accent);
  flex-shrink: 0;
}

.med-cancel-btn {
  min-height: 56px;
  padding: 0 20px;
  background: var(--bg-input);
  border: 2px solid var(--text-secondary);
  border-radius: var(--radius);
  color: var(--text-primary);
  font-size: var(--font-large);
  font-weight: 700;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

/* SAVE — exactly same dimensions as the main event SAVE button */
.med-save-btn {
  min-width: 72px;
  min-height: 56px;
  padding: 0 16px;
  background: var(--med-accent);
  border: none;
  border-radius: var(--radius);
  color: #fff;
  font-size: var(--font-large);
  font-weight: 700;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

.med-save-btn.inactive {
  background: var(--bg-input);
  color: var(--text-secondary);
  cursor: default;
}
