:root {
  --bg: #eceae5;
  --surface: #f1efea;
  --surface-2: #e2e0da;
  --text: #333634;
  --text-dim: #666b67;
  --line: #d3d1ca;
  --line-strong: #aaa9a3;
  --accent: #536f78;
  --accent-hover: #49636b;
  --accent-text: #f3f1ec;
  --danger: #86575a;
  --mild: #4c6d5c;
  --moderate: #755f35;
  --severe: #86575a;
  --choice-text: #fffaf5;
  --radius: 8px;
  --pad: 18px;
  --safe-b: env(safe-area-inset-bottom, 0px);
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #1b1e20;
    --surface: #202426;
    --surface-2: #262b2d;
    --text: #c1c0ba;
    --text-dim: #858986;
    --line: #2c3234;
    --line-strong: #3b4244;
    --accent: #7b8e96;
    --accent-hover: #8599a1;
    --accent-text: #161b1d;
    --danger: #b9787c;
    --mild: #789683;
    --moderate: #a48b60;
    --severe: #a87579;
    --choice-text: #161b1d;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

body {
  margin: 0;
  padding-bottom: calc(28px + var(--safe-b));
  background: var(--bg);
  color: var(--text);
  font: 16px/1.5 system-ui, -apple-system, "Segoe UI", sans-serif;
  -webkit-text-size-adjust: 100%;
}

main, .topbar, .footer {
  width: min(100%, 38rem);
  margin: 0 auto;
  padding-inline: var(--pad);
}

.topbar {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 24px;
  padding-top: calc(28px + env(safe-area-inset-top, 0px));
  padding-bottom: 18px;
  border-bottom: 1px solid var(--line);
}

.kicker {
  margin: 0 0 2px;
  color: var(--accent);
  font-size: 0.72rem;
  font-weight: 750;
  letter-spacing: 0.09em;
  text-transform: uppercase;
}

.topbar h1 {
  margin: 0;
  font-family: Georgia, "Times New Roman", serif;
  font-size: clamp(1.75rem, 6vw, 2.15rem);
  font-weight: 600;
  letter-spacing: -0.025em;
  line-height: 1.1;
}

.tally {
  max-width: 15rem;
  margin: 0 0 2px;
  color: var(--text-dim);
  font-size: 0.78rem;
  font-variant-numeric: tabular-nums;
  line-height: 1.35;
  text-align: right;
}
.tally:empty { display: none; }

.actions {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 10px;
  margin: 22px 0 26px;
}

.btn {
  display: inline-flex;
  min-height: 48px;
  align-items: center;
  justify-content: center;
  gap: 9px;
  padding: 11px 16px;
  border: 1px solid transparent;
  border-radius: var(--radius);
  font: inherit;
  font-weight: 650;
  cursor: pointer;
  transition: background-color 0.15s ease, border-color 0.15s ease, transform 0.08s ease;
  -webkit-tap-highlight-color: transparent;
}
.btn:active { transform: translateY(1px); }
.btn svg { width: 19px; height: 19px; flex: none; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; }
.btn-primary { background: var(--accent); color: var(--accent-text); }
.btn-primary:hover { background: var(--accent-hover); }
.btn-ghost { border-color: var(--line-strong); background: transparent; color: var(--text); }
.btn-ghost:hover { background: var(--surface-2); }
.btn-danger { border-color: transparent; background: transparent; color: var(--danger); }
.btn-sm { min-height: 44px; padding: 8px 13px; font-size: 0.92rem; }
.row { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 18px; }
.row .btn-danger { margin-left: auto; }

.card { background: var(--surface); }

label, legend { display: block; margin: 15px 0 6px; padding: 0; color: var(--text-dim); font-size: 0.86rem; font-weight: 650; }
.entry-body > label:first-child { margin-top: 0; }
.control-group { min-width: 0; margin: 0; padding: 0; border: 0; }
.entry-body > .control-group { margin-top: 22px; }
.control-group legend { width: 100%; margin-top: 0; }
.entry-notes-label { margin-top: 22px; }
.entry-body > .row { margin-top: 24px; }

input[type="datetime-local"], textarea {
  width: 100%;
  min-height: 48px;
  padding: 11px 12px;
  border: 1px solid var(--line-strong);
  border-radius: 6px;
  background: transparent;
  color: var(--text);
  font: inherit;
}
textarea { resize: vertical; line-height: 1.45; }
input:focus-visible, textarea:focus-visible, button:focus-visible, summary:focus-visible {
  outline: 3px solid color-mix(in srgb, var(--accent) 55%, transparent);
  outline-offset: 2px;
}

.list { margin: 0; padding: 0; border-top: 1px solid var(--line-strong); list-style: none; }
.entry { position: relative; border-bottom: 1px solid var(--line-strong); background: transparent; }
.entry::before { position: absolute; top: 18px; left: 0; width: 3px; height: 22px; background: var(--line-strong); content: ""; }
.entry.severity-mild::before { background: var(--mild); }
.entry.severity-moderate::before { background: var(--moderate); }
.entry.severity-severe::before { background: var(--severe); }
.entry-head {
  display: flex;
  width: 100%;
  min-height: 58px;
  align-items: center;
  gap: 12px;
  padding: 12px 4px 12px 14px;
  border: 0;
  background: none;
  color: inherit;
  font: inherit;
  text-align: left;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
.entry-head-main { display: flex; min-width: 0; flex: 1; flex-direction: column; gap: 2px; }
.entry-when { font-weight: 680; font-variant-numeric: tabular-nums; }
.entry-notes { overflow: hidden; color: var(--text-dim); font-size: 0.9rem; text-overflow: ellipsis; white-space: nowrap; }
.entry-notes:empty, .entry-meta:empty { display: none; }
.chev { width: 18px; height: 18px; flex: none; fill: none; stroke: var(--text-dim); stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; transition: transform 0.18s ease; }
.entry-meta { display: flex; flex-wrap: wrap; align-items: center; gap: 7px; color: var(--text-dim); font-size: 0.8rem; }
.badge { padding: 0 0 1px; border-bottom: 2px solid currentColor; font-size: 0.72rem; font-weight: 750; letter-spacing: 0.06em; text-transform: uppercase; }
.badge-mild { color: var(--mild); }
.badge-moderate { color: var(--moderate); }
.badge-severe { color: var(--severe); }

.chips { display: flex; flex-wrap: wrap; gap: 7px; }
.chip-wrap { display: inline-flex; }
.chip {
  min-height: 44px;
  padding: 8px 12px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: color-mix(in srgb, var(--surface) 72%, transparent);
  color: var(--text-dim);
  font: inherit;
  font-size: 0.87rem;
  cursor: pointer;
  transition: background-color 0.12s ease, border-color 0.12s ease;
  -webkit-tap-highlight-color: transparent;
}
.chip.on { border-color: var(--accent); background: var(--accent); color: var(--accent-text); font-weight: 650; }
.chip-add { border-style: dashed; color: var(--text-dim); }
.chip-wrap.has-x .chip { border-right: 0; border-radius: 6px 0 0 6px; }
.chip-x { min-width: 44px; min-height: 44px; padding: 7px 10px; border: 1px solid var(--line); border-radius: 0 6px 6px 0; background: color-mix(in srgb, var(--surface) 72%, transparent); color: var(--text-dim); font: inherit; font-size: 1rem; cursor: pointer; }
.chip-x:hover { color: var(--danger); }
.intensity-group .chips { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; }
.intensity-group .chip-wrap, .intensity-group .chip { width: 100%; }
.intensity-group .chip[data-value="Mild"] {
  border-color: color-mix(in srgb, var(--mild) 28%, var(--line));
  background: color-mix(in srgb, var(--mild) 5%, transparent);
  color: var(--mild);
}
.intensity-group .chip[data-value="Moderate"] {
  border-color: color-mix(in srgb, var(--moderate) 28%, var(--line));
  background: color-mix(in srgb, var(--moderate) 5%, transparent);
  color: var(--moderate);
}
.intensity-group .chip[data-value="Severe"] {
  border-color: color-mix(in srgb, var(--severe) 28%, var(--line));
  background: color-mix(in srgb, var(--severe) 5%, transparent);
  color: var(--severe);
}
.intensity-group .chip[data-value="Mild"].on,
.intensity-group .chip[data-value="Moderate"].on,
.intensity-group .chip[data-value="Severe"].on {
  color: var(--choice-text);
}
.intensity-group .chip[data-value="Mild"].on { border-color: var(--mild); background: var(--mild); }
.intensity-group .chip[data-value="Moderate"].on { border-color: var(--moderate); background: var(--moderate); }
.intensity-group .chip[data-value="Severe"].on { border-color: var(--severe); background: var(--severe); }

.entry.open .chev { transform: rotate(180deg); }
.entry.open .entry-notes { white-space: normal; }
.entry-body { padding: 4px 4px 22px 14px; }
.empty { margin: 42px 12px; color: var(--text-dim); line-height: 1.7; text-align: left; }

.footer { margin-top: 0; }
.footer details { border-top: 1px solid var(--line); }
.footer details:first-child { border-top: 0; }
summary { padding: 14px 0; color: var(--text-dim); font-size: 0.86rem; font-weight: 650; cursor: pointer; }
.note { max-width: 32rem; color: var(--text-dim); font-size: 0.84rem; line-height: 1.6; }
.install-steps { max-width: 34rem; margin: 10px 0 20px; padding-left: 1.2rem; color: var(--text-dim); font-size: 0.84rem; line-height: 1.6; }
.install-steps li + li { margin-top: 7px; }
.panel-status { font-weight: 400; }
.panel-status.stale { color: var(--accent); font-weight: 650; }

/* ---- Statistics -------------------------------------------------------- */
.stats {
  padding-bottom: 20px;
}

.stat-block { margin-top: 20px; }
.stat-block:first-child { margin-top: 12px; }

.stat-block h3 {
  margin: 0 0 10px;
  font-size: 0.74rem;
  font-weight: 700;
  letter-spacing: 0.09em;
  text-transform: uppercase;
  color: var(--text-dim);
}

.stat-facts {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 4px 16px;
  margin: 0;
  font-size: 0.93rem;
}
.stat-facts dt { color: var(--text-dim); }
.stat-facts dd { margin: 0; font-variant-numeric: tabular-nums; }

.stat-row {
  display: grid;
  grid-template-columns: 5.5rem 1fr 2rem;
  align-items: center;
  gap: 10px;
  padding: 5px 0;
  font-size: 0.9rem;
}

.stat-label {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--text-dim);
}

.stat-track {
  height: 9px;
  background: var(--surface-2);
  border: 1px solid var(--line);
}

.stat-bar {
  display: block;
  height: 100%;
  min-width: 0;
  background: var(--accent);
}

.stat-count {
  text-align: right;
  font-variant-numeric: tabular-nums;
  font-weight: 650;
}

/* A wider label column once there is room for it */
@media (min-width: 24rem) {
  .stat-row { grid-template-columns: 7rem 1fr 2rem; }
}

.toast {
  position: fixed;
  bottom: calc(20px + var(--safe-b));
  left: 50%;
  z-index: 10;
  width: max-content;
  max-width: calc(100vw - 32px);
  padding: 11px 16px;
  transform: translateX(-50%);
  border: 1px solid var(--line-strong);
  border-radius: 6px;
  background: var(--text);
  box-shadow: 0 8px 28px rgb(0 0 0 / 0.24);
  color: var(--bg);
  font-size: 0.88rem;
  font-weight: 650;
  text-align: center;
}

@media (max-width: 34rem) {
  .topbar { display: block; }
  .tally { margin-top: 8px; text-align: left; }
  .actions { grid-template-columns: 1fr; margin-bottom: 22px; }
}

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