/* HealthInsight — design tokens (light/dark selected, not flipped) */

:root {
  --page: #f9f9f7;
  --surface: #fcfcfb;
  --text-primary: #0b0b0b;
  --text-secondary: #52514e;
  --text-muted: #898781;
  --grid: #e1e0d9;
  --baseline: #c3c2b7;
  --border: rgba(11, 11, 11, 0.10);
  --series-1: #2a78d6; /* blue */
  --series-2: #1baf7a; /* aqua */
  --wash-1: rgba(42, 120, 214, 0.10);
  --delta-good: #006300;
  --delta-bad: #d03b3b;
  --accent: #2a78d6;
  --accent-ink: #ffffff;
}

@media (prefers-color-scheme: dark) {
  :root {
    --page: #0d0d0d;
    --surface: #1a1a19;
    --text-primary: #ffffff;
    --text-secondary: #c3c2b7;
    --text-muted: #898781;
    --grid: #2c2c2a;
    --baseline: #383835;
    --border: rgba(255, 255, 255, 0.10);
    --series-1: #3987e5;
    --series-2: #199e70;
    --wash-1: rgba(57, 135, 229, 0.10);
    --delta-good: #0ca30c;
    --delta-bad: #d03b3b;
    --accent: #3987e5;
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--page);
  color: var(--text-primary);
  font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
  font-size: 15px;
  line-height: 1.45;
}

main {
  max-width: 1080px;
  margin: 0 auto;
  padding: 0 16px 48px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.topbar {
  max-width: 1080px;
  margin: 0 auto;
  padding: 20px 16px 12px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.brand { font-size: 20px; font-weight: 650; margin: 0; }

.topbar-actions { display: flex; gap: 8px; }

h2 { font-size: 14px; font-weight: 600; margin: 0 0 12px; color: var(--text-secondary); }

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

/* ---- quick log ---- */

.log-row { display: grid; grid-template-columns: 3fr 2fr; gap: 16px; }
@media (max-width: 760px) { .log-row { grid-template-columns: 1fr; } }

.log-card { display: flex; flex-direction: column; gap: 12px; }
.log-card h2 { margin-bottom: 0; }

.field-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(110px, 1fr)); gap: 10px; }

label {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 12px;
  color: var(--text-secondary);
}

input {
  font: inherit;
  color: var(--text-primary);
  background: var(--page);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 10px;
}
input:focus { outline: 2px solid var(--accent); outline-offset: 1px; }

.hint { font-size: 12px; color: var(--text-muted); margin: 0; }

.primary-btn {
  font: inherit;
  font-weight: 600;
  background: var(--accent);
  color: var(--accent-ink);
  border: none;
  border-radius: 8px;
  padding: 9px 16px;
  cursor: pointer;
  align-self: start;
}
.primary-btn:hover { filter: brightness(1.08); }

.ghost-btn, .range-btn, .icon-btn, .danger-btn {
  font: inherit;
  font-size: 13px;
  background: transparent;
  color: var(--text-secondary);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 6px 12px;
  cursor: pointer;
}
.ghost-btn:hover, .range-btn:hover { background: var(--surface); border-color: var(--baseline); }

.danger-btn { color: var(--delta-bad); }

/* ---- stat tiles ---- */

.tile-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 12px;
}

.stat-tile {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 14px 16px;
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}

.stat-label { font-size: 12px; color: var(--text-secondary); }
.stat-value { font-size: 26px; font-weight: 600; color: var(--text-primary); }
.stat-value .unit { font-size: 14px; font-weight: 500; color: var(--text-muted); margin-left: 2px; }
.stat-sub { font-size: 12px; color: var(--text-muted); display: flex; align-items: center; gap: 6px; }
.stat-delta { font-weight: 600; }
.stat-delta.good { color: var(--delta-good); }
.stat-delta.bad { color: var(--delta-bad); }
.stat-delta.neutral { color: var(--text-secondary); }
.stat-spark { margin-top: 6px; }

/* ---- suggestions ---- */

.suggestions ul { margin: 0; padding: 0; list-style: none; display: flex; flex-direction: column; gap: 8px; }
.suggestions li { display: flex; gap: 10px; align-items: baseline; color: var(--text-secondary); }
.suggestions li .s-icon { flex: none; }
.suggestions li strong { color: var(--text-primary); font-weight: 600; }

/* ---- filter row ---- */

.filter-row { display: flex; gap: 8px; flex-wrap: wrap; }
.range-btn[aria-pressed="true"] {
  background: var(--accent);
  color: var(--accent-ink);
  border-color: var(--accent);
  font-weight: 600;
}

/* ---- charts ---- */

.chart-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.chart-card.wide { grid-column: 1 / -1; }
@media (max-width: 760px) { .chart-grid { grid-template-columns: 1fr; } }

.chart { position: relative; }
.chart svg { display: block; width: 100%; height: auto; }
.chart:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 8px; }

.chart-legend {
  display: flex;
  gap: 16px;
  margin-bottom: 8px;
  font-size: 12px;
  color: var(--text-secondary);
}
.chart-legend .key {
  display: inline-block;
  width: 14px;
  height: 2px;
  border-radius: 1px;
  vertical-align: middle;
  margin-right: 6px;
}

.chart-tooltip {
  position: absolute;
  pointer-events: none;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.12);
  padding: 8px 10px;
  font-size: 12px;
  min-width: 120px;
  z-index: 5;
}
.chart-tooltip .tt-date { color: var(--text-muted); margin-bottom: 4px; }
.chart-tooltip .tt-row { display: flex; align-items: center; gap: 6px; margin-top: 2px; }
.chart-tooltip .tt-key { width: 12px; height: 2px; border-radius: 1px; flex: none; }
.chart-tooltip .tt-value { font-weight: 600; color: var(--text-primary); }
.chart-tooltip .tt-name { color: var(--text-secondary); }

/* ---- tables ---- */

.table-wrap { overflow-x: auto; }

table { width: 100%; border-collapse: collapse; font-size: 13px; }
th {
  text-align: left;
  font-weight: 600;
  color: var(--text-muted);
  font-size: 12px;
  padding: 6px 10px;
  border-bottom: 1px solid var(--grid);
}
td {
  padding: 8px 10px;
  border-bottom: 1px solid var(--grid);
  color: var(--text-secondary);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}
td:first-child { color: var(--text-primary); }
tr:last-child td { border-bottom: none; }

.icon-btn { padding: 4px 10px; font-size: 12px; }

/* ---- food log ---- */

.food-day { margin-bottom: 14px; }
.food-day:last-child { margin-bottom: 0; }
.food-day-title { font-size: 12px; font-weight: 600; color: var(--text-muted); margin: 0 0 6px; }
.food-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 7px 0;
  border-bottom: 1px solid var(--grid);
}
.food-item:last-child { border-bottom: none; }
.food-time { flex: none; font-size: 12px; color: var(--text-muted); font-variant-numeric: tabular-nums; width: 52px; }
.food-desc { flex: 1; color: var(--text-primary); overflow-wrap: anywhere; }

.empty-msg { color: var(--text-muted); font-size: 13px; margin: 8px 0 0; }

/* ---- dialogs ---- */

dialog {
  background: var(--surface);
  color: var(--text-primary);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 20px;
  width: min(420px, calc(100vw - 32px));
}
dialog::backdrop { background: rgba(0, 0, 0, 0.4); }
dialog form { display: flex; flex-direction: column; gap: 12px; }
dialog h2 { margin: 0; }
.dialog-actions { display: flex; gap: 8px; align-items: center; margin-top: 4px; }
.dialog-actions .spacer { flex: 1; }

/* ---- misc ---- */

.disclaimer { font-size: 12px; color: var(--text-muted); text-align: center; padding: 8px 0; }

.toast {
  position: fixed;
  bottom: 20px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--text-primary);
  color: var(--page);
  border-radius: 8px;
  padding: 10px 16px;
  font-size: 13px;
  z-index: 10;
}

.grow { flex: 1; }
