/* ============================================================
   THEME SWITCHER - MODO CLARO
   Sobrescreve as variáveis CSS quando body.light-mode está ativo.
   Não altera NADA do modo escuro original.
   ============================================================ */

/* ---- Variáveis do modo claro (html para anti-flash + body para uso normal) ---- */
html.light-mode,
body.light-mode {
  --bg-1: #f0f2f5;
  --bg-2: #ffffff;
  --bg-3: #e2e6ec;
  --accent: #d49a00;
  --accent-2: #1a8ba6;
  --accent-break: #05b384;
  --accent-long: #7028d4;
  --accent-3: #7028d4;
  --purple: #7028d4;
  --success: #05b384;
  --danger: #e0365a;
  --error: #e0365a;
  --warning: #d49a00;
  --text: #1a202c;
  --muted: #4a5568;
  --shadow: 0 4px 24px rgba(0, 0, 0, 0.08);
}

/* ---- Body/html background (anti-flash precisa de html.light-mode também) ---- */
html.light-mode,
body.light-mode {
  background: 
    radial-gradient(circle at 20% 20%, rgba(33, 158, 188, 0.08), transparent 35%),
    radial-gradient(circle at 80% 10%, rgba(255, 183, 3, 0.08), transparent 30%),
    linear-gradient(145deg, var(--bg-1), var(--bg-2)) !important;
  color: var(--text);
}

/* ---- Sidebar ---- */
body.light-mode .sidebar {
  background: rgba(255, 255, 255, 0.97) !important;
  border-right: 1px solid rgba(0, 0, 0, 0.08) !important;
}

body.light-mode .sidebar-link {
  color: var(--muted);
}

body.light-mode .sidebar-link:hover {
  background: rgba(0, 0, 0, 0.04) !important;
  color: var(--text);
}

body.light-mode .sidebar-link.active {
  background: var(--accent) !important;
  color: #ffffff !important;
}

body.light-mode .sidebar-link.admin-link {
  background: linear-gradient(135deg, rgba(139, 92, 246, 0.08), rgba(124, 58, 237, 0.08)) !important;
  border-color: rgba(139, 92, 246, 0.2) !important;
  color: #7c3aed !important;
}

body.light-mode .sidebar-link.admin-link:hover {
  background: linear-gradient(135deg, rgba(139, 92, 246, 0.14), rgba(124, 58, 237, 0.14)) !important;
  color: #6d28d9 !important;
}

body.light-mode .sidebar-section-title {
  color: var(--muted);
}

body.light-mode .sidebar-divider,
body.light-mode .sidebar-user {
  border-color: rgba(0, 0, 0, 0.08) !important;
}

body.light-mode .sidebar-user-avatar {
  color: #ffffff !important;
}

body.light-mode .sidebar-logout {
  color: var(--muted);
}

body.light-mode .sidebar-logout:hover {
  background: rgba(239, 71, 111, 0.1) !important;
}

/* ---- Cards ---- */
body.light-mode .card,
body.light-mode .stat-card {
  background: rgba(255, 255, 255, 0.85) !important;
  border: 1px solid rgba(0, 0, 0, 0.08) !important;
  backdrop-filter: blur(8px);
}

body.light-mode .card-action {
  background: rgba(0, 0, 0, 0.04) !important;
  color: var(--muted);
}

body.light-mode .card-action:hover {
  background: rgba(0, 0, 0, 0.08) !important;
  color: var(--text);
}

/* ---- Stat icons ---- */
body.light-mode .stat-icon.primary { background: rgba(212, 154, 0, 0.12) !important; }
body.light-mode .stat-icon.secondary { background: rgba(26, 139, 166, 0.12) !important; }
body.light-mode .stat-icon.success { background: rgba(5, 179, 132, 0.12) !important; }
body.light-mode .stat-icon.purple { background: rgba(112, 40, 212, 0.12) !important; }

/* ---- Inputs, selects, textareas ---- */
body.light-mode input,
body.light-mode select,
body.light-mode textarea {
  background: rgba(0, 0, 0, 0.03) !important;
  border-color: rgba(0, 0, 0, 0.12) !important;
  color: var(--text) !important;
}

body.light-mode input::placeholder,
body.light-mode textarea::placeholder {
  color: #94a3b8 !important;
}

body.light-mode input:focus,
body.light-mode select:focus,
body.light-mode textarea:focus {
  border-color: var(--accent) !important;
  box-shadow: 0 0 0 3px rgba(212, 154, 0, 0.15) !important;
}

/* ---- Buttons genéricos ---- */
body.light-mode .btn-secondary,
body.light-mode button[style*="background: rgba(255, 255, 255, 0.06)"],
body.light-mode button[style*="background:rgba(255,255,255,0.06)"] {
  background: rgba(0, 0, 0, 0.05) !important;
  color: var(--text) !important;
}

/* ---- Modais / overlays ---- */
body.light-mode .modal-overlay,
body.light-mode [class*="overlay"] {
  background: rgba(0, 0, 0, 0.4) !important;
}

body.light-mode .modal,
body.light-mode .modal-content,
body.light-mode [class*="modal-content"],
body.light-mode [class*="modal-body"] {
  background: #ffffff !important;
  border: 1px solid rgba(0, 0, 0, 0.1) !important;
  color: var(--text) !important;
}

/* ---- Scrollbar ---- */
body.light-mode ::-webkit-scrollbar {
  width: 8px;
}

body.light-mode ::-webkit-scrollbar-track {
  background: transparent;
}

body.light-mode ::-webkit-scrollbar-thumb {
  background: rgba(0, 0, 0, 0.15);
  border-radius: 4px;
}

body.light-mode ::-webkit-scrollbar-thumb:hover {
  background: rgba(0, 0, 0, 0.25);
}

/* ---- Tooltips / toasts / badges ---- */
body.light-mode .toast,
body.light-mode [class*="toast"] {
  background: #ffffff !important;
  color: var(--text) !important;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.12) !important;
}

body.light-mode .badge {
  color: #ffffff !important;
}

/* ---- Tabelas ---- */
body.light-mode table {
  color: var(--text);
}

body.light-mode th {
  background: rgba(0, 0, 0, 0.03) !important;
  color: var(--muted);
  border-color: rgba(0, 0, 0, 0.08) !important;
}

body.light-mode td {
  border-color: rgba(0, 0, 0, 0.06) !important;
}

body.light-mode tr:hover td {
  background: rgba(0, 0, 0, 0.02) !important;
}

/* ---- Tags / chips ---- */
body.light-mode .tag,
body.light-mode .chip {
  background: rgba(0, 0, 0, 0.06) !important;
  color: var(--text) !important;
}

/* ---- Progress bars ---- */
body.light-mode .progress-bar,
body.light-mode [class*="progress-bg"],
body.light-mode [class*="progress-track"] {
  background: rgba(0, 0, 0, 0.08) !important;
}

/* ---- Dropdown / select menus ---- */
body.light-mode .dropdown-menu,
body.light-mode [class*="dropdown"] {
  background: #ffffff !important;
  border: 1px solid rgba(0, 0, 0, 0.1) !important;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.1) !important;
}

/* ---- Links em geral ---- */
body.light-mode a:not(.sidebar-link):not(.btn):not([class*="button"]) {
  color: var(--accent-2);
}

/* ---- Separadores / dividers genéricos ---- */
body.light-mode hr,
body.light-mode [class*="divider"] {
  border-color: rgba(0, 0, 0, 0.08) !important;
}

/* ============================================================
   OVERRIDES PARA COMPONENTES JS COM ESTILOS INLINE
   Usa !important para sobrescrever estilos inline hardcoded.
   Seletores baseados nos IDs/classes exatos de cada componente.
   ============================================================ */

/* -- Overlay mobile sidebar (sidebar-mobile.js) -- */
body.light-mode .sidebar-backdrop,
body.light-mode #sidebarBackdrop {
  background: rgba(0, 0, 0, 0.25) !important;
}

/* ---- Coach Bubble (coach-bubble.js) ---- */
body.light-mode #coachBubblePanel.coach-bubble-panel {
  background: #ffffff !important;
  border: 1px solid rgba(0, 0, 0, 0.1) !important;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.12) !important;
}

body.light-mode .coach-bubble-panel .coach-panel-header {
  background: linear-gradient(135deg, var(--accent), #e5a200) !important;
  border-bottom: 1px solid rgba(0, 0, 0, 0.06) !important;
}

body.light-mode .coach-bubble-panel .coach-panel-header h4,
body.light-mode .coach-bubble-panel .coach-panel-header p {
  color: #ffffff !important;
}

body.light-mode .coach-bubble-panel .coach-panel-header-btn {
  color: rgba(255, 255, 255, 0.8) !important;
}

body.light-mode .coach-bubble-panel .coach-msg.assistant {
  background: #f0f2f5 !important;
  color: var(--text) !important;
  border: 1px solid rgba(0, 0, 0, 0.06) !important;
}

body.light-mode .coach-bubble-panel .coach-msg.user {
  background: var(--accent) !important;
  color: #ffffff !important;
}

body.light-mode .coach-bubble-panel .coach-msg-time {
  color: var(--muted) !important;
}

body.light-mode .coach-bubble-panel .coach-panel-input {
  border-top: 1px solid rgba(0, 0, 0, 0.08) !important;
}

body.light-mode .coach-bubble-panel .coach-panel-input input {
  background: #f0f2f5 !important;
  border: 1px solid rgba(0, 0, 0, 0.1) !important;
  color: var(--text) !important;
}

body.light-mode .coach-bubble-panel .coach-suggestion-btn {
  background: rgba(0, 0, 0, 0.04) !important;
  border-color: rgba(0, 0, 0, 0.1) !important;
  color: var(--text) !important;
}

body.light-mode .coach-bubble-panel .coach-thinking {
  color: var(--muted) !important;
}

body.light-mode .coach-bubble-tip {
  background: #ffffff !important;
  color: var(--text) !important;
  border: 1px solid rgba(0, 0, 0, 0.1) !important;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.1) !important;
}

/* ---- Support Chat (support-chat.js) ---- */
body.light-mode #support-chat-panel.support-chat-panel {
  background: #ffffff !important;
  border: 1px solid rgba(0, 0, 0, 0.1) !important;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.12) !important;
}

body.light-mode .support-chat-panel .support-chat-header {
  border-bottom: 1px solid rgba(0, 0, 0, 0.06) !important;
}

body.light-mode .support-chat-panel .support-chat-header-text h4,
body.light-mode .support-chat-panel .support-chat-header-text p {
  color: #ffffff !important;
}

body.light-mode .support-chat-panel .support-chat-header-btn,
body.light-mode .support-chat-panel .support-chat-close-mobile {
  color: rgba(255, 255, 255, 0.8) !important;
}

body.light-mode #support-chat-body {
  background: #fafbfc !important;
}

body.light-mode .support-chat-message.user {
  background: var(--accent-2) !important;
  color: #ffffff !important;
}

body.light-mode .support-chat-message.admin,
body.light-mode .support-chat-message.ai {
  background: #f0f2f5 !important;
  color: var(--text) !important;
  border: 1px solid rgba(0, 0, 0, 0.06) !important;
}

body.light-mode .support-chat-message-time {
  color: var(--muted) !important;
}

body.light-mode .support-chat-input-area {
  border-top: 1px solid rgba(0, 0, 0, 0.08) !important;
  background: #ffffff !important;
}

body.light-mode .support-chat-input {
  background: #f0f2f5 !important;
  border: 1px solid rgba(0, 0, 0, 0.1) !important;
  color: var(--text) !important;
}

body.light-mode .support-chat-ticket-item {
  background: #ffffff !important;
  border: 1px solid rgba(0, 0, 0, 0.06) !important;
  color: var(--text) !important;
}

body.light-mode .support-chat-ticket-item:hover {
  background: #f7f8fa !important;
}

body.light-mode .support-chat-ticket-subject {
  color: var(--text) !important;
}

body.light-mode .support-chat-ticket-preview,
body.light-mode .support-chat-ticket-time {
  color: var(--muted) !important;
}

body.light-mode .support-chat-empty {
  color: var(--muted) !important;
}

body.light-mode .support-chat-quick-btn {
  background: rgba(0, 0, 0, 0.04) !important;
  border-color: rgba(0, 0, 0, 0.1) !important;
  color: var(--text) !important;
}

body.light-mode .support-chat-new-ticket input,
body.light-mode .support-chat-new-ticket select,
body.light-mode .support-chat-new-ticket textarea {
  background: #f0f2f5 !important;
  border: 1px solid rgba(0, 0, 0, 0.1) !important;
  color: var(--text) !important;
}

body.light-mode .support-chat-rating-box {
  background: #f7f8fa !important;
  border: 1px solid rgba(0, 0, 0, 0.06) !important;
}

/* ---- Quick Notes (quick-notes.js) ---- */
body.light-mode #notesPanel.notes-panel {
  background: #ffffff !important;
  border: 1px solid rgba(0, 0, 0, 0.1) !important;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.12) !important;
}

body.light-mode .notes-panel .notes-panel-header {
  border-bottom: 1px solid rgba(0, 0, 0, 0.06) !important;
  color: var(--text) !important;
}

body.light-mode .notes-panel .notes-panel-header h3 {
  color: var(--accent-2) !important;
}

body.light-mode .notes-panel .qnote-item {
  background: #f7f8fa !important;
  border: 1px solid rgba(0, 0, 0, 0.06) !important;
}

body.light-mode .notes-panel .qnote-item:hover {
  background: #f0f2f5 !important;
}

body.light-mode .notes-panel .qnote-title {
  color: var(--text) !important;
}

body.light-mode .notes-panel .qnote-preview,
body.light-mode .notes-panel .qnote-meta {
  color: var(--muted) !important;
}

body.light-mode .notes-panel .notes-editor-content {
  background: #f7f8fa !important;
  border: 1px solid rgba(0, 0, 0, 0.1) !important;
  color: var(--text) !important;
}

body.light-mode .notes-panel .notes-editor-toolbar button {
  background: rgba(0, 0, 0, 0.04) !important;
  color: var(--muted) !important;
  border-color: rgba(0, 0, 0, 0.08) !important;
}

body.light-mode .qnote-empty {
  color: var(--muted) !important;
}

/* ---- Plan Guard (plan-guard-v4.js) ---- */
body.light-mode #accessBlockedModal {
  background: rgba(0, 0, 0, 0.4) !important;
}

body.light-mode #accessBlockedModal > div {
  background: #ffffff !important;
  color: var(--text) !important;
  border: 1px solid rgba(0, 0, 0, 0.1) !important;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.15) !important;
}

body.light-mode #accessBlockedModal h2 {
  color: var(--accent) !important;
}

body.light-mode #accessBlockedModal p {
  color: var(--muted) !important;
}

body.light-mode .plan-banner {
  background: #ffffff !important;
  box-shadow: 0 2px 12px rgba(0, 0, 0, 0.08) !important;
}

body.light-mode .plan-banner-text {
  color: var(--text) !important;
}

/* ---- Gamificação (gamificacao.js) ---- */
body.light-mode .gamificacao-toast {
  background: #ffffff !important;
  color: var(--text) !important;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.12) !important;
}

body.light-mode .gamificacao-toast-title {
  color: var(--text) !important;
}

body.light-mode .gamificacao-toast-sub {
  color: var(--muted) !important;
}

body.light-mode .gamificacao-levelup-overlay {
  background: rgba(0, 0, 0, 0.5) !important;
}

body.light-mode .gamificacao-levelup-card {
  background: #ffffff !important;
  color: var(--text) !important;
  border: 2px solid var(--accent) !important;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.15) !important;
}

body.light-mode .gamificacao-levelup-title {
  color: var(--accent) !important;
}

body.light-mode .gamificacao-levelup-level {
  color: var(--text) !important;
}

body.light-mode .gamificacao-levelup-titulo {
  color: var(--muted) !important;
}

/* ---- Adaptive Feedback (adaptive-feedback.js) ---- */
body.light-mode #modal-adaptive-feedback .ciclo-alert-modal {
  background: rgba(0, 0, 0, 0.4) !important;
}

body.light-mode #modal-adaptive-feedback .ciclo-alert-content {
  background: #ffffff !important;
  color: var(--text) !important;
  border: 1px solid rgba(0, 0, 0, 0.1) !important;
}

body.light-mode #modal-adaptive-feedback .ciclo-alert-title {
  color: var(--accent) !important;
}

body.light-mode #autoavaliacao-opcoes button,
body.light-mode #quiz-alternativas button {
  background: rgba(0, 0, 0, 0.03) !important;
  color: var(--text) !important;
  border: 1px solid rgba(0, 0, 0, 0.1) !important;
}

body.light-mode #autoavaliacao-opcoes button:hover,
body.light-mode #quiz-alternativas button:hover {
  background: rgba(0, 0, 0, 0.06) !important;
}

/* ---- Transitions loader (transitions.js) ---- */
body.light-mode .page-transition-loader {
  background: linear-gradient(135deg, var(--bg-1), var(--bg-2)) !important;
}

body.light-mode .page-transition-loader .loader-spinner {
  border-top-color: var(--accent) !important;
}

body.light-mode .page-transition-loader .loader-spinner::after {
  border-bottom-color: var(--accent-2) !important;
}

body.light-mode .page-transition-loader .loader-logo {
  color: var(--accent) !important;
}

/* ---- Gemini API modal (gemini-api.js) ---- */
body.light-mode #quotaExceededModal {
  background: rgba(0, 0, 0, 0.4) !important;
}

body.light-mode #quotaExceededModal > div {
  background: #ffffff !important;
  color: var(--text) !important;
  border: 1px solid rgba(0, 0, 0, 0.1) !important;
}

body.light-mode #quotaExceededModal h2,
body.light-mode #quotaExceededModal h3 {
  color: var(--accent) !important;
}

body.light-mode #quotaExceededModal p,
body.light-mode #quotaExceededModal span {
  color: var(--muted) !important;
}

/* ---- Auth inline errors (auth.js) ---- */
body.light-mode [class*="auth-error"],
body.light-mode [class*="login-error"],
body.light-mode .error-message {
  background: rgba(224, 54, 90, 0.08) !important;
  color: var(--danger) !important;
}

/* ============================================================
   TOGGLE BUTTON STYLES
   ============================================================ */

.theme-selector {
  padding: 4px 16px 4px 16px;
  margin-top: 4px;
}

.theme-toggle-btn {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  padding: 8px 12px;
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 8px;
  color: var(--muted);
  font-size: 13px;
  font-family: inherit;
  cursor: pointer;
  transition: all 0.2s;
}

.theme-toggle-btn:hover {
  background: rgba(255, 255, 255, 0.1);
  color: var(--text);
}

.theme-toggle-btn .theme-icon {
  font-size: 16px;
  width: 20px;
  text-align: center;
  transition: transform 0.3s;
}

.theme-toggle-btn .theme-label {
  flex: 1;
  text-align: left;
}

.theme-toggle-btn .theme-indicator {
  width: 36px;
  height: 20px;
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.15);
  position: relative;
  transition: background 0.3s;
}

.theme-toggle-btn .theme-indicator::after {
  content: '';
  position: absolute;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: var(--muted);
  top: 2px;
  left: 2px;
  transition: all 0.3s;
}

/* Quando está no modo claro */
body.light-mode .theme-toggle-btn {
  background: rgba(0, 0, 0, 0.04) !important;
  border-color: rgba(0, 0, 0, 0.1) !important;
}

body.light-mode .theme-toggle-btn:hover {
  background: rgba(0, 0, 0, 0.08) !important;
}

body.light-mode .theme-toggle-btn .theme-indicator {
  background: var(--accent) !important;
}

body.light-mode .theme-toggle-btn .theme-indicator::after {
  background: #ffffff !important;
  transform: translateX(16px);
}

/* ============================================================
   PÁGINAS ESPECÍFICAS - COMPLEMENTOS
   ============================================================ */

/* -- Pomodoro timer -- */
body.light-mode .timer-display,
body.light-mode [class*="timer-circle"],
body.light-mode [class*="pomodoro-timer"] {
  color: var(--text) !important;
}

/* -- Flashcards -- */
body.light-mode .flashcard,
body.light-mode [class*="flashcard-card"],
body.light-mode .flip-card-front,
body.light-mode .flip-card-back {
  background: #ffffff !important;
  color: var(--text) !important;
  border: 1px solid rgba(0, 0, 0, 0.08) !important;
}

/* -- Mapas Mentais -- */
body.light-mode [class*="mind-map"] .node,
body.light-mode [class*="mapa"] .node {
  background: #ffffff !important;
  border: 1px solid rgba(0, 0, 0, 0.1) !important;
  color: var(--text) !important;
}

/* -- Conquistas / achievements -- */
body.light-mode .achievement-card,
body.light-mode [class*="achievement"] {
  background: rgba(255, 255, 255, 0.85) !important;
  border: 1px solid rgba(0, 0, 0, 0.06) !important;
}

body.light-mode .achievement-card.locked,
body.light-mode [class*="achievement"].locked {
  opacity: 0.5;
}

/* -- Ciclos de estudo -- */
body.light-mode .cycle-card,
body.light-mode [class*="cycle-item"] {
  background: rgba(255, 255, 255, 0.85) !important;
  border: 1px solid rgba(0, 0, 0, 0.06) !important;
}

/* -- Matérias -- */
body.light-mode .subject-card,
body.light-mode [class*="materia-card"] {
  background: rgba(255, 255, 255, 0.85) !important;
  border: 1px solid rgba(0, 0, 0, 0.06) !important;
}

/* -- Notas / Notes -- */
body.light-mode .note-editor,
body.light-mode [class*="note-content"],
body.light-mode [class*="editor-area"] {
  background: #ffffff !important;
  color: var(--text) !important;
}

/* -- Resumos -- */
body.light-mode [class*="resumo-card"],
body.light-mode [class*="summary-card"] {
  background: rgba(255, 255, 255, 0.85) !important;
  border: 1px solid rgba(0, 0, 0, 0.06) !important;
  color: var(--text) !important;
}

/* -- Perfil -- */
body.light-mode .profile-card,
body.light-mode [class*="profile-section"] {
  background: rgba(255, 255, 255, 0.85) !important;
  border: 1px solid rgba(0, 0, 0, 0.06) !important;
}

/* -- Planner / Agenda -- */
body.light-mode .planner-card,
body.light-mode [class*="agenda-item"],
body.light-mode [class*="event-card"] {
  background: rgba(255, 255, 255, 0.85) !important;
  border: 1px solid rgba(0, 0, 0, 0.06) !important;
}

/* -- Estatísticas chart bars -- */
body.light-mode .chart-bar {
  opacity: 0.9;
}

/* ============================================================
   MEDIA RESPONSIVE - Mobile sidebar light mode
   ============================================================ */
@media (max-width: 992px) {
  body.light-mode .sidebar {
    background: rgba(255, 255, 255, 0.98) !important;
  }
}

/* ============================================================
   TRANSIÇÃO SUAVE ENTRE TEMAS
   ============================================================ */
body,
body .sidebar,
body .card,
body .stat-card,
body .main-content,
body input,
body select,
body textarea,
body button,
body a {
  transition: background-color 0.3s ease, color 0.3s ease, border-color 0.3s ease, box-shadow 0.3s ease;
}

/* Desabilitar transição no carregamento inicial para evitar flash */
body.theme-transitioning * {
  transition: none !important;
}
