:root {
  --bg: #f7f1e7;
  --card: #fff;
  --brand-cream: #fff8eb;
  --brand-sage: #7e7860;
  --text: #2e231c;
  --muted: #7a6f66;
  --border: #e6dccd;
  --primary: #6b4a3a;
  --primary-dark: #4e3428;
  --primary-soft: #fbf3e6;
  --ok: #2e7d5b;
  --danger: #c0392b;
  --warn-bg: #fff4d6;
  --warn: #9a6b00;
  --bad-bg: #fde2df;
  --radius: 10px;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: "Segoe UI", system-ui, -apple-system, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 15px;
}

h1, h2 { margin: 0 0 12px; }
h2 { font-size: 18px; }

.hidden { display: none !important; }
.muted { color: var(--muted); }
.center { text-align: center; }
.small { font-size: 13px; }
.num { text-align: right; }

label { display: block; margin-bottom: 12px; font-weight: 500; }
label.inline { display: inline-flex; align-items: center; gap: 6px; margin: 0; font-weight: 400; }

input, select {
  width: 100%;
  margin-top: 4px;
  padding: 9px 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font: inherit;
  background: #fff;
}
input[type="checkbox"] { width: auto; margin: 0; }
input:focus, select:focus { outline: 2px solid var(--primary); outline-offset: -1px; }

.btn {
  padding: 9px 16px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #fff;
  font: inherit;
  cursor: pointer;
}
.btn:hover { background: #f0f2f4; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn.primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn.primary:hover { background: var(--primary-dark); }
.btn.danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn.small { padding: 5px 10px; font-size: 13px; }
.btn.block { width: 100%; }
.btn-row { display: flex; gap: 10px; }

.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px;
}

/* Login */
.login-wrap { min-height: 100vh; display: flex; align-items: center; justify-content: center; }
.login-card { width: 360px; background: var(--brand-cream); }
.login-logo { display: block; width: 240px; height: 240px; margin: -6px auto 4px; }

/* Top bar */
.topbar {
  display: flex;
  align-items: center;
  gap: 24px;
  padding: 6px 20px;
  background: var(--brand-cream);
  border-bottom: 1px solid var(--border);
}
.brand { display: flex; align-items: center; gap: 10px; }
.brand-logo { width: 46px; height: 46px; }
.brand-name {
  font-family: Georgia, "Times New Roman", serif;
  font-weight: 700;
  font-size: 20px;
  color: var(--primary-dark);
  line-height: 1.1;
}
.brand-sub { font-size: 11px; letter-spacing: 2px; text-transform: uppercase; color: var(--brand-sage); }
.tabs { display: flex; gap: 4px; flex: 1; }
.tab {
  padding: 8px 16px;
  border: none;
  border-radius: 8px;
  background: none;
  font: inherit;
  cursor: pointer;
  color: var(--muted);
}
.tab:hover { background: #f1e7d8; }
.tab.active { background: var(--primary); color: #fff; }
.user-box { display: flex; align-items: center; gap: 10px; }

.badge {
  padding: 3px 10px;
  border-radius: 20px;
  font-size: 12px;
  font-weight: 600;
  background: #eee;
}
.badge.open { background: #d4f3e8; color: var(--ok); }
.badge.closed { background: var(--bad-bg); color: var(--danger); }
.badge.warn { background: var(--warn-bg); color: var(--warn); }

main { padding: 20px; }

.notice { padding: 12px 16px; border-radius: 8px; margin-bottom: 16px; }
.notice.warn { background: var(--warn-bg); color: var(--warn); }

.panel-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 12px; }
.panel-head h2 { margin: 0; }
.panel-actions { display: flex; align-items: center; gap: 16px; }

.two-col { display: grid; grid-template-columns: 380px 1fr; gap: 20px; align-items: start; }

/* Sell */
.sell-layout { display: grid; grid-template-columns: 1fr 380px; gap: 20px; align-items: start; }
.search { margin: 0 0 14px; }
.filter-row { display: grid; grid-template-columns: 1fr 190px; gap: 8px; margin-bottom: 14px; }
.filter-row .search, .filter-row select { margin: 0; }
.panel-actions .search, .panel-actions select { margin: 0; width: auto; }
.product-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  gap: 12px;
}
.product-tile {
  text-align: left;
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #fff;
  font: inherit;
  cursor: pointer;
}
.product-tile:hover:not(:disabled) { border-color: var(--primary); background: var(--primary-soft); }
.product-tile:disabled { opacity: .45; cursor: not-allowed; }
.product-tile .name { font-weight: 600; }
.product-tile .sku { font-size: 12px; color: var(--muted); }
.product-tile .price { margin-top: 8px; font-size: 17px; font-weight: 700; color: var(--primary-dark); }
.product-tile .stock { font-size: 12px; color: var(--muted); }
.product-tile .tier-hint { font-size: 12px; font-weight: 600; color: var(--primary-dark); }

.customer-box { position: relative; margin-bottom: 12px; }
.customer-search-row { display: flex; gap: 8px; }
.customer-search-row input { margin: 0; }
.customer-search-row .btn { white-space: nowrap; }
.customer-results {
  position: absolute;
  left: 0;
  right: 0;
  top: 44px;
  z-index: 5;
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: 0 6px 18px rgba(0, 0, 0, .08);
  max-height: 240px;
  overflow-y: auto;
}
.customer-result {
  display: block;
  width: 100%;
  text-align: left;
  padding: 9px 12px;
  border: none;
  border-bottom: 1px solid var(--border);
  background: none;
  font: inherit;
  cursor: pointer;
}
.customer-result:last-child { border-bottom: none; }
.customer-result:hover { background: var(--primary-soft); }
.customer-result .meta, .customer-selected .meta { font-size: 12px; color: var(--muted); }
.customer-results .empty { padding: 9px 12px; }
.customer-selected {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border: 1px solid var(--primary);
  border-radius: 8px;
  background: var(--primary-soft);
}
.bold { font-weight: 600; }
.inline-search { width: 220px; margin: 0; }
.points-pos { color: var(--ok); }
.points-neg { color: var(--danger); }
.modal-box.wide { width: 640px; }
.detail-section { margin-top: 18px; }
.detail-section h3 { font-size: 15px; margin: 0 0 8px; }

.cart-items { min-height: 80px; max-height: 320px; overflow-y: auto; margin-bottom: 12px; }
.cart-line {
  display: grid;
  grid-template-columns: 1fr auto auto;
  gap: 8px;
  align-items: center;
  padding: 8px 0;
  border-bottom: 1px solid var(--border);
}
.cart-line .meta { font-size: 12px; color: var(--muted); }
.cart-line .tier-on, .cart-line .tier-next { color: var(--primary-dark); }

.tier-editor { border: 1px solid var(--border); border-radius: var(--radius); padding: 6px 12px 12px; margin: 0 0 12px; }
.tier-editor legend { font-weight: 500; padding: 0 4px; }
.tier-row { display: grid; grid-template-columns: 1fr 1fr auto; gap: 8px; align-items: end; }
.tier-row label, .tier-row button { margin-bottom: 8px; }
.bundle-products { max-height: 260px; overflow-y: auto; border: 1px solid var(--border); border-radius: var(--radius); padding: 6px 8px; margin-top: 6px; }
.bundle-product { display: flex; gap: 6px; align-items: baseline; padding: 3px 0; }
.settings-form { display: flex; gap: 10px; align-items: flex-end; max-width: 520px; }
.settings-form label { flex: 1; margin-bottom: 0; }
.settings-form input { margin-bottom: 0; }
.qty { display: flex; align-items: center; gap: 4px; }
.qty button { width: 28px; height: 28px; padding: 0; }
.qty input { width: 54px; margin: 0; padding: 4px; text-align: center; }
.line-total { min-width: 70px; text-align: right; font-weight: 600; }

.totals .row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  padding: 5px 0;
}
.totals .row label { margin: 0; font-weight: 400; }
.totals .row input, .totals .row select { width: 150px; margin: 0; text-align: right; }
.totals .row.total { font-size: 20px; font-weight: 700; border-top: 1px solid var(--border); padding-top: 10px; }
.pay-methods { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; margin: 8px 0 4px; }
.split-box { border: 1px dashed var(--border); border-radius: 8px; padding: 8px; margin: 6px 0; background: var(--primary-soft); }
.split-line { display: grid; grid-template-columns: 1fr 110px; gap: 6px; margin-bottom: 6px; align-items: center; }
.split-line select, .split-line input { margin: 0; }
.split-line input[type=number] { text-align: right; }
.split-line .split-ref { grid-column: 1 / -1; }
.split-rest { text-align: right; font-weight: 600; padding-right: 10px; }
.split-label { margin: 0; font-weight: 600; }
.auto-print { display: flex; margin: 10px 0 0; font-size: 13px; color: var(--muted); }
.split-error { color: var(--danger); font-size: 13px; margin-top: 4px; }
.assign-list { max-height: 320px; overflow-y: auto; display: grid; gap: 6px; margin-bottom: 8px; }
.assign-item {
  display: flex; justify-content: space-between; align-items: center; gap: 10px;
  width: 100%; padding: 8px 10px; text-align: left; cursor: pointer;
  border: 1px solid var(--border); border-radius: 8px; background: #fff; font: inherit;
}
.assign-item:hover { border-color: var(--primary); background: var(--primary-soft); }
.muted-code { display: block; font-size: 12px; color: var(--muted); }
.pay-method {
  padding: 9px 4px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #fff;
  font: inherit;
  font-size: 14px;
  cursor: pointer;
}
.pay-method:hover { background: var(--primary-soft); }
.pay-method.active { background: var(--primary); border-color: var(--primary); color: #fff; font-weight: 600; }
.pay-breakdown { margin-top: 4px; }

.cart-actions { display: grid; grid-template-columns: 1fr 2fr; gap: 10px; margin-top: 14px; }
.cart-actions .btn { padding: 12px; font-size: 16px; }

/* Tables */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { padding: 9px 10px; border-bottom: 1px solid var(--border); text-align: left; }
th { font-size: 13px; color: var(--muted); font-weight: 600; }
tr.inactive td { color: var(--muted); }
#count-detail-view .panel-actions, #valuation-view .panel-actions { flex-wrap: wrap; justify-content: flex-end; gap: 8px; }
#count-detail-view .panel-actions .btn, #valuation-view .panel-actions .btn { white-space: nowrap; }
.count-toolbar { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 16px; margin-bottom: 14px; }
.count-toolbar .search { flex: 1; min-width: 240px; margin: 0; }
.count-toolbar select { width: auto; margin: 0; }
.count-input { width: 110px; margin: 0; text-align: right; }
tr.counted td:first-child { box-shadow: inset 3px 0 0 var(--ok); }
tr.flash td { animation: row-flash 1.2s ease-out; }
@keyframes row-flash { from { background: var(--warn-bg); } to { background: transparent; } }
td.neg { color: var(--danger); }
td.pos { color: var(--ok); }
.post-diffs { max-height: 260px; overflow-y: auto; margin-bottom: 12px; }
.print-only { display: none; }
.count-sheet { width: 100%; border-collapse: collapse; font-size: 12px; }
.count-sheet th, .count-sheet td { border-bottom: 1px solid #bbb; padding: 5px 6px; text-align: left; }
.count-sheet td.box { width: 90px; border: 1px solid #000; }
.count-sheet .num { text-align: right; }
.sign-line { margin-top: 28px; }
.pin-reveal { font-size: 2rem; font-weight: 700; letter-spacing: 0.3em; text-align: center; margin: 16px 0; }

/* Shift info */
.kv { display: grid; grid-template-columns: 150px 1fr; gap: 6px 10px; margin-bottom: 16px; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; font-weight: 500; }
.variance-neg { color: var(--danger); }
.variance-pos { color: var(--ok); }

/* Sales history / report */
.filter-bar { display: flex; flex-wrap: wrap; align-items: flex-end; gap: 12px; margin-bottom: 14px; }
.filter-bar label { display: flex; flex-direction: column; margin: 0; font-size: 13px; color: var(--muted); }
.filter-bar input, .filter-bar select { width: auto; color: var(--text); }
.filter-bar .grow { flex: 1; min-width: 240px; }
.filter-bar .grow input { width: 100%; }
.quick-ranges { display: flex; gap: 6px; padding-bottom: 4px; }
.report-cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 12px; margin-bottom: 18px; }
.report-card { border: 1px solid var(--border); border-radius: 8px; padding: 12px 14px; background: var(--primary-soft); }
.report-card .label { font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: .5px; }
.report-card .value { font-size: 22px; font-weight: 700; color: var(--primary-dark); margin-top: 4px; }
.report-card .sub { font-size: 12px; color: var(--muted); }
.report-section { margin-top: 18px; }
.report-section h3 { font-size: 15px; margin: 0 0 8px; }
tr.total-row td { font-weight: 700; border-top: 2px solid var(--border); }
.report-print-header { display: none; }
.reprint-mark { text-align: center; font-weight: 700; letter-spacing: 2px; border: 1px dashed #999; padding: 2px; margin: 6px 0; }
.void-mark { text-align: center; font-weight: 800; font-size: 18px; letter-spacing: 4px; color: var(--danger); border: 2px solid var(--danger); padding: 4px; margin: 6px 0; }
.void-badge { display: inline-block; font-size: 11px; font-weight: 700; color: #fff; background: var(--danger); border-radius: 4px; padding: 1px 6px; vertical-align: middle; }
.voided-row td { color: var(--muted); }
.voided { text-decoration: line-through; color: var(--muted); }

/* Modal */
.modal {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, .4);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 10;
}
.modal-box {
  background: #fff;
  border-radius: var(--radius);
  padding: 22px;
  width: 420px;
  max-height: 90vh;
  overflow-y: auto;
}
.modal-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 16px; }

/* Receipt */
.receipt { font-family: Consolas, "Courier New", monospace; font-size: 14px; }
.receipt .center { text-align: center; }
.receipt .small { font-size: 12px; }
.receipt-logo { display: block; width: 72px; height: 72px; margin: 0 auto 6px; }
.receipt hr { border: none; border-top: 1px dashed #999; margin: 8px 0; }
.receipt .line { display: flex; justify-content: space-between; gap: 8px; }
.receipt .bold { font-weight: 700; }

/* Toast */
.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  padding: 12px 20px;
  border-radius: 8px;
  background: #1f2933;
  color: #fff;
  z-index: 20;
  max-width: 90vw;
}
.toast.error { background: var(--danger); }

@media (max-width: 900px) {
  .sell-layout, .two-col { grid-template-columns: 1fr; }
  .topbar { flex-wrap: wrap; }
}

@media print {
  body * { visibility: hidden; }
  .receipt, .receipt * { visibility: visible; }
  .receipt { position: absolute; left: 0; top: 0; width: 72mm; }
  /* Thermal printers dither anything not pure black, and thin strokes (Courier New) come out faint. */
  .receipt, .receipt * { color: #000 !important; border-color: #000 !important; }
  .receipt { font-family: Menlo, Consolas, "DejaVu Sans Mono", monospace; font-size: 13px; font-weight: 600; }
  .receipt .small { font-size: 12px; }
  .receipt .bold { font-weight: 800; }
  .receipt hr { border-top: 1px solid #000; }
  .receipt-logo { filter: grayscale(1) contrast(1.5); }
  /* Hidden (visibility) content still takes up pages, so a receipt lays out nothing but itself. */
  body:has(#modal:not(.hidden) .receipt):not(.printing-report) > :not(#modal) { display: none; }
  body:has(#modal:not(.hidden) .receipt):not(.printing-report) .modal { position: static; display: block; background: none; }
  body:has(#modal:not(.hidden) .receipt):not(.printing-report) .modal-box {
    width: auto; max-height: none; overflow: visible; padding: 0; border-radius: 0; box-shadow: none;
  }
  body:has(#modal:not(.hidden) .receipt):not(.printing-report) .modal-actions,
  body:has(#modal:not(.hidden) .receipt):not(.printing-report) #modal-content > p { display: none; }
  body:has(#modal:not(.hidden) .receipt):not(.printing-report) .receipt { position: static; }
  body.printing-report .report-print-area, body.printing-report .report-print-area * { visibility: visible; }
  body.printing-report .report-print-area { position: absolute; left: 0; top: 0; width: 100%; }
  body.printing-report .report-print-header { display: block; margin-bottom: 12px; }
  body.printing-report .report-card { background: none; }
  body.printing-report .print-only { display: block; }
  .count-sheet thead { display: table-header-group; }
  .count-sheet tr { page-break-inside: avoid; }
}
