<!DOCTYPE html>
<html lang="fr">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta name="csrf-token" content="{{ csrf_token() }}">
    <title>@yield('title', 'Comptabilité') - ATARA</title>
    <link rel="icon" type="image/svg+xml" href="{{ asset('favicon.svg') }}">
    <link rel="icon" type="image/x-icon" href="{{ asset('favicon.ico') }}">
    <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/css/bootstrap.min.css" rel="stylesheet">
    <link href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.11.1/font/bootstrap-icons.css" rel="stylesheet">
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/sweetalert2@11/dist/sweetalert2.min.css">
    <style>
        :root { --sidebar-width: 260px; }
        body { background-color: #f8f9fa; font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif; }
        .sidebar {
            width: var(--sidebar-width);
            height: 100vh;
            position: fixed;
            left: 0;
            top: 0;
            background: linear-gradient(135deg, #0284c7 0%, #0ea5e9 100%);
            color: white;
            padding: 1rem;
            overflow-y: auto;
        }
        .sidebar .nav-link {
            color: rgba(255,255,255,0.8);
            border-radius: 8px;
            margin-bottom: 0.25rem;
            padding: 0.75rem 1rem;
            transition: all 0.3s;
        }
        .sidebar .nav-link:hover, .sidebar .nav-link.active {
            background: rgba(255,255,255,0.15);
            color: white;
        }
        .sidebar .nav-section {
            font-size: 0.75rem;
            text-transform: uppercase;
            letter-spacing: 1px;
            opacity: 0.6;
            margin-top: 1rem;
            padding: 0.5rem 1rem;
        }
        .main-content {
            margin-left: var(--sidebar-width);
            padding: 2rem;
            min-height: 100vh;
        }
        .topbar {
            background: white;
            padding: 15px 25px;
            margin: -2rem -2rem 2rem -2rem;
            box-shadow: 0 2px 10px rgba(0,0,0,0.05);
        }
        .stat-card {
            border-radius: 12px;
            border: none;
            box-shadow: 0 2px 12px rgba(0,0,0,0.08);
        }
        .card { border: none; border-radius: 10px; box-shadow: 0 2px 10px rgba(0,0,0,0.05); }
        @media (max-width: 768px) {
            .sidebar { transform: translateX(-100%); }
            .main-content { margin-left: 0; }
        }
    </style>
    @stack('styles')
</head>
<body>
    @include('components.impersonate-banner')
    
    <nav class="sidebar">
        <div class="mb-4">
            <h4 class="fw-bold"><i class="bi bi-calculator me-2"></i>Comptabilité</h4>
            <small class="opacity-75">{{ Auth::user()->name }}</small>
        </div>
        
        <ul class="nav flex-column">
            <li class="nav-item">
                <a class="nav-link {{ request()->routeIs('comptabilite.dashboard') ? 'active' : '' }}" href="{{ route('comptabilite.dashboard') }}">
                    <i class="bi bi-speedometer2 me-2"></i> Tableau de bord
                </a>
            </li>
            
            <li class="nav-section">Finances</li>
            <li class="nav-item">
                <a class="nav-link {{ request()->routeIs('comptabilite.withdrawals.*') ? 'active' : '' }}" href="{{ route('comptabilite.withdrawals.index') }}">
                    <i class="bi bi-cash-stack me-2"></i> Retraits
                </a>
            </li>
            
            <li class="nav-section">Rapports</li>
            <li class="nav-item">
                <a class="nav-link {{ request()->routeIs('comptabilite.reports.index') ? 'active' : '' }}" href="{{ route('comptabilite.reports.index') }}">
                    <i class="bi bi-file-earmark-bar-graph me-2"></i> Rapports financiers
                </a>
            </li>
            <li class="nav-item">
                <a class="nav-link {{ request()->routeIs('comptabilite.reports.export') ? 'active' : '' }}" href="{{ route('comptabilite.reports.export') }}">
                    <i class="bi bi-download me-2"></i> Exporter
                </a>
            </li>
            
            <li class="nav-section">Accès Back-Office</li>
            <li class="nav-item">
                <a class="nav-link" href="{{ route('admin.dashboard') }}">
                    <i class="bi bi-grid me-2"></i> Admin Dashboard
                </a>
            </li>
        </ul>
        
        <hr class="my-4 opacity-25">
        
        <ul class="nav flex-column">
            <li class="nav-item">
                <form action="{{ route('logout') }}" method="POST">
                    @csrf
                    <button type="submit" class="nav-link w-100 text-start border-0 bg-transparent">
                        <i class="bi bi-box-arrow-left me-2"></i> Déconnexion
                    </button>
                </form>
            </li>
        </ul>
    </nav>

    <main class="main-content">
        <div class="topbar d-flex justify-content-between align-items-center">
            <h4 class="mb-0">@yield('page-title', 'Comptabilité')</h4>
            <div class="d-flex align-items-center">
                <span class="badge bg-info me-2">Comptabilité</span>
                <span class="text-muted">{{ now()->format('d/m/Y H:i') }}</span>
            </div>
        </div>
        
        @if(session('success'))
            <div class="alert alert-success alert-dismissible fade show">
                {{ session('success') }}
                <button type="button" class="btn-close" data-bs-dismiss="alert"></button>
            </div>
        @endif
        
        @if(session('error'))
            <div class="alert alert-danger alert-dismissible fade show">
                {{ session('error') }}
                <button type="button" class="btn-close" data-bs-dismiss="alert"></button>
            </div>
        @endif
        
        @yield('content')
    </main>

    <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/js/bootstrap.bundle.min.js"></script>
    <script src="https://cdn.jsdelivr.net/npm/sweetalert2@11"></script>
    
    <!-- SweetAlert2 Ultra Modern Theme -->
    @include('components.swal-modern-theme')
    
    <script>
        @if(session('success'))
            showSuccess('Succès !', '{{ session('success') }}');
        @endif
        
        @if(session('error'))
            showError('Erreur !', '{{ session('error') }}');
        @endif
        
        @if(session('warning'))
            showWarning('Attention !', '{{ session('warning') }}');
        @endif
        
        @if(session('info'))
            showInfo('Information', '{{ session('info') }}');
        @endif
    </script>
    
    @stack('scripts')
</body>
</html>
