/* Advisory Food: цвета — токенами, тёмная тема — по настройке системы (ADR-21). */
:root {
  --bg: #f6f7f5;
  --surface: #ffffff;
  --surface-2: #f0f2ee;
  --text: #1c2119;
  --muted: #69705f;
  --line: #e1e5dc;
  --accent: #1f7a3a;
  --accent-text: #ffffff;
  --accent-soft: #e4f2e7;
  --warn: #a85a00;
  --warn-soft: #fff4e2;
  --danger: #b3261e;
  --up: #b3261e;
  --down: #1f7a3a;
  --shadow: 0 1px 2px rgb(20 30 15 / 6%), 0 2px 8px rgb(20 30 15 / 5%);
  --radius: 14px;
  --radius-sm: 9px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #111410;
    --surface: #1a1e18;
    --surface-2: #232821;
    --text: #e7ebe2;
    --muted: #9aa392;
    --line: #2e342b;
    --accent: #4cb86c;
    --accent-text: #0d1a10;
    --accent-soft: #1d3324;
    --warn: #f0a640;
    --warn-soft: #33270f;
    --danger: #f2756b;
    --up: #f2756b;
    --down: #4cb86c;
    --shadow: none;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #111410; --surface: #1a1e18; --surface-2: #232821; --text: #e7ebe2; --muted: #9aa392; --line: #2e342b;
  --accent: #4cb86c; --accent-text: #0d1a10; --accent-soft: #1d3324; --warn: #f0a640; --warn-soft: #33270f;
  --danger: #f2756b; --up: #f2756b; --down: #4cb86c; --shadow: none; color-scheme: dark;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--bg); color: var(--text); font: 16px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; }
a { color: var(--accent); }
h1 { font-size: 1.6rem; line-height: 1.25; margin: 0 0 6px; }
h2 { font-size: 1.15rem; margin: 0 0 8px; }
h3 { font-size: 1rem; margin: 0; }
p { margin: 6px 0; }
ul, ol { margin: 6px 0; padding-left: 22px; }
ul.items li { margin: 6px 0; }
code { font: .9em ui-monospace, SFMono-Regular, Menlo, monospace; background: var(--surface-2); padding: 1px 5px; border-radius: 5px; word-break: break-all; }
.muted { color: var(--muted); font-size: .92rem; }
.warn { color: var(--warn); }

/* Каркас */
#app { min-height: 100vh; }
main { max-width: 880px; margin: 0 auto; padding: 20px 16px 96px; }
main.narrow { max-width: 720px; }
.topbar { position: sticky; top: 0; z-index: 10; background: color-mix(in srgb, var(--surface) 88%, transparent); backdrop-filter: blur(10px); border-bottom: 1px solid var(--line); }
/* Шапка по ширине содержимого: название — над левым краем страницы. */
.topbar-inner { max-width: 880px; margin: 0 auto; padding: 10px 16px; display: flex; align-items: center; gap: 16px; }
.theme { margin-left: auto; padding: 4px 9px; border-radius: 999px; font-size: 1.05rem; line-height: 1; border-color: transparent; background: none; }
.tabs + .theme { margin-left: 8px; }
.theme:hover:not(:disabled) { background: var(--surface-2); border-color: transparent; }
.brand { display: flex; align-items: center; gap: 8px; font-weight: 700; color: var(--text); text-decoration: none; white-space: nowrap; }
.logo { font-size: 1.3rem; }
.tabs { display: flex; gap: 4px; margin-left: auto; }
.tabs a { display: flex; align-items: center; gap: 6px; padding: 6px 12px; border-radius: 999px; color: var(--muted); text-decoration: none; font-size: .95rem; white-space: nowrap; }
.tabs a:hover { background: var(--surface-2); color: var(--text); }
.tabs a.active { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
/* Иконки вкладок — только в нижней панели телефона: в шапке подписи без них. */
.tabs .icon { display: none; }
@media (max-width: 860px) {
  .tabs { gap: 0; }
  .tabs a { padding: 6px 9px; font-size: .9rem; }
}
@media (max-width: 760px) and (min-width: 641px) {
  .brand-name { display: none; }
}
@media (max-width: 640px) {
  /* backdrop-filter делает шапку опорой для fixed: панель вкладок осталась бы в ней. */
  .topbar { backdrop-filter: none; background: var(--surface); }
  .topbar-inner { justify-content: space-between; }
  .tabs { position: fixed; left: 0; right: 0; bottom: 0; margin: 0; justify-content: space-around; gap: 0; padding: 6px 4px calc(6px + env(safe-area-inset-bottom));
    background: var(--surface); border-top: 1px solid var(--line); }
  .tabs a { flex-direction: column; gap: 0; padding: 4px 6px; font-size: .72rem; border-radius: 10px; }
  .tabs .icon { display: block; font-size: 1.25rem; }
  h1 { font-size: 1.35rem; }
}

/* Карточки и поля */
.card { display: block; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px; margin-top: 14px; box-shadow: var(--shadow); }
.card > h2:first-child { margin-top: 0; }
a.card { color: inherit; text-decoration: none; }
a.card:hover { border-color: color-mix(in srgb, var(--accent) 45%, var(--line)); }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; margin-top: 12px; }
.grow { flex: 1; min-width: 200px; }
input, select, textarea { font: inherit; color: var(--text); background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius-sm); padding: 9px 12px; }
input:focus, select:focus, textarea:focus { outline: 2px solid color-mix(in srgb, var(--accent) 55%, transparent); outline-offset: 1px; border-color: var(--accent); }
textarea { width: 100%; resize: vertical; min-height: 140px; line-height: 1.5; }
.field { display: grid; gap: 6px; margin: 10px 0; font-weight: 500; }
.field input { width: 100%; }
label.check { display: inline-flex; align-items: center; gap: 6px; cursor: pointer; }
label.option { display: flex; align-items: flex-start; margin: 8px 0; }
label.option input { margin-top: 4px; }
input[type="checkbox"] { width: 17px; height: 17px; accent-color: var(--accent); margin: 0; }

button, .button { font: inherit; display: inline-flex; align-items: center; justify-content: center; gap: 6px; padding: 9px 16px; border-radius: var(--radius-sm);
  border: 1px solid var(--line); background: var(--surface); color: var(--text); cursor: pointer; text-decoration: none; transition: background .15s, border-color .15s; }
button:hover:not(:disabled), .button:hover { border-color: var(--muted); }
button.primary, .button.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); font-weight: 600; }
button.primary:hover:not(:disabled) { filter: brightness(1.07); }
button.big { padding: 12px 28px; font-size: 1.05rem; }
button.small, .button.small { padding: 4px 11px; font-size: .86rem; }
button.danger { color: var(--danger); }
button.link { border: 0; background: none; color: var(--muted); text-decoration: underline; padding: 4px 6px; }
button:disabled { opacity: .5; cursor: default; }
button.current { border-color: var(--accent); color: var(--accent); font-weight: 600; }

.badge { display: inline-block; font-size: .75rem; font-weight: 600; color: var(--accent); background: var(--accent-soft); border-radius: 999px; padding: 1px 8px; margin-left: 8px; vertical-align: 2px; white-space: nowrap; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 10px; }
.chip { padding: 3px 11px; border-radius: 999px; font-size: .86rem; color: var(--muted); background: var(--surface-2); border-color: transparent; }
.chip:hover:not(:disabled) { color: var(--text); border-color: var(--line); }
.note { background: var(--surface-2); border-radius: var(--radius-sm); padding: 8px 12px; margin: 8px 0; font-size: .92rem; }
.note.warn { background: var(--warn-soft); }
.hint { display: block; margin-top: 14px; font-size: .9rem; color: var(--muted); text-decoration: none; }
.hint:hover { color: var(--accent); }
.hint.warn { color: var(--warn); }

/* Состояния */
.loading { display: flex; align-items: center; gap: 10px; color: var(--muted); padding: 18px 0; }
.spinner { width: 18px; height: 18px; border: 2px solid var(--line); border-top-color: var(--accent); border-radius: 50%; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .spinner { animation-duration: 3s; } }
.empty-state { text-align: center; padding: 26px 10px; color: var(--muted); }
.empty-state h3 { color: var(--text); margin-bottom: 6px; }
.empty-state .button { margin-top: 10px; }

.toasts { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); display: grid; gap: 8px; z-index: 50; width: min(520px, calc(100% - 32px)); }
.toast { background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 10px; box-shadow: 0 6px 20px rgb(0 0 0 / 20%); font-size: .95rem; animation: rise .2s ease-out; }
.toast.error { background: var(--danger); color: #fff; }
@keyframes rise { from { opacity: 0; transform: translateY(6px); } }
@media (max-width: 640px) { .toasts { bottom: 84px; } }

/* Вход */
.hero { padding: 18px 0 6px; }
.hero h1 { font-size: 2rem; }
.hero p { color: var(--muted); font-size: 1.05rem; max-width: 620px; }
.login-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); gap: 14px; }
.login-grid .card { margin-top: 0; display: flex; flex-direction: column; gap: 8px; align-items: flex-start; }
.login-grid .field { align-self: stretch; }
.key-card { border-color: var(--accent); }
.key-row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin: 8px 0; }
.key { flex: 1; min-width: 220px; padding: 9px 12px; font-size: .95rem; user-select: all; }
.key.small { font-size: .8rem; }
.login-card { display: flex; flex-direction: column; gap: 8px; align-items: flex-start; }
.login-card .field { align-self: stretch; }
.install .steps { margin-top: 8px; }
.install .steps summary { cursor: pointer; color: var(--muted); font-size: .92rem; }

/* Новый подбор */
.compose h1 { font-size: 1.5rem; }
.recent h2, .request-head h1 { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; }
.recent { margin-top: 26px; }
.more { font-size: .9rem; font-weight: 400; }
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 12px; }
.cards .card { margin-top: 0; }
.request-card { display: flex; flex-direction: column; gap: 4px; }
.request-text { display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; white-space: pre-line; }

/* История и «Мои товары» */
.list .card { margin-top: 10px; }
.request-row { display: flex; justify-content: space-between; gap: 16px; align-items: center; }
.request-link { flex: 1; min-width: 0; color: inherit; text-decoration: none; }
.request-row .side { display: grid; justify-items: end; gap: 6px; }
.head-side { display: grid; justify-items: end; gap: 8px; }
.sum { font-weight: 700; font-variant-numeric: tabular-nums; white-space: nowrap; }
.product { display: grid; grid-template-columns: 40px 1fr auto; gap: 12px; align-items: center; padding: 10px 0; border-top: 1px solid var(--line); }
.product.plain { grid-template-columns: 1fr auto; }
.product a { color: inherit; }
.card > .product:first-of-type, .card > p + .product { border-top: 0; }

/* Подбор */
.request-head { display: flex; justify-content: space-between; align-items: center; gap: 16px; flex-wrap: wrap; }
.grand { display: grid; text-align: right; }
.grand b { font-size: 1.6rem; font-variant-numeric: tabular-nums; }
.versions { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; margin-top: 10px; }
.review { background: var(--warn-soft); border: 1px solid color-mix(in srgb, var(--warn) 35%, transparent); border-radius: var(--radius); padding: 12px 16px; margin-top: 14px; }
.review a { color: inherit; }
.basket-head { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; }
.basket-head h2 { margin: 0; }
.line { display: grid; grid-template-columns: 64px 1fr auto; gap: 4px 14px; padding: 14px 0; border-top: 1px solid var(--line); scroll-margin-top: 80px; }
.basket-head + .line { border-top: 0; margin-top: 6px; }
.line.flagged .thumb { border-color: var(--warn); }
.line-main { min-width: 0; }
.line-title { overflow-wrap: anywhere; }
/* Действия, подписи и варианты строки — под ней, во всю ширину рядом с картинкой. */
.line-extra { grid-column: 2 / -1; min-width: 0; }
.more { position: relative; display: inline-block; }
.more > summary { list-style: none; cursor: pointer; display: inline-flex; align-items: center; }
.more > summary::-webkit-details-marker { display: none; }
.more > summary::after { content: "▾"; margin-left: 4px; font-size: .8em; }
.more .menu { position: absolute; z-index: 20; top: calc(100% + 4px); left: 0; display: grid; gap: 4px; min-width: 260px; padding: 6px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius-sm); box-shadow: 0 8px 24px rgb(0 0 0 / .18); }
.more .menu button { text-align: left; justify-content: flex-start; white-space: normal; }
.line-title a { color: inherit; font-weight: 500; }
.line .cost, .alternative .cost { text-align: right; white-space: nowrap; font-variant-numeric: tabular-nums; font-weight: 600; }
.thumb { width: 64px; height: 64px; object-fit: contain; border-radius: 10px; border: 1px solid var(--line); background: #fff; display: inline-block; }
.thumb.small { width: 40px; height: 40px; border-radius: 8px; }
.flags { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 6px; }
.flag { font-size: .78rem; color: var(--warn); background: var(--warn-soft); border-radius: 6px; padding: 1px 8px; }
.actions { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.replace { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 8px; }
.replace input { flex: 1; min-width: 200px; padding: 6px 10px; }
.picks { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 8px; margin-top: 10px; }
.pick { display: grid; grid-template-columns: 40px 1fr; gap: 2px 10px; text-align: left; align-items: start; justify-content: stretch; padding: 8px 10px; background: var(--surface-2); border-color: transparent; }
.pick:hover:not(:disabled) { border-color: var(--accent); }
.pick .thumb { grid-row: span 3; }
.pick .label { font-size: .72rem; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); display: flex; flex-wrap: wrap; justify-content: space-between; gap: 0 6px; min-width: 0; }
.pick .label b { white-space: nowrap; }
.pick > span { min-width: 0; overflow-wrap: anywhere; }
.pick-title { font-size: .9rem; line-height: 1.3; }
.pick .total { grid-column: 2; }
.pick .muted { font-size: .8rem; }
.up { color: var(--up); } .down { color: var(--down); }
.alternatives, .move { margin-top: 10px; }
.move summary, .move-basket summary { cursor: pointer; color: var(--muted); font-size: .92rem; }
.move-basket { margin-top: 12px; padding-top: 10px; border-top: 1px solid var(--line); }
.move .cost span { display: block; font-size: .8rem; font-weight: 500; }
.alternatives summary { cursor: pointer; color: var(--muted); font-size: .92rem; }
.alternatives > label { margin: 8px 0 4px; }
.alternative { display: grid; grid-template-columns: 40px minmax(0, 1fr) auto auto; gap: 4px 12px; align-items: center; padding: 8px 0; }
.alternative > div:nth-child(2) { min-width: 0; overflow-wrap: anywhere; }
.alternative .total, .pick .total { font-size: .82rem; margin-top: 2px; }
.alternative a { color: inherit; }
.totals { display: grid; grid-template-columns: 1fr auto; gap: 4px 12px; margin: 10px 0 0; padding-top: 10px; border-top: 1px solid var(--line); color: var(--muted); font-variant-numeric: tabular-nums; }
.totals dd { margin: 0; text-align: right; }
.summary .collector { margin-top: 6px; }
.cart-summary { margin-top: 12px; padding: 12px 14px; background: var(--surface-2); border-radius: var(--radius-sm); }
.cart-summary .totals { border-top: 0; padding-top: 4px; margin-top: 4px; color: var(--text); }
.cart-summary .totals dt.muted { font-size: .92rem; }
.cart-head { display: flex; justify-content: space-between; gap: 10px; }
.progress { color: var(--muted); }
@media (max-width: 560px) {
  .line { grid-template-columns: 48px minmax(0, 1fr) auto; gap: 4px 10px; }
  .line .thumb { width: 48px; height: 48px; }
  .line .cost { font-size: .95rem; }
  .line-extra { grid-column: 1 / -1; }
  .picks { grid-template-columns: 1fr; }
  .alternative { grid-template-columns: 40px minmax(0, 1fr) auto; }
  .alternative > :last-child { grid-column: 2 / -1; justify-self: start; }
  .more .menu { left: auto; right: 0; }
}

/* Доставка */
.shop { padding: 14px 0; border-top: 1px solid var(--line); }
.card > h2 + .shop { border-top: 0; padding-top: 4px; }
.shop-head { display: flex; justify-content: space-between; align-items: center; gap: 10px; flex-wrap: wrap; }
.controls { display: flex; gap: 14px; flex-wrap: wrap; font-size: .92rem; }
.shop-terms { display: flex; flex-wrap: wrap; gap: 4px 14px; margin-top: 6px; }
.shop-terms .main { font-weight: 600; }
.own, .history { margin-top: 8px; font-size: .92rem; }
.own summary, .history summary { cursor: pointer; color: var(--muted); }
.own form { display: flex; flex-wrap: wrap; gap: 10px 18px; align-items: end; margin-top: 8px; }
.own label { display: grid; gap: 4px; color: var(--muted); }
.own .row { margin-top: 0; }
.money { display: inline-flex; align-items: center; gap: 6px; color: var(--text); }
.money input { width: 7em; padding: 6px 10px; }
.facts { display: grid; grid-template-columns: max-content 1fr; gap: 6px 18px; margin: 4px 0 10px; }
.facts dt { color: var(--muted); }
.facts dd { margin: 0; }

/* Мои списки */
.lists { margin: 10px 0; }
.list-chips { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.list-chip { padding: 5px 12px; border-radius: 999px; font-size: .92rem; font-weight: 500; }
.list-chip .count { font-size: .75rem; color: var(--muted); background: var(--surface-2); border-radius: 999px; padding: 0 6px; }
.list-chip.on { background: var(--accent-soft); border-color: var(--accent); color: var(--accent); }
.list-chip.on .count { background: var(--surface); }
.lists-hint { margin: 8px 0; }
.edit-lists { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 10px; margin-top: 10px; }
.edit-list { display: grid; gap: 6px; padding: 10px; border: 1px solid var(--line); border-radius: var(--radius-sm); }
.edit-list textarea { min-height: 90px; }
.edit-list .row { margin-top: 0; }
.inline-form { display: inline-flex; gap: 6px; flex-wrap: wrap; align-items: center; }
.inline-form input { padding: 5px 10px; min-width: 220px; }
.hint .small { margin-left: 8px; }
/* Мои списки в «Мои товары»: название и позиции, под ними — правка. */
.saved-list { border-top: 1px solid var(--line); padding: 10px 0; }
.saved-list summary { cursor: pointer; }
.saved-list .edit-list { display: grid; gap: 8px; margin-top: 10px; }
.saved-list textarea { min-height: 120px; }
/* Форма постоянного пожелания в «Мои товары». */
.wish-form { display: grid; grid-template-columns: 1fr 1fr auto; gap: 8px; margin: 10px 0 6px; }
@media (max-width: 560px) { .wish-form { grid-template-columns: 1fr; } }
