/* ============================================================
   SMMPIX Contrast Fix v142
   Site-wide light + dark text visibility
   Load LAST so it wins over theme overrides
   ============================================================ */

/* ---------- Token safety ---------- */
html[data-theme="light"]{
  --tx:#0f172a;
  --mu:#64748b;
  --card:#ffffff;
  --sf:#f8fafc;
  --bd:#e2e8f0;
  --bg:#f5f7fb;
}
html[data-theme="dark"]{
  --tx:#e5e7eb;
  --mu:#94a3b8;
  --card:#111827;
  --sf:#0f172a;
  --bd:#1f2a3a;
  --bg:#0b1220;
}

/* ---------- Global readable text ---------- */
html[data-theme="light"] body,
html[data-theme="light"] body.is-client,
html[data-theme="light"] body.is-admin{
  color:var(--tx,#0f172a)!important;
}
html[data-theme="dark"] body,
html[data-theme="dark"] body.is-client,
html[data-theme="dark"] body.is-admin{
  color:var(--tx,#e5e7eb)!important;
}

/* Headings */
html[data-theme="light"] body.is-client h1,
html[data-theme="light"] body.is-client h2,
html[data-theme="light"] body.is-client h3,
html[data-theme="light"] body.is-client h4,
html[data-theme="light"] body.is-admin h1,
html[data-theme="light"] body.is-admin h2,
html[data-theme="light"] body.is-admin h3,
html[data-theme="light"] body.is-admin h4{
  color:var(--tx,#0f172a)!important;
}
html[data-theme="dark"] body.is-client h1,
html[data-theme="dark"] body.is-client h2,
html[data-theme="dark"] body.is-client h3,
html[data-theme="dark"] body.is-client h4,
html[data-theme="dark"] body.is-admin h1,
html[data-theme="dark"] body.is-admin h2,
html[data-theme="dark"] body.is-admin h3,
html[data-theme="dark"] body.is-admin h4{
  color:var(--tx,#e5e7eb)!important;
}

/* Muted labels */
html[data-theme="light"] body.is-client .muted,
html[data-theme="light"] body.is-client .text-muted,
html[data-theme="light"] body.is-client .text-gray-500,
html[data-theme="light"] body.is-client .text-gray-600,
html[data-theme="light"] body.is-client .text-\[var\(--mu\)\],
html[data-theme="light"] body.is-admin .muted,
html[data-theme="light"] body.is-admin .text-muted{
  color:var(--mu,#64748b)!important;
}
html[data-theme="dark"] body.is-client .muted,
html[data-theme="dark"] body.is-client .text-muted,
html[data-theme="dark"] body.is-client .text-gray-500,
html[data-theme="dark"] body.is-client .text-gray-600,
html[data-theme="dark"] body.is-client .text-\[var\(--mu\)\],
html[data-theme="dark"] body.is-admin .muted,
html[data-theme="dark"] body.is-admin .text-muted{
  color:var(--mu,#94a3b8)!important;
}

/* Cards / panels */
html[data-theme="light"] body.is-client .card,
html[data-theme="light"] body.is-client .ui-card,
html[data-theme="light"] body.is-client .xo-card,
html[data-theme="light"] body.is-client .xo-stat,
html[data-theme="light"] body.is-client .afx-card,
html[data-theme="light"] body.is-client .u6-card,
html[data-theme="light"] body.is-client .client-section,
html[data-theme="light"] body.is-client .dash-card,
html[data-theme="light"] body.is-client .api-card,
html[data-theme="light"] body.is-client .svc-group,
html[data-theme="light"] body.is-client .mo-filter,
html[data-theme="light"] body.is-client .mo-stat,
html[data-theme="light"] body.is-admin .card,
html[data-theme="light"] body.is-admin .ui-card,
html[data-theme="light"] body.is-admin .dashboard-kpi,
html[data-theme="light"] body.is-admin .dashboard-panel,
html[data-theme="light"] body.is-admin .ad-panel,
html[data-theme="light"] body.is-admin .ad-kpi,
html[data-theme="light"] body.is-admin .ad-hero,
html[data-theme="light"] body.is-admin .admin-card{
  background:var(--card,#fff)!important;
  color:var(--tx,#0f172a)!important;
  border-color:var(--bd,#e2e8f0)!important;
}
html[data-theme="dark"] body.is-client .card,
html[data-theme="dark"] body.is-client .ui-card,
html[data-theme="dark"] body.is-client .xo-card,
html[data-theme="dark"] body.is-client .xo-stat,
html[data-theme="dark"] body.is-client .afx-card,
html[data-theme="dark"] body.is-client .u6-card,
html[data-theme="dark"] body.is-client .client-section,
html[data-theme="dark"] body.is-client .dash-card,
html[data-theme="dark"] body.is-client .api-card,
html[data-theme="dark"] body.is-client .svc-group,
html[data-theme="dark"] body.is-client .mo-filter,
html[data-theme="dark"] body.is-client .mo-stat,
html[data-theme="dark"] body.is-admin .card,
html[data-theme="dark"] body.is-admin .ui-card,
html[data-theme="dark"] body.is-admin .dashboard-kpi,
html[data-theme="dark"] body.is-admin .dashboard-panel,
html[data-theme="dark"] body.is-admin .ad-panel,
html[data-theme="dark"] body.is-admin .ad-kpi{
  background:var(--card,#111827)!important;
  color:var(--tx,#e5e7eb)!important;
  border-color:var(--bd,#1f2a3a)!important;
}

/* Forms */
html[data-theme="light"] body.is-client input:not([type=checkbox]):not([type=radio]):not([type=color]),
html[data-theme="light"] body.is-client select,
html[data-theme="light"] body.is-client textarea,
html[data-theme="light"] body.is-client .xo-input,
html[data-theme="light"] body.is-client .xo-dd-btn,
html[data-theme="light"] body.is-client .afx-input,
html[data-theme="light"] body.is-client .svc-field,
html[data-theme="light"] body.is-client .mo-field,
html[data-theme="light"] body.is-admin input:not([type=checkbox]):not([type=radio]):not([type=color]),
html[data-theme="light"] body.is-admin select,
html[data-theme="light"] body.is-admin textarea{
  background:var(--sf,#f8fafc)!important;
  color:var(--tx,#0f172a)!important;
  border-color:var(--bd,#e2e8f0)!important;
}
html[data-theme="dark"] body.is-client input:not([type=checkbox]):not([type=radio]):not([type=color]),
html[data-theme="dark"] body.is-client select,
html[data-theme="dark"] body.is-client textarea,
html[data-theme="dark"] body.is-client .xo-input,
html[data-theme="dark"] body.is-client .xo-dd-btn,
html[data-theme="dark"] body.is-client .afx-input,
html[data-theme="dark"] body.is-client .svc-field,
html[data-theme="dark"] body.is-client .mo-field,
html[data-theme="dark"] body.is-admin input:not([type=checkbox]):not([type=radio]):not([type=color]),
html[data-theme="dark"] body.is-admin select,
html[data-theme="dark"] body.is-admin textarea{
  background:var(--sf,#0f172a)!important;
  color:var(--tx,#e5e7eb)!important;
  border-color:var(--bd,#1f2a3a)!important;
}
html[data-theme="light"] body.is-client ::placeholder,
html[data-theme="light"] body.is-admin ::placeholder{color:var(--mu,#64748b)!important;opacity:.85}
html[data-theme="dark"] body.is-client ::placeholder,
html[data-theme="dark"] body.is-admin ::placeholder{color:var(--mu,#94a3b8)!important;opacity:.8}

/* Tables */
html[data-theme="light"] body.is-client thead th,
html[data-theme="light"] body.is-admin thead th{
  color:var(--mu,#64748b)!important;
  background:color-mix(in srgb,var(--bg,#f8fafc) 80%,var(--card,#fff))!important;
  border-color:var(--bd,#e2e8f0)!important;
}
html[data-theme="light"] body.is-client tbody td,
html[data-theme="light"] body.is-admin tbody td{
  color:var(--tx,#0f172a)!important;
  border-color:color-mix(in srgb,var(--bd,#e2e8f0) 80%,transparent)!important;
}
html[data-theme="dark"] body.is-client thead th,
html[data-theme="dark"] body.is-admin thead th{
  color:var(--mu,#94a3b8)!important;
  background:color-mix(in srgb,var(--card,#111827) 90%,#000)!important;
  border-color:var(--bd,#1f2a3a)!important;
}
html[data-theme="dark"] body.is-client tbody td,
html[data-theme="dark"] body.is-admin tbody td{
  color:var(--tx,#e5e7eb)!important;
  border-color:color-mix(in srgb,var(--bd,#1f2a3a) 80%,transparent)!important;
}

/* Labels */
html[data-theme="light"] body.is-client label,
html[data-theme="light"] body.is-admin label{
  color:var(--tx,#0f172a)!important;
}
html[data-theme="dark"] body.is-client label,
html[data-theme="dark"] body.is-admin label{
  color:var(--tx,#e5e7eb)!important;
}

/* Dropdowns / menus */
html[data-theme="light"] body.is-client .xo-dd-menu,
html[data-theme="light"] body.is-client .cur-menu,
html[data-theme="light"] body.is-client .dropdown-menu,
html[data-theme="light"] body.is-client [role="menu"],
html[data-theme="light"] body.is-admin .cur-menu,
html[data-theme="light"] body.is-admin .dropdown-menu{
  background:var(--card,#fff)!important;
  color:var(--tx,#0f172a)!important;
  border-color:var(--bd,#e2e8f0)!important;
}
html[data-theme="dark"] body.is-client .xo-dd-menu,
html[data-theme="dark"] body.is-client .cur-menu,
html[data-theme="dark"] body.is-client .dropdown-menu,
html[data-theme="dark"] body.is-client [role="menu"],
html[data-theme="dark"] body.is-admin .cur-menu,
html[data-theme="dark"] body.is-admin .dropdown-menu{
  background:var(--card,#111827)!important;
  color:var(--tx,#e5e7eb)!important;
  border-color:var(--bd,#1f2a3a)!important;
}

/* New order specific */
html[data-theme="light"] .xo-page .xo-stat .t,
html[data-theme="light"] .xo-page .xo-fg > label,
html[data-theme="light"] .xo-page .xo-hint,
html[data-theme="light"] .xo-page .xo-groups .ttl,
html[data-theme="light"] .xo-page .xo-svc-item .meta,
html[data-theme="light"] .xo-page .xo-empty,
html[data-theme="light"] .xo-page .xo-dd-btn .ph{color:var(--mu,#64748b)!important}
html[data-theme="light"] .xo-page .xo-stat .v,
html[data-theme="light"] .xo-page .xo-head h2,
html[data-theme="light"] .xo-page .xo-cat-item,
html[data-theme="light"] .xo-page .xo-svc-item,
html[data-theme="light"] .xo-page .xo-summary .v{color:var(--tx,#0f172a)!important}

/* Services / orders / tickets / funds */
html[data-theme="light"] body.is-client .svc,
html[data-theme="light"] body.is-client .svc *,
html[data-theme="light"] body.is-client .uo-page,
html[data-theme="light"] body.is-client .afx,
html[data-theme="light"] body.is-client .mo-page{
  color:inherit;
}
html[data-theme="light"] body.is-client .svc-btn:not(.primary),
html[data-theme="light"] body.is-client .uo-btn:not(.primary),
html[data-theme="light"] body.is-client .btn-o,
html[data-theme="light"] body.is-client .btn-ghost,
html[data-theme="light"] body.is-client .btn-secondary{
  color:var(--tx,#0f172a)!important;
  background:var(--card,#fff)!important;
  border-color:var(--bd,#e2e8f0)!important;
}
html[data-theme="dark"] body.is-client .svc-btn:not(.primary),
html[data-theme="dark"] body.is-client .btn-o,
html[data-theme="dark"] body.is-client .btn-ghost,
html[data-theme="dark"] body.is-client .btn-secondary{
  color:var(--tx,#e5e7eb)!important;
  background:var(--card,#111827)!important;
  border-color:var(--bd,#1f2a3a)!important;
}

/* Dashboard stats outside hero */
html[data-theme="light"] body.is-client .db-stat,
html[data-theme="light"] body.is-client .db-stat-value,
html[data-theme="light"] body.is-client .db-stat-label,
html[data-theme="light"] body.is-client .client-stat .v,
html[data-theme="light"] body.is-client .client-stat .k{
  color:inherit;
}
html[data-theme="light"] body.is-client .db-stat{color:var(--tx,#0f172a)!important}
html[data-theme="light"] body.is-client .db-stat-label,
html[data-theme="light"] body.is-client .client-stat .k,
html[data-theme="light"] body.is-client .db-stat-meta{color:var(--mu,#64748b)!important}
html[data-theme="light"] body.is-client .db-stat-value,
html[data-theme="light"] body.is-client .client-stat .v{color:var(--tx,#0f172a)!important}
html[data-theme="dark"] body.is-client .db-stat{color:var(--tx,#e5e7eb)!important}
html[data-theme="dark"] body.is-client .db-stat-label,
html[data-theme="dark"] body.is-client .client-stat .k,
html[data-theme="dark"] body.is-client .db-stat-meta{color:var(--mu,#94a3b8)!important}
html[data-theme="dark"] body.is-client .db-stat-value,
html[data-theme="dark"] body.is-client .client-stat .v{color:var(--tx,#e5e7eb)!important}

/* Badges that must stay readable in light mode */
html[data-theme="light"] body.is-client .db-badge.is-success{color:#15803d!important;background:#dcfce7!important}
html[data-theme="light"] body.is-client .db-badge.is-info{color:#0369a1!important;background:#e0f2fe!important}
html[data-theme="light"] body.is-client .db-badge.is-danger{color:#b91c1c!important;background:#fee2e2!important}
html[data-theme="light"] body.is-client .db-badge.is-warning{color:#a16207!important;background:#fef3c7!important}
html[data-theme="light"] body.is-client .db-badge.is-pending{color:#6b21a8!important;background:#f3e8ff!important}

/* Admin light */
html[data-theme="light"] body.is-admin .page-head p,
html[data-theme="light"] body.is-admin .admin-page-sub,
html[data-theme="light"] body.is-admin .dashboard-kpi .kpi-label,
html[data-theme="light"] body.is-admin .text-\[11px\],
html[data-theme="light"] body.is-admin .text-xs{
  color:var(--mu,#64748b)!important;
}
html[data-theme="light"] body.is-admin .dashboard-kpi-value,
html[data-theme="light"] body.is-admin .ad-kpi b,
html[data-theme="light"] body.is-admin .font-bold{
  color:var(--tx,#0f172a)!important;
}
html[data-theme="dark"] body.is-admin .page-head p,
html[data-theme="dark"] body.is-admin .admin-page-sub{
  color:var(--mu,#94a3b8)!important;
}
html[data-theme="dark"] body.is-admin .dashboard-kpi-value,
html[data-theme="dark"] body.is-admin .ad-kpi b{
  color:var(--tx,#e5e7eb)!important;
}

/* Classic theme light — kill residual dark-card / light-text pairs */
html[data-ui-theme="classic"][data-theme="light"] body.is-client .card,
html[data-ui-theme="classic"][data-theme="light"] body.is-client .ui-card,
html[data-ui-theme="classic"][data-theme="light"] body.is-client .xo-card,
html[data-ui-theme="classic"][data-theme="light"] body.is-client .xo-stat,
html[data-ui-theme="classic"][data-theme="light"] body.is-client .afx-card,
html[data-ui-theme="classic"][data-theme="light"] body.is-client .u6-card,
html[data-ui-theme="classic"][data-theme="light"] body.is-client .client-section,
html[data-ui-theme="classic"][data-theme="light"] body.is-client .dash-card,
html[data-ui-theme="classic"][data-theme="light"] body.is-client .api-card,
html[data-ui-theme="classic"][data-theme="light"] body.is-client .svc-group,
html[data-ui-theme="classic"][data-theme="light"] body.is-client .mo-filter,
html[data-ui-theme="classic"][data-theme="light"] body.is-client .mo-stat{
  background:#fff!important;
  color:#0f172a!important;
  border-color:#e2e8f0!important;
  box-shadow:0 10px 28px rgba(15,23,42,.06)!important;
}
html[data-ui-theme="classic"][data-theme="light"] body.is-client h1,
html[data-ui-theme="classic"][data-theme="light"] body.is-client h2,
html[data-ui-theme="classic"][data-theme="light"] body.is-client h3,
html[data-ui-theme="classic"][data-theme="light"] body.is-client h4{
  color:#0f172a!important;
}
html[data-ui-theme="classic"][data-theme="light"] body.is-client{
  color:#0f172a!important;
}

/* Public pages (guest) */
html[data-theme="light"] .ppg-title,
html[data-theme="light"] .page-body,
html[data-theme="light"] .ppg-card{color:var(--tx,#0f172a)!important}
html[data-theme="dark"] .ppg-title,
html[data-theme="dark"] .page-body,
html[data-theme="dark"] .ppg-card{color:var(--tx,#e5e7eb)!important}
html[data-theme="light"] .ppg-sub,
html[data-theme="light"] .ppg-crumb{color:var(--mu,#64748b)!important}
html[data-theme="dark"] .ppg-sub,
html[data-theme="dark"] .ppg-crumb{color:var(--mu,#94a3b8)!important}
html[data-theme="light"] .ppg-card,
html[data-theme="light"] .ppg-aside-card{
  background:var(--card,#fff)!important;
  border-color:var(--bd,#e2e8f0)!important;
}
html[data-theme="dark"] .ppg-card,
html[data-theme="dark"] .ppg-aside-card{
  background:var(--card,#111827)!important;
  border-color:var(--bd,#1f2a3a)!important;
}

/* Auth */
html[data-theme="light"] .auth-title,
html[data-theme="light"] .auth-label,
html[data-theme="light"] .auth-input{color:var(--tx,#0f172a)!important}
html[data-theme="dark"] .auth-title,
html[data-theme="dark"] .auth-label,
html[data-theme="dark"] .auth-input{color:var(--tx,#e5e7eb)!important}
html[data-theme="light"] .auth-box{
  background:var(--card,#fff)!important;
  border-color:var(--bd,#e2e8f0)!important;
  color:var(--tx,#0f172a)!important;
}
html[data-theme="dark"] .auth-box{
  background:var(--card,#111827)!important;
  border-color:var(--bd,#1f2a3a)!important;
  color:var(--tx,#e5e7eb)!important;
}

/* Never force near-white text in light mode outside primary surfaces */
html[data-theme="light"] body.is-client .main-pad,
html[data-theme="light"] body.is-admin .main-pad{
  color:var(--tx,#0f172a)!important;
}
html[data-theme="dark"] body.is-client .main-pad,
html[data-theme="dark"] body.is-admin .main-pad{
  color:var(--tx,#e5e7eb)!important;
}

/* Keep white text only on primary-colored controls */
html[data-theme="light"] body.is-client .btn-primary,
html[data-theme="light"] body.is-client .btn-b,
html[data-theme="light"] body.is-client .xo-submit,
html[data-theme="light"] body.is-client .afx-submit,
html[data-theme="light"] body.is-client .svc-btn.primary,
html[data-theme="light"] body.is-admin .btn-primary,
html[data-theme="light"] body.is-admin .btn-b,
html[data-theme="dark"] body.is-client .btn-primary,
html[data-theme="dark"] body.is-client .btn-b,
html[data-theme="dark"] body.is-client .xo-submit,
html[data-theme="dark"] body.is-client .afx-submit,
html[data-theme="dark"] body.is-client .svc-btn.primary,
html[data-theme="dark"] body.is-admin .btn-primary{
  color:#fff!important;
}
