/**
 * System-wide contrast layer.
 * Dark mode was keeping Bootstrap's light-theme text tokens (near-black
 * .text-muted, placeholders, form controls, tables) on dark surfaces.
 */

html.dark-theme,
html[data-bs-theme='dark'] {
  color-scheme: dark;
  --bs-body-color: #e5e7eb;
  --bs-body-color-rgb: 229, 231, 235;
  --bs-body-bg: #0f172a;
  --bs-body-bg-rgb: 15, 23, 42;
  --bs-emphasis-color: #f8fafc;
  --bs-emphasis-color-rgb: 248, 250, 252;
  --bs-secondary-color: #cbd5e1;
  --bs-secondary-color-rgb: 203, 213, 225;
  --bs-secondary-bg: #1e293b;
  --bs-secondary-bg-rgb: 30, 41, 59;
  --bs-tertiary-color: #94a3b8;
  --bs-tertiary-color-rgb: 148, 163, 184;
  --bs-tertiary-bg: #162032;
  --bs-heading-color: #f8fafc;
  --bs-link-color: #86efac;
  --bs-link-hover-color: #bbf7d0;
  --bs-border-color: #475569;
  --bs-border-color-translucent: rgba(255, 255, 255, 0.14);
  --bs-form-control-bg: #1e293b;
  --bs-highlight-bg: #3f3f12;

  --math-text: #f8fafc;
  --math-text-light: #cbd5e1;
  --math-bg: #0f172a;
  --math-surface: #1e293b;
  --math-elevated: #273549;
  --math-border: #475569;
  --glass-bg: rgba(30, 41, 59, 0.88);
  --glass-border: rgba(148, 163, 184, 0.28);
  --student-primary: #4ade80;
  --student-secondary: #34d399;
}

html.light-theme,
html[data-bs-theme='light'] {
  color-scheme: light;
}

html.dark-theme .text-muted,
html.dark-theme .text-secondary,
html.dark-theme .text-body-secondary,
html.dark-theme .form-text,
html.dark-theme .blockquote-footer,
html.dark-theme .valid-feedback,
html.dark-theme small.text-muted {
  color: #cbd5e1 !important;
}

html.dark-theme .text-dark,
html.dark-theme .text-black,
html.dark-theme .text-body,
html.dark-theme .text-body-emphasis {
  color: #f1f5f9 !important;
}

html.dark-theme .lead {
  color: #cbd5e1;
}

html.dark-theme input:not([type='checkbox']):not([type='radio']):not([type='range']):not([type='file']):not([type='hidden']):not([type='submit']):not([type='button']),
html.dark-theme select,
html.dark-theme textarea,
html.dark-theme .form-control,
html.dark-theme .form-select,
html.dark-theme .form-control-plaintext,
html.dark-theme .admin-search-input,
html.dark-theme .admin-form-input,
html.dark-theme .admin-form-select,
html.dark-theme .admin-form-textarea {
  color: #f8fafc;
  color-scheme: dark;
}

html.dark-theme input:not([type='checkbox']):not([type='radio']):not([type='range']):not([type='file']):not([type='hidden']):not([type='submit']):not([type='button']):focus,
html.dark-theme select:focus,
html.dark-theme textarea:focus,
html.dark-theme .form-control:focus,
html.dark-theme .form-select:focus,
html.dark-theme .admin-search-input:focus,
html.dark-theme .admin-form-input:focus,
html.dark-theme .admin-form-select:focus,
html.dark-theme .admin-form-textarea:focus {
  color: #f8fafc;
}

html.dark-theme ::placeholder,
html.dark-theme .form-control::placeholder,
html.dark-theme .form-select::placeholder,
html.dark-theme .admin-search-input::placeholder,
html.dark-theme .admin-form-input::placeholder,
html.dark-theme .admin-form-textarea::placeholder {
  color: #94a3b8 !important;
  opacity: 1;
}

html.dark-theme input:-webkit-autofill,
html.dark-theme input:-webkit-autofill:hover,
html.dark-theme input:-webkit-autofill:focus,
html.dark-theme textarea:-webkit-autofill,
html.dark-theme select:-webkit-autofill {
  -webkit-text-fill-color: #f8fafc;
  caret-color: #f8fafc;
  box-shadow: 0 0 0 1000px #0f172a inset;
  transition: background-color 9999s ease-out;
}

html.dark-theme option {
  background-color: #1e293b;
  color: #f8fafc;
}

html.dark-theme .table,
html.dark-theme .table > :not(caption) > * > * {
  color: #e5e7eb;
  --bs-table-color: #e5e7eb;
  --bs-table-bg: transparent;
  --bs-table-border-color: #334155;
  --bs-table-hover-bg: rgba(52, 211, 153, 0.08);
  --bs-table-striped-bg: rgba(255, 255, 255, 0.03);
}

html.dark-theme .table thead th,
html.dark-theme .table thead td {
  color: #f1f5f9;
  background-color: rgba(15, 23, 42, 0.65);
  border-color: #334155;
}

html.dark-theme .dropdown-menu,
html.dark-theme .dropdown-item,
html.dark-theme .list-group-item,
html.dark-theme .modal-content,
html.dark-theme .offcanvas,
html.dark-theme .accordion-item,
html.dark-theme .accordion-button,
html.dark-theme .card,
html.dark-theme .popover,
html.dark-theme .tooltip-inner {
  color: #e5e7eb;
}

html.dark-theme .dropdown-menu,
html.dark-theme .modal-content,
html.dark-theme .offcanvas,
html.dark-theme .list-group-item,
html.dark-theme .accordion-item,
html.dark-theme .accordion-button,
html.dark-theme .card:not(.auth-card) {
  background-color: #1e293b;
  border-color: #334155;
}

html.dark-theme .dropdown-item:hover,
html.dark-theme .dropdown-item:focus,
html.dark-theme .list-group-item-action:hover,
html.dark-theme .accordion-button:not(.collapsed) {
  background-color: #273549;
  color: #f8fafc;
}

html.dark-theme input[type='file'],
html.dark-theme input[type='file'].admin-form-input,
html.dark-theme input[type='file'].form-control {
  color: #cbd5e1;
  background-color: #0b1220;
  border-color: #475569;
  color-scheme: dark;
}

html.dark-theme input[type='file']::file-selector-button,
html.dark-theme input[type='file'].admin-form-input::file-selector-button,
html.dark-theme input[type='file'].form-control::file-selector-button {
  background-color: #1e293b;
  border: 1px solid #475569;
  color: #e2e8f0;
}

html.dark-theme .btn-close {
  filter: invert(1) grayscale(100%) brightness(200%);
}

html.dark-theme .bg-light,
html.dark-theme .bg-white,
html.dark-theme .badge.bg-light {
  background-color: #273549 !important;
  color: #e5e7eb !important;
}

html.dark-theme .badge.text-dark {
  color: #f8fafc !important;
}

html.dark-theme .breadcrumb,
html.dark-theme .breadcrumb-item,
html.dark-theme .breadcrumb-item + .breadcrumb-item::before {
  color: #cbd5e1;
}

html.dark-theme .nav-tabs .nav-link,
html.dark-theme .nav-pills .nav-link {
  color: #cbd5e1;
}

html.dark-theme .nav-tabs .nav-link.active,
html.dark-theme .nav-pills .nav-link.active {
  color: #f8fafc;
  background-color: #273549;
  border-color: #475569;
}

html.dark-theme .pagination .page-link {
  background-color: #1e293b;
  border-color: #334155;
  color: #e5e7eb;
}

html.dark-theme .pagination .page-link:hover {
  background-color: #273549;
  color: #f8fafc;
}

html.dark-theme .alert-light,
html.dark-theme .alert-secondary {
  background-color: #1e293b;
  color: #e5e7eb;
  border-color: #334155;
}

html.dark-theme hr {
  border-color: #334155;
  opacity: 1;
}
