/* Headache Diary - Alignment First
   Calm clinical editorial: off-white canvas, teal accent, soft rounded cards.
   Mobile first. No external dependencies. */

:root {
  --bg: #f4f7f5;
  --surface: #ffffff;
  --tint: #e7f1ed;
  --tint-strong: #d6e9e2;
  --ink: #1b2b27;
  --ink-soft: #48584f;
  --muted: #6d7c75;
  --line: #dde6e1;
  --teal: #0e6e5c;
  --teal-dark: #0b5548;
  --teal-soft: #3fa88f;
  --danger: #b4432e;
  --danger-soft: #f3e0da;
  --amber: #d98a2b;

  --radius: 14px;
  --radius-sm: 10px;
  --shadow: 0 1px 2px rgba(18, 51, 43, 0.05), 0 8px 24px rgba(18, 51, 43, 0.06);
  --shadow-sm: 0 1px 2px rgba(18, 51, 43, 0.06);

  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;

  --maxw: 720px;
}

* { box-sizing: border-box; }

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

body {
  margin: 0;
  font-family: var(--font);
  color: var(--ink);
  background: var(--bg);
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  padding-bottom: env(safe-area-inset-bottom);
}

h1, h2, h3 { margin: 0; line-height: 1.2; letter-spacing: -0.01em; }
p { margin: 0; }

.container {
  width: 100%;
  max-width: var(--maxw);
  margin: 0 auto;
  padding: 0 18px;
}

.visually-hidden {
  position: absolute;
  width: 1px; height: 1px;
  padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0);
  white-space: nowrap; border: 0;
}

.skip-link {
  position: absolute;
  left: -999px;
  top: 0;
  background: var(--teal);
  color: #fff;
  padding: 10px 16px;
  border-radius: 0 0 var(--radius-sm) 0;
  z-index: 60;
  text-decoration: none;
}
.skip-link:focus { left: 0; }

/* Header */
.site-header {
  background: var(--surface);
  border-bottom: 1px solid var(--line);
  position: sticky;
  top: 0;
  z-index: 20;
}
.header-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding-top: 12px;
  padding-bottom: 12px;
}
.brand { display: flex; align-items: center; gap: 10px; }
.brand-mark {
  display: grid;
  place-items: center;
  width: 40px; height: 40px;
  border-radius: 11px;
  background: var(--tint);
  color: var(--teal);
  flex: none;
}
.brand-text { display: flex; flex-direction: column; line-height: 1.15; }
.brand-text strong { font-size: 1.02rem; font-weight: 700; }
.brand-text em { font-style: normal; font-size: 0.72rem; color: var(--muted); letter-spacing: 0.03em; text-transform: uppercase; }

.privacy-pill {
  font-size: 0.72rem;
  color: var(--teal-dark);
  background: var(--tint);
  border: 1px solid var(--tint-strong);
  padding: 5px 10px;
  border-radius: 999px;
  white-space: nowrap;
}

/* Layout */
.app-grid {
  display: flex;
  flex-direction: column;
  gap: 18px;
  padding-top: 22px;
  padding-bottom: 40px;
}

.intro { padding: 4px 2px 0; }
.intro h1 { font-size: 1.55rem; margin-bottom: 8px; }
.intro p { color: var(--ink-soft); max-width: 54ch; }
.fine-print { font-size: 0.8rem; color: var(--muted); margin-top: 8px; }

/* Cards */
.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 20px;
}
.card-head { margin-bottom: 16px; }
.card-head h2 { font-size: 1.18rem; }
.card-sub { color: var(--muted); font-size: 0.88rem; margin-top: 3px; }

/* Form */
.field { margin-bottom: 16px; }
.field:last-of-type { margin-bottom: 8px; }
label {
  display: block;
  font-weight: 600;
  font-size: 0.92rem;
  margin-bottom: 7px;
}
.label-row { display: flex; align-items: baseline; justify-content: space-between; }
.field-hint { font-size: 0.78rem; color: var(--muted); margin-top: 6px; }

input[type="date"],
input[type="number"],
textarea {
  width: 100%;
  font: inherit;
  color: var(--ink);
  background: #fbfdfc;
  border: 1.5px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 12px 13px;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}
textarea { resize: vertical; min-height: 70px; }

input[type="date"]:focus,
input[type="number"]:focus,
textarea:focus {
  outline: none;
  border-color: var(--teal-soft);
  box-shadow: 0 0 0 3px rgba(63, 168, 143, 0.2);
}

/* Severity output badge */
.severity-out {
  font-weight: 700;
  font-size: 1.05rem;
  color: var(--teal-dark);
  background: var(--tint);
  border-radius: 999px;
  min-width: 42px;
  text-align: center;
  padding: 2px 10px;
}

/* Range slider */
input[type="range"] {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 8px;
  border-radius: 999px;
  background: linear-gradient(90deg, var(--teal-soft), var(--amber) 65%, var(--danger));
  margin: 10px 0 4px;
  cursor: pointer;
}
input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 26px; height: 26px;
  border-radius: 50%;
  background: #fff;
  border: 3px solid var(--teal);
  box-shadow: var(--shadow-sm);
  cursor: pointer;
}
input[type="range"]::-moz-range-thumb {
  width: 24px; height: 24px;
  border-radius: 50%;
  background: #fff;
  border: 3px solid var(--teal);
  cursor: pointer;
}
input[type="range"]:focus-visible { outline: 2px solid var(--teal-soft); outline-offset: 4px; border-radius: 999px; }
.scale-legend {
  display: flex;
  justify-content: space-between;
  font-size: 0.76rem;
  color: var(--muted);
  margin-top: 2px;
}

/* Buttons */
.form-actions { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 4px; }
.btn {
  font: inherit;
  font-weight: 600;
  border-radius: var(--radius-sm);
  padding: 12px 18px;
  border: 1.5px solid transparent;
  cursor: pointer;
  transition: background 0.15s ease, border-color 0.15s ease, transform 0.05s ease, color 0.15s ease;
}
.btn:active { transform: translateY(1px); }
.btn-primary { background: var(--teal); color: #fff; }
.btn-primary:hover { background: var(--teal-dark); }
.btn-ghost { background: transparent; color: var(--ink-soft); border-color: var(--line); }
.btn-ghost:hover { background: var(--bg); }
.btn-danger { color: var(--danger); border-color: var(--danger-soft); }
.btn-danger:hover { background: var(--danger-soft); }
.btn-danger-solid { background: var(--danger); color: #fff; }
.btn-danger-solid:hover { background: #9a3826; }
.btn:focus-visible { outline: 2px solid var(--teal-soft); outline-offset: 2px; }

.form-feedback { font-size: 0.85rem; margin-top: 12px; min-height: 1.2em; }
.form-feedback.is-error { color: var(--danger); }
.form-feedback.is-ok { color: var(--teal-dark); }

/* Stat row */
.stat-row {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
  margin-bottom: 18px;
}
.stat {
  background: var(--tint);
  border-radius: var(--radius-sm);
  padding: 12px 10px;
  text-align: center;
}
.stat-label { display: block; font-size: 0.72rem; color: var(--ink-soft); text-transform: uppercase; letter-spacing: 0.04em; }
.stat-value { display: block; font-size: 1.35rem; font-weight: 700; color: var(--teal-dark); margin-top: 3px; }

/* Charts */
.chart-block { margin-top: 14px; }
.chart-heading { font-size: 0.82rem; font-weight: 600; color: var(--ink-soft); margin-bottom: 6px; }
.chart-wrap { width: 100%; }
.chart-wrap svg { width: 100%; height: auto; display: block; }
.chart-empty {
  text-align: center;
  color: var(--muted);
  font-size: 0.9rem;
  padding: 18px 8px 4px;
}

/* Chart bar pieces (styled via classes on SVG els) */
.bar-track { fill: #eef3f1; }
.bar-fill-low { fill: var(--teal-soft); }
.bar-fill-mid { fill: var(--amber); }
.bar-fill-high { fill: var(--danger); }
.bar-empty { fill: #e3ebe7; }
.bar-label { fill: var(--muted); font-size: 11px; font-family: var(--font); }
.bar-value { fill: var(--ink); font-size: 11px; font-weight: 600; font-family: var(--font); }
.sleep-fill { fill: var(--teal); }

/* List */
.list-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; }
.entry-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 12px; }

.entry {
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 14px;
  display: flex;
  gap: 14px;
  align-items: flex-start;
  background: #fcfefd;
}
.entry-sev {
  flex: none;
  width: 50px; height: 50px;
  border-radius: 12px;
  display: grid;
  place-items: center;
  font-weight: 700;
  font-size: 1.25rem;
  color: #fff;
}
.sev-low { background: var(--teal-soft); }
.sev-mid { background: var(--amber); }
.sev-high { background: var(--danger); }
.entry-body { flex: 1 1 auto; min-width: 0; }
.entry-top { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; flex-wrap: wrap; }
.entry-date { font-weight: 700; font-size: 0.98rem; }
.entry-meta { font-size: 0.82rem; color: var(--muted); }
.entry-notes { margin-top: 6px; color: var(--ink-soft); font-size: 0.9rem; word-break: break-word; white-space: pre-wrap; }
.entry-sev-word { font-size: 0.78rem; color: var(--muted); display: block; }

.entry-actions { display: flex; gap: 6px; flex: none; }
.icon-btn {
  border: 1px solid var(--line);
  background: #fff;
  border-radius: 9px;
  padding: 7px 11px;
  font: inherit;
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--ink-soft);
  cursor: pointer;
}
.icon-btn:hover { background: var(--bg); }
.icon-btn.danger { color: var(--danger); }
.icon-btn.danger:hover { background: var(--danger-soft); }
.icon-btn:focus-visible { outline: 2px solid var(--teal-soft); outline-offset: 2px; }

/* Empty state */
.empty-state {
  text-align: center;
  padding: 26px 12px 12px;
  color: var(--ink-soft);
}
.empty-mark {
  color: var(--teal-soft);
  margin-bottom: 10px;
}
.empty-state h3 { font-size: 1.05rem; margin-bottom: 6px; }
.empty-state p { color: var(--muted); font-size: 0.9rem; max-width: 40ch; margin: 0 auto; }

/* Footer */
.app-footer { text-align: center; color: var(--muted); font-size: 0.8rem; padding: 8px 4px 0; }
.app-footer p { margin: 0 auto; max-width: 48ch; }
.footer-brand { margin-top: 8px; color: var(--ink-soft); font-weight: 600; }

/* Modal */
.modal { position: fixed; inset: 0; z-index: 80; display: grid; place-items: center; padding: 20px; }
.modal[hidden] { display: none; }
.modal-backdrop { position: absolute; inset: 0; background: rgba(20, 35, 30, 0.5); }
.modal-box {
  position: relative;
  background: var(--surface);
  border-radius: var(--radius);
  padding: 22px;
  max-width: 380px;
  width: 100%;
  box-shadow: 0 20px 50px rgba(15, 40, 33, 0.3);
}
.modal-box h3 { font-size: 1.12rem; margin-bottom: 8px; }
.modal-box p { color: var(--ink-soft); font-size: 0.92rem; }
.modal-actions { display: flex; gap: 10px; margin-top: 18px; justify-content: flex-end; flex-wrap: wrap; }

/* Toast */
.toast {
  position: fixed;
  left: 50%;
  bottom: 22px;
  transform: translateX(-50%) translateY(8px);
  background: var(--ink);
  color: #fff;
  padding: 12px 18px;
  border-radius: 999px;
  font-size: 0.9rem;
  box-shadow: var(--shadow);
  z-index: 90;
  opacity: 0;
  transition: opacity 0.2s ease, transform 0.2s ease;
  max-width: calc(100% - 32px);
  text-align: center;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* Larger screens */
@media (min-width: 680px) {
  .intro h1 { font-size: 1.85rem; }
  .card { padding: 24px; }
  .entry-sev { width: 56px; height: 56px; }
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; }
}
