@extends('dashboard.layout')

@section('title', 'Home')

@section('content')
<style>
  body { background-color: var(--mob-bg); }
  
  @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, .toast-notif, .ios-modal-sheet { max-width: 480px; margin: 0 auto; left: 0; right: 0; }
  }
  
  .mob-header-custom { display: flex; align-items: center;
    padding: 16px 20px; padding-top: max(20px, env(safe-area-inset-top)); gap: 16px; justify-content: space-between; }
  .mob-greeting { display: flex; flex-direction: column;
    justify-content: center; }
  .mob-greeting-sub { font-size: 13px; color: var(--mob-text-muted); font-weight: 600; text-transform: uppercase; letter-spacing: 0.5px;
  }
  .mob-greeting-name { font-size: 18px; font-weight: 800; letter-spacing: -0.5px; color: var(--mob-text); line-height: 1.2;
    margin-top: 2px;}

  .mob-action-row-centered { display: flex; justify-content: space-evenly; padding: 0 10px; margin-bottom: 40px; margin-top: 10px;
  }
  .mob-action-item { display: flex; flex-direction: column; align-items: center; gap: 8px; text-decoration: none; color: var(--mob-text);
  }
  .mob-action-circle { width: 56px; height: 56px; background: var(--mob-surface); border-radius: 50%; display: flex; align-items: center; justify-content: center;
    color: var(--mob-primary); box-shadow: var(--mob-shadow-md); transition: transform 0.2s; border: 1px solid var(--mob-border); }
  .mob-action-circle:active { transform: scale(0.95);
  }
  .mob-action-circle svg { width: 24px; height: 24px; stroke-width: 2px;
  }
  .mob-action-label { font-size: 13px; font-weight: 600; }
  .mob-nav-icon svg { width: 24px;
    height: 24px; stroke-width: 2px; margin-bottom: 2px; }

  .mob-main-content { padding-top: 0; padding-bottom: 100px; }

  .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; }
</style>

<header class="mob-header-custom">
  <div style="display: flex; align-items: center; gap: 12px;">
    <div class="mob-greeting">
      <span class="mob-greeting-sub">Welcome back,</span>
      <strong class="mob-greeting-name">{{ $user->name }}</strong>
    </div>
  </div>
  
  <div style="display: flex; gap: 12px; align-items: center;">
    <button class="mob-avatar-mini" onclick="openProfileMenu()">
      {{ strtoupper(substr($user->name, 0, 1)) }}
    </button>
  </div>
</header>

<main class="mob-main-content">
  
  <div style="margin-top: 20px; margin-bottom: 40px; text-align: center;">
    <div style="font-size: 14px; font-weight: 600; color: var(--mob-text-muted);">Total Balance · EUR</div>
    <div style="font-size: 56px; font-weight: 800; letter-spacing: -1px; margin-bottom: 16px; color: var(--mob-text);">
      €{{ number_format($totalBalance, 2) }}
    </div>
    <button style="background: var(--mob-primary-dim); color: var(--mob-primary); border: none; padding: 10px 24px; border-radius: 20px; font-weight: 700; font-size: 14px; cursor: pointer;">Active Accounts</button>
  </div>

  <div class="mob-action-row-centered">
    <a href="{{ route('receive') }}" class="mob-action-item">
      <div class="mob-action-circle"><i data-lucide="plus"></i></div>
      <span class="mob-action-label">Add money</span>
    </a>
    
    <a href="{{ route('send') }}" class="mob-action-item">
      <div class="mob-action-circle"><i data-lucide="arrow-right-left"></i></div>
      <span class="mob-action-label">Make a payment</span>
    </a>

    <a href="{{ route('account') }}" class="mob-action-item">
      <div class="mob-action-circle"><i data-lucide="more-horizontal"></i></div>
      <span class="mob-action-label">Details</span>
    </a>
  </div>

  <div style="display: flex; justify-content: space-between; padding: 0 20px 14px 20px; align-items: center;">
    <h3 style="margin: 0; font-size: 18px; font-weight: 800; color: var(--mob-text); letter-spacing: -0.5px;">Recent transactions</h3>
  </div>

  <div style="background: var(--mob-surface);
    border-radius: var(--mob-radius-lg); border: 1px solid var(--mob-border); margin: 0 20px 24px 20px; padding: 12px 20px;
    box-shadow: var(--mob-shadow-sm);">
    
    @forelse ($recentTransactions as $tx)
      <div style="padding: 12px 0; border-bottom: 1px solid var(--mob-border); display: flex; justify-content: space-between; align-items: center;">
        <div>
          <div style="font-weight: 700; font-size: 15px; color: var(--mob-text);">{{ $tx->recipient_name ?? 'Transfer' }}</div>
          <div style="font-size: 13px; color: var(--mob-text-muted);">{{ $tx->created_at->format('M d, Y') }}</div>
        </div>
        <div style="font-weight: 800; font-size: 15px; color: {{ $tx->type === 'credit' ? '#10b981' : 'var(--mob-text)' }};">
          {{ $tx->type === 'credit' ? '+' : '-' }}€{{ number_format($tx->amount, 2) }}
        </div>
      </div>
    @empty
      <div style="text-align: center;
        color: var(--mob-text-muted); font-size: 14px; padding: 30px 0; font-weight: 500;">No recent activity</div>
    @endforelse
    
    <div style="padding-top: 16px;
      text-align: center;">
      <a href="{{ route('transfers') }}" style="color: var(--mob-primary); font-size: 14px; font-weight: 700;
        text-decoration: none;">See all history</a>
    </div>
  </div>

</main>

<nav class="mob-bottom-nav">
  <a href="{{ route('dashboard') }}" class="mob-nav-link active"><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>

<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>

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