<style>
  :root {
    --navy:     #0D1B2A;
    --navy2:    #1A2E44;
    --navy3:    #243B55;
    --accent:   #E8A020;
    --accent2:  #F5C55A;
    --teal:     #00B4A6;
    --red:      #E05555;
    --amber:    #F59E0B;
    --green:    #10B981;
    --blue:     #3B82F6;
    --text:     #E8EDF2;
    --text1:    #E8EDF2;
    --text2:    #8FA3B8;
    --text3:    #7494AE;
    --surface:  #243B55;
    --surface2: #1A2E44;
    --border:   rgba(255,255,255,0.08);
    --card:     rgba(255,255,255,0.04);
    --card2:    rgba(255,255,255,0.07);
    --hover:    rgba(255,255,255,0.06);
    --shadow:   0 4px 24px rgba(0,0,0,0.4);
    --amber-text: #F59E0B;
    --link:     #60A5FA;
  }

  /* ── Safewise light theme ── */
  [data-theme="safewise"] {
    --navy:     #ffffff;
    --navy2:    #f5f7f5;
    --navy3:    #eaf0ea;
    --accent:   #3d8f30;
    --accent2:  #57b848;
    --teal:     #2e7d32;
    --red:      #c0392b;
    --amber:    #d97706;
    --green:    #3d8f30;
    --blue:     #1d6fb8;
    --text:     #1a2e1a;
    --text1:    #1a2e1a;
    --text2:    #3a5c35;
    --text3:    #6b8f68;
    --surface:  #eef4ee;
    --surface2: #e4ede4;
    --border:   rgba(0,0,0,0.12);
    --card:     rgba(0,0,0,0.02);
    --card2:    rgba(0,0,0,0.04);
    --hover:    rgba(61,143,48,0.07);
    --shadow:   0 4px 24px rgba(0,0,0,0.10);
    --amber-text: #d97706;
    --link:     #1d6fb8;
  }

  * { margin:0; padding:0; box-sizing:border-box; }

  body {
    font-family: 'DM Sans', sans-serif;
    background: var(--navy);
    color: var(--text);
    min-height: 100vh;
    overflow-x: hidden;
  }

  /* ── LAYOUT ── */
  #app { display: flex; height: 100vh; overflow: hidden; }

  /* ── SIDEBAR ── */
  #sidebar {
    width: 240px;
    min-width: 240px;
    background: var(--navy2);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    z-index: 10;
  }

  .logo {
    padding: 24px 20px 20px;
    border-bottom: 1px solid var(--border);
  }
  .logo-mark {
    font-size: 20px;
    font-weight: 700;
    color: var(--accent);
    letter-spacing: -0.5px;
  }
  .logo-sub {
    font-size: 10px;
    color: var(--text3);
    text-transform: uppercase;
    letter-spacing: 2px;
    margin-top: 2px;
  }

  .nav-section-label {
    font-size: 10px;
    font-weight: 600;
    color: var(--text3);
    text-transform: uppercase;
    letter-spacing: 1.5px;
    padding: 16px 20px 6px;
  }

  .nav-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 20px;
    cursor: pointer;
    border-radius: 0;
    font-size: 14px;
    font-weight: 500;
    color: var(--text2);
    transition: all 0.15s;
    border-left: 3px solid transparent;
    position: relative;
  }
  .nav-item:hover { background: var(--hover); color: var(--text); }
  .nav-item.active {
    background: rgba(232,160,32,0.1);
    color: var(--accent);
    border-left-color: var(--accent);
  }
  .nav-item .icon { font-size: 16px; width: 20px; text-align: center; }
  .nav-badge {
    margin-left: auto;
    background: var(--red);
    color: white;
    font-size: 10px;
    font-weight: 700;
    padding: 2px 6px;
    border-radius: 10px;
    min-width: 20px;
    text-align: center;
  }

  .sidebar-footer {
    margin-top: auto;
    padding: 16px 20px;
    border-top: 1px solid var(--border);
  }
  .user-pill {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 10px;
    border-radius: 8px;
    background: var(--card);
    cursor: pointer;
  }
  .user-avatar {
    width: 24px; height: 24px;
    border-radius: 50%;
    background: var(--accent);
    display: flex; align-items: center; justify-content: center;
    font-size: 11px; font-weight: 700; color: var(--navy);
    flex-shrink: 0;
  }
  .user-info { display: flex; align-items: baseline; gap: 5px; }
  .user-name { font-size: 13px; font-weight: 600; }
  .user-role { font-size: 11px; color: var(--text3); }

  /* ── MAIN CONTENT ── */
  #main {
    flex: 1;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
  }

  .topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 28px;
    border-bottom: 1px solid var(--border);
    background: var(--navy);
    position: sticky;
    top: 0;
    z-index: 5;
  }
  .topbar-title { font-size: 18px; font-weight: 700; }
.topbar-actions { display: flex; gap: 10px; align-items: center; }

  .btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 8px 16px;
    border-radius: 8px;
    font-family: inherit;
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    border: none;
    transition: all 0.15s;
  }
  .btn-primary { background: var(--accent); color: var(--navy); }
  .btn-primary:hover { background: var(--accent2); }
  .btn-ghost {
    background: var(--card);
    color: var(--text2);
    border: 1px solid var(--border);
  }
  .btn-ghost:hover { background: var(--card2); color: var(--text); }
  .btn-danger { background: rgba(224,85,85,0.15); color: var(--red); border: 1px solid rgba(224,85,85,0.3); }
  .btn-danger:hover { background: rgba(224,85,85,0.25); }
  .btn-sm { padding: 5px 10px; font-size: 12px; }

  #toast {
    position: fixed; bottom: 28px; left: 50%; transform: translateX(-50%) translateY(12px);
    background: var(--navy2); border: 1px solid var(--border); border-radius: 10px;
    padding: 11px 20px 11px 16px; font-size: 13px; color: var(--text); white-space: nowrap;
    box-shadow: 0 4px 24px rgba(0,0,0,0.4); opacity: 0; pointer-events: none;
    transition: opacity 0.2s, transform 0.2s; z-index: 9999;
    border-left: 4px solid var(--green);
  }
  #toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
  #toast.toast-error   { border-left-color: var(--red);   }
  #toast.toast-warning { border-left-color: var(--amber); }
  #toast.toast-info    { border-left-color: var(--blue);  }

  .seg-toggle { display: inline-flex; border: 1px solid var(--border); border-radius: 8px; overflow: hidden; }
  .seg-toggle button {
    background: transparent; border: none; color: var(--text2);
    padding: 6px 14px; font-size: 13px; font-weight: 500; cursor: pointer;
    transition: all 0.15s; white-space: nowrap;
  }
  .seg-toggle button + button { border-left: 1px solid var(--border); }
  .seg-toggle button:hover:not(.seg-active) { background: var(--card2); color: var(--text); }
  .seg-toggle button.seg-active { background: var(--accent); color: var(--navy); font-weight: 700; }

  .content { padding: 24px 28px; flex: 1; }

  /* ── SEARCH + FILTER BAR ── */
  .search-bar {
    display: flex;
    gap: 10px;
    margin-bottom: 20px;
    align-items: center;
    flex-wrap: wrap;
  }
  .search-wrap {
    position: relative;
    flex: 1;
    min-width: 240px;
  }
  .search-wrap .icon {
    position: absolute;
    left: 12px;
    top: 50%;
    transform: translateY(-50%);
    color: var(--text3);
    font-size: 15px;
  }
  input[type="text"], input[type="email"], input[type="tel"], input[type="date"], select, textarea {
    background: var(--card);
    border: 1px solid var(--border);
    color: var(--text);
    font-family: inherit;
    font-size: 13px;
    border-radius: 8px;
    padding: 9px 12px;
    width: 100%;
    transition: border-color 0.15s;
    outline: none;
  }
  input:focus, select:focus, textarea:focus {
    border-color: var(--accent);
    background: var(--card2);
  }
  .search-input { padding-left: 36px !important; }
  select option { background: var(--navy2); color: var(--text); }

  /* ── STAT CARDS ── */
  .stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: 14px;
    margin-bottom: 24px;
  }
  .stat-card {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 18px;
    display: flex;
    flex-direction: column;
    gap: 6px;
    transition: all 0.2s;
  }
  .stat-card:hover { background: var(--card2); border-color: rgba(255,255,255,0.15); }
  .stat-card.clickable { cursor: pointer; }
  .stat-card.clickable:hover { border-color: var(--green); }
  .stat-label { font-size: 11px; font-weight: 600; color: var(--text3); text-transform: uppercase; letter-spacing: 1px; }
  .stat-value { font-size: 28px; font-weight: 700; line-height: 1; }
  .stat-sub { font-size: 12px; color: var(--text2); }
  .stat-accent { color: var(--accent); }
  .stat-teal { color: var(--teal); }
  .stat-red { color: var(--red); }
  .stat-green { color: var(--green); }
  .stat-blue { color: var(--blue); }

  /* ── TABLE ── */
  .table-wrap {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: 12px;
    overflow: hidden;
  }
  .table-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 14px 18px;
    border-bottom: 1px solid var(--border);
  }
  .table-head-title { font-size: 14px; font-weight: 700; }
  .table-count { font-size: 12px; color: var(--text3); }

  table { width: 100%; border-collapse: collapse; }
  th {
    padding: 10px 14px;
    text-align: left;
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.8px;
    color: var(--text3);
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    white-space: normal;
    cursor: pointer;
    min-width: 60px;
  }
  th:hover { color: var(--text2); }
  td {
    padding: 11px 14px;
    font-size: 13px;
    border-bottom: 1px solid var(--border);
    vertical-align: middle;
  }
  tr:last-child td { border-bottom: none; }
  tr:hover td { background: var(--hover); }
  tr:active td { background: rgba(255,255,255,0.10); }
  tr.mm-selected td { background: rgba(61,143,48,0.25) !important; }
  tr.mm-selected:hover td { background: rgba(61,143,48,0.35) !important; }
  tr { cursor: pointer; }

  /* ── Table density ── */
  [data-density="compact"] td { padding: 6px 14px; font-size: 12px; }
  [data-density="compact"] .badge { padding: 1px 5px; font-size: 10px; }

  .badge {
    display: inline-flex;
    align-items: center;
    padding: 3px 8px;
    border-radius: 20px;
    font-size: 11px;
    font-weight: 600;
    white-space: nowrap;
  }
  .badge-green  { background: rgba(16,185,129,0.15); color: var(--green); }
  .badge-red    { background: rgba(224,85,85,0.15);  color: var(--red); }
  .badge-amber  { background: rgba(245,158,11,0.15); color: var(--amber); }
  .badge-blue   { background: rgba(59,130,246,0.15); color: var(--blue); }
  .badge-grey   { background: rgba(255,255,255,0.08); color: var(--text3); }
  .badge-teal   { background: rgba(0,180,166,0.15);  color: var(--teal); }
  .badge-purple { background: rgba(139,92,246,0.15); color: #8b5cf6; }

  /* ── SERVICE COVERAGE MATRIX ── */
  #coverage-drawer-backdrop { position:fixed;inset:0;background:rgba(0,0,0,0.3);z-index:299;display:none; }
  #coverage-drawer-backdrop.open { display:block; }
  #coverage-drawer { position:fixed;top:0;right:0;width:380px;max-width:95vw;height:100%;background:var(--surface);border-left:1px solid var(--border);box-shadow:-4px 0 24px rgba(0,0,0,0.18);z-index:300;transform:translateX(100%);transition:transform 0.22s ease;overflow-y:auto;display:flex;flex-direction:column; }
  #coverage-drawer.open { transform:translateX(0); }
  .cov-card { border:1px solid var(--border);border-radius:var(--border-radius-md);padding:10px 12px;margin-bottom:6px; }
  .cov-card.cov-active { border-color:var(--green);background:rgba(61,143,48,0.06); }
  .cov-card.cov-gap { background:var(--surface2); }
  .cov-card-title { font-size:12px;font-weight:600; }
  .cov-card.cov-active .cov-card-title { color:var(--green); }
  .cov-card.cov-gap .cov-card-title { color:var(--text2); }
  .cov-card-sub { font-size:11px;color:var(--text3);margin-top:3px;line-height:1.4; }
  .cov-ytd-track { height:6px;background:var(--surface2);border-radius:3px;overflow:hidden;margin:4px 0 2px; }
  .cov-ytd-fill { height:100%;border-radius:3px; }
  .gap-pill { font-size:11px; padding:3px 10px; border-radius:20px; border:1px solid var(--border); background:var(--surface); color:var(--text2); cursor:pointer; user-select:none; }
  .gap-pill.active { background:rgba(61,143,48,0.12); border-color:var(--green); color:var(--green); font-weight:600; }
  .svc-dot { display:inline-flex;align-items:center;justify-content:center;width:20px;height:20px;border-radius:50%;font-size:9px;font-weight:600; }
  .svc-dot-y { background:#15803d;color:#fff;border:none; }
  .svc-dot-n { background:var(--surface2);color:var(--text3);border:0.5px solid var(--border);opacity:0.4; }
  .svc-gap { display:inline-flex;align-items:center;justify-content:center;min-width:44px;height:20px;border-radius:10px;font-size:9px;font-weight:700;padding:0 5px;cursor:pointer;user-select:none; }
  .svc-gap-needed { background:#dc2626;color:#fff;border:none; }
  .svc-gap-dbo    { background:#d97706;color:#fff;border:none; }
  .svc-gap-dbt    { background:#7c3aed;color:#fff;border:none; }
  .svc-gap-na     { background:#374151;color:#fff;border:none; }
  .svc-gap-unset  { background:var(--surface2);color:var(--text3);border:0.5px solid var(--border);opacity:0.4; }
  .gap-pill.active[data-status="needed"] { background:rgba(220,38,38,0.1);border-color:#dc2626;color:#dc2626; }
  .gap-pill.active[data-status="dbo"]    { background:rgba(217,119,6,0.1);border-color:#d97706;color:#b45309; }
  .gap-pill.active[data-status="dbt"]    { background:rgba(124,58,237,0.1);border-color:#7c3aed;color:#6d28d9; }
  .gap-pill.active[data-status="na"]     { background:rgba(55,65,81,0.1);border-color:#374151;color:#374151; }
  .gap-badge { display:inline-block;font-size:10px;padding:1px 6px;border-radius:8px;font-weight:500; }
  .gap-badge-0 { background:#eaf3de;color:#3b6d11; }
  .gap-badge-1 { background:#fef3c7;color:#633806; }
  .gap-badge-3 { background:#fee2e2;color:#791f1f; }

  /* ── MOBILE RESPONSIVE ── */
  #sidebar-toggle { display:none; background:none; border:none; color:var(--text); cursor:pointer; padding:4px; font-size:22px; line-height:1; flex-shrink:0; }
  #sidebar-backdrop { display:none; position:fixed; inset:0; background:rgba(0,0,0,0.65); z-index:199; }

  /* ── Collapsible sidebar ── */
  #sidebar-collapse-btn { background:none;border:none;cursor:pointer;color:var(--text3);font-size:16px;padding:4px 6px;border-radius:5px;line-height:1;transition:color 0.15s; }
  #sidebar-collapse-btn:hover { color:var(--text); }
  #sidebar.collapsed { width:56px; min-width:56px; }
  #sidebar.collapsed .logo-text { display:none !important; }
  [data-theme="safewise"] .logo { background: #ffffff; }
  #sidebar.collapsed .nav-label { display:none; }
  #sidebar.collapsed .nav-section-label { display:none; }
  #sidebar.collapsed .nav-badge { display:none; }
  #sidebar.collapsed .user-info { display:none; }
  #sidebar.collapsed .user-pill { justify-content:center; padding:8px; }
  #sidebar.collapsed .nav-item { justify-content:center; padding:10px 0; border-left:3px solid transparent; position:relative; }
  #sidebar.collapsed .nav-item .icon { width:auto; font-size:18px; }
  #sidebar.collapsed .logo { padding:14px 0; display:flex; justify-content:center; align-items:center; gap:0; }
  #sidebar.collapsed .sidebar-footer { padding:12px 8px; }
  #sidebar { transition: width 0.2s ease, min-width 0.2s ease; }

  /* Scroll shadow elements — injected by JS, only active on tablet/mobile */
  .scroll-fade-r { display:none; }
  .scroll-arrow  { display:none; }

  /* ── DESKTOP/LAPTOP (> 1024px): trim clients table to avoid horizontal scroll ── */
  @media (min-width: 1025px) {
    /* Clients table: hide Contact(2), Total Value(13), HR Advisor(15) */
    #client-tbody td:nth-child(2),  #thead-clients th:nth-child(2),
    #client-tbody td:nth-child(14), #thead-clients th:nth-child(14),
    #client-tbody td:nth-child(16), #thead-clients th:nth-child(16) { display: none; }
    /* Narrow the 7 service dot columns (4-10) */
    #thead-clients th:nth-child(4),  #client-tbody td:nth-child(4),
    #thead-clients th:nth-child(5),  #client-tbody td:nth-child(5),
    #thead-clients th:nth-child(6),  #client-tbody td:nth-child(6),
    #thead-clients th:nth-child(7),  #client-tbody td:nth-child(7),
    #thead-clients th:nth-child(8),  #client-tbody td:nth-child(8),
    #thead-clients th:nth-child(9),  #client-tbody td:nth-child(9),
    #thead-clients th:nth-child(10), #client-tbody td:nth-child(10) { width: 40px; }
    /* Mail merge mode: checkbox becomes col 1, everything shifts +1 */
    #client-tbody.mm-active td:nth-child(3),  #thead-clients.mm-active th:nth-child(3),
    #client-tbody.mm-active td:nth-child(15), #thead-clients.mm-active th:nth-child(15),
    #client-tbody.mm-active td:nth-child(17), #thead-clients.mm-active th:nth-child(17) { display: none; }
    #client-tbody.mm-active td:nth-child(2),  #thead-clients.mm-active th:nth-child(2)  { display: table-cell; }
  }

  /* ── TABLET (641px – 1024px): sidebar visible, adjusted spacing ── */
  @media (min-width: 641px) and (max-width: 1024px) {
    #sidebar { width: 200px; min-width: 200px; }
    .content { padding: 18px 20px; }
    .topbar { padding: 12px 20px; }
    .stats-grid { grid-template-columns: repeat(3, 1fr); gap: 12px; }

    /* Scroll shadows on tablet */
    .table-wrap { position: relative; }
    .scroll-fade-r {
      display: block; position: absolute;
      top: 0; right: 0; bottom: 0; width: 56px;
      background: linear-gradient(to right, transparent, rgba(13,27,42,0.92));
      pointer-events: none; z-index: 3; opacity: 0; transition: opacity 0.2s;
    }
    .scroll-arrow {
      display: block; position: absolute;
      top: 50%; right: 8px; transform: translateY(-50%);
      background: var(--accent); color: var(--navy);
      font-size: 14px; font-weight: 800;
      width: 26px; height: 26px; border-radius: 50%;
      text-align: center; line-height: 26px;
      pointer-events: none; z-index: 4; opacity: 0; transition: opacity 0.2s;
    }
    .table-wrap.can-scroll-r .scroll-fade-r,
    .table-wrap.can-scroll-r .scroll-arrow { opacity: 1; }

    /* Force table cells to not wrap — ensures tables overflow so the scroll indicator shows */
    td { white-space: nowrap; max-width: 220px; overflow: hidden; text-overflow: ellipsis; }
  }

  /* ── MOBILE (≤ 640px): hamburger menu, stacked layout ── */
  @media (max-width: 640px) {
    /* Sidebar as slide-in overlay */
    #sidebar {
      position: fixed;
      top: 0; left: 0; bottom: 0;
      transform: translateX(-100%);
      transition: transform 0.25s ease;
      z-index: 200;
    }
    #sidebar.mob-open { transform: translateX(0); }
    #sidebar-backdrop.mob-open { display: block; }
    #sidebar-toggle { display: flex; }

    /* Layout */
    #app { overflow: auto; }
    #main { width: 100%; min-width: 0; }

    /* Topbar */
    .topbar { padding: 10px 14px; gap: 8px; flex-wrap: wrap; }
    .topbar-title { font-size: 15px; }
    .topbar-actions { gap: 6px; flex-wrap: wrap; }
    .topbar-actions .btn { padding: 7px 11px; font-size: 12px; }

    /* Content */
    .content { padding: 14px; }

    /* Login */
    .login-card { width: calc(100% - 32px); padding: 32px 24px; border-radius: 16px; }

    /* Modals — sheet from bottom */
    .modal-overlay { padding: 0; align-items: flex-end; }
    .modal { border-radius: 20px 20px 0 0; max-height: 92vh; overflow-y: auto; max-width: 100%; }
    .modal-body { padding: 16px; }
    .modal-header { padding: 16px 18px; }
    .modal-footer { padding: 12px 16px; }

    /* Forms */
    .form-grid { grid-template-columns: 1fr !important; }
    .form-group.full { grid-column: 1 !important; }

    /* Stats */
    .stats-grid { grid-template-columns: repeat(2, 1fr); gap: 10px; }
    .stat-value { font-size: 22px; }

    /* Tables */
    .table-wrap { border-radius: 8px; position: relative; }
    td, th { padding: 9px 10px; font-size: 12px; }
    td { white-space: nowrap; max-width: 220px; overflow: hidden; text-overflow: ellipsis; }

    /* Detail tabs */
    .detail-tab { padding: 8px 10px; font-size: 12px; }

    /* Search bar — keep as wrapping row, search full-width, selects pair up */
    .search-bar { flex-direction: row; flex-wrap: wrap; gap: 8px; margin-bottom: 12px; }
    .search-wrap { flex: 0 0 100%; min-width: 0; }
    .search-bar select { flex: 1 1 calc(50% - 4px); min-width: 0; width: auto; font-size: 13px; }
    .search-bar .filter-chip { font-size: 12px; padding: 5px 10px; }

    /* Seg toggle */
    .seg-toggle button { padding: 6px 10px; font-size: 12px; }

    /* Calendar */
    .cal-appt-chip { font-size: 10px; }
    .cal-dow-header { font-size: 9px; padding: 5px 2px; }
    .cal-day-num { font-size: 11px; }
    .cal-controls { padding: 8px 10px; gap: 6px; }
    .cal-legend { padding: 6px 10px; gap: 8px; }

    /* Guide page */
    .guide-section-title { font-size: 14px; padding: 12px 14px; }
    .guide-section-body { padding: 12px 14px; }

    /* Scroll shadows */
    .scroll-fade-r {
      display: block; position: absolute;
      top: 0; right: 0; bottom: 0; width: 56px;
      background: linear-gradient(to right, transparent, rgba(13,27,42,0.92));
      pointer-events: none; z-index: 3; opacity: 0; transition: opacity 0.2s;
    }
    .scroll-arrow {
      display: block; position: absolute;
      top: 50%; right: 8px; transform: translateY(-50%);
      background: var(--accent); color: var(--navy);
      font-size: 14px; font-weight: 800;
      width: 26px; height: 26px; border-radius: 50%;
      text-align: center; line-height: 26px;
      pointer-events: none; z-index: 4; opacity: 0; transition: opacity 0.2s;
    }
    .table-wrap.can-scroll-r .scroll-fade-r,
    .table-wrap.can-scroll-r .scroll-arrow { opacity: 1; }

    /* Column hiding */
    /* Clients: hide Contact(2), Sector(3), YTD Value(6), Total Value(7), H&S Advisor(8), HR Advisor(9), Next Action(10) */
    #client-tbody td:nth-child(2), #thead-clients th:nth-child(2),
    #client-tbody td:nth-child(3), #thead-clients th:nth-child(3),
    #client-tbody td:nth-child(6), #thead-clients th:nth-child(6),
    #client-tbody td:nth-child(7), #thead-clients th:nth-child(7),
    #client-tbody td:nth-child(8), #thead-clients th:nth-child(8),
    #client-tbody td:nth-child(9), #thead-clients th:nth-child(9),
    #client-tbody td:nth-child(10), #thead-clients th:nth-child(10) { display: none; }
    /* Mail merge mode: checkbox is col 1, company shifts to col 2 — re-show col 2, hide shifted cols */
    #client-tbody.mm-active td:nth-child(2), #thead-clients.mm-active th:nth-child(2) { display: table-cell; }
    #client-tbody.mm-active td:nth-child(3), #thead-clients.mm-active th:nth-child(3),
    #client-tbody.mm-active td:nth-child(4), #thead-clients.mm-active th:nth-child(4),
    #client-tbody.mm-active td:nth-child(7), #thead-clients.mm-active th:nth-child(7),
    #client-tbody.mm-active td:nth-child(8), #thead-clients.mm-active th:nth-child(8),
    #client-tbody.mm-active td:nth-child(9), #thead-clients.mm-active th:nth-child(9),
    #client-tbody.mm-active td:nth-child(10), #thead-clients.mm-active th:nth-child(10),
    #client-tbody.mm-active td:nth-child(11), #thead-clients.mm-active th:nth-child(11) { display: none; }

    /* Renewals: hide Agreement End(5), Days to End(6), Value(7), Last Confirmed(8), Chased(9), Advisor(10) */
    #renewal-tbody td:nth-child(5), #thead-renewals th:nth-child(5),
    #renewal-tbody td:nth-child(6), #thead-renewals th:nth-child(6),
    #renewal-tbody td:nth-child(7), #thead-renewals th:nth-child(7),
    #renewal-tbody td:nth-child(8), #thead-renewals th:nth-child(8),
    #renewal-tbody td:nth-child(9), #thead-renewals th:nth-child(9),
    #renewal-tbody td:nth-child(10), #thead-renewals th:nth-child(10) { display: none; }

    /* Training: hide Delivery(4), Date(5), Result(7), Certificate(8), Action Status(9) */
    #training-tbody td:nth-child(4), #thead-train th:nth-child(4),
    #training-tbody td:nth-child(5), #thead-train th:nth-child(5),
    #training-tbody td:nth-child(7), #thead-train th:nth-child(7),
    #training-tbody td:nth-child(8), #thead-train th:nth-child(8),
    #training-tbody td:nth-child(9), #thead-train th:nth-child(9) { display: none; }

    /* Site Visits: hide Last Visit(3), Frequency(6), Consultant(7), Last Grade(8), Report Sent(9), Action Status(10) */
    #visit-tbody td:nth-child(3), #thead-visits th:nth-child(3),
    #visit-tbody td:nth-child(6), #thead-visits th:nth-child(6),
    #visit-tbody td:nth-child(7), #thead-visits th:nth-child(7),
    #visit-tbody td:nth-child(8), #thead-visits th:nth-child(8),
    #visit-tbody td:nth-child(9), #thead-visits th:nth-child(9),
    #visit-tbody td:nth-child(10), #thead-visits th:nth-child(10) { display: none; }
  }

  /* ── GUIDE PAGE ── */
  .guide-section { background:var(--surface); border:1px solid var(--border); border-radius:10px; margin-bottom:16px; overflow:hidden; }
  .guide-section-title { font-size:15px; font-weight:700; color:var(--text1); padding:14px 18px; background:var(--navy2); border-bottom:1px solid var(--border); }
  .guide-section-body { padding:16px 18px; font-size:13px; color:var(--text2); line-height:1.7; }
  .guide-section-body p { margin:0 0 10px; }
  .guide-section-body p:last-child { margin-bottom:0; }
  .guide-section-body ul { margin:0 0 10px; padding-left:20px; }
  .guide-section-body li { margin-bottom:5px; }
  .guide-highlight { background:rgba(61,143,48,0.08); border-left:3px solid var(--green); border-radius:0 6px 6px 0; padding:12px 14px; margin:12px 0; }

  /* ── CALENDAR ── */
  .cal-controls { display:flex; align-items:center; gap:8px; padding:12px 16px; flex-wrap:wrap; border-bottom:1px solid var(--border); background:var(--surface); }
  .cal-title { font-size:15px; font-weight:700; color:var(--text); min-width:200px; text-align:center; }
  .cal-legend { display:flex; gap:12px; flex-wrap:wrap; padding:8px 16px; border-bottom:1px solid var(--border); min-height:32px; }
  .cal-legend-item { display:flex; align-items:center; gap:5px; font-size:11px; color:var(--text2); }
  .cal-legend-dot { width:10px; height:10px; border-radius:3px; flex-shrink:0; }
  /* Week view */
  .cal-week-grid { display:flex; flex-direction:column; border-top:1px solid var(--border); height:100%; overflow-y:auto; }
  .cal-week-col { display:flex; flex-direction:row; border-bottom:1px solid var(--border); min-height:72px; flex:1; }
  .cal-week-header { padding:10px 12px; width:160px; min-width:160px; font-size:12px; font-weight:700; color:var(--text2); border-right:1px solid var(--border); background:var(--surface); display:flex; align-items:flex-start; flex-shrink:0; }
  .cal-week-header.today { color:var(--accent); }
  .cal-week-appts { padding:6px 10px; display:flex; flex-direction:row; flex-wrap:wrap; gap:6px; flex:1; align-content:flex-start; }
  .cal-appt-block { padding:6px 8px; border-radius:6px; cursor:pointer; border-left:3px solid; transition:opacity 0.15s; min-width:160px; max-width:280px; }
  .cal-appt-block:hover { opacity:0.8; }
  .cal-appt-block .ab-time { font-size:10px; font-weight:600; margin-bottom:2px; }
  .cal-appt-block .ab-client { font-size:12px; font-weight:600; color:var(--text); }
  .cal-appt-block .ab-type { font-size:10px; margin-top:1px; }
  .cal-no-appts { font-size:11px; color:var(--text3); padding:6px 2px; font-style:italic; }
  /* Month view */
  .cal-month { display:flex; flex-direction:column; height:100%; }
  .cal-dow-headers { display:grid; grid-template-columns:repeat(7,1fr); border-bottom:1px solid var(--border); background:var(--surface); border-left:1px solid var(--border); flex-shrink:0; }
  .cal-dow-header { padding:8px; text-align:center; font-size:11px; font-weight:700; color:var(--text3); text-transform:uppercase; border-right:1px solid var(--border); }
  .cal-month-grid { display:grid; grid-template-columns:repeat(7,1fr); grid-auto-rows:1fr; border-left:1px solid var(--border); flex:1; min-height:0; }
  .cal-day { border-right:1px solid var(--border); border-bottom:1px solid var(--border); padding:4px; min-height:80px; overflow-y:auto; }
  .cal-day-num { font-size:12px; font-weight:600; color:var(--text3); padding:1px 3px; margin-bottom:3px; display:inline-flex; align-items:center; justify-content:center; min-width:22px; }
  .cal-day-num.today { background:var(--accent); color:var(--navy); border-radius:50%; width:22px; height:22px; font-weight:700; }
  .cal-day.other-month .cal-day-num { opacity:0.35; }
  .cal-day.bank-holiday { background: color-mix(in srgb, #f59e0b 12%, var(--bg)); }
  .cal-day.bank-holiday .cal-day-num::after { content: 'BHOL'; font-size: 9px; font-weight: 700; color: #dc2626; margin-left: 4px; }
  .cal-appt-chip { font-size:11px; padding:2px 5px; border-radius:4px; margin-bottom:2px; cursor:grab; white-space:nowrap; overflow:hidden; text-overflow:ellipsis; border-left:3px solid; line-height:1.5; transition:opacity 0.15s; }
  .cal-appt-chip:hover { opacity:0.8; }
  .cal-appt-chip.dragging { opacity:0.4; }
  .cal-drag-over { background:rgba(61,143,48,0.08) !important; outline:2px dashed var(--green); outline-offset:-2px; }
  /* Advisor visibility pills */
  .cal-adv-pill { font-size:11px; padding:3px 9px; border-radius:12px; border:2px solid; background:transparent; cursor:pointer; transition:all 0.15s; font-weight:600; opacity:0.35; }
  .cal-adv-pill.on { opacity:1; color:#fff !important; }
  /* Day view */
  .cal-day-view { display:flex; flex-direction:column; height:100%; overflow:hidden; }
  .cal-dv-unscheduled { display:flex; align-items:flex-start; gap:8px; padding:8px 12px; border-bottom:1px solid var(--border); background:var(--surface); flex-wrap:wrap; }
  .cal-dv-unscheduled-label { font-size:11px; font-weight:600; color:var(--text3); text-transform:uppercase; letter-spacing:.04em; white-space:nowrap; padding-top:3px; min-width:80px; }
  .cal-dv-scroll { overflow-y:auto; flex:1; }
  .cal-dv-body { display:flex; }
  .cal-dv-time-col { width:56px; flex-shrink:0; position:relative; border-right:1px solid var(--border); }
  .cal-dv-time-label { position:absolute; right:8px; font-size:10px; color:var(--text3); transform:translateY(-50%); white-space:nowrap; }
  .cal-dv-grid-col { flex:1; position:relative; }
  .cal-dv-slot { position:absolute; left:0; right:0; height:60px; border-top:1px solid var(--border); cursor:pointer; box-sizing:border-box; }
  .cal-dv-slot:hover { background:rgba(61,143,48,0.04); }
  .cal-dv-slot.cal-drag-over { background:rgba(61,143,48,0.08) !important; outline:2px dashed var(--green); outline-offset:-2px; }
  .cal-dv-event { position:absolute; left:4px; right:4px; border-radius:5px; padding:4px 7px; font-size:11px; overflow:hidden; cursor:pointer; border-left:3px solid; box-shadow:0 1px 3px rgba(0,0,0,0.25); box-sizing:border-box; transition:opacity 0.15s; }
  .cal-dv-event:hover { opacity:0.85; }
  .cal-dv-event.dragging { opacity:0.4; }
  /* Agenda view */
  .cal-agenda { overflow-y:auto; height:100%; padding:8px 16px 24px; }
  .cal-agenda-day { margin-bottom:16px; }
  .cal-agenda-date { font-size:12px; font-weight:700; color:var(--text3); text-transform:uppercase; letter-spacing:.05em; padding:6px 0 6px; border-bottom:1px solid var(--border); margin-bottom:6px; display:flex; align-items:center; gap:10px; }
  .cal-agenda-date.today { color:var(--accent); }
  .cal-agenda-date-dot { width:8px; height:8px; border-radius:50%; background:var(--accent); flex-shrink:0; }
  .cal-agenda-row { display:flex; align-items:stretch; gap:12px; padding:6px 8px; border-radius:6px; margin-bottom:4px; cursor:pointer; transition:background 0.12s; }
  .cal-agenda-row:hover { background:var(--surface); }
  .cal-agenda-time { width:52px; flex-shrink:0; font-size:12px; font-weight:600; color:var(--text2); padding-top:2px; }
  .cal-agenda-bar { width:4px; border-radius:2px; flex-shrink:0; }
  .cal-agenda-body { flex:1; min-width:0; }
  .cal-agenda-client { font-size:13px; font-weight:600; color:var(--text); }
  .cal-agenda-meta { font-size:11px; color:var(--text3); margin-top:1px; }
  .cal-agenda-empty { font-size:13px; color:var(--text3); font-style:italic; text-align:center; padding:40px 0; }

  /* ── SCHEDULER VIEW ── */
  .cal-sched-view { display:flex; flex-direction:column; height:100%; overflow:hidden; }
  .cal-sched-allday { display:flex; border-bottom:2px solid var(--border); background:var(--surface); flex-shrink:0; min-height:36px; }
  .cal-sched-allday-label { width:56px; flex-shrink:0; font-size:10px; font-weight:600; color:var(--text3); text-transform:uppercase; letter-spacing:.04em; padding:8px 4px 0; border-right:1px solid var(--border); text-align:right; }
  .cal-sched-allday-adv { flex:1; min-width:120px; padding:3px 4px; border-right:1px solid var(--border); display:flex; flex-wrap:wrap; gap:3px; align-items:center; }
  .cal-sched-scroll { flex:1; overflow-y:auto; overflow-x:auto; }
  .cal-sched-hdr-row { display:flex; position:sticky; top:0; z-index:5; background:var(--bg); border-bottom:2px solid var(--border); }
  .cal-sched-hdr-time { width:56px; flex-shrink:0; border-right:1px solid var(--border); }
  .cal-sched-hdr-adv { flex:1; min-width:130px; padding:7px 8px 5px; font-size:12px; font-weight:700; color:var(--text); border-right:1px solid var(--border); text-align:center; border-top:3px solid transparent; }
  .cal-sched-body { display:flex; }
  .cal-sched-adv-col { flex:1; min-width:130px; position:relative; border-right:1px solid var(--border); }

  /* ── MODAL ── */
  .modal-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.7);
    z-index: 100;
    align-items: flex-start;
    justify-content: center;
    padding: 40px 20px;
    overflow-y: auto;
  }
  .modal-overlay.open { display: flex; }
  /* Modals that open on top of other modals need higher z-index */
  #modal-client-email,
  #modal-doc-upload,
  #modal-confirm,
  #modal-email-detail,
  #modal-quote-form { z-index: 200; }
  .modal {
    background: var(--navy2);
    border: 1px solid var(--border);
    border-radius: 16px;
    width: 100%;
    max-width: 800px;
    box-shadow: 0 24px 60px rgba(0,0,0,0.6);
    animation: modalIn 0.2s ease;
  }
  @keyframes modalIn {
    from { opacity: 0; transform: translateY(-16px); }
    to   { opacity: 1; transform: translateY(0); }
  }
  .modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 20px 24px;
    border-bottom: 1px solid var(--border);
  }
  .modal-title { font-size: 16px; font-weight: 700; }
  .modal-close {
    width: 32px; height: 32px;
    border-radius: 8px;
    background: var(--card);
    border: 1px solid var(--border);
    color: var(--text2);
    font-size: 18px;
    cursor: pointer;
    display: flex; align-items: center; justify-content: center;
  }
  .modal-close:hover { background: var(--card2); color: var(--text); }
  .modal-body { padding: 24px; }
  .modal-footer {
    display: flex;
    justify-content: flex-end;
    gap: 10px;
    padding: 16px 24px;
    border-top: 1px solid var(--border);
  }

  /* ── FORM ── */
  .form-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 14px;
  }
  .form-group { display: flex; flex-direction: column; gap: 5px; }
  .form-group.full { grid-column: 1 / -1; }
  .form-label { font-size: 12px; font-weight: 600; color: var(--text2); }
  .form-label .req { color: var(--red); }
  .form-section-title {
    grid-column: 1 / -1;
    font-size: 12px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 1px;
    color: var(--accent);
    padding-top: 8px;
    border-top: 1px solid var(--border);
    margin-top: 4px;
  }

  /* ── DETAIL PANEL ── */
  .detail-tabs {
    display: flex;
    flex-wrap: wrap;
    gap: 2px;
    border-bottom: 1px solid var(--border);
    margin-bottom: 20px;
  }
  .detail-tab {
    padding: 10px 16px;
    font-size: 13px;
    font-weight: 500;
    color: var(--text3);
    cursor: pointer;
    border-bottom: 2px solid transparent;
    transition: all 0.15s;
    white-space: nowrap;
    flex-shrink: 0;
  }
  .detail-tab:hover { color: var(--text2); }
  .detail-tab.active { color: var(--accent); border-bottom-color: var(--accent); }

  .detail-tab-content { display: none; }
  .detail-tab-content.active { display: block; }

  .detail-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 14px;
    margin-bottom: 20px;
  }
  .detail-field { display: flex; flex-direction: column; gap: 3px; }
  .detail-field-label { font-size: 11px; color: var(--text3); font-weight: 600; text-transform: uppercase; letter-spacing: 0.8px; }
  .detail-field-value { font-size: 13px; color: var(--text); font-weight: 500; }

  /* ── ALERT CARDS ── */
  .alert-strip {
    display: flex;
    flex-direction: column;
    gap: 8px;
    margin-bottom: 20px;
  }
  .alert-item {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 5px 10px;
    border-radius: 6px;
    border-left: 3px solid;
    background: var(--card);
    border-color: var(--amber);
    font-size: 12px;
    transition: background 0.12s, transform 0.12s;
  }
  .alert-item.critical { border-color: var(--red); background: rgba(224,85,85,0.06); }
  .alert-item.warning  { border-color: var(--amber); background: rgba(245,158,11,0.06); }
  .alert-item.clickable { cursor: pointer; }
  .alert-item.clickable:hover { background: rgba(255,255,255,0.09); transform: translateX(3px); }
  .alert-icon { font-size: 13px; line-height: 1; }
  .alert-body { flex: 1; display: flex; align-items: baseline; gap: 6px; min-width: 0; }
  .alert-title { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .alert-meta  { font-size: 11px; color: var(--text3); white-space: nowrap; flex-shrink: 0; }
  .alert-days  { font-size: 11px; font-weight: 700; margin-left: auto; white-space: nowrap; padding-left: 8px; flex-shrink: 0; }

  /* ── ACTIVITY LOG ── */
  .activity-list { display: flex; flex-direction: column; gap: 0; }
  .activity-item {
    display: flex;
    gap: 14px;
    padding: 12px 0;
    border-bottom: 1px solid var(--border);
  }
  .activity-dot {
    width: 8px; height: 8px;
    border-radius: 50%;
    background: var(--accent);
    margin-top: 5px;
    flex-shrink: 0;
  }
  .activity-text { font-size: 13px; }
  .activity-time { font-size: 11px; color: var(--text3); margin-top: 3px; }

  /* ── EMPTY STATE ── */
  .empty-state {
    text-align: center;
    padding: 60px 20px;
    color: var(--text3);
  }
  .empty-icon { font-size: 40px; margin-bottom: 12px; }
  .empty-title { font-size: 16px; font-weight: 600; color: var(--text2); margin-bottom: 6px; }
  .empty-sub { font-size: 13px; }

  /* ── KANBAN BOARD ── */
  .kanban-wrap { display:flex; gap:14px; overflow-x:auto; padding:4px 0 16px; min-height:calc(100vh - 160px); align-items:flex-start; }
  .kanban-col { flex:0 0 260px; display:flex; flex-direction:column; background:var(--navy2); border-radius:10px; border:1px solid var(--border); max-height:calc(100vh - 160px); }
  .kanban-col-header { padding:12px 14px; border-bottom:1px solid var(--border); }
  .kanban-col-num { font-size:10px; font-weight:700; text-transform:uppercase; letter-spacing:1px; color:var(--text3); margin-bottom:2px; }
  .kanban-col-title { font-size:13px; font-weight:700; color:var(--text1); }
  .kanban-col-meta { display:flex; justify-content:space-between; align-items:center; margin-top:4px; }
  .kanban-col-count { font-size:11px; color:var(--text3); background:var(--card); padding:2px 8px; border-radius:10px; }
  .kanban-cards { flex:1; overflow-y:auto; padding:10px; display:flex; flex-direction:column; gap:8px; }
  .kanban-card { background:var(--card); border:1px solid var(--border); border-radius:8px; padding:12px; cursor:pointer; transition:all 0.15s; }
  .kanban-card:hover { background:var(--card2); border-color:rgba(255,255,255,0.2); transform:translateY(-1px); }
  .kanban-card-company { font-size:13px; font-weight:700; color:var(--text1); margin-bottom:4px; }
  .kanban-card-advisor { font-size:11px; color:var(--text3); margin-bottom:6px; }
  .kanban-card-days { display:inline-flex; align-items:center; gap:4px; font-size:11px; font-weight:600; padding:2px 8px; border-radius:10px; }
  .days-green { background:rgba(16,185,129,0.15); color:var(--green); }
  .days-amber { background:rgba(245,158,11,0.15); color:var(--amber); }
  .days-red   { background:rgba(224,85,85,0.15);  color:var(--red); }
  .kanban-empty { font-size:12px; color:var(--text3); text-align:center; padding:20px 8px; font-style:italic; }

  /* ── LOGIN ── */
  #login-screen {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    background: var(--navy);
  }
  .login-card {
    background: var(--navy2);
    border: 1px solid var(--border);
    border-radius: 20px;
    padding: 48px;
    width: 400px;
    box-shadow: var(--shadow);
  }
  .login-logo { font-size: 28px; font-weight: 800; color: var(--accent); margin-bottom: 6px; }
  .login-sub  { font-size: 13px; color: var(--text3); margin-bottom: 32px; }
  .login-user-list { display: flex; flex-direction: column; gap: 8px; margin-top: 20px; }
  .login-user-btn {
    display: flex; align-items: center; gap: 12px;
    padding: 12px 16px;
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: 10px;
    cursor: pointer;
    transition: all 0.15s;
    color: var(--text);
    font-family: inherit;
    font-size: 14px;
    text-align: left;
  }
  .login-user-btn:hover { background: var(--card2); border-color: var(--accent); }
  .login-avatar {
    width: 36px; height: 36px; border-radius: 50%;
    display: flex; align-items: center; justify-content: center;
    font-weight: 700; font-size: 13px; color: var(--navy);
  }

  .page { display: none; }
  .page.active { display: block; }

  .section-divider {
    font-size: 11px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 1.5px;
    color: var(--text3);
    padding: 16px 0 8px;
    border-bottom: 1px solid var(--border);
    margin-bottom: 16px;
  }

  textarea { resize: vertical; min-height: 70px; }

  .filter-chip {
    display: inline-flex; align-items: center; gap: 5px;
    padding: 5px 10px;
    border-radius: 20px;
    font-size: 12px; font-weight: 600;
    background: var(--card);
    border: 1px solid var(--border);
    color: var(--text2);
    cursor: pointer;
    transition: all 0.15s;
  }
  .filter-chip.active { background: rgba(232,160,32,0.15); border-color: var(--accent); color: var(--accent); }
  .filter-chip:hover { background: var(--card2); }

  .mono { font-family: 'DM Mono', monospace; font-size: 12px; }

  /* ── Workflow tabs ── */
  .workflow-tabs { display:flex; gap:0; border-bottom:2px solid var(--border); margin-bottom:16px; overflow-x:auto; }
  .workflow-tab  { padding:10px 18px; font-size:13px; font-weight:500; cursor:pointer; white-space:nowrap;
                   border-bottom:3px solid transparent; margin-bottom:-2px; color:var(--text2);
                   transition:color 0.15s, border-color 0.15s; flex-shrink:0; }
  .workflow-tab:hover  { color:var(--text); }
  .workflow-tab.active { color:var(--accent); border-bottom-color:var(--accent); font-weight:600; }
  .workflow-tab .tab-count { display:inline-block; margin-left:6px; padding:1px 7px;
                              border-radius:10px; font-size:11px; font-weight:600;
                              background:var(--surface2); color:var(--text3); }
  .workflow-tab.active .tab-count { background:var(--accent); color:#fff; }
  .text-muted { color: var(--text3); }
  .text-accent { color: var(--accent); }
  .text-green { color: var(--green); }
  .text-red { color: var(--red); }
  .text-amber { color: var(--amber); }

  ::-webkit-scrollbar { width: 6px; }
  ::-webkit-scrollbar-track { background: transparent; }
  ::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.1); border-radius: 3px; }
  ::-webkit-scrollbar-thumb:hover { background: rgba(255,255,255,0.2); }
  @keyframes spin { to { transform: rotate(360deg); } }

/* ── AI Chat ──────────────────────────────────────────────────────── */
#chat-fab {
  position: fixed;
  bottom: 24px;
  right: 24px;
  width: 52px;
  height: 52px;
  border-radius: 50%;
  background: var(--accent);
  color: #fff;
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 4px 16px rgba(0,0,0,0.25);
  z-index: 9000;
  transition: transform 0.15s, box-shadow 0.15s;
}
#chat-fab:hover { transform: scale(1.08); box-shadow: 0 6px 20px rgba(0,0,0,0.3); }

#chat-drawer {
  position: fixed;
  bottom: 88px;
  right: 24px;
  width: 380px;
  max-width: calc(100vw - 48px);
  height: 520px;
  max-height: calc(100vh - 120px);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  box-shadow: 0 8px 32px rgba(0,0,0,0.2);
  z-index: 9000;
  flex-direction: column;
  overflow: hidden;
}

#chat-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 14px;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
  color: var(--text1);
  flex-shrink: 0;
}

#chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.chat-msg {
  max-width: 88%;
  padding: 9px 13px;
  border-radius: 12px;
  font-size: 13px;
  line-height: 1.5;
  white-space: pre-wrap;
  word-break: break-word;
}
.chat-msg.user {
  align-self: flex-end;
  background: var(--accent);
  color: #fff;
  border-bottom-right-radius: 3px;
}
.chat-msg.assistant {
  align-self: flex-start;
  background: var(--bg2);
  color: var(--text1);
  border-bottom-left-radius: 3px;
}
.chat-msg.thinking {
  align-self: flex-start;
  background: var(--bg2);
  color: var(--text3);
  font-style: italic;
  font-size: 12px;
}

#chat-input-row {
  display: flex;
  gap: 8px;
  padding: 10px 12px;
  border-top: 1px solid var(--border);
  flex-shrink: 0;
  background: var(--surface);
}

#chat-input {
  flex: 1;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 10px;
  font-size: 13px;
  resize: none;
  background: var(--bg2);
  color: var(--text1);
  max-height: 120px;
  overflow-y: auto;
  font-family: inherit;
}
#chat-input:focus { outline: none; border-color: var(--accent); }

#chat-send {
  width: 36px;
  height: 36px;
  border-radius: 8px;
  background: var(--accent);
  color: #fff;
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  align-self: flex-end;
  transition: opacity 0.15s;
}
#chat-send:hover { opacity: 0.85; }
#chat-send:disabled { opacity: 0.4; cursor: not-allowed; }

/* ── Client Health Score ─────────────────────────────────────── */
.health-grade-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 24px;
  height: 24px;
  border-radius: 6px;
  font-size: 12px;
  font-weight: 800;
  color: #fff;
  cursor: pointer;
  line-height: 1;
  letter-spacing: 0;
  transition: opacity 0.15s;
}
.health-grade-badge:hover { opacity: 0.8; }

.health-score-card {
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 16px;
  margin-bottom: 16px;
  display: flex;
  align-items: flex-start;
  gap: 16px;
}
.health-grade-circle {
  width: 60px;
  height: 60px;
  border-radius: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 28px;
  font-weight: 900;
  color: #fff;
  flex-shrink: 0;
}
.health-score-details { flex: 1; min-width: 0; }
.health-score-label { font-size: 11px; color: var(--text3); text-transform: uppercase; letter-spacing: 0.06em; font-weight: 600; margin-bottom: 2px; }
.health-score-value { font-size: 18px; font-weight: 700; color: var(--text1); margin-bottom: 6px; }
.health-breakdown-toggle { font-size: 12px; color: var(--accent); cursor: pointer; border: none; background: none; padding: 0; font-family: inherit; }
.health-breakdown-toggle:hover { text-decoration: underline; }
.health-breakdown-table { margin-top: 10px; border-collapse: collapse; width: 100%; font-size: 12px; }
.health-breakdown-table td { padding: 4px 6px; }
.health-breakdown-table tr:not(:last-child) td { border-bottom: 1px solid var(--border); }
.health-breakdown-icon { width: 20px; text-align: center; }
.health-dist-bar { display: flex; gap: 4px; flex-wrap: wrap; margin-top: 8px; }
