:root {
  color-scheme: light;
  --bg: #f4efe7;
  --card: #fffdf9;
  --text: #241c16;
  --muted: #7b6e62;
  --line: #eadfce;
  --danger: #c84b32;
  --shadow: 0 12px 32px rgba(72, 42, 16, 0.08);
  --tabh: 62px;
  --kb: 0px;
  --side: 280px;
  --list-a: #ff8a4c;
  --list-b: #e8572a;
  --list-ink: #fff;
  font-family: system-ui, "Segoe UI", sans-serif;
}

html[data-theme="dark"] {
  color-scheme: dark;
  --bg: #141311;
  --card: #221f1b;
  --text: #f6f1ea;
  --muted: #b3a79b;
  --line: #3a332c;
  --shadow: 0 12px 32px rgba(0, 0, 0, 0.35);
}

@media (prefers-color-scheme: dark) {
  html[data-theme="system"] {
    color-scheme: dark;
    --bg: #141311;
    --card: #221f1b;
    --text: #f6f1ea;
    --muted: #b3a79b;
    --line: #3a332c;
    --shadow: 0 12px 32px rgba(0, 0, 0, 0.35);
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg);
  color: var(--text);
  min-height: 100dvh;
  overscroll-behavior-y: contain;
}
button, input, textarea, select { font: inherit; color: inherit; }
button { cursor: pointer; }
img, svg { display: block; max-width: 100%; }
a { color: inherit; }

#app { min-height: 100dvh; }
.shell { min-height: 100dvh; }
.main {
  min-height: 100dvh;
  padding-bottom: calc(var(--tabh) + env(safe-area-inset-bottom));
}
.page { min-height: 100dvh; }
.body { padding: 8px 16px 120px; }
.sidebar { display: none; }

.top {
  position: sticky;
  top: 0;
  z-index: 5;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: calc(14px + env(safe-area-inset-top)) 16px 18px;
  background: linear-gradient(160deg, var(--list-a), var(--list-b));
  color: var(--list-ink);
}
.top h1 { margin: 0; font-size: 1.45rem; line-height: 1.15; }
.top.stack { flex-direction: column; align-items: flex-start; gap: 2px; }
.top.stack .textbtn { margin-left: -8px; }
.top p { margin: 4px 0 0; opacity: 0.9; }
.list-name, .avatar, .iconbtn, .textbtn.light { color: var(--list-ink); }
.list-name {
  flex: 1;
  min-width: 0;
  border: 0;
  background: transparent;
  text-align: left;
  padding: 0;
}
.list-name strong, .list-name span { display: block; }
.list-name strong { font-size: 1.35rem; }
.list-name span { opacity: 0.85; font-size: 0.85rem; }
.avatar {
  width: 42px;
  height: 42px;
  border-radius: 50%;
  border: 0;
  background: color-mix(in srgb, var(--list-ink) 18%, transparent);
  font-weight: 700;
}
.top-tools { display: flex; align-items: center; gap: 6px; }
.pill {
  border-radius: 999px;
  padding: 3px 8px;
  background: color-mix(in srgb, var(--list-ink) 18%, transparent);
  font-size: 0.75rem;
}
.iconbtn, .textbtn {
  border: 0;
  background: transparent;
  min-width: 36px;
  min-height: 36px;
}
.textbtn.light { font-weight: 650; }

.gate {
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 32px 20px calc(32px + env(safe-area-inset-bottom));
  text-align: center;
  gap: 8px;
}
.gate h1 { margin: 0; }
.lede { max-width: 28rem; margin: 0 0 8px; color: var(--muted); }
.logo svg { width: 88px; height: 88px; }
.logo.tiny svg { width: 36px; height: 36px; }
.card, .form, .recipe-card, .offer-card, .loyalty, .tile, .row, .hit, .dialog, .sheet {
  background: var(--card);
}
.card.form, .gate .form {
  width: min(420px, 100%);
  padding: 18px;
  border-radius: 22px;
  box-shadow: var(--shadow);
  text-align: left;
}
.field { display: flex; flex-direction: column; gap: 6px; margin: 0 0 12px; color: var(--muted); font-size: 0.9rem; }
.field input, .field textarea, .field select, .composer input, .import input, .line-edit input {
  width: 100%;
  border: 1px solid var(--line);
  background: var(--bg);
  border-radius: 12px;
  padding: 12px 14px;
  font-size: 16px;
  color: var(--text);
}
.field textarea { min-height: 88px; resize: vertical; }
.error { color: var(--danger); margin: 0 0 8px; }
.muted { color: var(--muted); }
.small { font-size: 0.85rem; }
.btn {
  border: 0;
  border-radius: 14px;
  padding: 12px 16px;
  background: var(--line);
  font-weight: 650;
}
.btn.primary { background: var(--list-b); color: var(--list-ink); }
.btn.ghost { background: transparent; border: 1px solid var(--line); }
.btn.danger { background: transparent; color: var(--danger); }
.btn.wide, .wide { width: 100%; }
.btn:disabled { opacity: 0.45; }
.actions { display: flex; flex-wrap: wrap; gap: 8px; margin: 12px 0; }

.empty { text-align: center; padding: 28px 8px; }
.ico svg { width: 64px; height: 64px; margin: 0 auto; }
.ico.sm svg { width: 36px; height: 36px; }
.ico.xl svg { width: 96px; height: 96px; }
.ico.photo { width: 72px; height: 72px; margin: 0 auto; border-radius: 16px; overflow: hidden; }
.ico.photo img { width: 100%; height: 100%; object-fit: cover; }

.section-title {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 22px 0 10px;
  font-size: 0.95rem;
}
.section-title.as-button { border: 0; background: transparent; padding: 0; color: inherit; }
.section-head { display: flex; justify-content: space-between; align-items: center; }
.dot { width: 10px; height: 10px; border-radius: 50%; display: inline-block; }
.tiles, .catalog { display: grid; grid-template-columns: repeat(auto-fill, minmax(168px, 1fr)); gap: 10px; }
.rows { display: flex; flex-direction: column; gap: 8px; }
.tile, .row {
  position: relative;
  border: 0;
  border-radius: 18px;
  box-shadow: 0 1px 0 rgba(60, 40, 20, 0.04);
  padding: 10px;
}
.tile {
  container-type: inline-size;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  text-align: center;
  min-height: 168px;
  padding: 16px 8px 14px;
}
.tile.plain { width: 100%; }
.tile .ico,
.catcard .ico {
  display: block;
  width: 112px;
  width: min(68cqi, 148px);
  margin-inline: auto;
}
.tile .ico svg,
.tile .ico.photo,
.catcard .ico svg,
.catcard .ico.photo {
  width: 100%;
  height: auto;
  aspect-ratio: 1;
  margin: 0;
}
.row { display: flex; align-items: center; gap: 12px; text-align: left; min-height: 72px; }
.row .ico svg, .row .ico.photo { width: 52px; height: 52px; margin: 0; }
.item-copy { min-width: 0; }
.tile .item-copy { width: 100%; }
.item-copy strong, .item-copy em, .item-copy small,
.tile strong, .catcard span {
  display: block;
  width: 100%;
  min-width: 0;
  font-size: 1rem;
  line-height: 1.2;
  overflow-wrap: normal;
}
.tile strong {
  font-size: 1rem;
  font-size: clamp(1rem, 10cqi, 1.55rem);
  font-weight: 700;
  line-height: 1.15;
}
.tile .item-copy em,
.tile .item-copy small {
  font-size: 0.95rem;
  font-size: clamp(0.95rem, 7cqi, 1.2rem);
}
.item-copy em { font-style: normal; color: var(--muted); }
.item-copy small { color: var(--muted); }
.badge {
  position: absolute;
  top: 8px;
  right: 8px;
  font-size: 0.68rem;
  border-radius: 999px;
  padding: 2px 6px;
  background: var(--bg);
}
.badge-urgent { color: #fff; background: #d4533b; }
.badge-offer { color: #3f2a14; background: #f2c14b; }
.badge-later { color: var(--muted); }
.leaving { animation: leave 0.16s ease forwards; }
.fresh { outline: 2px solid var(--list-b); }
.armed { outline: 2px dashed var(--list-b); }
@keyframes leave { to { transform: scale(0.92) translateY(8px); opacity: 0; } }
.scroller { display: flex; gap: 8px; overflow: auto; padding-bottom: 4px; }
.chip-card, .chip, .catcard {
  border: 1px solid var(--line);
  background: var(--card);
  border-radius: 14px;
}
.chip-card { display: flex; flex-direction: column; align-items: center; gap: 6px; min-width: 124px; padding: 12px 10px; }
.chip-card .ico { display: block; width: 80px; margin-inline: auto; }
.chip-card .ico svg { width: 100%; height: auto; aspect-ratio: 1; margin: 0; }
.chip-card span { display: block; width: 100%; font-size: 1.05rem; font-weight: 650; line-height: 1.2; text-align: center; overflow-wrap: normal; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; margin: 6px 0 10px; }
.chip { border-radius: 999px; padding: 6px 10px; }
.chip.on, .seg.on, .theme.on, .icon-pick.on { outline: 2px solid var(--list-b); }
.catcard {
  container-type: inline-size;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 14px 8px;
  text-align: center;
  min-width: 0;
  min-height: 148px;
}
.catcard span {
  font-size: 1.0625rem;
  font-size: clamp(1.0625rem, 11cqi, 1.4rem);
  font-weight: 700;
  line-height: 1.15;
  overflow-wrap: normal;
}
.cat-item { display: flex; flex-direction: column; min-width: 0; }

.composer {
  position: fixed;
  left: 0;
  right: 0;
  bottom: calc(var(--tabh) + env(safe-area-inset-bottom));
  z-index: 20;
  display: flex;
  gap: 6px;
  align-items: center;
  margin: 0;
  padding: 8px 12px;
  background: var(--bg);
}
.composer input { flex: 1; border-radius: 999px; padding: 12px 16px; border: 0; background: var(--card); box-shadow: var(--shadow); }
.send {
  width: 46px;
  height: 46px;
  border: 0;
  border-radius: 50%;
  background: var(--list-b);
  color: var(--list-ink);
  font-size: 1.6rem;
  line-height: 1;
}
.searchpanel {
  position: fixed;
  left: 12px;
  right: 12px;
  bottom: calc(var(--tabh) + env(safe-area-inset-bottom) + 68px);
  z-index: 20;
  max-height: min(52dvh, 460px);
  overflow: auto;
  background: var(--card);
  border-radius: 18px;
  box-shadow: var(--shadow);
  padding: 8px;
}
.hit { padding: 6px; border-bottom: 1px solid var(--line); }
.hit-main, .hit.custom {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 10px;
  border: 0;
  background: transparent;
  text-align: left;
  padding: 6px;
}
.hit-main .ico svg, .hit.custom .ico svg { width: 42px; height: 42px; margin: 0; }

.tabbar {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 15;
  display: grid;
  grid-auto-flow: column;
  grid-auto-columns: 1fr;
  height: calc(var(--tabh) + env(safe-area-inset-bottom));
  padding-bottom: env(safe-area-inset-bottom);
  background: var(--card);
  border-top: 1px solid var(--line);
}
.tab { display: flex; align-items: center; justify-content: center; text-decoration: none; color: var(--muted); font-size: 0.82rem; }
.tab.active { color: var(--list-b); font-weight: 700; }

.layer { position: fixed; inset: 0; display: flex; align-items: flex-end; justify-content: center; }
.layer.center { align-items: center; padding: 20px; }
.backdrop { position: absolute; inset: 0; border: 0; background: rgba(24, 16, 10, 0.46); }
.sheet, .dialog { position: relative; z-index: 1; width: min(680px, 100%); }
.sheet {
  max-height: min(92dvh, 880px);
  overflow: auto;
  border-radius: 22px 22px 0 0;
  padding: 6px 16px calc(18px + env(safe-area-inset-bottom));
}
.sheet-full { height: 100dvh; max-height: 100dvh; border-radius: 0; }
.dialog { border-radius: 22px; padding: 18px; box-shadow: var(--shadow); }
.grabber { width: 42px; height: 4px; border-radius: 4px; background: var(--line); margin: 6px auto 10px; }
.sheet-head, .stepper, .reorder, .menu-row, .toggle, .split { display: flex; align-items: center; gap: 8px; }
.menu-row, .toggle { width: 100%; border: 0; background: transparent; padding: 12px 0; border-bottom: 1px solid var(--line); text-align: left; }
.menu-row span, .reorder span, .toggle span:first-child { flex: 1; }
.switch { width: 42px; height: 26px; border-radius: 999px; background: var(--line); position: relative; }
.switch::after { content: ""; position: absolute; top: 3px; left: 3px; width: 20px; height: 20px; border-radius: 50%; background: white; }
.switch.on { background: var(--list-b); }
.switch.on::after { left: 19px; }
.themes, .icon-picks { display: flex; flex-wrap: wrap; gap: 8px; }
.theme { width: 42px; height: 42px; border-radius: 50%; border: 0; }
.icon-pick { width: 84px; border: 1px solid var(--line); border-radius: 14px; background: var(--bg); padding: 6px; }
.icon-pick .ico svg { width: 48px; height: 48px; }
.segment { display: flex; gap: 6px; background: var(--card); padding: 4px; border-radius: 14px; margin-bottom: 12px; }
.seg { flex: 1; border: 0; background: transparent; border-radius: 10px; padding: 8px; }
.list-layout { display: flex; flex-direction: column; gap: 8px; margin-bottom: 12px; }
.list-layout .segment { flex-wrap: wrap; margin-bottom: 0; }
.list-layout .seg { flex: 1 1 7rem; }
.import { display: flex; gap: 8px; margin-bottom: 12px; }
.import input { flex: 1; }
.cards { display: flex; flex-direction: column; gap: 10px; }
.recipe-card, .offer-card, .loyalty { display: block; width: 100%; text-align: left; text-decoration: none; border-radius: 18px; padding: 14px; border: 0; box-shadow: var(--shadow); }
.recipe-card span, .offer-card p { display: block; margin: 4px 0 0; }
.offer-card { display: flex; gap: 12px; }
.loyalty { min-height: 96px; }
.ingredients { list-style: none; padding: 0; margin: 0 0 12px; }
.ingredients li { border-bottom: 1px solid var(--line); }
.ingredients label { display: flex; align-items: center; gap: 8px; padding: 8px 0; }
.instructions p { line-height: 1.5; }
.line-edit { display: grid; grid-template-columns: 1fr 120px 36px; gap: 6px; margin-bottom: 8px; }
.checkline { display: flex; gap: 8px; align-items: center; margin-bottom: 12px; }
.scan {
  min-height: 100dvh;
  background: #fff;
  color: #161616;
  padding: calc(16px + env(safe-area-inset-top)) 16px 24px;
}
.scan .barcode svg { width: 100%; height: auto; background: #fff; }
.code-text { font-family: ui-monospace, monospace; font-size: 1.4rem; letter-spacing: 0.08em; word-break: break-all; }
.toast {
  position: fixed;
  left: 50%;
  bottom: calc(var(--tabh) + env(safe-area-inset-bottom) + 76px);
  transform: translateX(-50%);
  z-index: 80;
  background: #241c16;
  color: #fff;
  border-radius: 999px;
  padding: 10px 16px;
  max-width: min(90vw, 420px);
}

html.kb-open .tabbar { display: none; }
html.kb-open .composer { bottom: var(--kb); }
html.kb-open .searchpanel { bottom: calc(var(--kb) + 68px); }
html.sheet-open .composer, html.sheet-open .searchpanel, html.sheet-open .tabbar { visibility: hidden; }

@media (min-width: 960px) {
  .shell { display: grid; grid-template-columns: var(--side) 1fr; }
  .sidebar {
    display: flex;
    flex-direction: column;
    gap: 4px;
    position: sticky;
    top: 0;
    height: 100dvh;
    padding: 18px 14px;
    background: var(--card);
    border-right: 1px solid var(--line);
    overflow: auto;
  }
  .brand { display: flex; align-items: center; gap: 8px; margin-bottom: 12px; }
  .side-label, .side-list, .side-nav a { display: flex; align-items: center; gap: 8px; }
  .side-label { color: var(--muted); font-size: 0.8rem; justify-content: space-between; }
  .side-list, .side-nav a {
    border: 0;
    background: transparent;
    text-decoration: none;
    border-radius: 12px;
    padding: 10px;
    text-align: left;
  }
  .side-list.active, .side-nav a.active { background: var(--bg); font-weight: 700; }
  .side-list em { margin-left: auto; font-style: normal; color: var(--muted); }
  .side-nav { display: flex; flex-direction: column; margin-top: auto; padding-top: 12px; }
  .tabbar { display: none; }
  .main { padding-bottom: 0; }
  .composer { left: var(--side); bottom: 16px; }
  .searchpanel { left: calc(var(--side) + 16px); bottom: 84px; }
  .toast { bottom: 96px; }
}

@media (prefers-reduced-motion: reduce) {
  .leaving { animation: none; opacity: 0.35; }
}

@media print {
  .sidebar, .tabbar, .composer, .searchpanel, .recent, .suggestions, .catalog, .top-tools, .avatar, .badge, .list-layout { display: none !important; }
  .top { background: #fff !important; color: #000 !important; position: static; }
  .main, .page, .body { padding: 0 !important; }
  .tile, .row { break-inside: avoid; box-shadow: none; border: 1px solid #ddd; }
}
