/* Beyond the Scale — cheerful, phone-first, not clinical. */

:root {
  --bg: #fff7f2;
  --surface: #ffffff;
  --surface-2: #fff1ea;
  --ink: #34222a;
  --ink-soft: #7c6068;
  --line: #f0ddd3;

  --coral: #f2685f;
  --coral-soft: #ffe4e0;
  --teal: #2ba39b;
  --teal-soft: #ddf3f1;
  --plum: #7b5ea7;
  --sun: #f5a623;
  --sun-soft: #fff0d6;

  --radius: 18px;
  --radius-sm: 12px;
  --shadow: 0 2px 10px rgba(120, 70, 60, 0.07);
  --tab-h: 62px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #241a1f;
    --surface: #31242a;
    --surface-2: #3b2c33;
    --ink: #fbeee9;
    --ink-soft: #c0a5ad;
    --line: #46343c;
    --coral-soft: #543037;
    --teal-soft: #1e3f3e;
    --sun-soft: #4a3a22;
    --shadow: 0 2px 10px rgba(0, 0, 0, 0.3);
  }
}

* { box-sizing: border-box; }

/* Several elements here set `display`, which would otherwise beat the `hidden` attribute. */
[hidden] { display: none !important; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 16px/1.45 ui-rounded, "SF Pro Rounded", -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
  -webkit-font-smoothing: antialiased;
  overscroll-behavior-y: none;
}

h1, h2, h3 { margin: 0; font-weight: 700; letter-spacing: -0.01em; }
p { margin: 0 0 0.6rem; }
.muted { color: var(--ink-soft); }
.tiny { font-size: 0.8rem; }

/* ---------------- boot / sign-in ---------------- */

.boot {
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.6rem;
  padding: 2rem;
  text-align: center;
}
.boot-mark { font-size: 3rem; color: var(--coral); }
.boot h1 { font-size: 1.7rem; }
.boot-error { color: var(--coral); max-width: 30rem; }

/* ---------------- chrome ---------------- */

.topbar {
  position: sticky;
  top: 0;
  z-index: 5;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  padding: calc(env(safe-area-inset-top) + 0.7rem) 1rem 0.7rem;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--line);
}
.topbar h1 { font-size: 1.35rem; }
.topbar-right { display: flex; align-items: center; gap: 0.5rem; }

.icon-btn {
  border: 0;
  background: var(--surface);
  color: var(--ink-soft);
  width: 34px;
  height: 34px;
  border-radius: 50%;
  font-size: 1.05rem;
  cursor: pointer;
  box-shadow: var(--shadow);
}

.offline-pill {
  background: var(--sun-soft);
  color: var(--ink);
  border-radius: 999px;
  padding: 0.15rem 0.6rem;
  font-size: 0.75rem;
  font-weight: 600;
}

.view {
  padding: 1rem 1rem calc(var(--tab-h) + env(safe-area-inset-bottom) + 1.5rem);
  max-width: 40rem;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  gap: 0.9rem;
}

.tabs {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 6;
  display: flex;
  justify-content: space-around;
  padding-bottom: env(safe-area-inset-bottom);
  background: color-mix(in srgb, var(--surface) 94%, transparent);
  backdrop-filter: blur(12px);
  border-top: 1px solid var(--line);
}
.tab {
  flex: 1;
  border: 0;
  background: none;
  color: var(--ink-soft);
  font: inherit;
  font-size: 0.65rem;
  font-weight: 600;
  height: var(--tab-h);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
.tab-icon { font-size: 1.15rem; line-height: 1; }
.tab[aria-current="page"] { color: var(--coral); }

@media (min-width: 860px) {
  body { padding-left: 210px; }
  .topbar { padding-left: 1.5rem; }
  .view { padding-bottom: 3rem; max-width: 46rem; }
  .tabs {
    top: 0;
    right: auto;
    width: 210px;
    flex-direction: column;
    justify-content: flex-start;
    padding-top: 4.5rem;
    border-top: 0;
    border-right: 1px solid var(--line);
  }
  .tab {
    flex: 0 0 auto;
    flex-direction: row;
    justify-content: flex-start;
    gap: 0.7rem;
    height: 46px;
    padding: 0 1.5rem;
    font-size: 0.95rem;
  }
  .tab[aria-current="page"] { background: var(--coral-soft); }
}

/* ---------------- cards ---------------- */

.card {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 1rem;
  box-shadow: var(--shadow);
}
.card-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 0.5rem;
  margin-bottom: 0.6rem;
}
.card-head h2 { font-size: 1.02rem; }

/* the two balance cards — the whole point of the home screen */
.balances { display: grid; grid-template-columns: 1fr 1fr; gap: 0.7rem; }
.balance {
  border-radius: var(--radius);
  padding: 1rem 0.9rem;
  text-align: center;
  box-shadow: var(--shadow);
}
.balance.daily { background: var(--coral-soft); }
.balance.weekly { background: var(--teal-soft); }
.balance .label { font-size: 0.72rem; font-weight: 700; text-transform: uppercase; letter-spacing: 0.06em; color: var(--ink-soft); }
.balance .big { font-size: 2.9rem; font-weight: 800; line-height: 1.05; letter-spacing: -0.03em; }
.balance.daily .big { color: var(--coral); }
.balance.weekly .big { color: var(--teal); }
.balance .sub { font-size: 0.82rem; color: var(--ink-soft); }
.balance.over .big { color: var(--sun); }

.progress-track { height: 8px; border-radius: 999px; background: var(--surface-2); overflow: hidden; margin-top: 0.5rem; }
.progress-fill { height: 100%; border-radius: 999px; background: var(--coral); transition: width 0.35s ease; }
.progress-fill.teal { background: var(--teal); }

.stat-strip { display: grid; grid-template-columns: repeat(auto-fit, minmax(74px, 1fr)); gap: 0.5rem; text-align: center; }
.stat .n { font-size: 1.25rem; font-weight: 700; }
.stat .l { font-size: 0.7rem; color: var(--ink-soft); text-transform: uppercase; letter-spacing: 0.04em; }

/* ---------------- meals & lists ---------------- */

.meal + .meal { margin-top: 0.9rem; }
.meal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  padding-bottom: 0.35rem;
}
.meal-head h3 { font-size: 0.95rem; }
.meal-total { font-size: 0.85rem; font-weight: 700; color: var(--ink-soft); }

.entry {
  display: flex;
  align-items: center;
  gap: 0.7rem;
  padding: 0.55rem 0;
  border-top: 1px solid var(--line);
}
.entry:first-of-type { border-top: 0; }
.entry-main { flex: 1; min-width: 0; }
.entry-name { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.entry-sub { font-size: 0.79rem; color: var(--ink-soft); }
.entry-sp {
  min-width: 2.4rem;
  text-align: center;
  font-weight: 800;
  background: var(--surface-2);
  border-radius: 999px;
  padding: 0.15rem 0.5rem;
}
.entry-sp.zero { background: var(--teal-soft); color: var(--teal); }

.empty { color: var(--ink-soft); font-size: 0.9rem; padding: 0.5rem 0; }

.badge { display: inline-block; border-radius: 999px; padding: 0.1rem 0.5rem; font-size: 0.72rem; font-weight: 700; }
.badge.zero { background: var(--teal-soft); color: var(--teal); }
.badge.warn { background: var(--sun-soft); color: #8a5a06; }

/* ---------------- controls ---------------- */

.btn {
  border: 0;
  border-radius: 999px;
  padding: 0.6rem 1.1rem;
  font: inherit;
  font-weight: 600;
  cursor: pointer;
  background: var(--surface-2);
  color: var(--ink);
}
.btn-primary { background: var(--coral); color: #fff; }
.btn-teal { background: var(--teal); color: #fff; }
.btn-ghost { background: none; color: var(--coral); padding: 0.4rem 0.5rem; }
.btn-sm { padding: 0.35rem 0.75rem; font-size: 0.85rem; }
.btn-block { width: 100%; }
.btn:disabled { opacity: 0.5; cursor: default; }

.row { display: flex; gap: 0.5rem; align-items: center; flex-wrap: wrap; }
.row-end { justify-content: flex-end; }
.grow { flex: 1; }

label.field { display: block; margin-bottom: 0.7rem; }
label.field > span { display: block; font-size: 0.78rem; font-weight: 600; color: var(--ink-soft); margin-bottom: 0.2rem; }
input, select, textarea {
  width: 100%;
  font: inherit;
  color: var(--ink);
  background: var(--surface-2);
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  padding: 0.6rem 0.7rem;
}
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--coral); }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 0.6rem; }

/* ---------------- sheet & toast ---------------- */

.sheet {
  border: 0;
  padding: 0;
  background: transparent;
  width: min(34rem, 100%);
  max-height: 92dvh;
  margin: auto auto 0;
}
.sheet::backdrop { background: rgba(52, 34, 42, 0.45); }
.sheet-body {
  background: var(--surface);
  border-radius: var(--radius) var(--radius) 0 0;
  padding: 1.1rem 1.1rem calc(1.1rem + env(safe-area-inset-bottom));
  max-height: 92dvh;
  overflow-y: auto;
}
@media (min-width: 860px) {
  .sheet { margin: auto; }
  .sheet-body { border-radius: var(--radius); }
}
.sheet-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 0.8rem; }
.sheet-head h2 { font-size: 1.1rem; }

.toast {
  position: fixed;
  left: 50%;
  transform: translateX(-50%);
  bottom: calc(var(--tab-h) + env(safe-area-inset-bottom) + 1rem);
  z-index: 20;
  background: var(--ink);
  color: var(--bg);
  padding: 0.6rem 1rem;
  border-radius: 999px;
  font-size: 0.9rem;
  font-weight: 600;
  box-shadow: var(--shadow);
}

/* ---------------- charms ---------------- */

.charm-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(96px, 1fr)); gap: 0.8rem; }
.charm { text-align: center; cursor: pointer; border: 0; background: none; font: inherit; color: inherit; padding: 0; }
.charm svg { width: 100%; height: auto; aspect-ratio: 1; }
.charm .cap { font-size: 0.75rem; font-weight: 700; margin-top: 0.2rem; }
.charm.locked svg { filter: grayscale(1) opacity(0.28); }
.charm.locked .cap { color: var(--ink-soft); font-weight: 600; }

@keyframes pop { 0% { transform: scale(0.6); opacity: 0; } 60% { transform: scale(1.08); } 100% { transform: scale(1); opacity: 1; } }
.charm.just-earned svg { animation: pop 0.5s ease-out; }

/* ---------------- doctor report ---------------- */

/* The report body is always black-on-white, on screen and on paper, so what you preview is
   exactly what the printer gets. */
.report {
  background: #fff;
  color: #222;
  border-radius: var(--radius);
  padding: 1.2rem;
  box-shadow: var(--shadow);
}
.report-head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 1rem;
  flex-wrap: wrap;
  border-bottom: 2px solid #222;
  padding-bottom: 0.6rem;
}
.report-title { font-size: 1.25rem; color: #222; }
.report-sub { color: #777; font-size: 0.8rem; margin: 0.15rem 0 0; }

.report-sec { margin-top: 1.1rem; break-inside: avoid; }
.report-sec h3 {
  font-size: 1rem;
  color: #222;
  border-bottom: 1px solid #ddd;
  padding-bottom: 0.25rem;
  margin-bottom: 0.6rem;
}

.report-stats { display: flex; flex-wrap: wrap; gap: 0.4rem 1.6rem; margin-bottom: 0.6rem; }
.report-stat .n { font-size: 1.15rem; font-weight: 700; color: #222; }
.report-stat .l { font-size: 0.7rem; color: #777; text-transform: uppercase; letter-spacing: 0.03em; }

.report-chart { width: 100%; height: auto; margin: 0.3rem 0; }

.report-table { width: 100%; border-collapse: collapse; font-size: 0.8rem; margin-top: 0.4rem; }
.report-table th {
  text-align: left;
  font-size: 0.68rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: #777;
  border-bottom: 1px solid #bbb;
  padding: 0.25rem 0.5rem 0.25rem 0;
}
.report-table td { border-bottom: 1px solid #eee; padding: 0.3rem 0.5rem 0.3rem 0; vertical-align: top; color: #222; }
.report-ctx { color: #777; font-size: 0.72rem; }
.report-empty { color: #777; font-size: 0.85rem; }
.report-foot { color: #999; font-size: 0.7rem; margin-top: 1.2rem; }

.report-legend { display: flex; flex-wrap: wrap; gap: 0.9rem; font-size: 0.75rem; color: #555; margin-bottom: 0.4rem; }
.report-key { display: inline-flex; align-items: center; gap: 0.3rem; }
.report-dot { width: 9px; height: 9px; border-radius: 50%; display: inline-block; }

@media print {
  .topbar, .tabs, .no-print, .toast, .sheet { display: none !important; }
  body { background: #fff; padding: 0; }
  .view { padding: 0; max-width: none; display: block; }
  .report { box-shadow: none; border-radius: 0; padding: 0; }
  @page { margin: 1.6cm; }
}

/* ---------------- weight graph ---------------- */

.graph { width: 100%; height: auto; overflow: visible; }
.graph .line { fill: none; stroke: var(--coral); stroke-width: 2.5; stroke-linejoin: round; stroke-linecap: round; }
.graph .area { fill: var(--coral); opacity: 0.1; }
.graph .dot { fill: var(--surface); stroke: var(--coral); stroke-width: 2; }
.graph .goal { stroke: var(--teal); stroke-width: 1.5; stroke-dasharray: 4 4; }
.graph .lbl { fill: var(--ink-soft); font-size: 9px; }
