@extends('layouts.master')

@section('title', 'Suppliers')

@section('content')
<link rel="preconnect" href="https://fonts.googleapis.com">
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
<link href="https://fonts.googleapis.com/css2?family=Cormorant+Garamond:wght@400;600;700&family=DM+Sans:wght@300;400;500;600&display=swap" rel="stylesheet">

<style>
    :root {
        --sky: #0ea5e9;
        --sky-deep: #0369a1;
        --sky-light: #38bdf8;
        --sky-pale: #e0f2fe;
        --sky-ghost: rgba(14, 165, 233, 0.08);
        --sky-border: rgba(14, 165, 233, 0.22);
        --white: #ffffff;
        --font-display: 'Cormorant Garamond', Georgia, serif;
        --font-body: 'DM Sans', system-ui, sans-serif;
        --ease: cubic-bezier(0.22, 1, 0.36, 1);
    }

    .main-content {
        font-family: var(--font-body);
        background: linear-gradient(180deg, var(--white) 0%, var(--sky-pale) 100%);
    }

    .sp-page {
        max-width: 1100px;
        margin: 0 auto;
        padding: 40px 24px 64px;
        animation: spIn 0.45s var(--ease) both;
    }

    @keyframes spIn {
        from { opacity: 0; transform: translateY(16px); }
        to { opacity: 1; transform: translateY(0); }
    }

    .sp-bc {
        display: flex;
        gap: 8px;
        align-items: center;
        margin-bottom: 24px;
        text-transform: uppercase;
        letter-spacing: 0.06em;
        font-size: 11px;
        color: var(--sky-deep);
    }

    .sp-bc a {
        color: var(--sky-deep);
        text-decoration: none;
    }

    .sp-hero {
        background: linear-gradient(135deg, var(--sky-deep) 0%, var(--sky) 65%, var(--sky-light) 100%);
        border-radius: 22px;
        padding: 30px 36px;
        color: var(--white);
        box-shadow: 0 10px 32px rgba(14, 165, 233, 0.28);
        margin-bottom: 24px;
        display: flex;
        justify-content: space-between;
        align-items: center;
        gap: 18px;
    }

    .sp-hero h1 {
        margin: 0;
        font-family: var(--font-display);
        font-size: 40px;
        line-height: 1.05;
    }

    .sp-hero p {
        margin: 6px 0 0;
        font-size: 13px;
        color: rgba(255, 255, 255, 0.94);
    }

    .sp-stat {
        background: rgba(255, 255, 255, 0.18);
        border: 1px solid rgba(255, 255, 255, 0.35);
        border-radius: 14px;
        padding: 14px 20px;
        text-align: center;
        min-width: 140px;
    }

    .sp-stat .val {
        font-family: var(--font-display);
        font-size: 30px;
        line-height: 1;
        font-weight: 700;
    }

    .sp-stat .lab {
        font-size: 11px;
        text-transform: uppercase;
        letter-spacing: 0.08em;
        margin-top: 4px;
    }

    .sp-toolbar {
        display: flex;
        gap: 10px;
        align-items: center;
        margin-bottom: 18px;
        flex-wrap: wrap;
    }

    .sp-btn {
        display: inline-flex;
        align-items: center;
        gap: 7px;
        padding: 10px 16px;
        border-radius: 10px;
        border: 1px solid var(--sky-border);
        text-decoration: none;
        font-size: 13px;
        font-weight: 700;
        transition: all 0.18s var(--ease);
        background: var(--white);
        color: var(--sky-deep);
    }

    .sp-btn.primary {
        background: linear-gradient(135deg, var(--sky-deep), var(--sky));
        color: var(--white);
        border-color: var(--sky-deep);
    }

    .sp-btn:hover {
        transform: translateY(-1px);
        box-shadow: 0 8px 18px rgba(14, 165, 233, 0.22);
    }

    .sp-search {
        margin-left: auto;
        position: relative;
    }

    .sp-search input {
        width: 320px;
        max-width: 100%;
        padding: 10px 14px 10px 34px;
        border: 1px solid var(--sky-border);
        border-radius: 10px;
        background: var(--white);
        color: var(--sky-deep);
        font-size: 13px;
    }

    .sp-search input:focus {
        outline: none;
        border-color: var(--sky);
        box-shadow: 0 0 0 3px rgba(14, 165, 233, 0.14);
    }

    .sp-search .ico {
        position: absolute;
        left: 12px;
        top: 9px;
        color: var(--sky-deep);
    }

    .sp-grid {
        display: grid;
        grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
        gap: 14px;
    }

    .sp-card {
        border: 1px solid var(--sky-border);
        background: var(--white);
        border-radius: 14px;
        padding: 18px;
        text-decoration: none;
        transition: all 0.2s var(--ease);
        box-shadow: 0 4px 14px rgba(14, 165, 233, 0.11);
    }

    .sp-card:hover {
        transform: translateY(-2px);
        background: var(--sky-ghost);
        box-shadow: 0 10px 24px rgba(14, 165, 233, 0.2);
    }

    .sp-card .title {
        margin: 0;
        font-size: 18px;
        color: var(--sky-deep);
        font-family: var(--font-display);
        font-weight: 700;
    }

    .sp-card .desc {
        margin-top: 7px;
        font-size: 12px;
        color: rgba(3, 105, 161, 0.9);
    }

    .sp-empty {
        display: none;
        margin-top: 20px;
        text-align: center;
        padding: 20px;
        border-radius: 12px;
        border: 1px dashed var(--sky-border);
        background: var(--white);
        color: var(--sky-deep);
        font-size: 13px;
    }

    @media (max-width: 768px) {
        .sp-page { padding: 26px 14px 40px; }
        .sp-hero { flex-direction: column; align-items: flex-start; padding: 24px 20px; }
        .sp-hero h1 { font-size: 32px; }
        .sp-stat { width: 100%; }
        .sp-search { margin-left: 0; width: 100%; }
        .sp-search input { width: 100%; }
    }
</style>

<div class="sp-page">
    <nav class="sp-bc">
        <a href="{{ route('modules.edit') }}">Edit Menu</a>
        <span>›</span>
        <span>Suppliers</span>
    </nav>

    <div class="sp-hero">
        <div>
            <h1>Suppliers</h1>
            <p>Configure supplier accounts, categories, and reporting structures.</p>
        </div>
        <div class="sp-stat">
            <div class="val">3</div>
            <div class="lab">Sections</div>
        </div>
    </div>

    <div class="sp-toolbar">
        <a href="{{ route('modules.edit') }}" class="sp-btn">← Back to Edit Menu</a>
        <a href="{{ route('modules.edit.suppliers.accounts') }}" class="sp-btn primary">Open Accounts</a>
        <div class="sp-search">
            <span class="ico">🔍</span>
            <input type="search" id="spSearch" placeholder="Search section...">
        </div>
    </div>

    <div class="sp-grid" id="spGrid">
        <a href="{{ route('modules.edit.suppliers.accounts') }}" class="sp-card" data-search="accounts account supplier accounts">
            <h3 class="title">Accounts</h3>
            <p class="desc">Maintain supplier account records and details.</p>
        </a>

        <a href="{{ route('modules.edit.suppliers.area') }}" class="sp-card" data-search="area areas region regions">
            <h3 class="title">Area</h3>
            <p class="desc">Define supplier areas for filtering and reporting.</p>
        </a>

        <a href="{{ route('modules.edit.suppliers.categories') }}" class="sp-card" data-search="categories category">
            <h3 class="title">Categories</h3>
            <p class="desc">Manage supplier category codes and labels.</p>
        </a>
    </div>

    <div id="spEmpty" class="sp-empty">No matching section found.</div>
</div>

<script>
(() => {
    const input = document.getElementById('spSearch');
    const cards = Array.from(document.querySelectorAll('#spGrid .sp-card'));
    const empty = document.getElementById('spEmpty');

    input.addEventListener('input', function () {
        const q = this.value.trim().toLowerCase();
        let visible = 0;

        cards.forEach((card) => {
            const hit = !q || (card.dataset.search || '').includes(q);
            card.style.display = hit ? '' : 'none';
            if (hit) visible++;
        });

        empty.style.display = visible === 0 ? 'block' : 'none';
    });
})();
</script>
@endsection
