:root {
  --bg: #0a0a0c;
  --card: #141418;
  --card-2: #1c1c22;
  --line: #26262e;
  --text: #f3f3f6;
  --muted: #9b9ba8;
  --faint: #6b6b78;
  --accent: #ef3b3b;
  --accent-2: #ff6b4a;
  --green: #34c77b;
  --amber: #f5a524;
  --blue: #4c8dff;
  --input-bg: #0f0f13;
  --focus: #4a4a57;
  --nav-bg: rgba(14, 14, 18, .88);
  --nav-bg-solid: #0e0e12;
  --danger-text: #ff7b7b;
  --warn-text: #ffd28a;
  --good-text: #9ff0c4;
  --bad-text: #ffb3b3;
  --fav: #ffd166;
  --spinner-track: rgba(255, 255, 255, .2);
  --spinner-head: #fff;
  --backdrop: rgba(0, 0, 0, .6);
  --radius: 18px;
  --nav-h: 62px;
  --safe-t: env(safe-area-inset-top, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
  --vvh: 100dvh;
  --vv-top: 0px;
  --app-h: 100dvh;
  --screen-h: 100dvh;
  color-scheme: dark;
}

/* Soft light theme: warm grey paper instead of pure white, muted contrast */
:root[data-theme="light"] {
  --bg: #e9e7e1;
  --card: #f6f5f1;
  --card-2: #eeece6;
  --line: #d9d5cc;
  --text: #22222a;
  --muted: #676672;
  --faint: #97959c;
  --accent: #d63232;
  --accent-2: #e8563a;
  --green: #1e9a59;
  --amber: #c07a0c;
  --blue: #2e6bd6;
  --input-bg: #fbfaf7;
  --focus: #b3ada2;
  --nav-bg: rgba(246, 245, 241, .92);
  --nav-bg-solid: #f1efea;
  --danger-text: #c0392b;
  --warn-text: #875a06;
  --good-text: #16704a;
  --bad-text: #a33a3a;
  --fav: #b7791f;
  --spinner-track: rgba(0, 0, 0, .12);
  --spinner-head: #55555e;
  --backdrop: rgba(40, 36, 30, .35);
  color-scheme: light;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; background: var(--bg); color: var(--text); }
body {
  font: 15px/1.45 -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  -webkit-text-size-adjust: 100%;
  min-height: var(--app-h);
  overscroll-behavior-y: none;
}
[hidden] { display: none !important; }
img { max-width: 100%; display: block; }
a { color: inherit; text-decoration: none; }
h1, h2, h3 { margin: 0; letter-spacing: -0.01em; }
h1 { font-size: 26px; font-weight: 750; }
h2 { font-size: 16px; font-weight: 650; }
h3 { font-size: 17px; font-weight: 650; }
p { margin: 0; }
button, input, select, textarea { font: inherit; color: inherit; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.center { display: flex; align-items: center; justify-content: center; padding: 32px; }

/* ---------- buttons & inputs ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 42px; padding: 0 16px; border-radius: 12px; border: 1px solid var(--line);
  background: var(--card-2); color: var(--text); font-weight: 600; cursor: pointer; white-space: nowrap;
  transition: transform .08s ease, background .15s ease, opacity .15s;
}
.btn:active { transform: scale(.97); }
.btn:disabled { opacity: .5; pointer-events: none; }
.btn.primary { background: linear-gradient(135deg, var(--accent), var(--accent-2)); border-color: transparent; color: #fff; }
.btn.ghost { background: transparent; }
.btn.danger { color: var(--danger-text); }
.btn.small { min-height: 34px; padding: 0 12px; font-size: 13px; border-radius: 10px; }
.btn.block { width: 100%; }
.btn svg { width: 18px; height: 18px; }

.icon-btn {
  display: inline-flex; align-items: center; justify-content: center; width: 40px; height: 40px; flex: none;
  border-radius: 12px; border: 1px solid var(--line); background: var(--card-2); color: var(--text); cursor: pointer;
}
.icon-btn:disabled { opacity: .6; }
.icon-btn svg { width: 20px; height: 20px; }
.icon-btn.small { width: 32px; height: 32px; border-radius: 9px; }
.icon-btn.small svg { width: 16px; height: 16px; }
.icon-btn.plain { border-color: transparent; background: transparent; }

svg { fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }

input, select, textarea {
  width: 100%; min-height: 44px; padding: 10px 12px; border-radius: 12px;
  border: 1px solid var(--line); background: var(--input-bg); font-size: 16px; outline: none;
  transition: border-color .15s;
}
textarea { resize: vertical; min-height: 80px; }
input:focus, select:focus, textarea:focus { border-color: var(--focus); }
input[type="checkbox"] { width: 20px; height: 20px; min-height: 0; accent-color: var(--accent); }
select { appearance: none; background-image: linear-gradient(45deg, transparent 50%, var(--muted) 50%), linear-gradient(135deg, var(--muted) 50%, transparent 50%); background-position: calc(100% - 18px) 55%, calc(100% - 13px) 55%; background-size: 5px 5px; background-repeat: no-repeat; padding-right: 32px; }
label.field { display: flex; flex-direction: column; gap: 6px; font-size: 13px; color: var(--muted); }
label.check { display: flex; align-items: center; gap: 10px; font-size: 15px; color: var(--text); min-height: 44px; }
.file-input { position: absolute; width: 1px; height: 1px; opacity: 0; overflow: hidden; pointer-events: none; }

/* ---------- layout ---------- */
.nav {
  position: fixed; left: 0; right: 0; top: calc(var(--app-h) - var(--nav-h) - var(--safe-b)); z-index: 20;
  display: flex; justify-content: space-around; align-items: stretch;
  height: calc(var(--nav-h) + var(--safe-b)); padding-bottom: var(--safe-b);
  background: var(--nav-bg-solid);
  border-top: 1px solid var(--line);
}
.nav .brand { display: none; }
.nav a {
  flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px;
  color: var(--faint); font-size: 11px; font-weight: 600;
}
.nav a svg { width: 24px; height: 24px; }
.nav a.active { color: var(--text); }
.nav a.active svg { color: var(--accent); }

.view {
  max-width: 1120px; margin: 0 auto;
  padding: calc(var(--safe-t) + 16px) 16px calc(var(--nav-h) + var(--safe-b) + 24px);
}

@media (min-width: 900px) {
  .nav {
    top: 0; right: auto; width: 236px; height: 100vh; padding: 20px 14px;
    flex-direction: column; justify-content: flex-start; gap: 4px;
    border-top: 0; border-right: 1px solid var(--line); background: var(--nav-bg-solid);
  }
  .nav .brand { display: flex; align-items: center; gap: 10px; padding: 4px 10px 22px; font-weight: 750; font-size: 18px; }
  .nav .brand img { width: 34px; height: 34px; border-radius: 9px; }
  .nav a { flex: none; flex-direction: row; justify-content: flex-start; gap: 12px; padding: 11px 12px; border-radius: 12px; font-size: 15px; }
  .nav a:hover { background: var(--card); color: var(--text); }
  .nav a.active { background: var(--card-2); }
  .view { margin-left: 236px; margin-right: 0; max-width: none; padding: 32px 40px 48px; }
  .view > * { max-width: 1120px; }
}

.page-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 16px; }
.page-head .sub { color: var(--muted); font-size: 14px; margin-top: 2px; }

.grid { display: grid; gap: 14px; grid-template-columns: 1fr; }
@media (min-width: 760px) {
  .grid { grid-template-columns: 1fr 1fr; }
  .span2 { grid-column: span 2; }
}

.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; min-width: 0; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 12px; }
.link { color: var(--muted); font-size: 14px; font-weight: 600; }
.pill { font-size: 12px; font-weight: 650; padding: 4px 9px; border-radius: 999px; background: var(--card-2); color: var(--muted); border: 1px solid var(--line); white-space: nowrap; }
.pill.good { color: var(--green); }
.pill.bad { color: var(--danger-text); }
.notice { display: block; padding: 12px 14px; margin-bottom: 14px; border-radius: 14px; background: rgba(245, 165, 36, .1); border: 1px solid rgba(245, 165, 36, .35); color: var(--warn-text); font-size: 14px; }
.empty { color: var(--muted); padding: 10px 0; font-size: 14px; }
.error-box { padding: 16px; border-radius: 14px; border: 1px solid rgba(239, 59, 59, .4); background: rgba(239, 59, 59, .08); color: var(--bad-text); }

.spinner { width: 18px; height: 18px; border-radius: 50%; border: 2px solid var(--spinner-track); border-top-color: var(--spinner-head); animation: spin .8s linear infinite; display: inline-block; }
@keyframes spin { to { transform: rotate(360deg); } }
.skeleton { height: 140px; border-radius: var(--radius); background: linear-gradient(90deg, var(--card) 0%, var(--card-2) 50%, var(--card) 100%); background-size: 200% 100%; animation: shimmer 1.2s infinite; }
@keyframes shimmer { to { background-position: -200% 0; } }

/* ---------- today ---------- */
.cam-btn { position: relative; }
.kcal-card .kcal-top { display: flex; align-items: center; gap: 18px; }
.ring { position: relative; width: 132px; height: 132px; flex: none; }
.ring svg { width: 100%; height: 100%; }
.ring-bg { stroke: var(--card-2); stroke-width: 11; }
.ring-fg { stroke: var(--green); stroke-width: 11; transition: stroke-dashoffset .6s ease; }
.ring.warn .ring-fg { stroke: var(--amber); }
.ring.over .ring-fg { stroke: var(--accent); }
.ring-center { position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; text-align: center; }
.ring-center b { font-size: 26px; font-weight: 750; line-height: 1.1; }
.ring-center span { font-size: 11px; color: var(--muted); max-width: 90px; }
.kcal-stats { display: grid; gap: 8px; flex: 1; min-width: 0; }
.kcal-stat { display: flex; justify-content: space-between; gap: 8px; font-size: 14px; }
.kcal-stat span { color: var(--muted); }
.kcal-stat b { font-weight: 650; }
.macros { display: grid; gap: 10px; margin-top: 16px; }
.macro-top { display: flex; justify-content: space-between; font-size: 13px; margin-bottom: 5px; }
.macro-top span { color: var(--muted); }
.bar { height: 7px; border-radius: 99px; background: var(--card-2); overflow: hidden; }
.bar > div { height: 100%; border-radius: 99px; background: var(--blue); transition: width .5s ease; }
.bar.protein > div { background: #e05dff; }
.bar.fat > div { background: var(--amber); }
.bar.carbs > div { background: var(--blue); }
.bar.over > div { background: var(--accent); }

.weight-main { display: flex; align-items: baseline; gap: 8px; flex-wrap: wrap; }
.weight-main b { font-size: 38px; font-weight: 750; letter-spacing: -0.02em; line-height: 1.1; }
.weight-main .unit { color: var(--muted); font-size: 16px; }
.delta { font-size: 14px; font-weight: 650; }
.delta.down { color: var(--green); }
.delta.up { color: var(--danger-text); }
.progress { height: 10px; background: var(--card-2); border-radius: 99px; overflow: hidden; margin: 14px 0 6px; }
.progress > div { height: 100%; background: linear-gradient(90deg, var(--accent), var(--green)); border-radius: 99px; }
.weight-meta { display: flex; justify-content: space-between; font-size: 13px; color: var(--muted); }
.inline-form { display: flex; gap: 8px; margin-top: 14px; }
.inline-form input { flex: 1; min-width: 0; }

.rhythm-card .since { display: flex; align-items: baseline; gap: 8px; flex-wrap: wrap; }
.rhythm-card .since b { font-size: 28px; font-weight: 750; }
.rhythm-card .since span { color: var(--muted); font-size: 14px; }
.rhythm-text { margin-top: 8px; padding: 10px 12px; border-radius: 12px; font-size: 14px; background: var(--card-2); }
.rhythm-card.good .rhythm-text { background: rgba(52, 199, 123, .1); color: var(--good-text); }
.rhythm-card.warn .rhythm-text { background: rgba(245, 165, 36, .12); color: var(--warn-text); }
.rhythm-card.bad .rhythm-text { background: rgba(239, 59, 59, .12); color: var(--bad-text); }
.rhythm-card.bad .since b { color: var(--danger-text); }
.rhythm-card.warn .since b { color: var(--amber); }
.rhythm-meta { margin-top: 10px; font-size: 13px; color: var(--muted); }
.timeline { margin-top: 16px; }
.tl-track { position: relative; height: 26px; border-radius: 99px; background: var(--card-2); }
.tl-dot { position: absolute; top: 50%; width: var(--s, 12px); height: var(--s, 12px); transform: translate(-50%, -50%); border-radius: 50%; background: var(--green); border: 2px solid var(--card); }
.tl-dot.alc { background: var(--amber); }
.tl-dot.over { background: var(--accent); }
.tl-now { position: absolute; top: -4px; bottom: -4px; width: 2px; background: var(--text); opacity: .7; border-radius: 2px; }
.tl-labels { display: flex; justify-content: space-between; font-size: 11px; color: var(--faint); margin-top: 4px; padding: 0 2px; }

.analysis .headline { font-size: 17px; font-weight: 650; margin-bottom: 10px; }
.analysis .focus { padding: 10px 12px; border-radius: 12px; background: rgba(239, 59, 59, .1); border: 1px solid rgba(239, 59, 59, .3); font-size: 14px; margin-bottom: 12px; }
.analysis.good .focus { background: rgba(52, 199, 123, .08); border-color: rgba(52, 199, 123, .3); }
.points { list-style: none; margin: 0 0 10px; padding: 0; display: grid; gap: 10px; }
.points li { display: flex; gap: 10px; }
.points .pt-ico { flex: none; width: 22px; text-align: center; }
.points b { display: block; font-size: 14px; }
.points p { color: var(--muted); font-size: 14px; }
@media (min-width: 760px) { .points { grid-template-columns: 1fr 1fr; gap: 14px 20px; } }

.list { display: grid; gap: 8px; }
.row { display: flex; align-items: center; gap: 12px; padding: 8px; margin: 0 -8px; border-radius: 12px; cursor: pointer; }
.row:hover { background: var(--card-2); }
.row .thumb { width: 44px; height: 44px; }
.row-main { flex: 1; min-width: 0; }
.row-title { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.row-sub { font-size: 13px; color: var(--muted); }
.row-kcal { font-weight: 700; white-space: nowrap; }
.row-kcal.burn { color: var(--amber); }
.thumb { width: 56px; height: 56px; border-radius: 12px; object-fit: cover; flex: none; background: var(--card-2); }
.thumb.ph { display: flex; align-items: center; justify-content: center; font-size: 22px; }

.badge { display: inline-block; font-size: 11px; font-weight: 700; padding: 2px 7px; border-radius: 99px; margin-left: 6px; vertical-align: 1px; }
.badge.warn { background: rgba(245, 165, 36, .15); color: var(--amber); }
.badge.bad { background: rgba(239, 59, 59, .15); color: var(--danger-text); }
.badge.alc { background: rgba(245, 165, 36, .15); color: var(--warn-text); }

.week-tiles { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; }
@media (min-width: 760px) { .week-tiles { grid-template-columns: repeat(4, 1fr); } }
.tile { background: var(--card-2); border-radius: 14px; padding: 12px; min-width: 0; }
.tile span { display: block; font-size: 12px; color: var(--muted); }
.tile b { display: block; font-size: 20px; font-weight: 700; margin-top: 2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tile small { color: var(--faint); font-size: 12px; }

/* ---------- diary ---------- */
.day-nav { display: flex; align-items: center; gap: 8px; margin-bottom: 14px; }
.day-nav .day-title { flex: 1; text-align: center; position: relative; }
.day-nav .day-title b { font-size: 18px; }
.day-nav .day-title input { position: absolute; inset: 0; opacity: 0; cursor: pointer; }
.day-summary { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; margin-bottom: 14px; }
.day-summary .tile b { font-size: 17px; }
.section { margin-bottom: 18px; }
.section-head { display: flex; align-items: center; justify-content: space-between; margin: 0 2px 8px; }
.section-head h2 { font-size: 15px; color: var(--muted); font-weight: 650; text-transform: uppercase; letter-spacing: .04em; }
.meal-card { display: flex; gap: 12px; align-items: center; padding: 12px; background: var(--card); border: 1px solid var(--line); border-radius: 16px; cursor: pointer; margin-bottom: 8px; }
.meal-card:active { background: var(--card-2); }
.meal-info { flex: 1; min-width: 0; }
.meal-title { font-weight: 650; overflow: hidden; text-overflow: ellipsis; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
.meal-sub { font-size: 13px; color: var(--muted); margin-top: 2px; }
.macros-inline { font-size: 12px; color: var(--faint); margin-top: 2px; }
.meal-kcal { text-align: right; flex: none; }
.meal-kcal b { display: block; font-size: 18px; font-weight: 750; }
.meal-kcal span { font-size: 11px; color: var(--muted); }
.add-row { display: flex; gap: 8px; flex-wrap: wrap; }

/* ---------- quick add (favorites & frequent) ---------- */
.quick-label { font-size: 12px; color: var(--muted); font-weight: 650; margin: 2px 0 8px; }
.quick-list {
  display: flex; gap: 8px; overflow-x: auto; margin: 0 -16px 10px; padding: 0 16px 4px;
  scroll-snap-type: x proximity; -webkit-overflow-scrolling: touch; scrollbar-width: none;
}
.quick-list::-webkit-scrollbar { display: none; }
.quick-item {
  flex: none; width: 176px; display: flex; align-items: center; gap: 10px; padding: 8px; border-radius: 14px;
  background: var(--card-2); border: 1px solid var(--line); text-align: left; cursor: pointer; scroll-snap-align: start;
}
.quick-item:active { transform: scale(.98); }
.quick-item img, .quick-item .qi-ph {
  width: 42px; height: 42px; border-radius: 10px; object-fit: cover; flex: none; background: var(--card);
  display: flex; align-items: center; justify-content: center; font-size: 19px;
}
.qi-text { min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.qi-text b { font-size: 13px; font-weight: 650; line-height: 1.25; overflow: hidden; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
.qi-text small { color: var(--muted); font-size: 12px; }
.quick-kcal b { font-size: 30px; font-weight: 750; }
.quick-kcal span { color: var(--muted); }
.fav-on { color: var(--fav); border-color: rgba(255, 209, 102, .4); }
@media (min-width: 760px) {
  .quick-list { flex-wrap: wrap; overflow: visible; margin: 0 0 10px; padding: 0; }
}

/* ---------- products & barcode scanner ---------- */
.scanner { position: relative; width: 100%; aspect-ratio: 4 / 3; max-height: 52vh; border-radius: 16px; overflow: hidden; background: #000; }
.scanner video { width: 100%; height: 100%; object-fit: cover; display: block; }
.scan-frame { position: absolute; left: 10%; right: 10%; top: 30%; bottom: 30%; border: 2px solid rgba(255,255,255,.9); border-radius: 12px; box-shadow: 0 0 0 9999px rgba(0,0,0,.35); pointer-events: none; }
.scan-status { text-align: center; color: var(--muted); font-size: 14px; }
.product-list { display: grid; gap: 8px; }
.product-row { display: flex; align-items: center; gap: 10px; width: 100%; padding: 8px; border-radius: 14px; background: var(--card-2); border: 1px solid var(--line); text-align: left; cursor: pointer; }
.product-row .qi-text { flex: 1; }
.product-row img, .product-row .qi-ph, .product-head img, .product-head .qi-ph { width: 46px; height: 46px; border-radius: 10px; object-fit: contain; flex: none; background: #fff; display: flex; align-items: center; justify-content: center; font-size: 20px; }
.product-head { display: flex; gap: 12px; align-items: center; }
.product-head img, .product-head .qi-ph { width: 64px; height: 64px; }
.pr-kcal { flex: none; display: flex; flex-direction: column; text-align: right; }
.pr-kcal b { font-size: 16px; }
.pr-kcal small { font-size: 11px; color: var(--muted); }

/* ---------- chat ---------- */
/* iOS home-screen app: if the document is not taller than the screen, the layout viewport shrinks by the status
   bar height and everything fixed below it is clipped (empty band under the tab bar). Keep it 1px taller. */
body.chat-mode { min-height: calc(var(--screen-h) + 1px); }
body.chat-mode .view {
  position: fixed; left: 0; right: 0; top: var(--vv-top); padding: 0; margin: 0; max-width: none;
  height: calc(var(--app-h) - var(--nav-h) - var(--safe-b)); display: flex;
}
body.kb-open .nav { display: none; }
body.chat-mode.kb-open .view { height: var(--vvh); }
@media (min-width: 900px) {
  body.chat-mode .view { left: 236px; top: 0; height: 100vh; }
}
.chat { display: flex; flex-direction: column; width: 100%; max-width: 860px; margin: 0 auto; height: 100%; min-height: 0; }
.chat-top { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: calc(var(--safe-t) + 10px) 16px 10px; border-bottom: 1px solid var(--line); }
.chat-top h1 { font-size: 20px; }
.chat-top .sub { font-size: 12px; color: var(--muted); }
body.kb-open .chat-top { padding-top: 10px; }
.msgs { flex: 1; min-height: 0; overflow-y: auto; padding: 16px; display: flex; flex-direction: column; gap: 14px; -webkit-overflow-scrolling: touch; overscroll-behavior: contain; }
.msg { display: flex; flex-direction: column; max-width: 88%; gap: 6px; }
.msg.user { align-self: flex-end; align-items: flex-end; }
.msg.ai { align-self: flex-start; }
.bubble { padding: 10px 14px; border-radius: 18px; background: var(--card); border: 1px solid var(--line); word-wrap: break-word; overflow-wrap: anywhere; }
.msg.user .bubble { background: linear-gradient(135deg, #d33030, #e2553a); border: 0; color: #fff; border-bottom-right-radius: 6px; }
.msg.ai .bubble { border-bottom-left-radius: 6px; }
.bubble p + p, .bubble p + ul, .bubble ul + p { margin-top: 8px; }
.bubble ul { margin: 6px 0 0; padding-left: 20px; }
.bubble li + li { margin-top: 3px; }
.msg-photo { width: 220px; max-width: 100%; border-radius: 16px; cursor: pointer; object-fit: cover; max-height: 280px; }
.msg time { font-size: 11px; color: var(--faint); padding: 0 4px; }
.msg.pending { opacity: .7; }
.msg.error .bubble { border-color: rgba(239, 59, 59, .5); }
.typing .bubble { display: flex; gap: 5px; align-items: center; padding: 14px 16px; }
.typing i { width: 7px; height: 7px; border-radius: 50%; background: var(--muted); animation: blink 1.2s infinite; }
.typing i:nth-child(2) { animation-delay: .2s; }
.typing i:nth-child(3) { animation-delay: .4s; }
@keyframes blink { 0%, 80%, 100% { opacity: .25; } 40% { opacity: 1; } }
.typing small { color: var(--muted); margin-left: 6px; }

.rec { background: var(--card-2); border: 1px solid var(--line); border-radius: 14px; padding: 10px 12px; font-size: 14px; }
.rec-head { display: flex; align-items: center; gap: 10px; }
.rec-ico { font-size: 20px; flex: none; }
.rec-main { flex: 1; min-width: 0; }
.rec-title { font-weight: 650; }
.rec-sub { font-size: 12px; color: var(--muted); }
.rec-kcal { font-weight: 750; white-space: nowrap; }
.rec-actions { display: flex; gap: 6px; }
.rec.deleted { opacity: .45; }
.rec.deleted .rec-title { text-decoration: line-through; }
.rec-foot { display: flex; align-items: flex-start; justify-content: space-between; gap: 8px; margin-top: 6px; }
.rec-foot details { flex: 1; min-width: 0; }
.rec details { margin-top: 6px; }
.rec summary { cursor: pointer; color: var(--muted); font-size: 13px; }
.items-table { width: 100%; border-collapse: collapse; margin-top: 6px; font-size: 13px; }
.items-table td { padding: 4px 0; border-top: 1px solid var(--line); }
.items-table td:not(:first-child) { text-align: right; white-space: nowrap; padding-left: 8px; color: var(--muted); }

.welcome { margin: auto 0; text-align: center; padding: 20px 8px; }
.welcome h3 { margin-bottom: 6px; }
.welcome p { color: var(--muted); font-size: 14px; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; margin-top: 16px; }
.chip { padding: 8px 12px; border-radius: 99px; background: var(--card); border: 1px solid var(--line); font-size: 14px; cursor: pointer; }
.chip.active { background: var(--text); color: var(--bg); border-color: var(--text); }

.composer { padding: 8px 12px 10px; border-top: 1px solid var(--line); background: var(--bg); }
.composer-row { display: flex; align-items: flex-end; gap: 8px; }
.composer textarea { min-height: 44px; max-height: 140px; resize: none; border-radius: 22px; padding: 11px 16px; line-height: 1.35; }
.composer .attach { position: relative; width: 44px; height: 44px; border-radius: 50%; }
.send { width: 44px; height: 44px; border-radius: 50%; border: 0; flex: none; background: linear-gradient(135deg, var(--accent), var(--accent-2)); color: #fff; display: flex; align-items: center; justify-content: center; cursor: pointer; }
.send:disabled { opacity: .5; }
.chat.drop-hover .msgs { outline: 2px dashed var(--accent); outline-offset: -8px; border-radius: 16px; }
.composer-row { gap: 6px; }
.attach-wrap { position: relative; flex: none; }
.attach-menu { position: absolute; left: 0; bottom: calc(100% + 8px); z-index: 30; min-width: 230px; padding: 6px; display: grid; gap: 2px; border-radius: 16px; background: var(--card); border: 1px solid var(--line); box-shadow: 0 12px 32px rgba(0, 0, 0, .25); }
.attach-item { position: relative; display: flex; align-items: center; gap: 10px; width: 100%; padding: 11px 12px; border: 0; border-radius: 11px; background: transparent; color: var(--text); font-size: 15px; text-align: left; cursor: pointer; }
.attach-item:hover, .attach-item:active { background: var(--card-2); }
.attach-item svg { width: 20px; height: 20px; color: var(--muted); flex: none; }
.mic-btn.recording { background: var(--accent); border-color: transparent; color: #fff; animation: rec-pulse 1.2s ease-in-out infinite; }
.mic-btn .rec-time { font-size: 12px; font-weight: 700; font-variant-numeric: tabular-nums; }
@keyframes rec-pulse { 50% { box-shadow: 0 0 0 6px rgba(239, 59, 59, .25); } }
.send svg { width: 20px; height: 20px; }
.preview { display: flex; flex-direction: column; gap: 6px; margin-bottom: 8px; }
.preview-thumbs { display: flex; gap: 10px; overflow-x: auto; padding: 6px 6px 2px 0; }
.preview-thumb { position: relative; flex: none; }
.preview-thumb img { width: 64px; height: 64px; border-radius: 12px; object-fit: cover; }
.preview-thumb button { position: absolute; top: -6px; right: -6px; width: 24px; height: 24px; padding: 0; border-radius: 50%; border: 1px solid var(--line); background: var(--card-2); color: var(--text); display: flex; align-items: center; justify-content: center; cursor: pointer; }
.preview-thumb button svg { width: 12px; height: 12px; }
.preview-add { width: 64px; height: 64px; flex: none; border-radius: 12px; border: 1px dashed var(--line); display: flex; align-items: center; justify-content: center; color: var(--muted); cursor: pointer; position: relative; }
.preview-add svg { width: 22px; height: 22px; }
.msg-photos { display: grid; grid-template-columns: repeat(2, 112px); gap: 4px; justify-content: end; }
.msg-photos img { width: 112px; height: 112px; object-fit: cover; border-radius: 12px; cursor: pointer; }
.msg-photos.single { grid-template-columns: auto; }
.msg-photos.single img { width: 220px; height: auto; max-height: 280px; border-radius: 16px; }

/* ---------- charts ---------- */
.chart-card { position: relative; }
.chart-box { position: relative; height: 240px; }
@media (min-width: 760px) { .chart-box { height: 290px; } }
.legend { display: flex; flex-wrap: wrap; gap: 12px; font-size: 12px; color: var(--muted); margin-top: 8px; }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 5px; vertical-align: -1px; }
.chips.left { justify-content: flex-start; margin: 0 0 14px; }

/* ---------- profile ---------- */
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.form-grid .full { grid-column: 1 / -1; }
.calc-list { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.settings-actions { display: flex; flex-wrap: wrap; gap: 8px; }
.hint { font-size: 12px; color: var(--faint); margin-top: 8px; }

/* ---------- modal ---------- */
/* With the keyboard open, bottom sheets fit into the visible part of the screen */
body.kb-open .modal-backdrop { top: var(--vv-top); bottom: auto; height: var(--vvh); }
.modal-backdrop { position: fixed; left: 0; right: 0; top: 0; height: var(--app-h); z-index: 50; background: var(--backdrop); display: flex; align-items: flex-end; justify-content: center; animation: fade .15s ease; }
.modal { width: 100%; max-width: 560px; max-height: calc(var(--vvh) - var(--safe-t) - 12px); display: flex; flex-direction: column; background: var(--card); border: 1px solid var(--line); border-radius: 22px 22px 0 0; animation: up .2s ease; }
@media (min-width: 640px) {
  .modal-backdrop { align-items: center; padding: 20px; }
  .modal { border-radius: 22px; max-height: 90vh; }
}
.modal-head { display: flex; align-items: center; justify-content: space-between; padding: 14px 16px; border-bottom: 1px solid var(--line); }
.modal-body { padding: 16px; overflow-y: auto; -webkit-overflow-scrolling: touch; display: grid; gap: 14px; }
.modal-foot { display: flex; gap: 8px; justify-content: flex-end; padding: 12px 16px calc(12px + var(--safe-b)); border-top: 1px solid var(--line); }
.modal-foot .spacer { flex: 1; }
@keyframes fade { from { opacity: 0; } }
@keyframes up { from { transform: translateY(30px); opacity: 0; } }
.modal-photo { width: 100%; max-height: 220px; object-fit: cover; border-radius: 14px; cursor: zoom-in; }

.items-editor { display: grid; gap: 8px; }
.items-head { display: flex; align-items: center; justify-content: space-between; }
.item-row { background: var(--card-2); border-radius: 12px; padding: 8px; display: grid; gap: 6px; }
.item-row .item-top { display: flex; gap: 6px; align-items: center; }
.item-row .item-top input[data-f="name"] { flex: 1; }
.item-grid { display: grid; grid-template-columns: 58px repeat(5, minmax(0, 1fr)); gap: 5px; align-items: center; }
.item-grid > span { font-size: 11px; color: var(--muted); text-align: center; }
.item-grid .ig-label { text-align: left; font-size: 12px; line-height: 1.15; }
.item-grid .ig-dash { color: var(--faint); }
/* Column headers only once, above the first product */
.item-row + .item-row .ig-head { display: none; }
.item-grid input { padding: 7px 3px; min-height: 36px; text-align: center; font-size: 16px; }
.item-grid input[data-p] { background: transparent; border-style: dashed; }
.item-grid input:disabled { opacity: .4; }
.totals-summary { display: grid; gap: 4px; padding: 10px 12px; border-radius: 12px; background: var(--card-2); font-size: 14px; }
.items-table small { color: var(--faint); font-size: 11px; }
.item-row .alc-check { display: flex; align-items: center; gap: 6px; font-size: 12px; color: var(--muted); }
.item-row .alc-check input { width: 16px; height: 16px; }
.totals-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.totals-grid input[readonly] { background: transparent; border-style: dashed; color: var(--muted); }

.lightbox { position: fixed; inset: 0; z-index: 60; background: rgba(0, 0, 0, .92); display: flex; align-items: center; justify-content: center; padding: 16px; cursor: zoom-out; }
.lightbox img { max-height: 100%; object-fit: contain; border-radius: 10px; }

/* ---------- toast & login ---------- */
.toast { position: fixed; left: 50%; top: calc(var(--app-h) - var(--nav-h) - var(--safe-b) - 16px); transform: translate(-50%, -100%); z-index: 70; max-width: calc(100% - 32px); padding: 11px 16px; border-radius: 14px; background: #26262e; color: #fff; font-size: 14px; box-shadow: 0 10px 30px rgba(0,0,0,.4); animation: up .2s ease; }
.toast.error { background: #5a1f22; }
.toast.success { background: #1d4a33; }
@media (min-width: 900px) { .toast { top: auto; bottom: 24px; transform: translateX(-50%); left: calc(50% + 118px); } }

.login { min-height: var(--app-h); display: flex; align-items: center; justify-content: center; padding: 24px 16px; }
.login-card { width: 100%; max-width: 360px; display: grid; gap: 12px; text-align: center; }
.login-logo { width: 84px; height: 84px; border-radius: 22px; margin: 0 auto 6px; }
.login-card p { color: var(--muted); margin-bottom: 10px; }
.login-error { color: var(--danger-text); min-height: 20px; font-size: 14px; }

.theme-row { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; margin-bottom: 14px; }

/* Keyboard hide button: only while the on-screen keyboard is open */
.head-actions { display: flex; align-items: center; gap: 6px; }
.kb-hide-btn { display: none; }
body.kb-open .kb-hide-btn { display: inline-flex; }
