/* ========================================
   DARK MODE - TEMA ESCURO (PRETO PURO)
   ======================================== */

/* Light Mode (Padrão) - Já definido em style.css */

/* Dark Mode - Cores em Preto Puro */
[data-theme="dark"] {
    /* Cores Primárias - Otimizadas para preto puro */
    --primary: #818cf8;              /* Índigo mais claro no dark */
    --primary-dark: #6366f1;
    --primary-light: #a5b4fc;
    
    /* Cores Secundárias */
    --secondary: #f472b6;            /* Rosa mais clara */
    --secondary-light: #f9a8d4;
    
    /* Cores Funcionais */
    --success: #34d399;              /* Verde ajustado */
    --warning: #fbbf24;              /* Âmbar ajustado */
    --danger: #f87171;               /* Vermelho ajustado */
    --info: #60a5fa;                 /* Azul ajustado */
    
    /* Neutros - Invertidos para dark com preto puro */
    --text-primary: #f3f4f6;         /* Texto claro */
    --text-secondary: #d1d5db;       /* Texto médio */
    --text-light: #9ca3af;           /* Texto claro desabilitado */
    --bg-primary: #0a0a0a;           /* Preto puro principal */
    --bg-secondary: #1a1a1a;         /* Cinza bem escuro */
    --bg-tertiary: #282828;          /* Cinza escuro */
    --border: #333333;               /* Borda muito escura */
    
    /* Sombras - Adaptadas para preto puro */
    --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.5);
    --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.6);
    --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.7);
    --shadow-xl: 0 20px 25px -5px rgba(0, 0, 0, 0.8);
    --shadow-2xl: 0 25px 50px -12px rgba(0, 0, 0, 0.9);
}

/* ========================================
   SCROLL BAR - DARK MODE
   ======================================== */

[data-theme="dark"] ::-webkit-scrollbar-track {
    background: var(--bg-secondary);
}

[data-theme="dark"] ::-webkit-scrollbar-thumb {
    background: linear-gradient(180deg, var(--primary), var(--secondary));
}

[data-theme="dark"] ::-webkit-scrollbar-thumb:hover {
    background: linear-gradient(180deg, var(--secondary), var(--primary));
}

[data-theme="dark"] {
    scrollbar-color: var(--primary) var(--bg-secondary);
}

/* ========================================
   TRANSIÇÃO SUAVE DE TEMAS
   ======================================== */

html {
    transition: background-color 0.3s ease, color 0.3s ease;
}

/* ========================================
   PREFERÊNCIA DO SISTEMA
   ======================================== */

@media (prefers-color-scheme: dark) {
    :root {
        /* Apenas aplica se não houver preferência do usuário */
        color-scheme: dark light;
    }
}

/* ========================================
   AJUSTES ESPECÍFICOS PARA DARK MODE
   ======================================== */

[data-theme="dark"] .header {
    background: linear-gradient(135deg, #000000 0%, #111111 100%);
    box-shadow: 0 10px 15px -3px rgba(0, 0, 0, 0.5);
}

[data-theme="dark"] input,
[data-theme="dark"] textarea,
[data-theme="dark"] select {
    background: var(--bg-secondary);
    color: var(--text-primary);
    border-color: var(--border);
}

[data-theme="dark"] input:focus,
[data-theme="dark"] textarea:focus,
[data-theme="dark"] select:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(129, 140, 248, 0.2);
}

[data-theme="dark"] .form-container,
[data-theme="dark"] .chamado-detalhes {
    background: var(--bg-primary);
}

[data-theme="dark"] .sidebar {
    background: var(--bg-secondary);
    border-color: var(--border);
}

[data-theme="dark"] .chamado-card,
[data-theme="dark"] .card {
    background: var(--bg-secondary);
    border-color: var(--border);
}

[data-theme="dark"] .chamado-header {
    border-bottom-color: var(--border);
}

[data-theme="dark"] .descricao {
    background: var(--bg-tertiary);
    border-left-color: var(--primary);
}

[data-theme="dark"] .info-card {
    background: var(--bg-tertiary);
    border-color: var(--border);
}

[data-theme="dark"] .form-comentario {
    background: var(--bg-tertiary);
}

[data-theme="dark"] .comentario {
    background: var(--bg-tertiary);
    border-left-color: var(--primary);
}

[data-theme="dark"] .sem-comentarios {
    background: var(--bg-tertiary);
}

[data-theme="dark"] .badge-status.aberto {
    background: rgba(96, 165, 250, 0.15);
    color: #60a5fa;
}

[data-theme="dark"] .badge-status.em_andamento {
    background: rgba(251, 191, 36, 0.15);
    color: #fbbf24;
}

[data-theme="dark"] .badge-status.resolvido {
    background: rgba(52, 211, 153, 0.15);
    color: #34d399;
}

[data-theme="dark"] .badge-status.fechado {
    background: rgba(107, 114, 128, 0.15);
    color: #9ca3af;
}

[data-theme="dark"] .badge-priority.baixa {
    background: rgba(52, 211, 153, 0.15);
    color: #34d399;
}

[data-theme="dark"] .badge-priority.media {
    background: rgba(251, 191, 36, 0.15);
    color: #fbbf24;
}

[data-theme="dark"] .badge-priority.alta {
    background: rgba(248, 113, 113, 0.15);
    color: #f87171;
}

[data-theme="dark"] .badge-priority.critica {
    background: rgba(248, 113, 113, 0.25);
    color: #ef5350;
}

[data-theme="dark"] .alert,
[data-theme="dark"] .alert.erro {
    background: rgba(248, 113, 113, 0.15);
    color: #f87171;
    border-color: rgba(248, 113, 113, 0.3);
}

[data-theme="dark"] .alert.sucesso {
    background: rgba(52, 211, 153, 0.15);
    color: #34d399;
    border-color: rgba(52, 211, 153, 0.3);
}

[data-theme="dark"] .alert.aviso {
    background: rgba(251, 191, 36, 0.15);
    color: #fbbf24;
    border-color: rgba(251, 191, 36, 0.3);
}

[data-theme="dark"] .vazio {
    border: 2px dashed var(--border);
    background: var(--bg-secondary);
}

[data-theme="dark"] .modal {
    background: var(--bg-primary);
}

[data-theme="dark"] .modal-header {
    background: var(--bg-secondary);
    border-bottom-color: var(--border);
}

[data-theme="dark"] .modal-footer {
    background: var(--bg-secondary);
    border-top-color: var(--border);
}

[data-theme="dark"] .dropdown-menu {
    background: var(--bg-primary);
    border-color: var(--border);
}

[data-theme="dark"] .dropdown-item:hover {
    background: linear-gradient(90deg, var(--primary) 0%, var(--secondary) 100%);
    color: white;
}

[data-theme="dark"] .notification-card {
    background: var(--bg-secondary);
    border-color: var(--border);
}

[data-theme="dark"] .tabs {
    background: var(--bg-secondary);
    border-bottom-color: var(--border);
}

[data-theme="dark"] .tab-button:hover,
[data-theme="dark"] .tab-button.active {
    color: var(--primary);
}

[data-theme="dark"] .tab-content {
    color: var(--text-primary);
}

[data-theme="dark"] .stat-card {
    background: linear-gradient(135deg, var(--bg-secondary) 0%, var(--bg-tertiary) 100%);
    border-color: var(--border);
}

[data-theme="dark"] .progress-bar {
    background: var(--bg-tertiary);
    border-color: var(--border);
}

[data-theme="dark"] .timeline-item {
    border-left-color: var(--border);
}

[data-theme="dark"] .timeline-item::before {
    background: var(--primary);
    border-color: var(--bg-primary);
    box-shadow: 0 0 0 2px var(--border);
}

[data-theme="dark"] .pill {
    background: var(--bg-tertiary);
    color: var(--text-primary);
}

[data-theme="dark"] .pill:hover {
    background: var(--primary);
    color: white;
}

[data-theme="dark"] .file-upload-area {
    background: var(--bg-tertiary);
    border-color: var(--border);
}

[data-theme="dark"] .file-upload-area:hover {
    background: linear-gradient(135deg, var(--primary) 0%, var(--secondary) 100%);
    opacity: 0.15;
}

[data-theme="dark"] .image-container {
    background: var(--bg-tertiary);
    border-color: var(--border);
}

[data-theme="dark"] .toast {
    background: var(--bg-primary);
    border-color: var(--border);
}

/* Ajustes de contraste para elementos com estilo inline legado */
[data-theme="dark"] small[style*="color: #666"],
[data-theme="dark"] small[style*="color:#666"],
[data-theme="dark"] div[style*="color: #666"],
[data-theme="dark"] div[style*="color:#666"],
[data-theme="dark"] td[style*="color: #666"],
[data-theme="dark"] td[style*="color:#666"],
[data-theme="dark"] p[style*="color: #555"],
[data-theme="dark"] p[style*="color:#555"],
[data-theme="dark"] p[style*="color: #333"],
[data-theme="dark"] p[style*="color:#333"] {
    color: var(--text-secondary) !important;
}

[data-theme="dark"] div[style*="background: #f5f5f5"],
[data-theme="dark"] div[style*="background:#f5f5f5"],
[data-theme="dark"] div[style*="background: #f9f9f9"],
[data-theme="dark"] div[style*="background:#f9f9f9"] {
    background: var(--bg-tertiary) !important;
    border-color: var(--border) !important;
}

/* ========================================
   TRANSIÇÃO SUAVE DE TEMA
   ======================================== */

body,
.header,
input,
textarea,
select,
.form-container,
.chamado-card,
.sidebar,
.modal,
.dropdown-menu,
.notification-card {
    transition: background-color 0.3s ease, color 0.3s ease, border-color 0.3s ease;
}

/* ========================================
   ÍCONE DO TEMA (Toggle Button)
   ======================================== */

.theme-toggle {
    background: rgba(255, 255, 255, 0.2);
    border: 1px solid rgba(255, 255, 255, 0.3);
    color: white;
    padding: 0.5rem 1rem;
    border-radius: var(--radius-md);
    cursor: pointer;
    font-size: 14px;
    font-weight: 500;
    transition: var(--transition);
    display: flex;
    align-items: center;
    gap: 0.5rem;
    text-decoration: none;
}

.theme-toggle:hover {
    background: rgba(255, 255, 255, 0.3);
    transform: translateY(-2px);
}

.theme-toggle-icon {
    font-size: 18px;
    display: inline-flex;
    align-items: center;
}

/* ========================================
   ANIMAÇÃO DO TOGGLE
   ======================================== */

@keyframes spin-toggle {
    from {
        transform: rotate(0deg);
    }
    to {
        transform: rotate(360deg);
    }
}

.theme-toggle:active .theme-toggle-icon {
    animation: spin-toggle 0.5s ease-in-out;
}

/* ========================================
   PREFERÊNCIA DO SISTEMA (AUTO)
   ======================================== */

@media (prefers-color-scheme: dark) {
    /* Se o usuário não definiu preferência explícita, detectar do sistema */
    :root:not([data-theme]) {
        color-scheme: dark;
    }
}

/* ========================================
   OTIMIZAÇÃO RESPONSIVA - DARK MODE
   ======================================== */

/* Mobile First - Telas Pequenas (até 480px) */
@media (max-width: 480px) {
    [data-theme="dark"] {
        --gap-xs: 0.25rem;
        --gap-sm: 0.5rem;
        --gap-md: 0.75rem;
        --gap-lg: 1rem;
        --gap-xl: 1.5rem;
    }

    [data-theme="dark"] .container,
    [data-theme="dark"] .form-container,
    [data-theme="dark"] .chamado-detalhes {
        padding: 0.75rem;
        margin: 0;
    }

    [data-theme="dark"] .header {
        padding: 0.5rem 0.75rem;
    }

    [data-theme="dark"] .sidebar {
        display: none;
    }

    [data-theme="dark"] .chamado-card,
    [data-theme="dark"] .card,
    [data-theme="dark"] .info-card {
        padding: 0.75rem;
        margin-bottom: 0.75rem;
        border-radius: var(--radius-sm);
    }

    [data-theme="dark"] h1 {
        font-size: 1.75rem;
    }

    [data-theme="dark"] h2 {
        font-size: 1.25rem;
    }

    [data-theme="dark"] h3 {
        font-size: 1rem;
    }

    [data-theme="dark"] input,
    [data-theme="dark"] textarea,
    [data-theme="dark"] select,
    [data-theme="dark"] button {
        padding: 0.625rem 0.75rem;
        font-size: 14px;
        min-height: 44px;
        width: 100%;
    }

    [data-theme="dark"] .stats {
        grid-template-columns: 1fr;
        gap: 0.75rem;
    }

    [data-theme="dark"] table {
        font-size: 12px;
    }

    [data-theme="dark"] th,
    [data-theme="dark"] td {
        padding: 0.5rem;
    }

    [data-theme="dark"] .chamado-header {
        flex-direction: column;
        gap: 0.75rem;
    }

    [data-theme="dark"] .badge-status,
    [data-theme="dark"] .badge-priority {
        font-size: 11px;
        padding: 0.25rem 0.5rem;
    }

    [data-theme="dark"] .tab-button {
        padding: 0.5rem 0.75rem;
        font-size: 12px;
    }

    [data-theme="dark"] .modal {
        width: 100% !important;
        max-width: none;
        margin: 0;
        border-radius: var(--radius-md) var(--radius-md) 0 0;
        max-height: 90vh;
        bottom: 0;
    }

    [data-theme="dark"] .theme-toggle {
        padding: 0.4rem 0.75rem;
        font-size: 12px;
    }

    [data-theme="dark"] .theme-toggle-icon {
        font-size: 14px;
    }
}

/* Tablets - Telas Médias (481px até 768px) */
@media (min-width: 481px) and (max-width: 768px) {
    [data-theme="dark"] {
        --gap-xs: 0.5rem;
        --gap-sm: 0.75rem;
        --gap-md: 1.25rem;
        --gap-lg: 1.5rem;
        --gap-xl: 2rem;
    }

    [data-theme="dark"] .container,
    [data-theme="dark"] .form-container,
    [data-theme="dark"] .chamado-detalhes {
        padding: 1rem;
        margin: 0.5rem auto;
        max-width: 90%;
    }

    [data-theme="dark"] .stats {
        grid-template-columns: repeat(2, 1fr);
        gap: 1rem;
    }

    [data-theme="dark"] .chamado-card,
    [data-theme="dark"] .card {
        padding: 1rem;
        margin-bottom: 1rem;
    }

    [data-theme="dark"] input,
    [data-theme="dark"] textarea,
    [data-theme="dark"] select,
    [data-theme="dark"] button {
        min-height: 42px;
    }

    [data-theme="dark"] h1 {
        font-size: 1.875rem;
    }

    [data-theme="dark"] table {
        font-size: 13px;
    }
}

/* Desktop - Telas Grandes (acima de 768px) */
@media (min-width: 769px) {
    [data-theme="dark"] .container,
    [data-theme="dark"] .form-container {
        padding: 1.5rem;
    }

    [data-theme="dark"] .sidebar {
        display: block;
    }

    [data-theme="dark"] .stats {
        grid-template-columns: repeat(3, 1fr);
    }

    [data-theme="dark"] input,
    [data-theme="dark"] textarea,
    [data-theme="dark"] select,
    [data-theme="dark"] button {
        min-height: auto;
    }
}

/* ========================================
   MOBILE RESPONSIVO
   ======================================== */

@media (max-width: 768px) {
    .theme-toggle {
        padding: 0.5rem 0.75rem;
        font-size: 12px;
    }
    
    .theme-toggle-icon {
        font-size: 16px;
    }
}
