/* Shared tokens; existing light styles are retained until dark mode is selected. */
:root {
    --sm-theme-bg:#f3f6fa; --sm-theme-surface:#ffffff; --sm-theme-soft:#f8fafc;
    --sm-theme-text:#182536; --sm-theme-muted:#64758a; --sm-theme-border:#dce4ed;
    --sm-theme-hover:#e4edf6; --sm-theme-link:#126579;
    --sm-theme-danger-bg:#fff0f0; --sm-theme-danger:#8b2525;
    --sm-theme-success-bg:#e2f4ea; --sm-theme-success:#206747;
}
html[data-sm-theme="dark"] {
    color-scheme:dark;
    --sm-theme-bg:#101820; --sm-theme-surface:#192530; --sm-theme-soft:#21313f;
    --sm-theme-text:#e6edf5; --sm-theme-muted:#a9bacb; --sm-theme-border:#3b4f61;
    --sm-theme-hover:#2a4050; --sm-theme-link:#71d5e1;
    --sm-theme-danger-bg:#3e242c; --sm-theme-danger:#ffb4bd;
    --sm-theme-success-bg:#173b31; --sm-theme-success:#9ce2bd;
    --sm-bg:var(--sm-theme-bg); --sm-text:var(--sm-theme-text);
    --sm-text-muted:var(--sm-theme-muted); --sm-border:var(--sm-theme-border);
    --sm-hover:var(--sm-theme-hover);
    --sm-primary:#3cb7c5; --sm-primary-dark:#17616d; --sm-primary-light:#62d1dc;
    --toastify-color-light:var(--sm-theme-surface); --toastify-text-color-light:var(--sm-theme-text);
    --pq-bg:var(--sm-theme-bg); --pq-card-bg:var(--sm-theme-surface); --pq-border:var(--sm-theme-border);
    --pq-text-primary:var(--sm-theme-text); --pq-text-secondary:var(--sm-theme-muted); --pq-text-muted:var(--sm-theme-muted);
    --pq-primary-light:var(--sm-theme-soft); --pq-sidebar-bg:#142c39;
}
button.sm-theme-toggle {
    display:inline-flex; align-items:center; justify-content:center; gap:7px;
    padding:6px 10px; min-height:32px; border:1px solid var(--sm-theme-border);
    border-radius:7px; background:var(--sm-theme-soft); color:var(--sm-theme-text);
    font:500 12px/1.2 'Segoe UI',Arial,sans-serif; white-space:nowrap; cursor:pointer;
    flex-shrink:0; vertical-align:middle;
}
button.sm-theme-toggle:hover { background:var(--sm-theme-hover); }
button.sm-theme-toggle:focus-visible { outline:2px solid #1399ae; outline-offset:3px; }
.sm-theme-toggle .sm-theme-sun { display:none; }
html[data-sm-theme="dark"] .sm-theme-toggle .sm-theme-sun { display:block; }
html[data-sm-theme="dark"] .sm-theme-toggle .sm-theme-moon { display:none; }
.sm-theme-legacy-item { padding:10px 8px; }
.navbar .sm-theme-toggle { margin:8px 12px; }
.navbar>.sm-theme-toggle { position:absolute; right:12px; top:8px; margin:0; z-index:1; }
html[data-sm-theme="dark"], html[data-sm-theme="dark"] body {
    background:var(--sm-theme-bg) !important; color:var(--sm-theme-text);
    scrollbar-color:#52697c var(--sm-theme-bg);
}
html[data-sm-theme="dark"] :is(.dash-topbar,header.header,.navbar,.dash-search-results,
    .sm-drawer,.sm-modal,.sm-loader-card,.sm-modal-loading,.sm-drawer-loading,
    .panel,.well,.modal-content,dialog,.dropdown-menu,.list-group-item,
    .formbg-wrapper,.formbg,.bg-white,.tdwhite,.white-bg,.overview-stat,.distribution,
    .dashboard-note,.dashboard-details-panel,.body-content,.pq-content,.pq-main,.pq-shell) {
    background:var(--sm-theme-surface) !important;
    color:var(--sm-theme-text) !important; border-color:var(--sm-theme-border) !important;
}
html[data-sm-theme="dark"] :is(.dash-left,.dash-tabs,.dash-left-footer,.panel-default>.panel-heading,
    .modal-header,.modal-footer,.breadcrumb,.distribution-footer,.distribution-track,.table-striped>tbody>tr:nth-of-type(odd),
    .ui-widget-header,.ui-state-default,.dataTables_wrapper .dataTables_paginate .paginate_button) {
    background:var(--sm-theme-soft) !important; color:var(--sm-theme-text) !important;
    border-color:var(--sm-theme-border) !important;
}
html[data-sm-theme="dark"] :is(.dash-tab:not(.active),.dash-collapse-btn,.dash-pqt-btn,
    .overview-date,.overview-icon,.dash-item .item-icon,.user-chip) {
    background:var(--sm-theme-soft); color:var(--sm-theme-text); border-color:var(--sm-theme-border);
}
html[data-sm-theme="dark"] :is(.dash-subhead,.dash-item,.dash-search .ds-icon,.reset-pwd,.logout,
    .overview-head h1,.overview-stat strong,.distribution-head h2,.distribution-detail-link,
    .dataTables_wrapper .dataTables_info,.dataTables_wrapper .dataTables_filter,
    .dataTables_wrapper .dataTables_length,.dataTables_wrapper .dataTables_paginate,
    label,legend,.control-label,.text-muted,.help-block,.pq-main h1,.pq-main h2) { color:var(--sm-theme-text); }
html[data-sm-theme="dark"] :is(.dash-item:hover,.dash-subhead:hover,.dash-item.is-current,
    .table-hover>tbody>tr:hover,.dropdown-menu>li>a:hover,.list-group-item:hover) {
    background:var(--sm-theme-hover) !important; color:var(--sm-theme-text) !important;
}
html[data-sm-theme="dark"] :is(.dash-topbar a.logout:hover,.dash-topbar a.reset-pwd:hover) {
    background:var(--sm-theme-hover); color:var(--sm-theme-link);
}
html[data-sm-theme="dark"] .dash-subgroup.is-open {
    background:var(--sm-theme-surface); border-color:var(--sm-theme-border);
}
html[data-sm-theme="dark"] .dash-subgroup.is-open>.dash-subhead { color:var(--sm-theme-text); }
/* QA/QC Entry defines its own card colours after the shared layout styles. */
html[data-sm-theme="dark"] .aw-form {
    --awtext:var(--sm-theme-text); --awmut:var(--sm-theme-muted); --awbrd:var(--sm-theme-border);
    --awdanger:var(--sm-theme-danger); --awpd:var(--sm-theme-link); --awpl:var(--sm-theme-link);
    background:var(--sm-theme-bg); border-color:var(--sm-theme-border); color:var(--sm-theme-text);
}
html[data-sm-theme="dark"] :is(.aw-card,.aw-errors-wrap,.aw-actions,.aw-qc-chip) {
    background:var(--sm-theme-surface); color:var(--sm-theme-text); border-color:var(--sm-theme-border);
}
html[data-sm-theme="dark"] .aw-card-head {
    background:var(--sm-theme-soft); border-color:var(--sm-theme-border);
}
html[data-sm-theme="dark"] .aw-form :is(.fld>label,.fld .gfield_label,.aw-errors-head .gfield_label,.aw-hint b) {
    color:var(--sm-theme-text);
}
html[data-sm-theme="dark"] .aw-form :is(.btn-default,.btn-danger,.remove-icon[value="Clear"]) {
    background:var(--sm-theme-soft);
}
html[data-sm-theme="dark"] .aw-form .btn-default { color:var(--sm-theme-link); }
html[data-sm-theme="dark"] .aw-form #tblCallDetails { background:var(--sm-theme-surface); }
html[data-sm-theme="dark"] .aw-form #tblCallDetails tbody tr:hover td { background:var(--sm-theme-hover); }
html[data-sm-theme="dark"] #openModal :is(.modal-content,.qcm-choice) {
    background:var(--sm-theme-surface); color:var(--sm-theme-text); border-color:var(--sm-theme-border);
}
html[data-sm-theme="dark"] #openModal :is(.qcm-fld>label,.qcm-fld .gfield_label) { color:var(--sm-theme-text); }
html[data-sm-theme="dark"] #openModal .qcm-footer { background:var(--sm-theme-soft); border-color:var(--sm-theme-border); }
html[data-sm-theme="dark"] #openModal .qcm-choice:has(input:checked) {
    background:var(--sm-theme-hover); color:var(--sm-theme-link);
}
html[data-sm-theme="dark"] #openModal .qcm-pass:has(input:checked) { color:var(--sm-theme-success); }
html[data-sm-theme="dark"] #openModal .qcm-fail:has(input:checked) { color:var(--sm-theme-danger); }
html[data-sm-theme="dark"] #openModal .qcm-btn-reset { background:var(--sm-theme-soft); color:var(--sm-theme-danger); }
html[data-sm-theme="dark"] :is(.body-content,.dash-main,.modal-content,dialog,.ui-widget-content)
    :is(h1,h2,h3,h4,h5,h6) { color:var(--sm-theme-text); }
html[data-sm-theme="dark"] :is(.form-control,input:not([type=button]):not([type=submit]):not([type=reset]):not([type=checkbox]):not([type=radio]):not([type=range]):not([type=color]):not([type=hidden]),select,textarea) {
    background-color:var(--sm-theme-soft) !important; color:var(--sm-theme-text) !important;
    border-color:var(--sm-theme-border) !important;
}
html[data-sm-theme="dark"] :is(input,textarea)::placeholder { color:var(--sm-theme-muted); opacity:1; }
html[data-sm-theme="dark"] :is(input,select,textarea):disabled { opacity:.65; }
html[data-sm-theme="dark"] :is(.btn-default,.qa button:not(.primary):not(.danger)) {
    background:var(--sm-theme-soft); color:var(--sm-theme-text); border-color:var(--sm-theme-border);
}
html[data-sm-theme="dark"] :is(.distribution-tools button,.dashboard-details button) {
    background:var(--sm-theme-soft); color:var(--sm-theme-text);
}
html[data-sm-theme="dark"] :is(.distribution tbody tr:hover,.dashboard-details-table tbody tr:hover) {
    background:var(--sm-theme-hover);
}
html[data-sm-theme="dark"] :is(table,.table) { color:var(--sm-theme-text); background:transparent; }
html[data-sm-theme="dark"] :is(table,.table) :is(th,td) { border-color:var(--sm-theme-border) !important; }
html[data-sm-theme="dark"] :is(table,.table) th { background-color:var(--sm-theme-soft) !important; color:var(--sm-theme-text) !important; }
html[data-sm-theme="dark"] :is(table.dataTable tbody tr,.table>tbody>tr>td,.table>tfoot>tr>td) {
    background-color:var(--sm-theme-surface); color:var(--sm-theme-text);
}
html[data-sm-theme="dark"] :is(.ui-widget-content,.ui-datepicker,.select2-dropdown,.select2-selection,.select2-results__option) {
    background:var(--sm-theme-surface) !important; color:var(--sm-theme-text) !important; border-color:var(--sm-theme-border) !important;
}
html[data-sm-theme="dark"] :is(.select2-results__option--highlighted,.ui-state-hover,.ui-state-active) {
    background:var(--sm-theme-hover) !important; color:var(--sm-theme-text) !important;
}
html[data-sm-theme="dark"] :is(.dropdown-menu>li>a,.select2-selection__rendered,.ui-datepicker a) { color:var(--sm-theme-text) !important; }
html[data-sm-theme="dark"] .alert-danger { background:var(--sm-theme-danger-bg); color:var(--sm-theme-danger); border-color:#834251; }
html[data-sm-theme="dark"] .alert-success { background:var(--sm-theme-success-bg); color:var(--sm-theme-success); border-color:#387b62; }
html[data-sm-theme="dark"] .alert-warning { background:#40371d; color:#f6db8e; border-color:#76602e; }
html[data-sm-theme="dark"] .alert-info { background:#193c50; color:#a5dffc; border-color:#3b708b; }
/* Keep high-contrast text on brand-coloured banners. */
html[data-sm-theme="dark"] :is(.agent-training .at-hero h1,.sm-modal-header,.sm-drawer-header) { color:#ffffff; }
@media (max-width:600px) { .dash-topbar .sm-theme-toggle [data-sm-theme-label] { display:none; } }
@media print {
    .sm-theme-toggle { display:none !important; }
    html[data-sm-theme="dark"] {
        color-scheme:light !important;
        --sm-theme-bg:#fff; --sm-theme-surface:#fff; --sm-theme-soft:#f4f4f4;
        --sm-theme-text:#000; --sm-theme-muted:#333; --sm-theme-border:#bbb;
        --sm-theme-hover:#eee; --sm-text:#000; --sm-text-muted:#333;
    }
    html[data-sm-theme="dark"],html[data-sm-theme="dark"] body,
    html[data-sm-theme="dark"] :is(.body-content,.dash-main,.panel,.well,table,th,td) {
        background:#ffffff !important; color:#000000 !important;
    }
}
