@extends('dashboard.layout')

@section('title', 'Savings Vault')

@section('content')
<style>
  body { background-color: var(--mob-bg); overflow-x: hidden; }
  
  @media (min-width: 768px) {
    body { max-width: 480px; margin: 0 auto; border-left: 1px solid var(--mob-border); border-right: 1px solid var(--mob-border); box-shadow: 0 0 50px rgba(0,0,0,0.1); position: relative; min-height: 100vh; }
    .mob-bottom-nav, .ios-modal-sheet { max-width: 480px; margin: 0 auto; left: 0; right: 0; }
  }
  
  .vault-header { display: flex; align-items: center; justify-content: space-between; padding: 16px 20px; padding-top: max(20px, env(safe-area-inset-top)); background: var(--mob-bg); position: sticky; top: 0; z-index: 100; }
  .vault-header h1 { margin: 0; font-size: 20px; font-weight: 800; color: var(--mob-text); }
  .btn-back { background: var(--mob-surface); border: 1px solid var(--mob-border); width: 36px; height: 36px; border-radius: 50%; display: flex; align-items: center; justify-content: center; cursor: pointer; color: var(--mob-text); box-shadow: var(--mob-shadow-sm); }
  
  .promo-hero { background: var(--mob-primary); border-radius: var(--mob-radius-lg); padding: 40px 24px; margin: 10px 20px 24px 20px; color: white; text-align: center; box-shadow: var(--mob-shadow-md); position: relative; overflow: hidden; }
  .promo-hero::after { content: ''; position: absolute; top: -50%; left: -50%; width: 200%; height: 200%; background: radial-gradient(circle, rgba(0, 229, 196, 0.15) 0%, transparent 60%); pointer-events: none; }
  .promo-icon-wrap { width: 64px; height: 64px; background: var(--mob-accent); color: var(--mob-primary); border-radius: 20px; display: flex; align-items: center; justify-content: center; margin: 0 auto 20px auto; position: relative; z-index: 1; }
  .promo-hero h2 { font-size: 26px; font-weight: 800; margin: 0 0 12px 0; letter-spacing: -0.5px; position: relative; z-index: 1; }
  .promo-hero p { font-size: 15px; color: rgba(255,255,255,0.8); line-height: 1.5; margin: 0; position: relative; z-index: 1; }

  .feature-list { margin: 0 20px 32px 20px; display: flex; flex-direction: column; gap: 16px; }
  .feature-item { background: var(--mob-surface); border: 1px solid var(--mob-border); border-radius: 16px; padding: 20px; display: flex; gap: 16px; align-items: flex-start; box-shadow: var(--mob-shadow-sm); }
  .feature-icon { width: 40px; height: 40px; border-radius: 12px; background: var(--mob-primary-dim); color: var(--mob-primary); display: flex; align-items: center; justify-content: center; flex-shrink: 0; }
  .feature-icon.premium { background: #fefce8; color: #d97706; }
  .feature-text h4 { margin: 0 0 4px 0; font-size: 15px; font-weight: 700; color: var(--mob-text); }
  .feature-text p { margin: 0; font-size: 13px; color: var(--mob-text-muted); line-height: 1.4; }

  .btn-activate { background: var(--mob-primary); color: white; border: none; padding: 16px 20px; border-radius: 16px; font-weight: 700; font-size: 16px; width: calc(100% - 40px); margin: 0 20px; cursor: pointer; box-shadow: var(--mob-shadow-md); transition: transform 0.2s; display: block; text-align: center; text-decoration: none; }
  .btn-activate:active { transform: scale(0.98); }

  .status-alert { margin: 10px 20px 24px 20px; padding: 20px; border-radius: 16px; display: flex; gap: 16px; align-items: flex-start; }
  .status-alert.review { background: #eff6ff; border: 1px solid #bfdbfe; color: #1e3a8a; }
  .status-alert.error { background: #fef2f2; border: 1px solid #fecaca; color: #991b1b; }
  .status-icon { flex-shrink: 0; margin-top: 2px; }
  .status-alert h4 { margin: 0 0 4px 0; font-size: 15px; font-weight: 700; }
  .status-alert p { margin: 0; font-size: 13px; opacity: 0.9; line-height: 1.4; }

  .mob-avatar-mini {
    width: 36px; height: 36px; background: var(--mob-primary); color: white;
    border-radius: 50%; display: flex; align-items: center; justify-content: center;
    font-weight: 800; font-size: 15px; border: none; outline: none; cursor: pointer;
    box-shadow: var(--mob-shadow-sm); transition: transform 0.2s; flex-shrink: 0;
  }
  .mob-avatar-mini:active { transform: scale(0.95); }

  .mob-profile-menu { position: fixed; inset: 0; background-color: #051024; color: white; z-index: 9999; transform: translateY(100%); transition: transform 0.4s cubic-bezier(0.16, 1, 0.3, 1); display: none; flex-direction: column; overflow: hidden; }
  .mob-profile-menu.open { transform: translateY(0); }
  .mob-profile-menu::before { content: ''; position: absolute; top: -10%; left: -10%; width: 60vh; height: 60vh; background: radial-gradient(circle, rgba(0, 229, 196, 0.35) 0%, rgba(0, 229, 196, 0) 70%); animation: floatCyan 8s ease-in-out infinite alternate; z-index: 0; pointer-events: none; }
  .mob-profile-menu::after { content: ''; position: absolute; bottom: -10%; right: -10%; width: 60vh; height: 60vh; background: radial-gradient(circle, rgba(225, 20, 130, 0.3) 0%, rgba(225, 20, 130, 0) 70%); animation: floatPink 10s ease-in-out infinite alternate; z-index: 0; pointer-events: none; }
  @keyframes floatCyan { 0% { transform: translate(0, 0) scale(1); } 100% { transform: translate(15%, 15%) scale(1.2); } }
  @keyframes floatPink { 0% { transform: translate(0, 0) scale(1); } 100% { transform: translate(-15%, -15%) scale(1.2); } }
  
  .profile-menu-content-wrapper { position: relative; z-index: 1; display: flex; flex-direction: column; height: 100%; }
  .profile-menu-header { padding: 20px; padding-top: max(20px, env(safe-area-inset-top)); display: flex; justify-content: space-between; align-items: center; }
  .profile-menu-header .brand { font-size: 20px; font-weight: 800; letter-spacing: -0.5px; color: white; }
  
  .profile-menu-header button { background: transparent; border: none; color: white; display: flex; align-items: center; justify-content: center; cursor: pointer; padding: 4px; margin-right: -4px; outline: none; transition: transform 0.2s; }
  .profile-menu-header button:active { transform: scale(0.9); }
  
  .profile-menu-body { padding: 0 20px; flex: 1; overflow-y: auto; padding-bottom: 40px; }
  
  .profile-avatar-modal { width: 88px; height: 88px; background: var(--mob-accent); color: var(--mob-primary); border-radius: 50%; margin: 0 auto 16px; display: flex; align-items: center; justify-content: center; font-size: 32px; font-weight: 800; box-shadow: 0 8px 24px rgba(0, 229, 196, 0.3); }
  .profile-name { text-align: center; font-size: 26px; font-weight: 800; margin-bottom: 4px; letter-spacing: -0.5px; color: white; }
  .profile-handle { text-align: center; color: rgba(255,255,255,0.6); font-size: 14px; margin-bottom: 32px; font-weight: 500; }
  
  .profile-list { background: rgba(255, 255, 255, 0.04); backdrop-filter: blur(24px); -webkit-backdrop-filter: blur(24px); border-radius: 20px; overflow: hidden; margin-bottom: 16px; border: 1px solid rgba(255, 255, 255, 0.08); box-shadow: 0 10px 30px rgba(0,0,0,0.2); }
  .profile-list-item { padding: 18px 20px; display: flex; align-items: center; gap: 16px; color: white; text-decoration: none; font-weight: 600; font-size: 15px; border-bottom: 1px solid rgba(255,255,255,0.05); cursor: pointer; }
  .profile-list-item:last-child { border-bottom: none; }
  .profile-list-item svg { width: 20px; height: 20px; color: rgba(255,255,255,0.6); stroke-width: 2px; }

  .mob-nav-icon svg { width: 24px; height: 24px; stroke-width: 2px; margin-bottom: 2px; }
</style>

<header class="vault-header">
  <div style="display: flex; align-items: center; gap: 12px;">
    <a href="{{ route('dashboard') }}" class="btn-back"><i data-lucide="arrow-left" style="width: 18px;"></i></a>
    <h1>Savings Vault</h1>
  </div>
  
  <div style="display: flex; gap: 8px; align-items: center;">
    <button class="mob-avatar-mini" onclick="openProfileMenu()">
      {{ strtoupper(substr($user->name, 0, 1)) }}
    </button>
  </div>
</header>

<main class="mob-main-content" style="padding-top: 0; padding-bottom: 100px;">

  
    <div class="promo-hero">
      <div class="promo-icon-wrap">
        <i data-lucide="piggy-bank" style="width: 32px; height: 32px; stroke-width: 2.5px;"></i>
      </div>
      
      <h2>Make your money work harder.</h2>
      <p>Earn industry-leading daily interest on your idle EUR balance with our High-Yield Vaults.</p>
    </div>
    
    <div class="feature-list">
      <div class="feature-item">
        <div class="feature-icon"><i data-lucide="trending-up"></i></div>
        <div class="feature-text">
          <h4>Top-Tier Yields</h4>
          <p>High yields paid out monthly directly to your savings.</p>
        </div>
      </div>
      <div class="feature-item">
        <div class="feature-icon"><i data-lucide="zap"></i></div>
        <div class="feature-text">
          <h4>Instant Transfers</h4>
          <p>Move money instantly between accounts with no locking periods.</p>
        </div>
      </div>
      <div class="feature-item">
        <div class="feature-icon premium"><i data-lucide="crown"></i></div>
        <div class="feature-text">
          <h4>Premium Upgrades</h4>
          <p>Upgrade to Premium for exclusive APY yield advantages.</p>
        </div>
      </div>
    </div>

    
      <div class="status-alert error">
        <div class="status-icon"><i data-lucide="alert-triangle"></i></div>
        <div>
          <h4>Verification Required</h4>
          <p>You must fully verify your main account before applying for a vault.</p>
        </div>
      </div>
    

</main>

<div id="profileMenu" class="mob-profile-menu">
  <div class="profile-menu-content-wrapper">
    <div class="profile-menu-header">
      <div class="brand">Clear.Bank</div>
      <button onclick="closeProfileMenu()">
        <i data-lucide="x" style="width: 20px; height: 20px;"></i>
      </button>
    </div>
    
    <div class="profile-menu-body">
      <div class="profile-avatar-modal">{{ strtoupper(substr($user->name, 0, 1)) }}</div>
      <div class="profile-name">{{ $user->name }}</div>
      <div class="profile-handle">@username</div>
      
      <div class="profile-list">
        <a href="{{ route('profile') }}" class="profile-list-item" onclick="closeProfileMenu()">
          <i data-lucide="user"></i>
          <span>Personal Details</span>
        </a>
        <a href="{{ route('account') }}" class="profile-list-item" onclick="closeProfileMenu()">
          <i data-lucide="credit-card"></i>
          <span>Accounts</span>
        </a>
        <a href="{{ route('hisa') }}" class="profile-list-item" onclick="closeProfileMenu()">
          <i data-lucide="piggy-bank"></i>
          <span>Savings Vault</span>
        </a>
        <a href="{{ route('transfers') }}" class="profile-list-item" onclick="closeProfileMenu()">
          <i data-lucide="arrow-right-left"></i>
          <span>Transactions</span>
        </a>
      </div>

      <div class="profile-list">
        <a href="{{ route('support') }}" class="profile-list-item" onclick="closeProfileMenu()">
          <i data-lucide="headphones"></i>
          <span>Support</span>
        </a>
        <form method="POST" action="{{ route('logout') }}" id="logout-form" style="display: none;">@csrf</form>
        <a href="#" class="profile-list-item" onclick="event.preventDefault(); document.getElementById('logout-form').submit(); closeProfileMenu();">
          <i data-lucide="log-out"></i>
          <span>Log Out</span>
        </a>
      </div>
    </div>
  </div>
</div>

<nav class="mob-bottom-nav">
  <a href="{{ route('dashboard') }}" class="mob-nav-link">
    <span class="mob-nav-icon"><i data-lucide="home"></i></span>
    Home
  </a>
  <a href="{{ route('account') }}" class="mob-nav-link">
    <span class="mob-nav-icon"><i data-lucide="credit-card"></i></span>
    Accounts
  </a>
  <a href="{{ route('transfers') }}" class="mob-nav-link">
    <span class="mob-nav-icon"><i data-lucide="arrow-right-left"></i></span>
    Transactions
  </a>
  <a href="{{ route('support') }}" class="mob-nav-link">
    <span class="mob-nav-icon"><i data-lucide="headphones"></i></span>
    Support
  </a>
</nav>

<script>
  lucide.createIcons();
  const fiatBal = 0;
  const hisaBal = 0;
  
  function updateRoute() {
    const route = document.getElementById('routeSelect').value;
    const from = document.getElementById('from_account');
    const to = document.getElementById('to_account');
    const avail = document.getElementById('availableText');
    if (route === 'to_hisa') {
      from.value = 'main';
      to.value = 'hisa';
      avail.innerText = `€${fiatBal.toLocaleString('en-US', {minimumFractionDigits: 2})}`;
    } else {
      from.value = 'hisa';
      to.value = 'main';
      avail.innerText = `€${hisaBal.toLocaleString('en-US', {minimumFractionDigits: 2})}`;
    }
  }

  let deferredPrompt;
  const isIOS = /iPad|iPhone|iPod/.test(navigator.userAgent) && !window.MSStream;
  const isStandalone = window.matchMedia('(display-mode: standalone)').matches || window.navigator.standalone;
  if (!isStandalone) {
    if (isIOS) {
      document.querySelectorAll('.pwa-install-btn').forEach(btn => { btn.style.display = 'flex'; });
    } else {
      window.addEventListener('beforeinstallprompt', (e) => {
        e.preventDefault();
        deferredPrompt = e;
        document.querySelectorAll('.pwa-install-btn').forEach(btn => { btn.style.display = 'flex'; });
      });
    }
  }

  function triggerInstall() {
    if (isIOS) {
      document.getElementById('iosModalOverlay').classList.add('open');
      setTimeout(() => document.getElementById('iosModalSheet').classList.add('open'), 10);
    } else if (deferredPrompt) {
      deferredPrompt.prompt();
      deferredPrompt.userChoice.then((choiceResult) => { deferredPrompt = null; });
    }
  }

  function closeIOSModal() {
    document.getElementById('iosModalSheet').classList.remove('open');
    setTimeout(() => document.getElementById('iosModalOverlay').classList.remove('open'), 300);
  }

  function openProfileMenu() { document.getElementById('profileMenu').classList.add('open'); }
  function closeProfileMenu() { document.getElementById('profileMenu').classList.remove('open'); }
</script>
@endsection
