:root {
  --bg: #F5F6F8; --card: #FFFFFF; --ink: #14181F; --muted: #5A6472; --line: #E2E5EA; --soft: #EDF0FE;
  --accent: #3454D1; --accent-ink: #2F4FCF; --wa: #157F4B;
  --good: #146C43; --goodbg: #DDF3E7; --warn: #8A4B00; --warnbg: #FDEBCF; --bad: #A01C2B; --badbg: #FBE3E5;
  --info: #1F4E8C; --infobg: #E1ECFA; --idle: #4B5563; --idlebg: #ECEEF1;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #12151B; --card: #1B2029; --ink: #EEF0F4; --muted: #A3ADBA; --line: #2C333F; --soft: #242C45;
    --accent-ink: #9DB2FF; --good: #7FE0AE; --goodbg: #173527; --warn: #F4C27A; --warnbg: #3A2A12;
    --bad: #F5A3AC; --badbg: #3A1C20; --info: #A9C8F2; --infobg: #1C2C42; --idle: #B4BCC8; --idlebg: #2A303A;
  }
}
:root[data-theme="dark"] {
  --bg: #12151B; --card: #1B2029; --ink: #EEF0F4; --muted: #A3ADBA; --line: #2C333F; --soft: #242C45;
  --accent-ink: #9DB2FF; --good: #7FE0AE; --goodbg: #173527; --warn: #F4C27A; --warnbg: #3A2A12;
  --bad: #F5A3AC; --badbg: #3A1C20; --info: #A9C8F2; --infobg: #1C2C42; --idle: #B4BCC8; --idlebg: #2A303A;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
body { margin: 0; font: 15px/1.45 Inter, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; background: var(--bg); color: var(--ink); }
a { color: var(--accent-ink); }
h1 { font-size: 24px; margin: 0 0 12px; } h2 { font-size: 15px; margin: 18px 0 8px; } h3 { font-size: 14px; margin: 12px 0 6px; }
.small { font-size: 13px; color: var(--muted); } .warn { color: var(--warn); } .r { text-align: right; } .nowrap { white-space: nowrap; }
.ok { color: var(--good); font-weight: 600; font-size: 13px; }
.empty { color: var(--muted); font-style: italic; margin: 8px 0; }
.sub { margin: 0 0 16px; color: var(--muted); }

/* ---------- App shell ---------- */
.logo { display: flex; align-items: center; justify-content: center; flex: none; width: 36px; height: 36px; border-radius: 10px;
  background: var(--accent); color: #fff; font-weight: 700; font-size: 16px; text-decoration: none; }
.logo.large { width: 64px; height: 64px; border-radius: 16px; font-size: 28px; margin: 0 auto 16px; }
.top { position: sticky; top: 0; z-index: 20; display: flex; align-items: center; gap: 10px; height: 60px; padding: 0 16px;
  background: var(--card); border-bottom: 1px solid var(--line); }
.brand { font-weight: 700; font-size: 17px; color: var(--ink); text-decoration: none; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; min-width: 0; }
.spacer { flex: 1; }
.icon { position: relative; display: flex; align-items: center; justify-content: center; flex: none; width: 44px; height: 44px;
  background: none; border: 0; border-radius: 10px; color: var(--ink); cursor: pointer; }
.icon:hover { background: var(--bg); }
.badge { position: absolute; top: 3px; right: 2px; min-width: 18px; height: 18px; padding: 0 5px; border-radius: 9px; background: #C8102E;
  color: #fff; font-size: 11px; font-weight: 700; line-height: 18px; text-align: center; }
.avatar { display: flex; align-items: center; justify-content: center; width: 36px; height: 36px; border-radius: 50%;
  background: var(--soft); color: var(--accent-ink); font-weight: 700; font-size: 13px; }
.burger { display: none; }
.pop { position: fixed; right: 16px; top: 64px; z-index: 30; width: 320px; max-width: calc(100% - 16px); padding: 6px; background: var(--card);
  border: 1px solid var(--line); border-radius: 12px; box-shadow: 0 10px 30px rgba(0, 0, 0, .18); }
.pop h3 { margin: 8px 10px; font-size: 13px; color: var(--muted); font-weight: 600; }
.pop form { margin: 0; }
.popitem { display: block; width: 100%; min-height: 44px; padding: 10px; text-align: left; font: inherit; color: var(--ink); background: none; border: 0;
  border-radius: 8px; text-decoration: none; cursor: pointer; }
.popitem:hover { background: var(--bg); }
.popitem small { display: block; color: var(--muted); font-size: 13px; }
.shell { display: flex; align-items: stretch; min-height: calc(100vh - 60px); }
.side { position: sticky; top: 60px; flex: none; width: 236px; height: calc(100vh - 60px); overflow-y: auto; padding: 12px;
  background: var(--card); border-right: 1px solid var(--line); }
.group { margin: 16px 10px 6px; font-size: 11px; font-weight: 700; letter-spacing: .06em; color: var(--muted); text-transform: uppercase; }
.group:first-child { margin-top: 4px; }
.nav { display: flex; align-items: center; gap: 12px; min-height: 44px; padding: 0 10px; margin-bottom: 2px; border-radius: 9px; color: var(--ink); text-decoration: none; }
.nav:hover { background: var(--bg); }
.nav.on { background: var(--soft); color: var(--accent-ink); font-weight: 600; }
.nav svg { flex: none; }
main { flex: 1; min-width: 0; max-width: 1120px; padding: 24px; }
.public main { max-width: 620px; margin: 0 auto; }

/* ---------- Login ---------- */
.login { display: flex; justify-content: center; padding: 48px 16px; }
.logincard { width: 100%; max-width: 420px; padding: 36px 28px; text-align: center; background: var(--card); border: 1px solid var(--line); border-radius: 18px; }
.logincard h1 { margin: 0 0 6px; font-size: 26px; }
.logincard > p { margin: 0 0 24px; color: var(--muted); }
.logincard label { display: block; margin-bottom: 16px; text-align: left; font-weight: 500; font-size: 15px; color: var(--ink); }
.logincard input { margin-top: 6px; min-height: 46px; font-size: 16px; }
.logincard .btn { width: 100%; min-height: 46px; }
.logincard > p.hint { margin: 16px 0 0; font-size: 13px; }

/* ---------- Cards, panes, messages ---------- */
.card { display: block; padding: 12px 14px; margin: 8px 0; background: var(--card); border: 1px solid var(--line); border-radius: 12px; }
.card.link { color: var(--ink); text-decoration: none; }
.card.link:hover { border-color: var(--accent); }
.card.warn, .flags { background: var(--warnbg); border-color: transparent; color: var(--warn); }
.flags ul, .card.note ul { margin: 6px 0 0; padding-left: 20px; }
.card.note, div.note { background: var(--infobg); border-color: transparent; color: var(--info); }
div.note { border-radius: 10px; padding: 8px 12px; margin-bottom: 8px; }
.row { display: flex; flex-wrap: wrap; gap: 6px 8px; align-items: center; }
.toolbar { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-bottom: 12px; }
.toolbar .search { flex: 1 1 240px; } .toolbar form { margin: 0; }
.chip { display: inline-flex; align-items: center; min-height: 44px; padding: 0 14px; background: var(--card); border: 1px solid var(--line); border-radius: 10px; color: var(--ink); text-decoration: none; }
.chip.on { background: var(--soft); border-color: var(--accent); color: var(--accent-ink); font-weight: 600; }
.count { display: inline-block; min-width: 22px; padding: 0 7px; margin-left: 4px; border-radius: 999px; background: var(--idlebg); color: var(--idle); font-size: 12px; font-weight: 700; text-align: center; vertical-align: middle; }
.pill { display: inline-block; padding: 2px 9px; border-radius: 999px; font-size: 12px; font-weight: 600; white-space: nowrap; vertical-align: middle; background: var(--idlebg); color: var(--idle); }
.pill.review, .pill.packing { background: var(--warnbg); color: var(--warn); }
.pill.error { background: var(--badbg); color: var(--bad); }
.pill.confirmed, .pill.shipped, .pill.quoted, .pill.ordered { background: var(--infobg); color: var(--info); }
.pill.closed, .pill.delivered, .pill.done { background: var(--goodbg); color: var(--good); }
.pill.skipped, .pill.cancelled { background: var(--idlebg); color: var(--idle); }
details.pane { margin: 10px 0; background: var(--card); border: 1px solid var(--line); border-radius: 12px; }
details.pane > summary { display: flex; align-items: center; gap: 10px; min-height: 56px; padding: 10px 14px; cursor: pointer; list-style: none; border-radius: 12px; }
details.pane > summary::-webkit-details-marker { display: none; }
details.pane > summary::before { content: "›"; flex: none; width: 16px; font-size: 22px; line-height: 1; text-align: center; color: var(--muted); transition: transform .15s; }
details.pane[open] > summary::before { transform: rotate(90deg); }
details.pane > summary h2 { flex: 1; min-width: 0; margin: 0; font-size: 15px; font-weight: 600; color: var(--ink); }
details.pane > summary:hover { background: var(--bg); }
details.pane[open] > summary { border-bottom: 1px solid var(--line); border-radius: 12px 12px 0 0; }
.pane-body { padding: 8px 14px 14px; }
.pane-body .card { background: var(--bg); border-color: transparent; }
.pane-body .card.warn, .pane-body .flags { background: var(--warnbg); }
.pane-body .card.note { background: var(--infobg); }
.pane-tools { display: flex; gap: 8px; justify-content: flex-end; margin: 8px 0; }
.pane-body .card .card { background: var(--card); }
h2.step { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 8px; }
h2.step span { display: inline-grid; place-items: center; width: 24px; height: 24px; border-radius: 50%; background: var(--idlebg); color: var(--idle); font-size: 13px; font-weight: 700; }
h2.step small { font-weight: 400; color: var(--muted); font-size: 13px; }
pre.body { margin: 8px 0; padding: 10px; font: inherit; font-size: 14px; white-space: pre-wrap; overflow-wrap: anywhere; background: var(--card); border-radius: 8px; }
.pane-body .card .card pre.body { background: var(--bg); }
.msg-shared pre.body, .msg-skipped pre.body { color: var(--muted); }
.msg .files { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 4px; }

/* ---------- Today and order page ---------- */
.tiles { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px; margin-bottom: 16px; }
.tile { display: block; padding: 14px 16px; background: var(--card); border: 1px solid var(--line); border-radius: 12px; color: var(--ink); text-decoration: none; }
.tile:hover { border-color: var(--accent); }
.tile b { display: block; margin-bottom: 2px; font-size: 22px; font-weight: 700; overflow-wrap: anywhere; }
.tile span { color: var(--muted); font-size: 13px; }
.docstrip { display: flex; gap: 8px; overflow-x: auto; padding-bottom: 2px; margin-bottom: 12px; }
.doc { display: flex; flex: 0 0 auto; flex-direction: column; min-width: 136px; padding: 8px 12px; background: var(--card); border: 1px solid var(--line); border-radius: 10px; color: var(--ink); text-decoration: none; }
.doc:hover { border-color: var(--accent); }
.doc .dk { font-size: 11px; font-weight: 600; letter-spacing: .04em; text-transform: uppercase; color: var(--muted); }
.doc b { font-size: 13px; white-space: nowrap; } .doc.muted { opacity: .55; }
.progress { display: grid; grid-template-columns: repeat(6, minmax(0, 1fr)); gap: 4px; margin-bottom: 12px; padding: 14px 8px; background: var(--card); border: 1px solid var(--line); border-radius: 12px; }
.pstep { min-width: 0; text-align: center; font-size: 12px; color: var(--muted); }
.dot { display: flex; align-items: center; justify-content: center; width: 28px; height: 28px; margin: 0 auto 4px; border-radius: 50%; background: var(--idlebg); color: var(--idle); font-size: 12px; font-weight: 700; }
.pstep.done .dot { background: var(--good); color: var(--card); }
.pstep.now .dot { background: var(--accent); color: #fff; }
.pstep.now { color: var(--ink); font-weight: 600; }
.nextbar { position: sticky; bottom: 0; z-index: 5; display: flex; align-items: center; gap: 12px; margin: 16px -24px -24px; padding: 12px 24px; background: var(--card); border-top: 1px solid var(--line); }
.nextbar .grow small { display: block; color: var(--muted); font-size: 13px; }
.grow { flex: 1; min-width: 0; }

/* ---------- Forms and buttons ---------- */
.btn { display: inline-flex; align-items: center; justify-content: center; min-height: 44px; padding: 8px 14px; font: inherit; color: var(--ink); background: var(--card);
  border: 1px solid var(--line); border-radius: 10px; text-decoration: none; cursor: pointer; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600; }
.btn.wa { background: var(--wa); border-color: var(--wa); color: #fff; font-weight: 600; }
.btn.ghost { background: var(--card); }
.btn[disabled] { opacity: .5; cursor: not-allowed; }
.actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 10px; }
.actions form { margin: 0; }
.actions.sticky { position: sticky; bottom: 0; padding: 10px 0; background: var(--card); border-top: 1px solid var(--line); }
.fields { display: flex; flex-wrap: wrap; gap: 10px; margin: 6px 0 10px; }
.fields label { display: flex; flex: 1 1 180px; flex-direction: column; min-width: 0; font-size: 13px; color: var(--muted); }
.fields label.wide { flex-basis: 100%; }
input, select, textarea { width: 100%; min-height: 42px; padding: 8px 10px; font: inherit; color: var(--ink); background: var(--card); border: 1px solid var(--line); border-radius: 9px; }
textarea { resize: vertical; }
textarea.readonly, input[readonly] { background: var(--bg); color: var(--muted); resize: none; }
input[type=checkbox], input[type=radio] { width: 22px; min-height: 22px; accent-color: var(--accent); }
input.qty { width: 90px; }
form.inline { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
form.inline input { flex: 1 1 200px; width: auto; }
form.inline input.qty, form.inline input[type=date] { flex: 0 1 150px; }
label.check { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 10px; min-height: 44px; padding: 8px 0; border-bottom: 1px solid var(--line); }
.addr-row { align-items: end; border-top: 1px solid var(--line); padding-top: 8px; }
.price-alert td { background: var(--warnbg); }
.price-choice label { display: block; white-space: nowrap; }
.spinner { display: inline-block; width: 14px; height: 14px; border: 2px solid var(--line); border-top-color: var(--accent); border-radius: 50%; animation: spin 1s linear infinite; vertical-align: middle; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- Tables ---------- */
.scroll { overflow-x: auto; -webkit-overflow-scrolling: touch; }
table.grid { width: 100%; border-collapse: collapse; font-size: 14px; }
.grid th, .grid td { padding: 8px; text-align: left; vertical-align: top; border-bottom: 1px solid var(--line); }
.grid th { font-size: 12px; font-weight: 600; color: var(--muted); white-space: nowrap; }
.grid th.r, .grid td.r { text-align: right; }
.grid tbody tr[onclick] { cursor: pointer; }
.grid tbody tr[onclick]:hover td { background: var(--bg); }
.grid tr.muted { opacity: .55; }
.grid tfoot td { border-bottom: 0; }
.grid.edit td { padding: 4px; } .grid.edit input[name=desc] { min-width: 200px; } .grid.edit select { min-width: 180px; }
main > .scroll, main > form > .scroll { background: var(--card); border: 1px solid var(--line); border-radius: 12px; }
button.del { min-width: 40px; min-height: 40px; font-size: 16px; color: var(--muted); background: transparent; border: 0; border-radius: 8px; cursor: pointer; }
button.del:hover { background: var(--badbg); color: var(--bad); }
.docs { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 12px; }

/* ---------- Product dropdown and pop-up message ---------- */
.combo-list { position: absolute; z-index: 40; max-height: 45vh; overflow-y: auto; color: var(--ink); background: var(--card); border: 1px solid var(--line); border-radius: 10px; box-shadow: 0 6px 20px rgba(0, 0, 0, .25); }
.combo-item { padding: 10px 12px; border-bottom: 1px solid var(--line); cursor: pointer; }
.combo-item:hover, .combo-item.active { background: var(--bg); }
.combo-none { padding: 12px; }
.psearch { scroll-margin-top: 72px; }
.notice { position: fixed; left: 50%; bottom: 84px; z-index: 50; transform: translateX(-50%); width: max-content; max-width: calc(100% - 32px); padding: 10px 16px; border-radius: 10px;
  background: #14181F; color: #fff; font-size: 14px; box-shadow: 0 6px 20px rgba(0, 0, 0, .3); cursor: pointer; }
#pay-lines .inline { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
#pay-lines .inline input[type=date] { width: auto; }

/* ---------- Phones ---------- */
@media (max-width: 760px) {
  .burger { display: flex; }
  .top { gap: 6px; padding: 0 8px; }
  .top .btn { flex: none; padding: 8px 10px; white-space: nowrap; }
  .side { display: none; position: fixed; left: 0; right: 0; top: 60px; bottom: 0; z-index: 15; width: auto; height: auto; border-right: 0; }
  .side.open { display: block; }
  main { padding: 16px; }
  h1 { font-size: 21px; }
  .tiles { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .nextbar { margin: 16px -16px -16px; padding: 12px 16px; }
  .nextbar .btn { flex: 1; }
  .nextbar .grow { display: none; }
  .pane-body { padding: 8px; }
  .pstep { font-size: 11px; }
  h2.step small { display: none; }
  .actions.sticky .btn { flex: 1; }
  table.cards thead { display: none; }
  table.cards, table.cards tbody, table.cards tfoot { display: block; width: 100%; }
  table.cards tbody tr { display: grid; grid-template-columns: 1fr 1fr; gap: 8px 10px; position: relative; padding: 12px; margin-bottom: 10px; background: var(--bg); border-radius: 10px; }
  main > .scroll, main > form > .scroll { background: none; border: 0; }
  main > .scroll table.cards tbody tr, main > form > .scroll table.cards tbody tr { background: var(--card); }
  table.cards td { display: block; min-width: 0; padding: 0; text-align: left !important; border: 0; }
  table.cards td.full { grid-column: 1 / -1; }
  table.cards td[data-label]::before { content: attr(data-label); display: block; margin-bottom: 2px; font-size: 12px; color: var(--muted); }
  table.cards td.ln { display: none; }
  table.cards td:empty:not(.amt):not(.stock) { display: none; }
  table.cards td.rm { position: absolute; top: 4px; right: 4px; }
  table.cards td.full:first-child, table.cards tr > td.ln + td.full { padding-right: 36px; }
  table.cards input:not([type=checkbox]):not([type=radio]) { width: 100%; font-size: 16px; }
  table.cards tfoot tr { display: flex; justify-content: space-between; gap: 10px; padding: 10px 12px; }
  table.cards tfoot td { display: block; padding: 0; border: 0; }
  table.cards tfoot td:empty { display: none; }
  table.cards td.pay-tick { grid-column: 1 / -1; }
}
