:root {
  --bg: #f8f8fb;
  --surface: #ffffff;
  --surface-2: #f8f9fa;
  --border: #eff2f7;
  --border-strong: #ced4da;
  --text: #495057;
  --heading: #343a40;
  --muted: #74788d;
  --faint: #a6b0cf;
  --primary: #556ee6;
  --primary-hover: #4458b8;
  --primary-soft: #e6eafc;
  --on-primary: #ffffff;
  --sidebar: #2a3042;
  --sidebar-text: #a6b0cf;
  --sidebar-head: #6a7187;
  --sidebar-active: #ffffff;
  --ok: #34c38f; --ok-soft: #dcf5eb;
  --warn: #f1b44c; --warn-soft: #fdf2dd; --warn-text: #a66a00;
  --bad: #f46a6a; --bad-soft: #fde4e4; --bad-text: #c93c3c;
  --neutral: #74788d; --neutral-soft: #eff2f7;
  --col-body: #f1f1f4;
  --shadow: 0 1px 3px rgba(18, 38, 63, .06);
  --radius: 6px;
  --font: "Poppins", ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, "SF Mono", "Cascadia Mono", Menlo, Consolas, monospace;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #222736; --surface: #2a3042; --surface-2: #2e3548; --border: #353c50; --border-strong: #4a5268;
    --text: #c3cbe4; --heading: #f1f3f9; --muted: #a6b0cf; --faint: #7c86a8;
    --primary: #7a8ff0; --primary-hover: #94a5f5; --primary-soft: #343d63; --on-primary: #141a33;
    --sidebar: #1f2433; --sidebar-text: #a6b0cf; --sidebar-head: #6a7187;
    --ok-soft: #1d4a3c; --warn-soft: #4f3f1c; --warn-text: #f1b44c; --bad-soft: #522d33; --bad-text: #f79a9a;
    --neutral-soft: #353c50; --col-body: #252b3b;
    --shadow: none;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { background: var(--bg); color: var(--text); font: 13.5px/1.5 var(--font); -webkit-font-smoothing: antialiased; }
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3 { margin: 0; line-height: 1.25; color: var(--heading); }
h1 { font-size: 16px; font-weight: 600; text-transform: uppercase; letter-spacing: .01em; }
h2 { font-size: 15px; font-weight: 600; }
h3 { font-size: 13px; font-weight: 600; }
svg.ic { flex-shrink: 0; vertical-align: -3px; }
.mono { font-family: var(--mono); font-size: 12.5px; }
.muted { color: var(--muted); }
.faint { color: var(--faint); }
.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.center { text-align: center; }
.nowrap { white-space: nowrap; }
.pos-val { color: var(--ok); }
.neg-val { color: var(--bad-text); }
.warn-txt { color: var(--warn-text); }

/* shell */
.shell { display: flex; min-height: 100vh; }
.sidebar { width: 232px; flex-shrink: 0; background: var(--sidebar); color: var(--sidebar-text); padding: 0 0 24px; position: sticky; top: 0; height: 100vh; overflow-y: auto; transition: margin-left .2s; }
body.nav-collapsed .sidebar { margin-left: -232px; }
.brand { display: flex; gap: 10px; align-items: center; color: #fff; padding: 20px 24px 14px; text-decoration: none !important; }
.brand-mark { width: 28px; height: 28px; border-radius: 7px; background: #556ee6; color: #fff; display: grid; place-items: center; }
.brand-mark svg { width: 18px; height: 18px; }
.brand-name { font-size: 17px; font-weight: 500; letter-spacing: .12em; color: #dfe4f5; }
.nav-group { display: flex; width: 100%; align-items: center; justify-content: space-between; font: inherit; font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: .06em; color: var(--sidebar-head); padding: 18px 24px 8px; background: none; border: 0; text-align: left; }
button.nav-group { cursor: pointer; }
button.nav-group:hover { color: var(--sidebar-text); }
.chev { width: 7px; height: 7px; border-right: 1.5px solid currentColor; border-bottom: 1.5px solid currentColor; transform: rotate(45deg); transition: transform .15s; margin-right: 4px; }
[aria-expanded=true] .chev { transform: rotate(-135deg); }
#nav a { display: flex; align-items: center; gap: 8px; color: var(--sidebar-text); padding: 7px 24px 7px 50px; text-decoration: none; font-size: 13.5px; }
#nav a:hover { color: #fff; }
#nav a.active { color: var(--sidebar-active); font-weight: 600; }
.nav-badge { background: var(--bad); color: #fff; font-size: 10.5px; font-weight: 600; border-radius: 4px; padding: 0 6px; line-height: 17px; }
.main-wrap { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.topbar { height: 60px; display: flex; align-items: center; gap: 8px; padding: 0 20px; background: var(--surface); box-shadow: var(--shadow); position: sticky; top: 0; z-index: 5; }
.topbar-search { flex: 1; min-width: 0; display: flex; justify-content: flex-end; }
.search { width: 280px; max-width: 100%; }
.user-chip { display: flex; align-items: center; gap: 8px; font: inherit; color: var(--text); background: none; border: 0; cursor: pointer; padding: 4px 6px; border-radius: 6px; text-transform: uppercase; font-size: 12.5px; }
.user-chip:hover { background: var(--neutral-soft); }
.avatar { width: 32px; height: 32px; border-radius: 50%; background: #f1934c; color: #fff; display: grid; place-items: center; font-weight: 600; }
.main { padding: 22px 20px 80px; width: 100%; }

/* page header */
.page-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 14px; flex-wrap: wrap; }
.page-head p { margin: 4px 0 0; color: var(--muted); text-transform: none; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.head-row { display: flex; gap: 10px; align-items: stretch; flex-wrap: wrap; margin-bottom: 10px; }
.head-row .search-box { flex: 0 1 470px; }
.search-box { position: relative; min-width: 200px; }
.search-box input { width: 100%; height: 40px; border-color: var(--border); box-shadow: var(--shadow); padding-right: 36px; }
.search-box svg { position: absolute; right: 12px; top: 12px; color: var(--muted); }
.spacer { flex: 1; }
details.filters { background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow); margin-bottom: 10px; }
details.filters summary { list-style: none; cursor: pointer; padding: 10px 14px; font-weight: 500; color: var(--heading); display: flex; align-items: center; gap: 10px; }
details.filters summary::-webkit-details-marker { display: none; }
details.filters summary::before { content: ""; width: 6px; height: 6px; border-right: 2px solid currentColor; border-bottom: 2px solid currentColor; transform: rotate(-45deg); transition: transform .15s; }
details.filters[open] summary::before { transform: rotate(45deg); }
.filter-row { display: flex; gap: 10px 14px; flex-wrap: wrap; padding: 4px 14px 14px; align-items: flex-end; }
.tile { background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow); padding: 6px 22px; text-align: center; min-width: 150px; }
.tile strong { display: block; color: var(--heading); font-size: 15px; }

/* controls */
input, select, textarea { font: inherit; color: var(--text); background: var(--surface); border: 1px solid var(--border-strong); border-radius: 4px; padding: 7px 10px; min-width: 0; }
input:focus, select:focus, textarea:focus { outline: 2px solid color-mix(in srgb, var(--primary) 35%, transparent); outline-offset: 0; border-color: var(--primary); }
textarea { width: 100%; }
textarea.csv { font-family: var(--mono); font-size: 12.5px; }
input[type=checkbox] { width: 16px; height: 16px; accent-color: var(--primary); }
input.qty { width: 84px; text-align: right; }
input.cell { border-color: transparent; background: transparent; padding: 5px 6px; }
input.cell:hover, input.cell:focus { border-color: var(--border-strong); background: var(--surface); }
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; font: inherit; font-weight: 500; padding: 8px 14px; border-radius: 4px; border: 1px solid var(--border-strong); background: var(--surface); color: var(--text); cursor: pointer; white-space: nowrap; text-decoration: none !important; }
.btn:hover { background: var(--surface-2); }
.btn.primary { background: var(--primary); border-color: var(--primary); color: var(--on-primary); }
.btn.primary:hover { background: var(--primary-hover); border-color: var(--primary-hover); }
.btn.dark { background: var(--neutral); border-color: var(--neutral); color: #fff; }
.btn.dark:hover { filter: brightness(.92); }
.btn.danger { color: var(--bad-text); }
.btn.sm { padding: 4px 10px; font-size: 12.5px; }
.btn.block { width: 100%; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn.light { background: var(--neutral-soft); border-color: var(--neutral-soft); }
.icon-btn { display: inline-grid; place-items: center; border: 0; background: transparent; color: inherit; font-size: 16px; cursor: pointer; padding: 6px; border-radius: 6px; line-height: 1; }
.icon-btn:hover { background: var(--neutral-soft); text-decoration: none; }
.icon-btn:disabled { opacity: .3; cursor: not-allowed; }
.icon-btn.green { color: var(--ok); } .icon-btn.red { color: var(--bad); } .icon-btn.blue { color: var(--primary); }
.field { display: flex; flex-direction: column; gap: 4px; }
.field label { font-size: 12.5px; color: var(--muted); font-weight: 500; }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px 14px; }
.form-grid .full { grid-column: 1 / -1; }
.toolbar { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; margin-bottom: 12px; }
.check { display: inline-flex; gap: 6px; align-items: center; color: var(--muted); cursor: pointer; }
.fab { position: fixed; right: 26px; bottom: 26px; width: 54px; height: 54px; border-radius: 50%; border: 0; background: var(--primary); color: var(--on-primary); cursor: pointer; box-shadow: 0 6px 16px rgba(85, 110, 230, .45); display: grid; place-items: center; z-index: 6; }
.fab:hover { background: var(--primary-hover); }

/* cards */
.card { background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow); }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 14px 16px 10px; }
.card-body { padding: 0 16px 16px; }
.card-pad { padding: 16px; }
.grid { display: grid; gap: 14px; }
.grid.kpis { grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); margin-bottom: 14px; }
.grid.two { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid.three { grid-template-columns: 2fr 1fr; }
.grid > *, .stack > * { min-width: 0; }
.stack { display: flex; flex-direction: column; gap: 14px; }
.kpi { padding: 14px 16px; }
.kpi .label { color: var(--muted); font-size: 12.5px; }
.kpi .value { font-size: 22px; font-weight: 600; color: var(--heading); margin-top: 2px; font-variant-numeric: tabular-nums; }
.kpi .sub { color: var(--faint); font-size: 12px; margin-top: 2px; }
.kpi.alert .value { color: var(--bad-text); }

/* tables */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th { text-align: left; font-size: 13px; font-weight: 600; color: var(--heading); padding: 12px 10px; white-space: nowrap; background: var(--surface-2); }
td { padding: 12px 10px; border-top: 1px solid var(--border); vertical-align: middle; }
tbody tr[data-href] { cursor: pointer; }
tbody tr[data-href]:hover td, tbody tr.hover:hover td { background: var(--surface-2); }
th.num { text-align: right; } th.center { text-align: center; }
td.sep, th.sep { border-left: 1px solid var(--border); }
.card.table-card { padding: 12px 14px; }
tfoot td { font-weight: 600; color: var(--heading); }
.empty { padding: 32px 16px; text-align: center; color: var(--muted); }
.pager { display: flex; align-items: center; justify-content: center; gap: 0; padding: 16px 0 6px; position: relative; flex-wrap: wrap; }
.pager button { font: inherit; padding: 6px 12px; border: 1px solid var(--border-strong); background: var(--surface); color: var(--muted); cursor: pointer; margin-left: -1px; }
.pager button:first-of-type { border-radius: 4px 0 0 4px; } .pager button:last-of-type { border-radius: 0 4px 4px 0; }
.pager button.on { background: var(--primary); border-color: var(--primary); color: var(--on-primary); }
.pager button:disabled { opacity: .5; cursor: default; }
.pager .per { position: absolute; right: 0; display: flex; align-items: center; gap: 8px; color: var(--heading); font-weight: 500; }
.pager .per select { padding: 4px 6px; }
.row-actions { display: flex; align-items: center; justify-content: flex-end; gap: 0; white-space: nowrap; }
.row-actions .slash { color: var(--faint); }

/* badges */
.badge { display: inline-flex; align-items: center; gap: 4px; font-size: 11.5px; font-weight: 600; padding: 2px 7px; border-radius: 4px; background: var(--neutral-soft); color: var(--muted); white-space: nowrap; }
.badge.ok { background: var(--ok); color: #fff; }
.badge.warn { background: var(--warn); color: #fff; }
.badge.bad { background: var(--bad); color: #fff; }
.badge.info { background: var(--primary); color: var(--on-primary); }
.badge.dark { background: var(--neutral); color: #fff; }
.badge.soft-bad { background: var(--bad-soft); color: var(--bad-text); }
.badge.soft-ok { background: var(--ok-soft); color: var(--ok); }

/* work-order board */
.board { display: grid; grid-template-columns: repeat(4, minmax(250px, 1fr)); gap: 10px; overflow-x: auto; align-items: start; }
.col { background: var(--col-body); border-radius: var(--radius); min-height: 60vh; display: flex; flex-direction: column; }
.col-head { color: #fff; font-weight: 600; font-size: 15px; padding: 13px 14px; border-radius: var(--radius) var(--radius) 0 0; display: flex; justify-content: space-between; }
.col-head small { font-weight: 500; opacity: .85; }
.col.action .col-head { background: var(--bad); } .col.waiting .col-head { background: var(--warn); }
.col.empty-col .col-head { background: var(--neutral); } .col.done .col-head { background: var(--ok); }
.col-body { padding: 6px; display: flex; flex-direction: column; gap: 6px; max-height: calc(100vh - 290px); overflow-y: auto; }
.wo-card { background: var(--surface); border-radius: 4px; box-shadow: var(--shadow); padding: 12px 12px 10px; cursor: pointer; }
.wo-card:hover { box-shadow: 0 2px 8px rgba(18, 38, 63, .14); }
.wo-top { display: flex; align-items: center; gap: 8px; min-height: 30px; }
.wo-top strong { flex: 1; color: var(--heading); font-weight: 600; font-size: 14px; overflow-wrap: anywhere; }
.wo-top small { display: block; font-weight: 400; }
.wo-meta { display: flex; justify-content: space-between; gap: 8px; margin-top: 14px; color: var(--heading); font-size: 12.5px; flex-wrap: wrap; }
.wo-meta span { display: inline-flex; align-items: center; gap: 3px; white-space: nowrap; }
.wo-counts { display: flex; gap: 12px; }
.seg { display: inline-flex; }
.seg .btn { border-radius: 0; margin-left: -1px; } .seg .btn:first-child { border-radius: 4px 0 0 4px; margin-left: 0; } .seg .btn:last-child { border-radius: 0 4px 4px 0; }

/* bars / progress */
.progress { height: 6px; background: var(--neutral-soft); border-radius: 99px; overflow: hidden; min-width: 70px; }
.progress > span { display: block; height: 100%; background: var(--ok); border-radius: 99px; }
.bar-row { display: grid; grid-template-columns: 100px 1fr 80px; gap: 10px; align-items: center; padding: 5px 0; font-size: 13px; }
.bar-row .bar { height: 10px; background: var(--neutral-soft); border-radius: 4px; overflow: hidden; }
.bar-row .bar span { display: block; height: 100%; background: var(--primary); border-radius: 4px; }
.spark { display: block; width: 100%; height: 70px; }

/* detail */
.stat-row { display: flex; flex-wrap: wrap; }
.stat { flex: 1; min-width: 110px; padding: 12px 16px; border-right: 1px solid var(--border); }
.stat:last-child { border-right: 0; }
.stat .label { font-size: 12px; color: var(--muted); }
.stat .value { font-size: 18px; font-weight: 600; color: var(--heading); font-variant-numeric: tabular-nums; }
.kv { display: grid; grid-template-columns: max-content 1fr; gap: 6px 16px; margin: 0; }
.kv dt { color: var(--muted); } .kv dd { margin: 0; }
.tabs { display: flex; gap: 2px; border-bottom: 1px solid var(--border-strong); margin-bottom: 14px; overflow-x: auto; }
.tabs button { font: inherit; background: none; border: 0; border-bottom: 2px solid transparent; padding: 8px 14px; color: var(--muted); cursor: pointer; white-space: nowrap; }
.tabs button.active { color: var(--heading); border-bottom-color: var(--primary); font-weight: 600; }
.list { list-style: none; margin: 0; padding: 0; }
.list li { display: flex; justify-content: space-between; gap: 12px; padding: 8px 0; border-top: 1px solid var(--border); }
.list li:first-child { border-top: 0; }
.group + .group { margin-top: 14px; }
.crumb { color: var(--muted); font-size: 12.5px; margin-bottom: 4px; }

/* modal */
dialog { border: 0; border-radius: 6px; padding: 0; width: min(640px, calc(100vw - 24px)); background: var(--surface); color: var(--text); box-shadow: 0 20px 60px rgba(0, 0, 0, .3); }
dialog.wide { width: min(920px, calc(100vw - 24px)); }
dialog.xwide { width: min(1360px, calc(100vw - 24px)); max-width: none; }
dialog::backdrop { background: rgba(20, 24, 40, .55); }
dialog header { display: flex; align-items: center; justify-content: space-between; padding: 12px 16px; border-bottom: 1px solid var(--border); }
dialog h2 { font-size: 14px; font-weight: 500; }
.modal-body { padding: 18px; max-height: calc(100vh - 170px); overflow-y: auto; }
dialog footer { display: flex; justify-content: flex-end; gap: 8px; padding: 12px 16px; border-top: 1px solid var(--border); }
dialog footer:empty { display: none; }
.err { color: var(--bad-text); background: var(--bad-soft); padding: 8px 12px; border-radius: 4px; margin-bottom: 12px; }
.hint { font-size: 12.5px; color: var(--muted); margin: 6px 0 0; }
.drop { border: 1.5px dashed var(--border-strong); border-radius: 6px; padding: 14px; text-align: center; color: var(--muted); margin-bottom: 10px; }

/* order window */
.order-grid { display: grid; grid-template-columns: minmax(0, 2fr) minmax(260px, 1fr); gap: 22px; }
.order-top { display: flex; justify-content: space-between; align-items: flex-start; gap: 16px; margin-bottom: 14px; flex-wrap: wrap; }
.order-num { font-size: 30px; font-weight: 600; color: var(--heading); line-height: 1.1; display: flex; align-items: center; gap: 8px; }
.order-total { font-size: 28px; font-weight: 600; color: var(--heading); }
.add-row { display: flex; gap: 10px; align-items: flex-end; flex-wrap: wrap; margin: 12px 0; }
.add-row .field.grow { flex: 1 1 220px; }
.add-row input, .add-row select { height: 36px; width: 100%; }
.msg { background: var(--surface-2); border-radius: 6px; padding: 8px 10px; margin-top: 8px; }
.msg small { color: var(--muted); display: flex; justify-content: space-between; gap: 8px; }
.msg-form { display: flex; gap: 6px; margin-top: 10px; }
.msg-form input { flex: 1; }

/* toasts */
.toasts { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); display: flex; flex-direction: column; gap: 8px; z-index: 100; align-items: center; }
.toast { background: var(--heading); color: var(--surface); padding: 10px 16px; border-radius: 6px; box-shadow: 0 8px 24px rgba(0, 0, 0, .2); animation: in .2s ease-out; max-width: 420px; }
.toast.error { background: var(--bad-text); color: #fff; }
@keyframes in { from { transform: translateY(8px); opacity: 0; } }

/* search results */
.search-pop { position: fixed; top: 54px; right: 120px; width: 380px; max-width: calc(100vw - 24px); background: var(--surface); border: 1px solid var(--border); border-radius: 6px; box-shadow: 0 12px 32px rgba(0, 0, 0, .18); z-index: 20; max-height: 420px; overflow-y: auto; }
.search-pop a { display: flex; justify-content: space-between; gap: 10px; padding: 9px 14px; color: var(--text); border-bottom: 1px solid var(--border); text-decoration: none; }
.search-pop a:hover, .search-pop a.sel { background: var(--surface-2); }
.search-pop .kind { font-size: 11px; color: var(--faint); text-transform: uppercase; letter-spacing: .05em; }

pre.code { background: var(--surface-2); border: 1px solid var(--border); border-radius: 6px; padding: 12px; overflow-x: auto; font-family: var(--mono); font-size: 12.5px; margin: 8px 0 0; }

@media (max-width: 1000px) {
  .grid.two, .grid.three, .order-grid { grid-template-columns: minmax(0, 1fr); }
}
@media (max-width: 760px) {
  .sidebar { position: fixed; left: 0; z-index: 30; margin-left: -232px; }
  body.nav-open .sidebar { margin-left: 0; box-shadow: 0 0 40px rgba(0, 0, 0, .4); }
  .main { padding: 14px 10px 80px; }
  .topbar { padding: 0 10px; }
  .user-chip span:last-child { display: none; }
  .form-grid { grid-template-columns: 1fr; }
  .search-pop { right: 12px; }
  .pager .per { position: static; margin-left: 12px; }
  .board { grid-template-columns: repeat(4, 270px); }
}
@media print {
  .sidebar, .topbar, .actions, .no-print, .toasts, .fab { display: none !important; }
  body { background: #fff; }
  .main { padding: 0; }
}
td.mono { white-space: nowrap; }
.list li .badge { align-self: center; }
.card > .table-wrap th:first-child, .card > .table-wrap td:first-child { padding-left: 16px; }
.card > .table-wrap th:last-child, .card > .table-wrap td:last-child { padding-right: 16px; }
