/* กินดี AI — mobile-first styles */

@font-face {
  font-family: 'Noto Sans Thai';
  font-style: normal;
  font-weight: 400 700;
  font-display: swap;
  src: url('../fonts/noto-sans-thai-thai.woff2') format('woff2');
  unicode-range: U+02D7, U+0303, U+0331, U+0E01-0E5B, U+200C-200D, U+25CC;
}
@font-face {
  font-family: 'Noto Sans Thai';
  font-style: normal;
  font-weight: 400 700;
  font-display: swap;
  src: url('../fonts/noto-sans-thai-latin-ext.woff2') format('woff2');
  unicode-range: U+0100-02BA, U+02BD-02C5, U+02C7-02CC, U+02CE-02D7, U+02DD-02FF, U+0304, U+0308, U+0329, U+1D00-1DBF, U+1E00-1E9F, U+1EF2-1EFF, U+2020, U+20A0-20AB, U+20AD-20C0, U+2113, U+2C60-2C7F, U+A720-A7FF;
}
@font-face {
  font-family: 'Noto Sans Thai';
  font-style: normal;
  font-weight: 400 700;
  font-display: swap;
  src: url('../fonts/noto-sans-thai-latin.woff2') format('woff2');
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}

:root {
  color-scheme: light;
  --green: #16A34A;
  --green-dark: #0F7A36;
  --green-soft: #4ABE72;
  --ink: #14281C;
  --muted: #6B7F70;
  --faint: #8A9B90;
  --line: #DDE7DF;
  --line-soft: #E4EDE7;
  --track: #E7EEE9;
  --bg: #F8FAF8;
  --outer: #EDF1EE;
  --mint: #E9F6ED;
  --mint-2: #F1F7F3;
  --field: #FBFDFB;
  --amber: #F59E0B;
  --amber-bg: #FEF6E7;
  --amber-ink: #B45309;
  --sky: #38BDF8;
  --sky-bg: #F2FAFE;
  --sky-line: #CFE6F6;
  --sky-ink: #0C7EAE;
  --deep: #10331F;
  --danger: #C63838;
  --danger-line: #F0DADA;
  --shadow: 0 2px 10px rgba(20, 40, 28, 0.05);
  --radius: 22px;
  --app-width: 480px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --font: 'LINE Seed Sans TH', 'Noto Sans Thai', system-ui, -apple-system, 'Segoe UI', sans-serif;
}

*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }

html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--outer);
  color: var(--ink);
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}
body.no-scroll { overflow: hidden; }
img { max-width: 100%; display: block; }
a { color: var(--green); text-decoration: none; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
button:disabled { cursor: default; opacity: 0.55; }
:focus-visible { outline: 3px solid rgba(22, 163, 74, 0.45); outline-offset: 2px; }
h1, h2, h3, p { margin: 0; }

@keyframes kd-spin { to { transform: rotate(360deg); } }
@keyframes kd-pulse { 0%, 100% { opacity: 1; } 50% { opacity: 0.45; } }
@keyframes kd-rise { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: none; } }
@keyframes kd-sheet { from { transform: translateY(100%); } to { transform: none; } }
@keyframes kd-dot { 0%, 80%, 100% { opacity: 0.25; } 40% { opacity: 1; } }

/* ---------- App frame ---------- */
.app {
  max-width: var(--app-width);
  min-height: 100vh;
  min-height: 100dvh;
  margin: 0 auto;
  background: var(--bg);
}
.view {
  padding: calc(var(--safe-top) + 22px) 18px calc(var(--safe-bottom) + 104px);
}
.page { display: flex; flex-direction: column; gap: 14px; animation: kd-rise 0.25s ease both; }
.stack { display: flex; flex-direction: column; gap: 12px; }
.row { display: flex; align-items: center; }
.gap { gap: 10px; }
.grow { flex: 1; min-width: 0; }
.grow-2 { flex: 2; min-width: 0; }
.center { text-align: center; }

.head-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding-top: 6px; }
.title { font-size: 26px; font-weight: 700; letter-spacing: -0.3px; line-height: 1.25; }
.title.sm { font-size: 22px; }
.subtitle { font-size: 13px; color: var(--muted); margin-top: 2px; }
.hint { font-size: 12px; color: var(--muted); }
.strong { font-weight: 700; }
.green { color: var(--green); }
.card-label { font-size: 13px; font-weight: 700; color: var(--muted); padding: 4px 4px 0; }

.avatar-lg {
  width: 46px; height: 46px; border-radius: 50%; flex-shrink: 0;
  background: var(--mint); display: flex; align-items: center; justify-content: center; font-size: 24px;
}
.avatar-md {
  width: 48px; height: 48px; border-radius: 50%; flex-shrink: 0;
  background: var(--mint-2); display: flex; align-items: center; justify-content: center; font-size: 24px;
}
.avatar-lg, .avatar-md { overflow: hidden; }
.avatar-lg img, .avatar-md img { width: 100%; height: 100%; object-fit: cover; }
.sync-btn { position: relative; color: var(--green); transition: color 0.2s ease, border-color 0.2s ease; }
.sync-btn:hover { border-color: var(--green); }
.sync-btn svg { display: block; }
.sync-btn[data-sync-state='syncing'] svg { animation: kd-spin 0.9s linear infinite; }
.sync-btn[data-sync-state='offline'] { color: var(--faint); }
.sync-dot {
  position: absolute; top: 5px; right: 5px; width: 8px; height: 8px; border-radius: 50%;
  background: var(--green-soft); box-shadow: 0 0 0 2px #fff; transition: background 0.2s ease;
}
.sync-btn[data-sync-state='syncing'] .sync-dot { background: var(--sky); }
.sync-btn[data-sync-state='offline'] .sync-dot { background: var(--danger); animation: kd-pulse 1.2s ease-in-out infinite; }
.avatar-btn { border: none; background: none; padding: 0; border-radius: 50%; }
.head-actions { display: flex; align-items: center; gap: 8px; flex-shrink: 0; }
.view.quiet .page { animation: none; }

/* ---------- Cards ---------- */
.card {
  background: #fff; border-radius: var(--radius); padding: 16px; box-shadow: var(--shadow);
  display: flex; flex-direction: column; gap: 10px; min-width: 0;
}
.card.flush { padding: 0; overflow: hidden; gap: 0; }
.card-pad { padding: 16px; }
.card-title { font-size: 15px; font-weight: 700; display: flex; align-items: center; gap: 6px; }
.card.dark { background: var(--deep); color: #fff; flex-direction: row; gap: 12px; padding: 18px 16px; }
.row-card { flex-direction: row; align-items: center; gap: 12px; }
.list-card { padding: 4px 16px; gap: 0; }

.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.grid-4 { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }

.stat-value { font-size: 22px; font-weight: 700; line-height: 1.1; }
.stat-value .unit { font-size: 13px; font-weight: 500; color: var(--muted); }
.stat-label { font-size: 13px; color: var(--muted); }

.bar { height: 8px; border-radius: 4px; background: var(--track); overflow: hidden; }
.bar > i { display: block; height: 100%; border-radius: 4px; background: var(--green); transition: width 0.4s ease; }
.bar > i.water { background: var(--sky); }
.bar > i.amber { background: var(--amber); }
.bar.thin { height: 6px; background: #EDF3EF; }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  height: 48px; padding: 0 18px; border-radius: 16px; border: 1.5px solid transparent;
  font-size: 15px; font-weight: 700; background: #fff; color: var(--ink); white-space: nowrap;
  transition: background 0.15s ease, border-color 0.15s ease;
}
.btn-lg { height: 54px; font-size: 17px; }
.btn-sm { height: 38px; font-size: 13px; border-radius: 12px; padding: 0 12px; }
.btn-block { width: 100%; }
.btn-primary { background: var(--green); color: #fff; }
.btn-primary:hover:not(:disabled) { background: var(--green-dark); }
.btn-outline { border-color: var(--line); }
.btn-outline:hover:not(:disabled) { border-color: var(--green); }
.btn-danger-outline { border-color: var(--danger-line); color: var(--danger); }
.btn-danger-outline:hover:not(:disabled) { background: #FDF4F4; }
.btn-water { flex: 1; height: 38px; border-radius: 12px; border-color: var(--sky-line); background: var(--sky-bg); color: var(--sky-ink); font-size: 13px; padding: 0 6px; }
.btn-water:hover:not(:disabled) { background: #E3F4FD; }
.btn-dashed { height: 54px; border: 1.5px dashed #A8C6B4; border-radius: 16px; background: #fff; color: var(--green); font-size: 16px; font-weight: 700; }
.btn-dashed:hover { background: var(--mint-2); }
.btn-row { display: flex; gap: 8px; }
.btn-row .btn { flex: 1; }
.btn-row .btn.grow-2 { flex: 2; }

.link-btn { border: none; background: none; padding: 4px 0; font-size: 14px; font-weight: 500; color: var(--muted); }
.link-btn.small { font-size: 12px; align-self: flex-start; padding: 0; }
.link-btn.green { color: var(--green); }
.link-del { border: none; background: none; padding: 2px; color: #B8C6BC; font-size: 12px; }
.link-del:hover { color: #D14343; }
.icon-btn {
  width: 38px; height: 38px; border-radius: 12px; border: 1.5px solid var(--line-soft); background: #fff;
  display: inline-flex; align-items: center; justify-content: center; font-size: 22px; line-height: 1; color: var(--ink); flex-shrink: 0;
}
.value-btn { border: none; background: none; color: var(--green); font-weight: 700; font-size: 15px; padding: 4px 0; white-space: nowrap; }

/* ---------- Today ---------- */
.meal-btn {
  border: none; border-radius: 16px; padding: 12px 4px; background: var(--field);
  display: flex; flex-direction: column; align-items: center; gap: 5px; min-width: 0;
}
.meal-btn.done { background: var(--mint-2); }
.meal-btn .emoji { font-size: 24px; line-height: 1; }
.meal-btn .label { font-size: 12px; font-weight: 500; }
.meal-btn .mark { font-size: 11px; font-weight: 700; color: #A9B8AE; text-align: center; line-height: 1.2; }
.meal-btn.done .mark { color: var(--green); font-size: 12px; }

.score-card { flex-direction: row; align-items: center; gap: 18px; padding: 18px 16px; }
.ring { width: 92px; height: 92px; border-radius: 50%; flex-shrink: 0; position: relative; }
.ring-inner {
  position: absolute; inset: 9px; border-radius: 50%; background: #fff;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
}
.ring-inner b { font-size: 26px; line-height: 1; }
.ring-inner span { font-size: 11px; color: var(--faint); }
.score-rows { flex: 1; display: flex; flex-direction: column; gap: 7px; min-width: 0; }
.score-row { display: flex; align-items: center; gap: 8px; }
.score-row .lbl { font-size: 12px; color: var(--muted); width: 58px; flex-shrink: 0; }
.score-row .bar { flex: 1; }
.score-row .val { font-size: 12px; font-weight: 700; width: 42px; text-align: right; }

.ai-emoji { font-size: 22px; line-height: 1.2; }
.ai-title { font-size: 14px; font-weight: 700; color: #8AE0A8; }
.ai-text { font-size: 14px; line-height: 1.6; color: #EAF5EE; }
/* Water + activity cards share one structure so the pair lines up. */
.metric-card .card-title { min-height: 28px; }
.metric-card .stat-value { white-space: nowrap; }
.title-action {
  margin-left: auto; width: 28px; height: 28px; padding: 0; border-radius: 50%;
  border: 1.5px solid var(--line-soft); background: #fff; color: var(--muted); font-size: 15px; line-height: 1;
  display: inline-flex; align-items: center; justify-content: center;
}
.metric-hint {
  height: 24px; line-height: 24px; font-size: 12px; color: var(--muted);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.metric-hint.timer-live { display: flex; align-items: center; gap: 6px; }
.metric-hint.timer-live b { font-size: 18px; line-height: 24px; color: var(--ink); }
.metric-actions { margin-top: auto; display: flex; flex-direction: column; gap: 6px; }
.metric-actions > .btn { width: 100%; }
@media (max-width: 400px) {
  .metric-card .stat-value { font-size: 19px; }
  .metric-card .stat-value .unit { font-size: 12px; }
}

/* IF */
.fast-live { display: flex; align-items: center; gap: 16px; }
.ring.fast-ring { width: 104px; height: 104px; }
.fast-ring .ring-inner b { font-size: 18px; font-variant-numeric: tabular-nums; }
.fast-stage { font-size: 13px; color: #2F4A39; background: var(--mint-2); border-radius: 10px; padding: 6px 10px; }
.fast-status { font-size: 14px; font-weight: 700; }
.fast-status.eat { color: var(--green); }
.fast-status.fast { color: #4F5FA8; }
.fast-timeline { position: relative; padding-top: 3px; }
.fast-bar { position: relative; height: 12px; border-radius: 6px; background: #DCE2F3; overflow: hidden; }
.fast-bar i { position: absolute; top: 0; bottom: 0; background: #4ABE72; }
.fast-now { position: absolute; top: 0; width: 3px; height: 18px; margin-left: -1.5px; border-radius: 2px; background: var(--ink); box-shadow: 0 0 0 2px #fff; }
.fast-ticks { display: flex; justify-content: space-between; font-size: 10px; color: var(--faint); margin-top: 3px; }
.fast-rec { display: flex; flex-direction: column; gap: 4px; background: var(--mint-2); border-radius: 14px; padding: 10px 12px; font-size: 13px; color: #3E5A48; }
.fast-rec b { color: var(--green-dark); }
.tag { font-style: normal; font-size: 10px; font-weight: 700; background: var(--green); color: #fff; border-radius: 6px; padding: 1px 6px; margin-left: 6px; vertical-align: middle; }
.center-self { align-self: center !important; }

.btn-stack { display: flex; flex-direction: column; gap: 6px; }
.btn-stack .btn { width: 100%; }
.btn-stack .link-btn.small { align-self: center; padding: 2px 0; }
.timer-live { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.timer-live b { font-size: 20px; font-variant-numeric: tabular-nums; line-height: 1.2; }
.timer-dot { width: 9px; height: 9px; border-radius: 50%; background: var(--danger); animation: kd-pulse 1.2s ease-in-out infinite; }

.body-stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.body-stats > div {
  min-width: 0; padding: 10px; border-radius: 14px; background: var(--field); border: 1px solid #EDF3EF;
  display: flex; flex-direction: column; gap: 2px;
}
.body-stats span { font-size: 12px; color: var(--muted); }
.body-stats b { font-size: 20px; line-height: 1.15; }
.body-stats em { font-style: normal; font-size: 11px; color: var(--faint); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.body-stats em.bmi-normal { color: var(--green); font-weight: 700; }
.body-stats em.bmi-under, .body-stats em.bmi-over { color: var(--amber-ink); font-weight: 700; }
.body-stats em.bmi-obese { color: var(--danger); font-weight: 700; }
.bmi-scale {
  position: relative; height: 8px; border-radius: 4px; margin-top: 4px;
  background: linear-gradient(90deg, #F5B544 0 17.5%, #4ABE72 17.5% 40%, #F5B544 40% 50%, #E8806F 50% 100%);
}
.bmi-scale i {
  position: absolute; top: -4px; width: 5px; height: 16px; margin-left: -2.5px; border-radius: 3px;
  background: var(--ink); box-shadow: 0 0 0 2px #fff;
}
.bmi-legend { position: relative; height: 14px; font-size: 10px; color: var(--faint); margin-top: -4px; }
.bmi-legend span { position: absolute; transform: translateX(-50%); }
.kcal-row { display: flex; flex-direction: column; gap: 6px; }
.advice { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 6px; }
.advice li {
  position: relative; padding: 9px 12px 9px 36px; border-radius: 14px;
  background: var(--mint-2); color: #2F4A39; font-size: 13px; line-height: 1.55;
}
.advice li::before { content: '💡'; position: absolute; left: 12px; top: 9px; font-size: 13px; }
.advice li.good::before { content: '✅'; }
.advice li.warn { background: var(--amber-bg); color: #7C4A0B; }
.advice li.warn::before { content: '⚠️'; }
.value-btn.small { font-size: 13px; }
.pill-btn {
  height: 32px; padding: 0 12px; border-radius: 999px; flex-shrink: 0; white-space: nowrap;
  border: 1.5px solid var(--line); background: #fff; color: var(--green); font-size: 13px; font-weight: 700;
}
.pill-btn:hover:not(:disabled) { border-color: var(--green); background: var(--mint-2); }
.pill-link { display: inline-flex; align-items: center; }
.support-card .support-qr-link { align-self: center; flex: none; display: block; width: 240px; max-width: 82%; }
.support-card .support-qr {
  width: 100%; height: auto; display: block;
  border-radius: 16px; border: 1px solid var(--line-soft); background: #fff;
}
.support-card .btn { width: 100%; }
.value-text { font-weight: 700; white-space: nowrap; }

.btn-glass { align-self: flex-start; margin-top: 4px; height: 36px; padding: 0 14px; border: none; border-radius: 12px; background: rgba(255,255,255,0.14); color: #fff; font-size: 13px; font-weight: 700; }
.btn-glass:hover { background: rgba(255,255,255,0.24); }

/* ---------- Diary ---------- */
.date-nav { display: flex; align-items: center; gap: 10px; }
.date-label { flex: 1; text-align: center; font-size: 14px; font-weight: 700; }
.list { display: flex; flex-direction: column; gap: 10px; }
.log-card {
  background: #fff; border-radius: 20px; padding: 14px; box-shadow: var(--shadow);
  display: flex; gap: 12px; align-items: flex-start; cursor: pointer;
}
.thumb {
  width: 52px; height: 52px; border-radius: 16px; background: var(--mint-2); flex-shrink: 0; overflow: hidden;
  display: flex; align-items: center; justify-content: center; font-size: 26px;
}
.thumb img { width: 100%; height: 100%; object-fit: cover; }
.log-body { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 3px; }
.log-meta { display: flex; gap: 8px; font-size: 12px; color: var(--faint); }
.log-meta b { color: var(--green); }
.log-name { font-size: 16px; font-weight: 700; line-height: 1.35; overflow-wrap: anywhere; }
.log-levels { font-size: 12px; color: var(--muted); }
.log-side { display: flex; flex-direction: column; align-items: flex-end; gap: 6px; flex-shrink: 0; }
.badge { padding: 4px 9px; border-radius: 10px; font-size: 13px; font-weight: 700; }
.badge.good { background: var(--mint); color: #166534; }
.badge.warn { background: var(--amber-bg); color: var(--amber-ink); }
.mini-row { display: flex; justify-content: space-between; align-items: center; gap: 10px; font-size: 14px; padding: 4px 0; }

.empty {
  display: flex; flex-direction: column; align-items: center; gap: 10px; text-align: center;
  padding: 36px 16px; color: var(--muted); background: #fff; border-radius: var(--radius); box-shadow: var(--shadow);
}
.empty.small { padding: 18px; box-shadow: none; background: var(--field); }
.empty-emoji { font-size: 40px; }

/* ---------- Add food ---------- */
.opt-row { display: flex; gap: 6px; flex-wrap: wrap; }
.opt {
  flex: 1; min-width: 64px; height: 42px; border: 1.5px solid var(--line); border-radius: 14px; background: #fff;
  color: var(--muted); font-size: 13px; font-weight: 700; padding: 0 6px;
}
.opt.active { border-color: var(--green); background: var(--mint); color: var(--green); }

.big-camera {
  border: none; border-radius: 24px; background: var(--green); color: #fff; padding: 26px 20px;
  display: flex; flex-direction: column; align-items: center; gap: 6px;
  box-shadow: 0 10px 26px rgba(22, 163, 74, 0.28);
}
.big-camera:hover { background: var(--green-dark); }
.big-camera .emoji { font-size: 40px; line-height: 1; }
.big-camera b { font-size: 19px; }
.big-camera span { font-size: 13px; opacity: 0.88; }
.tile {
  background: #fff; border: 1.5px solid var(--line-soft); border-radius: 20px; padding: 18px 12px;
  display: flex; flex-direction: column; align-items: center; gap: 8px; font-size: 14px;
}
.tile:hover { border-color: var(--green); }
.tile .emoji { font-size: 26px; line-height: 1; }

.analyzing { display: flex; flex-direction: column; align-items: center; gap: 18px; padding: 30px 0; text-align: center; }
.preview-box {
  width: 200px; height: 200px; border-radius: 26px; background: var(--mint); overflow: hidden;
  display: flex; align-items: center; justify-content: center; font-size: 74px;
}
.preview-box img { width: 100%; height: 100%; object-fit: cover; }
.analyzing b { font-size: 17px; }
.pulse { animation: kd-pulse 1.4s ease-in-out infinite; }

.review-hero { aspect-ratio: 4 / 3; max-height: 320px; background: var(--mint); display: flex; align-items: center; justify-content: center; font-size: 64px; }
.review-hero img { width: 100%; height: 100%; object-fit: cover; }
.review-top { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; }
.name-input {
  width: 100%; border: none; border-bottom: 1.5px dashed #CFDCD4; background: none; font-size: 19px; font-weight: 700;
  padding: 4px 0; outline: none; border-radius: 0;
}
.name-input:focus { border-bottom-color: var(--green); }
.score-box {
  width: 58px; height: 58px; border-radius: 18px; background: var(--amber-bg); flex-shrink: 0;
  display: flex; flex-direction: column; align-items: center; justify-content: center; color: var(--amber-ink);
}
.score-box b { font-size: 20px; line-height: 1; }
.score-box span { font-size: 10px; }
.score-box.good { background: var(--mint); color: #166534; }
.score-box.kcal { background: var(--sky-bg); color: var(--sky-ink); }
.review-scores { display: flex; gap: 8px; flex-shrink: 0; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { padding: 5px 10px; border-radius: 10px; background: var(--mint-2); font-size: 12px; color: #3E5A48; }
.level-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.level-cell {
  display: flex; align-items: center; justify-content: space-between; gap: 6px;
  padding: 10px 12px; border-radius: 14px; background: var(--field); border: 1px solid #EDF3EF; font-size: 13px;
}
.level-cell span { color: var(--muted); }
.tip-box { background: var(--amber-bg); border-radius: 20px; padding: 14px 16px; display: flex; gap: 10px; font-size: 14px; line-height: 1.6; color: #7C4A0B; }
.manual-photo { aspect-ratio: 4 / 3; max-height: 260px; border-radius: 20px; overflow: hidden; background: var(--mint); }
.manual-photo img { width: 100%; height: 100%; object-fit: cover; }

/* ---------- Forms ---------- */
.field { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.field-label { font-size: 13px; font-weight: 500; color: var(--muted); }
.input {
  width: 100%; min-height: 50px; border: 1.5px solid var(--line); border-radius: 14px; padding: 0 14px;
  font-size: 16px; background: var(--field); outline: none; -webkit-appearance: none; appearance: none;
}
textarea.input { padding: 12px 14px; resize: vertical; min-height: 80px; line-height: 1.5; }
.input:focus { border-color: var(--green); background: #fff; }
.form-error { background: #FDF4F4; color: var(--danger); border-radius: 12px; padding: 10px 12px; font-size: 14px; }
.avatar-pick { display: grid; grid-template-columns: repeat(6, 1fr); gap: 6px; }
.avatar-pick button {
  aspect-ratio: 1; border: 1.5px solid var(--line-soft); border-radius: 14px; background: #fff; font-size: 24px; padding: 0;
}
.avatar-pick button.active { border-color: var(--green); background: var(--mint); }
.avatar-picker { display: flex; flex-direction: column; gap: 8px; }
.avatar-group-label { font-size: 12px; font-weight: 700; color: var(--faint); margin-top: 2px; }
.avatar-photo-row {
  display: flex; align-items: center; gap: 12px; padding: 10px 12px;
  border: 1.5px dashed var(--line); border-radius: 16px; background: #fff;
}
.avatar-photo-row .hint { margin-top: 4px; }
.avatar-preview {
  width: 58px; height: 58px; border-radius: 50%; flex-shrink: 0; overflow: hidden; padding: 0;
  border: 2.5px solid transparent; background: var(--mint-2); font-size: 22px;
  display: flex; align-items: center; justify-content: center;
}
.avatar-preview.active { border-color: var(--green); }
.avatar-preview img { width: 100%; height: 100%; object-fit: cover; }
.opt-col { display: flex; flex-direction: column; gap: 6px; }
.opt-col .opt {
  height: auto; min-height: 46px; padding: 8px 14px; text-align: left;
  display: flex; flex-direction: column; align-items: flex-start; gap: 1px;
}
.opt-col .opt small { font-size: 12px; font-weight: 500; }

.switch {
  width: 50px; height: 30px; border: none; border-radius: 15px; background: #D5DED8; position: relative; flex-shrink: 0; padding: 0;
  transition: background 0.18s ease;
}
.switch::after {
  content: ''; position: absolute; top: 3px; left: 3px; width: 24px; height: 24px; border-radius: 50%; background: #fff;
  box-shadow: 0 1px 3px rgba(0,0,0,0.2); transition: left 0.18s ease;
}
.switch[aria-checked='true'] { background: var(--green); }
.switch[aria-checked='true']::after { left: 23px; }

.setting-row { display: flex; align-items: center; gap: 12px; padding: 14px 0; border-bottom: 1px solid #F1F5F2; }
.setting-row:last-child { border-bottom: none; }
.setting-text { flex: 1; min-width: 0; }
.setting-label { font-size: 15px; font-weight: 500; }
.setting-hint { font-size: 12px; color: var(--faint); margin-top: 2px; overflow-wrap: anywhere; }

.note { background: var(--mint-2); border-radius: 18px; padding: 14px 16px; font-size: 13px; color: #3E5A48; line-height: 1.6; }
.note.warn { background: var(--amber-bg); color: #7C4A0B; }

/* ---------- Stats ---------- */
.seg { display: flex; gap: 6px; background: #EDF3EF; border-radius: 14px; padding: 4px; }
.seg button { flex: 1; height: 36px; border: none; border-radius: 11px; background: transparent; color: var(--muted); font-size: 13px; font-weight: 700; }
.seg button.active { background: #fff; color: var(--ink); box-shadow: 0 1px 4px rgba(20,40,28,0.08); }
.chart-bars { display: flex; align-items: flex-end; gap: 6px; height: 132px; }
.chart-bars.dense { gap: 2px; height: 112px; }
.bar-col { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: flex-end; gap: 6px; height: 100%; min-width: 0; }
.bar-fill { width: 100%; border-radius: 8px 8px 3px 3px; }
.chart-bars.dense .bar-fill { border-radius: 3px 3px 1px 1px; }
.bar-val, .bar-day { font-size: 10px; color: var(--faint); white-space: nowrap; }
.chart-foot { display: flex; justify-content: space-between; font-size: 11px; color: var(--faint); }
.weight-svg { width: 100%; height: 110px; display: block; }
.kcal-svg { width: 100%; height: 110px; display: block; }
.chart-days { display: grid; font-size: 10px; color: var(--faint); text-align: center; }
.kpi { background: #fff; border-radius: 20px; padding: 16px; box-shadow: var(--shadow); }
.kpi .stat-value { margin-top: 4px; }

/* ---------- Coach ---------- */
.chat { display: flex; flex-direction: column; gap: 10px; }
.bubble {
  max-width: 82%; padding: 12px 14px; border-radius: 18px; font-size: 14px; line-height: 1.6; overflow-wrap: anywhere;
  animation: kd-rise 0.2s ease both;
}
.bubble.ai { align-self: flex-start; background: #fff; box-shadow: var(--shadow); border-bottom-left-radius: 6px; }
.bubble.me { align-self: flex-end; background: var(--green); color: #fff; border-bottom-right-radius: 6px; }
.bubble.error { background: #FDF4F4; color: var(--danger); box-shadow: none; }
.bubble.typing { display: flex; gap: 5px; padding: 16px; }
.bubble.typing i { width: 7px; height: 7px; border-radius: 50%; background: var(--faint); animation: kd-dot 1.2s infinite; }
.bubble.typing i:nth-child(2) { animation-delay: 0.15s; }
.bubble.typing i:nth-child(3) { animation-delay: 0.3s; }
.suggest { display: flex; flex-wrap: wrap; gap: 8px; }
.chip-btn { padding: 9px 13px; border: 1.5px solid var(--line); border-radius: 14px; background: #fff; font-size: 13px; }
.chip-btn:hover:not(:disabled) { border-color: var(--green); }
.chat-bar {
  position: sticky; bottom: calc(var(--safe-bottom) + 92px); z-index: 5;
  display: flex; gap: 8px; padding: 8px; background: rgba(248,250,248,0.96); border-radius: 18px;
  box-shadow: 0 4px 18px rgba(20,40,28,0.08);
}
.chat-bar .input { min-height: 46px; }
.chat-bar .btn { height: 46px; }

/* ---------- Family ---------- */
.member-row { flex-direction: row; align-items: center; gap: 12px; padding: 14px; border-radius: 20px; cursor: pointer; text-align: left; border: none; width: 100%; }
.member-row.inactive { opacity: 0.55; }
.member-score { text-align: right; flex-shrink: 0; }
.member-score b { font-size: 20px; display: block; line-height: 1.2; }
.member-score span { font-size: 10px; color: var(--faint); }

/* ---------- Bottom navigation ---------- */
.nav {
  position: fixed; bottom: 0; left: 50%; transform: translateX(-50%); z-index: 30;
  width: 100%; max-width: var(--app-width);
  display: flex; align-items: flex-end; gap: 2px;
  padding: 8px 6px calc(var(--safe-bottom) + 10px);
  background: rgba(255,255,255,0.94); border-top: 1px solid var(--track);
  -webkit-backdrop-filter: blur(18px); backdrop-filter: blur(18px);
}
.nav-item {
  flex: 1; min-height: 56px; display: flex; flex-direction: column; align-items: center; justify-content: flex-end; gap: 4px;
  color: #9BAEA2; font-size: 10px; font-weight: 700; padding: 4px 0;
}
.nav-item.active { color: var(--green); }
.fab {
  width: 50px; height: 50px; border-radius: 50%; background: var(--green); color: #fff; margin-bottom: 4px;
  display: flex; align-items: center; justify-content: center; box-shadow: 0 6px 16px rgba(22,163,74,0.35);
}

/* ---------- Sheet (bottom modal) ---------- */
.sheet-backdrop {
  position: fixed; inset: 0; z-index: 50; background: rgba(16, 32, 22, 0.45);
  display: flex; align-items: flex-end; justify-content: center; animation: kd-rise 0.15s ease both;
}
.sheet-backdrop.closing { opacity: 0; transition: opacity 0.18s ease; }
.sheet {
  width: 100%; max-width: var(--app-width); max-height: 92vh; max-height: 92dvh; overflow-y: auto;
  background: var(--bg); border-radius: 26px 26px 0 0; padding: 8px 18px calc(var(--safe-bottom) + 20px);
  animation: kd-sheet 0.22s ease both;
}
.sheet-handle { width: 42px; height: 5px; border-radius: 3px; background: #D5DED8; margin: 4px auto 8px; }
.sheet-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 14px; }
.sheet-title { font-size: 19px; font-weight: 700; }
.sheet-close { border: none; background: var(--mint-2); width: 34px; height: 34px; border-radius: 50%; font-size: 15px; color: var(--muted); }
.sheet-body { display: flex; flex-direction: column; gap: 14px; }
.sheet-actions { display: flex; gap: 10px; margin-top: 4px; }
.sheet-actions .btn { flex: 1; }
.sheet-actions .btn.grow-2 { flex: 2; }
.sheet-photo { width: 100%; height: auto; aspect-ratio: 4 / 3; max-height: 300px; object-fit: cover; object-position: center; border-radius: 18px; background: var(--mint); }

/* ---------- Feedback ---------- */
.toast {
  position: fixed; left: 50%; transform: translateX(-50%); z-index: 60;
  bottom: calc(var(--safe-bottom) + 96px); width: calc(100% - 36px); max-width: calc(var(--app-width) - 36px);
  background: var(--deep); color: #fff; border-radius: 16px; padding: 13px 16px; font-size: 14px; font-weight: 500;
  box-shadow: 0 10px 26px rgba(0,0,0,0.24); animation: kd-rise 0.25s ease both;
}
.loading { display: flex; justify-content: center; padding: 80px 0; }
.spinner {
  width: 32px; height: 32px; border-radius: 50%; border: 4px solid #DCEDE2; border-top-color: var(--green);
  animation: kd-spin 0.9s linear infinite; display: inline-block;
}
.spinner.lg { width: 42px; height: 42px; }

/* ---------- Login ---------- */
.login-body { background: var(--bg); }
.login-wrap {
  max-width: var(--app-width); margin: 0 auto; min-height: 100vh; min-height: 100dvh;
  padding: calc(var(--safe-top) + 64px) 22px calc(var(--safe-bottom) + 34px);
  background: linear-gradient(180deg, var(--green-dark) 0, var(--green) 300px, var(--bg) 300px);
  display: flex; flex-direction: column; gap: 24px;
}
.login-hero { display: flex; flex-direction: column; align-items: center; gap: 14px; color: #fff; text-align: center; }
.login-hero img { width: 88px; height: 88px; border-radius: 22px; box-shadow: 0 12px 28px rgba(0,0,0,0.25); }
.login-hero p { font-size: 15px; font-weight: 500; opacity: 0.94; }
.login-card {
  background: #fff; border-radius: 24px; padding: 22px 20px; box-shadow: 0 10px 30px rgba(20,40,28,0.10);
  display: flex; flex-direction: column; gap: 14px;
}
.card-h { font-size: 19px; font-weight: 700; }
.device-users { display: flex; gap: 10px; overflow-x: auto; padding-bottom: 4px; }
.device-user {
  flex: 1 0 96px; position: relative; background: #fff; border: 1.5px solid var(--line-soft); border-radius: 18px;
  padding: 14px 6px; display: flex; flex-direction: column; align-items: center; gap: 4px;
}
.device-user:hover { border-color: var(--green); }
.device-user .emoji { font-size: 28px; line-height: 1; }
.device-user b { font-size: 14px; }
.device-user small { font-size: 11px; color: var(--faint); }
.device-user .forget {
  position: absolute; top: 4px; right: 6px; border: none; background: none; color: #B8C6BC; font-size: 13px; padding: 2px 4px;
}

@media (min-width: 520px) {
  .app { box-shadow: 0 0 0 1px rgba(20,40,28,0.04), 0 20px 60px rgba(20,40,28,0.08); }
}
@media (max-width: 360px) {
  .title { font-size: 23px; }
  .grid-2 { gap: 10px; }
  .score-card { gap: 12px; }
  .ring { width: 80px; height: 80px; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.01ms !important; transition-duration: 0.01ms !important; }
}
