/* =========================================================
   Base
   ========================================================= */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg:         #f3f6f9;
  --surface:    #ffffff;
  --surface-2:  #f0f4f8;
  --surface-3:  #e4ebf2;
  --border:     #d4dce6;
  --text:       #1e293b;
  --text-muted: #64748b;
  --accent:     #01A6E6;
  --accent-dark:#093A51;
  --green:      #16a34a;
  --green-dim:  #dcfce7;
  --red:        #dc2626;
  --red-dim:    #fee2e2;
  --yellow:     #d97706;
  --yellow-dim: #fef3c7;
  --purple:     #7c3aed;
  --radius:     8px;
  --font: "Montserrat", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  --font-heading: "Oswald", var(--font);
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 13px;
  line-height: 1.5;
  min-height: 100vh;
  font-weight: 400;
}

/* =========================================================
   Header
   ========================================================= */
header {
  display: flex;
  align-items: center;
  gap: 20px;
  padding: 14px 24px;
  background: linear-gradient(135deg, #01A6E6 0%, #093A51 100%);
  border-bottom: none;
  position: sticky;
  top: 0;
  z-index: 100;
  color: #fff;
  box-shadow: 0 2px 12px rgba(9, 58, 81, 0.25);
}

.header-brand { flex: 1; min-width: 0; }
.header-brand h1 { font-size: 24px; font-weight: 700; font-family: var(--font-heading); letter-spacing: 0.02em; color: #fff; }
.subtitle { font-size: 11px; color: rgba(255,255,255,0.7); margin-top: 1px; display: block; }

.header-stats {
  display: flex;
  align-items: center;
  gap: 0;
}

.header-stat {
  padding: 0 20px;
  text-align: right;
}

.header-stat-label {
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.6px;
  color: rgba(255,255,255,0.65);
  font-weight: 500;
  white-space: nowrap;
}

.header-stat-value {
  font-size: 22px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  line-height: 1.2;
  white-space: nowrap;
  color: #fff;
}

.stat-revenue  { color: #fff; }
.stat-exposure { color: #fbbf24; }

.header-stat-sep {
  width: 1px;
  height: 36px;
  background: rgba(255,255,255,0.2);
  flex-shrink: 0;
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 10px;
  padding-left: 20px;
  position: relative;
}

.sync-status {
  font-size: 11px;
  color: rgba(255,255,255,0.65);
  white-space: nowrap;
}

/* =========================================================
   Snapshot bar
   ========================================================= */
.snapshot-bar {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 10px;
  padding: 6px 24px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}

:root.dark .snapshot-bar { background: var(--surface); }

/* =========================================================
   Filter bar
   ========================================================= */
.filter-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 8px 24px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  flex-wrap: wrap;
}

.filter-left {
  display: flex;
  align-items: flex-end;
  gap: 10px;
  flex-wrap: wrap;
}

.filter-right {
  flex-shrink: 0;
}

.filter-count-label {
  font-size: 11px;
  color: var(--text-muted);
}

.filter-group {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.filter-group label {
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.4px;
  color: var(--text-muted);
  font-weight: 500;
}

select, input[type="text"], input[type="email"], input[type="password"] {
  background: #fff;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  font-size: 12px;
  padding: 5px 10px;
  outline: none;
  min-width: 130px;
  height: 30px;
}

select:focus, input[type="text"]:focus, input[type="email"]:focus, input[type="password"]:focus { border-color: var(--accent); }
input[type="text"]::placeholder { color: var(--text-muted); }

/* =========================================================
   Alerts
   ========================================================= */
#alerts-container {
  position: fixed;
  top: 64px;
  right: 16px;
  z-index: 300;
  display: flex;
  flex-direction: column;
  gap: 6px;
  max-width: 360px;
}

.alert {
  padding: 10px 14px;
  border-radius: var(--radius);
  font-size: 12px;
  font-weight: 500;
  transition: opacity 0.4s;
}

.alert-success { background: var(--green-dim); border: 1px solid var(--green); color: #15803d; }
.alert-error   { background: var(--red-dim); border: 1px solid var(--red); color: #b91c1c; }
.alert-warning { background: var(--yellow-dim); border: 1px solid var(--yellow); color: #92400e; }

/* =========================================================
   Main
   ========================================================= */
main { padding: 16px 24px; }
main.main-area { padding: 16px 24px; }

#init-warnings { margin-bottom: 10px; display: flex; flex-direction: column; gap: 6px; }

.loading-state, .error-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 80px 20px;
  gap: 14px;
  color: var(--text-muted);
}

.spinner {
  width: 28px; height: 28px;
  border: 3px solid var(--border);
  border-top-color: #01A6E6;
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* =========================================================
   Table
   ========================================================= */
.table-wrap {
  overflow-x: auto;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: #fff;
  box-shadow: 0 1px 3px rgba(0,0,0,0.06);
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 12px;
}

thead th {
  background: var(--surface-2);
  padding: 8px 12px;
  text-align: left;
  font-size: 10px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--text-muted);
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}

thead th.num-col  { text-align: right; }
thead th.action-col { text-align: right; }

tbody tr {
  border-bottom: 1px solid var(--border);
  transition: background 0.1s;
}
tbody tr:last-child { border-bottom: none; }
tbody tr:hover { background: var(--surface-2); }
tbody tr.processing { opacity: 0.4; pointer-events: none; }
tbody tr.new-company { border-top: 2px solid var(--surface-3); }

td {
  padding: 8px 12px;
  vertical-align: middle;
}

.num-col   { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.action-col { text-align: right; white-space: nowrap; }

/* Company name */
.company-name   { font-weight: 500; font-size: 12px; }
.company-repeat { font-weight: 400; font-size: 11px; color: var(--text-muted); }

/* Vendor cell */
.vendor-cell {
  white-space: nowrap;
  display: flex;
  align-items: center;
  gap: 6px;
}

.vendor-dot {
  display: inline-block;
  width: 7px;
  height: 7px;
  border-radius: 50%;
  flex-shrink: 0;
}

.vendor-dot-ninjarmm { background: #3db8f5; }
.vendor-dot-pax8     { background: #5c8fff; }
.vendor-dot-huntress { background: #a366ff; }

/* Service column */
.service-cell {
  max-width: 200px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--text-muted);
  font-size: 11px;
  font-family: "Consolas", "Courier New", monospace;
}

.muted { color: var(--text-muted); }

/* =========================================================
   Change badges
   ========================================================= */
.change-badge {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  padding: 2px 8px;
  border-radius: 4px;
  font-size: 11px;
  font-weight: 700;
  white-space: nowrap;
}

.change-up       { background: var(--green-dim); color: var(--green); }
.change-down     { background: var(--red-dim);   color: var(--red); }
.change-exposure { background: var(--yellow-dim); color: var(--yellow); }
.change-sync     { background: var(--surface-3); color: var(--text-muted); }

.row-sync td { opacity: 0.6; }

/* =========================================================
   Profit badges
   ========================================================= */
.profit-badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 4px;
  font-size: 11px;
  font-weight: 600;
  white-space: nowrap;
}

.profit-negative { background: var(--red-dim);   color: var(--red); }
.profit-positive { background: var(--green-dim); color: var(--green); }

/* =========================================================
   Contract badges
   ========================================================= */
.contract-badge {
  display: inline-block;
  padding: 2px 7px;
  border-radius: 4px;
  font-size: 10px;
  font-weight: 600;
  white-space: nowrap;
}

.contract-alliedcomplete { background: #dcfce7; color: #15803d; }
.contract-alliedsecure   { background: #f3e8ff; color: #6d28d9; }
.contract-microsoft365   { background: #dbeafe; color: #1d4ed8; }
.contract-ninjarmm       { background: #e0f2fe; color: #0369a1; }
.contract-huntressedr    { background: #f3e8ff; color: #7c3aed; }
.contract-legacy         { background: var(--yellow-dim); color: #92400e; }

/* =========================================================
   Totals row
   ========================================================= */
tfoot .totals-row td {
  padding: 9px 12px;
  background: var(--surface-2);
  border-top: 2px solid var(--border);
  font-size: 12px;
  color: var(--text-muted);
}

tfoot .totals-row strong { color: var(--text); }

/* Empty state */
.empty-state {
  text-align: center;
  padding: 48px 20px;
  color: var(--text-muted);
}

/* =========================================================
   Buttons
   ========================================================= */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 6px 12px;
  border-radius: var(--radius);
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  border: 1px solid transparent;
  transition: background 0.12s, opacity 0.12s;
  white-space: nowrap;
}
.btn:disabled { opacity: 0.4; cursor: not-allowed; }
.btn-sm { padding: 4px 10px; font-size: 11px; }

.btn-primary  { background: var(--accent); color: #fff; }
.btn-primary:hover:not(:disabled) { background: #0090cc; }

.btn-secondary { background: var(--surface-3); color: var(--text); border-color: var(--border); }
.btn-secondary:hover:not(:disabled) { background: #d4dce6; }

.btn-ghost { background: transparent; color: var(--text-muted); border-color: var(--border); }
.btn-ghost:hover:not(:disabled) { background: var(--surface-2); color: var(--text); }

.btn-approve {
  background: var(--green-dim);
  color: var(--green);
  border-color: #bbf7d0;
  font-size: 14px;
  padding: 3px 9px;
}
.btn-approve:hover:not(:disabled) { background: #bbf7d0; }

.btn-deny {
  background: var(--surface-3);
  color: var(--text-muted);
  border-color: var(--border);
  font-size: 14px;
  padding: 3px 9px;
}
.btn-deny:hover:not(:disabled) { background: var(--red-dim); color: var(--red); border-color: #fca5a5; }

/* =========================================================
   Modal
   ========================================================= */
.modal-overlay {
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.35);
  display: flex; align-items: center; justify-content: center;
  z-index: 400;
}
.modal {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  width: 400px; max-width: 94vw;
}
.modal-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 18px;
  border-bottom: 1px solid var(--border);
}
.modal-header h3 { font-size: 14px; font-weight: 600; }
.modal-close { background: none; border: none; color: var(--text-muted); font-size: 18px; cursor: pointer; padding: 2px 6px; }
.modal-close:hover { color: var(--text); }
.modal-body { padding: 18px; display: flex; flex-direction: column; gap: 10px; }
.modal-body p { font-size: 12px; color: var(--text-muted); }
.modal-body label { font-size: 11px; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.4px; }
.modal-footer { display: flex; justify-content: flex-end; gap: 8px; padding: 12px 18px; border-top: 1px solid var(--border); }

/* =========================================================
   Sync rows
   ========================================================= */
.sync-row td { padding-top: 6px; padding-bottom: 6px; }

.sync-badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 4px;
  font-size: 11px;
  font-weight: 600;
  background: var(--green-dim);
  color: var(--green);
}

.sync-count { color: var(--green); font-weight: 500; }

.prorated-note {
  font-size: 10px;
  font-weight: 600;
  color: var(--yellow);
  background: var(--yellow-dim);
  padding: 1px 5px;
  border-radius: 3px;
  white-space: nowrap;
  cursor: help;
}

/* Toggle label */
.toggle-label {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  color: var(--text-muted);
  cursor: pointer;
  white-space: nowrap;
  margin-right: 12px;
}

.toggle-label input[type="checkbox"] {
  width: auto;
  min-width: unset;
  height: auto;
  cursor: pointer;
  accent-color: var(--accent);
}

.filter-right {
  display: flex;
  align-items: center;
  gap: 12px;
}

/* =========================================================
   Theme Toggle Button
   ========================================================= */
.btn-theme-toggle {
  background: rgba(255,255,255,0.15);
  border: 1px solid rgba(255,255,255,0.25);
  color: #fff;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  font-size: 16px;
  transition: background 0.15s;
  flex-shrink: 0;
}
.btn-theme-toggle:hover {
  background: rgba(255,255,255,0.25);
}

/* =========================================================
   Dark Mode
   ========================================================= */
:root.dark {
  --bg:         #0f1117;
  --surface:    #181a24;
  --surface-2:  #1e2130;
  --surface-3:  #262a3a;
  --border:     #2e3348;
  --text:       #e2e4f0;
  --text-muted: #7a7f9a;
  --accent:     #01A6E6;
  --accent-dark:#093A51;
  --green:      #4ade80;
  --green-dim:  #0f2918;
  --red:        #f87171;
  --red-dim:    #2e1416;
  --yellow:     #fbbf24;
  --yellow-dim: #2a2010;
  --purple:     #c084f5;
}

:root.dark body {
  background: var(--bg);
  color: var(--text);
}

:root.dark select,
:root.dark input[type="text"],
:root.dark input[type="email"],
:root.dark input[type="password"] {
  background: var(--surface-2);
  border-color: var(--border);
  color: var(--text);
}

:root.dark .table-wrap {
  background: var(--surface);
  box-shadow: none;
}

:root.dark .alert-success { background: var(--green-dim); color: var(--green); }
:root.dark .alert-error   { background: var(--red-dim); color: var(--red); }
:root.dark .alert-warning { background: var(--yellow-dim); color: var(--yellow); }

:root.dark .modal-overlay { background: rgba(0,0,0,0.65); }

:root.dark .contract-alliedcomplete { background: #0e2218; color: #4ade80; }
:root.dark .contract-alliedsecure   { background: #1a1028; color: var(--purple); }
:root.dark .contract-microsoft365   { background: #0e1828; color: #60a5fa; }
:root.dark .contract-ninjarmm       { background: #0e1e2e; color: #38bdf8; }
:root.dark .contract-huntressedr    { background: #1a1028; color: #a78bfa; }
:root.dark .contract-legacy         { background: #1e1a0e; color: var(--yellow); }

:root.dark .btn-secondary:hover:not(:disabled) { background: #2e3348; }

:root.dark .sync-badge { background: var(--green-dim); color: var(--green); }

/* =========================================================
   Login Page
   ========================================================= */
.login-body {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  background: var(--bg);
}

.login-container {
  width: 360px;
  max-width: 94vw;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: 0 4px 24px rgba(0,0,0,0.1);
}

.login-header {
  background: linear-gradient(135deg, #01A6E6 0%, #093A51 100%);
  padding: 28px 24px 20px;
  text-align: center;
  color: #fff;
}

.login-header h1 {
  font-family: var(--font-heading);
  font-size: 22px;
  font-weight: 700;
  letter-spacing: 0.02em;
  margin-bottom: 4px;
}

.login-header .subtitle {
  color: rgba(255,255,255,0.7);
  font-size: 12px;
}

.login-form {
  padding: 24px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.login-field {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.login-field label {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-muted);
  font-weight: 500;
}

.login-field input {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  font-size: 14px;
  padding: 10px 12px;
  outline: none;
  width: 100%;
}

.login-field input:focus {
  border-color: var(--accent);
}

.login-btn {
  margin-top: 4px;
  padding: 10px;
  font-size: 14px;
  font-weight: 600;
}

.login-error {
  background: var(--red-dim);
  border: 1px solid var(--red);
  color: var(--red);
  padding: 8px 12px;
  border-radius: var(--radius);
  font-size: 12px;
  font-weight: 500;
}

:root.dark .login-container { background: var(--surface); }
:root.dark .login-field input { background: var(--surface-2); color: var(--text); }
:root.dark .login-error { color: var(--red); }

/* =========================================================
   Profile Page
   ========================================================= */
.profile-grid {
  display: grid;
  grid-template-columns: 300px 1fr;
  gap: 16px;
  max-width: 800px;
}

@media (max-width: 700px) {
  .profile-grid { grid-template-columns: 1fr; }
}

.profile-avatar-section {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
}

.profile-avatar-preview {
  width: 120px;
  height: 120px;
  border-radius: 50%;
  overflow: hidden;
  border: 3px solid var(--border);
}

.avatar-img-lg {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.avatar-placeholder-lg {
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, #01A6E6 0%, #093A51 100%);
  color: #fff;
  font-size: 48px;
  font-weight: 700;
  font-family: var(--font-heading);
}

.profile-avatar-form {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
}

.profile-form-fields {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

/* Avatar in header */
.header-avatar {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  object-fit: cover;
  border: 2px solid rgba(255,255,255,0.3);
  cursor: pointer;
}

.header-profile-link {
  display: flex;
  align-items: center;
  gap: 8px;
  text-decoration: none;
  padding: 4px 8px;
  border-radius: var(--radius);
  transition: background 0.15s;
}

.header-profile-link:hover {
  background: rgba(255,255,255,0.1);
}

.header-avatar-placeholder {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(255,255,255,0.2);
  color: #fff;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  border: 2px solid rgba(255,255,255,0.3);
}

/* =========================================================
   Admin Page
   ========================================================= */
.admin-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 20px;
  margin-bottom: 16px;
  box-shadow: 0 1px 3px rgba(0,0,0,0.06);
}

:root.dark .admin-card { background: var(--surface); box-shadow: none; }

.admin-card-title {
  font-size: 14px;
  font-weight: 600;
  margin-bottom: 12px;
}

.admin-form-row {
  display: flex;
  align-items: flex-end;
  gap: 12px;
  flex-wrap: wrap;
}

.admin-actions {
  display: flex;
  gap: 6px;
  justify-content: flex-end;
}

.inline-form {
  display: inline;
}

.perm-form {
  display: flex;
  gap: 6px;
}

.perm-check {
  display: flex;
  align-items: center;
  gap: 3px;
  font-size: 10px;
  color: var(--text-muted);
  cursor: pointer;
  white-space: nowrap;
}

.perm-check input {
  width: auto;
  min-width: unset;
  height: auto;
  cursor: pointer;
  accent-color: var(--accent);
}

.perm-row {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

/* =========================================================
   Role Badges
   ========================================================= */
.role-badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 10px;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.03em;
  text-transform: uppercase;
  white-space: nowrap;
}

.role-super-admin { background: #fee2e2; color: #dc2626; border: 1px solid #fca5a5; }
.role-account-manager { background: #dbeafe; color: #1d4ed8; border: 1px solid #bfdbfe; }
.role-technician { background: #dcfce7; color: #16a34a; border: 1px solid #bbf7d0; }

:root.dark .role-super-admin { background: #2e1416; color: #f87171; border-color: rgba(248,113,113,0.3); }
:root.dark .role-account-manager { background: #0e1828; color: #60a5fa; border-color: rgba(96,165,250,0.3); }
:root.dark .role-technician { background: #0f2918; color: #4ade80; border-color: rgba(74,222,128,0.3); }

/* =========================================================
   Utilities
   ========================================================= */
.hidden { display: none !important; }

/* =========================================================
   Mobile (shared chrome + table cards) -- refined
   ========================================================= */
@media (max-width: 768px) {

  body { font-size: 14px; }

  /* ----- Header: scrolls away on mobile (nav stays sticky instead) ----- */
  header {
    position: static;
    flex-wrap: wrap;
    gap: 12px;
    padding: 14px 16px;
  }
  .header-brand h1 { font-size: 19px; }
  .header-brand img { height: 38px !important; }
  .subtitle { display: none; }
  .header-profile-link .sync-status { display: none; }
  .header-actions { gap: 6px; padding-left: 0; }

  /* KPI stats: 2x2 grid of translucent chips on the gradient */
  .header-stats {
    order: 3;
    flex-basis: 100%;
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
  }
  .header-stats.hidden { display: none; }
  .header-stat {
    padding: 9px 12px;
    text-align: left;
    background: rgba(255,255,255,0.12);
    border-radius: 10px;
  }
  .header-stat-sep { display: none; }
  .header-stat-label { font-size: 9px; }
  .header-stat-value { font-size: 18px; }

  .snapshot-bar { padding: 8px 16px; }
  main { padding: 14px; }
  main.main-area { padding: 14px; }

  /* ----- Filter bar: stacked, comfortable touch targets ----- */
  .filter-bar { padding: 12px 14px; gap: 10px; }
  .filter-left { flex-direction: column; align-items: stretch; width: 100%; gap: 10px; }
  .filter-group { width: 100%; }
  .filter-group select,
  .filter-group input[type="text"] { width: 100%; min-width: 0; height: 40px; font-size: 14px; }
  .filter-right { width: 100%; justify-content: space-between; }

  /* ----- Bigger tap targets ----- */
  .btn { padding: 9px 14px; }
  .btn-sm { padding: 8px 12px; font-size: 12px; }

  /* ----- Modal ----- */
  .modal-footer { flex-direction: column; }
  .modal-footer .btn { width: 100%; }

  /* ----- Data tables -> clean stacked cards (label left, value right) ----- */
  .stack-table thead { display: none; }
  .stack-table,
  .stack-table tbody,
  .stack-table tr,
  .stack-table td { display: block; width: 100%; }

  .stack-table tr {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 12px;
    margin-bottom: 10px;
    padding: 2px 0;
    box-shadow: 0 1px 3px rgba(0,0,0,0.05);
    overflow: hidden;
  }

  .stack-table td {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 14px;
    text-align: right;
    padding: 11px 16px;
    border: none;
    border-bottom: 1px solid var(--surface-2);
    white-space: normal;
    min-height: 44px;
    font-size: 14px;
  }
  .stack-table tr td:last-child { border-bottom: none; }

  .stack-table td::before {
    content: attr(data-label);
    font-weight: 600;
    font-size: 10px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--text-muted);
    text-align: left;
    flex-shrink: 0;
    align-self: center;
  }

  /* Action / expand cells carry no label; keep their control right-aligned */
  .stack-table td[data-label=""] { justify-content: flex-end; }
  .stack-table td[data-label=""]::before { content: none; }

  .stack-table .num-col,
  .stack-table .action-col { text-align: right; white-space: normal; font-variant-numeric: tabular-nums; }
  .stack-table .service-cell { max-width: none; white-space: normal; text-align: right; }

  /* Totals row gets a subtle emphasis */
  .stack-table tfoot tr { background: var(--surface-2); }
}

@media (max-width: 480px) {
  .header-brand h1 { font-size: 17px; }
}
