/* Kalorien-Tracker — "Café": cozy, editorial, warm caramel. Mobile-first PWA. */

:root {
  --paper: #F3ECE1;
  --ink: #33271E;
  --muted: #94795F;
  --card: #FBF6ED;
  --card-2: #F6EEE1;
  --line: #E6D8C6;
  --line-strong: #D9C7B0;
  --accent: #B0743F;
  --accent-2: #A2683A;
  --accent-soft: #EFDFC9;
  --good: #6E8A55;
  --warn: #BE6A43;
  --danger: #B14B3C;
  --shadow: 0 14px 34px -20px rgba(74, 48, 24, .5);
  --serif: ui-serif, "New York", "Iowan Old Style", Georgia, "Times New Roman", serif;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --r: 18px;
  --safe-t: env(safe-area-inset-top);
  --safe-b: env(safe-area-inset-bottom);
}
@media (prefers-color-scheme: dark) {
  :root {
    --paper: #1D1712; --ink: #ECE1D2; --muted: #A48D74; --card: #271E17; --card-2: #221A13;
    --line: #3A2C21; --line-strong: #4A382A; --accent: #CB8B54; --accent-2: #D89A63;
    --accent-soft: #34271B; --good: #8AA36E; --warn: #D3835A; --danger: #D46A57;
    --shadow: 0 14px 34px -18px rgba(0, 0, 0, .7);
  }
}
:root[data-theme="light"] { --paper:#F3ECE1; --ink:#33271E; --muted:#94795F; --card:#FBF6ED; --card-2:#F6EEE1; --line:#E6D8C6; --line-strong:#D9C7B0; --accent:#B0743F; --accent-2:#A2683A; --accent-soft:#EFDFC9; --good:#6E8A55; --warn:#BE6A43; --danger:#B14B3C; --shadow:0 14px 34px -20px rgba(74,48,24,.5); }
:root[data-theme="dark"]  { --paper:#1D1712; --ink:#ECE1D2; --muted:#A48D74; --card:#271E17; --card-2:#221A13; --line:#3A2C21; --line-strong:#4A382A; --accent:#CB8B54; --accent-2:#D89A63; --accent-soft:#34271B; --good:#8AA36E; --warn:#D3835A; --danger:#D46A57; --shadow:0 14px 34px -18px rgba(0,0,0,.7); }

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--paper); color: var(--ink); font-family: var(--sans);
  line-height: 1.5; -webkit-font-smoothing: antialiased; text-rendering: optimizeLegibility;
  overscroll-behavior-y: none;
}
button { font: inherit; color: inherit; cursor: pointer; border: none; background: none; }
input, select, textarea { font: inherit; color: inherit; }
:focus-visible { outline: 2.5px solid var(--accent); outline-offset: 2px; border-radius: 6px; }
.tnum { font-variant-numeric: tabular-nums; }
.serif { font-family: var(--serif); }
.hidden { display: none !important; }

/* ---------- app frame ---------- */
#root { min-height: 100%; }
.app-wrap {
  max-width: 560px; margin: 0 auto; min-height: 100dvh;
  padding: calc(var(--safe-t) + 8px) 18px calc(var(--safe-b) + 150px);
  display: flex; flex-direction: column;
}
.topbar { display: flex; align-items: flex-end; justify-content: space-between; gap: 12px; padding: 8px 0 14px; }
.topbar .date-nav { display: flex; align-items: center; gap: 6px; }
.h-title { font-family: var(--serif); font-size: 30px; font-weight: 600; letter-spacing: -.01em; line-height: 1.05; }
.h-sub { font-size: 12.5px; color: var(--muted); letter-spacing: .01em; margin-top: 2px; }
.icon-btn { width: 40px; height: 40px; border-radius: 50%; display: grid; place-items: center; font-size: 18px;
  background: var(--card); border: 1px solid var(--line); color: var(--ink); transition: background .15s, transform .1s; }
.icon-btn:active { transform: scale(.94); }
.icon-btn.ghost { background: transparent; border-color: transparent; }

/* ---------- day figure ---------- */
.figure { text-align: center; padding: 6px 0 4px; }
.figure .big { font-family: var(--serif); font-size: 52px; font-weight: 600; letter-spacing: -.02em; line-height: 1; }
.figure .big.over { color: var(--warn); }
.figure .cap { font-size: 13px; color: var(--muted); margin-top: 4px; }
.figure .cap b { color: var(--ink); font-weight: 600; }
.track { height: 7px; border-radius: 99px; background: var(--line); overflow: hidden; margin: 14px 6px 0; }
.track > i { display: block; height: 100%; border-radius: 99px; background: var(--accent); transition: width .5s cubic-bezier(.2,.8,.2,1); }
.track > i.over { background: var(--warn); }

/* ---------- macro trio ---------- */
.trio { display: flex; margin: 18px 0 2px; }
.trio .col { flex: 1; text-align: center; padding: 0 6px; }
.trio .col + .col { border-left: 1px solid var(--line); }
.trio .k { font-family: var(--serif); font-size: 21px; font-weight: 600; }
.trio .of { font-size: 11px; color: var(--muted); }
.trio .t { font-size: 10px; letter-spacing: .12em; text-transform: uppercase; color: var(--muted); margin-top: 3px; }
.trio .mtrack { height: 4px; border-radius: 99px; background: var(--line); overflow: hidden; margin: 7px 4px 0; }
.trio .mtrack > i { display: block; height: 100%; background: var(--accent); border-radius: 99px; }

/* ---------- section labels ---------- */
.eyebrow { font-size: 11px; letter-spacing: .14em; text-transform: uppercase; color: var(--muted); font-weight: 700;
  display: flex; align-items: center; gap: 8px; margin: 24px 2px 10px; }
.eyebrow::after { content: ""; flex: 1; height: 1px; background: var(--line); }

/* ---------- chips (recents / favorites) ---------- */
.chips { display: flex; gap: 8px; overflow-x: auto; padding-bottom: 4px; scrollbar-width: none; }
.chips::-webkit-scrollbar { display: none; }
.chip { flex: none; display: inline-flex; align-items: center; gap: 6px; white-space: nowrap;
  background: var(--card); border: 1px solid var(--line); border-radius: 999px; padding: 8px 13px;
  font-size: 13px; font-weight: 600; transition: background .15s, transform .1s; }
.chip:active { transform: scale(.96); background: var(--accent-soft); }
.chip .cc { color: var(--muted); font-weight: 500; }
.chip.star { color: var(--accent); }

/* ---------- journal (today's entries) ---------- */
.journal { display: flex; flex-direction: column; }
.jrow { display: flex; align-items: baseline; gap: 12px; padding: 13px 2px; border-top: 1px solid var(--line);
  cursor: pointer; transition: background .12s; }
.jrow:first-child { border-top: none; }
.jrow:active { background: var(--card-2); }
.jrow .tm { font-size: 10.5px; letter-spacing: .07em; color: var(--muted); width: 42px; flex: none; padding-top: 4px; }
.jrow .body { flex: 1; min-width: 0; }
.jrow .dish { font-family: var(--serif); font-size: 16.5px; font-weight: 500; line-height: 1.25; }
.jrow .macs { font-size: 11.5px; color: var(--muted); margin-top: 2px; }
.jrow .kc { margin-left: auto; font-family: var(--serif); font-size: 17px; font-weight: 600; padding-top: 2px; white-space: nowrap; }
.jrow .kc small { font-family: var(--sans); font-size: 10px; color: var(--muted); font-weight: 600; }
.jrow.pending .dish { color: var(--muted); }
.jrow.error .dish { color: var(--danger); }
.spin { display: inline-block; width: 12px; height: 12px; border: 2px solid var(--line-strong); border-top-color: var(--accent);
  border-radius: 50%; animation: spin .7s linear infinite; vertical-align: -1px; margin-right: 6px; }
@keyframes spin { to { transform: rotate(360deg); } }
.empty { text-align: center; color: var(--muted); font-size: 14px; padding: 26px 10px; font-style: italic; font-family: var(--serif); }

/* entry detail actions */
.jdetail { padding: 4px 2px 14px 54px; display: flex; flex-wrap: wrap; gap: 8px; border-top: 1px dashed var(--line); }
.mini { font-size: 12.5px; font-weight: 600; padding: 7px 12px; border-radius: 10px; background: var(--card); border: 1px solid var(--line); }
.mini.danger { color: var(--danger); }
.assump { font-size: 12px; color: var(--muted); font-style: italic; padding: 8px 2px 0 54px; line-height: 1.45; }

/* ---------- coach button ---------- */
.coach-btn { margin: 22px 0 6px; display: flex; align-items: center; justify-content: center; gap: 9px;
  width: 100%; padding: 14px; border-radius: 14px; background: var(--accent); color: #fff; font-weight: 700; font-size: 15px;
  box-shadow: var(--shadow); transition: transform .1s, filter .15s; }
.coach-btn:active { transform: scale(.98); filter: brightness(.96); }
.coach-btn .em { font-size: 18px; }

/* ---------- input bar (fixed) ---------- */
.composer { position: fixed; left: 0; right: 0; bottom: 0; z-index: 20;
  padding: 10px 16px calc(var(--safe-b) + 10px); background: linear-gradient(to top, var(--paper) 72%, transparent);
  }
.composer .inner { max-width: 560px; margin: 0 auto; }
.refine-row { display: flex; align-items: center; gap: 8px; margin-bottom: 8px; padding-left: 4px; }
.switch { position: relative; width: 40px; height: 23px; border-radius: 99px; background: var(--line-strong); transition: background .2s; flex: none; }
.switch.on { background: var(--accent); }
.switch::after { content: ""; position: absolute; top: 2px; left: 2px; width: 19px; height: 19px; border-radius: 50%; background: #fff; transition: transform .2s; }
.switch.on::after { transform: translateX(17px); }
.refine-row label { font-size: 12.5px; color: var(--muted); font-weight: 600; }
.inputbar { display: flex; align-items: flex-end; gap: 8px; background: var(--card); border: 1px solid var(--line-strong);
  border-radius: 22px; padding: 7px 7px 7px 8px; box-shadow: var(--shadow); }
.inputbar textarea { flex: 1; border: none; background: none; resize: none; outline: none; font-size: 16px; line-height: 1.35;
  max-height: 108px; padding: 8px 4px; font-family: var(--sans); }
.round { width: 40px; height: 40px; border-radius: 50%; flex: none; display: grid; place-items: center; font-size: 17px; transition: transform .1s; }
.round:active { transform: scale(.9); }
.round.cam { background: var(--card-2); border: 1px solid var(--line); }
.round.send { background: var(--accent); color: #fff; }
.round.send:disabled { opacity: .4; }

/* ---------- questions (refine) ---------- */
.qbox { background: var(--card); border: 1px solid var(--line); border-radius: 16px; padding: 14px; margin-bottom: 10px; box-shadow: var(--shadow); }
.qbox h4 { margin: 0 0 4px; font-family: var(--serif); font-size: 16px; font-weight: 600; }
.qbox .hint { font-size: 12px; color: var(--muted); margin-bottom: 10px; }
.qitem { margin-bottom: 10px; }
.qitem p { margin: 0 0 7px; font-size: 13.5px; font-weight: 600; }
.qopts { display: flex; flex-wrap: wrap; gap: 7px; margin: 0 0 8px; }
.qopt { font-size: 13px; font-weight: 600; padding: 7px 12px; border-radius: 999px; background: var(--card-2); border: 1px solid var(--line); color: var(--ink); transition: background .12s, border-color .12s, color .12s, transform .1s; }
.qopt:active { transform: scale(.95); }
.qopt.sel { background: var(--accent); border-color: var(--accent); color: #fff; }
.qitem input { width: 100%; padding: 9px 11px; border-radius: 10px; border: 1px solid var(--line); background: var(--card-2); font-size: 15px; }
.qactions { display: flex; gap: 8px; margin-top: 4px; }
.btn { padding: 11px 15px; border-radius: 12px; font-weight: 700; font-size: 14px; }
.btn.primary { background: var(--accent); color: #fff; flex: 1; }
.btn.subtle { background: var(--card-2); border: 1px solid var(--line); color: var(--muted); }

/* ---------- auth / setup ---------- */
.auth { min-height: 100dvh; display: flex; flex-direction: column; justify-content: center; align-items: center;
  padding: calc(var(--safe-t) + 20px) 26px calc(var(--safe-b) + 20px); max-width: 460px; margin: 0 auto; text-align: center; }
.auth .brand { font-size: 40px; margin-bottom: 6px; }
.auth h1 { font-family: var(--serif); font-weight: 600; font-size: 30px; letter-spacing: -.01em; margin: 0 0 6px; }
.auth p.lede { color: var(--muted); font-size: 14.5px; margin: 0 0 26px; max-width: 34ch; }
.pin-dots { display: flex; gap: 14px; justify-content: center; margin: 10px 0 22px; }
.pin-dots i { width: 14px; height: 14px; border-radius: 50%; border: 2px solid var(--line-strong); transition: background .15s, border-color .15s; }
.pin-dots i.f { background: var(--accent); border-color: var(--accent); }
.pin-dots.err i { border-color: var(--danger); animation: shake .4s; }
@keyframes shake { 25% { transform: translateX(-7px); } 75% { transform: translateX(7px); } }
.keypad { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; width: 100%; max-width: 300px; }
.key { aspect-ratio: 1.5; border-radius: 16px; background: var(--card); border: 1px solid var(--line); font-family: var(--serif);
  font-size: 26px; font-weight: 600; display: grid; place-items: center; transition: transform .08s, background .12s; }
.key:active { transform: scale(.94); background: var(--accent-soft); }
.key.blank { background: none; border: none; }
.authmsg { min-height: 20px; font-size: 13.5px; color: var(--danger); margin-top: 14px; font-weight: 600; }

/* setup form */
.form { width: 100%; text-align: left; display: flex; flex-direction: column; gap: 14px; }
.field label { display: block; font-size: 12px; letter-spacing: .08em; text-transform: uppercase; color: var(--muted); font-weight: 700; margin-bottom: 5px; }
.field input, .field select { width: 100%; padding: 12px 13px; border-radius: 12px; border: 1px solid var(--line); background: var(--card); font-size: 16px; }
.two { display: flex; gap: 12px; } .two > * { flex: 1; }
.steps { font-size: 12px; color: var(--muted); letter-spacing: .1em; text-transform: uppercase; margin-bottom: 4px; }

/* ---------- sheets / modals ---------- */
.scrim { position: fixed; inset: 0; background: rgba(30, 18, 8, .42); z-index: 40; opacity: 0; pointer-events: none; transition: opacity .25s; }
.scrim.show { opacity: 1; pointer-events: auto; }
.sheet { position: fixed; left: 0; right: 0; bottom: 0; z-index: 41; background: var(--paper); border-radius: 24px 24px 0 0;
  max-width: 560px; margin: 0 auto; max-height: 88dvh; overflow-y: auto; transform: translateY(102%); transition: transform .32s cubic-bezier(.2,.8,.2,1);
  padding: 10px 20px calc(var(--safe-b) + 24px); box-shadow: 0 -10px 40px -12px rgba(0,0,0,.35); }
.sheet.show { transform: translateY(0); }
.grip { width: 40px; height: 5px; border-radius: 99px; background: var(--line-strong); margin: 6px auto 12px; }
.sheet h2 { font-family: var(--serif); font-weight: 600; font-size: 23px; margin: 4px 0 16px; }
.sheet h3 { font-size: 12px; letter-spacing: .1em; text-transform: uppercase; color: var(--muted); margin: 20px 0 8px; }

/* coach content (markdown) */
.coach-content { font-size: 15px; line-height: 1.6; }
.coach-content h1, .coach-content h2, .coach-content h3 { font-family: var(--serif); font-weight: 600; margin: 16px 0 6px; font-size: 18px; }
.coach-content p { margin: 0 0 10px; }
.coach-content ul { margin: 0 0 10px; padding-left: 20px; }
.coach-content li { margin: 3px 0; }
.coach-content strong { font-weight: 700; }
.coach-loading { text-align: center; padding: 30px; color: var(--muted); font-family: var(--serif); font-style: italic; }

/* settings rows */
.srow { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 12px 0; border-top: 1px solid var(--line); }
.srow:first-of-type { border-top: none; }
.srow .lab { font-size: 14.5px; }
.srow input { width: 96px; text-align: right; padding: 8px 10px; border-radius: 10px; border: 1px solid var(--line); background: var(--card); font-size: 15px; }
.srow input[type=text] { width: 150px; text-align: left; }
.export-row { display: flex; gap: 10px; margin-top: 10px; }
.export-row a { flex: 1; text-align: center; text-decoration: none; padding: 12px; border-radius: 12px; background: var(--card); border: 1px solid var(--line); color: var(--ink); font-weight: 700; font-size: 14px; }
.logout { width: 100%; margin-top: 18px; padding: 13px; border-radius: 12px; background: var(--card); border: 1px solid var(--line); color: var(--danger); font-weight: 700; }

/* ---------- toast ---------- */
.toast { position: fixed; left: 50%; bottom: calc(var(--safe-b) + 92px); transform: translate(-50%, 160%); z-index: 60;
  background: var(--ink); color: var(--paper); font-size: 13.5px; font-weight: 600; padding: 11px 17px; border-radius: 13px;
  box-shadow: var(--shadow); transition: transform .3s cubic-bezier(.2,.8,.2,1); max-width: 90vw; text-align: center;
  display: flex; align-items: center; gap: 4px; }
.toast.show { transform: translate(-50%, 0); }
.toast-act { background: none; border: none; color: var(--paper); font-weight: 800; font-size: 13.5px;
  margin-left: 10px; text-decoration: underline; text-underline-offset: 3px; white-space: nowrap; }

/* ---------- entry detail extras ---------- */
.jitems { padding: 8px 2px 2px 54px; }
.jitems .jit { display: flex; justify-content: space-between; gap: 12px; font-size: 12.5px; color: var(--muted); padding: 2.5px 0; }
.jitems .jit b { color: var(--ink); font-weight: 600; }
.mini.accent { color: var(--accent); background: var(--accent-soft); border-color: transparent; }

/* ---------- offline banner ---------- */
.ob-banner { margin-top: 12px; background: var(--accent-soft); border: 1px solid var(--line-strong); color: var(--ink);
  font-size: 12.5px; font-weight: 600; padding: 9px 13px; border-radius: 12px; }

/* ---------- sheet hint ---------- */
.sheet-hint { font-size: 13px; color: var(--muted); margin: -8px 0 14px; line-height: 1.45; }

/* ---------- week overview ---------- */
.wk-stats { display: flex; margin: 2px 0 18px; }
.wk-stats > div { flex: 1; text-align: center; }
.wk-stats > div + div { border-left: 1px solid var(--line); }
.wk-stats b { display: block; font-family: var(--serif); font-size: 21px; font-weight: 600; }
.wk-stats span { font-size: 10px; letter-spacing: .11em; text-transform: uppercase; color: var(--muted); }
.wk-chart { display: flex; flex-direction: column; gap: 4px; }
.wk-row { display: flex; align-items: center; gap: 10px; width: 100%; padding: 5px 0; background: none; border: none; text-align: left; border-radius: 8px; }
.wk-row:active { background: var(--card-2); }
.wk-day { width: 26px; flex: none; font-size: 11.5px; font-weight: 600; color: var(--muted); }
.wk-row.today .wk-day { color: var(--ink); font-weight: 800; }
.wk-track { flex: 1; position: relative; height: 11px; background: var(--line); border-radius: 6px; display: flex; align-items: stretch; overflow: visible; }
.wk-in { display: block; background: var(--accent); border-radius: 6px 4px 4px 6px; min-width: 0; }
.wk-over { display: block; background: var(--danger); border-radius: 4px; margin-left: 2px; }
.wk-rule { position: absolute; top: -3px; bottom: -3px; width: 0; border-left: 1.5px dashed var(--line-strong); }
.wk-val { width: 58px; flex: none; text-align: right; font-size: 12.5px; font-weight: 700; }
.wk-note { font-size: 11px; color: var(--muted); margin-top: 14px; line-height: 1.5; }

/* ---------- favorites management ---------- */
.favrow { display: flex; align-items: center; gap: 10px; padding: 10px 0; border-top: 1px solid var(--line); }
.favrow:first-child { border-top: none; }
.favlab { flex: 1; min-width: 0; font-size: 14px; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.favkc { color: var(--muted); font-size: 12.5px; }
.favx { width: 30px; height: 30px; border-radius: 50%; background: var(--card-2); border: 1px solid var(--line); color: var(--muted); font-size: 13px; flex: none; }
.hintrow { font-size: 13px; color: var(--muted); font-style: italic; padding: 6px 0; }

@media (prefers-reduced-motion: reduce) { * { transition: none !important; animation: none !important; } }
