/* Layout: one narrow column, sticky day bar, type buttons up top, timeline + list below */
:root {
  --bg: #f3f5f7;
  --surface: #ffffff;
  --fg: #14202b;
  --muted: #5d6b78;
  --line: #dbe1e7;
  --accent: #0b6e8a;
  --accent-fg: #ffffff;
  --danger: #b4232f;
  --t-meal: #2f7d32;
  --t-snack: #c07a00;
  --t-drink: #1f6fc2;
  --t-alc: #a23b72;
  --t-move: #00897b;
  --t-note: #6b6f76;
  --shadow: 0 1px 2px rgba(20,32,43,.06), 0 4px 16px rgba(20,32,43,.06);
  --sans: "IBM Plex Sans", system-ui, -apple-system, "Segoe UI", sans-serif;
  --mono: "IBM Plex Mono", ui-monospace, "SF Mono", Menlo, monospace;
}
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) {
  --bg: #0f151b; --surface: #18212a; --fg: #e6edf3; --muted: #93a2b1; --line: #2a3642;
  --accent: #4fb3d1; --accent-fg: #06222c; --danger: #ff6b76;
  --t-meal: #6cc070; --t-snack: #f0b23e; --t-drink: #6aa9f0; --t-alc: #e07ab4; --t-move: #4fc9bb; --t-note: #a3a9b1;
  --shadow: 0 1px 2px rgba(0,0,0,.3); color-scheme: dark; } }
:root[data-theme="dark"] {
  --bg: #0f151b; --surface: #18212a; --fg: #e6edf3; --muted: #93a2b1; --line: #2a3642;
  --accent: #4fb3d1; --accent-fg: #06222c; --danger: #ff6b76;
  --t-meal: #6cc070; --t-snack: #f0b23e; --t-drink: #6aa9f0; --t-alc: #e07ab4; --t-move: #4fc9bb; --t-note: #a3a9b1;
  --shadow: 0 1px 2px rgba(0,0,0,.3); color-scheme: dark; }

* { box-sizing: border-box; }
[hidden] { display: none !important; }
body { background: var(--bg); color: var(--fg); font-family: var(--sans); font-size: 16px; line-height: 1.45; }
body::before { content: ""; position: fixed; inset: 0 0 auto; height: env(safe-area-inset-top, 0px); z-index: 10; background: var(--surface); }
.wrap { max-width: 640px; margin: 0 auto; padding-left: max(16px, env(safe-area-inset-left, 0px)); padding-right: max(16px, env(safe-area-inset-right, 0px)); padding-block: 0 96px; display: flex; flex-direction: column; gap: 16px; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

header.bar { position: sticky; top: env(safe-area-inset-top, 0px); z-index: 5; background: var(--surface); border-bottom: 1px solid var(--line); padding: 10px max(16px, env(safe-area-inset-right, 0px)) 10px max(16px, env(safe-area-inset-left, 0px)); }
.bar-row { display: flex; align-items: center; gap: 8px; max-width: 640px; margin: 0 auto; }
.brand { font-weight: 700; font-size: 15px; letter-spacing: .01em; flex: 1; min-width: 0; }
.brand small { display: block; font-weight: 500; font-size: 12px; color: var(--muted); }
.sync { font-size: 12px; color: var(--muted); display: flex; align-items: center; gap: 6px; }
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--muted); }
.sync.ok .dot { background: var(--t-meal); }
.sync.warn .dot { background: var(--t-snack); }
.iconbtn { border: 1px solid var(--line); background: var(--surface); border-radius: 10px; height: 38px; min-width: 38px; padding: 0 10px; display: inline-flex; align-items: center; justify-content: center; gap: 6px; font-size: 14px; }

h2 { font-size: 13px; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); margin: 0; font-weight: 600; }
.types { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.tbtn { border: 1px solid var(--line); background: var(--surface); border-radius: 14px; padding: 12px 6px 10px; display: flex; flex-direction: column; align-items: center; gap: 6px; font-weight: 600; font-size: 14px; box-shadow: var(--shadow); }
.tbtn svg { width: 26px; height: 26px; }
.tbtn:active { transform: scale(.97); }

.card { background: var(--surface); border: 1px solid var(--line); border-radius: 16px; padding: 16px; box-shadow: var(--shadow); }
form.card { scroll-margin-top: 72px; display: flex; flex-direction: column; gap: 14px; }
.form-head { display: flex; align-items: center; gap: 10px; }
.form-head .title { font-weight: 700; font-size: 18px; flex: 1; }
.seg { display: flex; flex-wrap: wrap; gap: 6px; }
.seg button { border: 1px solid var(--line); background: transparent; border-radius: 999px; padding: 6px 12px; font-size: 14px; font-weight: 500; }
.seg button[aria-pressed="true"] { background: var(--tc, var(--accent)); border-color: var(--tc, var(--accent)); color: #fff; }
label.f { display: flex; flex-direction: column; gap: 4px; font-size: 13px; color: var(--muted); font-weight: 500; min-width: 0; }
.f input, .f textarea { border: 1px solid var(--line); background: var(--bg); border-radius: 10px; padding: 10px 12px; font-size: 16px; color: var(--fg); width: 100%; min-width: 0; }
.f textarea { resize: vertical; min-height: 48px; }
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.timerow { display: flex; gap: 6px; align-items: flex-end; flex-wrap: wrap; }
.timerow label.f { flex: 1 1 100%; }
.timerow .nudge { flex: 1; }
.timerow input { font-family: var(--mono); }
.nudge { border: 1px solid var(--line); background: transparent; border-radius: 10px; height: 44px; padding: 0 10px; font-family: var(--mono); font-size: 14px; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { border: 1px dashed var(--line); background: transparent; border-radius: 999px; padding: 5px 10px; font-size: 13px; max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.photo-row { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.photo-row img { width: 72px; height: 72px; object-fit: cover; border-radius: 10px; border: 1px solid var(--line); }
.filebtn { position: relative; overflow: hidden; }
.filebtn input { position: absolute; inset: 0; opacity: 0; cursor: pointer; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; }
.primary { background: var(--accent); color: var(--accent-fg); border: 0; border-radius: 12px; padding: 12px 18px; font-weight: 700; font-size: 16px; flex: 1; }
.ghost { background: transparent; border: 1px solid var(--line); border-radius: 12px; padding: 12px 14px; font-weight: 500; }
.danger { color: var(--danger); border-color: color-mix(in srgb, var(--danger) 40%, var(--line)); }
.hint { font-size: 12px; color: var(--muted); }

.daynav { display: flex; align-items: center; gap: 8px; }
.daynav .d { flex: 1; text-align: center; font-weight: 700; }
.daynav .d small { display: block; font-weight: 500; color: var(--muted); font-size: 12px; }
.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; text-align: center; }
.stat b { display: block; font-family: var(--mono); font-size: 20px; font-variant-numeric: tabular-nums; }
.stat span { font-size: 12px; color: var(--muted); }

.timeline { position: relative; height: 34px; margin: 6px 0 2px; }
.timeline .axis { position: absolute; left: 0; right: 0; top: 16px; height: 2px; background: var(--line); border-radius: 2px; }
.timeline .tick { position: absolute; top: 22px; font-family: var(--mono); font-size: 10px; color: var(--muted); transform: translateX(-50%); }
.timeline .m { position: absolute; top: 10px; width: 14px; height: 14px; border-radius: 50%; border: 2px solid var(--surface); transform: translateX(-50%); }

.list { display: flex; flex-direction: column; }
.entry { display: grid; grid-template-columns: 56px 1fr auto; gap: 10px; align-items: start; padding: 12px 0; border-top: 1px solid var(--line); background: none; border-left: 0; border-right: 0; border-bottom: 0; text-align: left; width: 100%; }
.entry:first-child { border-top: 0; }
.entry .time { font-family: var(--mono); font-weight: 600; font-size: 15px; font-variant-numeric: tabular-nums; padding-top: 1px; }
.entry .body { min-width: 0; }
.entry .desc { font-weight: 600; overflow-wrap: anywhere; }
.entry .meta { font-size: 13px; color: var(--muted); display: flex; flex-wrap: wrap; gap: 4px 10px; align-items: center; }
.pill { display: inline-flex; align-items: center; gap: 5px; font-size: 12px; font-weight: 600; color: var(--tc); }
.pill::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: var(--tc); }
.entry img { width: 52px; height: 52px; object-fit: cover; border-radius: 8px; border: 1px solid var(--line); }
.empty { text-align: center; color: var(--muted); padding: 22px 8px; font-size: 14px; }
.notice { font-size: 13px; color: var(--muted); background: color-mix(in srgb, var(--t-snack) 12%, transparent); border-radius: 10px; padding: 8px 12px; }
.export { display: flex; gap: 8px; flex-wrap: wrap; }
.export button { flex: 1 1 140px; }
.toast { position: fixed; left: 50%; bottom: calc(20px + env(safe-area-inset-bottom, 0px)); transform: translateX(-50%); background: var(--fg); color: var(--bg); padding: 10px 16px; border-radius: 12px; font-size: 14px; z-index: 20; max-width: calc(100% - 32px); }
textarea.copy { width: 100%; min-height: 120px; font-family: var(--mono); font-size: 12px; border: 1px solid var(--line); border-radius: 10px; background: var(--bg); color: var(--fg); padding: 8px; }
@media (max-width: 380px) { .types { grid-template-columns: repeat(2, 1fr); } }
@media (prefers-reduced-motion: reduce) { * { transition: none !important; } }

/* PWA additions */
html, body { margin: 0; }
img { max-width: 100%; }
body { padding-top: env(safe-area-inset-top, 0px); -webkit-tap-highlight-color: transparent; overscroll-behavior-y: contain; }
.login { min-height: 80vh; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 18px; text-align: center; padding: 24px; }
.login img { width: 96px; height: 96px; border-radius: 22px; }
.login h1 { margin: 0; font-size: 26px; }
.login p { margin: 0; color: var(--muted); max-width: 32ch; }
.login .primary { flex: none; min-width: 240px; }
.avatar { width: 34px; height: 34px; border-radius: 50%; border: 1px solid var(--line); background: var(--bg); padding: 0; overflow: hidden; display: inline-flex; align-items: center; justify-content: center; font-weight: 700; font-size: 14px; }
.avatar img { width: 100%; height: 100%; object-fit: cover; }
.menu { position: absolute; right: max(16px, env(safe-area-inset-right, 0px)); top: 58px; background: var(--surface); border: 1px solid var(--line); border-radius: 12px; box-shadow: var(--shadow); padding: 6px; display: flex; flex-direction: column; min-width: 200px; z-index: 30; }
.menu button, .menu .who { text-align: left; background: none; border: 0; padding: 10px 12px; border-radius: 8px; font-size: 15px; }
.menu .who { color: var(--muted); font-size: 13px; overflow-wrap: anywhere; }
.menu button:hover { background: var(--bg); }
.installbar { display: flex; gap: 10px; align-items: center; }
.installbar span { flex: 1; font-size: 14px; }
.lightbox { position: fixed; inset: 0; background: rgba(0,0,0,.85); display: flex; align-items: center; justify-content: center; z-index: 40; padding: 16px; }
.lightbox img { max-height: 100%; border-radius: 8px; }
.entry { cursor: pointer; }
.est-btn { align-self: flex-start; }
.est { background: color-mix(in srgb, var(--accent) 8%, transparent); border: 1px solid color-mix(in srgb, var(--accent) 30%, var(--line)); border-radius: 12px; padding: 10px 12px; font-size: 14px; display: flex; flex-direction: column; gap: 4px; }
.est-head { font-weight: 700; font-size: 16px; }
.est-head span { font-weight: 400; color: var(--muted); font-size: 13px; }
.est-item { display: flex; justify-content: space-between; gap: 10px; font-variant-numeric: tabular-nums; }
.est-item span { min-width: 0; overflow-wrap: anywhere; }
.scanbtn { border: 1px dashed var(--line); background: var(--surface); border-radius: 14px; padding: 12px; display: flex; align-items: center; justify-content: center; gap: 10px; font-weight: 600; font-size: 15px; }
.scanbtn svg { width: 24px; height: 24px; color: var(--accent); }
.scanner { position: fixed; inset: 0; z-index: 35; background: var(--bg); overflow-y: auto; display: flex; flex-direction: column; gap: 12px; padding: calc(12px + env(safe-area-inset-top, 0px)) max(16px, env(safe-area-inset-right, 0px)) calc(24px + env(safe-area-inset-bottom, 0px)) max(16px, env(safe-area-inset-left, 0px)); }
.scan-top { display: flex; align-items: center; justify-content: space-between; gap: 10px; font-size: 17px; }
.scan-view { position: relative; background: #000; border-radius: 16px; overflow: hidden; aspect-ratio: 4 / 3; max-width: 100%; }
.scan-view video { width: 100%; height: 100%; object-fit: cover; display: block; }
.scan-frame { position: absolute; left: 10%; right: 10%; top: 32%; bottom: 32%; border: 3px solid rgba(255,255,255,.9); border-radius: 12px; box-shadow: 0 0 0 999px rgba(0,0,0,.35); }
.scan-msg { position: absolute; left: 0; right: 0; bottom: 8px; margin: 0; text-align: center; color: #fff; font-size: 14px; text-shadow: 0 1px 3px #000; padding: 0 12px; }
.scan-manual { display: flex; gap: 8px; align-items: flex-end; }
.scan-manual label { flex: 1; }
.scan-manual button { height: 46px; }
.product { display: flex; flex-direction: column; gap: 10px; }
.prod-name { font-weight: 700; font-size: 17px; overflow-wrap: anywhere; }
.prod-carbs { font-family: var(--mono); font-size: 22px; font-weight: 600; font-variant-numeric: tabular-nums; }
