/* Restock — Supermarket Simulator companion. Mobile-first, light/dark via tokens. */
:root {
  --bg: #f3f4f7; --surface: #ffffff; --surface-2: #eef0f4; --surface-3: #e4e7ed;
  --text: #16181d; --muted: #667085; --border: #dfe2e8; --border-strong: #c9cdd6;
  --danger: #d64545; --danger-bg: #fdecec; --success: #1f9d55; --success-bg: #e6f6ec; --info-bg: #e8f0fd;
  --shadow: 0 1px 2px rgba(16,24,40,.06), 0 1px 3px rgba(16,24,40,.08);
  --shadow-lg: 0 -4px 24px rgba(16,24,40,.18);
  --accent: #2f80ed; --accent-text: #ffffff;
  --radius: 14px; --radius-sm: 10px; --tap: 44px;
  --nav-h: 62px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0e1014; --surface: #171a20; --surface-2: #20242c; --surface-3: #2a2f39;
    --text: #eceef2; --muted: #98a0ad; --border: #2a2f39; --border-strong: #3a4150;
    --danger: #ef6b6b; --danger-bg: #3a1d1d; --success: #4cc27c; --success-bg: #17301f; --info-bg: #1b2738;
    --shadow: 0 1px 2px rgba(0,0,0,.4); --shadow-lg: 0 -4px 30px rgba(0,0,0,.6);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0e1014; --surface: #171a20; --surface-2: #20242c; --surface-3: #2a2f39;
  --text: #eceef2; --muted: #98a0ad; --border: #2a2f39; --border-strong: #3a4150;
  --danger: #ef6b6b; --danger-bg: #3a1d1d; --success: #4cc27c; --success-bg: #17301f; --info-bg: #1b2738;
  --shadow: 0 1px 2px rgba(0,0,0,.4); --shadow-lg: 0 -4px 30px rgba(0,0,0,.6);
  color-scheme: dark;
}

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font: 16px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  -webkit-tap-highlight-color: transparent; touch-action: manipulation;
  min-height: 100dvh;
}
body.has-nav { padding-bottom: calc(var(--nav-h) + env(safe-area-inset-bottom) + 12px); }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3 { line-height: 1.2; margin: 0 0 .5rem; }
h1 { font-size: 1.5rem; } h2 { font-size: 1.15rem; } h3 { font-size: 1rem; margin-top: 1rem; }
p { margin: 0 0 .75rem; }
small, .small { font-size: .82rem; }
.muted { color: var(--muted); }
.center { text-align: center; }
.mono, .code { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; }
code.code { background: var(--surface-2); padding: 2px 6px; border-radius: 6px; font-size: .9em; letter-spacing: .04em; }
[hidden] { display: none !important; }

/* ---------- Top bar ---------- */
.topbar { position: sticky; top: 0; z-index: 30; background: var(--surface); border-bottom: 1px solid var(--border); padding-top: env(safe-area-inset-top); }
.topbar-inner { max-width: 760px; margin: 0 auto; padding: 8px 14px; display: flex; align-items: center; justify-content: space-between; gap: 10px; min-height: 56px; }
.admin .topbar-inner { max-width: 1100px; }
.brand { display: flex; align-items: center; gap: 10px; min-width: 0; color: inherit; }
.brand:hover { text-decoration: none; }
.brand-name { font-weight: 700; font-size: 1.05rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.brand-name small { color: var(--muted); font-weight: 500; }
.brand-icon { color: var(--accent); flex: none; display: block; }
.brand-icon.big { margin: 0 auto 10px; }
.topbar-actions { display: flex; align-items: center; gap: 6px; }
.icon-btn { display: inline-flex; align-items: center; justify-content: center; width: var(--tap); height: var(--tap); border-radius: 50%; border: 0; background: transparent; color: var(--text); cursor: pointer; }
.icon-btn:active { background: var(--surface-2); }
.theme-toggle .ico-sun { display: none; }
:root[data-theme="dark"] .theme-toggle .ico-sun { display: block; }
:root[data-theme="dark"] .theme-toggle .ico-moon { display: none; }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .theme-toggle .ico-sun { display: block; }
  :root:not([data-theme="light"]) .theme-toggle .ico-moon { display: none; }
}
.switcher-form { min-width: 0; }
.switcher {
  appearance: none; -webkit-appearance: none; border: 1px solid var(--border); background: var(--surface-2) no-repeat right 10px center;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23888' stroke-width='2.5' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E");
  background-size: 16px; color: var(--text); font-weight: 700; font-size: 1rem; padding: 8px 32px 8px 12px; border-radius: 999px; max-width: 56vw; min-height: 40px; text-overflow: ellipsis;
}

/* ---------- Admin nav ---------- */
.adminnav { border-bottom: 1px solid var(--border); background: var(--surface); }
.adminnav-inner { max-width: 1100px; margin: 0 auto; display: flex; gap: 2px; overflow-x: auto; padding: 0 8px; scrollbar-width: none; }
.adminnav-inner::-webkit-scrollbar { display: none; }
.adminnav a, .adminnav button { flex: none; padding: 12px 12px; min-height: var(--tap); color: var(--muted); font-weight: 600; font-size: .95rem; border: 0; background: none; border-bottom: 3px solid transparent; cursor: pointer; white-space: nowrap; }
.adminnav a.active { color: var(--accent); border-bottom-color: var(--accent); }
.adminnav a:hover { text-decoration: none; color: var(--text); }
.adminnav form { margin-left: auto; }

/* ---------- Layout ---------- */
.container { max-width: 760px; margin: 0 auto; padding: 16px 14px 24px; }
.container.wide { max-width: 1100px; }
.page-head { margin: 4px 0 14px; }
.page-head p { margin: 2px 0 0; }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; margin-bottom: 14px; box-shadow: var(--shadow); }
.card.empty { text-align: center; padding: 28px 16px; }
.card.empty p:last-child { margin: 0; }
.flashes { margin-bottom: 12px; }
.flash { padding: 11px 14px; border-radius: var(--radius-sm); margin-bottom: 8px; font-size: .95rem; border: 1px solid transparent; }
.flash-success { background: var(--success-bg); color: var(--success); border-color: color-mix(in srgb, var(--success) 30%, transparent); }
.flash-error { background: var(--danger-bg); color: var(--danger); border-color: color-mix(in srgb, var(--danger) 30%, transparent); }
.flash-info { background: var(--info-bg); color: var(--text); }

/* ---------- Forms ---------- */
label { display: block; font-weight: 600; font-size: .9rem; margin-bottom: 12px; }
label > input, label > select, label > textarea { margin-top: 6px; font-weight: 400; }
input[type="text"], input[type="email"], input[type="password"], input[type="search"], input[type="number"], input[type="file"], select, textarea {
  width: 100%; min-height: var(--tap); padding: 10px 12px; font: inherit; font-size: 16px; color: var(--text);
  background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--radius-sm); outline: none;
}
input:focus, select:focus, textarea:focus { border-color: var(--accent); box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 22%, transparent); }
input.tiny { width: 70px; }
select { appearance: none; -webkit-appearance: none; padding-right: 34px; background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23888' stroke-width='2.5' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E"); background-repeat: no-repeat; background-position: right 10px center; background-size: 16px; }
input[type="checkbox"] { width: 22px; height: 22px; accent-color: var(--accent); flex: none; }
.form-grid { display: grid; grid-template-columns: 1fr; gap: 0 14px; }
@media (min-width: 560px) { .form-grid { grid-template-columns: 1fr 1fr; } }
.inline-form { display: flex; gap: 8px; align-items: stretch; margin: 0; }
.inline-form input { flex: 1; min-width: 0; }
.inline-form .btn { flex: none; }
.row-actions { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin: 10px 0 4px; }
.row-actions.between { justify-content: space-between; }
.row-actions h2 { margin: 0; }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px; min-height: var(--tap); padding: 10px 16px;
  border-radius: var(--radius-sm); border: 1px solid var(--border-strong); background: var(--surface); color: var(--text);
  font: inherit; font-weight: 600; font-size: .95rem; cursor: pointer; user-select: none; -webkit-user-select: none; text-decoration: none;
  transition: transform .06s ease, background .12s ease;
}
.btn:hover { text-decoration: none; background: var(--surface-2); }
.btn:active { transform: scale(.96); }
.btn-accent { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
.btn-accent:hover { background: var(--accent); filter: brightness(1.07); }
.btn-ghost { background: transparent; border-color: transparent; color: var(--muted); }
.btn-ghost:hover { background: var(--surface-2); color: var(--text); }
.btn-danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn-danger-ghost { background: transparent; border-color: color-mix(in srgb, var(--danger) 40%, transparent); color: var(--danger); }
.btn-danger-ghost:hover { background: var(--danger-bg); }
.btn-block { display: flex; width: 100%; margin-top: 6px; }
.btn-sm { min-height: 36px; padding: 6px 12px; font-size: .85rem; }
.btn[disabled], .btn.busy { opacity: .6; pointer-events: none; }
.signout { margin-top: 24px; }
.count-badge { display: inline-flex; min-width: 22px; height: 22px; padding: 0 6px; border-radius: 999px; background: var(--accent); color: var(--accent-text); font-size: .78rem; align-items: center; justify-content: center; }
.badge { display: inline-block; font-size: .72rem; font-weight: 700; padding: 2px 8px; border-radius: 999px; background: var(--surface-3); color: var(--muted); vertical-align: middle; text-transform: uppercase; letter-spacing: .04em; }
.badge-accent { background: var(--accent); color: var(--accent-text); }

/* ---------- Auth ---------- */
.auth-wrap { max-width: 420px; margin: 6vh auto 0; }
.auth-logo { text-align: center; margin-bottom: 18px; }
.auth-logo h1 { margin-bottom: 2px; }
.auth-card .btn-block { margin-top: 4px; }
.auth-card p.center { margin: 14px 0 0; }

/* ---------- Color picker ---------- */
.color-picker { display: flex; flex-wrap: wrap; gap: 10px; margin: -4px 0 16px; }
.swatch { width: 40px; height: 40px; border-radius: 50%; border: 3px solid transparent; background: var(--sw); cursor: pointer; padding: 0; position: relative; box-shadow: inset 0 0 0 1px rgba(0,0,0,.12); }
.swatch.selected { border-color: var(--text); box-shadow: 0 0 0 2px var(--surface), inset 0 0 0 1px rgba(0,0,0,.1); }
.swatch.custom { display: flex; align-items: center; justify-content: center; margin: 0; background: conic-gradient(red, yellow, lime, cyan, blue, magenta, red); font-weight: 800; color: #fff; text-shadow: 0 1px 2px rgba(0,0,0,.6); overflow: hidden; }
.swatch.custom input { position: absolute; inset: 0; opacity: 0; width: 100%; height: 100%; cursor: pointer; }
.swatch.custom span { pointer-events: none; }

/* ---------- Check tiles ---------- */
.check-grid { display: grid; grid-template-columns: 1fr; gap: 8px; margin-bottom: 8px; }
@media (min-width: 560px) { .check-grid { grid-template-columns: 1fr 1fr; } }
.check-tile { display: flex; align-items: center; gap: 12px; padding: 10px 12px; min-height: var(--tap); border: 1px solid var(--border); border-radius: var(--radius-sm); background: var(--surface-2); cursor: pointer; margin: 0; font-weight: 600; }
.check-tile:has(input:checked) { border-color: var(--accent); background: color-mix(in srgb, var(--accent) 12%, var(--surface)); }
.check-tile span { display: flex; flex-direction: column; line-height: 1.25; }
.check-tile small { font-weight: 400; }
.plain-list { list-style: none; padding: 0; margin: 0 0 12px; }
.plain-list li { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 8px 0; border-bottom: 1px solid var(--border); }
.plain-list li:last-child { border-bottom: 0; }
.plain-list form { margin: 0; }
.danger-zone { border-color: color-mix(in srgb, var(--danger) 35%, var(--border)); }

/* ---------- Markets ---------- */
.market-grid { display: grid; gap: 10px; margin-bottom: 16px; }
.market-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden; }
.market-card.active { border-color: var(--card-accent); box-shadow: 0 0 0 2px color-mix(in srgb, var(--card-accent) 35%, transparent); }
.market-switch { margin: 0; }
.market-main { display: flex; align-items: center; gap: 12px; width: 100%; padding: 12px 14px; background: none; border: 0; color: inherit; font: inherit; text-align: left; cursor: pointer; min-height: 64px; }
.market-main:active { background: var(--surface-2); }
.market-swatch { width: 42px; height: 42px; border-radius: 12px; background: var(--card-accent); color: var(--card-accent-text); display: flex; align-items: center; justify-content: center; font-weight: 800; font-size: 1.2rem; flex: none; }
.market-text { display: flex; flex-direction: column; min-width: 0; flex: 1; }
.market-text strong { font-size: 1.05rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.check-badge { width: 26px; height: 26px; border-radius: 50%; background: var(--card-accent); color: var(--card-accent-text); display: flex; align-items: center; justify-content: center; font-weight: 800; flex: none; }
.market-actions { display: flex; gap: 8px; padding: 0 14px 12px; }
.market-actions form { margin: 0; }

/* ---------- Products ---------- */
.target-bar { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 10px 12px; border-radius: var(--radius-sm); background: color-mix(in srgb, var(--accent) 12%, var(--surface)); border: 1px solid color-mix(in srgb, var(--accent) 35%, transparent); margin-bottom: 12px; font-size: .92rem; }
.target-bar a { color: inherit; }
.target-bar .btn { flex: none; }
.filters { margin-bottom: 12px; }
.search-row { display: flex; gap: 8px; }
.search-row input { flex: 1; min-width: 0; }
.filter-panel { margin-top: 10px; }
.filter-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-bottom: 10px; }
@media (min-width: 640px) { .filter-grid { grid-template-columns: repeat(4, 1fr); } }
.tag-scroll { display: flex; gap: 6px; overflow-x: auto; padding: 2px 0 8px; scrollbar-width: none; -webkit-overflow-scrolling: touch; }
.tag-scroll::-webkit-scrollbar { display: none; }
.tag-pill { flex: none; padding: 7px 12px; min-height: 36px; display: inline-flex; align-items: center; border-radius: 999px; background: var(--surface-2); border: 1px solid var(--border); color: var(--text); font-size: .85rem; font-weight: 600; }
.tag-pill.selected { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
.tag-pill:hover { text-decoration: none; }
.count-line { margin: 0 0 8px; font-size: .85rem; }
.product-grid { display: grid; gap: 10px; }
@media (min-width: 640px) { .product-grid { grid-template-columns: 1fr 1fr; } }
.product { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 12px 12px 10px; box-shadow: var(--shadow); display: flex; flex-direction: column; gap: 6px; }
.product.flash-ok { animation: pulse .5s ease; }
@keyframes pulse { 0% { box-shadow: 0 0 0 0 color-mix(in srgb, var(--accent) 55%, transparent); } 100% { box-shadow: 0 0 0 10px transparent; } }
.product-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 8px; }
.product h3 { font-size: 1.02rem; margin: 0; line-height: 1.25; }
.flag { margin-right: 4px; font-size: .95em; }
.inlist { flex: none; min-width: 26px; height: 26px; padding: 0 8px; border-radius: 999px; background: var(--accent); color: var(--accent-text); font-size: .8rem; font-weight: 800; display: inline-flex; align-items: center; justify-content: center; }
.inlist::before { content: "×"; font-weight: 500; margin-right: 1px; opacity: .8; }
.meta { display: flex; flex-wrap: wrap; gap: 4px; }
.chip { font-size: .72rem; padding: 2px 7px; border-radius: 999px; background: var(--surface-2); color: var(--muted); border: 1px solid var(--border); white-space: nowrap; }
.chip-num { font-variant-numeric: tabular-nums; }
.tags { display: flex; flex-wrap: wrap; gap: 6px; }
.tag { font-size: .78rem; color: var(--accent); font-weight: 600; }
.add-btns { display: flex; gap: 8px; margin-top: 4px; }
.btn-add { flex: 1; min-height: 46px; font-size: 1.05rem; font-weight: 800; }
.product.compact, .product-grid.compact .product { padding: 10px 12px; border-radius: var(--radius-sm); }
.product.compact .meta, .product-grid.compact .product .meta { display: none; }
.product.compact .tags, .product-grid.compact .product .tags { display: none; }
.product.compact .add-btns, .product-grid.compact .product .add-btns { margin: 0; }
.product.compact, .product-grid.compact .product { flex-direction: row; align-items: center; flex-wrap: wrap; }
.product.compact .product-head, .product-grid.compact .product .product-head { flex: 1 1 140px; min-width: 0; }
.product.compact .add-btns, .product-grid.compact .product .add-btns { flex: 0 0 auto; }
.product.compact .btn-add, .product-grid.compact .product .btn-add { min-width: 64px; min-height: 42px; flex: none; }

/* ---------- Lists ---------- */
.create-list { padding: 12px; }
.list-grid { display: grid; gap: 10px; }
.list-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); padding: 12px 14px; }
.list-card.is-default { border-color: color-mix(in srgb, var(--accent) 60%, var(--border)); }
.list-main { display: flex; flex-direction: column; gap: 4px; color: inherit; }
.list-main:hover { text-decoration: none; }
.list-title { display: flex; align-items: center; gap: 8px; font-size: 1.05rem; flex-wrap: wrap; }
.progress { display: block; height: 6px; border-radius: 999px; background: var(--surface-3); overflow: hidden; margin-top: 4px; }
.progress span { display: block; height: 100%; background: var(--accent); border-radius: 999px; transition: width .3s; }
.list-more { margin-top: 8px; }
.list-more summary { list-style: none; display: inline-flex; }
.list-more summary::-webkit-details-marker { display: none; }
.list-more-body { display: grid; gap: 8px; padding-top: 10px; }
.list-more-body form { margin: 0; }
.list-head { margin-bottom: 14px; }
.list-head h1 { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; margin-top: 4px; }
.back { display: inline-block; font-weight: 600; padding: 6px 0; }
.item-group { margin-bottom: 16px; }
.group-title { font-size: .8rem; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin: 0 0 6px 4px; display: flex; gap: 6px; align-items: baseline; }
.item { display: flex; align-items: center; gap: 10px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 8px 8px 8px 10px; margin-bottom: 6px; box-shadow: var(--shadow); transition: opacity .2s; }
.item.checked { opacity: .55; }
.item.checked .item-text strong { text-decoration: line-through; }
.item.removing { opacity: 0; transform: translateX(20px); transition: all .2s; }
.check { width: 34px; height: 34px; border-radius: 50%; border: 2px solid var(--border-strong); background: var(--surface-2); color: transparent; display: flex; align-items: center; justify-content: center; cursor: pointer; flex: none; padding: 0; }
.item.checked .check { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
.item-text { flex: 1; min-width: 0; display: flex; flex-direction: column; line-height: 1.25; }
.item-text strong { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.stepper { display: flex; align-items: center; border: 1px solid var(--border-strong); border-radius: 999px; overflow: hidden; flex: none; background: var(--surface-2); }
.stepper button { width: 40px; height: 40px; border: 0; background: transparent; color: var(--text); font-size: 1.35rem; font-weight: 700; cursor: pointer; display: flex; align-items: center; justify-content: center; }
.stepper button:active { background: var(--surface-3); }
.stepper .qty { min-width: 32px; text-align: center; font-weight: 800; font-variant-numeric: tabular-nums; }
.remove { width: 36px; height: 40px; border: 0; background: transparent; color: var(--muted); font-size: 1.4rem; cursor: pointer; flex: none; }
.remove:active { color: var(--danger); }

/* ---------- Bottom sheet (picker) ---------- */
.sheet { position: fixed; inset: 0; z-index: 60; }
.sheet-backdrop { position: absolute; inset: 0; background: rgba(0,0,0,.45); }
.sheet-panel { position: absolute; left: 0; right: 0; bottom: 0; max-height: 88dvh; background: var(--bg); border-radius: 18px 18px 0 0; box-shadow: var(--shadow-lg); display: flex; flex-direction: column; animation: slideup .22s ease; padding-bottom: env(safe-area-inset-bottom); }
@keyframes slideup { from { transform: translateY(40px); opacity: 0; } to { transform: none; opacity: 1; } }
.sheet-head { display: flex; gap: 8px; padding: 12px 12px 8px; border-bottom: 1px solid var(--border); background: var(--surface); border-radius: 18px 18px 0 0; }
.sheet-head::before { content: ""; position: absolute; top: 6px; left: 50%; width: 40px; height: 4px; margin-left: -20px; border-radius: 2px; background: var(--border-strong); }
.sheet-head input { flex: 1; min-width: 0; }
.sheet-body { overflow-y: auto; padding: 10px 12px 20px; display: grid; gap: 8px; -webkit-overflow-scrolling: touch; }
body.sheet-open { overflow: hidden; }
@media (min-width: 760px) { .sheet-panel { max-width: 720px; margin: 0 auto; } }

/* ---------- Bottom nav ---------- */
.bottomnav { position: fixed; left: 0; right: 0; bottom: 0; z-index: 40; display: flex; background: var(--surface); border-top: 1px solid var(--border); padding-bottom: env(safe-area-inset-bottom); }
.navitem { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; min-height: var(--nav-h); color: var(--muted); font-size: .72rem; font-weight: 600; }
.navitem:hover { text-decoration: none; }
.navitem.active { color: var(--accent); }
.navitem:active { background: var(--surface-2); }
@media (min-width: 760px) { .bottomnav { max-width: 760px; margin: 0 auto; border-left: 1px solid var(--border); border-right: 1px solid var(--border); border-radius: 16px 16px 0 0; } }

/* ---------- Toast ---------- */
.toast-host { position: fixed; left: 0; right: 0; bottom: calc(var(--nav-h) + env(safe-area-inset-bottom) + 14px); z-index: 70; display: flex; flex-direction: column; align-items: center; gap: 6px; pointer-events: none; }
.no-nav .toast-host, .admin .toast-host { bottom: 20px; }
.toast { background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 999px; font-size: .9rem; font-weight: 600; box-shadow: 0 4px 16px rgba(0,0,0,.25); animation: toastin .2s ease; max-width: 92vw; text-align: center; }
.toast.error { background: var(--danger); color: #fff; }
.toast.out { opacity: 0; transition: opacity .3s; }
@keyframes toastin { from { transform: translateY(10px); opacity: 0; } to { transform: none; opacity: 1; } }

/* ---------- Admin ---------- */
.stat-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; margin-bottom: 14px; }
@media (min-width: 640px) { .stat-grid { grid-template-columns: repeat(3, 1fr); } }
@media (min-width: 900px) { .stat-grid { grid-template-columns: repeat(6, 1fr); } }
.stat { display: flex; flex-direction: column; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px; color: inherit; box-shadow: var(--shadow); }
.stat:hover { text-decoration: none; border-color: var(--accent); }
.stat strong { font-size: 1.6rem; line-height: 1.1; }
.stat span { color: var(--muted); font-size: .85rem; }
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; margin: 0 -16px; padding: 0 16px; }
table { width: 100%; border-collapse: collapse; font-size: .92rem; }
th, td { text-align: left; padding: 9px 8px; border-bottom: 1px solid var(--border); vertical-align: middle; }
th { font-size: .75rem; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); white-space: nowrap; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
tr.dim { opacity: .55; }
.tags-cell { color: var(--muted); font-size: .85rem; max-width: 200px; }
.actions-cell { white-space: nowrap; text-align: right; }
.actions-cell form { display: inline; }
.products-table td:nth-child(3) { font-weight: 600; min-width: 160px; }
.products-table input[type="checkbox"] { vertical-align: middle; }
td input[type="text"] { min-height: 38px; padding: 6px 10px; }
td input[type="number"] { min-height: 38px; padding: 6px 8px; }
.bulk-bar { position: sticky; bottom: 0; display: flex; flex-wrap: wrap; gap: 8px; align-items: center; padding: 10px 12px; margin-top: 10px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-sm); box-shadow: var(--shadow-lg); }
.bulk-bar select { width: auto; min-height: 38px; padding: 6px 30px 6px 10px; }
.inline-details { position: relative; display: inline-block; }
.inline-details summary { list-style: none; }
.inline-details summary::-webkit-details-marker { display: none; }
.popover { position: absolute; right: 0; top: calc(100% + 6px); z-index: 20; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 10px; box-shadow: 0 8px 24px rgba(0,0,0,.2); display: grid; gap: 8px; min-width: 260px; text-align: left; }
.popover form { margin: 0; display: block; }
.check-grid.two { grid-template-columns: 1fr 1fr; }
@media (max-width: 480px) { .check-grid.two { grid-template-columns: 1fr; } }

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

/* ---------- Product images ---------- */
/* Fixed-size boxes; the <img> inside scales to fit (never crops), centered. No reliance on object-fit. */
.product-img, .item-img, .thumb {
  display: inline-flex; align-items: center; justify-content: center; flex: none; overflow: hidden;
  background: var(--surface-2); border: 1px solid var(--border); border-radius: 10px; padding: 3px; vertical-align: middle;
}
.product-img { width: 52px; height: 52px; }
.item-img, .thumb { width: 40px; height: 40px; border-radius: 8px; padding: 2px; }
.product.compact .product-img, .product-grid.compact .product .product-img { width: 40px; height: 40px; border-radius: 8px; padding: 2px; }
.product-img img, .item-img img, .thumb img, .image-preview img {
  display: block; width: auto; height: auto; max-width: 100%; max-height: 100%; object-fit: contain;
}
.product-img-empty, .thumb-empty {
  background: var(--surface-2) center / 24px no-repeat;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23999' stroke-width='1.6' stroke-linecap='round' stroke-linejoin='round'%3E%3Crect x='3' y='3' width='18' height='18' rx='3'/%3E%3Ccircle cx='9' cy='9' r='2'/%3E%3Cpath d='M21 15l-5-5L5 21'/%3E%3C/svg%3E");
}
.thumb-empty { background-size: 18px; }
.product-head h3 { flex: 1; min-width: 0; }
.product-img-btn { display: contents; border: 0; background: none; padding: 0; margin: 0; font: inherit; color: inherit; cursor: default; }
.img-flags, .img-inlist, .tile-sub { display: none; }
.thumb-cell { width: 48px; padding-right: 0; }
.image-field { display: flex; gap: 14px; align-items: center; margin-bottom: 14px; }
.image-preview { width: 120px; height: 120px; border-radius: var(--radius-sm); background: var(--surface-2); border: 1px dashed var(--border-strong); display: flex; align-items: center; justify-content: center; overflow: hidden; flex: none; color: var(--muted); font-size: .8rem; padding: 6px; }
.image-preview:not(.empty) { border-style: solid; }
.image-controls { display: flex; flex-direction: column; gap: 8px; align-items: flex-start; min-width: 0; }
.image-controls .btn { cursor: pointer; }
.check-inline { display: flex; align-items: center; gap: 8px; font-weight: 500; margin: 0; }

/* ---------- View toggle + gallery mode ---------- */
.view-toggle { display: inline-flex; flex: none; border: 1px solid var(--border-strong); border-radius: var(--radius-sm); overflow: hidden; background: var(--surface); }
.view-toggle button { width: 42px; min-height: 36px; border: 0; background: transparent; color: var(--muted); cursor: pointer; display: flex; align-items: center; justify-content: center; }
.view-toggle button + button { border-left: 1px solid var(--border); }
.view-toggle button.active { background: var(--accent); color: var(--accent-text); }
.gallery-hint { margin: -4px 0 8px; }
.product-grid.compact { grid-template-columns: 1fr; gap: 6px; }
.product-grid.compact .product { padding: 8px 10px; }
.product-grid.compact .product h3 { font-size: .98rem; }
.product-grid.gallery { grid-template-columns: repeat(auto-fill, minmax(112px, 1fr)); gap: 8px; }
@media (min-width: 640px) { .product-grid.compact { grid-template-columns: 1fr; gap: 6px; }
.product-grid.compact .product { padding: 8px 10px; }
.product-grid.compact .product h3 { font-size: .98rem; }
.product-grid.gallery { grid-template-columns: repeat(auto-fill, minmax(132px, 1fr)); } }
.gallery .product { padding: 0 0 8px; gap: 4px; overflow: hidden; }
.gallery .product-head { flex-direction: column; align-items: stretch; gap: 6px; }
.gallery .product-img-btn { display: block; position: relative; width: 100%; height: auto; aspect-ratio: 1 / 1; min-height: 0; overflow: hidden; cursor: pointer; -webkit-user-select: none; user-select: none; touch-action: manipulation; background: var(--surface-2); }
@supports not (aspect-ratio: 1 / 1) { .gallery .product-img-btn { height: 0; padding-bottom: 100%; } }
.gallery .product-img-btn:active .product-img img { transform: scale(.94); }
/* Absolutely fill the square so the box size never depends on the image's own height */
.gallery .product-img { position: absolute; inset: 0; width: 100%; height: 100%; border: 0; border-radius: 0; padding: 8px; background: transparent; }
.gallery .product-img img { max-width: 100%; max-height: 100%; width: auto; height: auto; transition: transform .08s ease; }
.gallery .product-img-empty { background-size: 40px; }
.gallery .img-flags { display: flex; gap: 2px; position: absolute; top: 6px; left: 6px; font-size: .95rem; filter: drop-shadow(0 1px 1px rgba(0,0,0,.4)); }
.gallery .img-flags .flag { margin: 0; }
.gallery .img-inlist { display: inline-flex; position: absolute; top: 6px; right: 6px; box-shadow: 0 1px 3px rgba(0,0,0,.35); }
.gallery .img-inlist.hidden { display: none; }
.gallery .head-inlist { display: none; }
.gallery .product h3 { font-size: .85rem; padding: 0 8px; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.gallery .product h3 .flag { display: none; }
.gallery .meta, .gallery .tags, .gallery .add-btns { display: none; }
.gallery .tile-sub { display: block; padding: 0 8px; font-size: .74rem; }
