@extends('layouts.master')

@section('title', 'Cases')

@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%);
    }

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

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

    .cs-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);
    }

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

    .cs-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;
    }

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

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

    .cs-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;
    }

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

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

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

    .cs-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);
    }

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

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

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

    .cs-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;
    }

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

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

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

    .cs-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);
    }

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

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

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

    .cs-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) {
        .cs-page { padding: 26px 14px 40px; }
        .cs-hero { flex-direction: column; align-items: flex-start; padding: 24px 20px; }
        .cs-hero h1 { font-size: 32px; }
        .cs-stat { width: 100%; }
        .cs-search { margin-left: 0; width: 100%; }
        .cs-search input { width: 100%; }
    }
</style>

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

    <div class="cs-hero">
        <div>
            <h1>Cases</h1>
            <p>Configure case structure, parties, and supporting metadata.</p>
        </div>
        <div class="cs-stat">
            <div class="val">9</div>
            <div class="lab">Sections</div>
        </div>
    </div>

    <div class="cs-toolbar">
        <a href="{{ route('modules.edit') }}" class="cs-btn">← Back to Edit Menu</a>
        <a href="{{ route('modules.edit.cases-options') }}" class="cs-btn primary">Open Cases</a>
        <div class="cs-search">
            <span class="ico">🔍</span>
            <input type="search" id="csSearch" placeholder="Search section...">
        </div>
    </div>

    <div class="cs-grid" id="csGrid">
        <a href="{{ route('modules.edit.cases-options') }}" class="cs-card" data-search="cases">
            <h3 class="title">Cases</h3>
            <p class="desc">Create and manage case records.</p>
        </a>

        <a href="{{ route('modules.edit.case-parties') }}" class="cs-card" data-search="case parties">
            <h3 class="title">Case Parties</h3>
            <p class="desc">Parties, roles, and case relationships.</p>
        </a>

        <a href="{{ route('modules.edit.case-categories') }}" class="cs-card" data-search="case category categories">
            <h3 class="title">Case Categories</h3>
            <p class="desc">Classification for reporting and grouping.</p>
        </a>

        <a href="{{ route('modules.edit.case-types') }}" class="cs-card" data-search="case type types">
            <h3 class="title">Case Types</h3>
            <p class="desc">Standardize case type definitions.</p>
        </a>

        <a href="{{ route('modules.edit.case-status') }}" class="cs-card" data-search="case status statuses">
            <h3 class="title">Case Status</h3>
            <p class="desc">Define statuses and lifecycle steps.</p>
        </a>

        <a href="{{ route('modules.edit.case-reasons') }}" class="cs-card" data-search="case reasons cancellations">
            <h3 class="title">Case Reasons</h3>
            <p class="desc">Reasons for changes and cancellations.</p>
        </a>

        <a href="{{ route('modules.edit.case-outcomes') }}" class="cs-card" data-search="case outcomes">
            <h3 class="title">Case Outcomes</h3>
            <p class="desc">Outcome codes and result tracking.</p>
        </a>

        <a href="{{ route('modules.edit.case-priorities') }}" class="cs-card" data-search="case priorities priority">
            <h3 class="title">Case Priorities</h3>
            <p class="desc">Priority levels and handling rules.</p>
        </a>

        <a href="{{ route('modules.edit.case-roles') }}" class="cs-card" data-search="case roles role">
            <h3 class="title">Case Roles</h3>
            <p class="desc">Role definitions used across parties.</p>
        </a>
    </div>

    <div id="csEmpty" class="cs-empty">No matching section found.</div>
</div>

<script>
(() => {
    const input = document.getElementById('csSearch');
    const cards = Array.from(document.querySelectorAll('#csGrid .cs-card'));
    const empty = document.getElementById('csEmpty');

    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
