:root {
  --bg-main: #0a0c10;
  --bg-sidebar: #0d0f14;
  --bg-surface: #161a21;
  --bg-card: rgba(22, 26, 33, 0.6);
  --border-subtle: rgba(255, 255, 255, 0.05);
  --border-light: rgba(255, 255, 255, 0.1);
  --accent-blue: #3d7eff;
  --accent-green: #2eb872;
  --accent-red: #e75a5a;
  --text-primary: #ffffff;
  --text-secondary: #949db0;
  --text-muted: #4f5666;
  --sidebar-width: 240px;
  --sidebar-collapsed-width: 72px;
  --glass-blur: 20px;
  --card-radius: 20px;
  --mobile-header-height: 60px;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  padding: 0;
  font-family:
    "Outfit",
    "Inter",
    -apple-system,
    BlinkMacSystemFont,
    sans-serif;
  background: var(--bg-main);
  color: var(--text-primary);
  overflow-x: hidden;
  background:
    radial-gradient(
      circle at 0% 0%,
      rgba(61, 126, 255, 0.15) 0%,
      transparent 40%
    ),
    radial-gradient(
      circle at 100% 100%,
      rgba(35, 134, 54, 0.1) 0%,
      transparent 40%
    ),
    var(--bg-main);
}

/* Typography */
h1,
h2,
h3 {
  margin: 0;
  font-weight: 600;
}

/* Glassmorphism Classes */
.glass {
  background: var(--bg-surface);
  backdrop-filter: blur(var(--glass-blur));
  -webkit-backdrop-filter: blur(var(--glass-blur));
  border: 1px solid var(--border-subtle);
  border-radius: var(--card-radius);
  box-shadow: 
    0 8px 32px rgba(0, 0, 0, 0.4),
    inset 0 0 0 1px var(--border-highlight);
}

/* Layout */
.app-container {
  display: flex;
  min-height: 100vh;
}

/* Sidebar */
.sidebar {
  width: var(--sidebar-width);
  height: 100vh;
  position: fixed;
  left: 0;
  top: 0;
  padding: 2.5rem 1.5rem;
  display: flex;
  flex-direction: column;
  z-index: 100;
  border-right: 1px solid var(--border-subtle);
  background: var(--bg-sidebar);
  transition: width 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  overflow-x: hidden;
}

.sidebar.collapsed {
  width: var(--sidebar-collapsed-width);
  padding-left: 0.5rem;
  padding-right: 0.5rem;
}

.sidebar.collapsed .logo-text,
.sidebar.collapsed .nav-text,
.sidebar.collapsed .sw-label,
.sidebar.collapsed .sw-balance {
  display: none;
}

.sidebar.collapsed .sidebar-wallet {
  padding: 1rem 0;
  border: none;
  background: transparent;
  display: flex;
  justify-content: center;
}

.sidebar.collapsed .nav-link {
  justify-content: center;
  align-items: center;
  width: 44px;
  height: 44px;
  padding: 0;
  margin: 0 auto;
  border-radius: 14px;
}

/* Sidebar Toggle — lives inside logo-container */
.sidebar-toggle, .desktop-toggle {
  margin-left: auto;
  width: 24px;
  height: 24px;
  background: transparent;
  border: 1px solid var(--border-subtle);
  border-radius: 7px;
  color: var(--text-muted);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all 0.2s ease;
  flex-shrink: 0;
}

.sidebar-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 2.5rem;
}

.mobile-header {
  display: none;
}

.sidebar-overlay {
  display: none;
}

.sidebar-toggle svg,
.desktop-toggle svg {
  transition: transform 0.3s cubic-bezier(0.16, 1, 0.3, 1);
}

.sidebar-toggle:hover {
  color: var(--text-primary);
  border-color: var(--border-light);
  background: rgba(255,255,255,0.04);
}

/* When collapsed, center the container and hide margin */
.sidebar.collapsed .logo-container {
  justify-content: center;
  margin-bottom: 1.75rem;
  height: 44px;
}

.sidebar.collapsed .sidebar-toggle {
  display: flex;
  position: absolute;
  right: 50%;
  top: calc(100% + 6px);
  transform: translateX(50%);
}

.logo-container {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  margin-bottom: 2.5rem;
  position: relative;
  height: 32px;
}

.logo-img {
  width: 32px;
  height: 32px;
  flex-shrink: 0;
}

.logo-text {
  font-size: 1.25rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  white-space: nowrap;
  transition: opacity 0.2s ease;
}

.sidebar.collapsed .logo-text {
  opacity: 0;
  pointer-events: none;
}

.sidebar.collapsed .logo-container {
  justify-content: center;
}

.sidebar.collapsed .nav-links {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.6rem;
}

.sidebar.collapsed .nav-item {
  margin-bottom: 0;
  width: 100%;
  display: flex;
  justify-content: center;
}

.nav-links {
  list-style: none;
  padding: 0;
  margin: 0;
  flex: 1;
}

.nav-item {
  margin-bottom: 0.5rem;
}

.nav-link {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.7rem 0.85rem;
  text-decoration: none;
  color: var(--text-secondary);
  border-radius: 10px;
  transition: all 0.2s ease;
  font-weight: 500;
  font-size: 0.875rem;
}

.nav-link:hover {
  color: var(--text-primary);
  background: rgba(255, 255, 255, 0.03);
}

.nav-link.active {
  color: var(--accent-blue);
  background: rgba(61, 126, 255, 0.08);
  font-weight: 600;
}

/* Sidebar Wallet Widget */
.sidebar-wallet {
  padding: 1.5rem;
  margin: 1.5rem 0;
  border-radius: 18px;
  background: var(--bg-main);
  border: 1px solid var(--border-subtle);
  position: relative;
  overflow: hidden;
}

.sidebar-wallet::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 2px;
  background: linear-gradient(90deg, transparent, var(--accent-blue), transparent);
  opacity: 0.5;
}

.sw-label {
  font-size: 0.65rem;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--text-muted);
  margin-bottom: 0.5rem;
  font-weight: 700;
}

.sw-balance {
  font-size: 1rem;
  font-weight: 700;
  font-family: "JetBrains Mono", monospace;
  color: var(--text-primary);
  margin-top: 0.25rem;
}

/* Main Content */
.main-content {
  margin-left: var(--sidebar-width);
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  padding: 2.5rem 3.5rem;
  transition: margin-left 0.3s cubic-bezier(0.16, 1, 0.3, 1);
}

.main-content.sidebar-collapsed {
  margin-left: var(--sidebar-collapsed-width);
}

/* Top Header */
.top-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 3rem;
}

.top-header-left .page-title {
  font-size: 1.8rem;
  font-weight: 700;
  letter-spacing: -0.02em;
}

.top-header-right {
  display: flex;
  align-items: center;
  gap: 1.25rem;
}

.header-search {
  background: #12151a;
  border: 1px solid var(--border-subtle);
  border-radius: 12px;
  padding: 0.6rem 1rem;
  display: flex;
  align-items: center;
  gap: 0.75rem;
  width: 260px;
}

.header-search input {
  background: transparent;
  border: none;
  outline: none;
  color: var(--text-primary);
  font-size: 0.85rem;
  width: 100%;
}

.profile-avatar {
  width: 32px;
  height: 32px;
  background: linear-gradient(135deg, #1e2530, #2c3545);
  border: 1px solid var(--border-light);
  border-radius: 8px;
  position: relative;
  overflow: hidden;
}

.profile-avatar::after {
  content: '';
  position: absolute;
  inset: 0;
  background: radial-gradient(circle at center, rgba(255,255,255,0.1) 0%, transparent 70%);
}
.header-icon-btn {
  background: none;
  border: none;
  color: var(--text-secondary);
  cursor: pointer;
  padding: 0.6rem;
  border-radius: 12px;
  transition: all 0.2s ease;
  display: flex;
  align-items: center;
  justify-content: center;
}

.header-icon-btn:hover {
  background: var(--bg-surface);
  color: var(--text-primary);
}

.profile-avatar {
  width: 40px;
  height: 40px;
  border-radius: 12px;
  background: linear-gradient(135deg, var(--accent-blue), #5c94ff);
  border: 2px solid var(--border-subtle);
}

/* Page Content */
.page-content {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-height: 0;
  gap: 1.5rem;
}

.page-title {
  font-size: 1.75rem;
  font-weight: 700;
  color: var(--text-primary);
  letter-spacing: -0.03em;
}

/* Dashboard Cards */
.stats-container {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 1rem;
  margin-bottom: 0.75rem;
  flex-shrink: 0;
}

.stat-card {
  padding: 1.5rem;
  border-radius: 18px;
  transition: all 0.4s cubic-bezier(0.16, 1, 0.3, 1);
  position: relative;
  overflow: hidden;
  background: #11141a;
  border: 1px solid rgba(255, 255, 255, 0.04);
}

.stat-card:hover {
  transform: translateY(-4px);
  background: #161a21;
  border-color: rgba(255, 255, 255, 0.1);
  box-shadow: 
    0 24px 48px rgba(0, 0, 0, 0.5),
    inset 0 0 0 1px rgba(255, 255, 255, 0.15);
}

.stat-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: 1rem;
}

.stat-label {
  color: var(--text-secondary);
  font-size: 0.75rem;
  font-weight: 600;
  letter-spacing: 0.02em;
}

.stat-icon-wrapper {
  color: var(--text-muted);
  opacity: 0.6;
}

.stat-value {
  font-size: 1.5rem;
  font-weight: 700;
  color: var(--text-primary);
  margin-bottom: 0.25rem;
  letter-spacing: -0.02em;
}

.stat-footer {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.8rem;
}

.trend-up {
  color: var(--accent-green);
  font-weight: 600;
}
.trend-down {
  color: var(--accent-red);
  font-weight: 600;
}

.stat-sparkline {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  height: 40px;
  pointer-events: none;
  opacity: 0.3;
}

/* Dashboard Cards */
.dashboard-cards {
  padding: 1.25rem;
  flex: 1;
  min-height: 0;
}

.coin-cards-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: 1rem;
  align-content: start;
}

.coin-cards-slot {
  display: contents;
}

.coin-card {
  position: relative;
  aspect-ratio: 1;
  min-height: 120px;
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--card-radius);
  padding: 1rem;
  cursor: pointer;
  transition: all 0.2s ease;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
}

.coin-card-remove {
  position: absolute;
  top: 0.5rem;
  right: 0.5rem;
  width: 24px;
  height: 24px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: none;
  border-radius: 6px;
  background: rgba(255, 255, 255, 0.06);
  color: var(--text-muted);
  font-size: 1.1rem;
  line-height: 1;
  cursor: pointer;
  transition: all 0.2s ease;
}

.coin-card-remove:hover {
  background: rgba(231, 90, 90, 0.2);
  color: var(--accent-red);
}

.coin-card:hover {
  border-color: var(--accent-blue);
  background: rgba(61, 126, 255, 0.06);
  transform: translateY(-2px);
}

.coin-card-symbol {
  font-weight: 700;
  font-size: 1rem;
  color: var(--text-primary);
}

.coin-card-price {
  font-size: 0.8rem;
  color: var(--text-muted);
  font-family: "JetBrains Mono", monospace;
}

.add-card {
  border-style: dashed;
  border-color: var(--border-light);
  color: var(--text-muted);
}

.add-card:hover {
  border-color: var(--accent-blue);
  color: var(--accent-blue);
  background: rgba(61, 126, 255, 0.04);
}

.add-card-inner {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.85rem;
  font-weight: 500;
}

/* Skeleton cards */
.coin-card-skeleton {
  pointer-events: none;
  cursor: default;
}

.coin-card-skeleton:hover {
  transform: none;
  border-color: var(--border-subtle);
  background: var(--bg-surface);
}

.coin-card-skeleton .skeleton-line {
  display: block;
  height: 14px;
  border-radius: 6px;
  background: linear-gradient(
    90deg,
    var(--border-subtle) 25%,
    rgba(255, 255, 255, 0.08) 50%,
    var(--border-subtle) 75%
  );
  background-size: 200% 100%;
  animation: skeleton-shimmer 1.2s ease-in-out infinite;
}

.coin-card-skeleton .skeleton-line-title {
  width: 60px;
  height: 16px;
}

.coin-card-skeleton .skeleton-line-price {
  width: 45px;
  height: 12px;
  margin-top: 0.5rem;
}

@keyframes skeleton-shimmer {
  0% { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}

/* Chart Overlay */
.chart-overlay {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 1000;
  background: var(--bg-main);
  padding: 1rem;
  overflow: auto;
}

.chart-overlay.visible {
  display: flex;
  flex-direction: column;
}

.chart-overlay-close-btn {
  position: fixed;
  top: 1.25rem;
  right: 1.25rem;
  z-index: 1001;
  width: 44px;
  height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: none;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.06);
  color: var(--text-muted);
  cursor: pointer;
  transition: background 0.2s, color 0.2s, transform 0.2s;
}

.chart-overlay-close-btn:hover {
  background: rgba(231, 90, 90, 0.2);
  color: var(--accent-red);
  transform: scale(1.08);
}

.chart-overlay-close-btn:active {
  transform: scale(0.95);
}

.chart-overlay-close-btn svg {
  pointer-events: none;
}

.chart-overlay .chart-header {
  padding-right: 56px;
}

.chart-overlay-inner {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
}

.chart-overlay .chart-wrapper {
  min-height: 400px;
}

/* Symbol Picker Modal */
.symbol-picker-modal {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 1100;
  align-items: center;
  justify-content: center;
  padding: 2rem;
}

.symbol-picker-modal.visible {
  display: flex;
}

.symbol-picker-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  cursor: pointer;
}

.symbol-picker-panel {
  position: relative;
  width: 100%;
  max-width: 420px;
  max-height: 80vh;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  padding: 1.25rem;
  border-radius: var(--card-radius);
}

.symbol-picker-panel .symbol-list {
  flex: 1;
  min-height: 200px;
  max-height: 320px;
  overflow-y: auto;
}

/* Chart Area */
.chart-section {
  padding: 1.25rem;
  border-radius: var(--card-radius);
  display: flex !important;
  flex-direction: column;
  flex: 1;
  min-height: 0;
}

.chart-wrapper {
  position: relative;
  flex: 1;
  width: 100%;
  min-height: 0;
  display: flex;
  flex-direction: column;
}

.chart-wrapper:fullscreen {
  background: var(--bg-main);
  padding: 1rem;
}

#stock-chart {
  flex: 1;
  width: 100%;
  min-height: 0;
}

.chart-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 1rem;
  flex-shrink: 0;
}

.chart-header-left h2 {
  font-weight: 700;
  color: var(--text-primary);
  font-size: 1.25rem;
  letter-spacing: -0.02em;
  margin-bottom: 0.5rem;
}

.chart-header-subtitle {
  font-size: 0.85rem;
  color: var(--text-muted);
}

.chart-actions {
  display: flex;
  gap: 1rem;
  position: relative;
  z-index: 20;
}

.dropdown-btn {
  background: var(--bg-sidebar);
  border: 1px solid var(--border-subtle);
  color: var(--text-secondary);
  padding: 0.6rem 1.2rem;
  border-radius: 12px;
  font-size: 0.85rem;
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: 0.75rem;
  cursor: pointer;
  transition: all 0.2s ease;
}

.dropdown-btn:hover {
  border-color: var(--accent-blue);
  color: var(--text-primary);
  background: var(--bg-surface);
}

/* Buttons */
.btn-primary {
  background: var(--accent-blue);
  color: white;
  border: none;
  padding: 0.7rem 1.4rem;
  border-radius: 12px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
  box-shadow: 0 4px 12px rgba(61, 126, 255, 0.25);
}

.btn-primary:hover {
  filter: brightness(1.1);
  transform: translateY(-1px);
  box-shadow: 0 6px 16px rgba(61, 126, 255, 0.35);
}

/* Responsive Styles */
@media (max-width: 1024px) {
  .sidebar {
    width: 80px;
    padding: 2rem 0.75rem;
  }
  .logo-text,
  .nav-text {
    display: none;
  }
  .main-content {
    margin-left: 80px;
    padding: 2rem;
  }
}

@media (max-width: 768px) {
  .app-container {
    flex-direction: column;
  }
  
  /* Mobile Header */
  .mobile-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 1rem;
    height: var(--mobile-header-height);
    background: var(--bg-sidebar);
    border-bottom: 1px solid var(--border-subtle);
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    z-index: 99;
  }
  
  .hamburger-btn {
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: transparent;
    border: none;
    color: var(--text-primary);
    cursor: pointer;
    border-radius: 10px;
    transition: background 0.2s;
  }
  
  .hamburger-btn:hover {
    background: rgba(255, 255, 255, 0.06);
  }
  
  .hamburger-btn svg {
    transition: transform 0.3s ease;
  }
  
  body.menu-open .hamburger-btn svg {
    transform: rotate(90deg);
  }
  
  .mobile-logo {
    font-size: 1.1rem;
    font-weight: 700;
    letter-spacing: -0.02em;
  }
  
  .mobile-balance {
    font-size: 0.9rem;
    font-weight: 700;
    font-family: "JetBrains Mono", monospace;
    color: var(--text-primary);
  }
  
  /* Sidebar Mobile */
  .sidebar {
    width: 280px;
    height: 100vh;
    position: fixed;
    left: 0;
    top: 0;
    transform: translateX(-100%);
    z-index: 100;
    transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    padding: 1.5rem;
    padding-top: calc(var(--mobile-header-height) + 1rem);
  }
  
  .sidebar.mobile-open {
    transform: translateX(0);
  }
  
  .sidebar-header {
    display: none;
  }
  
  .sidebar .logo-container {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    margin-bottom: 2rem;
  }
  
  .sidebar .logo-container .logo-text {
    display: block;
    font-size: 1.1rem;
    font-weight: 700;
  }
  
  .sidebar .nav-links {
    display: flex !important;
    flex-direction: column;
    gap: 0.5rem;
  }
  
  .sidebar .nav-link {
    padding: 0.9rem 1rem;
    justify-content: flex-start;
  }
  
  .sidebar .nav-text {
    display: inline !important;
  }
  
  .sidebar-wallet {
    margin-top: auto;
    margin-bottom: 1rem;
  }
  
  .sidebar-footer {
    margin-top: 0.5rem;
    padding-top: 1rem;
    border-top: 1px solid var(--border-subtle);
  }
  
  .sidebar .sidebar-wallet,
  .sidebar .sidebar-footer {
    display: block !important;
  }
  
  /* Sidebar Overlay */
  .sidebar-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.6);
    z-index: 99;
    opacity: 0;
    transition: opacity 0.3s;
  }
  
  .sidebar-overlay.active {
    display: block;
    opacity: 1;
  }
  
  body.menu-open {
    overflow: hidden;
  }
  
  .main-content {
    margin-left: 0;
    padding: 1rem;
    padding-top: calc(var(--mobile-header-height) + 1rem);
  }
  
  .chart-section {
    min-height: 350px;
    padding: 1rem;
  }
  
  .coin-cards-grid {
    grid-template-columns: repeat(2, 1fr);
  }
  
  .view-header {
    flex-direction: column;
    gap: 1rem;
  }
  
  .header-actions {
    width: 100%;
  }
  
  .search-input-wrap input {
    width: 100%;
  }
  
  .portfolio-hero {
    flex-direction: column;
    padding: 1.5rem;
  }
  
  .portfolio-hero-right {
    flex-direction: row;
    width: 100%;
    justify-content: space-between;
    margin-top: 1.5rem;
  }
  
  .portfolio-big-value {
    font-size: 2rem;
  }
  
  .portfolio-metrics {
    grid-template-columns: repeat(2, 1fr);
    gap: 0.75rem;
  }
  
  .metric-card {
    padding: 1rem;
    flex-direction: column;
    align-items: flex-start;
    gap: 0.75rem;
  }
  
  .history-summary {
    grid-template-columns: 1fr;
  }
  
  .stats-container {
    grid-template-columns: 1fr;
  }
  
  .bottom-stats {
    grid-template-columns: 1fr;
  }
  
  .chart-header {
    flex-direction: column;
    align-items: flex-start;
    gap: 0.75rem;
  }
  
  .chart-actions {
    width: 100%;
    flex-wrap: wrap;
  }

  .tx-table th,
  .tx-table td {
    padding: 0.5rem;
    font-size: 0.75rem;
    white-space: nowrap;
  }

  .history-table-wrap,
  .backtest-trades-wrap {
    padding: 0.75rem;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }
}

/* Hide desktop toggle on mobile */
@media (max-width: 768px) {
  .desktop-toggle {
    display: none;
  }
}

/* Wallet */
.wallet-card {
  border-color: rgba(61, 126, 255, 0.25) !important;
  background: linear-gradient(135deg, rgba(61, 126, 255, 0.08), var(--bg-surface)) !important;
}

.btn-sm {
  padding: 0.35rem 0.85rem;
  border: none;
  border-radius: 8px;
  font-size: 0.8rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s ease;
  font-family: inherit;
}

.btn-deposit {
  background: rgba(35, 134, 54, 0.2);
  color: #3fb950;
}
.btn-deposit:hover {
  background: rgba(35, 134, 54, 0.35);
}

.btn-withdraw {
  background: rgba(218, 54, 51, 0.15);
  color: #f85149;
}
.btn-withdraw:hover {
  background: rgba(218, 54, 51, 0.3);
}

/* Transaction Table */
.tx-table {
  width: 100%;
  border-collapse: collapse;
}

.tx-table th {
  text-align: left;
  font-size: 0.65rem;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--text-muted);
  padding: 0.75rem;
  border-bottom: 1px solid var(--border-subtle);
  font-weight: 700;
}

.tx-table td {
  padding: 0.75rem;
  font-size: 0.875rem;
  border-bottom: 1px solid rgba(255, 255, 255, 0.03);
}

.tx-table tr:hover td {
  background: rgba(255, 255, 255, 0.02);
}

/* Modal */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  backdrop-filter: blur(4px);
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  animation: fadeIn 0.2s ease-out;
}

@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

.bottom-stats {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 1rem;
  flex-shrink: 0;
}

/* ═══════════════ SPA VIEW SYSTEM ═══════════════ */
.view { display: none; opacity: 0; }

.view.active-view {
  display: flex;
  flex-direction: column;
  min-height: calc(100vh - 2rem);
  animation: viewEnter 0.35s cubic-bezier(0.16, 1, 0.3, 1) forwards;
}

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

/* ─── Drawing Tools Toolbar (lwc-plugin-drawing-tools) ─── */
.lwc-toolbox {
  flex-direction: row !important;
  gap: 4px !important;
  padding: 4px 6px !important;
  top: 8px !important;
  left: 8px !important;
}

.lwc-toolbox .tool-btn {
  width: 32px !important;
  height: 32px !important;
  border-radius: 8px !important;
}

.lwc-toolbox .tool-btn svg {
  width: 16px !important;
  height: 16px !important;
}

/* ─── Chart Legend ─── */
.chart-legend {
  position: absolute;
  top: 10px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 0.35rem;
  font-size: 0.7rem;
  color: var(--text-muted);
  z-index: 10;
  background: rgba(10, 12, 16, 0.85);
  padding: 0.5rem 0.75rem;
  border-radius: 8px;
  border: 1px solid var(--border-subtle);
  min-width: 120px;
  transition: all 0.25s ease;
}

/* Legend toggle button */
.chart-legend-toggle {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  background: none;
  border: none;
  color: var(--text-secondary);
  cursor: pointer;
  padding: 0.25rem 0;
  font-size: 0.7rem;
  font-weight: 600;
  letter-spacing: 0.02em;
  text-transform: uppercase;
}

.chart-legend-toggle:hover {
  color: var(--text-primary);
}

.chart-legend-toggle svg {
  width: 12px;
  height: 12px;
  transition: transform 0.25s ease;
}

/* Collapsed state */
.chart-legend.collapsed {
  padding: 0.5rem 0.75rem;
}

.chart-legend.collapsed .chart-legend-items {
  display: none;
}

.chart-legend.collapsed .chart-legend-toggle svg {
  transform: rotate(-90deg);
}

/* Legend items container */
.chart-legend-items {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  margin-top: 0.5rem;
  padding-top: 0.5rem;
  border-top: 1px solid var(--border-subtle);
}

/* Session date stays top left of legend */
.chart-legend > span#session-date {
  display: block;
  width: 100%;
  margin-bottom: 0.25rem;
  padding-bottom: 0.25rem;
  border-bottom: 1px solid var(--border-subtle);
  font-size: 0.65rem;
}

.chart-legend > div[style*="flex:1"] {
  display: none;
}

/* Legend items vertical */
.chart-legend .legend-dot {
  cursor: pointer;
  transition: opacity 0.2s ease, background 0.15s ease;
  padding: 0.2rem 0.4rem;
  border-radius: 4px;
  white-space: nowrap;
}

.chart-legend .legend-dot:hover {
  background: rgba(255, 255, 255, 0.1);
}

/* Make legend inside chart section positioned relative */
.chart-section {
  position: relative;
}

.chart-legend-desc {
  margin-top: 0.5rem;
  padding: 0.75rem;
  background: rgba(255, 255, 255, 0.02);
  border-radius: 10px;
  font-size: 0.8rem;
  color: var(--text-muted);
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 0.35rem;
}

.chart-legend-desc strong {
  color: var(--text-secondary);
}

/* ─── Signals List ─── */
.signals-list-section {
  margin-top: 1rem;
  padding-top: 1rem;
  border-top: 1px solid var(--border-subtle);
  flex-shrink: 0;
}

.signals-list-title {
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--text-primary);
  margin-bottom: 0.75rem;
}

.signals-list {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  max-height: 110px;
  overflow-y: auto;
  background: rgba(255, 255, 255, 0.02);
  border-radius: 10px;
  padding: 0.6rem;
}

/* Dashboard chart-first layout (TradingView-like) */
#view-dashboard .stats-container,
#view-dashboard .bottom-stats {
  display: none;
}

#view-dashboard .chart-section {
  flex: 1;
  min-height: calc(100vh - 190px);
}

#view-dashboard .chart-wrapper {
  min-height: 400px;
}

#view-dashboard #stock-chart {
  min-height: calc(100vh - 380px);
}

.signals-empty {
  font-size: 0.8rem;
  color: var(--text-muted);
  padding: 0.5rem;
}

.signals-list-item {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.5rem 0.75rem;
  border-radius: 8px;
  font-size: 0.8rem;
  cursor: pointer;
  transition: background 0.15s ease;
}

.signals-list-item:hover {
  background: rgba(255, 255, 255, 0.06);
}

.signals-list-item.buy {
  border-left: 3px solid var(--accent-green);
}

.signals-list-item.sell {
  border-left: 3px solid var(--accent-red);
}

.signals-list-item.alert {
  border-left: 3px solid var(--text-muted);
}

.signals-list-item .sig-action {
  font-weight: 600;
  min-width: 3rem;
}

.signals-list-item.buy .sig-action { color: var(--accent-green); }
.signals-list-item.sell .sig-action { color: var(--accent-red); }
.signals-list-item.alert .sig-action { color: var(--text-muted); }

.signals-list-item .sig-date {
  color: var(--text-muted);
  font-size: 0.75rem;
}

.signals-list-item .sig-rule {
  color: var(--text-secondary);
  font-size: 0.75rem;
}

.signals-list-item .sig-price {
  margin-left: auto;
  font-weight: 500;
  font-family: "JetBrains Mono", monospace;
}

.symbol-picker {
  margin-bottom: 0.75rem;
  background: rgba(255, 255, 255, 0.02);
  border: 1px solid var(--border-subtle);
  border-radius: 12px;
  padding: 0.6rem 0.8rem;
  flex-shrink: 0;
}

.symbol-picker-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 0.82rem;
}

.selected-symbol-preview {
  margin-top: 0.25rem;
  color: var(--text-muted);
  font-size: 0.75rem;
}

.symbol-picker-actions {
  display: flex;
  align-items: center;
  gap: 0.55rem;
}

.symbol-toggle-btn {
  padding: 0.45rem 0.85rem;
  font-size: 0.75rem;
  border-radius: 9px;
}

.symbol-save-btn {
  padding: 0.45rem 0.85rem;
  font-size: 0.75rem;
  border-radius: 9px;
}

.symbol-dropdown {
  margin-top: 0.7rem;
  border-top: 1px solid var(--border-subtle);
  padding-top: 0.7rem;
  display: none;
}

.symbol-dropdown.open {
  display: block;
}

.symbol-search-wrap {
  margin-bottom: 0.55rem;
}

.symbol-meta {
  color: var(--text-muted);
  font-size: 0.72rem;
  margin-bottom: 0.5rem;
}

.symbol-search-wrap input {
  width: 100%;
  background: #0f1217;
  border: 1px solid var(--border-subtle);
  color: var(--text-primary);
  border-radius: 10px;
  padding: 0.55rem 0.7rem;
  font-size: 0.8rem;
  outline: none;
}

.symbol-search-wrap input:focus {
  border-color: var(--accent-blue);
  box-shadow: 0 0 0 3px rgba(61, 126, 255, 0.12);
}

.symbol-list {
  display: flex;
  flex-wrap: wrap;
  gap: 0.42rem;
  max-height: 170px;
  overflow-y: auto;
  padding-right: 0.2rem;
}

.symbol-chip {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  border: 1px solid var(--border-subtle);
  border-radius: 999px;
  padding: 0.25rem 0.55rem;
  font-size: 0.72rem;
  color: var(--text-secondary);
  background: #0f1217;
  cursor: pointer;
  transition: border-color 0.18s ease, color 0.18s ease;
}

.symbol-chip:hover {
  border-color: var(--border-light);
  color: var(--text-primary);
}

.symbol-chip input {
  accent-color: var(--accent-blue);
}

.symbol-empty {
  color: var(--text-muted);
  font-size: 0.8rem;
}

.live-status {
  margin-bottom: 0.5rem;
  color: var(--text-secondary);
  font-size: 0.76rem;
  flex-shrink: 0;
}

/* ─── Icon Pill Button ─── */
.icon-pill-btn {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  background: var(--bg-sidebar);
  border: 1px solid var(--border-subtle);
  color: var(--text-secondary);
  padding: 0.5rem 1rem;
  border-radius: 12px;
  font-size: 0.8rem;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s ease;
  font-family: inherit;
}
.icon-pill-btn:hover { color: var(--text-primary); border-color: var(--border-light); }

/* ─── View Header ─── */
.view-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: 2rem;
}
.view-subtitle { color: var(--text-muted); font-size: 0.85rem; margin-top: 0.35rem; }
.header-actions { display: flex; align-items: center; gap: 1rem; }

/* ─── Portfolio Hero ─── */
.portfolio-hero {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  padding: 2.5rem;
  margin-bottom: 1.5rem;
  position: relative;
  overflow: hidden;
}
.portfolio-hero::before {
  content: '';
  position: absolute;
  top: -60px; right: -60px;
  width: 300px; height: 300px;
  background: radial-gradient(circle, rgba(61,126,255,0.08) 0%, transparent 70%);
  pointer-events: none;
}
.portfolio-badge {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  background: rgba(46,184,114,0.1);
  color: var(--accent-green);
  font-size: 0.7rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  padding: 0.3rem 0.75rem;
  border-radius: 999px;
  margin-bottom: 1rem;
}
.portfolio-label { font-size: 0.8rem; color: var(--text-secondary); margin-bottom: 0.5rem; font-weight: 600; }
.portfolio-big-value {
  font-size: 2.8rem;
  font-weight: 700;
  letter-spacing: -0.04em;
  color: var(--text-primary);
  margin-bottom: 0.75rem;
  font-family: 'JetBrains Mono', monospace;
}
.portfolio-pnl-row { display: flex; align-items: center; gap: 0.75rem; font-size: 0.9rem; }
.portfolio-hero-right { display: flex; flex-direction: column; gap: 1.5rem; align-items: flex-end; }
.psm-label { font-size: 0.7rem; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.08em; font-weight: 700; margin-bottom: 0.25rem; }
.psm-value { font-size: 1.15rem; font-weight: 700; font-family: 'JetBrains Mono', monospace; color: var(--text-primary); }

/* ─── Portfolio Metrics ─── */
.portfolio-metrics {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 1.25rem;
  margin-bottom: 1.5rem;
}
.metric-card {
  padding: 1.5rem;
  display: flex;
  align-items: center;
  gap: 1.25rem;
  border-radius: 18px;
  background: #11141a;
  border: 1px solid rgba(255,255,255,0.04);
  transition: all 0.3s ease;
}
.metric-card:hover { transform: translateY(-3px); border-color: rgba(255,255,255,0.1); }
.metric-icon {
  width: 48px; height: 48px; min-width: 48px;
  border-radius: 14px;
  background: var(--c);
  color: var(--cc);
  display: flex; align-items: center; justify-content: center;
}
.metric-label { font-size: 0.7rem; color: var(--text-muted); font-weight: 700; text-transform: uppercase; letter-spacing: 0.08em; margin-bottom: 0.4rem; }
.metric-value { font-size: 1.25rem; font-weight: 700; color: var(--text-primary); font-family: 'JetBrains Mono', monospace; letter-spacing: -0.02em; }

/* ─── Portfolio Chart ─── */
.portfolio-chart-wrap { padding: 2rem; margin-bottom: 1.5rem; }
.period-btn {
  background: transparent;
  border: 1px solid var(--border-subtle);
  color: var(--text-muted);
  padding: 0.4rem 0.85rem;
  border-radius: 8px;
  font-size: 0.8rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s ease;
  font-family: inherit;
}
.period-btn.active, .period-btn:hover { background: var(--accent-blue); border-color: var(--accent-blue); color: white; }

/* ─── History View ─── */
.history-summary { display: grid; grid-template-columns: repeat(3, 1fr); gap: 1.25rem; margin-bottom: 1.5rem; }
.hs-card { padding: 1.5rem; display: flex; align-items: center; gap: 1.25rem; border-radius: 18px; background: #11141a; border: 1px solid rgba(255,255,255,0.04); }
.hs-icon { font-size: 1.5rem; font-weight: 700; width: 44px; text-align: center; }
.hs-label { font-size: 0.7rem; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.08em; font-weight: 700; margin-bottom: 0.35rem; }
.hs-value { font-size: 1.3rem; font-weight: 700; font-family: 'JetBrains Mono', monospace; color: var(--text-primary); }
.history-table-wrap { overflow-x: auto; }

/* ─── Search Input ─── */
.search-input-wrap {
  display: flex; align-items: center; gap: 0.75rem;
  background: #12151a; border: 1px solid var(--border-subtle);
  border-radius: 12px; padding: 0.6rem 1rem; color: var(--text-muted);
}
.search-input-wrap input { background: transparent; border: none; outline: none; color: var(--text-primary); font-size: 0.85rem; width: 220px; font-family: inherit; }
.search-input-wrap input::placeholder { color: var(--text-muted); }

/* ─── Enhanced Transaction Table ─── */
.tx-table { width: 100%; border-collapse: collapse; }
.tx-table th {
  text-align: left;
  font-size: 0.65rem; text-transform: uppercase; letter-spacing: 0.1em;
  color: var(--text-muted); padding: 1rem 1.5rem;
  border-bottom: 1px solid var(--border-subtle); font-weight: 700;
  background: rgba(255,255,255,0.015);
}
.tx-table td { padding: 0.9rem 1.5rem; font-size: 0.875rem; border-bottom: 1px solid rgba(255,255,255,0.025); }
.tx-table tr:last-child td { border-bottom: none; }
.tx-table tr:hover td { background: rgba(255,255,255,0.025); }
.tx-icon-wrap { width: 32px; height: 32px; border-radius: 10px; display: flex; align-items: center; justify-content: center; }
.tx-icon-wrap.trend-up { background: rgba(46,184,114,0.1); }
.tx-icon-wrap.trend-down { background: rgba(231,90,90,0.1); }
.tx-desc { color: var(--text-primary); font-weight: 500; }
.tx-type-badge { display: inline-block; padding: 0.2rem 0.65rem; border-radius: 999px; font-size: 0.72rem; font-weight: 700; letter-spacing: 0.04em; }
.tx-type-badge.trend-up { background: rgba(46,184,114,0.12); color: var(--accent-green); }
.tx-type-badge.trend-down { background: rgba(231,90,90,0.12); color: var(--accent-red); }
.tx-amount { font-family: 'JetBrains Mono', monospace; font-weight: 600; font-size: 0.9rem; }
.tx-balance { font-family: 'JetBrains Mono', monospace; font-size: 0.85rem; color: var(--text-secondary); }
.tx-date { color: var(--text-muted); font-size: 0.8rem; }
.tx-empty { text-align: center; color: var(--text-muted); padding: 3rem; }

.wallet-card {
  background: linear-gradient(135deg, rgba(61,126,255,0.08), #11141a) !important;
  border-color: rgba(61,126,255,0.2) !important;
}

@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

/* ── Backtest Styles ───────────────────────────────────────── */
.backtest-form { padding: 1.5rem; margin-bottom: 1.5rem; }
.backtest-form-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 1rem;
  align-items: end;
}
.backtest-form-grid .form-field { display: flex; flex-direction: column; gap: 0.4rem; }
.backtest-form-grid label { font-size: 0.78rem; font-weight: 600; color: var(--text-secondary); text-transform: uppercase; letter-spacing: 0.06em; }
.backtest-form-grid .form-input {
  background: rgba(255,255,255,0.04);
  border: 1px solid rgba(255,255,255,0.08);
  border-radius: 10px;
  padding: 0.65rem 0.9rem;
  color: var(--text-primary);
  font-size: 0.9rem;
  font-family: inherit;
  outline: none;
  transition: border-color 0.2s, box-shadow 0.2s;
}
.backtest-form-grid .form-input:focus { border-color: var(--accent-blue); box-shadow: 0 0 0 3px rgba(61,126,255,0.1); }
.backtest-form-grid .form-field-btn { display: flex; align-items: flex-end; }

.backtest-loading {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.75rem;
  padding: 3rem;
  color: var(--text-secondary);
  font-size: 0.95rem;
}
.spinner {
  width: 22px; height: 22px;
  border: 2.5px solid rgba(255,255,255,0.08);
  border-top-color: var(--accent-blue);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.backtest-results { animation: fadeIn 0.4s ease; }
.backtest-metrics { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 1rem; margin-bottom: 1.25rem; }
.backtest-metrics .metric-value { font-size: 1.15rem; }

.backtest-summary { padding: 1rem 1.5rem; margin-bottom: 1.25rem; }
.summary-row { display: flex; flex-wrap: wrap; gap: 1.5rem 2.5rem; }
.summary-item { display: flex; flex-direction: column; gap: 0.25rem; }
.summary-label { font-size: 0.72rem; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.06em; }
.summary-value { font-family: 'JetBrains Mono', monospace; font-size: 0.95rem; font-weight: 600; color: var(--text-primary); }

.backtest-chart-wrap { padding: 1.5rem; margin-bottom: 1.25rem; }
.backtest-trades-wrap { padding: 1.5rem; overflow-x: auto; }
