:root {
  --bg: #f6f7f6;
  --surface: #ffffff;
  --surface-alt: #f8f9f8;
  --text: #15201b;
  --muted: #5b6b63;
  --border: #d6ddd9;
  --green: #0b3d2e;
  --orange: #f28c28;
  --shadow: 0 10px 25px rgba(0, 0, 0, 0.08);
  --radius: 14px;
  --radius-sm: 10px;
  --mono: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace;
  --sans: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, Arial, "Noto Sans", "Liberation Sans", sans-serif;
}

* { box-sizing: border-box; }
html, body { min-height: 100%; }
body {
  margin: 0;
  font-family: var(--sans);
  background: radial-gradient(circle at top, #fbfcfb, var(--bg) 44%);
  color: var(--text);
  line-height: 1.45;
}

a { color: var(--green); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3, h4, p { margin-top: 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;
}

.container { max-width: 1100px; margin: 0 auto; padding: 18px; }

.topbar {
  background: rgba(255, 255, 255, 0.92);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 20;
  backdrop-filter: blur(12px);
}

.topbar-inner {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: 16px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
}

.brand img {
  height: 44px;
  width: auto;
  display: block;
  flex-shrink: 0;
}

.brand-copy {
  min-width: 0;
  display: grid;
  gap: 2px;
  line-height: 1.2;
}

.brand .name {
  font-weight: 800;
  letter-spacing: -0.2px;
  overflow-wrap: anywhere;
}

.brand .tag {
  color: var(--muted);
  font-size: 13px;
  overflow-wrap: anywhere;
}

.nav {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: center;
  justify-content: flex-end;
}

.nav a {
  padding: 8px 10px;
  border-radius: 999px;
  border: 1px solid transparent;
  color: var(--text);
}

.nav a.current,
.nav a[aria-current="page"] {
  background: rgba(11, 61, 46, 0.07);
  border-color: rgba(11, 61, 46, 0.2);
}

.nav a:hover {
  background: rgba(11, 61, 46, 0.05);
  text-decoration: none;
}

.nav-divider {
  width: 1px;
  height: 20px;
  background: var(--border);
}

main { padding-bottom: 60px; }

.hero {
  padding: 18px 0 10px;
  display: grid;
  grid-template-columns: 1.25fr 0.75fr;
  gap: 14px;
  align-items: start;
}

.hero.hero-single { grid-template-columns: 1fr; }

.grid {
  display: grid;
  grid-template-columns: repeat(12, 1fr);
  gap: 14px;
  margin: 14px 0 22px;
}

.col-4 { grid-column: span 4; }
.col-6 { grid-column: span 6; }
.col-8 { grid-column: span 8; }
.col-12 { grid-column: span 12; }

.card,
.list,
dialog.modal {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.list { overflow: hidden; }

.card-header,
.store-header {
  padding: 14px 14px 0;
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 10px;
  flex-wrap: wrap;
}

.card-body,
.store-body {
  padding: 14px;
}

.title {
  margin: 0;
  font-size: 22px;
  font-weight: 850;
  letter-spacing: -0.3px;
}

.subtitle { color: var(--muted); }

.section-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 10px;
  margin: 6px 0 10px;
}

.section-title {
  margin: 0;
  font-size: 18px;
  font-weight: 850;
}

.pill {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 6px 10px;
  border-radius: 999px;
  border: 1px solid var(--border);
  color: var(--muted);
  background: #fff;
  font-size: 13px;
}

.pill b { color: var(--text); }
.pill.ok { border-color: rgba(11, 61, 46, 0.25); background: rgba(11, 61, 46, 0.05); color: var(--green); }
.pill.warn { border-color: rgba(242, 140, 40, 0.35); background: rgba(242, 140, 40, 0.09); color: #8a4c12; }
.pill.bad { border-color: rgba(177, 44, 44, 0.35); background: rgba(177, 44, 44, 0.08); color: #7c1f1f; }

.flash-message { margin: 10px 0 0; }

#flash {
  max-width: 1100px;
  margin: 0 auto;
  padding: 0 18px;
}

.sync-shell {
  position: sticky;
  top: 76px;
  z-index: 15;
  background: rgba(246, 247, 246, 0.94);
  border-bottom: 1px solid rgba(214, 221, 217, 0.9);
  backdrop-filter: blur(8px);
}

.sync-shell-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding-top: 10px;
  padding-bottom: 10px;
}

.sync-shell-copy,
.sync-shell-actions,
.sync-conflict-card {
  display: flex;
  gap: 10px;
  align-items: center;
  flex-wrap: wrap;
}

.sync-conflicts {
  padding-top: 0;
  padding-bottom: 12px;
}

.sync-conflicts summary {
  cursor: pointer;
  color: var(--muted);
}

.sync-conflicts-list {
  display: grid;
  gap: 10px;
  margin-top: 10px;
}

.sync-conflict-card {
  justify-content: space-between;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 12px;
  background: var(--surface);
}

.sync-conflict-empty {
  margin: 0;
}

.actions,
.inline-actions {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}

.actions.actions-right { justify-content: flex-end; }

.btn,
button,
input[type="submit"] {
  font: inherit;
}

.btn,
.button_to button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 10px 12px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: #fff;
  color: var(--text);
  font-weight: 650;
  cursor: pointer;
}

.btn.small,
.button_to .small {
  padding: 7px 10px;
  border-radius: 10px;
  font-weight: 750;
}

.btn.circle,
.button_to .circle {
  width: 38px;
  height: 38px;
  padding: 0;
  border-radius: 999px;
}

.btn.primary { background: var(--green); color: #fff; border-color: var(--green); }
.btn.primary:hover { background: #083023; text-decoration: none; }
.btn.accent { background: var(--orange); color: #22160a; border-color: var(--orange); }
.btn.accent:hover { background: #e47f1c; text-decoration: none; }
.btn.danger,
.button_to .danger { border-color: rgba(177, 44, 44, 0.45); color: #7c1f1f; }
.btn:hover,
.button_to button:hover { background: #fafafa; text-decoration: none; }

.table {
  width: 100%;
  border-collapse: collapse;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  overflow: hidden;
}

.table th,
.table td {
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  text-align: left;
  vertical-align: top;
  font-size: 14px;
}

.table th { background: var(--surface-alt); color: #2c3a34; font-weight: 750; }
.table tr:last-child td { border-bottom: 0; }

.mono { font-family: var(--mono); font-size: 13px; color: #2c3a34; }
.muted { color: var(--muted); }

.form-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.form-row.form-row-single { grid-template-columns: 1fr; }

.stacked-form { display: grid; gap: 12px; }

.filter-bar {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 12px;
  align-items: center;
  margin-bottom: 14px;
}

.filter-bar-field {
  min-width: 0;
  position: relative;
}

.filter-bar-input.with-clear {
  padding-right: 76px;
}

.filter-bar-clear {
  position: absolute;
  top: 50%;
  right: 12px;
  transform: translateY(-50%);
  color: var(--muted);
  font-size: 14px;
  font-weight: 650;
}

.filter-bar-clear:hover {
  color: var(--green);
  text-decoration: none;
}

.form-section-break {
  margin-top: 6px;
  padding-top: 14px;
  border-top: 1px solid rgba(18, 45, 35, 0.08);
}

label { display: block; font-weight: 650; margin-bottom: 6px; }

input,
select,
textarea {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: #fff;
  font: inherit;
}

input[type="checkbox"] {
  width: 18px;
  height: 18px;
}

textarea { min-height: 96px; resize: vertical; }

.help {
  font-size: 13px;
  color: var(--muted);
  margin-top: 6px;
}

.quick-add {
  display: grid;
  grid-template-columns: 1.4fr 0.8fr 0.8fr auto;
  gap: 10px;
  margin-bottom: 12px;
}

.quick-add .button_to { margin: 0; }

.to-buy-page {
  padding-bottom: 110px;
}

.store { border-top: 1px solid var(--border); }
.store:first-child { border-top: 0; }

.store-sections {
  display: grid;
  gap: 14px;
}

.store-sections .store,
.store-sections .store:first-child {
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: #fff;
  overflow: hidden;
  box-shadow: 0 1px 0 rgba(21, 32, 27, 0.04);
}

.store-sections .store-header {
  padding-bottom: 12px;
  border-bottom: 1px solid rgba(18, 45, 35, 0.08);
  background: linear-gradient(180deg, rgba(11, 61, 46, 0.05), rgba(11, 61, 46, 0.02));
}

.location-sections .store,
.location-sections .store:first-child {
  border: 0;
  border-radius: 0;
  background: transparent;
  box-shadow: none;
  overflow: visible;
}

.location-sections .store-header {
  padding: 0 0 10px;
  border-bottom: 0;
  background: transparent;
}

.location-sections .store-body {
  padding: 0;
}

.completed-items-panel {
  overflow: hidden;
}

.completed-items-summary {
  list-style: none;
  cursor: pointer;
  padding-bottom: 14px;
}

.completed-items-summary::-webkit-details-marker {
  display: none;
}

.completed-items-summary::after {
  content: "▾";
  margin-left: auto;
  color: var(--muted);
  font-size: 16px;
}

.completed-items-panel:not([open]) .completed-items-summary {
  border-bottom: 0;
}

.completed-items-panel[open] .completed-items-summary {
  border-bottom: 1px solid rgba(18, 45, 35, 0.08);
}

.completed-items-panel[open] .completed-items-summary::after {
  transform: rotate(180deg);
}

.completed-items-actions {
  margin-bottom: 14px;
}

.group + .group { margin-top: 14px; }

.store-header-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 10px;
  flex-wrap: wrap;
}

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

.group-body {
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  overflow: hidden;
}

.item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 14px;
  border-top: 1px solid var(--border);
  transform-origin: top center;
  will-change: opacity, transform, max-height, padding;
  transition:
    opacity 220ms ease,
    transform 220ms ease,
    max-height 220ms ease,
    padding-top 220ms ease,
    padding-bottom 220ms ease,
    border-top-color 220ms ease;
}

.item:first-child { border-top: 0; }

.item.item-entering {
  animation: shopping-item-enter 240ms cubic-bezier(0.22, 1, 0.36, 1);
}

.item.item-leaving {
  overflow: hidden;
  max-height: var(--shopping-item-height, 88px);
}

.item.item-leaving.item-leaving-active {
  opacity: 0;
  transform: translateX(18px) scale(0.98);
  max-height: 0;
  padding-top: 0;
  padding-bottom: 0;
  border-top-color: transparent;
  pointer-events: none;
}

.item .right {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 10px;
  flex-wrap: wrap;
}

.item strong,
.item b { font-size: 15px; }

.stock-check-item-main {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  min-width: 0;
  flex: 1;
}

.stock-check-item-leading {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-shrink: 0;
}

.stock-check-item-copy {
  min-width: 0;
}

.stock-check-item-copy h4 {
  margin: 0;
}

.stock-check-item-copy p {
  margin: 4px 0 0;
}

.checkbox-line {
  display: flex;
  align-items: center;
  gap: 10px;
}

.checkbox-line form { margin: 0; }

.button_to {
  display: inline;
  margin: 0;
}

.button_to div { display: inline; }

.state-grid {
  display: grid;
  gap: 14px;
}

.footer {
  padding: 20px 0 40px;
  color: var(--muted);
  font-size: 13px;
}

dialog.modal {
  border: 0;
  padding: 0;
  width: min(760px, calc(100vw - 24px));
}

dialog.modal::backdrop { background: rgba(21, 32, 27, 0.55); }

.modal-header {
  padding: 14px 14px 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.modal-title {
  margin: 0;
  font-size: 18px;
  font-weight: 900;
}

.modal-body { padding: 14px; }

.quick-add-modal-intro {
  margin-top: 0;
  margin-bottom: 14px;
}

.quick-add-modal-form {
  gap: 14px;
}

.floating-add-button {
  position: fixed;
  right: max(16px, calc((100vw - 1120px) / 2 + 16px));
  bottom: calc(28px + env(safe-area-inset-bottom, 0px));
  width: 62px;
  height: 62px;
  padding: 0;
  border-radius: 999px;
  font-size: 32px;
  font-weight: 500;
  line-height: 1;
  box-shadow: 0 14px 32px rgba(11, 61, 46, 0.24);
  z-index: 40;
}

.form-errors {
  padding: 10px 12px;
  border: 1px solid rgba(177, 44, 44, 0.35);
  border-radius: 12px;
  background: rgba(177, 44, 44, 0.08);
  color: #7c1f1f;
}

.icon-btn {
  width: 36px;
  height: 36px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: #fff;
  color: var(--muted);
  cursor: pointer;
}

.icon-btn.accent {
  border-color: var(--orange);
  background: var(--orange);
  color: #22160a;
}

.icon-btn.accent:hover {
  background: #e47f1c;
}

.icon-btn.ok {
  border-color: rgba(11, 61, 46, 0.25);
  background: rgba(11, 61, 46, 0.05);
  color: var(--green);
}

.row-dragging { opacity: 0.5; }

.drag-cell {
  white-space: nowrap;
  cursor: move;
}

.aisle-order-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
}

.aisle-order-meta .help {
  margin: 0;
}

.aisle-order-status[data-state="idle"] {
  background: var(--surface-alt);
}

.aisle-order-status[data-state="saving"] {
  border-color: rgba(242, 140, 40, 0.35);
  background: rgba(242, 140, 40, 0.09);
  color: #8a4c12;
}

.aisle-order-status[data-state="saved"] {
  border-color: rgba(11, 61, 46, 0.25);
  background: rgba(11, 61, 46, 0.05);
  color: var(--green);
}

.aisle-order-status[data-state="error"] {
  border-color: rgba(177, 44, 44, 0.35);
  background: rgba(177, 44, 44, 0.08);
  color: #7c1f1f;
}

.aisle-controls-heading {
  width: 1%;
  white-space: nowrap;
}

.aisle-reorder-buttons {
  align-items: flex-start;
  white-space: nowrap;
}

.aisle-shift-form {
  display: inline;
}

.aisle-shift-placeholder {
  display: inline-block;
  width: 58px;
  height: 1px;
}

.empty-state {
  padding: 20px;
  border: 1px dashed var(--border);
  border-radius: var(--radius-sm);
  background: rgba(11, 61, 46, 0.02);
  color: var(--muted);
}

@keyframes shopping-item-enter {
  from {
    opacity: 0;
    transform: translateY(-8px) scale(0.985);
  }

  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

.page-actions {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
  margin-top: 12px;
}

@media (max-width: 900px) {
  .hero,
  .form-row,
  .quick-add,
  .filter-bar {
    grid-template-columns: 1fr;
  }

  .col-4,
  .col-6,
  .col-8 { grid-column: span 12; }

  .topbar-inner {
    grid-template-columns: 1fr;
    align-items: flex-start;
  }

  .brand,
  .nav {
    width: 100%;
  }

  .nav {
    justify-content: flex-start;
  }

  .aisle-order-meta {
    align-items: flex-start;
    flex-direction: column;
  }

  .floating-add-button {
    right: 16px;
    bottom: calc(16px + env(safe-area-inset-bottom, 0px));
  }
}

@media (hover: hover) and (pointer: fine) {
  .aisle-reorder-buttons {
    display: none;
  }
}

@media (prefers-reduced-motion: reduce) {
  .item {
    transition: none;
  }

  .item.item-entering {
    animation: none;
  }
}
