/* ─── Reset & Base ────────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --brand:       #1d4ed8;
  --brand-dark:  #1e40af;
  --brand-light: #eff6ff;

  --status-outstanding: #8b5cf6;
  --status-pending: #6b7280;
  --status-partial: #2563eb;
  --status-ready:   #d97706;
  --status-sent:    #16a34a;
  --status-problem: #dc2626;
  --status-stores:  #0d9488;
  --status-ignored: #7c3aed;

  --header-bg:   #1d4ed8;

  --bg:          #f3f4f6;
  --surface:     #ffffff;
  --border:      #e5e7eb;
  --text:        #111827;
  --text-muted:  #6b7280;
  --text-light:  #9ca3af;

  --radius:  6px;
  --shadow:  0 1px 3px rgba(0,0,0,.1), 0 1px 2px rgba(0,0,0,.06);
}

/* ─── Dark mode overrides ────────────────────────────────────────────────── */
[data-theme="dark"] {
  --brand:       #3b82f6;
  --brand-dark:  #2563eb;
  --brand-light: #1e293b;
  --header-bg:   #151e56;

  --bg:          #0f172a;
  --surface:     #1e293b;
  --border:      #334155;
  --text:        #e2e8f0;
  --text-muted:  #94a3b8;
  --text-light:  #64748b;

  --shadow:  0 1px 3px rgba(0,0,0,.3), 0 1px 2px rgba(0,0,0,.2);

  color-scheme: dark;
}

/* Hardcoded colour overrides for dark mode */
[data-theme="dark"] thead th { background: #1e293b; }
[data-theme="dark"] .progress-bar { background: #334155; }
[data-theme="dark"] .badge-outstanding { background: #2e1065; color: #a78bfa; border-color: #7c3aed; }
[data-theme="dark"] .badge-pending  { background: #1f2937; color: #9ca3af; border-color: #4b5563; }
[data-theme="dark"] .badge-partial  { background: #1e3a5f; color: #60a5fa; border-color: #3b82f6; }
[data-theme="dark"] .badge-ready    { background: #422006; color: #fbbf24; border-color: #d97706; }
[data-theme="dark"] .badge-sent     { background: #052e16; color: #4ade80; border-color: #16a34a; }
[data-theme="dark"] .badge-problem  { background: #450a0a; color: #f87171; border-color: #dc2626; }
[data-theme="dark"] .badge-stores   { background: #042f2e; color: #5eead4; border-color: #0d9488; }
[data-theme="dark"] .badge-coverage-covered    { background: #052e16; color: #4ade80; border-color: #16a34a; }
[data-theme="dark"] .badge-coverage-partial    { background: #422006; color: #fbbf24; border-color: #d97706; }
[data-theme="dark"] .badge-coverage-not_raised { background: #450a0a; color: #f87171; border-color: #dc2626; }
[data-theme="dark"] .badge-coverage-na         { background: #1f2937; color: #9ca3af; border-color: #4b5563; }
[data-theme="dark"] .badge-coverage-teco       { background: #3b0764; color: #d8b4fe; border-color: #7e22ce; }
[data-theme="dark"] .btn-icon.btn-icon-ignore  { background: #3b0764; border-color: #7e22ce; }
[data-theme="dark"] .btn-icon.btn-icon-ignore:hover:not(:disabled) { background: #581c87; }
[data-theme="dark"] .doc-pill.on { background: #052e16; color: #4ade80; border-color: #16a34a; }
[data-theme="dark"] .badge-type-glass  { background: #0c4a6e; color: #7dd3fc; border-color: #0369a1; }
[data-theme="dark"] .badge-type-stock  { background: #422006; color: #fde047; border-color: #a16207; }
[data-theme="dark"] .badge-type-manual { background: #3b0764; color: #d8b4fe; border-color: #7e22ce; }
[data-theme="dark"] .problem-panel { background: #450a0a; border-color: #991b1b; }
[data-theme="dark"] .error-banner  { background: #450a0a; border-color: #991b1b; color: #fca5a5; }
[data-theme="dark"] .po-replacement { background: #422006; color: #fbbf24; }
[data-theme="dark"] .btn-icon.btn-icon-ready   { background: #422006; border-color: #92400e; }
[data-theme="dark"] .btn-icon.btn-icon-sent    { background: #052e16; border-color: #166534; }
[data-theme="dark"] .btn-icon.btn-icon-problem { background: #450a0a; border-color: #991b1b; }
[data-theme="dark"] .btn-icon.btn-icon-clear   { background: #1e293b; border-color: #334155; }
[data-theme="dark"] .btn-icon.btn-icon-stores  { background: #042f2e; border-color: #0d9488; }
[data-theme="dark"] .btn-icon.btn-icon-ready:hover:not(:disabled)   { background: #78350f; }
[data-theme="dark"] .btn-icon.btn-icon-sent:hover:not(:disabled)    { background: #14532d; }
[data-theme="dark"] .btn-icon.btn-icon-problem:hover:not(:disabled) { background: #7f1d1d; }
[data-theme="dark"] .btn-icon.btn-icon-clear:hover:not(:disabled)   { background: #334155; }
[data-theme="dark"] .btn-icon.btn-icon-stores:hover:not(:disabled)  { background: #134e4a; }
[data-theme="dark"] .btn-secondary { background: var(--surface); color: var(--text); border-color: var(--border); }
[data-theme="dark"] .btn-secondary:hover:not(:disabled) { background: #334155; }
[data-theme="dark"] .timeline-dot { background: var(--surface); }
[data-theme="dark"] .timeline-dot.dot-received  { background: #1e3a5f; }
[data-theme="dark"] .timeline-dot.dot-ready     { background: #422006; }
[data-theme="dark"] .timeline-dot.dot-sent      { background: #052e16; }
[data-theme="dark"] .timeline-dot.dot-problem   { background: #450a0a; }
[data-theme="dark"] .chip-count { background: var(--surface); }
[data-theme="dark"] .modal-backdrop { background: rgba(0,0,0,.65); }

body {
  font-family: system-ui, -apple-system, Arial, sans-serif;
  font-size: 14px;
  line-height: 1.5;
  color: var(--text);
  background: var(--bg);
}

a { color: var(--brand); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ─── App shell (sidebar + main) ──────────────────────────────────────────── */
.app-shell {
  display: flex;
  min-height: 100vh;
}

/* ─── Sidebar ─────────────────────────────────────────────────────────────── */
.sidebar-no-transition .sidebar { transition: none !important; }

.sidebar {
  width: 232px;
  flex-shrink: 0;
  background: var(--header-bg);
  color: #fff;
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 0;
  height: 100vh;
  z-index: 100;
  overflow: hidden;
  transition: width .15s ease;
}

.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  height: 56px;
  padding: 0 20px;
  flex-shrink: 0;
  font-size: 17px;
  font-weight: 700;
  letter-spacing: .01em;
  white-space: nowrap;
  border-bottom: 1px solid rgba(255,255,255,.12);
}
.sidebar-brand-icon { display: inline-flex; flex-shrink: 0; }
.sidebar-brand-icon svg { width: 22px; height: 22px; }

.sidebar-nav {
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 12px 10px;
  flex: 1;
  overflow-y: auto;
}

.sidebar-link {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 12px;
  border-radius: var(--radius);
  color: rgba(255,255,255,.82);
  font-size: 13px;
  font-weight: 500;
  white-space: nowrap;
  text-decoration: none;
  transition: background .12s, color .12s;
}
.sidebar-link:hover { background: rgba(255,255,255,.12); color: #fff; text-decoration: none; }
.sidebar-link.active { background: rgba(255,255,255,.18); color: #fff; font-weight: 600; }
.sidebar-link-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  width: 20px;
  height: 20px;
}

.sidebar-heading {
  padding: 14px 16px 6px;
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .08em;
  color: rgba(255,255,255,.45);
  white-space: nowrap;
}
.app-shell.sidebar-collapsed .sidebar-heading { padding: 8px 0; }
.app-shell.sidebar-collapsed .sidebar-heading::after {
  content: '';
  display: block;
  height: 1px;
  background: rgba(255,255,255,.14);
  margin: 0 14px;
}

.sidebar-collapse-btn {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  padding: 12px 16px;
  background: transparent;
  border: none;
  border-top: 1px solid rgba(255,255,255,.12);
  color: rgba(255,255,255,.7);
  font-size: 13px;
  font-weight: 500;
  font-family: inherit;
  cursor: pointer;
  white-space: nowrap;
  flex-shrink: 0;
  transition: background .12s, color .12s;
}
.sidebar-collapse-btn:hover { background: rgba(255,255,255,.12); color: #fff; }
.sidebar-collapse-btn .sidebar-link-icon svg { transition: transform .15s ease; }

/* Collapsed (icon-rail) state */
.app-shell.sidebar-collapsed .sidebar { width: 64px; }
.app-shell.sidebar-collapsed .sidebar-link-text,
.app-shell.sidebar-collapsed .sidebar-brand-text { display: none; }
.app-shell.sidebar-collapsed .sidebar-link,
.app-shell.sidebar-collapsed .sidebar-brand,
.app-shell.sidebar-collapsed .sidebar-collapse-btn { justify-content: center; padding-left: 0; padding-right: 0; }
.app-shell.sidebar-collapsed .sidebar-collapse-btn .sidebar-link-icon svg { transform: rotate(180deg); }

/* ─── Main column ─────────────────────────────────────────────────────────── */
.app-main {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
}

.app-header {
  background: var(--header-bg);
  color: #fff;
  padding: 0 24px;
  height: 56px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  box-shadow: 0 2px 4px rgba(0,0,0,.2);
  position: sticky;
  top: 0;
  z-index: 90;
}

.header-left {
  display: flex;
  align-items: center;
  gap: 12px;
}

.app-header h1 {
  font-size: 18px;
  font-weight: 600;
  letter-spacing: .01em;
}

.header-right {
  display: flex;
  align-items: center;
  gap: 12px;
}

/* Mobile sidebar toggle (hidden on desktop) */
.btn-sidebar {
  display: none;
  background: transparent;
  border: 1px solid rgba(255,255,255,.4);
  border-radius: var(--radius);
  color: #fff;
  cursor: pointer;
  padding: 4px 8px;
  line-height: 1;
  transition: background .15s;
  align-items: center;
  justify-content: center;
}
.btn-sidebar:hover { background: rgba(255,255,255,.15); }
.btn-sidebar svg { width: 20px; height: 20px; }

.main-content {
  max-width: 1400px;
  width: 100%;
  margin: 0 auto;
  padding: 24px;
}

/* ─── Controller mode badge ───────────────────────────────────────────────── */
.mode-badge {
  font-size: 11px;
  font-weight: 700;
  padding: 3px 10px;
  border-radius: 999px;
  letter-spacing: .05em;
  text-transform: uppercase;
}
.mode-badge.view { background: rgba(255,255,255,.2); color: #fff; }
.mode-badge.controller { background: #fef08a; color: #713f12; }

/* ─── Buttons ─────────────────────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 16px;
  border-radius: var(--radius);
  border: 1px solid transparent;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: opacity .15s, background .15s;
  min-height: 36px;
  white-space: nowrap;
}
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn-primary   { background: var(--brand); color: #fff; border-color: var(--brand-dark); }
.btn-primary:hover:not(:disabled) { background: var(--brand-dark); }
.btn-secondary { background: var(--surface); color: var(--text); border-color: var(--border); }
.btn-secondary:hover:not(:disabled) { background: var(--bg); }
.btn-success   { background: #16a34a; color: #fff; border-color: #15803d; }
.btn-success:hover:not(:disabled)  { background: #15803d; }
.btn-warning   { background: #d97706; color: #fff; border-color: #b45309; }
.btn-warning:hover:not(:disabled)  { background: #b45309; }
.btn-danger    { background: #dc2626; color: #fff; border-color: #b91c1c; }
.btn-danger:hover:not(:disabled)   { background: #b91c1c; }
.btn-ghost     { background: transparent; color: #fff; border-color: rgba(255,255,255,.4); }
.btn-ghost:hover { background: rgba(255,255,255,.15); }
.btn-sm        { padding: 5px 10px; font-size: 12px; min-height: 30px; }

/* ─── Icon action buttons (dashboard) ────────────────────────────────────── */
.btn-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  padding: 0;
  border-radius: var(--radius);
  border: 1px solid transparent;
  cursor: pointer;
  transition: opacity .15s, background .15s, transform .1s;
  position: relative;
}
.btn-icon:hover:not(:disabled) { transform: scale(1.1); }
.btn-icon:disabled { opacity: .4; cursor: not-allowed; }
.btn-icon svg { width: 16px; height: 16px; pointer-events: none; }
.btn-icon.btn-icon-ready   { background: #fef3c7; color: var(--status-ready);   border-color: #fcd34d; }
.btn-icon.btn-icon-ready:hover:not(:disabled)   { background: #fde68a; }
.btn-icon.btn-icon-sent    { background: #dcfce7; color: var(--status-sent);    border-color: #86efac; }
.btn-icon.btn-icon-sent:hover:not(:disabled)    { background: #bbf7d0; }
.btn-icon.btn-icon-problem { background: #fee2e2; color: var(--status-problem); border-color: #fca5a5; }
.btn-icon.btn-icon-problem:hover:not(:disabled) { background: #fecaca; }
.btn-icon.btn-icon-clear   { background: var(--bg); color: var(--text-muted);   border-color: var(--border); }
.btn-icon.btn-icon-clear:hover:not(:disabled)   { background: var(--border); }
.btn-icon.btn-icon-stores  { background: #ccfbf1; color: #0d9488;              border-color: #5eead4; }
.btn-icon.btn-icon-stores:hover:not(:disabled)  { background: #99f6e4; }

.action-btns { display: flex; gap: 4px; }

/* ─── Replacement label ──────────────────────────────────────────────────── */
.po-replacement {
  font-size: 10px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .04em;
  color: #b45309;
  background: #fef3c7;
  border-radius: 3px;
  padding: 1px 5px;
  display: inline-block;
  margin-top: 2px;
}

/* ─── Status badges ───────────────────────────────────────────────────────── */
.badge {
  display: inline-block;
  padding: 2px 10px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: .04em;
  text-transform: uppercase;
}
.badge-outstanding { background: #ede9fe; color: var(--status-outstanding); border: 1px solid #c4b5fd; }
.badge-pending  { background: #f3f4f6; color: var(--status-pending); border: 1px solid #d1d5db; }
.badge-partial  { background: #dbeafe; color: var(--status-partial); border: 1px solid #93c5fd; }
.badge-ready    { background: #fef3c7; color: var(--status-ready);   border: 1px solid #fcd34d; }
.badge-sent     { background: #dcfce7; color: var(--status-sent);    border: 1px solid #86efac; }
.badge-problem  { background: #fee2e2; color: var(--status-problem); border: 1px solid #fca5a5; }
.badge-stores   { background: #ccfbf1; color: #0d9488; border: 1px solid #5eead4; }

/* PO-coverage badges (sales orders) */
.badge-coverage-covered    { background: #dcfce7; color: var(--status-sent);    border: 1px solid #86efac; }
.badge-coverage-partial    { background: #fef3c7; color: var(--status-ready);   border: 1px solid #fcd34d; }
.badge-coverage-not_raised { background: #fee2e2; color: var(--status-problem); border: 1px solid #fca5a5; }
.badge-coverage-na         { background: #f3f4f6; color: var(--status-pending); border: 1px solid #d1d5db; }
.badge-coverage-teco       { background: #ede9fe; color: var(--status-ignored); border: 1px solid #c4b5fd; }

/* Credited amount on the sales order list */
.credited-amount { color: var(--status-ignored); font-weight: 600; }

/* Ignored sales-order line items */
tr.item-ignored td { opacity: 0.6; }
tr.item-ignored .item-desc-primary { text-decoration: line-through; }
.ignore-note { display: block; font-size: 11px; color: var(--status-ignored); margin-top: 2px; }
.btn-icon.btn-icon-ignore { background: #ede9fe; color: var(--status-ignored); border-color: #c4b5fd; }
.btn-icon.btn-icon-ignore:hover:not(:disabled) { background: #ddd6fe; }

/* Document-flag pills (sales order detail) */
.doc-pills { display: flex; flex-wrap: wrap; gap: 6px; }
.doc-pill {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 4px 10px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 600;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text-muted);
}
.doc-pill.on {
  background: #dcfce7;
  color: var(--status-sent);
  border-color: #86efac;
}
.doc-pill.on svg { width: 13px; height: 13px; }
.doc-pill.off { opacity: .65; }

/* Problem indicator on rows */
.problem-icon {
  color: var(--status-problem);
  line-height: 1;
  cursor: default;
  display: inline-flex;
  vertical-align: middle;
}
.problem-icon svg { width: 16px; height: 16px; }

/* ─── Cards & Panels ──────────────────────────────────────────────────────── */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}
.card-body { padding: 20px; }
.card-header {
  padding: 14px 20px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}
.card-header h2 { font-size: 15px; font-weight: 600; }

/* ─── Filter bar ──────────────────────────────────────────────────────────── */
.filter-bar {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 20px;
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  gap: 12px;
  margin-bottom: 16px;
  box-shadow: var(--shadow);
}

.filter-group {
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.filter-group label {
  font-size: 11px;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: .05em;
}

.filter-group input,
.filter-group select {
  height: 36px;
  padding: 0 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 13px;
  color: var(--text);
  background: var(--surface);
}
.filter-group input[type="date"]  { width: 150px; }
.filter-group select              { width: 200px; }
.filter-group input[type="text"]  { width: 220px; }
.filter-group input:focus,
.filter-group select:focus {
  outline: none;
  border-color: var(--brand);
  box-shadow: 0 0 0 3px rgba(29,78,216,.12);
}

.filter-actions {
  display: flex;
  gap: 8px;
  align-items: flex-end;
  margin-left: auto;
}

/* ─── Status summary chips ────────────────────────────────────────────────── */
.chip-bar {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 16px;
}
.chip-group {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}
.chip-separator {
  width: 1px;
  height: 28px;
  background: var(--border);
  margin: 0 4px;
}
.chip-total {
  margin-left: auto;
  font-size: 12px;
  color: var(--text-muted);
  white-space: nowrap;
}
.chip-total span { font-weight: 700; }

.status-chip {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 14px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--surface);
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  transition: box-shadow .15s, opacity .15s;
  opacity: 0.5;
}
.status-chip:hover { box-shadow: 0 0 0 3px rgba(29,78,216,.15); opacity: 0.8; }
.status-chip.active { box-shadow: 0 0 0 2px var(--brand); opacity: 1; }
.status-chip .chip-count {
  background: var(--bg);
  border-radius: 999px;
  padding: 1px 8px;
  font-size: 11px;
}

/* ─── Item type badges ──────────────────────────────────────────────────── */
.badge-type-glass  { background: #e0f2fe; color: #0369a1; border: 1px solid #7dd3fc; }
.badge-type-stock  { background: #fef9c3; color: #a16207; border: 1px solid #fde047; }
.badge-type-manual { background: #f3e8ff; color: #7e22ce; border: 1px solid #d8b4fe; }

/* ─── Table ───────────────────────────────────────────────────────────────── */
.table-wrap {
  overflow-x: auto;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
}

table {
  width: 100%;
  border-collapse: collapse;
  background: var(--surface);
}

thead th {
  background: #f9fafb;
  padding: 10px 14px;
  text-align: left;
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .06em;
  color: var(--text-muted);
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}

tbody tr {
  border-bottom: 1px solid var(--border);
  transition: background .1s;
  cursor: pointer;
}
tbody tr:last-child { border-bottom: none; }
tbody tr:hover { background: var(--brand-light); }
tbody tr.has-problem { border-left: 3px solid var(--status-problem); }
tbody tr.has-ignored { border-left: 3px solid var(--status-ignored); }

td {
  padding: 10px 14px;
  vertical-align: middle;
  font-size: 13px;
}

td.muted { color: var(--text-muted); }
td.no-wrap { white-space: nowrap; }

/* Line item description: primary line truncated, secondary muted beneath */
.item-desc-primary {
  display: block;
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 280px;
}
.item-desc-secondary {
  display: block;
  font-size: 11px;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 280px;
}

.po-number {
  font-weight: 700;
  font-family: 'Courier New', monospace;
  font-size: 13px;
  color: var(--brand);
}

/* Clickable cross-link (PO ↔ Sales Order) */
a.po-link, .po-link {
  cursor: pointer;
  text-decoration: none;
}
a.po-link:hover, tr:hover .po-link {
  text-decoration: underline;
}

.supplier-name,
.ref-comment,
.linked-customer {
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.supplier-name {
  font-weight: 500;
  max-width: 180px;
}

.ref-comment {
  max-width: 200px;
  color: var(--text-muted);
  font-size: 12px;
}

.linked-customer {
  max-width: 160px;
  color: var(--text-muted);
  font-size: 11px;
  margin-top: 1px;
}

.qty-received { font-weight: 600; color: var(--text); }

/* ─── Progress bar (item receipt progress) ───────────────────────────────── */
.progress-wrap {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 100px;
}
.progress-bar {
  flex: 1;
  height: 6px;
  background: #e5e7eb;
  border-radius: 999px;
  overflow: hidden;
}
.progress-bar-fill {
  height: 100%;
  border-radius: 999px;
  background: var(--status-sent);
  transition: width .3s;
}
.progress-label {
  font-size: 11px;
  color: var(--text-muted);
  white-space: nowrap;
}

/* ─── Detail page sections ────────────────────────────────────────────────── */
.detail-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 16px;
  margin-bottom: 24px;
}

.detail-field label {
  display: block;
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .05em;
  color: var(--text-muted);
  margin-bottom: 2px;
}
.detail-field .value {
  font-size: 14px;
  font-weight: 500;
  color: var(--text);
}
.detail-field .value.mono {
  font-family: 'Courier New', monospace;
  font-size: 15px;
  font-weight: 700;
  color: var(--brand);
}
.detail-field .value.muted { color: var(--text-muted); }

/* Full-width notes block — sits under the detail grid so long notes don't
   stretch a single grid column and distort the data block. */
.detail-notes {
  margin: -8px 0 24px;
  padding: 12px 14px;
  background: var(--brand-light, rgba(29,78,216,.06));
  border: 1px solid var(--border);
  border-radius: var(--radius);
}
.detail-notes label {
  display: block;
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .05em;
  color: var(--text-muted);
  margin-bottom: 4px;
}
.detail-notes .value {
  font-size: 14px;
  color: var(--text);
  white-space: pre-wrap;
  word-break: break-word;
}

/* "Raised <date> by <user>" meta next to an order title — dimmed and smaller. */
.title-raised-meta {
  font-size: 12px;
  font-weight: 500;
  color: var(--text-muted);
}
.title-raised-meta strong { color: var(--text); font-weight: 600; }

.section { margin-bottom: 24px; }
.section-title {
  font-size: 13px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .06em;
  color: var(--text-muted);
  margin-bottom: 10px;
  padding-bottom: 6px;
  border-bottom: 1px solid var(--border);
}

/* ─── Tracking status block ───────────────────────────────────────────────── */
.tracking-block {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  margin-bottom: 24px;
  box-shadow: var(--shadow);
}

.tracking-block.has-problem {
  border-color: var(--status-problem);
  box-shadow: 0 0 0 2px rgba(220,38,38,.15);
}

.tracking-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 12px;
  margin-bottom: 16px;
}

.tracking-status-display {
  display: flex;
  align-items: center;
  gap: 10px;
}

.tracking-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.tracking-history {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 12px;
  margin-top: 12px;
  padding-top: 12px;
  border-top: 1px solid var(--border);
}

.history-step {
  background: var(--bg);
  border-radius: var(--radius);
  padding: 10px 12px;
  font-size: 12px;
}
.history-step .step-label {
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .05em;
  font-size: 10px;
  color: var(--text-muted);
  margin-bottom: 4px;
}
.history-step .step-date { font-weight: 600; color: var(--text); margin-bottom: 2px; }
.history-step .step-by   { color: var(--text-muted); }
.history-step .step-comment { color: var(--text); margin-top: 4px; font-style: italic; }

/* ─── Problem panel ───────────────────────────────────────────────────────── */
.problem-panel {
  background: #fff5f5;
  border: 1px solid #fca5a5;
  border-radius: var(--radius);
  padding: 12px 16px;
  margin-top: 12px;
  font-size: 12px;
}
.problem-panel .problem-label {
  font-weight: 700;
  color: var(--status-problem);
  margin-bottom: 4px;
}

/* ─── Stored panel ───────────────────────────────────────────────────────── */
.stored-panel {
  background: #f0fdfa;
  border: 1px solid #5eead4;
  border-radius: var(--radius);
  padding: 12px 16px;
  margin-top: 12px;
  font-size: 12px;
}
.stored-panel .stored-label {
  font-weight: 700;
  color: var(--status-stores);
  margin-bottom: 4px;
}
.stored-panel .stored-label svg { vertical-align: -3px; width: 16px; height: 16px; }

[data-theme="dark"] .stored-panel { background: #042f2e; border-color: #0d9488; }

/* ─── Modal ───────────────────────────────────────────────────────────────── */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.45);
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
}

.modal {
  background: var(--surface);
  border-radius: 10px;
  box-shadow: 0 20px 60px rgba(0,0,0,.25);
  width: 100%;
  max-width: 440px;
}

.modal-confirm { max-width: 400px; }
.modal-confirm .confirm-message {
  margin: 0;
  font-size: 14px;
  line-height: 1.5;
  color: var(--text);
}

/* "Coming soon" placeholder panel */
.coming-soon {
  text-align: center;
  padding: 56px 24px;
  background: var(--surface);
  border: 1px dashed var(--border);
  border-radius: var(--radius);
  color: var(--text-muted);
}
.coming-soon-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 60px;
  height: 60px;
  border-radius: 50%;
  background: var(--brand-light, rgba(29,78,216,.08));
  color: var(--brand);
  margin-bottom: 14px;
}
.coming-soon h3 { margin: 0 0 6px; font-size: 18px; color: var(--text); }
.coming-soon p { margin: 0 auto; max-width: 360px; font-size: 13px; }

.modal-header {
  padding: 18px 24px 14px;
  border-bottom: 1px solid var(--border);
  font-size: 16px;
  font-weight: 700;
}

.modal-body { padding: 20px 24px; }

.modal-footer {
  padding: 14px 24px 18px;
  border-top: 1px solid var(--border);
  display: flex;
  justify-content: flex-end;
  gap: 10px;
}

.form-group { margin-bottom: 14px; }
.form-group label {
  display: block;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: .05em;
  margin-bottom: 5px;
}
.form-group input,
.form-group textarea {
  width: 100%;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 13px;
  font-family: inherit;
  color: var(--text);
}
.form-group input:focus,
.form-group textarea:focus {
  outline: none;
  border-color: var(--brand);
  box-shadow: 0 0 0 3px rgba(29,78,216,.12);
}
.form-group textarea { resize: vertical; min-height: 70px; }
.form-group select,
.form-group .form-select {
  width: 100%;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 13px;
  font-family: inherit;
  color: var(--text);
  background: var(--surface);
  cursor: pointer;
}
.form-group select:focus,
.form-group .form-select:focus {
  outline: none;
  border-color: var(--brand);
  box-shadow: 0 0 0 3px rgba(29,78,216,.12);
}
.form-group .form-input {
  width: 100%;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 13px;
  font-family: inherit;
  color: var(--text);
}
.form-group .form-input:focus {
  outline: none;
  border-color: var(--brand);
  box-shadow: 0 0 0 3px rgba(29,78,216,.12);
}

/* Issued to info on items table */
.issued-to-info { color: var(--status-sent); font-weight: 500; }

/* ─── Back link ───────────────────────────────────────────────────────────── */
.back-link {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  color: var(--text-muted);
  font-size: 13px;
  margin-bottom: 16px;
  transition: color .15s;
}
.back-link:hover { color: var(--brand); text-decoration: none; }
.back-link svg { width: 16px; height: 16px; }

/* ─── Empty state ─────────────────────────────────────────────────────────── */
.empty-state {
  text-align: center;
  padding: 60px 20px;
  color: var(--text-muted);
}
.empty-state h3 { font-size: 16px; margin-bottom: 6px; color: var(--text); }
.empty-state p  { font-size: 13px; }

/* ─── Loading ─────────────────────────────────────────────────────────────── */
.loading {
  text-align: center;
  padding: 40px;
  color: var(--text-muted);
  font-size: 13px;
}

/* ─── Error banner ────────────────────────────────────────────────────────── */
.error-banner {
  background: #fee2e2;
  border: 1px solid #fca5a5;
  border-radius: var(--radius);
  padding: 12px 16px;
  color: #991b1b;
  font-size: 13px;
  margin-bottom: 16px;
}

/* ─── Linked orders section ───────────────────────────────────────────────── */
.linked-none {
  color: var(--text-muted);
  font-size: 12px;
  font-style: italic;
}

/* ─── Wide modal (item picker) ───────────────────────────────────────────── */
.modal-wide { max-width: 640px; }

.item-picker-controls {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 10px;
  font-size: 13px;
}
.item-picker-controls label {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  cursor: pointer;
  font-weight: 600;
}

.item-picker-list {
  max-height: 300px;
  overflow-y: auto;
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

.item-picker-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 12px;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  font-size: 13px;
  transition: background .1s;
}
.item-picker-row:last-child { border-bottom: none; }
.item-picker-row:hover { background: var(--brand-light); }

.item-picker-cb { flex-shrink: 0; width: 16px; height: 16px; cursor: pointer; }

.item-picker-pos {
  flex-shrink: 0;
  width: 28px;
  font-weight: 700;
  color: var(--text-muted);
  font-size: 12px;
  text-align: center;
}

.item-picker-desc {
  flex: 1;
  min-width: 0;
  overflow: hidden;
}
.item-picker-desc strong {
  display: block;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.item-picker-desc .muted {
  font-size: 11px;
  color: var(--text-muted);
}

.item-picker-qty {
  flex-shrink: 0;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-muted);
  white-space: nowrap;
}

.item-picker-qty-info {
  flex-shrink: 0;
  font-size: 11px;
  font-weight: 500;
  white-space: nowrap;
  min-width: 40px;
  text-align: right;
}

.item-picker-spinner {
  flex-shrink: 0;
  width: 60px;
  height: 30px;
  padding: 2px 6px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 13px;
  font-weight: 600;
  text-align: center;
  color: var(--text);
  background: var(--surface);
}
.item-picker-spinner:focus {
  outline: none;
  border-color: var(--brand);
  box-shadow: 0 0 0 3px rgba(29,78,216,.12);
}
/* Hide browser number spin buttons for cleaner look */
.item-picker-spinner::-webkit-inner-spin-button,
.item-picker-spinner::-webkit-outer-spin-button {
  opacity: 1;
}

.item-picker-toggle-btns {
  display: flex;
  gap: 4px;
}

/* Inline reset button for detail page items table */
.btn-reset-inline {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 22px;
  height: 22px;
  padding: 0;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text-muted);
  cursor: pointer;
  transition: background .15s, color .15s;
  margin-left: 6px;
  vertical-align: middle;
}
.btn-reset-inline:hover {
  background: #fee2e2;
  color: var(--status-problem);
  border-color: #fca5a5;
}
.btn-reset-inline svg { width: 14px; height: 14px; pointer-events: none; }

/* Inline qty reset popover */
.reset-popover {
  position: absolute;
  right: 0;
  top: 100%;
  margin-top: 4px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: 0 4px 12px rgba(0,0,0,.12);
  padding: 10px 12px;
  z-index: 50;
  white-space: nowrap;
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
}
.reset-popover input[type="number"] {
  width: 50px;
  height: 26px;
  padding: 2px 4px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 12px;
  text-align: center;
}
.reset-popover .btn { min-height: 26px; padding: 3px 8px; font-size: 11px; }

/* ─── Item dispatch badge (detail page) ──────────────────────────────────── */
.dispatch-info {
  font-size: 11px;
  color: var(--text-muted);
  margin-top: 2px;
}

/* ─── Item summary bar (detail tracking block) ───────────────────────────── */
.item-summary {
  display: flex;
  gap: 16px;
  flex-wrap: wrap;
  font-size: 13px;
  margin-top: 12px;
  padding-top: 12px;
  border-top: 1px solid var(--border);
}
.item-summary .summary-stat {
  display: flex;
  align-items: center;
  gap: 6px;
}
.item-summary .summary-stat .stat-label {
  color: var(--text-muted);
  font-size: 11px;
  text-transform: uppercase;
  font-weight: 700;
  letter-spacing: .05em;
}
.item-summary .summary-stat .stat-value {
  font-weight: 700;
  font-size: 14px;
}

/* ─── Timeline (dispatch status card) ─────────────────────────────────────── */
.timeline {
  margin-top: 16px;
  padding-top: 12px;
  border-top: 1px solid var(--border);
}
.timeline-title {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .05em;
  color: var(--text-muted);
  margin-bottom: 10px;
}

.timeline-list {
  position: relative;
  padding-left: 22px;
}
.timeline-list::before {
  content: '';
  position: absolute;
  left: 6px;
  top: 4px;
  bottom: 4px;
  width: 2px;
  background: var(--border);
}

.timeline-item {
  position: relative;
  padding-bottom: 14px;
  font-size: 12px;
  line-height: 1.5;
}
.timeline-item:last-child { padding-bottom: 0; }

.timeline-dot {
  position: absolute;
  left: -22px;
  top: 3px;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  border: 2px solid var(--border);
  background: var(--surface);
}
.timeline-dot.dot-received  { border-color: var(--status-partial); background: #dbeafe; }
.timeline-dot.dot-ready     { border-color: var(--status-ready);   background: #fef3c7; }
.timeline-dot.dot-sent      { border-color: var(--status-sent);    background: #dcfce7; }
.timeline-dot.dot-problem   { border-color: var(--status-problem); background: #fee2e2; }

.timeline-date {
  font-weight: 700;
  color: var(--text);
  margin-right: 6px;
}
.timeline-label {
  font-weight: 600;
}
.timeline-label.label-received  { color: var(--status-partial); }
.timeline-label.label-ready     { color: var(--status-ready);   }
.timeline-label.label-sent      { color: var(--status-sent);    }
.timeline-label.label-problem   { color: var(--status-problem); }

.timeline-detail {
  color: var(--text-muted);
  margin-top: 1px;
}
.timeline-detail .tl-by {
  font-weight: 500;
  color: var(--text);
}

/* ─── Dark mode toggle ───────────────────────────────────────────────────── */
.theme-toggle {
  background: transparent;
  border: 1px solid rgba(255,255,255,.4);
  border-radius: var(--radius);
  color: #fff;
  cursor: pointer;
  padding: 4px 8px;
  font-size: 16px;
  line-height: 1;
  transition: background .15s;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.theme-toggle:hover { background: rgba(255,255,255,.15); }
.theme-toggle svg { width: 18px; height: 18px; }

/* Lucide inline icon alignment */
.problem-label svg { vertical-align: -3px; width: 16px; height: 16px; }

/* ─── Multi-segment progress bar ─────────────────────────────────────────── */
.progress-bar-multi {
  flex: 1;
  height: 6px;
  background: #e5e7eb;
  border-radius: 999px;
  overflow: hidden;
  display: flex;
}
.progress-seg {
  height: 100%;
  transition: width .3s;
}
.progress-seg:first-child { border-radius: 999px 0 0 999px; }
.progress-seg:last-child  { border-radius: 0 999px 999px 0; }
.progress-seg:only-child  { border-radius: 999px; }
.progress-seg-sent     { background: var(--status-sent); }
.progress-seg-ready    { background: var(--status-ready); }
.progress-seg-received { background: var(--status-partial); }

/* Larger variant for modal */
.progress-bar-multi.progress-bar-lg { height: 10px; }

/* Progress legend (below section title) */
.progress-legend {
  display: flex;
  gap: 16px;
  font-size: 11px;
  color: var(--text-muted);
  margin-bottom: 8px;
}
.legend-item {
  display: flex;
  align-items: center;
  gap: 4px;
}
.legend-swatch {
  width: 12px;
  height: 6px;
  border-radius: 3px;
  display: inline-block;
}

/* ─── Item detail modal ─────────────────────────────────────────────────── */
.modal-detail { max-width: 560px; }

.item-detail-ident { margin-bottom: 16px; }
.item-detail-ident .item-detail-ref {
  font-size: 13px;
  color: var(--text-muted);
  margin-top: 2px;
}
.item-detail-ident .item-product {
  font-size: 15px;
  font-weight: 600;
  color: var(--text);
}
.item-detail-ident .item-dims {
  font-size: 13px;
  color: var(--text-muted);
  margin-top: 2px;
}
.item-detail-ident .item-code {
  font-size: 12px;
  color: var(--text-muted);
  font-family: 'Courier New', monospace;
  margin-top: 2px;
}

/* Quantity grid */
.item-detail-qty-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 12px;
  margin-bottom: 16px;
}
.item-detail-qty-cell { text-align: center; }
.item-detail-qty-cell .qty-label {
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .05em;
  color: var(--text-muted);
  margin-bottom: 2px;
}
.item-detail-qty-cell .qty-value {
  font-size: 18px;
  font-weight: 700;
  color: var(--text);
}

/* Tracking detail cards */
.item-detail-tracking {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  margin-top: 8px;
}
.detail-card {
  background: var(--bg);
  border-radius: var(--radius);
  padding: 12px 14px;
  font-size: 12px;
}
.detail-card .card-title {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .05em;
  margin-bottom: 8px;
}
.detail-card .card-title.title-ready { color: var(--status-ready); }
.detail-card .card-title.title-sent  { color: var(--status-sent); }
.detail-card .card-row {
  display: flex;
  justify-content: space-between;
  padding: 3px 0;
  border-bottom: 1px solid var(--border);
}
.detail-card .card-row:last-child { border-bottom: none; }
.detail-card .card-row .row-label {
  color: var(--text-muted);
  font-size: 11px;
}
.detail-card .card-row .row-value {
  color: var(--text);
  font-weight: 500;
  text-align: right;
}

/* Section dividers in modal */
.item-detail-section {
  margin-top: 16px;
  padding-top: 12px;
  border-top: 1px solid var(--border);
}
.item-detail-section-title {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .05em;
  color: var(--text-muted);
  margin-bottom: 8px;
}

/* Notes display */
.item-detail-notes {
  font-size: 13px;
  color: var(--text-muted);
  font-style: italic;
  padding: 8px 12px;
  background: var(--bg);
  border-radius: var(--radius);
}

/* Reset actions section */
.item-detail-reset {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  align-items: center;
}
.reset-inline-form {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
}
.reset-inline-form input[type="number"] {
  width: 50px;
  height: 28px;
  padding: 2px 4px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 12px;
  text-align: center;
  color: var(--text);
  background: var(--surface);
}
.reset-inline-form input[type="number"]:focus {
  outline: none;
  border-color: var(--brand);
  box-shadow: 0 0 0 3px rgba(29,78,216,.12);
}

/* ─── Dark mode: new components ─────────────────────────────────────────── */
[data-theme="dark"] .progress-bar-multi { background: #334155; }
[data-theme="dark"] .detail-card { background: #0f172a; }
[data-theme="dark"] .item-detail-notes { background: #0f172a; }

/* ─── Changelog modal ────────────────────────────────────────────────────── */
.modal-changelog { max-width: 500px; }

.changelog-modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.changelog-modal-title {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 16px;
  font-weight: 700;
}

.changelog-modal-title svg { color: var(--brand); flex-shrink: 0; }

.changelog-current-version {
  font-size: 11px;
  font-weight: 700;
  color: var(--text-muted);
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 2px 10px;
  letter-spacing: .04em;
}

.changelog-modal-body {
  max-height: 380px;
  overflow-y: auto;
  padding-top: 8px;
  padding-bottom: 8px;
}

.changelog-entry {
  padding: 14px 0;
  border-bottom: 1px solid var(--border);
}
.changelog-entry:last-child { border-bottom: none; }

.changelog-entry-latest .changelog-entry-header { margin-bottom: 10px; }

.changelog-entry-header {
  display: flex;
  align-items: baseline;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 8px;
}

.changelog-version-tag {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: .04em;
  color: var(--brand);
  background: var(--brand-light);
  border: 1px solid var(--brand);
  border-radius: 999px;
  padding: 2px 9px;
  flex-shrink: 0;
}

.changelog-entry-title {
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
}

.changelog-entry-date {
  font-size: 11px;
  color: var(--text-muted);
  margin-left: auto;
}

.changelog-change-list {
  list-style: none;
  padding: 0;
  margin: 0;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.changelog-change-list li {
  font-size: 13px;
  color: var(--text);
  padding-left: 16px;
  position: relative;
  line-height: 1.5;
}

.changelog-change-list li::before {
  content: '';
  position: absolute;
  left: 4px;
  top: 8px;
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: var(--brand);
  flex-shrink: 0;
}

[data-theme="dark"] .changelog-current-version { background: var(--surface); }
[data-theme="dark"] .changelog-version-tag { background: #1e3a5f; border-color: #3b82f6; }
[data-theme="dark"] .changelog-change-list li::before { background: var(--brand); }

/* ─── View strip / dashboard tabs (area sub-views) ────────────────────────── */
.view-strip,
.dash-tabs {
  display: flex;
  gap: 4px;
  border-bottom: 1px solid var(--border);
  margin: -8px 0 16px;
}
.view-tab,
.dash-tab {
  background: transparent;
  border: none;
  border-bottom: 2px solid transparent;
  padding: 9px 16px;
  font-size: 14px;
  font-weight: 600;
  font-family: inherit;
  color: var(--text-muted);
  cursor: pointer;
  transition: color .12s, border-color .12s;
  margin-bottom: -1px;
}
.view-tab:hover,
.dash-tab:hover { color: var(--text); text-decoration: none; }
.view-tab.active,
.dash-tab.active { color: var(--brand); border-bottom-color: var(--brand); }

.kpi-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 14px;
  margin-bottom: 20px;
}
.kpi-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 16px 18px;
}
.kpi-label {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .05em;
  color: var(--text-muted);
  margin-bottom: 6px;
}
.kpi-value {
  font-size: 24px;
  font-weight: 700;
  color: var(--text);
  line-height: 1.1;
}
.kpi-sub {
  font-size: 11px;
  color: var(--text-muted);
  margin-top: 4px;
}

/* Threshold colouring for figures (Profit/Loss, Unaccounted, etc.) */
.fig-pos { color: var(--status-sent, #16a34a) !important; }
.fig-neg { color: var(--status-problem, #dc2626) !important; }
.fig-warn { color: var(--status-ready, #d97706) !important; }

/* Stacked time + % chip inside activity table cells */
.act-time { display: block; text-align: center; }
.act-pct  {
  display: inline-block;
  margin: 3px auto 0;
  padding: 1px 7px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 600;
  line-height: 1.5;
  color: var(--brand);
  background: color-mix(in srgb, var(--brand) 12%, transparent);
}
.act-pct.fig-neg {
  color: var(--status-problem, #dc2626);
  background: color-mix(in srgb, var(--status-problem, #dc2626) 12%, transparent);
}

/* Teams summary totals table (shown above charts and at the bottom of the Summary view) */
.teams-table { width: 100%; border-collapse: collapse; }
.teams-table th, .teams-table td { padding: 8px 10px; white-space: nowrap; }
.teams-table tbody tr:hover { background: var(--bg); }
.teams-table tr.totals-row {
  border-top: 2px solid var(--border);
  font-weight: 700;
  background: var(--bg);
}
.teams-table tr.totals-row td { color: var(--text); }
.teams-table-top { margin-bottom: 22px; }

.dash-footnote {
  font-size: 11px;
  color: var(--text-muted);
  line-height: 1.6;
  margin-top: 16px;
  padding-top: 12px;
  border-top: 1px solid var(--border);
}

/* By Team — navigator strip */
.byteam-nav .btn-ghost {
  color: var(--text);
  border-color: var(--border);
  background: var(--surface);
}
.byteam-nav .btn-ghost:hover { background: var(--bg); }
.byteam-nav .btn-ghost:disabled { opacity: 0.35; cursor: default; }
.byteam-nav {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 12px 0 16px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 20px;
}
.byteam-nav-label {
  flex: 1;
  text-align: center;
  font-weight: 600;
  font-size: 15px;
}

/* Per-day block */
.byteam-day-block { margin-bottom: 24px; }
.byteam-day-heading {
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
  padding: 6px 0 4px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 0;
}

/* Entry table per day */
.byteam-entry-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}
.byteam-entry-table th {
  text-align: left;
  font-size: 11px;
  font-weight: 600;
  color: var(--text-muted);
  padding: 4px 10px;
  background: var(--bg);
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
.byteam-entry-table td {
  padding: 5px 10px;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
.byteam-entry-table th.r,
.byteam-entry-table td.r { text-align: right; }
.byteam-entry-table tr:last-child td { border-bottom: none; }
.byteam-entry-table tr:hover td { background: var(--hover-bg, var(--bg)); }

/* Day subtotal row */
.byteam-day-sub td {
  font-weight: 600;
  background: var(--surface) !important;
  border-top: 1px solid var(--border);
  color: var(--text);
}

/* Team summary card */
.byteam-summary {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px 20px;
  margin-top: 8px;
}
.byteam-summary-title {
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
  margin-bottom: 14px;
}
.byteam-summary-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  gap: 12px 20px;
}
.byteam-stat { display: flex; flex-direction: column; gap: 2px; }
.byteam-stat-label { font-size: 11px; color: var(--text-muted); text-transform: uppercase; }
.byteam-stat-value { font-size: 15px; font-weight: 600; }
.byteam-stat-value.negative { color: var(--status-problem, #dc2626); }

/* Crew size icons in entry table */
.crew-cell { display: flex; gap: 3px; align-items: center; }
.crew-icon { display: inline-flex; align-items: center; cursor: default; }
.crew-icon svg { width: 15px; height: 15px; }
.crew-leader svg { color: #1d4ed8; }
.crew-member svg { color: var(--text); }

/* Activity breakdown in period summary */
.byteam-act-breakdown { margin-top: 16px; }
.byteam-act-breakdown-title {
  font-size: 11px; font-weight: 700; text-transform: uppercase;
  letter-spacing: 0.06em; color: var(--text-muted); margin-bottom: 8px;
}
.byteam-act-row {
  display: grid; grid-template-columns: 130px 60px 50px 1fr;
  align-items: center; gap: 8px; font-size: 12px; margin-bottom: 4px;
}
.byteam-act-bar-bg { height: 6px; background: var(--border); border-radius: 3px; overflow: hidden; }
.byteam-act-bar-fill { height: 100%; border-radius: 3px; background: var(--brand); }

.chart-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 16px 18px;
  margin-bottom: 20px;
}
.chart-card-title {
  font-size: 13px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .05em;
  color: var(--text-muted);
  margin-bottom: 12px;
}
.chart-box {
  position: relative;
  height: 280px;
}
.chart-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 20px;
}
.chart-row .chart-card { margin-bottom: 20px; }

/* ─── Responsive tweaks ───────────────────────────────────────────────────── */
@media (max-width: 768px) {
  .chart-row { grid-template-columns: 1fr; }
  .view-tab,
  .dash-tab { padding: 9px 12px; font-size: 13px; }
  .main-content { padding: 12px; }
  .filter-bar { flex-direction: column; align-items: stretch; }
  .filter-actions { margin-left: 0; }
  .app-header h1 { font-size: 15px; }
  .detail-grid { grid-template-columns: 1fr 1fr; }
  .item-detail-tracking { grid-template-columns: 1fr; }
  .item-detail-qty-grid { grid-template-columns: repeat(2, 1fr); }

  /* Off-canvas sidebar drawer on mobile */
  .btn-sidebar { display: inline-flex; }
  .sidebar {
    position: fixed;
    left: 0;
    top: 0;
    height: 100vh;
    width: 232px;
    transform: translateX(-100%);
    transition: transform .2s ease;
    z-index: 300;
  }
  .app-shell.sidebar-collapsed .sidebar { width: 232px; }
  .app-shell.sidebar-collapsed .sidebar-link-text,
  .app-shell.sidebar-collapsed .sidebar-brand-text { display: inline; }
  .app-shell.sidebar-mobile-open .sidebar { transform: translateX(0); }
  .app-shell.sidebar-mobile-open::before {
    content: '';
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,.45);
    z-index: 250;
  }
  /* Hide the in-sidebar collapse button on mobile (drawer is full-width) */
  .sidebar-collapse-btn { display: none; }
}

/* ─── Login overlay ─────────────────────────────────────────────────────────── */

.login-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.65);
  z-index: 9000;
  display: flex;
  align-items: center;
  justify-content: center;
}

.login-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  box-shadow: 0 8px 40px rgba(0,0,0,.25);
  padding: 36px 40px 32px;
  width: 340px;
  max-width: calc(100vw - 32px);
}

.login-card-logo {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 24px;
}

.login-card-logo svg { color: var(--brand); }

.login-card-title {
  font-size: 18px;
  font-weight: 700;
  color: var(--text);
}

.login-card-subtitle {
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 2px;
}

.login-error {
  background: #fee2e2;
  color: #b91c1c;
  border-radius: 6px;
  padding: 8px 12px;
  font-size: 13px;
  margin-bottom: 12px;
  display: none;
}

[data-theme="dark"] .login-error {
  background: rgba(185,28,28,.2);
  color: #fca5a5;
}

/* ─── User badge ─────────────────────────────────────────────────────────────── */

.user-badge {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-muted);
  padding: 4px 10px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  white-space: nowrap;
}

/* ─── Toggle switch ──────────────────────────────────────────────────────────── */

.toggle {
  position: relative;
  display: inline-block;
  width: 38px;
  height: 22px;
  flex-shrink: 0;
}

.toggle input { opacity: 0; width: 0; height: 0; }

.toggle-slider {
  position: absolute;
  inset: 0;
  background: var(--border);
  border-radius: 22px;
  cursor: pointer;
  transition: background .2s;
}

.toggle-slider::before {
  content: '';
  position: absolute;
  width: 16px;
  height: 16px;
  left: 3px;
  top: 3px;
  background: #fff;
  border-radius: 50%;
  transition: transform .2s;
  box-shadow: 0 1px 3px rgba(0,0,0,.2);
}

.toggle input:checked + .toggle-slider { background: var(--brand); }
.toggle input:checked + .toggle-slider::before { transform: translateX(16px); }
.toggle input:disabled + .toggle-slider { opacity: .5; cursor: not-allowed; }

/* ─── Admin panel ────────────────────────────────────────────────────────────── */

.admin-section {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  margin-bottom: 20px;
  overflow: hidden;
}

.admin-section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
}

.admin-section-title {
  font-size: 15px;
  font-weight: 700;
  color: var(--text);
}

.admin-user-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

.admin-user-table th {
  padding: 10px 16px;
  text-align: left;
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .05em;
  color: var(--text-muted);
  background: var(--bg);
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}

.admin-user-table td {
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}

.admin-user-table tr:last-child td { border-bottom: none; }
.admin-user-table tr:hover td { background: var(--bg); }

.admin-user-name {
  font-weight: 600;
  color: var(--text);
}

.admin-user-gp-id {
  font-size: 11px;
  color: var(--text-muted);
  margin-top: 2px;
}

.admin-empty {
  padding: 40px 20px;
  text-align: center;
  color: var(--text-muted);
  font-size: 14px;
}

/* GlassPro sync modal */
.gp-user-list {
  max-height: 360px;
  overflow-y: auto;
  border: 1px solid var(--border);
  border-radius: 6px;
  margin-top: 8px;
}

.gp-user-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
  font-size: 13px;
}

.gp-user-row:last-child { border-bottom: none; }
.gp-user-row.already-imported { opacity: .55; }

.gp-user-row input[type="checkbox"] {
  width: 16px;
  height: 16px;
  cursor: pointer;
  flex-shrink: 0;
}

.gp-user-row-name { flex: 1; font-weight: 500; color: var(--text); }
.gp-user-row-meta { font-size: 11px; color: var(--text-muted); }
.gp-user-row-badge {
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .04em;
  color: var(--status-sent);
  background: rgba(22,163,74,.1);
  padding: 2px 7px;
  border-radius: 10px;
}

.sync-options {
  display: flex;
  gap: 16px;
  margin-top: 10px;
}

.sync-option-label {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  color: var(--text-muted);
  cursor: pointer;
}

/* ═══════════════════════════════════════════════════════════════════════════
   STOCK ISSUES
   ═══════════════════════════════════════════════════════════════════════════ */

.mono { font-family: 'Courier New', monospace; }
.muted { color: var(--text-muted); }

.page-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 16px; }
.page-title { font-size: 20px; font-weight: 700; }

/* Issue type & status badges */
.badge-draft { background: #f3f4f6; color: #6b7280; border: 1px solid #d1d5db; }
[data-theme="dark"] .badge-draft { background: #1f2937; color: #9ca3af; border-color: #374151; }
/* Issue lifecycle: Plan (grey) → Printed (blue) → Sent (green, reuses .badge-sent) */
.badge-plan    { background: #f3f4f6; color: #6b7280; border: 1px solid #d1d5db; }
.badge-printed { background: #dbeafe; color: #2563eb; border: 1px solid #93c5fd; }
[data-theme="dark"] .badge-plan    { background: #1f2937; color: #9ca3af; border-color: #374151; }
[data-theme="dark"] .badge-printed { background: #0c2d6b; color: #93c5fd; border-color: #1e40af; }

/* Clickable in-table cell link (e.g. Issues → Sales Order) */
.cell-link { color: var(--brand); text-decoration: none; }
.cell-link:hover { text-decoration: underline; }
.badge-type-project     { background: #eef2ff; color: #4338ca; border: 1px solid #c7d2fe; }
.badge-type-residential { background: #ecfeff; color: #0e7490; border: 1px solid #a5f3fc; }
.badge-type-other       { background: #f5f3ff; color: #6d28d9; border: 1px solid #ddd6fe; }
[data-theme="dark"] .badge-type-project     { background: #1e1b4b; color: #a5b4fc; border-color: #3730a3; }
[data-theme="dark"] .badge-type-residential { background: #083344; color: #67e8f9; border-color: #155e75; }
[data-theme="dark"] .badge-type-other       { background: #2e1065; color: #c4b5fd; border-color: #5b21b6; }

/* Inline form inputs (outside .form-group) */
.form-input, .form-select {
  width: 100%; padding: 8px 10px; font-size: 13px;
  border: 1px solid var(--border); border-radius: var(--radius, 6px);
  background: var(--surface); color: var(--text);
}
.form-input:focus, .form-select:focus { outline: none; border-color: var(--brand); }

/* Capture form */
.capture-form { display: grid; grid-template-columns: repeat(3, 1fr); gap: 14px; }
.capture-form .form-group { display: flex; flex-direction: column; gap: 4px; }
.capture-form .form-group label { font-size: 12px; font-weight: 600; color: var(--text-muted); }
.form-group-wide { grid-column: 1 / -1; }
.capture-form textarea.form-input { min-height: 46px; resize: vertical; }

.type-toggle { display: inline-flex; align-self: flex-start; width: fit-content; border: 1px solid var(--border); border-radius: var(--radius, 6px); overflow: hidden; }
.type-btn { padding: 8px 16px; background: var(--surface); color: var(--text); border: none; border-right: 1px solid var(--border); cursor: pointer; font-size: 13px; transition: background .12s; }
.type-btn:last-child { border-right: none; }
.type-btn:not(.active):hover { background: var(--bg); }
.type-btn.active { background: var(--brand); color: #fff; }

/* Two-panel capture layout */
.capture-panels { display: grid; grid-template-columns: 1fr 1.15fr; gap: 16px; align-items: start; }
.capture-source, .capture-lines { display: flex; flex-direction: column; }

/* Source tabs (PO / Stock) */
.source-tabs { display: flex; gap: 2px; padding: 0 8px; border-bottom: 1px solid var(--border); }
.source-tab { appearance: none; background: transparent; border: none; border-bottom: 2px solid transparent; margin-bottom: -1px; padding: 11px 16px; font-size: 13px; font-weight: 600; color: var(--text-muted); cursor: pointer; transition: color .12s; }
.source-tab .muted { font-weight: 500; }
.source-tab:hover { color: var(--text); }
.source-tab.active { color: var(--brand); border-bottom-color: var(--brand); }
.source-pane[hidden] { display: none; }

.source-search { padding: 12px 16px 0; position: relative; }
.source-filters { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; padding: 12px 16px; }
.source-filters .check-inline { grid-column: 1 / -1; display: flex; align-items: center; gap: 6px; font-size: 13px; color: var(--text-muted); }
.source-list { max-height: 460px; min-height: 120px; overflow-y: auto; overflow-x: hidden; border-top: 1px solid var(--border); }
.source-list .source-table td { word-break: break-word; }
.source-hint { padding: 16px; }

/* Issue lines panel */
.capture-lines-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.lines-meta { font-size: 12px; color: var(--text-muted); white-space: nowrap; }
.lines-empty { text-align: center; padding: 44px 20px; color: var(--text-muted); font-size: 13px; }
.lines-empty-icon { font-size: 22px; margin-bottom: 6px; }
.source-table, .capture-lines table { width: 100%; border-collapse: collapse; font-size: 13px; }
.source-table th, .source-table td { padding: 6px 10px; text-align: left; border-bottom: 1px solid var(--border); vertical-align: top; }
.source-table th { position: sticky; top: 0; background: var(--surface); font-size: 11px; text-transform: uppercase; color: var(--text-muted); }

/* Stacked description cell — each line truncated to a single line with ellipsis.
   max-width:0 on the cell (with width:100% tables) lets the column flex and clamp. */
.desc-cell { max-width: 0; width: 100%; }
.desc-stack { min-width: 0; }
.desc-line { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 100%; }
.desc-main { color: var(--text); }
.desc-sub { font-size: 11px; color: var(--text-muted); line-height: 1.4; }
/* code column: single line, capped width so it can't steal the description's space */
.source-table td.mono, .capture-lines td.mono, .issue-items-card td.mono {
  white-space: nowrap; max-width: 130px; overflow: hidden; text-overflow: ellipsis;
}
/* PO selector cells: single line, truncated (keeps PO rows compact → ≥3 visible) */
.po-sel-supplier { max-width: 0; width: 100%; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.po-sel-ref { max-width: 130px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* Search-as-you-type dropdowns */
.search-results { position: absolute; left: 16px; right: 16px; z-index: 30; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius, 6px); box-shadow: var(--shadow, 0 4px 16px rgba(0,0,0,.12)); max-height: 280px; overflow-y: auto; }
.search-row { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 8px 12px; border-bottom: 1px solid var(--border); cursor: pointer; font-size: 13px; }
.search-row:last-child { border-bottom: none; }
.search-row:hover { background: var(--brand-light); }

/* Qty stepper (− [input] +), value centered */
.qty-stepper { display: inline-flex; align-items: stretch; border: 1px solid var(--border); border-radius: 6px; overflow: hidden; background: var(--surface); }
.qty-btn { width: 26px; border: none; background: var(--bg); color: var(--text); font-size: 15px; font-weight: 600; line-height: 1; cursor: pointer; padding: 0; }
.qty-btn:hover { background: var(--border); }
.qty-btn:first-child { border-right: 1px solid var(--border); }
.qty-btn:last-child { border-left: 1px solid var(--border); }
.qty-stepper .qty-input { width: 48px; border: none; border-radius: 0; text-align: center; font-weight: 600; background: var(--surface); color: var(--text); padding: 5px 2px; -moz-appearance: textfield; }
.qty-stepper .qty-input::-webkit-inner-spin-button, .qty-stepper .qty-input::-webkit-outer-spin-button { -webkit-appearance: none; margin: 0; }
.qty-input:focus { outline: none; }
.qty-cap-row { text-align: center; }
.qty-cap { font-size: 11px; color: var(--text-muted); }

.issue-actions { display: flex; flex-wrap: wrap; gap: 8px; padding: 16px 0 0; margin-top: 16px; border-top: 1px solid var(--border); justify-content: flex-end; }

.item-desc-code { display: block; font-size: 11px; font-family: 'Courier New', monospace; color: var(--text-muted); }

/* Issued-via cross reference chips */
.issued-via-list { display: flex; flex-wrap: wrap; gap: 6px; }
.issued-via-chip { text-decoration: none; }
.issued-via-chip:hover { text-decoration: none; opacity: .85; }

/* ── Issue slip: compact header ──────────────────────────────────────────── */
.issue-head { margin-bottom: 4px; }
.issue-head .back-link { margin-bottom: 10px; }
.issue-head-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.issue-head-title { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.issue-head-title .page-title { font-size: 22px; }
.issue-head-sub { font-size: 13px; color: var(--text-muted); margin-top: 4px; }
.issue-divider { height: 1px; background: var(--border); margin: 14px 0 18px; }

/* Inline form row (Type / Project-SO / Team / Date) */
.inline-form { display: flex; flex-wrap: wrap; gap: 18px 24px; align-items: flex-start; margin-bottom: 20px; }
.inline-field { display: flex; flex-direction: column; gap: 5px; min-width: 150px; }
.inline-field > label { font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: .04em; color: var(--text-muted); }
.inline-field-grow { flex: 1 1 280px; }
.inline-field .form-input, .inline-field .form-select { min-width: 160px; }
.inline-field-grow .form-input, .inline-field-grow .form-select, .inline-field-grow #link-control { width: 100%; }
.inline-form-readonly .inline-field .value { font-size: 14px; font-weight: 500; color: var(--text); padding-top: 2px; }
.so-combo { position: relative; }

/* Notes block (bottom of the slip) */
.notes-block { margin-top: 18px; display: flex; flex-direction: column; gap: 6px; }
.notes-block > label { font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: .04em; color: var(--text-muted); }
.notes-block textarea.form-input { min-height: 60px; resize: vertical; }
.notes-block .value { font-size: 14px; color: var(--text); white-space: pre-wrap; }

/* PO pane: two distinct boxes — PO list (top) + selected PO's items (bottom) */
.po-pane { display: flex; flex-direction: column; gap: 12px; padding: 12px; }
.po-box { border: 1px solid var(--border); border-radius: var(--radius, 6px); background: var(--surface); overflow: hidden; }
.po-box-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 8px 12px; background: var(--bg); border-bottom: 1px solid var(--border); font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: .04em; color: var(--text-muted); }
.po-box-head-ref { text-transform: none; letter-spacing: 0; color: var(--brand); font-weight: 700; }
.po-box-filters { display: flex; flex-wrap: wrap; gap: 8px; padding: 10px 12px; border-bottom: 1px solid var(--border); }
.po-box-filters .form-input, .po-box-filters .form-select { flex: 1 1 140px; min-width: 110px; }
.po-box-filters .check-inline { flex-basis: 100%; display: flex; align-items: center; gap: 6px; font-size: 13px; color: var(--text-muted); }
.po-selector { max-height: 196px; overflow-y: auto; overflow-x: hidden; }
.po-items { max-height: 300px; overflow-y: auto; overflow-x: hidden; }
.po-num { color: var(--brand); font-weight: 700; }
.po-row { cursor: pointer; }
.po-row:hover { background: var(--brand-light); }
.po-row.selected { background: var(--brand-light); box-shadow: inset 3px 0 0 var(--brand); }
.po-item-depleted { opacity: .45; }

/* Searchable SO combobox (residential issues) */
.combo-results { position: absolute; top: calc(100% + 4px); left: 0; right: 0; z-index: 40; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius, 6px); box-shadow: var(--shadow, 0 4px 16px rgba(0,0,0,.12)); max-height: 300px; overflow-y: auto; }
.combo-results[hidden] { display: none; }
.combo-row { display: flex; flex-direction: column; gap: 2px; padding: 8px 12px; border-bottom: 1px solid var(--border); cursor: pointer; font-size: 13px; }
.combo-row:last-child { border-bottom: none; }
.combo-row:hover { background: var(--brand-light); }
.combo-sub { font-size: 11px; color: var(--text-muted); }

/* Generic combobox container (Project / Team / Supplier) */
.combo { position: relative; width: 100%; }
.combo > .form-input { width: 100%; }
.po-box-filters .combo { flex: 1 1 140px; min-width: 110px; }

/* Dropdown caret on combo-style boxes (matches the Issue Edit interface).
   Standalone free-text Search inputs are intentionally left without a caret. */
.combo::after,
.so-combo::after {
  content: "";
  position: absolute;
  right: 12px;
  top: 50%;
  width: 7px;
  height: 7px;
  border-right: 2px solid var(--text-muted);
  border-bottom: 2px solid var(--text-muted);
  transform: translateY(-65%) rotate(45deg);
  pointer-events: none;
}
.combo > .form-input,
.so-combo > .form-input { padding-right: 28px; }

/* Filter-bar combobox (native <select> replacement) — match filter sizing.
   The .filter-group input[type="text"] rule (200/220px, higher specificity than
   .combo > .form-input) would otherwise size the combo input past its wrapper and
   overlap the next group — so pin the input to the wrapper width explicitly. */
.filter-group .filter-combo { width: 200px; }
.filter-group .filter-combo .combo-input {
  width: 100%;
  height: 36px;
  box-sizing: border-box;
}

/* Issued-by tag on the capture header (far right) */
.issue-head-right { font-size: 13px; color: var(--text-muted); white-space: nowrap; }
.issue-head-right strong { color: var(--text); }

/* Small segmented toggle (Linked / All) */
.mini-toggle { display: inline-flex; border: 1px solid var(--border); border-radius: 6px; overflow: hidden; }
.mini-toggle button { border: none; background: var(--surface); color: var(--text-muted); font-size: 11px; font-weight: 600; padding: 3px 12px; cursor: pointer; line-height: 1.7; }
.mini-toggle button + button { border-left: 1px solid var(--border); }
.mini-toggle button.active { background: var(--brand); color: #fff; }

/* ── Issue detail: comfortable fixed-height panels; page scrolls; floating actions ──
   The panels get a stable, roomy height (capped so they never feel cramped and
   never grow absurdly). The page scrolls normally if the viewport is short, and
   the action bar floats (sticky) so Save / Print / Mark as Sent stay reachable. */
.shell-fixed .capture-panels {
  height: clamp(560px, calc(100vh - 280px), 720px);
  grid-template-rows: minmax(0, 1fr);
  align-items: stretch;
}
.shell-fixed .capture-source,
.shell-fixed .capture-lines { height: 100%; min-height: 0; overflow: hidden; }
.shell-fixed .capture-source .source-tabs { flex: none; }
.shell-fixed .source-pane { flex: 1; min-height: 0; overflow: hidden; }
.shell-fixed .capture-lines .table-wrap { flex: 1; min-height: 0; overflow: auto; }

/* PO pane: the two boxes share the height; both scroll internally */
.shell-fixed .po-pane { flex: 1; min-height: 0; }
.shell-fixed .po-pane .po-box { display: flex; flex-direction: column; min-height: 0; }
.shell-fixed .po-pane .po-box:first-child { flex: 1 1 0; }   /* PO list */
.shell-fixed .po-pane .po-box:last-child  { flex: 1.4 1 0; } /* Line items (a bit taller) */
.shell-fixed #pane-stock .po-box { flex: 1; }
/* Guarantee at least ~3 rows in both the PO list and items. PO rows are single
   line; item rows carry the stacked description, so they get a taller minimum. */
.shell-fixed .po-selector { max-height: none; flex: 1; min-height: 134px; }
.shell-fixed .po-items { max-height: none; flex: 1; min-height: 168px; }
.shell-fixed #stock-list { max-height: none; flex: 1; min-height: 0; }

/* View mode: items card gets the same comfortable height */
.shell-fixed .issue-items-card {
  height: clamp(380px, calc(100vh - 360px), 660px);
  min-height: 0; display: flex; flex-direction: column;
}
.shell-fixed .issue-items-card .table-wrap { flex: 1; min-height: 0; overflow: auto; }

/* Floating action bar — sticks to the viewport bottom, spans the content width */
.shell-fixed .issue-actions {
  position: sticky;
  bottom: 0;
  margin: 16px -24px 0;
  padding: 14px 24px;
  background: var(--bg);
  border-top: 1px solid var(--border);
  box-shadow: 0 -4px 12px rgba(0,0,0,.06);
  z-index: 30;
}
[data-theme="dark"] .shell-fixed .issue-actions { box-shadow: 0 -4px 12px rgba(0,0,0,.3); }

@media print {
  .shell-fixed .issue-actions { position: static; border-top: none; box-shadow: none; }
}
/* Short or narrow: let everything flow and scroll the page instead */
@media (max-width: 900px), (max-height: 520px) {
  .shell-fixed .capture-panels { height: auto; grid-template-rows: none; }
  .shell-fixed .capture-source, .shell-fixed .capture-lines { height: auto; overflow: visible; }
  .shell-fixed .po-selector { max-height: 220px; }
  .shell-fixed .po-items, .shell-fixed #stock-list { max-height: 340px; flex: none; }
  .shell-fixed .issue-items-card { height: auto; }
}

/* Add button (PO / stock source rows) */
.btn-icon-add { background: var(--brand-light); color: var(--brand); border-color: var(--brand); font-size: 15px; font-weight: 700; line-height: 1; }
.btn-icon-add:hover:not(:disabled) { background: var(--brand); color: #fff; }

@media (max-width: 900px) {
  .capture-form { grid-template-columns: 1fr; }
  .capture-panels { grid-template-columns: 1fr; }
  .inline-field, .inline-field-grow { flex: 1 1 100%; }
}

/* ── Print: issue sheet only ───────────────────────────────────────────────── */
.print-only { display: none; }
@media print {
  body * { visibility: hidden; }
  #print-sheet, #print-sheet * { visibility: visible; }
  #print-sheet { display: block; position: absolute; left: 0; top: 0; width: 100%; padding: 0; color: #000; }
  .no-print { display: none !important; }
}
/* Document body styles (.doc-*) now live in css/print.css (loaded on printable pages). */
