:root {
  color-scheme: dark;
  --bg-top: #0f2c33;
  --bg-bot: #081418;
  --panel: rgba(255, 255, 255, 0.05);
  --panel-line: rgba(255, 255, 255, 0.12);
  --text: #e8eef0;
  --muted: #8fa6ab;
  --accent: #e0872a;
  --teal: #2fb3a3;
  --over: #e2604a;
  --field: rgba(255, 255, 255, 0.08);
}

* { box-sizing: border-box; }
html, body { margin: 0; }
/* App shell locked to the viewport: header on top, content fills the rest, and
   only the conversation feed scrolls — so the input stays put and visible. */
body {
  height: 100dvh; overflow: hidden; display: flex; flex-direction: column;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
  background: linear-gradient(160deg, var(--bg-top) 0%, var(--bg-bot) 100%);
  background-attachment: fixed;
  color: var(--text);
  -webkit-font-smoothing: antialiased;
  padding: env(safe-area-inset-top) env(safe-area-inset-right)
           env(safe-area-inset-bottom) env(safe-area-inset-left);
}

.app-header {
  flex: 0 0 auto;
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 18px; max-width: 640px; margin: 0 auto; width: 100%;
}
.app-header h1 { font-size: 1.1rem; margin: 0; font-weight: 650; letter-spacing: .01em; }
.app-header .dot { color: var(--accent); }

.wrap {
  flex: 1 1 auto; min-height: 0; display: flex; flex-direction: column;
  max-width: 640px; margin: 0 auto; width: 100%; padding: 6px 18px 14px;
}
#login-view { overflow-y: auto; }
#app-view { flex: 1 1 auto; min-height: 0; display: flex; flex-direction: column; }

button { font: inherit; cursor: pointer; }
.btn {
  border: none; border-radius: 12px; padding: 14px 18px; font-weight: 600;
  background: var(--accent); color: #1a1205; width: 100%;
}
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .55; cursor: default; }
.btn-ghost {
  background: transparent; color: var(--muted); border: 1px solid var(--panel-line);
  border-radius: 10px; padding: 7px 12px; width: auto; font-size: .82rem; font-weight: 500;
}

.hidden { display: none !important; }

/* Login */
.login-card {
  background: var(--panel); border: 1px solid var(--panel-line); border-radius: 16px;
  padding: 22px; margin-top: 8vh; display: flex; flex-direction: column; gap: 14px;
}
.login-card h2 { margin: 0 0 2px; font-size: 1.15rem; }
.login-card p.sub { margin: 0 0 6px; color: var(--muted); font-size: .9rem; }
label { display: block; font-size: .78rem; color: var(--muted); margin-bottom: 6px; }
input[type=email], input[type=password], input[type=text] {
  width: 100%; border: 1px solid var(--panel-line); background: var(--field);
  color: var(--text); border-radius: 11px; padding: 13px 14px; font-size: 1rem;
}
input:focus { outline: 2px solid rgba(224,135,42,.5); outline-offset: 0; }

.error {
  color: var(--over); font-size: .85rem; min-height: 1em; margin: 0;
}

/* Status */
.card {
  background: var(--panel); border: 1px solid var(--panel-line); border-radius: 16px;
  padding: 20px;
}

/* Layout: single column on mobile; two columns (dials left, chat right) on wide.
   Fills the viewport height so the feed can scroll while the input stays put. */
.layout { display: flex; flex-direction: column; gap: 14px; margin-top: 6px; flex: 1 1 auto; min-height: 0; }
.col-status { display: flex; flex-direction: column; gap: 14px; min-width: 0; flex: 0 0 auto; }
.col-chat { display: flex; flex-direction: column; gap: 14px; min-width: 0; flex: 1 1 auto; min-height: 0; }

/* The feed is the one scrollable region; its title stays, the input card stays put. */
.feed-card { flex: 1 1 auto; min-height: 0; display: flex; flex-direction: column; }
.feed-list { flex: 1 1 auto; min-height: 0; overflow-y: auto; }
.entry-card { flex: 0 0 auto; }

@media (min-width: 820px) {
  .wrap { max-width: 940px; }
  .layout { flex-direction: row; align-items: stretch; gap: 18px; }
  .col-status { flex: 0 0 300px; }
  .col-chat { flex: 1 1 auto; }
  /* Stack the two dials vertically down the left rail. */
  .col-status .metrics { flex-direction: column; gap: 22px; }
  .col-status .ring { max-width: 190px; }
}
.status-top {
  display: flex; align-items: center; justify-content: space-between; margin-bottom: 4px;
}
.chip {
  font-size: .72rem; font-weight: 600; padding: 4px 10px; border-radius: 999px;
  background: rgba(47,179,163,.16); color: var(--teal); border: 1px solid rgba(47,179,163,.4);
}
.chip.gym { background: rgba(224,135,42,.16); color: var(--accent); border-color: rgba(224,135,42,.45); }
.date { color: var(--muted); font-size: .82rem; }

/* Two matching rings (calories + protein) as one consistent system. */
.metrics { display: flex; gap: 14px; margin-top: 10px; }
.metric { flex: 1; min-width: 0; text-align: center; }
.metric-title { font-size: .82rem; font-weight: 600; color: var(--muted); margin-bottom: 8px; }
.ring { position: relative; width: 100%; max-width: 168px; aspect-ratio: 1 / 1; margin: 0 auto; }
.ring svg { transform: rotate(-90deg); width: 100%; height: 100%; display: block; }
.ring .track { stroke: rgba(255,255,255,.08); }
.ring .fill { stroke: var(--teal); stroke-linecap: round; transition: stroke-dashoffset .5s ease, stroke .3s; }
.ring.over .fill { stroke: var(--over); }
.ring-center {
  position: absolute; inset: 0; display: flex; flex-direction: column;
  align-items: center; justify-content: center; gap: 1px;
}
.ring-center .big { font-size: 1.9rem; font-weight: 700; line-height: 1; font-variant-numeric: tabular-nums; }
.ring-center .lbl { font-size: .72rem; color: var(--muted); }
.ring-center .over-lbl { color: var(--over); }
.metric-sub { margin-top: 9px; font-size: .78rem; color: var(--muted); font-variant-numeric: tabular-nums; }

.center-msg { text-align: center; color: var(--muted); padding: 40px 0; }
.spinner {
  width: 26px; height: 26px; border-radius: 50%;
  border: 3px solid rgba(255,255,255,.15); border-top-color: var(--accent);
  animation: spin .8s linear infinite; margin: 0 auto 12px;
}
@keyframes spin { to { transform: rotate(360deg); } }

.actions { margin-top: 16px; display: flex; justify-content: center; }

/* Entry + feed (Phase 3) */
.section-title { font-size: .9rem; font-weight: 650; margin-bottom: 12px; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 12px; }
.chip-btn {
  border: 1px solid var(--panel-line); background: rgba(255,255,255,.05); color: var(--text);
  border-radius: 999px; padding: 8px 12px; font-size: .82rem; font-weight: 500; line-height: 1;
}
.chip-btn:active { background: rgba(224,135,42,.22); border-color: rgba(224,135,42,.5); }
textarea {
  width: 100%; resize: vertical; min-height: 52px; border: 1px solid var(--panel-line);
  background: var(--field); color: var(--text); border-radius: 11px; padding: 12px 14px;
  font: inherit; font-size: 1rem; margin-bottom: 6px;
}
textarea:focus { outline: 2px solid rgba(224,135,42,.5); outline-offset: 0; }
.feed-item { padding: 13px 0; border-top: 1px solid var(--panel-line); }
.feed-item:first-of-type { border-top: none; padding-top: 2px; }
.feed-item .you { font-size: .9rem; font-weight: 500; margin-bottom: 6px; }
.feed-item .coach { font-size: .9rem; color: var(--muted); line-height: 1.45; white-space: pre-wrap; }
.undo-btn {
  margin-top: 9px; background: transparent; border: 1px solid var(--panel-line);
  color: var(--muted); border-radius: 8px; padding: 5px 12px; font-size: .78rem;
}
.undo-btn:active { color: var(--over); border-color: var(--over); }
.feed-empty { color: var(--muted); font-size: .88rem; }
