/* Coach web — dark, neutral, anti-rigidity: no pass/fail colors anywhere.
   Only operational failures may use the error tones. */

:root {
  --bg: #0f1317;
  --surface: #171c21;
  --surface2: #1f262d;
  --surface3: #29323b;
  --text: #e3e8ed;
  --muted: #97a1ab;
  --faint: #6b7681;
  --accent: #8ab4f8;
  --outline: #2c353f;
  --err-bg: #3a2527;
  --err-text: #f2b8b5;
  --radius: 14px;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
}
.hidden { display: none !important; }
.muted { color: var(--muted); }
.faint { color: var(--faint); }
button { font: inherit; color: inherit; background: none; border: none; cursor: pointer; }
input, textarea, select {
  font: inherit; color: var(--text);
  background: var(--surface2);
  border: 1px solid var(--outline);
  border-radius: 10px;
  padding: 8px 10px;
  outline: none;
}
input:focus, textarea:focus, select:focus { border-color: var(--accent); }
a { color: var(--accent); }

/* ---------- login ---------- */
.login {
  position: fixed; inset: 0; display: flex; align-items: center; justify-content: center;
  background: var(--bg); z-index: 50;
}
.login-card {
  display: flex; flex-direction: column; gap: 12px; width: min(320px, 86vw);
  background: var(--surface); border: 1px solid var(--outline);
  border-radius: var(--radius); padding: 28px; text-align: center;
}
.login-card h1 { margin: 0; font-size: 22px; font-weight: 600; }
.login-card p { margin: 0 0 6px; }
.login-logo { display: flex; justify-content: center; }
.login-err { color: var(--err-text); font-size: 13px; min-height: 18px; }

/* ---------- app frame ---------- */
.app { display: flex; flex-direction: column; height: 100dvh; }
.tabs {
  display: flex; align-items: center; gap: 4px;
  padding: 8px 12px calc(4px);
  max-width: 760px; width: 100%; margin: 0 auto;
}
.tab {
  padding: 8px 16px; border-radius: 999px; color: var(--muted); font-weight: 600;
}
.tab.active { background: var(--surface3); color: var(--text); }
.tabs .signout { margin-left: auto; color: var(--faint); }
main { flex: 1; min-height: 0; display: flex; }
.panel { display: none; flex: 1; min-height: 0; overflow-y: auto; }
.panel.active { display: block; }
#panel-coach.panel.active { display: flex; }
.panel-inner { max-width: 760px; margin: 0 auto; padding: 8px 14px 40px; }

/* ---------- shared bits ---------- */
.card {
  background: var(--surface); border: 1px solid var(--outline);
  border-radius: var(--radius); padding: 14px; margin-bottom: 12px;
}
.btn {
  background: var(--surface3); border: 1px solid var(--outline);
  padding: 8px 16px; border-radius: 999px; font-weight: 600;
}
.btn.primary { background: var(--accent); color: #10233f; border: none; }
.btn.small { padding: 4px 12px; font-size: 13px; }
.btn.quiet { background: none; border: none; color: var(--accent); }
.btn:disabled { opacity: .45; cursor: default; }
.icon-btn { font-size: 18px; padding: 6px 10px; border-radius: 10px; color: var(--muted); }
.icon-btn:hover { background: var(--surface2); }
.chip-row { display: flex; gap: 8px; flex-wrap: wrap; margin: 10px 0; }
.chip {
  padding: 5px 12px; border-radius: 999px; font-size: 13px;
  background: var(--surface2); border: 1px solid var(--outline); color: var(--muted);
}
.chip.on { background: var(--surface3); color: var(--text); border-color: var(--faint); }
.row-flex { display: flex; align-items: center; gap: 10px; }
.spacer { flex: 1; }
.err-banner {
  background: var(--err-bg); color: var(--err-text);
  border-radius: 10px; padding: 10px 12px; margin-bottom: 10px;
  display: flex; align-items: center; gap: 10px; font-size: 14px;
}
.err-banner .btn { background: rgba(255,255,255,.08); border: none; color: var(--err-text); }

/* ---------- toast ---------- */
.toast {
  position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%);
  background: var(--surface3); border: 1px solid var(--outline);
  padding: 10px 18px; border-radius: 999px; font-size: 14px; z-index: 70;
  max-width: 86vw; box-shadow: 0 6px 24px rgba(0,0,0,.5);
}

/* ---------- sheets (modals) ---------- */
.sheet-back {
  position: fixed; inset: 0; background: rgba(0,0,0,.55); z-index: 60;
  display: flex; align-items: flex-end; justify-content: center;
}
@media (min-width: 640px) { .sheet-back { align-items: center; } }
.sheet-card {
  background: var(--surface); border: 1px solid var(--outline);
  border-radius: 18px 18px 0 0; width: 100%; max-width: 560px;
  max-height: 86dvh; overflow-y: auto; padding: 18px;
}
@media (min-width: 640px) { .sheet-card { border-radius: 18px; } }
.sheet-title { font-size: 17px; font-weight: 600; margin-bottom: 12px; }
.form-col { display: flex; flex-direction: column; gap: 10px; }
.form-col label { font-size: 13px; color: var(--muted); }
.sheet-actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 14px; flex-wrap: wrap; }

/* ---------- weight ---------- */
.hero { display: flex; align-items: baseline; gap: 8px; }
.hero .big { font-size: 34px; font-weight: 700; letter-spacing: -.5px; }
.hero .sd { color: var(--muted); font-size: 16px; }
.fresh-line { color: var(--muted); font-size: 13px; margin-top: 2px; }
.stat-chips { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 10px; }
.stat-chip {
  background: var(--surface2); border-radius: 10px; padding: 6px 10px;
  font-size: 13px; color: var(--muted);
}
.stat-chip b { color: var(--text); font-weight: 600; }
.chart-wrap { position: relative; margin-top: 6px; }
.chart-wrap canvas { width: 100%; display: block; touch-action: pan-y; }
.chart-note { color: var(--faint); font-size: 12px; margin: 4px 2px; }
.callout {
  position: absolute; top: 6px; pointer-events: none; z-index: 5;
  background: var(--surface3); border: 1px solid var(--outline); border-radius: 10px;
  padding: 6px 10px; font-size: 12.5px; color: var(--text);
  box-shadow: 0 4px 16px rgba(0,0,0,.4); white-space: nowrap;
}
.callout .sub { color: var(--muted); }
details.intake { margin-top: 10px; }
details.intake summary { color: var(--muted); font-size: 13px; cursor: pointer; user-select: none; }
.hist-row {
  display: flex; align-items: center; gap: 10px; padding: 9px 2px;
  border-bottom: 1px solid var(--outline); font-size: 14px;
}
.hist-row:last-child { border-bottom: none; }
.src-chip {
  font-size: 11px; padding: 2px 8px; border-radius: 999px;
  background: var(--surface2); color: var(--muted); border: 1px solid var(--outline);
}
.hist-actions { display: flex; gap: 2px; }
.hist-actions button { color: var(--faint); font-size: 13px; padding: 4px 6px; border-radius: 8px; }
.hist-actions button:hover { background: var(--surface2); color: var(--text); }
.excluded { opacity: .45; text-decoration: line-through; }
.notice-box {
  background: var(--surface2); border-radius: 10px; padding: 10px 12px;
  color: var(--muted); font-size: 13.5px; margin-top: 10px;
}

/* ---------- food ---------- */
.food-nav { display: flex; align-items: center; gap: 6px; margin: 4px 0 12px; }
.food-nav .date-label { font-weight: 600; font-size: 16px; padding: 6px 10px; border-radius: 10px; }
.food-nav .date-label:hover { background: var(--surface2); }
.meal-card { padding: 10px 14px; }
.meal-head { display: flex; align-items: baseline; gap: 8px; margin-bottom: 4px; }
.meal-head .name { font-weight: 600; font-size: 16px; }
.meal-head .kcals { margin-left: auto; color: var(--faint); font-size: 12.5px; }
.slot-row {
  display: flex; align-items: center; gap: 10px; padding: 8px 2px;
  border-radius: 10px; cursor: pointer;
}
.slot-row:hover { background: var(--surface2); }
.slot-row.disabled { opacity: .55; cursor: default; }
.slot-row.pending { opacity: .55; }
.food-ic {
  width: 30px; height: 30px; border-radius: 8px; flex: none;
  background: var(--surface3); display: flex; align-items: center; justify-content: center;
  font-weight: 600; color: var(--muted); overflow: hidden;
}
.food-ic img { width: 100%; height: 100%; object-fit: contain; }
.slot-main { flex: 1; min-width: 0; }
.slot-name { display: flex; align-items: center; gap: 6px; }
.slot-name .nm { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.slot-name .ck { color: var(--muted); font-size: 13px; }
.slot-sub { color: var(--faint); font-size: 12.5px; }
.slot-sub.logged { color: var(--muted); }
.note-line { color: var(--faint); font-size: 12px; font-style: italic; }
.plan-chip { font-size: 11px; color: var(--faint); border: 1px solid var(--outline); border-radius: 999px; padding: 1px 7px; }
.add-food-row { color: var(--accent); font-size: 14px; padding: 8px 2px 2px; cursor: pointer; }
.totals-line { font-size: 14px; color: var(--muted); }
.totals-line b { color: var(--text); font-size: 16px; }
.aim-line { color: var(--faint); font-size: 12.5px; margin-top: 4px; }
.lib-row { display: flex; align-items: center; gap: 10px; padding: 8px 2px; border-radius: 10px; cursor: pointer; }
.lib-row:hover { background: var(--surface2); }
.lib-expand { padding: 4px 0 10px 40px; display: flex; gap: 8px; align-items: center; }
.lib-expand input { width: 90px; }
.kcal-preview { color: var(--faint); font-size: 13px; }
.search-input { width: 100%; margin-bottom: 8px; }
.qty-input { width: 110px; font-size: 18px; }

/* ---------- chat ---------- */
.chat-root {
  display: flex; flex-direction: column; flex: 1; min-height: 0;
  max-width: 760px; width: 100%; margin: 0 auto; position: relative;
}
.chat-head {
  display: flex; align-items: center; gap: 8px; padding: 4px 10px 8px;
  border-bottom: 1px solid var(--outline);
}
.chat-title { font-weight: 600; flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.model-select { font-size: 13px; padding: 5px 8px; max-width: 175px; color: var(--muted); }
.chat-scroll { flex: 1; overflow-y: auto; min-height: 0; }
.chat-list { display: flex; flex-direction: column; gap: 14px; padding: 14px 12px 8px; }
.turn { display: flex; flex-direction: column; gap: 8px; }
.bubble-user {
  align-self: flex-end; max-width: 82%;
  background: var(--surface3); border-radius: 16px 16px 4px 16px;
  padding: 9px 13px; white-space: pre-wrap; overflow-wrap: break-word;
}
.bubble-user img { max-width: 200px; border-radius: 10px; display: block; margin-top: 6px; }
.bubble-coach { align-self: stretch; max-width: 100%; overflow-wrap: break-word; }
.bubble-coach .md > :first-child { margin-top: 0; }
.bubble-coach .md > :last-child { margin-bottom: 0; }
.md pre {
  background: var(--surface2); border: 1px solid var(--outline);
  padding: 10px; border-radius: 10px; overflow-x: auto; font-size: 13px;
}
.md code { background: var(--surface2); padding: 1px 5px; border-radius: 5px; font-size: 13px; }
.md pre code { background: none; padding: 0; }
.md table { border-collapse: collapse; margin: 8px 0; }
.md th, .md td { border: 1px solid var(--outline); padding: 4px 10px; font-size: 13.5px; }
.md blockquote { border-left: 3px solid var(--outline); margin: 8px 0; padding-left: 10px; color: var(--muted); }
.work-line { color: var(--faint); font-size: 12.5px; font-style: italic; padding-left: 2px; }
.think-block { font-size: 12.5px; color: var(--faint); }
.think-block summary { cursor: pointer; user-select: none; }
.think-block .think-body { white-space: pre-wrap; padding: 6px 0 0 12px; max-height: 300px; overflow-y: auto; }
.turn-err { color: var(--err-text); font-size: 13px; display: flex; align-items: center; gap: 10px; }
.status-line { color: var(--faint); font-size: 12.5px; text-align: center; }
.action-card {
  display: flex; align-items: center; gap: 10px;
  background: var(--surface2); border: 1px solid var(--outline);
  border-radius: 12px; padding: 8px 12px; margin: 6px 0; max-width: 440px;
}
.action-card .roundel {
  width: 26px; height: 26px; border-radius: 50%; flex: none;
  border: 1.5px solid var(--faint); color: var(--muted);
  display: flex; align-items: center; justify-content: center; font-size: 13px;
}
.action-card .t { font-size: 14px; }
.action-card .s { color: var(--muted); font-size: 12.5px; }
.chat-composer { padding: 8px 10px calc(10px + env(safe-area-inset-bottom)); border-top: 1px solid var(--outline); }
.composer-row { display: flex; align-items: flex-end; gap: 6px; }
.composer-row textarea {
  flex: 1; resize: none; max-height: 132px; border-radius: 18px; padding: 9px 14px;
}
.composer-row .send { color: var(--accent); font-size: 20px; }
.attach-preview { padding: 4px 0 8px; display: flex; }
.attach-preview .thumb { position: relative; }
.attach-preview img { height: 56px; border-radius: 10px; display: block; }
.attach-preview button {
  position: absolute; top: -7px; right: -7px; background: var(--surface3);
  border: 1px solid var(--outline); border-radius: 50%; width: 22px; height: 22px;
  font-size: 11px; line-height: 1; color: var(--text);
}
.drawer { position: absolute; inset: 0; z-index: 20; background: rgba(0,0,0,.45); }
.drawer-card {
  position: absolute; top: 0; left: 0; bottom: 0; width: min(340px, 88%);
  background: var(--surface); border-right: 1px solid var(--outline);
  display: flex; flex-direction: column;
}
.drawer-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px; font-weight: 600; border-bottom: 1px solid var(--outline);
}
.session-list { overflow-y: auto; flex: 1; padding: 6px; }
.sess-card { padding: 10px 10px; border-radius: 12px; cursor: pointer; position: relative; }
.sess-card:hover { background: var(--surface2); }
.sess-card.current { background: var(--surface2); }
.sess-title { font-weight: 600; font-size: 14px; display: flex; gap: 6px; align-items: center; padding-right: 26px; }
.sess-recap {
  color: var(--muted); font-size: 12.5px; margin-top: 2px;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
}
.sess-meta { color: var(--faint); font-size: 11.5px; margin-top: 3px; }
.sess-menu-btn { position: absolute; right: 4px; top: 8px; color: var(--faint); padding: 4px 8px; border-radius: 8px; }
.sess-menu-btn:hover { background: var(--surface3); }
.mini-menu {
  position: fixed; z-index: 80; background: var(--surface3); border: 1px solid var(--outline);
  border-radius: 12px; overflow: hidden; box-shadow: 0 8px 30px rgba(0,0,0,.5); min-width: 140px;
}
.mini-menu button { display: block; width: 100%; text-align: left; padding: 10px 16px; font-size: 14px; }
.mini-menu button:hover { background: var(--surface2); }
