/* ===================== THEME TOKENS ===================== */
:root {
  --bg:        #f4f1f8;
  --bg-2:      #ece7f4;
  --card:      #ffffff;
  --text:      #2c2833;
  --text-soft: #7d7689;
  --border:    #e7e1f0;
  --accent:    #a58fd8;
  --accent-soft:#efe9fb;
  --shadow:    0 6px 24px rgba(80, 60, 120, 0.10);

  /* migraine (coral) scale 0..3 */
  --m0:#ece7f4; --m1:#ffdccf; --m2:#f7ac91; --m3:#e77b5e;
  /* medication (mint) scale 0..4 */
  --d0:#ece7f4; --d1:#d3efe3; --d2:#a6e0c9; --d3:#75cbab; --d4:#4bb28c;

  --dot-migraine:#e77b5e;
  --dot-med:#4bb28c;

  --nav-h: 96px; /* clearance for floating + button */
}

html[data-theme="dark"] {
  --bg:        #17151c;
  --bg-2:      #201d29;
  --card:      #221f2b;
  --text:      #ece9f2;
  --text-soft: #9a92a8;
  --border:    #322e3d;
  --accent:    #b9a6ec;
  --accent-soft:#2e2740;
  --shadow:    0 6px 24px rgba(0, 0, 0, 0.35);

  --m0:#2a2634; --m1:#7a4636; --m2:#b8654a; --m3:#e88566;
  --d0:#2a2634; --d1:#2f5a48; --d2:#3f7e63; --d3:#57a483; --d4:#74c6a1;
}

@media (prefers-color-scheme: dark) {
  html[data-theme="auto"] {
    --bg:#17151c; --bg-2:#201d29; --card:#221f2b; --text:#ece9f2;
    --text-soft:#9a92a8; --border:#322e3d; --accent:#b9a6ec; --accent-soft:#2e2740;
    --shadow:0 6px 24px rgba(0,0,0,0.35);
    --m0:#2a2634; --m1:#7a4636; --m2:#b8654a; --m3:#e88566;
    --d0:#2a2634; --d1:#2f5a48; --d2:#3f7e63; --d3:#57a483; --d4:#74c6a1;
  }
}

/* ===================== BASE ===================== */
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin:0; padding:0; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  padding-bottom: calc(var(--nav-h) + env(safe-area-inset-bottom));
  -webkit-font-smoothing: antialiased;
  transition: background .25s ease, color .25s ease;
}

/* ===================== HEADER ===================== */
.app-header {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; justify-content: space-between;
  padding: calc(env(safe-area-inset-top) + 14px) 18px 12px;
  background: color-mix(in srgb, var(--bg) 85%, transparent);
  backdrop-filter: saturate(180%) blur(12px);
}
.app-title { font-size: 20px; font-weight: 700; margin: 0; letter-spacing: -0.3px; }
.icon-btn {
  border: none; background: var(--card); color: var(--text);
  width: 40px; height: 40px; border-radius: 50%; font-size: 18px;
  box-shadow: var(--shadow); cursor: pointer;
}

/* ===================== MAIN / VIEWS ===================== */
.app-main { padding: 8px 16px 24px; max-width: 560px; margin: 0 auto; }
#view-history { margin-top: 22px; }

/* ===================== CARD ===================== */
.card {
  background: var(--card); border-radius: 22px; padding: 18px 16px 16px;
  margin-bottom: 16px; box-shadow: var(--shadow);
}
.card-head { display:flex; align-items:center; gap:8px; margin-bottom: 14px; }
.card-head h2 { font-size: 17px; margin:0; font-weight: 700; }
.card-sub { margin-left:auto; font-size: 12px; color: var(--text-soft); }
.dot { width:11px; height:11px; border-radius:50%; display:inline-block; }
.dot-migraine { background: var(--dot-migraine); }
.dot-med { background: var(--dot-med); }

/* ===================== STATS ===================== */
.stats { display:grid; grid-template-columns: repeat(3, 1fr); gap:10px; margin-bottom: 18px; }
.stat { background: var(--bg-2); border-radius: 14px; padding: 12px 8px; text-align:center; }
.stat-num { font-size: 22px; font-weight: 800; line-height:1; letter-spacing:-0.5px; }
.stat-lbl { font-size: 11px; color: var(--text-soft); margin-top: 6px; line-height:1.25; }
.stat-wide { grid-column: span 3; display:flex; align-items:center; justify-content:center; gap:8px; }

/* ===================== HEATMAP ===================== */
.heatmap-wrap { overflow-x:auto; -webkit-overflow-scrolling: touch; padding-bottom: 4px; }
.heatmap-wrap::-webkit-scrollbar { height: 0; }
.heatmap { display:flex; gap: 4px; }
.hm-col { display:flex; flex-direction:column; gap:4px; }
.hm-col-labels { justify-content:flex-start; margin-right:2px; }
.hm-cell { width: 15px; height: 15px; border-radius: 4px; background: var(--m0); }
.hm-lbl { width: 15px; height:15px; font-size:9px; color:var(--text-soft); display:flex; align-items:center; }
.hm-month { font-size: 10px; color: var(--text-soft); height: 12px; margin-bottom: 3px; }
.hm-months { display:flex; gap:4px; margin-left: 19px; }

.legend { display:flex; align-items:center; gap:6px; justify-content:flex-end; margin-top:10px; font-size:11px; color:var(--text-soft); }
.legend .hm-cell { width:12px; height:12px; }

/* ===================== HISTORY ===================== */
.history { display:flex; flex-direction:column; gap:8px; }
.hist-day-label { font-size:12px; color:var(--text-soft); font-weight:600; margin: 14px 2px 2px; }
.hist-item {
  display:flex; align-items:center; gap:12px; background:var(--card);
  border-radius:16px; padding:12px 14px; box-shadow: var(--shadow);
}
.hist-emoji { font-size:20px; }
.hist-body { flex:1; min-width:0; }
.hist-title { font-weight:600; font-size:15px; }
.hist-meta { font-size:12px; color:var(--text-soft); margin-top:2px; }
.hist-del { border:none; background:transparent; color:var(--text-soft); font-size:18px; padding:6px; cursor:pointer; border-radius:8px; }
.hist-del:active { background: var(--bg-2); }
.pill { font-size:11px; font-weight:700; padding:2px 8px; border-radius:20px; color:#fff; }
.empty { text-align:center; color:var(--text-soft); margin-top: 60px; line-height:1.6; font-size:15px; display:none; }

/* ===================== FLOATING ADD BUTTON ===================== */
.fab {
  position: fixed; z-index: 30;
  right: max(20px, env(safe-area-inset-right));
  bottom: calc(20px + env(safe-area-inset-bottom));
  width:62px; height:62px; border-radius:50%; border:none;
  background: linear-gradient(145deg, var(--accent), color-mix(in srgb, var(--accent) 60%, #ff9ec4));
  color:#fff; font-size:34px; font-weight:300; line-height:1;
  box-shadow: 0 8px 22px color-mix(in srgb, var(--accent) 55%, transparent);
  cursor:pointer; display:flex; align-items:center; justify-content:center;
  transition: transform .12s ease;
}
.fab:active { transform: scale(0.92); }

/* section heading */
.section-title { font-size:17px; font-weight:700; margin: 8px 4px 12px; }

/* ===================== SHEET ===================== */
.backdrop {
  position: fixed; inset:0; background: rgba(20,14,30,0.42); z-index:40;
  opacity:0; pointer-events:none; transition: opacity .25s ease;
}
.backdrop.is-open { opacity:1; pointer-events:auto; }
.sheet {
  position: fixed; left:0; right:0; bottom:0; z-index:50;
  background: var(--card); border-radius: 26px 26px 0 0;
  padding: 10px 18px calc(20px + env(safe-area-inset-bottom));
  box-shadow: 0 -10px 40px rgba(0,0,0,0.25);
  transform: translateY(110%); transition: transform .3s cubic-bezier(.32,.72,0,1);
  max-height: 92vh; overflow-y:auto; max-width: 560px; margin: 0 auto;
}
.sheet.is-open { transform: translateY(0); }
.sheet-grip { width:42px; height:5px; border-radius:3px; background: var(--border); margin: 4px auto 14px; }

.type-switch { display:flex; gap:8px; background: var(--bg-2); padding:5px; border-radius:16px; margin-bottom:18px; }
.type-btn {
  flex:1; border:none; background:transparent; color:var(--text-soft);
  padding:11px; border-radius:12px; font-size:15px; font-weight:700; cursor:pointer;
  display:flex; align-items:center; justify-content:center; gap:6px; transition: all .15s ease;
}
.type-btn.is-active { background: var(--card); color: var(--text); box-shadow: var(--shadow); }

.field-label { display:block; font-size:12px; font-weight:700; color:var(--text-soft); margin: 16px 2px 8px; text-transform:uppercase; letter-spacing:.4px; }

.date-row { display:flex; gap:6px; }
.date-chip {
  flex:1; border:2px solid transparent; background: var(--bg-2); border-radius:14px;
  padding:8px 2px; cursor:pointer; text-align:center; color:var(--text);
}
.date-chip .dc-wd { font-size:11px; color:var(--text-soft); font-weight:600; }
.date-chip .dc-day { font-size:17px; font-weight:700; margin-top:2px; }
.date-chip.is-active { border-color: var(--accent); background: var(--accent-soft); }
.date-chip.is-active .dc-wd { color: var(--accent); }

.link-btn { background:none; border:none; color:var(--accent); font-size:13px; font-weight:600; padding:8px 2px; cursor:pointer; }
.hidden-date { display:none; }
.hidden-date.show { display:block; width:100%; padding:12px; border-radius:12px; border:1px solid var(--border); background:var(--bg-2); color:var(--text); font-size:15px; margin-top:4px; }

.time-row { display:flex; gap:10px; align-items:center; }
.time-input { flex:1; padding:12px 14px; border-radius:14px; border:1px solid var(--border); background:var(--bg-2); color:var(--text); font-size:16px; }
.chip { border:none; background:var(--accent-soft); color:var(--accent); font-weight:700; padding:11px 16px; border-radius:14px; cursor:pointer; font-size:14px; }

.intensity-row { display:flex; gap:8px; }
.int-btn {
  flex:1; border:2px solid transparent; border-radius:14px; padding:14px 4px; cursor:pointer;
  font-weight:700; font-size:14px; color:var(--text); text-align:center; transition: transform .1s ease;
}
.int-btn .int-emoji { font-size:22px; display:block; margin-bottom:4px; }
.int-btn.is-active { transform: scale(1.03); box-shadow: var(--shadow); }
.int-1 { background: var(--m1); } .int-2 { background: var(--m2); } .int-3 { background: var(--m3); color:#fff; }
.int-btn.is-active { border-color: var(--text); }

.med-row { display:flex; flex-wrap:wrap; gap:8px; }
.med-chip {
  border:2px solid transparent; background:var(--bg-2); color:var(--text);
  padding:10px 14px; border-radius:14px; font-size:14px; font-weight:600; cursor:pointer;
}
.med-chip.is-active { border-color: var(--dot-med); background: var(--d1); }
.text-input { width:100%; padding:12px 14px; border-radius:14px; border:1px solid var(--border); background:var(--bg-2); color:var(--text); font-size:16px; margin-top:8px; }

.dose-row { display:flex; align-items:center; gap:14px; justify-content:center; }
.step-btn { width:52px; height:52px; border-radius:50%; border:none; background:var(--bg-2); color:var(--text); font-size:26px; font-weight:600; cursor:pointer; }
.step-btn:active { background: var(--accent-soft); }
.dose-value { min-width:110px; text-align:center; font-size:26px; font-weight:800; }
.dose-unit { font-size:15px; color:var(--text-soft); margin-left:4px; font-weight:600; }

.sheet-actions { display:flex; gap:10px; margin-top:24px; }
.btn { flex:1; border:none; padding:15px; border-radius:16px; font-size:16px; font-weight:700; cursor:pointer; }
.btn-ghost { background: var(--bg-2); color: var(--text-soft); }
.btn-primary { background: var(--accent); color:#fff; box-shadow: 0 6px 16px color-mix(in srgb, var(--accent) 45%, transparent); }
.btn-primary:active { transform: scale(0.98); }

.hidden { display:none !important; }

/* ===================== TOAST ===================== */
.toast {
  position: fixed; bottom: calc(var(--nav-h) + 20px); left:50%; transform: translateX(-50%) translateY(20px);
  background: var(--text); color: var(--bg); padding:12px 20px; border-radius:14px; font-size:14px; font-weight:600;
  opacity:0; pointer-events:none; transition: all .28s ease; z-index:60; box-shadow: var(--shadow); white-space:nowrap;
}
.toast.show { opacity:1; transform: translateX(-50%) translateY(0); }
