/* ================== APP LAYOUT ================== */
/* ================== APP LAYOUT GRID ================== */
.app {
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  padding-top: calc(var(--header-height) + var(--safe-top));
  /* Bottom padding accounts for selection bar when visible */
  padding-bottom: var(--safe-bottom);
}

.app-header {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  height: calc(var(--header-height) + var(--safe-top));
  padding-top: var(--safe-top);
  background: rgba(10, 14, 20, 0.98);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border-color);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding-left: 12px;
  padding-right: 12px;
  z-index: var(--z-header);
}

.header-left, .header-right {
  display: flex;
  align-items: center;
  gap: 8px;
}

.header-center {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: flex-end;
  padding: 0 8px;
}

.header-title {
  font-size: 17px;
  font-weight: 600;
  margin-left: 8px;
}

.selection-mode-indicator {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-left: 12px;
  padding: 4px 10px;
  background: rgba(59, 130, 246, 0.2);
  border: 1px solid var(--accent-primary);
  border-radius: 20px;
  color: var(--accent-primary);
  font-size: 12px;
  font-weight: 600;
  animation: pulse-indicator 2s ease-in-out infinite;
}

@keyframes pulse-indicator {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.7; }
}

.selection-mode-indicator.hidden {
  display: none;
}

.header-selection-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 24px;
  height: 24px;
  margin-left: 8px;
  padding: 0 6px;
  background: var(--accent-primary);
  border-radius: 12px;
  color: #000;
  font-size: 12px;
  font-weight: 700;
  animation: pulse-badge 2s ease-in-out infinite;
}

.header-selection-badge.hidden {
  display: none;
}

@keyframes pulse-badge {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.1); }
}

.search-input-container {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--bg-tertiary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 6px 10px;
  flex: 1;
  max-width: 300px;
  animation: slideIn 0.2s ease;
}

.search-input-container input {
  flex: 1;
  background: transparent;
  border: none;
  color: var(--text-primary);
  font-size: 14px;
  outline: none;
}

.search-input-container input::placeholder {
  color: var(--text-muted);
}

@keyframes slideIn {
  from { opacity: 0; transform: translateX(10px); }
  to { opacity: 1; transform: translateX(0); }
}

.icon-btn {
  width: 44px;
  height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: none;
  border: none;
  color: var(--text-primary);
  border-radius: var(--radius-sm);
  cursor: pointer;
  position: relative;
}

.icon-btn:active {
  background: var(--bg-tertiary);
}

.connection-status {
  display: flex;
  align-items: center;
}

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--offline);
}

.status-dot.online {
  background: var(--online);
  box-shadow: 0 0 8px var(--online);
}

.badge {
  position: absolute;
  top: 6px;
  right: 6px;
  min-width: 18px;
  height: 18px;
  padding: 0 5px;
  background: var(--accent-danger);
  color: white;
  font-size: 11px;
  font-weight: 600;
  border-radius: 9px;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* ================== SIDEBAR ================== */
.sidebar {
  position: fixed;
  top: 0;
  left: 0;
  bottom: 0;
  width: var(--sidebar-width);
  background: var(--bg-secondary);
  border-right: 1px solid var(--border-color);
  z-index: var(--z-sidebar);
  transform: translateX(-100%);
  transition: transform 0.3s ease;
  display: flex;
  flex-direction: column;
}

.sidebar.open {
  transform: translateX(0);
}

.sidebar-header {
  height: calc(56px + var(--safe-top));
  padding-top: var(--safe-top);
  padding-left: 20px;
  display: flex;
  align-items: center;
  gap: 12px;
  border-bottom: 1px solid var(--border-color);
}

.logo-icon-sm {
  width: 28px;
  height: 28px;
  color: var(--accent-primary);
}

.nav-list {
  list-style: none;
  padding: 12px;
  flex: 1;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 16px;
  border-radius: var(--radius-md);
  cursor: pointer;
  color: var(--text-secondary);
  font-size: 15px;
  font-weight: 500;
  transition: transform, opacity, background-color, background, border-color, box-shadow 0.2s;
  margin-bottom: 4px;
}

.nav-item:active,
.nav-item.active {
  background: var(--accent-primary);
  color: white;
}

.sidebar-footer {
  padding: 16px;
  border-top: 1px solid var(--border-color);
}

.user-info {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 12px;
  padding: 8px;
  background: var(--bg-tertiary);
  border-radius: var(--radius-md);
  font-size: 14px;
  color: var(--text-secondary);
}

.sidebar-footer .btn-secondary {
  width: 100%;
}

.sidebar-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.6);
  z-index: var(--z-sidebar-overlay);
  opacity: 0;
  visibility: hidden;
  transition: transform, opacity, background-color, background, border-color, box-shadow 0.3s;
}

.sidebar-overlay.active {
  opacity: 1;
  visibility: visible;
}

/* ================== MAIN CONTENT ================== */
.main-content {
  display: flex;
  flex-direction: column;
  height: 100vh;
  min-height: 0;
  padding: 16px;
}

/* ================== PAGE LAYOUT ================== */
.page {
  display: none;
  flex-direction: column;
  flex: 1;
  min-height: 0;
  animation: fadeIn 0.2s ease;
}

.page.active {
  display: flex;
}

/* Accounts page has special layout with sticky sections */
#page-accounts {
  position: relative;
  display: none;
  flex-direction: column;
  height: 100%;
  overflow: hidden;
  /* ⭐ 1. Soft Page Background Atmosphere */
  background: radial-gradient(circle at top, var(--bg-secondary), var(--bg-primary));
}

#page-accounts.active {
  display: flex;
}

/* Scrollable content area within page */
.page-content {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  min-height: 0;
  display: flex;
  flex-direction: column;
  touch-action: pan-y;
  overscroll-behavior-y: contain;
}

/* ⭐ 6. Subtle fade at bottom of scroll */
.page-content::after {
  content: '';
  position: sticky;
  bottom: 0;
  height: 40px;
  background: linear-gradient(transparent, var(--bg-primary));
  display: block;
  pointer-events: none;
  margin-top: -40px;
}

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: translateY(0); }
}

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

.page-header h2 {
  font-size: 20px;
  font-weight: 600;
}

.back-btn {
  margin-left: -8px;
}

/* ================== STATS BAR ================== */
.stats-bar {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
  margin-bottom: 16px;
  /* Sticky positioning */
  position: sticky;
  top: 0;
  z-index: var(--z-base);
  background: var(--bg-primary);
  padding: 4px 0;
}

.stat-card {
  background: var(--bg-secondary);
  border: 1px solid var(--border-color);
  border-radius: 14px;
  padding: 14px 12px;
  text-align: center;
  /* ⭐ 2. Live Instrument Feel */
  box-shadow:
    0 6px 12px rgba(0,0,0,0.06),
    inset 0 1px 0 rgba(255,255,255,0.06);
  transition: transform, opacity, background-color, background, border-color, box-shadow 0.2s ease;
  /* mobile-opt: will-change removed to save GPU memory */
  /* will-change: transform, box-shadow; */
}

.stat-card.clickable {
  cursor: pointer;
  position: relative;
  z-index: 1;
}

.stat-card.clickable:hover {
  transform: translateY(-3px);
  box-shadow: 0 14px 28px rgba(0,0,0,0.1);
}

.stat-card.clickable:active {
  transform: scale(0.96);
}

.stat-card.clickable * {
  pointer-events: none; /* Ensure clicks go to the card, not children */
}

.stat-value {
  display: block;
  font-size: 24px;
  font-weight: 700;
  line-height: 1;
  margin-bottom: 4px;
  transition: transform 0.16s ease;
}

/* ⭐ 2. Animate value change */
.stat-value.updating {
  transform: scale(1.15);
  color: var(--accent-primary);
}

.stat-value.win { color: var(--accent-success); }
.stat-value.loss { color: var(--accent-danger); }
.stat-value.danger { color: var(--accent-danger); font-weight: 700; }

.stat-label {
  font-size: 12px;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

/* ================== SEARCH ================== */
.search-bar {
  position: relative;
  margin-bottom: 16px;
}

.search-bar i {
  position: absolute;
  left: 14px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-muted);
}

.search-bar input {
  width: 100%;
  height: 48px;
  padding: 0 14px 0 44px;
  background: var(--bg-secondary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  color: var(--text-primary);
  font-size: 15px;
}

.search-bar input:focus {
  outline: none;
  border-color: var(--accent-primary);
}

/* Filter bar styles moved to styles.css */


/* ================== SCROLLABLE STATS ROW ================== */
.stats-row {
  display: flex;
  gap: 10px;
  overflow-x: auto;
  overflow-y: hidden;
  flex-shrink: 0;
  padding: 12px 16px 18px 16px;
  background: var(--bg-primary);
  border-bottom: 1px solid var(--border-color);
  /* Hide scrollbar but keep functionality */
  scrollbar-width: thin;
  scrollbar-color: var(--border-light) transparent;
}

.stats-row::-webkit-scrollbar {
  height: 6px;
}

.stats-row::-webkit-scrollbar-track {
  background: transparent;
}

.stats-row::-webkit-scrollbar-thumb {
  background: var(--border-light);
  border-radius: 3px;
}

.stats-row::-webkit-scrollbar-thumb:hover {
  background: var(--text-muted);
}

/* Stat card in scrollable row */
.stats-row .stat-card {
  flex-shrink: 0;
  min-width: 110px;
  padding: 14px 18px;
}

/* Highlight animation for stat card clicks */
.stat-card.highlight-scroll {
  animation: stat-highlight 600ms ease;
}

@keyframes stat-highlight {
  0% { box-shadow: 0 0 0 0 rgba(99, 102, 241, 0.5); }
  50% { box-shadow: 0 0 0 8px rgba(99, 102, 241, 0); }
  100% { box-shadow: 0 0 0 0 rgba(99, 102, 241, 0); }
}

/* Account row highlight for stat navigation */
.account-card.highlight-stat-nav {
  animation: row-highlight-nav 1.5s ease;
}

@keyframes row-highlight-nav {
  0% {
    box-shadow: 0 0 0 4px rgba(99, 102, 241, 0.6);
    transform: scale(1.01);
  }
  50% {
    box-shadow: 0 0 0 2px rgba(99, 102, 241, 0.3);
  }
  100% {
    box-shadow: none;
    transform: scale(1);
  }
}

/* ================== RESPONSIVE BREAKPOINTS FOR STATS ROW ================== */

/* Mobile: 2-column grid */
@media (max-width: 480px) {
  .stats-row {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 10px;
    overflow-x: visible;
    padding: 12px 16px;
  }
  
  .stats-row .stat-card {
    min-width: auto;
    flex-shrink: 1;
    padding: 12px 10px;
  }
  
  .stats-row .stat-value {
    font-size: 18px;
  }
  
  .stats-row .stat-label {
    font-size: 10px;
  }
}

/* Tablet: 3-column grid */
@media (min-width: 481px) and (max-width: 767px) {
  .stats-row {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 12px;
    overflow-x: visible;
    padding: 12px 16px 18px 16px;
  }
  
  .stats-row .stat-card {
    min-width: auto;
    flex-shrink: 1;
    padding: 14px 12px;
  }
  
  .stats-row .stat-value {
    font-size: 20px;
  }
}

/* Small desktop: 5-column grid */
@media (min-width: 768px) and (max-width: 1023px) {
  .stats-row {
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    gap: 12px;
    overflow-x: visible;
    padding: 14px 20px 18px 20px;
  }
  
  .stats-row .stat-card {
    min-width: auto;
    flex-shrink: 1;
    padding: 14px 14px;
  }
}

/* Desktop: Grid layout instead of scroll */
@media (min-width: 1024px) {
  .stats-row {
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    gap: 16px;
    overflow-x: visible;
    padding: 16px 24px 20px 24px;
  }
  
  .stats-row .stat-card {
    min-width: auto;
    flex-shrink: 1;
    padding: 18px 20px;
  }
}

/* Large desktop: More spacious layout */
@media (min-width: 1400px) {
  .stats-row {
    grid-template-columns: repeat(5, 1fr);
    gap: 20px;
    padding: 20px 28px 24px 28px;
  }
  
  .stats-row .stat-card {
    padding: 20px 24px;
  }
}
/* ================== RESPONSIVE LAYOUT IMPROVEMENTS ================== */

/* Mobile header adjustments */
@media (max-width: 480px) {
  .app-header {
    padding-left: 8px;
    padding-right: 8px;
  }
  
  .header-title {
    font-size: 15px;
    margin-left: 4px;
    max-width: 120px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }
  
  .header-left, .header-right {
    gap: 4px;
  }
  
  .icon-btn {
    width: 40px;
    height: 40px;
  }
  
  .search-input-container {
    max-width: 200px;
    padding: 4px 8px;
  }
  
  .search-input-container input {
    font-size: 13px;
  }
  
  .selection-mode-indicator {
    margin-left: 6px;
    padding: 3px 8px;
    font-size: 11px;
  }
  
  .selection-mode-indicator span {
    display: none;
  }
  
  .header-selection-badge {
    margin-left: 4px;
    min-width: 20px;
    height: 20px;
    font-size: 11px;
  }
}

/* Tablet header adjustments */
@media (min-width: 481px) and (max-width: 768px) {
  .header-title {
    font-size: 16px;
    max-width: 200px;
  }
  
  .search-input-container {
    max-width: 250px;
  }
}

/* Page content responsive padding */
@media (max-width: 480px) {
  .main-content {
    padding: 12px;
  }
  
  .page-content {
    padding-bottom: 0;
  }
  
  .page-header {
    margin-bottom: 16px;
    gap: 8px;
  }
  
  .page-header h2 {
    font-size: 18px;
  }
}

/* Stats bar responsive */
@media (max-width: 480px) {
  .stats-bar {
    grid-template-columns: repeat(2, 1fr);
    gap: 8px;
    margin-bottom: 12px;
  }
  
  .stat-card {
    padding: 12px 10px;
  }
  
  .stat-value {
    font-size: 18px;
  }
  
  .stat-label {
    font-size: 10px;
  }
}

/* Search bar responsive */
@media (max-width: 480px) {
  .search-bar input {
    height: 44px;
    font-size: 14px;
    padding: 0 12px 0 40px;
  }
  
  .search-bar i {
    left: 12px;
  }
}

/* Small mobile optimizations */
@media (max-width: 360px) {
  .app-header {
    padding-left: 6px;
    padding-right: 6px;
  }
  
  .header-title {
    max-width: 90px;
    font-size: 14px;
  }
  
  .main-content {
    padding: 8px;
  }
  
  .stats-row {
    gap: 8px;
    padding: 10px 12px;
  }
}

/* Landscape mobile adjustments */
@media (max-height: 500px) and (orientation: landscape) {
  .app-header {
    height: calc(48px + var(--safe-top));
  }
  
  .app {
    padding-top: calc(48px + var(--safe-top));
  }
}


/* ================== SIDEBAR DESKTOP LAYOUT ================== */
/* When sidebar is visible on desktop, adjust main content */
@media (min-width: 1024px) {
  .sidebar-visible .app {
    padding-left: var(--sidebar-width);
  }
  
  .sidebar-visible .app-header {
    left: var(--sidebar-width);
    width: calc(100% - var(--sidebar-width));
  }
}

/* ================== MOBILE PERFORMANCE OVERRIDES ================== */
/* Disable backdrop-filter blur on mobile — causes scroll jank */
/* blanket kill: every element, every file, no specificity fight */
@media (max-width: 768px) {
  * {
    backdrop-filter: none !important;
    -webkit-backdrop-filter: none !important;
  }
}

/* ================== MOBILE ANIMATION OPTIMIZATIONS ================== */
/* Pause non-essential infinite animations on mobile to save GPU */
@media (max-width: 768px) {
  .selection-mode-indicator,
  .header-selection-badge,
  .pulse-indicator,
  .pulse-badge,
  .pulseDot,
  .pulseSpin,
  .rowGlow,
  .cashoutBtnPulse {
    animation-play-state: paused !important;
  }
}
