/* ==========================================================================
   Dashboard Variables & Base Reset
   ========================================================================== */
:root[data-theme="dark"] {
  --bg-main: var(--bg-primary);
  --bg-card: var(--bg-card);
  --bg-hover: rgba(255,255,255,0.05);
  --border-color: var(--border-subtle);
  --text-main: var(--text-primary);
  --text-muted: var(--text-muted);
  --accent-blue: var(--accent-primary);
  --accent-blue-hover: var(--accent-hover);
  --accent-red: var(--accent-red);
  --accent-green: var(--accent-secondary);
  --radius-md: var(--radius-md);
  --radius-lg: var(--radius-lg);
  --shadow-sm: var(--shadow-sm);
  --font-sans: var(--font-body);
  --font-mono: var(--font-mono);
}

body.dashboard-body {
  /* Inherit global styles */
}

/* Typography Utilities */
.text-blue { color: var(--accent-blue) !important; }
.text-red { color: var(--accent-red) !important; }
.text-green { color: var(--accent-green) !important; }
.text-muted { color: var(--text-muted) !important; }
.text-right { text-align: right; }

/* ==========================================================================
   Header
   ========================================================================== */
.dash-header {
  height: 60px;
  background-color: var(--bg-card);
  border-bottom: 1px solid var(--border-color);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 24px;
  flex-shrink: 0;
}

.dash-welcome h2 {
  margin: 0;
  font-size: 16px;
  font-weight: 500;
  color: var(--text-muted);
}
.dash-welcome h2 span {
  color: var(--accent-blue);
  font-weight: 600;
}
.dash-sync {
  font-size: 12px;
  color: var(--text-muted);
  display: flex;
  align-items: center;
  gap: 6px;
  margin-top: 4px;
}

.account-selector {
  display: flex;
  align-items: center;
  gap: 8px;
  background-color: var(--bg-main);
  padding: 6px 12px;
  border-radius: var(--radius-md);
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  border: 1px solid var(--border-color);
}
.account-selector img {
  border-radius: 50%;
}

.dash-header-right {
  display: flex;
  align-items: center;
  gap: 16px;
}

.view-toggle {
  display: flex;
  background-color: var(--bg-main);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  overflow: hidden;
}
.toggle-btn {
  background: none;
  border: none;
  color: var(--text-muted);
  padding: 8px 16px;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 6px;
  transition: all 0.2s;
}
.toggle-btn:hover {
  color: var(--text-main);
}
.toggle-btn.active {
  background-color: var(--accent-blue);
  color: #fff;
}

.filter-btn, .exit-btn {
  background: none;
  border: none;
  color: var(--text-muted);
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 14px;
  cursor: pointer;
  text-decoration: none;
}
.filter-btn:hover, .exit-btn:hover {
  color: var(--text-main);
}

/* ==========================================================================
   Main Layout & Cards
   ========================================================================== */
.dash-main {
  flex: 1;
  overflow-y: auto;
  padding: 24px;
}

.dash-view {
  display: none;
  animation: fadeIn 0.3s ease;
}
.dash-view.active {
  display: block;
}

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

.dash-card {
  background-color: var(--bg-card);
  border-radius: var(--radius-lg);
  border: 1px solid var(--border-color);
  padding: 20px;
  display: flex;
  flex-direction: column;
}

.stat-label {
  display: block;
  font-size: 13px;
  color: var(--text-muted);
  margin-bottom: 8px;
}
.stat-value {
  display: block;
  font-size: 18px;
  font-weight: 600;
  font-family: var(--font-mono);
}
.stat-value.large {
  font-size: 28px;
}
.stat-value.primary {
  color: var(--accent-blue);
}

/* ==========================================================================
   Metrics View Grid
   ========================================================================== */
.metrics-grid {
  display: grid;
  grid-template-columns: 350px 1fr;
  gap: 24px;
  height: 100%;
}

/* Sidebar */
.metrics-sidebar {
  padding: 0;
  overflow-y: auto;
}
.stat-group {
  padding: 16px 20px;
  border-bottom: 1px solid var(--border-color);
}
.stat-group:last-child {
  border-bottom: none;
}
.stat-group.highlight {
  background: linear-gradient(180deg, rgba(0, 163, 255, 0.05) 0%, rgba(0, 163, 255, 0) 100%);
}
.group-title {
  font-size: 12px;
  color: var(--accent-blue);
  font-weight: 600;
  margin-bottom: 12px;
  display: flex;
  align-items: center;
  gap: 6px;
}
.stat-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 10px;
  font-size: 13px;
}
.stat-row:last-child { margin-bottom: 0; }
.stat-row span:first-child { color: var(--text-muted); }
.stat-row span:last-child { font-family: var(--font-mono); font-weight: 500; }
.stat-row.split { align-items: flex-start; }

/* Content Right */
.metrics-content {
  display: flex;
  flex-direction: column;
  gap: 24px;
}

.top-cards {
  display: grid;
  grid-template-columns: 1fr 2fr;
  gap: 24px;
}

.streak-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
  margin-top: 8px;
}
.streak-item {
  background-color: var(--bg-main);
  padding: 12px;
  border-radius: var(--radius-md);
  border: 1px solid var(--border-color);
}
.streak-val {
  font-size: 24px;
  font-weight: 700;
  font-family: var(--font-mono);
  display: flex;
  align-items: center;
  gap: 8px;
}
.streak-sub {
  font-size: 12px;
  color: var(--text-muted);
  margin-bottom: 8px;
}
.streak-minmax {
  display: flex;
  gap: 8px;
}
.badge {
  font-size: 10px;
  padding: 2px 6px;
  border-radius: 4px;
  font-weight: 600;
}
.badge.blue { background: rgba(0, 163, 255, 0.1); color: var(--accent-blue); border: 1px solid rgba(0, 163, 255, 0.2); }
.badge.red { background: rgba(255, 71, 87, 0.1); color: var(--accent-red); border: 1px solid rgba(255, 71, 87, 0.2); }

.main-chart-card {
  flex: 1;
  min-height: 400px;
}
.chart-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: 16px;
}
.dash-select {
  background: var(--bg-main);
  color: var(--text-main);
  border: 1px solid var(--border-color);
  padding: 6px 12px;
  border-radius: var(--radius-md);
  font-size: 13px;
  outline: none;
}

.bottom-cards {
  display: grid;
  grid-template-columns: 1fr 2fr;
  gap: 24px;
}

.chart-container-large { position: relative; height: 300px; width: 100%; }
.chart-container-medium { position: relative; height: 200px; width: 100%; }
.chart-container-donut { position: relative; height: 180px; width: 100%; margin-top: 16px; }

/* ==========================================================================
   Calendar View Grid
   ========================================================================== */
.calendar-grid {
  display: grid;
  grid-template-columns: 1fr 400px;
  gap: 24px;
}

/* Calendar Component */
.cal-header {
  display: flex;
  align-items: center;
  margin-bottom: 24px;
  gap: 16px;
}
.cal-header h3 { margin: 0; font-size: 20px; font-weight: 600; min-width: 120px; text-align: center; }
.icon-btn {
  background: var(--bg-main);
  border: 1px solid var(--border-color);
  color: var(--text-main);
  width: 32px;
  height: 32px;
  border-radius: var(--radius-md);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: 0.2s;
}
.icon-btn:hover { background: var(--bg-hover); }

.cal-summary {
  margin-left: auto;
  display: flex;
  gap: 24px;
}
.cal-sum-item {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
}
.cal-sum-item span { font-size: 12px; color: var(--text-muted); }
.cal-sum-item strong { font-size: 16px; font-family: var(--font-mono); }

.cal-grid-header {
  display: grid;
  grid-template-columns: repeat(7, 1fr) 80px;
  margin-bottom: 8px;
}
.cal-grid-header div {
  text-align: center;
  font-size: 13px;
  color: var(--text-muted);
  font-weight: 500;
  padding: 8px 0;
}
.cal-grid-body {
  display: grid;
  grid-template-columns: repeat(7, 1fr) 80px;
  gap: 4px;
}
.cal-cell {
  background: var(--bg-main);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  aspect-ratio: 1;
  padding: 8px;
  display: flex;
  flex-direction: column;
  position: relative;
  transition: 0.2s;
}
.cal-cell:hover {
  border-color: rgba(255,255,255,0.2);
}
.cal-cell.empty {
  background: none;
  border-color: transparent;
}
.cal-date {
  font-size: 12px;
  color: var(--text-muted);
  position: absolute;
  top: 8px;
  left: 8px;
}
.cal-data {
  margin-top: auto;
  text-align: center;
}
.cal-prof {
  display: block;
  font-size: 14px;
  font-weight: 600;
  font-family: var(--font-mono);
}
.cal-pct {
  display: block;
  font-size: 11px;
}
.cal-cell.win .cal-prof, .cal-cell.win .cal-pct { color: var(--accent-blue); }
.cal-cell.loss .cal-prof, .cal-cell.loss .cal-pct { color: var(--accent-red); }

/* Win Cell Background Intensity */
.cal-cell.win-1 { background: rgba(0, 163, 255, 0.05); }
.cal-cell.win-2 { background: rgba(0, 163, 255, 0.1); }
.cal-cell.win-3 { background: rgba(0, 163, 255, 0.15); }
.cal-cell.win-4 { background: rgba(0, 163, 255, 0.2); }
.cal-cell.loss-1 { background: rgba(255, 71, 87, 0.05); }
.cal-cell.loss-2 { background: rgba(255, 71, 87, 0.1); }
.cal-cell.loss-3 { background: rgba(255, 71, 87, 0.15); }

/* Withdrawal Calendar Cell */
.cal-cell.cal-withdrawal {
  border: 1.5px solid rgba(0, 230, 118, 0.5) !important;
  background: rgba(0, 230, 118, 0.06) !important;
  position: relative;
  animation: withdrawalPulse 2s ease-in-out infinite;
}
.cal-cell.cal-withdrawal::before {
  content: '';
  position: absolute;
  top: 4px;
  right: 4px;
  width: 8px;
  height: 8px;
  background: #00E676;
  border-radius: 50%;
  box-shadow: 0 0 6px rgba(0, 230, 118, 0.6);
}
@keyframes withdrawalPulse {
  0%, 100% { border-color: rgba(0, 230, 118, 0.3); }
  50% { border-color: rgba(0, 230, 118, 0.7); }
}

/* Withdrawal badge inside calendar cell */
.cal-withdraw-badge {
  display: block;
  font-size: 9px;
  font-weight: 700;
  font-family: var(--font-mono);
  color: #00E676;
  background: rgba(0, 230, 118, 0.1);
  border: 1px solid rgba(0, 230, 118, 0.3);
  border-radius: 3px;
  padding: 1px 4px;
  margin-top: 3px;
  white-space: nowrap;
  cursor: help;
}

.cal-col-total {
  border-left: 1px solid var(--border-color);
}
.cal-cell.total {
  border: 1px dashed var(--border-color);
  background: var(--bg-card);
  display: flex;
  align-items: center;
  justify-content: center;
}

/* Right Charts */
.calendar-charts {
  display: flex;
  flex-direction: column;
  gap: 24px;
}
.top-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 24px;
}
.gauge-container {
  position: relative;
  height: 100px;
  margin-top: 16px;
}
.gauge-center {
  position: absolute;
  bottom: 0;
  left: 50%;
  transform: translateX(-50%);
  font-size: 24px;
  font-weight: 700;
  font-family: var(--font-mono);
}
.ratio-bar {
  display: flex;
  height: 12px;
  border-radius: 6px;
  overflow: hidden;
  margin-top: 24px;
}
.ratio-win { background-color: var(--accent-blue); }
.ratio-loss { background-color: var(--accent-red); }

/* ==========================================================================
   Annual Performance Table
   ========================================================================== */
.annual-card {
  overflow: visible;
}
.annual-table-wrap {
  overflow-x: auto;
}
.annual-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 12px;
  font-family: var(--font-mono);
}
.annual-table th {
  color: var(--text-muted);
  font-weight: 500;
  font-size: 11px;
  padding: 10px 8px;
  text-align: center;
  border-bottom: 1px solid var(--border-color);
  white-space: nowrap;
  font-family: var(--font-sans);
}
.annual-table td {
  padding: 12px 8px;
  text-align: center;
  border: 1px solid var(--border-color);
  color: var(--text-muted);
  font-size: 12px;
  font-weight: 500;
  white-space: nowrap;
}
.annual-table td:first-child {
  font-family: var(--font-sans);
  font-weight: 600;
  color: var(--text-main);
  text-align: left;
  padding-left: 16px;
  background: rgba(255,255,255,0.02);
}
.annual-table td.month-pos {
  color: var(--accent-blue);
  background: rgba(0, 163, 255, 0.04);
}
.annual-table td.month-neg {
  color: var(--accent-red);
  background: rgba(255, 71, 87, 0.04);
}
.annual-table td.ytd-cell {
  font-weight: 700;
  font-size: 13px;
  border-left: 2px solid var(--accent-blue);
}
.annual-table td.month-empty {
  color: var(--text-muted);
  opacity: 0.4;
}
.annual-table .month-sub {
  display: block;
  font-size: 10px;
  color: var(--text-muted);
  opacity: 0.7;
  margin-top: 2px;
}

/* Dashboard Light Theme Overrides */
[data-theme="light"] .dash-card {
  box-shadow: 0 1px 4px rgba(0,0,0,0.05);
}
[data-theme="light"] .cal-cell {
  background: rgba(255, 255, 255, 0.8);
  border-color: rgba(0, 0, 0, 0.06);
}
[data-theme="light"] .cal-cell.empty {
  background: none;
  border-color: transparent;
}
[data-theme="light"] .streak-item {
  background: rgba(0, 0, 0, 0.02);
  border-color: rgba(0, 0, 0, 0.06);
}
[data-theme="light"] .toggle-btn {
  color: #4A5568;
}
[data-theme="light"] .toggle-btn.active {
  background: var(--accent-primary);
  color: #fff;
}
[data-theme="light"] .dash-select {
  background: #fff;
  border-color: rgba(0,0,0,0.1);
}
[data-theme="light"] .account-selector {
  background: rgba(0,0,0,0.03);
  border-color: rgba(0,0,0,0.08);
}
[data-theme="light"] .icon-btn {
  background: #fff;
  border-color: rgba(0,0,0,0.08);
}
[data-theme="light"] .dash-loading {
  background: rgba(245, 247, 250, 0.6);
}
[data-theme="light"] .annual-table td {
  border-color: rgba(0,0,0,0.06);
}
[data-theme="light"] .annual-table td.month-pos {
  background: rgba(0, 163, 255, 0.06);
}
[data-theme="light"] .annual-table td.month-neg {
  background: rgba(255, 71, 87, 0.06);
}
[data-theme="light"] .cal-cell.total {
  background: rgba(0, 0, 0, 0.02);
}

@media (max-width: 1200px) {
  .metrics-grid { grid-template-columns: 1fr; }
  .calendar-grid { grid-template-columns: 1fr; }
  .metrics-sidebar { height: auto; }
  body.dashboard-body { overflow: auto; height: auto; }
}
