/* Health Assistant PWA — mobile-first, iPhone safe areas, light/dark. */
:root {
  --bg: #f4f6f3;
  --surface: #ffffff;
  --surface-2: #eef1ec;
  --text: #17201a;
  --muted: #5d6b61;
  --line: #dde3dc;
  --accent: #2f7d4f;
  --accent-ink: #ffffff;
  --accent-soft: #e2f1e7;
  --warn: #a15c00;
  --warn-soft: #fff1dc;
  --danger: #b3261e;
  --danger-soft: #fde7e5;
  --radius: 16px;
  --shadow: 0 1px 2px rgba(20, 30, 20, .06), 0 4px 16px rgba(20, 30, 20, .06);
  --tabbar: 64px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1411;
    --surface: #18201b;
    --surface-2: #212b24;
    --text: #e8eee9;
    --muted: #9aa89e;
    --line: #2c3730;
    --accent: #5cc184;
    --accent-ink: #08130c;
    --accent-soft: #1d3326;
    --warn: #f0b35e;
    --warn-soft: #3a2b14;
    --danger: #ff8a80;
    --danger-soft: #3b1a18;
    --shadow: none;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg);
  color: var(--text);
  font: 16px/1.4 -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior-y: contain;
}
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--accent); }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.row { display: flex; align-items: center; gap: 8px; }
.row.between { justify-content: space-between; }
.wrap { flex-wrap: wrap; }
.grow { flex: 1; min-width: 0; }
.center { text-align: center; }

/* Layout */
.app-header {
  position: sticky; top: 0; z-index: 5;
  padding: calc(env(safe-area-inset-top) + 10px) 16px 10px;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: saturate(1.4) blur(12px);
  -webkit-backdrop-filter: saturate(1.4) blur(12px);
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
}
.app-header h1 { font-size: 22px; margin: 0; letter-spacing: -.01em; }
main {
  padding: 4px 16px calc(var(--tabbar) + env(safe-area-inset-bottom) + 96px);
  max-width: 640px; margin: 0 auto;
}
.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 6;
  display: grid; grid-template-columns: repeat(4, 1fr);
  height: calc(var(--tabbar) + env(safe-area-inset-bottom));
  padding-bottom: env(safe-area-inset-bottom);
  background: color-mix(in srgb, var(--surface) 92%, transparent);
  backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px);
  border-top: 1px solid var(--line);
}
.tabbar a {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  text-decoration: none; color: var(--muted); font-size: 11px; font-weight: 500;
}
.tabbar a svg { width: 24px; height: 24px; }
.tabbar a.active { color: var(--accent); }

/* Status chip */
.chip {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 4px 10px; border-radius: 999px; font-size: 12px; font-weight: 600;
  background: var(--surface-2); color: var(--muted);
}
.chip.ok::before, .chip.off::before, .chip.queue::before {
  content: ""; width: 7px; height: 7px; border-radius: 50%; background: currentColor;
}
.chip.ok { color: var(--accent); background: var(--accent-soft); }
.chip.off { color: var(--warn); background: var(--warn-soft); }
.chip.queue { color: var(--warn); background: var(--warn-soft); }

/* Cards */
.card {
  background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 16px; margin: 12px 0;
}
.card h2 { font-size: 17px; margin: 0 0 8px; }
.card h3 { font-size: 15px; margin: 0; }
.banner {
  border-radius: 12px; padding: 12px 14px; margin: 8px 0; font-size: 14px;
  background: var(--warn-soft); color: var(--warn);
}
.banner.danger { background: var(--danger-soft); color: var(--danger); }
.banner .row { margin-top: 8px; }

/* Day summary */
.day-nav { display: flex; align-items: center; justify-content: space-between; margin: 4px 0 8px; }
.day-nav button { width: 40px; height: 40px; }
.day-nav strong { font-size: 17px; }
.summary { display: grid; grid-template-columns: 1.3fr 1fr 1fr 1fr; gap: 8px; align-items: end; }
.metric .value { font-size: 22px; font-weight: 700; letter-spacing: -.02em; }
.metric .label { font-size: 12px; color: var(--muted); }
.metric.big .value { font-size: 30px; color: var(--accent); }

/* Meal list */
.meal-card { display: block; text-decoration: none; color: inherit; }
.meal-card .thumbs { display: flex; gap: 6px; margin-top: 10px; overflow: hidden; }
.thumb {
  width: 56px; height: 56px; border-radius: 10px; object-fit: cover; background: var(--surface-2);
  flex: none;
}
.badge {
  display: inline-block; padding: 2px 8px; border-radius: 999px; font-size: 12px; font-weight: 600;
  background: var(--surface-2); color: var(--muted);
}
.badge.done { background: var(--accent-soft); color: var(--accent); }
.badge.warn { background: var(--warn-soft); color: var(--warn); }
.kcal { font-weight: 700; white-space: nowrap; }

/* Buttons */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 48px; padding: 0 18px; border-radius: 14px; border: 0; cursor: pointer;
  background: var(--surface-2); font-weight: 600; text-decoration: none; color: var(--text);
}
.btn:disabled { opacity: .5; }
.btn.primary { background: var(--accent); color: var(--accent-ink); }
.btn.danger { background: var(--danger-soft); color: var(--danger); }
.btn.block { width: 100%; }
.btn.small { min-height: 36px; padding: 0 12px; border-radius: 10px; font-size: 14px; }
.btn svg { width: 20px; height: 20px; }
.icon-btn {
  border: 0; background: var(--surface-2); border-radius: 12px; width: 44px; height: 44px;
  display: inline-flex; align-items: center; justify-content: center; cursor: pointer;
}
.fab {
  position: fixed; right: 20px; z-index: 7;
  bottom: calc(var(--tabbar) + env(safe-area-inset-bottom) + 18px);
  height: 58px; padding: 0 22px; border-radius: 29px; border: 0;
  background: var(--accent); color: var(--accent-ink); font-weight: 700; font-size: 16px;
  box-shadow: 0 6px 20px rgba(30, 90, 50, .35); display: flex; align-items: center; gap: 8px;
}
.fab svg { width: 22px; height: 22px; }
.actions { display: grid; gap: 10px; margin: 12px 0; }
.actions.two { grid-template-columns: 1fr 1fr; }
.actions.three { grid-template-columns: 1fr 1fr 1fr; }
.actions.three .btn { padding-left: 6px; padding-right: 6px; }

/* Forms */
.field { display: block; margin: 12px 0; }
.field > span { display: block; font-size: 13px; color: var(--muted); margin-bottom: 6px; }
input[type=text], input[type=email], input[type=password], input[type=number], input[type=search], textarea {
  width: 100%; min-height: 48px; padding: 10px 14px; border-radius: 12px;
  border: 1px solid var(--line); background: var(--surface); outline: none; font-size: 17px;
}
input:focus, textarea:focus { border-color: var(--accent); }
.segmented { display: flex; background: var(--surface-2); border-radius: 12px; padding: 3px; gap: 3px; }
.segmented button {
  flex: 1; min-height: 38px; border: 0; border-radius: 9px; background: transparent; font-weight: 600;
  font-size: 14px; cursor: pointer;
}
.segmented button.on { background: var(--surface); box-shadow: var(--shadow); color: var(--accent); }
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chips button {
  border: 1px solid var(--line); background: var(--surface); border-radius: 999px; padding: 8px 14px;
  font-size: 14px; cursor: pointer;
}
.chips button.on { background: var(--accent-soft); border-color: var(--accent); color: var(--accent); }
input[type=range] { width: 100%; accent-color: var(--accent); height: 32px; }

/* Dishes */
.course { padding: 12px 0; border-top: 1px solid var(--line); }
.course:first-child { border-top: 0; }
.course-head { display: flex; justify-content: space-between; font-size: 13px; color: var(--muted); }
.dish { display: flex; gap: 12px; align-items: center; padding: 10px 0; cursor: pointer; }
.dish .name { font-weight: 600; }
.dish .meta { font-size: 13px; color: var(--muted); }
.dish .src { font-size: 11px; }
.spinner {
  width: 18px; height: 18px; border-radius: 50%; border: 2px solid var(--line);
  border-top-color: var(--accent); animation: spin 0.9s linear infinite; flex: none;
}
@keyframes spin { to { transform: rotate(360deg); } }
.photos-strip { display: flex; gap: 8px; overflow-x: auto; padding: 4px 0; }
.photos-strip img { width: 84px; height: 84px; border-radius: 12px; object-fit: cover; }

/* Bottom sheet */
.sheet-backdrop {
  position: fixed; inset: 0; background: rgba(0, 0, 0, .35); z-index: 20;
  display: flex; align-items: flex-end; justify-content: center;
}
.sheet {
  background: var(--surface); width: 100%; max-width: 640px; max-height: 92vh; overflow: auto;
  border-radius: 20px 20px 0 0; padding: 8px 16px calc(env(safe-area-inset-bottom) + 16px);
  animation: up .2s ease-out;
}
.sheet .grabber { width: 40px; height: 5px; border-radius: 3px; background: var(--line); margin: 6px auto 10px; }
.sheet h2 { margin: 4px 0 12px; font-size: 19px; }
@keyframes up { from { transform: translateY(30px); opacity: .6; } }
.list-item {
  display: flex; justify-content: space-between; align-items: center; gap: 12px;
  padding: 12px 0; border-bottom: 1px solid var(--line); cursor: pointer;
}

/* Toast */
.toast {
  position: fixed; left: 50%; transform: translateX(-50%); z-index: 30;
  bottom: calc(var(--tabbar) + env(safe-area-inset-bottom) + 90px);
  background: var(--text); color: var(--bg); padding: 12px 16px; border-radius: 12px;
  font-size: 14px; max-width: calc(100% - 32px); box-shadow: 0 6px 20px rgba(0, 0, 0, .2);
}

/* Charts */
.bars { display: grid; grid-template-columns: repeat(7, 1fr); gap: 8px; align-items: end; height: 150px; }
.bar { display: flex; flex-direction: column; align-items: center; justify-content: flex-end; height: 100%; gap: 4px; }
.bar .fill { width: 100%; border-radius: 8px 8px 4px 4px; background: var(--accent); min-height: 3px; }
.bar .fill.draft { background: repeating-linear-gradient(45deg, var(--accent), var(--accent) 4px, var(--accent-soft) 4px, var(--accent-soft) 8px); }
.bar .d { font-size: 11px; color: var(--muted); }
.bar .v { font-size: 11px; font-weight: 600; }
svg.line { width: 100%; height: 160px; }
svg.line path { fill: none; stroke: var(--accent); stroke-width: 2.5; }
svg.line circle { fill: var(--accent); }
svg.line text { fill: var(--muted); font-size: 10px; }
.meter { height: 10px; background: var(--surface-2); border-radius: 6px; overflow: hidden; }
.meter > div { height: 100%; background: var(--accent); }
.meter.warn > div { background: var(--warn); }
.guide { margin-top: 12px; }
.guide .row { margin-bottom: 6px; }

/* Auth */
.auth { max-width: 420px; margin: 8vh auto 0; padding: 0 20px; }
.auth h1 { font-size: 28px; margin: 0 0 8px; }
.empty { text-align: center; padding: 36px 12px; color: var(--muted); }
.empty svg { width: 56px; height: 56px; color: var(--accent); }

code.token { display: block; word-break: break-all; font-size: 13px; padding: 8px; margin: 8px 0;
  background: var(--surface-2); border-radius: 8px; user-select: all; -webkit-user-select: all; }
details ol { padding-left: 20px; margin: 4px 0 8px; }
details li { margin-bottom: 4px; }
