/* DIIMS look and feel. Colors come from the DIIMS logo and design file (navy, green, sky).
   Sections: tokens, shell, buttons, forms, tables, dialogs, dashboard, scanning, warehouse map, printable labels. */
:root {
  --brand: #16407a; --brand-dd: #0f2d5c; --brand-50: #e3ecf9; --brand-100: #cfe0f5; --sky: #a8d5f2; --sky-50: #eaf4fc; --accent: #5bb85b; --green-d: #3f8f3f; --focus: #1f78c1;
  --ink: #1f2933; --ink-2: #3d4852; --muted: #5f6b76; --line: #dfe6ea; --line-2: #c3cdd4;
  --bg: #f3f6f7; --surface: #fff;
  --side: #0f2d5c; --side-2: #16407a; --side-ink: #eef2f6; --side-muted: #a9b6c4;
  --danger: #b42318; --danger-bg: #fdecea; --warn: #7a4f00; --warn-bg: #fff3d1; --ok: #2c6a17; --ok-bg: #e6f4dc;
  --r: 10px; --r-sm: 7px;
  --font: "Segoe UI", system-ui, -apple-system, Roboto, "Helvetica Neue", Arial, sans-serif;
}
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--bg); color: var(--ink); font: 16px/1.5 var(--font); }
h1, h2, h3, p { margin: 0; }
h1 { font-size: 1.5rem; line-height: 1.25; font-weight: 650; }
h2 { font-size: 1.125rem; line-height: 1.3; font-weight: 650; }
h3 { font-size: 1rem; font-weight: 650; }
a { color: var(--brand); }
button, input, select, textarea { font: inherit; color: inherit; }
:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.muted { color: var(--muted); }
.icon { width: 20px; height: 20px; flex: none; }

/* Shell */
.shell { display: grid; grid-template-columns: 1fr; min-height: 100vh; }
.sidebar { position: fixed; inset: 0 auto 0 0; width: 272px; max-width: 86vw; background: var(--side); color: var(--side-ink);
  display: flex; flex-direction: column; transform: translateX(-100%); transition: transform .18s ease; z-index: 30; overflow-y: auto; }
.sidebar.is-open { transform: none; }
.scrim { position: fixed; inset: 0; background: rgba(15, 23, 32, .5); z-index: 20; }
.brand { display: flex; align-items: center; gap: 12px; padding: 18px 18px 14px; }
.brand img { width: 44px; height: 44px; border-radius: 50%; background: #fff; object-fit: contain; }
.brand-name { font-weight: 650; line-height: 1.2; }
.brand-sub { font-size: .8125rem; color: var(--side-muted); }
.nav { padding: 6px 10px 20px; }
.nav-group { margin: 16px 10px 4px; font-size: .8125rem; color: var(--side-muted); }
.nav-link { display: flex; align-items: center; gap: 12px; min-height: 44px; padding: 0 12px; border-radius: var(--r-sm);
  color: var(--side-ink); text-decoration: none; }
.nav-link:hover { background: var(--side-2); }
.nav-link[aria-current="page"] { background: rgba(136, 200, 240, .18); box-shadow: inset 4px 0 0 var(--accent); font-weight: 600; }
.main { min-width: 0; display: flex; flex-direction: column; }
.topbar { position: sticky; top: 0; z-index: 10; display: flex; align-items: center; gap: 10px; padding: 8px 12px;
  background: var(--surface); border-bottom: 1px solid var(--line); min-height: 56px; }
.topbar .spacer { flex: 1; }
.site-pick { min-width: 0; max-width: 220px; }
.view { padding: 18px 14px 56px; width: 100%; max-width: 1180px; margin: 0 auto; }
.view:focus { outline: none; }
.page-head { display: flex; flex-wrap: wrap; align-items: flex-end; justify-content: space-between; gap: 12px; margin-bottom: 18px; }
.page-head p { color: var(--muted); margin-top: 2px; max-width: 60ch; }
.actions { display: flex; flex-wrap: wrap; gap: 8px; }
@media (min-width: 960px) {
  .shell { grid-template-columns: 272px 1fr; }
  .sidebar { position: sticky; top: 0; height: 100vh; transform: none; transition: none; }
  .scrim, .menu-btn { display: none; }
  .view { padding: 28px 32px 64px; }
}

/* Buttons */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-height: 44px; padding: 0 16px;
  border: 1px solid var(--line-2); border-radius: var(--r-sm); background: var(--surface); font-weight: 600; cursor: pointer; text-decoration: none; color: var(--ink); }
.btn:hover { background: #eef3f5; }
.btn[disabled] { opacity: .55; cursor: not-allowed; }
.btn--primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn--primary:hover { background: var(--brand-dd); }
.btn--danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn--danger:hover { background: #8f1c12; }
.btn--sm { min-height: 36px; padding: 0 12px; font-size: .9375rem; }
.btn--quiet { border-color: transparent; background: transparent; }
.icon-btn { display: inline-grid; place-items: center; width: 44px; height: 44px; border: 0; background: transparent; border-radius: var(--r-sm); cursor: pointer; }
.icon-btn:hover { background: #eef3f5; }

/* Forms */
.form { display: grid; gap: 14px; }
.field { display: grid; gap: 4px; min-width: 0; }
.field > label, .field > .label { font-weight: 600; }
.field .opt { font-weight: 400; color: var(--muted); }
.input, .select, .textarea { width: 100%; min-height: 44px; padding: 9px 12px; background: #fff; border: 1px solid var(--line-2); border-radius: var(--r-sm); }
.textarea { min-height: 88px; resize: vertical; }
.input:focus, .select:focus, .textarea:focus { outline: 3px solid var(--focus); outline-offset: 0; border-color: var(--brand); }
.input[disabled], .select[disabled] { background: #f1f4f6; color: var(--muted); }
.hint { color: var(--muted); font-size: .875rem; }
.field--error .input, .field--error .select, .field--error .textarea { border-color: var(--danger); }
.field-error { color: var(--danger); font-size: .9375rem; }
.form-error { background: var(--danger-bg); color: #7a1a12; border: 1px solid #f1b9b2; border-radius: var(--r-sm); padding: 10px 12px; }
.check { display: flex; align-items: center; gap: 10px; min-height: 44px; cursor: pointer; }
.check input { width: 22px; height: 22px; accent-color: var(--brand); flex: none; }
.checks { display: grid; gap: 0 16px; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); }
.row2 { display: grid; gap: 14px; grid-template-columns: 1fr; }
@media (min-width: 560px) { .row2 { grid-template-columns: 1fr 1fr; } }
.preview { background: var(--brand-50); border: 1px solid var(--brand-100); border-radius: var(--r-sm); padding: 8px 12px; color: #003060; }

/* Surfaces */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r); }
.card + .card { margin-top: 16px; }
.card-head { padding: 16px 18px 0; }
.card-head p { color: var(--muted); }
.card-body { padding: 16px 18px 18px; }
.toolbar { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; margin-bottom: 14px; }
.toolbar .input, .toolbar .select { width: auto; min-width: 180px; flex: 1 1 200px; max-width: 320px; }
.toolbar .check { min-height: 44px; }

/* Tables: columns on wide screens, stacked cards on phones */
.table-wrap { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r); overflow-x: auto; }
.table { width: 100%; border-collapse: collapse; }
.table th { text-align: left; font-weight: 600; color: var(--muted); font-size: .9375rem; padding: 10px 14px; background: #f8fafb; border-bottom: 1px solid var(--line); }
.table td { padding: 12px 14px; border-bottom: 1px solid var(--line); vertical-align: middle; }
.table tr:last-child td { border-bottom: 0; }
.table .num { text-align: right; font-variant-numeric: tabular-nums; }
.table .actions-cell { text-align: right; white-space: nowrap; }
.table .sub { color: var(--muted); font-size: .9rem; }
.table tr.is-inactive td { color: var(--muted); }
.loc-name { padding-left: calc(var(--depth, 0) * 22px); display: flex; align-items: center; gap: 8px; }
@media (max-width: 719px) {
  .table thead { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
  .table, .table tbody, .table tr, .table td { display: block; width: 100%; }
  .table tr { padding: 10px 14px; border-bottom: 1px solid var(--line); }
  .table tr:last-child { border-bottom: 0; }
  .table td { display: flex; justify-content: space-between; gap: 16px; padding: 4px 0; border: 0; text-align: right; }
  .table td::before { content: attr(data-label); color: var(--muted); text-align: left; flex: none; }
  .table td.actions-cell { justify-content: flex-end; padding-top: 8px; }
  .table td.actions-cell::before, .table td[data-label=""]::before { content: none; }
  .table .loc-name { padding-left: calc(var(--depth, 0) * 14px); }
}

.badge { display: inline-block; padding: 2px 10px; border-radius: 999px; font-size: .8125rem; font-weight: 600; background: #e9eef1; color: var(--ink-2); white-space: nowrap; }
.badge--brand { background: var(--brand-50); color: #003060; }
.badge--ok { background: var(--ok-bg); color: var(--ok); }
.badge--warn { background: var(--warn-bg); color: var(--warn); }
.badge--off { background: #eceff1; color: var(--muted); }

.empty { text-align: center; padding: 44px 20px; background: var(--surface); border: 1px dashed var(--line-2); border-radius: var(--r); }
.empty h3 { margin-bottom: 4px; }
.empty p { color: var(--muted); max-width: 46ch; margin: 0 auto 16px; }
.state { padding: 40px 0; text-align: center; color: var(--muted); }
.spinner { width: 26px; height: 26px; margin: 0 auto 10px; border-radius: 50%; border: 3px solid var(--line); border-top-color: var(--brand); animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* Dashboard */
.steps { list-style: none; margin: 0; padding: 0; }
.step { display: grid; grid-template-columns: 28px 1fr auto; gap: 12px; align-items: center; padding: 14px 18px; border-top: 1px solid var(--line); }
.step:first-child { border-top: 0; }
.step-mark { width: 26px; height: 26px; border-radius: 50%; border: 2px solid var(--line-2); display: grid; place-items: center; color: #fff; }
.step.is-done .step-mark { background: var(--green-d); border-color: var(--green-d); }
.step .icon { width: 16px; height: 16px; }
.step small { display: block; color: var(--muted); }
.progress { height: 8px; background: var(--line); border-radius: 99px; overflow: hidden; margin-top: 12px; }
.progress > span { display: block; height: 100%; background: var(--accent); }
.modules { list-style: none; margin: 0; padding: 0; display: grid; gap: 0 24px; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); }
.modules li { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 12px 0; border-top: 1px solid var(--line); }
.plan-list { margin: 12px 0 0; padding-left: 20px; display: grid; gap: 6px; }

/* Modal, menu, toast */
.form-actions { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 8px; margin-top: 6px; padding-bottom: 14px; }
.overlay { position: fixed; inset: 0; z-index: 50; display: flex; align-items: flex-end; justify-content: center; background: rgba(15, 23, 32, .55); padding: 0; }
.modal { background: var(--surface); width: 100%; max-height: 92vh; overflow: auto; border-radius: 16px 16px 0 0; box-shadow: 0 -8px 30px rgba(0, 0, 0, .25); }
.modal-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 14px 16px 0 20px; }
.modal-body { padding: 14px 20px 6px; }
.modal-foot { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 8px; padding: 14px 20px 20px; }
@media (min-width: 600px) {
  .overlay { align-items: center; padding: 24px; }
  .modal { width: 540px; border-radius: var(--r); box-shadow: 0 20px 50px rgba(0, 0, 0, .3); }
  .modal--wide { width: 680px; }
}
.menu { position: relative; }
.menu-panel { position: absolute; right: 0; top: calc(100% + 6px); min-width: 230px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--r); box-shadow: 0 10px 30px rgba(0, 0, 0, .14); padding: 8px; z-index: 40; }
.menu-panel .who { padding: 8px 10px 10px; border-bottom: 1px solid var(--line); margin-bottom: 6px; }
.menu-panel .who span { display: block; color: var(--muted); font-size: .9rem; }
.menu-item { display: flex; align-items: center; gap: 10px; width: 100%; min-height: 44px; padding: 0 10px; border: 0; background: transparent; border-radius: var(--r-sm); cursor: pointer; text-align: left; }
.menu-item:hover { background: #eef3f5; }
.user-btn { display: flex; align-items: center; gap: 10px; min-height: 44px; padding: 0 8px; border: 0; background: transparent; border-radius: var(--r-sm); cursor: pointer; }
.avatar { width: 32px; height: 32px; border-radius: 50%; background: var(--brand); color: #fff; display: grid; place-items: center; font-weight: 650; font-size: .875rem; }
.user-btn .label { display: none; text-align: left; line-height: 1.2; }
@media (min-width: 720px) { .user-btn .label { display: block; } }
.toasts { position: fixed; left: 0; right: 0; bottom: 16px; display: grid; gap: 8px; justify-items: center; z-index: 60; pointer-events: none; padding: 0 12px; }
.toast { pointer-events: auto; background: #1f2933; color: #fff; padding: 11px 16px; border-radius: var(--r-sm); max-width: 520px; box-shadow: 0 6px 20px rgba(0, 0, 0, .25); }
.toast--error { background: var(--danger); }
.secret { display: flex; gap: 8px; align-items: center; }
.secret code { flex: 1; font: 600 1.25rem/1 ui-monospace, "Cascadia Mono", Consolas, monospace; letter-spacing: .04em; background: var(--brand-50); border: 1px solid var(--brand-100); padding: 14px; border-radius: var(--r-sm); user-select: all; word-break: break-all; }
.notice { background: var(--warn-bg); color: var(--warn); border-radius: var(--r-sm); padding: 10px 12px; }
.notice--ok { background: var(--ok-bg); color: var(--ok); }

/* Logo upload and update notice */
.logo-row { display: flex; flex-wrap: wrap; align-items: center; gap: 18px; }
.logo-preview { width: 96px; height: 96px; object-fit: contain; background: #fff; border: 1px solid var(--line); border-radius: 12px; padding: 6px; }
.logo-controls { display: grid; gap: 8px; flex: 1 1 260px; }
.update-banner { display: flex; flex-wrap: wrap; gap: 6px 14px; align-items: center; padding: 10px 16px; background: var(--warn-bg); color: var(--warn); font-weight: 600; }
.update-banner a { color: inherit; }

/* Startup messages */
.boot-msg { padding: 48px 20px; text-align: center; color: var(--muted); }
.boot-box { max-width: 520px; margin: 12vh auto 0; padding: 24px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--r); }
.boot-box h1 { font-size: 1.25rem; margin-bottom: 8px; }

/* Sign in */
.login { min-height: 100vh; display: grid; place-items: center; padding: 20px; background: var(--side); }
.login-card { width: 100%; max-width: 400px; background: var(--surface); border-radius: 14px; padding: 28px 24px 24px; }
.login-brand { display: grid; justify-items: center; gap: 10px; text-align: center; margin-bottom: 18px; }
.login-brand img { width: 132px; height: 132px; }
.login-brand h1 { font-size: 1.125rem; font-weight: 600; color: var(--ink-2); }
.login-card .form { margin-top: 6px; }
details.diff summary { cursor: pointer; color: var(--brand); }
details.diff pre { margin: 6px 0 0; padding: 10px; background: #f6f8f9; border-radius: var(--r-sm); overflow: auto; font-size: .85rem; max-width: 100%; white-space: pre-wrap; word-break: break-word; }

@media (prefers-reduced-motion: reduce) { *, *::before, *::after { animation: none !important; transition: none !important; } }


/* ===== Stat strip, detail lists, history ===== */
.stats { display: grid; gap: 12px; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); margin-bottom: 16px; }
.stat { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r); padding: 14px 16px; }
.stat-value { font-size: 1.5rem; font-weight: 650; font-variant-numeric: tabular-nums; }
.detail-list { display: grid; grid-template-columns: max-content 1fr; gap: 6px 18px; margin: 0; }
.detail-list dt { color: var(--muted); }
.detail-list dd { margin: 0; min-width: 0; overflow-wrap: anywhere; }
.history { margin: 8px 0 0; padding-left: 18px; display: grid; gap: 4px; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.starter-group { border: 1px solid var(--line); border-radius: var(--r-sm); margin: 0; padding: 8px 12px 4px; }
.starter-group legend { font-weight: 600; padding: 0 6px; }
.kit-rows { display: grid; gap: 8px; }
.kit-row { display: grid; gap: 8px; grid-template-columns: 1fr 90px auto; align-items: center; }

/* ===== Scan hub (built for one-handed phone use) ===== */
.scan-tiles { display: grid; gap: 12px; grid-template-columns: repeat(auto-fit, minmax(230px, 1fr)); }
.scan-tile { display: grid; gap: 6px; justify-items: start; text-align: left; min-height: 124px; padding: 16px; background: var(--surface);
  border: 1px solid var(--line); border-radius: var(--r); cursor: pointer; color: var(--brand); }
.scan-tile strong { color: var(--ink); font-size: 1.0625rem; }
.scan-tile:hover:not([disabled]) { border-color: var(--brand); background: var(--brand-50); }
.scan-tile[disabled] { opacity: .65; cursor: not-allowed; }
.scan-top { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 6px; }
.scan-prompt { font-weight: 600; margin: 0 0 10px; }
.scanner { display: grid; gap: 8px; margin-bottom: 12px; }
.scanner-frame { position: relative; background: #0b1b2e; border-radius: var(--r); overflow: hidden; aspect-ratio: 4 / 3; max-height: 52vh; width: 100%; }
.scanner-video { width: 100%; height: 100%; object-fit: cover; display: block; }
.scanner-aim { position: absolute; inset: 16% 18%; border: 3px solid rgba(255, 255, 255, .92); border-radius: 14px; box-shadow: 0 0 0 9999px rgba(0, 0, 0, .3); pointer-events: none; }
.scanner-status { color: var(--muted); font-size: .9375rem; }
.scanner-torch { justify-self: start; }
.manual-entry { display: flex; gap: 8px; margin-bottom: 14px; }
.manual-entry .input { flex: 1; min-width: 0; }
.scan-panel { display: grid; gap: 12px; }
.scan-card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r); padding: 14px 16px; display: grid; gap: 6px; }
.scan-card h2 { overflow-wrap: anywhere; }
.scan-card p { margin: 0; }
.scan-card-head { display: flex; justify-content: space-between; align-items: center; gap: 10px; }
.scan-card--ok { background: var(--ok-bg); border-color: #b9dfa3; }
.scan-card--problem { background: var(--danger-bg); border-color: #f1b9b2; }
.scan-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.scan-row { width: 100%; text-align: left; display: grid; gap: 2px; padding: 10px 12px; min-height: 44px; border: 1px solid var(--line); border-radius: var(--r-sm); background: #fff; cursor: pointer; }
.scan-row:hover { background: var(--brand-50); }

/* ===== Warehouse map ===== */
.map-grid { display: grid; grid-template-columns: 72px repeat(var(--bays, 1), minmax(86px, 1fr)); gap: 6px; overflow-x: auto; padding-bottom: 6px; }
.map-aisle-label { align-self: center; font-weight: 600; color: var(--muted); }
.map-bay { display: grid; gap: 3px; align-content: start; }
.map-slot { display: flex; justify-content: space-between; gap: 6px; min-height: 38px; padding: 4px 7px; text-align: left; font-size: .8125rem;
  border: 1px solid var(--line-2); border-radius: 6px; background: #fff; cursor: pointer; align-items: center; }
.map-slot:hover { outline: 2px solid var(--brand); }
.map-slot-level { font-weight: 700; }
.map-slot-what { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.map-slot.is-empty, .map-swatch.is-empty { background: #fff; color: var(--muted); }
.map-slot.is-full, .map-swatch.is-full { background: var(--brand-100); border-color: var(--brand); }
.map-slot.is-hold, .map-swatch.is-hold { background: var(--warn-bg); border-color: #d9a928; }
.map-slot.is-recount, .map-swatch.is-recount { background: var(--sky-50); border: 2px dashed var(--brand); }
.map-slot.is-inactive, .map-swatch.is-inactive { background: #eceff1; color: var(--muted); border-style: dashed; }
.map-legend { display: flex; flex-wrap: wrap; gap: 6px 16px; list-style: none; padding: 0; margin: 14px 0 0; color: var(--muted); }
.map-swatch { display: inline-block; width: 16px; height: 16px; border: 1px solid var(--line-2); border-radius: 4px; margin-right: 6px; vertical-align: -3px; }

/* ===== Printable labels ===== */
.qr-label-sheet { display: grid; grid-template-columns: repeat(auto-fill, 2.6in); gap: .15in; }
.qr-label { width: 2.6in; height: 1.7in; padding: .1in; display: flex; gap: .1in; align-items: center; background: #fff; border: 1px dashed #8a97a3; break-inside: avoid; overflow: hidden; }
.qr-label-qr svg { display: block; width: 1.4in; height: 1.4in; }
.qr-label-text { display: grid; gap: 2px; min-width: 0; font-size: 9pt; line-height: 1.2; }
.qr-label-head { font-size: 14pt; line-height: 1.1; overflow-wrap: anywhere; }
@media print {
  .sidebar, .topbar, .page-head, .toolbar, .update-banner, .toasts, .scrim, .no-print { display: none !important; }
  .shell { display: block; }
  body { background: #fff; }
  .view { padding: 0; max-width: none; }
  .qr-label { border: 1px solid #000; }
  @page { margin: .35in; }
}
@media (max-width: 719px) { .kit-row { grid-template-columns: 1fr 80px; } .kit-row .btn { grid-column: 1 / -1; } }
