<!DOCTYPE html>
<html lang="ar" dir="rtl">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width,initial-scale=1">
    <meta name="csrf-token" content="{{ csrf_token() }}">
    @if($siteBrand->hasFavicon())
        <link rel="icon" href="{{ $siteBrand->faviconUrl() }}">
    @endif
    <title>{{ $siteBrand->name() }} — تسجيل الدخول</title>
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.11.3/font/bootstrap-icons.css">
    <style>
        *{box-sizing:border-box;margin:0;padding:0}
        body{
            min-height:100vh;
            font-family:-apple-system,BlinkMacSystemFont,'Segoe UI',Tahoma,sans-serif;
            background:#0f0b1e;
            display:flex;align-items:center;justify-content:center;
            overflow:hidden;direction:rtl;
        }

        /* ── خلفية متحركة ── */
        .bg{position:fixed;inset:0;z-index:0;overflow:hidden}
        .bg-blob{
            position:absolute;border-radius:50%;
            filter:blur(80px);opacity:.18;
            animation:blob 10s ease-in-out infinite;
        }
        .b1{width:500px;height:500px;background:#6d28d9;top:-150px;right:-100px;animation-delay:0s}
        .b2{width:400px;height:400px;background:#0f766e;bottom:-100px;left:-100px;animation-delay:3s}
        .b3{width:300px;height:300px;background:#4f46e5;top:40%;left:40%;animation-delay:6s}
        @keyframes blob{
            0%,100%{transform:scale(1) translate(0,0)}
            33%{transform:scale(1.08) translate(20px,-20px)}
            66%{transform:scale(.95) translate(-15px,15px)}
        }

        /* ── الكارد ── */
        .card{
            position:relative;z-index:1;
            width:100%;max-width:420px;
            margin:1.5rem;
            background:rgba(255,255,255,.04);
            backdrop-filter:blur(24px);
            border:1px solid rgba(255,255,255,.1);
            border-radius:28px;
            padding:2.5rem 2rem;
            box-shadow:0 30px 80px rgba(0,0,0,.5);
        }

        /* ── Logo ── */
        .logo{text-align:center;margin-bottom:2rem}
        .logo-icon{
            width:76px;height:76px;
            background:linear-gradient(135deg,#6d28d9,#0f766e);
            border-radius:22px;
            display:inline-flex;align-items:center;justify-content:center;
            font-size:2rem;
            margin-bottom:.9rem;
            box-shadow:0 8px 30px rgba(109,40,217,.4);
            overflow:hidden;
        }
        .logo-icon img{width:100%;height:100%;object-fit:contain;padding:6px}
        .logo-icon--plain{background:rgba(255,255,255,.12);box-shadow:0 8px 30px rgba(0,0,0,.25)}
        .logo h1{color:#fff;font-size:1.55rem;font-weight:800;margin-bottom:.2rem}
        .logo p{color:rgba(255,255,255,.45);font-size:.85rem}

        /* ── Alert ── */
        .alert{
            border-radius:12px;padding:.65rem .9rem;
            font-size:.83rem;margin-bottom:1.2rem;
            display:flex;align-items:center;gap:.5rem;
        }
        .alert-err{background:rgba(239,68,68,.15);border:1px solid rgba(239,68,68,.3);color:#fca5a5}
        .alert-ok{background:rgba(16,185,129,.15);border:1px solid rgba(16,185,129,.3);color:#6ee7b7}

        /* ── Fields ── */
        .field{margin-bottom:1rem}
        .field-label{
            display:block;color:rgba(255,255,255,.65);
            font-size:.78rem;font-weight:600;margin-bottom:.4rem;
        }
        .field-wrap{position:relative}
        .field-icon{
            position:absolute;right:13px;top:50%;
            transform:translateY(-50%);
            color:rgba(255,255,255,.3);font-size:1rem;pointer-events:none;
        }
        .field-input{
            width:100%;padding:.78rem 2.6rem .78rem 1rem;
            background:rgba(255,255,255,.07);
            border:1.5px solid rgba(255,255,255,.12);
            border-radius:14px;
            color:#fff;font-size:.92rem;
            outline:none;transition:border-color .2s,background .2s;
            font-family:inherit;
        }
        .field-input::placeholder{color:rgba(255,255,255,.25)}
        .field-input:focus{
            border-color:rgba(109,40,217,.6);
            background:rgba(255,255,255,.1);
            box-shadow:0 0 0 3px rgba(109,40,217,.15);
        }
        .eye-btn{
            position:absolute;left:13px;top:50%;transform:translateY(-50%);
            background:none;border:none;color:rgba(255,255,255,.3);
            cursor:pointer;font-size:1rem;transition:color .2s;padding:0;
        }
        .eye-btn:hover{color:rgba(255,255,255,.7)}

        /* ── Submit ── */
        .submit-btn{
            width:100%;padding:.88rem;
            background:linear-gradient(135deg,#6d28d9,#7c3aed);
            color:#fff;border:none;border-radius:14px;
            font-weight:700;font-size:1rem;cursor:pointer;
            display:flex;align-items:center;justify-content:center;gap:.5rem;
            margin-top:1.5rem;
            transition:all .2s;
            box-shadow:0 4px 20px rgba(109,40,217,.4);
            font-family:inherit;
        }
        .submit-btn:hover{transform:translateY(-1px);box-shadow:0 6px 28px rgba(109,40,217,.5)}
        .submit-btn:active{transform:scale(.98)}
        .submit-btn:disabled{opacity:.6;cursor:not-allowed;transform:none}

        /* ── Spinner ── */
        .spinner{
            width:18px;height:18px;border:2px solid rgba(255,255,255,.3);
            border-top-color:#fff;border-radius:50%;
            animation:spin .6s linear infinite;display:none;
        }
        @keyframes spin{to{transform:rotate(360deg)}}

        /* ── Hint ── */
        .hint{
            text-align:center;margin-top:1.3rem;
            color:rgba(255,255,255,.35);font-size:.78rem;
        }
        .hint a{color:rgba(255,255,255,.6);text-decoration:none;font-weight:600}
        .hint a:hover{color:#fff}

        /* ── Bottom note ── */
        .roles-note{
            margin-top:1.5rem;padding-top:1.2rem;
            border-top:1px solid rgba(255,255,255,.08);
            display:flex;justify-content:center;gap:.8rem;flex-wrap:wrap;
        }
        .role-chip{
            display:flex;align-items:center;gap:4px;
            color:rgba(255,255,255,.3);font-size:.7rem;
        }
    </style>
</head>
<body>

<div class="bg">
    <div class="bg-blob b1"></div>
    <div class="bg-blob b2"></div>
    <div class="bg-blob b3"></div>
</div>

<div class="card">

    <div class="logo">
        @if($siteBrand->hasLogo())
            <div class="logo-icon logo-icon--plain"><img src="{{ $siteBrand->logoUrl() }}" alt="{{ $siteBrand->name() }}"></div>
        @else
            <div class="logo-icon">🏥</div>
        @endif
        <h1>{{ $siteBrand->name() }}</h1>
        <p>نظام إدارة الطابور الطبي</p>
    </div>

    @if(session('error'))
    <div class="alert alert-err">
        <i class="bi bi-exclamation-circle-fill"></i>
        {{ session('error') }}
    </div>
    @endif

    @if(session('success'))
    <div class="alert alert-ok">
        <i class="bi bi-check-circle-fill"></i>
        {{ session('success') }}
    </div>
    @endif

    <form method="POST" action="{{ route('login.post') }}" onsubmit="handleSubmit(this)">
        @csrf

        <div class="field">
            <label class="field-label">
                رقم الهاتف
            </label>
            <div class="field-wrap">
                <i class="bi bi-phone field-icon"></i>
                <input type="text"
                       name="phone"
                       value="{{ old('phone') }}"
                       class="field-input"
                       placeholder="07xxxxxxxxx"
                       required
                       autofocus
                       inputmode="tel"
                       autocomplete="tel">
            </div>
        </div>

        <p class="hint" style="margin-top:-0.25rem;margin-bottom:0;font-size:.76rem;line-height:1.5;color:rgba(255,255,255,.4)">
            أدخل رقم الهاتف المسجّل — يُحدَّد الدخول تلقائياً (مريض، طبيب، استقبال، إدارة) حسب نوع حسابك.
        </p>

        <button type="submit" class="submit-btn" id="submitBtn">
            <span id="btnText"><i class="bi bi-box-arrow-in-right"></i> دخول</span>
            <div class="spinner" id="btnSpinner"></div>
        </button>
    </form>

    <div class="hint">
        مريض جديد؟
        <a href="{{ route('patient.register') }}">سجّل حساباً مجاناً ←</a>
    </div>

    <div class="roles-note">
        <span class="role-chip">🛡 مدير</span>
        <span class="role-chip">💊 طبيب</span>
        <span class="role-chip">🎧 استقبال</span>
        <span class="role-chip">👤 مريض</span>
    </div>

</div>

<script>
function handleSubmit(form){
    const btn=document.getElementById('submitBtn');
    document.getElementById('btnText').style.display='none';
    document.getElementById('btnSpinner').style.display='block';
    btn.disabled=true;
}
</script>
</body>
</html>
