:root {
  color-scheme: dark;
  --bg: #080b11;
  --panel: rgba(18, 23, 34, 0.94);
  --panel-2: rgba(26, 32, 45, 0.96);
  --line: rgba(255, 255, 255, 0.09);
  --text: #f7f8fb;
  --muted: #9aa4b5;
  --accent: #8f7cff;
  --accent-2: #32d7c0;
  --danger: #ff667d;
  --warning: #ffbd59;
  --success: #56e39f;
  --radius: 22px;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }
html { background: var(--bg); }
body {
  margin: 0;
  min-height: 100vh;
  background:
    radial-gradient(circle at 12% 0%, rgba(143, 124, 255, 0.16), transparent 35%),
    radial-gradient(circle at 100% 20%, rgba(50, 215, 192, 0.08), transparent 34%),
    var(--bg);
  color: var(--text);
}
button, input, select, textarea { font: inherit; }
button { cursor: pointer; }
.hidden { display: none !important; }
.app-shell { width: min(1120px, 100%); margin: 0 auto; padding: env(safe-area-inset-top) 16px calc(44px + env(safe-area-inset-bottom)); }
.topbar { display: flex; align-items: center; gap: 14px; padding: 18px 0 14px; position: sticky; top: 0; z-index: 20; backdrop-filter: blur(18px); background: linear-gradient(to bottom, rgba(8,11,17,.95), rgba(8,11,17,.72), transparent); }
.topbar > div { flex: 1; }
h1, h2, p { margin: 0; }
h1 { font-size: clamp(1.45rem, 3vw, 2rem); }
h2 { font-size: clamp(1.25rem, 2.5vw, 1.8rem); }
.eyebrow { font-size: .72rem; letter-spacing: .15em; font-weight: 800; color: var(--accent-2); margin-bottom: 4px; }
.icon-button { width: 44px; height: 44px; border-radius: 50%; border: 1px solid var(--line); color: var(--text); background: rgba(255,255,255,.055); font-size: 1.6rem; display: grid; place-items: center; }
.hero-card { display: flex; justify-content: space-between; align-items: center; gap: 20px; padding: 24px; border: 1px solid var(--line); background: linear-gradient(135deg, rgba(143,124,255,.2), rgba(20,27,41,.92) 45%, rgba(50,215,192,.1)); border-radius: 28px; box-shadow: 0 20px 50px rgba(0,0,0,.24); }
.hero-card p:last-child { color: var(--muted); margin-top: 8px; line-height: 1.45; }
.scan-button, .secondary-button, .dialog-actions button, .recipe-form button, .inline-form button { border: 0; border-radius: 14px; padding: 12px 16px; text-decoration: none; font-weight: 800; color: #080b11; background: linear-gradient(135deg, var(--accent-2), #7bf0df); white-space: nowrap; }
.secondary-button { color: var(--text); background: rgba(255,255,255,.07); border: 1px solid var(--line); }
.stat-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; margin: 16px 0; }
.stat-card { border: 1px solid var(--line); background: var(--panel); color: var(--text); border-radius: 18px; padding: 16px; text-align: left; }
.stat-card strong { display: block; font-size: 1.65rem; }
.stat-card span { color: var(--muted); font-size: .84rem; }
.tabs { display: flex; gap: 8px; overflow-x: auto; padding: 2px 0 12px; scrollbar-width: none; }
.tabs::-webkit-scrollbar { display: none; }
.tab { border: 1px solid var(--line); border-radius: 999px; color: var(--muted); background: rgba(255,255,255,.035); padding: 10px 16px; font-weight: 700; white-space: nowrap; }
.tab.active { color: var(--text); background: rgba(143,124,255,.2); border-color: rgba(143,124,255,.5); }
.tab-panel { display: none; }
.tab-panel.active { display: block; }
.toolbar { display: grid; grid-template-columns: minmax(220px, 1fr) repeat(3, minmax(140px, .35fr)); gap: 10px; margin-bottom: 14px; }
.search-box { display: flex; align-items: center; gap: 8px; padding: 0 14px; background: var(--panel); border: 1px solid var(--line); border-radius: 15px; }
.search-box input { border: 0; background: transparent; color: var(--text); width: 100%; padding: 13px 0; outline: 0; }
select, input, textarea { width: 100%; border: 1px solid var(--line); border-radius: 14px; background: rgba(255,255,255,.05); color: var(--text); padding: 12px 13px; outline: 0; }
select:focus, input:focus, textarea:focus { border-color: rgba(143,124,255,.7); box-shadow: 0 0 0 3px rgba(143,124,255,.12); }
.product-list { display: grid; gap: 10px; }
.product-card { display: grid; grid-template-columns: 58px minmax(0,1fr) auto; align-items: center; gap: 13px; padding: 14px; border-radius: 19px; border: 1px solid var(--line); background: var(--panel); }
.product-image { width: 58px; height: 58px; border-radius: 15px; overflow: hidden; background: linear-gradient(135deg, rgba(143,124,255,.25), rgba(50,215,192,.12)); display: grid; place-items: center; font-weight: 900; color: rgba(255,255,255,.7); }
.product-image img { width: 100%; height: 100%; object-fit: cover; }
.product-copy { min-width: 0; }
.product-copy h3 { margin: 0 0 4px; font-size: 1rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.product-copy p { color: var(--muted); font-size: .82rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.product-meta { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.badge { border-radius: 999px; padding: 5px 8px; font-size: .7rem; font-weight: 800; background: rgba(255,255,255,.065); color: var(--muted); }
.badge.low { color: var(--warning); background: rgba(255,189,89,.12); }
.badge.out, .badge.expired { color: var(--danger); background: rgba(255,102,125,.12); }
.badge.expiring { color: var(--warning); background: rgba(255,189,89,.12); }
.badge.in_stock { color: var(--success); background: rgba(86,227,159,.12); }
.product-actions { display: flex; align-items: center; gap: 7px; }
.product-actions button { min-width: 42px; height: 42px; border: 1px solid var(--line); border-radius: 13px; background: rgba(255,255,255,.055); color: var(--text); font-weight: 900; }
.product-actions .open-product { min-width: 64px; padding: 0 10px; color: var(--accent-2); }
.quantity-copy { text-align: right; min-width: 74px; }
.quantity-copy strong { display: block; font-size: 1.2rem; }
.quantity-copy span { color: var(--muted); font-size: .74rem; }
.section-heading { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin: 8px 0 14px; }
.inline-form { display: grid; grid-template-columns: 1fr 110px 110px auto; gap: 8px; margin-bottom: 14px; }
.shopping-list, .activity-list { display: grid; gap: 9px; }
.shopping-item, .activity-item { display: flex; align-items: center; gap: 12px; padding: 13px 14px; border: 1px solid var(--line); background: var(--panel); border-radius: 16px; }
.shopping-item input[type="checkbox"] { width: 22px; height: 22px; accent-color: var(--accent-2); }
.shopping-copy, .activity-copy { flex: 1; min-width: 0; }
.shopping-copy strong, .activity-copy strong { display: block; }
.shopping-copy span, .activity-copy span { color: var(--muted); font-size: .8rem; }
.shopping-item button, .activity-item button { border: 1px solid var(--line); background: rgba(255,255,255,.05); color: var(--text); border-radius: 11px; padding: 8px 10px; }
.activity-delta { font-weight: 900; min-width: 58px; text-align: right; }
.activity-delta.positive { color: var(--success); }
.activity-delta.negative { color: var(--danger); }
.empty-state { text-align: center; color: var(--muted); padding: 42px 16px; border: 1px dashed var(--line); border-radius: 20px; }
.empty-state strong { display: block; color: var(--text); margin-bottom: 5px; }
.recipe-form { display: grid; gap: 12px; padding: 18px; border-radius: 20px; border: 1px solid var(--line); background: var(--panel); }
.recipe-form label, .form-grid label { display: grid; gap: 6px; color: var(--muted); font-size: .82rem; font-weight: 700; }
.form-row, .form-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; }
.form-grid .wide { grid-column: 1 / -1; }
textarea { min-height: 88px; resize: vertical; }
.form-message { color: var(--muted); font-size: .84rem; min-height: 1.2em; }
.recipe-results { display: grid; gap: 12px; margin-top: 14px; }
.recipe-card { border: 1px solid var(--line); background: var(--panel); border-radius: 20px; padding: 18px; }
.recipe-card h3 { margin: 0 0 6px; }
.recipe-card p, .recipe-card li { color: var(--muted); line-height: 1.45; }
.sheet-dialog { width: min(720px, calc(100% - 18px)); max-height: calc(100dvh - 18px); padding: 0; border: 1px solid var(--line); border-radius: 25px; background: var(--panel-2); color: var(--text); }
.sheet-dialog::backdrop { background: rgba(0,0,0,.72); backdrop-filter: blur(5px); }
.dialog-shell { padding: 20px; overflow-y: auto; max-height: calc(100dvh - 20px); }
.dialog-heading { display: flex; align-items: center; justify-content: space-between; margin-bottom: 18px; }
.quantity-control { display: grid; grid-template-columns: 56px 1fr 56px; align-items: center; gap: 10px; margin-bottom: 18px; }
.quantity-control button { height: 52px; border: 1px solid var(--line); border-radius: 16px; color: var(--text); background: rgba(255,255,255,.06); font-size: 1.6rem; }
.quantity-control div { text-align: center; }
.quantity-control strong { display: block; font-size: 2rem; }
.quantity-control span { color: var(--muted); }
.dialog-actions { display: flex; gap: 10px; margin-top: 14px; }
.dialog-actions button { flex: 1; }
.batch-section { border-top: 1px solid var(--line); margin-top: 18px; padding-top: 14px; }
.batch-section summary { cursor: pointer; font-weight: 800; }
.batch-item { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; padding: 12px 0; border-bottom: 1px solid var(--line); }
.batch-item button { grid-column: 1 / -1; border: 1px solid var(--line); color: var(--text); background: rgba(255,255,255,.05); border-radius: 11px; padding: 9px; }
.toast { position: fixed; left: 50%; bottom: calc(22px + env(safe-area-inset-bottom)); transform: translate(-50%, 120px); transition: transform .22s ease; z-index: 50; background: #f4f6fb; color: #090b11; border-radius: 999px; padding: 11px 16px; font-weight: 800; box-shadow: 0 12px 35px rgba(0,0,0,.35); max-width: calc(100% - 24px); }
.toast.show { transform: translate(-50%, 0); }

@media (max-width: 820px) {
  .toolbar { grid-template-columns: 1fr 1fr; }
  .search-box { grid-column: 1 / -1; }
  .product-card { grid-template-columns: 50px minmax(0,1fr); }
  .product-image { width: 50px; height: 50px; }
  .product-actions { grid-column: 1 / -1; justify-content: flex-end; }
  .quantity-copy { margin-right: auto; text-align: left; }
}

@media (max-width: 560px) {
  .app-shell { padding-left: 10px; padding-right: 10px; }
  .hero-card { align-items: flex-start; flex-direction: column; padding: 20px; }
  .scan-button { width: 100%; text-align: center; }
  .stat-grid { grid-template-columns: repeat(2, 1fr); }
  .toolbar { grid-template-columns: 1fr; }
  .search-box { grid-column: auto; }
  .inline-form { grid-template-columns: 1fr 1fr; }
  .inline-form input:first-child { grid-column: 1 / -1; }
  .inline-form button { grid-column: 1 / -1; }
  .form-row, .form-grid { grid-template-columns: 1fr; }
  .form-grid .wide { grid-column: auto; }
  .dialog-actions { flex-direction: column; }
}

/* Stage 6.1 touch-first controls */
.toolbar { grid-template-columns: minmax(220px, 1fr) repeat(4, minmax(135px, .32fr)); }
select { min-height: 48px; }
.product-copy .category-line { color: var(--accent-2); font-size: .74rem; font-weight: 800; margin-top: 3px; }
.quick-adjust { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; margin: -5px 0 18px; }
.quick-adjust button { min-height: 44px; border: 1px solid var(--line); border-radius: 13px; color: var(--text); background: rgba(255,255,255,.055); font-weight: 900; }
.date-selects { margin: 0; border: 1px solid var(--line); border-radius: 16px; padding: 10px; display: grid; grid-template-columns: .75fr 1.15fr 1fr; gap: 8px; }
.date-selects legend { padding: 0 6px; color: var(--muted); font-size: .82rem; font-weight: 700; }
.batch-item { grid-template-columns: 1fr 1fr; }
.batch-date-selects { grid-column: 1 / -1; display: grid; grid-template-columns: .75fr 1.15fr 1fr; gap: 8px; }
.remember-note { grid-column: 1 / -1; color: var(--muted); font-size: .77rem; margin-top: -2px; }

@media (max-width: 980px) {
  .toolbar { grid-template-columns: 1fr 1fr; }
  .search-box { grid-column: 1 / -1; }
}

@media (max-width: 560px) {
  .quick-adjust { grid-template-columns: repeat(4, 1fr); }
  .date-selects, .batch-date-selects { grid-template-columns: .8fr 1.1fr 1fr; }
  .date-selects select, .batch-date-selects select { padding-left: 8px; padding-right: 8px; }
}


/* Stage 6.2 remembered pack sizes */
.wide-pack-button { width: 100%; min-height: 50px; margin: -5px 0 18px; border: 1px solid rgba(255,255,255,.12); border-radius: 14px; color: var(--text); background: rgba(255,255,255,.07); font-weight: 900; }
.shopping-heading-actions{display:flex;flex-wrap:wrap;gap:8px;justify-content:flex-end}.shopping-manager-button{display:grid;place-items:center;text-decoration:none;padding:0 16px}@media(max-width:620px){.shopping-heading-actions{width:100%;justify-content:stretch}.shopping-heading-actions>*{flex:1}}
