/* Shared dark theme for the agency CRM and client portal. */
html[data-theme="dark"] {
  color-scheme: dark;
  --bg:#0c131b;
  --surface:#15202b;
  --surface-2:#1b2935;
  --surface-sunken:#223341;
  --surface-dim:rgba(255,255,255,.07);
  --ink-900:#f7f9fc;
  --ink-700:#d7e0e9;
  --ink-500:#aebdca;
  --ink-400:#98aaba;
  --ink-300:#8195a7;
  --ink-200:#607386;
  --border:#354758;
  --border-strong:#4b6072;
  --border-muted:#2a3a49;
  --brand-50:#143532;
  --brand-100:#194a45;
  --brand-500:#5fb3aa;
  --brand-600:#0f766e;
  --brand-700:#9adbd4;
  --success:#34d399;
  --success-bg:#113a31;
  --danger:#fb7185;
  --danger-bg:#451f2a;
  --warn:#fbbf24;
  --warn-bg:#3d3014;
  --info:#60a5fa;
  --info-bg:#172f52;
  --ring:0 0 0 3px rgba(95,179,170,.25);
  --gold:#4f9f97;
  --gold-d:#8fcec7;
  --gold-soft:#194a45;
  --cream:#1b2935;
  --ink:#f7f9fc;
  --muted:#aebdca;
  --line:#354758;
  --card:#15202b;
  --ok:#34d399;
  --err:#fb7185;
  --ux-ink:#f1f5f9;
  --ux-muted:#a7b4c4;
  --ux-border:#2a394a;
  --ux-surface:#121a24;
  --ux-teal:#5fb3aa;
  --ux-teal-dark:#9adbd4;
  --ux-teal-soft:#173d3a;
}

html[data-theme="dark"] body,
html[data-theme="dark"] .login-wrap,
html[data-theme="dark"] body.ux-portal-settings,
html[data-theme="dark"] [data-workstreams],
html[data-theme="dark"] [data-coupons-ui] { background:#0c131b; color:#eef3f8; }

html[data-theme="dark"] :where(.topbar,.tabbar,.card,.modal,dialog,.lead-table,.data-grid,.as-stat,.as-card,.as-table table,.login-card,.notif-panel,.dropdown-menu,.popover,.drawer,.panel) {
  background-color:#15202b;
  color:#eef3f8;
  border-color:#354758;
}

html[data-theme="dark"] :where(input:not([type="color"]),select,textarea) {
  background-color:#101b25;
  color:#f3f6fa;
  border-color:#4b6072;
}
html[data-theme="dark"] :where(input,textarea)::placeholder { color:#9aabba; opacity:1; }
html[data-theme="dark"] option { background:#15202b; color:#eef3f8; }
html[data-theme="dark"] input[type="checkbox"] { background-color:#101b25; border-color:#607386; }
html[data-theme="dark"] input[type="checkbox"]:checked { background-color:#397f78; border-color:#5fb3aa; }

html[data-theme="dark"] :where(.muted,.sec-sub,.row-sub,.meta,.field label) { color:#aebdca; }
html[data-theme="dark"] :where(h1,h2,h3,h4,.row-title,.sec-title,.brand) { color:#f7f9fc; }
html[data-theme="dark"] :where(.data-grid thead th,.lead-table th,.lead-table tr.clickable:hover,.surface-2) { background:#1b2935; color:#c1ccd6; }
html[data-theme="dark"] :where(.table-scroll,.lead-table,.card,.modal,dialog) { box-shadow:0 12px 34px rgba(0,0,0,.28); }
html[data-theme="dark"] .topbar { background:rgba(21,32,43,.99); box-shadow:-8px 0 28px rgba(0,0,0,.28); }
html[data-theme="dark"] .sidebar-toggle { background:#1b2935; color:#d7e0e9; border-color:#4b6072; }
html[data-theme="dark"] .nav-btn { color:#b9c6d1; }
html[data-theme="dark"] .nav-btn:hover { color:#f7f9fc; background:#223341; }
html[data-theme="dark"] .topbar .nav-btn.active { background:linear-gradient(135deg,#176f69,#105b56); color:#fff; }
html[data-theme="dark"] #docsLink { border-color:#3b4c61 !important; }
html[data-theme="dark"] .login-card button[type="submit"] { background:linear-gradient(135deg,#0f766e,#0b625c); color:#fff; }
html[data-theme="dark"] .login-card button[type="submit"]:hover { background:linear-gradient(135deg,#0b625c,#084f4a); }

/* Buttons cannot reuse the light theme's ink token as a background: in dark
   mode that token is intentionally near-white. Keep action contrast explicit. */
html[data-theme="dark"] .btn:not(.secondary):not(.ghost):not(.danger):not(.ok),
html[data-theme="dark"] #newLeadBtn { background:#0f766e; border-color:#0f766e; color:#fff; }
html[data-theme="dark"] .btn:not(.secondary):not(.ghost):not(.danger):not(.ok):hover,
html[data-theme="dark"] #newLeadBtn:hover { background:#0b625c; border-color:#0b625c; }
html[data-theme="dark"] :where(.btn.secondary,.btn.ghost) { background:#1b2935; border-color:#4b6072; color:#eef3f8; }
html[data-theme="dark"] :where(.btn.secondary,.btn.ghost):hover { background:#223341; color:#fff; }
html[data-theme="dark"] .btn:disabled { opacity:.62; }
html[data-theme="dark"] .as-stat strong { color:#9adbd4; }

/* Generated CRM views still contain older literal light surfaces. */
html[data-theme="dark"] :where([style*="background:#fff;"],[style$="background:#fff"],[style*="background: #fff;"],[style$="background: #fff"],[style*="background:white;"],[style$="background:white"],[style*="background: white;"],[style$="background: white"]) { background-color:#121a24 !important; }
html[data-theme="dark"] :where([style*="background:#f8fafc"],[style*="background: #f8fafc"],[style*="background:#fafaf7"],[style*="background:#f6f8fa"]) { background-color:#17212d !important; }
html[data-theme="dark"] :where([style*="background:#e2e8f0"],[style*="background: #e2e8f0"],[style*="background:#f1f5f9"]) { background-color:#1d2937 !important; }
html[data-theme="dark"] :where([style*="color:#334155"],[style*="color: #334155"],[style*="color:#1b1b1b"],[style*="color: #1b1b1b"]) { color:#dbe4ee !important; }
html[data-theme="dark"] :where([style*="color:#0f766e"],[style*="color: #0f766e"],[style*="color:#115e59"],[style*="color: #115e59"]) { color:#9adbd4 !important; }
html[data-theme="dark"] :where([style*="color:#475569"],[style*="color: #475569"],[style*="color:#64748b"],[style*="color: #64748b"]) { color:#b9c6d1 !important; }

/* Client portal shell and its settings workspace. */
html[data-theme="dark"] .tabbar { background:#101822; border-color:#2a394a; box-shadow:-12px 0 32px rgba(0,0,0,.42); }
html[data-theme="dark"] .portal-nav-brand { border-color:#2a394a; }
html[data-theme="dark"] .portal-nav-brand img,
html[data-theme="dark"] .topbar .client-logo { background:#fff; border-radius:9px; padding:4px; }
html[data-theme="dark"] .tab { color:#a7b4c4; }
html[data-theme="dark"] .tab:hover { background:rgba(95,179,170,.11); color:#9adbd4; }
html[data-theme="dark"] .tab-sec { color:#718096; border-color:#213043; }
html[data-theme="dark"] .portal-logout { background:#251820; color:#fda4af; border-color:#5e2937; }
html[data-theme="dark"] .portal-logout:hover { background:#351c27; border-color:#9f3e55; }
html[data-theme="dark"] .portal-nav-footer { background:linear-gradient(to bottom,rgba(21,32,43,0),#15202b 14px); }
html[data-theme="dark"] .portal-account-button { background:#1b2935; color:#d7e0e9; border-color:#4b6072; }
html[data-theme="dark"] .portal-account-button:hover,
html[data-theme="dark"] .portal-account-button[aria-expanded="true"] { background:#194a45; color:#9adbd4; border-color:#5fb3aa; }
html[data-theme="dark"] .portal-account-menu { background:#15202b; border-color:#354758; box-shadow:0 18px 42px rgba(0,0,0,.5); }
html[data-theme="dark"] .portal-account-menu .tab-doc { background:#1b2935; color:#d7e0e9; border-color:#4b6072 !important; }
html[data-theme="dark"] .portal-side-lock { background:#1b2935; color:#d7e0e9; border-color:#4b6072; }
html[data-theme="dark"] .portal-side-mode-menu { background:#15202b !important; border-color:#354758 !important; box-shadow:0 18px 42px rgba(0,0,0,.5) !important; }
html[data-theme="dark"] .portal-side-mode-option { color:#d7e0e9 !important; }
html[data-theme="dark"] .portal-side-mode-option:hover,
html[data-theme="dark"] .portal-side-mode-option:focus-visible,
html[data-theme="dark"] .portal-side-mode-option[aria-checked="true"] { background:#1b2935 !important; }
html[data-theme="dark"] .portal-side-mode-hint { color:#94a3b8 !important; }
html[data-theme="dark"] .hamb { background:#1d2937; color:#dbe4ee; }
html[data-theme="dark"] .topbar .logo { background:#fff; }
html[data-theme="dark"] .bub.them { background:#1d2937; color:#e6edf5; }
html[data-theme="dark"] .account-menu { background:#15202b; border-color:#354758; box-shadow:0 18px 42px rgba(0,0,0,.5); }
html[data-theme="dark"] .account-menu-name { color:#f7f9fc; border-color:#2a3a49; }
html[data-theme="dark"] .account-menu #docsLink { color:#d7e0e9; background:#1b2935; }
html[data-theme="dark"] .account-menu #logoutBtn { color:#fda4af; }
html[data-theme="dark"] .account-menu .ux-sidebar-lock {
  background:#1b2935 !important;
  color:#d7e0e9 !important;
  border-color:#4b6072 !important;
}
html[data-theme="dark"] .account-menu .ux-sidebar-lock:hover,
html[data-theme="dark"] .account-menu .ux-sidebar-lock.is-pinned {
  background:#194a45 !important;
  color:#9adbd4 !important;
  border-color:#5fb3aa !important;
}

/* The dashboard command search is injected by crm-ux-overhaul and used
   hard-coded light gradients, so token overrides alone could not recolor it. */
html[data-theme="dark"] .ux-dashboard-search {
  background:linear-gradient(125deg,#15202b 0%,#17312f 54%,#192636 100%);
  color:#f7f9fc;
  border-color:#354758;
  box-shadow:0 18px 48px -34px rgba(0,0,0,.9);
}
html[data-theme="dark"] .ux-dashboard-search__eyebrow { color:#9adbd4; }
html[data-theme="dark"] .ux-dashboard-search h1 { color:#f7f9fc; }
html[data-theme="dark"] .ux-dashboard-search p { color:#aebdca; }
html[data-theme="dark"] .ux-dashboard-search__input {
  background:#101b25;
  color:#f7f9fc;
  border-color:#4b6072;
  box-shadow:none;
}
html[data-theme="dark"] .ux-dashboard-search__input:focus {
  border-color:#5fb3aa;
  outline-color:rgba(54,214,193,.3);
}
html[data-theme="dark"] .ux-dashboard-search__results {
  background:#15202b;
  border-color:#354758;
  box-shadow:0 20px 44px rgba(0,0,0,.45);
}
html[data-theme="dark"] .ux-dashboard-search__result {
  background:#15202b;
  color:#f7f9fc;
  border-color:#2a3a49;
}
html[data-theme="dark"] .ux-dashboard-search__result:hover,
html[data-theme="dark"] .ux-dashboard-search__result:focus-visible { background:#223341; }
html[data-theme="dark"] .ux-dashboard-search__result span,
html[data-theme="dark"] .ux-dashboard-search__empty { color:#aebdca; }
html[data-theme="dark"] #leadList,
html[data-theme="dark"] #clientsTableShell,
html[data-theme="dark"] #clientsList,
html[data-theme="dark"] #clientsList > .card[data-cm],
html[data-theme="dark"] section[data-tab="comments_inbox"] .ci-item,
html[data-theme="dark"] section[data-tab="comments_inbox"] .ci-rule-card,
html[data-theme="dark"] section[data-tab="comments_inbox"] .ci-empty { background:#121a24; border-color:#2a394a; }
html[data-theme="dark"] .mgr-hdrrow { background:#0b1118; }
html[data-theme="dark"] .lead-item:hover,
html[data-theme="dark"] #clientsList > .card[data-cm]:hover { background:#17212d; }
html[data-theme="dark"] #leadModal .lm-box { background:#0f1722; }
html[data-theme="dark"] #leadModal .lm-head { background:#121a24; border-color:#2a394a; }
html[data-theme="dark"] :where(.cm-lane-money,.cm-lane-notes,.lf-notes) { background:#17212d; border-color:#2a394a; }
html[data-theme="dark"] section[data-tab="settings"] > .card { background:rgba(18,26,36,.88) !important; border-color:#2a394a !important; }
html[data-theme="dark"] section[data-tab="settings"] > .card > h2 { background:rgba(23,33,45,.94) !important; color:#5eead4 !important; }
html[data-theme="dark"] section[data-tab="settings"] > .card:not(.collapsed) > h2 { background:#1d2937 !important; }
html[data-theme="dark"] section[data-tab="settings"] .compact-rows .set-row,
html[data-theme="dark"] #setNav { background:rgba(18,26,36,.94) !important; border-color:#2a394a !important; }
html[data-theme="dark"] #setNavChips button { background:#17212d; color:#b7f7ee; border-color:#3b4c61; }

/* Agency/manager views are generated by the UX enhancement layer with more
   specific light-theme selectors. These overrides keep every surface and its
   text in the same colour system instead of producing white cards with white
   labels. */
html[data-theme="dark"] :where(.ux-page-intro,.ux-command-bar) {
  background:#15202b !important;
  color:#eef3f8 !important;
  border-color:#354758 !important;
  box-shadow:0 14px 34px rgba(0,0,0,.28) !important;
}
html[data-theme="dark"] :where(.ux-page-intro h1,.ux-page-intro h2,.ux-page-intro p,.ux-command-bar label) { color:inherit !important; }
html[data-theme="dark"] :where(.ux-view-switch,.ux-view-toggle) {
  background:#101b25 !important;
  border-color:#354758 !important;
}
html[data-theme="dark"] :where(.ux-view-switch button,.ux-view-toggle button,.ux-command-bar button,.ux-command-bar select) {
  background:#1b2935 !important;
  color:#d7e0e9 !important;
  border-color:#4b6072 !important;
}
html[data-theme="dark"] :where(.ux-view-switch button.active,.ux-view-toggle button.active) {
  background:#176f69 !important;
  color:#fff !important;
}
html[data-theme="dark"] body.ux-agency-list #activeCards > .card.active-card,
html[data-theme="dark"] #activeCards > .card.active-card {
  background:#15202b !important;
  color:#eef3f8 !important;
  border-color:#354758 !important;
  box-shadow:0 10px 26px rgba(0,0,0,.24) !important;
}
html[data-theme="dark"] #activeCards > .card.active-card :where(h2,h3,h4,b,strong,.card-toggle) { color:#f7f9fc !important; }
html[data-theme="dark"] #activeCards > .card.active-card :where(.muted,small,.sub) { color:#aebdca !important; }
html[data-theme="dark"] #activeCards > .card.active-card :where(hr,.card-toggle) { border-color:#354758 !important; }
html[data-theme="dark"] :where(#quickJumpInput,#quickJumpList) {
  background:#101b25 !important;
  color:#f3f6fa !important;
  border-color:#4b6072 !important;
}
html[data-theme="dark"] #quickJumpList { box-shadow:0 14px 30px rgba(0,0,0,.45) !important; }
html[data-theme="dark"] #quickJumpList .qj-row { background:#15202b; color:#eef3f8; border-color:#354758 !important; }
html[data-theme="dark"] #quickJumpList .qj-row:hover { background:#223341 !important; }
html[data-theme="dark"] :where(.lead-table,.data-grid) :where(tbody tr,td) { background:#15202b; color:#d7e0e9; border-color:#354758; }
html[data-theme="dark"] :where(.lead-table,.data-grid) tbody tr:hover :where(td) { background:#223341; }
html[data-theme="dark"] :where(.ux-lead-detail .card,.ux-lead-hero,.ux-lead-panel) { background:#15202b !important; color:#eef3f8 !important; border-color:#354758 !important; }

/* Employee portal: its legacy template contains literal light colours. The
   body class limits these corrections to /rep while covering desktop/mobile,
   login, drawers, calendars and dropdowns. */
html[data-theme="dark"] body.rep-app :where(.app,.topbar,.tabs,.card,.stat,.lead,.lead .body,.msg,.drawer,.mselect-pop,.calcell,.lf-stwrap) {
  background:#15202b !important;
  color:#eef3f8 !important;
  border-color:#354758 !important;
}
html[data-theme="dark"] body.rep-app .app { box-shadow:0 0 60px rgba(0,0,0,.35); }
html[data-theme="dark"] body.rep-app :where(.lead:nth-child(even),.lead:hover,.calcell:hover,.calcell.sel,.pipe-chip:hover,.lf-tab:hover) { background:#1b2935 !important; }
html[data-theme="dark"] body.rep-app :where(.btn.ghost,.clockpill,.hamb,.iconbtn,.calnav button,.pipe-chip) { background:#1b2935; color:#d7e0e9; border-color:#4b6072; }
html[data-theme="dark"] body.rep-app :where(.tabs,.topbar) { box-shadow:0 6px 18px rgba(0,0,0,.22); }
html[data-theme="dark"] body.rep-app :where(.muted,.sub,.lcol-note,.lead .ph,.msg .tm) { color:#aebdca !important; }
html[data-theme="dark"] body.rep-app :where(.h,.biz,.caldate,.lf-stselect,.daygroup,.lead strong) { color:#f7f9fc !important; }
html[data-theme="dark"] body.rep-app :where(.tab.active,.btn:not(.ghost):not(.red):not(.green):not(.dark),.pipe-chip.active) { background:#176f69; color:#fff; }
html[data-theme="dark"] body.rep-app :where(.tab:hover,.lf-tab.active,.caldow,.calmore,.msg .who) { color:#9adbd4; }
html[data-theme="dark"] body.rep-app :where(.drawer .x) { background:#223341; color:#f7f9fc; border-color:#4b6072; }
html[data-theme="dark"] body.rep-app :where(.drawer .x:hover) { background:#2b3e4d; }

/* Optional modules loaded inside either shell. */
html[data-theme="dark"] .as-column,
html[data-theme="dark"] #analyticsReport .ar-columns > div,
html[data-theme="dark"] #analyticsReport tbody tr:nth-child(even),
html[data-theme="dark"] [data-workstreams] .ws-general,
html[data-theme="dark"] [data-workstreams] .ws-event,
html[data-theme="dark"] [data-workstreams] tbody tr:nth-child(even) { background:#17212d; }
html[data-theme="dark"] #analyticsReport thead th,
html[data-theme="dark"] #analyticsReport tfoot th,
html[data-theme="dark"] #analyticsReport tfoot td,
html[data-theme="dark"] #analyticsReport th:first-child { background:#173d3a; color:#b7f7ee; }
html[data-theme="dark"] [data-workstreams] :where(table,button,dialog,input:not([type="checkbox"]),select,textarea),
html[data-theme="dark"] [data-coupons-ui] :where(.page-card,.empty,.ticket,dialog,input,select,textarea) { background:#121a24; color:#e6edf5; border-color:#2a394a; }
html[data-theme="dark"] [data-workstreams] .ws-card[aria-pressed="true"] { background:#173d3a; }
html[data-theme="dark"] [data-coupons-ui] .perforation::before,
html[data-theme="dark"] [data-coupons-ui] .perforation::after { background:#0b1118; }

/* One accessible switch component, reused in both shells. */
.theme-toggle {
  display:inline-flex; align-items:center; justify-content:center; gap:7px;
  min-height:38px; padding:7px 11px; border:1px solid var(--border,#dce5ee);
  border-radius:10px; background:var(--surface,#fff); color:var(--ink-700,#2d3038);
  font:700 12.5px/1.2 'Heebo','Segoe UI',Arial,sans-serif; cursor:pointer;
}
.theme-toggle:hover { background:var(--surface-sunken,#f1f5f9); }
.theme-toggle:focus-visible { outline:2px solid var(--brand-500,#14b8a6); outline-offset:2px; }
.theme-toggle [data-theme-icon] { font-size:16px; line-height:1; }
.portal-theme-toggle { width:100%; justify-content:flex-start; min-height:44px; margin-bottom:7px; }
.topbar-mobile-theme { flex:0 0 auto; width:42px; height:42px; min-height:42px; padding:0; border-radius:11px; }
.topbar-mobile-theme [data-theme-label] { display:none; }
.topbar .user-info > .theme-toggle { grid-column:1 / -1; width:100%; }
.login-theme-toggle { position:fixed; inset-block-start:18px; inset-inline-end:18px; z-index:2; }

@media (min-width:1024px) { .topbar-mobile-theme { display:none; } }
@media (max-width:1024px) {
  html .topbar .user-info > .theme-toggle { display:flex !important; width:42px; min-height:42px; padding:0; margin:0 auto; }
  html .topbar .user-info > .theme-toggle [data-theme-label] { display:none; }
}
@media print {
  .theme-toggle { display:none !important; }
  html[data-theme="dark"] { color-scheme:light; }
}
