:root {
  --bg: #f4f7fb;
  --card: #ffffff;
  --text: #162033;
  --muted: #667085;
  --line: #e4e9f2;
  --primary: #2563eb;
  --primary-dark: #1d4ed8;
  --success: #15803d;
  --success-soft: #ecfdf3;
  --danger: #b42318;
  --danger-soft: #fff1f0;
  --warning: #b54708;
  --shadow: 0 6px 20px rgba(19, 33, 68, .06);
  --shadow-hover: 0 10px 26px rgba(19, 33, 68, .10);
  --shadow-menu: 0 16px 40px rgba(16, 24, 40, .22);
  --topbar-bg: rgba(255, 255, 255, .94);
  --surface-subtle: #f8fafc;
  --surface-hover: #fbfcfe;
  --input-bg: #ffffff;
  --input-border: #cfd7e6;
  --label: #344054;
  --secondary: #475467;
  --primary-soft: #eaf1ff;
  --icon-soft: #eef4ff;
  --neutral-soft: #f2f4f7;
  --radius: 14px;
}

html[data-theme="dark"] {
  color-scheme: dark;
  --bg: #0b1220;
  --card: #111a2b;
  --text: #edf2ff;
  --muted: #9aa9bf;
  --line: #26364e;
  --primary: #7da5ff;
  --primary-dark: #9ab8ff;
  --success: #35c774;
  --success-soft: #102b20;
  --danger: #ff8a80;
  --danger-soft: #321a1d;
  --warning: #ffbd66;
  --shadow: 0 8px 24px rgba(0, 0, 0, .22);
  --shadow-hover: 0 12px 30px rgba(0, 0, 0, .32);
  --shadow-menu: 0 18px 44px rgba(0, 0, 0, .52);
  --topbar-bg: rgba(11, 18, 32, .94);
  --surface-subtle: #162236;
  --surface-hover: #17243a;
  --input-bg: #0d1728;
  --input-border: #344761;
  --label: #c8d2e1;
  --secondary: #b5c1d3;
  --primary-soft: #172d55;
  --icon-soft: #182c4d;
  --neutral-soft: #1b293e;
}

* { box-sizing: border-box; }
html { color-scheme: light; scroll-padding-top: 70px; }
body {
  margin: 0;
  min-width: 320px;
  min-height: 100vh;
  overflow-x: hidden;
  background: var(--bg);
  color: var(--text);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  line-height: 1.4;
}
button, input, select { font: inherit; }
a { color: inherit; }
h1, h2, h3, p { margin-top: 0; }
h1 { margin-bottom: .25rem; font-size: 1.72rem; line-height: 1.08; letter-spacing: -.035em; }
h2 { margin-bottom: .3rem; font-size: 1.15rem; }
h3 { margin-bottom: .15rem; font-size: 1rem; }

/* Mobile-first shell */
.topbar {
  position: sticky;
  top: 0;
  z-index: 30;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: .5rem;
  min-height: 56px;
  padding: .5rem .65rem;
  border-bottom: 1px solid var(--line);
  background: var(--topbar-bg);
  backdrop-filter: none;
}
.brand { display: inline-flex; min-width: 0; align-items: center; gap: .5rem; font-weight: 850; text-decoration: none; }
.brand-mark { display: grid; flex: 0 0 auto; place-items: center; width: 34px; height: 34px; border-radius: 10px; background: var(--primary-soft); font-size: 1rem; }
.brand-name { overflow: hidden; font-size: .92rem; text-overflow: ellipsis; white-space: nowrap; }
.user-menu { display: flex; flex: 0 0 auto; align-items: center; gap: .35rem; }
.user-menu form { margin: 0; }
.user-name { display: none; color: var(--muted); font-size: .82rem; }
.logout-icon { display: inline; }
.logout-label { display: none; }

.main-nav {
  position: fixed;
  right: 0;
  bottom: 0;
  left: 0;
  z-index: 40;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: .25rem;
  padding: .35rem .5rem calc(.35rem + env(safe-area-inset-bottom));
  border-top: 1px solid var(--line);
  background: var(--topbar-bg);
  box-shadow: 0 -8px 24px rgba(16, 24, 40, .08);
  backdrop-filter: blur(16px);
}
.main-nav a {
  display: grid;
  min-width: 0;
  min-height: 48px;
  place-items: center;
  align-content: center;
  gap: .05rem;
  padding: .25rem .35rem;
  border-radius: 10px;
  color: var(--muted);
  font-size: .72rem;
  font-weight: 800;
  line-height: 1.15;
  text-align: center;
  text-decoration: none;
}
.main-nav a.active { background: var(--primary-soft); color: var(--primary); }
.nav-icon { font-size: 1rem; line-height: 1; }

.page {
  width: min(100% - 1rem, 1120px);
  margin: 0 auto;
  padding: .9rem 0 calc(5.4rem + env(safe-area-inset-bottom));
}
.card { border: 1px solid var(--line); border-radius: var(--radius); background: var(--card); box-shadow: var(--shadow); }
.hero-row { display: flex; align-items: center; justify-content: space-between; gap: .75rem; margin-bottom: .8rem; }
.hero-row > div { min-width: 0; }
.hero-row p { margin-bottom: 0; }
.hero-row .muted { font-size: .83rem; }
.eyebrow { margin-bottom: .22rem; color: var(--primary); font-size: .68rem; font-weight: 850; letter-spacing: .11em; text-transform: uppercase; }
.muted { color: var(--muted); }
.small { font-size: .78rem; }
.grow { flex: 1; }
.min-width-0 { min-width: 0; }
.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; }

label { display: grid; gap: .28rem; color: var(--label); font-size: .8rem; font-weight: 750; }
input, select {
  width: 100%;
  min-width: 0;
  min-height: 42px;
  padding: .58rem .7rem;
  border: 1px solid var(--input-border);
  border-radius: 10px;
  outline: none;
  background: var(--input-bg);
  color: var(--text);
}
input:focus, select:focus { border-color: var(--primary); box-shadow: 0 0 0 3px color-mix(in srgb, var(--primary) 18%, transparent); }
input[aria-invalid="true"], select[aria-invalid="true"] { border-color: var(--danger); box-shadow: 0 0 0 3px color-mix(in srgb, var(--danger) 18%, transparent); }
.field-error { margin-top: -.15rem; color: var(--danger); font-size: .74rem; font-weight: 700; }

.button {
  display: inline-flex;
  min-height: 40px;
  align-items: center;
  justify-content: center;
  gap: .35rem;
  padding: .52rem .78rem;
  border: 1px solid transparent;
  border-radius: 10px;
  cursor: pointer;
  font-size: .86rem;
  font-weight: 800;
  line-height: 1;
  text-decoration: none;
  white-space: nowrap;
}
.button.primary { background: var(--primary); color: #fff; }
.button.primary:hover { background: var(--primary-dark); }
.button.success { background: var(--success); color: #fff; }
.button.ghost { border-color: var(--line); background: var(--input-bg); color: var(--label); }
.button.danger { color: var(--danger); }
.button.danger:not(.ghost) { background: var(--danger); color: white; }
.button.compact { min-height: 36px; padding: .4rem .62rem; font-size: .78rem; }
.button.full { width: 100%; }
.icon-button { width: 36px; min-width: 36px; padding-inline: 0; font-size: 1.05rem; }
.theme-toggle { min-width: 38px; padding-inline: .55rem; }
.theme-toggle .theme-icon { width: 1.05rem; text-align: center; }
.theme-label { display: none; }
.theme-toggle-login { position: fixed; top: .75rem; right: .75rem; z-index: 30; }

.flash-stack { display: grid; gap: .45rem; margin-bottom: .65rem; }
.flash { padding: .62rem .75rem; border: 1px solid var(--line); border-radius: 10px; background: var(--card); font-size: .83rem; }
.flash.success { border-color: #abefc6; background: #ecfdf3; color: #067647; }
.flash.error { border-color: #fecdca; background: #fef3f2; color: #b42318; }

/* Lists */
.create-card { margin-bottom: .8rem; padding: .65rem; }
.inline-form { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: .5rem; }
.list-grid { display: grid; grid-template-columns: 1fr; gap: .5rem; }
.list-card { display: flex; align-items: center; gap: .65rem; padding: .7rem; text-decoration: none; transition: box-shadow .15s ease, transform .15s ease; }
.list-card:hover { box-shadow: var(--shadow-hover); transform: translateY(-1px); }
.list-card h2 { overflow: hidden; margin-bottom: .05rem; font-size: 1rem; text-overflow: ellipsis; white-space: nowrap; }
.list-card p { overflow: hidden; margin-bottom: 0; font-size: .72rem; text-overflow: ellipsis; white-space: nowrap; }
.list-card-icon { display: grid; flex: 0 0 auto; width: 36px; height: 36px; place-items: center; border-radius: 10px; background: var(--icon-soft); font-size: 1rem; }
.count-pill { display: inline-grid; min-width: 30px; height: 30px; place-items: center; padding: 0 .45rem; border-radius: 999px; background: var(--primary-soft); color: var(--primary); font-size: .8rem; font-weight: 850; }

.empty-state { display: grid; justify-items: center; padding: 2rem 1rem; text-align: center; }
.empty-state p { max-width: 460px; margin-bottom: .9rem; font-size: .84rem; }
.empty-icon { margin-bottom: .5rem; font-size: 2rem; }
.compact-empty { padding: 1.5rem .8rem; }

.back-link { display: inline-block; margin-bottom: .4rem; color: var(--primary); font-size: .8rem; font-weight: 750; text-decoration: none; }
.list-heading { align-items: flex-start; }
.list-heading > form .button { min-height: 36px; }
.add-item-card { margin-bottom: 1rem; padding: .75rem; }
.add-item-heading { display: flex; align-items: center; justify-content: space-between; gap: .7rem; margin-bottom: .55rem; }
.add-item-heading h2 { margin-bottom: 0; font-size: 1rem; }
.add-item-heading a { color: var(--primary); font-size: .76rem; font-weight: 800; text-decoration: none; }
.item-form { display: grid; grid-template-columns: minmax(0, 1fr) 88px; align-items: end; gap: .55rem; }
.field-notes { grid-column: 1 / -1; }
.item-form > .button { grid-column: 1 / -1; }
.section-heading { display: flex; align-items: center; justify-content: space-between; gap: .7rem; margin: 1rem 0 .55rem; }
.section-heading h2, .section-heading p { margin-bottom: 0; }
.shopping-items { display: grid; gap: .5rem; }
.shopping-item { display: grid; gap: .55rem; padding: .7rem; }
.item-main { display: flex; min-width: 0; align-items: center; gap: .6rem; }
.product-icon { display: grid; flex: 0 0 auto; width: 36px; height: 36px; place-items: center; border-radius: 10px; background: var(--neutral-soft); font-size: 1rem; }
.quantity { color: var(--muted); font-weight: 650; }
.item-notes { overflow: hidden; margin: .2rem 0 0; color: var(--secondary); font-size: .78rem; text-overflow: ellipsis; white-space: nowrap; }
.item-actions { display: flex; flex-wrap: wrap; align-items: center; justify-content: flex-end; gap: .35rem; }
.purchase-details { position: relative; flex: 1; }
.purchase-details > summary { width: 100%; list-style: none; }
.purchase-details summary::-webkit-details-marker,
.compact-details summary::-webkit-details-marker { display: none; }
.purchase-form { display: none; gap: .55rem; margin-top: .4rem; padding: .65rem; border: 1px solid var(--line); border-radius: 11px; background: var(--surface-subtle); }
.purchase-details[open] { flex-basis: 100%; order: 2; }
.purchase-details[open] .purchase-form { display: grid; }
.recent-section { margin-top: 1.3rem; }
.recent-list { padding: .15rem .7rem; box-shadow: none; }
.recent-row { display: flex; align-items: center; gap: .55rem; padding: .55rem 0; border-bottom: 1px solid var(--line); }
.recent-row:last-child { border-bottom: 0; }
.recent-row .grow { display: grid; min-width: 0; }
.recent-row strong { overflow: hidden; font-size: .88rem; text-overflow: ellipsis; white-space: nowrap; }

/* Compact pantry */
.title-with-count { display: flex; align-items: center; gap: .45rem; }
.title-with-count h1 { margin-bottom: 0; }
.title-count { display: inline-grid; min-width: 28px; height: 28px; place-items: center; padding: 0 .45rem; border-radius: 999px; background: var(--primary-soft); color: var(--primary); font-size: .78rem; font-weight: 850; }
.pantry-subtitle { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pantry-summary { display: flex; flex-wrap: wrap; gap: .35rem; margin: -.15rem 0 .55rem; }
.pantry-summary-chip { display: inline-flex; align-items: baseline; gap: .25rem; padding: .25rem .48rem; border: 1px solid var(--line); border-radius: 999px; background: var(--card); color: var(--secondary); font-size: .7rem; }
.pantry-summary-chip.expired, .pantry-summary-chip.urgent { border-color: color-mix(in srgb, var(--danger) 28%, var(--line)); color: var(--danger); }
.pantry-summary-chip.soon { color: var(--warning); }
.pantry-list { overflow: visible; box-shadow: none; }
.pantry-row {
  position: relative;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: .38rem .55rem;
  padding: .62rem .65rem .62rem .82rem;
  border-bottom: 1px solid var(--line);
}
.pantry-row:last-child { border-bottom: 0; }
.pantry-row::before { content: ""; position: absolute; inset: 0 auto 0 0; width: 3px; background: #d0d5dd; }
.pantry-row.expiry-expired::before { background: #d92d20; }
.pantry-row.expiry-urgent::before { background: #f04438; }
.pantry-row.expiry-soon::before { background: #f79009; }
.pantry-row.expiry-ok::before { background: #12b76a; }
.pantry-info { align-self: center; }
.pantry-title-line { display: flex; min-width: 0; align-items: center; gap: .4rem; }
.pantry-product-name { overflow: hidden; font-size: .92rem; text-overflow: ellipsis; white-space: nowrap; }
.quantity-chip { display: inline-flex; flex: 0 0 auto; align-items: center; min-height: 21px; padding: .08rem .4rem; border-radius: 999px; background: var(--neutral-soft); color: var(--secondary); font-size: .68rem; font-weight: 800; }
.pantry-meta { display: flex; min-width: 0; flex-wrap: wrap; align-items: center; gap: .15rem .35rem; margin-top: .12rem; color: var(--muted); font-size: .7rem; }
.pantry-note { overflow: hidden; max-width: 100%; text-overflow: ellipsis; white-space: nowrap; }
.pantry-note::before { content: "•"; margin-right: .35rem; }
.pantry-separator { color: var(--line); }
.expiry-badge { display: inline-flex; flex: 0 0 auto; align-items: center; padding: .22rem .45rem; border-radius: 999px; background: var(--neutral-soft); color: var(--secondary); font-size: .67rem; font-weight: 850; white-space: nowrap; }
.expiry-badge.expired, .expiry-badge.urgent { background: #fef3f2; color: #b42318; }
.expiry-badge.soon { background: #fffaeb; color: #b54708; }
.expiry-badge.ok { background: #ecfdf3; color: #067647; }
.pantry-actions { grid-column: 1 / -1; display: flex; align-items: center; justify-content: flex-end; gap: .3rem; }
.pantry-actions form { margin: 0; }
.compact-details { position: relative; }
.compact-details > summary { list-style: none; }
.compact-popover {
  position: fixed;
  right: .75rem;
  bottom: calc(4.75rem + env(safe-area-inset-bottom));
  left: .75rem;
  z-index: 60;
  display: grid;
  width: min(300px, calc(100% - 1.5rem));
  gap: .55rem;
  margin: 0 auto;
  padding: .7rem;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--card);
  box-shadow: var(--shadow-menu);
}
.compact-details:not([open]) .compact-popover { display: none; }

/* History */
.history-hero p:last-child { max-width: 780px; }
.history-table-card { overflow: visible; border: 0; background: transparent; box-shadow: none; }
.history-table, .history-table tbody { display: block; width: 100%; }
.history-table colgroup, .history-table thead { display: none; }
.history-table tr { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: .45rem .65rem; margin-bottom: .5rem; padding: .7rem; border: 1px solid var(--line); border-radius: 12px; background: var(--card); box-shadow: var(--shadow); }
.history-table td { display: block; padding: 0; border: 0; }
.history-product-cell { grid-column: 1; min-width: 0; }
.history-last-cell { grid-column: 2; text-align: right; }
.history-action-cell { grid-column: 1 / -1; padding-top: .48rem !important; border-top: 1px solid var(--line) !important; }
.history-product-name { display: flex; min-width: 0; align-items: center; gap: .4rem; }
.history-product-name strong { overflow: hidden; font-size: .9rem; text-overflow: ellipsis; white-space: nowrap; }
.history-note, .history-frequency, .history-source { display: block; color: var(--muted); font-size: .69rem; }
.history-note { overflow: hidden; margin-top: .12rem; text-overflow: ellipsis; white-space: nowrap; }
.history-frequency { margin-top: .1rem; }
.history-last-cell strong { display: block; font-size: .78rem; }
.history-source { overflow: hidden; max-width: 110px; margin-top: .08rem; text-overflow: ellipsis; white-space: nowrap; }
.history-action-form { display: grid; grid-template-columns: minmax(0, 1fr) 82px; align-items: end; gap: .45rem; }
.history-action-form label { gap: .2rem; }
.history-action-form label > span { color: var(--muted); font-size: .66rem; font-weight: 800; }
.history-action-form select, .history-action-form input { min-height: 38px; padding: .45rem .55rem; border-radius: 9px; font-size: .8rem; }
.history-action-grid { grid-column: 1 / -1; display: grid; grid-template-columns: 1fr minmax(130px, 1fr) auto; align-items: end; gap: .4rem; }
.history-action-grid .button { min-height: 38px; padding: .45rem .6rem; font-size: .74rem; }

/* Login and generic compact dialogs */
.login-page { display: grid; min-height: 100vh; place-items: center; padding: 1rem; }
.login-card { width: min(420px, 100%); padding: 1.25rem; text-align: center; }
.login-card h1 { font-size: clamp(1.8rem, 9vw, 2.45rem); }
.login-icon { margin-bottom: .5rem; font-size: 2.5rem; }
.form-stack { display: grid; gap: .75rem; margin-top: 1rem; text-align: left; }
dialog, .modal {
  width: min(340px, calc(100% - 1.5rem));
  max-height: min(82vh, 560px);
  padding: .8rem;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--card);
  color: var(--text);
  box-shadow: var(--shadow-menu);
}
dialog::backdrop { background: rgba(7, 13, 24, .52); }

html[data-theme="dark"] .flash.success { border-color: #275e43; background: #102b20; color: #74e5a4; }
html[data-theme="dark"] .flash.error { border-color: #70363b; background: #321a1d; color: #ffaaa3; }
html[data-theme="dark"] .expiry-badge.expired,
html[data-theme="dark"] .expiry-badge.urgent { background: #321a1d; color: #ffaaa3; }
html[data-theme="dark"] .expiry-badge.soon { background: #332711; color: #ffd08a; }
html[data-theme="dark"] .expiry-badge.ok { background: #102b20; color: #74e5a4; }
html[data-theme="dark"] input[type="date"]::-webkit-calendar-picker-indicator { filter: invert(1); opacity: .8; }

@media (max-width: 390px) {
  .brand-name { display: none; }
  .inline-form { grid-template-columns: 1fr; }
  .inline-form .button { width: 100%; }
  .pantry-hero .button { padding-inline: .55rem; }
  .history-action-grid { grid-template-columns: 1fr auto; }
  .history-add-button { grid-column: 1 / -1; width: 100%; }
  .history-buy-button { min-width: 94px; }
}

@media (min-width: 651px) {
  h1 { font-size: clamp(2rem, 5vw, 3rem); }
  h2 { font-size: 1.3rem; }
  .page { width: min(1120px, calc(100% - 2rem)); padding-top: 1.7rem; }
  .hero-row { margin-bottom: 1.15rem; }
  .hero-row .muted { font-size: .9rem; }
  .eyebrow { font-size: .74rem; }
  .list-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: .8rem; }
  .list-card { padding: 1rem; }
  .list-card-icon { width: 44px; height: 44px; font-size: 1.2rem; }
  .item-form { grid-template-columns: 2fr .7fr 1.6fr auto; }
  .field-notes, .item-form > .button { grid-column: auto; }
  .shopping-item { display: flex; align-items: center; justify-content: space-between; padding: .85rem; }
  .item-actions { flex-wrap: nowrap; }
  .purchase-details { flex: 0 0 auto; }
  .purchase-details[open] { flex-basis: auto; order: initial; }
  .purchase-form { position: absolute; right: 0; top: calc(100% + .4rem); z-index: 50; width: 280px; margin-top: 0; padding: .75rem; background: var(--card); box-shadow: var(--shadow-menu); }
  .pantry-row { grid-template-columns: minmax(0, 1fr) auto auto; padding: .7rem .8rem .7rem .95rem; }
  .pantry-actions { grid-column: auto; }
  .compact-popover { position: absolute; right: 0; bottom: auto; left: auto; top: calc(100% + .4rem); width: 270px; }
  .history-table-card { overflow: hidden; border: 1px solid var(--line); background: var(--card); box-shadow: var(--shadow); }
  .history-table { display: table; border-collapse: collapse; table-layout: fixed; }
  .history-table colgroup { display: table-column-group; }
  .history-table thead { display: table-header-group; }
  .history-table tbody { display: table-row-group; }
  .history-table tr { display: table-row; padding: 0; border: 0; border-radius: 0; background: transparent; box-shadow: none; }
  .history-table th { padding: .7rem .85rem; border-bottom: 1px solid var(--line); background: var(--surface-subtle); color: var(--secondary); font-size: .7rem; font-weight: 850; letter-spacing: .04em; text-align: left; text-transform: uppercase; }
  .history-table td { display: table-cell; padding: .85rem; border-bottom: 1px solid var(--line); vertical-align: middle; }
  .history-table tbody tr:last-child td { border-bottom: 0; }
  .history-col-product { width: 27%; }
  .history-col-last { width: 17%; }
  .history-col-action { width: 56%; }
  .history-product-cell, .history-last-cell, .history-action-cell { text-align: left; }
  .history-action-cell { padding-top: .85rem !important; border-top: 0 !important; }
  .history-action-form { grid-template-columns: minmax(130px, .8fr) minmax(78px, .42fr) minmax(0, 1.8fr); gap: .55rem; }
  .history-action-grid { grid-column: auto; grid-template-columns: auto minmax(130px, 1fr) auto; }
}

@media (min-width: 851px) {
  .topbar {
    display: grid;
    grid-template-columns: 1fr auto 1fr;
    gap: 1rem;
    min-height: 68px;
    padding: .7rem max(1rem, calc((100vw - 1120px) / 2));
    backdrop-filter: blur(14px);
  }
  .brand-mark { width: 38px; height: 38px; border-radius: 12px; font-size: 1.1rem; }
  .brand-name { display: inline; font-size: 1rem; }
  .main-nav {
    position: static;
    display: flex;
    grid-template-columns: none;
    gap: .25rem;
    padding: .22rem;
    border: 1px solid var(--line);
    border-radius: 13px;
    background: var(--surface-subtle);
    box-shadow: none;
    backdrop-filter: none;
  }
  .main-nav a { display: flex; min-height: 38px; padding: .45rem .8rem; border-radius: 9px; font-size: .84rem; }
  .main-nav a.active { background: var(--card); box-shadow: 0 2px 8px rgba(20, 30, 55, .08); }
  .nav-icon { display: none; }
  .user-menu { justify-self: end; gap: .55rem; }
  .user-name { display: inline; }
  .theme-toggle { min-width: 88px; }
  .theme-label, .logout-label { display: inline; }
  .logout-icon { display: none; }
  .page { padding-bottom: 4rem; }
}

/* Dodatkowe zagęszczenie najczęściej używanych widoków mobilnych */
.field-label { display: inline; }
.label-wide { display: none; }
.label-short { display: inline; }
.product-icon { display: none; }
.shopping-item { padding: .62rem .7rem; }
.item-main { gap: .35rem; }
.item-actions { margin-top: -.05rem; }

.history-action-form {
  grid-template-columns: minmax(0, 1fr) 74px auto;
}
.history-action-grid { display: contents; }
.history-list-field { grid-column: 1; grid-row: 1; }
.history-quantity-field { grid-column: 2; grid-row: 1; }
.history-add-button { grid-column: 3; grid-row: 1; align-self: end; }
.history-date-field { grid-column: 1 / 3; grid-row: 2; }
.history-buy-button { grid-column: 3; grid-row: 2; align-self: end; }

@media (min-width: 651px) {
  .label-wide { display: inline; }
  .label-short { display: none; }
  .product-icon { display: grid; }
  .history-action-form { grid-template-columns: minmax(130px, .8fr) minmax(78px, .42fr) minmax(0, 1.8fr); }
  .history-action-grid { display: grid; grid-template-columns: auto minmax(130px, 1fr) auto; }
  .history-list-field,
  .history-quantity-field,
  .history-add-button,
  .history-date-field,
  .history-buy-button { grid-column: auto; grid-row: auto; }
}

/* Recipes AI and pantry export */
.main-nav { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.pantry-hero-actions { display: flex; flex: 0 0 auto; align-items: center; gap: .35rem; }
.recipe-generator-card { margin-bottom: .8rem; padding: .75rem; }
.recipe-generator-form { display: grid; grid-template-columns: minmax(0, 1fr) 78px; gap: .55rem; align-items: end; }
.recipe-preferences-field { grid-column: 1 / -1; }
.recipe-generate-button { grid-column: 1 / -1; min-height: 42px; }
.recipe-api-notice { display: grid; gap: .12rem; margin-top: .65rem; padding: .55rem .65rem; border: 1px solid var(--line); border-radius: 10px; background: var(--surface-subtle); color: var(--secondary); font-size: .75rem; }
.recipe-api-notice code { color: var(--text); font-size: .72rem; }
.recipe-grid { display: grid; gap: .65rem; }
.recipe-card { padding: .75rem; scroll-margin-top: 78px; }
.recipe-card-header { display: flex; align-items: flex-start; justify-content: space-between; gap: .55rem; padding-bottom: .55rem; border-bottom: 1px solid var(--line); }
.recipe-card-header form { margin: 0; }
.recipe-title-line { display: flex; min-width: 0; align-items: center; gap: .4rem; }
.recipe-title-line h2 { overflow: hidden; margin: 0; text-overflow: ellipsis; white-space: nowrap; }
.recipe-ingredients { display: grid; gap: 0; margin: .2rem 0 .65rem; padding: 0; list-style: none; }
.recipe-ingredients li { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: .1rem .55rem; align-items: baseline; padding: .42rem 0; border-bottom: 1px solid var(--line); font-size: .82rem; }
.recipe-ingredients li:last-child { border-bottom: 0; }
.recipe-ingredient-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.recipe-ingredients strong { color: var(--secondary); font-size: .78rem; white-space: nowrap; }
.recipe-ingredients small { grid-column: 1 / -1; color: var(--muted); font-size: .68rem; }
.recipe-steps { margin: -.05rem 0 .65rem; padding: .45rem .55rem; border: 1px solid var(--line); border-radius: 10px; background: var(--surface-subtle); font-size: .76rem; }
.recipe-steps summary { cursor: pointer; color: var(--secondary); font-weight: 800; }
.recipe-steps ol { display: grid; gap: .35rem; margin: .5rem 0 0; padding-left: 1.25rem; }
.recipe-add-form { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: .45rem; align-items: end; padding-top: .6rem; border-top: 1px solid var(--line); }
.recipe-add-form label { gap: .18rem; }
.recipe-add-form label > span { color: var(--muted); font-size: .67rem; }
.recipe-add-form select, .recipe-add-form .button { min-height: 40px; }
.recipe-add-form .button { padding-inline: .65rem; font-size: .76rem; white-space: nowrap; }

@media (max-width: 370px) {
  .main-nav a { padding-inline: .15rem; font-size: .66rem; }
  .pantry-hero { align-items: flex-start; }
  .pantry-hero-actions { flex-direction: column; align-items: stretch; }
  .pantry-hero-actions .button { width: 100%; }
  .recipe-add-form { grid-template-columns: 1fr; }
  .recipe-add-form .button { width: 100%; }
}

@media (min-width: 651px) {
  .recipe-generator-card { padding: 1rem; }
  .recipe-generator-form { grid-template-columns: minmax(220px, 1.2fr) 100px minmax(220px, 1fr) auto; }
  .recipe-preferences-field, .recipe-generate-button { grid-column: auto; }
  .recipe-generate-button { min-height: 42px; }
  .recipe-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: .8rem; }
  .recipe-card { padding: .9rem; }
}
