
* { margin:0; padding:0; box-sizing:border-box; }
body { font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif; background:#f5f6fa; color:#333; }

/* ── Top Bar (refined) ── */
.topbar {
  background:linear-gradient(135deg,#1a1a2e,#16213e);
  color:#fff; padding:14px 24px;
  display:flex; align-items:center; justify-content:space-between;
  position:sticky; top:0; z-index:100;
  box-shadow:0 1px 3px rgba(0,0,0,0.08);
}
.topbar h1 {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  font-size:20px; font-weight:800;
  letter-spacing:-0.04em;
  font-feature-settings: 'cv11', 'ss01', 'ss03';  /* Inter stylistic alternates: alt-a, single-storey g */
}
.topbar h1 span { color:#e94560; font-weight:800; }
.topbar-right { display:flex; align-items:center; gap:14px; }
.topbar-right > a { color:rgba(255,255,255,0.7); font-size:12px; text-decoration:none; transition:color 0.15s; }
.topbar-right > a:hover { color:#fff; }
#aiSearchWrap:hover, #aiSearchWrap:focus-within { background:rgba(255,255,255,0.18) !important; border-color:rgba(99,102,241,0.6) !important; box-shadow:0 0 0 3px rgba(99,102,241,0.15); }
#aiSearchInput::placeholder { color:rgba(255,255,255,0.55); }
.topbar-user { font-size:13px; font-weight:600; color:rgba(255,255,255,0.95); }
.topbar-role {
  background:rgba(233,69,96,0.15); color:#fda4af;
  padding:3px 9px; border-radius:10px;
  font-size:10px; font-weight:700;
  text-transform:uppercase; letter-spacing:0.5px;
  border:1px solid rgba(233,69,96,0.3);
}
body.role-admin .topbar-role  { background:rgba(220,38,38,0.15); color:#fca5a5; border-color:rgba(220,38,38,0.35); }
body.role-staff .topbar-role  { background:rgba(8,145,178,0.15); color:#67e8f9; border-color:rgba(8,145,178,0.35); }
body.role-broker .topbar-role { background:rgba(245,158,11,0.15); color:#fcd34d; border-color:rgba(245,158,11,0.35); }
body.role-viewer .topbar-role { background:rgba(107,114,128,0.2);  color:#cbd5e1; border-color:rgba(107,114,128,0.4); }
.btn-logout {
  background:none; border:1px solid rgba(255,255,255,0.25); color:#fff;
  padding:6px 14px; border-radius:6px; cursor:pointer; font-size:12px;
  transition:all 0.15s;
}
.btn-logout:hover { background:rgba(255,255,255,0.1); border-color:rgba(255,255,255,0.5); }
#bellBtn { transition:transform 0.15s; }
#bellBtn:hover { transform:scale(1.1); }

/* ── Stats Cards (polished) ── */
.stats { display:grid; grid-template-columns:repeat(auto-fit,minmax(180px,1fr)); gap:14px; padding:20px 24px 0; }
.stats + .stats { padding-top:14px; }
.stat-card {
  background:#fff; border-radius:14px; padding:18px 20px;
  box-shadow:0 1px 3px rgba(0,0,0,0.04), 0 4px 12px rgba(0,0,0,0.05);
  border:1px solid rgba(0,0,0,0.04);
  position:relative; overflow:hidden;
  transition:transform 0.15s ease, box-shadow 0.15s ease;
}
.stat-card::before {
  content:''; position:absolute; top:0; left:0; right:0; height:3px;
  background:linear-gradient(90deg, currentColor, transparent);
  opacity:0.6;
}
.stat-card.clickable:hover {
  transform:translateY(-2px);
  box-shadow:0 4px 8px rgba(0,0,0,0.06), 0 12px 24px rgba(0,0,0,0.08);
}
.stat-card .label {
  font-size:11px; color:#6b7280; text-transform:uppercase; font-weight:700;
  letter-spacing:0.5px; display:flex; align-items:center; gap:6px;
}
.stat-card .value { font-size:30px; font-weight:800; margin-top:6px; line-height:1.1; letter-spacing:-0.5px; }
.stat-card .value.green { color:#16a34a; }
.stat-card .value.red { color:#dc2626; }
.stat-card .value.blue { color:#2563eb; }
.stat-card .trend {
  display:inline-flex; align-items:center; gap:3px;
  font-size:11px; font-weight:700; padding:2px 7px; border-radius:10px;
  margin-top:4px;
}
.stat-card .trend.up { background:#d1fae5; color:#065f46; }
.stat-card .trend.down { background:#fee2e2; color:#991b1b; }
.stat-card .trend.flat { background:#f3f4f6; color:#374151; }

/* ── Quick-action menu bar (clean, dropdown-based) ── */
.qa-btn {
  display:inline-flex; align-items:center; gap:5px;
  background:#fff; color:#374151;
  border:1px solid #e5e7eb; border-radius:7px;
  padding:7px 13px; font-size:12px; font-weight:600;
  cursor:pointer; transition:all 0.15s ease;
  white-space:nowrap; line-height:1.2;
  box-shadow:0 1px 2px rgba(0,0,0,0.03);
}
.qa-btn:hover {
  background:#f9fafb; border-color:#cbd5e1;
  transform:translateY(-1px);
  box-shadow:0 2px 6px rgba(0,0,0,0.07);
}
.qa-btn.qa-primary {
  background:#1e3a8a; color:#fff; border-color:#1e3a8a;
}
.qa-btn.qa-primary:hover {
  background:#1e40af; border-color:#1e40af;
}
.qa-btn.qa-urgent {
  background:#fef2f2; color:#dc2626; border-color:#fecaca;
}
.qa-btn.qa-urgent:hover {
  background:#fee2e2; border-color:#fca5a5;
}
.qa-menu { position:relative; display:inline-block; }
.qa-menu-btn { user-select:none; }
.qa-menu.open .qa-menu-btn {
  background:#f3f4f6; border-color:#cbd5e1;
}
.qa-dropdown {
  display:none; position:absolute; top:calc(100% + 6px); left:0;
  background:#fff; min-width:240px;
  border:1px solid #e5e7eb; border-radius:8px;
  box-shadow:0 10px 30px rgba(0,0,0,0.15), 0 2px 6px rgba(0,0,0,0.05);
  padding:6px; z-index:500;
  animation:qaDropFade 0.12s ease-out;
}
@keyframes qaDropFade {
  from { opacity:0; transform:translateY(-4px); }
  to   { opacity:1; transform:translateY(0); }
}
.qa-menu.open .qa-dropdown { display:block; }
.qa-dropdown a {
  display:flex; align-items:center; gap:8px;
  padding:8px 12px; font-size:13px;
  color:#374151; text-decoration:none;
  border-radius:5px; cursor:pointer;
  transition:background 0.1s;
}
.qa-dropdown a:hover { background:#f3f4f6; color:#111; }
.qa-dropdown a strong { font-weight:600; }
.qa-dropdown .qa-hint {
  font-size:10px; color:#9ca3af; font-weight:400;
  margin-left:auto; padding-left:8px;
}
.qa-divider {
  height:1px; background:#f3f4f6; margin:4px 0;
}

/* ── Today's Pulse strip (live activity ticker on dashboard) ── */
.pulse-strip {
  background:linear-gradient(135deg, #1a1a2e, #16213e);
  color:#fff; margin:16px 24px 0; border-radius:14px; padding:14px 20px;
  display:flex; align-items:center; gap:18px; flex-wrap:wrap;
  box-shadow:0 4px 16px rgba(26,26,46,0.25);
}
.pulse-strip .pulse-label {
  display:flex; align-items:center; gap:8px; font-size:13px;
  letter-spacing:0.5px; font-weight:600;
}
.pulse-strip .pulse-dot {
  display:inline-block; width:8px; height:8px; border-radius:50%;
  background:#22c55e; animation:pulse-anim 2s infinite;
}
@keyframes pulse-anim {
  0%, 100% { opacity:1; transform:scale(1); }
  50% { opacity:0.5; transform:scale(1.4); }
}
.pulse-strip .pulse-stat {
  display:flex; flex-direction:column; gap:1px;
  border-left:1px solid rgba(255,255,255,0.2); padding-left:14px;
}
.pulse-strip .pulse-stat .num { font-size:18px; font-weight:800; line-height:1; }
.pulse-strip .pulse-stat .lab { font-size:10px; color:rgba(255,255,255,0.65); text-transform:uppercase; letter-spacing:0.5px; }
.pulse-strip .pulse-feed {
  flex:1; min-width:200px; font-size:12px; color:rgba(255,255,255,0.85);
  overflow:hidden; white-space:nowrap; text-overflow:ellipsis;
}
.pulse-strip .pulse-feed .pf-item {
  display:inline-flex; align-items:center; gap:5px; margin-right:18px;
}

/* ── Content Area ── */
.content { padding:0 24px 24px; }
.section { background:#fff; border-radius:12px; padding:24px; box-shadow:0 2px 8px rgba(0,0,0,0.06); margin-bottom:20px; }
.section h2 { font-size:18px; margin-bottom:16px; color:#1a1a2e; }

/* ── Table ── */
.table-wrap { overflow-x:auto; }
table { width:100%; border-collapse:collapse; font-size:13px; }
th { background:#f8f9fa; padding:10px 12px; text-align:left; font-weight:600; color:#555; border-bottom:2px solid #e0e0e0; white-space:nowrap; }
td { padding:10px 12px; border-bottom:1px solid #f0f0f0; }
tr:hover td { background:#f8f9fa; }
.badge { padding:2px 8px; border-radius:4px; font-size:11px; font-weight:600; }
.badge-pending { background:#fff3cd; color:#856404; }
.badge-renewed { background:#d4edda; color:#155724; }
.badge-cancelled { background:#f8d7da; color:#721c24; }

/* ── Toolbar ── */
.toolbar { display:flex; gap:12px; margin-bottom:16px; flex-wrap:wrap; align-items:center; }
.toolbar input, .toolbar select { padding:8px 12px; border:1px solid #ddd; border-radius:6px; font-size:13px; }
.toolbar input { width:240px; }
.btn { padding:8px 16px; border:none; border-radius:6px; font-size:13px; font-weight:600; cursor:pointer; }
.btn-primary { background:#e94560; color:#fff; }
.btn-primary:hover { background:#d63851; }
.btn-sm { padding:4px 10px; font-size:12px; }

/* ── Policy row action menu ── */
.act-wrap { display:flex; align-items:center; gap:3px; flex-wrap:nowrap; }
.act-menu-wrap { position:relative; }
.act-menu { display:none; position:fixed; z-index:1000;
  background:#fff; border:1px solid #e5e7eb; border-radius:8px;
  box-shadow:0 6px 18px rgba(0,0,0,.14); padding:4px; min-width:150px; max-height:78vh; overflow:auto; }
.act-menu.open { display:flex; flex-direction:column; gap:2px; }
.act-menu button { width:100%; text-align:left; background:transparent !important;
  color:#374151 !important; border-radius:5px; white-space:nowrap; }
.act-menu button:hover { background:#f3f4f6 !important; }
.act-more { background:#f1f5f9 !important; color:#475569 !important;
  font-size:16px; line-height:1; padding:2px 8px !important; letter-spacing:1px; }
.act-more:hover { background:#e2e8f0 !important; }

/* ── Admin Panel ── */
.admin-panel { display:none; }
.admin-panel.show { display:block; }

/* Hide admin-only elements by default — JS reveals them when user.role === 'admin' */
.admin-only { display:none !important; }
.admin-only.show { display:inline-flex !important; }
.tab.admin-only.show { display:block !important; }
/* v1137 — staff open the Leads tab, without delete / CSV import / Apify (server refuses them too) */
body.role-staff .lead-admin { display:none !important; }
/* v214 — confidentiality: hide commission/broker/insurer financials from denied users */
body.no-fin .fin-only { display:none !important; }
/* v1055 — accounting-only users: keep the sub-views that carry no commission analytics */
body.acct-limited .acct-sub { display:none !important; }
body.acct-limited #acctSubJournal, body.acct-limited #acctSubReleve, body.acct-limited #acctSubLocks, body.acct-limited #acctSubTresor { display:inline-block !important; }

/* Viewer role — hide all write actions (Add/Edit/Delete/Post/Pay/Save/etc.) */
body.role-viewer .btn-primary,
body.role-viewer button[onclick*="openAdd"],
body.role-viewer button[onclick*="addInsurer"],
body.role-viewer button[onclick*="openAddUser"],
body.role-viewer button[onclick*="openAddReferral"],
body.role-viewer button[onclick*="openAddPolicy"],
body.role-viewer button[onclick*="openAddClient"],
body.role-viewer button[onclick*="openEdit"],
body.role-viewer button[onclick*="editClient"],
body.role-viewer button[onclick*="editUser"],
body.role-viewer button[onclick*="editReferral"],
body.role-viewer button[onclick*="editInsurer"],
body.role-viewer button[onclick*="deletePolicy"],
body.role-viewer button[onclick*="deleteClient"],
body.role-viewer button[onclick*="deleteInsurer"],
body.role-viewer button[onclick*="deleteReferral"],
body.role-viewer button[onclick*="voidPayment"],
body.role-viewer button[onclick*="renameInsurer"],
body.role-viewer button[onclick*="openPayBroker"],
body.role-viewer button[onclick*="openReferralPay"],
body.role-viewer button[onclick*="submitPv"],
body.role-viewer button[onclick*="submitRv"],
body.role-viewer button[onclick*="submitJv"],
body.role-viewer button[onclick*="openJvBuilder"],
body.role-viewer button[onclick*="openRvBuilder"],
body.role-viewer button[onclick*="openPvBuilder"],
body.role-viewer button[onclick*="openPayInsurer"],
body.role-viewer button[onclick*="openClientDirect"],
body.role-viewer button[onclick*="openImportGroups"],
body.role-viewer button[onclick*="reset"],
body.role-viewer button[onclick*="postPolicy"],
body.role-viewer button[onclick*="renewPolicy"],
body.role-viewer button[onclick*="createRenewal"],
body.role-viewer button[onclick*="saveEdit"],
body.role-viewer button[onclick*="markRenewed"],
body.role-viewer button[onclick*="addEndorsement"],
body.role-viewer .btn-success,
body.role-viewer input[type="file"] {
  display:none !important;
}
body.role-viewer #viewerBanner { display:block !important; }

/* ── Tabs (horizontal-scroll with arrows + fade indicators) ── */
.tabs-wrap {
  position: relative;
  margin-bottom: 20px;
  border-bottom: 2px solid #e0e0e0;
}
.tabs {
  display: flex;
  gap: 4px;
  overflow-x: auto;
  scroll-behavior: smooth;
  scrollbar-width: thin;
  scrollbar-color: rgba(233,69,96,0.3) transparent;
  white-space: nowrap;
  padding: 0 32px;  /* room for the arrow buttons on each side */
  -webkit-overflow-scrolling: touch;
  border-bottom: none !important;  /* moved to .tabs-wrap */
  cursor: grab;
  user-select: none;
}
.tabs.dragging {
  cursor: grabbing;
  scroll-behavior: auto;  /* disable smooth-scroll while dragging for instant response */
}
.tabs.dragging .tab {
  pointer-events: none;  /* prevent accidental clicks during drag */
}
.tabs::-webkit-scrollbar { height: 4px; }
.tabs::-webkit-scrollbar-track { background: transparent; }
.tabs::-webkit-scrollbar-thumb { background: rgba(233,69,96,0.3); border-radius: 2px; }
.tabs::-webkit-scrollbar-thumb:hover { background: rgba(233,69,96,0.6); }
.tab {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  padding: 10px 18px;
  cursor: pointer;
  font-size: 14px;
  font-weight: 600;
  letter-spacing: -0.015em;
  font-feature-settings: 'cv11', 'ss01';
  color: #888;
  border-bottom: 2px solid transparent;
  margin-bottom: -2px;
  transition: all 0.18s ease;
  flex-shrink: 0;
  position: relative;
  overflow: hidden;
}
/* Glow effect on hover — sliding gradient under the text */
.tab::before {
  content: '';
  position: absolute;
  inset: 0;
  background: linear-gradient(90deg, transparent, rgba(233,69,96,0.08), transparent);
  transform: translateX(-100%);
  transition: transform 0.4s ease;
  pointer-events: none;
}
.tab:hover::before { transform: translateX(0); }
.tab:hover {
  color: #1a1a2e;
  font-weight: 700;
  background: rgba(233,69,96,0.06);
  border-bottom-color: rgba(233,69,96,0.45);
  transform: translateY(-1px);
}
.tab.active {
  color: #e94560;
  border-bottom-color: #e94560;
  font-weight: 700;
}
.tab.active:hover { background: rgba(233,69,96,0.08); color: #e94560; transform: none; }

/* Scroll arrow buttons — appear on hover of the wrap */
.tabs-arrow {
  position: absolute;
  top: 0;
  bottom: 0;
  width: 32px;
  background: linear-gradient(90deg, #fff 60%, rgba(255,255,255,0));
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
  color: #1a1a2e;
  opacity: 0;
  transition: opacity 0.2s, transform 0.15s;
  z-index: 5;
  font-weight: 700;
}
.tabs-arrow.right {
  right: 0;
  background: linear-gradient(270deg, #fff 60%, rgba(255,255,255,0));
}
.tabs-arrow.left { left: 0; }

/* ═══ Grouped tab menus (declutter the long tab bar into ~5 dropdowns) ═══ */
/* #mainTabs must NOT clip the absolutely-positioned dropdowns, and with only
   ~5 group buttons it never overflows, so drop the scroll/grab behavior. */
#mainTabs { overflow: visible !important; cursor: default !important; gap: 2px; }
.tabgroup-wrap { position: relative; flex-shrink: 0; }
/* v623 — bigger main bar + stronger hover (owner request): larger type/padding, and
   hover gets a visible lift + tinted pill + solid underline instead of the faint tint. */
.tabgroup {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  padding: 14px 22px; cursor: pointer; font-size: 16px; font-weight: 600; color: #777;
  background: none; border: none; border-bottom: 3px solid transparent; margin-bottom: -2px;
  border-radius: 10px 10px 0 0;
  display: inline-flex; align-items: center; gap: 7px; transition: all .18s ease;
}
.tabgroup:hover {
  color: #1a1a2e; background: rgba(233,69,96,0.10); border-bottom-color: #e94560;
  transform: translateY(-1px); box-shadow: 0 2px 8px rgba(233,69,96,0.12);
}
.tabgroup.active { color: #e94560; border-bottom-color: #e94560; font-weight: 700; background: rgba(233,69,96,0.05); }
.tabgroup .caret { font-size: 10px; opacity: .7; transition: transform .15s; }
.tabgroup.open .caret { transform: rotate(180deg); }
.tabgroup-menu {
  display: none; position: absolute; top: calc(100% + 4px); left: 0; min-width: 210px;
  background: #fff; border: 1px solid #e5e7eb; border-radius: 10px;
  box-shadow: 0 12px 32px rgba(0,0,0,0.16); padding: 6px; z-index: 1200;
}
.tabgroup-menu.open { display: block; }
/* Tabs become stacked menu rows inside the dropdown */
.tabgroup-menu .tab {
  display: block !important; width: 100%; border-bottom: none !important; margin: 0;
  padding: 9px 12px; border-radius: 7px; color: #374151; font-size: 13px; white-space: nowrap;
}
.tabgroup-menu .tab:hover { background: #f1f5f9; color: #1a1a2e; transform: none; border-bottom-color: transparent; }
.tabgroup-menu .tab.active { background: rgba(233,69,96,0.10); color: #e94560; border-bottom: none !important; }
.tabgroup-menu .tab.admin-only.show { display: block !important; }
.grp-dot {
  background: #e94560; color: #fff; border-radius: 10px; font-size: 10px; font-weight: 700;
  min-width: 16px; height: 16px; display: none; align-items: center; justify-content: center; padding: 0 4px; line-height: 1;
}
.tabs-wrap:hover .tabs-arrow.show { opacity: 1; }
.tabs-arrow:hover {
  color: #e94560;
  transform: scale(1.2);
}
.tabs-arrow:active { transform: scale(0.95); }

/* ── Modal ── */
.modal-overlay { position:fixed; top:0; left:0; right:0; bottom:0; background:rgba(0,0,0,0.5); z-index:200; display:none; align-items:center; justify-content:center; }
.modal-overlay.show { display:flex; }
.modal { background:#fff; border-radius:12px; padding:32px; max-width:600px; width:90%; max-height:80vh; overflow-y:auto; }
.modal h3 { margin-bottom:20px; font-size:18px; }
.modal .form-row { margin-bottom:14px; }
.modal .form-row label { display:block; font-size:12px; font-weight:600; color:#555; margin-bottom:4px; }
.modal .form-row input, .modal .form-row select { width:100%; padding:8px 12px; border:1px solid #ddd; border-radius:6px; font-size:14px; }
.modal-actions { display:flex; gap:10px; margin-top:20px; justify-content:flex-end; }
.btn-cancel { background:#eee; color:#333; }

/* ── Loading ── */
.loading { text-align:center; padding:40px; color:#888; }
.spinner { display:inline-block; width:32px; height:32px; border:3px solid #e0e0e0; border-top-color:#e94560; border-radius:50%; animation:spin 0.8s linear infinite; }
@keyframes spin { to { transform:rotate(360deg); } }

/* ── Responsive: tablet (≤1024px) ── */
@media (max-width: 1024px) {
  .stats { grid-template-columns:repeat(2, 1fr) !important; padding:14px 16px 0 !important; gap:10px; }
  .pulse-strip { margin:12px 16px 0; padding:10px 14px; gap:12px; flex-direction:column; align-items:flex-start; }
  .pulse-strip .pulse-feed { white-space:normal; max-height:60px; overflow-y:auto; }
  .topbar { padding:10px 16px; }
  .content { padding:0 16px 16px; }
  .section { padding:16px; }
}

/* ── Responsive: phone (≤768px) ── */
@media (max-width: 768px) {
  body { font-size:14px; }
  /* Topbar: stack name vs. controls; hide change-password text */
  .topbar { padding:8px 12px; flex-wrap:wrap; gap:6px; }
  .topbar h1 { font-size:16px; }
  .topbar-right { gap:8px; }
  .topbar-right a { display:none; }   /* hide "Change Password" link on phone */
  #aiSearchWrap { display:none; }     /* hide search bar on phone — too cramped */
  .topbar-user { font-size:12px; max-width:80px; overflow:hidden; text-overflow:ellipsis; white-space:nowrap; }
  /* Bell dropdown narrower on phone */
  #bellDropdown { width:calc(100vw - 24px) !important; right:-12px !important; }
  /* Stat cards: 1 column */
  .stats { grid-template-columns:1fr !important; padding:10px 12px 0 !important; gap:8px; }
  .stat-card { padding:14px 16px; }
  .stat-card .value { font-size:24px; }
  /* Pulse strip more compact */
  .pulse-strip { margin:10px 12px 0; padding:8px 12px; gap:10px; border-radius:10px; }
  .pulse-strip .pulse-stat { padding-left:10px; border-left-width:1px; }
  .pulse-strip .pulse-stat .num { font-size:15px; }
  /* Tabs scroll horizontally instead of wrapping */
  .tabs { padding:0 24px; }
  .tabs-arrow { width:24px; font-size:16px; }
  .tabs-arrow.show { opacity:1 !important; }  /* always visible on mobile (no hover) */
  .tab { padding:9px 14px; font-size:12px; }
  .tabgroup { padding:10px 14px; font-size:14px; }  /* v623 — keep the bigger desktop bar compact on phones */
  /* Toolbar stacks vertically */
  .toolbar { flex-direction:column; align-items:stretch; gap:8px; }
  .toolbar input, .toolbar select { width:100% !important; }
  /* Quick-action button row — wrap, smaller */
  .quick-actions { padding:6px 12px 0; gap:6px; }
  .quick-actions .btn-sm { padding:6px 10px; font-size:11px; }
  /* Tables scroll horizontally */
  .table-wrap { overflow-x:auto; -webkit-overflow-scrolling:touch; }
  table { font-size:12px; min-width:600px; }
  th, td { padding:8px 10px; }
  /* Section padding tighter */
  .section { padding:14px; border-radius:10px; }
  .section h2 { font-size:16px; }
  /* Modals: full width on phone with margin */
  .modal { padding:18px; max-width:calc(100vw - 24px) !important; max-height:calc(100vh - 24px); }
  .modal-content { max-width:calc(100vw - 24px) !important; padding:16px !important; }
  /* Form rows stack on phone */
  .form-row[style*="grid-template-columns"] { grid-template-columns:1fr !important; }
  /* Larger touch targets for buttons */
  .btn { min-height:36px; padding:8px 14px; }
  .btn-sm { min-height:32px; padding:6px 12px; font-size:12px; }
  /* Hide cashflow inner grid columns for very small */
  .stat-card[style*="grid-template-columns"] { grid-template-columns:1fr 1fr !important; }
}

/* ── Tiny phones (≤375px) ── */
@media (max-width: 375px) {
  .pulse-strip .pulse-label { font-size:11px; }
  .pulse-strip .pulse-stat .num { font-size:14px; }
  .pulse-strip .pulse-stat .lab { font-size:9px; }
  .stat-card .value { font-size:22px; }
  .stat-card .label { font-size:10px; }
  .topbar h1 { font-size:14px; }
  .btn-logout { padding:5px 8px; font-size:11px; }
}

/* ══════════════════════════════════════════════════════════
   MOBILE BOTTOM NAVIGATION + MOBILE UX IMPROVEMENTS (v463)
   Targets ≤768px — desktop layout unchanged above 768px
   ══════════════════════════════════════════════════════════ */
.mobile-bottom-nav { display:none; }
.mobile-more-sheet { display:none; }

@media (max-width: 768px) {
  /* Hide desktop tab bar — replaced by bottom nav */
  .tabs-wrap { display:none !important; }

  /* Bottom fixed nav bar */
  .mobile-bottom-nav {
    display:flex;
    position:fixed;
    bottom:0; left:0; right:0;
    height:62px;
    background:#1a1a2e;
    border-top:1px solid rgba(255,255,255,.12);
    z-index:9999;
    padding-bottom:env(safe-area-inset-bottom,0px);
    box-shadow:0 -4px 20px rgba(0,0,0,.35);
  }
  .mnav-btn {
    flex:1;
    display:flex;
    flex-direction:column;
    align-items:center;
    justify-content:center;
    gap:3px;
    background:none;
    border:none;
    color:rgba(255,255,255,.45);
    font-size:10px;
    font-family:Inter,-apple-system,sans-serif;
    font-weight:500;
    cursor:pointer;
    padding:6px 2px;
    transition:color .15s;
    -webkit-tap-highlight-color:transparent;
  }
  .mnav-btn.active { color:#e94560; }
  .mnav-btn svg { width:22px; height:22px; stroke-width:1.8; }
  .mnav-btn.mnav-center {
    background:#e94560;
    border-radius:50%;
    width:46px; height:46px;
    margin-top:-10px;
    padding:0;
    flex:none;
    margin-left:auto; margin-right:auto;
    box-shadow:0 4px 16px rgba(233,69,96,.5);
    color:#fff;
    align-self:flex-start;
  }
  .mnav-btn.mnav-center svg { width:24px; height:24px; }

  /* Push page content above the fixed nav */
  .content { padding-bottom:74px !important; }
  body > .pulse-strip { margin-bottom:0; }

  /* Stat cards — 2 per row (denser, more info at a glance) */
  .stats { grid-template-columns:repeat(2,1fr) !important; gap:10px !important; padding:10px 12px !important; }
  .stat-card { padding:12px 10px !important; }
  .stat-card .value { font-size:20px !important; }
  .stat-card .label { font-size:10px !important; }

  /* Compact topbar */
  .topbar { padding:8px 12px !important; min-height:unset !important; }
  .topbar h1 { font-size:15px !important; }

  /* Quick-actions row — horizontal scroll, no wrap */
  .quick-actions {
    flex-wrap:nowrap !important;
    overflow-x:auto !important;
    -webkit-overflow-scrolling:touch;
    padding:6px 10px !important;
    gap:6px !important;
    scrollbar-width:none;
  }
  .quick-actions::-webkit-scrollbar { display:none; }
  .quick-actions a { white-space:nowrap; flex-shrink:0; }

  /* Tables — keep horizontal scroll, bigger tap targets */
  table td, table th { padding:9px 8px !important; font-size:12px !important; }

  /* Toolbar filters — single column on mobile */
  .toolbar { flex-direction:column !important; gap:6px !important; }
  .toolbar input, .toolbar select { width:100% !important; box-sizing:border-box; }

  /* Modals — full width minus small margin */
  .modal-overlay .modal, .modal { max-width:calc(100vw - 16px) !important; width:100% !important; margin:8px !important; }

  /* More-sheet overlay */
  .mobile-more-sheet {
    display:none;
    position:fixed;
    bottom:62px; left:0; right:0;
    background:#1e2040;
    border-top:1px solid rgba(255,255,255,.1);
    border-radius:16px 16px 0 0;
    z-index:9998;
    padding:16px 12px 8px;
    box-shadow:0 -8px 32px rgba(0,0,0,.4);
    max-height:60vh;
    overflow-y:auto;
  }
  .mobile-more-sheet.open { display:block; }
  .mobile-more-sheet-title {
    font-size:11px; font-weight:700; color:rgba(255,255,255,.4);
    text-transform:uppercase; letter-spacing:.08em;
    margin-bottom:10px; padding:0 4px;
  }
  .mobile-more-grid {
    display:grid;
    grid-template-columns:repeat(4,1fr);
    gap:8px;
  }
  .mobile-more-item {
    display:flex; flex-direction:column; align-items:center;
    gap:5px; padding:10px 4px;
    background:rgba(255,255,255,.05);
    border-radius:12px;
    color:#e2e8f0;
    font-size:10px; font-weight:500;
    cursor:pointer; border:none;
    -webkit-tap-highlight-color:transparent;
    transition:background .15s;
  }
  .mobile-more-item:active { background:rgba(233,69,96,.15); }
  .mobile-more-item .mmi-icon { font-size:20px; }
}

/* ── Analytics KPI Dashboard ── */
.akpi-grid { display:grid; grid-template-columns:repeat(4,1fr); gap:16px; margin-bottom:24px; }
.akpi-card { background:#fff; border-radius:12px; padding:18px 16px; border-left:4px solid #94a3b8; box-shadow:0 2px 8px rgba(0,0,0,.06); }
.akpi-label { font-size:11px; color:#64748b; font-weight:700; text-transform:uppercase; letter-spacing:.05em; margin-bottom:6px; }
.akpi-value { font-size:28px; font-weight:800; color:#1a1a2e; line-height:1.1; }
.akpi-value.blue  { color:#2563eb; }
.akpi-value.green { color:#16a34a; }
.akpi-value.red   { color:#e94560; }
.akpi-value.amber { color:#d97706; }
.akpi-sub { font-size:11px; color:#94a3b8; margin-top:5px; }
.akpi-charts { display:grid; grid-template-columns:1fr 1fr; gap:20px; margin-bottom:24px; }
.akpi-chart-box { background:#fff; border-radius:12px; padding:18px; box-shadow:0 2px 8px rgba(0,0,0,.06); position:relative; min-height:240px; }
.akpi-chart-title { margin:0 0 14px; font-size:13px; font-weight:700; color:#374151; }
.akpi-table-wrap { background:#fff; border-radius:12px; padding:20px; box-shadow:0 2px 8px rgba(0,0,0,.06); }
@media (max-width:900px) { .akpi-grid { grid-template-columns:repeat(2,1fr); } .akpi-charts { grid-template-columns:1fr; } }
@media (max-width:480px) { .akpi-value { font-size:22px; } .akpi-card { padding:12px; } }

/* ── Broker / Insurer Card Grid ── */
.entity-card {
  background:#fff; border-radius:14px; padding:18px;
  box-shadow:0 2px 12px rgba(0,0,0,.07); border:1px solid #e5e7eb;
  cursor:pointer; transition:box-shadow .18s, transform .18s;
}
.entity-card:hover { box-shadow:0 6px 24px rgba(0,0,0,.13); transform:translateY(-2px); }
.ec-header { display:flex; justify-content:space-between; align-items:flex-start; margin-bottom:12px; }
.ec-name { font-size:15px; font-weight:700; color:#1a1a2e; }
.ec-sub  { font-size:11px; color:#9ca3af; margin-top:2px; }
.ec-badge { font-size:10px; font-weight:600; background:#f3f0ff; color:#7c3aed;
            padding:2px 8px; border-radius:4px; }
.ec-stats { display:grid; grid-template-columns:1fr 1fr; gap:8px; margin-bottom:12px; }
.ec-stat  { border-radius:8px; padding:8px 10px; }
.ec-stat .ec-stat-lbl { font-size:10px; text-transform:uppercase; font-weight:600; letter-spacing:.5px; }
.ec-stat .ec-stat-val { font-size:16px; font-weight:700; margin-top:2px; }
.ec-bar-wrap { margin-bottom:10px; }
.ec-bar-row { display:flex; justify-content:space-between; font-size:11px; color:#9ca3af; margin-bottom:4px; }
.ec-bar-bg  { background:#e5e7eb; border-radius:4px; height:7px; }
.ec-bar-fill { border-radius:4px; height:7px; transition:width .3s; }
.ec-aging   { display:flex; flex-wrap:wrap; gap:4px; margin-bottom:8px; }
.ec-aging-pill { padding:2px 8px; border-radius:12px; font-size:11px; font-weight:600; cursor:pointer; }
.ec-kite  { display:flex; justify-content:space-between; padding:6px 10px;
            background:#f3f0ff; border-radius:6px; font-size:12px; margin-bottom:8px; }
.ec-actions { display:flex; gap:6px; padding-top:10px; border-top:1px solid #f0f0f0; }
/* Detail panel */
.brk-detail-header { display:flex; align-items:center; gap:12px; margin-bottom:16px;
                      padding-bottom:14px; border-bottom:2px solid #e5e7eb; }
.brk-bucket-pills { display:flex; gap:6px; flex-wrap:wrap; margin-bottom:14px; }
.brk-bucket-pill  { padding:5px 14px; border-radius:20px; font-size:12px; font-weight:600;
                    cursor:pointer; border:2px solid transparent; transition:all .15s; }
.brk-bucket-pill.active { border-color:#1a1a2e; }

/* ═══ Left-sidebar nav PREVIEW (opt-in via body.nav-sidebar) — default stays the top-bar ═══ */
/* CSS-only: flips .content into a [sidebar | main] flex row; no DOM moves, no logic change. */
body.nav-sidebar .content { display:flex; align-items:flex-start; gap:0; padding:0; }
body.nav-sidebar .tabs-wrap { width:216px; flex-shrink:0; margin:0; border-bottom:none; border-right:1px solid #e5e7eb;
  background:#fafafb; align-self:stretch; position:sticky; top:var(--topbar-h,74px); max-height:calc(100vh - var(--topbar-h,74px));
  overflow-y:auto; padding:10px 0; }
body.nav-sidebar .tabs-arrow { display:none !important; }
body.nav-sidebar .tabs { flex-direction:column; overflow:visible; white-space:normal; padding:0; gap:1px; cursor:default; align-items:stretch; }
body.nav-sidebar #mainTabs { flex-direction:column; gap:2px; overflow:visible !important; align-items:stretch; }
body.nav-sidebar .tabgroup-wrap { width:100%; position:static; flex-shrink:0; }
body.nav-sidebar .tabgroup { width:100%; justify-content:flex-start; border-bottom:none !important; margin:0;
  padding:9px 18px; border-radius:0; border-left:3px solid transparent; }
body.nav-sidebar .tabgroup:hover { border-bottom:none; transform:none; box-shadow:none; }
body.nav-sidebar .tabgroup.active { border-bottom:none !important; border-left-color:#e94560; background:rgba(233,69,96,0.07); }
body.nav-sidebar .tabgroup .caret { margin-left:auto; }
body.nav-sidebar .tabgroup-menu { position:static; display:none; box-shadow:none; border:none; border-radius:0;
  min-width:0; padding:1px 0 6px; background:transparent; z-index:auto; }
body.nav-sidebar .tabgroup-menu.open { display:block; }
body.nav-sidebar .tabgroup-menu .tab { padding:7px 18px 7px 36px; border-radius:0; }
body.nav-sidebar .section.tab-content { flex:1 1 auto; min-width:0; padding:16px 22px; }
@media (max-width:820px) {
  body.nav-sidebar .content { display:block; padding:0 16px 16px; }
  body.nav-sidebar .tabs-wrap { width:auto; position:static; max-height:none; border-right:none; border-bottom:2px solid #e0e0e0; }
}
