<!DOCTYPE html>
<html lang="bn">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    

      @php
      $companySetup = \App\Models\CompanySetup::first();
      $currentUser  = auth()->user(); // ✅ current logged-in user
  @endphp
  <title>{{ $companySetup->company_name }}</title>
 <link rel="icon" href="{{ asset('storage/' . $companySetup->fav_icon) }}" type="image/png">

    {{-- Google Fonts --}}
    <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=Inter:wght@400;500;600;700&family=Noto+Sans+Bengali:wght@400;500;600;700&display=swap" rel="stylesheet">

    {{-- Bootstrap Icons --}}
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.11.3/font/bootstrap-icons.css">

    <style>
        :root{
            --primary:#EA4643;
            --primary-soft:#ffe3e2;
            --bg:#020617;
            --card-bg:#ffffff;
            --border-soft:#f3d4d2;
            --border:#e5e7eb;
            --text-main:#111827;
            --text-muted:#6b7280;
        }

        *{ box-sizing:border-box; }

        body{
            margin:0;
            min-height:100vh;
            font-family:'Noto Sans Bengali','Inter',system-ui,-apple-system,BlinkMacSystemFont,'Segoe UI',Roboto,sans-serif;
            background:radial-gradient(circle at top, #1f2937 0, #020617 48%, #000 100%);
            color:var(--text-main);
        }

        .auth-wrapper{
            min-height:100vh;
            display:flex;
            align-items:center;
            justify-content:center;
            padding:24px 16px;
            position:relative;
            overflow:hidden;
        }

        .bg-shape{
            position:absolute;
            z-index:0;
            opacity:0.7;
        }
        .bg-shape-1{
            top:-120px;
            left:-80px;
            width:340px;
            animation: float1 18s ease-in-out infinite alternate;
        }
        .bg-shape-2{
            bottom:-140px;
            right:-60px;
            width:280px;
            animation: float2 20s ease-in-out infinite alternate;
        }

        @keyframes float1{
            0%{ transform:translate3d(0,0,0) scale(1); }
            100%{ transform:translate3d(36px,40px,0) scale(1.08); }
        }
        @keyframes float2{
            0%{ transform:translate3d(0,0,0) scale(1); }
            100%{ transform:translate3d(-34px,-30px,0) scale(1.05); }
        }

        .login-card{
            position:relative;
            z-index:1;
            width:100%;
            max-width:440px;
            background:radial-gradient(circle at top,#fff5f5,#ffffff 55%);
            border-radius:28px;
            padding:26px 26px 22px;
            box-shadow:0 18px 55px rgba(15,23,42,.5);
            border:1px solid rgba(255,255,255,.9);
            backdrop-filter:blur(12px);
        }

        .login-card::before{
            content:"";
            position:absolute;
            inset:-1px;
            border-radius:inherit;
            background:linear-gradient(135deg,rgba(234,70,67,.45),rgba(248,250,252,0),rgba(79,70,229,.45));
            z-index:-1;
            opacity:.18;
        }

        .logo{
            display:flex;
            align-items:center;
            gap:12px;
            margin-bottom:12px;
        }

        .logo-circle{
            width:54px;
            height:54px;
            border-radius:18px;
            border:1.5px solid rgba(234,70,67,.45);
            background:radial-gradient(circle at 0 0,#ffe8e7,#ffffff);
            display:flex;
            align-items:center;
            justify-content:center;
            box-shadow:0 10px 28px rgba(234,70,67,.4);
            overflow:hidden;
        }
        .logo-circle img{
            width:78%;
            height:auto;
            display:block;
        }

        .logo-text-main{
            font-size:19px;
            font-weight:700;
            letter-spacing:.03em;
            color:#111827;
        }

        .title{
            font-size:20px;
            font-weight:700;
            margin:6px 0 4px;
            color:#111827;
        }
        .subtitle{
            font-size:13px;
            color:var(--text-muted);
            margin-bottom:18px;
        }

        .alert-error{
            border-radius:12px;
            padding:9px 11px;
            font-size:13px;
            background:#fef2f2;
            color:#b91c1c;
            border:1px solid #fecaca;
            display:flex;
            align-items:flex-start;
            gap:8px;
            margin-bottom:14px;
        }
        .alert-error i{
            margin-top:1px;
        }

        .input-group{
            margin-bottom:16px;
        }
        .input-group.has-error .phone-combo{
            border-color:#fecaca;
            background:#fef2f2;
            box-shadow:0 0 0 1px rgba(248,113,113,.35);
        }
        .input-group.has-error .input-wrap input,
        .input-group.has-error .input-wrap select{
            border-color:#fecaca;
            background:#fef2f2;
        }

        .input-label{
            font-size:13px;
            margin-bottom:6px;
            color:#4b5563;
            display:flex;
            align-items:center;
            gap:6px;
        }
        .input-label i{
            font-size:15px;
            color:var(--primary);
        }

        .input-wrap{
            position:relative;
        }

        .input-icon{
            position:absolute;
            left:14px;
            top:50%;
            transform:translateY(-50%);
            font-size:18px;
            color:#a3a3a3;
        }

        .input-wrap input,
        .input-wrap select{
            width:100%;
            padding:11px 14px 11px 44px;
            border-radius:999px;
            border:1px solid var(--border);
            font-size:15px;
            background:#ffffff;
            transition:border-color .18s, box-shadow .18s, background .18s, transform .08s;
            -webkit-appearance:none;
               -moz-appearance:none;
                    appearance:none;
        }

        .input-wrap select{
            cursor:pointer;
            background-image:url("data:image/svg+xml;charset=UTF-8,%3csvg xmlns='http://www.w3.org/2000/svg' width='20' height='20' viewBox='0 0 16 16'%3e%3cpath fill='%23a3a3a3' d='M3.2 5.5 8 10.3l4.8-4.8.7.7L8 11.7 2.5 6.2z'/%3e%3c/svg%3e");
            background-repeat:no-repeat;
            background-position:right 16px center;
            background-size:14px;
        }

        .input-wrap input::placeholder{
            color:#a3a3a3;
        }

        .input-wrap input:focus,
        .input-wrap select:focus{
            outline:none;
            border-color:var(--primary);
            box-shadow:0 0 0 1px rgba(234,70,67,.18),0 10px 24px rgba(15,23,42,.12);
            background:#ffffff;
        }

        .error-text{
            color:#dc2626;
            font-size:12px;
            margin-top:4px;
        }

        /* ফোন + country code combo */
        .phone-combo{
            position:relative;
            display:flex;
            align-items:center;
            gap:10px;
            padding:6px 12px;
            border-radius:999px;
            border:1px solid var(--border);
            background:linear-gradient(to right,#fffefd,#fff);
            transition:border-color .18s, box-shadow .18s, background .18s, transform .08s;
        }
        .phone-combo:hover{
            border-color:var(--primary-soft);
            background:linear-gradient(to right,#fff7f6,#ffffff);
        }
        .phone-combo:focus-within{
            outline:none;
            border-color:var(--primary);
            box-shadow:0 0 0 1px rgba(234,70,67,.18),0 10px 24px rgba(15,23,42,.12);
            background:#ffffff;
        }

        .phone-combo .code-box,
        .phone-combo .number-box{
            display:flex;
            align-items:center;
        }

        .phone-combo .code-box{
            padding-right:10px;
            margin-right:4px;
            border-right:1px solid var(--border-soft);
            min-width:120px;
        }

        .phone-combo .code-box i,
        .phone-combo .number-box i{
            font-size:15px;
            color:#9ca3af;
            margin-right:6px;
        }

        .phone-combo input{
            border:none;
            background:transparent;
            padding:6px 4px;
            font-size:14px;
            outline:none;
            box-shadow:none;
            width:100%;
        }
        .phone-combo input::placeholder{
            color:#a3a3a3;
        }

        .error-row{
            margin-top:4px;
            display:flex;
            flex-direction:column;
            gap:2px;
        }

        .register-btn{
            width:100%;
            padding:13px;
            border:none;
            border-radius:999px;
            font-size:16px;
            font-weight:600;
            color:#ffffff;
            background:linear-gradient(135deg,#ff7b76,#EA4643);
            cursor:pointer;
            display:flex;
            align-items:center;
            justify-content:center;
            gap:8px;
            margin-top:4px;
            margin-bottom:16px;
            box-shadow:0 14px 30px rgba(234,70,67,.5);
            transition:transform .16s, box-shadow .16s, filter .16s;
        }
        .register-btn i{
            font-size:18px;
        }
        .register-btn:hover{
            transform:translateY(-1px);
            box-shadow:0 18px 40px rgba(185,28,28,.6);
            filter:brightness(1.03);
        }
        .register-btn:active{
            transform:translateY(0);
            box-shadow:0 10px 26px rgba(185,28,28,.5);
        }

        .login-text{
            text-align:center;
            font-size:13px;
            color:#6b7280;
        }
        .login-text a{
            color:var(--primary);
            font-weight:600;
            text-decoration:none;
        }
        .login-text a:hover{
            text-decoration:underline;
        }

        /* ✅ Searchable country dropdown */
        .country-select{
            position:absolute;
            opacity:0;
            pointer-events:none;
            width:0;
            height:0;
        }

        .country-select-wrapper{
            position:relative;
            min-width:90px;
        }

        .country-display{
            display:flex;
            align-items:center;
            justify-content:space-between;
            cursor:pointer;
            gap:6px;
            min-width:0;
        }

        .country-display-text{
            font-size:13px;
            color:#111827;
            white-space:nowrap;
        }

        .country-display i{
            font-size:12px;
            color:#9ca3af;
        }

        .country-panel{
            position:absolute;
            z-index:30;
            top:115%;
            left:-8px;
            right:-8px;
            background:#ffffff;
            border-radius:16px;
            border:1px solid #e5e7eb;
            box-shadow:0 18px 35px rgba(15,23,42,.22);
            padding:6px 8px 8px;
            display:none;
        }
        .country-panel.is-open{
            display:block;
        }

        .country-search{
            width:100%;
            border-radius:999px;
            border:1px solid #e5e7eb;
            font-size:12px;
            padding:6px 10px;
            outline:none;
            margin-bottom:6px;
        }
        .country-search:focus{
            border-color:var(--primary);
            box-shadow:0 0 0 1px rgba(234,70,67,.18);
        }

        .country-list{
            max-height:220px;
            overflow-y:auto;
            padding-right:2px;
        }

        .country-item{
            font-size:12px;
            padding:5px 9px;
            border-radius:999px;
            cursor:pointer;
            display:flex;
            align-items:center;
            justify-content:space-between;
        }
        .country-item span{
            white-space:nowrap;
        }
        .country-item:hover{
            background:#fee2e2;
        }
        .country-item.is-active{
            background:#f97373;
            color:#ffffff;
        }

        @media (max-width:480px){
            .login-card{
                padding:22px 18px 20px;
                border-radius:22px;
            }
            .phone-combo .code-box{
                min-width:110px;
            }
        }
    </style>
</head>
<body>
    <div class="auth-wrapper">

        <svg class="bg-shape bg-shape-1" viewBox="0 0 400 400" xmlns="http://www.w3.org/2000/svg" aria-hidden="true">
            <defs>
                <linearGradient id="regGrad1" x1="0" y1="0" x2="1" y2="1">
                    <stop offset="0%" stop-color="#EA4643"/>
                    <stop offset="50%" stop-color="#fb7185"/>
                    <stop offset="100%" stop-color="#4f46e5"/>
                </linearGradient>
            </defs>
            <circle cx="200" cy="200" r="190" fill="url(#regGrad1)" />
        </svg>

        <svg class="bg-shape bg-shape-2" viewBox="0 0 400 400" xmlns="http://www.w3.org/2000/svg" aria-hidden="true">
            <defs>
                <linearGradient id="regGrad2" x1="1" y1="0" x2="0" y2="1">
                    <stop offset="0%" stop-color="#f97316"/>
                    <stop offset="40%" stop-color="#EA4643"/>
                    <stop offset="100%" stop-color="#0ea5e9"/>
                </linearGradient>
            </defs>
            <path d="M60,40 C140,-10 320,20 360,160 C390,260 320,360 200,360 C90,360 10,300 20,200 C30,120 10,70 60,40 Z"
                  fill="url(#regGrad2)" />
        </svg>

        <div class="login-card">
            <div class="logo">
                <div class="logo-circle">
                      @php $companySetup = \App\Models\CompanySetup::first(); @endphp
                    <img src="{{ $companySetup?->logo ? asset('storage/' . $companySetup->logo) : asset('images/default-logo.png') }}"
                        alt="Logo">
                </div>
                <div>
                    <div class="logo-text-main">Ecarbd</div>
                </div>
            </div>

            <h2 class="title">একাউন্ট তৈরি করুন</h2>
            <p class="subtitle">কিছু তথ্য দিয়ে খুব সহজেই আপনার Ecarbd একাউন্ট খুলে নিন।</p>

            @if ($errors->any())
                <div class="alert-error">
                    <i class="bi bi-exclamation-triangle-fill"></i>
                    <span>{{ $errors->first() }}</span>
                </div>
            @endif

            <form action="{{ route('register') }}" method="POST">
                @csrf

                {{-- পূর্ণ নাম --}}
                <div class="input-group @error('name') has-error @enderror">
                    <label class="input-label">
                        <i class="bi bi-person"></i>
                        <span>পূর্ণ নাম</span>
                    </label>
                    <div class="input-wrap">
                        <i class="bi bi-person-circle input-icon"></i>
                        <input
                            type="text"
                            name="name"
                            value="{{ old('name') }}"
                            placeholder="পূর্ণ নাম লিখুন"
                            required
                        >
                    </div>
                    @error('name')
                        <div class="error-text">{{ $message }}</div>
                    @enderror
                </div>

                {{-- ভূমিকা / রোল --}}
                <div class="input-group @error('role') has-error @enderror">
                    <label class="input-label">
                        <i class="bi bi-person-badge"></i>
                        <span>ভূমিকা</span>
                    </label>
                    <div class="input-wrap">
                        <i class="bi bi-people input-icon"></i>
                        <select name="role" required>
                            <option value="" disabled {{ old('role') ? '' : 'selected' }} hidden>ভূমিকা নির্বাচন করুন</option>
                            <option value="student"  {{ old('role') == 'student'  ? 'selected' : '' }}>ছাত্র/ছাত্রী</option>
                            <option value="teacher"  {{ old('role') == 'teacher'  ? 'selected' : '' }}>শিক্ষক</option>
                            <option value="guardian" {{ old('role') == 'guardian' ? 'selected' : '' }}>অভিভাবক</option>
                            <option value="business" {{ old('role') == 'business' ? 'selected' : '' }}>ব্যবসায়ী</option>
                            <option value="employee" {{ old('role') == 'employee' ? 'selected' : '' }}>কর্মচারী</option>
                            <option value="other"    {{ old('role') == 'other'    ? 'selected' : '' }}>অন্যান্য</option>
                        </select>
                    </div>
                    @error('role')
                        <div class="error-text">{{ $message }}</div>
                    @enderror
                </div>

                {{-- মোবাইল নম্বর + কান্ট্রি কোড (login-এর মতোই) --}}
                <div class="input-group @error('country_code') has-error @enderror @error('phone') has-error @enderror">
                    <label class="input-label">
                        <i class="bi bi-phone"></i>
                        <span>মোবাইল নম্বর</span>
                    </label>

                    <div class="phone-combo">
                        <div class="code-box">
                            <i class="bi bi-globe"></i>

                            {{-- আসল select (hidden) + custom searchable dropdown --}}
                            <div class="country-select-wrapper">
                                <select name="country_code" class="country-select" required>
                                    <option value="" disabled {{ old('country_code') ? '' : 'selected' }} hidden>কোড</option>

                                    @if(isset($countries) && count($countries))
                                        @foreach($countries as $country)
                                            @foreach($country['codes'] as $code)
                                                <option value="{{ $code }}" {{ old('country_code') == $code ? 'selected' : '' }}>
                                                    {{ strtoupper($country['short'] ?? '') }} {{ $code }}
                                                </option>
                                            @endforeach
                                        @endforeach
                                    @else
                                        <option value="+880" {{ old('country_code') == '+880' ? 'selected' : '' }}>BD +880</option>
                                        <option value="+91"  {{ old('country_code') == '+91'  ? 'selected' : '' }}>IN +91</option>
                                        <option value="+92"  {{ old('country_code') == '+92'  ? 'selected' : '' }}>PK +92</option>
                                    @endif
                                </select>

                                <div class="country-display">
                                    <span class="country-display-text">কোড</span>
                                    <i class="bi bi-chevron-down"></i>
                                </div>

                                <div class="country-panel">
                                    <input type="text" class="country-search" placeholder="দেশ / কোড সার্চ করুন">
                                    <div class="country-list"></div>
                                </div>
                            </div>
                        </div>

                        <div class="number-box">
                            <i class="bi bi-telephone"></i>
                            <input
                                type="tel"
                                name="phone"
                                value="{{ old('phone') }}"
                                placeholder="মোবাইল নম্বর"
                                required
                            >
                        </div>
                    </div>

                    <div class="error-row">
                        @error('country_code')
                            <div class="error-text">{{ $message }}</div>
                        @enderror
                        @error('phone')
                            <div class="error-text">{{ $message }}</div>
                        @enderror
                    </div>
                </div>

                {{-- পাসওয়ার্ড --}}
                <div class="input-group @error('password') has-error @enderror">
                    <label class="input-label">
                        <i class="bi bi-shield-lock"></i>
                        <span>পাসওয়ার্ড</span>
                    </label>
                    <div class="input-wrap">
                        <i class="bi bi-lock input-icon"></i>
                        <input
                            type="password"
                            name="password"
                            placeholder="পাসওয়ার্ড (ন্যূনতম ৬ অক্ষর)"
                            required
                        >
                    </div>
                    @error('password')
                        <div class="error-text">{{ $message }}</div>
                    @enderror
                </div>

                <button type="submit" class="register-btn">
                    <i class="bi bi-person-plus"></i>
                    <span>রেজিস্ট্রেশন সম্পন্ন করুন</span>
                </button>
            </form>

            <div class="login-text">
                আগে একাউন্ট আছে? <a href="{{ route('login') }}">লগইন করুন</a>
            </div>
        </div>
    </div>

    <script>
        // ✅ Searchable country dropdown logic (login এর মতোই)
        document.addEventListener('DOMContentLoaded', function () {
            document.querySelectorAll('.country-select').forEach(function (select) {
                const wrapper = select.closest('.country-select-wrapper');
                const display = wrapper.querySelector('.country-display');
                const displayText = wrapper.querySelector('.country-display-text');
                const panel = wrapper.querySelector('.country-panel');
                const search = wrapper.querySelector('.country-search');
                const list = wrapper.querySelector('.country-list');

                function buildList() {
                    list.innerHTML = '';
                    Array.from(select.options).forEach(function (opt) {
                        if (!opt.value) return; // placeholder বাদ
                        const item = document.createElement('div');
                        item.className = 'country-item';
                        item.dataset.value = opt.value;
                        item.innerHTML = '<span>' + opt.textContent.trim() + '</span>';
                        if (opt.selected) {
                            item.classList.add('is-active');
                        }
                        list.appendChild(item);
                    });
                }

                function setFromSelect() {
                    const opt = select.options[select.selectedIndex];
                    if (opt && opt.value) {
                        displayText.textContent = opt.textContent.trim();
                    } else {
                        displayText.textContent = 'কোড';
                    }
                }

                buildList();
                setFromSelect();

                // open / close
                display.addEventListener('click', function (e) {
                    e.stopPropagation();
                    const open = panel.classList.contains('is-open');
                    document.querySelectorAll('.country-panel.is-open').forEach(p => p.classList.remove('is-open'));
                    if (!open) {
                        panel.classList.add('is-open');
                        search.value = '';
                        list.querySelectorAll('.country-item').forEach(function (item) {
                            item.style.display = '';
                        });
                        search.focus();
                    }
                });

                // search filter
                search.addEventListener('input', function () {
                    const q = this.value.toLowerCase();
                    list.querySelectorAll('.country-item').forEach(function (item) {
                        item.style.display = item.textContent.toLowerCase().includes(q) ? '' : 'none';
                    });
                });

                // select item
                list.addEventListener('click', function (e) {
                    const item = e.target.closest('.country-item');
                    if (!item) return;
                    const val = item.dataset.value;

                    select.value = val;
                    Array.from(select.options).forEach(function (o) {
                        o.selected = (o.value === val);
                    });

                    list.querySelectorAll('.country-item').forEach(i => i.classList.remove('is-active'));
                    item.classList.add('is-active');

                    setFromSelect();
                    panel.classList.remove('is-open');
                });

                // বাইরে ক্লিক করলে panel বন্ধ
                document.addEventListener('click', function () {
                    panel.classList.remove('is-open');
                });
            });
        });
    </script>
</body>
</html>
