:root {
  --bg: #f4f5f8; --panel: #ffffff; --surface-2: #f6f8fc; --ink: #141a2e; --muted: #5d6478; --line: #dde1ea; --line-strong: #b3bbcc;
  --accent: #1e40af; --accent-hover: #172f8a; --accent-ink: #ffffff; --accent-soft: #e3e9ff;
  --side-bg: #0f172a; --side-ink: #b8c2d6; --side-muted: #94a3b8; --side-focus: #93c5fd;
  --chip-bg: #eef0f5; --chart-2: #f59e0b; --wa: #146c2e; --wa-soft: #e7f8ee;
  --warn: #b45309; --warn-soft: #fef3c7; --bad: #b91c1c; --bad-soft: #fee2e2; --bad-line: #f3c3c3; --good: #15803d; --good-soft: #dcfce7; --good-line: #b7e4c7; --info: #3730a3; --info-soft: #e0e7ff;
  --radius: 12px; --shadow: 0 10px 30px rgba(20, 26, 46, .12);
  --font: "Segoe UI", system-ui, -apple-system, sans-serif; --mono: ui-monospace, "Cascadia Mono", Consolas, monospace;
  --tap: 44px;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { font: 14px/1.45 var(--font); color: var(--ink); background: var(--bg); font-variant-numeric: tabular-nums; accent-color: var(--accent); }
::selection { background: var(--accent-soft); color: var(--ink); }
a { color: var(--accent); text-underline-offset: 2px; }
h1 { font-size: 24px; margin: 0 0 4px; letter-spacing: -.015em; text-wrap: balance; }
h2 { font-size: 15px; margin: 22px 0 8px; }
h3 { font-size: 13px; margin: 14px 0 6px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.mono { font-family: var(--mono); font-size: 13px; }
.r { text-align: right; }
.n { text-align: right; white-space: nowrap; }
.err { color: var(--bad); min-height: 1.2em; font-size: 13px; }
.sub { color: var(--muted); margin: 0 0 16px; max-width: 72ch; }
.small { font-size: 13px; }
b.big { font-size: 18px; }

/* icons */
.ico { width: 16px; height: 16px; flex: none; vertical-align: -3px; }
.btn .ico, .btn i { margin-right: 6px; }
.btn i { display: inline-flex; vertical-align: -3px; }
.btn i .ico { margin: 0; }
.btn.icon { padding: 6px; line-height: 0; }
.btn.icon .ico { margin: 0; }
.close .ico { width: 14px; height: 14px; vertical-align: middle; }
.fab .ico { width: 26px; height: 26px; vertical-align: middle; }

/* scrollbars, from the palette rather than the OS */
.tblwrap, .drawer-panel, .modal-card, #nav, .log { scrollbar-width: thin; scrollbar-color: var(--line-strong) transparent; }
.tblwrap::-webkit-scrollbar, .drawer-panel::-webkit-scrollbar, .modal-card::-webkit-scrollbar, .log::-webkit-scrollbar { height: 8px; width: 8px; }
.tblwrap::-webkit-scrollbar-thumb, .drawer-panel::-webkit-scrollbar-thumb, .modal-card::-webkit-scrollbar-thumb, .log::-webkit-scrollbar-thumb { background: var(--line-strong); border-radius: 999px; }

/* layout */
.shell { display: grid; grid-template-columns: 224px 1fr; min-height: 100vh; }
.side { background: var(--side-bg); color: var(--side-ink); display: flex; flex-direction: column; padding: 18px 14px; position: sticky; top: 0; height: 100vh; }
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 16px; padding: 4px 8px 18px; color: #fff; }
.logo { width: 26px; height: 26px; border-radius: 8px; background: var(--accent); display: inline-block; position: relative; flex: none; }
.logo::after { content: ""; position: absolute; left: 6px; top: 8px; width: 14px; height: 9px; border: 2.5px solid #fff; border-radius: 2px; }
#nav { display: flex; flex-direction: column; gap: 2px; }
#nav a, .nav-more { display: flex; align-items: center; gap: 10px; padding: 9px 10px; border-radius: 9px; color: var(--side-ink); text-decoration: none; font-weight: 500; font: inherit; background: none; border: 0; cursor: pointer; text-align: left; }
#nav a i, .nav-more i { display: inline-flex; width: 18px; justify-content: center; opacity: .85; }
#nav a i .ico, .nav-more i .ico { width: 18px; height: 18px; }
#nav a:hover, .nav-more:hover { background: rgba(255,255,255,.06); color: #fff; }
#nav a.active { background: var(--accent); color: #fff; }
.nav-more { display: none; }
.side-foot { margin-top: auto; display: flex; flex-direction: column; gap: 8px; }
.who { color: var(--side-muted); font-size: 12px; margin: 0; }
.who input { margin-top: 4px; background: rgba(255,255,255,.08); border-color: rgba(255,255,255,.12); color: #fff; }
.main { min-width: 0; }
.top { display: flex; gap: 12px; align-items: center; padding: 14px 24px; background: var(--panel); border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 5; }
.search { display: flex; gap: 8px; flex: 1; max-width: 560px; }
.search input { flex: 1; }
.top-actions { display: none; gap: 8px; }
.view { padding: 22px 24px 60px; max-width: 1320px; }

/* controls */
input, select, textarea { font: inherit; color: var(--ink); background: #fff; border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; width: 100%; caret-color: var(--accent); }
input::placeholder, textarea::placeholder { color: var(--muted); opacity: .8; }
input:focus, select:focus, textarea:focus { border-color: var(--accent); }
:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; border-radius: 6px; }
input:focus-visible, select:focus-visible, textarea:focus-visible { outline-offset: 1px; }
.side :focus-visible, #nav a:focus-visible { outline-color: var(--side-focus); }
textarea { min-height: 64px; resize: vertical; }
label { display: block; font-size: 13px; color: var(--muted); font-weight: 600; margin-bottom: 10px; }
label > input, label > select, label > textarea { margin-top: 4px; font-weight: 400; }
label.inline { display: flex; align-items: center; gap: 8px; margin-top: 6px; }
label.inline input { width: auto; margin: 0; }
.btn { font: inherit; font-weight: 600; border: 1px solid var(--line); background: #fff; color: var(--ink); padding: 8px 13px; border-radius: 8px; cursor: pointer; white-space: nowrap; display: inline-flex; align-items: center; justify-content: center; }
a.btn { text-decoration: none; }
.btn:hover { border-color: var(--line-strong); background: var(--surface-2); }
.btn:active { transform: translateY(1px); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); }
.btn.danger { color: var(--bad); border-color: var(--bad-line); }
.btn.danger:hover { background: var(--bad-soft); }
.btn.good { color: var(--good); border-color: var(--good-line); background: #f2fbf5; }
/* "create" buttons that are not THE primary action: filled, never white-on-white */
.btn.soft { background: var(--accent-soft); border-color: var(--accent-soft); color: var(--accent); }
.btn.soft:hover { background: #d3dcff; border-color: #d3dcff; }
.side .btn.soft { background: rgba(255,255,255,.14); border-color: rgba(255,255,255,.14); color: #fff; }
.side .btn.soft:hover { background: rgba(255,255,255,.22); }
.btn.wa { background: var(--wa-soft); border-color: var(--good-line); color: var(--wa); }
.btn.wa:hover { background: #d4f3e1; }
.summary .btn.sm, td .btn.wa { padding: 2px 8px; font-size: 12px; vertical-align: middle; }
.btn.primary { box-shadow: 0 1px 2px rgba(20, 26, 46, .18); }
.btn.sm { padding: 4px 9px; font-size: 13px; border-radius: 7px; }
.btn.block { width: 100%; }
.btn:disabled { opacity: .5; cursor: not-allowed; transform: none; }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.row.between { justify-content: space-between; }
.row.end { justify-content: flex-end; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 16px; }
.grid3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 0 16px; }
.grid4 { display: grid; grid-template-columns: repeat(4, 1fr); gap: 0 16px; }
.chips { display: flex; gap: 6px; flex-wrap: wrap; margin: 10px 0 14px; }
.chip { font: inherit; border: 1px solid var(--line); background: #fff; border-radius: 999px; padding: 5px 12px; font-size: 13px; font-weight: 600; cursor: pointer; color: var(--muted); line-height: 1.45; }
.chip:hover { border-color: var(--line-strong); color: var(--ink); }
.chip.active { background: var(--ink); border-color: var(--ink); color: #fff; }
.filters { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; margin: 10px 0 14px; }
.filters select, .filters input { width: auto; min-width: 140px; }
.rowlink { font: inherit; color: inherit; background: none; border: 0; padding: 0; margin: 0; text-align: left; cursor: pointer; font-weight: 700; }
.rowlink:hover { color: var(--accent); text-decoration: underline; }
td .rowlink.mono { font-family: var(--mono); font-size: 13px; }

/* cards & tables */
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px 18px; }
.card + .card { margin-top: 14px; }
.card h2:first-child { margin-top: 0; }
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; margin: 14px 0 20px; }
.kpi { display: block; width: 100%; text-align: left; font: inherit; color: inherit; background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; }
button.kpi { cursor: pointer; }
button.kpi:hover { border-color: var(--accent); }
.kpi b { display: block; font-size: 24px; letter-spacing: -.02em; line-height: 1.1; }
.kpi span { font-size: 12px; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: .05em; }
.kpi small { display: block; color: var(--muted); margin-top: 4px; font-size: 12px; }
.kpi.warn b { color: var(--warn); } .kpi.bad b { color: var(--bad); } .kpi.good b { color: var(--good); }
.two { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.three { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 14px; }
.tblwrap { overflow-x: auto; }
table { border-collapse: collapse; width: 100%; font-size: 13px; }
th, td { padding: 8px 10px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: top; }
th { font-size: 12px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); font-weight: 700; white-space: nowrap; }
tr.click { cursor: pointer; } tr.click:hover td { background: var(--surface-2); }
tr.sel td { background: var(--accent-soft); }
tfoot td { font-weight: 700; background: var(--surface-2); }
td.actions { white-space: nowrap; }
.tag { display: inline-block; font-size: 11px; font-weight: 700; padding: 2px 8px; border-radius: 999px; background: var(--chip-bg); color: var(--muted); letter-spacing: .03em; text-transform: uppercase; white-space: nowrap; }
.tag.IN_USE, .tag.DONE, .tag.APPROVED, .tag.FOUND, .tag.active, .tag.RECEIVED, .tag.ok { background: var(--good-soft); color: var(--good); }
.tag.NEW, .tag.ORDERED, .tag.MOVED, .tag.ending, .tag.soon { background: var(--info-soft); color: var(--info); }
.tag.UNDER_SERVICE, .tag.OPEN, .tag.PENDING, .tag.REQUESTED, .tag.DAMAGED, .tag.watch, .tag.ahead { background: var(--warn-soft); color: var(--warn); }
.tag.IDLE, .tag.CANCELLED, .tag.none { background: var(--chip-bg); color: var(--muted); }
.tag.SOLD, .tag.SCRAPPED, .tag.LOST, .tag.WRITTEN_OFF, .tag.REJECTED, .tag.MISSING, .tag.expired, .tag.overdue, .tag.over { background: var(--bad-soft); color: var(--bad); }
.tag.A { background: var(--good-soft); color: var(--good); } .tag.B { background: var(--info-soft); color: var(--info); } .tag.C { background: var(--warn-soft); color: var(--warn); } .tag.D { background: var(--bad-soft); color: var(--bad); }
.bar { height: 8px; background: var(--chip-bg); border-radius: 999px; overflow: hidden; margin-top: 6px; }
.bar i { display: block; height: 100%; background: var(--accent); border-radius: 999px; }
.bar.warn i { background: var(--warn); } .bar.bad i { background: var(--bad); } .bar.good i { background: var(--good); }
.pace { display: flex; justify-content: space-between; font-size: 12px; color: var(--muted); margin-top: 3px; }
.insight { display: flex; gap: 12px; padding: 10px 0; border-bottom: 1px solid var(--line); align-items: flex-start; }
.insight:last-child { border-bottom: 0; }
.insight .dot { width: 10px; height: 10px; border-radius: 50%; margin-top: 6px; flex: none; background: var(--info); }
.insight.warn .dot { background: var(--warn); } .insight.bad .dot { background: var(--bad); }
.insight b { display: block; } .insight span { color: var(--muted); font-size: 13px; }
.timeline { list-style: none; margin: 0; padding: 0; }
.timeline li { display: grid; grid-template-columns: 86px 1fr; gap: 12px; padding: 8px 0; border-bottom: 1px solid var(--line); font-size: 13px; }
.timeline li:last-child { border-bottom: 0; }
.timeline .when { color: var(--muted); font-family: var(--mono); font-size: 12px; }
.timeline .what b { margin-right: 6px; }
.empty { color: var(--muted); padding: 18px 0; text-align: center; }
.summary { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 6px 18px; font-size: 13px; margin: 10px 0; }
.summary div span { color: var(--muted); display: block; font-size: 12px; text-transform: uppercase; letter-spacing: .04em; }
.photo { width: 96px; height: 96px; object-fit: cover; border-radius: 10px; border: 1px solid var(--line); background: var(--chip-bg); }
.docs { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; }
.doc { border: 1px solid var(--line); border-radius: 10px; padding: 8px; font-size: 13px; }
.doc img { width: 100%; height: 90px; object-fit: cover; border-radius: 6px; }
.chart { display: flex; gap: 6px; align-items: flex-end; height: 120px; padding-top: 10px; }
.chart .col { flex: 1; display: flex; flex-direction: column; justify-content: flex-end; height: 100%; font-size: 11px; color: var(--muted); text-align: center; gap: 2px; }
.chart .col i { display: block; background: var(--accent); border-radius: 4px 4px 0 0; min-height: 2px; }
.chart .col i.opex { background: var(--chart-2); }
.scanbox { font-size: 18px; padding: 12px 14px; font-family: var(--mono); }
.stat-row { display: flex; gap: 18px; flex-wrap: wrap; font-size: 13px; }
.stat-row b { font-size: 16px; }

/* drawer, modal, toast */
.drawer, .modal { position: fixed; inset: 0; background: rgba(20,26,46,.45); z-index: 20; display: flex; justify-content: flex-end; }
.modal { align-items: center; justify-content: center; z-index: 30; }
.drawer-panel { width: min(860px, 100%); background: var(--panel); height: 100%; overflow: auto; padding: 22px 24px 40px; box-shadow: var(--shadow); position: relative; }
.modal-card { width: min(760px, calc(100% - 24px)); max-height: calc(100% - 40px); overflow: auto; background: var(--panel); border-radius: 14px; padding: 22px 24px; box-shadow: var(--shadow); position: relative; }
.close { position: absolute; top: 12px; right: 12px; border: 0; background: var(--chip-bg); color: var(--ink); border-radius: 50%; width: 32px; height: 32px; cursor: pointer; display: inline-flex; align-items: center; justify-content: center; }
.close:hover { background: var(--line); }
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); margin: 16px 0 12px; overflow-x: auto; }
.tabs button { font: inherit; font-weight: 600; background: none; border: 0; border-bottom: 2px solid transparent; padding: 8px 12px; cursor: pointer; color: var(--muted); white-space: nowrap; }
.tabs button:hover { color: var(--ink); }
.tabs button.active { color: var(--accent); border-bottom-color: var(--accent); }
.toast { position: fixed; bottom: 22px; left: 50%; transform: translateX(-50%) translateY(20px); background: var(--ink); color: #fff; padding: 10px 16px; border-radius: 10px; opacity: 0; transition: opacity .2s ease-out, transform .25s cubic-bezier(.2,.8,.2,1); z-index: 40; pointer-events: none; max-width: 90vw; }
.toast.show { opacity: 1; transform: translateX(-50%); }
.toast.bad { background: var(--bad); }
.fab { display: none; position: fixed; right: 18px; bottom: 74px; width: 54px; height: 54px; border-radius: 50%; background: var(--accent); color: #fff; border: 0; box-shadow: var(--shadow); z-index: 15; cursor: pointer; align-items: center; justify-content: center; }
.lock { position: fixed; inset: 0; background: var(--bg); z-index: 60; display: flex; align-items: center; justify-content: center; }
.lock-card { background: var(--panel); border: 1px solid var(--line); border-radius: 14px; padding: 26px; width: 320px; }
.lock .brand { color: var(--ink); padding-bottom: 12px; }
.auth-card { width: min(440px, calc(100% - 24px)); }
.auth-card .tabs { margin: 4px 0 16px; }
.auth-card .sub { margin-bottom: 8px; }
.alertbar { position: fixed; top: 0; left: 0; right: 0; z-index: 50; background: var(--bad); color: #fff; padding: 9px 16px; display: flex; gap: 12px; align-items: center; justify-content: center; font-weight: 500; flex-wrap: wrap; min-height: 44px; }
.alertbar.info { background: var(--accent); }
.alertbar .btn { padding: 4px 10px; min-height: 0; }
.account { display: flex; align-items: center; justify-content: space-between; gap: 8px; color: var(--side-muted); }
.account .btn { padding: 3px 8px; font-size: 12px; background: rgba(255,255,255,.08); border-color: rgba(255,255,255,.12); color: #fff; }
.menu { display: flex; flex-direction: column; gap: 8px; }
.menu .btn { justify-content: flex-start; }
.form-actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 8px; flex-wrap: wrap; }
.calc { background: var(--surface-2); border-radius: 10px; padding: 10px 12px; font-size: 13px; display: flex; gap: 18px; flex-wrap: wrap; margin-bottom: 12px; }
.calc b { font-size: 15px; }
.warnbox { background: var(--warn-soft); color: var(--warn); border-radius: 10px; padding: 10px 12px; font-size: 13px; margin-bottom: 12px; }
.infobox { background: var(--info-soft); color: var(--info); border-radius: 10px; padding: 10px 12px; font-size: 13px; margin-bottom: 12px; }
.okbox { background: var(--good-soft); color: var(--good); border-radius: 10px; padding: 10px 12px; font-size: 13px; margin-bottom: 12px; }
.badbox { background: var(--bad-soft); color: var(--bad); border-radius: 10px; padding: 10px 12px; font-size: 13px; margin-bottom: 12px; }
.log { font-family: var(--mono); font-size: 12px; max-height: 200px; overflow: auto; background: var(--surface-2); border-radius: 8px; padding: 8px 10px; }
details summary { cursor: pointer; font-weight: 600; color: var(--muted); font-size: 13px; margin: 8px 0; }

@media (prefers-reduced-motion: reduce) {
  .toast { transition: opacity .1s linear; transform: translateX(-50%); }
  .btn:active { transform: none; }
}

@media (max-width: 900px) {
  .shell { grid-template-columns: 1fr; }
  .side { position: fixed; bottom: 0; left: 0; right: 0; top: auto; height: auto; flex-direction: row; padding: 4px 4px calc(4px + env(safe-area-inset-bottom)); z-index: 12; align-items: center; }
  .brand, .side-foot { display: none; }
  #nav { flex-direction: row; width: 100%; justify-content: space-around; gap: 0; }
  #nav a, .nav-more { flex: 1; flex-direction: column; gap: 3px; font-size: 11px; padding: 6px 2px; min-height: var(--tap); justify-content: center; border-radius: 8px; }
  #nav a:nth-child(n+6) { display: none; }
  .nav-more { display: flex; }
  .top { padding: 10px 12px; }
  .view { padding: 14px 12px 96px; }
  .fab { display: inline-flex; bottom: calc(74px + env(safe-area-inset-bottom)); }
  .two, .three, .grid2, .grid3, .grid4 { grid-template-columns: 1fr; }
  .drawer-panel { width: 100%; padding: 18px 14px 96px; }
  .modal-card { padding: 18px 14px; max-height: calc(100% - 24px); }
  .timeline li { grid-template-columns: 1fr; gap: 2px; }
  .kpi b { font-size: 19px; }
  /* touch: nothing interactive under 44px */
  .btn, .chip, .tabs button, .close { min-height: var(--tap); }
  .summary .btn.sm, td .btn.wa { min-height: 36px; padding: 6px 10px; }
  .btn.sm { padding: 8px 12px; font-size: 13px; }
  .btn.icon { min-width: var(--tap); padding: 8px; }
  .chip { padding: 9px 14px; }
  input, select, textarea { min-height: var(--tap); font-size: 16px; }
  label.inline input { min-height: 24px; width: 24px; height: 24px; }
  td .rowlink { display: inline-block; padding: 8px 0; }
  td.actions .btn { margin: 2px 0; }
}
@media (min-width: 901px) { .top-actions { display: flex; } }
@media print { .side, .top, .fab { display: none !important; } .shell { display: block; } .view { padding: 0; max-width: none; } }
