:root {
  --bg: #f4f1ea;
  --surface: #ffffff;
  --ink: #1c1917;
  --ink-muted: #57534e;
  --line: #e7e5e4;
  --action: #0b5cab;
  --action-press: #084a89;
  --action-soft: #e6f0f8;
  --best: #0f6b4c;
  --better: #0b5cab;
  --good: #8a5a12;
  --danger: #b42318;
  --warn: #92400e;
  --shadow: 0 2px 10px rgba(28, 25, 23, 0.08);
  --radius: 16px;
  --tap: 64px;
  --header: 76px;
  color-scheme: light;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  height: 100dvh;
  max-height: 100dvh;
  background: var(--bg);
  color: var(--ink);
  font-family: "Avenir Next", "Segoe UI", "Helvetica Neue", system-ui, -apple-system, sans-serif;
  font-size: 22px;
  line-height: 1.35;
  overflow: hidden;
}

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

button {
  touch-action: manipulation;
  cursor: pointer;
  border: none;
  background: none;
}

img { display: block; }

.app {
  height: 100%;
  height: 100dvh;
  max-height: 100dvh;
  min-height: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.topbar {
  box-sizing: border-box;
  min-height: var(--header);
  height: auto;
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 8px 16px;
  padding-top: max(8px, env(safe-area-inset-top));
  padding-left: max(16px, env(safe-area-inset-left));
  padding-right: max(16px, env(safe-area-inset-right));
  background: var(--surface);
  border-bottom: 1px solid var(--line);
  overflow: hidden;
}

.btn {
  min-height: var(--tap);
  min-width: var(--tap);
  padding: 0 20px;
  border-radius: 14px;
  font-weight: 700;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
}

.btn-back {
  background: #eceae6;
  color: var(--ink);
  font-size: 20px;
  flex: 0 0 148px;
}

.btn-back[hidden],
.cart-pill[hidden] {
  visibility: hidden;
  display: inline-flex !important;
  pointer-events: none;
}

.btn-action {
  background: var(--action);
  color: #fff;
}

.btn-action:active { background: var(--action-press); }

.btn-ghost {
  background: #eceae6;
  color: var(--ink);
}

.btn-danger {
  background: #fde8e6;
  color: var(--danger);
  min-width: var(--tap);
  padding: 0 16px;
}

.title-wrap { text-align: center; min-width: 0; flex: 1 1 auto; overflow: hidden; }
.title {
  margin: 0;
  font-size: 26px;
  font-weight: 750;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.subtitle {
  margin: 2px 0 0;
  font-size: 15px;
  color: var(--ink-muted);
  display: -webkit-box;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
  overflow: hidden;
  text-overflow: ellipsis;
  overflow-wrap: anywhere;
  line-height: 1.25;
  max-height: 2.5em;
}

.sample-badge {
  flex: 0 0 auto;
  background: #fff4d6;
  color: var(--warn);
  border: 1px solid #f0d48a;
  border-radius: 999px;
  padding: 8px 12px;
  font-size: 14px;
  font-weight: 800;
  letter-spacing: 0.04em;
  white-space: nowrap;
}

.cart-pill {
  min-height: var(--tap);
  min-width: 110px;
  padding: 0 18px;
  border-radius: 999px;
  background: var(--action);
  color: #fff;
  font-weight: 800;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
}
.cart-pill .count {
  background: #fff;
  color: var(--action);
  min-width: 32px;
  height: 32px;
  border-radius: 50%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
}
.cart-pill.is-empty { background: #4b5563; }
.cart-pill.is-empty .count { color: #4b5563; }

.view {
  flex: 1 1 0%;
  min-height: 0;
  overflow: auto;
  padding: 20px 24px 24px;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
}

.hero {
  background: var(--surface);
  border-radius: 20px;
  padding: 22px 24px;
  box-shadow: var(--shadow);
  margin-bottom: 18px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}
.hero .btn-action { white-space: nowrap; flex: 0 0 auto; }
.hero h2 {
  margin: 0 0 6px;
  font-size: 34px;
}
.hero p { margin: 0; color: var(--ink-muted); font-size: 20px; }

.tile-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  grid-template-rows: repeat(3, minmax(128px, 1fr));
  gap: 14px;
  min-height: min(56vh, 460px);
}


.home-grid {
  grid-template-columns: repeat(6, 1fr);
  grid-template-rows: repeat(2, minmax(170px, 1fr));
  min-height: min(58vh, 480px);
}
.home-grid .tile {
  grid-column: span 2;
  min-height: 160px;
}
.home-grid .tile:nth-child(4) { grid-column: 2 / span 2; }
.home-grid .tile:nth-child(5) { grid-column: 4 / span 2; }

.tile {
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  min-height: 128px;
  padding: 18px 20px;
  text-align: left;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  gap: 6px;
  border: 2px solid transparent;
}
.tile:active { border-color: var(--action); transform: scale(0.99); }
.tile-icon { font-size: 30px; line-height: 1; margin-bottom: auto; }
.tile strong { font-size: 24px; }
.tile span { color: var(--ink-muted); font-size: 18px; }

.note {
  margin-top: 16px;
  color: var(--ink-muted);
  font-size: 16px;
  text-align: center;
}

.card-list { display: grid; gap: 12px; }

.product-card {
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  min-height: 96px;
  padding: 16px 20px;
  text-align: left;
  display: grid;
  grid-template-columns: 92px 1fr;
  gap: 16px;
  align-items: center;
  border: 2px solid transparent;
  width: 100%;
}
.product-card:active { border-color: var(--action); }

.tier {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 44px;
  border-radius: 999px;
  font-size: 16px;
  font-weight: 800;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  padding: 0 12px;
}
.tier.best { background: #dcf5ea; color: var(--best); }
.tier.better { background: var(--action-soft); color: var(--better); }
.tier.good { background: #fff1d6; color: var(--good); }
.tier.empty { background: #eceae6; color: var(--ink-muted); }

.product-card h3 { margin: 0 0 4px; font-size: 24px; }
.product-card p { margin: 0; color: var(--ink-muted); font-size: 18px; }

.family-tabs {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding-bottom: 10px;
  margin-bottom: 12px;
}
.family-tab {
  min-height: 56px;
  padding: 0 18px;
  border-radius: 999px;
  background: var(--surface);
  border: 2px solid var(--line);
  font-weight: 700;
  white-space: nowrap;
}
.family-tab[aria-selected="true"] {
  background: var(--action);
  border-color: var(--action);
  color: #fff;
}

.search-row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 10px;
  margin-bottom: 14px;
  min-width: 0;
}
.search-input {
  min-width: 0;
  width: 100%;
  min-height: var(--tap);
  border: 2px solid var(--line);
  border-radius: 14px;
  padding: 0 16px;
  background: var(--surface);
  font-size: 22px;
}
.search-input:focus { outline: 3px solid #b9d4ee; border-color: var(--action); }

.swatch-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: 12px;
}

.swatch {
  background: var(--surface);
  border-radius: 14px;
  overflow: hidden;
  border: 2px solid transparent;
  box-shadow: var(--shadow);
  text-align: left;
  padding: 0 0 10px;
  min-height: 140px;
}
.swatch:active { border-color: var(--action); }
.swatch .chip {
  height: 84px;
  border-bottom: 1px solid var(--line);
}
.swatch strong, .swatch em {
  display: block;
  padding: 8px 10px 0;
  font-style: normal;
}
.swatch strong { font-size: 16px; }
.swatch em { font-size: 14px; color: var(--ink-muted); }

.picker {
  display: grid;
  gap: 16px;
  padding-bottom: 96px;
}
.picker-head {
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 16px 18px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}
.color-summary {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
}
.color-chip {
  width: 56px;
  height: 56px;
  border-radius: 12px;
  border: 1px solid rgba(0,0,0,0.18);
  flex: 0 0 auto;
}
.color-summary strong, .color-summary span { display: block; }
.color-summary span { color: var(--ink-muted); font-size: 16px; }

.section-label {
  font-size: 16px;
  font-weight: 800;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--ink-muted);
  margin: 0 0 8px;
}

.choice-row {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}
.choice {
  min-height: var(--tap);
  padding: 0 18px;
  border-radius: 14px;
  background: var(--surface);
  border: 2px solid var(--line);
  font-weight: 700;
}
.choice[aria-pressed="true"] {
  background: var(--action-soft);
  border-color: var(--action);
  color: var(--action);
}

.size-row {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
}
.size-btn {
  min-height: 92px;
  border-radius: 14px;
  background: var(--surface);
  border: 2px solid var(--line);
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  font-weight: 800;
}
.size-btn small {
  font-size: 18px;
  font-weight: 700;
  color: var(--ink-muted);
}
.size-btn[aria-pressed="true"] {
  border-color: var(--action);
  background: var(--action-soft);
}
.size-btn[aria-pressed="true"] small { color: var(--action); }

.qty-row {
  display: flex;
  align-items: center;
  gap: 16px;
}
.qty-btn {
  width: var(--tap);
  height: var(--tap);
  border-radius: 14px;
  background: var(--action);
  color: #fff;
  font-size: 32px;
  font-weight: 800;
}
.qty-btn:active { background: var(--action-press); }
.qty-value { font-size: 32px; font-weight: 800; min-width: 48px; text-align: center; }

.add-bar {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  padding: 12px 24px calc(12px + env(safe-area-inset-bottom));
  background: linear-gradient(180deg, transparent, var(--bg) 24%);
}
.add-bar .btn-action { width: 100%; font-size: 24px; }

.cart-item {
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 14px 16px;
  display: grid;
  grid-template-columns: 56px 1fr auto;
  gap: 12px;
  align-items: center;
}
.cart-item h3 { margin: 0 0 4px; font-size: 20px; }
.cart-item p { margin: 0; color: var(--ink-muted); font-size: 16px; }
.cart-actions { display: flex; align-items: center; gap: 8px; }
.line-price { font-weight: 800; text-align: right; }

.totals {
  margin-top: 16px;
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 16px 20px;
}
.totals-row {
  display: flex;
  justify-content: space-between;
  margin: 6px 0;
}
.totals-row.grand { font-size: 26px; font-weight: 800; margin-top: 10px; }

.bottom-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  margin-top: 18px;
}

.field { margin-bottom: 16px; }
.field label { display: block; font-weight: 700; margin-bottom: 8px; }
.field input {
  width: 100%;
  min-height: var(--tap);
  border: 2px solid var(--line);
  border-radius: 14px;
  padding: 0 16px;
  background: var(--surface);
  font-size: 22px;
}

.keypad {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
  max-width: 420px;
}
.key {
  min-height: var(--tap);
  border-radius: 14px;
  background: var(--surface);
  border: 2px solid var(--line);
  font-size: 26px;
  font-weight: 800;
}
.key:active { background: var(--action-soft); }
.key.wide { grid-column: span 2; }

.confirm {
  min-height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  gap: 12px;
}
.order-number {
  font-size: 96px;
  line-height: 1;
  font-weight: 800;
  color: var(--action);
  letter-spacing: -0.03em;
}
.confirm h2 { margin: 0; font-size: 36px; }

.overlay {
  position: fixed;
  inset: 0;
  background: rgba(28, 25, 23, 0.55);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  z-index: 40;
}
.overlay[hidden] { display: none !important; }
.modal {
  background: var(--surface);
  width: min(720px, 100%);
  border-radius: 20px;
  padding: 24px;
  box-shadow: 0 16px 40px rgba(0,0,0,0.2);
}
.modal h2 { margin: 0 0 8px; font-size: 30px; }
.modal p { margin: 0 0 18px; color: var(--ink-muted); }
.preview-chip {
  height: 220px;
  border-radius: 16px;
  border: 1px solid rgba(0,0,0,0.15);
  margin-bottom: 16px;
}
.modal-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }

.toast {
  position: fixed;
  left: 50%;
  bottom: 28px;
  transform: translateX(-50%);
  background: #1c1917;
  color: #fff;
  padding: 14px 20px;
  border-radius: 14px;
  z-index: 50;
  max-width: 80vw;
  text-align: center;
  font-weight: 700;
}
.toast[hidden] { display: none !important; }

.status-banner {
  background: #fff4d6;
  color: var(--warn);
  border-radius: 12px;
  padding: 12px 14px;
  font-weight: 700;
  margin-bottom: 12px;
}

.empty {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 36px 20px;
  text-align: center;
  color: var(--ink-muted);
}

/* Counter */
.counter-page { overflow: auto; }
.counter-head {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: center;
  flex-wrap: wrap;
}
.toggle {
  min-height: var(--tap);
  padding: 0 18px;
  border-radius: 999px;
  background: #eceae6;
  font-weight: 800;
}
.toggle.on { background: #dcf5ea; color: var(--best); }

.order-card {
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 16px 18px;
  margin-top: 14px;
  border-left: 8px solid var(--action);
}
.order-card.printed { border-left-color: #9ca3af; opacity: 0.88; }
.order-card.done { border-left-color: var(--best); }
.order-card h3 { margin: 0; font-size: 28px; }
.order-meta { color: var(--ink-muted); margin: 4px 0 12px; font-size: 18px; }
.ticket-lines { margin: 0 0 12px; padding-left: 20px; }
.ticket-lines li { margin: 6px 0; }

/* 80mm receipt */
.receipt {
  display: none;
  width: 80mm;
  color: #000;
  background: #fff;
  font-family: "Courier New", ui-monospace, monospace;
  font-size: 13px;
  line-height: 1.35;
}
.receipt.show-preview {
  display: block;
  margin: 16px auto;
  padding: 8px;
  border: 1px dashed #999;
}
.receipt pre {
  margin: 0;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  word-break: break-word;
}

@media print {
  @page { size: 80mm auto; margin: 4mm; }
  body * { visibility: hidden; }
  .receipt, .receipt * { visibility: visible; }
  .receipt {
    display: block !important;
    position: absolute;
    left: 0;
    top: 0;
    width: 72mm;
    box-shadow: none;
    border: 0;
  }
}



.view.view-colors {
  display: flex;
  flex-direction: column;
  min-height: 0;
  overflow: hidden;
}
.view.view-colors > .approx-note,
.view.view-colors > .status-banner,
.view.view-colors > .family-tabs,
.view.view-colors > .search-row,
.view.view-colors > .keypad,
.view.view-colors > .swatch-count {
  flex: 0 0 auto;
}
.approx-note {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 0 0 10px;
  color: var(--ink-muted);
  font-size: 15px;
  font-weight: 600;
  line-height: 1.3;
}
.approx-note p { margin: 0; flex: 1; min-width: 0; }
.info-btn {
  flex: 0 0 auto;
  width: 32px;
  height: 32px;
  min-width: 32px;
  min-height: 32px;
  border-radius: 50%;
  background: #fff4d6;
  border: 1px solid #f0d48a;
  color: var(--warn);
  font-family: Georgia, "Times New Roman", serif;
  font-size: 17px;
  font-style: italic;
  font-weight: 700;
  line-height: 1;
}
.info-modal p {
  max-height: min(50dvh, 360px);
  overflow: auto;
  -webkit-overflow-scrolling: touch;
}
.swatch-count {
  margin: 0 0 10px;
  color: var(--ink-muted);
  font-size: 16px;
}
.swatch-viewport {
  flex: 1 1 0%;
  min-height: 0;
  overflow-x: hidden;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
  touch-action: pan-y;
  position: relative;
}
.swatch-spacer { position: relative; width: 100%; }
.swatch-window {
  position: absolute;
  left: 0;
  right: 0;
  display: grid;
  gap: 12px;
}
.swatch {
  height: 140px;
}
.swatch strong, .swatch em {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.wood-preview {
  position: relative;
  isolation: isolate;
  overflow: hidden;
  background-color: #c49a62;
  background-image: url("./img/wood-grain.jpg");
  background-size: cover;
  background-position: center;
}
.wood-preview::before,
.wood-preview::after {
  content: "";
  position: absolute;
  inset: 0;
  background: var(--stain, #8b5a2b);
  pointer-events: none;
}
.wood-preview::before {
  mix-blend-mode: color;
  opacity: 0.7;
}
.wood-preview::after {
  mix-blend-mode: multiply;
  opacity: var(--stain-opacity, 0.48);
}
.preview-chip.wood-preview {
  height: 280px;
}
.product-card h3 { overflow-wrap: anywhere; }

@media (max-width: 900px) {
  .topbar { gap: 8px; }
  .sample-badge { display: none; }
  .btn-back {
    flex: 0 0 auto;
    min-width: 56px;
    width: auto;
    padding: 0 12px;
    font-size: 16px;
  }
  .cart-pill { min-width: 72px; padding: 0 10px; font-size: 16px; gap: 6px; }
  .title { font-size: 17px; }
  .subtitle { font-size: 12px; }
  .view { padding: 12px 14px 16px; }
  .approx-note { font-size: 13px; margin-bottom: 8px; }
  .search-row { margin-bottom: 10px; }
  .swatch-count { font-size: 14px; margin-bottom: 8px; }
  .hero { flex-direction: column; align-items: flex-start; }
  .hero h2 { font-size: 28px; }
  .tile-grid { min-height: 0; grid-template-rows: none; }
  .home-grid {
    grid-template-columns: 1fr 1fr;
    grid-template-rows: none;
    min-height: 0;
  }
  .home-grid .tile,
  .home-grid .tile:nth-child(4) { grid-column: auto; }
  .home-grid .tile:nth-child(5) { grid-column: 1 / -1; }
  .size-row { grid-template-columns: 1fr; }
  .order-number { font-size: 72px; }
  .modal-actions, .bottom-actions { grid-template-columns: 1fr; }
}

@media (max-height: 800px) and (orientation: landscape) {
  .tile-grid { min-height: 0; }
  .home-grid { min-height: min(52vh, 400px); grid-template-rows: repeat(2, minmax(140px, 1fr)); }
  .hero { padding: 14px 18px; margin-bottom: 12px; }
  .hero h2 { font-size: 28px; }
}
