/* InLoop Inventory. Colours are roles defined once here, for light and dark. */
:root {
  color-scheme: light;
  --page: #f9f9f7;
  --surface: #fcfcfb;
  --surface-2: #f1f1ee;
  --ink: #0b0b0b;
  --ink-2: #52514e;
  --muted: #898781;
  --line: #e1e0d9;
  --line-strong: #c3c2b7;
  --ring: rgba(11, 11, 11, 0.10);
  --accent: #256abf;
  --accent-ink: #1c5cab;
  --accent-wash: #e6f0fc;
  --on-accent: #ffffff;
  --good: #0ca30c;
  --warning: #fab219;
  --serious: #ec835a;
  --critical: #d03b3b;
  --critical-wash: #fbeceb;
  --st-stock: #2a78d6;
  --st-ordered: #eda100;
  --st-missing: #d03b3b;
  --meter-fill: #2a78d6;
  --meter-track: #cde2fb;
  --shadow: 0 1px 2px rgba(11, 11, 11, .06), 0 12px 32px rgba(11, 11, 11, .12);
  --font: system-ui, -apple-system, "Segoe UI", sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root:where(:not([data-theme="light"])) {
    color-scheme: dark;
    --page: #0d0d0d; --surface: #1a1a19; --surface-2: #242422; --ink: #f0efec; --ink-2: #c3c2b7;
    --muted: #898781; --line: #2c2c2a; --line-strong: #383835; --ring: rgba(255, 255, 255, 0.10);
    --accent: #256abf; --accent-ink: #86b6ef; --accent-wash: #12233a; --on-accent: #ffffff;
    --critical-wash: #331615;
    --st-stock: #3987e5; --st-ordered: #c98500; --st-missing: #d03b3b;
    --meter-fill: #3987e5; --meter-track: #104281;
    --shadow: 0 1px 2px rgba(0, 0, 0, .4), 0 12px 32px rgba(0, 0, 0, .5);
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --page: #0d0d0d; --surface: #1a1a19; --surface-2: #242422; --ink: #f0efec; --ink-2: #c3c2b7;
  --muted: #898781; --line: #2c2c2a; --line-strong: #383835; --ring: rgba(255, 255, 255, 0.10);
  --accent: #256abf; --accent-ink: #86b6ef; --accent-wash: #12233a; --on-accent: #ffffff;
  --critical-wash: #331615;
  --st-stock: #3987e5; --st-ordered: #c98500; --st-missing: #d03b3b;
  --meter-fill: #3987e5; --meter-track: #104281;
  --shadow: 0 1px 2px rgba(0, 0, 0, .4), 0 12px 32px rgba(0, 0, 0, .5);
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body { margin: 0; background: var(--page); color: var(--ink); font: 14px/1.45 var(--font); -webkit-font-smoothing: antialiased; }
a { color: var(--accent-ink); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 21px; font-weight: 650; margin: 0; letter-spacing: -0.01em; }
h2 { font-size: 15px; font-weight: 650; margin: 0 0 10px; }
h3 { font-size: 13px; font-weight: 650; margin: 0 0 6px; }
p { margin: 0 0 10px; }
small, .small { font-size: 12.5px; }
.muted { color: var(--muted); }
.ink2 { color: var(--ink-2); }
.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.nowrap { white-space: nowrap; }
.grow { flex: 1; min-width: 0; }
.row { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.stack { display: flex; flex-direction: column; gap: 14px; }
.spread { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.hidden { display: none !important; }

/* layout */
.shell { display: grid; grid-template-columns: 216px minmax(0, 1fr); min-height: 100vh; }
.side { background: var(--surface); border-right: 1px solid var(--line); padding: 14px 10px; position: sticky; top: 0; height: 100vh; overflow-y: auto; display: flex; flex-direction: column; }
.brand { display: flex; align-items: center; gap: 9px; padding: 4px 8px 14px; font-weight: 700; font-size: 15px; letter-spacing: -0.01em; }
.brand-mark { width: 22px; height: 22px; border-radius: 6px; background: var(--ink); display: grid; place-items: center; }
.brand-mark i { width: 9px; height: 9px; border: 2px solid var(--surface); border-radius: 50%; display: block; }
.nav-group { margin: 10px 8px 4px; font-size: 11px; font-weight: 650; color: var(--muted); text-transform: uppercase; letter-spacing: .06em; }
.nav a { display: flex; align-items: center; justify-content: space-between; padding: 6px 8px; border-radius: 7px; color: var(--ink-2); font-weight: 500; }
.nav a:hover { background: var(--surface-2); text-decoration: none; color: var(--ink); }
.nav a.active { background: var(--accent-wash); color: var(--accent-ink); font-weight: 650; }
.nav .count { font-size: 11.5px; font-weight: 650; min-width: 20px; text-align: center; padding: 0 6px; border-radius: 10px; background: var(--surface-2); color: var(--ink-2); }
.nav .count.alert { background: var(--critical); color: #fff; }
.side-foot { margin-top: auto; padding: 10px 8px 0; border-top: 1px solid var(--line); font-size: 12.5px; color: var(--ink-2); }
.main { min-width: 0; }
.topbar { display: flex; align-items: center; gap: 12px; padding: 10px 24px; border-bottom: 1px solid var(--line); background: var(--surface); position: sticky; top: 0; z-index: 20; }
.content { padding: 20px 24px 60px; max-width: 1500px; }
.content.wide { max-width: none; }
.page-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; margin-bottom: 16px; flex-wrap: wrap; }
.page-head .sub { color: var(--ink-2); margin-top: 3px; }
.crumb { font-size: 12.5px; color: var(--muted); margin-bottom: 4px; }

/* controls */
button, input, select, textarea { font: inherit; color: inherit; }
.btn { display: inline-flex; align-items: center; gap: 6px; padding: 6px 12px; border-radius: 7px; border: 1px solid var(--line-strong); background: var(--surface); color: var(--ink); font-weight: 550; cursor: pointer; white-space: nowrap; line-height: 1.3; }
.btn:hover { background: var(--surface-2); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--on-accent); }
.btn.primary:hover { filter: brightness(1.08); }
.btn.danger { color: var(--critical); border-color: var(--critical); }
.btn.danger.solid { background: var(--critical); color: #fff; }
.btn.ghost { border-color: transparent; background: transparent; color: var(--accent-ink); padding: 4px 7px; }
.btn.ghost:hover { background: var(--accent-wash); }
.btn.sm { padding: 3px 8px; font-size: 12.5px; }
.btn:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible, a:focus-visible, .cell:focus-visible { outline: 2px solid var(--st-stock); outline-offset: 1px; }
input[type=text], input[type=password], input[type=number], input[type=date], input[type=search], input[type=url], select, textarea {
  width: 100%; padding: 6px 9px; border-radius: 7px; border: 1px solid var(--line-strong); background: var(--surface); min-height: 33px; }
textarea { min-height: 70px; resize: vertical; }
input[type=checkbox], input[type=radio] { accent-color: var(--accent); width: 15px; height: 15px; margin: 0; }
input::placeholder, textarea::placeholder { color: var(--muted); }
label.check { display: flex; align-items: flex-start; gap: 8px; cursor: pointer; }
label.check input { margin-top: 3px; flex: none; }
.field { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.field > span.lbl { font-size: 12.5px; font-weight: 600; color: var(--ink-2); }
.field .help { font-size: 12px; color: var(--muted); }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px 14px; }
.form-grid .full { grid-column: 1 / -1; }
.toolbar { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin-bottom: 12px; }
.toolbar input[type=search], .toolbar input[type=text] { width: 260px; }
.toolbar select { width: auto; }
.searchbox { position: relative; width: 340px; max-width: 100%; }
.results { position: absolute; top: 38px; left: 0; right: 0; background: var(--surface); border: 1px solid var(--line-strong); border-radius: 9px; box-shadow: var(--shadow); padding: 6px; z-index: 40; max-height: 60vh; overflow: auto; }
.results a, .results .opt { display: block; padding: 6px 8px; border-radius: 6px; color: var(--ink); cursor: pointer; }
.results a:hover, .results .opt:hover, .results .opt.on { background: var(--accent-wash); text-decoration: none; }
.results .hd { font-size: 11px; font-weight: 650; color: var(--muted); text-transform: uppercase; letter-spacing: .06em; padding: 6px 8px 2px; }
.picker { position: relative; }
.picker .results { top: 36px; }

/* cards, tiles, tables */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: 10px; padding: 14px 16px; }
.card.flush { padding: 0; overflow: hidden; }
.card > .card-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 10px 14px; border-bottom: 1px solid var(--line); }
.card > .card-head h2 { margin: 0; }
.grid2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px; }
.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 10px; margin-bottom: 16px; }
.tile { background: var(--surface); border: 1px solid var(--line); border-radius: 10px; padding: 12px 14px; color: var(--ink); display: block; }
a.tile:hover { text-decoration: none; border-color: var(--line-strong); }
.tile .t-label { font-size: 12.5px; color: var(--ink-2); display: flex; align-items: center; gap: 6px; }
.tile .t-value { font-size: 26px; font-weight: 650; line-height: 1.2; margin-top: 2px; letter-spacing: -0.01em; white-space: nowrap; }
.tile .t-value small { font-size: 13px; font-weight: 600; color: var(--ink-2); margin-left: 4px; letter-spacing: 0; }
.tile .t-note { font-size: 12px; color: var(--muted); margin-top: 1px; }
table.data { width: 100%; border-collapse: collapse; font-size: 13.5px; }
table.data th { text-align: left; font-size: 12px; font-weight: 650; color: var(--ink-2); padding: 7px 10px; border-bottom: 1px solid var(--line-strong); white-space: nowrap; background: var(--surface); position: sticky; top: 0; z-index: 2; }
table.data th.sortable { cursor: pointer; user-select: none; }
table.data th.sortable:hover { color: var(--ink); }
table.data td { padding: 7px 10px; border-bottom: 1px solid var(--line); vertical-align: top; }
table.data tr:last-child td { border-bottom: 0; }
table.data tr.click { cursor: pointer; }
table.data tr.click:hover td { background: var(--surface-2); }
table.data td.actions { text-align: right; white-space: nowrap; padding-top: 4px; padding-bottom: 4px; }
table.data td.actions .btn + .btn { margin-left: 4px; }
table.data tr.section td { background: var(--surface-2); font-weight: 650; font-size: 12px; text-transform: uppercase; letter-spacing: .05em; color: var(--ink-2); padding: 5px 10px; }
.table-wrap { overflow-x: auto; }
.empty { padding: 26px 16px; text-align: center; color: var(--ink-2); }
.empty b { display: block; color: var(--ink); margin-bottom: 4px; }
.kv { display: grid; grid-template-columns: max-content 1fr; gap: 5px 16px; font-size: 13.5px; }
.kv dt { color: var(--ink-2); }
.kv dd { margin: 0; min-width: 0; overflow-wrap: anywhere; }

/* badges: a coloured dot or icon next to ink text, never coloured text alone */
.badge { display: inline-flex; align-items: center; gap: 5px; padding: 1px 8px 1px 6px; border-radius: 20px; border: 1px solid var(--line-strong); font-size: 12px; font-weight: 600; color: var(--ink); white-space: nowrap; background: var(--surface); }
.badge .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--muted); flex: none; }
.badge.plain { padding: 1px 8px; color: var(--ink-2); }
.dot.good { background: var(--good); } .dot.warning { background: var(--warning); } .dot.serious { background: var(--serious); }
.dot.critical { background: var(--critical); } .dot.info { background: var(--st-stock); } .dot.neutral { background: var(--muted); }
.dot.hollow { background: transparent; border: 2px solid var(--muted); }
.tag { display: inline-block; font-size: 11.5px; font-weight: 600; padding: 0 6px; border-radius: 5px; background: var(--surface-2); color: var(--ink-2); border: 1px solid var(--line); white-space: nowrap; }
/* pictures and files */
.pic { display: block; object-fit: contain; background: #fff; border: 1px solid var(--line); border-radius: 6px; }
.pic.wait { background: var(--surface-2); }
.pic.none { background: none; border-style: dashed; }
td.pic-cell { padding-top: 4px; padding-bottom: 4px; }
.page-head .media { flex: none; }
.head-pic { padding: 0; border: 0; background: none; cursor: pointer; border-radius: 8px; }
.head-pic .pic { border-radius: 8px; }
.dropzone { border-radius: 10px; outline: 2px dashed transparent; outline-offset: 6px; }
.dropzone.over { outline-color: var(--accent); background: var(--accent-wash); }
.pic-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(232px, 1fr)); gap: 12px; padding: 14px; }
.pic-card { border: 1px solid var(--line); border-radius: 8px; overflow: hidden; background: var(--surface); min-width: 0; }
.pic-card .frame { display: grid; place-items: center; width: 100%; height: 150px; padding: 0; border: 0; background: #fff; cursor: zoom-in; }
.pic-card .frame img { max-width: 100%; max-height: 150px; object-fit: contain; display: block; }
.pic-card .cap { padding: 7px 9px; border-top: 1px solid var(--line); }
.pic-card .name { font-size: 12.5px; font-weight: 550; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.modal-body.viewer { padding: 0; background: #fff; display: grid; place-items: center; }
.modal-body.viewer img { max-width: 100%; max-height: 72vh; display: block; }
.modal-foot .grow { align-self: center; }
.starter { border: 1px solid var(--line); border-radius: 8px; padding: 10px 12px; }
.starter-head { align-items: flex-start; flex-wrap: nowrap; gap: 14px; }
.callout { border: 1px solid var(--line-strong); border-left: 3px solid var(--st-stock); border-radius: 8px; padding: 9px 12px; background: var(--surface); font-size: 13.5px; }
.callout.bad { border-left-color: var(--critical); background: var(--critical-wash); }
.callout.warn { border-left-color: var(--warning); }

/* meter: fill and track from one ramp */
.meter { display: inline-flex; align-items: center; gap: 7px; }
.meter .track { width: 64px; height: 8px; border-radius: 4px; background: var(--meter-track); overflow: hidden; }
.meter .fill { height: 100%; background: var(--meter-fill); border-radius: 4px; }
.meter .txt { font-size: 12px; color: var(--ink-2); font-variant-numeric: tabular-nums; }

/* tabs */
.tabs { display: flex; gap: 2px; border-bottom: 1px solid var(--line-strong); margin-bottom: 14px; overflow-x: auto; }
.tabs button { background: none; border: 0; padding: 8px 12px; font-weight: 600; color: var(--ink-2); cursor: pointer; border-bottom: 2px solid transparent; margin-bottom: -1px; white-space: nowrap; }
.tabs button:hover { color: var(--ink); }
.tabs button.on { color: var(--ink); border-bottom-color: var(--accent); }
.tabs .n { font-weight: 500; color: var(--muted); margin-left: 4px; }

/* modal + toast */
.overlay { position: fixed; inset: 0; background: rgba(11, 11, 11, .45); display: flex; align-items: flex-start; justify-content: center; padding: 6vh 16px 16px; z-index: 100; overflow-y: auto; }
.modal { background: var(--surface); border-radius: 12px; box-shadow: var(--shadow); width: 560px; max-width: 100%; border: 1px solid var(--ring); }
.modal.wide { width: 780px; }
.modal-head { display: flex; align-items: center; justify-content: space-between; padding: 14px 18px 10px; }
.modal-head h2 { margin: 0; font-size: 16px; }
.modal-body { padding: 4px 18px 14px; }
.modal-foot { display: flex; justify-content: flex-end; gap: 8px; padding: 12px 18px; border-top: 1px solid var(--line); }
.x { background: none; border: 0; cursor: pointer; font-size: 20px; line-height: 1; color: var(--muted); padding: 2px 6px; border-radius: 6px; }
.x:hover { background: var(--surface-2); color: var(--ink); }
.error { color: var(--ink); background: var(--critical-wash); border: 1px solid var(--critical); border-radius: 8px; padding: 8px 11px; font-size: 13.5px; margin-bottom: 10px; }
.toasts { position: fixed; right: 18px; bottom: 18px; display: flex; flex-direction: column; gap: 8px; z-index: 200; }
.toast { background: var(--ink); color: var(--page); padding: 9px 14px; border-radius: 9px; box-shadow: var(--shadow); font-weight: 550; max-width: 420px; }
.toast.bad { background: var(--critical); color: #fff; }

/* fleet matrix */
.legend { display: flex; flex-wrap: wrap; gap: 6px 16px; font-size: 12.5px; color: var(--ink-2); margin-bottom: 10px; }
.legend span.item { display: inline-flex; align-items: center; gap: 6px; }
.mark { width: 18px; height: 18px; border-radius: 5px; display: inline-grid; place-items: center; flex: none; color: #fff; }
.mark svg { width: 12px; height: 12px; display: block; }
.mark.ok { background: transparent; color: var(--good); border: 1.5px solid var(--line-strong); }
.mark.old { background: transparent; color: var(--ink-2); border: 1.5px solid var(--line-strong); }
.mark.upgrade { background: var(--ink); color: var(--surface); }
.mark.partial { background: transparent; color: var(--st-stock); border: 1.5px solid var(--st-stock); }
.mark.in_stock { background: var(--st-stock); color: #fff; }
.mark.ordered { background: var(--st-ordered); color: #0b0b0b; }
.mark.missing { background: var(--st-missing); color: #fff; }
.matrix-wrap { overflow: auto; max-height: calc(100vh - 250px); border: 1px solid var(--line); border-radius: 10px; background: var(--surface); }
table.matrix { border-collapse: separate; border-spacing: 0; font-size: 13px; }
table.matrix th, table.matrix td { border-bottom: 1px solid var(--line); border-right: 1px solid var(--line); padding: 5px 8px; background: var(--surface); }
table.matrix thead th { position: sticky; top: 0; z-index: 5; vertical-align: bottom; text-align: left; font-size: 12px; font-weight: 650; color: var(--ink-2); }
table.matrix thead th.robot { min-width: 92px; max-width: 120px; text-align: center; font-weight: 600; color: var(--ink); }
table.matrix thead th.robot a { color: var(--ink); display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
table.matrix thead th.robot .meter { margin-top: 4px; justify-content: center; }
table.matrix thead th.robot .meter .track { width: 44px; }
table.matrix .stick { position: sticky; left: 0; z-index: 4; }
table.matrix thead .stick { z-index: 6; }
table.matrix td.name { min-width: 250px; max-width: 320px; }
table.matrix td.name .pn { color: var(--muted); font-size: 12px; margin-right: 6px; font-variant-numeric: tabular-nums; }
table.matrix tr.section td { background: var(--surface-2); font-weight: 650; font-size: 12px; text-transform: uppercase; letter-spacing: .05em; color: var(--ink-2); }
table.matrix tr.section td span { position: sticky; left: 8px; display: inline-block; }
table.matrix td.c { padding: 0; text-align: center; }
.cell { display: flex; align-items: center; justify-content: center; gap: 5px; width: 100%; min-height: 31px; padding: 3px 6px; background: none; border: 0; cursor: pointer; position: relative; color: var(--ink-2); font-size: 12px; font-variant-numeric: tabular-nums; }
.cell:hover { background: var(--surface-2); }
.cell.noted::after { content: ""; position: absolute; top: 0; right: 0; border-style: solid; border-width: 0 8px 8px 0; border-color: transparent var(--ink-2) transparent transparent; }
table.matrix th.dim > *, table.matrix td.dim > * { opacity: .5; }
.cell-note { max-width: 110px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--ink); }

/* auth */
.auth { min-height: 100vh; display: grid; place-items: center; padding: 20px; }
.auth .card { width: 380px; max-width: 100%; padding: 22px; }
.auth .brand { padding: 0 0 12px; font-size: 17px; }

@media (max-width: 900px) {
  .shell { grid-template-columns: 1fr; }
  .side { position: static; height: auto; flex-direction: row; flex-wrap: wrap; gap: 4px; border-right: 0; border-bottom: 1px solid var(--line); }
  .side .nav { display: flex; flex-wrap: wrap; gap: 2px; }
  .nav-group, .side-foot { display: none; }
  .pic-grid { grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); padding: 10px; gap: 10px; }
  .pic-card .frame, .pic-card .frame img { height: 110px; max-height: 110px; }
  .pic-card .frame img { height: auto; }
  .starter-head { flex-wrap: wrap; gap: 8px; }
  .starter-head .grow { flex-basis: 100%; }
  .grid2, .form-grid { grid-template-columns: 1fr; }
  .page-head { flex-direction: column; align-items: stretch; }
  .content { padding: 14px; }
  .topbar { padding: 8px 14px; }
}
@media print {
  .side, .topbar, .toolbar, .btn, .tabs { display: none !important; }
  .shell { display: block; }
  .matrix-wrap { max-height: none; overflow: visible; border: 0; }
}

/* watchdog events */
.event-detail { white-space: pre-wrap; word-break: break-word; max-height: 320px; overflow: auto; margin: 6px 0 0;
  padding: 8px 10px; border-radius: 6px; background: var(--surface-2); font-size: 12px; line-height: 1.45; }
