[hidden] { display: none !important; }
:root {
  --bg: #f7f6f3;
  --surface: #ffffff;
  --surface-2: #f1efea;
  --border: #dedad2;
  --border-strong: #c7c1b6;
  --text: #1c1c1e;
  --muted: #5f5b55;
  --accent: #1f3a5f;
  --accent-hover: #162b47;
  --accent-soft: #e6ecf4;
  --rose: #9b3b5a;
  --ok: #1e6b43;
  --ok-soft: #e3f2e8;
  --warn: #8a5a00;
  --warn-soft: #fff4d6;
  --err: #a32020;
  --err-soft: #fdeaea;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(0,0,0,.05), 0 4px 16px rgba(0,0,0,.05);
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, "SFMono-Regular", Consolas, "Liberation Mono", monospace;
}
* { box-sizing: border-box; }
html { font-size: 16px; }
body { margin: 0; background: var(--bg); color: var(--text); font-family: var(--font); line-height: 1.45; -webkit-font-smoothing: antialiased; }
h1, h2, h3 { line-height: 1.2; margin: 0 0 .5rem; }
h1 { font-size: 1.5rem; }
h2 { font-size: 1.15rem; }
h3 { font-size: 1rem; }
p { margin: 0 0 .75rem; }
a { color: var(--accent); }
code, .code { font-family: var(--mono); font-size: .92em; }
.muted { color: var(--muted); }
.small { font-size: .875rem; }
.nowrap { white-space: nowrap; }
.skip-link { position: absolute; left: -999px; top: 0; background: var(--accent); color: #fff; padding: .5rem 1rem; z-index: 100; }
.skip-link:focus { left: 0; }
:focus-visible { outline: 3px solid #5b8fd6; outline-offset: 2px; }

/* top bar */
.topbar { display: flex; align-items: center; gap: 1.5rem; padding: .6rem 1.25rem; background: var(--surface); border-bottom: 1px solid var(--border); position: sticky; top: 0; z-index: 20; flex-wrap: wrap; }
.brand { display: flex; align-items: center; gap: .6rem; }
.brand small { display: block; color: var(--muted); font-size: .8rem; }
.brand-mark { width: 32px; height: 32px; border-radius: 8px; background: var(--accent); color: #fff; display: grid; place-items: center; font-weight: 700; }
.mainnav { display: flex; gap: .25rem; flex: 1; flex-wrap: wrap; }
.mainnav a { padding: .5rem .8rem; border-radius: 8px; text-decoration: none; color: var(--text); font-weight: 500; }
.mainnav a:hover { background: var(--surface-2); }
.mainnav a.active { background: var(--accent-soft); color: var(--accent); }
.usermenu { display: flex; gap: .75rem; align-items: center; color: var(--muted); font-size: .9rem; }
main { padding: 1.25rem; max-width: 1480px; margin: 0 auto; outline: none; }

/* buttons & forms */
button, .btn { font: inherit; cursor: pointer; border-radius: 8px; border: 1px solid var(--border-strong); background: var(--surface); color: var(--text); padding: .55rem 1rem; font-weight: 500; display: inline-flex; align-items: center; gap: .4rem; text-decoration: none; min-height: 40px; }
button:hover, .btn:hover { background: var(--surface-2); }
button:disabled { opacity: .5; cursor: not-allowed; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-hover); }
.btn-danger { color: var(--err); border-color: #e2b5b5; }
.btn-danger:hover { background: var(--err-soft); }
.btn-small { padding: .3rem .65rem; min-height: 32px; font-size: .875rem; }
.btn-link { background: none; border: none; color: var(--accent); padding: .25rem; min-height: 0; text-decoration: underline; }
.btn-link:hover { background: none; }
.btn-icon { padding: .3rem .5rem; min-height: 32px; border-color: transparent; background: transparent; }
.btn-row { display: flex; gap: .5rem; flex-wrap: wrap; align-items: center; }
label { font-weight: 500; font-size: .9rem; display: block; margin-bottom: .25rem; }
input[type=text], input[type=password], input[type=date], input[type=search], input[type=tel], input:not([type]), select, textarea {
  font: inherit; width: 100%; padding: .55rem .7rem; border: 1px solid var(--border-strong); border-radius: 8px; background: #fff; color: var(--text); min-height: 40px; }
textarea { min-height: 70px; resize: vertical; }
input[aria-invalid=true] { border-color: var(--err); background: var(--err-soft); }
.field { margin-bottom: .85rem; }
.field-hint { font-size: .8rem; color: var(--muted); margin-top: .2rem; }
.field-error { font-size: .85rem; color: var(--err); margin-top: .2rem; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 1rem; }
.grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 0 1rem; }

/* cards & layout */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); padding: 1.1rem 1.25rem; }
.card + .card { margin-top: 1rem; }
.page-head { display: flex; justify-content: space-between; align-items: flex-end; gap: 1rem; margin-bottom: 1rem; flex-wrap: wrap; }
.page-head p { margin: 0; }
.badge { display: inline-block; padding: .1rem .55rem; border-radius: 999px; font-size: .8rem; font-weight: 600; background: var(--surface-2); color: var(--muted); white-space: nowrap; }
.badge-draft { background: var(--accent-soft); color: var(--accent); }
.badge-exported { background: var(--warn-soft); color: var(--warn); }
.badge-sent { background: var(--ok-soft); color: var(--ok); }
.badge-err { background: var(--err-soft); color: var(--err); }
.badge-new { background: var(--ok-soft); color: var(--ok); }
.badge-update { background: var(--accent-soft); color: var(--accent); }
.badge-demo { background: #f3e6ee; color: var(--rose); }
.notice { border-radius: var(--radius); padding: .75rem 1rem; margin-bottom: 1rem; border: 1px solid; }
.notice-warn { background: var(--warn-soft); border-color: #ecd28a; color: #5c3d00; }
.notice-err { background: var(--err-soft); border-color: #e8b4b4; color: #6f1414; }
.notice-ok { background: var(--ok-soft); border-color: #b3dbc1; color: #134a2d; }
.notice-info { background: var(--accent-soft); border-color: #c4d2e6; color: #183150; }
.empty { text-align: center; color: var(--muted); padding: 2rem 1rem; }

/* tables */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: .95rem; }
th, td { text-align: left; padding: .5rem .6rem; border-bottom: 1px solid var(--border); vertical-align: middle; }
th { font-size: .8rem; text-transform: uppercase; letter-spacing: .03em; color: var(--muted); font-weight: 600; background: var(--surface); position: sticky; top: 0; }
tr.clickable { cursor: pointer; }
tr.clickable:hover td { background: #faf8f4; }
td.num, th.num { text-align: right; }
tr.flagged td { background: var(--warn-soft); }
tr.inactive td { color: var(--muted); }
tr.flash td { animation: flash 1.6s ease-out; }
@keyframes flash { from { background: #d7f0df; } to { background: transparent; } }

/* order builder */
.builder { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 1.25rem; align-items: start; }
.builder > .card { min-width: 0; }
.order-panel { position: sticky; top: 76px; max-height: calc(100vh - 92px); display: flex; flex-direction: column; }
.order-panel .lines { overflow: auto; flex: 1; min-height: 120px; }
.save-state { font-size: .85rem; color: var(--muted); display: inline-flex; gap: .35rem; align-items: center; }
.save-state.ok::before { content: ''; width: 8px; height: 8px; border-radius: 50%; background: var(--ok); }
.save-state.saving::before { content: ''; width: 8px; height: 8px; border-radius: 50%; background: #c99a2e; }
.save-state.error { color: var(--err); font-weight: 600; }
.save-banner { position: sticky; top: 56px; z-index: 19; background: var(--err); color: #fff; padding: .6rem 1.25rem; display: flex; gap: 1rem; align-items: center; justify-content: center; flex-wrap: wrap; }
.save-banner button { background: #fff; color: var(--err); border-color: #fff; min-height: 32px; padding: .25rem .8rem; }
.search-box { position: relative; }
.search-box input { padding-left: 2.2rem; font-size: 1.05rem; min-height: 46px; }
.search-box::before { content: ''; position: absolute; left: .8rem; top: 50%; width: 12px; height: 12px; border: 2px solid var(--muted); border-radius: 50%; transform: translateY(-60%); }
.search-box::after { content: ''; position: absolute; left: 1.55rem; top: 58%; width: 6px; height: 2px; background: var(--muted); transform: rotate(45deg); }
.tabs { display: flex; gap: .25rem; border-bottom: 1px solid var(--border); margin: .75rem 0 .5rem; }
.tabs button { border: none; border-bottom: 3px solid transparent; border-radius: 0; background: none; padding: .5rem .8rem; color: var(--muted); }
.tabs button[aria-selected=true] { color: var(--accent); border-bottom-color: var(--accent); }
.results { list-style: none; margin: 0; padding: 0; max-height: 340px; overflow: auto; border: 1px solid var(--border); border-radius: 8px; }
.results li { padding: .55rem .75rem; border-bottom: 1px solid var(--border); cursor: pointer; display: flex; justify-content: space-between; gap: .75rem; }
.results li:last-child { border-bottom: none; }
.results li:hover, .results li[aria-selected=true] { background: var(--accent-soft); }
.results .r-name { font-weight: 600; }
.results .r-meta { font-size: .82rem; color: var(--muted); }
.results .r-sizes { font-size: .82rem; color: var(--muted); text-align: right; }
mark { background: #fbe7a1; color: inherit; border-radius: 2px; padding: 0 1px; }
.picker { margin-top: 1rem; border-top: 1px solid var(--border); padding-top: 1rem; }
.picker-head { display: flex; justify-content: space-between; align-items: baseline; gap: .5rem; flex-wrap: wrap; }
.chips { display: flex; flex-wrap: wrap; gap: .4rem; margin: .5rem 0 .75rem; }
.chip { border-radius: 999px; padding: .35rem .85rem; min-height: 36px; border: 1px solid var(--border-strong); background: #fff; }
.chip[aria-pressed=true] { background: var(--accent); border-color: var(--accent); color: #fff; }
.chip .chip-code { font-family: var(--mono); font-size: .8em; opacity: .8; margin-left: .3rem; }
.shade-grid { max-height: 52vh; overflow: auto; border: 1px solid var(--border); border-radius: 8px; }
.shade-grid table td { padding: .3rem .6rem; }
.shade-grid input.qty { width: 5.5rem; text-align: right; min-height: 36px; padding: .3rem .5rem; font-variant-numeric: tabular-nums; }
.shade-grid tr.matched td { background: #fffbe8; }
.shade-grid tr.has-qty td { background: #eef6f0; }
.swatch { display: inline-block; width: 14px; height: 14px; border-radius: 3px; border: 1px solid rgba(0,0,0,.2); vertical-align: -2px; margin-right: .35rem; }
.star { font-size: 1.15rem; line-height: 1; color: #b9b2a6; }
.star[aria-pressed=true] { color: #c48a0a; }
.custom-shade { margin-top: .9rem; padding: .75rem .9rem; border: 1px dashed var(--border-strong); border-radius: 8px; background: #fbfaf7; }
.custom-shade-row { display: flex; gap: .5rem; flex-wrap: wrap; align-items: center; }
.custom-shade-row input#custom-shade { flex: 1 1 14rem; width: auto; }
.custom-shade-row input.qty { width: 5.5rem; text-align: right; }
.custom-shade-row select { width: auto; }
/* customer orders */
input.qty { width: 5.5rem; text-align: right; font-variant-numeric: tabular-nums; }
.co-table a, #co-detail-lines a { white-space: nowrap; }
.filter-chips { display: flex; flex-wrap: wrap; gap: .4rem; margin: .75rem 0; }
.filter-chip { border-radius: 999px; min-height: 36px; padding: .3rem .8rem; font-size: .9rem; }
.filter-chip .count { margin-left: .4rem; font-size: .8rem; background: var(--surface-2); border-radius: 999px; padding: 0 .45rem; color: var(--muted); }
.filter-chip[aria-selected=true] { background: var(--accent); border-color: var(--accent); color: #fff; }
.filter-chip[aria-selected=true] .count { background: rgba(255,255,255,.25); color: #fff; }
.filter-chip.hot:not([aria-selected=true]) { border-color: var(--rose); color: var(--rose); font-weight: 600; }
.filter-chip.hot .count { background: #f6dde6; color: var(--rose); }
.co-table td { vertical-align: top; }
.co-table .products-cell { max-width: 280px; }
.picked-customer { display: flex; justify-content: space-between; align-items: center; gap: .75rem; padding: .7rem .9rem; border: 1px solid var(--border); border-radius: 8px; background: var(--accent-soft); margin-bottom: .85rem; }
.results.compact { max-height: 220px; margin: .35rem 0 .85rem; }
details.optional { margin-top: .5rem; border-top: 1px solid var(--border); padding-top: .5rem; }
details.optional > summary, details > summary { cursor: pointer; font-weight: 600; color: var(--accent); padding: .25rem 0; }
.inline-fieldset { border: 1px solid var(--border); border-radius: 8px; padding: .5rem .9rem 0; margin: 0; }
.inline-fieldset legend { font-size: .9rem; font-weight: 500; padding: 0 .3rem; }
.status-row { display: flex; flex-wrap: wrap; gap: .4rem; align-items: center; margin-top: .35rem; }
.notify-box { border: 1px solid var(--border); border-radius: 8px; padding: .8rem .9rem; margin-bottom: 1rem; background: #fbfaf7; }
.notify-box.needs { border-color: #e2a3b7; background: #fcf1f5; }
.notify-box textarea { margin: .25rem 0 .5rem; font-size: .9rem; }
.inline-form { display: flex; gap: .5rem; align-items: center; flex-wrap: wrap; margin-top: .5rem; }
.inline-form input, .inline-form select { width: auto; flex: 1 1 9rem; }
.collect-box h3 { margin-top: .25rem; }
label.check { display: flex; align-items: center; gap: .4rem; margin-top: .5rem; font-weight: 600; }
ul.history { list-style: none; padding: 0; margin: .5rem 0 0; }
ul.history li { padding: .4rem 0; border-bottom: 1px solid var(--border); font-size: .9rem; }
dl.details-list { display: grid; grid-template-columns: max-content 1fr; gap: .2rem 1rem; margin: 0 0 1rem; }
dl.details-list dt { font-weight: 600; } dl.details-list dd { margin: 0; }
.card-inset { margin-top: 1rem; padding: .9rem; border: 1px dashed var(--border-strong); border-radius: 8px; background: #fbfaf7; }
.cust-badge { cursor: pointer; border: none; }
tr.recv-line td { border-top: 2px solid var(--border-strong); }
tr.recv-customer td { background: #fbfaf7; font-size: .92rem; }
.add-bar { display: flex; justify-content: space-between; align-items: center; gap: .75rem; padding-top: .75rem; flex-wrap: wrap; }
.kbd-help { font-size: .8rem; color: var(--muted); }
kbd { font-family: var(--mono); font-size: .78rem; border: 1px solid var(--border-strong); border-bottom-width: 2px; border-radius: 4px; padding: 0 .3rem; background: #fff; }
.lines table input.qty { width: 5rem; text-align: right; min-height: 34px; padding: .25rem .45rem; }
.totals { display: flex; gap: 1.25rem; padding: .75rem 0; border-top: 1px solid var(--border); font-weight: 600; flex-wrap: wrap; }
.order-details summary { cursor: pointer; font-weight: 600; padding: .25rem 0; }
.order-actions { display: flex; flex-wrap: wrap; gap: .5rem; padding-top: .75rem; border-top: 1px solid var(--border); }
.review-note { font-size: .82rem; color: var(--warn); margin-top: .15rem; }

/* toasts & modal */
.toasts { position: fixed; bottom: 1.25rem; right: 1.25rem; display: flex; flex-direction: column; gap: .5rem; z-index: 50; max-width: min(420px, calc(100vw - 2.5rem)); }
.toast { background: #1d2a3a; color: #fff; padding: .75rem 1rem; border-radius: 10px; box-shadow: 0 6px 24px rgba(0,0,0,.18); display: flex; gap: .75rem; align-items: center; justify-content: space-between; animation: slidein .2s ease-out; }
.toast.ok { background: #17533a; }
.toast.err { background: #8a1c1c; }
.toast button { background: transparent; color: #fff; border-color: rgba(255,255,255,.5); min-height: 30px; padding: .2rem .6rem; }
@keyframes slidein { from { transform: translateY(8px); opacity: 0; } to { transform: none; opacity: 1; } }
.modal { border: none; border-radius: 12px; padding: 0; width: min(560px, calc(100vw - 2rem)); box-shadow: 0 20px 60px rgba(0,0,0,.25); }
.modal::backdrop { background: rgba(20, 24, 32, .45); }
.modal form, .modal .modal-body { padding: 1.25rem 1.4rem; }
.modal .modal-actions { display: flex; justify-content: flex-end; gap: .5rem; margin-top: 1rem; }

/* auth */
.auth { max-width: 420px; margin: 8vh auto; }
.auth .brand { margin-bottom: 1.25rem; }

/* import */
.steps { display: flex; gap: .5rem; margin-bottom: 1rem; flex-wrap: wrap; list-style: none; padding: 0; }
.steps li { padding: .35rem .8rem; border-radius: 999px; background: var(--surface-2); color: var(--muted); font-size: .875rem; }
.steps li.current { background: var(--accent); color: #fff; }
.steps li.done { background: var(--ok-soft); color: var(--ok); }
.dropzone { border: 2px dashed var(--border-strong); border-radius: var(--radius); padding: 2rem; text-align: center; background: #fff; }
.dropzone.over { border-color: var(--accent); background: var(--accent-soft); }
.mapping-table td:first-child { width: 30%; }
.summary-chips { display: flex; gap: .5rem; flex-wrap: wrap; margin: .5rem 0 1rem; }
.summary-chips .badge { font-size: .9rem; padding: .3rem .8rem; }

/* print view */
.print-doc { background: #fff; max-width: 900px; margin: 0 auto; padding: 2rem; border: 1px solid var(--border); }
.print-doc table { font-size: 10.5pt; }
.print-doc th { position: static; color: #000; border-bottom: 2px solid #000; }
.print-doc dl { display: grid; grid-template-columns: max-content 1fr; gap: .2rem 1rem; margin: 0 0 1.25rem; }
.print-doc dt { font-weight: 600; }
.print-doc dd { margin: 0; white-space: pre-wrap; }
@media print {
  .topbar, .no-print, .toasts, .save-banner, .skip-link { display: none !important; }
  body, main { background: #fff; padding: 0; margin: 0; max-width: none; }
  .print-doc { border: none; padding: 0; max-width: none; }
  tr { break-inside: avoid; }
}

/* responsive */
@media (max-width: 1100px) {
  .builder { grid-template-columns: 1fr; }
  .order-panel { position: static; max-height: none; }
}
@media (max-width: 640px) {
  main { padding: .75rem; }
  .grid-2, .grid-3 { grid-template-columns: 1fr; }
  .topbar { gap: .5rem; padding: .5rem .75rem; }
  .usermenu #user-name { display: none; }
  .usermenu { margin-left: auto; }
  .mainnav { order: 3; width: 100%; flex: none; flex-wrap: nowrap; overflow-x: auto; }
  .mainnav a { white-space: nowrap; padding: .45rem .6rem; }
  th, td { padding: .4rem .35rem; }
  .lines table { font-size: .875rem; }
  .lines table input.qty { width: 3.6rem; }
  .shade-grid input.qty { width: 4rem; }
  .card { padding: .9rem; }
  .hide-sm { display: none; }
}
.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; }

/* Online mode: setup restore option, storage warning */
.restore-option { margin-top: 1.25rem; border-top: 1px solid var(--border); padding-top: 1rem; }
.restore-option summary { cursor: pointer; font-weight: 600; }
.restore-option form { margin-top: .75rem; }
.storage-warning { margin: .75rem auto; max-width: 1200px; }
