/* ==========================================================
   HyperCopy Platform - Dark Theme Stylesheet
   Matches the existing dashboard design at localhost:3456
   ========================================================== */

/* ── Reset ── */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

/* ── Variables ── */
:root {
  --bg-body: #0a0e14;
  --bg-card: #111820;
  --bg-card-hover: #161e28;
  --bg-input: #0d1117;
  --bg-badge: #1c2128;
  --border: #1c2128;
  --border-focus: #30363d;
  --text-primary: #f0f6fc;
  --text-secondary: #c9d1d9;
  --text-muted: #6e7681;
  --text-dim: #484f58;
  --color-green: #3fb950;
  --color-red: #f85149;
  --color-yellow: #d29922;
  --color-blue: #58a6ff;
  --color-cyan: #39d2c0;
  --font-mono: 'SF Mono', 'Consolas', 'Monaco', monospace;
  --font-sans: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
  --radius: 8px;
  --radius-lg: 10px;
}

/* ── Base ── */
body {
  font-family: var(--font-sans);
  background: var(--bg-body);
  color: var(--text-secondary);
  min-height: 100vh;
  line-height: 1.5;
}

.container {
  max-width: 1200px;
  margin: 0 auto;
  padding: 24px;
}

/* ── Typography ── */
h1 {
  font-size: 22px;
  font-weight: 600;
  color: var(--text-primary);
  margin-bottom: 6px;
}

h2 {
  font-size: 15px;
  font-weight: 600;
  color: var(--text-primary);
  margin-bottom: 4px;
}

.subtitle {
  font-size: 13px;
  color: var(--text-muted);
  margin-bottom: 20px;
}

.mono {
  font-family: var(--font-mono);
}

/* ── Status Bar ── */
.status-bar {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  color: var(--color-green);
  background: #2386361a;
  padding: 4px 12px;
  border-radius: 20px;
  margin-bottom: 20px;
}

.status-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--color-green);
  animation: pulse 2s infinite;
}

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.4; }
}

/* ── Cards and Sections ── */
.card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 18px 20px;
  margin-bottom: 20px;
}

.card-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: 14px;
}

.network-badge {
  font-size: 10px;
  font-weight: 700;
  padding: 3px 10px;
  border-radius: 4px;
  text-transform: uppercase;
  letter-spacing: 0.6px;
}

.badge-testnet {
  background: #1f6feb22;
  color: var(--color-blue);
  border: 1px solid #1f6feb44;
}

.badge-mainnet {
  background: #23863622;
  color: var(--color-green);
  border: 1px solid #23863644;
}

/* ── Info Grid ── */
.info-grid {
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 16px;
  margin-bottom: 14px;
}

.info-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 5px 0;
  border-bottom: 1px solid #161b22;
}

.info-row:last-child {
  border-bottom: none;
}

.info-label {
  font-size: 13px;
  color: var(--text-muted);
}

.info-value {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-primary);
  font-family: var(--font-mono);
}

.info-value.positive { color: var(--color-green); }
.info-value.negative { color: var(--color-red); }
.info-value.leverage { color: var(--color-yellow); }

/* ── Positions Table ── */
.positions-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
}

@media (max-width: 900px) {
  .positions-grid {
    grid-template-columns: 1fr;
  }
}

.positions-scroll {
  overflow-x: auto;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

thead th {
  text-align: left;
  padding: 10px 12px;
  color: var(--text-muted);
  font-weight: 500;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}

tbody td {
  padding: 12px 12px;
  border-bottom: 1px solid #161b22;
  white-space: nowrap;
}

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

tbody tr:hover {
  background: var(--bg-card-hover);
}

.coin-cell {
  display: flex;
  align-items: center;
  gap: 8px;
}

.coin-icon {
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: #f7931a;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 11px;
  font-weight: 700;
  color: white;
}

.coin-name {
  font-weight: 600;
  color: var(--text-primary);
}

.dir-badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 4px;
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.dir-long { background: #23863633; color: var(--color-green); }
.dir-short { background: #da363333; color: var(--color-red); }

/* ── Forms ── */
.form-group {
  margin-bottom: 16px;
}

.form-label {
  display: block;
  font-size: 12px;
  color: var(--text-muted);
  margin-bottom: 6px;
  text-transform: uppercase;
  letter-spacing: 0.3px;
}

.form-input {
  width: 100%;
  padding: 10px 14px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text-primary);
  font-family: var(--font-mono);
  font-size: 13px;
  outline: none;
  transition: border-color 0.15s;
}

.form-input:focus {
  border-color: var(--color-blue);
}

.form-input::placeholder {
  color: var(--text-dim);
}

.form-input.error {
  border-color: var(--color-red);
}

.form-error {
  font-size: 11px;
  color: var(--color-red);
  margin-top: 4px;
}

/* ── Buttons ── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 10px 20px;
  border: none;
  border-radius: var(--radius);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: opacity 0.15s, background 0.15s;
  font-family: var(--font-sans);
}

.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.btn:hover:not(:disabled) {
  opacity: 0.9;
}

.btn-primary {
  background: var(--color-blue);
  color: white;
}

.btn-success {
  background: #238636;
  color: white;
}

.btn-danger {
  background: #da3633;
  color: white;
}

.btn-outline {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text-secondary);
}

.btn-outline:hover:not(:disabled) {
  border-color: var(--text-muted);
  background: var(--bg-card-hover);
}

.btn-outline.active {
  border-color: var(--color-blue);
  color: var(--color-blue);
  background: #1f6feb22;
}

.btn-group {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}

.btn-group .btn {
  flex: 1;
  min-width: 60px;
  padding: 8px 12px;
  font-size: 12px;
}

/* ── Ratio / Mode Selectors ── */
.ratio-preset-grid {
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  gap: 6px;
  margin-bottom: 8px;
}

.ratio-preset-grid .btn {
  padding: 8px 4px;
  font-size: 12px;
  min-width: 0;
}

.custom-ratio-input {
  width: 120px;
}

.mode-toggle {
  display: flex;
  gap: 6px;
}

.mode-toggle .btn {
  flex: 1;
  padding: 10px 16px;
  font-size: 13px;
}

/* ── Two-column account layout ── */
.account-columns {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
  margin-bottom: 14px;
}

@media (max-width: 900px) {
  .account-columns {
    grid-template-columns: 1fr;
  }
}

.account-column {
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 16px;
}

.account-column-header {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-muted);
  margin-bottom: 8px;
  text-transform: uppercase;
  letter-spacing: 0.3px;
}

/* ── Steps ── */
.step {
  display: none;
}

.step.active {
  display: block;
}

.step-number {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: var(--color-blue);
  color: white;
  font-size: 12px;
  font-weight: 700;
  margin-right: 8px;
}

/* ── Balance Display ── */
.balance-display {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin-bottom: 14px;
}

.balance-icon {
  font-size: 24px;
}

.balance-amount {
  font-size: 18px;
  font-weight: 700;
  color: var(--text-primary);
  font-family: var(--font-mono);
}

.balance-label {
  font-size: 11px;
  color: var(--text-muted);
}

/* ── Trade History ── */
.trade-history {
  margin-top: 16px;
}

.trade-history h3 {
  font-size: 12px;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.3px;
  margin-bottom: 8px;
}

/* ── Error / Empty States ── */
.error-state {
  background: #da363322;
  color: var(--color-red);
  padding: 12px 16px;
  border-radius: var(--radius);
  font-size: 12px;
  margin-bottom: 12px;
}

.empty-state {
  text-align: center;
  padding: 20px;
  color: var(--text-dim);
  font-size: 13px;
}

/* ── Loading Spinner ── */
.spinner {
  display: inline-block;
  width: 14px;
  height: 14px;
  border: 2px solid var(--text-muted);
  border-top-color: var(--color-blue);
  border-radius: 50%;
  animation: spin 0.6s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

/* ── Password Visibility Toggle ── */
.input-wrapper {
  position: relative;
}

.input-wrapper .form-input {
  padding-right: 40px;
}

.toggle-visibility {
  position: absolute;
  right: 10px;
  top: 50%;
  transform: translateY(-50%);
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 14px;
  padding: 4px;
}

/* ── Last Updated ── */
.last-updated {
  text-align: center;
  font-size: 11px;
  color: var(--text-dim);
  margin-top: 12px;
}

/* ── Nav Bar ── */
.nav-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 0;
  margin-bottom: 12px;
  border-bottom: 1px solid var(--border);
}
.nav-left {
  display: flex;
  flex-direction: column;
}
.nav-title {
  font-size: 20px;
  font-weight: 700;
  color: var(--text-primary);
}
.nav-subtitle {
  font-size: 11px;
  color: var(--text-muted);
  margin-top: 1px;
}
.nav-right {
  display: flex;
  gap: 6px;
}
.nav-btn {
  background: var(--bg-badge);
  border: 1px solid var(--border);
  color: var(--text-muted);
  padding: 6px 16px;
  font-size: 12px;
  font-weight: 600;
  border-radius: 6px;
  cursor: pointer;
  transition: all 0.15s;
}
.nav-btn:hover:not(:disabled) {
  border-color: var(--text-muted);
  color: var(--text-secondary);
}
.nav-btn.active {
  background: var(--bg-badge);
  border-color: var(--color-blue);
  color: var(--color-blue);
}
.nav-btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

/* ── Action Buttons ── */
.btn-danger {
  background: #da3633;
  border: 1px solid #da3633;
  color: #fff;
}
.btn-danger:hover {
  background: #b62324;
  border-color: #b62324;
}
.btn-warning {
  background: #d29922;
  border: 1px solid #d29922;
  color: #fff;
}
.btn-warning:hover {
  background: #bb8009;
  border-color: #bb8009;
}

/* ── FAQ ── */
.faq-item {
  background: var(--bg-card);
  transition: border-color 0.15s ease;
}
.faq-item:hover {
  border-color: var(--border-focus) !important;
}
.faq-question:hover {
  opacity: 0.92;
}
.faq-answer a {
  color: var(--color-blue);
  text-decoration: none;
}
.faq-answer a:hover {
  text-decoration: underline;
}

/* ── Tutorial Box ── */
.tutorial-box {
  background: #0d1b2a;
  border: 1px solid #1b3a5c;
  border-radius: var(--radius);
  padding: 16px 20px;
  margin-bottom: 20px;
}

.tutorial-title {
  font-size: 13px;
  font-weight: 600;
  color: var(--color-blue);
  margin-bottom: 10px;
}

.tutorial-steps {
  font-size: 13px;
  color: var(--text-secondary);
  padding-left: 20px;
  margin: 0;
  line-height: 1.7;
}

.tutorial-steps li {
  margin-bottom: 4px;
}

.tutorial-steps a {
  color: var(--color-blue);
  text-decoration: none;
}

.tutorial-steps a:hover {
  text-decoration: underline;
}

.tutorial-steps strong {
  color: var(--text-primary);
}

.tutorial-security {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  margin-top: 12px;
  padding-top: 10px;
  border-top: 1px solid #1b3a5c;
  font-size: 12px;
  color: var(--text-muted);
}

.tutorial-security div {
  display: flex;
  align-items: center;
  gap: 4px;
}

/* ═══════════════════════════════════════════════════════════
   PHASE 1: Performance Metrics, Toast, Skeletons, Status Bar
   ═══════════════════════════════════════════════════════════ */

/* ── Performance Metrics ── */
.performance-metrics {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 18px 20px;
  margin-bottom: 20px;
}

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

.metrics-header h3 {
  font-size: 14px;
  font-weight: 600;
  color: var(--text-primary);
  margin: 0;
}

.metrics-period {
  font-size: 11px;
  color: var(--text-muted);
  font-family: var(--font-mono);
}

.metrics-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 12px;
}

.metric-card {
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 14px;
  transition: border-color 0.15s;
}

.metric-card:hover {
  border-color: var(--border-focus);
}

.metric-label {
  font-size: 11px;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.3px;
  margin-bottom: 6px;
}

.metric-value {
  font-size: 18px;
  font-weight: 700;
  color: var(--text-primary);
  font-family: var(--font-mono);
  margin-bottom: 4px;
}

.metric-value.positive {
  color: var(--color-green);
}

.metric-value.negative {
  color: var(--color-red);
}

.metric-sublabel {
  font-size: 11px;
  color: var(--text-secondary);
  font-family: var(--font-mono);
}

/* ── Toast Notifications ── */
.toast-container {
  position: fixed;
  top: 20px;
  right: 20px;
  z-index: 10000;
  display: flex;
  flex-direction: column;
  gap: 10px;
  max-width: 400px;
  pointer-events: none;
}

.toast {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 16px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
  transform: translateX(400px);
  opacity: 0;
  transition: transform 0.3s ease, opacity 0.3s ease;
  pointer-events: auto;
}

.toast-show {
  transform: translateX(0);
  opacity: 1;
}

.toast-hide {
  transform: translateX(400px);
  opacity: 0;
}

.toast-content {
  display: flex;
  align-items: center;
  gap: 10px;
}

.toast-icon {
  font-size: 16px;
  flex-shrink: 0;
}

.toast-message {
  flex: 1;
  font-size: 13px;
  color: var(--text-secondary);
  line-height: 1.4;
}

.toast-close {
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 18px;
  cursor: pointer;
  padding: 0;
  width: 20px;
  height: 20px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: color 0.15s;
}

.toast-close:hover {
  color: var(--text-primary);
}

.toast-success {
  border-left: 3px solid var(--color-green);
}

.toast-error {
  border-left: 3px solid var(--color-red);
}

.toast-warning {
  border-left: 3px solid var(--color-yellow);
}

.toast-info {
  border-left: 3px solid var(--color-blue);
}

.toast-trade {
  border-left: 3px solid var(--color-cyan);
}

/* ── Loading Skeletons ── */
.skeleton {
  pointer-events: none;
}

.skeleton-pulse {
  background: linear-gradient(90deg, 
    var(--bg-input) 0%, 
    var(--bg-card-hover) 50%, 
    var(--bg-input) 100%
  );
  background-size: 200% 100%;
  animation: skeleton-pulse 1.5s ease-in-out infinite;
  border-radius: 4px;
}

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

.skeleton-header {
  height: 14px;
  width: 40%;
  margin-bottom: 12px;
}

.skeleton-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 8px 0;
  border-bottom: 1px solid #161b22;
}

.skeleton-row:last-child {
  border-bottom: none;
}

.skeleton-label {
  height: 12px;
  width: 35%;
}

.skeleton-value {
  height: 12px;
  width: 25%;
}

.skeleton-cell {
  height: 14px;
  width: 60px;
}

.skeleton-coin {
  display: flex;
  align-items: center;
  gap: 8px;
}

.skeleton-coin-icon {
  width: 24px;
  height: 24px;
  border-radius: 50%;
  flex-shrink: 0;
}

.skeleton-coin-name {
  height: 12px;
  width: 40px;
  margin-bottom: 4px;
}

.skeleton-coin-sub {
  height: 10px;
  width: 30px;
}

.skeleton-period {
  height: 11px;
  width: 80px;
}

.skeleton-metric-label {
  height: 11px;
  width: 60%;
  margin-bottom: 8px;
}

.skeleton-metric-value {
  height: 18px;
  width: 80%;
  margin-bottom: 6px;
}

.skeleton-metric-sublabel {
  height: 11px;
  width: 50%;
}

/* ── Enhanced Status Bar ── */
.status-bar-enhanced {
  display: flex;
  align-items: center;
  gap: 16px;
  font-size: 12px;
  padding: 8px 16px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin-bottom: 20px;
  flex-wrap: wrap;
}

.status-item {
  display: flex;
  align-items: center;
  gap: 6px;
}

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
}

.status-dot.connected {
  background: var(--color-green);
  box-shadow: 0 0 8px var(--color-green);
  animation: pulse-green 2s infinite;
}

.status-dot.reconnecting {
  background: var(--color-yellow);
  box-shadow: 0 0 8px var(--color-yellow);
  animation: pulse-yellow 1s infinite;
}

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

@keyframes pulse-green {
  0%, 100% { 
    opacity: 1;
    box-shadow: 0 0 8px var(--color-green);
  }
  50% { 
    opacity: 0.6;
    box-shadow: 0 0 4px var(--color-green);
  }
}

@keyframes pulse-yellow {
  0%, 100% { 
    opacity: 1;
    box-shadow: 0 0 8px var(--color-yellow);
  }
  50% { 
    opacity: 0.6;
    box-shadow: 0 0 4px var(--color-yellow);
  }
}

.status-label {
  color: var(--text-muted);
  font-weight: 500;
}

.status-value {
  color: var(--text-primary);
  font-family: var(--font-mono);
  font-weight: 600;
}

.status-value.synced {
  color: var(--color-green);
}

.status-value.lagging {
  color: var(--color-yellow);
}

.status-value.error {
  color: var(--color-red);
}

.status-separator {
  width: 1px;
  height: 16px;
  background: var(--border);
}

.status-updated {
  color: var(--text-muted);
  font-size: 11px;
  margin-left: auto;
}

@media (max-width: 768px) {
  .status-bar-enhanced {
    font-size: 11px;
    gap: 12px;
  }
  
  .status-separator {
    display: none;
  }
  
  .metrics-grid {
    grid-template-columns: repeat(2, 1fr);
  }
  
  .toast-container {
    top: 10px;
    right: 10px;
    left: 10px;
    max-width: none;
  }
}

/* ═══════════════════════════════════════════════════════════
   PHASE 2: Position Comparison, Advanced Management, Visual
   ═══════════════════════════════════════════════════════════ */

/* ── Position Comparison ── */
.position-comparison {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 18px 20px;
  margin-bottom: 20px;
}

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

.comparison-header h3 {
  font-size: 14px;
  font-weight: 600;
  color: var(--text-primary);
  margin: 0;
}

.comparison-ratio {
  font-size: 12px;
  color: var(--color-blue);
  font-weight: 600;
  padding: 4px 10px;
  background: #1f6feb22;
  border: 1px solid #1f6feb44;
  border-radius: 4px;
}

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

.comparison-table thead th {
  text-align: left;
  padding: 10px 12px;
  color: var(--text-muted);
  font-weight: 500;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  border-bottom: 1px solid var(--border);
}

.comparison-table tbody td {
  padding: 12px;
  border-bottom: 1px solid #161b22;
  vertical-align: middle;
}

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

.comparison-table tbody tr:hover {
  background: var(--bg-card-hover);
}

.position-cell {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.position-main {
  display: flex;
  align-items: center;
  gap: 8px;
}

.position-size {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-primary);
}

.position-details {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 11px;
}

.position-leverage {
  color: var(--color-yellow);
  font-weight: 600;
}

.no-position {
  color: var(--text-dim);
  font-size: 16px;
}

.delta-cell {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.delta-value {
  font-size: 13px;
  font-weight: 600;
  font-family: var(--font-mono);
}

.delta-value.positive {
  color: var(--color-green);
}

.delta-value.negative {
  color: var(--color-red);
}

.delta-pct {
  font-size: 11px;
  font-family: var(--font-mono);
}

.delta-pct.success {
  color: var(--color-green);
}

.delta-pct.warning {
  color: var(--color-yellow);
}

.delta-pct.error {
  color: var(--color-red);
}

.status-badge {
  display: inline-block;
  padding: 3px 8px;
  border-radius: 4px;
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.status-badge.success {
  background: #23863633;
  color: var(--color-green);
}

.status-badge.warning {
  background: #d2992233;
  color: var(--color-yellow);
}

.status-badge.error {
  background: #da363333;
  color: var(--color-red);
}

/* ── Position Controls ── */
.positions-controls {
  display: flex;
  gap: 16px;
  margin-bottom: 12px;
  padding: 12px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  flex-wrap: wrap;
}

.filter-group,
.sort-group {
  display: flex;
  align-items: center;
  gap: 8px;
}

.filter-group label,
.sort-group label {
  font-size: 12px;
  color: var(--text-muted);
  font-weight: 500;
}

.btn-sm {
  padding: 6px 12px;
  font-size: 11px;
}

.close-position-btn {
  white-space: nowrap;
}

/* ── Trade History Enhancements ── */
.trade-history-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 12px;
}

.trade-history-header h3 {
  font-size: 14px;
  font-weight: 600;
  color: var(--text-primary);
  margin: 0;
}

.trade-stats {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
  gap: 12px;
  margin-bottom: 12px;
  padding: 12px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

.stat-item {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.stat-label {
  font-size: 11px;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.3px;
}

.stat-value {
  font-size: 14px;
  font-weight: 600;
  color: var(--text-primary);
  font-family: var(--font-mono);
}

.trade-filters {
  display: flex;
  gap: 16px;
  margin-bottom: 12px;
  padding: 12px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  flex-wrap: wrap;
}

.pagination {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 12px;
  margin-top: 16px;
  padding: 12px;
}

.page-info {
  font-size: 12px;
  color: var(--text-muted);
  font-family: var(--font-mono);
}

/* ── Visual Enhancements ── */
.position-bars {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 18px 20px;
  margin-bottom: 20px;
}

.position-bars h4 {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-primary);
  margin-bottom: 16px;
}

.bars-container {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.bar-row {
  display: grid;
  grid-template-columns: 100px 1fr 120px;
  gap: 12px;
  align-items: center;
}

.bar-label {
  display: flex;
  align-items: center;
  gap: 8px;
}

.bar-coin {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-primary);
}

.bar-direction {
  font-size: 10px;
  font-weight: 700;
  padding: 2px 6px;
  border-radius: 3px;
  text-transform: uppercase;
}

.bar-track {
  height: 24px;
  background: var(--bg-input);
  border-radius: 4px;
  overflow: hidden;
  position: relative;
}

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

.bar-fill.bar-long {
  background: linear-gradient(90deg, var(--color-green), #2ea043);
}

.bar-fill.bar-short {
  background: linear-gradient(90deg, var(--color-red), #b62324);
}

.bar-value {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 2px;
}

.bar-size {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-primary);
}

.bar-pnl {
  font-size: 11px;
  font-weight: 600;
}

.bar-pnl.pnl-positive {
  color: var(--color-green);
}

.bar-pnl.pnl-negative {
  color: var(--color-red);
}

/* ── PnL Heatmap ── */
.pnl-heatmap {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 18px 20px;
  margin-bottom: 20px;
}

.pnl-heatmap h4 {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-primary);
  margin-bottom: 16px;
}

.heatmap-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
  gap: 8px;
}

.heatmap-cell {
  padding: 12px;
  border-radius: var(--radius);
  text-align: center;
  transition: transform 0.15s;
}

.heatmap-cell:hover {
  transform: scale(1.05);
}

.heatmap-coin {
  font-size: 12px;
  font-weight: 700;
  margin-bottom: 4px;
}

.heatmap-pnl {
  font-size: 14px;
  font-weight: 700;
  margin-bottom: 2px;
}

.heatmap-pct {
  font-size: 11px;
  opacity: 0.9;
}

/* ── Sparklines ── */
.sparkline {
  display: block;
}

.sparkline-empty {
  color: var(--text-dim);
  font-size: 12px;
  text-align: center;
  padding: 8px;
}

@media (max-width: 768px) {
  .bar-row {
    grid-template-columns: 80px 1fr 100px;
    gap: 8px;
  }
  
  .heatmap-grid {
    grid-template-columns: repeat(auto-fill, minmax(100px, 1fr));
  }
}

/* ═══════════════════════════════════════════════════════════
   PHASE 3: Risk Management, Analytics, UX Improvements
   ═══════════════════════════════════════════════════════════ */

/* ── Risk Settings ── */
.risk-settings {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 18px 20px;
  margin-bottom: 20px;
}

.risk-settings-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 16px;
}

.risk-settings-header h3 {
  font-size: 14px;
  font-weight: 600;
  color: var(--text-primary);
  margin: 0;
}

.risk-settings-content {
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.risk-section {
  padding: 16px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

.risk-section h4 {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-primary);
  margin-bottom: 8px;
}

.risk-description {
  font-size: 12px;
  color: var(--text-muted);
  margin-bottom: 12px;
}

.risk-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-bottom: 12px;
}

.risk-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

.risk-item label {
  font-size: 12px;
  color: var(--text-muted);
  font-weight: 500;
}

.risk-unit {
  font-size: 12px;
  color: var(--text-muted);
  font-weight: 500;
}

.risk-empty {
  font-size: 12px;
  color: var(--text-dim);
  padding: 12px;
  text-align: center;
  background: var(--bg-card);
  border: 1px dashed var(--border);
  border-radius: var(--radius);
}

.risk-hint {
  font-size: 11px;
  color: var(--text-dim);
  margin-left: 8px;
}

.risk-actions {
  display: flex;
  gap: 12px;
  padding-top: 16px;
  border-top: 1px solid var(--border);
}

.risk-remove {
  padding: 4px 8px;
  font-size: 14px;
  line-height: 1;
}

/* ── Analytics & Insights ── */
.analytics-insights {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 18px 20px;
  margin-bottom: 20px;
}

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

.analytics-header h3 {
  font-size: 14px;
  font-weight: 600;
  color: var(--text-primary);
  margin: 0;
}

.analytics-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 12px;
  margin-bottom: 20px;
}

.analytics-card {
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 14px;
  transition: border-color 0.15s;
}

.analytics-card:hover {
  border-color: var(--border-focus);
}

.analytics-label {
  font-size: 11px;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.3px;
  margin-bottom: 6px;
}

.analytics-value {
  font-size: 18px;
  font-weight: 700;
  color: var(--text-primary);
  font-family: var(--font-mono);
  margin-bottom: 4px;
}

.analytics-value.positive {
  color: var(--color-green);
}

.analytics-value.negative {
  color: var(--color-red);
}

.analytics-value.warning {
  color: var(--color-yellow);
}

.analytics-sublabel {
  font-size: 11px;
  color: var(--text-secondary);
  font-family: var(--font-mono);
}

.chart-section {
  margin-bottom: 20px;
  padding: 16px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

.chart-section h4 {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-primary);
  margin-bottom: 12px;
}

.chart-container {
  width: 100%;
  overflow-x: auto;
}

.chart-svg {
  width: 100%;
  height: auto;
  display: block;
}

.chart-empty {
  text-align: center;
  padding: 40px;
  color: var(--text-dim);
  font-size: 13px;
}

/* ── UX Improvements ── */
.theme-toggle-btn {
  background: var(--bg-badge);
  border: 1px solid var(--border);
  color: var(--text-primary);
  padding: 6px 12px;
  font-size: 16px;
  border-radius: 6px;
  cursor: pointer;
  transition: all 0.15s;
  margin-right: 8px;
}

.theme-toggle-btn:hover {
  border-color: var(--text-muted);
  background: var(--bg-card-hover);
}

/* Keyboard Shortcuts Modal */
.shortcuts-modal {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.7);
  z-index: 10001;
  display: flex;
  align-items: center;
  justify-content: center;
  animation: fadeIn 0.2s ease;
}

.shortcuts-content {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 24px;
  max-width: 500px;
  width: 90%;
  max-height: 80vh;
  overflow-y: auto;
}

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

.shortcuts-header h3 {
  font-size: 16px;
  font-weight: 600;
  color: var(--text-primary);
  margin: 0;
}

.shortcuts-close {
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 24px;
  cursor: pointer;
  padding: 0;
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: color 0.15s;
}

.shortcuts-close:hover {
  color: var(--text-primary);
}

.shortcuts-list {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.shortcut-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

.shortcut-item kbd {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 4px 8px;
  font-size: 12px;
  font-family: var(--font-mono);
  font-weight: 600;
  color: var(--text-primary);
  box-shadow: 0 2px 0 var(--border);
}

.shortcut-item span {
  flex: 1;
  font-size: 13px;
  color: var(--text-secondary);
}

/* Loading Indicator */
.loading-indicator {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.5);
  z-index: 10002;
  display: flex;
  align-items: center;
  justify-content: center;
}

.loading-spinner {
  width: 48px;
  height: 48px;
  border: 4px solid var(--border);
  border-top-color: var(--color-blue);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

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

/* Mobile Optimizations */
@media (max-width: 768px) {
  .shortcuts-content {
    padding: 16px;
  }

  .shortcut-item {
    padding: 10px;
    gap: 8px;
  }

  .shortcut-item kbd {
    padding: 3px 6px;
    font-size: 11px;
  }

  .shortcut-item span {
    font-size: 12px;
  }

  .theme-toggle-btn {
    padding: 4px 8px;
    font-size: 14px;
  }
}

/* Touch-friendly styles */
@media (hover: none) and (pointer: coarse) {
  .btn {
    min-height: 44px;
  }

  .form-input {
    min-height: 44px;
    font-size: 16px; /* Prevents zoom on iOS */
  }

  .nav-btn {
    min-height: 44px;
    padding: 8px 16px;
  }
}
