:root {
  --bg: #fafaf7;
  --surface: #ffffff;
  --border: #e6e2da;
  --border-strong: #d4cfc4;
  --text: #1f1d1a;
  --muted: #6b6557;
  --muted-2: #98917f;
  --accent: #2c5e3f;
  --accent-strong: #1f4730;
  --accent-soft: #e8f0eb;
  --warn-bg: #fff8e1;
  --warn-border: #f0d57e;
  --warn-text: #5b4a10;
  --cat-stationery: #d99f73;
  --cat-stationery-soft: #f4e3d2;
  --cat-office: #6a8eae;
  --cat-office-soft: #d8e3ec;
  --cat-lifestyle: #8a9d6e;
  --cat-lifestyle-soft: #e1e8d5;
  --radius: 10px;
  --radius-sm: 6px;
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.04);
  --shadow-md: 0 2px 6px rgba(0, 0, 0, 0.06);
}

* {
  box-sizing: border-box;
}

html, body {
  margin: 0;
  padding: 0;
}

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

a {
  color: var(--accent-strong);
}

main {
  max-width: 1100px;
  margin: 0 auto;
  /* Bottom padding leaves room for the inspector drawer (~240px max). */
  padding: 2.5rem 1.5rem 18rem;
}

h1, h2, h3 {
  margin: 0;
  letter-spacing: -0.01em;
  font-weight: 600;
}

h1 {
  font-size: 1.85rem;
  margin-bottom: 0.5rem;
}

h2 {
  font-size: 1.25rem;
}

h3 {
  font-size: 1.05rem;
}

/* --- Header --- */

.site-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 1rem 2rem;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 100;
}

.brand {
  font-weight: 600;
  font-size: 1.05rem;
  text-decoration: none;
  color: var(--text);
  letter-spacing: -0.01em;
}

.site-header nav a {
  margin-left: 1.25rem;
  text-decoration: none;
  color: var(--muted);
  font-size: 0.95rem;
  transition: color 0.15s ease;
}

.site-header nav a:hover {
  color: var(--text);
}

/* Admin header variant */
.site-header--admin {
  background: #1a1a1a;
  border-bottom-color: #2a2a2a;
}

.site-header--admin .brand {
  color: #f5f5f5;
}

.site-header--admin nav a {
  color: #cfd8dc;
}

.site-header--admin nav a:hover {
  color: #fff;
}

/* --- Banners --- */

.demo-banner,
.admin-banner {
  background: var(--warn-bg);
  border: 1px solid var(--warn-border);
  border-radius: var(--radius);
  padding: 0.9rem 1.1rem;
  margin-bottom: 1.5rem;
  font-size: 0.92rem;
  color: var(--warn-text);
  line-height: 1.5;
}

.demo-banner strong,
.admin-banner strong {
  color: #3a2e08;
}

/* --- Catalog (product list) --- */

.catalog-hero {
  margin-bottom: 2rem;
  padding: 1.75rem 0 1rem;
  border-bottom: 1px solid var(--border);
}

.catalog-hero h1 {
  font-size: 2.1rem;
  margin-bottom: 0.4rem;
}

.catalog-hero p {
  margin: 0;
  color: var(--muted);
  font-size: 1.05rem;
}

.catalog-section {
  margin-bottom: 3rem;
}

.catalog-section-header {
  margin-bottom: 1.1rem;
  display: flex;
  align-items: baseline;
  gap: 1rem;
  flex-wrap: wrap;
}

.catalog-section-header h2 {
  font-size: 1.4rem;
}

.catalog-section-blurb {
  margin: 0;
  color: var(--muted);
  font-size: 0.95rem;
}

.product-grid {
  list-style: none;
  padding: 0;
  margin: 0;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: 1.25rem;
}

.product-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  display: flex;
  flex-direction: column;
  box-shadow: var(--shadow-sm);
  transition: transform 0.15s ease, box-shadow 0.15s ease;
}

.product-card:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-md);
}

/* Placeholder thumbnail. Flat color block per category, restrained
 * initials — stands in for product imagery without competing with the
 * actual product info below. */
.product-thumb {
  aspect-ratio: 4 / 3;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: 'Georgia', 'Times New Roman', serif;
  font-weight: 500;
  font-size: 1.6rem;
  letter-spacing: 0.08em;
  border-bottom: 1px solid var(--border);
}

.product-thumb-initials {
  opacity: 0.6;
}

.product-thumb--stationery {
  background: var(--cat-stationery-soft);
  color: #7a5a3a;
}

.product-thumb--office {
  background: var(--cat-office-soft);
  color: #3e5670;
}

.product-thumb--lifestyle {
  background: var(--cat-lifestyle-soft);
  color: #4f5e3a;
}

.product-body {
  padding: 1rem 1rem 1.1rem;
  display: flex;
  flex-direction: column;
  flex: 1;
}

.product-name {
  margin-bottom: 0.3rem;
}

.product-description {
  color: var(--muted);
  font-size: 0.9rem;
  margin: 0 0 1rem;
  flex: 1;
}

.product-footer {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.75rem;
}

.product-price {
  font-weight: 600;
  font-size: 1.05rem;
}

/* --- Buttons --- */

button {
  cursor: pointer;
  border: 1px solid var(--border-strong);
  background: var(--surface);
  padding: 0.45rem 0.85rem;
  border-radius: var(--radius-sm);
  font-size: 0.9rem;
  font-family: inherit;
  color: var(--text);
  transition: background 0.12s ease, border-color 0.12s ease, color 0.12s ease;
}

button:hover {
  background: #f3f0ea;
}

.add-btn {
  font-weight: 500;
}

.add-btn.in-cart {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

.add-btn.in-cart:hover {
  background: var(--accent-strong);
  border-color: var(--accent-strong);
}

.btn-primary {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: var(--accent);
  border: 1px solid var(--accent);
  color: #fff;
  text-decoration: none;
  padding: 0.6rem 1.2rem;
  border-radius: var(--radius-sm);
  font-weight: 500;
}

.btn-primary:hover {
  background: var(--accent-strong);
  border-color: var(--accent-strong);
}

.btn-secondary {
  background: var(--surface);
  border-color: var(--border-strong);
  color: var(--text);
  padding: 0.55rem 1rem;
}

/* --- Cart --- */

.cart-header {
  margin-bottom: 1.5rem;
  padding-bottom: 1rem;
  border-bottom: 1px solid var(--border);
}

.cart-summary-line {
  margin: 0.5rem 0 0;
  color: var(--muted);
  font-size: 1rem;
}

.cart-summary-line strong {
  color: var(--text);
  font-weight: 600;
}

.cart-empty {
  background: var(--surface);
  border: 1px dashed var(--border-strong);
  border-radius: var(--radius);
  padding: 2rem;
  text-align: center;
  color: var(--muted);
}

.cart-empty .link-back {
  display: inline-block;
  margin-top: 0.75rem;
  text-decoration: none;
  color: var(--accent-strong);
}

.cart-lines {
  list-style: none;
  padding: 0;
  margin: 0;
}

.cart-line {
  display: grid;
  grid-template-columns: 64px 1fr auto auto auto;
  gap: 1rem;
  align-items: center;
  padding: 1rem 0;
  border-bottom: 1px solid var(--border);
}

.cart-line:last-child {
  border-bottom: none;
}

.cart-line-thumb {
  width: 64px;
  height: 64px;
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: 'Georgia', 'Times New Roman', serif;
  font-weight: 500;
  font-size: 0.95rem;
  letter-spacing: 0.06em;
}

.cart-line-thumb .product-thumb-initials {
  opacity: 0.6;
}

.cart-line-info {
  display: flex;
  flex-direction: column;
}

.cart-line-name {
  font-weight: 500;
}

.cart-line-unit {
  color: var(--muted);
  font-size: 0.85rem;
}

.cart-line-qty {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 0.15rem;
}

.qty-btn {
  border: none;
  background: transparent;
  width: 28px;
  height: 28px;
  padding: 0;
  font-size: 1rem;
  line-height: 1;
  color: var(--muted);
  border-radius: 4px;
}

.qty-btn:hover {
  background: var(--surface);
  color: var(--text);
}

.qty-value {
  min-width: 2ch;
  text-align: center;
  font-variant-numeric: tabular-nums;
  font-weight: 500;
}

.cart-line-total {
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  min-width: 70px;
  text-align: right;
}

.cart-line-remove {
  width: 28px;
  height: 28px;
  padding: 0;
  border-radius: 50%;
  border: none;
  background: transparent;
  color: var(--muted-2);
  font-size: 1.2rem;
  line-height: 1;
}

.cart-line-remove:hover {
  background: #f2e9e9;
  color: #b85b5b;
}

.cart-footer {
  display: flex;
  flex-direction: column;
  gap: 1.25rem;
  margin-top: 2rem;
  padding-top: 1.5rem;
  border-top: 1px solid var(--border);
}

.cart-totals {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem 1.25rem;
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
  max-width: 360px;
  margin-left: auto;
}

.cart-totals-row {
  display: flex;
  justify-content: space-between;
  font-variant-numeric: tabular-nums;
}

.cart-totals-row--muted {
  color: var(--muted);
  font-size: 0.9rem;
}

.cart-totals-row--grand {
  padding-top: 0.5rem;
  border-top: 1px solid var(--border);
  font-weight: 600;
  font-size: 1.05rem;
}

.cart-actions {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
}

/* --- Checkout --- */

.state-label {
  color: var(--muted-2);
  font-style: italic;
  font-size: 0.85rem;
  margin: 0.25rem 0 1.5rem;
}

.step {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.5rem;
  margin: 1rem 0;
  box-shadow: var(--shadow-sm);
}

.step h2 {
  margin-bottom: 0.75rem;
}

.step p {
  margin: 0.4rem 0;
}

.step-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-top: 1rem;
}

.hint {
  color: var(--muted-2);
  font-size: 0.85rem;
  margin-top: 1rem;
}

/* --- Admin dashboard --- */

.admin-hint {
  color: var(--muted);
  font-style: italic;
  margin-bottom: 1.5rem;
}

.admin-metrics {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 1rem;
  padding: 0.6rem 1rem;
  background: #1a1a1a;
  color: #d0d0d0;
  border-radius: var(--radius-sm);
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 0.78rem;
  margin-bottom: 1.5rem;
}

.admin-metrics-label {
  color: #6a9955;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  font-weight: 600;
}

.admin-metric {
  display: inline-flex;
  gap: 0.4rem;
  align-items: baseline;
}

.admin-metric-label {
  color: #888;
}

.admin-metric-value {
  color: #d0d0d0;
  font-variant-numeric: tabular-nums;
}

.admin-aggregates {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 1rem;
  margin-bottom: 2rem;
}

.aggregate {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem;
  display: flex;
  flex-direction: column;
}

.aggregate-label {
  font-size: 0.78rem;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.aggregate-value {
  font-size: 1.6rem;
  font-weight: 600;
  margin-top: 0.25rem;
  font-variant-numeric: tabular-nums;
}

.product-totals,
.admin-sessions {
  list-style: none;
  padding: 0;
}

.product-total-row {
  display: flex;
  justify-content: space-between;
  padding: 0.5rem 0;
  border-bottom: 1px solid var(--border);
}

.product-total-count {
  font-variant-numeric: tabular-nums;
  font-weight: 500;
}

.admin-empty {
  color: var(--muted-2);
  font-style: italic;
}

.admin-session {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem;
  margin: 0.75rem 0;
}

.admin-session-head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  margin-bottom: 0.5rem;
}

.admin-session-sid {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  color: var(--muted);
  font-size: 0.85rem;
}

.admin-session-meta {
  font-weight: 500;
}

.admin-session-items {
  list-style: none;
  padding: 0;
  margin: 0;
}

.admin-session-item {
  display: grid;
  grid-template-columns: 1fr auto auto;
  gap: 1rem;
  padding: 0.4rem 0;
  border-top: 1px solid #f0ece5;
  font-size: 0.95rem;
}

.admin-item-qty {
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

.admin-item-price {
  font-variant-numeric: tabular-nums;
  text-align: right;
  width: 80px;
}

/* ===== Stator inspector ===== */

.stator-inspector {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 1000;
  pointer-events: none;
}

.stator-inspector > * {
  pointer-events: auto;
}

/* `display: flex`/`inline-flex` on the drawer/toggle would override the UA
 * stylesheet's `[hidden] { display: none }`. Restore the hide with a more
 * specific selector. */
.stator-inspector-drawer[hidden],
.stator-inspector-toggle[hidden] {
  display: none;
}

.stator-inspector-toggle {
  position: fixed;
  bottom: 1rem;
  right: 1rem;
  background: #1a1a1a;
  color: #d0d0d0;
  border: 1px solid #2a2a2a;
  padding: 0.45rem 0.85rem;
  border-radius: 999px;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 0.82rem;
  cursor: pointer;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.18);
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
}

.stator-inspector-toggle:hover {
  background: #232323;
  color: #f0f0f0;
}

.stator-inspector-drawer {
  background: #141414;
  color: #d0d0d0;
  border-top: 1px solid #2a2a2a;
  max-height: 240px;
  display: flex;
  flex-direction: column;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 0.78rem;
  box-shadow: 0 -2px 12px rgba(0, 0, 0, 0.25);
}

.stator-inspector-header {
  display: flex;
  align-items: center;
  gap: 1rem;
  padding: 0.5rem 0.9rem;
  background: #1a1a1a;
  border-bottom: 1px solid #262626;
  flex-shrink: 0;
}

.stator-inspector-title {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  color: #f5f5f5;
  font-weight: 600;
  letter-spacing: 0.02em;
}

.stator-inspector-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #6a9955;
  box-shadow: 0 0 0 2px rgba(106, 153, 85, 0.18);
}

.stator-inspector-legend {
  display: inline-flex;
  gap: 0.75rem;
  color: #888;
}

.stator-inspector-key--up {
  color: #dcdcaa;
}

.stator-inspector-key--down {
  color: #9cdcfe;
}

.stator-inspector-header button {
  background: transparent;
  border: 1px solid #333;
  color: #aaa;
  padding: 0.15rem 0.55rem;
  font-family: inherit;
  font-size: 0.75rem;
  border-radius: 4px;
  cursor: pointer;
}

.stator-inspector-header button:hover {
  background: #232323;
  color: #f0f0f0;
}

.stator-inspector-close {
  margin-left: auto;
  font-size: 1rem !important;
  line-height: 1;
  padding: 0.05rem 0.5rem !important;
}

.stator-inspector-body {
  flex: 1;
  overflow-y: auto;
  padding: 0;
}

.stator-inspector-empty {
  margin: 0;
  padding: 1rem 0.9rem;
  color: #6a6a6a;
  font-style: italic;
}

.stator-inspector-row {
  border-bottom: 1px solid #1f1f1f;
}

.stator-inspector-row:last-child {
  border-bottom: none;
}

.stator-inspector-summary {
  display: grid;
  grid-template-columns: 90px 16px 130px 1fr auto;
  align-items: baseline;
  gap: 0.75rem;
  padding: 0.35rem 0.9rem;
  cursor: pointer;
  user-select: none;
}

.stator-inspector-summary:hover {
  background: #1c1c1c;
}

.stator-inspector-time {
  color: #6a6a6a;
  font-variant-numeric: tabular-nums;
}

.stator-inspector-arrow {
  text-align: center;
  font-weight: 700;
}

.stator-inspector-row--up .stator-inspector-arrow {
  color: #dcdcaa;
}

.stator-inspector-row--down .stator-inspector-arrow {
  color: #9cdcfe;
}

.stator-inspector-machine {
  color: #c586c0;
  font-weight: 500;
}

.stator-inspector-row--down .stator-inspector-machine {
  color: #9cdcfe;
}

.stator-inspector-event-type {
  color: #4ec9b0;
  font-weight: 500;
}

.stator-inspector-params {
  color: #888;
  text-align: right;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}

.stator-inspector-detail {
  margin: 0;
  padding: 0.5rem 0.9rem 0.75rem 2.5rem;
  background: #0e0e0e;
  color: #cfcfcf;
  font-size: 0.74rem;
  white-space: pre-wrap;
  word-break: break-word;
  border-top: 1px dashed #2a2a2a;
}

/* ===== Slot flash — visual confirmation when a patch hits the DOM ===== */

.stator-flash {
  outline-style: solid;
  outline-offset: 3px;
  animation: stator-flash 1200ms ease-out forwards;
  border-radius: 2px;
}

@keyframes stator-flash {
  0% {
    outline-width: 3px;
    outline-color: var(--flash-color, dodgerblue);
    background-color: var(--flash-bg, rgba(30, 144, 255, 0.16));
  }
  /* Hold the bright state for the first third so it's easy to catch. */
  30% {
    outline-width: 3px;
    outline-color: var(--flash-color, dodgerblue);
    background-color: var(--flash-bg, rgba(30, 144, 255, 0.16));
  }
  100% {
    outline-width: 0;
    outline-color: transparent;
    background-color: transparent;
  }
}

.stator-flash--text {
  --flash-color: #3b82f6;
  --flash-bg: rgba(59, 130, 246, 0.12);
}

.stator-flash--attr {
  --flash-color: #a855f7;
  --flash-bg: rgba(168, 85, 247, 0.12);
}

.stator-flash--html {
  --flash-color: #14b8a6;
  --flash-bg: rgba(20, 184, 166, 0.10);
}

/* Make sure inspector + flash don't fight body padding on shorter viewports */
@media (max-height: 600px) {
  .stator-inspector-drawer {
    max-height: 50vh;
  }
}
