/* Palette roles come from the data-viz reference instance; both modes are
   selected steps, not an automatic flip. */
.viz-root {
  color-scheme: light;
  --surface-0: #f4f4f2;
  --surface-1: #fcfcfb;
  --border:    #e0dfda;
  --text-primary:   #0b0b0b;
  --text-secondary: #52514e;
  --text-muted:     #78776f;
  --series-trend: #2a78d6;
  --series-raw:   #9a9990;
  --series-lean:  #2a78d6;
  --series-fat:   #eb6834;
  --accent-ink:   #ffffff;
  --danger: #c0322f;
}
@media (prefers-color-scheme: dark) {
  .viz-root {
    color-scheme: dark;
    --surface-0: #121211;
    --surface-1: #1a1a19;
    --border:    #33322f;
    --text-primary:   #ffffff;
    --text-secondary: #c3c2b7;
    --text-muted:     #97968c;
    --series-trend: #3987e5;
    --series-raw:   #7d7c74;
    --series-lean:  #3987e5;
    --series-fat:   #d95926;
    --accent-ink:   #ffffff;
    --danger: #e66767;
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--surface-0);
  color: var(--text-primary);
  font-family: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  /* 17px base: this is read at arm's length on a phone, often first thing in
     the morning. Secondary text below steps down to 15px, never past 13px. */
  font-size: 17px;
  line-height: 1.5;
  -webkit-text-size-adjust: 100%;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}

.view { max-width: 46rem; margin: 0 auto; padding: 1rem; }
.visually-hidden {
  position: absolute; width: 1px; height: 1px; overflow: hidden;
  clip: rect(0 0 0 0); clip-path: inset(50%); white-space: nowrap;
}

/* ---------- sign in ---------- */
.auth-card {
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 1.5rem;
  margin-top: 2rem;
}
.brand { font-size: 1.9rem; margin: 0; letter-spacing: -0.02em; }
.brand-sub { margin: 0.25rem 0 1.5rem; color: var(--text-secondary); font-size: 1rem; }
.profiles { margin-bottom: 1.5rem; }
.profile-buttons { display: flex; flex-wrap: wrap; gap: 0.5rem; margin-top: 0.5rem; }
.profile-chip {
  font: inherit; font-size: 1rem;
  padding: 0.6rem 1rem;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--surface-0);
  color: var(--text-primary);
  cursor: pointer;
  min-height: 44px;
}
.profile-chip:hover { border-color: var(--series-trend); }

.auth-copy { color: var(--text-secondary); font-size: 1rem; margin: 0 0 1.25rem; }
.button.discord {
  width: 100%;
  display: inline-flex; align-items: center; justify-content: center; gap: 0.6rem;
  background: #5865f2; border-color: #5865f2; color: #fff;
  min-height: 52px; font-size: 1.05rem;
}
.button.discord:hover { filter: brightness(1.08); }
.button.discord svg { width: 22px; height: 17px; flex: none; }
/* Sign-in outcomes are the only thing on this screen, so they read at body size. */
.auth-note { margin: 1rem 0 0; font-size: 1rem; color: var(--text-secondary); }
.auth-note.is-error { color: var(--danger); }

.form { display: grid; gap: 1rem; }
.field { display: grid; gap: 0.35rem; }
.field-label { font-size: 0.95rem; color: var(--text-secondary); font-weight: 600; }
.field-hint  { font-size: 0.875rem; color: var(--text-muted); }
input {
  font: inherit;
  font-size: 1rem;
  padding: 0.7rem 0.8rem;
  min-height: 46px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--surface-0);
  color: var(--text-primary);
  width: 100%;
}
input:focus-visible, button:focus-visible, summary:focus-visible {
  outline: 2px solid var(--series-trend);
  outline-offset: 2px;
}

.button {
  font: inherit; font-size: 1rem; font-weight: 600;
  padding: 0.7rem 1.1rem;
  min-height: 46px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--surface-0);
  color: var(--text-primary);
  cursor: pointer;
}
.button:hover { border-color: var(--text-muted); }
.button.primary { background: var(--series-trend); border-color: var(--series-trend); color: var(--accent-ink); }
.button.primary:hover { filter: brightness(1.08); }
.button.ghost { background: transparent; }
.button.link {
  background: none; border: none; color: var(--series-trend);
  padding: 0.5rem 0; text-decoration: underline; margin-top: 1rem; font-size: 0.95rem;
}
.button[disabled] { opacity: 0.55; cursor: default; }

.error { color: var(--danger); font-size: 0.95rem; margin: 0; }
.muted { color: var(--text-secondary); font-size: 0.95rem; }
.empty { color: var(--text-muted); font-size: 0.95rem; margin: 0.5rem 0 0; }

/* ---------- dashboard ---------- */
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  gap: 1rem; padding: 0.5rem 0 1.25rem;
}
.topbar-eyebrow { margin: 0; font-size: 0.875rem; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.06em; }
.topbar-name { margin: 0; font-size: 1.35rem; }

.stack { display: grid; gap: 1rem; }
.card {
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 1.25rem;
}
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 0.75rem; flex-wrap: wrap; }
.card-title { margin: 0 0 0.75rem; font-size: 1.05rem; color: var(--text-secondary); font-weight: 600; }
.card-head .card-title { margin-bottom: 0; }

/* The headline number stays in text ink, with an arrow carrying direction.
   Weight going down is not universally "good", so no red/green verdict. */
.hero-number { margin: 0.25rem 0 0.35rem; font-size: 2.75rem; font-weight: 700; letter-spacing: -0.03em; line-height: 1.1; }
.hero-detail { margin: 0 0 1rem; color: var(--text-secondary); font-size: 0.95rem; }
.hero-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 0.75rem; margin: 0; padding-top: 1rem; border-top: 1px solid var(--border); }
.hero-grid div { min-width: 0; }
.hero-grid dt { font-size: 0.875rem; color: var(--text-muted); margin-bottom: 0.15rem; }
.hero-grid dd { margin: 0; font-size: 1.15rem; font-weight: 600; }

.range { display: flex; gap: 0.35rem; }
.chip {
  font: inherit; font-size: 0.9rem; font-weight: 600;
  padding: 0.45rem 0.8rem; min-height: 40px;
  border-radius: 999px; border: 1px solid var(--border);
  background: transparent; color: var(--text-secondary); cursor: pointer;
}
.chip.is-active { background: var(--series-trend); border-color: var(--series-trend); color: var(--accent-ink); }

.legend { display: flex; gap: 1rem; margin: 0.75rem 0 0.25rem; font-size: 0.9rem; color: var(--text-secondary); }
.legend-item { display: inline-flex; align-items: center; gap: 0.4rem; }
.swatch { width: 14px; height: 3px; border-radius: 2px; display: inline-block; }
.swatch-trend { background: var(--series-trend); }
.swatch-raw { background: var(--series-raw); height: 9px; width: 9px; border-radius: 50%; }

.chart-wrap { position: relative; width: 100%; }
#chart { width: 100%; height: 240px; display: block; touch-action: pan-y; }
.grid-line { stroke: var(--border); stroke-width: 1; }
.axis-text { fill: var(--text-muted); font-size: 13px; }
.trend-line { fill: none; stroke: var(--series-trend); stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.raw-dot { fill: var(--series-raw); stroke: var(--surface-1); stroke-width: 2; }
.crosshair { stroke: var(--text-muted); stroke-width: 1; stroke-dasharray: 3 3; }
.focus-dot { fill: var(--series-trend); stroke: var(--surface-1); stroke-width: 2; }
.end-label { fill: var(--text-primary); font-size: 14px; font-weight: 700; }

.tooltip {
  position: absolute; pointer-events: none;
  background: var(--surface-0); border: 1px solid var(--border);
  border-radius: 10px; padding: 0.5rem 0.7rem;
  font-size: 0.9rem; line-height: 1.35; color: var(--text-primary);
  box-shadow: 0 6px 20px rgb(0 0 0 / 0.16);
  white-space: nowrap; transform: translate(-50%, -115%); z-index: 5;
}
.tooltip b { display: block; font-size: 0.95rem; }
.tooltip span { color: var(--text-secondary); }

.table-toggle { margin-top: 1rem; }
.table-toggle summary { cursor: pointer; color: var(--text-secondary); font-size: 0.95rem; padding: 0.35rem 0; }
.table-scroll { max-height: 15rem; overflow: auto; margin-top: 0.5rem; }
table { border-collapse: collapse; width: 100%; font-size: 0.95rem; }
th, td { text-align: left; padding: 0.45rem 0.5rem; border-bottom: 1px solid var(--border); }
th { color: var(--text-secondary); font-size: 0.9rem; position: sticky; top: 0; background: var(--surface-1); }

.weight-form { display: grid; gap: 0.9rem; grid-template-columns: 1fr; }
@media (min-width: 30rem) {
  .weight-form { grid-template-columns: 1fr 1.3fr auto; align-items: end; }
}
.row-actions { display: flex; gap: 0.5rem; flex-wrap: wrap; margin-top: 0.75rem; }

.card-meta { font-size: 0.95rem; color: var(--text-muted); }

/* Fat and lean are parts of one whole, so they share one bar rather than
   becoming two numbers the reader has to add up. */
.split { display: flex; width: 100%; height: 46px; margin: 0.5rem 0 0.25rem; border-radius: 10px; overflow: hidden; gap: 2px; }
.split-lean, .split-fat { display: flex; align-items: center; justify-content: center; min-width: 0; }
.split-lean { background: var(--series-lean); }
.split-fat  { background: var(--series-fat); }
.split span { font-size: 0.95rem; font-weight: 700; color: #fff; padding: 0 0.4rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.swatch-lean { background: var(--series-lean); }
.swatch-fat  { background: var(--series-fat); }

.tiles { display: grid; grid-template-columns: repeat(2, 1fr); gap: 1rem 0.75rem; margin: 1.25rem 0 0; padding-top: 1.25rem; border-top: 1px solid var(--border); }
@media (min-width: 30rem) { .tiles { grid-template-columns: repeat(3, 1fr); } }
.tiles div { min-width: 0; }
.tiles dt { font-size: 0.9rem; color: var(--text-muted); margin-bottom: 0.15rem; }
.tiles dd { margin: 0; font-size: 1.25rem; font-weight: 600; }

.import-controls { display: grid; gap: 0.9rem; margin-bottom: 0.9rem; }
@media (min-width: 30rem) { .card-meta { font-size: 0.95rem; color: var(--text-muted); }

/* Fat and lean are parts of one whole, so they share one bar rather than
   becoming two numbers the reader has to add up. */
.split { display: flex; width: 100%; height: 46px; margin: 0.5rem 0 0.25rem; border-radius: 10px; overflow: hidden; gap: 2px; }
.split-lean, .split-fat { display: flex; align-items: center; justify-content: center; min-width: 0; }
.split-lean { background: var(--series-lean); }
.split-fat  { background: var(--series-fat); }
.split span { font-size: 0.95rem; font-weight: 700; color: #fff; padding: 0 0.4rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.swatch-lean { background: var(--series-lean); }
.swatch-fat  { background: var(--series-fat); }

.tiles { display: grid; grid-template-columns: repeat(2, 1fr); gap: 1rem 0.75rem; margin: 1.25rem 0 0; padding-top: 1.25rem; border-top: 1px solid var(--border); }
@media (min-width: 30rem) { .tiles { grid-template-columns: repeat(3, 1fr); } }
.tiles div { min-width: 0; }
.tiles dt { font-size: 0.9rem; color: var(--text-muted); margin-bottom: 0.15rem; }
.tiles dd { margin: 0; font-size: 1.25rem; font-weight: 600; }

.import-controls { grid-template-columns: 1fr auto; align-items: end; } }
select {
  font: inherit; font-size: 1rem;
  padding: 0.7rem 0.8rem; min-height: 46px;
  border-radius: 10px; border: 1px solid var(--border);
  background: var(--surface-0); color: var(--text-primary); width: 100%;
}
input[type="file"] { padding: 0.55rem 0.6rem; }
input[type="file"]::file-selector-button {
  font: inherit; font-size: 0.95rem; font-weight: 600;
  margin-right: 0.7rem; padding: 0.4rem 0.8rem;
  border-radius: 8px; border: 1px solid var(--border);
  background: var(--surface-1); color: var(--text-primary); cursor: pointer;
}
.import-status { margin: 0.75rem 0 0; font-size: 0.95rem; color: var(--text-secondary); }
.import-status.is-error { color: var(--danger); }

.recent { list-style: none; margin: 0; padding: 0; display: grid; gap: 0.15rem; }
.recent li { display: flex; align-items: center; justify-content: space-between; gap: 0.75rem; padding: 0.6rem 0; border-bottom: 1px solid var(--border); }
.recent li:last-child { border-bottom: none; }
.recent-kg { font-size: 1.05rem; font-weight: 600; }
.recent-meta { font-size: 0.9rem; color: var(--text-muted); }
.source-tag { font-size: 0.85rem; text-transform: uppercase; letter-spacing: 0.05em; color: var(--text-muted); border: 1px solid var(--border); border-radius: 999px; padding: 0.1rem 0.45rem; margin-left: 0.4rem; }
.delete-weight {
  font: inherit; font-size: 0.9rem; background: none; border: none;
  color: var(--text-muted); cursor: pointer; padding: 0.5rem; min-height: 40px;
}
.delete-weight:hover { color: var(--danger); }
