:root {
  color-scheme: light dark;
  --bg: #f4f6f1;
  --card: #ffffff;
  --text: #1d241a;
  --muted: #6b7565;
  --accent: #2f7d32;
  --accent-strong: #256428;
  --accent-soft: #e4f2e2;
  --border: #e0e5dc;
  --danger: #b3261e;
  --shadow: 0 6px 24px rgba(20, 35, 15, .08);
  --radius: 14px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #12160f;
    --card: #1b2118;
    --text: #eef2ea;
    --muted: #a3ada0;
    --accent: #6fbf73;
    --accent-strong: #8fd493;
    --accent-soft: #24301f;
    --border: #2c3527;
    --danger: #ff8a80;
    --shadow: 0 6px 24px rgba(0, 0, 0, .35);
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; }

body {
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  line-height: 1.4;
  -webkit-font-smoothing: antialiased;
}

.screen { min-height: 100dvh; }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.error { color: var(--danger); min-height: 1.2em; margin: 0; }

input, select, textarea, button { font: inherit; color: inherit; }

input, select {
  width: 100%;
  padding: 11px 12px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--card);
  min-height: 44px;
}

input:focus-visible, select:focus-visible, textarea:focus-visible, button:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

button {
  cursor: pointer;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--card);
  min-height: 44px;
  padding: 0 14px;
}

button.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
  font-weight: 600;
}

button.primary:hover { background: var(--accent-strong); }
button.ghost { background: transparent; color: var(--muted); border-color: transparent; }
button.danger { color: var(--danger); }

/* Login */
.login-screen { display: grid; place-items: center; padding: 24px; }

.login-card {
  width: min(100%, 380px);
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 28px;
  box-shadow: var(--shadow);
}

.login-card h1 { margin: 0 0 4px; font-size: 1.6rem; }
.login-card form { display: grid; gap: 10px; margin-top: 18px; }
.login-card label { font-size: .9rem; color: var(--muted); }

/* App shell */
.app-screen {
  width: min(100%, 820px);
  margin: 0 auto;
  padding: 0 16px calc(96px + env(safe-area-inset-bottom));
}

.topbar {
  display: flex;
  justify-content: flex-end;
  gap: 4px;
  padding: 10px 0 0;
}

.topbar .icon-button {
  width: 38px;
  min-height: 38px;
  font-size: 1.1rem;
  background: transparent;
  border-color: transparent;
}

.topbar .icon-button:disabled {
  opacity: .35;
  cursor: default;
}

.brand { font-weight: 700; white-space: nowrap; }
.topbar #logout { margin-left: auto; }
.tabs {
  display: flex;
  margin-left: auto;
  padding: 3px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--card);
}

.tab {
  border: 0;
  border-radius: 999px;
  min-height: 36px;
  padding: 0 14px;
  background: transparent;
  color: var(--muted);
  font-size: .92rem;
}

.tab.active { background: var(--accent); color: #fff; font-weight: 600; }

.view { padding-top: 8px; }
.view-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
}

.view-head h2 { margin: 0; font-size: 1.3rem; }
.view-head p { margin: 4px 0 0; font-size: .9rem; }
.view-head .icon-button { flex: 0 0 auto; }

.icon-button {
  width: 44px;
  min-height: 44px;
  padding: 0;
  font-size: 1.3rem;
  line-height: 1;
}

/* Plan: category grid */
.category-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 10px;
}

.category-card {
  display: grid;
  gap: 4px;
  justify-items: start;
  text-align: left;
  padding: 14px;
  min-height: 96px;
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.category-card .emoji { font-size: 1.6rem; }
.category-card .title { font-weight: 600; }
.category-card .counts { color: var(--muted); font-size: .82rem; }

/* Plan: quick entry */
.quick-entry {
  margin-top: 24px;
  padding: 16px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.list-head { margin-top: 4px; }

.quick-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 10px;
}

.quick-head h2 { margin: 0; font-size: 1.1rem; }
.quick-head p { margin: 4px 0 0; font-size: .85rem; }

.quick-form {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 100px 48px;
  gap: 8px;
  margin-top: 12px;
}

.quick-form input { min-height: 46px; }
.quick-form button { min-height: 46px; }
.quick-link { margin-top: 8px; padding: 0; min-height: 32px; font-size: .85rem; }

.quick-bar {
  position: fixed;
  left: 50%;
  bottom: calc(12px + env(safe-area-inset-bottom) + var(--keyboard-inset, 0px));
  transform: translateX(-50%);
  width: min(calc(100% - 24px), 788px);
  display: grid;
  grid-template-columns: minmax(0, 1fr) 48px;
  gap: 8px;
  padding: 10px;
  background: color-mix(in srgb, var(--card) 92%, transparent);
  border: 1px solid var(--border);
  border-radius: 16px;
  box-shadow: var(--shadow);
  backdrop-filter: blur(10px);
  z-index: 20;
}

.quick-bar input { min-height: 46px; }
.quick-bar > button { width: 48px; min-height: 46px; padding: 0; font-size: 1.4rem; }

.menu-dialog { width: min(calc(100% - 32px), 300px); }
.menu-dialog button { width: 100%; margin-top: 8px; }

.menu-toggle {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 0;
  color: var(--text);
  font-size: .95rem;
  cursor: pointer;
}

.menu-toggle input {
  width: 20px;
  min-height: 20px;
  margin: 0;
  accent-color: var(--accent);
}

.suggestions-section {
  margin-top: 24px;
  padding-top: 14px;
  border-top: 1px solid var(--border);
}

.suggestions-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 10px;
}

.suggestions-head h3 { margin: 0; font-size: 1rem; }
.suggestions-head .muted { font-size: .78rem; }

.suggestions-list { display: grid; gap: 6px; }

.suggestion-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--card);
  cursor: pointer;
  min-width: 0;
}

.suggestion-item input[type="checkbox"] {
  width: 22px;
  height: 22px;
  margin: 0;
  flex: 0 0 auto;
  accent-color: var(--accent);
}

.suggestion-item .suggestion-main {
  display: grid;
  gap: 2px;
  flex: 1 1 auto;
  min-width: 0;
}

.suggestion-name {
  font-weight: 600;
  min-width: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.suggestion-meta {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
  color: var(--muted);
  font-size: .78rem;
  white-space: nowrap;
  overflow: hidden;
}

.suggestion-meta-part {
  display: inline-flex;
  align-items: center;
  gap: 2px;
  flex: 0 0 auto;
}
.suggestions-more { width: 100%; margin-top: 8px; }
.suggestions-empty {
  margin: 0;
  padding: 4px 2px;
  color: var(--muted);
  font-size: .9rem;
}

.autocomplete { position: relative; min-width: 0; }

.suggestions {
  position: absolute;
  left: 0;
  right: 0;
  top: auto;
  bottom: calc(100% + 6px);
  z-index: 50;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 12px;
  box-shadow: var(--shadow);
  max-height: 260px;
  overflow: auto;
  padding: 4px;
}

.suggestion {
  display: flex;
  align-items: center;
  gap: 2px;
  width: 100%;
  padding: 2px 4px;
  border-radius: 8px;
}

.suggestions .suggestion-main {
  display: flex;
  align-items: center;
  gap: 8px;
  flex: 1;
  min-width: 0;
  min-height: 40px;
  padding: 6px 6px;
  border: 0;
  border-radius: 8px;
  background: transparent;
  text-align: left;
}

.suggestion-delete {
  width: 32px;
  min-height: 32px;
  padding: 0;
  border: 0;
  background: transparent;
  color: var(--muted);
  font-size: .95rem;
}

.suggestion-delete:hover { color: var(--danger); }

.suggestion .name { flex: 1; min-width: 0; overflow-wrap: anywhere; }
.suggestion .meta { color: var(--muted); font-size: .8rem; white-space: nowrap; }
.suggestion .badge {
  color: var(--accent-strong);
  background: var(--accent-soft);
  border-radius: 999px;
  padding: 2px 6px;
  font-size: .72rem;
  white-space: nowrap;
}

.suggestion.active, .suggestion:hover { background: var(--accent-soft); }

/* Plan: category detail */
#product-search { margin-bottom: 12px; }

.category-controls {
  display: flex;
  gap: 8px;
  align-items: center;
  margin-bottom: 12px;
}

.category-controls #product-search { flex: 1; margin-bottom: 0; }
.category-controls select { flex: 0 0 auto; width: 160px; }

.product-list { display: grid; gap: 8px; }

.product-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 76px 36px 40px 36px;
  gap: 7px;
  align-items: center;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 7px 9px;
}

.product-row.no-edit {
  grid-template-columns: minmax(0, 1fr) 76px 36px 40px;
}

.product-name {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 44px;
  padding: 0;
  border: 0;
  background: transparent;
  text-align: left;
  overflow-wrap: anywhere;
}

.on-list-badge {
  font-size: .72rem;
  color: var(--accent-strong);
  background: var(--accent-soft);
  border-radius: 999px;
  padding: 2px 7px;
  white-space: nowrap;
}

.qty-input { min-height: 40px; padding: 7px 8px; font-size: .9rem; }
.product-row .add,
.product-row .edit { width: 40px; min-height: 44px; padding: 0; font-size: 1.15rem; }

.product-row .star {
  width: 36px;
  min-height: 44px;
  padding: 0;
  border: 0;
  background: transparent;
  color: var(--muted);
  font-size: 1.15rem;
}

.product-row .star.active { color: #d4a017; }

.product-name .meta {
  color: var(--muted);
  font-size: .78rem;
  white-space: nowrap;
}

.list-heading {
  margin: 18px 0 8px;
  font-size: .95rem;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: .04em;
}

.suggestions-card {
  border-color: color-mix(in srgb, var(--accent) 35%, var(--border));
}

.suggestions-note { margin: 0 0 10px; font-size: .85rem; }

.empty {
  text-align: center;
  padding: 40px 16px;
  color: var(--muted);
}
.empty strong { display: block; color: var(--text); margin-bottom: 6px; }

.on-list-block { margin-top: 22px; }
.on-list-block h3 { margin: 0 0 8px; font-size: 1rem; }

.on-list-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  border: 1px dashed var(--border);
  border-radius: 10px;
  margin-bottom: 6px;
}

.on-list-row .name { flex: 1; min-width: 0; overflow-wrap: anywhere; }
.on-list-row .qty { color: var(--muted); font-size: .9rem; }

.new-product-bar {
  position: fixed;
  left: 50%;
  bottom: calc(12px + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  width: min(calc(100% - 24px), 788px);
  display: grid;
  grid-template-columns: minmax(0, 1fr) 100px 48px;
  gap: 8px;
  padding: 10px;
  background: color-mix(in srgb, var(--card) 92%, transparent);
  border: 1px solid var(--border);
  border-radius: 16px;
  box-shadow: var(--shadow);
  backdrop-filter: blur(10px);
  z-index: 20;
}

.new-product-bar input { min-height: 46px; }
.new-product-bar > button { width: 48px; min-height: 46px; padding: 0; font-size: 1.4rem; }

/* Shop */
.shop-actions { display: flex; gap: 4px; flex-wrap: wrap; justify-content: flex-end; }
.shop-actions button { min-height: 36px; padding: 0 8px; font-size: .85rem; }

.progress {
  height: 8px;
  background: var(--accent-soft);
  border-radius: 999px;
  overflow: hidden;
  margin: 4px 0 18px;
}

#shop-bar {
  height: 100%;
  width: 0;
  background: var(--accent);
  border-radius: inherit;
  transition: width .25s ease;
}

.shop-category {
  margin-bottom: 12px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 12px;
  overflow: hidden;
}

.shop-category summary {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 11px 12px;
  cursor: pointer;
  list-style: none;
  font-weight: 600;
}

.shop-category summary::-webkit-details-marker { display: none; }
.shop-category summary .count { margin-left: auto; color: var(--muted); font-size: .82rem; font-weight: 400; }

.shop-items { padding: 0 8px 8px; }

.shop-item {
  display: grid;
  grid-template-columns: 24px minmax(0, 1fr) 38px 38px 38px;
  gap: 7px;
  align-items: center;
  padding: 7px 4px;
  border-top: 1px solid var(--border);
}

.shop-item input[type="checkbox"] {
  width: 22px;
  height: 22px;
  margin: 0;
  accent-color: var(--accent);
  cursor: pointer;
}

.shop-label {
  display: flex;
  align-items: baseline;
  gap: 8px;
  flex-wrap: wrap;
  min-height: 40px;
  padding: 0;
  border: 0;
  background: transparent;
  text-align: left;
  overflow-wrap: anywhere;
}

.shop-label .qty { color: var(--muted); font-size: .9rem; white-space: nowrap; }
.shop-item.checked .shop-label { text-decoration: line-through; opacity: .6; }
.shop-item .icon { width: 38px; min-height: 38px; padding: 0; font-size: 1.1rem; }

/* Dialogs */
.dialog {
  width: min(calc(100% - 32px), 420px);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--card);
  color: var(--text);
  padding: 20px;
  box-shadow: var(--shadow);
}

.dialog::backdrop { background: rgba(0, 0, 0, .45); }
.dialog:not([open]) { display: none !important; }
.dialog h3 { margin: 0 0 14px; }

.recipe-dialog {
  width: min(calc(100% - 32px), 640px);
  max-height: 90dvh;
  overflow: auto;
}

.recipe-button,
.idea-button,
.price-button {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.recipe-icon,
.idea-icon,
.price-icon {
  width: 18px;
  height: 18px;
  flex: 0 0 auto;
}

.price-dialog {
  width: min(calc(100% - 32px), 1100px);
  max-height: 90dvh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.price-dialog-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  flex: 0 0 auto;
  margin-bottom: 12px;
}

.price-dialog-head h3 { margin: 0; }
.price-dialog-head p { margin: 4px 0 0; font-size: .8rem; }

.price-dialog-head .icon-button {
  flex: 0 0 auto;
  width: 38px;
  min-height: 38px;
  font-size: 1.4rem;
  background: transparent;
  border-color: transparent;
}

.price-loading {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 16px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: color-mix(in srgb, var(--card) 90%, var(--accent-soft));
}

.price-loading p { margin: 4px 0 0; font-size: .8rem; }

.price-spinner {
  width: 28px;
  height: 28px;
  flex: 0 0 auto;
  border: 3px solid var(--accent-soft);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: priceSpin .9s linear infinite;
}

@keyframes priceSpin {
  to { transform: rotate(360deg); }
}

.price-content {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  padding: 2px 2px 8px;
}

.price-summary {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 8px;
  margin: 4px 0 14px;
}

.price-summary-card {
  min-width: 0;
  padding: 10px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--card);
}

.price-summary-card.cheapest {
  border-color: var(--accent);
  box-shadow: 0 0 0 1px var(--accent-soft);
}

.price-summary-head {
  display: flex;
  align-items: center;
  gap: 5px;
  flex-wrap: wrap;
  font-size: .8rem;
}

.price-summary-value {
  margin-top: 5px;
  font-size: 1.05rem;
  font-weight: 700;
}

.price-summary-meta {
  margin-top: 4px;
  color: var(--muted);
  font-size: .72rem;
}

.price-summary-error {
  margin-top: 4px;
  color: var(--danger);
  font-size: .7rem;
}

.price-table-wrap {
  max-width: 100%;
  overflow: auto;
  border: 1px solid var(--border);
  border-radius: 12px;
}

.price-table {
  width: 100%;
  min-width: 780px;
  border-collapse: collapse;
  font-size: .82rem;
}

.price-table th,
.price-table td {
  padding: 8px 9px;
  border-bottom: 1px solid var(--border);
  text-align: left;
  vertical-align: top;
}

.price-table thead th {
  position: sticky;
  top: 0;
  z-index: 1;
  background: var(--card);
  color: var(--muted);
  font-size: .72rem;
  font-weight: 600;
  letter-spacing: .03em;
  text-transform: uppercase;
  white-space: nowrap;
}

.price-table tbody tr.checked { opacity: .6; }
.price-product { min-width: 130px; white-space: nowrap; }
.price-product-name { font-weight: 600; }
.price-quantity { color: var(--muted); white-space: nowrap; }
.price-value-cell { min-width: 150px; }
.price-cell-line { display: flex; align-items: baseline; gap: 5px; flex-wrap: wrap; }
.price-badges { display: inline-flex; gap: 4px; flex-wrap: wrap; }

.price-badge {
  display: inline-block;
  border-radius: 999px;
  padding: 1px 6px;
  background: var(--accent-soft);
  color: var(--accent-strong);
  font-size: .66rem;
  line-height: 1.5;
  white-space: nowrap;
}

.price-badge.checked { margin-left: 5px; background: var(--border); color: var(--muted); }
.price-badge.offer { background: color-mix(in srgb, var(--accent) 18%, transparent); color: var(--accent-strong); }
.price-badge.estimated { background: color-mix(in srgb, #f4b400 20%, transparent); color: var(--text); }
.price-badge.package { background: transparent; border: 1px dashed var(--border); color: var(--muted); }
.price-detail {
  display: block;
  max-width: 190px;
  margin-top: 2px;
  color: var(--muted);
  font-size: .7rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.price-missing { color: var(--muted); }
.price-source {
  display: inline-block;
  margin-top: 2px;
  color: var(--accent-strong);
  font-size: .78rem;
  text-decoration: none;
}
.price-source:hover { text-decoration: underline; }
.price-total-row th,
.price-total-row td { border-top: 2px solid var(--border); border-bottom: 0; background: var(--card); }
.price-total-meta { margin-top: 3px; color: var(--muted); font-size: .7rem; font-weight: 400; }
.price-meta { margin: 8px 2px 0; font-size: .75rem; }
.price-actions {
  flex: 0 0 auto;
  margin: 10px 0 0;
  padding-top: 10px;
  border-top: 1px solid var(--border);
}

@media (prefers-reduced-motion: reduce) {
  .price-spinner { animation: none; }
}

.idea-dialog {
  width: min(calc(100% - 32px), 700px);
  max-height: 90dvh;
  overflow: auto;
  display: flex;
  flex-direction: column;
}

.idea-dialog-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
}

.idea-dialog-head h3 {
  margin: 0;
}

.idea-dialog-head .icon-button {
  flex: 0 0 auto;
  width: 38px;
  min-height: 38px;
  font-size: 1.4rem;
  background: transparent;
  border-color: transparent;
}

.idea-button.lit .idea-icon {
  color: #f4b400;
  filter: drop-shadow(0 0 4px rgba(244, 180, 0, .9));
  animation: ideaGlow 1.8s ease-in-out infinite;
}

@keyframes ideaGlow {
  0%, 100% { filter: drop-shadow(0 0 3px rgba(244, 180, 0, .55)); }
  50% { filter: drop-shadow(0 0 7px rgba(244, 180, 0, 1)); }
}

@media (prefers-reduced-motion: reduce) {
  .idea-button.lit .idea-icon { animation: none; }
}

.idea-light-row {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 8px 14px;
  border-bottom: 1px solid var(--border);
  background: var(--card);
}

.idea-light-toggle {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--text);
  font-size: .9rem;
  cursor: pointer;
}

.idea-light-toggle input {
  width: 20px;
  min-height: 20px;
  margin: 0;
  accent-color: #f4b400;
}

.idea-form {
  order: 1;
  display: grid;
  gap: 8px;
}

.idea-scroll {
  order: 2;
}

.idea-form textarea {
  width: 100%;
  min-height: 140px;
  padding: 11px 12px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--card);
  resize: vertical;
}

.idea-section {
  margin-top: 22px;
  padding-top: 14px;
  border-top: 1px solid var(--border);
}

.idea-section h4 {
  margin: 0 0 10px;
  font-size: .95rem;
}

.idea-history,
.changelog-history {
  display: grid;
  gap: 10px;
}

.idea-entry,
.changelog-entry {
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--bg);
}

.changelog-entry {
  border-left: 3px solid var(--accent);
}

.idea-meta,
.changelog-meta {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 6px;
  color: var(--muted);
  font-size: .78rem;
}

.idea-meta-right {
  display: flex;
  align-items: center;
  gap: 6px;
}

.idea-delete,
.idea-edit {
  width: 34px;
  min-height: 34px;
  padding: 0;
  font-size: .9rem;
}

.idea-edit-text {
  width: 100%;
  min-height: 110px;
  padding: 10px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--card);
  resize: vertical;
}

.idea-edit-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 8px;
}

.idea-text {
  margin: 0;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.changelog-version {
  font-weight: 700;
  color: var(--accent-strong);
}

.changelog-summary {
  margin: 0;
  font-size: .9rem;
}

.idea-empty {
  margin: 0;
  padding: 4px 2px;
  color: var(--muted);
  font-size: .9rem;
}

.recipe-tabs {
  display: flex;
  gap: 4px;
  margin-bottom: 12px;
}

.recipe-tab {
  flex: 1;
  min-height: 40px;
  padding: 0 8px;
  font-size: .9rem;
}

.recipe-tab.active {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

.recipe-step input,
.recipe-step textarea {
  width: 100%;
}

.recipe-step textarea {
  min-height: 180px;
  padding: 10px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--card);
  color: var(--text);
  font: inherit;
  resize: vertical;
}

.recipe-list-text {
  min-height: 260px;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
}

.recipe-ingredients-text {
  min-height: 240px;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
}

.recipe-ingredients-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 6px;
  flex-wrap: wrap;
}

.recipe-ingredients-actions .muted {
  font-size: .8rem;
  margin-left: auto;
}

.servings-row {
  display: flex;
  gap: 10px;
  margin-bottom: 8px;
}

.servings-row label {
  flex: 1;
  display: grid;
  gap: 4px;
  font-size: .85rem;
  color: var(--muted);
}

.recipe-ingredients {
  display: grid;
  gap: 2px;
  max-height: 260px;
  overflow: auto;
  margin: 12px 0;
  padding: 8px;
  border: 1px solid var(--border);
  border-radius: 10px;
}

.recipe-ingredient {
  padding: 4px 6px;
  border-bottom: 1px solid var(--border);
  font-size: .92rem;
}

.recipe-ingredient:last-child { border-bottom: 0; }

.recipe-step menu {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin: 14px 0 0;
}
.dialog form { display: grid; gap: 10px; }
.dialog label { display: grid; gap: 5px; font-size: .9rem; color: var(--muted); }
.dialog menu { display: flex; justify-content: flex-end; gap: 8px; padding: 0; margin: 16px 0 0; }

.picker-list { display: grid; gap: 7px; }
.picker-button {
  display: flex;
  align-items: center;
  gap: 8px;
  text-align: left;
  min-height: 46px;
}
.picker-button.active { border-color: var(--accent); background: var(--accent-soft); }

.manage-list { display: grid; gap: 6px; max-height: 40vh; overflow: auto; margin-bottom: 14px; }
.manage-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 8px;
  border: 1px solid var(--border);
  border-radius: 9px;
}
.manage-row .name { flex: 1; min-width: 0; overflow-wrap: anywhere; }
.manage-row .count { color: var(--muted); font-size: .78rem; }
.manage-row button { min-height: 34px; width: 34px; padding: 0; }

.category-form { display: grid; grid-template-columns: 56px minmax(0, 1fr) auto auto; gap: 6px; }
.category-form input { min-height: 40px; padding: 7px 8px; }
.category-form button { min-height: 40px; padding: 0 10px; font-size: .9rem; }

/* Toast */
.toast {
  position: fixed;
  left: 50%;
  bottom: calc(84px + env(safe-area-inset-bottom) + var(--keyboard-inset, 0px));
  transform: translateX(-50%);
  max-width: min(92vw, 560px);
  padding: 10px 14px;
  border-radius: 10px;
  background: var(--text);
  color: var(--bg);
  box-shadow: var(--shadow);
  font-size: .92rem;
  z-index: 30;
}

.toast.error { background: var(--danger); color: #fff; }

@media (max-width: 620px) {
  .brand { font-size: .95rem; }
  .topbar { gap: 8px; }
  .tab { padding: 0 10px; }
  .product-row { grid-template-columns: minmax(0, 1fr) 64px 34px 38px 34px; }
  .product-row.no-edit { grid-template-columns: minmax(0, 1fr) 64px 34px 38px; }
  .product-row .add, .product-row .edit { width: 38px; min-height: 40px; }
  .product-row .star { width: 34px; min-height: 40px; }
  .new-product-bar { grid-template-columns: minmax(0, 1fr) 80px 48px; }
  .quick-form { grid-template-columns: minmax(0, 1fr) 80px 48px; }
  .quick-bar { grid-template-columns: minmax(0, 1fr) 48px; }
  .category-controls { flex-wrap: wrap; }
  .category-controls select { width: 100%; }
  .shop-item { grid-template-columns: 22px minmax(0, 1fr) 36px 36px 36px; }
  .shop-item .icon { width: 36px; min-height: 36px; }
  .category-form { grid-template-columns: 48px minmax(0, 1fr); }
  .category-form button { grid-column: span 1; }
}

@media (max-width: 520px) {
  .brand { display: none; }
  .topbar { justify-content: space-between; }
  .tabs { margin-left: 0; }
}

/* Mobile: full-screen sheets, sticky actions and keyboard-safe layout */
@media (max-width: 680px) {
  .idea-dialog,
  .recipe-dialog,
  .price-dialog {
    width: 100%;
    max-width: none;
    height: var(--vvh, 100dvh);
    max-height: var(--vvh, 100dvh);
    margin: 0;
    top: var(--vv-offset-top, 0px);
    border: 0;
    border-radius: 0;
    padding: 0;
    overflow: hidden;
  }

  .idea-dialog {
    display: flex;
    flex-direction: column;
  }

  .price-dialog {
    display: flex;
    flex-direction: column;
  }

  .price-dialog-head {
    flex: 0 0 auto;
    margin: 0;
    padding: calc(8px + env(safe-area-inset-top)) 14px 8px;
    border-bottom: 1px solid var(--border);
    background: var(--card);
  }

  .price-dialog-head h3 { font-size: 1.05rem; }
  .price-dialog-head .icon-button { width: 40px; min-height: 40px; }
  .price-content { padding: 10px 12px 8px; }
  .price-summary { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 6px; }
  .price-summary-card { padding: 8px; }
  .price-summary-value { font-size: .98rem; }
  .price-loading { margin: 12px 14px 0; }
  .price-actions {
    margin: 0;
    padding: 10px 14px calc(10px + env(safe-area-inset-bottom));
    background: var(--card);
  }
  .price-actions button { flex: 1 1 auto; }

  .idea-dialog-head {
    flex: 0 0 auto;
    margin: 0;
    padding: calc(8px + env(safe-area-inset-top)) 14px 8px;
    border-bottom: 1px solid var(--border);
    background: var(--card);
  }

  .idea-dialog-head h3 { font-size: 1rem; }
  .idea-dialog-head .icon-button { width: 40px; min-height: 40px; }

  .idea-scroll {
    order: 1;
    flex: 1 1 auto;
    min-height: 0;
    overflow-y: auto;
    overscroll-behavior: contain;
    -webkit-overflow-scrolling: touch;
    padding: 0 14px 14px;
  }

  .idea-form {
    order: 2;
    flex: 0 0 auto;
    padding: 10px 14px calc(10px + env(safe-area-inset-bottom));
    border-top: 1px solid var(--border);
    background: var(--card);
  }

  .idea-form textarea {
    min-height: 84px;
    max-height: 24dvh;
    resize: none;
  }

  .idea-form menu { margin-top: 8px; }
  .idea-form menu button { width: 100%; }
  .idea-section { margin-top: 16px; padding-top: 12px; }
  .idea-section:first-child { margin-top: 12px; }

  .recipe-dialog { display: flex; flex-direction: column; }

  .recipe-step {
    flex: 1 1 auto;
    min-height: 0;
    padding: calc(14px + env(safe-area-inset-top)) 14px 14px;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
  }

  .recipe-step h3 { font-size: 1.1rem; }
  .recipe-step textarea { resize: none; }
  .servings-row { gap: 8px; margin-bottom: 6px; }
  .servings-row label { font-size: .8rem; }
  .servings-row input { min-height: 40px; padding: 8px 10px; }

  .recipe-step menu {
    position: sticky;
    bottom: 0;
    margin-top: auto;
    padding: 10px 0 calc(10px + env(safe-area-inset-bottom));
    background: var(--card);
  }

  .recipe-step menu button { flex: 1 1 auto; }

  #recipe-step-2 { overflow: hidden; }
  #recipe-step-2 #recipe-ingredients-text {
    flex: 1 1 auto;
    min-height: 110px;
  }
  #recipe-step-2 .recipe-ingredients-actions { flex: 0 0 auto; }
  #recipe-step-2 menu {
    position: static;
    margin-top: 8px;
    padding-bottom: calc(10px + env(safe-area-inset-bottom));
  }

  .dialog:not(.idea-dialog):not(.recipe-dialog):not(.price-dialog) {
    max-height: calc(var(--vvh, 100dvh) - 20px);
    overflow-y: auto;
  }
}

@media (max-width: 620px) {
  .app-screen {
    padding: 0 12px calc(92px + env(safe-area-inset-bottom));
  }

  .topbar { padding-top: calc(6px + env(safe-area-inset-top)); }

  .view-head.list-head {
    flex-direction: column;
    align-items: stretch;
    gap: 8px;
    margin-bottom: 10px;
  }

  .view-head h2 { font-size: 1.15rem; }
  .shop-actions { justify-content: flex-start; }
  .shop-actions button { flex: 1 1 auto; }
  .progress { margin: 2px 0 12px; }
  .quick-bar {
    bottom: calc(8px + env(safe-area-inset-bottom) + var(--keyboard-inset, 0px));
    width: calc(100% - 16px);
    padding: 8px;
  }
  .toast {
    bottom: calc(88px + env(safe-area-inset-bottom) + var(--keyboard-inset, 0px));
  }
  .shop-item {
    grid-template-columns: 22px minmax(0, 1fr) 34px 34px 34px;
    gap: 4px;
  }
  .shop-item .icon { width: 34px; min-height: 34px; }
}

@media (max-width: 520px) {
  .topbar { justify-content: flex-end; }
}
