/* Apricut — ported from mockups/apricut-mockup.html and reworked per phone
   testing feedback: no horizontal scroll, iOS-safe bottom nav, tile dashboard
   for the latest day, clearer timeline cells. */

:root {
  --bg: #fff6ec;
  --card: #ffffff;
  --ink: #211a2c;
  --ink-soft: #6b6478;
  --line: #f0e2d8;
  --brand: #ff6a3d;
  --brand2: #ffb020;
  --brand-dark: #e14f26;
  --good: #12b76a;
  --good-bg: #e7f8ef;
  --good-ink: #0a8a52;
  --bad: #f0453d;
  --bad-bg: #ffe9e6;
  --bad-ink: #c81e13;
  --amber-bg: #fff3d9;
  --amber-ink: #b9790a;
  --muted: #9a92a8;
  --muted-bg: #f2eef5;
  --chip-bg: #fdeee0;
  --purple: #7c4dff;
  --grad-brand: linear-gradient(135deg, var(--brand), var(--brand2));
}

* { box-sizing: border-box; }

/* Interactive controls built as <button> keep their custom look but gain native
   keyboard access; reset the UA button chrome. */
button.choice, button.subtab, button.sort-chip {
  font: inherit; -webkit-appearance: none; appearance: none;
}
/* Visible focus ring for keyboard users (accessibility). */
button:focus-visible, [role="button"]:focus-visible, a:focus-visible, input:focus-visible {
  outline: 2px solid var(--brand-dark); outline-offset: 2px;
}

/* Horizontal scroll is allowed so nothing is ever unreachable if some element
   ends up wider than the viewport (still hunting the offender on-device via the
   ?diag banner). App background on html too so any bounce shows the app colour. */
html { background: var(--bg); }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: linear-gradient(180deg, #fff9f2 0%, var(--bg) 100%);
  color: var(--ink);
  min-height: 100vh;
  min-height: 100dvh;
}

.hidden { display: none !important; }

/* The page scrolls normally (so Safari's toolbar auto-hides and reveals the
   nav). Bottom padding clears the fixed nav + home indicator — sized to the
   nav's actual height so there's no empty gap below it. */
.screen {
  width: 100%;
  max-width: 480px;
  margin: 0 auto;
  padding: 12px 16px calc(74px + env(safe-area-inset-bottom));
}

/* Chart canvas must never force the layout wider than its container (a likely
   iOS overflow cause). */
canvas { max-width: 100%; }

/* ============ Titles (#3) ============ */
.top-row { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; }
.title-block { min-width: 0; }
h1.page-title { font-size: 24px; margin: 4px 0 2px; font-weight: 800; letter-spacing: -0.01em; }
.page-title .title-accent { color: var(--brand-dark); }
.page-sub {
  display: inline-block; font-size: 12px; font-weight: 700; color: var(--brand-dark);
  background: var(--chip-bg); border: 1px solid #ffd9b8; padding: 2px 10px;
  border-radius: 999px; margin: 2px 0 16px;
}
.page-note { font-size: 13px; color: var(--ink-soft); margin: 0 0 16px; }
.signout {
  flex: 0 0 auto; font-size: 12px; color: var(--muted); cursor: pointer;
  text-decoration: underline; background: none; border: none; font-family: inherit; padding: 4px 0;
}
.section-title { font-size: 14px; font-weight: 700; margin: 20px 0 10px; color: var(--ink); }

/* ============ Cards & forms ============ */
.card { background: var(--card); border: 1px solid var(--line); border-radius: 16px; padding: 16px; margin-bottom: 14px; }
label { display: block; font-size: 12px; font-weight: 600; color: var(--ink-soft); margin-bottom: 6px; }
input[type="text"], input[type="email"], input[type="number"], input[type="date"] {
  width: 100%; min-width: 0; border: 1px solid var(--line); background: #fbfaf7; border-radius: 10px;
  padding: 11px 12px; font-size: 15px; color: var(--ink); margin-bottom: 14px; font-family: inherit;
}
/* iOS renders native date controls with a wide intrinsic size that ignores
   width:100% and overlaps the next field — appearance:none makes it a normal
   box that respects its column. */
input[type="date"] { -webkit-appearance: none; appearance: none; text-align: left; }
.field-row { display: flex; gap: 10px; }
.field-row > div { flex: 1 1 0; min-width: 0; }
.choice-group { display: flex; gap: 8px; margin-bottom: 14px; }
.choice {
  flex: 1; text-align: center; padding: 10px 4px; border-radius: 10px; border: 1px solid var(--line);
  background: #fbfaf7; font-size: 13px; font-weight: 600; color: var(--ink-soft); cursor: pointer; user-select: none;
}
.choice.selected { background: var(--grad-brand); border-color: var(--brand); color: #fff; box-shadow: 0 4px 10px rgba(255, 106, 61, .35); }
.tri-toggle { display: flex; gap: 8px; margin-bottom: 14px; }
.tri-toggle .choice.selected.yes { background: var(--good); border-color: var(--good); color: #fff; }
.tri-toggle .choice.selected.no { background: var(--bad); border-color: var(--bad); color: #fff; }
/* Empty third slot for Yes/No toggles — keeps them aligned with the 3-column
   Diet/Steps rows; leaving both unpicked means "not logged". */
.choice-spacer { flex: 1; }

.btn-primary {
  width: 100%; background: var(--grad-brand); color: #fff; border: none; border-radius: 12px;
  padding: 13px; font-size: 15px; font-weight: 700; cursor: pointer;
  box-shadow: 0 6px 16px rgba(255, 106, 61, .4); font-family: inherit;
}
.btn-primary:active { filter: brightness(0.92); }
.btn-primary:disabled { opacity: .6; cursor: default; }
.save-note { font-size: 12px; color: var(--good-ink); text-align: center; margin-top: 10px; }
.link-btn { background: none; border: none; color: var(--brand-dark); font-weight: 700; font-size: 13px; cursor: pointer; text-decoration: underline; padding: 0; font-family: inherit; }

/* Google sign-in button + "or" divider */
.btn-google {
  width: 100%; background: #fff; color: var(--ink); border: 1px solid var(--line);
  border-radius: 12px; padding: 12px; font-size: 15px; font-weight: 700; cursor: pointer;
  font-family: inherit; display: flex; align-items: center; justify-content: center; gap: 10px;
}
.btn-google:active { background: #f6f3ef; }
.btn-google:disabled { opacity: .6; cursor: default; }
.g-logo {
  font-weight: 800; font-size: 16px; color: #4285f4;
  font-family: Arial, sans-serif; line-height: 1;
}
.or-divider { display: flex; align-items: center; gap: 10px; color: var(--muted); font-size: 12px; margin: 14px 0; }
.or-divider::before, .or-divider::after { content: ''; flex: 1; height: 1px; background: var(--line); }
.cooldown { font-size: 12px; color: var(--muted); text-align: center; margin-top: 10px; }
.banner { background: #fdf1e6; border: 1px solid #f2d6b8; color: #7a4a1c; font-size: 12px; padding: 10px 12px; border-radius: 10px; margin-bottom: 14px; }
.center-empty { text-align: center; padding: 48px 20px; color: var(--muted); font-size: 13px; }

/* ============ Day hero — latest-day tile dashboard (#4, #5) ============ */
.day-hero { background: var(--card); border: 1px solid var(--line); border-radius: 18px; padding: 16px; margin-bottom: 12px; }
.day-hero-head { display: flex; align-items: baseline; justify-content: space-between; gap: 10px; margin-bottom: 12px; }
.day-hero-label { font-size: 16px; font-weight: 800; }
.day-hero-label .day-date { color: var(--muted); font-weight: 600; font-size: 13px; margin-left: 6px; }
.day-hero-edit { font-size: 12px; }
.hero-weight-row { display: flex; align-items: baseline; gap: 6px; margin-bottom: 4px; }
.hero-weight { font-size: 36px; font-weight: 800; line-height: 1; letter-spacing: -0.02em; }
.hero-weight-unit { font-size: 15px; font-weight: 700; color: var(--ink-soft); }
.hero-weight-none { font-size: 20px; font-weight: 700; color: var(--muted); }
/* minmax(0,1fr) lets the 4 columns shrink below their content instead of
   forcing the grid (and page) wider — a common silent overflow cause. */
.tile-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 8px; margin-top: 12px; }
.tile { border-radius: 12px; padding: 9px 6px; text-align: center; border: 1px solid transparent; }
.tile-label { font-size: 9.5px; font-weight: 700; text-transform: uppercase; letter-spacing: .04em; opacity: .8; }
.tile-value { font-size: 14px; font-weight: 800; margin-top: 3px; }
.tile.good { background: var(--good-bg); color: var(--good-ink); }
.tile.amber { background: var(--amber-bg); color: var(--amber-ink); }
.tile.bad { background: var(--bad-bg); color: var(--bad-ink); }
.tile.muted { background: var(--muted-bg); color: var(--muted); }
.kcal-toggle {
  display: flex; align-items: center; gap: 6px; margin-top: 12px; cursor: pointer;
  font-size: 13px; font-weight: 700; color: var(--ink-soft); background: #fbfaf7;
  border: 1px solid var(--line); border-radius: 10px; padding: 9px 12px; width: 100%; font-family: inherit;
}
.kcal-toggle .kcal-value { margin-left: auto; color: var(--ink); }
.hero-log-btn { margin-top: 6px; }

/* ============ Timeline table (#8, #9, #10) ============ */
.stat-strip { display: flex; gap: 8px; margin-bottom: 14px; flex-wrap: wrap; }
.stat-chip { font-size: 11.5px; font-weight: 600; color: var(--brand-dark); background: var(--chip-bg); padding: 6px 10px; border-radius: 8px; border: 1px solid #ffd9b8; }
.table-scroll { overflow-x: auto; -webkit-overflow-scrolling: touch; touch-action: pan-x pan-y pinch-zoom; }
table.timeline { width: 100%; border-collapse: separate; border-spacing: 0 4px; font-size: 12px; }
table.timeline th { text-align: center; color: var(--muted); font-weight: 600; padding: 4px 6px; font-size: 11px; }
table.timeline th:first-child { text-align: left; }
table.timeline td { padding: 8px 6px; color: var(--ink); text-align: center; background: #fbfaf7; }
table.timeline td:first-child { text-align: left; font-weight: 600; border-radius: 8px 0 0 8px; white-space: nowrap; }
table.timeline td:last-child { border-radius: 0 8px 8px 0; }
/* #9 — status cells are full-cell tinted, not floating pills */
.cell-good { background: var(--good-bg) !important; color: var(--good-ink); font-weight: 800; }
.cell-amber { background: var(--amber-bg) !important; color: var(--amber-ink); font-weight: 800; }
.cell-bad { background: var(--bad-bg) !important; color: var(--bad-ink); font-weight: 800; }
.num { font-variant-numeric: tabular-nums; }
.dash { color: var(--muted); }
.row-actions { display: flex; gap: 6px; justify-content: center; }
.icon-btn { border: 1px solid var(--line); background: #fff; border-radius: 6px; width: 26px; height: 26px; font-size: 12px; cursor: pointer; color: var(--ink-soft); }

/* ============ Chart ============ */
.chart-card { padding: 12px 14px 6px; }
.chart-wrap { position: relative; height: 168px; }

/* ============ My Log entry form (behind "Log today"/edit) ============ */
.log-entry-form { background: var(--card); border: 1px solid var(--line); border-radius: 16px; padding: 16px; margin-bottom: 14px; }
.log-entry-form .form-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 12px; }
.log-entry-form .form-head b { font-size: 15px; }

/* ============ Browse (#11, #12, #13) ============ */
.participant-item { display: flex; align-items: center; gap: 12px; background: var(--card); border: 1px solid var(--line); border-radius: 14px; padding: 13px 14px; margin-bottom: 10px; cursor: pointer; }
.avatar { width: 36px; height: 36px; border-radius: 50%; display: flex; align-items: center; justify-content: center; font-weight: 700; font-size: 13px; color: #fff; flex: 0 0 auto; box-shadow: 0 3px 8px rgba(0, 0, 0, .15); }
.p-main { flex: 1 1 auto; min-width: 0; }
.p-name { font-size: 14px; font-weight: 700; }
.p-sub { font-size: 11px; color: var(--muted); }
.p-metrics { display: flex; align-items: center; gap: 12px; flex: 0 0 auto; }
.p-delta { font-size: 12px; font-weight: 800; }
.p-delta.down { color: var(--good-ink); }
.p-delta.up { color: var(--bad-ink); }
.p-delta.flat { color: var(--muted); }
.p-weight { font-weight: 800; font-size: 15px; min-width: 62px; text-align: right; }
.chev { color: var(--muted); font-size: 18px; flex: 0 0 auto; }
.self-tag { font-size: 10px; background: var(--grad-brand); color: #fff; font-weight: 700; padding: 2px 8px; border-radius: 6px; margin-left: 6px; }
.subtabs { display: flex; gap: 6px; margin-bottom: 14px; }
.subtab { flex: 1; text-align: center; padding: 9px 4px; border-radius: 10px; border: 1px solid var(--line); background: var(--card); font-size: 12.5px; font-weight: 600; color: var(--ink-soft); cursor: pointer; }
.subtab.active { background: var(--grad-brand); color: #fff; border-color: var(--brand); }

/* ============ KPI dashboard ============ */
.kpi-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-bottom: 8px; }
.kpi-grid.kpi-grid-wide { grid-template-columns: 1fr; }
.kpi-card { background: var(--card); border: 1px solid var(--line); border-left: 4px solid var(--purple); border-radius: 12px; padding: 10px 12px; }
.kpi-card.tone-good { border-color: #cfe4d4; border-left-color: var(--good); background: #f2fcf6; }
.kpi-card.tone-bad { border-color: #f0d3c4; border-left-color: var(--bad); background: #fff5f4; }
.kpi-label { font-size: 10.5px; color: var(--ink-soft); font-weight: 600; margin-bottom: 4px; }
.kpi-value { font-size: 16px; font-weight: 700; color: var(--ink); }
.kpi-sub { font-size: 10.5px; color: var(--muted); margin-top: 2px; }
.kpi-arrow.down { color: var(--good); font-weight: 800; }
.kpi-arrow.up { color: var(--bad); font-weight: 800; }

/* ============ Summary (#14, #15) ============ */
.summary-table { width: 100%; border-collapse: collapse; font-size: 12px; }
.summary-table th { text-align: left; color: var(--muted); font-weight: 600; padding: 6px 4px; border-bottom: 1px solid var(--line); font-size: 10.5px; }
.summary-table td { padding: 9px 4px; border-bottom: 1px solid var(--line); }
.summary-table tr:last-child td { border-bottom: none; }
.sort-row { display: flex; gap: 8px; margin-bottom: 12px; }
.sort-chip { font-size: 12px; font-weight: 600; padding: 7px 12px; border-radius: 20px; border: 1px solid var(--line); background: var(--card); color: var(--ink-soft); cursor: pointer; }
.sort-chip.active { background: var(--grad-brand); color: #fff; border-color: var(--brand); }
.badge { display: inline-block; font-size: 10px; font-weight: 700; padding: 2px 6px; border-radius: 6px; }
.badge.good { background: var(--good-bg); color: var(--good-ink); }
.badge.bad { background: var(--bad-bg); color: var(--bad-ink); }
.badge.muted { background: var(--chip-bg); color: var(--muted); }
.info-note { background: #eef4ff; border: 1px solid #d4e0f7; color: #3a4a6b; font-size: 12px; padding: 10px 12px; border-radius: 10px; margin-bottom: 12px; }

/* Install ("Add to Home Screen") card on the login screen. */
.install-card { border-color: #ffd9b8; background: #fffaf3; margin-top: 16px; }
.install-steps { font-size: 13px; color: var(--ink); line-height: 1.5; margin: 0; }

/* Offline banner — fixed at the top, clears the notch. */
.offline-banner {
  position: fixed; top: 0; left: 0; right: 0; z-index: 50;
  background: var(--ink); color: #fff; text-align: center;
  font-size: 12px; font-weight: 600;
  padding: calc(6px + env(safe-area-inset-top)) 10px 6px;
}
/* Push content clear of the fixed banner while offline. */
body.is-offline .screen { padding-top: calc(40px + env(safe-area-inset-top)); }

/* ============ Bottom nav — fixed, centered, clearing the home indicator.
   For a fully chrome-free experience, add the app to the Home Screen (it runs
   standalone with no Safari toolbar). ============ */
.nav {
  position: fixed; bottom: 0; left: 50%; transform: translateX(-50%);
  width: 100%; max-width: 480px; z-index: 10;
  background: var(--card); border-top: 1px solid var(--line);
  display: flex; padding: 8px 6px calc(10px + env(safe-area-inset-bottom));
}
.nav-item { flex: 1; text-align: center; font-size: 11px; font-weight: 600; color: var(--muted); padding: 6px 0; cursor: pointer; border-radius: 10px; text-decoration: none; }
.nav-item.active { color: #fff; background: var(--grad-brand); box-shadow: 0 4px 12px rgba(255, 106, 61, .35); }
.nav-icon { display: block; font-size: 17px; margin-bottom: 2px; }
