/* =====================================================================
   DARK MODE   (html[data-mode="dark"])
   Light is the default. The header sun/moon button switches the mode and
   saves it in localStorage ("adminMode").

   Part 1 (below)  : hand-written colour tokens - tweak these freely.
   Part 2 (further): auto-generated dark twins of every hard-coded light
                     colour in the project's stylesheets (do not edit by hand;
                     re-run tools/gen_dark.py after changing other CSS files).
   ===================================================================== */
html[data-mode="dark"]{
  color-scheme: dark;

  /* surfaces */
  --dk-surface:   #151d2c;
  --dk-surface-2: #1a2335;
  --bg:  #0d121c;
  --bg0: #0d121c;

  /* text */
  --dk-text:     #e6ebf5;
  --text:        #e6ebf5;
  --text-color:  #d6deec;
  --text-strong: #f2f5fb;
  --text-muted:  #93a0b8;
  --muted:       #93a0b8;
  /* brand colour that is readable on dark (follows the chosen colour theme) */
  --dk-accent: color-mix(in srgb, var(--c1) 45%, #ffffff);

  /* lines / borders */
  --line:         #263147;
  --border-color: #2f3d57;
  --border-light: #263147;

  /* tints follow the active colour theme (blue / maroon / teal / purple) */
  --tint:  color-mix(in srgb, var(--c1) 14%, #151d2c);
  --tint2: color-mix(in srgb, var(--c1) 22%, #151d2c);
  --tint3: color-mix(in srgb, var(--c1) 34%, #151d2c);
  --bg-soft:   var(--tint);
  --grey-soft: #1c2638;
  --primary-soft:  var(--tint2);
  --primary-hover: var(--tint);
  --primary-ring:  rgba(var(--rgb1), .28);
  --purple-soft:   var(--tint2);
  --purple-border: var(--tint3);
  --shadow: 0 10px 30px rgba(0,0,0,.45);

  /* status colours used by the page stylesheets */
  --theme-success:        #4ade80;
  --theme-success-soft:   rgba(34,197,94,.16);
  --theme-success-border: rgba(34,197,94,.38);
  --theme-danger:         #f87171;
  --theme-danger-soft:    rgba(239,68,68,.16);
  --theme-danger-border:  rgba(239,68,68,.38);
  --theme-warning:        #fbbf24;
  --theme-warning-soft:   rgba(245,158,11,.16);
  --theme-warning-border: rgba(245,158,11,.38);
  --theme-grey-soft:      #1c2638;
  --green: #34d399;

  /* header avatar (defined in includes/header.html) */
  --theme-avatar-bg:   color-mix(in srgb, var(--c1) 22%, #151d2c);
  --theme-avatar-text: var(--dk-accent);
}

html[data-mode="dark"] body{ background: var(--bg0); color: var(--text); }
html[data-mode="dark"] ::placeholder{ color:#6f7c95; opacity:1; }
html[data-mode="dark"] ::selection{ background: rgba(var(--rgb1), .45); color:#fff; }
html[data-mode="dark"] code{ background: var(--tint2); color: var(--dk-text); }
html[data-mode="dark"] .status-pill.inactive{ background: rgba(233,30,99,.18); color:#ff6b9a; }
html[data-mode="dark"] img.avatar-img{ filter:none; }
/* illustration shown for "no data" is drawn for a white page */
html[data-mode="dark"] img[src*="no-data"]{ filter: brightness(.82) contrast(1.05); }

/* session-sync.js injects its own "session expired" popup */
html[data-mode="dark"] .ss-box{ background: var(--dk-surface); }
html[data-mode="dark"] .ss-box h3{ color: var(--dk-text); }
html[data-mode="dark"] .ss-box p{ color: var(--muted); }
html[data-mode="dark"] .ss-ic{ background: rgba(239,68,68,.16); color:#f87171; }

/* smooth switch */
html.mode-anim, html.mode-anim *{ transition: background-color .25s ease, border-color .25s ease, color .2s ease !important; }

/* ---------------- Part 2 : auto-generated -------------------------------- */


/* ---- from style.css ---- */
:where(html[data-mode="dark"]) .sidebar{background:#151d2c}
:where(html[data-mode="dark"]) .menu a{color:#bdc2cf}
:where(html[data-mode="dark"]) .topbar{background:#151d2c}
:where(html[data-mode="dark"]) .search{background:#1a2335}
:where(html[data-mode="dark"])[data-menu=mini] .has-sub:hover>.sub{background:#151d2c}
:where(html[data-mode="dark"]) .card{background:#151d2c}
:where(html[data-mode="dark"]) .btn.ghost{background:#151d2c;color:var(--dk-accent)}
:where(html[data-mode="dark"]) .ring{color:var(--dk-accent)}
:where(html[data-mode="dark"]) .f input{border:1px solid #2c3344}
:where(html[data-mode="dark"]) .legend{color:#bdc2cf}
:where(html[data-mode="dark"]) .visa-wrap{background:#151d2c}
:where(html[data-mode="dark"]) .mini .sq{color:var(--dk-accent)}
:where(html[data-mode="dark"]) .mini .sq.gray{background:#2b3243}
:where(html[data-mode="dark"]) .sidebar .brand{background:linear-gradient(120deg,#151d2c,var(--tint))}
:where(html[data-mode="dark"]) .sidebar h6{color:var(--dk-accent)}
:where(html[data-mode="dark"]) .menu a:hover{color:var(--dk-accent)}
:where(html[data-mode="dark"]) .card h2{color:var(--dk-text)}
:where(html[data-mode="dark"]) .btn.ghost{background:#151d2c;color:var(--dk-accent)}
:where(html[data-mode="dark"]) th{color:var(--dk-accent)}
:where(html[data-mode="dark"]) .f:focus-within label{color:var(--dk-accent)}
:where(html[data-mode="dark"]) .f:focus-within label{color:var(--dk-accent)}
:where(html[data-mode="dark"]) .theme-btn{background:#151d2c}
:where(html[data-mode="dark"]) .theme-menu{background:#151d2c}
:where(html[data-mode="dark"]) .theme-menu button{color:var(--dk-text)}
:where(html[data-mode="dark"]) .theme-menu button.on::after{color:var(--dk-accent)}
:where(html[data-mode="dark"]) .theme-btn{color:var(--dk-accent)}
:where(html[data-mode="dark"]) .auth{background:#151d2c}
:where(html[data-mode="dark"]) .auth-left{background:linear-gradient(180deg,#151d2c,var(--bg0))}
:where(html[data-mode="dark"]) .auth-top{color:var(--dk-text)}
:where(html[data-mode="dark"]) .auth-main h1{color:var(--dk-text)}
:where(html[data-mode="dark"]) .field label{color:var(--dk-text)}
:where(html[data-mode="dark"]) .field input{border:1px solid #2c3344;background:#151d2c}
:where(html[data-mode="dark"]) .field .box:focus-within>i.lead-ic{color:var(--dk-accent)}
:where(html[data-mode="dark"]) .field .eye:hover{color:var(--dk-accent)}
:where(html[data-mode="dark"]) .auth-row label{color:#bdc2cf}
:where(html[data-mode="dark"]) .auth-row a{color:var(--dk-accent)}
:where(html[data-mode="dark"]) .auth-err{background:#3f1f1c;color:#eb8a85}
:where(html[data-mode="dark"]) .auth-submit .spin{border-top-color:#1c212c}
:where(html[data-mode="dark"]) .auth-social a{border:1px solid #2c3344;background:#151d2c;color:var(--dk-text)}
:where(html[data-mode="dark"]) .auth-social .fa-google{color:#f2877e}
:where(html[data-mode="dark"]) .auth-social .fa-facebook-f{color:#7bb0f4}
:where(html[data-mode="dark"]) .auth-foot{color:#afb4bf}
:where(html[data-mode="dark"]) .auth-foot a{color:var(--dk-accent)}
:where(html[data-mode="dark"]) .status-pill.active{background:var(--theme-success-soft,#1c402d);color:var(--theme-success,#81eea9)}
:where(html[data-mode="dark"]) .status-pill.inactive{color:#f27da5}

/* ---- from activity_log.css ---- */
:where(html[data-mode="dark"]) .filter-field{background:#151d2c}
:where(html[data-mode="dark"]) .cd-trigger{background:#151d2c}
:where(html[data-mode="dark"]) .cd-menu{background:#151d2c}
:where(html[data-mode="dark"]) .cd-option:hover{color:var(--dk-accent)}
:where(html[data-mode="dark"]) .cd-option.selected{color:var(--dk-accent)}
:where(html[data-mode="dark"]) .cd-option.selected::after{color:var(--dk-accent)}
:where(html[data-mode="dark"]) .tw thead th{background:#151d2c}
:where(html[data-mode="dark"]) .badge-role{color:var(--dk-accent)}
:where(html[data-mode="dark"]) .btn-view{color:var(--dk-accent)}
:where(html[data-mode="dark"]) .custom-checkbox{background-color:#151d2c}
:where(html[data-mode="dark"]) .btn-delete-bulk:hover{background:#522424}
:where(html[data-mode="dark"]) #paginationWrap .btn{background:#151d2c}
:where(html[data-mode="dark"]) #paginationWrap .btn:hover:not(:disabled){color:var(--dk-accent)}
:where(html[data-mode="dark"]) .modal-box{background:#151d2c}
:where(html[data-mode="dark"]) .modal-btn-cancel{background:#151d2c}
:where(html[data-mode="dark"]) .view-avatar{color:var(--dk-accent)}
:where(html[data-mode="dark"]) .view-badge{color:var(--dk-accent)}
:where(html[data-mode="dark"]) .view-loading i{color:var(--dk-accent)}
:where(html[data-mode="dark"]) .diff-num{color:#f4bc7b}
:where(html[data-mode="dark"]) .diff-bool{color:#a87cf3}

/* ---- from change_password.css ---- */
:where(html[data-mode="dark"]) .card{background:#151d2c}
:where(html[data-mode="dark"]) .form-input:focus{background:#151d2c}
:where(html[data-mode="dark"]) .eye-icon:hover{color:var(--dk-accent)}

/* ---- from company_list.css ---- */
:where(html[data-mode="dark"]) .filter-field{background:#151d2c}
:where(html[data-mode="dark"]) .cd-trigger{background:#151d2c}
:where(html[data-mode="dark"]) .cd-menu{background:#151d2c}
:where(html[data-mode="dark"]) .cd-option:hover{color:var(--dk-accent)}
:where(html[data-mode="dark"]) .cd-option.selected{color:var(--dk-accent)}
:where(html[data-mode="dark"]) .cd-option.selected::after{color:var(--dk-accent)}
:where(html[data-mode="dark"]) .company-cell .meta .ccode .code-badge{color:var(--dk-accent)}
:where(html[data-mode="dark"]) .scholar-count{color:var(--dk-accent)}
:where(html[data-mode="dark"]) .tw thead th{background:#151d2c}

/* ---- from dashboard.css ---- */
:where(html[data-mode="dark"]) .dash-item{background:#1c2232}
:where(html[data-mode="dark"]) .dash-item:hover{background:#202638}
:where(html[data-mode="dark"]) .dash-avatar{background:var(--tint2, #1e2742);color:var(--dk-accent, #4361ee)}
:where(html[data-mode="dark"]) .dash-item .name{color:var(--text-strong, #cfd6e5)}
:where(html[data-mode="dark"]) .dash-status.on{background:#1c402d;color:#81eea9}
:where(html[data-mode="dark"]) .dash-status.off{background:#3d1b1b;color:#eb8484}

/* ---- from login_management.css ---- */
:where(html[data-mode="dark"]) .filter-field{background:#151d2c}
:where(html[data-mode="dark"]) .cd-trigger{background:#151d2c}
:where(html[data-mode="dark"]) .cd-menu{background:#151d2c}
:where(html[data-mode="dark"]) .cd-option:hover{color:var(--dk-accent)}
:where(html[data-mode="dark"]) .cd-option.selected{color:var(--dk-accent)}
:where(html[data-mode="dark"]) .cd-option.selected::after{color:var(--dk-accent)}
:where(html[data-mode="dark"]) .tw thead th{background:#151d2c}
:where(html[data-mode="dark"]) .badge-role{color:var(--dk-accent)}
:where(html[data-mode="dark"]) .lm-icon-btn{background:#151d2c;color:var(--dk-accent)}
:where(html[data-mode="dark"]) .lm-modal{background:#151d2c}
:where(html[data-mode="dark"]) .lm-pwd-wrap input{background:#151d2c}
:where(html[data-mode="dark"]) .lm-btn-ghost{background:#151d2c}
:where(html[data-mode="dark"]) .lm-confirm-icon{color:var(--dk-accent)}

/* ---- from profile.css ---- */
:where(html[data-mode="dark"]) .card{background:#151d2c}
:where(html[data-mode="dark"]) .avatar-big{color:var(--dk-accent)}
:where(html[data-mode="dark"]) .form-input:focus{background:#151d2c}

/* ---- from rolesstyle.css ---- */
:where(html[data-mode="dark"]) .role-avatar{color:var(--dk-accent)}
:where(html[data-mode="dark"]) .user-count{color:var(--dk-accent)}
:where(html[data-mode="dark"]) .icon-btn{background:#151d2c}
:where(html[data-mode="dark"]) .icon-btn:hover{color:var(--dk-accent)}
:where(html[data-mode="dark"]) .vr-header{background:linear-gradient(135deg, var(--theme-primary-soft), #151d2c)}
:where(html[data-mode="dark"]) .vr-stat-icon{color:var(--dk-accent)}
:where(html[data-mode="dark"]) .vr-section-head i{color:var(--dk-accent)}
:where(html[data-mode="dark"]) .vr-perm-count{color:var(--dk-accent)}
:where(html[data-mode="dark"]) .vr-perm-card{background:#151d2c}
:where(html[data-mode="dark"]) .vr-perm-card-top i{color:var(--dk-accent)}
:where(html[data-mode="dark"]) .vr-chip.action-view{color:var(--dk-accent)}
:where(html[data-mode="dark"]) .ar-modal{background:#151d2c}
:where(html[data-mode="dark"]) .ar-modal-close{background:#151d2c}
:where(html[data-mode="dark"]) .ar-input{background:#151d2c}
:where(html[data-mode="dark"]) .ar-perm-global span{color:var(--dk-accent)}
:where(html[data-mode="dark"]) .ar-perm-group{background:#151d2c}
:where(html[data-mode="dark"]) .ar-perm-group-title{color:var(--dk-accent)}
:where(html[data-mode="dark"]) .ar-perm-checkall-inline:hover{color:var(--dk-accent)}
:where(html[data-mode="dark"]) .ar-btn-ghost{background:#151d2c}
:where(html[data-mode="dark"]) .ct-icon{color:var(--dk-accent)}
:where(html[data-mode="dark"]) .status-pill.inactive{color:#f27da5}
:where(html[data-mode="dark"]) .filter-field{background:#151d2c}
:where(html[data-mode="dark"]) .cd-trigger{background:#151d2c}
:where(html[data-mode="dark"]) .cd-menu{background:#151d2c}
:where(html[data-mode="dark"]) .cd-option:hover{color:var(--dk-accent)}
:where(html[data-mode="dark"]) .cd-option.selected{color:var(--dk-accent)}
:where(html[data-mode="dark"]) .cd-option.selected::after{color:var(--dk-accent)}
:where(html[data-mode="dark"]) .ar-perm-global{border:1px solid var(--theme-border, #28303b);background:var(--theme-bg-soft, #1b2534)}
:where(html[data-mode="dark"]) .ar-perm-checkall-inline{color:var(--theme-text-muted, #b2b6bf)}

/* ---- from user_list.css ---- */
:where(html[data-mode="dark"]) .filter-field{background:#151d2c}
:where(html[data-mode="dark"]) .cd-trigger{background:#151d2c}
:where(html[data-mode="dark"]) .cd-menu{background:#151d2c}
:where(html[data-mode="dark"]) .cd-option:hover{color:var(--dk-accent)}
:where(html[data-mode="dark"]) .cd-option.selected{color:var(--dk-accent)}
:where(html[data-mode="dark"]) .cd-option.selected::after{color:var(--dk-accent)}
:where(html[data-mode="dark"]) .modal-box{background:#151d2c}
:where(html[data-mode="dark"]) .modal-icon{color:var(--dk-accent)}
:where(html[data-mode="dark"]) .modal-icon.danger{background:#431e1e;color:#eb8484}
:where(html[data-mode="dark"]) .modal-btn-cancel{background:#151d2c}
:where(html[data-mode="dark"]) .scholar-count{color:var(--dk-accent)}
:where(html[data-mode="dark"]) .tw thead th{background:#151d2c}
:where(html[data-mode="dark"]) .view-btn{background:#151d2c;color:var(--dk-accent)}
:where(html[data-mode="dark"]) .detail-box{background:#151d2c}
:where(html[data-mode="dark"]) .detail-head h3 i{color:var(--dk-accent)}
:where(html[data-mode="dark"]) .detail-close:hover{background:#151d2c}
:where(html[data-mode="dark"]) .detail-error{color:#ec8383;border:1px solid #492020}
:where(html[data-mode="dark"]) .detail-section-title i{color:var(--dk-accent)}

/* ---- from user_role.css ---- */
:where(html[data-mode="dark"]) .filter-field{background:#151d2c}
:where(html[data-mode="dark"]) .cd-trigger{background:#151d2c}
:where(html[data-mode="dark"]) .cd-menu{background:#151d2c}
:where(html[data-mode="dark"]) .cd-option:hover{color:var(--dk-accent)}
:where(html[data-mode="dark"]) .cd-option.selected{color:var(--dk-accent)}
:where(html[data-mode="dark"]) .cd-option.selected::after{color:var(--dk-accent)}
:where(html[data-mode="dark"]) .modal-box{background:#151d2c}
:where(html[data-mode="dark"]) .modal-icon{color:var(--dk-accent)}
:where(html[data-mode="dark"]) .modal-icon.danger{background:#431e1e;color:#eb8484}
:where(html[data-mode="dark"]) .modal-btn-cancel{background:#151d2c}
:where(html[data-mode="dark"]) .scholar-count{color:var(--dk-accent)}
:where(html[data-mode="dark"]) .tw thead th{background:#151d2c}
:where(html[data-mode="dark"]) .role-viewer{color:var(--dk-accent)}
:where(html[data-mode="dark"]) .icon-btn{background:#151d2c}
:where(html[data-mode="dark"]) .icon-btn:hover{color:var(--dk-accent)}
:where(html[data-mode="dark"]) .modal-close:hover{color:var(--dk-accent)}
:where(html[data-mode="dark"]) .form-input,:where(html[data-mode="dark"]) .form-select{background:#151d2c}

/* ---- from visitors.css ---- */
:where(html[data-mode="dark"]) .filter-field{background:#151d2c}
:where(html[data-mode="dark"]) .cd-trigger{background:#151d2c}
:where(html[data-mode="dark"]) .cd-menu{background:#151d2c}
:where(html[data-mode="dark"]) .cd-option:hover{color:var(--dk-accent)}
:where(html[data-mode="dark"]) .cd-option.selected{color:var(--dk-accent)}
:where(html[data-mode="dark"]) .cd-option.selected::after{color:var(--dk-accent)}
:where(html[data-mode="dark"]) .tw thead th{background:#151d2c}
:where(html[data-mode="dark"]) .badge-role{color:var(--dk-accent)}
:where(html[data-mode="dark"]) .custom-checkbox{background-color:#151d2c}
:where(html[data-mode="dark"]) .btn-delete-bulk:hover{background:#522424}
:where(html[data-mode="dark"]) .modal-box{background:#151d2c}
:where(html[data-mode="dark"]) .modal-btn-cancel{background:#151d2c}

/* ---- from templates/pages/login.html (inline <style>, login page only) ---- */
:where(html[data-mode="dark"][data-auth]) .modal-box{background:#151d2c}
:where(html[data-mode="dark"][data-auth]) .modal-close{color:#acb3c3}
:where(html[data-mode="dark"][data-auth]) .modal-close:hover{background:#202c38;color:#96aad9}
:where(html[data-mode="dark"][data-auth]) .modal-box h2{color:#96aad9}
:where(html[data-mode="dark"][data-auth]) .modal-lead{color:#acb3c3}
:where(html[data-mode="dark"][data-auth]) .modal-msg.error{background:#391919;color:#ec8383;border:1px solid #492020}
:where(html[data-mode="dark"][data-auth]) .modal-msg.success{background:#1a3b24;color:#84ebab;border:1px solid #245234}
:where(html[data-mode="dark"][data-auth]) .modal-msg.info{background:#1a283a;color:#819eee;border:1px solid #22354d}
