:root {
  --bg: #f4f5f7;
  --panel: #ffffff;
  --border: #e3e6ea;
  --text: #1a202c;
  --muted: #6b7280;
  --accent: #2563eb;
  --accent-soft: #eff4ff;
  --green: #16a34a;
  --green-soft: #ecfdf3;
  --amber: #d97706;
  --amber-soft: #fffbeb;
  --red: #dc2626;
  --red-soft: #fef2f2;
  --purple: #7c3aed;
  --purple-soft: #f5f3ff;
  --sidebar: #111827;
  --sidebar-text: #9ca3af;
  --radius: 10px;
  --shadow: 0 1px 3px rgba(16, 24, 40, 0.08), 0 1px 2px rgba(16, 24, 40, 0.04);
  --surface-2: #fafbfc;   /* table headers, subtle fills */
  --hover: #f6f8fb;       /* row / button hover */
  --input-bg: #ffffff;
}

/* ---------- Appearance: accent themes ---------- */
html[data-accent="violet"] { --accent: #7c3aed; --accent-soft: #f3effe; }
html[data-accent="green"]  { --accent: #16a34a; --accent-soft: #e9faf0; }
html[data-accent="slate"]  { --accent: #475569; --accent-soft: #eef1f5; }
html[data-accent="rose"]   { --accent: #e11d48; --accent-soft: #ffeef1; }
html[data-accent="amber"]  { --accent: #d97706; --accent-soft: #fff5e6; }

/* ---------- Appearance: text size (content zoom) ---------- */
html[data-text="small"] .main { zoom: 0.92; }
html[data-text="large"] .main { zoom: 1.14; }

/* ---------- Appearance: dark theme ---------- */
html[data-theme="dark"] {
  --bg: #0f141b;
  --panel: #1a212c;
  --border: #2b3542;
  --text: #e6eaf0;
  --muted: #93a1b3;
  --accent-soft: rgba(37, 99, 235, 0.20);
  --green-soft: rgba(22, 163, 74, 0.18);
  --amber-soft: rgba(217, 119, 6, 0.18);
  --red-soft: rgba(220, 38, 38, 0.18);
  --purple-soft: rgba(124, 58, 237, 0.22);
  --sidebar: #0b0f15;
  --shadow: 0 1px 3px rgba(0, 0, 0, 0.45);
  --surface-2: #141b24;
  --hover: #222b37;
  --input-bg: #131a23;
}
html[data-theme="dark"][data-accent="violet"] { --accent-soft: rgba(124, 58, 237, 0.22); }
html[data-theme="dark"][data-accent="green"]  { --accent-soft: rgba(22, 163, 74, 0.20); }
html[data-theme="dark"][data-accent="rose"]   { --accent-soft: rgba(225, 29, 72, 0.20); }
html[data-theme="dark"][data-accent="amber"]  { --accent-soft: rgba(217, 119, 6, 0.20); }
html[data-theme="dark"] .tbl td { border-bottom-color: var(--border); }
html[data-theme="dark"] .tbl tr:last-child td { border-bottom: none; }
html[data-theme="dark"] .stat,
html[data-theme="dark"] .loc-card,
html[data-theme="dark"] .login-card { background: var(--panel); }
html[data-theme="dark"] .shortage-alert { background: rgba(220,38,38,0.10); border-color: rgba(220,38,38,0.4); }
html[data-theme="dark"] .shortage-alert .sa-table th,
html[data-theme="dark"] .card.card-alert > .card-head { background: rgba(220,38,38,0.16); color: #fca5a5; }
html[data-theme="dark"] .section-row td { background: #1f2733; }
html[data-theme="dark"] .pick-progress { background: #2b3542; }
html[data-theme="dark"] .seg-tabs { background: #131a23; }
html[data-theme="dark"] .seg-tabs .seg.active { background: var(--panel); color: var(--text); }
html[data-theme="dark"] input[type=checkbox] { filter: invert(0.1); }
html[data-theme="dark"] input,
html[data-theme="dark"] select,
html[data-theme="dark"] textarea { color: var(--text); }
html[data-theme="dark"] input:-webkit-autofill,
html[data-theme="dark"] input:-webkit-autofill:hover,
html[data-theme="dark"] input:-webkit-autofill:focus {
  -webkit-box-shadow: 0 0 0 30px var(--input-bg) inset !important;
  -webkit-text-fill-color: var(--text) !important;
  caret-color: var(--text);
}

/* ---------- Appearance: tag (chip) styles ---------- */
html[data-tags="solid"] .chip.green  { background: var(--green);  color: #fff; }
html[data-tags="solid"] .chip.amber  { background: var(--amber);  color: #fff; }
html[data-tags="solid"] .chip.red    { background: var(--red);    color: #fff; }
html[data-tags="solid"] .chip.blue   { background: var(--accent); color: #fff; }
html[data-tags="solid"] .chip.purple { background: var(--purple); color: #fff; }
html[data-tags="solid"] .chip.gray   { background: var(--muted);  color: #fff; }
html[data-tags="outline"] .chip { background: transparent; border: 1px solid currentColor; }
html[data-tags="outline"] .chip.gray { color: var(--muted); }

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
}
button { font: inherit; cursor: pointer; }
input, select, textarea { font: inherit; color: inherit; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ---------- Layout ---------- */
#app { display: flex; min-height: 100vh; }
.sidebar {
  width: 218px; flex-shrink: 0; background: var(--sidebar); color: var(--sidebar-text);
  display: flex; flex-direction: column; position: sticky; top: 0; height: 100vh;
}
.sidebar .brand {
  padding: 18px 18px 14px; color: #fff; font-weight: 700; font-size: 16px;
  display: flex; align-items: center; gap: 9px; letter-spacing: 0.2px;
}
.brand-mark {
  width: 28px; height: 28px; border-radius: 7px; background: var(--accent);
  display: inline-flex; align-items: center; justify-content: center; font-size: 15px;
}
.nav { flex: 1; overflow-y: auto; padding: 6px 10px; }
.nav a {
  display: flex; align-items: center; gap: 10px; padding: 9px 12px; border-radius: 8px;
  color: var(--sidebar-text); font-weight: 500; margin-bottom: 1px;
}
.nav a:hover { background: rgba(255,255,255,0.06); color: #e5e7eb; text-decoration: none; }
.nav a.active { background: rgba(37, 99, 235, 0.25); color: #fff; }
.nav .nav-section { font-size: 11px; text-transform: uppercase; letter-spacing: 0.8px; padding: 14px 12px 5px; color: var(--muted); }
.nav .icon { width: 18px; text-align: center; }
.sidebar .user-box {
  padding: 12px 14px; border-top: 1px solid rgba(255,255,255,0.08);
  display: flex; align-items: center; gap: 10px; font-size: 13px;
}
.user-box .avatar {
  width: 30px; height: 30px; border-radius: 50%; background: var(--accent); color: #fff;
  display: inline-flex; align-items: center; justify-content: center; font-weight: 600; flex-shrink: 0;
}
.user-box .uname { color: #e5e7eb; font-weight: 600; line-height: 1.15; }
.user-box .urole { font-size: 11px; text-transform: capitalize; }
.user-box button { background: none; border: none; color: var(--sidebar-text); padding: 4px; margin-left: auto; }
.user-box button:hover { color: #fff; }

.main { flex: 1; min-width: 0; padding: 22px 28px 60px; }
.page-head { display: flex; align-items: center; gap: 14px; margin-bottom: 18px; flex-wrap: wrap; }
.page-head h1 { font-size: 21px; margin: 0; font-weight: 700; }
.page-head .sub { color: var(--muted); font-size: 13px; }
.page-head .spacer { flex: 1; }

/* ---------- Components ---------- */
.card { background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); }
.card .card-head { padding: 13px 16px; border-bottom: 1px solid var(--border); font-weight: 600; display: flex; align-items: center; gap: 10px; }
.card .card-head .spacer { flex: 1; }
.card .card-body { padding: 16px; }

.btn {
  display: inline-flex; align-items: center; gap: 6px; padding: 7px 14px; border-radius: 8px;
  border: 1px solid var(--border); background: var(--panel); color: var(--text); font-weight: 600; font-size: 13px;
  white-space: nowrap;
}
.btn:hover { background: var(--hover); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { filter: brightness(0.92); }
.btn.danger { color: var(--red); border-color: #fecaca; }
.btn.danger:hover { background: var(--red-soft); }
.btn.success { background: var(--green); border-color: var(--green); color: #fff; }
.btn.success:hover { filter: brightness(0.92); }
.btn.sm { padding: 4px 10px; font-size: 12px; border-radius: 7px; }
.btn.xs { padding: 2px 6px; font-size: 11px; border-radius: 5px; line-height: 1.4; }
.btn.ghost { border-color: transparent; background: transparent; color: var(--muted); }
.btn.ghost:hover { background: var(--hover); color: var(--text); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.live-dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; background: var(--green); opacity: 0; transition: opacity 0.4s; }
.live-dot--active { opacity: 1; animation: live-pulse 2s ease-in-out infinite; }
@keyframes live-pulse { 0%,100% { opacity: 1; } 50% { opacity: 0.35; } }

input:not([type=checkbox]):not([type=radio]):not([type=file]), select, textarea {
  padding: 7px 11px; border: 1px solid var(--border); border-radius: 8px; background: var(--input-bg); color: var(--text); width: 100%;
}
input:focus, select:focus, textarea:focus { outline: 2px solid rgba(37,99,235,0.35); outline-offset: 0; border-color: var(--accent); }
textarea { resize: vertical; min-height: 64px; }
label.field { display: block; margin-bottom: 12px; }
label.field .lbl, .lbl { display: block; font-size: 12px; font-weight: 600; color: var(--muted); margin-bottom: 4px; }
.field-row { display: flex; gap: 12px; }
.field-row > * { flex: 1; }
.checkbox-line { display: flex; align-items: center; gap: 8px; font-weight: 500; }
input[type=checkbox] { width: 16px; height: 16px; accent-color: var(--accent); }

/* Tables */
table.tbl { width: 100%; border-collapse: collapse; font-size: 13.5px; }
.tbl th {
  text-align: left; font-size: 11.5px; text-transform: uppercase; letter-spacing: 0.5px;
  color: var(--muted); padding: 9px 12px; border-bottom: 1px solid var(--border); font-weight: 600;
  background: var(--surface-2); position: sticky; top: 0;
}
.tbl td { padding: 9px 12px; border-bottom: 1px solid var(--border); vertical-align: middle; }
.tbl tr:last-child td { border-bottom: none; }
.tbl tbody tr.clickable { cursor: pointer; }
.tbl tbody tr.clickable:hover { background: var(--hover); }
.tbl .num { text-align: right; font-variant-numeric: tabular-nums; }
.tbl td.muted, .muted { color: var(--muted); }
.small { font-size: 12px; }
.mono { font-family: ui-monospace, "SF Mono", Menlo, monospace; font-size: 12.5px; }

/* Chips */
.chip {
  display: inline-flex; align-items: center; gap: 5px; padding: 2px 9px; border-radius: 999px;
  font-size: 11.5px; font-weight: 600; white-space: nowrap;
}
.chip .dot { width: 7px; height: 7px; border-radius: 50%; background: currentColor; }
.chip.green { background: var(--green-soft); color: var(--green); }
.chip.amber { background: var(--amber-soft); color: var(--amber); }
.chip.red { background: var(--red-soft); color: var(--red); }
.chip.blue { background: var(--accent-soft); color: var(--accent); }
.chip.purple { background: var(--purple-soft); color: var(--purple); }
.chip.gray { background: #f1f2f4; color: var(--muted); }
.cat-chip { display: inline-flex; align-items: center; gap: 6px; font-weight: 500; }
.cat-chip .swatch { width: 9px; height: 9px; border-radius: 3px; flex-shrink: 0; }
.swatch-row { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.swatch-btn { width: 26px; height: 26px; border-radius: 7px; border: 2px solid transparent; cursor: pointer; padding: 0; }
.swatch-btn.sel { border-color: var(--text); box-shadow: 0 0 0 2px var(--panel) inset; }
.swatch-row input[type=color] { width: 38px; height: 30px; padding: 2px; cursor: pointer; }
.bulk-bar { display: flex; align-items: center; gap: 10px; padding: 10px 12px; margin-top: 10px;
  background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow);
  position: sticky; bottom: 12px; }
.bulk-bar select { width: auto; min-width: 180px; }
.bulk-bar[hidden] { display: none; }

/* Stat cards */
.stat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 14px; margin-bottom: 20px; }
.stat { background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 16px; box-shadow: var(--shadow); }
.stat.clickable { cursor: pointer; transition: border-color 0.12s, box-shadow 0.12s; }
.stat.clickable:hover, .stat.clickable:focus-visible { border-color: var(--accent); box-shadow: 0 2px 8px rgba(37, 99, 235, 0.14); }
.stat .v { font-size: 26px; font-weight: 700; line-height: 1.2; }
.stat .l { color: var(--muted); font-size: 12.5px; font-weight: 500; }
.stat.warn .v { color: var(--amber); }
.stat.bad .v { color: var(--red); }
.stat.good .v { color: var(--green); }

.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; align-items: start; }
@media (max-width: 1100px) { .grid-2 { grid-template-columns: 1fr; } }

/* Filter bar */
.filters { display: flex; gap: 10px; margin-bottom: 14px; flex-wrap: wrap; align-items: center; }
.filters input[type=search] { width: 260px; }
.filters select { width: auto; min-width: 140px; }

/* Modal */
.modal-backdrop {
  position: fixed; inset: 0; background: rgba(15, 23, 42, 0.5); z-index: 50;
  display: flex; align-items: flex-start; justify-content: center; padding: 6vh 16px; overflow-y: auto;
}
.modal {
  background: var(--panel); border-radius: 14px; width: 560px; max-width: 100%;
  box-shadow: 0 20px 50px rgba(0,0,0,0.3); animation: pop .14s ease-out;
}
.modal.wide { width: 860px; }
@keyframes pop { from { transform: scale(0.97); opacity: 0; } }
.modal .m-head { padding: 16px 20px; border-bottom: 1px solid var(--border); font-weight: 700; font-size: 16px; display: flex; align-items: center; }
.modal .m-head .x { margin-left: auto; background: none; border: none; font-size: 19px; color: var(--muted); padding: 2px 6px; }
.modal .m-body { padding: 18px 20px; max-height: 70vh; overflow-y: auto; }
.modal .m-foot { padding: 13px 20px; border-top: 1px solid var(--border); display: flex; justify-content: flex-end; gap: 9px; }

/* Toasts */
#toasts { position: fixed; bottom: 18px; right: 18px; z-index: 100; display: flex; flex-direction: column; gap: 8px; }
.toast {
  background: #111827; color: #f9fafb; padding: 11px 16px; border-radius: 10px; font-size: 13.5px;
  box-shadow: 0 8px 24px rgba(0,0,0,0.25); max-width: 360px; animation: slide .18s ease-out;
}
.toast.error { background: var(--red); }
.toast.success { background: var(--green); }
@keyframes slide { from { transform: translateY(8px); opacity: 0; } }

/* Login */
.login-wrap { min-height: 100vh; display: flex; align-items: center; justify-content: center; background: var(--sidebar); width: 100%; }
.login-card { background: var(--panel); border-radius: 16px; padding: 34px; width: 380px; box-shadow: 0 24px 60px rgba(0,0,0,0.4); }
.login-card h1 { margin: 0 0 4px; font-size: 21px; display: flex; align-items: center; gap: 10px; }
.login-card .sub { color: var(--muted); margin-bottom: 22px; font-size: 13px; }

/* Availability bars */
.avail-bar { display: flex; height: 18px; border-radius: 6px; overflow: hidden; background: #eef0f2; min-width: 160px; }
.avail-bar .seg { height: 100%; }
.avail-bar .seg.free { background: #34d399; }
.avail-bar .seg.committed { background: #f87171; }
.avail-bar .seg.required { background: #fbbf24; }
.avail-bar .seg.soft { background: #fbbf24; }
.avail-bar .seg.maint { background: #a78bfa; }
.legend { display: flex; gap: 16px; font-size: 12px; color: var(--muted); flex-wrap: wrap; }
.legend .key { display: inline-flex; align-items: center; gap: 6px; }
.legend .sw { width: 11px; height: 11px; border-radius: 3px; }

/* Pick list */
.pick-progress { height: 9px; background: #eef0f2; border-radius: 5px; overflow: hidden; flex: 1; }
.pick-progress .fill { height: 100%; background: var(--green); transition: width .2s; }
.pick-row .codecell { font-weight: 600; }
/* Unallocated requirement rows sit inline in their section but read as "to do":
   a soft amber wash + left accent so they're distinct from picked/real gear. */
/* No per-state row tinting — the action buttons and the Unallocated/Out chips
   are the indicators. The only left stripe is the section's own hue. */
.scan-box {
  display: flex; gap: 10px; align-items: center; background: var(--accent-soft);
  border: 1px solid #d3e0fb; border-radius: 10px; padding: 11px 14px; margin-bottom: 14px;
}
.scan-box input { background: var(--input-bg); }

/* Status workflow */
.flow { display: flex; gap: 6px; flex-wrap: wrap; align-items: center; }
.flow .step { padding: 4px 12px; border-radius: 999px; font-size: 12px; font-weight: 600; background: #f1f2f4; color: var(--muted); }
.flow .step.done { background: var(--green-soft); color: var(--green); }
.flow .step.now { background: var(--accent); color: #fff; }

.kv { display: grid; grid-template-columns: 130px 1fr; gap: 6px 14px; font-size: 13.5px; }
.kv .k { color: var(--muted); font-weight: 500; }

.empty { text-align: center; color: var(--muted); padding: 36px 16px; }
.empty .big { font-size: 30px; margin-bottom: 8px; }

/* ---------- Inventory category grid (default landing) ---------- */
.cat-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 12px; padding: 4px; }
.cat-tile {
  display: flex; flex-direction: column; align-items: flex-start; gap: 6px;
  padding: 18px 16px; min-height: 92px; text-align: left; cursor: pointer;
  background: var(--panel); border: 1px solid var(--border); border-radius: 12px;
  box-shadow: var(--shadow); transition: border-color .12s, transform .06s, box-shadow .12s;
}
.cat-tile:hover { border-color: var(--accent); transform: translateY(-1px); box-shadow: 0 4px 14px rgba(16,24,40,0.10); }
.cat-tile:active { transform: translateY(0); }
.cat-tile .ct-dot { width: 12px; height: 12px; border-radius: 4px; }
.cat-tile .ct-name { font-weight: 700; font-size: 15px; color: var(--text); }
.cat-tile .ct-count { font-size: 12.5px; color: var(--muted); margin-top: auto; }
.cat-tile-all { background: var(--accent-soft); border-color: transparent; }
.cat-tile-all .ct-name { color: var(--accent); }

.pager { display: flex; gap: 8px; align-items: center; justify-content: flex-end; padding: 10px 12px; color: var(--muted); font-size: 13px; }

.loc-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 14px; }
.loc-card { background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; box-shadow: var(--shadow); }
.loc-card h3 { margin: 0 0 4px; font-size: 15px; }
.loc-card .addr { color: var(--muted); font-size: 12.5px; min-height: 17px; }
.loc-card .counts { display: flex; gap: 14px; margin-top: 12px; font-size: 13px; }
.loc-card .counts b { font-size: 17px; display: block; }

.search-pick { max-height: 380px; overflow-y: auto; border: 1px solid var(--border); border-radius: 8px; }
.search-pick .row {
  display: flex; align-items: center; gap: 10px; padding: 8px 12px; border-bottom: 1px solid var(--border); cursor: pointer;
}
.search-pick .row:hover { background: var(--hover); }
.search-pick .row.disabled { opacity: 0.55; cursor: not-allowed; }
.search-pick .row .grow { flex: 1; min-width: 0; }

.tabs { display: flex; gap: 2px; border-bottom: 1px solid var(--border); margin-bottom: 16px; }
.tabs button {
  padding: 9px 16px; border: none; background: none; font-weight: 600; color: var(--muted);
  border-bottom: 2px solid transparent; margin-bottom: -1px;
}
.tabs button.active { color: var(--accent); border-bottom-color: var(--accent); }

/* ---------- Icons ---------- */
.ic { vertical-align: -2px; flex-shrink: 0; }
.nav .icon { display: inline-flex; align-items: center; }
.brand-mark .ic { vertical-align: middle; }
.chip .ic { vertical-align: -1.5px; }

/* ---------- One-shot action buttons (warehouse-friendly) ---------- */
.btn.act {
  padding: 9px 18px; font-size: 13.5px; min-width: 104px; justify-content: center;
  border-radius: 9px;
}
.btn.act.picked { background: var(--green-soft); border-color: #bbe7c9; color: var(--green); }
.act-cell { white-space: nowrap; }
.act-cell .btn + .btn { margin-left: 6px; }
.act-col { min-width: 150px; }
.drag-grip { display: inline-flex; vertical-align: middle; margin-right: 6px; color: var(--muted); opacity: .45; cursor: grab; }
.drag-grip:hover { opacity: 1; }
.pick-row[draggable="true"] td.codecell { cursor: grab; }
.pick-row.dragging { opacity: .45; }
.pick-tbl tr.drop-into > td { background: var(--accent-soft) !important; }
.tbl-scroll { overflow-x: auto; }
.scan-ic { display: inline-flex; color: var(--accent); }

/* ---------- Segmented tabs (modal mode switch) ---------- */
.seg-tabs { display: flex; gap: 4px; background: var(--surface-2); border-radius: 9px; padding: 4px; margin-bottom: 16px; }
.seg-tabs .seg {
  flex: 1; border: none; background: transparent; padding: 8px 10px; border-radius: 7px;
  font-weight: 600; font-size: 13px; color: var(--muted);
}
.seg-tabs .seg.active { background: var(--panel); color: var(--text); box-shadow: var(--shadow); }

/* ---------- Searchable model list (requirement modal) ---------- */
.model-list {
  border: 1px solid var(--border); border-radius: 8px; max-height: 240px; overflow-y: auto;
  margin: -6px 0 12px;
}
.model-list .row {
  display: flex; align-items: center; gap: 10px; padding: 9px 12px;
  border-bottom: 1px solid var(--border); cursor: pointer;
}
.model-list .row:last-child { border-bottom: none; }
.model-list .row:hover { background: var(--hover); }
.model-list .row .grow { flex: 1; min-width: 0; }

/* ---------- Pick list sections ---------- */
/* Rows are all rendered; collapsing and searching just toggle this class. */
.row-hidden { display: none !important; }

.section-row td {
  background: var(--accent-soft); padding: 6px 12px 6px 10px;
  border-top: 2px solid var(--border); border-bottom: 1px solid var(--border);
  border-left: 3px solid var(--accent);
}
/* Indent by nesting depth (--sec-d), so sub-sections sit visibly inside their
   parent instead of reading as separate top-level sections. */
.section-row.sub-sec td {
  background: var(--hover); border-left-color: var(--border); border-left-width: 2px;
  padding-left: calc(10px + var(--sec-d, 1) * 18px);
}
html[data-theme="dark"] .section-row td { background: rgba(37,99,235,0.10); }
html[data-theme="dark"] .section-row.sub-sec td { background: var(--hover); }
.section-row { cursor: pointer; }
.section-row.drop-before td { box-shadow: inset 0 3px 0 var(--accent); }
.section-row.drop-into td { box-shadow: inset 0 0 0 2px var(--accent); }
/* A little air above each sub-section header so nesting reads as grouping. */
.section-row.sub-sec td { border-top: 6px solid transparent; background-clip: padding-box; }

/* Per-section hue: a deterministic colour per top-level section so blocks are
   distinguishable at a glance while scrolling a long list. */
.section-row.has-hue td {
  background: hsl(var(--sec-h) 72% 94%);
  border-left-color: hsl(var(--sec-h) 62% 48%);
}
.section-row.has-hue .sec-name { color: hsl(var(--sec-h) 65% 28%); }
.pick-row.has-hue td:first-child { box-shadow: inset 3px 0 0 hsl(var(--sec-h) 62% 48%); }
.kit-row.has-hue td { border-left-color: hsl(var(--sec-h) 62% 48%); }
html[data-theme="dark"] .section-row.has-hue td { background: hsl(var(--sec-h) 45% 16%); }
html[data-theme="dark"] .section-row.has-hue .sec-name { color: hsl(var(--sec-h) 70% 78%); }

/* Kit group inside a section: section > kit > gear */
.kit-row td {
  background: rgba(139, 92, 246, 0.07); padding: 4px 12px 4px 24px;
  border-bottom: 1px solid var(--border); border-left: 3px solid var(--purple);
}
.kit-row { cursor: pointer; }
html[data-theme="dark"] .kit-row td { background: rgba(139, 92, 246, 0.12); }
.kit-head { display: flex; align-items: center; gap: 8px; }
.kit-head .kit-ic { color: var(--purple); display: inline-flex; }
.kit-head .kit-name { font-weight: 600; font-size: 13px; }
.kit-head .kit-name a { color: inherit; }
.pick-row.kit-member td:first-child { box-shadow: inset 3px 0 0 var(--purple); }
.pick-row.kit-member td.codecell { padding-left: 24px; }

.sec-head { display: flex; align-items: center; gap: 9px; }
.sec-head .sec-grip { cursor: grab; opacity: .5; }
.sec-head .sec-grip:hover { opacity: 1; }
.sec-head .sec-hits { font-weight: 600; color: var(--accent); }
.sec-head .sec-parent { font-size: 11px; color: var(--muted); font-weight: 500; }
.sec-head .sec-name {
  font-weight: 700; font-size: 13.5px; text-transform: uppercase; letter-spacing: 0.7px; color: var(--text);
}
.sec-head .spacer { flex: 1; }
.sec-fold { background: none; border: none; padding: 4px 6px; display: inline-flex; }
.chev {
  width: 9px; height: 9px; border-right: 2px solid var(--muted); border-bottom: 2px solid var(--muted);
  transform: rotate(45deg); transition: transform 0.12s; margin-top: -3px;
}
.chev.closed { transform: rotate(-45deg); margin-top: 0; }

/* Inline notes column — one line tall until focused, so rows stay compact. */
.note-cell { min-width: 150px; width: 20%; }
.note-in {
  width: 100%; padding: 3px 7px; border: 1px solid transparent;
  background: transparent; border-radius: 6px; font-size: 12.5px;
  font-family: inherit; line-height: 1.35; resize: none; overflow: hidden;
  height: 24px; min-height: 0; display: block; white-space: nowrap; text-overflow: ellipsis;
}
.note-in:hover { border-color: var(--border); background: var(--input-bg); }
.note-in:focus { border-color: var(--accent); background: var(--input-bg); white-space: pre-wrap; }

/* ---------- Compact pick list ---------- */
.pick-tbl td { padding: 4px 10px; }
.pick-tbl .codecell { white-space: nowrap; }
.pick-tbl .cell-item { line-height: 1.3; }
.pick-tbl .row-hint { font-size: 11px; margin-left: 6px; white-space: nowrap; }
.pick-tbl .act-cell .btn { padding: 3px 9px; font-size: 12px; }
.pick-tbl .qty-in { padding: 3px 6px; height: 26px; }
.pick-head { flex-wrap: wrap; gap: 8px; }
.pick-head .ph-title { font-weight: 600; }
.pick-search { width: auto; min-width: 190px; flex: 0 1 240px; padding: 5px 10px; font-size: 13px; }

/* Bulk actions follow you down the page instead of living at the top. */
.pick-bulkbar {
  position: fixed; left: 50%; transform: translateX(-50%); bottom: 16px; z-index: 60;
  display: flex; align-items: center; gap: 10px; padding: 9px 14px;
  background: var(--panel); border: 1px solid var(--border); border-radius: 12px;
  box-shadow: 0 6px 24px rgba(0,0,0,0.18); max-width: calc(100vw - 24px); flex-wrap: wrap;
}
.pick-bulkbar[hidden] { display: none; }
.pick-bulkbar #bulk-count { font-weight: 600; font-size: 13px; white-space: nowrap; }
.pick-bulkbar .spacer { flex: 1; }
.pick-bulkbar [hidden] { display: none; }

/* ---------- Shortage alert (dashboard) ---------- */
.shortage-alert {
  background: var(--red-soft); border: 1.5px solid #f5b5b5; border-radius: var(--radius);
  margin-bottom: 20px; overflow: hidden; box-shadow: 0 2px 10px rgba(220,38,38,0.12);
}
.shortage-alert .sa-head { display: flex; align-items: center; gap: 13px; padding: 14px 16px; }
.shortage-alert .sa-badge {
  width: 38px; height: 38px; border-radius: 9px; background: var(--red); color: #fff;
  display: inline-flex; align-items: center; justify-content: center; flex-shrink: 0;
}
.shortage-alert .sa-title { font-weight: 700; font-size: 15.5px; color: #991b1b; }
.shortage-alert .sa-sub { font-size: 12.5px; color: #b04a4a; margin-top: 1px; }
.shortage-alert .sa-table { background: var(--panel); }
.shortage-alert .sa-table th { background: #fdeaea; }
.shortage-alert .sa-more { padding: 8px 16px; font-size: 12.5px; color: #b04a4a; background: #fff; }

/* Shortage list (dashboard widget) */
.sa-sub { font-size: 12.5px; color: var(--muted); padding: 0 0 12px; }
.shortage-list { display: flex; flex-direction: column; gap: 8px; }
.shortage-item {
  display: flex; align-items: center; gap: 12px; padding: 11px 13px;
  border: 1px solid var(--border); border-left: 3px solid var(--red);
  border-radius: 9px; background: var(--panel);
}
.shortage-item .si-main { flex: 1; min-width: 0; }
.shortage-item .si-name { font-size: 14px; }
.shortage-item .si-meta { font-size: 12.5px; color: var(--muted); margin-top: 3px; display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.shortage-item .si-dot { color: var(--border); }
.shortage-item .si-jobs { margin-top: 6px; display: flex; gap: 5px; flex-wrap: wrap; }
.shortage-item .si-jobs a { text-decoration: none; }
.shortage-item .si-btn { flex-shrink: 0; }

/* ---------- Bulk action bar ---------- */
.bulk-bar {
  display: flex; align-items: center; gap: 9px; background: var(--accent-soft);
  border: 1px solid #cfe0fb; border-radius: 10px; padding: 9px 13px; margin-top: 10px;
}
.bulk-bar #bulk-count { font-weight: 600; font-size: 13px; }
.bulk-bar .spacer { flex: 1; }
.cb-col { width: 34px; text-align: center; }
.cb-col input { width: 16px; height: 16px; accent-color: var(--accent); }
tr.row-sel td { background: var(--accent-soft) !important; }
.sec-all { width: 15px; height: 15px; accent-color: var(--accent); margin-right: 2px; }

/* ---------- Configurable dashboard ---------- */
.dash-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; align-items: start; }
.dash-w.full { grid-column: 1 / -1; }
.dash-w.is-hidden { opacity: 0.5; }
.dash-w .card-body.flush { padding: 0; }
.dash-w .card-body.flush .tbl th { border-top: none; }
.dash-w .card-head .btn.sm.ghost { padding: 3px 7px; }
.dash-cust-bar {
  display: flex; align-items: center; gap: 12px; flex-wrap: wrap;
  background: var(--accent-soft); border: 1px solid #cfe0fb; border-radius: 10px;
  padding: 10px 14px; margin-bottom: 14px; font-size: 13px;
}
.dash-hidden-tray {
  display: flex; align-items: center; gap: 8px; flex-wrap: wrap;
  margin-bottom: 14px; font-size: 13px; color: var(--muted);
}
.empty.good-empty { color: var(--green); }
.scan-box.no-scan { background: transparent; border-color: transparent; padding: 0 0 4px; }
.card.card-alert { border: 1.5px solid #f5b5b5; box-shadow: 0 2px 10px rgba(220,38,38,0.12); }
.card.card-alert > .card-head { background: #fdeaea; color: #991b1b; }
.sa-badge.sm {
  width: 24px; height: 24px; border-radius: 7px; background: var(--red); color: #fff;
  display: inline-flex; align-items: center; justify-content: center; vertical-align: middle; margin-right: 2px;
}

/* ---------- Availability expandable rows ---------- */
.chev-inline {
  display: inline-block; width: 7px; height: 7px; margin-right: 9px;
  border-right: 2px solid var(--muted); border-bottom: 2px solid var(--muted);
  transform: rotate(-45deg); transition: transform 0.12s; vertical-align: middle;
}
.av-row.expanded .chev-inline { transform: rotate(45deg); }
.av-row.expanded td { background: #f0f4fb; }
.av-over > td:first-child { box-shadow: inset 3px 0 0 var(--red); }
html[data-theme="dark"] .av-row.expanded td { background: #1b2735; }

/* ---------- Mobile ---------- */
.mobile-bar { display: none; }
.sidebar-scrim { display: none; }

@media (max-width: 880px) {
  #app { flex-direction: column; }
  .mobile-bar {
    display: flex; align-items: center; gap: 12px; position: sticky; top: 0; z-index: 45;
    background: var(--sidebar); color: #fff; padding: 10px 14px;
  }
  .mobile-bar button { background: none; border: none; color: #fff; padding: 4px; display: inline-flex; }
  .mobile-bar .mb-title { font-weight: 700; font-size: 15px; }
  .sidebar {
    position: fixed; top: 0; left: -250px; height: 100vh; width: 240px; z-index: 70;
    transition: left 0.18s ease-out; box-shadow: none;
  }
  .sidebar.open { left: 0; box-shadow: 0 0 40px rgba(0,0,0,0.4); }
  .sidebar.open ~ .sidebar-scrim {
    display: block; position: fixed; inset: 0; background: rgba(15,23,42,0.45); z-index: 60;
  }
  .main { padding: 14px 12px 70px; }
  .page-head h1 { font-size: 18px; }
  .grid-2 { grid-template-columns: 1fr; }
  .filters input[type=search] { width: 100%; }
  .filters select { flex: 1; }
  .card { overflow-x: auto; }
  .tbl { min-width: 560px; }
  .btn { padding: 9px 14px; }
  .btn.sm { padding: 7px 11px; }
  .btn.act { padding: 11px 18px; min-width: 112px; }

  /* ---- Pick list → touch-friendly cards (Tier 2) ---- */
  .pick-tbl { min-width: 0; }
  .pick-tbl, .pick-tbl tbody { display: block; }
  .pick-tbl thead { display: none; }
  .card .tbl-scroll { overflow-x: visible; }

  .pick-tbl tr.pick-row {
    display: flex; flex-wrap: wrap; align-items: center; gap: 2px 9px;
    position: relative; background: var(--panel);
    border: 1px solid var(--border); border-radius: 10px;
    margin: 5px 4px; padding: 8px 12px 8px 42px; box-shadow: var(--shadow);
  }
  .pick-tbl tr.pick-row.has-hue { border-left: 3px solid hsl(var(--sec-h) 62% 48%); }
  .pick-tbl tr.pick-row td { display: block; border: none !important; padding: 0; background: none !important; }
  .pick-tbl tr.pick-row.row-sel { border-color: var(--accent); box-shadow: 0 0 0 2px var(--accent-soft); }

  /* checkbox: large tap target pinned to the card's left edge */
  .pick-row .cb-col { position: absolute; left: 9px; top: 10px; width: auto; }
  .pick-row .cb-col input { width: 22px; height: 22px; }

  .pick-row .codecell { order: 1; font-size: 13px; }
  .drag-grip { display: none; }
  .pick-row .cell-status { order: 2; margin-left: auto; }
  .pick-row .cell-item { order: 3; flex-basis: 100%; font-weight: 600; font-size: 14.5px; line-height: 1.25; }
  .pick-row .cell-kit { order: 4; }
  .pick-row .cell-kit:empty { display: none; }
  .pick-row .cell-qty { order: 6; color: var(--muted); font-size: 12px; }
  .pick-row .cell-qty::before { content: "Qty "; }
  .pick-row .note-cell { order: 7; flex-basis: 100%; width: auto; min-width: 0; margin-top: 2px; }
  .pick-row .note-cell .note-in { border-color: var(--border); background: var(--input-bg); font-size: 13px; }
  .pick-row .act-cell { order: 8; flex-basis: 100%; display: flex; gap: 8px; margin-top: 6px; white-space: normal; }
  .pick-row .act-cell .btn:not(.ghost) { flex: 1; padding: 10px; min-height: 42px; font-size: 14px; min-width: 0; }
  .pick-row .act-cell .btn.ghost { min-height: 42px; padding: 0 13px; }
  .pick-row .act-cell .btn + .btn { margin-left: 0; }
  /* Keep the pick-list header to two tight rows: search, then the actions. */
  .pick-head { gap: 6px; padding: 10px 12px; }
  .pick-head .pick-search { flex: 1 1 100%; min-width: 0; order: -2; }
  /* Counts on their own line so the three action buttons get the full width. */
  .pick-head .muted.small { flex: 1 1 100%; order: -1; }
  .pick-head .spacer, .pick-head .pick-progress { display: none; }
  .pick-head .btn { flex: 1 1 0; padding: 7px 6px; font-size: 12.5px; white-space: nowrap; min-width: 0; }
  /* The card is obviously the pick list — the counts alone carry the meaning. */
  .pick-head .ph-title { display: none; }
  .pick-bulkbar { left: 8px; right: 8px; bottom: 8px; transform: none; max-width: none; justify-content: center; }
  .pick-bulkbar .btn { flex: 1 1 auto; }

  /* section ribbons keep their accent identity, just spaced as cards */
  .pick-tbl tr.section-row { display: block; margin: 10px 4px 2px; }
  .pick-tbl tr.section-row td { display: block; border-radius: 8px; }
  .pick-tbl tr.section-row.sub-sec { margin-left: 16px; }
  /* One line per section header: the name ellipses, the icons hold their size. */
  .pick-tbl .section-row .sec-head { flex-wrap: nowrap; gap: 5px; }
  .pick-tbl .section-row .sec-head .btn.sm.ghost { padding: 5px 6px; flex: 0 0 auto; }
  .pick-tbl .section-row .sec-head .sec-name {
    overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0;
  }
  .pick-tbl .section-row .sec-head .sec-parent { display: none; }
  .pick-tbl tr.kit-row { display: block; margin: 6px 4px 2px 14px; }
  .pick-tbl tr.kit-row td { display: block; border-radius: 8px 8px 0 0; }
  .pick-tbl tr.pick-row.kit-member { margin-left: 14px; }
  .pick-tbl tr.pick-row.kit-member td:first-child { box-shadow: none; }

  /* scan bar + bulk bar stack to full-width controls */
  .scan-box { flex-wrap: wrap; }
  .scan-box input { flex: 1 1 100%; }
  .scan-box .btn { flex: 1 1 100%; padding: 13px; min-height: 48px; }
  .bulk-bar { flex-wrap: wrap; }
  .bulk-bar .btn { flex: 1 1 auto; }
  .card .card-head { flex-wrap: wrap; }
  input[type=text], input[type=search], input[type=date], input[type=number],
  input[type=password], input[type=email], select, textarea { font-size: 16px; padding: 9px 12px; }
  .modal { width: 100%; border-radius: 12px; }
  .modal-backdrop { padding: 3vh 8px; }
  .stat .v { font-size: 21px; }
  .kv { grid-template-columns: 110px 1fr; }
}

@media print {
  .sidebar, .filters, .btn, .scan-box, .no-print, .mobile-bar,
  .pick-bulkbar, .pick-search, .pick-progress, .flow, .live-dot { display: none !important; }
  .main { padding: 0; }
  body { background: #fff; color: #000; }
  .card { box-shadow: none; border: none; }
  .note-in { border: none; background: none; padding: 0; resize: none; overflow: visible; height: auto; white-space: pre-wrap; }
  .note-in::placeholder { color: transparent; }

  /* A printed pick list is a document, not a screenshot of the screen:
     everything collapsed on screen still has to appear on paper. */
  .row-hidden { display: table-row !important; }
  .pick-tbl, .pick-tbl tbody, .pick-tbl thead { display: table !important; width: 100%; }
  .pick-tbl thead { display: table-header-group !important; }  /* repeat header per page */
  .pick-tbl tbody { display: table-row-group !important; }
  .pick-tbl tr { display: table-row !important; margin: 0 !important; }
  .pick-tbl td, .pick-tbl th { display: table-cell !important; padding: 4px 8px !important; }
  .card, .tbl-scroll { overflow: visible !important; }

  /* Keep a row (and a section and its first rows) from splitting across pages. */
  .pick-row, .section-row, .kit-row { break-inside: avoid; page-break-inside: avoid; }
  .section-row, .kit-row { break-after: avoid; page-break-after: avoid; }

  /* Section colour won't survive most printers — lean on weight and rules. */
  .section-row td {
    background: none !important; border-top: 1.5px solid #000 !important;
    border-bottom: 1px solid #000 !important; border-left: none !important;
  }
  .section-row .sec-name { color: #000 !important; }
  .kit-row td { background: none !important; border-left: none !important; }

  /* A tick box to work down by hand, in place of the on-screen select column. */
  .pick-row .cb-col { display: table-cell !important; width: 22px; }
  .pick-row .cb-col input { -webkit-appearance: none; appearance: none; opacity: 1;
    width: 12px; height: 12px; border: 1px solid #000; border-radius: 2px; display: inline-block; }
  thead .cb-col { display: table-cell !important; }
  /* The actions column is only buttons — drop it rather than print a blank
     strip. Needs to outrank the ".pick-tbl td" display rule above. */
  .pick-tbl .act-cell, .pick-tbl .act-col { display: none !important; }
  .pick-tbl .note-cell { width: 30%; }
}
