:root {
  --bg: #f6f5f3;
  --card: #ffffff;
  --text: #141414;
  --muted: #6b6b6b;
  --line: #e2e0dc;
  --primary: #111111;
  --primary-text: #ffffff;
  --accent: #1f7a4d;
  --danger: #b3261e;
  --changed: #fff6d6;
  --radius: 14px;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #121212;
    --card: #1d1d1d;
    --text: #f2f2f2;
    --muted: #a3a3a3;
    --line: #333333;
    --primary: #f2f2f2;
    --primary-text: #111111;
    --accent: #4cc38a;
    --danger: #ff8a80;
    --changed: #3a3320;
  }
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
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;
}
body.has-pending { padding-bottom: 88px; }
h1, h2 { margin: 0 0 6px; line-height: 1.2; }
h2 { font-size: 1.15rem; }
.muted { color: var(--muted); margin: 0 0 12px; }
.small { font-size: .85rem; }
.visually-hidden { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

.btn {
  display: inline-flex; align-items: center; justify-content: center;
  min-height: 48px; padding: 0 18px; border-radius: 12px;
  border: 1px solid var(--line); background: var(--card); color: var(--text);
  font: inherit; font-weight: 600; cursor: pointer; text-decoration: none;
  -webkit-tap-highlight-color: transparent;
}
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn-primary { background: var(--primary); color: var(--primary-text); border-color: var(--primary); }
.btn-secondary { background: transparent; }
.btn-ghost { background: transparent; border-color: transparent; min-height: 40px; }
.btn-big { min-height: 64px; font-size: 1.1rem; }
.btn-block { width: 100%; }
.btn-small { min-height: 36px; padding: 0 10px; font-size: .9rem; }

/* Login */
body.login { display: flex; min-height: 100vh; align-items: center; justify-content: center; padding: 16px; }
.login-box { width: 100%; max-width: 360px; background: var(--card); border-radius: var(--radius); padding: 28px 22px; border: 1px solid var(--line); }
.login-logo { display: block; margin-bottom: 14px; }
.login-box label { display: block; font-weight: 600; margin: 8px 0 6px; }
.alert { background: #fdecea; color: #8a1c13; padding: 10px 12px; border-radius: 10px; }

input[type="password"], input[type="search"], input[type="number"], select {
  width: 100%; min-height: 48px; padding: 0 12px; border-radius: 10px;
  border: 1px solid var(--line); background: var(--card); color: var(--text);
  font: inherit; font-size: 16px; /* 16px avoids iOS zoom on focus */
}
.login-box .btn { margin-top: 16px; }

/* App */
.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; justify-content: space-between;
  padding: 10px 16px; padding-top: max(10px, env(safe-area-inset-top));
  background: var(--primary); color: var(--primary-text);
}
.topbar .btn-ghost { color: var(--primary-text); }
.brand { font-weight: 700; letter-spacing: .02em; }
.menu {
  position: fixed; right: 12px; top: 60px; z-index: 30; min-width: 240px;
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: 0 10px 30px rgba(0,0,0,.18); padding: 6px;
}
.menu-item { display: block; width: 100%; text-align: left; min-height: 48px; padding: 0 14px; border: 0; background: none; color: var(--text); font: inherit; font-weight: 600; border-radius: 10px; }
.menu-item:active { background: var(--bg); }
.menu-item.danger { color: var(--danger); }
.menu-note { margin: 0 14px 8px; font-size: .8rem; color: var(--muted); }

.wrap { max-width: 720px; margin: 0 auto; padding: 16px; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px 16px; margin-bottom: 18px; }
.photo-actions { display: grid; gap: 10px; }
.photo-preview { display: flex; align-items: center; gap: 12px; margin-top: 12px; }
.photo-preview img { width: 88px; height: 88px; object-fit: cover; border-radius: 10px; border: 1px solid var(--line); }
.filters { margin-top: 14px; border-top: 1px solid var(--line); padding-top: 10px; }
.filters summary { min-height: 44px; display: flex; align-items: center; font-weight: 600; cursor: pointer; }
.filters label { display: block; font-size: .85rem; font-weight: 600; color: var(--muted); }
.filters label select, .filters label input { margin-top: 4px; color: var(--text); }
.grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-bottom: 10px; }
.row-actions { display: flex; gap: 10px; margin-top: 14px; flex-wrap: wrap; }
.row-actions .btn { flex: 1 1 140px; }
.status { min-height: 1.2em; margin: 10px 0 0; font-weight: 600; }
.status.error { color: var(--danger); }
.section-title { margin: 6px 0 4px; }

.product { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); margin-bottom: 10px; overflow: hidden; }
.product-head { display: flex; gap: 12px; width: 100%; padding: 12px; border: 0; background: none; color: var(--text); text-align: left; font: inherit; cursor: pointer; }
.thumb { width: 72px; height: 72px; flex: none; border-radius: 10px; object-fit: cover; background: var(--bg); }
.thumb-empty { display: flex; align-items: center; justify-content: center; color: var(--muted); }
.product-text { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.product-text strong { overflow-wrap: anywhere; }
.badges { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 4px; }
.badge { font-size: .75rem; padding: 2px 8px; border-radius: 999px; background: var(--bg); border: 1px solid var(--line); }
.badge-score { background: var(--accent); color: #fff; border-color: var(--accent); }
.variants { border-top: 1px solid var(--line); }
.variant { display: flex; align-items: center; gap: 10px; padding: 10px 12px; border-bottom: 1px solid var(--line); }
.variant:last-child { border-bottom: 0; }
.variant.changed { background: var(--changed); }
.thumb-small { width: 44px; height: 44px; flex: none; border-radius: 8px; object-fit: cover; }
.variant-info { display: flex; flex-direction: column; min-width: 0; flex: 1; }
.variant-info strong { font-size: .95rem; overflow-wrap: anywhere; }
.stepper { display: flex; align-items: center; gap: 4px; flex: none; }
.step { width: 44px; height: 44px; border-radius: 10px; border: 1px solid var(--line); background: var(--card); color: var(--text); font-size: 1.3rem; font-weight: 700; }
.qty { width: 64px !important; text-align: center; padding: 0 4px !important; }

.pending-bar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 25;
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 12px 16px; padding-bottom: max(12px, env(safe-area-inset-bottom));
  background: var(--card); border-top: 1px solid var(--line); box-shadow: 0 -6px 20px rgba(0,0,0,.08);
  font-weight: 600;
}

.sheet { position: fixed; inset: 0; z-index: 40; background: rgba(0,0,0,.45); display: flex; align-items: flex-end; justify-content: center; }

.sheet-body {
  width: 100%; max-width: 640px; max-height: 92vh; overflow-y: auto;
  background: var(--card); border-radius: 18px 18px 0 0; padding: 20px 16px;
  padding-bottom: max(20px, env(safe-area-inset-bottom));
}
.review-list { list-style: none; margin: 10px 0; padding: 0; }
.review-item { display: flex; flex-direction: column; padding: 10px 0; border-bottom: 1px solid var(--line); }
.review-item .change { font-size: 1.15rem; font-weight: 700; margin-top: 4px; }
.review-item .note { color: var(--danger); font-size: .85rem; }
.confirm { display: flex; gap: 10px; align-items: flex-start; margin: 12px 0; font-weight: 600; }
.confirm input { width: 24px; height: 24px; flex: none; margin: 0; }

@media (min-width: 720px) {
  .photo-actions { grid-template-columns: 2fr 1fr; }
  .sheet { align-items: center; }
  .sheet-body { border-radius: 18px; }
}

/* Chips */
.filters { margin-top: 14px; border-top: 1px solid var(--line); padding-top: 10px; }
.filters-head { display: flex; align-items: center; justify-content: space-between; }
.filters-head h3 { margin: 0; font-size: 1rem; }
.active-filters { display: flex; flex-wrap: wrap; gap: 6px; margin: 8px 0 4px; }
.active-filters:empty { margin: 0; }
.chip-group { margin: 10px 0; }
.chip-label { display: block; font-size: .8rem; font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; margin-bottom: 6px; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  min-height: 40px; padding: 0 14px; border-radius: 999px; border: 1px solid var(--line);
  background: var(--card); color: var(--text); font: inherit; font-size: .92rem; cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
.chip[aria-pressed="true"] { background: var(--primary); color: var(--primary-text); border-color: var(--primary); font-weight: 600; }
.chip-active { min-height: 34px; background: var(--changed); border-color: var(--line); font-size: .85rem; }
.q-label { display: block; margin-top: 10px; font-size: .85rem; font-weight: 600; color: var(--muted); }
.q-label input { margin-top: 4px; color: var(--text); }
.match-count { margin: 10px 0 0; font-weight: 600; min-height: 1.3em; }
.match-count.warn, .muted.warn { color: var(--danger); font-weight: 600; }
.attrs { color: var(--text); }
