:root {
  color-scheme: dark;
  --bg: #0d0f10;
  --surface: #15181a;
  --surface-2: #1c2023;
  --surface-3: #252a2e;
  --line: #30363a;
  --muted: #8f999f;
  --text: #f5f7f8;
  --accent: #ffb340;
  --accent-soft: #3d2b13;
  --green: #7fdba4;
  --danger: #ff6f6f;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  font-family: Inter, ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }
html { background: var(--bg); }
body { margin: 0; min-height: 100vh; background: var(--bg); color: var(--text); }
button, input, select { font: inherit; }
button { color: inherit; }
button, select { -webkit-tap-highlight-color: transparent; }
svg { fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
[hidden] { display: none !important; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0,0,0,0); white-space: nowrap; border: 0; }

.app-shell { width: min(100%, 560px); min-height: 100vh; margin: 0 auto; background: var(--bg); padding-bottom: calc(94px + var(--safe-bottom)); }
.topbar { position: sticky; z-index: 15; top: 0; display: flex; align-items: center; justify-content: space-between; padding: max(18px, env(safe-area-inset-top)) 20px 14px; background: linear-gradient(180deg, rgba(13,15,16,.98) 78%, rgba(13,15,16,0)); }
.topbar h1, .page-heading h2, .sheet-header h2 { margin: 1px 0 0; font-size: 1.75rem; line-height: 1.12; letter-spacing: -.04em; }
.eyebrow, .storage-kicker { margin: 0; color: var(--muted); font-size: .72rem; font-weight: 750; letter-spacing: .12em; }
.icon-button, .close-button { display: grid; place-items: center; width: 46px; height: 46px; padding: 0; border: 0; border-radius: 50%; background: var(--accent); color: #181108; cursor: pointer; }
.icon-button svg { width: 24px; height: 24px; stroke-width: 2.3; }
.close-button { width: 40px; height: 40px; background: var(--surface-3); color: var(--text); font-size: 1.75rem; font-weight: 300; }

.view { display: none; padding: 4px 16px 18px; }
.view.is-active { display: block; animation: fade-in .18s ease-out; }
@keyframes fade-in { from { opacity: 0; transform: translateY(3px); } }
.search-box { display: flex; align-items: center; gap: 10px; min-height: 50px; margin: 2px 4px 17px; padding: 0 15px; border: 1px solid var(--line); border-radius: 15px; background: var(--surface); }
.search-box svg { flex: 0 0 auto; width: 21px; color: var(--muted); }
.search-box input { width: 100%; min-width: 0; border: 0; outline: 0; background: transparent; color: var(--text); font-size: 1rem; }
.search-box input::placeholder { color: #768087; }

.storage-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
.storage-card { position: relative; min-width: 0; min-height: 184px; overflow: hidden; padding: 16px; border: 1px solid var(--line); border-radius: 22px; background: linear-gradient(145deg, #1c2022, #141719); color: var(--text); text-align: left; box-shadow: 0 14px 36px rgba(0,0,0,.18); }
button.storage-card { cursor: pointer; }
button.storage-card:active, .fridge-zone:active { transform: scale(.985); }
.fridge-card { grid-column: 1 / -1; min-height: 255px; background: radial-gradient(circle at 85% 0, rgba(255,179,64,.12), transparent 36%), linear-gradient(145deg, #202427, #151719); }
.storage-card-heading, .card-title-row { display: flex; align-items: flex-start; justify-content: space-between; gap: 10px; }
.storage-card-heading h3 { margin: 5px 0 0; font-size: 1.35rem; letter-spacing: -.025em; }
.card-title-row { margin-top: 5px; }
.card-title-row strong { max-width: 115px; font-size: 1.08rem; line-height: 1.17; letter-spacing: -.02em; }
.count-pill { flex: 0 0 auto; padding: 5px 8px; border-radius: 99px; background: var(--surface-3); color: #c6cdd1; font-size: .72rem; font-weight: 700; }
.fridge-map { display: grid; grid-template-columns: 42% 1fr; gap: 8px; height: 165px; margin-top: 15px; }
.fridge-zone { position: relative; display: flex; align-items: flex-end; gap: 10px; min-width: 0; padding: 13px; border: 1px solid #3a4145; border-radius: 14px; background: rgba(9,11,12,.52); color: var(--text); text-align: left; cursor: pointer; }
.fridge-zone > span:nth-child(2) { min-width: 0; }
.fridge-zone strong, .fridge-zone small { display: block; }
.fridge-zone strong { margin-bottom: 3px; font-size: .94rem; }
.fridge-zone small { overflow: hidden; color: var(--muted); font-size: .75rem; text-overflow: ellipsis; white-space: nowrap; }
.fridge-zone svg { width: 18px; margin-left: auto; color: var(--muted); }
.freezer-zone { align-items: center; }
.snow-icon { display: grid; place-items: center; width: 30px; height: 30px; border-radius: 9px; background: #19323a; color: #86d9f0; font-size: 1.3rem; }
.main-fridge-zone { padding-top: 76px; }
.shelf-lines { position: absolute; inset: 15px 14px auto; display: grid; gap: 16px; }
.shelf-lines i { height: 1px; background: #596166; }
.shelf-lines i::before, .shelf-lines i::after { content: ""; display: inline-block; width: 24px; height: 18px; margin: -18px 8px 0 5px; border-radius: 8px 8px 2px 2px; background: #353c40; }
.cabinet-card { min-height: 275px; }
.card-foot { position: absolute; right: 15px; bottom: 14px; left: 15px; overflow: hidden; color: var(--muted); font-size: .75rem; text-overflow: ellipsis; white-space: nowrap; }
.cabinet-visual { display: grid; gap: 12px; margin: 22px 5px 38px; padding: 14px 12px; border: 1px solid #3a4145; border-radius: 9px 9px 13px 13px; box-shadow: inset 5px 0 #22272a; }
.cabinet-visual i { display: block; height: 36px; padding: 8px 10px; border-bottom: 2px solid #596166; color: #c78d3b; font-size: 1rem; font-style: normal; letter-spacing: 8px; }
.cupboard-card { min-height: 275px; background: radial-gradient(circle at 100% 100%, rgba(127,219,164,.10), transparent 42%), var(--surface); }
.box-visual { position: relative; display: block; height: 142px; margin: 20px 4px 35px; }
.box-visual i { position: absolute; bottom: 0; width: 68%; height: 64px; border: 1px solid #555f64; background: #24292c; }
.box-visual i:nth-child(1) { left: 0; transform: translateY(-55px); }
.box-visual i:nth-child(2) { right: 0; width: 58%; transform: translateY(-4px); }
.box-visual i:nth-child(3) { left: 4%; width: 48%; height: 48px; }
.tray-card, .basket-card { min-height: 190px; }
.tray-visual, .nutrition-visual { display: flex; align-items: flex-end; gap: 8px; height: 70px; margin: 18px 4px 34px; padding: 0 10px 7px; border-bottom: 6px solid #4a5257; border-radius: 0 0 7px 7px; }
.tray-visual i { width: 25%; height: 62px; border: 1px solid #5b646a; border-radius: 4px; transform: skew(-3deg); }
.tray-visual i:nth-child(2) { height: 50px; }
.tray-visual i:nth-child(3) { height: 58px; background: #2d2620; }
.nutrition-visual i { width: 34px; height: 56px; border: 1px solid #596268; border-radius: 7px 7px 4px 4px; background: #24292c; }
.nutrition-visual i:nth-child(2) { height: 68px; background: #322719; }
.nutrition-visual i:nth-child(3) { width: 42px; height: 49px; }
.basket-card { grid-column: 1 / -1; min-height: 170px; }
.basket-visual { display: flex; align-items: flex-end; justify-content: center; gap: 8px; height: 72px; margin: 16px 7px 26px; border: 1px solid #525b60; border-top: 0; border-radius: 0 0 17px 17px; background: repeating-linear-gradient(90deg, transparent 0 18px, #353b3f 19px 21px); }
.basket-visual i { width: 31px; height: 49px; border: 1px solid #596268; border-radius: 8px 8px 4px 4px; background: #262b2e; }
.basket-visual i:nth-child(2) { height: 60px; background: #322719; }
.basket-visual i:nth-child(4) { height: 43px; }

.search-results { display: grid; gap: 9px; margin: -3px 2px 16px; }
.search-result { display: flex; align-items: center; gap: 12px; width: 100%; padding: 13px; border: 1px solid var(--line); border-radius: 15px; background: var(--surface); text-align: left; }
.search-result .result-letter { display: grid; place-items: center; flex: 0 0 auto; width: 40px; height: 40px; border-radius: 12px; background: var(--surface-3); color: var(--accent); font-weight: 800; }
.search-result span:nth-child(2) { min-width: 0; }
.search-result strong, .search-result small { display: block; }
.search-result small { margin-top: 2px; color: var(--muted); }
.search-result .result-qty { margin-left: auto; color: var(--text); font-size: .9rem; font-weight: 750; white-space: nowrap; }

.page-heading { display: flex; align-items: flex-end; justify-content: space-between; padding: 5px 4px 0; }
.page-heading h2 { font-size: 2rem; }
.large-count { color: var(--accent); font-size: 2.1rem; font-weight: 800; line-height: 1; }
.page-note { margin: 8px 4px 22px; color: var(--muted); line-height: 1.45; }
.buy-groups, .activity-list { display: grid; gap: 12px; }
.shop-group { overflow: hidden; border: 1px solid var(--line); border-radius: 18px; background: var(--surface); }
.shop-header { display: flex; align-items: center; width: 100%; padding: 15px; border: 0; background: transparent; text-align: left; }
.shop-mark { display: grid; place-items: center; width: 38px; height: 38px; margin-right: 11px; border-radius: 11px; background: var(--accent-soft); color: var(--accent); font-weight: 800; }
.shop-header strong { font-size: 1.02rem; }
.shop-header small { display: block; margin-top: 2px; color: var(--muted); }
.shop-chevron { width: 18px; margin-left: auto; color: var(--muted); transition: transform .2s; }
.shop-group.is-collapsed .shop-chevron { transform: rotate(-90deg); }
.shop-group.is-collapsed .shop-items { display: none; }
.shop-items { border-top: 1px solid var(--line); }

.item-row-shell { position: relative; overflow: hidden; background: #391c1c; }
.item-row-shell + .item-row-shell { border-top: 1px solid var(--line); }
.delete-reveal { position: absolute; inset: 0 0 0 auto; display: grid; place-items: center; width: 88px; border: 0; background: #b83f45; color: white; font-size: .78rem; font-weight: 800; letter-spacing: .03em; }
.item-row { position: relative; z-index: 1; display: flex; align-items: center; gap: 10px; min-height: 74px; padding: 10px 12px 10px 14px; background: var(--surface); transition: transform .18s ease; touch-action: pan-y; }
.item-row-shell.is-swiped .item-row { transform: translateX(-88px); }
.item-main { min-width: 0; flex: 1; border: 0; padding: 0; background: transparent; text-align: left; }
.item-main strong { display: block; overflow: hidden; font-size: 1rem; text-overflow: ellipsis; white-space: nowrap; }
.item-main small { display: block; margin-top: 4px; overflow: hidden; color: var(--muted); font-size: .75rem; text-overflow: ellipsis; white-space: nowrap; }
.out-label { color: var(--danger) !important; }
.stepper { display: flex; align-items: center; gap: 2px; flex: 0 0 auto; padding: 3px; border: 1px solid var(--line); border-radius: 13px; background: #101214; }
.stepper button { width: 36px; height: 36px; padding: 0; border: 0; border-radius: 10px; background: var(--surface-3); font-size: 1.25rem; }
.stepper button:disabled { opacity: .35; }
.quantity-button { min-width: 58px; height: 36px; padding: 0 6px; border: 0; background: transparent; color: var(--text); font-size: .85rem; font-weight: 800; }
.buy-row .item-row { min-height: 78px; }
.restock-button { flex: 0 0 auto; padding: 10px 12px; border: 0; border-radius: 11px; background: var(--accent); color: #171008; font-size: .78rem; font-weight: 800; }
.shop-select-inline { max-width: 106px; margin-top: 5px; padding: 0; border: 0; background: transparent; color: var(--muted); font-size: .72rem; }

.empty-state { padding: 38px 22px; border: 1px dashed #3b4246; border-radius: 20px; color: var(--muted); text-align: center; }
.empty-state .empty-icon { display: grid; place-items: center; width: 52px; height: 52px; margin: 0 auto 13px; border-radius: 17px; background: var(--surface-2); color: var(--green); font-size: 1.5rem; }
.empty-state h3 { margin: 0 0 6px; color: var(--text); font-size: 1.08rem; }
.empty-state p { max-width: 290px; margin: 0 auto; font-size: .9rem; line-height: 1.5; }

.activity-entry { display: grid; grid-template-columns: 42px 1fr auto; align-items: center; gap: 11px; min-height: 70px; padding: 12px; border: 1px solid var(--line); border-radius: 17px; background: var(--surface); }
.activity-icon { display: grid; place-items: center; width: 42px; height: 42px; border-radius: 13px; background: var(--surface-3); color: var(--accent); font-size: 1.1rem; font-weight: 800; }
.activity-entry strong, .activity-entry small { display: block; }
.activity-entry small { margin-top: 3px; color: var(--muted); font-size: .76rem; }
.activity-time { color: var(--muted); font-size: .7rem; }

.bottom-nav { position: fixed; z-index: 25; right: 0; bottom: 0; left: 0; display: grid; grid-template-columns: repeat(3, 1fr); width: min(100%, 560px); margin: 0 auto; padding: 9px 14px calc(9px + var(--safe-bottom)); border-top: 1px solid rgba(55,62,66,.85); background: rgba(18,21,23,.94); backdrop-filter: blur(18px); }
.nav-button { display: grid; place-items: center; gap: 3px; min-height: 54px; border: 0; border-radius: 15px; background: transparent; color: #7d878d; font-size: .69rem; font-weight: 700; }
.nav-button svg { width: 22px; height: 22px; }
.nav-button.is-active { background: var(--surface-3); color: var(--text); }
.nav-button.is-active svg { color: var(--accent); }
.nav-icon-wrap { position: relative; display: grid; place-items: center; }
.nav-icon-wrap b { position: absolute; top: -7px; right: -10px; min-width: 18px; height: 18px; padding: 2px 5px; border: 2px solid var(--surface); border-radius: 99px; background: var(--danger); color: white; font-size: .62rem; line-height: 10px; }

.backdrop { position: fixed; z-index: 40; inset: 0; background: rgba(0,0,0,.62); backdrop-filter: blur(2px); }
.bottom-sheet { position: fixed; z-index: 45; right: 0; bottom: 0; left: 0; width: min(100%, 560px); max-height: 88vh; margin: 0 auto; overflow-y: auto; padding: 8px 16px calc(16px + var(--safe-bottom)); border: 1px solid var(--line); border-bottom: 0; border-radius: 26px 26px 0 0; background: #15181a; box-shadow: 0 -18px 60px rgba(0,0,0,.45); animation: sheet-up .25s cubic-bezier(.2,.8,.2,1); }
@keyframes sheet-up { from { transform: translateY(100%); } }
.sheet-handle { width: 43px; height: 5px; margin: 1px auto 13px; border-radius: 99px; background: #41484c; }
.sheet-header { display: flex; align-items: center; justify-content: space-between; gap: 15px; padding: 0 2px 16px; }
.segment-control { display: grid; grid-template-columns: 1fr 1fr; gap: 4px; margin: -3px 0 14px; padding: 4px; border-radius: 13px; background: #0e1011; }
.segment-control button { min-height: 40px; border: 0; border-radius: 10px; background: transparent; color: var(--muted); font-weight: 750; }
.segment-control button.is-active { background: var(--surface-3); color: var(--text); }
.item-list { overflow: hidden; border: 1px solid var(--line); border-radius: 17px; background: var(--surface); }
.item-list > .empty-state { border: 0; }
.sticky-sheet-button { position: sticky; bottom: 0; margin-top: 14px; box-shadow: 0 -14px 25px #15181a; }

.item-form { display: grid; gap: 14px; }
.field { display: grid; gap: 7px; }
.field span { color: #b3bcc1; font-size: .79rem; font-weight: 700; }
.field input, .field select { width: 100%; min-width: 0; height: 51px; padding: 0 13px; border: 1px solid #3b4347; border-radius: 13px; outline: 0; background: #101213; color: var(--text); font-size: 1rem; }
.field input:focus, .field select:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(255,179,64,.11); }
.field input[readonly] { color: var(--muted); }
.form-row { display: grid; gap: 11px; }
.form-row.two-one { grid-template-columns: 1.7fr 1fr; }
.primary-button, .secondary-button, .danger-button { min-height: 52px; padding: 0 18px; border: 0; border-radius: 14px; font-weight: 800; }
.primary-button { background: var(--accent); color: #181108; }
.secondary-button { background: var(--surface-3); color: var(--text); }
.danger-button { background: #c8464c; color: white; }
.danger-text-button { min-height: 44px; border: 0; background: transparent; color: var(--danger); font-weight: 750; }
.restock-name { margin: -2px 0 2px; font-size: 1.25rem; font-weight: 800; }

.dialog-backdrop { position: fixed; z-index: 70; inset: 0; display: grid; place-items: center; padding: 22px; background: rgba(0,0,0,.72); backdrop-filter: blur(4px); }
.confirm-dialog { width: min(100%, 360px); padding: 25px; border: 1px solid var(--line); border-radius: 24px; background: var(--surface-2); text-align: center; box-shadow: 0 25px 80px rgba(0,0,0,.45); }
.confirm-icon { display: grid; place-items: center; width: 48px; height: 48px; margin: 0 auto 14px; border-radius: 15px; background: #442326; color: var(--danger); font-size: 1.4rem; font-weight: 900; }
.confirm-dialog h2 { margin: 0; font-size: 1.3rem; }
.confirm-dialog p { margin: 9px 0 20px; color: var(--muted); line-height: 1.45; }
.dialog-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 9px; }
.toast { position: fixed; z-index: 90; right: 16px; bottom: calc(88px + var(--safe-bottom)); left: 16px; width: min(calc(100% - 32px), 440px); margin: 0 auto; padding: 13px 15px; border: 1px solid #3e474b; border-radius: 13px; background: #242a2d; color: var(--text); font-size: .88rem; font-weight: 650; text-align: center; box-shadow: 0 12px 36px rgba(0,0,0,.38); animation: toast-in .2s ease-out; }
@keyframes toast-in { from { opacity: 0; transform: translateY(8px); } }

@media (min-width: 700px) {
  body { background: #090a0b; }
  .app-shell { border-right: 1px solid #24282b; border-left: 1px solid #24282b; }
}

@media (max-width: 365px) {
  .view { padding-right: 12px; padding-left: 12px; }
  .storage-grid { gap: 9px; }
  .storage-card { padding: 13px; border-radius: 19px; }
  .card-title-row strong { font-size: .98rem; }
  .fridge-map { grid-template-columns: 1fr; height: auto; }
  .fridge-zone { min-height: 80px; }
  .main-fridge-zone { padding-top: 46px; }
  .shelf-lines { gap: 8px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; animation-duration: .01ms !important; transition-duration: .01ms !important; }
}
