:root {
  --bg: #f6f4ef;
  --surface: #ffffff;
  --surface-2: #efece4;
  --text: #22261f;
  --muted: #6b6f66;
  --border: #dcd8cd;
  --accent: #3f6b5c;
  --accent-text: #ffffff;
  --accent-soft: #e2ece7;
  --danger: #b4452f;
  --sev-1: #e8d98a;
  --sev-2: #e9a85a;
  --sev-3: #d2603f;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(30, 30, 20, 0.06), 0 4px 16px rgba(30, 30, 20, 0.05);
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #161815;
    --surface: #1f221e;
    --surface-2: #282c27;
    --text: #e9ebe5;
    --muted: #9ea398;
    --border: #353a33;
    --accent: #7fb8a3;
    --accent-text: #10201a;
    --accent-soft: #24352e;
    --danger: #e9806a;
    --sev-1: #8f8440;
    --sev-2: #a8692e;
    --sev-3: #b2462c;
    --shadow: none;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }

html, body { margin: 0; }

body {
  background: var(--bg);
  color: var(--text);
  font: 16px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
}

.wrap { max-width: 760px; margin: 0 auto; padding: 16px 16px 96px; }

h1, h2, h3 { line-height: 1.2; margin: 0; }
h1 { font-size: 1.5rem; letter-spacing: -0.01em; }
h2 { font-size: 1.1rem; }
h3 { font-size: 0.95rem; }

.muted { color: var(--muted); }
.small { font-size: 0.85rem; }

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

button, .btn {
  font: inherit;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  padding: 9px 14px;
  cursor: pointer;
  min-height: 42px;
}
button:hover { border-color: var(--muted); }
button:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}
button.primary { background: var(--accent); color: var(--accent-text); border-color: var(--accent); font-weight: 600; }
button.danger { color: var(--danger); }
button.ghost { background: transparent; border-color: transparent; }
button:disabled { opacity: 0.6; cursor: default; }

input, select, textarea {
  font: inherit;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 9px 11px;
  width: 100%;
  min-height: 42px;
}
textarea { min-height: 80px; resize: vertical; }
label { display: block; font-size: 0.9rem; font-weight: 500; margin-bottom: 4px; }

/* ---------- login ---------- */
.login {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 16px;
}
.login .card { width: 100%; max-width: 360px; display: grid; gap: 14px; }
.error { color: var(--danger); font-size: 0.9rem; min-height: 1.2em; margin: 0; }

/* ---------- header ---------- */
.top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  margin-bottom: 16px;
}
.top-actions { display: flex; gap: 8px; flex-wrap: wrap; }

/* ---------- report list ---------- */
.list { display: grid; gap: 12px; }
.report-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 8px; margin-bottom: 10px; }
.report-actions { display: flex; gap: 4px; }
.report-actions button { min-height: 34px; padding: 4px 10px; font-size: 0.85rem; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 10px; }
.chip {
  font-size: 0.82rem;
  border-radius: 999px;
  padding: 3px 10px;
  background: var(--surface-2);
  border: 1px solid var(--border);
}
.chip.s1 { background: var(--sev-1); border-color: transparent; color: #2a2610; }
.chip.s2 { background: var(--sev-2); border-color: transparent; color: #2a1a08; }
.chip.s3 { background: var(--sev-3); border-color: transparent; color: #fff; }
.kv { display: grid; grid-template-columns: max-content 1fr; gap: 2px 12px; font-size: 0.9rem; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; overflow-wrap: anywhere; }
.empty-state { text-align: center; padding: 32px 16px; }

/* ---------- form ---------- */
.form { display: grid; gap: 16px; }
.form fieldset { border: 0; margin: 0; padding: 0; display: grid; gap: 12px; }
.form legend { font-weight: 700; font-size: 1.05rem; margin-bottom: 4px; padding: 0; }
.hint { font-size: 0.85rem; color: var(--muted); margin: -6px 0 0; }

.sym-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 2.2em;
  grid-template-areas: "name val" "range range";
  gap: 2px 8px;
  align-items: center;
}
.sym-row .name { grid-area: name; font-size: 0.95rem; }
.sym-row output { grid-area: val; text-align: right; font-weight: 700; font-variant-numeric: tabular-nums; }
.sym-row input[type="range"] { grid-area: range; padding: 0; min-height: 28px; border: 0; background: transparent; accent-color: var(--accent); }
.sym-row.active .name { font-weight: 600; }
.sym-name-input { min-height: 34px; padding: 4px 8px; }

.meal { display: grid; grid-template-columns: 140px 1fr; gap: 8px; align-items: end; }
.meal label { grid-column: 1 / -1; margin-bottom: -4px; }

.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }

.scale { display: flex; gap: 6px; }
.scale input { position: absolute; opacity: 0; pointer-events: none; width: 1px; min-height: 0; }
.scale label {
  flex: 1;
  margin: 0;
  text-align: center;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 7px 0;
  cursor: pointer;
  background: var(--surface);
  font-weight: 600;
}
.scale input:checked + label { background: var(--accent); color: var(--accent-text); border-color: var(--accent); }
.scale input:focus-visible + label { outline: 2px solid var(--accent); outline-offset: 2px; }

.check { display: flex; align-items: center; gap: 8px; font-weight: 500; }
.check input { width: 20px; min-height: 20px; height: 20px; accent-color: var(--accent); }

.form-actions {
  position: sticky;
  bottom: 0;
  display: flex;
  gap: 8px;
  justify-content: flex-end;
  padding: 12px 0;
  background: linear-gradient(transparent, var(--bg) 30%);
}

.toast {
  position: fixed;
  left: 50%;
  bottom: 20px;
  transform: translateX(-50%);
  background: var(--text);
  color: var(--bg);
  padding: 10px 16px;
  border-radius: 10px;
  font-size: 0.9rem;
  opacity: 0;
  transition: opacity 0.2s;
  pointer-events: none;
  max-width: calc(100% - 32px);
}
.toast.show { opacity: 1; }

.swatches { display: grid; grid-template-columns: repeat(17, minmax(0, 1fr)); gap: 3px; }
.swatches input { position: absolute; opacity: 0; pointer-events: none; width: 1px; min-height: 0; }
.swatches label {
  margin: 0;
  cursor: pointer;
  text-align: center;
  font-size: 0.7rem;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}
.swatches label span {
  display: block;
  height: 40px;
  border-radius: 5px;
  margin-bottom: 2px;
  border: 2px solid transparent;
}
.swatches label.normal span { box-shadow: inset 0 -4px 0 rgba(255,255,255,0.35); }
.swatches input:checked + label span { border-color: var(--text); outline: 2px solid var(--accent); outline-offset: 1px; }
.swatches input:checked + label { color: var(--text); font-weight: 700; }
.swatches input:focus-visible + label span { outline: 2px solid var(--accent); outline-offset: 1px; }
.swatch-dot { display: inline-block; width: 0.8em; height: 0.8em; border-radius: 3px; vertical-align: -0.05em; margin-right: 3px; }

[hidden] { display: none !important; }

@media (max-width: 520px) {
  .grid-2 { grid-template-columns: 1fr; }
  .meal { grid-template-columns: 1fr; }
  .stats { grid-template-columns: 1fr 1fr 1fr; }
  .top-actions button { padding: 8px 10px; }
}
