/* ═══════════════════════════════════════════════════════════
   DASHBOARD SPECIFIC STYLES
   ═══════════════════════════════════════════════════════════ */

/* ─── Layout ─── */
body {
  overflow: hidden; /* Prevent full page scroll in dashboard */
}

.dashboard-layout {
  display: flex;
  height: 100vh;
  width: 100vw;
  background: var(--bg-primary);
}

/* ─── Sidebar ─── */
.sidebar {
  width: 280px;
  background: var(--bg-card);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  transition: all var(--transition);
  z-index: 50;
}

.sidebar-header {
  height: 80px;
  display: flex;
  align-items: center;
  padding: 0 32px;
  border-bottom: 1px solid var(--border);
}

.sidebar-nav {
  flex: 1;
  padding: 32px 20px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  overflow-y: auto;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 14px 20px;
  border-radius: var(--radius-md);
  color: var(--text-secondary);
  font-weight: 500;
  text-decoration: none;
  transition: all var(--transition);
}

.nav-item:hover {
  background: var(--bg-card-hover);
  color: var(--text-primary);
}

.nav-item.active {
  background: var(--accent-glow);
  color: var(--accent);
  border: 1px solid var(--border-accent);
}

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

/* ─── Main Content ─── */
.main-content {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0; /* Prevent overflow */
}

/* ─── Topbar ─── */
.topbar {
  height: 80px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 40px;
  background: var(--glass-bg);
  backdrop-filter: blur(var(--glass-blur));
  -webkit-backdrop-filter: blur(var(--glass-blur));
  border-bottom: 1px solid var(--border);
  z-index: 40;
}

.topbar-search {
  display: flex;
  align-items: center;
  gap: 12px;
  color: var(--text-muted);
  background: var(--bg-primary);
  padding: 10px 20px;
  border-radius: var(--radius-lg);
  border: 1px solid var(--border);
  width: 300px;
  transition: all var(--transition);
}

.topbar-search:focus-within {
  border-color: var(--border-hover);
  box-shadow: 0 0 0 2px var(--accent-glow);
}

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

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 24px;
}

.profile-badge {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 8px 16px 8px 8px;
  background: var(--bg-card);
  border-radius: 40px;
  border: 1px solid var(--border);
  cursor: pointer;
  transition: all var(--transition);
}

.profile-badge:hover {
  background: var(--bg-card-hover);
  border-color: var(--border-hover);
}

.pb-avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: var(--accent-gradient);
  color: var(--bg-primary);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-family: 'Outfit';
}

.pb-info {
  display: flex;
  flex-direction: column;
}

.pb-name {
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--text-primary);
}

.pb-status {
  font-size: 0.75rem;
  color: var(--green);
  font-weight: 600;
}

/* ─── Dashboard Scroll Area ─── */
.dashboard-scroll-area {
  flex: 1;
  overflow-y: auto;
  padding: 40px;
  display: flex;
  flex-direction: column;
  gap: 32px;
}

.dashboard-header {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
}

.dashboard-header h1 {
  font-family: 'Outfit';
  font-size: 2.5rem;
  margin-bottom: 8px;
}

/* ─── Metrics Grid ─── */
.metrics-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 24px;
}

.metric-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 24px;
  transition: all var(--transition);
}

.metric-card:hover {
  transform: translateY(-4px);
  border-color: var(--border-hover);
  box-shadow: var(--shadow-card);
}

.mc-title {
  color: var(--text-secondary);
  font-size: 0.9rem;
  font-weight: 500;
  margin-bottom: 12px;
}

.mc-value {
  font-family: 'Outfit';
  font-size: 2rem;
  font-weight: 700;
  color: var(--text-primary);
  margin-bottom: 8px;
}

.mc-change {
  font-size: 0.85rem;
  font-weight: 600;
}

.mc-change.positive { color: var(--green); }
.mc-change.negative { color: var(--red); }
.mc-change.neutral { color: var(--text-muted); }

/* ─── Main Grid (Chart + Rules) ─── */
.main-grid {
  display: grid;
  grid-template-columns: 2fr 1fr;
  gap: 24px;
}

.card-panel {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-xl);
  padding: 32px;
}

.panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 24px;
}

.panel-header h3 {
  font-family: 'Outfit';
  font-size: 1.25rem;
}

.custom-select {
  background: var(--bg-primary);
  color: var(--text-secondary);
  border: 1px solid var(--border);
  padding: 8px 16px;
  border-radius: var(--radius-sm);
  outline: none;
  font-family: inherit;
  font-size: 0.9rem;
}

.chart-wrapper {
  width: 100%;
  height: 300px;
  position: relative;
}

/* ─── Rules Tracking List ─── */
.rules-list {
  display: flex;
  flex-direction: column;
  gap: 24px;
}

.rule-item {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.ri-header {
  display: flex;
  justify-content: space-between;
  font-size: 0.95rem;
  font-weight: 600;
}

.text-green { color: var(--green); }
.text-red { color: var(--red); }
.text-accent { color: var(--accent); }

.ri-bar-bg {
  width: 100%;
  height: 8px;
  background: rgba(255,255,255,0.05);
  border-radius: 4px;
  overflow: hidden;
}
.light-theme .ri-bar-bg { background: rgba(0,0,0,0.05); }

.ri-bar-fill {
  height: 100%;
  border-radius: 4px;
  transition: width 1s ease;
}

.ri-footer {
  font-size: 0.8rem;
  color: var(--text-secondary);
}

/* ─── Trade History Table ─── */
.table-responsive {
  overflow-x: auto;
}

.data-table {
  width: 100%;
  border-collapse: collapse;
}

.data-table th {
  text-align: left;
  padding: 16px;
  color: var(--text-muted);
  font-weight: 500;
  font-size: 0.85rem;
  border-bottom: 1px solid var(--border);
}

.data-table td {
  padding: 16px;
  border-bottom: 1px solid var(--border);
  font-size: 0.95rem;
}

.data-table tbody tr:last-child td {
  border-bottom: none;
}

.data-table tbody tr {
  transition: background var(--transition);
}

.data-table tbody tr:hover {
  background: rgba(255,255,255,0.01);
}

.light-theme .data-table tbody tr:hover {
  background: rgba(0,0,0,0.02);
}

.badge {
  padding: 6px 12px;
  border-radius: 20px;
  font-size: 0.8rem;
  font-weight: 600;
}

.badge-buy { background: rgba(16, 185, 129, 0.1); color: var(--green); }
.badge-sell { background: rgba(239, 68, 68, 0.1); color: var(--red); }

.text-right { text-align: right; }

/* ─── Responsive ─── */
@media (max-width: 1024px) {
  .metrics-grid { grid-template-columns: repeat(2, 1fr); }
  .main-grid { grid-template-columns: 1fr; }
}

@media (max-width: 768px) {
  body { overflow: auto; } /* Restore native scrolling on mobile */
  .dashboard-layout { display: block; height: auto; min-height: 100vh; }
  .sidebar {
    width: 100%; height: 65px; flex-direction: row; position: fixed; bottom: 0; left: 0; z-index: 100;
    border-right: none; border-top: 1px solid var(--border); padding: 0;
  }
  .sidebar-header, .sidebar-footer { display: none; }
  .sidebar-nav {
    flex-direction: row; padding: 0; justify-content: space-around; align-items: center; width: 100%; height: 100%;
  }
  .sidebar span { display: none; }
  .nav-item { flex: 1; justify-content: center; height: 100%; border-radius: 0; padding: 0; }
  .nav-item.active { border: none; border-top: 2px solid var(--accent); background: rgba(16,185,129,0.05); }
  
  .main-content { display: block; margin-bottom: 80px; }
  .dashboard-scroll-area { overflow: visible; padding: 20px; }
  
  .dashboard-header { flex-direction: column; align-items: flex-start; gap: 20px; }
  .topbar-search { width: auto; flex: 1; margin-right: 0; }
  .topbar { padding: 0 20px; }
  
  /* Trading Pro Layout Fixes */
  .trade-pro-layout { flex-direction: column; gap: 10px; }
  .tr-chart-container .panel-header { flex-direction: column !important; align-items: flex-start !important; gap: 8px; padding-bottom: 8px; }
  .timeframe-selector { overflow-x: auto; width: 100%; padding-bottom: 4px; }
  .timeframe-selector::-webkit-scrollbar { display: none; }
  
  /* Make chart large again */
  #tvChart { min-height: 450px !important; height: 450px !important; }
  
  /* Ultra-compact Trade Ticket for Mobile */
  .trade-ticket { padding: 12px; }
  .trade-ticket .panel-header { display: none; } /* Hide "New Order" */
  .trade-ticket > .tr-select { margin-bottom: 8px; }
  .trade-ticket > .tr-price { font-size: 1.3rem !important; margin: 4px 0 8px !important; text-align: center; }
  .trade-ticket > div[style*="display:grid"] {
    grid-template-columns: repeat(3, 1fr) !important;
    gap: 8px !important;
    margin-bottom: 12px !important;
  }
  .tr-select, .tr-input { padding: 8px 6px; margin-bottom: 0; font-size: 0.9rem; }
  .tr-label { font-size: 0.7rem; margin-bottom: 4px; }
  .tr-buttons { gap: 8px; }
  .tr-buttons .btn { padding: 12px; font-size: 0.9rem; }
}

@media (max-width: 480px) {
  .metrics-grid { grid-template-columns: 1fr; }
  .dashboard-scroll-area { padding: 20px; }
  .topbar { padding: 0 20px; }
  .pb-info { display: none; }
}

/* Account lifecycle panel (SP3) */
.acct-row { display: flex; align-items: center; gap: 14px; flex-wrap: wrap; }
.acct-msg { color: var(--text-secondary, #8892a8); }
.acct-badge { display: inline-flex; align-items: center; padding: 4px 12px; border-radius: 999px;
  background: var(--accent-glow, rgba(16,185,129,0.12)); color: var(--accent, #10b981);
  font-weight: 600; font-size: 0.85rem; text-transform: capitalize; }
.sub-badge { display:inline-flex; align-items:center; padding:4px 12px; border-radius:999px; font-size:0.8rem; font-weight:600; }
.sub-active { background: var(--accent-glow, rgba(16,185,129,0.12)); color: var(--accent, #10b981); text-transform: capitalize; }
.sub-inactive { background: rgba(148,163,184,0.12); color: var(--text-secondary, #8892a8); }

/* Live trading panel (SP4) */
.trade-grid { display: grid; grid-template-columns: 320px 1fr; gap: 20px; }
@media (max-width: 768px) { .trade-grid { grid-template-columns: 1fr; } }
.trade-ticket .tr-select, .trade-ticket .tr-input {
  width: 100%; padding: 10px 12px; margin-bottom: 12px; border-radius: 10px;
  background: rgba(255,255,255,0.04); border: 1px solid rgba(255,255,255,0.1);
  color: var(--text, #f1f5f9); font: inherit; box-sizing: border-box; }
.tr-price { font-size: 1.8rem; font-weight: 700; margin: 4px 0 12px; font-variant-numeric: tabular-nums; }
.tr-label { font-size: 0.78rem; color: var(--text-secondary, #8892a8); display: block; margin-bottom: 6px; }
.tr-buttons { display: flex; gap: 10px; }
.tr-buttons .btn { flex: 1; }
.tr-err { color: #f87171; font-size: 0.85rem; min-height: 1.1em; margin-top: 10px; }
.tr-equity { font-weight: 600; color: var(--accent, #10b981); font-size: 0.95rem; }
.tr-pos { display: flex; align-items: center; gap: 12px; padding: 10px 0; border-bottom: 1px solid rgba(255,255,255,0.06); }
.tr-pos-sym { flex: 1; font-weight: 600; }
.tr-pos-side { text-transform: uppercase; font-size: 0.7rem; padding: 2px 6px; border-radius: 4px; }
.tr-pos-side.long { background: rgba(16,185,129,0.15); color: #10b981; }
.tr-pos-side.short { background: rgba(248,113,113,0.15); color: #f87171; }
.tr-pos-entry { color: var(--text-secondary, #8892a8); font-size: 0.85rem; font-variant-numeric: tabular-nums; }
.tr-pos-pnl { font-variant-numeric: tabular-nums; font-weight: 600; min-width: 80px; text-align: right; }
.text-green { color: #10b981; } .text-red { color: #f87171; }

/* Risk banners (SP5) */
.risk-banner { padding: 16px 20px; border-radius: 12px; line-height: 1.5; }
.risk-banner.breached { background: rgba(248,113,113,0.10); border: 1px solid rgba(248,113,113,0.35); color: #fecaca; }
.risk-banner.funded { background: rgba(16,185,129,0.10); border: 1px solid rgba(16,185,129,0.35); color: #a7f3d0; }

/* Fix: stack Account Growth + Objectives on mobile (was clipped at ~804px) */
@media (max-width: 768px) {
  .main-grid { grid-template-columns: 1fr !important; }
  .main-grid > * { min-width: 0 !important; width: auto !important; }
  .chart-container, .rules-tracking { min-width: 0 !important; width: auto !important; max-width: 100% !important; }
  .chart-wrapper, #growthChart { max-width: 100% !important; }
}

/* ─── Pro Trading Layout ─── */
.trade-pro-layout {
  display: flex;
  gap: 20px;
  flex-direction: row;
}
.tr-chart-container {
  flex: 1;
  display: flex;
  flex-direction: column;
}
.timeframe-selector {
  display: flex;
  gap: 4px;
}
.tf-btn {
  background: transparent;
  border: 1px solid rgba(255, 255, 255, 0.1);
  color: #8892a8;
  padding: 4px 8px;
  border-radius: 4px;
  cursor: pointer;
  font-size: 0.85rem;
  transition: all 0.2s;
}
.tf-btn:hover {
  background: rgba(255, 255, 255, 0.05);
}
.tf-btn.active {
  background: #10b981;
  color: #fff;
  border-color: #10b981;
}
.light-theme .tf-btn {
  border: 1px solid rgba(0, 0, 0, 0.1);
  color: #475569;
}
.light-theme .tf-btn:hover {
  background: rgba(0, 0, 0, 0.05);
}
.light-theme .tf-btn.active {
  background: #10b981;
  color: #fff;
  border-color: #10b981;
}
.tr-sidebar {
  width: 340px;
  display: flex;
  flex-direction: column;
}
@media (max-width: 1024px) {
  .trade-pro-layout {
    flex-direction: column;
  }
  .tr-sidebar {
    width: 100%;
  }
}
.tv-lightweight-charts {
  font-family: inherit !important;
}
