:root {
    --bg-dark: #0f172a;
    --bg-sidebar: #1e293b;
    --bg-card: #ffffff;
    --bg-main: #f1f5f9;

    --text-main: #334155;
    --text-light: #94a3b8;
    --text-white: #ffffff;

    --primary: #6366f1;
    --primary-hover: #4f46e5;
    --accent: #8b5cf6;

    --success: #10b981;
    --warning: #f59e0b;
    --danger: #ef4444;

    --border: #e2e8f0;
}

body {
    margin: 0;
    font-family: 'Inter', sans-serif;
    background-color: var(--bg-main);
    color: var(--text-main);
    height: 100vh;
    overflow: hidden;
}

/* AUTH LOADER & LOGIN */
#auth-loader,
#login-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: var(--bg-dark);
    display: flex;
    /* Flex by default, toggled via JS */
    flex-direction: column;
    align-items: center;
    justify-content: center;
    color: white;
    z-index: 9999;
}

#login-overlay {
    display: none;
    /* Hidden by default */
    background: rgba(15, 23, 42, 0.95);
    backdrop-filter: blur(10px);
}

.login-card {
    background: var(--bg-sidebar);
    padding: 40px;
    border-radius: 20px;
    width: 100%;
    max-width: 400px;
    box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.5);
    border: 1px solid rgba(255, 255, 255, 0.1);
    text-align: center;
}

.login-title {
    font-size: 1.5rem;
    font-weight: 700;
    margin-bottom: 8px;
    color: white;
}

.login-subtitle {
    font-size: 0.9rem;
    color: var(--text-light);
    margin-bottom: 30px;
}

.form-group {
    margin-bottom: 20px;
    text-align: left;
}

.form-group label {
    display: block;
    font-size: 0.85rem;
    margin-bottom: 8px;
    color: var(--text-light);
}

.form-input {
    width: 100%;
    padding: 12px 16px;
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 8px;
    color: white;
    font-size: 1rem;
    outline: none;
    box-sizing: border-box;
    /* Fix padding issue */
    transition: all 0.2s;
}

.form-input:focus {
    border-color: var(--primary);
    background: rgba(255, 255, 255, 0.1);
}

#view-commercial .form-input,
#view-commercial textarea.form-input,
#view-commercial select.form-input {
    background: #ffffff;
    border: 1px solid #dbe3ef;
    color: #0f172a;
}

#view-commercial .form-input:focus,
#view-commercial textarea.form-input:focus,
#view-commercial select.form-input:focus {
    background: #ffffff;
    border-color: #93c5fd;
    box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.12);
}

#view-commercial .form-input::placeholder,
#view-commercial textarea.form-input::placeholder {
    color: #94a3b8;
}

.btn-full {
    width: 100%;
    padding: 14px;
    font-size: 1rem;
    margin-top: 10px;
}

.error-msg {
    color: var(--danger);
    font-size: 0.9rem;
    margin-top: 15px;
    min-height: 20px;
}

.spinner {
    width: 40px;
    height: 40px;
    border: 4px solid rgba(255, 255, 255, 0.3);
    border-radius: 50%;
    border-top-color: var(--primary);
    animation: spin 1s linear infinite;
    margin-bottom: 20px;
}


@keyframes spin {
    to {
        transform: rotate(360deg);
    }
}

/* LAYOUT */
.admin-container {
    display: flex;
    height: 100%;
}

/* SIDEBAR */
.sidebar {
    width: 260px;
    background: var(--bg-sidebar);
    color: var(--text-white);
    display: flex;
    flex-direction: column;
    transition: transform 0.3s ease;
}

.logo-area {
    padding: 24px;
    display: flex;
    align-items: center;
    gap: 12px;
    font-size: 1.25rem;
    font-weight: 700;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}

.badge-pro {
    font-size: 0.6rem;
    background: var(--accent);
    padding: 2px 6px;
    border-radius: 4px;
    margin-left: 8px;
    text-transform: uppercase;
}

.nav-menu {
    padding: 20px 10px;
    flex: 1;
}

.nav-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 16px;
    color: var(--text-light);
    text-decoration: none;
    border-radius: 8px;
    margin-bottom: 4px;
    transition: all 0.2s;
}

.nav-item:hover,
.nav-item.active {
    background: rgba(255, 255, 255, 0.1);
    color: var(--text-white);
}

.nav-divider {
    height: 1px;
    background: rgba(255, 255, 255, 0.1);
    margin: 10px 0;
}

/* MAIN CONTENT */
.main-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    position: relative;
}

.top-bar {
    background: white;
    padding: 16px 32px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 1px solid var(--border);
    flex-wrap: wrap;
    gap: 12px;
}

@media (max-width: 600px) {
    .top-bar {
        padding: 12px 16px;
    }

    .user-profile span {
        display: none;
    }
}

.menu-toggle {
    display: none;
    cursor: pointer;
    font-size: 1.5rem;
}

.user-profile {
    display: flex;
    align-items: center;
    gap: 12px;
}

.avatar {
    width: 36px;
    height: 36px;
    background: var(--primary);
    color: white;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 600;
}

#content-area {
    flex: 1;
    padding: 32px;
    overflow-y: auto;
}

@media (max-width: 600px) {
    #content-area {
        padding: 16px;
    }
}

.view-section {
    display: none;
}

.view-section.active {
    display: block;
    animation: fadeIn 0.3s;
}

@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(10px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* KPI CARDS */
.kpi-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
    gap: 24px;
    margin-bottom: 32px;
}

.kpi-card {
    background: white;
    border-radius: 12px;
    padding: 20px;
    display: flex;
    align-items: center;
    gap: 20px;
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
}

.kpi-icon {
    width: 50px;
    height: 50px;
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.5rem;
    color: white;
}

.bg-blue {
    background: #3b82f6;
}

.bg-green {
    background: #10b981;
}

.bg-purple {
    background: #8b5cf6;
}

.bg-orange {
    background: #f59e0b;
}

.kpi-info h3 {
    margin: 4px 0;
    font-size: 1.5rem;
    color: var(--text-main);
}

.kpi-info label {
    font-size: 0.85rem;
    color: var(--text-light);
}

.kpi-info .trend {
    font-size: 0.75rem;
    font-weight: 600;
}

.trend.up {
    color: var(--success);
}

/* CHARTS */
.charts-row {
    display: flex;
    gap: 24px;
    margin-bottom: 32px;
}

.chart-card {
    background: white;
    border-radius: 12px;
    padding: 24px;
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
}

.large {
    flex: 2;
}

.small {
    flex: 1;
}

.card-header {
    display: flex;
    justify-content: space-between;
    margin-bottom: 20px;
}

/* TABLES */
.table-container {
    background: white;
    border-radius: 12px;
    overflow-x: auto;
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
    -webkit-overflow-scrolling: touch;
}

.toolbar {
    display: flex;
    justify-content: space-between;
    margin-bottom: 16px;
}

.search-box {
    background: white;
    padding: 8px 16px;
    border: 1px solid var(--border);
    border-radius: 8px;
    display: flex;
    align-items: center;
    gap: 8px;
    width: 300px;
}

.search-box input {
    border: none;
    outline: none;
    width: 100%;
}

.data-table {
    width: 100%;
    border-collapse: collapse;
    min-width: 600px;
}

.data-table th,
.data-table td {
    padding: 16px;
    text-align: left;
    border-bottom: 1px solid var(--border);
}

.data-table th {
    background: #f8fafc;
    color: var(--text-light);
    font-weight: 600;
    font-size: 0.85rem;
}

.data-table tr:hover {
    background: #f8fafc;
}

/* MODAL */
.modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.5);
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 1000;
}

.modal-content {
    background: white;
    border-radius: 16px;
    padding: 0;
    /* Header handles padding */
    width: 90%;
    max-width: 500px;
    max-height: 90vh;
    overflow-y: auto;
    position: relative;
}

.large-modal {
    max-width: 800px;
}

.modal-header {
    background: var(--bg-sidebar);
    color: white;
    padding: 30px;
    display: flex;
    align-items: center;
    gap: 20px;
}

.user-avatar-large {
    width: 80px;
    height: 80px;
    background: var(--accent);
    color: white;
    border-radius: 50%;
    font-size: 2rem;
    display: flex;
    align-items: center;
    justify-content: center;
}

.close-modal {
    position: absolute;
    top: 16px;
    right: 24px;
    font-size: 2rem;
    color: white;
    cursor: pointer;
    opacity: 0.8;
}

.modal-tabs {
    display: flex;
    border-bottom: 1px solid var(--border);
    padding: 0 20px;
    margin-top: 10px;
}

.tab-btn {
    padding: 16px;
    background: none;
    border: none;
    border-bottom: 2px solid transparent;
    font-weight: 600;
    color: var(--text-light);
    cursor: pointer;
}

.tab-btn.active {
    color: var(--primary);
    border-bottom-color: var(--primary);
}

.modal-body-content {
    padding: 30px;
}

/* FINANCIAL CARDS IN MODAL */
.financial-summary-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 20px;
}

.fin-card {
    background: #f8fafc;
    padding: 20px;
    border-radius: 12px;
    border: 1px solid var(--border);
}

.fin-card.highlight {
    background: #f0fdf4;
    border-color: #bbf7d0;
}

.fin-card h3 {
    margin: 8px 0 0 0;
    font-size: 1.5rem;
}

.fin-card label {
    font-size: 0.85rem;
    color: var(--text-light);
}


/* BTNS */
.btn {
    padding: 8px 16px;
    border-radius: 6px;
    cursor: pointer;
    border: none;
    font-weight: 500;
}

.btn-primary {
    background: var(--primary);
    color: white;
}

.btn-outline {
    background: white;
    border: 1px solid var(--border);
    color: var(--text-main);
}

.btn-sm {
    padding: 4px 10px;
    font-size: 0.85rem;
}

/* MOBILE */
@media (max-width: 768px) {
    .sidebar {
        position: fixed;
        height: 100%;
        transform: translateX(-100%);
        z-index: 999;
    }

    .sidebar.open {
        transform: translateX(0);
    }

    .menu-toggle {
        display: block;
    }

    .charts-row {
        flex-direction: column;
    }

    .kpi-grid {
        grid-template-columns: 1fr;
    }

    .large-modal {
        width: 95%;
    }

    .financial-summary-grid {
        grid-template-columns: 1fr;
    }
}
