:root {
  color-scheme: light;
  color: #202b3d;
  background: #f1f4f9;
  font: 14px/1.5 "Malgun Gothic", system-ui, sans-serif;
  --surface: #fff;
  --border: #dbe2ed;
  --control-border: #cbd5e3;
  --row-border: #e5eaf2;
  --accent: #344ec2;
  --accent-light: #eef0ff;
  --table-head: #f5f7fb;
  --muted: #59687d;
  --sidebar: #1a2943;
  --bar: 60px;
  --nav-width: 196px;
}
[hidden] { display: none !important; }
body.history { min-height: 100vh; margin: 0; }
.app-header {
  position: sticky; top: 0; z-index: 5;
  min-height: var(--bar);
  padding: 8px 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}
.brand, .header-actions { display: flex; align-items: center; gap: 9px; }
.brand img { display: block; flex: none; }
.header-actions { flex-wrap: wrap; justify-content: flex-end; }
.workspace-shell { display: grid; grid-template-columns: var(--nav-width) minmax(0, 1fr); min-height: calc(100dvh - var(--bar)); }
.workspace-sidebar {
  position: sticky; top: var(--bar); align-self: start; min-height: calc(100dvh - var(--bar));
  max-height: calc(100dvh - var(--bar)); overflow: auto; background: var(--sidebar);
}
.workspace-nav { display: grid; gap: 4px; padding: 22px 12px; }
.workspace-nav a {
  display: flex; align-items: center; gap: 10px; min-height: 40px; padding: 7px 10px;
  color: #e3eaf5; border: 1px solid transparent; border-radius: 7px; font-weight: 700; text-decoration: none;
}
.workspace-nav a:hover { color: #fff; background: #2a3d5e; }
.workspace-nav a[aria-current="page"] { background: #dce7ff; color: #172e75; border-color: #dce7ff; }
.menu-icon { position: relative; width: 14px; height: 14px; flex: 0 0 14px; border: 1px solid currentColor; border-radius: 3px; opacity: .85; }
.icon-history::before, .icon-history::after, .icon-orders::before, .icon-changes::before, .icon-stock::before { content: ""; position: absolute; }
.icon-history::before { top: 5px; inset-inline: 0; border-top: 1px solid; }
.icon-history::after { left: 5px; inset-block: 0; border-left: 1px solid; }
.icon-orders::before { inset: 3px 2px auto; border-top: 1px solid; border-bottom: 1px solid; height: 3px; }
.icon-changes::before { inset: 3px 2px 4px; border-top: 1px solid; border-right: 1px solid; transform: rotate(-28deg); }
.icon-stock::before { inset: 4px 0 auto; border-top: 1px solid; }
.workspace-content { min-width: 0; padding: 22px clamp(16px, 2.6vw, 40px) 28px; }
.history h1, .history h2, .history h3 { margin: 0; line-height: 1.35; letter-spacing: -.035em; }
.history h1, .history dialog h2 { font-size: 18px; }
.history .workspace-heading { margin: 0 0 15px; font-size: clamp(22px, 2.4vw, 27px); }
.history h3 { font-size: 16px; }
.history p { margin: 0; }
.history button, .history input:not([type="checkbox"]) {
  min-height: 36px;
  border: 1px solid var(--control-border);
  border-radius: 6px;
  padding: 7px 10px;
  background: var(--surface);
  color: #202b3d;
  font: inherit;
}
.history button { flex: none; font-weight: 700; cursor: pointer; }
.history button:disabled { cursor: default; opacity: .45; }
.history button:not(:disabled):hover { background: var(--table-head); border-color: #8b9cc5; }
.history :is(button, input, summary, a):focus-visible { outline: 2px solid #516ff1; outline-offset: 2px; }
.history :is(button.primary, .settings-tabs button[aria-pressed="true"], .match-tabs button[aria-pressed="true"]) {
  border-color: var(--accent);
  color: #fff;
  background: var(--accent);
}
.history :is(button.primary, .settings-tabs button[aria-pressed="true"], .match-tabs button[aria-pressed="true"]):not(:disabled):hover {
  background: #273da4; border-color: #273da4;
}
.section-top, .staff-heading { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.panel { padding: 18px; margin-bottom: 13px; border: 1px solid var(--border); border-radius: 10px; background: var(--surface); }
.filters { display: flex; flex-wrap: wrap; align-items: end; gap: 9px 12px; padding: 13px 16px; }
.history label { display: grid; gap: 5px; font-size: 13px; font-weight: 700; }
.search { flex: 0 1 535px; min-width: 0; }
.search-fields { display: flex; gap: 8px; margin-top: 5px; }
.search-fields input { flex: 1; min-width: 0; }
.history .check { display: flex; align-items: center; gap: 7px; min-height: 37px; }
.history .check input { accent-color: var(--accent); margin: 0; }
#message:not(:empty), #stock-status:not(:empty) { margin: 0 0 14px; color: var(--muted); }
#total { margin-left: 6px; color: var(--accent); font-size: 13px; font-weight: 700; }
.order-table, .match-table { overflow: auto; margin-top: 14px; }
.history table { width: 100%; border-collapse: collapse; text-align: left; font-size: 13px; }
.order-table table { min-width: 630px; }
.history th, .history td { padding: 10px 9px; border-bottom: 1px solid var(--row-border); vertical-align: top; text-align: left; }
.history th { background: var(--table-head); white-space: nowrap; }
.history tr:last-child td { border-bottom: 0; }
.history[data-view="changes"] .order-table th:nth-child(2) { width: 43%; }
.history[data-view="changes"] .order-table th:nth-child(4) { width: 24%; }
.history[data-view="stock"] .order-table table { min-width: 0; }
.history[data-view="stock"] .order-table th:last-child { width: 18%; }
.products { min-width: 200px; overflow-wrap: anywhere; }
.product-list { margin: 0; padding: 0; list-style: none; }
.product-list li + li { margin-top: 4px; }
.quantity { white-space: nowrap; font-variant-numeric: tabular-nums; }
.snapshot-banner {
  display: flex; flex-wrap: wrap; gap: 4px 14px; padding: 10px 14px;
  margin-bottom: 13px; border: 1px solid #e9dcc5; border-radius: 8px;
  background: #fffbf2; color: #5f4921; font-size: 13px;
}
.dispatch-summary { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; margin-bottom: 13px; }
.history .dispatch-summary button { display: grid; gap: 5px; padding: 14px; text-align: left; white-space: normal; }
.history .dispatch-summary button[aria-pressed="true"] { background: var(--accent-light); border-color: #a5b4e8; }
.dispatch-summary strong { color: var(--accent); font-size: 22px; }
.order-number { white-space: nowrap; color: var(--accent); font-weight: 700; text-underline-offset: 3px; }
.history .muted { color: var(--muted); }
.history .address { margin-top: 3px; overflow-wrap: anywhere; }
.size { display: inline-block; white-space: nowrap; border-radius: 5px; padding: 2px 8px; background: var(--accent-light); color: var(--accent); font-weight: 700; }
.history-cell summary { width: fit-content; cursor: pointer; color: var(--accent); font-weight: 700; }
.events { display: grid; gap: 6px; list-style: none; margin: 8px 0 0; padding: 0; }
.events li { padding: 7px 9px; border-radius: 7px; background: var(--table-head); overflow-wrap: anywhere; }
.size-change { font-weight: 700; }
.history td.empty { padding: 20px 9px 12px; color: var(--muted); }
#pages { display: flex; align-items: center; justify-content: center; gap: 10px; margin-top: 16px; }
.history dialog {
  width: min(600px, calc(100% - 32px));
  max-height: 85vh;
  padding: 20px;
  border: 1px solid var(--border);
  border-radius: 12px;
  color: inherit;
}
#settings-dialog { width: min(820px, calc(100% - 32px)); }
.history dialog::backdrop { background: #122a38ad; }
.settings-tabs, .match-tabs { display: flex; flex-wrap: wrap; gap: 8px; margin: 14px 0; }
:is(#stock-account-form, #cafe-account-form) { display: flex; align-items: end; flex-wrap: wrap; gap: 12px; margin-top: 12px; }
:is(#stock-account-form, #cafe-account-form) label { flex: 1 1 170px; }
:is(#stock-account-form, #cafe-account-form) input { width: 100%; }
#match-form, #password-form { display: grid; gap: 10px; }
#password-form input { width: 100%; }
#password-message:not(:empty) { margin-top: 12px; color: var(--muted); }
#match-form input { min-width: 0; }
.match-quantity { width: 120px; }
.match-actions { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 6px; }
.match-table table { min-width: 500px; }
.ratio { white-space: nowrap; }
#stock-account-message:not(:empty), #cafe-account-message:not(:empty), #staff-message:not(:empty), #match-message:not(:empty) { margin-top: 12px; color: var(--muted); }
.staff-group { margin-top: 15px; }
.staff-group h3 { margin: 0 0 7px; font-size: 14px; }
.staff-group ul { list-style: none; margin: 0; padding: 0; border: 1px solid var(--border); border-radius: 8px; }
.staff-group li { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 12px; padding: 8px 11px; overflow-wrap: anywhere; }
.staff-group li + li { border-top: 1px solid var(--row-border); }
.staff-actions { display: flex; flex-wrap: wrap; gap: 6px; margin-left: auto; }
.history .staff-actions button { min-height: 30px; padding: 3px 8px; font-size: 13px; }
.history .staff-remove-button { color: #942f2b; }
.staff-remove-form { display: grid; gap: 10px; margin-top: 14px; padding: 14px; border: 1px solid #ebc9bf; border-radius: 8px; }
.staff-remove-form h3 { margin: 0; }
#staff-remove-target { font-weight: 700; overflow-wrap: anywhere; }
#staff-remove-help { color: var(--muted); }
.history button.danger { background: #942f2b; border-color: #942f2b; color: #fff; }
@media (max-width: 760px) {
  .app-header { position: static; align-items: start; padding: 10px 14px; flex-wrap: wrap; }
  .header-actions { justify-content: flex-start; }
  .workspace-shell { grid-template-columns: minmax(0, 1fr); }
  .workspace-sidebar { position: static; min-height: 0; max-height: none; }
  .workspace-nav { display: flex; gap: 8px; padding: 8px 12px; overflow-x: auto; }
  .workspace-nav a { flex: none; white-space: nowrap; }
  .workspace-content { padding: 16px 12px 24px; }
  .panel { padding: 12px; }
  .search { flex: 1 1 100%; }
  .filters { gap: 8px; }
  .history[data-view="changes"] .order-table th:nth-child(2) { width: 37%; }
}

#matching-settings { max-width: 1100px; }
#matching-settings #match-form input:not([type="checkbox"]) { width: 100%; }
.icon-matching::before { content: ""; position: absolute; inset: 3px 2px; border-top: 1px solid; border-bottom: 1px solid; }

/* Product matching workspace */
#matching-settings { max-width: none; }
#matching-settings .match-heading { display:flex; align-items:center; justify-content:space-between; gap:16px; margin-bottom:18px; }
.match-stats { display:grid; grid-template-columns:repeat(3,minmax(0,1fr)); gap:14px; }
.match-stats .panel { padding:18px 22px; display:grid; gap:8px; }
.match-stats span { color:var(--muted); font-weight:700; font-size:13px; }
.match-stats strong { color:var(--accent); font-size:26px; line-height:1.3; letter-spacing:-.04em; }
.match-list-panel { padding:20px; }
.match-toolbar { display:flex; align-items:end; justify-content:space-between; gap:20px; flex-wrap:wrap; }
.match-search-label { flex:0 1 480px; min-width:0; }
.match-search-label input { box-sizing:border-box; width:100%; }
#matching-settings .match-tabs { margin:18px 0 0; }
#matching-settings .match-table { border:1px solid var(--border); border-radius:8px; }
#matching-settings .match-table table { min-width:720px; }
#matching-settings th:nth-child(1) { width:40%; }
#matching-settings th:nth-child(2) { width:32%; }
#matching-settings th:last-child { text-align:right; }
#matching-settings td { vertical-align:middle; overflow-wrap:anywhere; }
#matching-settings td:first-child { font-weight:600; }
#matching-settings tbody tr:hover { background:#f8faff; }
.match-type { display:inline-block; white-space:nowrap; padding:3px 8px; border-radius:5px; background:#eef2f7; color:#52627b; font-size:12px; }
.match-type.manual { background:var(--accent-light); color:var(--accent); }
#matching-settings .match-actions button { min-height:30px; font-size:12px; padding:4px 9px; white-space:nowrap; }
#matching-settings .match-empty { text-align:center; padding:32px; font-weight:400; }
.match-footer { display:flex; flex-wrap:wrap; justify-content:space-between; align-items:center; gap:12px; padding-top:16px; }
#match-pagination { display:flex; align-items:center; gap:12px; }
#match-dialog { width:min(650px,calc(100% - 32px)); }
#match-dialog #match-form { margin-top:20px; gap:14px; }
#match-dialog #match-form input { box-sizing:border-box; width:100%; }
#match-dialog-message:not(:empty) { margin-top:12px; color:var(--muted); }
@media(max-width:760px) { .match-stats { gap:7px; } .match-stats .panel { padding:12px; } .match-stats strong { font-size:20px; } .match-list-panel { padding:12px; } #matching-settings .match-heading { flex-wrap:wrap; } }

:is(#stock-mode, #match-enabled)[aria-checked="true"] { color: var(--accent); border-color: var(--accent); font-weight: 700; }
:is(#stock-mode, #match-enabled)[aria-checked="false"] { color: #64748b; background: #f1f5f9; font-weight: 700; }
#stock-refresh:disabled { opacity: .5; cursor: not-allowed; }

:is(#stock-mode, #match-enabled) { display: inline-flex; align-items: center; gap: 7px; }
:is(#stock-mode, #match-enabled)::after { content: ''; display: inline-block; width: 28px; height: 16px; border-radius: 99px; background: radial-gradient(circle at 8px 8px, white 0 5px, transparent 5.5px), #94a3b8; }
:is(#stock-mode, #match-enabled)[aria-checked="true"]::after { background: radial-gradient(circle at 20px 8px, white 0 5px, transparent 5.5px), var(--accent); }

/* Dedicated master-only membership page */
.staff-page { display:grid; gap:16px; width:100%; }
.staff-page .panel { min-width:0; }
.staff-feature-panel h3, .staff-list-panel > h3 { margin:0 0 10px; font-size:16px; }
.staff-feature-table { overflow-x:auto; }
.staff-feature-table table { width:100%; min-width:460px; border-collapse:collapse; }
.staff-feature-table th, .staff-feature-table td { padding:12px 14px; text-align:left; border-bottom:1px solid var(--row-border); }
.staff-feature-table thead { background:#f1f5f9; }
.staff-feature-toggle { display:inline-flex; align-items:center; gap:7px; min-width:72px; font-weight:700; }
.staff-feature-toggle[aria-checked=true] { color:var(--accent); border-color:var(--accent); }
.staff-feature-toggle::after { content:''; width:28px; height:16px; border-radius:99px; background:radial-gradient(circle at 8px 8px, white 0 5px, transparent 5.5px), #94a3b8; }
.staff-feature-toggle[aria-checked=true]::after { background:radial-gradient(circle at 20px 8px, white 0 5px, transparent 5.5px), var(--accent); }
.staff-effective { display:block; color:var(--muted); font-size:12px; margin-top:4px; }
.staff-effective.is-on { color:#23724c; }
.icon-staff::before { content:''; position:absolute; width:5px; height:5px; border:1px solid; border-radius:50%; top:1px; left:3px; }
.icon-staff::after { content:''; position:absolute; width:8px; height:4px; border:1px solid; border-radius:5px 5px 0 0; bottom:1px; left:1px; }
