:root {
  --paper: #f4efe5;
  --paper-light: #fbf8f1;
  --ink: #251e1b;
  --muted: #6f645e;
  --rule: #cfc4b6;
  --accent: #7d2638;
  --accent-dark: #5f1829;
  --success: #276148;
  --warning: #8a551c;
  --danger: #9b2d2d;
  --shadow: 0 16px 44px rgba(51, 38, 31, 0.14);
  color-scheme: light;
  font-family: "Avenir Next", Avenir, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }
html { background: var(--paper); }
body {
  margin: 0;
  color: var(--ink);
  background:
    linear-gradient(rgba(80, 56, 42, 0.035) 1px, transparent 1px) 0 0 / 100% 28px,
    var(--paper);
  min-height: 100vh;
  padding-bottom: 104px;
}
button, input, select { font: inherit; }
button, select, input { min-height: 44px; }
button { cursor: pointer; }
button:disabled { cursor: not-allowed; opacity: .48; }
:focus-visible { outline: 3px solid rgba(125, 38, 56, .35); outline-offset: 2px; }

.skip-link {
  position: fixed;
  left: 16px;
  top: -80px;
  z-index: 20;
  padding: 12px 16px;
  background: var(--ink);
  color: white;
}
.skip-link:focus { top: 12px; }

.site-header {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  gap: 12px 28px;
  align-items: center;
  padding: 24px clamp(20px, 4vw, 64px);
  border-bottom: 1px solid var(--rule);
  background: rgba(244, 239, 229, .95);
}
.wordmark {
  display: inline-flex;
  align-items: center;
  min-height: 44px;
  color: var(--ink);
  font: 700 2.2rem/1 Georgia, serif;
  letter-spacing: -.08em;
  text-decoration: none;
}
.page-intro h1, .ledger-heading h2, dialog h2 {
  margin: 3px 0;
  font-family: Georgia, serif;
  font-size: 1.5rem;
  font-size: clamp(1.5rem, 2vw, 2.25rem);
  font-weight: 500;
  line-height: 1.05;
}
.page-intro > p, .status-strip p, .ledger-heading p, dialog > p { margin: 0; color: var(--muted); }
.eyebrow {
  margin: 0;
  color: var(--accent);
  font-size: .75rem;
  font-weight: 800;
  letter-spacing: .14em;
  text-transform: uppercase;
}

main { width: min(1520px, calc(100% - 40px)); margin: 28px auto 44px; }

/* One navigation for every admin section. */
.admin-nav { display: flex; flex-wrap: wrap; gap: 4px; }
.nav-link {
  display: inline-flex;
  align-items: center;
  min-height: 44px;
  min-width: 44px;
  padding: 0 14px;
  border-bottom: 3px solid transparent;
  color: var(--ink);
  font-weight: 750;
  text-decoration: none;
}
.nav-link:hover { color: var(--accent); }
.nav-link[aria-current="page"] { border-bottom-color: var(--accent); color: var(--accent); }
.page-intro { margin: 0 0 22px; }
.page-intro > p { max-width: 70ch; margin-top: 6px; }
.status-strip {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 24px;
  padding: 20px 22px;
  border: 1px solid var(--rule);
  border-top: 3px solid var(--accent);
  background: var(--paper-light);
}
.draft-count strong { color: var(--accent); font-size: 1.4em; }

.catalog-tools {
  display: grid;
  grid-template-columns: minmax(260px, 1fr) 210px auto;
  gap: 14px;
  align-items: end;
  margin: 22px 0;
}
.search-field, .filter-field, .product-row label, #add-form > label { display: grid; gap: 6px; color: var(--muted); font-size: .75rem; font-weight: 700; }
input, select {
  width: 100%;
  border: 1px solid var(--rule);
  border-radius: 2px;
  padding: 9px 10px;
  color: var(--ink);
  background: #fffdf8;
}
input:focus, select:focus { border-color: var(--accent); }
input[aria-invalid="true"] { border-color: var(--danger); background: #fff4f2; }

.primary-button, .secondary-button, .quiet-button, .icon-button {
  border: 1px solid var(--ink);
  border-radius: 2px;
  padding: 10px 16px;
  font-weight: 750;
}
.primary-button { color: white; background: var(--accent); border-color: var(--accent); }
.primary-button:hover:not(:disabled) { background: var(--accent-dark); }
.secondary-button { color: var(--ink); background: transparent; }
.quiet-button, .icon-button { color: var(--ink); background: transparent; }
.icon-button { width: 44px; padding: 0; font-size: 1.6rem; }

.ledger { border: 1px solid var(--rule); background: var(--paper-light); box-shadow: var(--shadow); }
.ledger-heading { display: flex; justify-content: space-between; align-items: end; padding: 22px; border-bottom: 1px solid var(--rule); }
.column-labels, .product-row {
  display: grid;
  grid-template-columns: minmax(260px, 2fr) minmax(90px, .7fr) minmax(90px, .7fr) 78px 110px 150px;
  gap: 14px;
  align-items: center;
}
.column-labels { padding: 10px 18px; color: var(--muted); background: #ece4d7; font-size: .75rem; font-weight: 800; letter-spacing: .08em; text-transform: uppercase; }
.product-row { padding: 14px 18px; border-top: 1px solid var(--rule); background: rgba(255, 253, 248, .78); }
.product-row:first-child { border-top: 0; }
.product-row.is-changed { background: #f8eef0; }
.product-row.is-hidden { opacity: .72; }
.product-identity { display: grid; grid-template-columns: 74px minmax(0, 1fr); gap: 12px; align-items: center; }
.product-photo-control { display: grid; gap: 5px; width: 74px; }
.product-image { width: 74px; height: 74px; object-fit: cover; border: 1px solid var(--rule); background: #e6ded2; }
.image-upload-button {
  width: 100%;
  min-height: 44px;
  border: 1px solid var(--rule);
  border-radius: 2px;
  padding: 6px 4px;
  color: var(--ink);
  background: transparent;
  font-size: .75rem;
  font-weight: 800;
  line-height: 1.15;
}
.image-upload-button:hover:not(:disabled) { color: var(--accent); border-color: var(--accent); background: #fffaf3; }
.product-photo-control.is-uploading .product-image { opacity: .5; }
.product-id { display: block; margin-top: 5px; color: var(--muted); font-size: .75rem; overflow-wrap: anywhere; }
.field-label { display: none; }
.numeric-input { font-variant-numeric: tabular-nums; }
.visibility-control { display: flex !important; align-items: center; gap: 8px !important; min-height: 44px; color: var(--ink) !important; }
.visibility-control input { width: 20px; min-height: 20px; accent-color: var(--accent); }
.save-state { margin: 0; color: var(--success); font-size: .75rem; font-weight: 800; }
.save-state[data-state="saving"], .save-state[data-state="pending"], .save-state[data-state="uploading"] { color: var(--warning); }
.save-state[data-state="error"], .save-state[data-state="invalid"], .save-state[data-state="auth"], .save-state[data-state="network"] { color: var(--danger); }
.save-cell { display: grid; gap: 6px; justify-items: start; }
.retry-save-button { min-height: 44px; padding: 8px 14px; }
.save-state[data-state="conflict"] { color: var(--danger); }
.conflict-actions { display: flex; flex-wrap: wrap; gap: 6px; }
.conflict-actions[hidden] { display: none; }
.conflict-actions button { min-height: 44px; padding: 8px 12px; }
.history-note { color: var(--ink); }
.history-changes { margin: 6px 0 0; padding-left: 18px; color: var(--muted); font-size: .8rem; }
.history-changes li { margin: 2px 0; }
.product-row.has-unsaved { box-shadow: inset 4px 0 0 var(--danger); }
.product-list.is-locked { opacity: .7; pointer-events: none; }
.session-banner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-top: 14px;
  padding: 14px 18px;
  border: 1px solid var(--danger);
  border-left-width: 4px;
  background: #fff4f2;
}
.session-banner[hidden] { display: none; }
.payment-warning { margin-top: 14px; padding: 14px 18px; border: 1px solid var(--danger); border-left-width: 4px; background: #fff4f2; }
.payment-warning[hidden] { display: none; }
.payment-warning p { margin: 0; color: var(--ink); }
.payment-warning ul { margin: 8px 0 0; padding-left: 20px; color: var(--ink); font-weight: 650; }
.qr-state { color: var(--danger); font-size: .75rem; font-weight: 700; }
.qr-state:empty { display: none; }
.product-row.has-payment-mismatch .price-input { border-color: var(--danger); background: #fff4f2; }
.session-banner p { margin: 0; color: var(--ink); font-weight: 650; }
.session-actions { display: flex; flex-wrap: wrap; gap: 10px; }
.session-actions a, .session-actions button { display: inline-flex; align-items: center; justify-content: center; min-height: 44px; text-decoration: none; }
.product-details { grid-column: 1 / -1; }
.product-details summary { width: max-content; min-height: 44px; padding-block: 13px; color: var(--muted); font-size: .75rem; line-height: 18px; cursor: pointer; }
.detail-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; margin-top: 12px; }
.empty-state { padding: 48px 22px; text-align: center; color: var(--muted); }

.publish-rail {
  position: fixed;
  z-index: 10;
  left: 0;
  right: 0;
  bottom: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  padding: 14px clamp(20px, 4vw, 64px);
  color: #fff;
  background: var(--ink);
  box-shadow: 0 -8px 28px rgba(25, 18, 15, .2);
}
.publish-rail p { margin: 2px 0; }
.publish-rail .eyebrow { color: #d8a8b3; }
.publish-rail .primary-button { min-width: 180px; }

dialog {
  width: min(680px, calc(100% - 28px));
  max-height: min(760px, calc(100vh - 40px));
  border: 1px solid var(--ink);
  border-radius: 2px;
  padding: 24px;
  color: var(--ink);
  background: var(--paper-light);
  box-shadow: var(--shadow);
}
dialog::backdrop { background: rgba(30, 23, 20, .6); }
.dialog-heading { display: flex; align-items: start; justify-content: space-between; gap: 20px; }
.history-list { display: grid; margin-top: 20px; border-top: 1px solid var(--rule); }
.history-item { display: grid; grid-template-columns: 1fr auto; gap: 14px; padding: 16px 0; border-bottom: 1px solid var(--rule); }
.history-item p { margin: 3px 0; }
.history-meta { color: var(--muted); font-size: .8rem; }
#add-form { display: grid; gap: 18px; }
.dialog-actions { display: flex; justify-content: end; gap: 10px; }

/* Today in stock */
.availability-page { padding-bottom: 0; }
.availability-main { width: min(760px, calc(100% - 40px)); }
.availability-status { margin: 0 0 14px; padding: 14px 18px; border: 1px solid var(--rule); border-left: 4px solid var(--success); background: var(--paper-light); }
.availability-status.error { border-left-color: var(--danger); color: var(--danger); background: #fff4f2; }
.session-link-row { margin: 0 0 14px; }
.session-link-row a { display: inline-flex; align-items: center; min-height: 44px; text-decoration: none; }
.session-link-row a[hidden] { display: none; }
.toggle-list { border: 1px solid var(--rule); background: var(--paper-light); }
.product-toggle {
  position: relative;
  display: grid;
  grid-template-columns: 54px minmax(0, 1fr) 52px;
  gap: 14px;
  align-items: center;
  min-height: 72px;
  padding: 9px 16px;
  border-top: 1px solid var(--rule);
  cursor: pointer;
}
.product-toggle:first-child { border-top: 0; }
.product-toggle:hover { background: #fffaf3; }
.product-toggle > img { width: 54px; height: 54px; object-fit: cover; border: 1px solid var(--rule); background: #e6ded2; }
.product-toggle-copy { display: grid; gap: 2px; min-width: 0; }
.product-toggle-copy strong { overflow-wrap: anywhere; }
.product-toggle-copy span { color: var(--muted); font-size: .8rem; font-variant-numeric: tabular-nums; }
.product-toggle input { position: absolute; width: 1px; height: 1px; min-height: 0; margin: 0; opacity: 0; }
.toggle-control { position: relative; width: 44px; height: 26px; border: 1px solid var(--ink); border-radius: 13px; background: #fffdf8; justify-self: end; }
.toggle-control::after { content: ""; position: absolute; top: 3px; left: 3px; width: 18px; height: 18px; border-radius: 50%; background: var(--ink); transition: transform .15s ease; }
.product-toggle input:checked + .toggle-control { border-color: var(--accent); background: var(--accent); }
.product-toggle input:checked + .toggle-control::after { background: #fff; transform: translateX(18px); }
.product-toggle input:focus-visible + .toggle-control { outline: 3px solid rgba(125, 38, 56, .35); outline-offset: 3px; }
.availability-actions { position: sticky; bottom: 0; display: flex; flex-wrap: wrap; gap: 10px; margin-top: 18px; padding: 14px 0; background: var(--paper); }

@media (max-width: 980px) {
  .column-labels { display: none; }
  .product-row {
    grid-template-columns: minmax(220px, 2fr) repeat(3, minmax(80px, .7fr));
  }
  .field-label { display: block; }
  .visibility-control, .save-cell { grid-column: span 2; }
}

@media (max-width: 760px) {
  body { padding-bottom: 138px; }
  .site-header { gap: 4px 12px; padding: 12px 16px; }
  .wordmark { font-size: 1.8rem; }
  .nav-link { padding: 0 10px; }
  .page-intro > p { display: none; }
  .availability-main { width: calc(100% - 24px); }
  .availability-actions > button { flex: 1 1 140px; }
  main { width: min(100% - 24px, 620px); margin-top: 14px; }
  .status-strip { align-items: start; padding: 16px; }
  .draft-count { text-align: right; max-width: 110px; }
  .catalog-tools { grid-template-columns: 1fr 1fr; gap: 10px; }
  .search-field { grid-column: 1 / -1; }
  .catalog-tools button { align-self: end; }
  .ledger { box-shadow: none; border: 0; background: transparent; }
  .ledger-heading { padding: 16px 2px; }
  .product-list { display: grid; gap: 12px; }
  .product-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
    padding: 14px;
    border: 1px solid var(--rule);
    background: var(--paper-light);
  }
  .product-row:first-child { border-top: 1px solid var(--rule); }
  .product-identity, .product-details { grid-column: 1 / -1; }
  .product-identity { grid-template-columns: 74px 1fr; }
  .product-image { width: 74px; height: 74px; }
  .visibility-control, .save-cell { grid-column: auto; }
  .save-cell { justify-items: end; text-align: right; }
  .detail-grid { grid-template-columns: 1fr; }
  .publish-rail { align-items: stretch; flex-direction: column; gap: 10px; padding: 12px; }
  .publish-rail .primary-button { width: 100%; }
  .publish-rail p { font-size: .82rem; }
  dialog { padding: 18px; }
  .history-item { grid-template-columns: 1fr; }
  .session-banner { align-items: stretch; flex-direction: column; }
  .session-actions > * { flex: 1 1 140px; }
}

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