/* ============================================================
   NPW Purchasing Dashboard — Enterprise Design System
   Brand red #DC2626 · Navy #0F1554 — matches Sales Dashboard
   ============================================================ */

/* ── Light mode (default) ───────────────────────────────── */
:root {
  --navy:     #0F1554;
  --navy-d:   #0a0f3d;
  --red:      #DC2626;
  --red-l:    #ef4444;
  --bg:       #F0F2F7;
  --panel:    #ffffff;
  --panel-r:  #f7f8fc;
  --hover-bg: #eef1fa;
  --ink:      #1a2036;
  --muted:    #64748b;
  --line:     #dde3ef;
  --shadow:   rgba(0,0,0,0.08);
  --blue:     #1d4ed8;
  --green:    #15803d;
  --amber:    #b45309;
  --danger:   #b91c1c;
  --row-risk: #fef2f2;
  --row-good: #f0fdf4;
  --urgent:       #b91c1c;
  --urgent-bg:    #fef2f2;
  --urgent-line:  #fecaca;
  --covered:      #0f766e;
  --covered-bg:   #ecfdf5;
  --covered-line: #99f6e4;
  --condition-red-bg:     #fee2e2;
  --condition-red-text:   #7c0010;
  --condition-yellow-bg:  #fef3c7;
  --location-risk-bg:     #fef9c3;
}

/* ── Dark mode ──────────────────────────────────────────── */
[data-theme="dark"] {
  --bg:       #0d1021;
  --panel:    #141828;
  --panel-r:  #1a1f35;
  --hover-bg: #1e2440;
  --ink:      #e2e8f6;
  --muted:    #8892aa;
  --line:     #252c45;
  --shadow:   rgba(0,0,0,0.35);
  --row-risk: rgba(185,28,28,0.12);
  --row-good: rgba(21,128,61,0.10);
  --urgent:       #fca5a5;
  --urgent-bg:    rgba(185,28,28,0.18);
  --urgent-line:  rgba(185,28,28,0.40);
  --covered:      #5eead4;
  --covered-bg:   rgba(20,184,166,0.12);
  --covered-line: rgba(94,234,212,0.30);
  --condition-red-bg:     rgba(185,28,28,0.20);
  --condition-red-text:   #fecaca;
  --condition-yellow-bg:  rgba(180,131,9,0.25);
  --location-risk-bg:     rgba(180,131,9,0.20);
}

*, *::before, *::after { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: "Inter", "Segoe UI", ui-sans-serif, system-ui, -apple-system, sans-serif;
  font-size: 14px;
  line-height: 1.5;
}

a { color: inherit; text-decoration: none; }
h1, h2, h3 { margin: 0; font-weight: 700; }
h1 { font-size: 24px; }
h2 { font-size: 16px; }
h3 { font-size: 15px; }
p  { color: var(--muted); margin: 4px 0 0; }

/* ── Topbar ─────────────────────────────────────────────── */
.topbar {
  height: 58px;
  display: flex;
  align-items: center;
  gap: 24px;
  padding: 0 24px;
  background: var(--navy);
  border-bottom: 2px solid var(--red);
  position: sticky;
  top: 0;
  z-index: 100;
  flex-shrink: 0;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  text-decoration: none;
  flex-shrink: 0;
}
.brand-logo {
  height: 38px;
  width: auto;
  object-fit: contain;
  display: block;
}
/* ── NPW Gearbox brand mark ─────────────────────────────── */
.brand-mark {
  display: flex;
  align-items: center;
  gap: 9px;
  border-left: 1px solid rgba(255,255,255,0.2);
  padding-left: 12px;
  color: #fff;               /* shift-gate strokes pick this up */
}
.gearbox-icon { width: 30px; height: 30px; display: block; flex-shrink: 0; }
.gearbox-icon .gear-ring {
  transform-origin: 24px 24px;
  transition: transform 0.5s ease;
}
.brand:hover .gearbox-icon .gear-ring { transform: rotate(45deg); }
.brand-text { display: flex; flex-direction: column; line-height: 1.1; }
.brand-name {
  font-size: 15px;
  font-weight: 800;
  font-style: italic;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: #fff;
}
.brand-tag {
  font-size: 8.5px;
  font-weight: 600;
  font-style: italic;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: rgba(255,255,255,0.55);
}

/* ── Gearbox loading overlay ────────────────────────────── */
.loading-overlay {
  position: fixed;
  inset: 0;
  z-index: 2000;
  display: none;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
  background: rgba(15, 21, 84, 0.55);
  backdrop-filter: blur(2px);
}
.loading-overlay.active { display: flex; }
.gearset { position: relative; width: 104px; height: 78px; }
.gearset .gear { position: absolute; display: block; }
.gearset .gear-big {
  width: 64px; height: 64px;
  left: 0; top: 14px;
  animation: gear-spin 2.4s linear infinite;
}
.gearset .gear-small {
  width: 42px; height: 42px;
  left: 60px; top: 0;
  animation: gear-spin-rev 1.575s linear infinite; /* 42/64 of the big gear's period — meshed ratio */
}
@keyframes gear-spin     { to { transform: rotate(360deg); } }
@keyframes gear-spin-rev { from { transform: rotate(22.5deg); } to { transform: rotate(-337.5deg); } }
.loading-text {
  font-size: 12px;
  font-weight: 700;
  font-style: italic;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: #fff;
}

/* ── Per-panel gear loading ─────────────────────────────── */
/* Small gearset pinned over an individual panel while its data is in
   flight; cleared per-visual as each one renders (see gearPanel in app.js). */
.gear-host { position: relative; }
.panel-loading {
  position: absolute;
  inset: 0;
  z-index: 60;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  border-radius: inherit;
  background: rgba(255,255,255,0.72);
  backdrop-filter: blur(1px);
  color: var(--navy);          /* small gear + text pick this up */
}
[data-theme="dark"] .panel-loading {
  background: rgba(13,16,33,0.72);
  color: #e2e8f6;
}
.panel-loading .gearset { transform: scale(0.62); margin: -8px 0; }
.panel-loading .loading-text {
  color: currentColor;
  font-size: 10.5px;
  opacity: 0.75;
}

/* Hamburger — hidden on desktop, shown at the mobile breakpoint */
.nav-toggle {
  display: none;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  margin-left: -8px;
  border: none;
  border-radius: 8px;
  background: none;
  color: #fff;
  cursor: pointer;
  flex-shrink: 0;
}
.nav-toggle:hover { background: rgba(255,255,255,0.12); }
.nav-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 90;
  background: rgba(15, 21, 84, 0.45);
}

.top-nav {
  display: flex;
  gap: 4px;
  flex: 1;
}
.top-nav-link {
  color: rgba(255,255,255,0.65);
  font-weight: 600;
  font-size: 13px;
  padding: 6px 12px;
  border-radius: 6px;
  transition: background 0.15s, color 0.15s;
}
.top-nav-link:hover,
.top-nav-link.active {
  background: rgba(255,255,255,0.12);
  color: #ffffff;
}

/* User dropdown */
.user-area { margin-left: auto; }
.user-menu {
  display: flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
  padding: 6px 10px;
  border-radius: 8px;
  position: relative;
  transition: background 0.15s;
}
.user-menu:hover,
.user-menu:focus-within {
  background: rgba(255,255,255,0.1);
}
.user-avatar {
  width: 30px;
  height: 30px;
  border-radius: 50%;
  background: var(--red);
  color: #fff;
  font-weight: 700;
  font-size: 13px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.user-name {
  color: rgba(255,255,255,0.85);
  font-size: 13px;
  font-weight: 600;
}
.chevron { color: rgba(255,255,255,0.5); }

.user-dropdown {
  display: none;
  position: absolute;
  top: calc(100% + 8px);
  right: 0;
  min-width: 220px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 10px;
  box-shadow: 0 8px 30px rgba(0,0,0,0.15);
  z-index: 200;
  overflow: hidden;
}
.user-menu:focus-within .user-dropdown { display: block; }
.dropdown-header {
  padding: 14px 16px;
  border-bottom: 1px solid var(--line);
  background: var(--panel-r);
}
.dropdown-name { font-weight: 700; font-size: 14px; }
.dropdown-role { font-size: 12px; color: var(--muted); margin-top: 2px; }
.dropdown-item {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 11px 16px;
  background: none;
  border: none;
  font-size: 14px;
  font-weight: 500;
  color: var(--ink);
  cursor: pointer;
  text-align: left;
  transition: background 0.12s;
}
.dropdown-item:hover { background: var(--hover-bg); }
.dropdown-item svg { color: var(--muted); flex-shrink: 0; }
.dropdown-signout { color: var(--danger); }
.dropdown-signout svg { color: var(--danger); }

/* ── Page body ──────────────────────────────────────────── */
.page-body {
  padding: 0 0 40px;
}

/* ── Alert ──────────────────────────────────────────────── */
.alert {
  padding: 12px 20px;
  margin: 12px 24px;
  border-radius: 8px;
  font-weight: 500;
  background: #dbeafe;
  color: #1e40af;
  border-left: 4px solid #3b82f6;
}
.alert.error {
  background: #fef2f2;
  color: var(--danger);
  border-left-color: var(--danger);
}
.alert.success {
  background: #f0fdf4;
  color: var(--green);
  border-left-color: var(--green);
}

/* ── Page header strip ──────────────────────────────────── */
.page-header {
  background: var(--panel);
  border-bottom: 1px solid var(--line);
  padding: 16px 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
}
.page-header-title h1 { font-size: 20px; }
.page-header-title p  { margin: 4px 0 0; font-size: 13px; }
.page-header-actions {
  display: flex;
  align-items: flex-end;
  gap: 12px;
  flex-wrap: wrap;
}

/* ── Filter bar ─────────────────────────────────────────── */
.filter-bar {
  background: var(--panel);
  border-bottom: 1px solid var(--line);
  padding: 12px 24px;
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  align-items: flex-end;
}
.filter-bar.inline-bar {
  border-bottom: 1px solid var(--line);
  background: var(--panel-r);
}
.filter-form {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  align-items: flex-end;
}
.filter-group {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}
.filter-label {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--muted);
}
.filter-select {
  height: 36px;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 0 10px;
  background: var(--panel);
  color: var(--ink);
  font-size: 13px;
  min-width: 140px;
  outline: none;
  transition: border-color 0.15s, box-shadow 0.15s;
}
.filter-select:focus {
  border-color: var(--navy);
  box-shadow: 0 0 0 3px rgba(15,21,84,0.1);
}
input.filter-select { min-width: 120px; }
textarea.filter-select {
  height: auto;
  min-height: 96px;
  padding: 10px;
  resize: vertical;
  font-family: inherit;
}
.hidden { display: none !important; }

/* ── KPI strip ──────────────────────────────────────────── */
.kpi-strip {
  display: flex;
  gap: 0;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
  padding: 0 24px;
  overflow-x: auto;
}
.kpi-card {
  flex: 1;
  min-width: 160px;
  padding: 16px 20px;
  border-right: 1px solid var(--line);
}
.kpi-card:last-child { border-right: 0; }
.kpi-card.kpi-urgent {
  background: var(--urgent-bg);
  border-bottom: 2px solid var(--urgent-line);
}
.kpi-card.kpi-covered {
  background: var(--covered-bg);
  border-bottom: 2px solid var(--covered-line);
}
.kpi-label {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--muted);
  margin-bottom: 4px;
}
.kpi-value {
  font-size: 26px;
  font-weight: 800;
  line-height: 1.1;
  color: var(--ink);
}
.kpi-value.navy   { color: var(--navy); }
.kpi-value.red    { color: var(--danger); }
.kpi-value.danger { color: var(--danger); }
.kpi-value.good   { color: var(--green); }
.kpi-value.green  { color: var(--green); }
.kpi-value.amber  { color: var(--amber); }
.kpi-value.covered { color: var(--covered); }
.kpi-sub {
  font-size: 11px;
  color: var(--muted);
  margin-top: 3px;
}
.kpi-card.drill-link {
  cursor: pointer;
  transition: background 0.12s;
}
.kpi-card.drill-link:hover,
.kpi-card.drill-link:focus-visible {
  outline: 2px solid var(--navy);
  outline-offset: -2px;
}

/* ── Content area / panels ──────────────────────────────── */
.content-area {
  padding: 20px 24px;
}
.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 18px;
}
.panel.panel-flush { padding: 0; }
.panel-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  margin-bottom: 16px;
}
.panel.panel-flush .panel-head {
  padding: 14px 18px;
  margin: 0;
  border-bottom: 1px solid var(--line);
}
.panel-head h2 { margin: 0; }
.panel-head .meta {
  color: var(--muted);
  font-size: 12px;
  font-weight: 500;
}
.panel-grid { display: grid; gap: 18px; }
.panel-grid.two { grid-template-columns: repeat(2, minmax(0,1fr)); }
.panel-grid.three { grid-template-columns: repeat(3, minmax(0,1fr)); }
.panel-grid.two-one { grid-template-columns: 2fr 1fr; }
.panel-grid.three-two { grid-template-columns: 3fr 2fr; }

/* ── Risk buckets ─────────────────────────────────────────── */
.bucket-list {
  padding: 14px 18px;
  display: grid;
  gap: 10px;
}
.bucket {
  border: 1px solid var(--line);
  border-left: 4px solid var(--navy);
  border-radius: 8px;
  padding: 12px 14px;
  display: grid;
  gap: 8px;
  background: var(--panel-r);
}
.bucket.action {
  border-left-color: var(--urgent);
  background: var(--urgent-bg);
}
.bucket.covered {
  border-left-color: var(--covered);
  background: var(--covered-bg);
}
.bucket.drill-link {
  cursor: pointer;
  transition: filter 0.12s;
}
.bucket.drill-link:hover,
.bucket.drill-link:focus-visible {
  outline: 2px solid var(--navy);
  outline-offset: -2px;
}
.bucket-top {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  font-weight: 700;
  font-size: 13px;
}
.bucket-metrics {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  color: var(--muted);
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.bucket-metrics strong {
  display: block;
  color: var(--ink);
  font-size: 16px;
  font-weight: 800;
  margin-bottom: 2px;
  text-transform: none;
  letter-spacing: 0;
}

/* ── Chart wrapper ─────────────────────────────────────────── */
.chart-wrap {
  width: 100%;
  height: 260px;
  position: relative;
  padding: 8px 12px 12px;
}
.chart-wrap.tall { height: 320px; }

/* ── Tables ─────────────────────────────────────────────── */
.table-wrap {
  overflow-x: auto;
  max-height: 460px;
  overflow-y: auto;
}
.table-wrap.compact { max-height: 360px; }
.table-wrap.tall    { max-height: calc(100vh - 320px); min-height: 360px; }
.table-wrap.flush   { border-top: 1px solid var(--line); }

table { width: 100%; border-collapse: collapse; }
th, td {
  padding: 9px 10px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  white-space: nowrap;
}
th {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--muted);
  background: var(--panel-r);
  position: sticky;
  top: 0;
  z-index: 1;
}
td.num, th.num { text-align: right; }
td.bold { font-weight: 700; }
td.muted, .muted { color: var(--muted); }
td.small, .small { font-size: 12px; }
td.empty { color: var(--muted); text-align: center; padding: 24px; font-style: italic; }

table.dense th,
table.dense td { padding: 7px 8px; font-size: 12px; }

th[data-sort],
th[data-vendor-sort] { cursor: pointer; user-select: none; }
th.sorted::after { content: " " attr(data-direction); color: var(--navy); font-size: 10px; text-transform: uppercase; }

/* Draggable column headers (order persists per-user in localStorage) */
th.col-draggable { cursor: grab; }
th.col-draggable:active { cursor: grabbing; }
th.col-drop-target { box-shadow: inset 3px 0 0 0 var(--navy); background: var(--hover-bg); }

tr.selectable-row { cursor: pointer; transition: background 0.1s; }
tr.selectable-row:hover td { background: var(--hover-bg); }
tr.selectable-row.selected td {
  outline: 2px solid var(--navy);
  outline-offset: -2px;
  background: var(--hover-bg);
}

tr.condition-red    td { background: var(--condition-red-bg); color: var(--condition-red-text); }
tr.condition-yellow td { background: var(--condition-yellow-bg); }

tr.location-oos      td { background: var(--urgent-bg); }
tr.location-risk     td { background: var(--location-risk-bg); }
tr.location-nonstock td { color: var(--muted); }

.note-cell {
  min-width: 220px;
  max-width: 380px;
  white-space: normal;
  font-size: 12px;
}

/* ── Focus chip ─────────────────────────────────────────── */
.focus-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 10px;
  background: var(--covered-bg);
  border: 1px solid var(--covered-line);
  color: var(--covered);
  border-radius: 6px;
  font-size: 12px;
  font-weight: 700;
}
.focus-chip[hidden] { display: none; }

/* ── Buttons ────────────────────────────────────────────── */
.btn-primary {
  height: 36px;
  padding: 0 18px;
  background: var(--navy);
  color: #fff;
  border: none;
  border-radius: 6px;
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
  transition: background 0.15s;
  white-space: nowrap;
}
.btn-primary:hover { background: var(--navy-d); }
.btn-primary:disabled { background: var(--muted); cursor: not-allowed; opacity: 0.7; }
.btn-primary.btn-full { width: 100%; height: 42px; }
.btn-primary-sm {
  height: 28px;
  padding: 0 12px;
  background: var(--navy);
  color: #fff;
  border: none;
  border-radius: 5px;
  font-size: 12px;
  font-weight: 700;
  cursor: pointer;
}
.btn-ghost {
  height: 36px;
  padding: 0 16px;
  background: var(--panel);
  color: var(--ink);
  border: 1px solid var(--line);
  border-radius: 6px;
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  text-decoration: none;
  transition: background 0.15s;
}
.btn-ghost:hover { background: var(--hover-bg); }
.btn-ghost-sm {
  height: 28px;
  padding: 0 10px;
  background: var(--bg);
  color: var(--ink);
  border: 1px solid var(--line);
  border-radius: 5px;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
}
.btn-danger-sm {
  height: 28px;
  padding: 0 10px;
  background: var(--row-risk);
  color: var(--danger);
  border: 1px solid rgba(185,28,28,0.25);
  border-radius: 5px;
  font-size: 12px;
  font-weight: 700;
  cursor: pointer;
}
.btn-danger-sm:hover { background: #fee2e2; }

/* ── Badges ─────────────────────────────────────────────── */
.badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 10px;
  font-size: 11px;
  font-weight: 700;
}
.badge-blue  { background: #dbeafe; color: #1e40af; }
.badge-red   { background: #fee2e2; color: var(--danger); }
.badge-green { background: #dcfce7; color: #166534; }
.badge-gray  { background: #f1f5f9; color: #475569; }
.badge-amber { background: #fef3c7; color: #92400e; }

/* ── Notes panel ─────────────────────────────────────────── */
.note-body {
  padding: 14px 18px;
  display: grid;
  gap: 10px;
}
.selected-opportunity {
  min-height: 38px;
  padding: 9px 12px;
  border: 1px dashed var(--line);
  background: var(--panel-r);
  border-radius: 6px;
  font-size: 13px;
  color: var(--ink);
  font-weight: 500;
}
.selected-opportunity.muted { color: var(--muted); font-style: italic; font-weight: 400; }
.note-actions {
  display: grid;
  grid-template-columns: 140px 1fr auto;
  gap: 8px;
  align-items: end;
}
.note-list {
  display: grid;
  gap: 8px;
  max-height: 320px;
  overflow-y: auto;
  padding-right: 4px;
}
.note-item {
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 10px 12px;
  background: var(--panel-r);
}
.note-item .note-head {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  font-size: 11px;
  color: var(--muted);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}
.note-item .note-head strong { color: var(--ink); }
.note-item p {
  margin: 6px 0 4px;
  white-space: pre-wrap;
  font-size: 13px;
  color: var(--ink);
}
.note-item small { color: var(--muted); font-size: 11px; }

/* ── Error banner ─────────────────────────────────────────── */
.error-banner {
  position: fixed;
  left: 18px;
  right: 18px;
  bottom: 18px;
  padding: 13px 16px;
  background: #3a1110;
  color: #fff;
  border-radius: 8px;
  box-shadow: 0 12px 30px var(--shadow);
  z-index: 500;
  font-size: 13px;
}

/* ── Auth pages ─────────────────────────────────────────── */
.auth-wrap {
  min-height: calc(100vh - 58px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 40px 20px;
}
.auth-card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 36px 32px;
  width: 100%;
  max-width: 400px;
  box-shadow: 0 4px 24px rgba(0,0,0,0.08);
}
.auth-logo {
  text-align: center;
  line-height: 1;
  margin-bottom: 6px;
}
.auth-logo-img {
  height: 52px;
  width: auto;
  object-fit: contain;
}
.auth-title {
  text-align: center;
  font-size: 16px;
  font-weight: 600;
  color: var(--muted);
  margin-bottom: 28px;
}

/* Login-card variant */
.auth-brandmark {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  margin: 8px 0 2px;
  color: var(--ink);         /* shift-gate strokes pick this up */
}
.auth-brandmark .gearbox-icon { width: 34px; height: 34px; }
.auth-brandmark .auth-title {
  font-size: 22px;
  font-weight: 800;
  font-style: italic;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--ink);
}
.auth-tagline {
  text-align: center;
  font-size: 11px;
  font-weight: 600;
  font-style: italic;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--muted);
  margin-bottom: 26px;
}
.auth-form {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

/* ── Theme toggle ───────────────────────────────────────── */
.theme-toggle {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  border: 1px solid rgba(255,255,255,0.2);
  background: rgba(255,255,255,0.08);
  color: rgba(255,255,255,0.75);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: background 0.15s, color 0.15s;
  margin-left: 8px;
}
.theme-toggle:hover {
  background: rgba(255,255,255,0.18);
  color: #fff;
}
.theme-toggle .icon-sun  { display: none; }
.theme-toggle .icon-moon { display: block; }
[data-theme="dark"] .theme-toggle .icon-sun  { display: block; }
[data-theme="dark"] .theme-toggle .icon-moon { display: none; }

/* ── Auto-logout modal ──────────────────────────────────── */
.modal-overlay {
  position: fixed;
  inset: 0;
  z-index: 900;
  background: rgba(15,21,84,0.50);
  display: flex;
  align-items: center;
  justify-content: center;
}
.modal-overlay[hidden] { display: none; }
.modal-card {
  background: var(--panel);
  border-radius: 14px;
  padding: 40px 44px 36px;
  width: 380px;
  max-width: 92vw;
  text-align: center;
  box-shadow: 0 24px 64px rgba(0,0,0,0.22);
  animation: modalIn 0.18s ease;
}
@keyframes modalIn {
  from { transform: translateY(-14px); opacity: 0; }
  to   { transform: translateY(0);     opacity: 1; }
}
.modal-icon-wrap { color: var(--amber); margin-bottom: 14px; }
.modal-title {
  font-size: 20px;
  font-weight: 800;
  color: var(--navy);
  margin: 0 0 10px;
}
.modal-body {
  font-size: 14px;
  color: var(--muted);
  line-height: 1.65;
  margin: 0 0 26px;
}
.modal-body strong { color: var(--ink); }
.modal-actions { display: flex; gap: 10px; justify-content: center; }

.modal-box {
  background: var(--panel);
  border-radius: 12px;
  box-shadow: 0 20px 60px rgba(0,0,0,0.25);
  padding: 24px;
  width: 420px;
  max-width: 95vw;
}
.modal-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 18px;
}
.modal-close {
  background: none;
  border: none;
  font-size: 18px;
  cursor: pointer;
  color: var(--muted);
  line-height: 1;
  padding: 0 4px;
}
.modal-close:hover { color: var(--ink); }

/* ── Impersonation bar ───────────────────────────────────── */
.impersonate-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 24px;
  background: #92400e;
  color: #fef3c7;
  font-size: 13px;
  font-weight: 500;
  border-bottom: 1px solid #b45309;
}
[data-theme="dark"] .impersonate-bar {
  background: #78350f;
  border-bottom-color: #92400e;
}
.impersonate-bar strong { color: #ffffff; }
.impersonate-stop {
  background: rgba(255,255,255,0.15);
  border: 1px solid rgba(255,255,255,0.35);
  color: #fef3c7;
  font-size: 12px;
  font-weight: 600;
  padding: 3px 10px;
  border-radius: 5px;
  cursor: pointer;
  transition: background 0.15s;
}
.impersonate-stop:hover { background: rgba(255,255,255,0.25); }

/* ── Admin page ─────────────────────────────────────────── */
.admin-page {
  max-width: 1300px;
  margin: 0 auto;
  padding: 20px 24px;
}
.page-title-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 18px;
}
.form-row {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  align-items: flex-end;
}
.stack { display: flex; flex-direction: column; gap: 12px; }
.row-actions { display: flex; gap: 6px; flex-wrap: wrap; }
.required { color: var(--red); }
.mono { font-family: "JetBrains Mono", ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 12.5px; }

/* ── Inventory chart canvas ──────────────────────────────── */
canvas#inventoryChart {
  display: block;
  width: 100%;
  height: 260px;
}
canvas#trendChart {
  display: block;
  width: 100%;
  height: 320px;
}

/* ── Chart canvas should respond to clicks ─────────────── */
canvas#trendChart { cursor: crosshair; }

/* ── Export buttons (Excel / PDF) ───────────────────────── */
.export-group {
  display: inline-flex;
  gap: 6px;
  align-items: center;
}
.btn-export {
  height: 28px;
  padding: 0 10px;
  background: var(--panel);
  color: var(--ink);
  border: 1px solid var(--line);
  border-radius: 5px;
  font-size: 11px;
  font-weight: 700;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 4px;
  transition: background 0.12s, border-color 0.12s, color 0.12s;
  letter-spacing: 0.02em;
}
.btn-export:hover {
  background: var(--hover-bg);
  border-color: var(--navy);
  color: var(--navy);
}
.btn-export svg {
  width: 12px;
  height: 12px;
  flex-shrink: 0;
}

/* ── Stacked tables on Buyout/Lost page ─────────────────── */
.buyout-stack {
  display: flex;
  flex-direction: column;
  gap: 18px;
  min-width: 0;
}

/* ── Row detail card (notes panel) ──────────────────────── */
.row-details {
  display: grid;
  grid-template-columns: max-content 1fr;
  gap: 4px 12px;
  margin: 6px 0;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--panel-r);
  font-size: 12px;
}
.row-details dt {
  color: var(--muted);
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  font-size: 10.5px;
  align-self: center;
}
.row-details dd {
  margin: 0;
  color: var(--ink);
  word-break: break-word;
  white-space: pre-wrap;
}
.row-details dd.empty { color: var(--muted); font-style: italic; }
.equiv-oh-stock { color: var(--ok, #15803d); font-weight: 600; }

/* ── Drill-down table ───────────────────────────────────── */
.drill-table .drill-col {
  width: 38%;
  min-width: 280px;
}
.drill-toggle {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 18px;
  height: 18px;
  font-size: 12px;
  line-height: 1;
  border: 1px solid var(--line);
  border-radius: 4px;
  background: var(--panel);
  color: var(--ink);
  cursor: pointer;
  margin-right: 8px;
  padding: 0;
  font-weight: 700;
}
.drill-toggle:hover { background: var(--hover-bg); border-color: var(--navy); }
.drill-toggle.placeholder {
  visibility: hidden;
  cursor: default;
}
.drill-row-loc td  { background: rgba(15, 21, 84, 0.05); font-weight: 600; }
.drill-row-line td { background: rgba(15, 21, 84, 0.025); font-size: 12px; }
.drill-row-cat td  { background: transparent; font-size: 12px; }
[data-theme="dark"] .drill-row-loc td  { background: rgba(99, 102, 241, 0.10); }
[data-theme="dark"] .drill-row-line td { background: rgba(99, 102, 241, 0.05); }
.drill-label-loc  { padding-left: 4px; }
.drill-label-line { padding-left: 32px; color: var(--muted); }
.drill-label-cat  { padding-left: 60px; color: var(--muted); }
.drill-row-part td { background: transparent; font-size: 11.5px; color: var(--muted); }
.drill-table tbody tr.drill-row-loc.expanded td  { background: var(--hover-bg); }

/* ── Tab group (segmented control) ─────────────────────────────────────── */
.tab-group { display: inline-flex; gap: 4px; }
.tab-group button {
  border: 1px solid var(--line);
  background: var(--panel);
  color: var(--muted);
  font-size: 12px;
  font-weight: 600;
  padding: 4px 12px;
  border-radius: 6px;
  cursor: pointer;
}
.tab-group button:hover { border-color: var(--navy); color: var(--ink); }
.tab-group button.active { background: var(--navy); border-color: var(--navy); color: #fff; }
[data-theme="dark"] .tab-group button.active { background: var(--accent, #6366f1); border-color: var(--accent, #6366f1); }

/* ── Location drilldown: selected part + nested PO history ──────────────── */
.drill-part { font-weight: 700; color: var(--navy); margin-left: 6px; }
[data-theme="dark"] .drill-part { color: var(--text); }

/* Nested 12-month PO history reads as an inset card so its narrower column grid
   doesn't look like it should line up with the outer location columns. */
.po-history-card {
  margin: 6px 12px 12px 40px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel-bg, #fff);
  overflow: hidden;
}
[data-theme="dark"] .po-history-card { background: rgba(99, 102, 241, 0.06); }
.po-history-caption {
  padding: 6px 10px;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--muted);
  border-bottom: 1px solid var(--line);
}
.po-history-card > .muted { padding: 10px 12px; }
table.po-history-table { width: 100%; }

/* ── Responsive ─────────────────────────────────────────── */
@media (max-width: 960px) {
  .topbar { gap: 12px; padding: 0 16px; }
  .nav-toggle { display: inline-flex; }

  /* Top nav becomes a slide-in drawer */
  .top-nav {
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    width: 260px;
    max-width: 82vw;
    flex-direction: column;
    align-items: stretch;
    gap: 2px;
    padding: 14px 12px;
    background: var(--navy);
    box-shadow: 2px 0 20px rgba(0,0,0,0.35);
    transform: translateX(-100%);
    transition: transform 0.22s ease;
    z-index: 100;
    overflow-y: auto;
  }
  .top-nav-link { font-size: 15px; padding: 12px 14px; border-radius: 8px; }
  body.nav-open .top-nav { transform: translateX(0); }
  body.nav-open .nav-backdrop { display: block; }
  body.nav-open { overflow: hidden; }

  .user-name { display: none; }

  /* Pin the first column of dense tables so row labels stay visible while
     the numeric columns scroll horizontally */
  table.dense th:first-child,
  table.dense td:first-child {
    position: sticky;
    left: 0;
    z-index: 1;
    background: var(--panel);
  }
  table.dense thead th:first-child { z-index: 2; background: var(--panel-r); }
  table.dense .total-row td:first-child { background: var(--bg); }

  /* iOS zooms any focused input under 16px — keep form controls at 16px */
  .filter-select,
  input.filter-select,
  select.filter-select,
  input[type="text"],
  input[type="search"],
  input[type="number"],
  input[type="date"] { font-size: 16px; }

  .kpi-strip { flex-wrap: wrap; }
  .kpi-card { min-width: 45%; }
  .panel-grid.two,
  .panel-grid.three,
  .panel-grid.two-one,
  .panel-grid.three-two { grid-template-columns: 1fr; }
  .filter-bar { padding: 10px 16px; }
  .content-area { padding: 14px 16px; }
  .page-header { padding: 12px 16px; }
  .note-actions { grid-template-columns: 1fr; }
}

/* ── Customer Inventory ───────────────────────────────────────────────────── */
.ci-typeahead {
  position: absolute; top: 100%; left: 0; right: 0; z-index: 30;
  background: var(--panel, #fff); border: 1px solid var(--border, #e2e8f0);
  border-radius: 8px; box-shadow: 0 8px 24px rgba(0,0,0,.12);
  max-height: 320px; overflow-y: auto; margin-top: 4px;
}
.ci-typeahead-item {
  display: flex; flex-direction: column; gap: 2px;
  padding: 8px 12px; cursor: pointer; font-size: 13px;
}
.ci-typeahead-item:hover,
.ci-typeahead-item.active { background: var(--hover, #f1f5f9); }

/* Searchable filter dropdown (type-to-narrow Vendor / Line on Network Inventory) */
.search-select { position: relative; display: block; }
.search-select .ci-typeahead-item { flex-direction: row; gap: 6px; align-items: baseline; }
.search-select .ci-typeahead-item.chosen { font-weight: 600; }
.ci-section-label { font-weight: 600; font-size: 13px; margin-bottom: 8px; }
.ci-attr-grid {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 14px;
}
.ci-attr-group { border: 1px solid var(--border, #e2e8f0); border-radius: 8px; padding: 10px 12px; }
.ci-attr-title { font-weight: 600; font-size: 12px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted, #64748b); margin-bottom: 6px; }
.ci-attr-item { display: flex; align-items: center; gap: 7px; font-size: 13px; padding: 3px 0; cursor: pointer; }

/* ── Extract tool ─────────────────────────────────────────────────────────── */
.ex-checkbox-box {
  border: 1px solid var(--border, #e2e8f0); border-radius: 8px; padding: 8px 10px;
  max-height: 240px; overflow-y: auto; display: flex; flex-direction: column; gap: 2px;
  background: var(--panel, #fff);
}
.ex-check-item { display: flex; align-items: center; gap: 8px; font-size: 13px; padding: 2px 0; cursor: pointer; }
.ex-check-item span { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* Dual-listbox (slushbucket) */
.ex-slush { display: grid; grid-template-columns: 1fr auto 1fr; gap: 10px; align-items: stretch; }
.ex-slush-pane { display: flex; flex-direction: column; border: 1px solid var(--border, #e2e8f0); border-radius: 8px; overflow: hidden; background: var(--panel, #fff); }
.ex-slush-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 6px 10px; font-size: 12px; font-weight: 600; border-bottom: 1px solid var(--border, #e2e8f0); background: var(--hover, #f8fafc); }
.ex-slush-list { max-height: 300px; overflow-y: auto; padding: 4px; }
.ex-slush-group { font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: .04em; color: var(--muted, #64748b); padding: 6px 8px 2px; }
.ex-slush-item { display: flex; align-items: center; justify-content: space-between; gap: 8px; font-size: 13px; padding: 4px 8px; border-radius: 6px; cursor: pointer; }
.ex-slush-item:hover { background: var(--hover, #f1f5f9); }
.ex-slush-label { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ex-slush-add { color: var(--accent, #2563eb); font-weight: 700; }
.ex-slush-btns { display: flex; gap: 2px; flex-shrink: 0; }
.ex-slush-btns button { border: none; background: transparent; cursor: pointer; font-size: 11px; padding: 1px 4px; color: var(--muted, #64748b); border-radius: 4px; }
.ex-slush-btns button:hover { background: var(--border, #e2e8f0); color: var(--text, #0f172a); }
.ex-slush-mid { display: flex; flex-direction: column; justify-content: center; gap: 8px; }
.ex-slush-mid button { padding: 6px 8px; }

/* ── Change-request floating action button ────────────────────────────── */
.cr-fab { position: fixed; right: 20px; bottom: 20px; z-index: 60; display: inline-flex; align-items: center; gap: 8px; padding: 11px 16px; border: none; border-radius: 999px; background: var(--accent, #DC2626); color: #fff; font-size: 13px; font-weight: 600; cursor: pointer; box-shadow: 0 4px 14px rgba(0,0,0,.25); transition: transform .12s, box-shadow .12s; }
.cr-fab:hover { transform: translateY(-1px); box-shadow: 0 6px 18px rgba(0,0,0,.3); }
.cr-fab svg { flex-shrink: 0; }
@media (max-width: 640px) { .cr-fab span { display: none; } .cr-fab { padding: 13px; } }

/* ── Vendor → SKU fill drill ──────────────────────────────────────────── */
tr.drillable { cursor: pointer; }
tr.drillable:hover > td { background: var(--border, #eef2f7); }
tr.drill-detail > td { padding: 0; background: var(--panel-2, #f7f8fc); }
.drill-panel { padding: 10px 14px; }
.drill-title { font-size: 12px; font-weight: 600; color: var(--muted, #64748b); margin-bottom: 6px; }
table.drill-table { width: 100%; }
table.drill-table th, table.drill-table td { font-size: 12px; }

/* ── Data freshness note ──────────────────────────────────────────────── */
.data-freshness { font-size: 11px; color: var(--muted, #64748b); margin-top: 4px; }
.data-freshness:empty { display: none; }
