: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;
    color: #fff;
}

/* ===== 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;
    }
}

/* ===== Member name display ===== */
.member-name { text-transform: uppercase; }

/* ===== Member Detail Page ===== */
.detail-label {
    font-size: 0.68rem;
    font-weight: 700;
    letter-spacing: 0.07em;
    color: #9ca3af;
    text-transform: uppercase;
    margin-bottom: 3px;
}
.detail-value {
    font-size: 0.9rem;
    color: #1a1d21;
    font-weight: 500;
}
.detail-section-title {
    font-size: 0.875rem;
    font-weight: 700;
    color: #1a1d21;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    margin-bottom: 1rem;
    padding-bottom: 0.5rem;
    border-bottom: 1px solid #f3f4f6;
}
.member-hero-avatar {
    width: 72px;
    height: 72px;
    border-radius: 50%;
    object-fit: cover;
    border: 3px solid #e5e7eb;
    flex-shrink: 0;
}
.member-hero-avatar-placeholder {
    width: 72px;
    height: 72px;
    border-radius: 50%;
    border: 3px solid #e5e7eb;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 1.4rem;
    font-weight: 700;
    flex-shrink: 0;
}
.activity-icon-wrap {
    width: 38px;
    height: 38px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}
.biometric-card {
    background: #0a2744;
    color: #fff;
    border-radius: 0.75rem;
}
.biometric-card .detail-label { color: rgba(255,255,255,0.5); }
.group-dot {
    width: 8px; height: 8px; border-radius: 50%;
    flex-shrink: 0; display: inline-block;
}

/* ===== CF Green Theme ===== */
:root {
    --cf-primary: #0d6efd;
    --cf-primary-hover: #0a58ca;
    --cf-primary-light: #dcfce7;
    --cf-primary-text: #15803d;
}

.btn-primary {
    background-color: var(--cf-primary);
    border-color: var(--cf-primary);
}
.btn-primary:hover, .btn-primary:focus, .btn-primary:active {
    background-color: var(--cf-primary-hover) !important;
    border-color: var(--cf-primary-hover) !important;
}
.btn-outline-primary {
    color: var(--cf-primary);
    border-color: var(--cf-primary);
}
.btn-outline-primary:hover {
    background-color: var(--cf-primary);
    border-color: var(--cf-primary);
}
.pagination .page-link { color: var(--cf-primary); }
.pagination .page-item.active .page-link {
    background-color: var(--cf-primary);
    border-color: var(--cf-primary);
    color: #fff;
    border-radius: 50%;
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0;
}

/* ===== CF Avatars (initials circles) ===== */
.cf-avatar {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 0.68rem;
    font-weight: 700;
    flex-shrink: 0;
    letter-spacing: 0.02em;
    user-select: none;
}
.cf-avatar-0 { background: #dbeafe; color: #1d4ed8; }
.cf-avatar-1 { background: #ede9fe; color: #6d28d9; }
.cf-avatar-2 { background: #fef3c7; color: #b45309; }
.cf-avatar-3 { background: #d1fae5; color: #065f46; }
.cf-avatar-4 { background: #ffe4e6; color: #be123c; }
.cf-avatar-5 { background: #f0fdfa; color: #0f766e; }
.cf-avatar-6 { background: #fce7f3; color: #9d174d; }
.cf-avatar-7 { background: #ecfdf5; color: #064e3b; }

/* ===== CF Status Pills ===== */
.cf-pill {
    display: inline-flex;
    align-items: center;
    gap: 0.3rem;
    padding: 0.22rem 0.65rem;
    border-radius: 100px;
    font-size: 0.72rem;
    font-weight: 600;
    line-height: 1.4;
}
.cf-pill::before {
    content: '';
    width: 6px;
    height: 6px;
    border-radius: 50%;
    flex-shrink: 0;
}
.cf-pill-active  { background: #dcfce7; color: #15803d; }
.cf-pill-active::before  { background: #16a34a; }
.cf-pill-inactive { background: #f1f5f9; color: #64748b; }
.cf-pill-inactive::before { background: #94a3b8; }
.cf-pill-danger  { background: #ffe4e6; color: #be123c; }
.cf-pill-danger::before  { background: #e11d48; }

/* ===== Topbar global search ===== */
.topbar-search {
    flex: 1;
    max-width: 400px;
    margin: 0 1.25rem;
}
.topbar-search-wrap {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    background: #f8f9fa;
    border: 1px solid #e5e7eb;
    border-radius: 0.5rem;
    padding: 0.38rem 0.75rem;
    transition: border-color 0.15s, background 0.15s;
    cursor: text;
}
.topbar-search-wrap:focus-within {
    border-color: var(--cf-primary);
    background: #fff;
}
.topbar-search-wrap .bi-search {
    color: #9ca3af;
    font-size: 0.875rem;
    flex-shrink: 0;
}
.topbar-search-wrap input {
    border: none;
    background: transparent;
    outline: none;
    font-size: 0.875rem;
    color: #374151;
    flex: 1;
    min-width: 0;
    padding: 0;
}
.topbar-search-wrap input::placeholder { color: #9ca3af; }
.topbar-search-kbd {
    background: #fff;
    border: 1px solid #d1d5db;
    border-radius: 4px;
    font-size: 0.65rem;
    padding: 1px 6px;
    color: #9ca3af;
    white-space: nowrap;
    flex-shrink: 0;
}

/* ===== Topbar user dropdown ===== */
.topbar-user-btn {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.3rem 0.5rem;
    border-radius: 0.5rem;
    border: none;
    background: transparent;
    cursor: pointer;
    transition: background 0.15s;
}
.topbar-user-btn:hover { background: #f8f9fa; }
.topbar-user-btn.dropdown-toggle::after { display: none; }
.topbar-user-avatar {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background: var(--cf-primary);
    color: #fff;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 0.68rem;
    font-weight: 700;
    flex-shrink: 0;
}
.topbar-user-info { line-height: 1.2; text-align: left; }
.topbar-user-name  { font-size: 0.8rem; font-weight: 600; color: #1a1d21; display: block; }
.topbar-user-email { font-size: 0.68rem; color: #9ca3af; display: block; }

/* ===== Icon-only table action buttons ===== */
.btn-icon {
    background: transparent;
    border: none;
    padding: 0.3rem 0.4rem;
    border-radius: 0.375rem;
    color: #6c757d;
    line-height: 1;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    transition: background 0.15s, color 0.15s;
    font-size: 0.9rem;
    text-decoration: none;
}
.btn-icon:hover { background: #f1f5f9; color: #1a1d21; }
.btn-icon[data-bs-toggle="dropdown"]::after { display: none; }

.btn-icon-circle {
    width: 30px;
    height: 30px;
    border-radius: 50%;
    background: #f1f3f5;
    border: none;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    color: #6c757d;
    transition: background 0.15s, color 0.15s;
    font-size: 0.9rem;
    cursor: pointer;
}
.btn-icon-circle:hover { background: #e2e6ea; color: #1a1d21; }
.btn-icon-circle[data-bs-toggle="dropdown"]::after { display: none; }
