:root {
  color-scheme: light;
  --bg: #f4f4f2;
  --surface: #ffffff;
  --surface-2: #f8f8f6;
  --surface-3: #efeeea;
  --border: #e3e2dd;
  --border-strong: #cfcdc6;
  --text: #16161a;
  --text-2: #52514e;
  --muted: #86857f;
  --accent: #2a78d6;
  --accent-ink: #1c5cab;
  --accent-soft: #e6f0fc;
  --good: #0f7b3d; --good-soft: #e3f4ea;
  --warn: #9a6100; --warn-soft: #fdf1d8;
  --bad: #c43434; --bad-soft: #fde7e7;
  --row-total: #eef4fc;
  --row-body: #fbfaf7;
  --shadow: 0 1px 2px rgba(0,0,0,.05), 0 4px 16px rgba(0,0,0,.06);
  --radius: 10px;
  --c1: #2a78d6; --c2: #eb6834; --c3: #1baf7a; --c4: #eda100; --c5: #e87ba4; --c6: #008300; --c7: #4a3aa7; --c8: #e34948;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #111110; --surface: #1a1a19; --surface-2: #21211f; --surface-3: #2a2a27;
    --border: #33332f; --border-strong: #46463f;
    --text: #f3f2ee; --text-2: #c3c2b7; --muted: #8f8e86;
    --accent: #3987e5; --accent-ink: #86b6ef; --accent-soft: #1b2b40;
    --good: #5cc98b; --good-soft: #15301f; --warn: #e6b04a; --warn-soft: #33280f; --bad: #ef7c7c; --bad-soft: #3a1c1c;
    --row-total: #1b2636; --row-body: #1e1e1c;
    --shadow: 0 1px 2px rgba(0,0,0,.4), 0 4px 16px rgba(0,0,0,.3);
    --c1: #3987e5; --c2: #d95926; --c3: #199e70; --c4: #c98500; --c5: #d55181; --c6: #008300; --c7: #9085e9; --c8: #e66767;
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #111110; --surface: #1a1a19; --surface-2: #21211f; --surface-3: #2a2a27;
  --border: #33332f; --border-strong: #46463f;
  --text: #f3f2ee; --text-2: #c3c2b7; --muted: #8f8e86;
  --accent: #3987e5; --accent-ink: #86b6ef; --accent-soft: #1b2b40;
  --good: #5cc98b; --good-soft: #15301f; --warn: #e6b04a; --warn-soft: #33280f; --bad: #ef7c7c; --bad-soft: #3a1c1c;
  --row-total: #1b2636; --row-body: #1e1e1c;
  --shadow: 0 1px 2px rgba(0,0,0,.4), 0 4px 16px rgba(0,0,0,.3);
  --c1: #3987e5; --c2: #d95926; --c3: #199e70; --c4: #c98500; --c5: #d55181; --c6: #008300; --c7: #9085e9; --c8: #e66767;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg); color: var(--text);
  font: 14px/1.5 'IBM Plex Sans Thai', 'Sarabun', 'Segoe UI', Tahoma, sans-serif;
  -webkit-font-smoothing: antialiased;
}
a { color: var(--accent-ink); text-decoration: none; }
button, input, select { font: inherit; color: inherit; }
.num { font-variant-numeric: tabular-nums; text-align: right; white-space: nowrap; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.hidden { display: none !important; }

/* ---------- layout ---------- */
.layout { display: grid; grid-template-columns: 232px 1fr; min-height: 100vh; }
.sidebar {
  background: var(--surface); border-right: 1px solid var(--border);
  padding: 18px 12px; position: sticky; top: 0; height: 100vh; overflow-y: auto;
  display: flex; flex-direction: column; gap: 4px;
}
.brand { display: flex; align-items: center; gap: 10px; padding: 4px 8px 18px; font-weight: 700; font-size: 16px; }
.brand-mark { width: 30px; height: 30px; border-radius: 8px; background: var(--accent); color: #fff; display: grid; place-items: center; font-size: 15px; }
.nav-label { font-size: 11px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); padding: 14px 10px 4px; }
.nav a {
  display: flex; align-items: center; gap: 10px; padding: 8px 10px; border-radius: 8px; color: var(--text-2);
}
.nav a:hover { background: var(--surface-2); color: var(--text); }
.nav a.active { background: var(--accent-soft); color: var(--accent-ink); font-weight: 600; }
.nav svg { width: 18px; height: 18px; flex: none; }
.sidebar-foot { margin-top: auto; border-top: 1px solid var(--border); padding: 12px 8px 0; display: flex; flex-direction: column; gap: 8px; }
.user-chip { display: flex; align-items: center; gap: 8px; }
.avatar { width: 30px; height: 30px; border-radius: 50%; background: var(--surface-3); display: grid; place-items: center; font-weight: 600; font-size: 13px; }

.main { min-width: 0; padding: 22px 28px 60px; }
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; margin-bottom: 18px; flex-wrap: wrap; }
.page-head h1 { font-size: 22px; margin: 0; letter-spacing: -.01em; }
.page-head .sub { color: var(--muted); font-size: 13px; margin-top: 2px; }
.topbar-mobile { display: none; }

/* ---------- cards / tiles ---------- */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); }
.card-h { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 14px 16px 6px; flex-wrap: wrap; }
.card-h h2 { font-size: 15px; margin: 0; }
.card-b { padding: 8px 16px 16px; }
.grid { display: grid; gap: 16px; }
.g-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.g-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.g-32 { grid-template-columns: 3fr 2fr; }
.tile { padding: 14px 16px; }
.tile .label { color: var(--text-2); font-size: 13px; }
.tile .value { font-size: 26px; font-weight: 700; letter-spacing: -.02em; margin-top: 2px; font-variant-numeric: tabular-nums; }
.tile .hint { color: var(--muted); font-size: 12px; }
.chart-box { position: relative; height: 320px; }
.chart-box.tall { height: 380px; }

.type-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(210px, 1fr)); gap: 12px; }
.type-card { padding: 14px 16px; cursor: pointer; transition: border-color .15s, transform .15s; text-align: left; width: 100%; }
.type-card:hover { border-color: var(--accent); transform: translateY(-1px); }
.type-card .t { font-weight: 600; }
.type-card .n { font-size: 22px; font-weight: 700; font-variant-numeric: tabular-nums; margin-top: 6px; }
.type-card .s { color: var(--muted); font-size: 12px; }

/* ---------- controls ---------- */
.btn {
  border: 1px solid var(--border-strong); background: var(--surface); padding: 7px 14px; border-radius: 8px; cursor: pointer;
  display: inline-flex; align-items: center; gap: 6px; white-space: nowrap;
}
.btn:hover { background: var(--surface-2); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { filter: brightness(1.07); }
.btn.danger { color: var(--bad); }
.btn.sm { padding: 3px 9px; font-size: 12px; }
.btn:disabled { opacity: .55; cursor: default; }
.input, select.input {
  border: 1px solid var(--border-strong); background: var(--surface); border-radius: 8px; padding: 7px 10px; min-width: 0;
}
.input:focus, .btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
.searchbar { display: flex; gap: 8px; margin-bottom: 18px; }
.searchbar .input { flex: 1; font-size: 16px; padding: 11px 14px 11px 40px; border-radius: 10px;
  background: var(--surface) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='18' height='18' fill='none' stroke='%2386857f' stroke-width='2' viewBox='0 0 24 24'%3E%3Ccircle cx='11' cy='11' r='7'/%3E%3Cpath d='m20 20-3.5-3.5'/%3E%3C/svg%3E") no-repeat 13px center; }
.filters { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-bottom: 12px; }
.filters label { display: inline-flex; align-items: center; gap: 6px; color: var(--text-2); font-size: 13px; }
.chip { display: inline-flex; align-items: center; gap: 6px; padding: 2px 10px; border-radius: 999px; background: var(--surface-3); font-size: 12px; color: var(--text-2); white-space: nowrap; }
.chip.accent { background: var(--accent-soft); color: var(--accent-ink); }
.chip.warn { background: var(--warn-soft); color: var(--warn); }
.chip.good { background: var(--good-soft); color: var(--good); }
.chip.bad { background: var(--bad-soft); color: var(--bad); }
.dot { width: 8px; height: 8px; border-radius: 50%; display: inline-block; flex: none; }

/* ---------- tables ---------- */
.table-wrap { overflow: auto; border-radius: var(--radius); }
table.t { width: 100%; border-collapse: separate; border-spacing: 0; font-size: 13px; }
.t th {
  position: sticky; top: 0; z-index: 1; background: var(--surface-2); color: var(--text-2); font-weight: 600; text-align: left;
  padding: 8px 10px; border-bottom: 1px solid var(--border); white-space: nowrap; font-size: 12px;
}
.t th.sortable { cursor: pointer; user-select: none; }
.t th.sortable:hover { color: var(--text); }
.t th .arrow { color: var(--accent); }
.t td { padding: 7px 10px; border-bottom: 1px solid var(--border); vertical-align: middle; }
.t tr:last-child td { border-bottom: 0; }
.t tbody tr:hover td { background: var(--surface-2); }
.t td.name { min-width: 220px; max-width: 380px; }
.t td.code { white-space: nowrap; font-weight: 600; }
.t .clickable { cursor: pointer; border-radius: 6px; }
.t td.cell-btn { cursor: pointer; }
.t td.cell-btn:hover { background: var(--accent-soft) !important; color: var(--accent-ink); }
.t td.zero { color: var(--muted); }
.t tr.total td { background: var(--row-total); font-weight: 600; }
.t tr.body td { background: var(--row-body); }
.t tr.body td.code { padding-left: 22px; }
.tag-type { font-size: 11px; padding: 1px 7px; border-radius: 5px; background: var(--surface-3); color: var(--text-2); white-space: nowrap; }
.tag-type.fg { background: var(--accent-soft); color: var(--accent-ink); }
.tag-type.body { background: var(--warn-soft); color: var(--warn); }
.tag-type.sum { background: var(--accent); color: #fff; }
.block { margin-bottom: 14px; overflow: hidden; }
.t tbody.blk + tbody.blk tr:first-child td { border-top: 2px solid var(--border-strong); }

/* latest-update bar */
.freshbar { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 16px; padding: 7px 28px; font-size: 12px; color: var(--text-2); background: var(--surface); border-bottom: 1px solid var(--border); }
.fresh-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--good); display: inline-block; }
@media (max-width: 800px) { .freshbar { padding: 6px 16px; } }

/* frozen header row + first two columns in item tables */
.t.rz tr > :nth-child(1), .t.rz tr > :nth-child(2) { position: sticky; z-index: 1; }
.t.rz tr > :nth-child(1) { left: 0; }
.t.rz tr > :nth-child(2) { left: var(--fz1, 0px); box-shadow: inset -1px 0 0 var(--border); }
.t.rz th:nth-child(-n+2) { z-index: 3; }
.t.rz td:nth-child(-n+2) { background: var(--surface); }
.t.rz tr.total td:nth-child(-n+2) { background: var(--row-total); }
.t.rz tr.body td:nth-child(-n+2) { background: var(--row-body); }
.t.rz tbody tr:hover td:nth-child(-n+2) { background: var(--surface-2); }
.t tbody.sep td { background: var(--surface-3); padding: 9px 10px; font-weight: 600; color: var(--text-2); border-top: 2px solid var(--border-strong); }
.t tbody.sep .sep-in { position: sticky; left: 10px; width: max-content; }

/* inline per-pallet editor */
.pal-in { width: 100%; padding: 3px 6px; text-align: right; font-variant-numeric: tabular-nums; }
.pal-in.missing { border-color: var(--warn); background: var(--warn-soft); }
.pal-in.saved { border-color: var(--good); }
select.on-filter { border-color: var(--accent); background: var(--accent-soft); }

/* multi-select dropdown */
.msel { position: relative; max-width: 100%; }
.msel-btn { width: 100%; display: flex; align-items: center; gap: 4px; cursor: pointer; text-align: left; white-space: nowrap; overflow: hidden; }
.msel-btn.on { border-color: var(--accent); background: var(--accent-soft); }
.msel-sum { overflow: hidden; text-overflow: ellipsis; flex: 1; min-width: 0; }
.msel-caret { color: var(--muted); font-size: 11px; }
.msel-pop { position: absolute; top: calc(100% + 4px); left: 0; z-index: 45; width: max(100%, 280px); background: var(--surface); border: 1px solid var(--border-strong); border-radius: 10px; box-shadow: 0 10px 30px rgba(0,0,0,.15); padding: 8px; }
.msel-q { width: 100%; }
.msel-actions { display: flex; justify-content: space-between; font-size: 12px; padding: 6px 2px; }
.msel-list { max-height: 280px; overflow-y: auto; display: flex; flex-direction: column; }
.msel-list label { display: flex; align-items: center; gap: 8px; padding: 5px 6px; border-radius: 6px; cursor: pointer; font-size: 13px; color: var(--text); }
.msel-list label:hover { background: var(--surface-2); }
.msel-foot { display: flex; justify-content: flex-end; padding-top: 6px; border-top: 1px solid var(--border); margin-top: 4px; }

/* resizable / reorderable item tables */
table.t.rz { table-layout: fixed; }
.t.rz th, .t.rz td { overflow: hidden; text-overflow: ellipsis; }
.t.rz td.name { min-width: 0; max-width: none; }
.t.rz th { position: sticky; cursor: grab; }
.t.rz th.dragging { opacity: .45; }
.t.rz th.drop-l { box-shadow: inset 3px 0 0 var(--accent); }
.t.rz th.drop-r { box-shadow: inset -3px 0 0 var(--accent); }
.rz-h { position: absolute; top: 0; right: 0; width: 8px; height: 100%; cursor: col-resize; z-index: 2; }
.rz-h::after { content: ''; position: absolute; top: 25%; bottom: 25%; right: 3px; width: 2px; border-radius: 2px; background: var(--border-strong); }
.rz-h:hover::after, body.col-resizing .rz-h::after { background: var(--accent); }
body.col-resizing { cursor: col-resize; user-select: none; }
.section-sep { display: flex; align-items: center; gap: 12px; margin: 30px 0 14px; color: var(--text-2); font-weight: 600; }
.section-sep::after { content: ''; flex: 1; height: 1px; background: var(--border-strong); }

/* ---------- popover / drawer / modal ---------- */
.popover { overscroll-behavior: contain;
  position: fixed; z-index: 60; background: var(--surface); border: 1px solid var(--border-strong); border-radius: 10px;
  box-shadow: 0 10px 40px rgba(0,0,0,.18); min-width: 300px; max-width: min(720px, calc(100vw - 24px)); max-height: 70vh; overflow: auto;
}
.popover .ph { padding: 10px 14px; border-bottom: 1px solid var(--border); font-weight: 600; display: flex; justify-content: space-between; gap: 12px; align-items: center; }
.popover .pb { padding: 4px 4px 8px; }
.drawer-bg { position: fixed; inset: 0; background: rgba(0,0,0,.35); z-index: 50; }
.drawer {
  position: fixed; top: 0; right: 0; bottom: 0; width: min(1100px, 100vw); background: var(--bg); z-index: 51; overflow-y: auto;
  box-shadow: -10px 0 40px rgba(0,0,0,.2); animation: slidein .18s ease-out;
}
@keyframes slidein { from { transform: translateX(30px); opacity: .6; } }
.drawer-head { position: sticky; top: 0; z-index: 3; background: var(--surface); border-bottom: 1px solid var(--border); padding: 14px 20px; display: flex; justify-content: space-between; gap: 14px; align-items: flex-start; }
.drawer-body { padding: 18px 20px 40px; display: flex; flex-direction: column; gap: 16px; }
.modal-bg { position: fixed; inset: 0; background: rgba(0,0,0,.4); z-index: 70; display: grid; place-items: center; padding: 16px; }
.modal { background: var(--surface); border-radius: 12px; padding: 22px; width: min(440px, 100%); box-shadow: var(--shadow); }
.modal h3 { margin: 0 0 10px; }
.pw-big { font-size: 34px; font-weight: 700; letter-spacing: .25em; text-align: center; padding: 14px; background: var(--surface-2); border-radius: 10px; margin: 12px 0; font-variant-numeric: tabular-nums; }
.toast { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); background: var(--text); color: var(--bg); padding: 10px 18px; border-radius: 10px; z-index: 90; box-shadow: var(--shadow); }
.toast.err { background: var(--bad); color: #fff; }
.iconbtn { border: 0; background: transparent; cursor: pointer; padding: 6px; border-radius: 8px; color: var(--text-2); }
.iconbtn:hover { background: var(--surface-3); }
.kv { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; }
.kv > div { background: var(--surface); border: 1px solid var(--border); border-radius: 10px; padding: 10px 12px; }
.kv .k { font-size: 12px; color: var(--text-2); display: flex; align-items: center; gap: 6px; }
.kv .v { font-size: 20px; font-weight: 700; font-variant-numeric: tabular-nums; }
.kv > div.btnlike { cursor: pointer; }
.kv > div.btnlike:hover { border-color: var(--accent); }
.empty { padding: 40px 16px; text-align: center; color: var(--muted); }
.loading { padding: 40px; text-align: center; color: var(--muted); }
.upload-card .drop { border: 2px dashed var(--border-strong); border-radius: 10px; padding: 18px; text-align: center; color: var(--text-2); cursor: pointer; }
.upload-card .drop:hover { border-color: var(--accent); color: var(--accent-ink); }
.legend { display: flex; flex-wrap: wrap; gap: 14px; font-size: 12px; color: var(--text-2); }
.legend span { display: inline-flex; align-items: center; gap: 6px; }
.switch { position: relative; width: 38px; height: 22px; display: inline-block; flex: none; }
.switch input { opacity: 0; width: 0; height: 0; }
.switch span { position: absolute; inset: 0; background: var(--border-strong); border-radius: 999px; transition: .15s; cursor: pointer; }
.switch span::before { content: ''; position: absolute; width: 16px; height: 16px; left: 3px; top: 3px; background: #fff; border-radius: 50%; transition: .15s; }
.switch input:checked + span { background: var(--accent); }
.switch input:checked + span::before { transform: translateX(16px); }
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--border); margin-bottom: 16px; overflow-x: auto; }
.tabs a { padding: 8px 14px; color: var(--text-2); border-bottom: 2px solid transparent; white-space: nowrap; }
.tabs a.active { color: var(--accent-ink); border-color: var(--accent); font-weight: 600; }

/* ---------- login ---------- */
.login-wrap { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login-card { width: min(380px, 100%); padding: 28px; }
.login-card h1 { font-size: 20px; margin: 14px 0 4px; }
.field { display: flex; flex-direction: column; gap: 6px; margin-top: 14px; }
.field label { font-size: 13px; color: var(--text-2); }
.err-msg { color: var(--bad); font-size: 13px; min-height: 20px; margin-top: 10px; }

@media (max-width: 1100px) { .g-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); } .g-32, .g-2 { grid-template-columns: 1fr; } }
@media (max-width: 800px) {
  .layout { grid-template-columns: 1fr; }
  .sidebar { position: fixed; left: 0; top: 0; z-index: 40; width: 250px; transform: translateX(-105%); transition: transform .2s; box-shadow: var(--shadow); }
  .sidebar.open { transform: none; }
  .topbar-mobile { display: flex; align-items: center; gap: 10px; padding: 10px 16px; background: var(--surface); border-bottom: 1px solid var(--border); position: sticky; top: 0; z-index: 30; }
  .main { padding: 16px 16px 50px; }
  .g-4 { grid-template-columns: 1fr 1fr; }
  .tile .value { font-size: 20px; }
}

/* Alert Product tags */
.tagmini { font-size: 11px; padding: 0 7px; margin-right: 5px; vertical-align: 1px; }
.tagbar { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 14px; align-items: center; }
.tagchip { border: 1px solid transparent; border-radius: 999px; padding: 6px 14px; cursor: pointer; font: inherit; font-size: 13px; display: inline-flex; gap: 8px; align-items: center; }
.tagchip.bad { background: var(--bad-soft); color: var(--bad); }
.tagchip.warn { background: var(--warn-soft); color: var(--warn); }
.tagchip.accent { background: var(--accent-soft); color: var(--accent-ink); }
.tagchip.on { border-color: currentColor; box-shadow: 0 0 0 1px currentColor inset; }

/* left/right scroll buttons: second sticky header row */
/* overflow must stay visible here or the sticky inner box can't stick */
.t.rz tr.hnav th, .t.rz tbody.sep td { overflow: visible; }
.t thead tr.hnav th { top: var(--hh, 34px); padding: 4px 8px; background: var(--surface); border-bottom: 1px solid var(--border); cursor: default; }
.hnav-in { position: sticky; left: 8px; display: inline-flex; gap: 6px; align-items: center; width: max-content; }
.hnav-in .btn { padding: 2px 10px; }
.filters-toggle { display: none; margin-bottom: 10px; }

/* ---------- phone layout ---------- */
@media (max-width: 800px) {
  body { font-size: 14px; }
  .page-head { margin-bottom: 12px; }
  .page-head h1 { font-size: 19px; }
  .searchbar .input { font-size: 16px; }              /* 16px stops iOS zooming into the field */
  .input, select.input { font-size: 16px; }
  .filters-toggle { display: inline-flex; width: 100%; justify-content: center; }
  .filters.collapsible { display: none; }
  .filters.collapsible.open { display: flex; }
  .filters { gap: 8px; }
  .filters > .msel, .filters > select, .filters > input.input { width: 100% !important; max-width: none !important; flex: 1 1 100%; }
  .filters > .btn, .filters > a.btn { flex: 1 1 auto; justify-content: center; }
  .type-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
  .type-card { padding: 10px 12px; }
  .type-card .n { font-size: 18px; }
  .table-wrap[style*="max-height"] { max-height: 72vh !important; }
  .t { font-size: 12.5px; }
  .t td, .t th { padding: 6px 8px; }
  /* only the code column stays frozen on a phone, the name scrolls */
  .t.rz td:nth-child(2) { position: static; box-shadow: none; }
  .t.rz th:nth-child(2) { left: auto; box-shadow: none; }
  .hnav-tip { display: none; }
  .hnav-in .btn { padding: 4px 12px; }
  .rz-h { width: 14px; }                               /* bigger touch target for resizing */
  .card-h { padding: 12px 12px 4px; }
  .card-b { padding: 8px 12px 12px; }
  .drawer-head { padding: 12px 14px; }
  .drawer-body { padding: 12px 12px 30px; }
  .kv { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
  .kv .v { font-size: 17px; }
  .popover { left: 8px !important; right: 8px; max-width: none; }
  .msel-pop { width: 100%; }
  .tabs { margin-bottom: 10px; }
  .chart-box { height: 260px; }
  .freshbar span { white-space: nowrap; }
  .freshbar .muted { display: none; }   /* keep the bar to Stock-age + FG on phones */
}

/* ---- filters: hidden behind "Show more" on every screen size ---- */
.filters-toggle { display: inline-flex; }
.filters.collapsible { display: none; padding: 12px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); }
.filters.collapsible.open { display: flex; }

/* ---- narrow code column ---- */
.t td.code { white-space: nowrap; }
.t.rz td.code .tag-type { padding: 0 5px; font-size: 10px; margin-right: 2px; }
.more-codes { display: inline-block; margin-left: 3px; padding: 0 5px; border-radius: 5px; background: var(--surface-3); color: var(--text-2); font-size: 11px; font-weight: 600; cursor: help; }
.codelink { text-decoration: underline dotted; text-underline-offset: 3px; }

/* ---- price tooltip ---- */
.price-tip { position: fixed; z-index: 80; background: var(--surface); border: 1px solid var(--border-strong); border-radius: 10px; box-shadow: 0 10px 30px rgba(0,0,0,.18); padding: 10px 12px; min-width: 210px; max-width: 320px; pointer-events: none; font-size: 13px; }
.price-tip .pt-h { font-weight: 700; display: flex; gap: 6px; align-items: center; }
.price-tip .pt-row { display: flex; justify-content: space-between; gap: 16px; padding: 2px 0; font-variant-numeric: tabular-nums; }
.price-tip .pt-row span { color: var(--text-2); }
.drawer-prices { margin-top: 4px; font-size: 13px; color: var(--text-2); }
.drawer-prices b { color: var(--text); font-variant-numeric: tabular-nums; }

/* ---- Product Alert Cat (Help Me / Special) ---- */
.chip.pcat, .tagchip.pcat { background: #efe9fb; color: #5b3fb5; }
:root[data-theme="dark"] .chip.pcat, :root[data-theme="dark"] .tagchip.pcat { background: #2b2346; color: #b9a6f2; }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .chip.pcat, :root:not([data-theme="light"]) .tagchip.pcat { background: #2b2346; color: #b9a6f2; } }
.switch.danger input:checked + span { background: var(--bad); }

/* ---- collapsible sidebar (desktop) ---- */
.layout { transition: grid-template-columns .18s ease; }
.brand { position: relative; }
.collapse-btn { margin-left: auto; color: var(--muted); }
.collapse-btn svg { transition: transform .18s; }
.foot-btns { display: flex; gap: 6px; }
@media (min-width: 801px) {
  .layout.nav-collapsed { grid-template-columns: 68px 1fr; }
  .nav-collapsed .sidebar { padding: 18px 10px; overflow-x: hidden; }
  .nav-collapsed .brand { flex-direction: column; gap: 8px; padding: 4px 0 14px; }
  .nav-collapsed .brand-name, .nav-collapsed .nav a span, .nav-collapsed .nav-label, .nav-collapsed .user-info { display: none; }
  .nav-collapsed .collapse-btn { margin: 0; }
  .nav-collapsed .collapse-btn svg { transform: rotate(180deg); }
  .nav-collapsed .nav a { justify-content: center; padding: 10px 0; }
  .nav-collapsed .nav-label + a, .nav-collapsed .nav a + .nav-label { margin-top: 10px; }
  .nav-collapsed .sidebar-foot { padding: 10px 0 0; align-items: center; }
  .nav-collapsed .user-chip { justify-content: center; }
  .nav-collapsed .foot-btns { flex-direction: column; }
  .nav-collapsed .foot-btns .btn { padding: 4px 6px; font-size: 11px; }
}
@media (max-width: 800px) { .collapse-btn { display: none; } }
.t tr.row-off td:not(:last-child) { opacity: .45; }
/* icon-only footer buttons in the collapsed rail */
@media (min-width: 801px) {
  .nav-collapsed .foot-btns .btn { font-size: 0; width: 36px; height: 30px; justify-content: center; padding: 0; }
  .nav-collapsed #themeBtn::before { content: '◐'; font-size: 15px; }
  .nav-collapsed #logoutBtn::before { content: '⏻'; font-size: 14px; }
}

/* =========================================================
   Compact density — more rows on screen, smaller controls
   ========================================================= */
@media (min-width: 801px) {
  .main { padding: 14px 20px 40px; }
  .freshbar { padding: 4px 20px; font-size: 11.5px; gap: 4px 14px; }
  .page-head { margin-bottom: 10px; align-items: center; }
  .page-head h1 { font-size: 18px; }
  .page-head .sub { font-size: 12px; margin-top: 0; }

  /* search: short and slim */
  .searchbar { max-width: 560px; margin-bottom: 10px; gap: 6px; }
  .searchbar .input { font-size: 13.5px; padding: 6px 10px 6px 32px; border-radius: 8px; background-position: 10px center; background-size: 15px; }
  .searchbar .btn { padding: 5px 14px; font-size: 13px; }

  /* "Show more" filters + chips */
  .filters-toggle { padding: 4px 12px; font-size: 12.5px; margin-bottom: 8px; }
  .filters.collapsible { padding: 8px; gap: 6px; }
  .filters .input, .filters select.input { padding: 4px 8px; font-size: 12.5px; }
  .filters .btn { padding: 4px 10px; font-size: 12.5px; }
  .filters label { font-size: 12px; }
  .msel-btn { padding: 4px 8px; font-size: 12.5px; }
  .tagbar { gap: 6px; margin-bottom: 8px; }
  .tagchip { padding: 3px 10px; font-size: 12px; gap: 6px; }
}

/* item lists: small text, tight rows, one line per product */
.t.rz { font-size: 12px; }
.t.rz th { font-size: 11px; padding: 5px 6px; white-space: normal; line-height: 1.25; vertical-align: bottom; }
.t.rz td { padding: 3px 6px; line-height: 1.35; }
.t.rz td { white-space: nowrap; }
.t.rz .tag-type, .t.rz .tagmini { font-size: 10px; padding: 0 5px; }
.t.rz .tagmini { margin-right: 4px; }
.t.rz .more-codes { font-size: 10px; padding: 0 4px; }
.t.rz tr.body td.code { padding-left: 14px; }
.t thead tr.hnav th { padding: 2px 6px; }
.hnav-in { gap: 4px; }
.hnav-in .btn { padding: 1px 8px; font-size: 11px; }
.hnav-tip { font-size: 11px; }
.t tbody.sep td { padding: 5px 8px; font-size: 12px; }
.t.rz .pal-in { padding: 1px 5px; font-size: 12px; }
.card-b .muted.small, #lc { font-size: 11.5px; }

/* ---- set price window ---- */
.modal.modal-wide { width: min(820px, 100%); max-height: 92vh; overflow-y: auto; }
.sp-sub { font-weight: 600; font-size: 13px; margin-bottom: 6px; }
.sp-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 10px; }
.sp-grid label, .pf-grid label { display: flex; flex-direction: column; gap: 4px; font-size: 12.5px; color: var(--text-2); }
.pricecell { font-variant-numeric: tabular-nums; cursor: help; }
.pricecell.manual { color: #5b3fb5; border-bottom: 1px dashed currentColor; }
.price-edit { font-size: 11px; color: var(--muted); }
.t.rz .price-btn { padding: 0 8px; font-size: 11px; line-height: 18px; border-color: var(--accent); color: var(--accent-ink); }

/* ---- Promotion ---- */
.promo-stats { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 10px; margin-bottom: 12px; }
.pstat { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 10px 14px; border-left: 4px solid var(--border-strong); }
.pstat .n { font-size: 24px; font-weight: 700; font-variant-numeric: tabular-nums; line-height: 1.2; }
.pstat .l { font-size: 12px; color: var(--text-2); }
.pstat.good { border-left-color: var(--good); } .pstat.warn { border-left-color: var(--warn); } .pstat.accent { border-left-color: var(--accent); }
.promo-bar { display: flex; gap: 10px; align-items: center; justify-content: space-between; flex-wrap: wrap; margin-bottom: 12px; }
.promo-bar .seg { display: inline-flex; background: var(--surface-3); border-radius: 10px; padding: 3px; gap: 2px; flex-wrap: wrap; }
.promo-bar .seg a { padding: 5px 12px; border-radius: 8px; color: var(--text-2); font-size: 13px; }
.promo-bar .seg a b { font-weight: 600; margin-left: 2px; color: var(--muted); }
.promo-bar .seg a.on { background: var(--surface); color: var(--text); box-shadow: 0 1px 3px rgba(0,0,0,.1); font-weight: 600; }
.promo-bar .input { width: 280px; max-width: 100%; padding: 5px 10px; font-size: 13px; }
.promo-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(320px, 1fr)); gap: 14px; }
.promo-card { padding: 14px 16px; display: flex; flex-direction: column; gap: 10px; border-top: 4px solid var(--good); }
.promo-card.soon { border-top-color: var(--warn); }
.promo-card.upcoming { border-top-color: var(--accent); }
.promo-card.ended { border-top-color: var(--border-strong); opacity: .78; }
.pc-top { display: flex; justify-content: space-between; gap: 10px; align-items: flex-start; }
.pc-name { font-size: 16px; font-weight: 700; line-height: 1.3; }
.pc-dates { display: flex; align-items: flex-end; gap: 10px; background: var(--surface-2); border-radius: 8px; padding: 8px 10px; }
.pc-dates > div { display: flex; flex-direction: column; font-size: 13px; }
.pc-dates .arrow { color: var(--muted); align-self: center; }
.pc-dates .pc-dur { margin-left: auto; text-align: right; }
.pc-left { display: flex; justify-content: space-between; align-items: baseline; }
.pc-big { font-size: 20px; font-weight: 700; }
.promo-card.soon .pc-big { color: var(--warn); }
.pc-pct { font-size: 18px; font-weight: 700; font-variant-numeric: tabular-nums; }
.pc-track { height: 8px; background: var(--surface-3); border-radius: 999px; overflow: hidden; }
.pc-fill { height: 100%; border-radius: 999px; background: var(--good); transition: width .4s; }
.promo-card.soon .pc-fill { background: var(--warn); }
.promo-card.upcoming .pc-fill { background: var(--accent); }
.pc-items { display: flex; flex-wrap: wrap; gap: 6px; }
.pc-item { display: inline-flex; gap: 6px; align-items: center; max-width: 100%; background: var(--surface-2); border: 1px solid var(--border); border-radius: 6px; padding: 2px 8px; font-size: 12px; }
.pc-item .muted { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 170px; }
.pc-more { font-size: 12px; color: var(--muted); align-self: center; }
.pc-note { font-size: 12.5px; color: var(--text-2); background: var(--warn-soft); border-radius: 6px; padding: 6px 8px; }
.pc-actions { display: flex; gap: 6px; justify-content: flex-end; border-top: 1px solid var(--border); padding-top: 8px; }
/* promotion form */
.pf-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.pf-full { grid-column: 1 / -1; }
.pf-label { font-size: 12.5px; color: var(--text-2); margin-bottom: 4px; }
.pf-calc { background: var(--accent-soft); color: var(--accent-ink); border-radius: 8px; padding: 8px 12px; font-size: 13px; }
.pf-picker { position: relative; }
.pf-picker .input { width: 100%; }
.pf-results { position: absolute; left: 0; right: 0; top: calc(100% + 4px); z-index: 5; background: var(--surface); border: 1px solid var(--border-strong); border-radius: 8px; box-shadow: var(--shadow); max-height: 240px; overflow-y: auto; }
.pf-res { padding: 6px 10px; font-size: 13px; cursor: pointer; border-bottom: 1px solid var(--border); }
.pf-res:hover { background: var(--surface-2); }
.pf-res.on { background: var(--good-soft); }
.pf-chips { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.pf-chip { display: inline-flex; gap: 6px; align-items: center; background: var(--accent-soft); border-radius: 999px; padding: 3px 6px 3px 10px; font-size: 12px; max-width: 100%; }
.pf-chip .muted { max-width: 200px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pf-chip a { color: var(--muted); padding: 0 4px; }
@media (max-width: 800px) {
  .promo-stats { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .promo-grid { grid-template-columns: 1fr; }
  .pf-grid, .sp-grid { grid-template-columns: 1fr; }
  .promo-bar .input { width: 100%; }
}

/* ---- wrap text in lists: names / type / series wrap, numbers and codes stay on one line ---- */
.t.rz td { white-space: normal; overflow-wrap: anywhere; text-overflow: clip; vertical-align: top; }
.t.rz td.num, .t.rz td.code { white-space: nowrap; overflow-wrap: normal; }
.t.rz td.name { line-height: 1.3; }

/* ---- sidebar always fits the screen: menu scrolls, footer (user / logout) pinned at the bottom ---- */
.sidebar { height: 100vh; height: 100dvh; overflow: hidden; padding: 12px 10px; gap: 2px; }
.brand { padding: 2px 6px 10px; font-size: 15px; flex: none; }
.brand-mark { width: 28px; height: 28px; font-size: 13px; }
.nav { flex: 1 1 auto; min-height: 0; overflow-y: auto; overscroll-behavior: contain; scrollbar-width: thin; }
.nav a { padding: 6px 10px; font-size: 13.5px; }
.nav svg { width: 17px; height: 17px; }
.nav-label { padding: 10px 10px 2px; }
.sidebar-foot { flex: none; margin-top: 6px; padding: 8px 6px 0; gap: 6px; }
.user-chip { gap: 8px; }
.avatar { width: 26px; height: 26px; font-size: 12px; }
.user-info { min-width: 0; }
.user-info > div { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.foot-btns .btn { padding: 3px 9px; font-size: 12px; }

/* ---- Check Stock landing: grouped long rows ---- */
.typelist tbody tr { cursor: pointer; }
.typelist td:first-child { white-space: normal; min-width: 220px; }
.typelist td.num { white-space: nowrap; }
.typelist tr.tl-all td { background: var(--accent-soft); color: var(--accent-ink); }
.typelist tr.tl-head td { background: var(--surface-3); border-top: 2px solid var(--border-strong); font-size: 13.5px; }
.typelist tr.tl-row td:first-child { padding-left: 28px; }
.typelist tbody tr:hover td { background: var(--accent-soft) !important; }

/* ---- Promotion: long rows ---- */
.promo-list { display: flex; flex-direction: column; gap: 8px; }
.pr-head, .pr-row { display: grid; grid-template-columns: minmax(180px, 1.1fr) 150px 170px minmax(260px, 2.4fr) 92px; gap: 14px; align-items: start; }
.promo-list:not(:has(.pr-actions)) .pr-head, .promo-list:not(:has(.pr-actions)) .pr-row { grid-template-columns: minmax(180px, 1.1fr) 150px 170px minmax(260px, 2.6fr); }
.pr-head { padding: 0 14px; font-size: 12px; color: var(--muted); font-weight: 600; }
.pr-row { padding: 12px 14px; border-left: 5px solid var(--good); }
.pr-row.soon { border-left-color: var(--warn); }
.pr-row.upcoming { border-left-color: var(--accent); }
.pr-row.ended { border-left-color: var(--border-strong); opacity: .75; }
.pr-main { display: flex; flex-direction: column; gap: 4px; align-items: flex-start; }
.pr-dates { display: flex; flex-direction: column; gap: 2px; font-size: 13px; }
.pr-left { display: flex; flex-direction: column; gap: 4px; }
.pr-left .pc-big { font-size: 17px; }
.pr-left .pc-pct { font-size: 14px; }
.pr-row.soon .pc-big { color: var(--warn); }
.pr-row.soon .pc-fill { background: var(--warn); }
.pr-row.upcoming .pc-fill { background: var(--accent); }
.pr-items { display: grid; grid-template-columns: repeat(auto-fill, minmax(250px, 1fr)); gap: 4px 12px; max-height: 172px; overflow: hidden; }
.pr-items.all { max-height: none; }
.pr-items > .btn { grid-column: 1 / -1; justify-self: start; }
.pr-item { display: flex; justify-content: space-between; gap: 8px; align-items: baseline; font-size: 12.5px; border-bottom: 1px dashed var(--border); padding: 2px 0; min-width: 0; }
.pr-iname { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; }
.pr-price { flex: none; font: inherit; font-size: 12px; background: none; border: 0; padding: 1px 4px; border-radius: 5px; cursor: pointer; color: var(--text-2); font-variant-numeric: tabular-nums; white-space: nowrap; }
.pr-price:not(.ro):hover { background: var(--accent-soft); color: var(--accent-ink); }
.pr-price.ro { cursor: default; }
.pr-list { color: var(--muted); }
.pr-promo { color: var(--bad); }
.pr-noprice { color: var(--warn); font-size: 11px; }
.pr-actions { display: flex; flex-direction: column; gap: 6px; }
/* picker in the promotion form */
.pf-filter { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; margin-bottom: 6px; }
.pf-filter .input { flex: 1; min-width: 180px; }
.pf-resbox { border: 1px solid var(--border); border-radius: 8px; overflow: hidden; }
.pf-reshead { display: flex; justify-content: space-between; align-items: center; padding: 6px 8px; background: var(--surface-2); border-bottom: 1px solid var(--border); }
.pf-list { max-height: 220px; overflow-y: auto; }
.pf-res { display: flex; gap: 8px; align-items: center; padding: 5px 10px; font-size: 13px; cursor: pointer; border-bottom: 1px solid var(--border); }
.pf-res:hover { background: var(--surface-2); }
.pf-check { width: 15px; height: 15px; border: 1.5px solid var(--border-strong); border-radius: 4px; flex: none; }
.pf-res.on { background: var(--good-soft); }
.pf-res.on .pf-check { background: var(--good); border-color: var(--good); box-shadow: inset 0 0 0 2px var(--surface); }
.pf-chips { max-height: 140px; overflow-y: auto; }
.pick-price { font-variant-numeric: tabular-nums; }
@media (max-width: 1000px) {
  .pr-head { display: none; }
  .pr-row, .promo-list:not(:has(.pr-actions)) .pr-row { grid-template-columns: 1fr 1fr; }
  .pr-main, .pr-items { grid-column: 1 / -1; }
  .pr-actions { flex-direction: row; grid-column: 1 / -1; justify-content: flex-end; }
}

/* ---- promotion: per-item discount ---- */
.pf-bulk { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; font-size: 12.5px; color: var(--text-2); background: var(--surface-2); border-radius: 8px; padding: 6px 8px; margin-bottom: 6px; }
.pf-bulk .input { padding: 3px 6px; font-size: 13px; }
.pf-chips { max-height: 300px; overflow-y: auto; border: 1px solid var(--border); border-radius: 8px; }
.pf-chips > .muted { display: block; padding: 8px; }
.pf-sel { font-size: 12.5px; }
.pf-sel td { padding: 3px 8px; vertical-align: middle; }
.pf-sel td.name { max-width: 300px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pf-disc { white-space: nowrap; }
.pf-disc .input { padding: 2px 6px; font-size: 13px; }
.pf-disc .d-val { width: 80px; text-align: right; }
.pf-sel [data-rm] { color: var(--muted); padding: 0 4px; }
.pr-off { color: var(--good); font-size: 11px; font-weight: 600; }
.pf-chips { display: block; } .pf-sel { width: 100%; }
/* user / logout sit right under the menu (no big gap for short menus); a long menu shrinks and scrolls instead */
.nav { flex: 0 1 auto; }
.sidebar-foot { margin-top: 12px; }

/* ---- Check Stock type list: resizable columns, sideways scroll, type name frozen on the left ---- */
.typelist.rzt { table-layout: fixed; }
.typelist.rzt th { white-space: normal; line-height: 1.25; vertical-align: bottom; }
.typelist.rzt td { overflow: hidden; text-overflow: ellipsis; }
.typelist td:first-child { min-width: 0; }
.typelist.rzt tr > :first-child { position: sticky; left: 0; z-index: 1; box-shadow: inset -1px 0 0 var(--border); }
.typelist.rzt thead th:first-child { z-index: 3; }
.typelist.rzt tbody td:first-child { background: var(--surface); }
.typelist.rzt tr.tl-all td:first-child { background: var(--accent-soft); }
.typelist.rzt tr.tl-head td:first-child { background: var(--surface-3); }
.typelist.rzt td:first-child { white-space: normal; overflow-wrap: anywhere; }

/* ---- Total stock ---- */
.t td.total-col { background: var(--accent-soft); }
.t tr.total td.total-col { background: var(--accent-soft); }
.t.rz tbody tr:hover td.total-col { background: var(--surface-2); }
.kv > div.kv-total { background: var(--accent-soft); border-color: var(--accent); }
.pr-stock { color: var(--muted); font-size: 11px; }

/* popover: header stays visible while the content scrolls, and it is the drag handle */
.popover { max-height: none; display: flex; flex-direction: column; overflow: hidden; }
.popover .ph { cursor: move; user-select: none; flex: none; background: var(--surface-2); border-radius: 10px 10px 0 0; touch-action: none; }
.popover .pb { overflow: auto; flex: 1 1 auto; min-height: 0; }

/* ---- collapsed FG / Body groups: only the combined row until ▸ is clicked ---- */
tbody.blk.collapsed tr:not(.total) { display: none; }
.exp { border: 0; background: var(--accent-soft); color: var(--accent-ink); border-radius: 4px; width: 18px; height: 18px; padding: 0; font-size: 10px; line-height: 18px; cursor: pointer; margin-right: 3px; vertical-align: 1px; }
.exp:hover { background: var(--accent); color: #fff; }
/* ---- row checkboxes + selection sum bar ---- */
.t.rz td.selcell, .t.rz th[data-col="sel"] { text-align: center; padding-left: 2px; padding-right: 2px; }
.rowsel, .selall { width: 15px; height: 15px; cursor: pointer; vertical-align: middle; accent-color: var(--accent); }
.selbar { position: sticky; top: 0; z-index: 6; display: flex; flex-wrap: wrap; gap: 6px 14px; align-items: center; background: var(--accent-soft); border: 1px solid var(--accent); color: var(--text); border-radius: var(--radius); padding: 7px 12px; margin-bottom: 8px; font-size: 12.5px; box-shadow: var(--shadow); }
.selbar .sb-c { display: inline-flex; gap: 5px; align-items: center; white-space: nowrap; }
.selbar b { font-variant-numeric: tabular-nums; }
.selbar .sb-total { padding-left: 10px; border-left: 1px solid var(--accent); font-size: 13px; }
.selbar #selClear { margin-left: auto; }

/* freeze checkbox + code + product name when scrolling sideways (desktop) */
@media (min-width: 801px) {
  .t.rz tr > :nth-child(2) { box-shadow: none; }
  .t.rz tr > :nth-child(3) { position: sticky; left: var(--fz2, 0px); z-index: 1; box-shadow: inset -1px 0 0 var(--border-strong); }
  .t.rz th:nth-child(3) { z-index: 3; }
  .t.rz td:nth-child(3) { background: var(--surface); }
  .t.rz tr.total td:nth-child(3) { background: var(--row-total); }
  .t.rz tr.body td:nth-child(3) { background: var(--row-body); }
  .t.rz tbody tr:hover td:nth-child(3) { background: var(--surface-2); }
}

/* ---- Reserve Item ---- */
.rv-teams { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 8px; margin-bottom: 12px; }
.rv-team { text-align: left; background: var(--surface); border: 1px solid var(--border); border-left: 4px solid var(--accent); border-radius: 10px; padding: 8px 12px; cursor: pointer; font: inherit; color: inherit; }
.rv-team:hover { border-color: var(--accent); }
.rv-team.on { background: var(--accent-soft); border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent) inset; }
.rv-team.noteam { border-left-color: var(--warn); }
.rv-team.noteam .rv-name { color: var(--warn); }
.rv-name { font-weight: 600; font-size: 13.5px; line-height: 1.3; }
.rv-code { font-size: 11.5px; color: var(--muted); }
.rv-num { margin-top: 4px; font-variant-numeric: tabular-nums; }
.rv-table tr.rv-head td { background: var(--surface-3); border-top: 2px solid var(--border-strong); }
.rv-table td.name { white-space: normal; }

/* search: matching product types */
.type-hits { margin-bottom: 10px; }
.type-hits .card-b { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; padding: 10px 12px; }
.type-hit { text-decoration: none; cursor: pointer; }
.type-hit:hover { border-color: var(--accent); }
/* Reserve Item: sortable headers */
.rv-table th.sortable { cursor: pointer; user-select: none; white-space: nowrap; }
.rv-table th.sortable:hover { color: var(--accent-ink); }
/* Promotion sales channels */
.pf-chans { display: flex; flex-wrap: wrap; gap: 6px; }
.chk-chip { display: inline-flex; align-items: center; gap: 6px; padding: 4px 10px; border: 1px solid var(--border-strong); border-radius: 999px; cursor: pointer; font-size: 13px; }
.chk-chip:has(input:checked) { border-color: var(--accent); background: var(--accent-soft, rgba(37, 99, 235, .08)); color: var(--accent-ink); font-weight: 600; }
.pr-chans { display: flex; flex-wrap: wrap; gap: 4px; margin: 4px 0; }
.filters .seg { display: inline-flex; background: var(--surface-3); border-radius: 10px; padding: 3px; gap: 2px; }
.filters .seg a { padding: 5px 12px; border-radius: 8px; color: var(--text-2); font-size: 13px; text-decoration: none; }
.filters .seg a.on { background: var(--surface); color: var(--text); box-shadow: 0 1px 3px rgba(0,0,0,.1); font-weight: 600; }

/* ---------- v7 ---------- */
/* ticked rows: strong highlight (also on the frozen code/name cells); clicking a row ticks it */
:root { --sel-bg: #ffe08a; --sel-line: #d99a00; }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) { --sel-bg: #5a4508; --sel-line: #e6b04a; } }
:root[data-theme="dark"] { --sel-bg: #5a4508; --sel-line: #e6b04a; }
.t tbody tr:has(> td > .rowsel:checked) > td { background: var(--sel-bg) !important; }
.t tbody tr:has(> td > .rowsel:checked) > td:first-child { box-shadow: inset 4px 0 0 var(--sel-line); }
.t tbody tr:has(> td > .rowsel) { cursor: pointer; }
.sv-col { color: var(--accent-ink); }
/* Product Alert tag colours: Non Move / Z-TOUCH */
.chip.nm, .tagchip.nm { background: #ece4fb; color: #5b3fb5; }
.chip.zt, .tagchip.zt { background: #dff4f1; color: #0f766e; }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .chip.nm, :root:not([data-theme="light"]) .tagchip.nm { background: #2c2347; color: #b9a4f2; } :root:not([data-theme="light"]) .chip.zt, :root:not([data-theme="light"]) .tagchip.zt { background: #12302c; color: #6fd6c8; } }
.chip.off { opacity: .55; text-decoration: line-through; }
.chips { display: flex; flex-wrap: wrap; gap: 5px; }
.neg { color: var(--bad); font-weight: 600; }
.page-head .seg { display: inline-flex; background: var(--surface-3); border-radius: 10px; padding: 3px; gap: 2px; }
.page-head .seg a { padding: 5px 12px; border-radius: 8px; color: var(--text-2); font-size: 13px; text-decoration: none; }
.page-head .seg a.on { background: var(--surface); color: var(--text); box-shadow: 0 1px 3px rgba(0,0,0,.1); font-weight: 600; }
a.pstat { color: inherit; text-decoration: none; cursor: pointer; }
.pstat.bad { border-left-color: var(--bad); }
.pstat.sel { outline: 2px solid var(--accent); }
/* view-as banner */
.simbar { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; padding: 8px 20px; background: #5b3fb5; color: #fff; font-size: 13px; }
.simbar svg { width: 18px; height: 18px; }
.simbar .btn { margin-left: auto; background: #fff; color: #5b3fb5; border-color: #fff; }
.sim-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(320px, 1fr)); gap: 14px; }
.sim-card .btn svg { width: 16px; height: 16px; vertical-align: -3px; }
/* role matrix */
.role-matrix th.rm-role { min-width: 130px; vertical-align: top; }
.role-matrix .rl-label { width: 100%; font-weight: 600; }
.role-matrix .rm-sec td { background: var(--surface-3); font-weight: 700; font-size: 12px; text-transform: none; position: sticky; left: 0; }
.role-matrix td.rm-cell { text-align: center; }
.role-matrix td.rm-cell input { width: 18px; height: 18px; cursor: pointer; }
.role-matrix tbody tr:hover td { background: var(--surface-2); }
/* Intelligence Search: every answer in a clear frame */
.isearch-form { display: flex; gap: 10px; align-items: stretch; }
.isearch-form textarea { flex: 1; resize: vertical; min-height: 56px; font-size: 15px; }
.isearch-form .btn { white-space: nowrap; }
.isearch-form .btn svg, .ai-a .btn svg { width: 16px; height: 16px; vertical-align: -3px; }
.ai-box { border: 2px solid var(--border-strong); border-radius: 14px; background: var(--surface); margin-bottom: 14px; overflow: hidden; }
.ai-box.ai { border-color: var(--accent); }
.ai-box.keyword { border-color: var(--good); }
.ai-box.limit, .ai-box.none { border-color: var(--warn); }
.ai-box.error { border-color: var(--bad); }
.ai-q { padding: 10px 14px; background: var(--surface-2); border-bottom: 1px solid var(--border); font-weight: 600; }
.ai-who { display: inline-block; font-size: 11px; font-weight: 500; color: var(--text-2); margin-right: 8px; text-transform: uppercase; }
.ai-a { padding: 12px 14px; }
.ai-head { display: flex; gap: 10px; align-items: center; margin-bottom: 8px; }
.ai-msg { white-space: pre-wrap; line-height: 1.65; font-size: 14px; }
.ai-a .sp-sub { margin-top: 12px; }
.ai-a .table-wrap { border: 1px solid var(--border); border-radius: 8px; max-height: 380px; }
.ai-set label { display: flex; flex-direction: column; gap: 4px; margin-bottom: 12px; font-size: 13px; }
.ai-set label.sw-line { flex-direction: row; align-items: center; gap: 10px; }
/* water filters: list + detail */
.fl-grid { display: grid; grid-template-columns: minmax(300px, 420px) 1fr; gap: 14px; align-items: start; }
.fl-row { cursor: pointer; }
.fl-row.on td { background: var(--accent-soft) !important; }
#flDetail, #fpDetail { position: sticky; top: 10px; max-height: calc(100vh - 120px); overflow: auto; }
.fp-cat { font-weight: 600; margin: 10px 0 4px; }
@media (max-width: 800px) {
  .fl-grid { grid-template-columns: 1fr; }
  #flDetail, #fpDetail { position: static; max-height: none; scroll-margin-top: 60px; }
  .fl-grid > .card:first-child .table-wrap { max-height: 42vh !important; }
  .isearch-form { flex-direction: column; }
  .simbar { padding: 8px 16px; }
}

/* ================= v8: cleaner look ================= */
/* calmer neutral palette (cool grey + one blue), softer cards, lighter table lines */
:root {
  --bg: #f5f6f8; --surface: #ffffff; --surface-2: #f8fafc; --surface-3: #eef1f5;
  --border: #e5e8ee; --border-strong: #d3d8e0; --text: #111827; --text-2: #4b5563; --muted: #8a93a3;
  --accent: #2563eb; --accent-ink: #1d4ed8; --accent-soft: #e8efff;
  --row-total: #f1f5ff; --row-body: #fafbfc;
  --shadow: 0 1px 2px rgba(16,24,40,.04), 0 1px 3px rgba(16,24,40,.06);
  --radius: 12px;
}
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) { --bg: #0f1115; --surface: #171a21; --surface-2: #1c2029; --surface-3: #252a35; --border: #2a303b; --border-strong: #3a4250; --text: #eef0f4; --text-2: #b7bdc8; --muted: #8790a0; --accent: #4f8bff; --accent-ink: #9dbcff; --accent-soft: #1b2944; --row-total: #18223a; --row-body: #161a21; } }
:root[data-theme="dark"] { --bg: #0f1115; --surface: #171a21; --surface-2: #1c2029; --surface-3: #252a35; --border: #2a303b; --border-strong: #3a4250; --text: #eef0f4; --text-2: #b7bdc8; --muted: #8790a0; --accent: #4f8bff; --accent-ink: #9dbcff; --accent-soft: #1b2944; --row-total: #18223a; --row-body: #161a21; }
.brand-logo { width: 30px; height: 30px; flex: none; border-radius: 9px; }
.brand-logo.sm { width: 24px; height: 24px; margin-right: 6px; vertical-align: -6px; }
.login-logo { width: 52px; height: 52px; border-radius: 14px; }
.nav a { border-radius: 8px; position: relative; }
.nav a.active { background: var(--accent-soft); color: var(--accent-ink); }
.nav a.active::before { content: ""; position: absolute; left: -10px; top: 6px; bottom: 6px; width: 3px; border-radius: 0 3px 3px 0; background: var(--accent); }
.page-head h1 { font-size: 21px; font-weight: 700; }
.btn svg { width: 16px; height: 16px; }
/* table: header on white with a stronger line, quieter row lines, numbers tabular & right, badges centred */
.t th { background: var(--surface); color: var(--muted); font-weight: 600; font-size: 12px; border-bottom: 1px solid var(--border-strong); }
.t td.center, .t th.center { text-align: center; }
body.comfortable .t.rz td { padding-top: 11px; padding-bottom: 11px; font-size: 13.5px; }
body.comfortable .t.rz th { padding-top: 11px; padding-bottom: 11px; }
/* list toolbar: filters + display settings side by side */
.list-toolbar { display: flex; gap: 8px; margin-bottom: 10px; flex-wrap: wrap; }
.list-toolbar .filters-toggle { margin: 0; width: auto; }
@media (max-width: 800px) { .list-toolbar .btn { flex: 1; justify-content: center; } }
/* badges under the product code: alert tags + movement */
.code-badges { display: flex; flex-wrap: wrap; gap: 3px; margin-top: 3px; font-weight: 500; }
.code-badges .chip { font-size: 10.5px; padding: 0 6px; line-height: 17px; }
.mv { display: inline-block; font-size: 10.5px; line-height: 17px; padding: 0 7px; border-radius: 999px; font-weight: 600; letter-spacing: .02em; }
.mv-fast { background: #dcfce7; color: #15803d; }
.mv-normal { background: #e0ecff; color: #1d4ed8; }
.mv-slow { background: #fef3c7; color: #a16207; }
.mv-dead { background: #f3f4f6; color: #4b5563; }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .mv-fast { background: #12301f; color: #6ee7a0; } :root:not([data-theme="light"]) .mv-normal { background: #1b2944; color: #9dbcff; } :root:not([data-theme="light"]) .mv-slow { background: #33280f; color: #f3c75a; } :root:not([data-theme="light"]) .mv-dead { background: #252a35; color: #b7bdc8; } }
/* substitute-product icon button */
.alt-btn { border: 1px solid var(--border); background: var(--surface); border-radius: 8px; width: 30px; height: 26px; display: inline-grid; place-items: center; cursor: pointer; color: var(--text-2); padding: 0; }
.alt-btn:hover { border-color: var(--accent); color: var(--accent-ink); background: var(--accent-soft); }
.alt-btn svg { width: 16px; height: 16px; }
/* column chooser */
.cc { padding: 10px 12px; min-width: 280px; }
.cc-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 4px 12px; }
.cc-item { display: flex; gap: 6px; align-items: center; font-size: 13px; cursor: pointer; }
.cc-seg { display: inline-flex; background: var(--surface-3); border-radius: 10px; padding: 3px; gap: 2px; }
.cc-seg a { padding: 4px 12px; border-radius: 8px; color: var(--text-2); font-size: 13px; }
.cc-seg a.on { background: var(--surface); color: var(--text); box-shadow: 0 1px 3px rgba(0,0,0,.1); font-weight: 600; }
.cc-foot { display: flex; gap: 6px; justify-content: flex-end; margin-top: 12px; flex-wrap: wrap; }
/* filters: totals of the filter set */
.fl-sum { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-bottom: 12px; }
.fl-sum > div { background: var(--surface-2); border: 1px solid var(--border); border-radius: 10px; padding: 8px 12px; display: flex; flex-direction: column; }
.fl-sum b { font-size: 20px; font-variant-numeric: tabular-nums; }
.fl-sum .promo { border-color: var(--good); background: var(--good-soft); }
.fl-sum .promo b, .pr-promo-cell b { color: var(--good); }
/* Intelligence Search: choose before using the AI */
.ai-confirm { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 12px; }
.ai-box.confirm { border-color: var(--warn); }
/* match page summary */
.match-sum { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-bottom: 14px; }
.match-sum .ms { background: var(--surface); border: 1px solid var(--border); border-left: 4px solid var(--warn); border-radius: var(--radius); padding: 12px 16px; color: inherit; text-decoration: none; }
.match-sum .ms .n { font-size: 26px; font-weight: 700; }
.match-sum .ms .l { font-size: 13px; color: var(--text-2); }
.match-sum a.ms:hover, .match-sum .ms.sel { border-color: var(--accent); }
@media (max-width: 800px) { .match-sum, .fl-sum { grid-template-columns: 1fr; } }
/* feedback button (every page) */
.fb-fab { position: fixed; right: 18px; bottom: 18px; z-index: 50; display: inline-flex; align-items: center; gap: 8px; border: 0; border-radius: 999px; padding: 10px 16px 10px 12px;
  background: var(--accent); color: #fff; box-shadow: 0 6px 20px rgba(37,99,235,.35); cursor: pointer; font-weight: 600; }
.fb-fab svg { width: 20px; height: 20px; }
.fb-fab:hover { filter: brightness(1.08); }
@media (max-width: 800px) { .fb-fab span { display: none; } .fb-fab { padding: 12px; } }
.modal h3 svg { width: 20px; height: 20px; vertical-align: -4px; }
.fb-l { display: flex; flex-direction: column; gap: 4px; margin-bottom: 10px; font-size: 13px; }
.fb-l textarea { resize: vertical; }
.fb-mine { padding: 4px 0; border-bottom: 1px dashed var(--border); }
.sec-q { padding: 8px 10px; border-radius: 8px; background: var(--surface-2); border: 1px solid var(--border); font-weight: 600; }
/* user manual */
.man-toc { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 14px; position: sticky; top: 0; z-index: 5; background: var(--bg); padding: 6px 0; }
.man-toc a { padding: 6px 12px; border-radius: 999px; background: var(--surface); border: 1px solid var(--border); font-size: 13px; }
.man-sec { margin-bottom: 18px; scroll-margin-top: 50px; }
.man-sec h3 { font-size: 15px; margin: 18px 0 8px; }
.man-sec h3:first-child { margin-top: 4px; }
.man-shot { margin: 0 0 8px; }
.man-shot img { width: 100%; max-width: 1100px; border: 1px solid var(--border); border-radius: 10px; display: block; box-shadow: var(--shadow); }
.man-shot figcaption { font-size: 12px; color: var(--muted); margin-top: 4px; }
.man-steps { margin: 6px 0 12px; padding-left: 0; list-style: none; counter-reset: st; }
.man-steps li { counter-increment: st; position: relative; padding: 4px 0 4px 34px; line-height: 1.6; }
.man-steps li::before { content: counter(st); position: absolute; left: 0; top: 4px; width: 24px; height: 24px; border-radius: 50%; background: #e11d48; color: #fff; font-weight: 700; font-size: 13px; display: grid; place-items: center; }
.man-legend { line-height: 2.2; }
.man-legend .mv { margin: 0 4px 0 10px; }
.man-cats td { vertical-align: top; }

@media (min-width: 801px) { .fl-grid { grid-template-columns: minmax(280px, 360px) 1fr; } }
.fl-parts td.name { min-width: 160px; }

/* ================= v9 ================= */
/* highlighted columns: พร้อมขาย (green) and Total stock (blue), header included */
.t td.ready-col { background: #ecfdf3; color: #166534; font-weight: 600; }
.t th.ready-col { background: #dcfce7; color: #166534; }
.t td.total-col { background: #e8efff; color: #1e3a8a; font-weight: 700; }
.t th.total-col { background: #dbe6ff; color: #1e3a8a; }
.t tr.total td.ready-col { background: #d1fadf; }
.t tr.total td.total-col { background: #d4e2ff; }
.t.rz tbody tr:hover td.ready-col { background: #d1fadf; }
.t.rz tbody tr:hover td.total-col { background: #d4e2ff; }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .t td.ready-col, :root:not([data-theme="light"]) .t th.ready-col { background: #12301f; color: #86efac; } :root:not([data-theme="light"]) .t td.total-col, :root:not([data-theme="light"]) .t th.total-col { background: #1b2944; color: #bfd3ff; } }
/* Clearance tag */
.chip.clr, .tagchip.clr { background: #ffedd5; color: #c2410c; }
.good-t { color: var(--good); font-weight: 600; }
.bad-t { color: var(--bad); font-weight: 600; }
/* หน้าแรก */
.home-grid { display: grid; grid-template-columns: 1fr 1fr 1.3fr; gap: 14px; margin-bottom: 16px; }
.hc { padding: 14px 16px; border-top: 4px solid var(--border-strong); }
.hc.clr { border-top-color: #ea580c; }
.hc.nm { border-top-color: #7c3aed; }
.hc-h { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.hc-n { font-size: 32px; font-weight: 700; margin: 8px 0 0; font-variant-numeric: tabular-nums; }
.hc-n small { font-size: 14px; font-weight: 500; color: var(--muted); }
.hc-cmps { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-top: 12px; }
.hc-cmp { display: flex; flex-direction: column; gap: 2px; padding: 8px 10px; border-radius: 10px; background: var(--surface-2); border: 1px solid var(--border); }
.hc-cmp.better { background: var(--good-soft); border-color: transparent; color: var(--good); }
.hc-cmp.worse { background: var(--bad-soft); border-color: transparent; color: var(--bad); }
.hc-cmp b { font-size: 15px; }
.hc-chart .card-b { padding-top: 0; }
.home-t td.name { max-width: 340px; }
@media (max-width: 1100px) { .home-grid { grid-template-columns: 1fr 1fr; } .hc-chart { grid-column: 1 / -1; } }
@media (max-width: 800px) { .home-grid { grid-template-columns: 1fr; } }
/* Dead Stock movement */
.trend-cell svg { vertical-align: middle; margin-right: 4px; }
.trend-cell .good-t, .trend-cell .bad-t { stroke: currentColor; }
