<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title><?= esc($title ?? 'Jambo Admin') ?></title>
    <style>
        /* Modern CSS reset & variables */
        * {
            margin: 0;
            padding: 0;
            box-sizing: border-box;
        }

        :root {
            --primary: #4f46e5;
            --primary-dark: #4338ca;
            --secondary: #6b7280;
            --secondary-dark: #4b5563;
            --bg: #f9fafb;
            --surface: #ffffff;
            --text: #111827;
            --text-light: #6b7280;
            --border: #e5e7eb;
            --sidebar-bg: #1f2937;
            --sidebar-hover: #374151;
            --sidebar-active: var(--primary);
            --shadow-sm: 0 1px 2px 0 rgb(0 0 0 / 0.05);
            --shadow: 0 1px 3px 0 rgb(0 0 0 / 0.1), 0 1px 2px -1px rgb(0 0 0 / 0.1);
            --shadow-md: 0 4px 6px -1px rgb(0 0 0 / 0.1), 0 2px 4px -2px rgb(0 0 0 / 0.1);
            --radius: 0.5rem;
        }

        body {
            font-family: 'Inter', system-ui, -apple-system, sans-serif;
            background: var(--bg);
            color: var(--text);
            line-height: 1.5;
        }

        .admin-wrap {
            display: flex;
            min-height: 100vh;
        }

        /* Sidebar */
        .sidebar {
            width: 260px;
            background: var(--sidebar-bg);
            color: #e5e7eb;
            flex-shrink: 0;
            box-shadow: var(--shadow-md);
            transition: width 0.2s;
        }

        .sidebar h2 {
            padding: 1.5rem 1rem 1rem;
            margin: 0;
            font-size: 1.25rem;
            font-weight: 600;
            letter-spacing: 0.025em;
            color: #f9fafb;
            border-bottom: 1px solid #374151;
        }

        .sidebar a {
            display: block;
            padding: 0.75rem 1.5rem;
            color: #d1d5db;
            text-decoration: none;
            font-weight: 500;
            transition: all 0.2s;
            border-left: 3px solid transparent;
        }

        .sidebar a:hover {
            background: var(--sidebar-hover);
            color: #ffffff;
            border-left-color: var(--primary);
        }

        .sidebar a.active {
            background: var(--sidebar-active);
            color: white;
            border-left-color: white;
        }

        /* Main content */
        .main {
            flex: 1;
            padding: 2rem;
            overflow: auto;
        }

        .header {
            display: flex;
            justify-content: space-between;
            align-items: center;
            margin-bottom: 2rem;
        }

        .header h1 {
            margin: 0;
            font-size: 1.875rem;
            font-weight: 600;
            color: var(--text);
        }

        /* Cards & tables */
        table {
            width: 100%;
            border-collapse: separate;
            border-spacing: 0;
            background: var(--surface);
            border-radius: var(--radius);
            overflow: hidden;
            box-shadow: var(--shadow);
            margin-bottom: 2rem;
        }

        th, td {
            padding: 1rem 1.5rem;
            text-align: left;
            border-bottom: 1px solid var(--border);
        }

        th {
            background: #f9fafb;
            font-weight: 600;
            color: var(--text-light);
            text-transform: uppercase;
            font-size: 0.75rem;
            letter-spacing: 0.05em;
        }

        tr:last-child td {
            border-bottom: none;
        }

        tbody tr:hover {
            background: #f9fafb;
        }

        /* Buttons */
        .btn {
            display: inline-block;
            padding: 0.5rem 1rem;
            border-radius: var(--radius);
            text-decoration: none;
            font-size: 0.875rem;
            font-weight: 500;
            cursor: pointer;
            border: none;
            transition: all 0.15s;
            box-shadow: var(--shadow-sm);
        }

        .btn-primary {
            background: var(--primary);
            color: white;
        }
        .btn-primary:hover {
            background: var(--primary-dark);
            box-shadow: var(--shadow);
        }

        .btn-secondary {
            background: var(--secondary);
            color: white;
        }
        .btn-secondary:hover {
            background: var(--secondary-dark);
        }

        /* Flash messages */
        .message, .error {
            padding: 1rem 1.5rem;
            margin-bottom: 2rem;
            border-radius: var(--radius);
            font-weight: 500;
            box-shadow: var(--shadow-sm);
        }
        .message {
            background: #d1fae5;
            color: #065f46;
            border-left: 4px solid #10b981;
        }
        .error {
            background: #fee2e2;
            color: #991b1b;
            border-left: 4px solid #ef4444;
        }

        /* Forms */
        form label {
            display: block;
            margin-bottom: 0.25rem;
            font-weight: 500;
            color: var(--text);
        }

        form input, form select {
            padding: 0.625rem 0.875rem;
            margin-bottom: 1.25rem;
            border: 1px solid var(--border);
            border-radius: var(--radius);
            width: 100%;
            max-width: 300px;
            font-size: 0.95rem;
            transition: border 0.2s, box-shadow 0.2s;
        }

        form input:focus, form select:focus {
            outline: none;
            border-color: var(--primary);
            box-shadow: 0 0 0 3px rgba(79, 70, 229, 0.1);
        }

        form button[type="submit"] {
            margin-top: 0.5rem;
        }

        /* Responsive */
        @media (max-width: 768px) {
            .admin-wrap {
                flex-direction: column;
            }
            .sidebar {
                width: 100%;
            }
            .sidebar a {
                padding: 0.75rem 1rem;
            }
            .main {
                padding: 1.5rem;
            }
            table {
                display: block;
                overflow-x: auto;
            }
        }
    </style>
</head>
<body>
    <div class="admin-wrap">
        <nav class="sidebar">
            <h2>Jambo Admin</h2>
            <a href="<?= base_url('admin') ?>" class="<?= (uri_string() === 'admin' || uri_string() === 'admin/dashboard') ? 'active' : '' ?>">Dashboard</a>
            <a href="<?= base_url('admin/orders') ?>" class="<?= strpos(uri_string(), 'admin/orders') === 0 ? 'active' : '' ?>">Orders</a>
            <a href="<?= base_url('admin/rescue') ?>" class="<?= strpos(uri_string(), 'admin/rescue') === 0 ? 'active' : '' ?>">Rescue+</a>
            <a href="<?= base_url('admin/users') ?>" class="<?= strpos(uri_string(), 'admin/users') === 0 ? 'active' : '' ?>">Users</a>
            <a href="<?= base_url('admin/drivers') ?>" class="<?= strpos(uri_string(), 'admin/drivers') === 0 ? 'active' : '' ?>">Drivers</a>
            <a href="<?= base_url('admin/providers') ?>" class="<?= strpos(uri_string(), 'admin/providers') === 0 ? 'active' : '' ?>">Providers & Prices</a>
            <a href="<?= base_url('admin/gas-kit-addons') ?>" class="<?= strpos(uri_string(), 'admin/gas-kit-addons') === 0 ? 'active' : '' ?>">Gas kit add-ons</a>
            <a href="<?= base_url('admin/shop') ?>" class="<?= strpos(uri_string(), 'admin/shop') === 0 ? 'active' : '' ?>">Shop</a>
            <a href="<?= base_url('admin/service-fee') ?>" class="<?= uri_string() === 'admin/service-fee' ? 'active' : '' ?>">Service Fee</a>
            <a href="<?= base_url('admin/app-version') ?>" class="<?= uri_string() === 'admin/app-version' ? 'active' : '' ?>">App Version</a>
            <a href="<?= base_url('admin/service-images') ?>" class="<?= strpos(uri_string(), 'admin/service-images') === 0 ? 'active' : '' ?>">Service images</a>
            <a href="<?= base_url('admin/login/logout') ?>">Logout</a>
        </nav>
        <main class="main">
            <?php if (session()->getFlashdata('message')): ?>
                <div class="message"><?= esc(session()->getFlashdata('message')) ?></div>
            <?php endif ?>
            <?php if (session()->getFlashdata('error')): ?>
                <div class="error"><?= esc(session()->getFlashdata('error')) ?></div>
            <?php endif ?>
            <?= $content ?? '' ?>
        </main>
    </div>
</body>
</html>