:root {
  --bg: #f6f7f9;
  --card: #ffffff;
  --text: #16181d;
  --muted: #6b7280;
  --line: #e3e6ea;
  --accent: #2f6fed;
  --ok: #1f9d55;
  --warn: #c98a00;
  --bad: #d0342c;
  --steps: #2f6fed;
  --deep: #3f4ea8;
  --light: #7c9bf0;
  --rem: #59b8c9;
  --awake: #d8b25a;
  --hr: #d0342c;
  --stress: #b05ccc;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #14161a;
    --card: #1c1f25;
    --text: #e8eaee;
    --muted: #98a1b0;
    --line: #2b3038;
    --accent: #6f9bff;
    --ok: #4cc38a;
    --warn: #e0b341;
    --bad: #f0736a;
    --steps: #6f9bff;
    --deep: #6f7ad8;
    --light: #9db6f5;
    --rem: #6fd3e2;
    --awake: #e0c47a;
    --hr: #f0736a;
    --stress: #cd8fe2;
  }
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font:
    15px / 1.5 system-ui,
    -apple-system,
    "Segoe UI",
    Roboto,
    sans-serif;
}

a {
  color: var(--accent);
  text-decoration: none;
}
a:hover {
  text-decoration: underline;
}

.topbar {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  align-items: center;
  justify-content: space-between;
  padding: 12px 20px;
  background: var(--card);
  border-bottom: 1px solid var(--line);
}

.topbar .brand {
  font-weight: 600;
  font-size: 16px;
  color: var(--text);
}
.topbar nav {
  display: flex;
  gap: 16px;
}

main {
  max-width: 1100px;
  margin: 0 auto;
  padding: 20px;
}

h1 {
  font-size: 22px;
  margin: 0 0 16px;
}
h2 {
  font-size: 17px;
  margin: 24px 0 12px;
}
h3 {
  font-size: 15px;
  margin: 0 0 8px;
}

.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 16px;
  margin-bottom: 16px;
}

.grid {
  display: grid;
  gap: 16px;
  grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
}
.row {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  align-items: center;
}
.spread {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 12px;
}

.muted {
  color: var(--muted);
}
.small {
  font-size: 13px;
}
.mono {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 12px;
}
.error {
  color: var(--bad);
}
.ok {
  color: var(--ok);
}
.warn {
  color: var(--warn);
}
.bad {
  color: var(--bad);
}

.metric {
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.metric .value {
  font-size: 24px;
  font-weight: 600;
}
.metric .label {
  font-size: 12px;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.metrics {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(110px, 1fr));
  gap: 12px;
  margin: 12px 0;
}

.badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 12px;
  border: 1px solid var(--line);
  color: var(--muted);
}
.badge.ok {
  border-color: var(--ok);
  color: var(--ok);
}
.badge.warn {
  border-color: var(--warn);
  color: var(--warn);
}
.badge.bad {
  border-color: var(--bad);
  color: var(--bad);
}

button,
.button {
  font: inherit;
  padding: 7px 14px;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: var(--card);
  color: var(--text);
  cursor: pointer;
}
button.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}
button:disabled {
  opacity: 0.55;
  cursor: default;
}

input,
select {
  font: inherit;
  padding: 7px 10px;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: var(--bg);
  color: var(--text);
}
label {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 13px;
  color: var(--muted);
}
label input,
label select {
  color: var(--text);
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
}
th,
td {
  text-align: right;
  padding: 6px 8px;
  border-bottom: 1px solid var(--line);
  white-space: nowrap;
}
th:first-child,
td:first-child {
  text-align: left;
}
th {
  color: var(--muted);
  font-weight: 500;
}
.scroll {
  overflow-x: auto;
}

.chart {
  width: 100%;
  height: auto;
  display: block;
}
.legend {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  font-size: 12px;
  color: var(--muted);
  margin-top: 6px;
}
.legend span::before {
  content: "";
  display: inline-block;
  width: 10px;
  height: 10px;
  border-radius: 2px;
  margin-right: 5px;
  background: currentColor;
}

.login {
  max-width: 340px;
  margin: 60px auto;
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.qr {
  max-width: 260px;
  border-radius: 8px;
  background: #fff;
  padding: 8px;
}
dialog::backdrop {
  background: rgba(0, 0, 0, 0.45);
}
dialog {
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--card);
  color: var(--text);
  max-width: 460px;
}

.code {
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px 12px;
  overflow-x: auto;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 12px;
  line-height: 1.45;
  white-space: pre;
  margin: 6px 0 12px;
}

h4 {
  font-size: 14px;
  margin: 14px 0 4px;
}
ol.small {
  padding-left: 20px;
  margin: 4px 0;
}
ul.small {
  padding-left: 18px;
  margin: 4px 0;
}

.profile-section {
  padding: 18px 20px 20px;
}
.profile-section > .spread {
  margin-bottom: 10px;
}

/* One chart per metric, side by side on wide screens, stacked on a phone. */
.charts-grid {
  display: grid;
  gap: 18px 24px;
  grid-template-columns: repeat(auto-fit, minmax(420px, 1fr));
  margin-top: 12px;
}

.chart-card {
  min-width: 0;
}
.chart-card h4 {
  margin: 0 0 4px;
  font-size: 13px;
  color: var(--muted);
  font-weight: 600;
  letter-spacing: 0.02em;
}

@media (max-width: 700px) {
  .charts-grid {
    grid-template-columns: 1fr;
  }
  main {
    padding: 12px;
  }
}

/* ---------- diary ---------- */

.diary-columns {
  display: grid;
  gap: 20px;
  grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
}

.diary-column form {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.symptom-row {
  margin-bottom: 10px;
}

.symptom-label {
  display: block;
  font-size: 13px;
  color: var(--muted);
  margin-bottom: 4px;
}

.scale {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
}

/* Tap targets sized for a thumb: the diary is filled in on a phone, standing in a kitchen. */
.chip {
  min-width: 34px;
  min-height: 34px;
  padding: 4px 10px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--card);
  color: var(--text);
  font: inherit;
  font-size: 13px;
  cursor: pointer;
}

.chip:hover {
  border-color: var(--accent);
}

.chip-on {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

.hidden-block[hidden] {
  display: none;
}

.heatmap {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(34px, 1fr));
  gap: 3px;
  margin: 10px 0;
}

.heat-cell {
  aspect-ratio: 1;
  border-radius: 4px;
  border: 1px solid var(--line);
  display: flex;
  align-items: center;
  justify-content: center;
}

.heat-day {
  font-size: 10px;
  color: var(--muted);
}

/* "Not recorded" must not look like "fine": it gets a dashed outline, not a pale green. */
.heat-none {
  background: transparent;
  border-style: dashed;
}

.heat-1 {
  background: color-mix(in srgb, var(--ok) 22%, transparent);
}
.heat-2 {
  background: color-mix(in srgb, var(--warn) 30%, transparent);
}
.heat-3 {
  background: color-mix(in srgb, var(--warn) 60%, transparent);
}
.heat-4 {
  background: color-mix(in srgb, var(--bad) 60%, transparent);
}
.heat-3 .heat-day,
.heat-4 .heat-day {
  color: var(--text);
}

.feed-day h3 {
  font-size: 14px;
  color: var(--muted);
  margin: 16px 0 6px;
  border-bottom: 1px solid var(--line);
  padding-bottom: 4px;
}

.feed {
  list-style: none;
  margin: 0;
  padding: 0;
}

.feed-item {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  padding: 6px 0;
  border-bottom: 1px solid var(--line);
}

.feed-item:last-child {
  border-bottom: none;
}

.feed-icon {
  flex: none;
}

.feed-body {
  flex: 1;
  min-width: 0;
}

.tag-list {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  margin-top: 3px;
}

.card.warn {
  border-left: 3px solid var(--warn);
}

.card.ok {
  border-left: 3px solid var(--ok);
}

.symptom-group h4 {
  margin: 12px 0 4px;
  font-size: 13px;
  color: var(--muted);
}

.dish-rows {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.dish-row {
  display: flex;
  gap: 4px;
  align-items: center;
}

.dish-name {
  flex: 1 1 auto;
  min-width: 90px;
}

/* Five numeric fields have to fit next to a name on a phone, hence the hard cap. */
.dish-num {
  width: 62px;
  flex: none;
}

.temp-input {
  width: 90px;
}

.secret-field {
  margin: 8px 0;
  padding-bottom: 6px;
  border-bottom: 1px solid var(--line);
}

.secret-field:last-child {
  border-bottom: none;
}

.secret-field .row {
  flex-wrap: wrap;
}
