/* APK Theme Repair 2027
   Canonical theme layer loaded last. It fixes light/dark/auto colors, contrast,
   legacy white backgrounds, sidebar/topbar/table/modal/select/date widgets, and theme button consistency. */
:root{
  color-scheme: light;
  --apk-bg:#f2f7ff;
  --apk-bg-2:#eaf3ff;
  --apk-surface:#ffffff;
  --apk-surface-2:#f8fbff;
  --apk-surface-3:#eef5ff;
  --apk-text:#0b1b34;
  --apk-text-2:#233a5f;
  --apk-muted:#64748b;
  --apk-line:#d7e6fb;
  --apk-line-strong:#aac5ee;
  --apk-primary:#2563eb;
  --apk-primary-2:#7c3aed;
  --apk-primary-3:#ec4899;
  --apk-success:#16a34a;
  --apk-danger:#dc2626;
  --apk-warning:#d97706;
  --apk-info:#0284c7;
  --apk-btn-text:#ffffff;
  --apk-shadow:0 18px 44px rgba(15,42,95,.12);
  --apk-shadow-sm:0 8px 22px rgba(15,42,95,.09);
  --apk-focus:0 0 0 4px rgba(37,99,235,.18);
  --apk-radius-sm:14px;
  --apk-radius-md:18px;
  --apk-radius-lg:26px;
  --apk-radius-pill:999px;
}
html[data-apk-theme="dark"]{
  color-scheme: dark;
  --apk-bg:#07111f;
  --apk-bg-2:#0b1730;
  --apk-surface:#111d33;
  --apk-surface-2:#16243d;
  --apk-surface-3:#1c2e4c;
  --apk-text:#eef6ff;
  --apk-text-2:#d8e7ff;
  --apk-muted:#a8bad6;
  --apk-line:#2b4368;
  --apk-line-strong:#4f75ad;
  --apk-primary:#60a5fa;
  --apk-primary-2:#a78bfa;
  --apk-primary-3:#f472b6;
  --apk-success:#4ade80;
  --apk-danger:#fb7185;
  --apk-warning:#fbbf24;
  --apk-info:#67e8f9;
  --apk-btn-text:#07111f;
  --apk-shadow:0 20px 58px rgba(0,0,0,.38);
  --apk-shadow-sm:0 10px 26px rgba(0,0,0,.28);
  --apk-focus:0 0 0 4px rgba(96,165,250,.24);
}
html[data-apk-theme="light"]{
  color-scheme: light;
}

html,body{
  background:linear-gradient(135deg,var(--apk-bg) 0%,var(--apk-bg-2) 100%)!important;
  background-image:none!important;
  color:var(--apk-text)!important;
  -webkit-text-fill-color:initial!important;
}
body *{box-sizing:border-box;}
#app,#main,.apk-page-content{
  background:transparent!important;
  color:var(--apk-text)!important;
}
#main[style]{background:transparent!important;color:var(--apk-text)!important;}
.sidebar-wrapper,.sidebar-wrapper.active,#sidebar,#sidebar.active{
  background:var(--apk-surface)!important;
  color:var(--apk-text)!important;
  border-color:var(--apk-line)!important;
  box-shadow:var(--apk-shadow-sm)!important;
}
.sidebar-header,.sidebar-menu,.sidebar-item,.sidebar-link,.submenu-item a,.sidebar-wrapper .menu .sidebar-link span{
  color:var(--apk-text)!important;
  -webkit-text-fill-color:var(--apk-text)!important;
}
.sidebar-link:hover,.sidebar-item.active>.sidebar-link,.submenu-item.active>a{
  background:var(--apk-surface-3)!important;
  color:var(--apk-primary)!important;
  -webkit-text-fill-color:var(--apk-primary)!important;
}
.apk-system-badge,.apk-pill{
  background:var(--apk-surface-2)!important;
  border:1px solid var(--apk-line)!important;
  color:var(--apk-primary-3)!important;
  -webkit-text-fill-color:var(--apk-primary-3)!important;
}

.apk-topbar,.card,.card-body,.apk-panel,.apk-filter-panel,.apk-list-panel,.apk-form-panel,.apk-entry-dialog,.modal-content,.dropdown-menu,.table-responsive,.apk-table-shell{
  background:var(--apk-surface)!important;
  color:var(--apk-text)!important;
  border-color:var(--apk-line)!important;
  box-shadow:var(--apk-shadow)!important;
}
.apk-topbar h1,.apk-topbar h2,.apk-section-title,h1,h2,h3,h4,h5,h6,label,.form-label,.table th,.table td{
  color:var(--apk-text)!important;
  -webkit-text-fill-color:var(--apk-text)!important;
}
p,.text-muted,.apk-topbar p,.apk-help,.small,small,.dataTables_info{
  color:var(--apk-muted)!important;
  -webkit-text-fill-color:var(--apk-muted)!important;
}

/* Inputs and widgets */
.form-control,input[type="text"],input[type="password"],input[type="email"],input[type="number"],input[type="date"],input[type="search"],textarea,select,.custom-select{
  background:var(--apk-surface)!important;
  color:var(--apk-text)!important;
  -webkit-text-fill-color:var(--apk-text)!important;
  border:1.5px solid var(--apk-line)!important;
  border-radius:var(--apk-radius-md)!important;
  box-shadow:none!important;
}
.form-control:focus,input:focus,textarea:focus,select:focus,.custom-select:focus{
  border-color:var(--apk-primary)!important;
  box-shadow:var(--apk-focus)!important;
  outline:none!important;
}
::placeholder{color:var(--apk-muted)!important;-webkit-text-fill-color:var(--apk-muted)!important;opacity:.85!important;}

/* Unified button contrast */
button,.btn,.button,input[type="submit"],input[type="button"],input[type="reset"],a.btn,a.button,.dt-button,.apk-top-action,.apk-action-btn,.apk-theme-toggle,[data-apk-theme-toggle]{
  position:relative!important;
  display:inline-flex!important;
  align-items:center!important;
  justify-content:center!important;
  gap:8px!important;
  min-height:42px!important;
  min-width:auto!important;
  padding:0 18px!important;
  border:0!important;
  border-radius:var(--apk-radius-pill)!important;
  background:linear-gradient(135deg,var(--apk-primary),var(--apk-primary-2))!important;
  color:#fff!important;
  -webkit-text-fill-color:#fff!important;
  font-weight:900!important;
  line-height:1!important;
  text-decoration:none!important;
  cursor:pointer!important;
  pointer-events:auto!important;
  z-index:25!important;
  box-shadow:0 12px 26px rgba(37,99,235,.22)!important;
  transform:none!important;
  opacity:1!important;
  visibility:visible!important;
}
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"] input[type="reset"],html[data-apk-theme="dark"] a.btn,html[data-apk-theme="dark"] a.button,html[data-apk-theme="dark"] .dt-button,html[data-apk-theme="dark"] .apk-top-action,html[data-apk-theme="dark"] .apk-action-btn,html[data-apk-theme="dark"] .apk-theme-toggle,html[data-apk-theme="dark"] [data-apk-theme-toggle]{
  color:#07111f!important;
  -webkit-text-fill-color:#07111f!important;
}
button:hover,.btn:hover,.button:hover,input[type="submit"]:hover,input[type="button"]:hover,a.btn:hover,.apk-action-btn:hover,.apk-top-action:hover,.apk-theme-toggle:hover,[data-apk-theme-toggle]:hover{
  filter:brightness(1.04)!important;
  transform:translateY(-1px)!important;
}
button:disabled,.btn.disabled,.btn:disabled,input:disabled,select:disabled,textarea:disabled{
  opacity:.58!important;
  cursor:not-allowed!important;
  filter:grayscale(.15)!important;
}
button::before,button::after,.btn::before,.btn::after,.button::before,.button::after{display:none!important;content:none!important;}
.btn-danger,.delete button,.apk-action-btn--danger,input[value="Delete"],input[value="Reject"]{background:linear-gradient(135deg,#dc2626,#f43f5e)!important;color:#fff!important;-webkit-text-fill-color:#fff!important;}
.btn-success,.approve button,.approvex button,.process button,.donememo button,.apk-action-btn--success,input[value="Approve"],input[value="Done"],input[value="Ready!"]{background:linear-gradient(135deg,#16a34a,#22c55e)!important;color:#fff!important;-webkit-text-fill-color:#fff!important;}
.btn-warning,.apk-action-btn--warning{background:linear-gradient(135deg,#d97706,#f59e0b)!important;color:#111827!important;-webkit-text-fill-color:#111827!important;}
.btn-info,.detail button,.checks button,.apk-action-btn--info{background:linear-gradient(135deg,#0284c7,#2563eb)!important;color:#fff!important;-webkit-text-fill-color:#fff!important;}
.print button,.apk-action-btn--print{background:linear-gradient(135deg,#0f766e,#06b6d4)!important;color:#fff!important;-webkit-text-fill-color:#fff!important;}

/* Theme toggle */
.apk-theme-toggle,[data-apk-theme-toggle]{
  min-width:132px!important;
  border:1px solid var(--apk-line)!important;
  background:var(--apk-surface-2)!important;
  color:var(--apk-text)!important;
  -webkit-text-fill-color:var(--apk-text)!important;
  box-shadow:var(--apk-shadow-sm)!important;
}
.apk-theme-toggle .apk-theme-dot,[data-apk-theme-toggle] .apk-theme-dot{
  width:10px;height:10px;border-radius:50%;display:inline-block;background:var(--apk-primary-3);box-shadow:0 0 0 4px rgba(236,72,153,.13);
}
html[data-apk-theme="dark"] .apk-theme-toggle,html[data-apk-theme="dark"] [data-apk-theme-toggle]{
  background:var(--apk-surface-3)!important;
  color:var(--apk-text)!important;
  -webkit-text-fill-color:var(--apk-text)!important;
}

/* Tables and pagination */
.table,.dataTable{background:var(--apk-surface)!important;color:var(--apk-text)!important;}
.table thead th,.dataTable thead th{
  background:var(--apk-surface-3)!important;
  color:var(--apk-text-2)!important;
  -webkit-text-fill-color:var(--apk-text-2)!important;
  border-color:var(--apk-line)!important;
}
.table tbody td,.dataTable tbody td{background:var(--apk-surface)!important;color:var(--apk-text)!important;-webkit-text-fill-color:var(--apk-text)!important;border-color:var(--apk-line)!important;}
.table tbody tr:hover td,.dataTable tbody tr:hover td{background:rgba(37,99,235,.07)!important;}
html[data-apk-theme="dark"] .table tbody tr:hover td,html[data-apk-theme="dark"] .dataTable tbody tr:hover td{background:rgba(96,165,250,.11)!important;}
.dataTables_wrapper{color:var(--apk-text)!important;}
.dataTables_filter input,.dataTables_length select{
  background:var(--apk-surface)!important;color:var(--apk-text)!important;-webkit-text-fill-color:var(--apk-text)!important;border-color:var(--apk-line)!important;border-radius:var(--apk-radius-pill)!important;
}
.dataTables_paginate,.pagination{display:flex!important;gap:8px!important;flex-wrap:wrap!important;align-items:center!important;}
.dataTables_paginate .paginate_button,.pagination .page-link{
  min-width:40px!important;height:40px!important;border-radius:var(--apk-radius-pill)!important;border:1px solid var(--apk-line)!important;background:var(--apk-surface)!important;color:var(--apk-primary)!important;-webkit-text-fill-color:var(--apk-primary)!important;box-shadow:none!important;font-weight:900!important;
}
.dataTables_paginate .paginate_button.current,.dataTables_paginate .paginate_button.current:hover,.pagination .page-item.active .page-link{
  background:linear-gradient(135deg,var(--apk-primary),var(--apk-primary-2))!important;color:#fff!important;-webkit-text-fill-color:#fff!important;border-color:transparent!important;
}

/* Select2 / dropdown / modal / datepicker dark support */
.select2-container .select2-selection,.select2-dropdown,.select2-search__field,.select2-results__option{
  background:var(--apk-surface)!important;color:var(--apk-text)!important;-webkit-text-fill-color:var(--apk-text)!important;border-color:var(--apk-line)!important;
}
.select2-container--default .select2-selection--single .select2-selection__rendered,.select2-container--default .select2-selection--multiple .select2-selection__choice,.select2-container--default .select2-selection--multiple .select2-selection__rendered{
  color:var(--apk-text)!important;-webkit-text-fill-color:var(--apk-text)!important;
}
.select2-results__option--highlighted,.select2-container--default .select2-results__option--highlighted[aria-selected]{
  background:linear-gradient(135deg,var(--apk-primary),var(--apk-primary-2))!important;color:#fff!important;-webkit-text-fill-color:#fff!important;
}
.modal-backdrop,.apk-entry-modal::before{background:rgba(2,6,23,.50)!important;}
.Zebra_DatePicker,.Zebra_DatePicker table,.Zebra_DatePicker td,.Zebra_DatePicker th{
  background:var(--apk-surface)!important;color:var(--apk-text)!important;-webkit-text-fill-color:var(--apk-text)!important;border-color:var(--apk-line)!important;
}
.Zebra_DatePicker .dp_selected,.Zebra_DatePicker .dp_current{background:linear-gradient(135deg,var(--apk-primary),var(--apk-primary-2))!important;color:#fff!important;-webkit-text-fill-color:#fff!important;}

/* Dark mode hard fixes for legacy white cards */
html[data-apk-theme="dark"] .bg-white,html[data-apk-theme="dark"] .card,html[data-apk-theme="dark"] .list-group-item,html[data-apk-theme="dark"] .dropdown-menu,html[data-apk-theme="dark"] .modal-content{
  background:var(--apk-surface)!important;color:var(--apk-text)!important;
}
html[data-apk-theme="dark"] .text-dark{color:var(--apk-text)!important;-webkit-text-fill-color:var(--apk-text)!important;}
html[data-apk-theme="dark"] .text-primary{color:var(--apk-primary)!important;-webkit-text-fill-color:var(--apk-primary)!important;}
html[data-apk-theme="dark"] .border,html[data-apk-theme="dark"] .border-top,html[data-apk-theme="dark"] .border-bottom{border-color:var(--apk-line)!important;}

@media(max-width:900px){
  .apk-theme-toggle,[data-apk-theme-toggle]{min-width:112px!important;font-size:12px!important;padding:0 14px!important;}
  .apk-top-actions{gap:8px!important;}
  .dataTables_paginate,.pagination{flex-wrap:nowrap!important;overflow-x:auto!important;padding-bottom:6px!important;}
}
