/* APK Dark Mode Hardfix 2027
   Loaded last. Fixes mixed white/dark table rows, unreadable text, legacy inline backgrounds,
   sidebar cards, DataTables controls, and dark-mode widget contrast without changing app flow. */

html[data-apk-theme="dark"]{
  color-scheme: dark;
  --apk-bg:#070d19;
  --apk-bg-2:#0a1324;
  --apk-surface:#101b2f;
  --apk-surface-2:#15223a;
  --apk-surface-3:#1b2d4a;
  --apk-table-head:#1d3152;
  --apk-table-row:#101c31;
  --apk-table-row-alt:#16243d;
  --apk-table-hover:#20365a;
  --apk-text:#f8fbff;
  --apk-text-2:#e6f0ff;
  --apk-muted:#b8c7dd;
  --apk-line:#33527e;
  --apk-line-strong:#5c81b9;
  --apk-primary:#7ab7ff;
  --apk-primary-2:#a78bfa;
  --apk-primary-3:#f472b6;
  --apk-success:#4ade80;
  --apk-danger:#fb7185;
  --apk-warning:#facc15;
  --apk-info:#67e8f9;
}

html[data-apk-theme="dark"],
html[data-apk-theme="dark"] body{
  background:#070d19!important;
  background-image:linear-gradient(135deg,#070d19 0%,#0a1324 55%,#130d22 100%)!important;
  color:var(--apk-text)!important;
  -webkit-text-fill-color:initial!important;
}

/* Main layout + cards */
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"] .apk-page-content{
  background:transparent!important;
  color:var(--apk-text)!important;
}
html[data-apk-theme="dark"] .sidebar-wrapper,
html[data-apk-theme="dark"] #sidebar,
html[data-apk-theme="dark"] .card,
html[data-apk-theme="dark"] .card-body,
html[data-apk-theme="dark"] .apk-topbar,
html[data-apk-theme="dark"] .apk-user-card,
html[data-apk-theme="dark"] .apk-menu-shell,
html[data-apk-theme="dark"] .apk-panel,
html[data-apk-theme="dark"] .apk-list-panel,
html[data-apk-theme="dark"] .apk-filter-panel,
html[data-apk-theme="dark"] .apk-form-panel,
html[data-apk-theme="dark"] .modal-content,
html[data-apk-theme="dark"] .dropdown-menu{
  background:rgba(16,27,47,.96)!important;
  background-image:none!important;
  color:var(--apk-text)!important;
  -webkit-text-fill-color:initial!important;
  border-color:var(--apk-line)!important;
  box-shadow:0 22px 60px rgba(0,0,0,.42)!important;
}

html[data-apk-theme="dark"] .apk-topbar h1,
html[data-apk-theme="dark"] .apk-topbar h2,
html[data-apk-theme="dark"] .apk-page-title,
html[data-apk-theme="dark"] .apk-section-title,
html[data-apk-theme="dark"] h1,
html[data-apk-theme="dark"] h2,
html[data-apk-theme="dark"] h3,
html[data-apk-theme="dark"] h4,
html[data-apk-theme="dark"] h5,
html[data-apk-theme="dark"] h6,
html[data-apk-theme="dark"] label,
html[data-apk-theme="dark"] .form-label,
html[data-apk-theme="dark"] .sidebar-link,
html[data-apk-theme="dark"] .sidebar-link span,
html[data-apk-theme="dark"] .submenu-item a{
  color:var(--apk-text)!important;
  -webkit-text-fill-color:var(--apk-text)!important;
}
html[data-apk-theme="dark"] p,
html[data-apk-theme="dark"] small,
html[data-apk-theme="dark"] .small,
html[data-apk-theme="dark"] .text-muted,
html[data-apk-theme="dark"] .apk-date,
html[data-apk-theme="dark"] .apk-welcome,
html[data-apk-theme="dark"] .dataTables_info{
  color:var(--apk-muted)!important;
  -webkit-text-fill-color:var(--apk-muted)!important;
}

/* DataTables / table hard reset: prevents white row + white text bugs. */
html[data-apk-theme="dark"] .table-responsive,
html[data-apk-theme="dark"] .apk-table-shell,
html[data-apk-theme="dark"] .dataTables_wrapper,
html[data-apk-theme="dark"] #table1{
  background:var(--apk-surface)!important;
  background-image:none!important;
  color:var(--apk-text)!important;
  border-color:var(--apk-line)!important;
}
html[data-apk-theme="dark"] table,
html[data-apk-theme="dark"] .table,
html[data-apk-theme="dark"] table.table,
html[data-apk-theme="dark"] table.dataTable,
html[data-apk-theme="dark"] .apk-data-table{
  background:var(--apk-surface)!important;
  background-color:var(--apk-surface)!important;
  background-image:none!important;
  color:var(--apk-text)!important;
  border-color:var(--apk-line)!important;
}
html[data-apk-theme="dark"] table thead,
html[data-apk-theme="dark"] table thead tr,
html[data-apk-theme="dark"] table thead th,
html[data-apk-theme="dark"] .table thead th,
html[data-apk-theme="dark"] table.dataTable thead th,
html[data-apk-theme="dark"] table.dataTable thead td{
  background:var(--apk-table-head)!important;
  background-color:var(--apk-table-head)!important;
  background-image:none!important;
  color:var(--apk-text-2)!important;
  -webkit-text-fill-color:var(--apk-text-2)!important;
  border-color:var(--apk-line)!important;
}
html[data-apk-theme="dark"] table tbody,
html[data-apk-theme="dark"] table tbody tr,
html[data-apk-theme="dark"] .table tbody tr,
html[data-apk-theme="dark"] table.dataTable tbody tr{
  background:var(--apk-table-row)!important;
  background-color:var(--apk-table-row)!important;
  background-image:none!important;
  color:var(--apk-text)!important;
}
html[data-apk-theme="dark"] table tbody tr:nth-child(odd),
html[data-apk-theme="dark"] table tbody tr.odd,
html[data-apk-theme="dark"] table.dataTable tbody tr.odd,
html[data-apk-theme="dark"] .table-striped tbody tr:nth-of-type(odd){
  background:var(--apk-table-row)!important;
  background-color:var(--apk-table-row)!important;
  background-image:none!important;
}
html[data-apk-theme="dark"] table tbody tr:nth-child(even),
html[data-apk-theme="dark"] table tbody tr.even,
html[data-apk-theme="dark"] table.dataTable tbody tr.even,
html[data-apk-theme="dark"] .table-striped tbody tr:nth-of-type(even){
  background:var(--apk-table-row-alt)!important;
  background-color:var(--apk-table-row-alt)!important;
  background-image:none!important;
}
html[data-apk-theme="dark"] table tbody tr > th,
html[data-apk-theme="dark"] table tbody tr > td,
html[data-apk-theme="dark"] .table tbody tr > th,
html[data-apk-theme="dark"] .table tbody tr > td,
html[data-apk-theme="dark"] table.dataTable tbody tr > th,
html[data-apk-theme="dark"] table.dataTable tbody tr > td,
html[data-apk-theme="dark"] table tbody tr > td[style],
html[data-apk-theme="dark"] table tbody tr[style] > td{
  background:inherit!important;
  background-color:inherit!important;
  background-image:none!important;
  color:var(--apk-text)!important;
  -webkit-text-fill-color:var(--apk-text)!important;
  border-color:var(--apk-line)!important;
  text-shadow:none!important;
}
html[data-apk-theme="dark"] table tbody tr:hover,
html[data-apk-theme="dark"] table tbody tr:hover > td,
html[data-apk-theme="dark"] .table tbody tr:hover > td,
html[data-apk-theme="dark"] table.dataTable tbody tr:hover > td{
  background:var(--apk-table-hover)!important;
  background-color:var(--apk-table-hover)!important;
  color:#ffffff!important;
  -webkit-text-fill-color:#ffffff!important;
}
html[data-apk-theme="dark"] table tbody a:not(.btn):not(.apk-action-btn),
html[data-apk-theme="dark"] table tbody span,
html[data-apk-theme="dark"] table tbody b,
html[data-apk-theme="dark"] table tbody strong{
  color:inherit!important;
  -webkit-text-fill-color:inherit!important;
}

/* Inputs, search fields, select, dropdown, datepicker */
html[data-apk-theme="dark"] input,
html[data-apk-theme="dark"] textarea,
html[data-apk-theme="dark"] select,
html[data-apk-theme="dark"] .form-control,
html[data-apk-theme="dark"] .custom-select,
html[data-apk-theme="dark"] .dataTables_filter input,
html[data-apk-theme="dark"] .dataTables_length select,
html[data-apk-theme="dark"] .select2-container .select2-selection,
html[data-apk-theme="dark"] .select2-dropdown,
html[data-apk-theme="dark"] .select2-search__field,
html[data-apk-theme="dark"] .select2-results__option,
html[data-apk-theme="dark"] .Zebra_DatePicker,
html[data-apk-theme="dark"] .Zebra_DatePicker table,
html[data-apk-theme="dark"] .Zebra_DatePicker td,
html[data-apk-theme="dark"] .Zebra_DatePicker th{
  background:var(--apk-surface-2)!important;
  background-color:var(--apk-surface-2)!important;
  background-image:none!important;
  color:var(--apk-text)!important;
  -webkit-text-fill-color:var(--apk-text)!important;
  border-color:var(--apk-line)!important;
}
html[data-apk-theme="dark"] ::placeholder{color:var(--apk-muted)!important;-webkit-text-fill-color:var(--apk-muted)!important;opacity:1!important;}
html[data-apk-theme="dark"] .select2-container--default .select2-selection--single .select2-selection__rendered,
html[data-apk-theme="dark"] .select2-container--default .select2-selection--multiple .select2-selection__rendered,
html[data-apk-theme="dark"] .select2-selection__choice{
  color:var(--apk-text)!important;
  -webkit-text-fill-color:var(--apk-text)!important;
}
html[data-apk-theme="dark"] .select2-results__option--highlighted,
html[data-apk-theme="dark"] .select2-container--default .select2-results__option--highlighted[aria-selected]{
  background:linear-gradient(135deg,#2563eb,#7c3aed)!important;
  color:#fff!important;
  -webkit-text-fill-color:#fff!important;
}

/* Buttons keep same shape but use readable dark contrast. */
html[data-apk-theme="dark"] button,
html[data-apk-theme="dark"] .btn,
html[data-apk-theme="dark"] .button,
html[data-apk-theme="dark"] input[type="submit"],
html[data-apk-theme="dark"] input[type="button"],
html[data-apk-theme="dark"] a.btn,
html[data-apk-theme="dark"] .apk-action-btn,
html[data-apk-theme="dark"] .dt-button,
html[data-apk-theme="dark"] .apk-top-action{
  color:#fff!important;
  -webkit-text-fill-color:#fff!important;
  background:linear-gradient(135deg,#2563eb,#7c3aed)!important;
  border:1px solid rgba(255,255,255,.12)!important;
  box-shadow:0 12px 28px rgba(37,99,235,.28)!important;
}
html[data-apk-theme="dark"] .apk-theme-toggle,
html[data-apk-theme="dark"] [data-apk-theme-toggle]{
  background:var(--apk-surface-3)!important;
  color:#fff!important;
  -webkit-text-fill-color:#fff!important;
  border:1px solid var(--apk-line-strong)!important;
  box-shadow:0 10px 26px rgba(0,0,0,.30)!important;
}
html[data-apk-theme="dark"] .apk-action-btn--success,
html[data-apk-theme="dark"] .btn-success,
html[data-apk-theme="dark"] input[value="Approve"],
html[data-apk-theme="dark"] input[value="Done"],
html[data-apk-theme="dark"] input[value="Ready!"]{background:linear-gradient(135deg,#15803d,#22c55e)!important;color:#fff!important;-webkit-text-fill-color:#fff!important;}
html[data-apk-theme="dark"] .apk-action-btn--danger,
html[data-apk-theme="dark"] .btn-danger,
html[data-apk-theme="dark"] input[value="Delete"],
html[data-apk-theme="dark"] input[value="Reject"]{background:linear-gradient(135deg,#dc2626,#fb7185)!important;color:#fff!important;-webkit-text-fill-color:#fff!important;}
html[data-apk-theme="dark"] .apk-action-btn--print,
html[data-apk-theme="dark"] .print button{background:linear-gradient(135deg,#0f766e,#06b6d4)!important;color:#fff!important;-webkit-text-fill-color:#fff!important;}

/* Status chips and legacy light utility classes. */
html[data-apk-theme="dark"] .bg-white,
html[data-apk-theme="dark"] .bg-light,
html[data-apk-theme="dark"] .list-group-item{
  background:var(--apk-surface)!important;
  color:var(--apk-text)!important;
  -webkit-text-fill-color:var(--apk-text)!important;
}
html[data-apk-theme="dark"] .text-dark,
html[data-apk-theme="dark"] .text-black{
  color:var(--apk-text)!important;
  -webkit-text-fill-color:var(--apk-text)!important;
}
html[data-apk-theme="dark"] .apk-status-pill--success{background:rgba(34,197,94,.18)!important;color:#86efac!important;-webkit-text-fill-color:#86efac!important;border-color:rgba(134,239,172,.35)!important;}
html[data-apk-theme="dark"] .apk-status-pill--warning{background:rgba(250,204,21,.16)!important;color:#fde68a!important;-webkit-text-fill-color:#fde68a!important;border-color:rgba(253,230,138,.32)!important;}
html[data-apk-theme="dark"] .apk-status-pill--info{background:rgba(96,165,250,.16)!important;color:#bfdbfe!important;-webkit-text-fill-color:#bfdbfe!important;border-color:rgba(191,219,254,.32)!important;}

/* Responsive dark table remains readable. */
@media(max-width:900px){
  html[data-apk-theme="dark"] .dataTables_wrapper{background:var(--apk-surface)!important;}
  html[data-apk-theme="dark"] .table-responsive{border-radius:20px!important;}
}
