:root {
    --theme-surface: #fff;
    --theme-surface-rgb: 255, 255, 255;
    --theme-surface-subtle: #f8f9fa;
    --theme-surface-soft: #f0f2f5;
    --theme-surface-alt: #f6f7f9;
    --theme-dark-bg: #0f172a;
    --theme-dark-surface: #111827;
    --theme-dark-surface-2: #1f2937;
    --theme-dark-border: #2b3646;
    --theme-dark-text: #e5e7eb;
    --theme-dark-muted: #94a3b8;
    --theme-dark-accent: #60a5fa;
    --theme-dark-primary: #3b82f6;
    --theme-dark-success: #22c55e;
    --theme-dark-warning: #f59e0b;
    --theme-dark-danger: #ef4444;
}

.theme-toggle {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    white-space: nowrap;
}

body.theme-dark {
    background-color: var(--theme-dark-bg) !important;
    color: var(--theme-dark-text);
    --theme-surface: var(--theme-dark-surface);
    --theme-surface-rgb: 17, 24, 39;
    --theme-surface-subtle: var(--theme-dark-surface);
    --theme-surface-soft: var(--theme-dark-surface);
    --theme-surface-alt: var(--theme-dark-surface);
    --bs-body-bg: var(--theme-dark-bg);
    --bs-body-color: var(--theme-dark-text);
    --bs-border-color: var(--theme-dark-border);
    --bs-card-bg: var(--theme-dark-surface);
    --bs-card-color: var(--theme-dark-text);
    --bs-secondary-color: var(--theme-dark-muted);
    --bs-tertiary-color: var(--theme-dark-muted);
    --bs-link-color: var(--theme-dark-accent);
    --bs-link-hover-color: #93c5fd;
    --bs-table-bg: var(--theme-dark-surface);
    --bs-table-color: var(--theme-dark-text);
    --bs-table-striped-bg: rgba(148, 163, 184, 0.08);
    --bs-table-striped-color: var(--theme-dark-text);
    --bs-table-hover-bg: rgba(148, 163, 184, 0.12);
    --bs-table-hover-color: var(--theme-dark-text);
    --bs-emphasis-color: #f8fafc;
}

body.theme-dark::before {
    background:
        radial-gradient(circle at 12% -10%, rgba(56, 189, 248, 0.08), transparent 60%),
        radial-gradient(circle at 90% 10%, rgba(236, 72, 153, 0.08), transparent 55%),
        radial-gradient(circle at 60% 80%, rgba(15, 23, 42, 0.6), transparent 60%);
}

body.theme-dark::after {
    opacity: 0.18;
}

body.theme-dark .navbar,
body.theme-dark .navbar-admin,
body.theme-dark .prof-navbar,
body.theme-dark .aluno-navbar {
    background: var(--theme-dark-surface) !important;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.45);
}

body.theme-dark .navbar-brand,
body.theme-dark .navbar .nav-link,
body.theme-dark .navbar-admin .nav-link,
body.theme-dark .prof-navbar .nav-link,
body.theme-dark .aluno-navbar .nav-link {
    color: var(--theme-dark-text) !important;
}

body.theme-dark .navbar .nav-link.active,
body.theme-dark .navbar-admin .nav-link.active,
body.theme-dark .prof-navbar .nav-link.active,
body.theme-dark .aluno-navbar .nav-link.active {
    color: var(--theme-dark-accent) !important;
}

body.theme-dark .aluno-navbar .aluno-nome,
body.theme-dark .aluno-navbar .aluno-nome i {
    color: #fff !important;
}

body.theme-dark .dropdown-menu {
    background: var(--theme-dark-surface);
    border-color: var(--theme-dark-border);
    box-shadow: 0 8px 20px rgba(0, 0, 0, 0.35);
}

body.theme-dark .dropdown-item {
    color: var(--theme-dark-text);
}

body.theme-dark .dropdown-item:hover,
body.theme-dark .dropdown-item:focus {
    background: var(--theme-dark-surface-2);
    color: var(--theme-dark-text);
}

body.theme-dark .card,
body.theme-dark .stat-card,
body.theme-dark .admin-card,
body.theme-dark .content-section,
body.theme-dark .actions-section,
body.theme-dark .info-box,
body.theme-dark .mensageria-card,
body.theme-dark .recado-card,
body.theme-dark .header,
body.theme-dark .controls,
body.theme-dark .videos-container,
body.theme-dark .table,
body.theme-dark .list-group-item,
body.theme-dark .modal-content,
body.theme-dark .accordion-item {
    background: var(--theme-dark-surface);
    color: var(--theme-dark-text);
    border-color: var(--theme-dark-border);
}

body.theme-dark .table th,
body.theme-dark .table td {
    border-color: var(--theme-dark-border);
}

body.theme-dark .table thead th {
    color: var(--theme-dark-text);
}

body.theme-dark .form-control,
body.theme-dark .form-select,
body.theme-dark .input-group-text,
body.theme-dark textarea,
body.theme-dark input {
    background: #0f172a;
    color: var(--theme-dark-text);
    border-color: var(--theme-dark-border);
}

body.theme-dark .form-control::placeholder,
body.theme-dark textarea::placeholder,
body.theme-dark input::placeholder {
    color: var(--theme-dark-muted);
}

body.theme-dark .btn {
    color: var(--theme-dark-text);
}

body.theme-dark .btn-primary {
    background: var(--theme-dark-primary);
    border-color: var(--theme-dark-primary);
}

body.theme-dark .btn-secondary {
    background: #334155;
    border-color: #334155;
}

body.theme-dark .btn-success {
    background: var(--theme-dark-success);
    border-color: var(--theme-dark-success);
    color: #052e16;
}

body.theme-dark .btn-warning {
    background: var(--theme-dark-warning);
    border-color: var(--theme-dark-warning);
    color: #1f1300;
}

body.theme-dark .btn-danger {
    background: var(--theme-dark-danger);
    border-color: var(--theme-dark-danger);
}

body.theme-dark .btn-outline-secondary {
    color: var(--theme-dark-text);
    border-color: var(--theme-dark-muted);
}

body.theme-dark .badge,
body.theme-dark .alert {
    color: var(--theme-dark-text);
}

body.theme-dark .alert-warning {
    background: var(--theme-dark-surface-2) !important;
    border-color: var(--theme-dark-warning) !important;
    color: var(--theme-dark-text) !important;
}

body.theme-dark a {
    color: var(--theme-dark-accent);
}

body.theme-dark a:hover {
    color: #93c5fd;
}

body.theme-dark .btn-outline-primary,
body.theme-dark .btn-outline-success,
body.theme-dark .btn-outline-warning,
body.theme-dark .btn-outline-danger,
body.theme-dark .btn-outline-info,
body.theme-dark .btn-outline-light,
body.theme-dark .btn-outline-dark {
    color: var(--theme-dark-text);
    border-color: var(--theme-dark-muted);
}

body.theme-dark .btn-outline-primary:hover,
body.theme-dark .btn-outline-success:hover,
body.theme-dark .btn-outline-warning:hover,
body.theme-dark .btn-outline-danger:hover,
body.theme-dark .btn-outline-info:hover,
body.theme-dark .btn-outline-light:hover,
body.theme-dark .btn-outline-dark:hover {
    background-color: var(--theme-dark-surface-2);
    color: var(--theme-dark-text);
}

body.theme-dark .btn-light {
    background: #e5e7eb;
    border-color: #e5e7eb;
    color: #0f172a;
}

body.theme-dark .btn-light:hover {
    background: #cbd5f5;
    border-color: #cbd5f5;
}

body.theme-dark .table-responsive {
    background: var(--theme-dark-surface);
}

body.theme-dark .page-link {
    background-color: var(--theme-dark-surface);
    color: var(--theme-dark-text);
    border-color: var(--theme-dark-border);
}

body.theme-dark .page-link:hover {
    background-color: var(--theme-dark-surface-2);
    color: var(--theme-dark-text);
}

body.theme-dark .page-item.active .page-link {
    background-color: var(--theme-dark-primary);
    border-color: var(--theme-dark-primary);
    color: #fff;
}

body.theme-dark .nav-tabs .nav-link {
    color: var(--theme-dark-text);
    border-color: var(--theme-dark-border);
}

body.theme-dark .nav-tabs .nav-link.active {
    background-color: var(--theme-dark-surface);
    color: var(--theme-dark-text);
    border-color: var(--theme-dark-border);
}

body.theme-dark .nav-pills .nav-link.active {
    background-color: var(--theme-dark-primary);
}
body.theme-dark .bg-white,
body.theme-dark .bg-light,
body.theme-dark .bg-body,
body.theme-dark .bg-body-tertiary {
    background-color: var(--theme-dark-surface) !important;
    color: var(--theme-dark-text) !important;
}

body.theme-dark .card,
body.theme-dark .card-header,
body.theme-dark .card-body,
body.theme-dark .card-footer,
body.theme-dark .stat-card,
body.theme-dark .admin-card,
body.theme-dark .content-section,
body.theme-dark .actions-section,
body.theme-dark .info-box,
body.theme-dark .mensageria-card,
body.theme-dark .recado-card,
body.theme-dark .quick-action,
body.theme-dark .action-card,
body.theme-dark .activity-item,
body.theme-dark .video-card,
body.theme-dark .modal-content,
body.theme-dark .accordion-item,
body.theme-dark .list-group-item {
    background-color: var(--theme-dark-surface) !important;
    color: var(--theme-dark-text) !important;
    border-color: var(--theme-dark-border) !important;
}

body.theme-dark .card-header,
body.theme-dark .card-footer {
    border-color: var(--theme-dark-border) !important;
}

body.theme-dark .card {
    --bs-card-bg: var(--theme-dark-surface);
    --bs-card-color: var(--theme-dark-text);
}

body.theme-dark .text-muted,
body.theme-dark .text-secondary {
    color: var(--theme-dark-muted) !important;
}

body.theme-dark .text-dark,
body.theme-dark .text-body,
body.theme-dark .text-body-secondary,
body.theme-dark .text-black-50 {
    color: var(--theme-dark-text) !important;
}

body.theme-dark .table,
body.theme-dark .table th,
body.theme-dark .table td,
body.theme-dark .table thead th {
    background: var(--theme-dark-surface) !important;
    color: var(--theme-dark-text) !important;
    border-color: var(--theme-dark-border) !important;
}

body.theme-dark .table {
    --bs-table-bg: var(--theme-dark-surface);
    --bs-table-color: var(--theme-dark-text);
    --bs-table-striped-bg: rgba(148, 163, 184, 0.08);
    --bs-table-striped-color: var(--theme-dark-text);
    --bs-table-hover-bg: rgba(148, 163, 184, 0.12);
    --bs-table-hover-color: var(--theme-dark-text);
    --bs-table-border-color: var(--theme-dark-border);
}

body.theme-dark .table > :not(caption) > * > * {
    background: var(--theme-dark-surface) !important;
    color: var(--theme-dark-text) !important;
}

body.theme-dark .table-light,
body.theme-dark .table-light > :not(caption) > * > * {
    background: var(--theme-dark-surface) !important;
    color: var(--theme-dark-text) !important;
}

body.theme-dark .table-striped > tbody > tr:nth-of-type(odd) > * {
    background-color: rgba(148, 163, 184, 0.08) !important;
}

body.theme-dark .table-hover > tbody > tr:hover > * {
    background-color: rgba(148, 163, 184, 0.12) !important;
    color: var(--theme-dark-text) !important;
}

body.theme-dark table,
body.theme-dark table thead,
body.theme-dark table tbody,
body.theme-dark table tfoot,
body.theme-dark table tr,
body.theme-dark table th,
body.theme-dark table td {
    background: var(--theme-dark-surface) !important;
    color: var(--theme-dark-text) !important;
    border-color: var(--theme-dark-border) !important;
}

body.theme-dark .quick-action,
body.theme-dark .action-card {
    background: var(--theme-dark-surface) !important;
    background-image: none !important;
    color: var(--theme-dark-text) !important;
    border-color: var(--theme-dark-border) !important;
}

body.theme-dark .quick-action:hover,
body.theme-dark .action-card:hover {
    background: var(--theme-dark-surface-2) !important;
    background-image: none !important;
    color: var(--theme-dark-text) !important;
}

body.theme-dark .quick-action::before,
body.theme-dark .action-card::before {
    background: none !important;
}

body.theme-dark [style*="background: #fff"],
body.theme-dark [style*="background:#fff"],
body.theme-dark [style*="background-color: #fff"],
body.theme-dark [style*="background-color:#fff"],
body.theme-dark [style*="background: white"],
body.theme-dark [style*="background-color: white"] {
    background-color: var(--theme-dark-surface) !important;
    color: var(--theme-dark-text) !important;
}

body.theme-dark .form-control,
body.theme-dark .form-select,
body.theme-dark .input-group-text,
body.theme-dark textarea,
body.theme-dark input {
    background-color: #0b1220 !important;
    color: var(--theme-dark-text) !important;
    border-color: var(--theme-dark-border) !important;
}

body.theme-dark input[type="file"]::file-selector-button,
body.theme-dark input[type="file"]::-webkit-file-upload-button {
    background: var(--theme-dark-surface-2);
    color: var(--theme-dark-text);
    border: 1px solid var(--theme-dark-border);
    border-radius: 6px;
    padding: 0.375rem 0.75rem;
    margin-right: 0.75rem;
}

body.theme-dark .form-control:focus,
body.theme-dark .form-select:focus,
body.theme-dark textarea:focus,
body.theme-dark input:focus {
    border-color: var(--theme-dark-accent) !important;
    box-shadow: 0 0 0 0.2rem rgba(96, 165, 250, 0.25) !important;
}

body.theme-dark .btn-outline-secondary,
body.theme-dark .btn-outline-dark {
    color: var(--theme-dark-text) !important;
    border-color: var(--theme-dark-border) !important;
}

body.theme-dark .btn-outline-secondary:hover,
body.theme-dark .btn-outline-dark:hover {
    background-color: var(--theme-dark-surface-2) !important;
}

/* Aluno pages: normalize white cards in dark mode */
body.theme-dark .search-section,
body.theme-dark .turma-card,
body.theme-dark .plano-card,
body.theme-dark .filtros-card,
body.theme-dark .foto-card,
body.theme-dark .info-card,
body.theme-dark .duvida-card,
body.theme-dark .history-item,
body.theme-dark .stats-section,
body.theme-dark .ranking-table,
body.theme-dark .badge-item {
    background: var(--theme-dark-surface) !important;
    color: var(--theme-dark-text) !important;
    border-color: var(--theme-dark-border) !important;
}

body.theme-dark .turma-header,
body.theme-dark .professor-info,
body.theme-dark .progress-section,
body.theme-dark .info-item,
body.theme-dark .stat-card,
body.theme-dark .documento-item,
body.theme-dark .conteudo-aula,
body.theme-dark .documentos-list,
body.theme-dark .upload-area,
body.theme-dark .upload-area:hover {
    background: var(--theme-dark-surface-2) !important;
    color: var(--theme-dark-text) !important;
    border-color: var(--theme-dark-border) !important;
}

body.theme-dark .upload-area.drag-over {
    background: rgba(34, 197, 94, 0.15) !important;
    border-color: var(--theme-dark-success) !important;
}

body.theme-dark .progress-bar-custom {
    background: var(--theme-dark-border) !important;
}

body.theme-dark .faixa-branca {
    background: var(--theme-dark-surface-2) !important;
    color: var(--theme-dark-text) !important;
}

body.theme-dark .duvida-titulo,
body.theme-dark .history-title,
body.theme-dark .turma-title,
body.theme-dark .info-number,
body.theme-dark .stats-section h2,
body.theme-dark .page-header h1 {
    color: var(--theme-dark-text) !important;
}

body.theme-dark .duvida-meta,
body.theme-dark .history-meta,
body.theme-dark .turma-subtitle,
body.theme-dark .info-label,
body.theme-dark .stat-card .label,
body.theme-dark .page-header p,
body.theme-dark .info-card h6 {
    color: var(--theme-dark-muted) !important;
}

body.theme-dark .duvida-video,
body.theme-dark .resposta-box,
body.theme-dark .replica-box,
body.theme-dark .alert-info,
body.theme-dark .duvida-descricao,
body.theme-dark .edit-form {
    background: var(--theme-dark-surface-2) !important;
    color: var(--theme-dark-text) !important;
    border-color: var(--theme-dark-border) !important;
}

body.theme-dark .duvida-video:hover {
    background: var(--theme-dark-surface) !important;
}

body.theme-dark .resposta-header {
    color: var(--theme-dark-success) !important;
}

body.theme-dark .replica-header {
    color: var(--theme-dark-warning) !important;
}

/* Professor pages: cards, filters, charts */
body.theme-dark .alunos-list,
body.theme-dark .aluno-item,
body.theme-dark .aluno-card,
body.theme-dark .videos-section,
body.theme-dark .video-item,
body.theme-dark .filter-section,
body.theme-dark .filters,
body.theme-dark .filters-card,
body.theme-dark .filter-card,
body.theme-dark .section-tabs,
body.theme-dark .chart-card,
body.theme-dark .destinatario-header,
body.theme-dark .destinatario-content,
body.theme-dark .form-section,
body.theme-dark .cenario-card,
body.theme-dark .decisao-card,
body.theme-dark .risk-card {
    background: var(--theme-dark-surface) !important;
    color: var(--theme-dark-text) !important;
    border-color: var(--theme-dark-border) !important;
}

body.theme-dark .destinatario-header {
    background: var(--theme-dark-surface-2) !important;
}

body.theme-dark .destinatario-content {
    background: var(--theme-dark-surface) !important;
}

body.theme-dark .destinatario-chip {
    background: var(--theme-dark-surface-2) !important;
    color: var(--theme-dark-text) !important;
    border: 1px solid var(--theme-dark-border) !important;
}

body.theme-dark .filter-btn {
    background: var(--theme-dark-surface) !important;
    color: var(--theme-dark-text) !important;
    border-color: var(--theme-dark-border) !important;
}

body.theme-dark .filter-btn:hover {
    background: var(--theme-dark-surface-2) !important;
    border-color: var(--theme-dark-accent) !important;
    color: var(--theme-dark-text) !important;
}

body.theme-dark .filter-btn.active {
    background: var(--theme-dark-primary) !important;
    border-color: var(--theme-dark-primary) !important;
    color: #fff !important;
}

body.theme-dark .cenario-header {
    background: var(--theme-dark-surface-2) !important;
    border-color: var(--theme-dark-border) !important;
}

body.theme-dark .empty-state {
    background: var(--theme-dark-surface) !important;
    color: var(--theme-dark-text) !important;
    border-color: var(--theme-dark-border) !important;
}

body.theme-dark .select2-container--bootstrap-5 .select2-selection--multiple,
body.theme-dark .select2-container--bootstrap-5 .select2-selection--single {
    background-color: var(--theme-dark-surface) !important;
    color: var(--theme-dark-text) !important;
    border-color: var(--theme-dark-border) !important;
}

body.theme-dark .select2-container--bootstrap-5 .select2-selection__rendered,
body.theme-dark .select2-container--bootstrap-5 .select2-selection__placeholder {
    color: var(--theme-dark-text) !important;
}

body.theme-dark .select2-dropdown {
    background: var(--theme-dark-surface) !important;
    border-color: var(--theme-dark-border) !important;
}

body.theme-dark .select2-search__field {
    background: var(--theme-dark-surface-2) !important;
    color: var(--theme-dark-text) !important;
    border-color: var(--theme-dark-border) !important;
}

body.theme-dark .select2-results__option {
    color: var(--theme-dark-text) !important;
}

body.theme-dark .select2-results__option--highlighted,
body.theme-dark .select2-results__option[aria-selected='true'] {
    background: var(--theme-dark-surface-2) !important;
    color: var(--theme-dark-text) !important;
}

body.theme-dark [style*="background: #ffffff"],
body.theme-dark [style*="background:#ffffff"],
body.theme-dark [style*="background-color: #ffffff"],
body.theme-dark [style*="background-color:#ffffff"],
body.theme-dark [style*="background: rgb(255, 255, 255)"],
body.theme-dark [style*="background-color: rgb(255, 255, 255)"],
body.theme-dark [style*="background: rgb(255,255,255)"],
body.theme-dark [style*="background-color: rgb(255,255,255)"] {
    background-color: var(--theme-dark-surface) !important;
    color: var(--theme-dark-text) !important;
}

body.theme-dark [style*="background: #e3f2fd"],
body.theme-dark [style*="background:#e3f2fd"],
body.theme-dark [style*="background-color: #e3f2fd"],
body.theme-dark [style*="background-color:#e3f2fd"] {
    background-color: var(--theme-dark-surface-2) !important;
    color: var(--theme-dark-text) !important;
}

body.theme-dark .list-item.particular-item,
body.theme-dark .list-item.particular-item:hover,
body.theme-dark .turma-card.particular,
body.theme-dark .plano-card.particular,
body.theme-dark .feedback-content,
body.theme-dark .feedback-content.correta,
body.theme-dark .feedback-content.boa,
body.theme-dark .feedback-content.arriscada,
body.theme-dark .feedback-content.incorreta {
    background: var(--theme-dark-surface-2) !important;
    color: var(--theme-dark-text) !important;
}

body.theme-dark .conteudo-fade {
    background: linear-gradient(transparent, var(--theme-dark-surface)) !important;
}

.login-toolbar {
    display: flex;
    justify-content: flex-end;
    margin-bottom: 1rem;
}

.login-theme-toggle {
    border: 1px solid var(--border-color);
    background: var(--card-background);
    color: var(--text-primary);
    padding: 0.35rem 0.75rem;
    border-radius: 999px;
    font-size: 0.85rem;
    cursor: pointer;
    transition: background-color 0.2s ease, border-color 0.2s ease, color 0.2s ease;
}

.login-theme-toggle i {
    font-size: 0.85rem;
}

body.theme-dark.login-page {
    --background-color: var(--theme-dark-bg);
    --card-background: var(--theme-dark-surface);
    --text-primary: var(--theme-dark-text);
    --text-secondary: var(--theme-dark-muted);
    --border-color: var(--theme-dark-border);
    --accent-color: var(--theme-dark-accent);
    --light-accent: #93c5fd;
    --primary-color: var(--theme-dark-text);
    --secondary-color: var(--theme-dark-surface-2);
    --login-bg: var(--theme-dark-bg);
    --shadow-light: 0 2px 10px rgba(0, 0, 0, 0.35);
    --shadow-medium: 0 4px 20px rgba(0, 0, 0, 0.45);
}

body.theme-dark.login-page .forms-wrapper,
body.theme-dark.login-page .form-container,
body.theme-dark.login-page .checkin-section {
    background: var(--theme-dark-surface) !important;
    border-color: var(--theme-dark-border) !important;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.4);
}

body.theme-dark.login-page .form-container {
    background: var(--theme-dark-surface-2) !important;
}

body.theme-dark.login-page .checkin-section h2 {
    color: var(--theme-dark-text);
}

body.theme-dark.login-page .info-item {
    background: var(--theme-dark-surface-2);
    color: var(--theme-dark-text);
    border-color: var(--theme-dark-border);
}

body.theme-dark.login-page .info-item strong {
    color: var(--theme-dark-text);
}

body.theme-dark.login-page .info-item small {
    color: var(--theme-dark-muted);
}

body.theme-dark.login-page .checkin-alternative {
    border-top-color: var(--theme-dark-border);
}

body.theme-dark.login-page .form-switch {
    color: var(--theme-dark-muted);
}

body.theme-dark.login-page .form-switch a {
    color: var(--theme-dark-accent);
}

body.theme-dark.login-page .qr-code-display img,
body.theme-dark.login-page .qr-code-display #qrcode-checkin {
    background: #fff !important;
    color: inherit;
}
