<!DOCTYPE html>
<html lang="pt">
<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', 'SINAGEM — Sistema Nacional de Gestão de Mercados')</title>

    {{-- Bootstrap 5 CSS --}}
    <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/css/bootstrap.min.css" rel="stylesheet">

    {{-- DataTables CSS --}}
    <link rel="stylesheet" href="https://cdn.datatables.net/1.13.7/css/dataTables.bootstrap5.min.css">
    <link rel="stylesheet" href="https://cdn.datatables.net/responsive/2.5.0/css/responsive.bootstrap5.min.css">

    {{-- SINAGEM DataTable Styles --}}
    <link rel="stylesheet" href="{{ asset('assets/css/modules/datatable.css') }}">

    {{-- Font Awesome 6 (Free) --}}
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css">

    {{-- SINAGEM Custom Styles --}}
    <link rel="stylesheet" href="{{ asset('assets/css/app.css') }}">

    @stack('styles')
</head>
<body>

<div id="wrapper">

    {{-- Sidebar --}}
    @include('admin.partials.sidebar')

    {{-- Page Content Wrapper --}}
    <div id="page-content-wrapper">

        {{-- Header --}}
        @include('admin.partials.header')

        {{-- Flash Messages --}}
        @if(session('success'))
            <div class="sinagem-flash-alert sinagem-alert sinagem-alert-success mx-4 mt-3">
                <i class="bi bi-check-circle-fill"></i>
                <span>{{ session('success') }}</span>
                <button type="button" class="flash-close" aria-label="Fechar">&times;</button>
            </div>
        @endif

        @if(session('error'))
            <div class="sinagem-flash-alert sinagem-alert sinagem-alert-danger mx-4 mt-3">
                <i class="bi bi-exclamation-circle-fill"></i>
                <span>{{ session('error') }}</span>
                <button type="button" class="flash-close" aria-label="Fechar">&times;</button>
            </div>
        @endif

        @if(session('warning'))
            <div class="sinagem-flash-alert sinagem-alert sinagem-alert-warning mx-4 mt-3">
                <i class="bi bi-exclamation-triangle-fill"></i>
                <span>{{ session('warning') }}</span>
                <button type="button" class="flash-close" aria-label="Fechar">&times;</button>
            </div>
        @endif

        {{-- Main Content --}}
        <main class="sinagem-main">
            @yield('content')
        </main>

        {{-- Modais fora do main para evitar conflito de stacking context --}}
        @stack('modals')

        {{-- Footer --}}
        @include('admin.partials.footer')

    </div>
</div>

{{-- Bootstrap 5 JS --}}
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/js/bootstrap.bundle.min.js"></script>

{{-- Chart.js --}}
<script src="https://cdn.jsdelivr.net/npm/chart.js@4.4.0/dist/chart.umd.min.js"></script>

{{-- jQuery (required for DataTables) --}}
<script src="https://code.jquery.com/jquery-3.7.1.min.js"></script>

{{-- DataTables JS --}}
<script src="https://cdn.datatables.net/1.13.7/js/jquery.dataTables.min.js"></script>
<script src="https://cdn.datatables.net/1.13.7/js/dataTables.bootstrap5.min.js"></script>
<script src="https://cdn.datatables.net/responsive/2.5.0/js/dataTables.responsive.min.js"></script>
<script src="https://cdn.datatables.net/responsive/2.5.0/js/responsive.bootstrap5.min.js"></script>

{{-- SINAGEM DataTable Module --}}
<script src="{{ asset('assets/js/modules/datatable.js') }}"></script>

{{-- SINAGEM Custom Scripts --}}
<script src="{{ asset('assets/js/app.js') }}"></script>

@stack('scripts')
</body>
</html>
