<?php
// Mobile header - included at top of every mobile page
$page_title = $page_title ?? 'Cash Lending';
$settings = getSettings($conn);
$company_name = $settings['company_name'] ?? 'Cash Lending';
$current_user = getCurrentUser($conn);
?>
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no">
    <meta name="mobile-web-app-capable" content="yes">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="theme-color" content="#1a56db">
    <title><?php echo htmlspecialchars($page_title); ?> — <?php echo htmlspecialchars($company_name); ?></title>

    <link rel="preconnect" href="https://fonts.googleapis.com">
    <link href="https://fonts.googleapis.com/css2?family=Plus+Jakarta+Sans:wght@400;500;600;700;800&display=swap" rel="stylesheet">
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css">

    <style>
        *, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

        :root {
            --primary:    #1a56db;
            --primary-dk: #1447b2;
            --success:    #057a55;
            --danger:     #e02424;
            --warning:    #c27803;
            --info:       #0694a2;
            --bg:         #f3f4f8;
            --surface:    #ffffff;
            --border:     #e5e7eb;
            --text:       #111827;
            --muted:      #6b7280;
            --nav-h:      64px;
            --top-h:      56px;
            --radius:     16px;
            --shadow:     0 2px 12px rgba(0,0,0,.08);
        }

        html, body {
            font-family: 'Plus Jakarta Sans', sans-serif;
            background: var(--bg);
            color: var(--text);
            min-height: 100vh;
            -webkit-font-smoothing: antialiased;
        }

        /* ── Top bar ── */
        .top-bar {
            position: fixed; top: 0; left: 0; right: 0; z-index: 100;
            height: var(--top-h);
            background: var(--primary);
            display: flex; align-items: center; justify-content: space-between;
            padding: 0 16px;
            box-shadow: 0 2px 8px rgba(26,86,219,.3);
        }
        .top-bar .page-title {
            font-size: 17px; font-weight: 700; color: #fff; letter-spacing: -.2px;
        }
        .top-bar .top-right { display: flex; align-items: center; gap: 10px; }
        .top-bar .avatar {
            width: 34px; height: 34px; border-radius: 50%;
            background: rgba(255,255,255,.25);
            display: flex; align-items: center; justify-content: center;
            font-weight: 700; font-size: 13px; color: #fff;
            text-decoration: none;
        }
        .top-bar .notif-btn {
            width: 34px; height: 34px; border-radius: 50%;
            background: rgba(255,255,255,.15);
            border: none; color: #fff; font-size: 15px;
            display: flex; align-items: center; justify-content: center;
            cursor: pointer;
        }

        /* ── Content wrapper ── */
        .mobile-content {
            padding: calc(var(--top-h) + 16px) 14px calc(var(--nav-h) + 20px);
            min-height: 100vh;
        }

        /* ── Bottom nav ── */
        .bottom-nav {
            position: fixed; bottom: 0; left: 0; right: 0; z-index: 100;
            height: var(--nav-h);
            background: var(--surface);
            border-top: 1px solid var(--border);
            display: flex;
            box-shadow: 0 -4px 20px rgba(0,0,0,.07);
        }
        .nav-item {
            flex: 1; display: flex; flex-direction: column;
            align-items: center; justify-content: center;
            gap: 3px; text-decoration: none;
            color: var(--muted); font-size: 10px; font-weight: 600;
            letter-spacing: .2px; transition: color .15s;
            position: relative;
        }
        .nav-item i { font-size: 20px; transition: transform .15s; }
        .nav-item.active { color: var(--primary); }
        .nav-item.active i { transform: translateY(-2px); }
        .nav-item.active::after {
            content: '';
            position: absolute; top: 0; left: 20%; right: 20%; height: 3px;
            background: var(--primary); border-radius: 0 0 4px 4px;
        }

        /* ── Cards ── */
        .card {
            background: var(--surface); border-radius: var(--radius);
            box-shadow: var(--shadow); border: 1px solid var(--border);
            overflow: hidden;
        }
        .card-body { padding: 16px; }
        .card-header {
            padding: 14px 16px; font-weight: 700; font-size: 14px;
            border-bottom: 1px solid var(--border);
            display: flex; align-items: center; gap: 8px;
        }

        /* ── Stat cards ── */
        .stat-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-bottom: 16px; }
        .stat-card {
            border-radius: var(--radius); padding: 16px 14px;
            color: #fff; position: relative; overflow: hidden;
        }
        .stat-card::after {
            content: ''; position: absolute;
            width: 80px; height: 80px; border-radius: 50%;
            background: rgba(255,255,255,.12);
            right: -20px; bottom: -20px;
        }
        .stat-card .stat-label { font-size: 11px; font-weight: 600; opacity: .85; text-transform: uppercase; letter-spacing: .5px; }
        .stat-card .stat-num   { font-size: 26px; font-weight: 800; line-height: 1.1; margin: 4px 0 2px; }
        .stat-card .stat-sub   { font-size: 11px; opacity: .75; }
        .stat-card.blue   { background: linear-gradient(135deg, #1a56db, #3b82f6); }
        .stat-card.green  { background: linear-gradient(135deg, #057a55, #10b981); }
        .stat-card.red    { background: linear-gradient(135deg, #e02424, #f87171); }
        .stat-card.orange { background: linear-gradient(135deg, #c27803, #f59e0b); }

        /* ── Buttons ── */
        .btn {
            display: inline-flex; align-items: center; justify-content: center;
            gap: 7px; padding: 11px 18px; border-radius: 10px;
            font-family: inherit; font-size: 14px; font-weight: 600;
            cursor: pointer; border: none; transition: all .15s; text-decoration: none;
        }
        .btn-primary   { background: var(--primary); color: #fff; }
        .btn-primary:hover { background: var(--primary-dk); }
        .btn-success   { background: var(--success); color: #fff; }
        .btn-danger    { background: var(--danger);  color: #fff; }
        .btn-outline   { background: transparent; border: 1.5px solid var(--border); color: var(--text); }
        .btn-block     { width: 100%; }
        .btn-sm        { padding: 7px 12px; font-size: 12px; border-radius: 8px; }

        /* ── Form controls ── */
        .form-group { margin-bottom: 14px; }
        .form-label { display: block; font-size: 13px; font-weight: 600; margin-bottom: 5px; color: var(--text); }
        .form-control, .form-select {
            width: 100%; padding: 11px 13px;
            border: 1.5px solid var(--border); border-radius: 10px;
            font-family: inherit; font-size: 14px; color: var(--text);
            background: var(--surface); transition: border-color .15s;
            -webkit-appearance: none; appearance: none;
        }
        .form-control:focus, .form-select:focus {
            outline: none; border-color: var(--primary);
            box-shadow: 0 0 0 3px rgba(26,86,219,.12);
        }
        textarea.form-control { resize: vertical; min-height: 80px; }

        /* ── List rows ── */
        .list-row {
            display: flex; align-items: center; gap: 12px;
            padding: 13px 16px; border-bottom: 1px solid var(--border);
            text-decoration: none; color: var(--text);
            transition: background .1s;
        }
        .list-row:last-child { border-bottom: none; }
        .list-row:active { background: var(--bg); }
        .list-row .row-avatar {
            width: 44px; height: 44px; border-radius: 12px;
            object-fit: cover; flex-shrink: 0;
            background: var(--bg);
        }
        .list-row .row-info { flex: 1; min-width: 0; }
        .list-row .row-name { font-weight: 700; font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
        .list-row .row-sub  { font-size: 12px; color: var(--muted); margin-top: 1px; }
        .list-row .row-right { text-align: right; flex-shrink: 0; }
        .list-row .row-amount { font-weight: 700; font-size: 14px; }
        .list-row .chevron { color: var(--border); font-size: 12px; }

        /* ── Badges ── */
        .badge {
            display: inline-block; padding: 3px 8px; border-radius: 20px;
            font-size: 10px; font-weight: 700; text-transform: uppercase; letter-spacing: .4px;
        }
        .badge-success { background: #d1fae5; color: #065f46; }
        .badge-danger  { background: #fee2e2; color: #991b1b; }
        .badge-warning { background: #fef3c7; color: #92400e; }
        .badge-info    { background: #cffafe; color: #155e75; }
        .badge-primary { background: #dbeafe; color: #1e40af; }

        /* ── Alert ── */
        .alert { padding: 12px 14px; border-radius: 10px; font-size: 13px; font-weight: 500; margin-bottom: 14px; }
        .alert-danger  { background: #fee2e2; color: #991b1b; border: 1px solid #fecaca; }
        .alert-success { background: #d1fae5; color: #065f46; border: 1px solid #a7f3d0; }

        /* ── Section title ── */
        .section-title {
            font-size: 13px; font-weight: 700; color: var(--muted);
            text-transform: uppercase; letter-spacing: .6px;
            margin: 20px 0 10px;
        }

        /* ── Quick action buttons ── */
        .quick-actions { display: grid; grid-template-columns: repeat(4,1fr); gap: 10px; margin-bottom: 16px; }
        .qa-btn {
            display: flex; flex-direction: column; align-items: center; gap: 6px;
            padding: 14px 8px; border-radius: var(--radius);
            background: var(--surface); border: 1px solid var(--border);
            text-decoration: none; color: var(--text);
            font-size: 11px; font-weight: 700; text-align: center;
            box-shadow: var(--shadow); transition: transform .1s;
        }
        .qa-btn:active { transform: scale(.96); }
        .qa-btn .qa-icon {
            width: 40px; height: 40px; border-radius: 12px;
            display: flex; align-items: center; justify-content: center; font-size: 18px;
        }

        /* ── Empty state ── */
        .empty-state { padding: 40px 20px; text-align: center; color: var(--muted); }
        .empty-state i { font-size: 40px; opacity: .3; margin-bottom: 12px; display: block; }
        .empty-state p { font-size: 14px; font-weight: 500; }

        /* ── Collection banner ── */
        .collection-banner {
            border-radius: var(--radius); padding: 18px 16px; margin-bottom: 16px;
            background: linear-gradient(135deg, var(--primary), #3b82f6);
            color: #fff; position: relative; overflow: hidden;
        }
        .collection-banner::before {
            content: ''; position: absolute;
            width: 160px; height: 160px; border-radius: 50%;
            background: rgba(255,255,255,.08); right: -40px; top: -40px;
        }
        .collection-banner .cb-label { font-size: 12px; opacity: .8; font-weight: 600; text-transform: uppercase; letter-spacing: .5px; }
        .collection-banner .cb-amount { font-size: 32px; font-weight: 800; margin: 4px 0; }
        .collection-banner .cb-sub    { font-size: 12px; opacity: .7; }

        /* ── Utility ── */
        .mt-1 { margin-top: 6px; }
        .mt-2 { margin-top: 12px; }
        .mt-3 { margin-top: 18px; }
        .mb-1 { margin-bottom: 6px; }
        .mb-2 { margin-bottom: 12px; }
        .mb-3 { margin-bottom: 18px; }
        .text-muted { color: var(--muted); }
        .text-center { text-align: center; }
        .fw-bold { font-weight: 700; }
        .d-flex { display: flex; }
        .align-center { align-items: center; }
        .justify-between { justify-content: space-between; }
        .gap-2 { gap: 10px; }
        .w-100 { width: 100%; }
        .required { color: var(--danger); }
    </style>
</head>
<body>

<!-- Top bar -->
<div class="top-bar">
    <span class="page-title"><?php echo htmlspecialchars($page_title); ?></span>
    <div class="top-right">
        <a href="/cash_lending/mobile/logout.php" class="avatar" title="Logout">
            <?php echo strtoupper(substr($current_user['full_name'] ?? 'U', 0, 1)); ?>
        </a>
    </div>
</div>

<!-- Main content -->
<div class="mobile-content">
