/* migraine-reporter - mobile first, light & dark following the device */

:root {
  color-scheme: light;
  --bg: #f4f3f0;
  --surface-1: #fcfcfb;
  --surface-2: #ffffff;
  --border: #e3e2de;
  --grid: #e6e5e1;
  --text-primary: #0b0b0b;
  --text-secondary: #52514e;
  --text-muted: #77766f;
  --accent: #6250d6;
  --accent-ink: #ffffff;
  --accent-soft: #ecebfb;
  --series-1: #2a78d6;
  --series-1-wash: rgba(42, 120, 214, .10);
  --danger: #c4302f;
  --danger-soft: #fbe9e8;
  --good: #1b7a4b;
  --warning-soft: #fff4d6;
  --brand: #2b2160;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(0, 0, 0, .06), 0 4px 16px rgba(0, 0, 0, .05);
  /* intensity 0 to 5, one hue light to dark */
  --i0: #86b6ef; --i1: #5598e7; --i2: #2a78d6; --i3: #256abf; --i4: #184f95; --i5: #0d366b;
}

@media (prefers-color-scheme: dark) {
  :root {
    color-scheme: dark;
    --bg: #111110;
    --surface-1: #1a1a19;
    --surface-2: #201f1e;
    --border: #34332f;
    --grid: #2e2d2a;
    --text-primary: #f0efec;
    --text-secondary: #c3c2b7;
    --text-muted: #96958c;
    --accent: #9085e9;
    --accent-ink: #14112e;
    --accent-soft: #2a2550;
    --series-1: #3987e5;
    --series-1-wash: rgba(57, 135, 229, .14);
    --danger: #ef6b6a;
    --danger-soft: #3a1d1d;
    --good: #5ccf8f;
    --warning-soft: #3a3016;
    --shadow: none;
    --i0: #cde2fb; --i1: #9ec5f4; --i2: #6da7ec; --i3: #3987e5; --i4: #256abf; --i5: #184f95;
  }
}

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

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  font: 16px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text-primary);
  /* room for the sticky action bar of small screens */
  padding-bottom: env(safe-area-inset-bottom);
}

h1, h2, h3 { line-height: 1.2; margin: 0; }
h1 { font-size: 1.25rem; }
h2 { font-size: 1.15rem; margin-bottom: .75rem; }
h3 { font-size: .95rem; font-weight: 600; color: var(--text-secondary); }
p { margin: .5rem 0; }
a { color: var(--accent); }

.hidden { display: none !important; }
.muted { color: var(--text-muted); }
.small { font-size: .875rem; }

/* ---------------------------------------------------------------- layout */

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  gap: .75rem;
  padding: .6rem max(1rem, env(safe-area-inset-left));
  padding-top: max(.6rem, env(safe-area-inset-top));
  background: var(--brand);
  color: #fff;
}
.topbar .brand { display: flex; align-items: center; gap: .6rem; color: inherit; text-decoration: none; min-width: 0; }
.topbar .brand img { width: 36px; height: 36px; flex: none; }
.topbar .brand h1 { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.topbar .actions { margin-left: auto; display: flex; gap: .4rem; }
.topbar .btn { background: rgba(255, 255, 255, .12); color: #fff; border-color: transparent; }
.topbar .btn:hover { background: rgba(255, 255, 255, .22); }

main {
  max-width: 72rem;
  margin: 0 auto;
  padding: 1rem max(1rem, env(safe-area-inset-left)) 6rem;
}

section { margin: 1.5rem 0 2rem; }

.section-head { display: flex; align-items: baseline; gap: .75rem; flex-wrap: wrap; margin-bottom: .75rem; }
.section-head h2 { margin: 0; }
.section-head .muted { font-size: .875rem; }

.card {
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 1rem;
}

.grid { display: grid; gap: 1rem; grid-template-columns: 1fr; }
@media (min-width: 700px) { .grid { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
@media (min-width: 1100px) { .grid.three { grid-template-columns: repeat(3, minmax(0, 1fr)); } }
.grid .wide { grid-column: 1 / -1; }

/* ---------------------------------------------------------------- hero & sign-in */

.hero { display: grid; gap: 1rem; align-items: center; margin-top: .5rem; }
@media (min-width: 800px) { .hero { grid-template-columns: 1.2fr 1fr; gap: 2rem; } }
.hero .pitch h2 { font-size: clamp(1.5rem, 5vw, 2.2rem); margin-bottom: .5rem; }
.hero .pitch p { color: var(--text-secondary); font-size: 1.05rem; }

form.stack { display: grid; gap: .9rem; }

/* ---------------------------------------------------------------- controls */

label { display: grid; gap: .3rem; font-weight: 600; font-size: .9rem; }
label .hint { font-weight: 400; color: var(--text-muted); }

input, select {
  font: inherit;
  width: 100%;
  min-height: 48px;
  padding: .6rem .8rem;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text-primary);
}
input:focus-visible, select:focus-visible, .btn:focus-visible, .chip input:focus-visible + span {
  outline: 3px solid var(--accent);
  outline-offset: 2px;
}

.btn {
  font: inherit;
  font-weight: 600;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: .4rem;
  min-height: 44px;
  padding: .5rem 1rem;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text-primary);
  cursor: pointer;
  text-decoration: none;
  touch-action: manipulation;
}
.btn:hover { border-color: var(--text-muted); }
.btn:disabled { opacity: .55; cursor: progress; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.primary:hover { filter: brightness(1.08); }
.btn.danger { color: var(--danger); }
.btn.big { min-height: 56px; font-size: 1.1rem; padding: .7rem 1.4rem; border-radius: 14px; }
.btn.block { width: 100%; }
.btn.small { min-height: 36px; padding: .3rem .7rem; font-size: .875rem; }

.toggle { display: flex; align-items: center; gap: .7rem; font-weight: 600; min-height: 44px; cursor: pointer; }
.toggle input { width: 1.4rem; height: 1.4rem; min-height: 0; accent-color: var(--accent); }

.segmented { display: grid; grid-template-columns: repeat(2, 1fr); gap: .5rem; }

/* intensity chips: a radio group with the descriptions */
.chips { display: grid; gap: .5rem; grid-template-columns: 1fr; }
@media (min-width: 520px) { .chips { grid-template-columns: repeat(2, 1fr); } }
.chip { position: relative; display: block; font-weight: 400; cursor: pointer; }
.chip input { position: absolute; opacity: 0; width: 1px; height: 1px; min-height: 0; }
.chip span {
  display: grid;
  grid-template-columns: auto 1fr;
  column-gap: .6rem;
  align-items: center;
  min-height: 52px;
  padding: .5rem .7rem;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface-2);
}
.chip b { grid-row: span 2; }
.chip small { color: var(--text-muted); line-height: 1.3; }
.chip input:checked + span { border-color: var(--accent); background: var(--accent-soft); box-shadow: inset 0 0 0 1px var(--accent); }

.segmented .chip span { grid-template-columns: 1fr; text-align: center; font-weight: 600; }

/* ---------------------------------------------------------------- badges & messages */

.badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 1.8rem;
  height: 1.8rem;
  padding: 0 .45rem;
  border-radius: 999px;
  font-weight: 700;
  font-size: .9rem;
}
.badge.i0, .badge.i1 { color: #0b0b0b; }
.badge.i2, .badge.i3, .badge.i4, .badge.i5 { color: #fff; }
.badge.i0 { background: var(--i0); } .badge.i1 { background: var(--i1); } .badge.i2 { background: var(--i2); }
.badge.i3 { background: var(--i3); } .badge.i4 { background: var(--i4); } .badge.i5 { background: var(--i5); }
@media (prefers-color-scheme: dark) {
  .badge.i0, .badge.i1, .badge.i2 { color: #0b0b0b; }
}
.badge.none { background: var(--grid); color: var(--text-secondary); }
.badge.status { font-size: .75rem; height: 1.5rem; }
.badge.status.suspended { background: var(--danger-soft); color: var(--danger); }
.badge.status.admin { background: var(--accent-soft); color: var(--accent); }

.notice { padding: .8rem 1rem; border-radius: 10px; background: var(--accent-soft); margin: .5rem 0; }
.notice.error { background: var(--danger-soft); color: var(--danger); }
.notice.warning { background: var(--warning-soft); }

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(5.5rem + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  z-index: 100;
  max-width: calc(100% - 2rem);
  padding: .7rem 1.1rem;
  border-radius: 10px;
  background: var(--text-primary);
  color: var(--bg);
  box-shadow: 0 6px 24px rgba(0, 0, 0, .25);
}
.toast.error { background: var(--danger); color: #fff; }

/* ---------------------------------------------------------------- stats */

.tiles { display: grid; gap: .75rem; grid-template-columns: repeat(2, minmax(0, 1fr)); }
@media (min-width: 640px) { .tiles { grid-template-columns: repeat(3, minmax(0, 1fr)); } }
@media (min-width: 1000px) { .tiles { grid-template-columns: repeat(6, minmax(0, 1fr)); } }
.tile { padding: .8rem 1rem; }
.tile .label { font-size: .85rem; color: var(--text-secondary); }
.tile .value { font-size: 1.6rem; font-weight: 650; line-height: 1.2; margin-top: .15rem; font-variant-numeric: tabular-nums; }
.tile .sub { font-size: .8rem; color: var(--text-muted); }
.tile.hero-tile .value { font-size: clamp(2rem, 8vw, 3rem); }

.chart-card h3 { margin-bottom: .2rem; }
.chart-card .caption { font-size: .8rem; color: var(--text-muted); margin: 0 0 .5rem; }
.chart { position: relative; width: 100%; touch-action: pan-y; }
.chart svg { display: block; width: 100%; overflow: visible; }
.chart text { fill: var(--text-muted); font-size: 11px; font-family: inherit; }
.chart text.value { fill: var(--text-primary); font-weight: 600; }
.chart text.label { fill: var(--text-secondary); font-size: 12px; }
.chart .gridline { stroke: var(--grid); stroke-width: 1; }
.chart .baseline { stroke: var(--text-muted); stroke-width: 1; }
.chart .bar { fill: var(--series-1); }
.chart .bar.active { fill: var(--accent); }
.chart .line { fill: none; stroke: var(--series-1); stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.chart .area { fill: var(--series-1-wash); }
.chart .dot { fill: var(--series-1); stroke: var(--surface-1); stroke-width: 2; }
.chart .crosshair { stroke: var(--text-muted); stroke-width: 1; }
.chart .hit { fill: transparent; cursor: crosshair; }
.chart .empty { fill: var(--text-muted); font-size: 13px; }

.chart-tooltip {
  position: fixed;
  z-index: 50;
  pointer-events: none;
  padding: .4rem .6rem;
  border-radius: 8px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  box-shadow: 0 4px 16px rgba(0, 0, 0, .18);
  font-size: .85rem;
  white-space: nowrap;
}
.chart-tooltip b { display: block; }

details.data { margin-top: .4rem; font-size: .85rem; }
details.data summary { cursor: pointer; color: var(--text-muted); min-height: 32px; display: flex; align-items: center; }
details.data table { width: 100%; border-collapse: collapse; margin-top: .3rem; }
details.data td, details.data th { padding: .2rem .4rem; border-bottom: 1px solid var(--grid); text-align: left; }
details.data td:last-child, details.data th:last-child { text-align: right; font-variant-numeric: tabular-nums; }

/* ---------------------------------------------------------------- records & users */

.ongoing {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: .75rem;
  padding: 1rem;
  border-radius: var(--radius);
  background: var(--warning-soft);
  border: 1px solid var(--border);
  margin-bottom: 1rem;
}
.ongoing .what { flex: 1 1 14rem; }
.ongoing .what b { display: block; font-size: 1.05rem; }

.list { display: grid; gap: .6rem; }
.item {
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: .75rem;
  padding: .75rem .9rem;
}
.item .main { min-width: 0; }
.item .main b { display: block; overflow-wrap: anywhere; }
.item .main .muted { font-size: .85rem; }
@media (min-width: 900px) {
  .list.records { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

.users .item { grid-template-columns: 1fr auto; }
.users .facts { display: flex; flex-wrap: wrap; gap: .2rem .9rem; font-size: .85rem; color: var(--text-muted); }
.filter { margin-bottom: .75rem; }

/* ---------------------------------------------------------------- the sticky "new migraine" bar */

.action-bar {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 20;
  padding: .75rem max(1rem, env(safe-area-inset-left)) calc(.75rem + env(safe-area-inset-bottom));
  background: linear-gradient(to top, var(--bg) 70%, transparent);
  display: flex;
  justify-content: center;
}
.action-bar .btn { width: 100%; max-width: 28rem; box-shadow: 0 6px 20px rgba(98, 80, 214, .35); }

/* ---------------------------------------------------------------- dialogs: full screen on phones */

dialog {
  padding: 0;
  border: none;
  color: var(--text-primary);
  background: var(--surface-1);
  width: 100%;
  max-width: 100%;
  height: 100%;
  max-height: 100%;
  margin: 0;
}
dialog::backdrop { background: rgba(10, 8, 30, .55); }
@media (min-width: 640px) {
  dialog {
    width: min(36rem, calc(100% - 2rem));
    height: auto;
    max-height: calc(100% - 2rem);
    margin: auto;
    border-radius: var(--radius);
    box-shadow: 0 20px 60px rgba(0, 0, 0, .35);
  }
}
dialog form { display: flex; flex-direction: column; min-height: 100%; }
dialog header {
  position: sticky;
  top: 0;
  z-index: 1;
  display: flex;
  align-items: center;
  gap: .5rem;
  padding: .75rem 1rem;
  padding-top: max(.75rem, env(safe-area-inset-top));
  background: var(--surface-1);
  border-bottom: 1px solid var(--border);
}
dialog header h2 { margin: 0; flex: 1; }
dialog .body { padding: 1rem; display: grid; gap: 1rem; flex: 1; align-content: start; }
dialog footer {
  position: sticky;
  bottom: 0;
  display: flex;
  flex-wrap: wrap;
  gap: .5rem;
  padding: .75rem 1rem calc(.75rem + env(safe-area-inset-bottom));
  background: var(--surface-1);
  border-top: 1px solid var(--border);
}
dialog footer .spacer { flex: 1; }
dialog footer .btn.primary { flex: 1 1 10rem; }
fieldset { border: none; padding: 0; margin: 0; display: grid; gap: .5rem; }
legend { font-weight: 600; font-size: .9rem; padding: 0; margin-bottom: .3rem; }
.fields { display: grid; gap: 1rem; }
@media (min-width: 520px) { .fields.two { grid-template-columns: 1fr 1fr; } }

.top-gap { margin-top: 1rem; }

footer.page { text-align: center; color: var(--text-muted); font-size: .85rem; padding: 2rem 1rem 7rem; }
footer.page p { margin: 0 0 .75rem; }
.lang-picker select { width: auto; min-height: 40px; padding: .3rem 2rem .3rem .7rem; font-size: .9rem; }

@media (prefers-reduced-motion: no-preference) {
  .btn, .chip span { transition: background-color .15s, border-color .15s, filter .15s; }
}
