:root {
  --bg: #14181f;
  --card: #1d232d;
  --line: #2b3340;
  --text: #e8ecf1;
  --muted: #8d98a8;
  --accent: #5fd4a4;
  --accent-ink: #0d2a1f;
  --warn: #f0b35a;
  --bad: #ef7a6a;
  --radius: 16px;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--text); }
body {
  font: 16px/1.45 -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", sans-serif;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}
[hidden] { display: none !important; }
h1 { font-size: 28px; margin: 0; letter-spacing: -0.02em; }
h2 { font-size: 15px; margin: 0 0 10px; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: 0.04em; }
p { margin: 0 0 8px; }
button {
  font: inherit; border: 0; border-radius: 12px; padding: 12px 16px; cursor: pointer;
  background: var(--line); color: var(--text);
}
a.button { display: block; text-align: center; text-decoration: none; border-radius: 12px; padding: 12px 16px; margin: 4px 0 8px; flex: 1; }
button.primary, a.button.primary { background: var(--accent); color: var(--accent-ink); font-weight: 600; }
button.secondary { background: var(--line); }
button.small { padding: 8px 12px; font-size: 14px; }
button:disabled { opacity: 0.5; }
input, textarea {
  font: inherit; color: var(--text); background: var(--bg); border: 1px solid var(--line);
  border-radius: 12px; padding: 10px 12px; width: 100%;
}

.screen { padding: calc(env(safe-area-inset-top) + 12px) 16px calc(env(safe-area-inset-bottom) + 84px); max-width: 640px; margin: 0 auto; }
.top { display: flex; align-items: flex-end; justify-content: space-between; gap: 12px; margin: 8px 0 16px; }
.eyebrow { color: var(--accent); font-size: 13px; font-weight: 600; }
.card { background: var(--card); border-radius: var(--radius); padding: 16px; margin-bottom: 12px; }
.card.warn { border: 1px solid var(--warn); color: var(--warn); }
.card.evening { border: 1px solid var(--accent); }
.row { display: flex; gap: 10px; flex-wrap: wrap; }
.row button { flex: 1; }
.muted { color: var(--muted); }
.small-text { font-size: 13px; }
.error { color: var(--bad); min-height: 1.4em; }
.reply { margin-top: 12px; white-space: pre-wrap; }

.kpis { display: grid; grid-template-columns: 1.3fr 1fr 1fr; gap: 8px; margin-bottom: 8px; }
.label { display: block; font-size: 12px; color: var(--muted); }
.big { font-size: 30px; font-weight: 700; letter-spacing: -0.02em; }
.mid { font-size: 20px; font-weight: 600; }
.legend { font-size: 12px; color: var(--muted); display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.legend .dot { width: 7px; height: 7px; border-radius: 50%; background: var(--muted); display: inline-block; }
.legend .line { width: 14px; height: 3px; background: var(--accent); display: inline-block; }
.legend .goal { width: 14px; border-top: 1px dashed var(--warn); display: inline-block; }
svg { width: 100%; height: auto; display: block; }

.bars > div { display: grid; grid-template-columns: 70px 1fr auto; align-items: center; gap: 10px; margin-bottom: 8px; }
.bars .label { font-size: 14px; }
.bar { height: 10px; background: var(--bg); border-radius: 6px; overflow: hidden; }
.bar i { display: block; height: 100%; width: 0; background: var(--accent); border-radius: 6px; }
.bar i.over { background: var(--warn); }
.meals { list-style: none; padding: 0; margin: 8px 0; }
.meals li { display: flex; justify-content: space-between; align-items: center; gap: 8px; padding: 8px 0; border-top: 1px solid var(--line); font-size: 14px; }
.meals li span:last-of-type { color: var(--muted); white-space: nowrap; }
.meals button { background: none; color: var(--muted); padding: 4px 8px; }

.messages { display: flex; flex-direction: column; gap: 10px; padding-bottom: 90px; }
.msg { max-width: 88%; padding: 10px 14px; border-radius: 16px; white-space: normal; word-wrap: break-word; }
.msg.user { align-self: flex-end; background: var(--accent); color: var(--accent-ink); border-bottom-right-radius: 4px; }
.msg.assistant { align-self: flex-start; background: var(--card); border-bottom-left-radius: 4px; }
.msg .meta { font-size: 11px; opacity: 0.65; margin-bottom: 2px; }
.msg ul { margin: 4px 0; padding-left: 18px; }
.msg p { margin: 0 0 6px; }
.msg p:last-child { margin: 0; }
.msg.pending { color: var(--muted); font-style: italic; }

.composer {
  position: fixed; left: 0; right: 0; bottom: calc(env(safe-area-inset-bottom) + 58px);
  display: flex; gap: 8px; align-items: flex-end; padding: 8px 12px; background: var(--bg); border-top: 1px solid var(--line);
  max-width: 640px; margin: 0 auto;
}
.composer textarea { resize: none; max-height: 140px; }
.input-wrap { flex: 1; display: flex; flex-direction: column; gap: 6px; }
.input-wrap img { max-height: 80px; max-width: 120px; border-radius: 8px; object-fit: cover; }
.photo { background: var(--line); border-radius: 12px; padding: 8px 10px; font-size: 14px; cursor: pointer; }

.kv { display: grid; grid-template-columns: 70px 1fr; gap: 6px 10px; margin: 8px 0; font-size: 14px; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; word-break: break-all; }

.tabs {
  position: fixed; left: 0; right: 0; bottom: 0; display: flex; justify-content: space-around;
  padding: 8px 0 calc(env(safe-area-inset-bottom) + 8px); background: #10141a; border-top: 1px solid var(--line);
}
.tabs a { color: var(--muted); text-decoration: none; font-size: 14px; font-weight: 600; padding: 6px 18px; border-radius: 10px; }
.tabs a.active { color: var(--accent); background: var(--card); }

.login-box { max-width: 360px; margin: 18vh auto 0; text-align: center; display: flex; flex-direction: column; gap: 14px; }
.login-box .logo { width: 72px; height: 72px; margin: 0 auto; border-radius: 18px; }
.login-box #setup { display: flex; flex-direction: column; gap: 10px; }

.toast {
  position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(env(safe-area-inset-bottom) + 130px);
  background: #000c; color: var(--text); padding: 10px 16px; border-radius: 12px; font-size: 14px; max-width: 90vw;
}
