:root {
    --sidebar-width: 250px;
    --sidebar-bg: #1a1d21;
    --sidebar-hover: rgba(255, 255, 255, 0.08);
    --sidebar-active: rgba(99, 132, 255, 0.15);
    --sidebar-active-border: #6384ff;
    --topbar-height: 60px;
}

html {
    font-size: 14px;
}

@media (min-width: 768px) {
    html { font-size: 15px; }
}

body {
    font-family: 'Segoe UI', -apple-system, BlinkMacSystemFont, 'Helvetica Neue', sans-serif;
    background-color: #f0f2f5;
    margin: 0;
}

/* ===== Sidebar ===== */
#sidebar {
    width: var(--sidebar-width);
    min-width: var(--sidebar-width);
    max-width: var(--sidebar-width);
    min-height: 100vh;
    background: var(--sidebar-bg);
    transition: all 0.3s ease;
    overflow-y: auto;
    position: sticky;
    top: 0;
    height: 100vh;
}

#sidebar.collapsed {
    margin-left: calc(-1 * var(--sidebar-width));
}

.sidebar-brand {
    padding: 1.25rem 1.25rem;
    color: #fff;
    font-size: 1.2rem;
    font-weight: 700;
    display: flex;
    align-items: center;
    gap: 0.75rem;
    border-bottom: 1px solid rgba(255,255,255,0.06);
}

.sidebar-brand i {
    font-size: 1.4rem;
    color: var(--sidebar-active-border);
}

.sidebar-nav {
    padding: 0.5rem 0.75rem;
}

.nav-section-label {
    color: rgba(255,255,255,0.35);
    font-size: 0.7rem;
    font-weight: 700;
    letter-spacing: 0.08em;
    padding: 1rem 0.75rem 0.4rem;
    text-transform: uppercase;
}

.sidebar-link {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.55rem 0.75rem;
    margin: 1px 0;
    border-radius: 0.5rem;
    color: rgba(255,255,255,0.65);
    text-decoration: none;
    font-size: 0.875rem;
    transition: all 0.15s ease;
    border-left: 3px solid transparent;
}

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

.sidebar-link.active {
    background: var(--sidebar-active);
    color: #fff;
    border-left-color: var(--sidebar-active-border);
    font-weight: 600;
}

.sidebar-link i {
    font-size: 1.1rem;
    width: 1.25rem;
    text-align: center;
}

/* ===== Top Bar ===== */
.topbar {
    height: var(--topbar-height);
    background: #fff;
    border-bottom: 1px solid #e5e7eb;
    padding: 0 1.5rem;
    display: flex;
    align-items: center;
    justify-content: space-between;
    position: sticky;
    top: 0;
    z-index: 100;
}

/* ===== Main Content ===== */
.main-content {
    padding: 1.5rem;
}

/* ===== Cards ===== */
.card {
    border-radius: 0.75rem;
    transition: box-shadow 0.2s ease;
}

.card:hover {
    box-shadow: 0 4px 12px rgba(0,0,0,0.08) !important;
}

.card-header {
    border-bottom: 1px solid #f0f0f0;
}

/* ===== Tables ===== */
.table th {
    font-weight: 600;
    font-size: 0.8rem;
    text-transform: uppercase;
    letter-spacing: 0.03em;
    color: #6c757d;
    border-bottom-width: 1px;
}

.table td {
    vertical-align: middle;
}

/* ===== Page header ===== */
.page-header {
    margin-bottom: 1.5rem;
}

.page-header h2 {
    font-weight: 700;
    font-size: 1.5rem;
}

/* ===== Login page ===== */
.login-container {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(135deg, #1a1d21 0%, #16213e 50%, #0f3460 100%);
}

.login-card {
    max-width: 420px;
    width: 100%;
    border-radius: 1rem;
}

/* ===== Pagination ===== */
.pagination .page-link {
    color: #6384ff;
    border-radius: 0.375rem;
}

.pagination .page-item.active .page-link {
    background-color: #6384ff;
    border-color: #6384ff;
}

/* ===== Badge styles ===== */
.badge {
    font-weight: 500;
    font-size: 0.75rem;
}

/* ===== Buttons ===== */
.btn {
    border-radius: 0.5rem;
}

/* ===== Alerts ===== */
.alert {
    border-radius: 0.75rem;
    border: none;
}

/* ===== Modal ===== */
.modal-content {
    border-radius: 0.75rem;
    border: none;
}

.modal-header {
    border-bottom: 1px solid #f0f0f0;
}

/* ===== Responsive ===== */

/* Mobile: sidebar is off-screen by default, slides in when .open */
@media (max-width: 991.98px) {
    #sidebar {
        position: fixed;
        z-index: 1050;
        margin-left: calc(-1 * var(--sidebar-width));
    }

    #sidebar.open {
        margin-left: 0;
    }

    /* Dark overlay behind sidebar */
    .sidebar-overlay {
        display: none;
        position: fixed;
        inset: 0;
        background: rgba(0,0,0,0.5);
        z-index: 1040;
    }

    .sidebar-overlay.active {
        display: block;
    }

    .main-content {
        padding: 1rem 0.75rem;
    }

    .topbar {
        padding: 0 1rem;
    }

    /* Stack KPI cards better */
    .page-header h2 {
        font-size: 1.25rem;
    }

    /* Make tables scroll smoothly */
    .table-responsive {
        -webkit-overflow-scrolling: touch;
    }

    /* Better touch targets */
    .btn-sm {
        padding: 0.4rem 0.75rem;
        font-size: 0.8rem;
    }

    .sidebar-link {
        padding: 0.7rem 0.75rem;
    }

    /* Forms on mobile */
    .form-select-sm, .form-control-sm {
        font-size: 0.875rem;
        padding: 0.4rem 0.6rem;
    }

    /* Hide less important table columns on small screens */
    .d-mobile-none {
        display: none !important;
    }
}

/* Desktop: sidebar uses collapsed class */
@media (min-width: 992px) {
    #sidebar.collapsed {
        margin-left: calc(-1 * var(--sidebar-width));
    }
}

/* Extra small devices */
@media (max-width: 575.98px) {
    .main-content {
        padding: 0.75rem 0.5rem;
    }

    h3.fw-bold { font-size: 1.5rem; }
    h4.fw-bold { font-size: 1.1rem; }

    .card-body { padding: 0.75rem; }

    /* Full width buttons on mobile */
    .btn-group-mobile {
        display: flex;
        flex-direction: column;
        gap: 0.5rem;
    }
    .btn-group-mobile .btn {
        width: 100%;
    }
}

/* ===== Tour / Walkthrough ===== */
.churchflow-popover .driver-popover-title {
    font-size: 1rem;
    font-weight: 700;
    color: #1a1d21;
}

.churchflow-popover .driver-popover-description {
    font-size: 0.875rem;
    color: #495057;
    line-height: 1.5;
}

.churchflow-popover .driver-popover-progress-text {
    font-size: 0.75rem;
    color: #6c757d;
}

#takeTourBtn {
    display: none;
}

/* ===== Page Loader ===== */
#pageLoader {
    position: fixed;
    inset: 0;
    z-index: 9999;
    background: rgba(255, 255, 255, 0.75);
    display: none;
    align-items: center;
    justify-content: center;
    backdrop-filter: blur(2px);
}

#pageLoader.active {
    display: flex;
}

.loader-logo-wrapper {
    position: relative;
    width: 72px;
    height: 72px;
}

.loader-spinner {
    position: absolute;
    inset: 0;
    border: 4px solid #e5e7eb;
    border-top-color: #6384ff;
    border-radius: 50%;
    animation: spin 0.9s linear infinite;
}

.loader-logo {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 40px;
    height: 40px;
    object-fit: contain;
    border-radius: 50%;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

/* Button loading state */
.btn-loading {
    pointer-events: none;
    opacity: 0.75;
}

.btn-loading .btn-text {
    visibility: hidden;
}

.btn-loading .btn-spinner {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
}

/* ===== Print styles ===== */
@media print {
    #sidebar, .topbar, footer, .no-print {
        display: none !important;
    }

    main {
        margin: 0 !important;
        padding: 0 !important;
    }
}
