* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

:root {
    --primary: #3b82f6;
    --primary-dark: #2563eb;
    --primary-light: #60a5fa;
    --secondary: #64748b;
    --success: #10b981;
    --danger: #ef4444;
    --warning: #f59e0b;
    --dark: #0f172a;
    --dark-light: #1e293b;
    --light: #f1f5f9;
    --border: #e2e8f0;
    --sidebar-bg: #0f172a;
    --sidebar-hover: #1e293b;
    --sidebar-active: #3b82f6;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    background: var(--light);
    color: var(--dark);
    line-height: 1.6;
}

/* Layout com Sidebar */
.app-layout {
    display: flex;
    min-height: 100vh;
}

/* Sidebar */
.sidebar {
    width: 260px;
    background: var(--sidebar-bg);
    color: white;
    position: fixed;
    height: 100vh;
    overflow-y: auto;
    z-index: 1000;
    transition: width 0.3s ease-in-out;
}

.sidebar.collapsed {
    width: 70px;
}

.sidebar.collapsed .sidebar-logo-text,
.sidebar.collapsed .sidebar-section-title,
.sidebar.collapsed .sidebar-user-info {
    display: none;
}

.sidebar.collapsed .sidebar-link span:not(.sidebar-icon) {
    display: none;
}

.sidebar.collapsed .sidebar-header {
    padding: 24px 10px;
}

.sidebar.collapsed .sidebar-logo {
    justify-content: center;
}

.sidebar.collapsed .sidebar-link {
    justify-content: center;
    padding: 12px 10px;
}

.sidebar.collapsed .sidebar-section .sidebar-link {
    padding-left: 10px;
}

.sidebar-header {
    padding: 24px 20px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}

.sidebar-logo {
    font-size: 24px;
    font-weight: 700;
    color: white;
    text-decoration: none;
    display: flex;
    align-items: center;
    gap: 12px;
}

.sidebar-logo-icon {
    width: 36px;
    height: 36px;
    background: var(--primary);
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 20px;
}

.sidebar-nav {
    padding: 20px 0;
}

.sidebar-section {
    margin-bottom: 24px;
}

.sidebar-section-title {
    padding: 0 20px;
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: rgba(255, 255, 255, 0.5);
    margin-bottom: 8px;
    font-weight: 600;
}

.sidebar-link {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 20px;
    color: rgba(255, 255, 255, 0.8);
    text-decoration: none;
    transition: all 0.2s;
    font-size: 14px;
    font-weight: 500;
}

.sidebar-section .sidebar-link {
    padding-left: 40px;
    font-size: 13px;
}

.sidebar-section .sidebar-link .sidebar-icon {
    font-size: 14px;
}

.sidebar-link:hover {
    background: var(--sidebar-hover);
    color: #fff;
}

.sidebar-link.active {
    background: var(--primary);
    color: white;
}

.sidebar-icon {
    width: 20px;
    height: 20px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.sidebar-footer {
    padding: 20px;
    border-top: 1px solid rgba(255, 255, 255, 0.1);
    margin-top: auto;
}

.sidebar-user {
    display: flex;
    align-items: center;
    gap: 12px;
}

.sidebar-user-avatar {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: var(--primary);
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 600;
    font-size: 16px;
}

.sidebar-user-info {
    flex: 1;
}

.sidebar-user-name {
    font-size: 14px;
    font-weight: 600;
    color: white;
}

.sidebar-user-role {
    font-size: 12px;
    color: rgba(255, 255, 255, 0.6);
}

/* Botão Toggle Desktop */
.sidebar-toggle-desktop {
    width: 40px;
    height: 40px;
    background: var(--light);
    border: 1px solid var(--border);
    border-radius: 8px;
    color: var(--dark);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 18px;
    transition: all 0.2s;
    margin-right: 16px;
}

.sidebar-toggle-desktop:hover {
    background: var(--primary);
    color: white;
    border-color: var(--primary);
}

/* Main Content */
.main-content {
    flex: 1;
    margin-left: 260px;
    min-height: 100vh;
    background: var(--light);
    transition: margin-left 0.3s ease-in-out;
}

.main-content.expanded {
    margin-left: 70px;
}

.topbar {
    background: white;
    border-bottom: 1px solid var(--border);
    padding: 12px 24px;
    display: flex;
    align-items: center;
    gap: 16px;
    position: sticky;
    top: 0;
    z-index: 100;
}

.topbar-title {
    font-size: 20px;
    font-weight: 600;
    color: var(--dark);
}

.topbar-user {
    display: flex;
    align-items: center;
    gap: 12px;
}

.topbar-user-avatar {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background: var(--primary);
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 600;
    font-size: 14px;
    color: white;
}

.topbar-user-info {
    display: flex;
    flex-direction: column;
}

.topbar-user-name {
    font-size: 14px;
    font-weight: 600;
    color: var(--dark);
}

.topbar-user-role {
    font-size: 12px;
    color: var(--secondary);
}

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

.container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 20px;
}

.card {
    background: white;
    border-radius: 8px;
    box-shadow: 0 1px 3px rgba(0,0,0,0.1);
    padding: 20px;
    margin-bottom: 20px;
}

.btn {
    display: inline-block;
    padding: 10px 20px;
    border-radius: 6px;
    border: none;
    cursor: pointer;
    font-size: 14px;
    font-weight: 500;
    text-decoration: none;
    transition: all 0.2s;
}

.btn-primary {
    background: var(--primary);
    color: white;
}

.btn-primary:hover {
    background: var(--primary-dark);
}

.btn-danger {
    background: var(--danger);
    color: white;
}

.btn-secondary {
    background: var(--secondary);
    color: white;
}

.table {
    width: 100%;
    border-collapse: collapse;
}

.table th,
.table td {
    padding: 12px;
    text-align: left;
    border-bottom: 1px solid var(--border);
}

.table th {
    background: var(--light);
    font-weight: 600;
}

.badge {
    display: inline-block;
    padding: 4px 12px;
    border-radius: 12px;
    font-size: 12px;
    font-weight: 500;
}

.badge-success {
    background: #d1fae5;
    color: var(--success);
}

.badge-danger {
    background: #fee2e2;
    color: var(--danger);
}

.form-group {
    margin-bottom: 20px;
}

.form-label {
    display: block;
    margin-bottom: 8px;
    font-weight: 500;
    color: var(--dark);
}

.form-control {
    width: 100%;
    padding: 10px;
    border: 1px solid var(--border);
    border-radius: 6px;
    font-size: 14px;
}

.form-control:focus {
    outline: none;
    border-color: var(--primary);
}

.header {
    background: white;
    border-bottom: 1px solid var(--border);
    padding: 20px 0;
    margin-bottom: 30px;
}

.header h1 {
    font-size: 24px;
    color: var(--dark);
}

.nav {
    display: flex;
    gap: 20px;
    margin-top: 10px;
}

.nav a {
    color: var(--secondary);
    text-decoration: none;
    font-weight: 500;
}

.nav a:hover {
    color: var(--primary);
}

.alert {
    padding: 12px 16px;
    border-radius: 6px;
    margin-bottom: 20px;
}

.alert-success {
    background: #d1fae5;
    color: var(--success);
}

.alert-danger {
    background: #fee2e2;
    color: var(--danger);
}

/* ========================================
   RESPONSIVIDADE E MENU HAMBÚRGUER
   ======================================== */

/* Botão Hambúrguer */
.menu-toggle {
    display: none;
    position: fixed;
    top: 16px;
    left: 16px;
    z-index: 1100;
    background: var(--primary);
    border: none;
    border-radius: 8px;
    width: 44px;
    height: 44px;
    cursor: pointer;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 4px;
    transition: all 0.3s;
}

.menu-toggle span {
    display: block;
    width: 22px;
    height: 2px;
    background: white;
    border-radius: 2px;
    transition: all 0.3s;
}

.menu-toggle.active span:nth-child(1) {
    transform: rotate(45deg) translate(5px, 5px);
}

.menu-toggle.active span:nth-child(2) {
    opacity: 0;
}

.menu-toggle.active span:nth-child(3) {
    transform: rotate(-45deg) translate(5px, -5px);
}

/* Overlay para mobile */
.sidebar-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: 999;
    opacity: 0;
    transition: opacity 0.3s;
}

.sidebar-overlay.active {
    opacity: 1;
}

/* ========================================
   MEDIA QUERIES - TABLET (max-width: 1024px)
   ======================================== */
@media (max-width: 1024px) {
    .container {
        max-width: 100%;
        padding: 16px;
    }
    
    .topbar {
        padding: 16px 20px;
    }
    
    .topbar-title {
        font-size: 18px;
    }
    
    /* Ajustar grid de cards */
    [style*="grid-template-columns: repeat(3, 1fr)"] {
        grid-template-columns: repeat(2, 1fr) !important;
    }
}

/* ========================================
   MEDIA QUERIES - MOBILE (max-width: 768px)
   ======================================== */
@media (max-width: 768px) {
    /* Esconder botão toggle desktop em mobile */
    .sidebar-toggle-desktop {
        display: none !important;
    }
    
    /* Mostrar botão hambúrguer */
    .menu-toggle {
        display: flex;
    }
    
    /* Ajustar topbar para mobile */
    .topbar {
        padding: 12px 16px;
        padding-left: 70px !important;
        flex-wrap: wrap;
        gap: 12px;
    }
    
    /* Esconder informações do usuário em mobile (mostrar apenas avatar) */
    .topbar-user-info {
        display: none;
    }
    
    /* Botão sair mais compacto em mobile */
    .topbar a[href*="logout"] span:last-child {
        display: none;
    }
    
    /* Seletor de paróquia em linha separada */
    .topbar > div[style*="margin-right: auto"] {
        width: 100%;
        order: 10;
    }
    
    /* Sidebar mobile */
    .sidebar {
        transform: translateX(-100%);
        transition: transform 0.3s ease-in-out;
    }
    
    .sidebar.active {
        transform: translateX(0);
    }
    
    .sidebar-overlay {
        display: block;
    }
    
    /* Main content sem margem do sidebar */
    .main-content {
        margin-left: 0;
        width: 100%;
    }
    
    /* Topbar mobile */
    .topbar {
        padding: 16px;
        padding-left: 70px; /* Espaço para o botão hambúrguer */
        flex-wrap: wrap;
    }
    
    .topbar-title {
        font-size: 16px;
    }
    
    /* Seletor de paróquia em linha separada no mobile */
    .topbar > div[style*="margin-left: auto"] {
        width: 100%;
        margin-left: 0 !important;
        margin-top: 12px;
    }
    
    .topbar form {
        width: 100%;
    }
    
    .topbar form select {
        width: 100% !important;
    }
    
    /* Container */
    .container {
        padding: 16px;
    }
    
    /* Cards */
    .card {
        padding: 16px;
    }
    
    /* Grid de cards - 1 coluna no mobile */
    [style*="grid-template-columns"] {
        grid-template-columns: 1fr !important;
    }
    
    /* Tabelas responsivas */
    .table-responsive {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }
    
    .table {
        min-width: 600px;
    }
    
    .table th,
    .table td {
        padding: 8px;
        font-size: 13px;
    }
    
    /* Botões em mobile */
    .btn {
        padding: 8px 16px;
        font-size: 13px;
    }
    
    /* Formulários */
    .form-control {
        font-size: 16px; /* Evita zoom no iOS */
    }
    
    /* Ajustar flex containers */
    [style*="display: flex"] {
        flex-wrap: wrap;
    }
    
    /* Tabs */
    .tab-link {
        padding: 10px 12px;
        font-size: 13px;
    }
    
    /* Sidebar footer mobile */
    .sidebar-footer {
        padding: 16px;
    }
    
    .sidebar-user-name {
        font-size: 13px;
    }
    
    .sidebar-user-role {
        font-size: 11px;
    }
}

/* ========================================
   MEDIA QUERIES - MOBILE PEQUENO (max-width: 480px)
   ======================================== */
@media (max-width: 480px) {
    .topbar {
        padding: 12px;
        padding-left: 60px;
    }
    
    .topbar-title {
        font-size: 14px;
    }
    
    .container {
        padding: 12px;
    }
    
    .card {
        padding: 12px;
        margin-bottom: 12px;
    }
    
    /* Botões menores */
    .btn {
        padding: 6px 12px;
        font-size: 12px;
    }
    
    /* Tabelas ainda mais compactas */
    .table th,
    .table td {
        padding: 6px;
        font-size: 12px;
    }
    
    /* Tabs em scroll horizontal */
    [style*="display: flex; gap: 10px"] {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        flex-wrap: nowrap;
    }
    
    .tab-link {
        white-space: nowrap;
        padding: 8px 12px;
        font-size: 12px;
    }
    
    /* Ajustar cards de estatísticas */
    .card [style*="font-size: 32px"] {
        font-size: 24px !important;
    }
    
    .card [style*="font-size: 12px"] {
        font-size: 11px !important;
    }
}

/* ========================================
   UTILITÁRIOS RESPONSIVOS
   ======================================== */

/* Esconder em mobile */
.hide-mobile {
    display: block;
}

@media (max-width: 768px) {
    .hide-mobile {
        display: none !important;
    }
}

/* Mostrar apenas em mobile */
.show-mobile {
    display: none;
}

@media (max-width: 768px) {
    .show-mobile {
        display: block !important;
    }
}

/* Wrapper para tabelas responsivas */
.table-wrapper {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    margin: 0 -20px;
    padding: 0 20px;
}

@media (max-width: 768px) {
    .table-wrapper {
        margin: 0 -16px;
        padding: 0 16px;
    }
}
