:root {
  --bg: #f4f6fa; --surface: #fff; --text: #1b2433; --muted: #667085; --line: #e3e7ee;
  --brand: #2f5bea; --brand-d: #2447c0; --brand-soft: #e9eefe; --ok: #12805c; --ok-soft: #e1f5ed; --warn: #b45309; --warn-soft: #fdf1dc; --bad: #c0362c; --bad-soft: #fde8e6;
  --b2b: #7a4de8; --ota: #2f5bea; --products: #0e9f8e;
}
@media (prefers-color-scheme: dark) {
  :root { --bg: #0f1420; --surface: #171e2d; --text: #e8ecf4; --muted: #96a1b6; --line: #2a3447; --brand: #6d8dff; --brand-d: #8aa3ff; --brand-soft: #1f2a4d;
    --ok: #4cd1a0; --ok-soft: #12362b; --warn: #f2b050; --warn-soft: #3b2e14; --bad: #ff8a80; --bad-soft: #3d1e1b; --b2b: #a98bff; --ota: #6d8dff; --products: #3fd1bf; }
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--text); font: 14px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; }
button, input, select, textarea { font: inherit; color: inherit; }
h1, h2, h3 { margin: 0; line-height: 1.2; }
.hidden { display: none !important; }

/* top bar */
.topbar { background: var(--surface); border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 20; }
.topbar-in { max-width: 1400px; margin: 0 auto; padding: 0 16px; display: flex; align-items: center; gap: 16px; min-height: 56px; flex-wrap: wrap; }
.brand { font-weight: 700; font-size: 16px; letter-spacing: -.01em; white-space: nowrap; }
.brand span { color: var(--brand); }
.tabs { display: flex; gap: 4px; flex: 1; flex-wrap: wrap; }
.tab { border: 0; background: none; padding: 17px 14px 14px; cursor: pointer; border-bottom: 3px solid transparent; color: var(--muted); font-weight: 600; }
.tab:hover { color: var(--text); }
.tab.active { color: var(--text); border-bottom-color: var(--accent, var(--brand)); }
.tab .dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; margin-right: 8px; background: var(--accent, var(--brand)); }
.who { display: flex; align-items: center; gap: 10px; color: var(--muted); }
.who b { color: var(--text); }

main { max-width: 1400px; margin: 0 auto; padding: 20px 16px 60px; }
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 12px; margin-bottom: 16px; flex-wrap: wrap; }
.page-head h2 { font-size: 22px; }
.page-head p { margin: 4px 0 0; color: var(--muted); }

/* buttons */
.btn { border: 1px solid var(--line); background: var(--surface); padding: 8px 14px; border-radius: 8px; cursor: pointer; font-weight: 600; }
.btn:hover { border-color: var(--brand); color: var(--brand); }
.btn.primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn.primary:hover { background: var(--brand-d); color: #fff; }
.btn.danger { color: var(--bad); }
.btn.danger:hover { border-color: var(--bad); color: var(--bad); }
.btn.small { padding: 4px 10px; font-size: 13px; }
.btn:disabled { opacity: .55; cursor: default; }
.btn:focus-visible, .tab:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible { outline: 2px solid var(--brand); outline-offset: 2px; }

/* sub tabs */
.subtabs { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 14px; }
.chip { border: 1px solid var(--line); background: var(--surface); padding: 6px 12px; border-radius: 999px; cursor: pointer; font-weight: 600; color: var(--muted); }
.chip.active { background: var(--accent, var(--brand)); border-color: var(--accent, var(--brand)); color: #fff; }
.chip small { opacity: .8; margin-left: 4px; font-weight: 500; }
.badge-report { font-size: 11px; text-transform: uppercase; letter-spacing: .04em; margin-left: 6px; opacity: .85; }

/* cards + tables */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: 12px; }
.toolbar { display: flex; gap: 10px; padding: 12px; flex-wrap: wrap; align-items: center; border-bottom: 1px solid var(--line); }
.toolbar .grow { flex: 1; }
.toolbar input[type=search], .toolbar select { padding: 7px 10px; border: 1px solid var(--line); border-radius: 8px; background: var(--bg); min-width: 200px; }
.table-wrap { overflow: auto; max-height: 70vh; -webkit-overflow-scrolling: touch; }
table { border-collapse: separate; border-spacing: 0; width: max-content; min-width: 100%; }
th, td { padding: 10px 14px; text-align: left; border-bottom: 1px solid var(--line); vertical-align: top; min-width: 110px; max-width: 280px; }
th { position: sticky; top: 0; background: var(--surface); font-size: 11.5px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); white-space: nowrap; z-index: 2; }
td { overflow-wrap: break-word; word-break: normal; hyphens: auto; }
td .cl { display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; }
td .cl .pill { white-space: normal; }
th:first-child, td:first-child { position: sticky; left: 0; background: var(--surface); min-width: 150px; max-width: 220px; font-weight: 600; z-index: 1; box-shadow: 1px 0 0 var(--line); }
th:first-child { z-index: 3; }
th:last-child, td:last-child { min-width: 60px; }
tbody tr:hover { background: var(--brand-soft); }
tbody tr:hover td:first-child { background: var(--brand-soft); }
tr.clickable { cursor: pointer; }
td.act { white-space: nowrap; min-width: 0; }
.empty { padding: 40px 20px; text-align: center; color: var(--muted); }
.pager { display: flex; justify-content: space-between; align-items: center; padding: 10px 12px; color: var(--muted); }
.pill { display: inline-block; padding: 1px 9px; border-radius: 999px; font-size: 12px; font-weight: 600; background: var(--bg); border: 1px solid var(--line); white-space: nowrap; }
.pill.ok { background: var(--ok-soft); color: var(--ok); border-color: transparent; }
.pill.warn { background: var(--warn-soft); color: var(--warn); border-color: transparent; }
.pill.bad { background: var(--bad-soft); color: var(--bad); border-color: transparent; }
.muted { color: var(--muted); }

/* stat tiles */
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 12px; margin-bottom: 18px; }
.stat { padding: 14px 16px; border-left: 4px solid var(--accent, var(--brand)); }
.stat .n { font-size: 28px; font-weight: 700; line-height: 1.1; }
.stat .l { color: var(--muted); }

/* modal */
.overlay { position: fixed; inset: 0; background: rgba(10, 14, 25, .55); z-index: 50; display: flex; align-items: flex-start; justify-content: center; padding: 4vh 12px; overflow: auto; }
.modal { background: var(--surface); border-radius: 14px; width: 100%; max-width: 760px; box-shadow: 0 20px 60px rgba(0,0,0,.35); }
.modal-head { padding: 16px 20px; border-bottom: 1px solid var(--line); display: flex; justify-content: space-between; align-items: center; gap: 10px; }
.modal-head h3 { font-size: 18px; }
.modal-body { padding: 18px 20px; display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px 16px; }
.modal-foot { padding: 14px 20px; border-top: 1px solid var(--line); display: flex; gap: 10px; justify-content: flex-end; align-items: center; }
.modal-foot .err { margin-right: auto; }
.field { display: flex; flex-direction: column; gap: 5px; }
.field.wide { grid-column: 1 / -1; }
.field label, .field .lab { font-weight: 600; font-size: 13px; }
.field label i { color: var(--bad); font-style: normal; }
.field input[type=text], .field input[type=date], .field input[type=number], .field input[type=password], .field select, .field textarea {
  padding: 8px 10px; border: 1px solid var(--line); border-radius: 8px; background: var(--bg); width: 100%; }
.field textarea { min-height: 76px; resize: vertical; }
.field input:disabled, .field select:disabled, .field textarea:disabled { opacity: .7; cursor: not-allowed; }
.check { display: flex; align-items: center; gap: 8px; padding: 8px 0; font-weight: 500 !important; }
.check input { width: 18px; height: 18px; }
.modcheck { display: grid; gap: 8px; }
.modcheck label { display: flex; gap: 10px; align-items: flex-start; padding: 10px 12px; border: 1px solid var(--line); border-radius: 10px; cursor: pointer; font-weight: 600; }
.modcheck label:has(input:checked) { border-color: var(--accent); background: var(--brand-soft); }
.modcheck small { display: block; color: var(--muted); font-weight: 400; }
.err { color: var(--bad); font-weight: 600; }
.note { background: var(--warn-soft); color: var(--warn); padding: 10px 14px; border-radius: 10px; margin-bottom: 14px; }

/* login */
.login-wrap { min-height: 100vh; display: grid; place-items: center; padding: 20px; }
.login { width: 100%; max-width: 380px; padding: 28px; }
.login h1 { font-size: 22px; margin-bottom: 4px; }
.login p { color: var(--muted); margin: 0 0 20px; }
.login .field { margin-bottom: 14px; }
.toast { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); background: var(--text); color: var(--bg); padding: 10px 18px; border-radius: 10px; z-index: 99; font-weight: 600; }

@media (max-width: 640px) {
  .modal-body { grid-template-columns: 1fr; }
  .tab { padding: 12px 10px 10px; }
  .who span.n { display: none; }
}

@media (max-width: 900px) {
  main { padding: 14px 12px 48px; }
  .topbar-in { gap: 6px 12px; padding: 6px 12px; }
  .tabs { order: 3; flex: 1 0 100%; flex-wrap: nowrap; overflow-x: auto; scrollbar-width: none; }
  .tabs::-webkit-scrollbar { display: none; }
  .tab { white-space: nowrap; padding: 10px 12px 9px; }
  .who { margin-left: auto; }
  .subtabs { flex-wrap: nowrap; overflow-x: auto; padding-bottom: 4px; scrollbar-width: none; }
  .chip { white-space: nowrap; }
  .toolbar input[type=search], .toolbar select { min-width: 0; flex: 1 1 160px; }
  .toolbar .grow { flex: 1 0 100%; order: 5; }
}
@media (max-width: 700px) {
  .page-head h2 { font-size: 19px; }
  .table-wrap { max-height: none; overflow: visible; }
  table, thead, tbody, tr, td { display: block; width: 100%; min-width: 0; }
  thead { display: none; }
  tbody tr { border: 1px solid var(--line); border-radius: 10px; margin: 10px 12px; width: auto; padding: 4px 0; background: var(--surface); }
  td, td:first-child { max-width: none; border: 0; padding: 6px 12px; display: flex; gap: 12px; position: static; box-shadow: none; background: transparent; }
  td:first-child { font-size: 15px; padding-top: 10px; }
  td[data-label]::before { content: attr(data-label); flex: 0 0 38%; max-width: 150px; color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: .04em; padding-top: 2px; }
  td:first-child[data-label]::before { content: attr(data-label); }
  td .cl { -webkit-line-clamp: 5; flex: 1; min-width: 0; }
  td.act { justify-content: flex-end; padding-bottom: 10px; }
  .pager { flex-wrap: wrap; gap: 8px; }
  .overlay { padding: 0; }
  .modal { border-radius: 0; min-height: 100%; }
  .modal-foot { position: sticky; bottom: 0; background: var(--surface); }
}

.with-pick { display: flex; gap: 6px; align-items: stretch; }
.with-pick input[type=text] { flex: 1; min-width: 0; }
.field .with-pick input.datepick { width: 46px; flex: 0 0 46px; padding: 0 4px; cursor: pointer; color-scheme: light dark; }
