@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700&display=swap');

:root {
    /* Theme Variables - Dark (Default) */
    --bg-main: radial-gradient(circle at top left, #1a202c, #111827);
    --bg-sidebar: rgba(17, 24, 39, 0.8);
    --bg-card: rgba(31, 41, 55, 0.4);
    --bg-input: rgba(55, 65, 81, 0.4);
    --text-main: #f3f4f6;
    --text-muted: #9ca3af;
    --border: rgba(255, 255, 255, 0.08);
    --accent: #3b82f6;
    --accent-glow: rgba(59, 130, 246, 0.3);
    --sidebar-text: #9ca3af;
    --sidebar-active-bg: rgba(59, 130, 246, 0.2);
    --card-shadow: 0 8px 32px 0 rgba(0, 0, 0, 0.37);

    /* Table specific */
    --table-header-bg: #1f2937;
    --table-header-text: #f3f4f6;
    --table-row-hover: rgba(31, 41, 55, 0.4);
}

[data-theme="light"] {
    /* Theme Variables - Light (Igreja Refúgio da Graça Colors) */
    --bg-main: #f1f5f9;
    --bg-sidebar: #000000;
    --bg-card: #ffffff;
    --bg-input: #ffffff;
    --text-main: #0f172a;
    --text-muted: #475569;
    --border: #ccd3de;
    --accent: #ff7a00;
    --accent-glow: rgba(255, 122, 0, 0.1);
    --sidebar-text: #64748b;
    --sidebar-active-bg: rgba(255, 122, 0, 0.15);
    --card-shadow: 0 10px 15px -3px rgba(0, 0, 0, 0.1);

    /* Table specific */
    --table-header-bg: #e2e8f0;
    --table-header-text: #1e293b;
    --table-row-hover: #f8fafc;
}

body {
    font-family: 'Inter', sans-serif;
    background: var(--bg-main);
    color: var(--text-main);
    transition: background 0.3s, color 0.3s;
}

.glass-card {
    background: var(--bg-card);
    backdrop-filter: blur(16px) saturate(180%);
    border: 1px solid var(--border);
    border-radius: 1.25rem;
    box-shadow: var(--card-shadow);
}

.glass-sidebar {
    background: var(--bg-sidebar);
    backdrop-filter: blur(10px);
    border-right: 1px solid var(--border);
}

.input-field {
    width: 100%;
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: 0.5rem;
    padding: 0.75rem 1rem;
    color: var(--text-main);
    transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
}

button:active,
.nav-link:active,
.mobile-nav-item:active {
    transform: scale(0.95);
}

.input-field:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 2px var(--accent-glow);
}

.nav-link {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.75rem 1.25rem;
    border-radius: 0.5rem;
    color: #94a3b8;
    transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
}

.nav-link:hover {
    color: white !important;
    background: rgba(255, 255, 255, 0.05);
    transform: translateX(4px);
}

.nav-link.active {
    color: white !important;
    background: linear-gradient(to right, rgba(245, 158, 11, 0.15), transparent) !important;
    border-left: 4px solid #f59e0b !important;
    box-shadow: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
    border-radius: 0 0.5rem 0.5rem 0;
}

.nav-link.active i {
    color: white !important;
}

.stat-card {
    background: var(--bg-card);
    padding: 1.5rem;
    border-radius: 1.25rem;
    border: 1px solid var(--border);
    transition: all 0.4s cubic-bezier(0.4, 0, 0.2, 1);
    position: relative;
    overflow: hidden;
}

[data-theme="dark"] .stat-card {
    background: linear-gradient(135deg, rgba(31, 41, 55, 0.6) 0%, rgba(17, 24, 39, 0.6) 100%);
}

.stat-card:hover {
    transform: translateY(-3px);
    border-color: var(--accent);
    box-shadow: 0 5px 15px -5px rgba(0, 0, 0, 0.1);
}

.modal {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.7);
    backdrop-filter: blur(4px);
    z-index: 100;
    display: flex;
    align-items: center;
    justify-content: center;
}

.page-section {
    animation: slideUp 0.4s ease-out;
}

@keyframes slideUp {
    from {
        opacity: 0;
        transform: translateY(10px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.animate-fade-in {
    animation: fade-in 0.2s ease-out;
}

@keyframes slide-up {
    from {
        transform: translateY(100%);
    }

    to {
        transform: translateY(0);
    }
}

.animate-slide-up {
    animation: slide-up 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

/* Custom scrollbar */
::-webkit-scrollbar {
    width: 6px;
}

::-webkit-scrollbar-track {
    background: transparent;
}

::-webkit-scrollbar-thumb {
    background: var(--border);
    border-radius: 3px;
}

/* Light theme specific overrides */
[data-theme="light"] .glass-sidebar .nav-link:hover {
    background: rgba(255, 255, 255, 0.1);
}

.page-title {
    font-size: 1.875rem;
    font-weight: 700;
    background: linear-gradient(to right, var(--text-main), var(--text-muted));
    -webkit-background-clip: text;
    background-clip: text;
    color: transparent;
}

/* Base tailwind override for readability in light mode */
[data-theme="light"] .text-gray-400,
[data-theme="light"] .text-gray-500 {
    color: var(--text-muted) !important;
}

[data-theme="light"] .bg-gray-800 {
    background-color: var(--table-header-bg) !important;
}

[data-theme="light"] .border-gray-800,
[data-theme="light"] .border-white\/5 {
    border-color: var(--border) !important;
}

[data-theme="light"] .bg-gray-800\/30 {
    background-color: rgba(0, 0, 0, 0.03) !important;
}

[data-theme="light"] .stat-card h3:not(.text-emerald-400):not(.text-rose-400):not(.text-blue-400):not(.text-emerald-500):not(.text-rose-500):not(.text-blue-500) {
    color: var(--text-main) !important;
}

/* --- Premium Eclesiastic Login Styles --- */
@keyframes premium-slide-up {
    0% {
        opacity: 0;
        transform: translateY(40px);
    }

    100% {
        opacity: 1;
        transform: translateY(0);
    }
}

@keyframes logo-fade-in {
    0% {
        opacity: 0;
        transform: scale(0.9);
    }

    100% {
        opacity: 1;
        transform: scale(1);
    }
}

@keyframes staggered-fade-in {
    0% {
        opacity: 0;
        transform: translateX(-10px);
    }

    100% {
        opacity: 1;
        transform: translateX(0);
    }
}

@keyframes particles-drift {

    0%,
    100% {
        transform: translate(0, 0);
    }

    50% {
        transform: translate(100px, 100px);
    }
}

.animate-premium-in {
    animation: premium-slide-up 0.8s cubic-bezier(0.2, 1, 0.3, 1) forwards;
}

.animate-logo-in {
    opacity: 0;
    animation: logo-fade-in 1s cubic-bezier(0.2, 1, 0.3, 1) 0.2s forwards;
}

.stagger-1 {
    animation: staggered-fade-in 0.6s ease-out 0.4s forwards;
    opacity: 0;
}

.stagger-2 {
    animation: staggered-fade-in 0.6s ease-out 0.5s forwards;
    opacity: 0;
}

.stagger-3 {
    animation: staggered-fade-in 0.6s ease-out 0.6s forwards;
    opacity: 0;
}

.stagger-4 {
    animation: staggered-fade-in 0.6s ease-out 0.7s forwards;
    opacity: 0;
}

.bg-particles {
    position: absolute;
    inset: 0;
    background-image: radial-gradient(circle, rgba(255, 255, 255, 0.05) 1px, transparent 1px);
    background-size: 50px 50px;
    opacity: 0.5;
    animation: particles-drift 120s linear infinite;
}

.gold-radial {
    background: radial-gradient(circle at 80% 50%, rgba(212, 175, 55, 0.12) 0%, transparent 60%);
}

/* --- Sidebar Collapsible Styles --- */
aside {
    transition: width 0.3s cubic-bezier(0.4, 0, 0.2, 1) !important;
    overflow-x: hidden;
}

.sidebar-collapsed {
    width: 80px !important;
}

.sidebar-collapsed .sidebar-text,
.sidebar-collapsed .sidebar-subtitle,
.sidebar-collapsed .user-info-text,
.sidebar-collapsed .logout-text {
    opacity: 0;
    width: 0;
    visibility: hidden;
    position: absolute;
    white-space: nowrap;
}

.sidebar-collapsed .sidebar-header {
    padding-left: 0;
    padding-right: 0;
    justify-content: center;
}

.sidebar-collapsed .nav-link {
    justify-content: center;
    padding-left: 0;
    padding-right: 0;
    margin-left: 0.5rem;
    margin-right: 0.5rem;
}

.sidebar-collapsed .sidebar-footer {
    padding-left: 0;
    padding-right: 0;
    justify-content: center;
}

.sidebar-collapsed .sidebar-footer .flex {
    flex-direction: column;
    gap: 0.5rem;
}

.sidebar-collapsed .sidebar-footer button {
    padding-left: 0;
    padding-right: 0;
}

/* --- Tooltips for Collapsed Sidebar --- */
.sidebar-collapsed .nav-link {
    position: relative;
}

.sidebar-collapsed .nav-link::after {
    content: attr(data-tooltip);
    position: absolute;
    left: 100%;
    margin-left: 0.75rem;
    background: #1e293b;
    color: white;
    font-size: 0.75rem;
    padding: 0.4rem 0.75rem;
    border-radius: 0.375rem;
    box-shadow: 0 10px 15px -3px rgba(0, 0, 0, 0.5);
    opacity: 0;
    visibility: hidden;
    transition: all 0.2s ease-in-out;
    white-space: nowrap;
    pointer-events: none;
    z-index: 50;
    border: 1px solid rgba(255, 255, 255, 0.1);
}

.sidebar-collapsed .nav-link:hover::after {
    opacity: 1;
    visibility: visible;
    transform: translateX(5px);
}

/* Rotate toggle icon when collapsed */
.sidebar-collapsed #sidebar-toggle-icon {
    transform: rotate(180deg);
}

#sidebar-toggle-icon {
    transition: transform 0.3s ease;
}

/* --- Mobile Optimization --- */
@media (max-width: 768px) {

    /* Transformar Tabelas em Cards */
    #incomes-table-body,
    #expenses-table-body,
    #members-table-body {
        display: block;
        width: 100%;
    }

    table {
        display: block;
        width: 100%;
    }

    thead {
        display: none;
        /* Esconde cabeçalho da tabela no mobile */
    }

    tr {
        display: block;
        margin-bottom: 0.6rem;
        background: var(--bg-card) !important;
        border: 1px solid var(--border);
        border-radius: 0.75rem;
        padding: 0.5rem 0.75rem;
    }

    td {
        display: flex;
        justify-content: space-between;
        align-items: center;
        padding: 0.25rem 0 !important;
        border: none !important;
        font-size: 0.8rem;
    }

    td:before {
        content: attr(data-label);
        font-weight: 600;
        color: var(--text-muted);
        font-size: 0.65rem;
        text-transform: uppercase;
    }

    /* Botões de Ação no Mobile */
    td.admin-only {
        border-top: 1px solid var(--border) !important;
        margin-top: 0.4rem;
        padding-top: 0.5rem !important;
        justify-content: flex-end !important;
        gap: 0.75rem;
    }

    /* Otimização de Layout Geral */
    main {
        padding: 0.75rem !important;
        padding-bottom: 5.5rem !important;
        /* Espaço para o menu inferior */
    }

    /* Dashboard Cards 4-in-a-row */
    .stat-grid-mobile {
        display: flex !important;
        flex-direction: row !important;
        gap: 0.5rem !important;
        overflow-x: hidden;
        flex-wrap: nowrap;
    }

    .stat-card {
        padding: 0.6rem !important;
        flex: 1;
        min-width: 0;
        display: flex;
        flex-direction: column;
        align-items: center;
        text-align: center;
    }

    .stat-card .p-3 {
        padding: 0.4rem !important;
        margin-bottom: 0.25rem !important;
    }

    .stat-card i {
        font-size: 0.9rem !important;
    }

    .stat-card p {
        font-size: 0.6rem !important;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
        width: 100%;
    }

    .stat-card h3 {
        font-size: 0.75rem !important;
        margin-top: 0.1rem !important;
    }

    /* Reduzir filtros mobile */
    .input-field {
        padding: 0.5rem 0.75rem !important;
        font-size: 0.8rem !important;
    }

    .filter-bar-mobile {
        padding: 0.75rem !important;
        gap: 0.5rem !important;
    }

    .filter-bar-mobile select,
    .filter-bar-mobile input,
    .filter-bar-mobile button {
        height: 2.25rem !important;
        font-size: 0.75rem !important;
    }

    #sidebar {
        display: none !important;
    }

    /* Botão flutuante mobile */
    .btn-fab {
        position: fixed;
        bottom: 5.5rem;
        right: 1.5rem;
        width: 3.5rem;
        height: 3.5rem;
        border-radius: 50%;
        background: var(--accent);
        color: white;
        display: flex;
        align-items: center;
        justify-content: center;
        box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
        z-index: 90;
        border: none;
    }
}

/* Mobile Bottom Navigation */
.mobile-nav {
    display: none;
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    height: 4.5rem;
    background: rgba(15, 23, 42, 0.95);
    backdrop-filter: blur(12px);
    border-top: 1px solid var(--border);
    z-index: 1000;
    padding: 0 1rem;
    justify-content: space-around;
    align-items: center;
}

@media (max-width: 768px) {
    .mobile-nav {
        display: flex;
    }
}

.mobile-nav-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.25rem;
    color: var(--text-muted);
    font-size: 0.6rem;
    text-decoration: none;
    transition: all 0.2s;
}

.mobile-nav-item.active {
    color: var(--accent);
}

.mobile-nav-item i {
    font-size: 1.25rem;
}