/* Mena - appnest house style, muted rose-berry accent.
   Neutral tokens follow the family skeleton (APPNEST_TOOLKIT.md §1.1); the
   --accent* trio and the --cal-* calendar overlay colours are Mena's own.
   Every colour is a variable so the two dark-mode triggers only swap variables. */

:root {
  --bg: #f6f7f9; --surface: #ffffff;
  --ink: #1c2430; --ink-soft: #5b6674; --ink-faint: #8d97a5;
  --accent: #a24e63; --accent-ink: #ffffff; --accent-soft: #f6e8ec;
  --warn-bg: #fff7e6; --warn-border: #f0d9a8; --warn-ink: #7a5b16;
  --danger: #b3423a; --warm: #b06a12; --success: #2f7d4f; --line: #e3e7ec;
  --input-bg: #fbfcfd; --input-focus-bg: #ffffff; --btn-primary-hover: #86404f;
  --chip-hover: #eed5dc; --del-hover-bg: #fdf1f0; --summary-bg: #f3f5f7;
  --urgent-bg: #fdecea; --urgent-border: #f2b8b1; --urgent-ink: #8f2f27;

  /* calendar overlays (light) */
  --cal-period: #e59ab0; --cal-period-light: #f3c9d3; --cal-period-strong: #d4738f;
  --cal-spotting: #f6e2e7;
  --cal-period-predicted: #d99cae;
  --cal-fertile-pos: #d7efe0; --cal-fertile-neutral: #e7e4f5; --cal-fertile-caution: #fbe4c6;
  --cal-ovulation: #7a5aa6;
  --cal-pms: #e7dee8; --cal-pms-line: #9b8aa8;
  --cal-symptom: #a9741f;

  --radius: 12px;
  --shadow: 0 1px 2px rgba(16,24,40,.05), 0 4px 16px rgba(16,24,40,.06);
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  color-scheme: light dark;
}
:root[data-theme="light"] { color-scheme: light; }
:root[data-theme="dark"]  { color-scheme: dark; }

@media (prefers-color-scheme: dark) {
  :root:not([data-theme]) {
    --bg:#10151b; --surface:#1a222b; --ink:#e7ecf2; --ink-soft:#a6b1be; --ink-faint:#75808d;
    --accent:#dd94a6; --accent-ink:#2c121a; --accent-soft:#3a2028;
    --warn-bg:#2b2410; --warn-border:#6a5620; --warn-ink:#eacc7b;
    --danger:#f07b72; --warm:#e2a352; --success:#6dc79a; --line:#2b3542;
    --input-bg:#141b22; --input-focus-bg:#10161c; --btn-primary-hover:#cc8496;
    --chip-hover:#472731; --del-hover-bg:#3a2320; --summary-bg:#141b22;
    --urgent-bg:#3a1d19; --urgent-border:#7a3830; --urgent-ink:#f3a99f;

    --cal-period:#7a3a4c; --cal-period-light:#5a2f3b; --cal-period-strong:#9c455d;
    --cal-spotting:#3a262c;
    --cal-period-predicted:#8a5566;
    --cal-fertile-pos:#1c3a2c; --cal-fertile-neutral:#2c2740; --cal-fertile-caution:#3a2f18;
    --cal-ovulation:#b198d8;
    --cal-pms:#332b3a; --cal-pms-line:#6a5a72;
    --cal-symptom:#d8b26a;

    --shadow: 0 1px 2px rgba(0,0,0,.4), 0 4px 16px rgba(0,0,0,.35);
  }
}
:root[data-theme="dark"] {
  --bg:#10151b; --surface:#1a222b; --ink:#e7ecf2; --ink-soft:#a6b1be; --ink-faint:#75808d;
  --accent:#dd94a6; --accent-ink:#2c121a; --accent-soft:#3a2028;
  --warn-bg:#2b2410; --warn-border:#6a5620; --warn-ink:#eacc7b;
  --danger:#f07b72; --warm:#e2a352; --success:#6dc79a; --line:#2b3542;
  --input-bg:#141b22; --input-focus-bg:#10161c; --btn-primary-hover:#cc8496;
  --chip-hover:#472731; --del-hover-bg:#3a2320; --summary-bg:#141b22;
  --urgent-bg:#3a1d19; --urgent-border:#7a3830; --urgent-ink:#f3a99f;

  --cal-period:#7a3a4c; --cal-period-light:#5a2f3b; --cal-period-strong:#9c455d;
  --cal-spotting:#3a262c;
  --cal-period-predicted:#8a5566;
  --cal-fertile-pos:#1c3a2c; --cal-fertile-neutral:#2c2740; --cal-fertile-caution:#3a2f18;
  --cal-ovulation:#b198d8;
  --cal-pms:#332b3a; --cal-pms-line:#6a5a72;
  --cal-symptom:#d8b26a;

  --shadow: 0 1px 2px rgba(0,0,0,.4), 0 4px 16px rgba(0,0,0,.35);
}

/* ---------- base ---------- */
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--ink);
  font-family: var(--font); font-size: 16px; line-height: 1.55;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 1.7rem; line-height: 1.25; margin: 0 0 10px; }
h2 { font-size: 1.15rem; margin: 0 0 12px; }
h3 { font-size: .9rem; margin: 0 0 8px; }
button { font-family: inherit; }
.muted { color: var(--ink-soft); font-size: .9rem; margin: 0 0 14px; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ---------- topbar ---------- */
.topbar {
  display: flex; align-items: center; gap: 14px;
  padding: 10px 20px; background: var(--surface);
  border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 8px; color: var(--accent); flex: none; }
.brand:hover { text-decoration: none; }
.brand-name { font-weight: 700; font-size: 1.15rem; color: var(--ink); letter-spacing: -.01em; }
.tagline { color: var(--ink-faint); font-size: .85rem; }
.topbar-controls { margin-left: auto; display: flex; align-items: center; gap: 10px; }

.icon-btn {
  display: inline-flex; align-items: center; justify-content: center;
  background: none; border: 1px solid var(--line); border-radius: 10px;
  color: var(--ink-soft); padding: 7px; cursor: pointer;
}
.icon-btn:hover { background: var(--accent-soft); color: var(--accent); }

/* pill toggle - the family's signature control */
.unit-toggle {
  display: inline-flex; border: 1px solid var(--line); border-radius: 10px;
  overflow: hidden; background: var(--surface);
}
.unit-toggle button {
  border: 0; background: none; color: var(--ink-soft); cursor: pointer;
  padding: 6px 11px; font-size: .8rem; font-weight: 600;
  display: inline-flex; align-items: center; gap: 4px;
}
.unit-toggle button + button { border-left: 1px solid var(--line); }
.unit-toggle button.active { background: var(--accent); color: var(--accent-ink); }
.unit-toggle button:not(.active):hover { background: var(--accent-soft); color: var(--accent); }

/* ---------- layout ---------- */
main { max-width: 640px; margin: 0 auto; padding: 22px 20px 48px; }
.card {
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 20px; margin-bottom: 16px;
}

/* ---------- status ---------- */
.status-card { text-align: center; }
.status-line { font-size: 1.15rem; font-weight: 600; margin: 4px 0; color: var(--ink); }
.status-sub { font-size: .85rem; color: var(--ink-soft); margin: 6px 0 0; }
.status-sub.low { color: var(--warm); }

/* ---------- buttons ---------- */
.actions-row { display: flex; flex-wrap: wrap; gap: 10px; margin-bottom: 16px; }
.actions-row .btn { flex: 1 1 auto; }
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  border-radius: 10px; border: 1px solid transparent; cursor: pointer;
  font-size: .92rem; font-weight: 600; padding: 9px 16px; text-decoration: none;
}
.btn:hover { text-decoration: none; }
.btn-primary { background: var(--accent); color: var(--accent-ink); }
.btn-primary:hover { background: var(--btn-primary-hover); }
.btn-ghost { background: var(--surface); color: var(--ink); border-color: var(--line); }
.btn-ghost:hover { background: var(--accent-soft); color: var(--accent); border-color: var(--accent); }
.btn-lg { padding: 12px 18px; font-size: 1rem; }
.btn-sm { padding: 7px 12px; font-size: .82rem; }
.btn-danger { color: var(--danger); }
.btn-danger:hover { background: var(--del-hover-bg); color: var(--danger); border-color: var(--danger); }

/* ---------- intent slider ---------- */
.intent-range {
  -webkit-appearance: none; appearance: none;
  width: 100%; height: 8px; border-radius: 999px; margin: 10px 0 6px;
  background: linear-gradient(90deg, var(--warm), var(--ink-faint), var(--success));
  outline-offset: 4px;
}
.intent-range::-webkit-slider-thumb {
  -webkit-appearance: none; appearance: none;
  width: 24px; height: 24px; border-radius: 50%;
  background: var(--accent); border: 3px solid var(--surface);
  box-shadow: var(--shadow); cursor: pointer;
}
.intent-range::-moz-range-thumb {
  width: 24px; height: 24px; border-radius: 50%;
  background: var(--accent); border: 3px solid var(--surface);
  box-shadow: var(--shadow); cursor: pointer;
}
.intent-labels {
  display: flex; justify-content: space-between; gap: 6px;
  font-size: .76rem; color: var(--ink-faint); font-weight: 600;
}
.intent-labels span { flex: 1; text-align: center; }
.intent-labels span:first-child { text-align: left; }
.intent-labels span:last-child { text-align: right; }
.intent-desc { font-size: .88rem; color: var(--ink-soft); margin: 12px 0 0; }

/* ---------- banner & toast ---------- */
.banner {
  background: var(--warn-bg); border: 1px solid var(--warn-border); color: var(--warn-ink);
  border-radius: 10px; padding: 10px 14px; font-size: .85rem; margin: 12px 0 0;
}
.banner.urgent { background: var(--urgent-bg); border-color: var(--urgent-border); color: var(--urgent-ink); }
.toast {
  position: fixed; left: 50%; bottom: 26px; transform: translateX(-50%);
  background: var(--ink); color: var(--bg); border-radius: 999px;
  padding: 9px 18px; font-size: .88rem; z-index: 60; box-shadow: var(--shadow);
}

/* ---------- calendar ---------- */
.cal-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 12px; }
.cal-title { margin: 0; font-size: 1.05rem; text-align: center; flex: 1; text-transform: capitalize; }
.cal-weekdays, .cal-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 5px; }
.cal-weekdays {
  margin-bottom: 5px; font-size: .72rem; font-weight: 700; text-transform: uppercase;
  letter-spacing: .03em; color: var(--ink-faint); text-align: center;
}
.cal-cell {
  position: relative; aspect-ratio: 1 / 1;
  display: flex; align-items: center; justify-content: center;
  border: 2px solid transparent; border-radius: 10px;
  background: var(--summary-bg); color: var(--ink);
  font-size: .95rem; font-weight: 600; cursor: pointer; padding: 0;
}
.cal-cell.empty { background: none; cursor: default; }
.cal-cell.editable:hover { border-color: var(--accent); }
.cal-cell.future { cursor: default; color: var(--ink-faint); }
.cal-num { position: relative; z-index: 2; }

/* background states (JS assigns exactly one) */
.cal-cell.spotting { background: var(--cal-spotting); }
.cal-cell.period { background: var(--cal-period); }
.cal-cell.period.f2 { background: var(--cal-period-light); }
.cal-cell.period.f4 { background: var(--cal-period-strong); }
.cal-cell.predicted { border: 2px dashed var(--cal-period-predicted); background: none; }
.cal-cell.fertile-pos { background: var(--cal-fertile-pos); }
.cal-cell.fertile-neutral { background: var(--cal-fertile-neutral); }
.cal-cell.fertile-caution { background: var(--cal-fertile-caution); }
.cal-cell.pms { background: var(--cal-pms); }

/* shape overlays that can co-exist with a background */
.cal-cell.fertile-pos::before, .cal-cell.fertile-neutral::before, .cal-cell.fertile-caution::before {
  content: ''; position: absolute; top: 5px; left: 50%; transform: translateX(-50%);
  width: 5px; height: 5px; border-radius: 50%; background: var(--ink-soft); z-index: 2;
}
.cal-cell.pms::after {
  content: ''; position: absolute; bottom: 5px; left: 24%; right: 24%;
  height: 3px; border-radius: 2px; background: var(--cal-pms-line); z-index: 2;
}
.cal-cell.ovulation { box-shadow: inset 0 0 0 2px var(--cal-ovulation); }
.cal-cell.today { outline: 2px solid var(--accent); outline-offset: 1px; }
.cal-mark {
  position: absolute; bottom: 5px; left: 50%; transform: translateX(-50%);
  width: 5px; height: 5px; border-radius: 50%; background: var(--cal-symptom); z-index: 2;
}

/* legend */
.legend { margin-top: 18px; border-top: 1px solid var(--line); padding-top: 14px; }
.legend-list {
  list-style: none; margin: 0; padding: 0;
  display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 6px 14px;
}
.legend-list li { display: flex; align-items: center; gap: 8px; font-size: .82rem; color: var(--ink-soft); }
.swatch { width: 16px; height: 16px; border-radius: 5px; flex: none; background: var(--summary-bg); border: 1px solid var(--line); position: relative; }
.sw-period { background: var(--cal-period); border-color: transparent; }
.sw-spotting { background: var(--cal-spotting); border-color: transparent; }
.sw-predicted { background: none; border: 2px dashed var(--cal-period-predicted); }
.sw-fertile { background: var(--cal-fertile-neutral); border-color: transparent; }
.sw-ovulation { background: none; box-shadow: inset 0 0 0 2px var(--cal-ovulation); }
.sw-pms { background: var(--cal-pms); border-color: transparent; }
.sw-symptom { background: none; }
.sw-symptom::after { content: ''; position: absolute; inset: 0; margin: auto; width: 6px; height: 6px; border-radius: 50%; background: var(--cal-symptom); }

/* ---------- stats ---------- */
.stat-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(120px, 1fr)); gap: 8px; margin: 4px 0 12px; }
.stat-tile { background: var(--summary-bg); border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; text-align: center; }
.stat-value { font-size: 1.3rem; font-weight: 700; color: var(--accent); line-height: 1.2; }
.stat-label { font-size: .7rem; font-weight: 600; letter-spacing: .04em; text-transform: uppercase; color: var(--ink-faint); margin-top: 2px; }
.regularity { font-size: .9rem; color: var(--ink-soft); margin: 6px 0; }
.regularity b { color: var(--ink); }
.new-symptoms { font-size: .9rem; color: var(--warm); margin: 6px 0; }
.stats-actions { margin-top: 12px; }

/* ---------- data ---------- */
.data-actions { display: flex; flex-wrap: wrap; gap: 8px; }

/* ---------- more tools ---------- */
.more-tools {
  text-align: center; font-size: .82rem; color: var(--ink-faint);
  display: flex; flex-wrap: wrap; gap: 6px 12px; justify-content: center; align-items: center;
  padding: 6px 0 4px;
}
.more-link { font-weight: 600; }

/* ---------- footer ---------- */
.footer {
  border-top: 1px solid var(--line); margin-top: 8px;
  padding: 22px 20px 30px; text-align: center;
  color: var(--ink-faint); font-size: .82rem;
}
.footer p { margin: 0 0 8px; max-width: 52ch; margin-inline: auto; }
.footer-links { display: flex; justify-content: center; gap: 10px; align-items: center; }
.footer-link {
  background: none; border: 0; padding: 0; cursor: pointer;
  color: var(--ink-soft); font-size: .82rem; text-decoration: underline;
}
.footer-link:hover { color: var(--accent); }

/* ---------- dialogs ---------- */
dialog {
  border: 1px solid var(--line); border-radius: var(--radius);
  background: var(--surface); color: var(--ink);
  box-shadow: var(--shadow); padding: 22px; max-width: min(92vw, 460px); width: 100%;
}
dialog::backdrop { background: rgba(10, 14, 20, .55); }
.dialog-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 18px; }
.dialog-actions .btn { flex: 1 1 auto; }
.field { margin-bottom: 16px; }
.field-label { display: block; font-size: .78rem; font-weight: 700; letter-spacing: .04em; text-transform: uppercase; color: var(--ink-faint); margin-bottom: 8px; }
.text-input, .note-input {
  width: 100%; font: inherit; font-size: .95rem;
  border: 1px solid var(--line); border-radius: 10px;
  background: var(--input-bg); color: var(--ink); padding: 9px 11px; outline: none;
}
.text-input:focus, .note-input:focus { border-color: var(--accent); background: var(--input-focus-bg); }
.note-input { resize: vertical; min-height: 52px; }
.text-input.num { width: 100px; }

/* flow pills */
.flow-row { display: flex; flex-wrap: wrap; gap: 6px; }
.flow-btn {
  flex: 1 1 auto; border: 1px solid var(--line); background: var(--input-bg);
  color: var(--ink-soft); border-radius: 9px; padding: 8px 6px; cursor: pointer;
  font-size: .82rem; font-weight: 600;
}
.flow-btn:hover { border-color: var(--accent); color: var(--accent); }
.flow-btn.active { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }

/* symptom chips */
.chip-row { display: flex; flex-wrap: wrap; gap: 6px; }
.sym-chip {
  border: 1px solid var(--line); background: var(--input-bg); color: var(--ink-soft);
  border-radius: 999px; padding: 6px 12px; cursor: pointer; font-size: .84rem;
  display: inline-flex; align-items: center; gap: 6px;
}
.sym-chip:hover { border-color: var(--accent); color: var(--accent); background: var(--chip-hover); }
.sym-chip.active { background: var(--accent-soft); color: var(--accent); border-color: var(--accent); }
.sym-new {
  font-size: .62rem; font-weight: 700; letter-spacing: .04em; text-transform: uppercase;
  color: var(--accent-ink); background: var(--accent); border-radius: 5px; padding: 1px 5px;
}

/* backfill */
.backfill-dialog { max-width: min(92vw, 480px); }
.backfill-form { display: flex; flex-wrap: wrap; gap: 12px; align-items: flex-end; margin-bottom: 8px; }
.backfill-form .field { margin-bottom: 0; flex: 1 1 140px; }
.backfill-form .btn { flex: none; }
.backfill-list-title { margin-top: 14px; }
.backfill-list { list-style: none; margin: 0; padding: 0; max-height: 34vh; overflow-y: auto; }
.backfill-list li {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  border: 1px solid var(--line); border-radius: 9px; padding: 7px 12px; margin-bottom: 6px;
  font-size: .9rem;
}
.bf-remove { background: none; border: 0; color: var(--danger); cursor: pointer; font-size: .82rem; text-decoration: underline; padding: 0; }

/* doctor summary */
.summary-dialog { max-width: min(94vw, 560px); }
.summary-body h2 { margin-bottom: 4px; }
.summary-body .sum-meta { color: var(--ink-faint); font-size: .8rem; margin: 0 0 14px; }
.summary-body h3 { margin-top: 18px; color: var(--ink-soft); text-transform: uppercase; letter-spacing: .04em; font-size: .74rem; }
.sum-table { width: 100%; border-collapse: collapse; font-size: .86rem; }
.sum-table th, .sum-table td { text-align: left; padding: 5px 8px; border-bottom: 1px solid var(--line); font-variant-numeric: tabular-nums; }
.sum-table th { color: var(--ink-faint); font-size: .72rem; text-transform: uppercase; letter-spacing: .03em; }
.sum-list { margin: 6px 0 0; padding-left: 1.2em; font-size: .88rem; color: var(--ink-soft); }
.sum-list li { margin: 2px 0; }
.sum-disclaimer { font-size: .78rem; color: var(--ink-faint); margin-top: 16px; font-style: italic; }

.privacy-dialog p { color: var(--ink-soft); font-size: .92rem; margin: 0 0 10px; }

/* ---------- print (doctor summary) ---------- */
@media print {
  body > *:not(#summaryDialog) { display: none !important; }
  #summaryDialog { position: static; display: block; border: 0; box-shadow: none; max-width: none; padding: 0; }
  #summaryDialog::backdrop { display: none; }
  .no-print { display: none !important; }
}

/* ---------- responsive ---------- */
@media (max-width: 480px) {
  .tagline { display: none; }
  main { padding: 16px 12px 40px; }
  .actions-row .btn { flex: 1 1 100%; }
}
@media (prefers-reduced-motion: reduce) { * { transition: none !important; } }
