/* 
 * Design System - Sistema de Gestão Institucional
 * Estilo Premium Moderno (Glassmorphism & Responsive Grid)
 */

/* ==========================================================================
   1. Variáveis de Tema (Design System Tokens)
   ========================================================================== */
:root {
    /* Palete Claro */
    --light-bg: #f3f4f6;
    --light-bg-grid: radial-gradient(at 0% 0%, rgba(99, 102, 241, 0.05) 0px, transparent 50%),
                         radial-gradient(at 100% 100%, rgba(6, 182, 212, 0.04) 0px, transparent 50%);
    --light-card-bg: rgba(255, 255, 255, 0.75);
    --light-card-border: rgba(255, 255, 255, 0.6);
    --light-text-primary: #1f2937;
    --light-text-secondary: #4b5563;
    --light-text-tertiary: #9ca3af;
    --light-shadow: 0 10px 30px rgba(31, 41, 55, 0.05), 0 1px 3px rgba(31, 41, 55, 0.02);
    --light-input-bg: rgba(255, 255, 255, 0.9);
    --light-input-border: #e5e7eb;
    --light-sidebar-bg: rgba(255, 255, 255, 0.8);
    --light-sidebar-border: rgba(229, 231, 235, 0.5);

    /* Cores Universais */
    --primary: #6366f1;         /* Indigo Moderno */
    --primary-light: #818cf8;
    --primary-dark: #4f46e5;
    --primary-glow: rgba(99, 102, 241, 0.15);
    --accent: #06b6d4;          /* Teal / Cyan */
    --accent-glow: rgba(6, 182, 212, 0.15);
    --success: #10b981;         /* Emerald */
    --success-glow: rgba(16, 185, 129, 0.1);
    --warning: #f59e0b;         /* Amber */
    --warning-glow: rgba(245, 158, 11, 0.1);
    --danger: #ef4444;          /* Rose Red */
    --danger-glow: rgba(239, 68, 68, 0.1);

    /* Atribuições Padrão (Tema Escuro é o Default por ser mais Impressionante) */
    --bg-color: #0b0f19;
    --bg-image: radial-gradient(at 0% 0%, rgba(99, 102, 241, 0.15) 0px, transparent 50%),
                 radial-gradient(at 100% 100%, rgba(6, 182, 212, 0.1) 0px, transparent 50%);
    --card-bg: rgba(22, 30, 49, 0.7);
    --card-border: rgba(255, 255, 255, 0.08);
    --text-primary: #f8fafc;
    --text-secondary: #94a3b8;
    --text-tertiary: #64748b;
    --shadow-color: rgba(0, 0, 0, 0.3);
    --shadow: 0 10px 30px var(--shadow-color), 0 1px 3px rgba(0, 0, 0, 0.1);
    --input-bg: rgba(15, 23, 42, 0.6);
    --input-border: rgba(255, 255, 255, 0.08);
    --sidebar-bg: rgba(15, 23, 42, 0.75);
    --sidebar-border: rgba(255, 255, 255, 0.06);
    --table-header-bg: rgba(30, 41, 59, 0.5);
    --table-row-hover: rgba(255, 255, 255, 0.02);

    --border-radius-sm: 8px;
    --border-radius-md: 12px;
    --border-radius-lg: 20px;
    --border-radius-xl: 30px;
    
    --transition-fast: 0.2s ease;
    --transition-normal: 0.3s ease;
    --transition-slow: 0.5s cubic-bezier(0.4, 0, 0.2, 1);
}

/* Redefinições para Tema Claro */
body.light-theme {
    --bg-color: var(--light-bg);
    --bg-image: var(--light-bg-grid);
    --card-bg: var(--light-card-bg);
    --card-border: var(--light-card-border);
    --text-primary: var(--light-text-primary);
    --text-secondary: var(--light-text-secondary);
    --text-tertiary: var(--light-text-tertiary);
    --shadow-color: rgba(31, 41, 55, 0.08);
    --shadow: var(--light-shadow);
    --input-bg: var(--light-input-bg);
    --input-border: var(--light-input-border);
    --sidebar-bg: var(--light-sidebar-bg);
    --sidebar-border: var(--light-sidebar-border);
    --table-header-bg: rgba(229, 231, 235, 0.5);
    --table-row-hover: rgba(0, 0, 0, 0.015);
}

/* ==========================================================================
   2. Reset e Estilo Geral
   ========================================================================== */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Inter', sans-serif;
    background-color: var(--bg-color);
    background-image: var(--bg-image);
    background-attachment: fixed;
    color: var(--text-primary);
    min-height: 100vh;
    overflow-x: hidden;
    transition: background-color var(--transition-normal), color var(--transition-normal);
}

/* Scrollbar estilizada */
::-webkit-scrollbar {
    width: 8px;
    height: 8px;
}
::-webkit-scrollbar-track {
    background: transparent;
}
::-webkit-scrollbar-thumb {
    background: rgba(99, 102, 241, 0.2);
    border-radius: 4px;
}
::-webkit-scrollbar-thumb:hover {
    background: rgba(99, 102, 241, 0.4);
}

/* ==========================================================================
   3. Estrutura do Layout (Dashboard Grid)
   ========================================================================== */
.app-container {
    display: grid;
    grid-template-columns: 280px 1fr;
    min-height: 100vh;
    position: relative;
}

/* Mobile Sidebar Overlay */
.sidebar-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    backdrop-filter: blur(4px);
    z-index: 998;
}

/* ==========================================================================
   4. Elegant Sidebar Component (Glassmorphism)
   ========================================================================== */
.sidebar {
    background: var(--sidebar-bg);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border-right: 1px solid var(--sidebar-border);
    padding: 30px 20px;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    height: 100vh;
    position: sticky;
    top: 0;
    z-index: 999;
    transition: all var(--transition-normal);
}

.sidebar-header {
    display: flex;
    align-items: center;
    gap: 15px;
    padding-bottom: 25px;
    border-bottom: 1px solid var(--sidebar-border);
    margin-bottom: 30px;
}

.sidebar-logo {
    width: 48px;
    height: 48px;
    border-radius: 12px;
    object-fit: cover;
    border: 2px solid var(--primary);
    background: rgba(255, 255, 255, 0.05);
}

.sidebar-title {
    font-family: 'Outfit', sans-serif;
    font-weight: 700;
    font-size: 1.25rem;
    letter-spacing: -0.5px;
    background: linear-gradient(135deg, var(--text-primary), var(--primary-light));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.sidebar-menu {
    list-style: none;
    flex-grow: 1;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.sidebar-item a {
    display: flex;
    align-items: center;
    gap: 14px;
    padding: 12px 16px;
    border-radius: 12px;
    color: var(--text-secondary);
    text-decoration: none;
    font-weight: 500;
    font-size: 0.95rem;
    transition: all var(--transition-fast);
}

.sidebar-item a:hover {
    color: var(--text-primary);
    background: rgba(99, 102, 241, 0.08);
}

.sidebar-item.active a {
    color: white;
    background: linear-gradient(135deg, var(--primary), var(--primary-dark));
    box-shadow: 0 4px 15px var(--primary-glow);
}

.sidebar-footer {
    border-top: 1px solid var(--sidebar-border);
    padding-top: 20px;
    margin-top: 20px;
}

.user-profile-badge {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px;
    border-radius: 12px;
    background: rgba(255, 255, 255, 0.02);
    border: 1px solid rgba(255, 255, 255, 0.04);
}

.user-avatar {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--primary), var(--accent));
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    font-weight: 700;
    font-size: 0.9rem;
    text-transform: uppercase;
}

.user-info {
    overflow: hidden;
    white-space: nowrap;
    text-overflow: ellipsis;
    flex-grow: 1;
}

.user-name {
    font-weight: 600;
    font-size: 0.85rem;
    color: var(--text-primary);
}

.user-role {
    font-size: 0.75rem;
    color: var(--text-secondary);
    text-transform: uppercase;
    font-weight: 600;
    letter-spacing: 0.5px;
}

/* ==========================================================================
   5. Área de Conteúdo Principal e Top Bar
   ========================================================================== */
.main-content {
    display: flex;
    flex-direction: column;
    padding: 30px;
    height: 100vh;
    overflow-y: auto;
}

.topbar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 35px;
    padding-bottom: 15px;
    border-bottom: 1px solid var(--card-border);
}

.topbar-title {
    font-family: 'Outfit', sans-serif;
    font-weight: 700;
    font-size: 1.75rem;
}

.topbar-actions {
    display: flex;
    align-items: center;
    gap: 15px;
}

.theme-toggle-btn {
    background: var(--card-bg);
    border: 1px solid var(--card-border);
    color: var(--text-primary);
    width: 42px;
    height: 42px;
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all var(--transition-fast);
}

.theme-toggle-btn:hover {
    transform: translateY(-2px);
    border-color: var(--primary);
}

.hamburger-btn {
    display: none;
    background: transparent;
    border: none;
    color: var(--text-primary);
    font-size: 1.5rem;
    cursor: pointer;
}

/* ==========================================================================
   6. UI Components: Cards, Tables, Forms
   ========================================================================== */
.card {
    background: var(--card-bg);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    border: 1px solid var(--card-border);
    border-radius: var(--border-radius-lg);
    padding: 25px;
    box-shadow: var(--shadow);
    transition: transform var(--transition-normal), box-shadow var(--transition-normal);
}

.card:hover {
    box-shadow: 0 15px 35px var(--shadow-color);
}

/* Grid de Estatísticas */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: 20px;
    margin-bottom: 35px;
}

.stat-card {
    display: flex;
    align-items: center;
    gap: 20px;
}

.stat-icon {
    width: 56px;
    height: 56px;
    border-radius: var(--border-radius-md);
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
}

.stat-icon.primary { background: linear-gradient(135deg, var(--primary), var(--primary-light)); }
.stat-icon.accent { background: linear-gradient(135deg, var(--accent), #22d3ee); }
.stat-icon.success { background: linear-gradient(135deg, var(--success), #34d399); }
.stat-icon.warning { background: linear-gradient(135deg, var(--warning), #fbbf24); }

.stat-data {
    display: flex;
    flex-direction: column;
}

.stat-value {
    font-family: 'Outfit', sans-serif;
    font-size: 1.75rem;
    font-weight: 700;
    line-height: 1.2;
}

.stat-label {
    font-size: 0.85rem;
    color: var(--text-secondary);
    font-weight: 500;
}

/* Tabelas Premium */
.table-container {
    overflow-x: auto;
    width: 100%;
}

.data-table {
    width: 100%;
    border-collapse: collapse;
    text-align: left;
}

.data-table th {
    background: var(--table-header-bg);
    padding: 16px 20px;
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    border-bottom: 1px solid var(--card-border);
}

.data-table td {
    padding: 16px 20px;
    font-size: 0.95rem;
    border-bottom: 1px solid var(--card-border);
    color: var(--text-primary);
}

.data-table tr:last-child td {
    border-bottom: none;
}

.data-table tr:hover td {
    background: var(--table-row-hover);
}

/* Badges / Estados */
.badge {
    display: inline-flex;
    align-items: center;
    padding: 4px 10px;
    border-radius: 30px;
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
}

.badge.active { background: rgba(16, 185, 129, 0.12); color: var(--success); border: 1px solid rgba(16, 185, 129, 0.2); }
.badge.inactive { background: rgba(239, 68, 68, 0.12); color: var(--danger); border: 1px solid rgba(239, 68, 68, 0.2); }
.badge.role-admin { background: rgba(99, 102, 241, 0.12); color: var(--primary-light); border: 1px solid rgba(99, 102, 241, 0.2); }
.badge.role-direcao { background: rgba(6, 182, 212, 0.12); color: var(--accent); border: 1px solid rgba(6, 182, 212, 0.2); }
.badge.role-coordenacao { background: rgba(245, 158, 11, 0.12); color: var(--warning); border: 1px solid rgba(245, 158, 11, 0.2); }
.badge.role-utilizador { background: rgba(255, 255, 255, 0.05); color: var(--text-secondary); border: 1px solid rgba(255, 255, 255, 0.08); }

/* Form Elements */
.form-group {
    margin-bottom: 20px;
    text-align: left;
}

.form-label {
    display: block;
    margin-bottom: 8px;
    font-size: 0.88rem;
    font-weight: 550;
    color: var(--text-secondary);
}

.form-control {
    width: 100%;
    background: var(--input-bg);
    border: 1px solid var(--input-border);
    border-radius: var(--border-radius-md);
    padding: 12px 16px;
    color: var(--text-primary);
    font-family: inherit;
    font-size: 0.95rem;
    transition: all var(--transition-fast);
}

.form-control:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 4px var(--primary-glow);
}

/* Botões */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    font-family: inherit;
    font-weight: 600;
    font-size: 0.92rem;
    padding: 12px 20px;
    border-radius: var(--border-radius-md);
    border: none;
    cursor: pointer;
    transition: all var(--transition-fast);
    text-decoration: none;
}

.btn-primary {
    background: linear-gradient(135deg, var(--primary), var(--primary-dark));
    color: white;
    box-shadow: 0 4px 12px var(--primary-glow);
}
.btn-primary:hover {
    transform: translateY(-1.5px);
    box-shadow: 0 6px 18px rgba(99, 102, 241, 0.3);
}

.btn-secondary {
    background: rgba(255, 255, 255, 0.04);
    border: 1px solid var(--card-border);
    color: var(--text-primary);
}
.btn-secondary:hover {
    background: rgba(255, 255, 255, 0.08);
}

.btn-danger {
    background: linear-gradient(135deg, var(--danger), #be123c);
    color: white;
    box-shadow: 0 4px 12px var(--danger-glow);
}
.btn-danger:hover {
    transform: translateY(-1.5px);
    box-shadow: 0 6px 18px rgba(239, 68, 68, 0.3);
}

.btn-sm {
    padding: 8px 14px;
    font-size: 0.85rem;
    border-radius: var(--border-radius-sm);
}

/* ==========================================================================
   7. Painel do Módulo (Grid do Dashboard)
   ========================================================================== */
.modules-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
    gap: 25px;
    margin-bottom: 40px;
}

.module-card {
    position: relative;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    min-height: 200px;
}

.module-card::after {
    content: '';
    position: absolute;
    top: 0;
    right: 0;
    width: 120px;
    height: 120px;
    background: radial-gradient(circle, var(--primary-glow) 0%, transparent 70%);
    z-index: 1;
    pointer-events: none;
}

.module-header {
    z-index: 2;
}

.module-icon-wrap {
    width: 48px;
    height: 48px;
    border-radius: 12px;
    background: var(--primary-glow);
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--primary-light);
    margin-bottom: 16px;
}

.module-title {
    font-family: 'Outfit', sans-serif;
    font-size: 1.25rem;
    font-weight: 650;
    margin-bottom: 8px;
}

.module-desc {
    font-size: 0.85rem;
    color: var(--text-secondary);
    line-height: 1.4;
    margin-bottom: 20px;
}

/* ==========================================================================
   8. Sistema de Toast (Avisos Flutuantes)
   ========================================================================== */
.toast-container {
    position: fixed;
    bottom: 25px;
    right: 25px;
    display: flex;
    flex-direction: column;
    gap: 10px;
    z-index: 10000;
}

.toast {
    background: var(--card-bg);
    backdrop-filter: blur(25px);
    -webkit-backdrop-filter: blur(25px);
    border: 1px solid var(--card-border);
    border-radius: var(--border-radius-md);
    padding: 16px 20px;
    color: var(--text-primary);
    box-shadow: 0 10px 30px rgba(0,0,0,0.25);
    display: flex;
    align-items: center;
    gap: 12px;
    min-width: 300px;
    max-width: 450px;
    animation: slideIn 0.3s cubic-bezier(0.16, 1, 0.3, 1) forwards;
}

.toast.success { border-left: 4px solid var(--success); }
.toast.error { border-left: 4px solid var(--danger); }
.toast.info { border-left: 4px solid var(--primary); }

@keyframes slideIn {
    from {
        opacity: 0;
        transform: translateY(20px) scale(0.95);
    }
    to {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

/* ==========================================================================
   9. Media Queries (Responsividade)
   ========================================================================== */
@media (max-width: 1024px) {
    .app-container {
        grid-template-columns: 1fr;
    }
    
    .sidebar {
        position: fixed;
        left: -280px;
        top: 0;
        bottom: 0;
        width: 280px;
        height: 100vh;
        z-index: 999;
    }
    
    .sidebar.open {
        left: 0;
        box-shadow: 15px 0 40px rgba(0, 0, 0, 0.4);
    }
    
    .hamburger-btn {
        display: block;
    }
    
    .main-content {
        padding: 20px;
        padding-top: 80px; /* Espaço para o menu flutuante */
    }
    
    /* Topbar flutuante no Mobile */
    .topbar {
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        height: 70px;
        background: var(--sidebar-bg);
        backdrop-filter: blur(20px);
        -webkit-backdrop-filter: blur(20px);
        border-bottom: 1px solid var(--card-border);
        padding: 0 20px;
        margin-bottom: 0;
        z-index: 990;
        display: flex;
        align-items: center;
    }
    
    .topbar-title {
        font-size: 1.35rem;
    }
}

@media (max-width: 640px) {
    .stats-grid {
        grid-template-columns: 1fr;
    }
    .modules-grid {
        grid-template-columns: 1fr;
    }
    .card {
        padding: 20px;
    }
}

/* ==========================================================================
   Modais Glassmorphic Globais (Center Overlays)
   ========================================================================== */
.modal {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.65) !important;
    backdrop-filter: blur(10px) !important;
    -webkit-backdrop-filter: blur(10px) !important;
    align-items: center;
    justify-content: center;
    z-index: 9999;
    padding: 20px;
    opacity: 0;
    transition: opacity 0.25s ease;
}

.modal.active, .modal.show, [style*="display: flex"] {
    opacity: 1 !important;
}

.modal-card {
    background: var(--sidebar-bg) !important;
    border: 1px solid var(--card-border) !important;
    border-radius: var(--border-radius-lg) !important;
    width: 100%;
    max-width: 500px;
    box-shadow: 0 25px 60px rgba(0, 0, 0, 0.45) !important;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    animation: modalAppear 0.3s cubic-bezier(0.34, 1.56, 0.64, 1) forwards;
}

@keyframes modalAppear {
    from { transform: translateY(-30px); opacity: 0; }
    to { transform: translateY(0); opacity: 1; }
}

.modal-header {
    padding: 20px 25px;
    border-bottom: 1px solid var(--card-border);
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: rgba(255, 255, 255, 0.01);
}

.modal-title {
    font-family: 'Outfit', sans-serif;
    font-size: 1.3rem;
    font-weight: 700;
    color: var(--text-primary);
}

.modal-close-btn {
    background: transparent;
    border: none;
    color: var(--text-secondary);
    font-size: 1.6rem;
    cursor: pointer;
    line-height: 1;
    transition: color 0.2s ease, transform 0.2s ease;
}

.modal-close-btn:hover {
    color: var(--danger) !important;
    transform: scale(1.15);
}

.modal-body {
    padding: 25px;
    color: var(--text-primary);
}

.modal-footer {
    padding: 15px 25px 25px;
    border-top: 1px solid var(--card-border);
    display: flex;
    justify-content: flex-end;
    gap: 12px;
    background: rgba(255, 255, 255, 0.01);
}

/* ==========================================================================
   Botões de Ação Circulares Premium (X, +)
   ========================================================================== */
.action-circle-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 42px;
    height: 42px;
    border-radius: 50% !important;
    background: rgba(255, 255, 255, 0.03);
    border: 1px solid rgba(255, 255, 255, 0.08) !important;
    color: var(--text-secondary);
    cursor: pointer;
    transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1) !important;
    box-shadow: 0 4px 10px rgba(0, 0, 0, 0.15);
    text-decoration: none;
    outline: none;
}

.action-circle-btn svg {
    transition: transform 0.25s ease;
}

.action-circle-btn:hover {
    background: rgba(255, 255, 255, 0.08) !important;
    border-color: rgba(255, 255, 255, 0.2) !important;
    color: var(--text-primary) !important;
    box-shadow: 0 6px 15px rgba(0, 0, 0, 0.25);
    transform: translateY(-2px);
}

.action-circle-btn:hover svg {
    transform: scale(1.1);
}

.action-circle-btn:active {
    transform: translateY(0);
}

/* Variação Danger (X de fechar) */
.action-circle-btn[style*="color: var(--danger)"], 
.action-circle-btn.btn-close-danger {
    color: var(--danger) !important;
    background: rgba(239, 68, 68, 0.08) !important;
    border-color: rgba(239, 68, 68, 0.2) !important;
}

.action-circle-btn[style*="color: var(--danger)"]:hover,
.action-circle-btn.btn-close-danger:hover {
    background: rgba(239, 68, 68, 0.15) !important;
    border-color: rgba(239, 68, 68, 0.35) !important;
    box-shadow: 0 4px 15px rgba(239, 68, 68, 0.25) !important;
}

/* Variação Success (+ de adicionar) */
.action-circle-btn[style*="color: var(--success)"],
.action-circle-btn.btn-add-success {
    color: var(--success) !important;
    background: rgba(16, 185, 129, 0.08) !important;
    border-color: rgba(16, 185, 129, 0.2) !important;
}

.action-circle-btn[style*="color: var(--success)"]:hover,
.action-circle-btn.btn-add-success:hover {
    background: rgba(16, 185, 129, 0.15) !important;
    border-color: rgba(16, 185, 129, 0.35) !important;
    box-shadow: 0 4px 15px rgba(16, 185, 129, 0.25) !important;
}
