:root {
  /* Calm, slightly clinical but warmer than pure medical white.
     Ink-teal primary, muted clay for symptom warmth, a green->red severity ramp. */
  --bg:        #f3f1ec;   /* warm paper */
  --surface:   #ffffff;
  --ink:       #1c2b2d;   /* deep teal-ink, near-black */
  --muted:     #5e6f6f;
  --line:      #dcd8cf;
  --teal:      #1f6f6b;   /* meals / primary */
  --teal-soft: #e3efed;
  --clay:      #b4533a;   /* symptoms */
  --clay-soft: #f4e3dd;
  --focus:     #1f6f6b;

  /* severity ramp 0..5 */
  --s0: #8ba888;
  --s1: #b6c06a;
  --s2: #e0c14e;
  --s3: #e0993f;
  --s4: #d36a39;
  --s5: #b4332a;

  --radius: 12px;
  --maxw: 880px;
  font-synthesis: none;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  line-height: 1.5;
  -webkit-text-size-adjust: 100%;
}

h2 { font-weight: 650; letter-spacing: -0.01em; }

a { color: var(--teal); }

/* ---- top bar ---- */
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  gap: 1rem; padding: 0.85rem 1.1rem;
  background: var(--ink); color: #fff;
  position: sticky; top: 0; z-index: 10;
}
.wordmark {
  font-weight: 700; font-size: 1.15rem; letter-spacing: 0.02em;
  color: #fff; text-decoration: none;
}
.topbar nav { display: flex; gap: 0.35rem; }
.topbar nav a {
  color: #cfdedd; text-decoration: none; font-size: 0.92rem;
  padding: 0.35rem 0.7rem; border-radius: 999px;
}
.topbar nav a.active { background: rgba(255,255,255,0.14); color: #fff; }

main { max-width: var(--maxw); margin: 0 auto; padding: 1.1rem; }

/* ---- entry forms ---- */
.entry-grid { display: grid; gap: 1rem; grid-template-columns: 1fr; }
@media (min-width: 720px) { .entry-grid { grid-template-columns: 1fr 1fr; } }

.card {
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 1.1rem;
}
.card-title {
  margin: 0 0 0.9rem; font-size: 1.05rem; display: flex; align-items: center; gap: 0.55rem;
}
.dot { width: 0.7rem; height: 0.7rem; border-radius: 50%; display: inline-block; }
.dot-meal { background: var(--teal); }
.dot-symptom { background: var(--clay); }

.stack { display: flex; flex-direction: column; gap: 0.85rem; }
.field { display: flex; flex-direction: column; gap: 0.3rem; border: 0; padding: 0; margin: 0; }
.field > span { font-size: 0.82rem; color: var(--muted); font-weight: 600; }

input[type=datetime-local], input[type=text], textarea, select {
  width: 100%; padding: 0.6rem 0.7rem; font: inherit; color: var(--ink);
  background: #fff; border: 1px solid var(--line); border-radius: 8px;
}
textarea { resize: vertical; }
input:focus, textarea:focus, select:focus {
  outline: 2px solid var(--focus); outline-offset: 1px; border-color: var(--focus);
}
input[type=range] { accent-color: var(--clay); width: 100%; }
#sevout { color: var(--ink); font-weight: 700; }

/* tag chips */
.chips { display: flex; flex-wrap: wrap; gap: 0.4rem; }
.chip { position: relative; }
.chip input { position: absolute; opacity: 0; inset: 0; cursor: pointer; }
.chip span {
  display: inline-block; padding: 0.3rem 0.65rem; border-radius: 999px;
  border: 1px solid var(--line); font-size: 0.85rem; background: #fff; cursor: pointer;
}
.chip input:checked + span { background: var(--teal); border-color: var(--teal); color: #fff; }
.chip input:focus-visible + span { outline: 2px solid var(--focus); outline-offset: 1px; }

.btn {
  border: 0; border-radius: 8px; padding: 0.7rem 1rem; font: inherit; font-weight: 650;
  color: #fff; cursor: pointer;
}
.btn-meal { background: var(--teal); }
.btn-symptom { background: var(--clay); }
.btn:hover { filter: brightness(1.06); }
.btn:active { transform: translateY(1px); }

/* ---- timeline ---- */
.timeline { margin-top: 1.6rem; }
.timeline-head { font-size: 1rem; color: var(--muted); margin: 0 0 0.7rem; font-weight: 600; }
.empty {
  color: var(--muted); background: var(--surface); border: 1px dashed var(--line);
  border-radius: var(--radius); padding: 1.1rem; margin: 0.5rem 0;
}

.event {
  display: grid; grid-template-columns: auto 1fr auto; gap: 0.75rem; align-items: start;
  background: var(--surface); border: 1px solid var(--line);
  border-left-width: 4px; border-radius: 10px; padding: 0.7rem 0.85rem; margin-bottom: 0.55rem;
}
.event-meal { border-left-color: var(--teal); }
.event-symptom { border-left-color: var(--clay); }
.event-time { font-variant-numeric: tabular-nums; color: var(--muted); font-size: 0.9rem; padding-top: 0.1rem; }
.event-body { min-width: 0; }
.event-desc { margin: 0; }
.event-note { margin: 0.25rem 0 0; color: var(--muted); font-size: 0.9rem; }
.event-tags { margin-top: 0.4rem; display: flex; flex-wrap: wrap; gap: 0.3rem; }
.tag-pill {
  font-size: 0.76rem; background: var(--teal-soft); color: var(--teal);
  padding: 0.12rem 0.5rem; border-radius: 999px;
}
.event-ingredients { margin-top: 0.35rem; display: flex; flex-wrap: wrap; gap: 0.3rem; }
.ingredient-pill {
  font-size: 0.72rem; background: #f0ece3; color: var(--muted);
  border: 1px solid var(--line); padding: 0.1rem 0.45rem; border-radius: 999px;
}
.sev { font-size: 0.78rem; padding: 0.1rem 0.5rem; border-radius: 999px; color: #fff; margin-left: 0.4rem; }
.sev-0 { background: var(--s0); } .sev-1 { background: var(--s1); color: #3a3a1a; }
.sev-2 { background: var(--s2); color: #4a3a10; } .sev-3 { background: var(--s3); }
.sev-4 { background: var(--s4); } .sev-5 { background: var(--s5); }

.event-actions { display: flex; flex-direction: column; gap: 0.2rem; align-items: center; }
.event-del { margin: 0; }
.event-del button {
  border: 0; background: transparent; color: var(--muted); font-size: 1.3rem;
  line-height: 1; cursor: pointer; padding: 0 0.2rem; border-radius: 6px;
}
.event-del button:hover { color: var(--clay); background: var(--clay-soft); }
.btn-edit {
  border: 0; background: transparent; color: var(--muted); font-size: 1.1rem;
  line-height: 1; cursor: pointer; padding: 0 0.2rem; border-radius: 6px;
}
.btn-edit:hover { color: var(--teal); background: var(--teal-soft); }

/* inline edit form */
.event-editing { display: block; }
.edit-row { display: grid; grid-template-columns: 1fr 1fr; gap: 0.65rem; }
@media (max-width: 480px) { .edit-row { grid-template-columns: 1fr; } }
.edit-actions { display: flex; gap: 0.65rem; align-items: center; }
.btn-cancel {
  border: 0; background: transparent; color: var(--muted); font: inherit;
  font-size: 0.9rem; cursor: pointer; padding: 0.35rem 0.65rem; border-radius: 8px;
}
.btn-cancel:hover { color: var(--ink); background: var(--line); }

/* ---- dashboard ---- */
.dash-head h2, .tags-head h2 { margin: 0 0 0.3rem; }
.lede { color: var(--muted); margin: 0 0 0.9rem; max-width: 60ch; }
.lede em { color: var(--ink); font-style: normal; font-weight: 650; }
.statline { display: flex; gap: 1.2rem; font-size: 0.9rem; color: var(--muted); margin-bottom: 1rem; }
.statline span { font-variant-numeric: tabular-nums; }

.sevfilter { display: flex; align-items: center; gap: 0.5rem; margin-bottom: 1rem; font-size: 0.88rem; color: var(--muted); flex-wrap: wrap; }
.sevbtn {
  text-decoration: none; color: var(--ink); border: 1px solid var(--line);
  border-radius: 7px; padding: 0.25rem 0.6rem; background: #fff; font-variant-numeric: tabular-nums;
}
.sevbtn.on { background: var(--ink); color: #fff; border-color: var(--ink); }

.table-wrap { overflow-x: auto; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); }
table.lag { border-collapse: collapse; width: 100%; min-width: 520px; }
table.lag th, table.lag td { padding: 0.6rem 0.7rem; text-align: center; font-variant-numeric: tabular-nums; }
table.lag thead th { background: #ece8e0; font-size: 0.82rem; color: var(--muted); font-weight: 650; border-bottom: 1px solid var(--line); }
.th-tag, .td-tag { text-align: left; font-variant-numeric: normal; }
.td-tag { font-weight: 600; }
table.lag tbody tr + tr td { border-top: 1px solid var(--line); }
.td-base { color: var(--muted); }

/* heat cell: shaded by EXCESS over baseline (0..1), white -> clay.
   Multiplied up because an excess of ~0.5 is already a strong signal. */
.heat {
  background: color-mix(in srgb, var(--clay) calc(min(var(--rate) * 160%, 85%)), #fff);
}
.heat { color: var(--ink); }

.caveat { color: var(--muted); font-size: 0.85rem; margin-top: 0.9rem; max-width: 64ch; }

/* ---- tags page ---- */
.addtag { display: flex; gap: 0.5rem; margin-bottom: 1rem; max-width: 420px; }
.addtag input { flex: 1; }
.taglist { list-style: none; padding: 0; margin: 0; display: flex; flex-wrap: wrap; gap: 0.5rem; }
.taglist li {
  display: flex; align-items: center; gap: 0.5rem; background: var(--surface);
  border: 1px solid var(--line); border-radius: 999px; padding: 0.3rem 0.4rem 0.3rem 0.8rem;
}
.taglist form { margin: 0; }
.taglist button {
  border: 0; background: transparent; color: var(--muted); cursor: pointer;
  font-size: 1.1rem; line-height: 1; border-radius: 50%; width: 1.5rem; height: 1.5rem;
}
.taglist button:hover { color: var(--clay); background: var(--clay-soft); }

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