/* APK 2027 final dark-mode text/readability layer.
   Loaded last. Purpose: eliminate white-on-white / black-on-black states caused by legacy inline styles. */
:root{
  --apk-radius: 18px;
}
html[data-apk-theme="dark"]{
  --apk-bg: #06111f;
  --apk-bg-2: #09182c;
  --apk-surface: #0f1e33;
  --apk-surface-2: #142641;
  --apk-surface-3: #1a3152;
  --apk-border: rgba(148, 180, 231, .28);
  --apk-border-strong: rgba(148, 180, 231, .42);
  --apk-text: #f7fbff;
  --apk-text-strong: #ffffff;
  --apk-muted: #c9d6ea;
  --apk-muted-2: #9fb2ce;
  --apk-blue: #4f8dff;
  --apk-purple: #8b5cf6;
  --apk-pink: #ff4fa3;
  --apk-green: #34d399;
  --apk-red: #ff5b6c;
  --apk-yellow: #ffd166;
}

html[data-apk-theme="dark"],
html[data-apk-theme="dark"] body{
  background:
    radial-gradient(circle at 88% 8%, rgba(255,79,163,.14), transparent 28%),
    radial-gradient(circle at 10% 10%, rgba(79,141,255,.14), transparent 30%),
    linear-gradient(135deg, var(--apk-bg), var(--apk-bg-2)) !important;
  color: var(--apk-text) !important;
}

html[data-apk-theme="dark"] #app,
html[data-apk-theme="dark"] #main,
html[data-apk-theme="dark"] .main-content,
html[data-apk-theme="dark"] .page-content,
html[data-apk-theme="dark"] .content-wrapper{
  background: transparent !important;
  color: var(--apk-text) !important;
}

/* Global text normalization for dark surfaces */
html[data-apk-theme="dark"] :where(h1,h2,h3,h4,h5,h6,label,legend,p,small,strong,b,span,div,li,td,th,a,em,i){
  color: inherit;
}
html[data-apk-theme="dark"] :where(h1,h2,h3,h4,h5,h6,.page-title,.card-title,.modal-title,.pf-card h2,.pf-card h3,.pf-step-title,.pf-status-title){
  color: var(--apk-text-strong) !important;
  text-shadow: none !important;
}
html[data-apk-theme="dark"] :where(p,small,.text-muted,.muted,.help-text,.form-text,.pf-step-meta,.pf-step-status,.pf-status-hint,.pf-kv span,.pf-guide-item span,.dataTables_info){
  color: var(--apk-muted) !important;
}
html[data-apk-theme="dark"] :where(b,strong,.fw-bold,.font-bold,.pf-kv b,.pf-guide-item b){
  color: var(--apk-text-strong) !important;
}

/* Kill legacy inline white cards / black text in dark mode */
html[data-apk-theme="dark"] [style*="background:#fff"],
html[data-apk-theme="dark"] [style*="background: #fff"],
html[data-apk-theme="dark"] [style*="background:white"],
html[data-apk-theme="dark"] [style*="background: white"],
html[data-apk-theme="dark"] [style*="background-color:#fff"],
html[data-apk-theme="dark"] [style*="background-color: #fff"],
html[data-apk-theme="dark"] [style*="background-color:white"],
html[data-apk-theme="dark"] [style*="background-color: white"]{
  background: var(--apk-surface) !important;
  color: var(--apk-text) !important;
  border-color: var(--apk-border) !important;
}
html[data-apk-theme="dark"] [style*="color:#000"],
html[data-apk-theme="dark"] [style*="color: #000"],
html[data-apk-theme="dark"] [style*="color:black"],
html[data-apk-theme="dark"] [style*="color: black"],
html[data-apk-theme="dark"] [style*="color:#333"],
html[data-apk-theme="dark"] [style*="color: #333"]{
  color: var(--apk-text) !important;
}

/* Surfaces: cards, panels, modals, page-specific containers */
html[data-apk-theme="dark"] :where(.card,.box,.panel,.content-card,.data-card,.section-card,.table-card,.form-card,.apk-card,.apk-panel,.apk-page-hero,.apk-entry-modal__dialog,.modal-content,.modal-body,.modal-header,.modal-footer,.project-flow-page,.pf-hero,.pf-status-card,.pf-card,.pf-kv,.pf-guide-item,.pf-match-list a,.pf-empty,.pf-ok,.pf-warning,.alert,.dropdown-menu,.select2-dropdown,.datepicker,.Zebra_DatePicker){
  background: linear-gradient(135deg, rgba(15,30,51,.98), rgba(20,38,65,.96)) !important;
  color: var(--apk-text) !important;
  border-color: var(--apk-border) !important;
  box-shadow: 0 22px 56px rgba(0,0,0,.30) !important;
}
html[data-apk-theme="dark"] :where(.modal-header,.modal-footer,.card-header,.card-footer){
  background: rgba(20,38,65,.95) !important;
  color: var(--apk-text) !important;
  border-color: var(--apk-border) !important;
}
html[data-apk-theme="dark"] :where(.pf-hero:before,.pf-hero:after){
  opacity: .55 !important;
}
html[data-apk-theme="dark"] :where(.pf-eyebrow,.badge,.apk-badge,.brand-pill,.status-pill){
  background: rgba(255,79,163,.12) !important;
  border-color: rgba(255,79,163,.34) !important;
  color: #ffd7ea !important;
}
html[data-apk-theme="dark"] :where(.pf-badge,.pf-badge.green,.pf-badge.pink){
  background: rgba(79,141,255,.13) !important;
  border: 1px solid rgba(79,141,255,.32) !important;
  color: #dbeafe !important;
}

/* Sidebar + submenu fix: no white popout with white text */
html[data-apk-theme="dark"] :where(#sidebar,.sidebar-wrapper,.sidebar-menu,.sidebar-header,.sidebar-content,.menu,.submenu,.sidebar-submenu,.dropdown-content){
  background: var(--apk-surface) !important;
  color: var(--apk-text) !important;
  border-color: var(--apk-border) !important;
}
html[data-apk-theme="dark"] :where(#sidebar a,#sidebar .menu-title,#sidebar .sidebar-item,#sidebar .sidebar-link,#sidebar .submenu-item,#sidebar .submenu a,#sidebar li,#sidebar span){
  color: var(--apk-text) !important;
}
html[data-apk-theme="dark"] :where(#sidebar a:hover,#sidebar .sidebar-link:hover,#sidebar .submenu a:hover,#sidebar .active>a){
  background: rgba(79,141,255,.16) !important;
  color: #ffffff !important;
  border-color: rgba(79,141,255,.30) !important;
}

/* Forms, inputs, comboboxes, date fields */
html[data-apk-theme="dark"] :where(input,select,textarea,.form-control,.form-select,.custom-select,.select2-selection,.select2-selection__rendered,.select2-search__field){
  background: #0b1a2e !important;
  color: var(--apk-text) !important;
  border-color: var(--apk-border-strong) !important;
  box-shadow: none !important;
  caret-color: #ffffff !important;
}
html[data-apk-theme="dark"] :where(input::placeholder,textarea::placeholder,.select2-selection__placeholder){
  color: var(--apk-muted-2) !important;
  opacity: 1 !important;
}
html[data-apk-theme="dark"] :where(input:focus,select:focus,textarea:focus,.form-control:focus,.select2-container--open .select2-selection){
  background: #0f223d !important;
  border-color: var(--apk-blue) !important;
  color: #ffffff !important;
  box-shadow: 0 0 0 4px rgba(79,141,255,.18) !important;
}
html[data-apk-theme="dark"] :where(.select2-results__option){
  background: var(--apk-surface) !important;
  color: var(--apk-text) !important;
}
html[data-apk-theme="dark"] :where(.select2-results__option--highlighted,.select2-results__option[aria-selected="true"]){
  background: linear-gradient(135deg, #2563eb, #7c3aed) !important;
  color: #ffffff !important;
}

/* Tables: consistent dark rows + readable text */
html[data-apk-theme="dark"] :where(.table,table,.dataTable,.pf-table){
  background: var(--apk-surface) !important;
  color: var(--apk-text) !important;
  border-color: var(--apk-border) !important;
}
html[data-apk-theme="dark"] :where(.table thead th,table thead th,.dataTable thead th,.pf-table th){
  background: #1b2f50 !important;
  color: #eaf2ff !important;
  border-color: var(--apk-border) !important;
}
html[data-apk-theme="dark"] :where(.table tbody tr,table tbody tr,.dataTable tbody tr,.pf-table tbody tr){
  background: #0e1d32 !important;
  color: var(--apk-text) !important;
}
html[data-apk-theme="dark"] :where(.table tbody tr:nth-child(even),table tbody tr:nth-child(even),.dataTable tbody tr:nth-child(even),.pf-table tbody tr:nth-child(even)){
  background: #13243c !important;
}
html[data-apk-theme="dark"] :where(.table tbody tr:hover,table tbody tr:hover,.dataTable tbody tr:hover,.pf-table tbody tr:hover){
  background: #1b3356 !important;
}
html[data-apk-theme="dark"] :where(.table td,table td,.dataTable td,.pf-table td){
  background: transparent !important;
  color: var(--apk-text) !important;
  border-color: var(--apk-border) !important;
  -webkit-text-fill-color: var(--apk-text) !important;
}
html[data-apk-theme="dark"] :where(.table td a,table td a,.dataTable td a,.pf-table td a){
  color: #dbeafe !important;
  -webkit-text-fill-color: #dbeafe !important;
}
html[data-apk-theme="dark"] :where(.dataTables_wrapper,.dataTables_length,.dataTables_filter,.dataTables_paginate){
  color: var(--apk-text) !important;
}

/* Buttons: primary/print/action must stay visible; close/cancel must be clickable/readable */
html[data-apk-theme="dark"] :where(button,.btn,a.btn,input[type="submit"],input[type="button"],.apk-btn,.pf-btn){
  border-radius: 999px !important;
  color: #ffffff !important;
  -webkit-text-fill-color: #ffffff !important;
  text-shadow: none !important;
  position: relative;
  pointer-events: auto !important;
}
html[data-apk-theme="dark"] :where(.btn-light,.btn-secondary,.btn-outline-secondary,.btn-close,.close,.modal-close,.apk-modal-close,[data-dismiss="modal"],button[aria-label="Close"]){
  background: #203653 !important;
  color: #ffffff !important;
  border: 1px solid var(--apk-border-strong) !important;
  -webkit-text-fill-color: #ffffff !important;
}
html[data-apk-theme="dark"] :where(.btn-primary,.btn-info,.btn-print,.apk-print-button,.print-button,.apk-flow-link,.apk-flow-btn,.btn-submit,.btn-success,input[type="submit"]){
  background: linear-gradient(135deg, #2563eb 0%, #7c3aed 58%, #ec4899 100%) !important;
  color: #ffffff !important;
  -webkit-text-fill-color: #ffffff !important;
  border: 0 !important;
  box-shadow: 0 14px 30px rgba(79,141,255,.30), 0 0 0 1px rgba(255,255,255,.08) inset !important;
}
html[data-apk-theme="dark"] :where(.btn-danger,.delete,.btn-delete){
  background: linear-gradient(135deg, #ef4444, #e11d48) !important;
  color: #ffffff !important;
  -webkit-text-fill-color: #ffffff !important;
}
html[data-apk-theme="dark"] :where(.btn:hover,.apk-btn:hover,.pf-btn:hover){
  filter: brightness(1.10) saturate(1.10) !important;
  transform: translateY(-1px);
}

/* Pagination */
html[data-apk-theme="dark"] :where(.pagination,.dataTables_paginate){
  background: transparent !important;
  color: var(--apk-text) !important;
}
html[data-apk-theme="dark"] :where(.pagination .page-link,.paginate_button,.dataTables_paginate a){
  background: #0f223d !important;
  color: #eaf2ff !important;
  border-color: var(--apk-border) !important;
  -webkit-text-fill-color: #eaf2ff !important;
}
html[data-apk-theme="dark"] :where(.pagination .active .page-link,.paginate_button.current,.dataTables_paginate a.current){
  background: linear-gradient(135deg, #2563eb, #7c3aed) !important;
  color: #ffffff !important;
  -webkit-text-fill-color: #ffffff !important;
  border-color: transparent !important;
}
html[data-apk-theme="dark"] :where(.paginate_button.disabled,.page-item.disabled .page-link){
  background: #111c2c !important;
  color: #7f92ad !important;
  -webkit-text-fill-color: #7f92ad !important;
}

/* Datepicker / calendar widgets */
html[data-apk-theme="dark"] :where(.Zebra_DatePicker,.Zebra_DatePicker *,.datepicker,.datepicker *){
  color: var(--apk-text) !important;
  border-color: var(--apk-border) !important;
}
html[data-apk-theme="dark"] :where(.Zebra_DatePicker td,.Zebra_DatePicker th,.datepicker td,.datepicker th){
  background: var(--apk-surface) !important;
  color: var(--apk-text) !important;
}
html[data-apk-theme="dark"] :where(.Zebra_DatePicker .dp_selected,.datepicker .active){
  background: linear-gradient(135deg,#2563eb,#7c3aed) !important;
  color:#ffffff !important;
}

/* Flow Progress page-specific inline style override */
html[data-apk-theme="dark"] .project-flow-page :where(.pf-card,.pf-hero,.pf-status-card,.pf-kv,.pf-guide-item,.pf-match-list a,.pf-empty,.pf-ok,.pf-warning){
  background: linear-gradient(135deg, #101f35, #152845) !important;
  color: var(--apk-text) !important;
  border-color: var(--apk-border) !important;
}
html[data-apk-theme="dark"] .project-flow-page :where(.pf-card *,.pf-hero *,.pf-status-card *,.pf-kv *,.pf-guide-item *,.pf-step *,.pf-empty,.pf-ok,.pf-warning){
  color: var(--apk-text) !important;
  -webkit-text-fill-color: currentColor !important;
}
html[data-apk-theme="dark"] .project-flow-page :where(.pf-step-role,.pf-status-label){
  color: #8bb8ff !important;
}
html[data-apk-theme="dark"] .project-flow-page :where(.pf-step-meta,.pf-step-status,.pf-status-hint,.pf-kv span,.pf-guide-item span){
  color: var(--apk-muted) !important;
}

/* Keep true white text on gradient buttons, even inside tables. */
html[data-apk-theme="dark"] :where(button,a.btn,.btn,.apk-btn,.pf-btn,.btn *){
  -webkit-text-fill-color: currentColor !important;
}
html[data-apk-theme="dark"] :where(.btn-primary,.btn-info,.btn-success,.btn-danger,.btn-print,.apk-print-button,.print-button,.apk-flow-link,.apk-flow-btn,.btn-submit,input[type="submit"]),
html[data-apk-theme="dark"] :where(.btn-primary *,.btn-info *,.btn-success *,.btn-danger *,.btn-print *,.apk-print-button *,.print-button *,.apk-flow-link *,.apk-flow-btn *,.btn-submit *){
  color:#ffffff !important;
  -webkit-text-fill-color:#ffffff !important;
}

/* Light mode minor safety: button text on gradients stays white. */
html[data-apk-theme="light"] :where(.btn-primary,.btn-info,.btn-success,.btn-danger,.btn-print,.apk-print-button,.print-button,.apk-flow-link,.apk-flow-btn,.btn-submit,input[type="submit"]),
html[data-apk-theme="light"] :where(.btn-primary *,.btn-info *,.btn-success *,.btn-danger *,.btn-print *,.apk-print-button *,.print-button *,.apk-flow-link *,.apk-flow-btn *,.btn-submit *){
  color:#ffffff !important;
  -webkit-text-fill-color:#ffffff !important;
}

html[data-apk-theme="dark"] .apk-text-contrast-fixed{color:var(--apk-text) !important;-webkit-text-fill-color:var(--apk-text) !important;}
