/* ============================================================================
   Admin panel — extends styles.css + portal.css with a sidebar layout
   ============================================================================ */

.admin-body { padding-bottom: 0; min-height: 100vh; }

.admin-topbar {
  background: rgba(15, 23, 42, 0.92) !important;
  border-bottom: 1px solid rgba(201, 145, 60, 0.35);
}
.admin-topbar .brand-name,
.admin-topbar .user-name { color: #f4f1e8 !important; }
.admin-topbar .user-firm,
.admin-topbar .brand-motto { color: rgba(244, 241, 232, 0.75) !important; }
.admin-topbar .logout-btn {
  color: #f4f1e8;
  border-color: rgba(244, 241, 232, 0.25);
}
.admin-topbar .logout-btn:hover {
  background: rgba(196, 74, 74, 0.22);
  color: #fff;
  border-color: rgba(196, 74, 74, 0.6);
}
.admin-avatar {
  background: linear-gradient(180deg, #d4a64a, #b8821f) !important;
}

/* Lock the dashboard viewport so the sidebar can never scroll away —
   only the main pane scrolls. */
body.admin-app { height: 100vh; overflow: hidden; }

/* Shell — sidebar + main */
.admin-shell {
  display: grid;
  grid-template-columns: 230px 1fr;
  height: 100vh;
  max-width: 1480px;
  margin: 0 auto;
}

/* Right column: fixed topbar + the only scrolling region */
.admin-col {
  min-width: 0;
  min-height: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

/* Sidebar — full-height fixed column (brand pinned at top, never scrolls away) */
.admin-sidebar {
  background: rgb(var(--glass-rgb) / 0.55);
  backdrop-filter: blur(20px) saturate(160%);
  -webkit-backdrop-filter: blur(20px) saturate(160%);
  border-right: 1px solid var(--line);
  padding: 14px 11px;
  position: relative;
  height: 100vh;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
}

/* Brand at the top of the sidebar */
.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 9px;
  text-decoration: none;
  padding: 2px 5px 11px;
  margin-bottom: 5px;
  border-bottom: 1px solid var(--line);
}
.sidebar-brand img { width: 28px; height: 28px; flex: none; }
.sidebar-brand .brand-name { color: var(--ink); font-weight: 800; font-size: 16px; line-height: 1.1; letter-spacing: -0.01em; }
.sidebar-brand .brand-motto { color: #c9913c; font-size: 10px; letter-spacing: 1.5px; text-transform: uppercase; }
.sidebar-section { margin-bottom: 11px; }
.sidebar-label {
  font-size: 9.5px;
  font-weight: 700;
  letter-spacing: 1.5px;
  text-transform: uppercase;
  color: var(--muted);
  padding: 0 11px 4px;
}
.sidebar-item {
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 6px 11px;
  margin: 1px 0;
  border-radius: 9px;
  color: var(--ink-2);
  text-decoration: none;
  font-size: 13px;
  font-weight: 500;
  transition: background 0.15s, color 0.15s;
}
.sidebar-item:hover {
  background: rgba(58, 109, 181, 0.1);
  color: var(--primary);
  text-decoration: none;
}
.sidebar-item.active {
  background: linear-gradient(180deg, var(--primary-2), var(--primary));
  color: #fff;
  box-shadow: inset 0 1px 0 rgb(var(--glass-rgb) / 0.3), 0 4px 10px rgba(58,109,181,0.3);
}
.sidebar-item .si-icon {
  width: 19px;
  height: 19px;
  display: inline-grid;
  place-items: center;
  font-size: 12px;
  font-weight: 700;
  border-radius: 6px;
  background: rgba(15, 23, 42, 0.06);
}
.sidebar-item.active .si-icon {
  background: rgb(var(--glass-rgb) / 0.18);
  color: #fff;
}
.sidebar-foot {
  margin-top: auto;
  padding: 10px 11px;
  font-size: 10px;
  color: var(--muted);
  letter-spacing: 1px;
  text-transform: uppercase;
}

/* Main */
.admin-main {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: 0 32px 60px;
  min-width: 0;
}

.admin-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  gap: 24px;
  flex-wrap: wrap;
  /* Pinned section header: stays put while the rows below scroll. The negative
     margins pull it over .admin-main's padding so its background spans edge-to-edge. */
  position: sticky;
  top: 0;
  z-index: 20;
  background: var(--bg-base);
  margin: 0 -32px 16px;
  padding: 13px 32px 11px;
  border-bottom: 1px solid var(--line);
}
.admin-kicker {
  color: var(--primary);
  font-size: 9px;
  font-weight: 700;
  letter-spacing: 2.5px;
  text-transform: uppercase;
  margin-bottom: 1px;
}
.admin-head h1 {
  margin: 0;
  font-size: 18px;
  font-weight: 700;
  letter-spacing: -0.015em;
  color: var(--ink);
}
.admin-head-actions {
  display: flex;
  gap: 10px;
  align-items: center;
  flex-wrap: wrap;
}
.admin-select,
.admin-search {
  font: inherit;
  padding: 9px 13px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: rgb(var(--glass-rgb) / 0.85);
  font-size: 13px;
  color: var(--ink);
  outline: none;
  transition: border-color 0.2s, box-shadow 0.2s;
}
.admin-search { min-width: 260px; }
.admin-select:focus,
.admin-search:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(58,109,181,0.15);
}

.admin-section { animation: row-in 0.35s var(--ease-out); }

.admin-help {
  margin: 0 0 16px;
  font-size: 13px;
  color: var(--muted);
  line-height: 1.55;
}

/* KPI grid */
.kpi-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 14px;
  margin-bottom: 24px;
}
.kpi-grid:has(.kpi-card:nth-child(6)) { grid-template-columns: repeat(3, 1fr); }
.kpi-grid.kpi-grid-3 { grid-template-columns: repeat(3, 1fr); }

.kpi-card {
  background: var(--glass);
  backdrop-filter: blur(22px) saturate(170%);
  -webkit-backdrop-filter: blur(22px) saturate(170%);
  border: 1px solid var(--glass-border);
  border-radius: 16px;
  padding: 18px 20px;
  box-shadow: inset 0 1px 0 var(--glass-edge), var(--shadow-sm);
}
.kpi-label {
  font-size: 9.5px;
  letter-spacing: 1.5px;
  text-transform: uppercase;
  color: var(--muted);
  font-weight: 700;
}
.kpi-value {
  font-size: 22px;
  font-weight: 700;
  color: var(--ink);
  margin: 6px 0 3px;
  letter-spacing: -0.025em;
  font-variant-numeric: tabular-nums;
}
.kpi-value.danger { color: var(--danger); }
.kpi-value.ok { color: var(--ok); }
.kpi-foot { font-size: 10.5px; color: var(--muted); }
.kpi-foot.up { color: var(--ok); font-weight: 600; }
.kpi-foot.down { color: var(--danger); font-weight: 600; }

/* Two-up grid */
.admin-grid-2 {
  display: grid;
  grid-template-columns: 1.4fr 1fr;
  gap: 20px;
  margin-bottom: 20px;
}

/* Top list */
.top-list {
  list-style: none;
  padding: 0;
  margin: 0;
  counter-reset: top-counter;
}
.top-list li {
  display: grid;
  grid-template-columns: 32px 1fr auto;
  gap: 12px;
  align-items: center;
  padding: 10px 0;
  border-bottom: 1px solid var(--line-soft);
  counter-increment: top-counter;
}
.top-list li:last-child { border-bottom: 0; }
.top-list li::before {
  content: counter(top-counter);
  font-weight: 700;
  color: var(--muted);
  font-size: 13px;
  text-align: center;
  background: rgba(15, 23, 42, 0.06);
  border-radius: 8px;
  padding: 4px 0;
  font-variant-numeric: tabular-nums;
}
.top-list .tl-name { font-weight: 600; color: var(--ink); font-size: 14px; }
.top-list .tl-sub { font-size: 11px; color: var(--muted); margin-top: 2px; }
.top-list .tl-value { font-weight: 700; color: var(--primary); font-size: 14px; font-variant-numeric: tabular-nums; }

/* Sparkline / bar charts (SVG, inline) */
.chart-bars {
  display: flex;
  align-items: flex-end;
  height: 180px;
  gap: 2px;
  padding: 12px 0;
}
.chart-bar {
  flex: 1;
  background: linear-gradient(180deg, var(--primary-2), var(--primary));
  border-radius: 3px 3px 0 0;
  min-height: 2px;
  position: relative;
  transition: opacity 0.2s;
}
.chart-bar:hover { opacity: 0.85; }
.chart-bar[data-value="0"] { background: rgba(15, 23, 42, 0.08); }
.chart-bar::after {
  content: attr(data-tooltip);
  position: absolute;
  bottom: 100%;
  left: 50%;
  transform: translateX(-50%) translateY(-6px);
  background: var(--ink);
  color: #fff;
  font-size: 11px;
  padding: 4px 8px;
  border-radius: 6px;
  white-space: nowrap;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.15s;
  font-variant-numeric: tabular-nums;
}
.chart-bar:hover::after { opacity: 1; }
.chart-axis {
  display: flex;
  justify-content: space-between;
  font-size: 10px;
  color: var(--muted);
  border-top: 1px solid var(--line);
  padding-top: 6px;
  letter-spacing: 0.5px;
}

/* Service breakdown bars */
.breakdown-bar {
  margin-bottom: 14px;
}
.breakdown-bar .bb-row {
  display: flex;
  justify-content: space-between;
  font-size: 13px;
  margin-bottom: 4px;
}
.breakdown-bar .bb-name { color: var(--ink-2); font-weight: 600; }
.breakdown-bar .bb-value { color: var(--primary); font-weight: 700; font-variant-numeric: tabular-nums; }
.breakdown-bar .bb-track {
  height: 8px;
  background: rgba(15, 23, 42, 0.06);
  border-radius: 999px;
  overflow: hidden;
}
.breakdown-bar .bb-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--primary-2), var(--primary));
  border-radius: 999px;
}

/* Placeholder panel (e.g., drivers section) */
.placeholder-panel {
  text-align: center;
  padding: 50px 32px;
}
.placeholder-panel .placeholder-icon {
  font-size: 40px;
  color: var(--primary);
  margin-bottom: 14px;
}
.placeholder-panel h2 {
  margin: 0 0 10px;
}
.placeholder-panel p {
  color: var(--muted);
  max-width: 540px;
  margin: 0 auto 12px;
  font-size: 14px;
}

/* Settings */
.settings-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 18px;
  margin-bottom: 16px;
}

.danger-panel {
  border-color: rgba(196, 74, 74, 0.3);
  background: linear-gradient(180deg, rgba(196, 74, 74, 0.06), rgb(var(--glass-rgb) / 0.55));
}
.danger-btn {
  background: var(--danger);
  color: #fff;
  border: 0;
  font-weight: 700;
  font-size: 13px;
  padding: 11px 18px;
  border-radius: 10px;
  cursor: pointer;
  letter-spacing: 0.02em;
  box-shadow: 0 6px 14px rgba(196, 74, 74, 0.35);
  transition: transform 0.15s, box-shadow 0.2s;
}
.danger-btn:hover { transform: translateY(-1px); box-shadow: 0 10px 20px rgba(196, 74, 74, 0.42); }
.danger-btn:active { transform: translateY(1px); }

/* Status pill — extend portal.css */
.status-pill.signed-up { background: rgba(58, 109, 181, 0.10); color: var(--primary); }

/* Responsive */
@media (max-width: 1100px) {
  .admin-grid-2 { grid-template-columns: 1fr; }
  .kpi-grid { grid-template-columns: 1fr 1fr; }
}
@media (max-width: 900px) {
  /* Phone/tablet: horizontal menu — revert to normal page scroll, no viewport lock */
  body.admin-app { height: auto; overflow: visible; }
  .admin-shell { grid-template-columns: 1fr; height: auto; }
  .admin-col { overflow: visible; }
  .admin-main { overflow: visible; min-height: auto; }
  .admin-sidebar {
    position: static;
    height: auto;
    flex-direction: row;
    flex-wrap: wrap;
    overflow-x: auto;
    border-right: 0;
    border-bottom: 1px solid var(--line);
    padding: 12px;
    gap: 4px;
  }
  .sidebar-brand { flex-basis: 100%; border-bottom: 0; padding: 2px 4px 6px; margin-bottom: 4px; }
  .sidebar-section { display: flex; margin: 0; gap: 4px; }
  .sidebar-label { display: none; }
  .sidebar-item { white-space: nowrap; padding: 8px 12px; font-size: 13px; }
  .sidebar-foot { display: none; }
  .admin-main { padding: 24px 20px 60px; }
  .kpi-grid, .kpi-grid.kpi-grid-3 { grid-template-columns: 1fr; }
  .settings-grid { grid-template-columns: 1fr; }
  .admin-search { min-width: 0; width: 100%; }
}

/* ============================================================================
   Client detail sheet (rolodex)
   ============================================================================ */
.kpi-grid.kpi-grid-5 { grid-template-columns: repeat(5, 1fr); }

/* Clickable client rows */
.data-table tr.row-click { cursor: pointer; transition: background .12s ease; }
.data-table tr.row-click:hover { background: var(--primary-soft, rgba(58,109,181,0.06)); }
.data-table tr.row-click:focus-visible { outline: 2px solid var(--primary); outline-offset: -2px; }

/* Compact rows — smaller per-line text for the admin Deliveries table only
   (scoped class so it never shrinks the client portal's shared .data-table). */
.data-table--compact { font-size: 13px; }
.data-table--compact .tracking { font-size: 11px; }
.data-table--compact .service-cell { font-size: 11px; }
.data-table--compact .route-cell { font-size: 12px; }
.data-table--compact .firm-contact,
.data-table--compact .route-to { font-size: 11px; }
.data-table--compact .status-pill { font-size: 9.5px; padding: 3px 8px; letter-spacing: 0.3px; }
.data-table--compact .row-btn { font-size: 11px; padding: 5px 10px; }

.cd-back {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  margin-top: 16px;       /* .admin-main no longer pads the top — restore space for the detail view */
  color: var(--primary);
  text-decoration: none;
  font-weight: 600;
  font-size: 14px;
}
.cd-back:hover { text-decoration: underline; }

/* Header card */
.cd-header {
  display: flex;
  align-items: center;
  gap: 20px;
}
.cd-avatar {
  flex: none;
  width: 64px;
  height: 64px;
  border-radius: 18px;
  background: linear-gradient(180deg, var(--primary-2, #4a7fc4), var(--primary, #3a6db5));
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 24px;
  font-weight: 700;
  letter-spacing: 0.02em;
  box-shadow: inset 0 1px 0 rgb(var(--glass-rgb) / 0.4), 0 6px 14px rgba(58,109,181,0.3);
}
.cd-headmeta { min-width: 0; }
.cd-firm {
  font-size: 24px;
  font-weight: 700;
  letter-spacing: -0.02em;
  color: var(--ink, var(--ink));
}
.cd-sub { color: var(--muted, var(--muted)); font-size: 14px; margin-top: 2px; }
.cd-contacts { display: flex; flex-wrap: wrap; gap: 16px; margin-top: 8px; }
.cd-contacts a { color: var(--primary); text-decoration: none; font-size: 13px; font-weight: 500; }
.cd-contacts a:hover { text-decoration: underline; }

/* Sub-nav */
.cd-subnav {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  margin: 22px 0 18px;
  border-bottom: 1px solid var(--line, var(--bd-cool));
  padding-bottom: 0;
}
.cd-tab {
  appearance: none;
  background: transparent;
  border: 0;
  border-bottom: 2px solid transparent;
  padding: 10px 14px;
  font: inherit;
  font-size: 14px;
  font-weight: 600;
  color: var(--muted, var(--muted));
  cursor: pointer;
  margin-bottom: -1px;
  transition: color .15s ease, border-color .15s ease;
}
.cd-tab:hover { color: var(--ink, var(--ink)); }
.cd-tab.active { color: var(--primary); border-bottom-color: var(--primary); }

/* Rolodex rows */
.rolo-row {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  padding: 9px 0;
  border-bottom: 1px dashed rgba(15,23,42,0.07);
  font-size: 14px;
}
.rolo-row:last-child { border-bottom: 0; }
.rolo-label { color: var(--muted, var(--muted)); font-weight: 500; white-space: nowrap; }
.rolo-value { color: var(--ink, var(--ink)); text-align: right; font-weight: 500; word-break: break-word; }
.rolo-value a { color: var(--primary); text-decoration: none; }
.rolo-value a:hover { text-decoration: underline; }
.rolo-value code { font-family: ui-monospace, Menlo, monospace; font-size: 13px; background: rgba(58,109,181,0.08); padding: 2px 6px; border-radius: 5px; }
.rolo-sep { border: 0; border-top: 1px solid rgba(15,23,42,0.08); margin: 12px 0; }

/* Credit activity list */
.cd-credit-list { list-style: none; margin: 0; padding: 0; }
.cd-credit-list li {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 0;
  border-bottom: 1px solid rgba(15,23,42,0.06);
}
.cd-credit-list li:last-child { border-bottom: 0; }
.cd-ch-icon {
  flex: none;
  width: 30px; height: 30px;
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-weight: 700;
}
.cd-ch-icon.earned { background: #dcfce7; color: #166534; }
.cd-ch-icon.applied { background: #fee2e2; color: #991b1b; }
.cd-ch-body { flex: 1; min-width: 0; }
.cd-ch-title { font-weight: 600; font-size: 14px; color: var(--ink, var(--ink)); }
.cd-ch-sub { font-size: 12px; color: var(--muted, var(--muted)); margin-top: 1px; }
.cd-ch-amt { font-weight: 700; font-size: 15px; }
.cd-ch-amt.earned { color: #166534; }
.cd-ch-amt.applied { color: #991b1b; }

/* ============================================================================
   Delivery timeline manager (modal)
   ============================================================================ */
.dt-overlay {
  position: fixed; inset: 0; z-index: 1000;
  display: flex; align-items: flex-start; justify-content: center;
  padding: 40px 16px; overflow-y: auto;
}
.dt-overlay[hidden] { display: none; }   /* explicit display:flex would otherwise ignore [hidden] */
.dt-backdrop {
  position: fixed; inset: 0;
  background: rgba(15, 23, 42, 0.45);
  backdrop-filter: blur(3px);
}
.dt-card {
  position: relative; z-index: 1;
  width: 100%; max-width: 620px;
  background: var(--surface); border-radius: 18px;
  box-shadow: 0 24px 60px rgba(15, 23, 42, 0.28);
  padding: 28px 30px 30px;
}
.dt-x {
  position: absolute; top: 16px; right: 16px;
  background: transparent; border: 0; font-size: 20px; cursor: pointer;
  color: #94a3b8; line-height: 1; padding: 4px;
}
.dt-x:hover { color: var(--ink); }
.dt-kicker { font-size: 11px; letter-spacing: 2px; text-transform: uppercase; color: #c9913c; font-weight: 700; }
.dt-title { margin: 4px 0 8px; font-size: 22px; letter-spacing: -0.02em; }
.dt-route { font-size: 15px; font-weight: 600; color: #1e293b; }
.dt-arrow { color: #94a3b8; margin: 0 4px; }
.dt-sub { font-size: 13px; color: var(--muted); margin-top: 4px; }

/* Vertical stepper */
.dt-steps { list-style: none; margin: 24px 0 0; padding: 0; position: relative; }
.dt-step { position: relative; padding: 0 0 22px 38px; }
.dt-step:before {
  content: ""; position: absolute; left: 12px; top: 22px; bottom: -4px;
  width: 2px; background: var(--bd-cool);
}
.dt-step:last-child:before { display: none; }
.dt-dot {
  position: absolute; left: 0; top: 0;
  width: 26px; height: 26px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: 13px; font-weight: 700;
  background: #eef1f6; color: #94a3b8; border: 2px solid var(--bd-cool);
}
.dt-step.done .dt-dot { background: #1b7a43; color: #fff; border-color: #1b7a43; }
.dt-step.done:before { background: #b6e2c7; }
.dt-step.cancelled .dt-dot { background: #b42318; color: #fff; border-color: #b42318; }
.dt-step-head { display: flex; justify-content: space-between; gap: 12px; align-items: baseline; }
.dt-step-label { font-weight: 600; font-size: 15px; color: #1e293b; }
.dt-step.pending .dt-step-label { color: #94a3b8; }
.dt-step-time { font-size: 12px; color: var(--muted); white-space: nowrap; }
.dt-step-meta { font-size: 13px; color: var(--muted); margin-top: 3px; }
.dt-actor { color: #94a3b8; }
.dt-sig { margin-top: 8px; }
.dt-sig img {
  max-width: 200px; max-height: 90px;
  border: 1px solid var(--bd-cool); border-radius: 8px; background: var(--surface); padding: 4px;
}

/* Action area */
.dt-actions { margin-top: 8px; border-top: 1px solid #eef1f6; padding-top: 18px; }
.dt-actions-label { font-size: 12px; letter-spacing: 1px; text-transform: uppercase; color: #94a3b8; font-weight: 700; margin-bottom: 10px; }
.dt-action-btns { display: flex; flex-wrap: wrap; gap: 8px; }
.btn-inline-primary {
  appearance: none; border: 0; cursor: pointer;
  background: linear-gradient(180deg, #5784c7, #3a6db5); color: #fff;
  padding: 9px 16px; border-radius: 999px; font: inherit; font-size: 13px; font-weight: 600;
  box-shadow: 0 4px 10px rgba(58, 109, 181, 0.28);
}
.btn-inline-primary:hover { filter: saturate(112%); }
.dt-danger { color: #b42318 !important; border-color: #f3c7c2 !important; }
.dt-danger:hover { background: #fef2f2 !important; }
.dt-readonly { margin-top: 16px; font-size: 13px; color: #94a3b8; font-style: italic; }

/* Inline step form */
.dt-step-form { margin-top: 14px; background: #f8fafc; border: 1px solid #eef1f6; border-radius: 12px; padding: 16px; }
.dt-step-form.is-cancel { background: #fef6f5; border-color: #f3d3ce; }
.dt-form-title { font-weight: 700; font-size: 14px; margin-bottom: 12px; color: #1e293b; }
.dt-form-actions { display: flex; gap: 8px; align-items: center; }

/* Signature pad */
.dt-sigpad-wrap { position: relative; }
.dt-sigpad {
  width: 100%; height: 130px; display: block;
  background: var(--surface); border: 1px dashed #c3cedd; border-radius: 10px;
  touch-action: none; cursor: crosshair;
}
.dt-sig-clear {
  position: absolute; top: 8px; right: 8px;
  background: var(--surface); border: 1px solid var(--bd-cool); border-radius: 6px;
  font-size: 12px; padding: 4px 10px; cursor: pointer; color: var(--muted);
}
.dt-sig-clear:hover { background: #f4f8fd; color: #3a6db5; }

@media (max-width: 600px) {
  .dt-card { padding: 22px 18px 24px; }
  .dt-overlay { padding: 16px 8px; }
}

/* Credit-grant limits banner */
.credit-cap-note {
  background: #f4f8fd;
  border: 1px solid #e3edf9;
  border-radius: 10px;
  padding: 10px 14px;
  font-size: 13px;
  color: #475569;
  margin-bottom: 16px;
  line-height: 1.5;
}
.credit-cap-note strong { color: #1e293b; }
.credit-cap-note .cap-ok { color: #1b7a43; font-weight: 600; }
.credit-cap-note .cap-empty { color: #b42318; font-weight: 600; }

@media (max-width: 1100px) {
  .kpi-grid.kpi-grid-5 { grid-template-columns: repeat(3, 1fr); }
}
@media (max-width: 900px) {
  .kpi-grid.kpi-grid-5 { grid-template-columns: 1fr 1fr; }
  .cd-header { flex-direction: column; align-items: flex-start; text-align: left; }
  .cd-subnav { overflow-x: auto; }
}

/* ============================================================================
   Client messaging — sidebar badge + two-pane chat
   ========================================================================== */
.nav-badge {
  margin-left: auto;
  min-width: 18px; height: 18px; padding: 0 5px;
  border-radius: 9px;
  background: var(--danger);
  color: #fff;
  font-size: 11px; font-weight: 700; line-height: 18px;
  text-align: center; font-variant-numeric: tabular-nums;
}
.nav-badge[hidden] { display: none; }
.sidebar-item.active .nav-badge { background: #fff; color: var(--primary); }

.msg-layout {
  display: grid;
  grid-template-columns: 300px 1fr;
  gap: 16px;
  height: calc(100vh - 150px);
  min-height: 440px;
}
.msg-threads {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 14px;
  overflow-y: auto;
  padding: 6px;
}
.msg-thread {
  display: block; width: 100%; text-align: left;
  border: 0; border-bottom: 1px solid var(--line-soft);
  background: transparent;
  border-radius: 10px;
  padding: 10px 11px;
  cursor: pointer;
  transition: background 0.12s;
}
.msg-thread:hover { background: rgba(58, 109, 181, 0.07); }
.msg-thread.active { background: rgba(58, 109, 181, 0.13); }
.msg-thread-top { display: flex; align-items: center; gap: 8px; }
.msg-thread-firm {
  flex: 1; font-weight: 700; color: var(--ink); font-size: 14px;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.msg-thread-badge {
  min-width: 18px; height: 18px; padding: 0 5px;
  border-radius: 9px; background: var(--danger); color: #fff;
  font-size: 11px; font-weight: 700; line-height: 18px; text-align: center;
}
.msg-thread-snip {
  color: var(--muted); font-size: 12px; margin-top: 3px;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.msg-snip-you { color: var(--ink-2); font-weight: 600; }
.msg-thread-time { color: var(--muted); font-size: 11px; margin-top: 3px; }

.msg-conv {
  display: flex; flex-direction: column;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 14px;
  overflow: hidden;
  min-width: 0;
}
.msg-empty { margin: auto; color: var(--muted); font-size: 14px; padding: 40px; text-align: center; }
.msg-conv-head {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 13px 16px; border-bottom: 1px solid var(--line);
}
.msg-conv-firm { font-weight: 700; color: var(--ink); font-size: 15px; }
.msg-conv-sub { color: var(--muted); font-size: 12px; margin-top: 2px; }
.msg-conv-open { color: var(--primary); font-size: 13px; font-weight: 600; text-decoration: none; white-space: nowrap; }
.msg-conv-open:hover { text-decoration: underline; }

.msg-stream {
  flex: 1; overflow-y: auto; padding: 16px;
  display: flex; flex-direction: column; gap: 8px;
  background: var(--bg-base);
}
.msg-row { display: flex; }
.msg-row.mine { justify-content: flex-end; }
.msg-row.theirs { justify-content: flex-start; }
.msg-bubble {
  max-width: 74%;
  padding: 8px 12px;
  border-radius: 14px;
  box-shadow: 0 1px 2px rgba(15, 23, 42, 0.06);
}
.msg-row.theirs .msg-bubble {
  background: var(--surface); border: 1px solid var(--line);
  border-bottom-left-radius: 4px;
}
.msg-row.mine .msg-bubble {
  background: linear-gradient(180deg, var(--primary-2), var(--primary));
  color: #fff; border-bottom-right-radius: 4px;
}
.msg-text { font-size: 14px; line-height: 1.4; white-space: pre-wrap; word-wrap: break-word; }
.msg-meta { font-size: 10.5px; margin-top: 3px; }
.msg-row.mine .msg-meta { color: rgba(255, 255, 255, 0.85); }
.msg-row.theirs .msg-meta { color: var(--muted); }

.msg-compose {
  display: flex; gap: 9px; align-items: flex-end;
  padding: 11px 12px; border-top: 1px solid var(--line);
  background: var(--surface);
}
.msg-compose textarea {
  flex: 1; resize: none;
  border: 1px solid var(--line); border-radius: 11px;
  padding: 9px 12px; font: inherit; font-size: 14px; line-height: 1.4;
  color: var(--ink); background: var(--bg-base); max-height: 140px;
}
.msg-compose textarea:focus { outline: none; border-color: var(--primary); }
.msg-send {
  border: 0; border-radius: 11px; padding: 9px 18px; cursor: pointer;
  background: linear-gradient(180deg, var(--primary-2), var(--primary));
  color: #fff; font-weight: 700; font-size: 14px; white-space: nowrap;
}
.msg-send:hover { filter: brightness(1.05); }

/* Per-delivery thread extras */
.msg-thread-client { color: var(--ink-2); font-size: 12px; font-weight: 600; margin-top: 2px; }
.msg-thread-courier { color: var(--muted); font-size: 12px; margin-top: 2px; }
.msg-closed-tag {
  display: inline-block; font-size: 10px; font-weight: 700; text-transform: uppercase;
  letter-spacing: 0.04em; color: var(--muted); background: var(--line-soft);
  padding: 1px 6px; border-radius: 6px; vertical-align: middle;
}
.msg-closed-note {
  padding: 14px 16px; text-align: center; color: var(--muted); font-size: 13px;
  border-top: 1px solid var(--line); background: var(--surface);
}

@media (max-width: 900px) {
  .msg-layout { grid-template-columns: 1fr; height: auto; }
  .msg-threads { max-height: 280px; }
  .msg-stream { min-height: 340px; }
}
