/* CA Portal v1.16.40 — Phase 2: module colour and legibility refinement.
 * Presentation only. This file does not change business rules, DOM visibility,
 * pointer events, form state, positioning, modal open/close or printed output.
 * Loaded AFTER the v1.16.39 shared design stylesheet on portal screens.
 */
@media screen {
  body.msa-crystal-ui {
    --ca40-navy: #143e5f;
    --ca40-muted: #46677e;
    --ca40-line: #c1dbe9;
    --ca40-soft-blue: #edf7ff;
    --ca40-soft-teal: #e9faf3;
    --ca40-shadow: 0 8px 24px rgba(20,67,101,.10);
  }

  /* Common page panels, respecting the original module layout and gradients. */
  body.msa-crystal-ui :is(
    .staff-modern-priority-card,.staff-modern-module-grid > *,
    .client-desk-new-panel,.desk-gst-kpi,.desk-quick-tile,
    .billing51-page .billingx-priority-card,.billing51-page .billingx-stat,
    .cgw-v85 .cgw-card,.cgw-v85 .cgw-glass-kpi,
    .ch-final-dashboard .ch-account-panel,.ch-final-dashboard .ch-business-card,
    .spay .spay-panel,.ep-panel,.ep-stat,.ep-overview-kpi
  ) {
    border-color: var(--ca40-line) !important;
    box-shadow: var(--ca40-shadow);
  }

  /* Dashboard — headings, descriptive text and compact action labels. */
  body.portal-context-staff.msa-crystal-ui :is(
    .staff-modern-hero-compact,.staff-modern-section-head,
    .staff-modern-quick-head,.staff-modern-module-grid
  ) :is(h1,h2,h3) { color: #163e60; text-wrap: pretty; }
  body.portal-context-staff.msa-crystal-ui .staff-modern-priority-card :is(.priority-copy,small),
  body.portal-context-staff.msa-crystal-ui .staff-modern-hero-compact p {
    color: #41657e;
    line-height: 1.5;
  }
  body.portal-context-staff.msa-crystal-ui .staff-modern-priority-card :is(a,button):focus-visible {
    outline: 3px solid #0577a3 !important;
    outline-offset: 3px;
  }

  /* Client search register — scanning aid for wide tables; no columns removed. */
  body.portal-context-staff.msa-crystal-ui .client-desk-body :is(
    .client-desk-toolbar,.client-desk-new-panel,.desk-detail-title
  ) { border-color: #bbdce9; }
  body.portal-context-staff.msa-crystal-ui .client-desk-table th {
    color: #193f5c !important;
    background: linear-gradient(115deg,#e4f3ff,#e4f9f1) !important;
    font-weight: 800;
  }
  body.portal-context-staff.msa-crystal-ui .client-desk-table td { border-color: #d7e6ef; }
  body.portal-context-staff.msa-crystal-ui .client-desk-body :is(
    .desk-gst-kpi,.desk-detail-kv,.desk-quick-tile
  ) small { color: #44657b; }
  body.portal-context-staff.msa-crystal-ui .client-desk-toolbar :is(input,select) {
    border-color: #a9cddf;
    background-color: #fff;
    color: #173f5f;
  }

  /* Billing: legible dense financial lists, preserving paid/due status colours. */
  body.portal-context-staff.msa-crystal-ui .billing51-page :is(
    .billingx-priority-head,.billing51-section-nav,.billingx-hero-meta
  ) :is(h1,h2,h3) { color: #173e60; }
  body.portal-context-staff.msa-crystal-ui .billing51-page :is(
    .billingx-table,.billingx-priority-table
  ) thead th {
    color: #173e60 !important;
    background: linear-gradient(110deg,#e3f2ff,#e3f9ee) !important;
    border-bottom: 1px solid #b7d7e5;
    font-weight: 800;
  }
  body.portal-context-staff.msa-crystal-ui .billing51-page :is(
    .billingx-table,.billingx-priority-table
  ) tbody td { border-bottom-color: #dce9f0; }
  body.portal-context-staff.msa-crystal-ui .billing51-page :is(
    .billingx-muted,.billingx-hero-meta small
  ) { color: #46677e !important; }
  body.portal-context-staff.msa-crystal-ui .billing51-page :is(
    .billing49-find input,.billingx-form input,.billingx-form select
  ) { border-color: #b0d1e1; background-color: #fff; color: #163e5e; }

  /* Tax dashboard: badges/status semantics remain owned by GST feature CSS. */
  body.portal-context-client.msa-crystal-ui .cgw-v85 :is(.cgw-head,.cgw-filter-intro,.cgw-work-title),
  body.portal-context-client.msa-crystal-ui .ch-final-dashboard :is(
    .ch-section-head,.ch-business-card
  ) :is(h2,h3) { color: #183f5e; }
  body.portal-context-client.msa-crystal-ui .cgw-v85 :is(
    .cgw-filter,.cgw-card,.cgw-glass-kpi,.cbr-card
  ) { border-color: #bcdce9; }
  body.portal-context-client.msa-crystal-ui .cgw-v85 :is(
    .cgw-tool-copy small,.cgw-filter-intro p,.cgw-disclaimer
  ) { color: #42667e; line-height: 1.5; }
  body.portal-context-client.msa-crystal-ui .cgw-v85 :is(input,select) {
    border-color: #adcddd;
    color: #193f5c;
  }
  body.portal-context-client.msa-crystal-ui .ch-final-dashboard :is(
    .ch-business-card,.ch-account-panel
  ) { border-color: #bddce9; }

  /* Simplex Bank Book / salary: respect the v1.16.37+ modal footer and fields.
     Only text legibility, borders and keyboard focus are refined here. */
  body.portal-context-staff.msa-crystal-ui .sbb :is(
    .sbb-tax-client-details,.sbb-trans-panel,.sbb-table-wrap
  ) { border-color: #bbdce9; }
  body.portal-context-staff.msa-crystal-ui .sbb :is(
    .sbb-muted,.sbb-footnote,.sbb-tax-client-grid small
  ) { color: #42647a !important; }
  body.portal-context-staff.msa-crystal-ui .spay :is(
    .spay-panel,.spay-quick-item,.spay-attendance-form
  ) { border-color: #bddbe9; }
  body.portal-context-staff.msa-crystal-ui .spay :is(
    .spay-quick-item small,.spay-att-legend small
  ) { color: #45657a; }
  body.portal-context-staff.msa-crystal-ui .spay :is(
    input:not([type=checkbox]):not([type=radio]),select,textarea
  ) { border-color: #b4d3e1; color: #143e5e; }

  /* Office Head payments, tax, bank and audit reconciliation screens. */
  body.portal-context-staff.msa-crystal-ui :is(
    .ep-hero,.ep-panel,.ep-stat,.ep-overview-kpi,.ep-form
  ) { border-color: #bddae9; }
  body.portal-context-staff.msa-crystal-ui .ep-hero p { color: #446780; }
  body.portal-context-staff.msa-crystal-ui :is(
    .ep-table,.ep-overview-table,.ep-bulk-table,.ep-tracker-table
  ) thead th {
    background: linear-gradient(110deg,#e6f3ff,#eafbf3) !important;
    color: #1c4560 !important;
    border-bottom: 1px solid #bfdae7;
  }

  /* Admin list pages: consistent table heading contrast, no table structure edit. */
  body.portal-context-admin.msa-crystal-ui .table-wrap > table thead th {
    color: #193f5c !important;
    background: linear-gradient(110deg,#e4f3ff,#e7f8f1) !important;
    border-bottom: 1px solid #c4dce8;
    font-weight: 800;
  }
  body.portal-context-admin.msa-crystal-ui .table-wrap > table tbody td {
    border-bottom-color: #ddeaf1;
  }
  body.portal-context-admin.msa-crystal-ui .form-card :is(h1,h2,h3) {
    color: #153f60;
  }

  /* Field and button visibility. Never force display/enable a disabled action. */
  body.msa-crystal-ui :is(
    .client-desk-body,.billing51-page,.spay,.ep-hero,.ep-panel,.cgw-v85
  ) :is(label,legend) { color: #284d68; }
  body.msa-crystal-ui :is(
    .client-desk-body,.billing51-page,.spay,.ep-panel,.cgw-v85
  ) :is(input,textarea)::placeholder { color: #54738a; opacity: 1; }
  body.msa-crystal-ui :is(.btn,.btn-small,.sbb-btn,.ep-btn,.spay-pay):disabled {
    filter: none;
    opacity: .72;
    cursor: not-allowed;
  }
  body.msa-crystal-ui :is(.table-wrap,.client-desk-table-wrap,.billingx-scroll) {
    scrollbar-color: #9bbccc #eff7fb;
    scrollbar-width: thin;
  }
}

@media screen and (max-width: 760px) {
  body.msa-crystal-ui :is(
    .staff-modern-priority-card,.client-desk-new-panel,.spay-panel,
    .ep-panel,.ep-hero,.billing51-page .billingx-priority-card
  ) { border-radius: 14px; }
  body.msa-crystal-ui :is(
    .client-desk-table-wrap,.billingx-scroll,.ep-table-wrap,.sbb-table-wrap
  ) { -webkit-overflow-scrolling: touch; }
  body.msa-crystal-ui :is(.staff-modern-hero-compact,.ep-hero) :is(h1,h2) {
    overflow-wrap: anywhere;
  }
}

@media (prefers-reduced-motion: reduce) {
  body.msa-crystal-ui :is(.staff-modern-priority-card,.desk-quick-tile,.billingx-stat) {
    animation: none;
  }
}
