/* Tema global Toca — paleta alinhada ao Transcrever Áudio */
html[data-theme="dark"] {
    --tx-bg: #0f1419;
    --tx-surface: #161a24;
    --tx-surface-2: #10131a;
    --tx-border: #2a3142;
    --tx-text: #e8eaef;
    --tx-muted: #94a3b8;
    --tx-accent: #60a5fa;
    --tx-focus: #60a5fa;
    --tx-brand: #e85d5d;
    --tx-cta: #f97316;
    --tx-brand-soft: rgba(232, 93, 93, 0.12);
    --tx-success: #34d399;
    --tx-shadow: rgba(0, 0, 0, 0.25);
    --tx-hero: #161a24;

    --primary-color: #1a1c2e;
    --primary-dark: #12141a;
    --accent-color: #e85d5d;
    --accent-hover: #c94a4a;
    --text-primary: var(--tx-text);
    --text-secondary: var(--tx-muted);
    --border-color: var(--tx-border);
    --bg-light: var(--tx-surface-2);
    --bg-white: var(--tx-surface);
    --shadow: var(--tx-shadow);
    --shadow-hover: rgba(0, 0, 0, 0.35);
}

html[data-theme="light"] {
    --tx-bg: #f8fafc;
    --tx-surface: #ffffff;
    --tx-surface-2: #f1f5f9;
    --tx-border: #e2e8f0;
    --tx-text: #1e293b;
    --tx-muted: #64748b;
    --tx-accent: #3b82f6;
    --tx-focus: #3b82f6;
    --tx-brand: #a80909;
    --tx-cta: #ea580c;
    --tx-brand-soft: rgba(168, 9, 9, 0.08);
    --tx-success: #059669;
    --tx-shadow: rgba(15, 23, 42, 0.08);
    --tx-hero: #f8fafc;

    --primary-color: #1a1c2e;
    --primary-dark: #16181f;
    --accent-color: #a80909;
    --accent-hover: #8a0707;
    --text-primary: #1a1c2e;
    --text-secondary: #6c757d;
    --border-color: #e9ecef;
    --bg-light: #f8f9fa;
    --bg-white: #ffffff;
    --shadow: rgba(0, 0, 0, 0.1);
    --shadow-hover: rgba(0, 0, 0, 0.15);
}

html[data-theme="dark"] body,
html[data-theme="dark"] body.bg-light,
html[data-theme="dark"] #dashboard-body {
    background: var(--tx-bg) !important;
    color: var(--tx-text);
}

html[data-theme="dark"] .main-content {
    background: var(--tx-bg);
    color: var(--tx-text);
}

html[data-theme="dark"] .page-sticky-top--homepage,
html[data-theme="dark"] .page-sticky-top--list {
    background: var(--tx-bg);
}

/* Cards, filtros, tabelas, homepage */
html[data-theme="dark"] .stat-card,
html[data-theme="dark"] .filters-section,
html[data-theme="dark"] .table-section,
html[data-theme="dark"] .program-card,
html[data-theme="dark"] .homepage-toolbar,
html[data-theme="dark"] .chamado-card,
html[data-theme="dark"] .card:not(.page-header) {
    background: var(--tx-surface);
    border-color: var(--tx-border);
    color: var(--tx-text);
    box-shadow: 0 2px 8px var(--tx-shadow);
}

html[data-theme="dark"] .card-image-wrapper,
html[data-theme="dark"] .program-category {
    background: var(--tx-surface-2);
    color: var(--tx-muted);
}

html[data-theme="dark"] .program-card .program-name,
html[data-theme="dark"] .stat-label,
html[data-theme="dark"] .stat-value,
html[data-theme="dark"] .filters-header h3,
html[data-theme="dark"] .filter-group label {
    color: var(--tx-text);
}

html[data-theme="dark"] .stat-label,
html[data-theme="dark"] .filters-header h3 {
    color: var(--tx-muted);
}

html[data-theme="dark"] .modern-input,
html[data-theme="dark"] .form-control,
html[data-theme="dark"] .form-select {
    background: var(--tx-surface-2);
    border-color: var(--tx-border);
    color: var(--tx-text);
}

html[data-theme="dark"] .form-control::placeholder,
html[data-theme="dark"] .modern-input::placeholder {
    color: var(--tx-muted);
}

html[data-theme="dark"] .form-control:focus,
html[data-theme="dark"] .modern-input:focus,
html[data-theme="dark"] .form-select:focus {
    background: var(--tx-surface);
    border-color: var(--tx-accent);
    color: var(--tx-text);
    box-shadow: 0 0 0 2px rgba(96, 165, 250, 0.2);
}

html[data-theme="dark"] .btn-clear-filters {
    background: var(--tx-surface-2);
    border-color: var(--tx-border);
    color: var(--tx-muted);
}

html[data-theme="dark"] .btn-clear-filters:hover {
    background: var(--tx-border);
    color: var(--tx-text);
}

html[data-theme="dark"] .filter-btn {
    background: var(--tx-surface);
    border-color: var(--tx-border);
    color: var(--tx-text);
}

html[data-theme="dark"] .filter-btn:hover {
    border-color: var(--accent-color);
    color: var(--accent-color);
}

html[data-theme="dark"] .filter-btn.active {
    background: var(--accent-color);
    border-color: var(--accent-color);
    color: #fff;
}

html[data-theme="dark"] .homepage-search .form-control {
    background: var(--tx-surface-2);
    border-color: var(--tx-border);
    color: var(--tx-text);
}

html[data-theme="dark"] .modern-table tbody td {
    color: var(--tx-text);
    border-color: var(--tx-border);
}

html[data-theme="dark"] .modern-table tbody tr:hover {
    background: var(--tx-surface-2);
}

html[data-theme="dark"] .modern-table tbody tr:hover td {
    color: var(--tx-text);
}

html[data-theme="dark"] .empty-state,
html[data-theme="dark"] .empty-state h3 {
    color: var(--tx-text);
}

html[data-theme="dark"] .empty-state p,
html[data-theme="dark"] .text-muted {
    color: var(--tx-muted) !important;
}

html[data-theme="dark"] .toggle-btn {
    background: var(--tx-surface);
    border: 1px solid var(--tx-border);
}

html[data-theme="dark"] .toggle-btn i {
    color: var(--tx-text);
}

/* Chamados / cards bootstrap */
html[data-theme="dark"] .card-header {
    background: var(--tx-surface-2);
    border-color: var(--tx-border);
    color: var(--tx-text);
}

html[data-theme="dark"] .table {
    color: var(--tx-text);
}

html[data-theme="dark"] .table thead th {
    background-color: #252b38 !important;
    color: #d2dae5 !important;
    border-color: var(--tx-border) !important;
}

html[data-theme="dark"] .table tbody td {
    border-color: var(--tx-border);
    background-color: var(--tx-surface);
    color: var(--tx-text);
}

html[data-theme="dark"] .table-hover tbody tr:hover,
html[data-theme="dark"] .table-hover tbody tr:hover > td {
    background-color: var(--tx-surface-2) !important;
    color: var(--tx-text) !important;
}

html[data-theme="dark"] .btn-outline-secondary {
    border-color: var(--tx-border);
    color: var(--tx-text);
}

html[data-theme="dark"] .btn-outline-secondary:hover {
    background: rgba(232, 93, 93, 0.15);
    border-color: var(--accent-color);
    color: var(--tx-text);
}

html[data-theme="dark"] .modal-content {
    background: var(--tx-surface);
    border-color: var(--tx-border);
    color: var(--tx-text);
}

html[data-theme="dark"] .modal-header,
html[data-theme="dark"] .modal-footer {
    border-color: var(--tx-border);
}

html[data-theme="dark"] .btn-close {
    filter: invert(1);
    opacity: 0.85;
}

html[data-theme="dark"] .form-label {
    color: var(--tx-text);
}

html[data-theme="dark"] #meusChamadosTabs .nav-link {
    color: var(--tx-muted);
}

html[data-theme="dark"] #meusChamadosTabs .nav-link:hover,
html[data-theme="dark"] #meusChamadosTabs .nav-link.active {
    color: var(--accent-color);
}

html[data-theme="dark"] #meusChamadosTabs .nav-link.active {
    background-color: var(--tx-surface-2);
    border-color: var(--tx-border) var(--tx-border) var(--tx-surface-2);
}

/* Auditório — calendário */
html[data-theme="dark"] .calendar-weekday {
    color: var(--tx-muted);
}

html[data-theme="dark"] .calendar-day {
    background-color: var(--tx-surface);
    border-color: var(--tx-border);
    color: var(--tx-text);
}

html[data-theme="dark"] .calendar-day.is-empty {
    background-color: var(--tx-surface-2);
}

html[data-theme="dark"] .calendar-day.is-today {
    background-color: rgba(232, 93, 93, 0.12);
}

/* Dashboard TI */
html[data-theme="dark"] .resumo-metrica-card {
    background: var(--tx-surface);
    border-color: var(--tx-border);
}

html[data-theme="dark"] .resumo-metrica-label {
    color: var(--tx-muted);
}

html[data-theme="dark"] .resumo-metrica-valor {
    color: var(--tx-text);
}

html[data-theme="dark"] .grafico-chart-wrapper,
html[data-theme="dark"] .grafico-y-axis {
    background: var(--tx-surface-2);
    border-color: var(--tx-border);
}

html[data-theme="dark"] .dropdown-menu {
    background: var(--tx-surface);
    border-color: var(--tx-border);
}

html[data-theme="dark"] .dropdown-item {
    color: var(--tx-text);
}

html[data-theme="dark"] .dropdown-item:hover,
html[data-theme="dark"] .dropdown-item:focus {
    background: var(--tx-surface-2);
    color: var(--tx-text);
}

/* Sidebar: área de links ocupa o espaço; toggle fixo no rodapé */
.sidebar.d-flex.flex-column {
    min-height: 100vh;
}

.sidebar.d-flex.flex-column > .nav.flex-column {
    flex: 1 1 auto;
    min-height: 0;
    overflow-y: auto;
}

/* Botão de tema na sidebar */
.sidebar-theme-wrap {
    flex-shrink: 0;
    margin-top: auto;
    padding: 0.75rem 1rem 1rem;
    border-top: 1px solid rgba(255, 255, 255, 0.08);
}

#tocaThemeToggle,
.toca-sidebar-theme-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    width: 100%;
    padding: 0.55rem 0.75rem;
    border-radius: 8px;
    border: 1px solid rgba(232, 93, 93, 0.55);
    background: rgba(232, 93, 93, 0.18);
    color: #fff;
    font-size: 0.82rem;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.2s, border-color 0.2s, transform 0.15s;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2);
}

#tocaThemeToggle:hover,
.toca-sidebar-theme-btn:hover {
    background: rgba(232, 93, 93, 0.32);
    border-color: rgba(232, 93, 93, 0.85);
    transform: translateY(-1px);
}

#tocaThemeToggle i,
.toca-sidebar-theme-btn i {
    font-size: 0.95rem;
}

/* Cabeçalho da página: botão de tema visível ao lado do título */
.page-header-with-theme {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 0.75rem;
    flex-wrap: wrap;
}

.page-header-with-theme .page-header-main {
    flex: 1;
    min-width: 0;
}

.main-content .page-header .toca-theme-toggle-header,
.page-header-with-theme .toca-theme-toggle-header {
    flex-shrink: 0;
    align-self: center;
    border: 1px solid rgba(255, 255, 255, 0.45);
    background: rgba(255, 255, 255, 0.14);
    color: #fff;
    font-weight: 600;
    white-space: nowrap;
}

.main-content .page-header .toca-theme-toggle-header:hover,
.page-header-with-theme .toca-theme-toggle-header:hover {
    background: rgba(255, 255, 255, 0.24);
    border-color: rgba(255, 255, 255, 0.7);
    color: #fff;
}

.main-content .page-header .header-actions .toca-theme-toggle-header {
    align-self: center;
}

.sidebar.collapsed #tocaThemeToggle .toca-theme-label,
.sidebar.collapsed .toca-sidebar-theme-btn .toca-theme-label {
    display: none;
}

.sidebar.collapsed #tocaThemeToggle,
.sidebar.collapsed .toca-sidebar-theme-btn {
    padding: 0.5rem;
}

/* Toggle flutuante (login e páginas sem sidebar) */
.toca-theme-floating-wrap {
    position: fixed;
    top: 0.85rem;
    right: 0.85rem;
    z-index: 1050;
}

.toca-theme-floating-btn {
    display: inline-flex;
    align-items: center;
    gap: 0.45rem;
    padding: 0.45rem 0.85rem;
    border-radius: 999px;
    border: 1px solid var(--tx-border, #e2e8f0);
    background: var(--tx-surface, #fff);
    color: var(--tx-text, #1e293b);
    font-size: 0.8rem;
    font-weight: 500;
    cursor: pointer;
    box-shadow: 0 2px 10px var(--tx-shadow, rgba(0, 0, 0, 0.1));
    transition: border-color 0.2s, color 0.2s;
}

.toca-theme-floating-btn:hover {
    border-color: var(--tx-accent, #3b82f6);
    color: var(--tx-accent, #3b82f6);
}

html[data-theme="dark"] .login-wrapper {
    background: linear-gradient(135deg, #0f1419 0%, #161a24 50%, #10131a 100%) !important;
}

html[data-theme="dark"] .login-card .card-body {
    background-color: var(--tx-surface) !important;
    color: var(--tx-text);
}

html[data-theme="dark"] .login-card .card-header {
    border-bottom: 1px solid var(--tx-border);
}

/* Toggle no header (Transcrever / Assistente) */
.toca-theme-toggle-header {
    border-radius: 999px;
    font-size: 0.85rem;
    padding: 0.4rem 0.65rem;
    color: var(--tx-text, var(--text-primary));
    border: 1px solid var(--tx-border, var(--border-color));
    background: var(--tx-surface, var(--bg-white));
}

.toca-theme-toggle-header:hover {
    border-color: var(--tx-accent, var(--accent-color));
    color: var(--tx-accent, var(--accent-color));
}

html[data-theme="dark"] .theme-switch {
    border-color: var(--tx-border);
    background: var(--tx-surface);
}

html[data-theme="dark"] .theme-switch-icon {
    color: var(--tx-muted);
}

/* Compat: páginas que ainda usam body.dark-dashboard */
html[data-theme="dark"] body.dark-dashboard {
    background: var(--tx-bg);
    color: var(--tx-text);
}
