:root {
  color-scheme: light;
  --ink: #173e36;
  --muted: #61746d;
  --paper: #f7f5ef;
  --surface: #fffdf8;
  --line: #dedbd2;
  --green: #28745f;
  --green-soft: #dfeadf;
  --coral: #d8644b;
  --gold: #e4ad3d;
  --shadow: 0 8px 24px rgba(31, 51, 44, .09);
}

* { box-sizing: border-box; }
body { margin: 0; min-height: 100vh; background: var(--paper); color: var(--ink); font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif; }
button, input, select { font: inherit; }
button { color: inherit; }
[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; }
.eyebrow { margin: 0 0 4px; color: var(--green); font-size: 12px; font-weight: 800; text-transform: uppercase; }
h1, h2, p { letter-spacing: 0; }
h1 { margin: 0; font-size: 30px; line-height: 1.1; }
h2 { margin: 0; font-size: 17px; }

.login-shell { min-height: 100vh; display: grid; place-items: center; padding: 24px; }
.login-panel { width: min(100%, 430px); background: var(--surface); border: 1px solid var(--line); padding: 32px; box-shadow: var(--shadow); border-radius: 8px; }
.brand-mark { display: grid; place-items: center; width: 48px; height: 48px; margin-bottom: 24px; background: var(--ink); color: white; font-size: 22px; font-weight: 850; border-radius: 6px; }
.login-copy { color: var(--muted); margin: 10px 0 24px; }
.login-panel label { display: block; margin-bottom: 7px; font-size: 13px; font-weight: 750; }
.login-row { display: grid; grid-template-columns: 1fr auto; gap: 8px; }
input { min-width: 0; border: 1px solid var(--line); border-radius: 6px; background: white; color: var(--ink); padding: 12px 14px; outline: none; }
input:focus { border-color: var(--green); box-shadow: 0 0 0 3px rgba(40, 116, 95, .13); }
.primary-button { border: 0; border-radius: 6px; background: var(--green); color: white; padding: 0 18px; font-weight: 750; cursor: pointer; }
.form-error { min-height: 20px; margin: 8px 0 0; color: #a83f31; font-size: 13px; }

.app-shell { min-height: 100vh; padding-bottom: env(safe-area-inset-bottom); }
.app-header { position: sticky; top: 0; z-index: 10; display: flex; align-items: center; justify-content: space-between; min-height: 82px; padding: max(16px, env(safe-area-inset-top)) max(20px, calc((100vw - 1120px) / 2)) 14px; background: rgba(247, 245, 239, .96); border-bottom: 1px solid var(--line); backdrop-filter: blur(12px); }
.header-actions { display: flex; align-items: center; gap: 12px; }
.home-link { display: inline-flex; align-items: center; min-height: 42px; padding: 0 10px; color: var(--green); font-weight: 750; }
.app-header { gap: 12px; }
.app-header > div:first-child { min-width: 0; overflow-wrap: anywhere; }
.header-actions { flex-wrap: wrap; justify-content: flex-end; }
.sync-state { color: var(--muted); font-size: 12px; font-weight: 700; }
.sync-state.error { color: #a83f31; }
.icon-button, .add-button { display: grid; place-items: center; width: 42px; height: 42px; padding: 0; border: 1px solid var(--line); border-radius: 6px; background: var(--surface); cursor: pointer; }
.icon-button svg, .add-button svg, .search-box svg { width: 20px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }

.tabs { display: flex; gap: 24px; max-width: 1120px; margin: 0 auto; padding: 0 20px; border-bottom: 1px solid var(--line); overflow-x: auto; }
.tab { min-height: 54px; padding: 0; border: 0; border-bottom: 3px solid transparent; background: transparent; color: var(--muted); font-weight: 760; cursor: pointer; }
.tab.active { border-color: var(--coral); color: var(--ink); }
.count { display: inline-grid; place-items: center; min-width: 22px; height: 22px; margin-left: 5px; padding: 0 6px; background: var(--green-soft); border-radius: 11px; font-size: 12px; }
.content { width: min(100%, 1120px); margin: 0 auto; padding: 24px 20px 72px; }
.view { max-width: 760px; margin: 0 auto; }
.quick-add { display: grid; grid-template-columns: 1fr 46px; gap: 8px; margin-bottom: 20px; }
.quick-add input { height: 46px; }
.add-button { width: 46px; height: 46px; border-color: var(--green); background: var(--green); color: white; }
.list-toolbar, .shop-toolbar { display: flex; align-items: center; justify-content: space-between; gap: 16px; margin: 0 0 14px; }
.list-cost, .toolbar-copy { color: var(--muted); font-size: 12px; font-weight: 680; }
.toolbar-copy { margin: 4px 0 0; }
.sort-control { display: flex; align-items: center; gap: 7px; color: var(--muted); font-size: 12px; font-weight: 720; }
.sort-control select { max-width: 170px; height: 38px; padding: 0 30px 0 10px; border: 1px solid var(--line); border-radius: 6px; background: var(--surface); color: var(--ink); }
.item-list { display: grid; gap: 8px; }
.shopping-item { display: grid; grid-template-columns: 28px 52px minmax(0, 1fr) auto; align-items: center; gap: 12px; min-height: 74px; padding: 9px 12px; background: var(--surface); border: 1px solid var(--line); border-radius: 7px; }
.shopping-item.completed, .shop-item.completed { opacity: .68; }
.shopping-item.completed .item-title, .shop-item.completed .item-title { text-decoration: line-through; }
.check-button { display: grid; place-items: center; width: 44px; height: 44px; margin: -9px; padding: 0; border: 0; border-radius: 50%; background: transparent; cursor: pointer; }
.check-button::before { content: ""; box-sizing: border-box; display: grid; place-items: center; width: 26px; height: 26px; border: 2px solid #9aaba4; border-radius: 50%; }
.check-button.checked::before { content: "✓"; border-color: var(--green); background: var(--green); color: white; font-weight: 850; }
.item-image { width: 52px; height: 52px; object-fit: contain; background: white; border: 1px solid #ece9e0; border-radius: 5px; }
.item-image.placeholder { display: grid; place-items: center; background: var(--green-soft); color: var(--green); font-weight: 850; }
.item-copy { min-width: 0; }
.item-summary-button { width: 100%; padding: 6px 0; border: 0; background: transparent; text-align: left; cursor: pointer; }
.item-title { overflow-wrap: anywhere; font-size: 15px; font-weight: 760; line-height: 1.25; }
.item-meta { margin-top: 4px; color: var(--muted); font-size: 12px; }
.price { margin-left: 6px; color: var(--ink); font-weight: 780; }
.item-row-actions { display: flex; align-items: center; gap: 9px; }
.cost-display { display: grid; min-width: 70px; justify-items: end; line-height: 1.2; }
.each-cost, .cost-missing { color: var(--muted); font-size: 10px; white-space: nowrap; }
.total-cost { font-size: 14px; white-space: nowrap; }
.quantity-control { display: grid; grid-template-columns: 32px 34px 32px; align-items: center; border: 1px solid var(--line); border-radius: 6px; overflow: hidden; }
.quantity-control button { width: 32px; height: 34px; padding: 0; border: 0; background: #f0eee8; cursor: pointer; font-size: 18px; }
.quantity-value { text-align: center; font-size: 13px; font-weight: 780; }
.section-heading { display: flex; align-items: center; justify-content: space-between; margin: 32px 0 10px; }
.text-button { border: 0; background: transparent; font-size: 13px; font-weight: 740; cursor: pointer; }
.text-button.danger { color: #a83f31; }
.text-button[data-clear-checked] { min-height: 44px; }
.text-button:disabled { opacity: .5; cursor: default; }
.delete-button { display: grid; place-items: center; width: 34px; height: 34px; padding: 0; border: 1px solid var(--line); border-radius: 6px; background: var(--surface); color: #a83f31; cursor: pointer; }
.delete-button svg { width: 18px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.empty-state { padding: 64px 20px; text-align: center; color: var(--muted); }
.empty-state h2 { margin-bottom: 6px; color: var(--ink); }
.empty-state p { margin: 0; }
.empty-icon { display: grid; place-items: center; width: 48px; height: 48px; margin: 0 auto 14px; border: 2px solid var(--green); border-radius: 50%; color: var(--green); font-size: 22px; }

.search-box { position: relative; margin-bottom: 14px; }
.search-box svg { position: absolute; left: 14px; top: 13px; color: var(--muted); }
.search-box input { width: 100%; height: 46px; padding-left: 44px; }
.filter-row { display: flex; gap: 7px; overflow-x: auto; padding: 0 0 15px; scrollbar-width: none; }
.filter-chip { flex: 0 0 auto; border: 1px solid var(--line); border-radius: 15px; background: var(--surface); padding: 7px 11px; font-size: 12px; font-weight: 720; cursor: pointer; }
.filter-chip.active { border-color: var(--ink); background: var(--ink); color: white; }
.catalogue-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
.catalogue-item { display: grid; grid-template-columns: 70px minmax(0, 1fr) 40px; align-items: center; min-height: 94px; gap: 12px; padding: 11px; border: 1px solid var(--line); border-radius: 7px; background: var(--surface); }
.catalogue-item .item-image { width: 70px; height: 70px; }
.catalogue-add { display: grid; place-items: center; width: 38px; height: 38px; padding: 0; border: 1px solid var(--green); border-radius: 50%; background: transparent; color: var(--green); font-size: 22px; cursor: pointer; }
.catalogue-add.in-list { border-color: var(--line); background: var(--green-soft); font-size: 16px; }
.shop-list { display: grid; gap: 12px; }
#checkedShopSection { margin-top: 12px; }
.aisle-group { overflow: hidden; border: 1px solid var(--line); border-radius: 7px; background: var(--surface); }
.aisle-heading { display: flex; align-items: center; justify-content: space-between; padding: 14px 15px; background: var(--green-soft); border-bottom: 1px solid var(--line); }
.aisle-count { color: var(--muted); font-size: 12px; font-weight: 720; }
.shop-item { display: grid; grid-template-columns: 28px 48px minmax(0, 1fr) auto 34px; align-items: center; gap: 11px; min-height: 72px; padding: 9px 12px; border-bottom: 1px solid var(--line); }
.shop-item:last-child { border-bottom: 0; }
.shop-item .item-image { width: 48px; height: 48px; }

.details-dialog { width: min(92vw, 620px); max-height: min(88vh, 760px); padding: 0; border: 1px solid var(--line); border-radius: 8px; background: var(--surface); color: var(--ink); box-shadow: 0 24px 70px rgba(21, 48, 40, .24); }
.details-dialog::backdrop { background: rgba(19, 38, 33, .42); backdrop-filter: blur(2px); }
.details-header { display: flex; align-items: center; justify-content: space-between; gap: 16px; padding: 20px 22px; border-bottom: 1px solid var(--line); }
.details-body { display: grid; grid-template-columns: 170px minmax(0, 1fr); gap: 22px; padding: 22px; overflow-y: auto; }
.details-image { display: grid; place-items: center; width: 170px; height: 170px; border: 1px solid var(--line); border-radius: 7px; background: white; }
.details-image .item-image { width: 150px; height: 150px; border: 0; }
.details-facts { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
.details-facts div { min-width: 0; padding: 11px; border: 1px solid var(--line); border-radius: 6px; }
.details-facts span, .details-notes span { display: block; margin-bottom: 4px; color: var(--muted); font-size: 11px; font-weight: 720; }
.details-facts strong { display: block; overflow-wrap: anywhere; font-size: 14px; }
.details-notes { grid-column: 1 / -1; padding: 13px; background: var(--paper); border-radius: 6px; }
.details-notes p { margin: 0; font-size: 14px; }
.product-link { grid-column: 1 / -1; display: flex; align-items: center; justify-content: space-between; min-height: 46px; padding: 0 14px; border: 1px solid var(--green); border-radius: 6px; color: var(--green); font-size: 14px; font-weight: 760; text-decoration: none; }
.product-link svg { width: 18px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.product-matcher { grid-column: 1 / -1; padding-top: 16px; border-top: 1px solid var(--line); }
.matcher-heading { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; margin-bottom: 12px; }
.matcher-heading h3 { margin: 0; font-size: 16px; }
.matcher-heading p { margin: 3px 0 0; color: var(--muted); font-size: 12px; }
.matcher-search { margin-bottom: 9px; }
.product-results { display: grid; gap: 7px; max-height: 330px; overflow-y: auto; }
.product-result { display: grid; grid-template-columns: 52px minmax(0, 1fr) auto; align-items: center; gap: 10px; padding: 8px; border: 1px solid var(--line); border-radius: 6px; background: white; }
.product-result.selected { background: var(--green-soft); }
.product-result .item-image { width: 52px; height: 52px; }
.product-result .secondary-button { white-space: nowrap; }
.matcher-empty { margin: 18px 0 4px; color: var(--muted); text-align: center; font-size: 13px; }
.retailer-search-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-top: 12px; }
.retailer-search-row .matcher-empty { margin: 0; }
.retailer-results-block { border-top: 1px solid var(--line); margin-top: 16px; padding-top: 16px; }
.retailer-results-heading { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; margin-bottom: 10px; }
.retailer-results-heading h4 { font-size: 15px; margin: 0; }
.retailer-results-heading span { color: var(--muted); font-size: 13px; }
.external-product-import { display: grid; gap: 10px; margin-top: 12px; }
.external-product-import p { margin: 0; color: var(--muted); font-size: 13px; }
.external-product-import label { display: grid; gap: 5px; color: var(--muted); font-size: 12px; font-weight: 700; }
.external-product-import input { min-width: 0; height: 42px; padding: 0 11px; border: 1px solid var(--line); border-radius: 6px; }
.import-product-fields { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.external-product-import .primary-button { justify-self: end; min-height: 42px; }
.details-actions { display: flex; justify-content: flex-end; gap: 9px; padding: 15px 22px max(15px, env(safe-area-inset-bottom)); border-top: 1px solid var(--line); }
.secondary-button { min-height: 42px; padding: 0 16px; border: 1px solid var(--line); border-radius: 6px; background: var(--surface); font-weight: 740; cursor: pointer; }
.secondary-button.danger { color: #a83f31; }
.details-primary { min-height: 42px; cursor: pointer; }
.toast { position: fixed; left: 50%; bottom: max(24px, env(safe-area-inset-bottom)); z-index: 30; transform: translateX(-50%); max-width: calc(100vw - 32px); padding: 11px 16px; border-radius: 6px; background: var(--ink); color: white; box-shadow: var(--shadow); font-size: 13px; font-weight: 700; }

@media (max-width: 720px) {
  .app-header { padding-left: 16px; padding-right: 16px; }
  .content, .tabs { padding-left: 12px; padding-right: 12px; }
  .catalogue-grid { grid-template-columns: 1fr; }
  .shopping-item { grid-template-columns: 28px 44px minmax(0, 1fr); gap: 9px; }
  .shopping-item .item-row-actions { grid-column: 2 / -1; justify-content: flex-end; }
  .item-image { width: 44px; height: 44px; }
  .quantity-control { grid-template-columns: 28px 28px 28px; }
  .quantity-control button { width: 28px; }
  .details-body { grid-template-columns: 1fr; }
  .details-image { width: 100%; height: 180px; }
  .details-image .item-image { width: 160px; height: 160px; }
}

@media (max-width: 420px) {
  .retailer-search-row { align-items: stretch; flex-direction: column; }
  .import-product-fields { grid-template-columns: 1fr; }
  .login-panel { padding: 24px 18px; }
  .login-row { grid-template-columns: 1fr; }
  .primary-button { min-height: 44px; }
  .tab { white-space: nowrap; }
  .tabs { gap: 20px; scrollbar-width: none; }
  .list-toolbar { align-items: flex-start; }
  .shop-toolbar { display: grid; grid-template-columns: 1fr; align-items: start; }
  .shop-toolbar .sort-control { justify-content: space-between; }
  .shop-toolbar .sort-control select { flex: 1; max-width: none; }
  .list-cost { max-width: 180px; }
  .shopping-item { grid-template-columns: 28px minmax(0, 1fr); }
  .shopping-item .item-image { display: none; }
  .shopping-item .item-row-actions { grid-column: 2; flex-wrap: wrap; }
  .shop-item { grid-template-columns: 28px minmax(0, 1fr) auto 34px; gap: 8px; }
  .shop-item > * { min-width: 0; }
  .shop-item .item-image { display: none; }
  .shop-item .cost-display { min-width: 58px; }
  .details-dialog { width: 100vw; max-width: none; max-height: 92vh; margin: auto 0 0; border-radius: 8px 8px 0 0; }
  .details-header, .details-body, .details-actions { padding-left: 16px; padding-right: 16px; }
  .product-result { grid-template-columns: 44px minmax(0, 1fr); }
  .product-result .item-image { width: 44px; height: 44px; }
  .product-result .secondary-button { grid-column: 2; justify-self: start; }
  .details-actions { flex-wrap: wrap; }
}
