<?php start_session(); $user = current_user(); ?>
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title><?= e(config('app.name')) ?></title>
    <link rel="stylesheet" href="assets/css/style.css">
</head>
<body>
<div class="app-shell">
    <aside class="sidebar">
        <div class="brand-block">
            <div class="brand-kicker">Corporate Messaging Suite</div>
            <div class="brand">INS Communications</div>
        </div>
        <nav>
            <?php if (can_access('dashboard.view')): ?><a href="index.php">Dashboard</a><?php endif; ?>
            <?php if (can_access('contacts.view')): ?><a href="index.php?route=contacts/index">Contacts</a><?php endif; ?>
            <?php if (can_access('templates.view')): ?><a href="index.php?route=templates/index">Templates</a><?php endif; ?>
            <?php if (can_access('messages.view')): ?><a href="index.php?route=messages/index">Inbox & Campaigns</a><?php endif; ?>
            <?php if (can_access('dashboard.view')): ?><a href="index.php?route=search/index">Global Search</a><?php endif; ?>
            <a href="index.php?route=settings/profile">My Profile</a>
            <?php if (can_access('settings.view')): ?><a href="index.php?route=settings/index">Settings & Users</a><?php endif; ?>
            <?php if (can_access('settings.view')): ?><a href="index.php?route=settings/diagnostics">Diagnostics</a><?php endif; ?>
            <?php if (can_access('settings.manage')): ?><a href="install.php#update-packages">Update Center</a><?php endif; ?>
        </nav>
        <div class="sidebar-footer">
            <div class="muted small"><?= e($user['name'] ?? '') ?></div>
            <div class="muted small"><?= e($user['role'] ?? '') ?></div>
            <a class="btn secondary full" href="index.php?route=auth/logout">Sign Out</a>
        </div>
    </aside>
    <main class="content">
        <header class="topbar">
            <div>
                <h1><?= e(config('app.name')) ?></h1>
                <p>SMS, MMS, email, inbox, templates, campaigns, callbacks, segmentation, permissions, suppression, reporting, and queue operations in one place.</p>
            </div>
            <form method="get" action="index.php" style="display:flex;gap:8px;align-items:center;">
                <input type="hidden" name="route" value="search/index">
                <input type="search" name="q" value="<?= e($_GET['q'] ?? '') ?>" placeholder="Search everything" style="min-width:260px;">
                <button class="btn secondary" type="submit">Search</button>
            </form>
        </header>
        <?php if ($msg = flash('success')): ?><div class="alert success"><?= e($msg) ?></div><?php endif; ?>
        <?php if ($msg = flash('error')): ?><div class="alert error"><?= e($msg) ?></div><?php endif; ?>
