<?php
/**
 * Super Admin Header Component
 * Uso: include __DIR__ . '/includes/header.php';
 * Variável necessária: $pageTitle
 */
$pageTitle = $pageTitle ?? 'Super Admin';
?>
<!DOCTYPE html>
<html lang="pt-BR" data-theme="light">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title><?= htmlspecialchars($pageTitle) ?> - MontaLoja</title>
    <link rel="stylesheet" href="/assets/css/style.css">
    <script defer src="https://cdn.jsdelivr.net/npm/iconify-icon@1.0.7/dist/iconify-icon.min.js"></script>
    <script>
        // Aplicar tema antes do carregamento para evitar flash
        (function() {
            const saved = localStorage.getItem('superadmin-theme') || 'light';
            if (saved === 'auto') {
                const prefersDark = window.matchMedia('(prefers-color-scheme: dark)').matches;
                document.documentElement.setAttribute('data-theme', prefersDark ? 'dark' : 'light');
            } else {
                document.documentElement.setAttribute('data-theme', saved);
            }
        })();
    </script>
    <style>
        /* ===== TEMA CLARO (Padrão) ===== */
        :root, [data-theme="light"] {
            --gold: #CCA43B;
            --gold-hover: #B8963A;
            --bg-dark: #F5F5F7;
            --bg-panel: #FFFFFF;
            --bg-input: #F0F0F2;
            --text-primary: #1A1A1A;
            --text-secondary: #4A4A4A;
            --text-muted: #6B7280;
            --border-light: rgba(0,0,0,0.1);
            --success: #16A34A;
            --danger: #DC2626;
            --warning: #D97706;
            --info: #2563EB;
            --radius-md: 8px;
            --radius-lg: 12px;
            --sidebar-width: 260px;
            --shadow-sm: 0 1px 2px rgba(0,0,0,0.05);
            --shadow-md: 0 4px 6px rgba(0,0,0,0.07);
            --shadow-lg: 0 10px 15px rgba(0,0,0,0.1);
        }

        /* ===== TEMA ESCURO ===== */
        [data-theme="dark"] {
            --gold: #CCA43B;
            --gold-hover: #DDB84C;
            --bg-dark: #0F0F0F;
            --bg-panel: #1A1A1A;
            --bg-input: #252525;
            --text-primary: #FFFFFF;
            --text-secondary: #E5E5E5;
            --text-muted: #9CA3AF;
            --border-light: rgba(255,255,255,0.1);
            --success: #22C55E;
            --danger: #EF4444;
            --warning: #F59E0B;
            --info: #3B82F6;
            --shadow-sm: 0 1px 2px rgba(0,0,0,0.3);
            --shadow-md: 0 4px 6px rgba(0,0,0,0.4);
            --shadow-lg: 0 10px 15px rgba(0,0,0,0.5);
        }

        * {
            box-sizing: border-box;
        }

        body {
            background: var(--bg-dark);
            color: var(--text-primary);
            font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
            margin: 0;
            min-height: 100vh;
            transition: background-color 0.3s ease, color 0.3s ease;
        }

        .app-container {
            display: flex;
            min-height: 100vh;
        }

        /* Sidebar */
        .sidebar {
            width: var(--sidebar-width);
            background: var(--bg-panel);
            border-right: 1px solid var(--border-light);
            display: flex;
            flex-direction: column;
            position: fixed;
            height: 100vh; /* Fallback */
            height: 100dvh; /* Dynamic viewport height for mobile */
            z-index: 1000;
            transition: transform 0.3s ease, background-color 0.3s ease;
            box-shadow: var(--shadow-md);
        }

        .sidebar-header {
            padding: 1.5rem;
            border-bottom: 1px solid var(--border-light);
            flex-shrink: 0; /* Prevent shrinking */
        }

        .logo {
            display: flex;
            align-items: center;
            gap: 0.75rem;
            font-size: 1.5rem;
            font-weight: 700;
            color: var(--text-primary);
            margin-bottom: 0.75rem;
        }

        .super-admin-badge {
            background: linear-gradient(135deg, #CCA43B, #FFD700);
            color: #1A1A1A;
            padding: 4px 12px;
            border-radius: 20px;
            font-size: 0.75rem;
            font-weight: 700;
            text-transform: uppercase;
            letter-spacing: 0.5px;
            display: inline-block;
        }

        .sidebar-nav {
            flex: 1;
            padding: 0.5rem 0;
            overflow-y: auto; /* Added scroll here */
            overflow-x: hidden;
        }

        .nav-item {
            display: flex;
            align-items: center;
            gap: 0.75rem;
            padding: 0.875rem 1.5rem;
            color: var(--text-muted);
            text-decoration: none;
            transition: all 0.2s;
            font-size: 0.95rem;
        }

        .nav-item:hover {
            background: var(--bg-input);
            color: var(--text-primary);
        }

        .nav-item.active {
            background: rgba(204,164,59,0.15);
            color: var(--gold);
            border-right: 3px solid var(--gold);
        }

        .nav-item.danger {
            color: var(--danger);
        }

        .nav-item.danger:hover {
            background: rgba(239,68,68,0.1);
        }

        .nav-item iconify-icon {
            font-size: 1.25rem;
        }

        .sidebar-footer {
            padding: 0.5rem 0;
            border-top: 1px solid var(--border-light);
            flex-shrink: 0;
            
            /* Safe area for mobile devices */
            padding-bottom: env(safe-area-inset-bottom, 20px);
            margin-bottom: 60px; /* Extra margin for mobile browser bars */
        }
        
        @media (min-width: 769px) {
            .sidebar-footer {
                margin-bottom: 0;
                padding-bottom: 0.5rem;
            }
        }

        /* Mobile Menu Button */
        .mobile-menu-btn {
            display: none;
            background: transparent;
            border: none;
            color: var(--text-primary);
            font-size: 1.5rem;
            cursor: pointer;
            padding: 0.5rem;
            border-radius: var(--radius-md);
        }

        .mobile-menu-btn:hover {
            background: var(--bg-input);
        }

        /* Sidebar Overlay */
        .sidebar-overlay {
            display: none;
            position: fixed;
            top: 0;
            left: 0;
            right: 0;
            bottom: 0;
            background: rgba(0,0,0,0.5);
            z-index: 999;
        }

        .sidebar-overlay.active {
            display: block;
        }

        /* Main Content */
        .main-content {
            flex: 1;
            margin-left: var(--sidebar-width);
            min-height: 100vh;
            width: calc(100% - var(--sidebar-width));
        }

        /* Topbar */
        .topbar {
            display: flex;
            justify-content: space-between;
            align-items: center;
            padding: 1rem 2rem;
            background: var(--bg-panel);
            border-bottom: 1px solid var(--border-light);
            position: sticky;
            top: 0;
            z-index: 100;
            gap: 1rem;
            box-shadow: var(--shadow-sm);
            transition: background-color 0.3s ease;
        }

        .topbar-left {
            display: flex;
            align-items: center;
            gap: 1rem;
            min-width: 0;
            flex: 1;
        }

        .topbar-title {
            font-size: 1.5rem;
            font-weight: 600;
            margin: 0;
            white-space: nowrap;
            overflow: hidden;
            text-overflow: ellipsis;
            color: var(--text-primary);
        }

        .topbar-right {
            display: flex;
            align-items: center;
            gap: 1.5rem;
            flex-shrink: 0;
        }

        /* Theme Switcher */
        .theme-switcher {
            display: flex;
            align-items: center;
            gap: 0.25rem;
            background: var(--bg-input);
            padding: 0.25rem;
            border-radius: var(--radius-md);
            border: 1px solid var(--border-light);
        }

        .theme-btn {
            display: flex;
            align-items: center;
            justify-content: center;
            width: 36px;
            height: 36px;
            border: none;
            background: transparent;
            color: var(--text-muted);
            border-radius: 6px;
            cursor: pointer;
            transition: all 0.2s;
        }

        .theme-btn:hover {
            color: var(--text-primary);
            background: var(--bg-panel);
        }

        .theme-btn.active {
            background: var(--gold);
            color: #1A1A1A;
            box-shadow: var(--shadow-sm);
        }

        .theme-btn iconify-icon {
            font-size: 1.25rem;
        }

        .user-menu {
            display: flex;
            align-items: center;
            gap: 0.75rem;
        }

        .user-avatar {
            width: 40px;
            height: 40px;
            border-radius: 50%;
            flex-shrink: 0;
        }

        .user-info {
            display: flex;
            flex-direction: column;
        }

        .user-name {
            font-weight: 600;
            font-size: 0.9rem;
            color: var(--text-primary);
        }

        .user-role {
            font-size: 0.75rem;
            color: var(--text-muted);
        }

        /* Content Area */
        .content-area {
            padding: 2rem;
        }

        /* KPI Cards */
        .kpi-grid {
            display: grid;
            grid-template-columns: repeat(4, 1fr);
            gap: 1.5rem;
            margin-bottom: 2rem;
        }

        .kpi-card {
            background: var(--bg-panel);
            border-radius: var(--radius-lg);
            padding: 1.5rem;
            border: 1px solid var(--border-light);
            box-shadow: var(--shadow-sm);
            transition: background-color 0.3s ease, box-shadow 0.2s ease;
        }

        .kpi-card:hover {
            box-shadow: var(--shadow-md);
        }

        .kpi-card.highlight {
            background: linear-gradient(135deg, rgba(204,164,59,0.1), rgba(204,164,59,0.05));
            border-color: var(--gold);
        }

        .kpi-label {
            font-size: 0.85rem;
            color: var(--text-muted);
            margin-bottom: 0.5rem;
        }

        .kpi-value {
            font-size: 2rem;
            font-weight: 700;
            color: var(--text-primary);
        }

        .kpi-value.gold {
            color: var(--gold);
        }

        .kpi-trend {
            font-size: 0.8rem;
            margin-top: 0.5rem;
        }

        .kpi-trend.up {
            color: var(--success);
        }

        /* Panel */
        .panel {
            background: var(--bg-panel);
            border-radius: var(--radius-lg);
            border: 1px solid var(--border-light);
            padding: 1.5rem;
            margin-bottom: 1.5rem;
            overflow-x: auto;
            box-shadow: var(--shadow-sm);
            transition: background-color 0.3s ease;
        }

        /* Tables */
        .table-responsive {
            overflow-x: auto;
            -webkit-overflow-scrolling: touch;
        }

        .data-table {
            width: 100%;
            border-collapse: collapse;
            min-width: 600px;
        }

        .data-table th,
        .data-table td {
            padding: 1rem;
            text-align: left;
            border-bottom: 1px solid var(--border-light);
            white-space: nowrap;
        }

        .data-table th {
            font-weight: 600;
            color: var(--text-muted);
            font-size: 0.85rem;
            text-transform: uppercase;
        }

        .data-table tbody tr:hover {
            background: var(--bg-input);
        }

        /* Buttons */
        .btn {
            display: inline-flex;
            align-items: center;
            justify-content: center;
            gap: 0.5rem;
            padding: 0.625rem 1.25rem;
            border-radius: var(--radius-md);
            font-weight: 500;
            font-size: 0.875rem;
            cursor: pointer;
            transition: all 0.2s;
            text-decoration: none;
            border: none;
            white-space: nowrap;
        }

        .btn-primary {
            background: var(--gold);
            color: #1A1A1A;
        }

        .btn-primary:hover {
            background: var(--gold-hover);
            box-shadow: var(--shadow-md);
        }

        .btn-secondary {
            background: var(--bg-input);
            color: var(--text-primary);
            border: 1px solid var(--border-light);
        }

        .btn-secondary:hover {
            background: var(--bg-panel);
            box-shadow: var(--shadow-sm);
        }

        .btn-outline {
            background: transparent;
            border: 1px solid var(--gold);
            color: var(--gold);
        }

        .btn-outline:hover {
            background: var(--gold);
            color: #1A1A1A;
        }

        .btn-danger {
            background: rgba(239,68,68,0.15);
            color: var(--danger);
        }

        .btn-danger:hover {
            background: rgba(239,68,68,0.25);
        }

        .btn-sm {
            padding: 0.375rem 0.75rem;
            font-size: 0.8rem;
        }

        .btn-icon {
            padding: 0.5rem;
            border-radius: var(--radius-md);
        }

        /* Status Badges */
        .status-badge {
            padding: 4px 10px;
            border-radius: 20px;
            font-size: 0.75rem;
            font-weight: 600;
            white-space: nowrap;
        }

        .status-active {
            background: rgba(34, 197, 94, 0.15);
            color: var(--success);
        }

        .status-trial {
            background: rgba(59, 130, 246, 0.15);
            color: var(--info);
        }

        .status-past_due, .status-suspended {
            background: rgba(239, 68, 68, 0.15);
            color: var(--danger);
        }

        .status-inactive {
            background: rgba(107, 114, 128, 0.15);
            color: var(--text-muted);
        }

        /* Forms */
        .form-group {
            margin-bottom: 1.25rem;
        }

        .form-label {
            display: block;
            color: var(--text-muted);
            font-size: 0.875rem;
            margin-bottom: 0.5rem;
        }

        .form-input {
            width: 100%;
            background: var(--bg-input);
            border: 1px solid var(--border-light);
            border-radius: var(--radius-md);
            padding: 0.75rem 1rem;
            color: var(--text-primary);
            font-size: 0.9rem;
            transition: all 0.2s;
        }

        .form-select {
            width: 100%;
            background-color: var(--bg-input);
            background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='24' height='24' viewBox='0 0 24 24'%3E%3Cpath fill='%239CA3AF' d='M7 10l5 5 5-5H7z'%3E%3C/path%3E%3C/svg%3E");
            background-repeat: no-repeat;
            background-position: right 0.75rem center;
            background-size: 1.25rem;
            border: 1px solid var(--border-light);
            border-radius: var(--radius-md);
            padding: 0.75rem 2.5rem 0.75rem 1rem;
            color: var(--text-primary);
            font-size: 0.9rem;
            appearance: none;
            -webkit-appearance: none;
            -moz-appearance: none;
            cursor: pointer;
            transition: all 0.2s;
        }

        .form-input:focus,
        .form-select:focus {
            outline: none;
            border-color: var(--gold);
            box-shadow: 0 0 0 3px rgba(204, 164, 59, 0.15);
        }

        .form-select:hover {
            border-color: var(--gold);
        }

        .form-select option {
            background-color: var(--bg-panel);
            color: var(--text-primary);
            padding: 12px 16px;
            font-size: 0.95rem;
        }

        .form-select option:checked {
            background: linear-gradient(135deg, rgba(204, 164, 59, 0.3), rgba(204, 164, 59, 0.1));
            color: var(--gold);
        }

        .form-select option:disabled {
            color: var(--text-muted);
            background-color: var(--bg-input);
        }

        .form-input::placeholder {
            color: var(--text-muted);
        }

        /* Section Headers */
        .section-header {
            display: flex;
            justify-content: space-between;
            align-items: center;
            margin-bottom: 1.5rem;
            flex-wrap: wrap;
            gap: 1rem;
        }

        .section-title {
            font-size: 1.25rem;
            font-weight: 600;
            color: var(--text-primary);
            margin: 0;
        }

        /* Page Header */
        .page-header {
            display: flex;
            justify-content: space-between;
            align-items: flex-start;
            margin-bottom: 2rem;
            flex-wrap: wrap;
            gap: 1rem;
        }

        .page-header h1, .page-header h2 {
            font-size: 1.75rem;
            font-weight: 600;
            margin: 0;
            display: flex;
            align-items: center;
            gap: 0.5rem;
            color: var(--text-primary);
        }

        .page-header p {
            color: var(--text-muted);
            margin: 0.25rem 0 0 0;
        }

        /* Grid Layouts */
        .grid-2 {
            display: grid;
            grid-template-columns: repeat(2, 1fr);
            gap: 1.5rem;
        }

        .grid-3 {
            display: grid;
            grid-template-columns: repeat(3, 1fr);
            gap: 1.5rem;
        }

        .grid-4 {
            display: grid;
            grid-template-columns: repeat(4, 1fr);
            gap: 1.5rem;
        }

        /* Action buttons container */
        .action-buttons {
            display: flex;
            gap: 0.5rem;
            flex-wrap: wrap;
        }

        /* ===== RESPONSIVE BREAKPOINTS ===== */

        /* Large tablets and small desktops */
        @media (max-width: 1200px) {
            .kpi-grid {
                grid-template-columns: repeat(2, 1fr);
            }
            .grid-4 {
                grid-template-columns: repeat(2, 1fr);
            }
        }

        /* Tablets */
        @media (max-width: 992px) {
            :root, [data-theme="light"], [data-theme="dark"] {
                --sidebar-width: 240px;
            }

            .topbar-title {
                font-size: 1.25rem;
            }

            .content-area {
                padding: 1.5rem;
            }

            .grid-3 {
                grid-template-columns: repeat(2, 1fr);
            }

            .kpi-value {
                font-size: 1.75rem;
            }
        }

        /* Mobile landscape and small tablets */
        @media (max-width: 768px) {
            .sidebar {
                transform: translateX(-100%);
                width: 280px;
            }

            .sidebar.open {
                transform: translateX(0);
            }

            .main-content {
                margin-left: 0;
                width: 100%;
            }

            .mobile-menu-btn {
                display: flex !important;
                align-items: center;
                justify-content: center;
            }

            .topbar {
                padding: 1rem;
            }

            .topbar-title {
                font-size: 1.1rem;
            }

            .topbar-right {
                gap: 0.75rem;
            }

            .theme-switcher {
                padding: 0.125rem;
            }

            .theme-btn {
                width: 32px;
                height: 32px;
            }

            .theme-btn iconify-icon {
                font-size: 1.1rem;
            }

            .user-info {
                display: none;
            }

            .content-area {
                padding: 1rem;
            }

            .kpi-grid {
                grid-template-columns: repeat(2, 1fr);
                gap: 1rem;
            }

            .kpi-card {
                padding: 1rem;
            }

            .kpi-value {
                font-size: 1.5rem;
            }

            .kpi-label {
                font-size: 0.75rem;
            }

            .grid-4, .grid-3, .grid-2 {
                grid-template-columns: 1fr;
            }

            .page-header {
                flex-direction: column;
                align-items: flex-start;
            }

            .page-header h1, .page-header h2 {
                font-size: 1.5rem;
            }

            .section-header {
                flex-direction: column;
                align-items: flex-start;
            }

            .panel {
                padding: 1rem;
            }

            .data-table th,
            .data-table td {
                padding: 0.75rem 0.5rem;
                font-size: 0.85rem;
            }

            .btn {
                padding: 0.5rem 1rem;
                font-size: 0.8rem;
            }

            .btn-lg {
                padding: 0.75rem 1.25rem !important;
                font-size: 0.9rem !important;
            }
        }

        /* Mobile portrait */
        @media (max-width: 480px) {
            .kpi-grid {
                grid-template-columns: 1fr;
            }

            .topbar-title {
                font-size: 1rem;
            }

            .page-header h1, .page-header h2 {
                font-size: 1.25rem;
            }

            .logo span {
                font-size: 1.25rem;
            }

            .data-table {
                min-width: 500px;
            }

            .form-input,
            .form-select {
                padding: 0.625rem 2.5rem 0.625rem 0.875rem;
                font-size: 16px; /* Prevent zoom on iOS */
            }
        }

        /* Utility Classes */
        .text-gold { color: var(--gold); }
        .text-muted { color: var(--text-muted); }
        .text-success { color: var(--success); }
        .text-danger { color: var(--danger); }
        .text-warning { color: var(--warning); }
        .text-sm { font-size: 0.875rem; }
        .text-xs { font-size: 0.75rem; }
        .font-bold { font-weight: 700; }
        .font-medium { font-weight: 500; }
        .mt-1 { margin-top: 0.25rem; }
        .mt-2 { margin-top: 0.5rem; }
        .mt-4 { margin-top: 1rem; }
        .mb-2 { margin-bottom: 0.5rem; }
        .mb-4 { margin-bottom: 1rem; }
        .flex { display: flex; }
        .flex-wrap { flex-wrap: wrap; }
        .items-center { align-items: center; }
        .justify-between { justify-content: space-between; }
        .gap-2 { gap: 0.5rem; }
        .gap-3 { gap: 0.75rem; }
        .gap-4 { gap: 1rem; }
        .hidden-mobile { display: block; }
        .show-mobile { display: none; }

        @media (max-width: 768px) {
            .hidden-mobile { display: none !important; }
            .show-mobile { display: block !important; }
        }
    </style>
    <link rel="stylesheet" href="/pages/superadmin/assets/css/global.css">
</head>
<body>
    <!-- Sidebar Overlay for mobile -->
    <div class="sidebar-overlay" id="sidebarOverlay"></div>
