/* ═══════════════════════════════════════════════════════════════════════════
   Ecclesia Platform — Mobile-First Responsive CSS
   ═══════════════════════════════════════════════════════════════════════ */
:root {
    --sidebar-w: 260px;
    --sidebar-bg: #1a1e2e;
    --sidebar-active: #2d3352;
    --sidebar-hover: #252a3e;
    --primary: #4f46e5;
    --primary-light: #818cf8;
    --success: #10b981;
    --warning: #f59e0b;
    --danger: #ef4444;
    --info: #06b6d4;
    --surface: #f8f9fc;
    --card-bg: #ffffff;
    --text: #1e293b;
    --text-muted: #64748b;
    --border: #e2e8f0;
    --topbar-h: 56px;
    --radius: 10px;
}

*, *::before, *::after { box-sizing: border-box; }
body {
    margin: 0;
    font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
    background: var(--surface);
    color: var(--text);
    overflow-x: hidden;
}

/* ── SCROLLBAR ─────────────────────────────────────────────────────────── */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: #c1c7d0; border-radius: 3px; }

/* ═══════════════════════════════════════════════════════════════════════════
   MOBILE TOP BAR
   ═══════════════════════════════════════════════════════════════════════ */
.mobile-topbar {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    height: var(--topbar-h);
    background: var(--sidebar-bg);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 12px;
    z-index: 1050;
}
.topbar-brand {
    color: #fff;
    font-weight: 700;
    font-size: 1.1rem;
}
.topbar-right {
    display: flex;
    align-items: center;
    gap: 8px;
}

/* ═══════════════════════════════════════════════════════════════════════════
   SIDEBAR
   ═══════════════════════════════════════════════════════════════════════ */
.sidebar {
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    width: var(--sidebar-w);
    background: var(--sidebar-bg);
    color: #cbd5e1;
    display: flex;
    flex-direction: column;
    z-index: 1060;
    transition: transform 0.3s ease;
    overflow-y: auto;
}

.sidebar-header {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 16px 18px;
    border-bottom: 1px solid rgba(255,255,255,.08);
}
.sidebar-logo { font-size: 1.5rem; color: var(--primary-light); }
.sidebar-title { margin: 0; font-size: 1.1rem; color: #fff; font-weight: 700; }

.sidebar-context {
    padding: 10px 14px;
    border-bottom: 1px solid rgba(255,255,255,.08);
}
.sidebar-context .form-select {
    background-color: var(--sidebar-active);
    color: #e2e8f0;
    border: 1px solid rgba(255,255,255,.12);
    font-size: 0.8rem;
}

.sidebar-nav {
    flex: 1;
    padding: 8px 0;
    overflow-y: auto;
}
.sidebar-nav .nav-link {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 18px;
    color: #94a3b8;
    text-decoration: none;
    font-size: 0.9rem;
    transition: all 0.15s;
    border-left: 3px solid transparent;
}
.sidebar-nav .nav-link:hover {
    background: var(--sidebar-hover);
    color: #e2e8f0;
}
.sidebar-nav .nav-link.active {
    background: var(--sidebar-active);
    color: #fff;
    border-left-color: var(--primary-light);
}
.sidebar-nav .nav-link i { width: 20px; text-align: center; font-size: 0.95rem; }

.sidebar-footer {
    padding: 12px 14px;
    border-top: 1px solid rgba(255,255,255,.08);
}

/* ── SIDEBAR OVERLAY (mobile) ──────────────────────────────────────────── */
.sidebar-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,.5);
    z-index: 1055;
}
.sidebar-overlay.show { display: block; }

/* ── MOBILE: sidebar hidden off-screen ─────────────────────────────────── */
@media (max-width: 991.98px) {
    .sidebar { transform: translateX(-100%); }
    .sidebar.open { transform: translateX(0); }
    .main-content {
        margin-left: 0 !important;
        padding-top: calc(var(--topbar-h) + 12px) !important;
    }
}

/* ═══════════════════════════════════════════════════════════════════════════
   MAIN CONTENT
   ═══════════════════════════════════════════════════════════════════════ */
.main-content {
    margin-left: var(--sidebar-w);
    padding: 24px;
    min-height: 100vh;
    transition: margin-left 0.3s ease;
}

.content-section { display: none; }
.content-section.active { display: block; }

.section-header {
    display: flex;
    flex-wrap: wrap;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
    gap: 10px;
}
.section-header h4 {
    margin: 0;
    font-weight: 700;
    font-size: 1.35rem;
    color: var(--text);
}
.header-actions {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
}

/* ═══════════════════════════════════════════════════════════════════════════
   KPI CARDS
   ═══════════════════════════════════════════════════════════════════════ */
.kpi-card {
    background: var(--card-bg);
    border-radius: var(--radius);
    padding: 18px 16px;
    text-align: center;
    box-shadow: 0 1px 3px rgba(0,0,0,.06);
    border: 1px solid var(--border);
    transition: transform 0.15s, box-shadow 0.15s;
}
.kpi-card:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(0,0,0,.1);
}
.kpi-icon {
    font-size: 1.6rem;
    margin-bottom: 6px;
    opacity: .7;
}
.kpi-value {
    font-size: 1.6rem;
    font-weight: 800;
    line-height: 1.1;
}
.kpi-label {
    font-size: 0.78rem;
    color: var(--text-muted);
    margin-top: 4px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}
.kpi-members .kpi-icon { color: var(--primary); }
.kpi-branches .kpi-icon { color: var(--success); }
.kpi-attendance .kpi-icon { color: var(--info); }
.kpi-income .kpi-icon, .kpi-income .kpi-value { color: var(--success); }
.kpi-expense .kpi-icon, .kpi-expense .kpi-value { color: var(--danger); }

/* ═══════════════════════════════════════════════════════════════════════════
   CARDS
   ═══════════════════════════════════════════════════════════════════════ */
.card {
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: 0 1px 3px rgba(0,0,0,.04);
    background: var(--card-bg);
}
.card-header {
    background: #f1f5f9;
    font-weight: 600;
    font-size: 0.9rem;
    padding: 12px 16px;
    border-bottom: 1px solid var(--border);
}

/* ═══════════════════════════════════════════════════════════════════════════
   TABLES
   ═══════════════════════════════════════════════════════════════════════ */
.table {
    font-size: 0.88rem;
}
.table thead th {
    background: #f8fafc;
    font-weight: 600;
    font-size: 0.8rem;
    text-transform: uppercase;
    letter-spacing: 0.3px;
    color: var(--text-muted);
    border-bottom: 2px solid var(--border);
    white-space: nowrap;
}
.table tbody tr:hover { background: #f1f5f9; }
.table .btn-action {
    padding: 2px 8px;
    font-size: 0.78rem;
}

/* ═══════════════════════════════════════════════════════════════════════════
   BRANCH / EVENT / DEPARTMENT GRID CARDS
   ═══════════════════════════════════════════════════════════════════════ */
.grid-card {
    background: var(--card-bg);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 16px;
    cursor: pointer;
    transition: transform 0.15s, box-shadow 0.15s;
}
.grid-card:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(0,0,0,.08);
}
.grid-card .card-title {
    font-weight: 700;
    font-size: 1rem;
    margin-bottom: 6px;
}
.grid-card .card-subtitle {
    font-size: 0.82rem;
    color: var(--text-muted);
    margin-bottom: 8px;
}
.grid-card .card-stats {
    display: flex;
    gap: 16px;
    font-size: 0.82rem;
}
.grid-card .card-stats span { display: flex; align-items: center; gap: 4px; }

/* Status badges */
.badge-active   { background: #d1fae5; color: #065f46; }
.badge-inactive { background: #fee2e2; color: #991b1b; }
.badge-planted  { background: #dbeafe; color: #1e40af; }
.badge-merged   { background: #fef3c7; color: #92400e; }
.badge-closed   { background: #f3f4f6; color: #374151; }
.badge-open     { background: #dbeafe; color: #1e40af; }
.badge-resolved { background: #d1fae5; color: #065f46; }
.badge-escalated{ background: #fef3c7; color: #92400e; }
.badge-pending  { background: #fef3c7; color: #92400e; }
.badge-submitted{ background: #dbeafe; color: #1e40af; }
.badge-received { background: #d1fae5; color: #065f46; }
.badge-reconciled{background: #d1fae5; color: #065f46; }
.badge-queried  { background: #fee2e2; color: #991b1b; }

/* ═══════════════════════════════════════════════════════════════════════════
   SUB-TABS (finance, staff, reports, settings)
   ═══════════════════════════════════════════════════════════════════════ */
.nav-tabs .nav-link {
    cursor: pointer;
    font-size: 0.88rem;
    font-weight: 500;
    color: var(--text-muted);
}
.nav-tabs .nav-link.active {
    color: var(--primary);
    font-weight: 600;
}

/* Panels toggled by sub-tabs */
.fin-panel, .staff-panel, .rpt-panel, .set-panel { /* managed via d-none */ }

/* ═══════════════════════════════════════════════════════════════════════════
   FORMS / MODALS
   ═══════════════════════════════════════════════════════════════════════ */
.form-label {
    font-size: 0.84rem;
    font-weight: 600;
    color: var(--text-muted);
}
.form-control, .form-select {
    border-radius: 8px;
    border: 1px solid var(--border);
    font-size: 0.9rem;
}
.form-control:focus, .form-select:focus {
    border-color: var(--primary-light);
    box-shadow: 0 0 0 3px rgba(79,70,229,.12);
}

.modal-content { border-radius: var(--radius); }
.modal-header {
    background: #f8fafc;
    border-bottom: 1px solid var(--border);
}

/* ═══════════════════════════════════════════════════════════════════════════
   TOAST
   ═══════════════════════════════════════════════════════════════════════ */
.toast-container .toast {
    border-radius: 8px;
    font-size: 0.88rem;
}

/* ═══════════════════════════════════════════════════════════════════════════
   PAGINATION
   ═══════════════════════════════════════════════════════════════════════ */
.pagination .page-link {
    font-size: 0.82rem;
    border-radius: 6px;
    margin: 0 2px;
}

/* ═══════════════════════════════════════════════════════════════════════════
   RESPONSIVE BREAKPOINTS
   ═══════════════════════════════════════════════════════════════════════ */

/* ── Small phones (< 576px) ─────────────────────────────────────────── */
@media (max-width: 575.98px) {
    .main-content { padding: 12px 8px; padding-top: calc(var(--topbar-h) + 8px); }
    .section-header h4 { font-size: 1.1rem; }
    .kpi-card { padding: 12px 10px; }
    .kpi-value { font-size: 1.2rem; }
    .kpi-label { font-size: 0.7rem; }
    .table { font-size: 0.78rem; }
    .table thead th { font-size: 0.72rem; }
    .header-actions { width: 100%; justify-content: flex-end; }
    .header-actions .btn { font-size: 0.78rem; padding: 4px 10px; }
    .grid-card { padding: 12px; }
    .grid-card .card-title { font-size: 0.9rem; }
    .card-header { font-size: 0.82rem; padding: 10px 12px; }
}

/* ── Tablets (576–767px) ────────────────────────────────────────────── */
@media (min-width: 576px) and (max-width: 767.98px) {
    .main-content { padding: 16px 12px; }
}

/* ── Desktop (≥992px) ───────────────────────────────────────────────── */
@media (min-width: 992px) {
    .mobile-topbar { display: none !important; }
    .sidebar-overlay { display: none !important; }
}

/* ═══════════════════════════════════════════════════════════════════════════
   CHART CANVAS
   ═══════════════════════════════════════════════════════════════════════ */
canvas {
    max-height: 320px;
    width: 100% !important;
}

/* ═══════════════════════════════════════════════════════════════════════════
   UTILITIES
   ═══════════════════════════════════════════════════════════════════════ */
.text-truncate-2 {
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}
.cursor-pointer { cursor: pointer; }
.gap-1 { gap: 4px; }
.gap-2 { gap: 8px; }

/* ── Announcement urgency ──────────────────────────────────────────── */
.ann-urgent { border-left: 4px solid var(--danger); }
.ann-normal { border-left: 4px solid var(--border); }

/* ── Welfare priority colours ──────────────────────────────────────── */
.welfare-open       { border-left: 4px solid var(--info); }
.welfare-in_progress{ border-left: 4px solid var(--warning); }
.welfare-escalated  { border-left: 4px solid var(--danger); }
.welfare-resolved   { border-left: 4px solid var(--success); }

/* ── Loading state ─────────────────────────────────────────────────── */
.loading-spinner {
    display: inline-block;
    width: 20px;
    height: 20px;
    border: 3px solid var(--border);
    border-top-color: var(--primary);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* Empty state */
.empty-state {
    text-align: center;
    padding: 40px 20px;
    color: var(--text-muted);
}
.empty-state i { font-size: 3rem; opacity: .4; margin-bottom: 12px; }
.empty-state p { font-size: 0.9rem; }

/* ═══════════════════════════════════════════════════════════════════════════
   EMBEDDED MODE (inside erp_home iframe)
   Hide own sidebar/topbar — erp_home provides the outer shell
   ═══════════════════════════════════════════════════════════════════════ */
html.embedded .sidebar,
html.embedded .mobile-topbar,
html.embedded .sidebar-overlay { display: none !important; }
html.embedded .main-content {
    margin-left: 0 !important;
    padding-top: 12px !important;
}
