/* CSS Variables */
:root {
  --ease-spring: cubic-bezier(0.175, 0.885, 0.32, 1.1);
  --ease-smooth: cubic-bezier(0.23, 1, 0.32, 1);
  
  --bg-color: #030303;
  --bg-gradient: radial-gradient(circle at 50% -10%, rgba(139, 92, 246, 0.15) 0%, rgba(3, 3, 3, 0) 60%);
  
  --surface: rgba(18, 18, 22, 0.6);
  --surface-border: rgba(255, 255, 255, 0.06);
  
  --text-primary: #ffffff;
  --text-secondary: #8b8b93;
  
  --brand: #8b5cf6;
  --brand-glow: rgba(139, 92, 246, 0.4);
  --brand-gradient: linear-gradient(135deg, #a78bfa 0%, #7c3aed 100%);
  
  --error: #ef4444;
  --success: #10b981;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  touch-action: manipulation;
}

html, body {
  height: 100%;
  overflow: hidden; /* Fix iOS mobile bar jumping */
}

body {
  font-family: 'Outfit', -apple-system, sans-serif;
  background: var(--bg-color) var(--bg-gradient) no-repeat;
  color: var(--text-primary);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

/* Base button resets */
button {
  font-family: inherit;
}

/* Glass Panel Utility */
.glass-panel {
  background: var(--surface);
  backdrop-filter: blur(24px);
  -webkit-backdrop-filter: blur(24px);
  border: 1px solid var(--surface-border);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.05), 0 20px 40px rgba(0, 0, 0, 0.4);
  border-radius: 24px;
}

/* Shared Topbar Elements */
.app-topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  z-index: 10;
}

.page-title {
  font-size: 20px;
  font-weight: 600;
  color: var(--text-primary);
  letter-spacing: -0.02em;
}

.topbar-right {
  display: flex;
  align-items: center;
  gap: 12px;
}

/* Balance Pill */
.balance-pill {
  display: flex;
  align-items: center;
  gap: 6px;
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid rgba(255, 255, 255, 0.05);
  padding: 8px 14px;
  border-radius: 20px;
  font-weight: 600;
  font-size: 14px;
  color: var(--text-primary);
  transition: background 200ms ease;
}
.balance-pill i { color: var(--success); font-size: 16px; }
@media(hover:hover) { .balance-pill:hover { background: rgba(255,255,255,0.08); } }

/* Action Buttons */
.action-btn {
  background: var(--surface);
  border: 1px solid rgba(255, 255, 255, 0.05);
  color: var(--text-primary);
  cursor: pointer;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 300ms var(--ease-spring);
}
.action-btn i { font-size: 20px; }
@media(hover:hover) {
  .action-btn:hover { background: rgba(255, 255, 255, 0.1); transform: scale(1.05); }
}
.action-btn:active { transform: scale(0.95); }

/* Avatar Dropdown */
.avatar-dropdown-container { position: relative; }
.profile-avatar {
  width: 38px; height: 38px;
  border-radius: 50%; overflow: hidden;
  background: var(--surface);
  border: 2px solid rgba(255, 255, 255, 0.1);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.4);
  cursor: pointer; transition: transform 200ms ease;
}
.profile-avatar img { width: 100%; height: 100%; object-fit: cover; }
.avatar-fallback { width: 100%; height: 100%; background: var(--brand-gradient); }
.avatar-loading { width: 100%; height: 100%; display: flex; align-items: center; justify-content: center; background: rgba(255, 255, 255, 0.05); color: #a1a1aa; font-size: 1.2rem; position: absolute; inset: 0; border-radius: 50%; }
@media(hover:hover) { .profile-avatar:hover { transform: scale(1.05); } }
.profile-avatar:active { transform: scale(0.95); }

.avatar-dropdown-menu {
  position: absolute;
  top: 100%; right: 0;
  margin-top: 12px; width: 220px;
  background: rgba(18, 18, 22, 0.95);
  backdrop-filter: blur(24px); -webkit-backdrop-filter: blur(24px);
  border: 1px solid var(--surface-border);
  border-radius: 16px;
  box-shadow: 0 10px 40px rgba(0,0,0,0.6);
  padding: 8px;
  opacity: 0; visibility: hidden;
  transform: translateY(-10px) scale(0.95);
  transform-origin: top right;
  transition: all 300ms var(--ease-spring);
  z-index: 100;
}
.avatar-dropdown-menu.show { opacity: 1; visibility: visible; transform: translateY(0) scale(1); }
.dropdown-header { padding: 8px 12px; color: var(--text-primary); }
.dropdown-divider { height: 1px; background: var(--surface-border); margin: 6px 0; }
.dropdown-item {
  width: 100%; padding: 10px 12px; border-radius: 10px;
  background: transparent; border: none; color: var(--text-primary);
  display: flex; align-items: center; gap: 10px;
  font-size: 14px; font-weight: 500; cursor: pointer;
  transition: all 200ms ease; text-align: left;
}
@media(hover:hover) { .dropdown-item:hover { background: rgba(255,255,255,0.05); } }
.dropdown-item.text-error { color: var(--error); }
@media(hover:hover) { .dropdown-item.text-error:hover { background: rgba(239, 68, 68, 0.1); } }

/* Scrollbar Styling for webkit (Global & View Container) */
::-webkit-scrollbar {
  width: 8px;
  height: 8px;
}
::-webkit-scrollbar-track {
  background: rgba(0, 0, 0, 0.2);
  border-radius: 10px;
}
::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.1);
  border-radius: 10px;
}
::-webkit-scrollbar-thumb:hover {
  background: rgba(255, 255, 255, 0.25);
}

/* View Container */
.view-container {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow-y: auto;
  overflow-x: hidden;
  -webkit-overflow-scrolling: touch;
}

/* Nav Base */
.nav-btn {
  background: transparent; border: none; color: var(--text-secondary);
  cursor: pointer; display: flex; align-items: center;
  transition: all 300ms var(--ease-smooth);
}
.nav-btn:active { transform: scale(0.95); }
.nav-btn.active { color: var(--text-primary); }
.nav-btn.active i { color: var(--brand); filter: drop-shadow(0 0 8px var(--brand-glow)); }


/* --- DESKTOP ISLAND LAYOUT --- */
@media (min-width: 769px) {
  .app-layout {
    display: flex;
    height: 100dvh;
    padding: 16px; /* Space from monitor edges */
    gap: 16px; /* Gap between Island Sidebar and Main Content */
  }

  /* Island Sidebar */
  .app-nav {
    width: 260px;
    background: rgba(15, 15, 18, 0.6);
    backdrop-filter: blur(30px); -webkit-backdrop-filter: blur(30px);
    border: 1px solid var(--surface-border);
    border-radius: 24px;
    display: flex; flex-direction: column;
    padding: 24px 16px;
    transition: width 300ms var(--ease-spring), padding 300ms ease;
    overflow: hidden; /* For collapsing */
  }


  /* Collapsed Mode */
  .app-layout.nav-collapsed .app-nav {
    width: 88px;
    padding: 24px 12px;
  }

  /* Sidebar Header */
  .nav-header {
    display: flex; align-items: center; justify-content: space-between;
    margin-bottom: 40px;
    padding: 0 12px;
  }
  .nav-brand h2 {
    font-size: 24px; font-weight: 700;
    background: var(--brand-gradient);
    -webkit-background-clip: text; color: transparent;
    transition: opacity 200ms ease;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }
  .app-layout.nav-collapsed .nav-brand h2 { opacity: 0; width: 0; display: none; }
  
  .collapse-btn { width: 32px; height: 32px; border-radius: 10px; background: transparent; border: none; }
  @media(hover:hover) { .collapse-btn:hover { background: rgba(255,255,255,0.05); } }
  .collapse-btn i { font-size: 18px; transition: transform 300ms var(--ease-spring); }
  .app-layout.nav-collapsed .collapse-btn i { transform: rotate(180deg); }

  /* Nav Links Desktop */
  .nav-links { list-style: none; display: flex; flex-direction: column; gap: 8px; }
  .nav-btn {
    width: 100%; padding: 12px 16px; border-radius: 16px;
    gap: 16px; font-size: 15px; font-weight: 500;
  }
  .nav-btn i { font-size: 22px; }
  
  .nav-text { transition: opacity 200ms ease; white-space: nowrap; }
  .app-layout.nav-collapsed .nav-text { opacity: 0; display: none; }
  .app-layout.nav-collapsed .nav-btn { padding: 14px 0; justify-content: center; }

  .nav-btn.active {
    background: rgba(255, 255, 255, 0.04);
    box-shadow: inset 0 1px 0 rgba(255,255,255,0.05);
  }
  @media(hover:hover) { .nav-btn:hover:not(.active) { background: rgba(255,255,255,0.02); } }

  /* Main Island */
  .app-main {
    flex: 1;
    background: rgba(15, 15, 18, 0.4);
    backdrop-filter: blur(30px); -webkit-backdrop-filter: blur(30px);
    border: 1px solid var(--surface-border);
    border-radius: 24px;
    display: flex; flex-direction: column;
    overflow: hidden;
    position: relative;
  }

  .app-topbar { padding: 24px 40px; border-bottom: 1px solid rgba(255,255,255,0.02); }
  .view-container { padding: 40px; display: flex; flex-direction: column; }
}

/* --- MOBILE LAYOUT (Bottom Nav) --- */
@media (max-width: 768px) {
  .app-layout { display: flex; flex-direction: column; height: 100%; overflow: hidden; }
  .nav-header { display: none; }
  .view-container { padding: 20px 16px; overflow-y: auto; overflow-x: hidden; -webkit-overflow-scrolling: touch; }
  
  .app-nav {
    order: 3;
    background: rgba(10, 10, 12, 0.95);
    backdrop-filter: blur(20px); -webkit-backdrop-filter: blur(20px);
    border-top: 1px solid var(--surface-border);
    padding-bottom: env(safe-area-inset-bottom);
    z-index: 20;
  }

  .nav-links { display: flex; justify-content: space-around; list-style: none; padding: 4px 0; }
  .nav-btn {
    flex-direction: column; gap: 2px;
    font-size: 10px; font-weight: 500;
    padding: 4px; width: 55px;
  }
  .nav-btn i { font-size: 20px; }
  
  .app-main { flex: 1; display: flex; flex-direction: column; overflow: hidden; }
  .app-topbar { padding: 12px 16px; border-bottom: 1px solid var(--surface-border); }
  .page-title { display: none; }
  .balance-pill { padding: 6px 10px; font-size: 13px; }
  .topbar-right { gap: 8px; width: 100%; justify-content: flex-end; }
  .action-btn { width: 36px; height: 36px; }
  .action-btn i { font-size: 18px; }
}