/* ==========================================================================
   AlphaQuant Engine v2.0 - Real-World Edition
   Institutional Dark Mode Quantitative Trading Terminal Styles
   ========================================================================== */

:root {
  --bg-primary: #080c14;
  --bg-secondary: #0d1322;
  --bg-tertiary: #131c31;
  --bg-card: rgba(17, 26, 46, 0.85);
  --bg-card-hover: rgba(23, 35, 62, 0.95);
  
  --border-subtle: rgba(255, 255, 255, 0.08);
  --border-glow: rgba(16, 185, 129, 0.3);
  --border-accent: rgba(6, 182, 212, 0.4);

  --accent-green: #10b981;
  --accent-green-glow: rgba(16, 185, 129, 0.25);
  --accent-cyan: #06b6d4;
  --accent-cyan-glow: rgba(6, 182, 212, 0.25);
  --accent-red: #f43f5e;
  --accent-red-glow: rgba(244, 63, 94, 0.25);
  --accent-gold: #f59e0b;
  --accent-purple: #8b5cf6;
  
  --text-primary: #f8fafc;
  --text-secondary: #94a3b8;
  --text-muted: #64748b;
  
  --font-mono: 'JetBrains Mono', monospace, Consolas, 'Courier New';
  --font-sans: 'Inter', system-ui, -apple-system, sans-serif;
  --font-arabic: 'Cairo', 'Inter', system-ui, sans-serif;

  --shadow-card: 0 8px 32px 0 rgba(0, 0, 0, 0.5);
  --glass-blur: blur(14px);
  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 16px;
}

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

body {
  background-color: var(--bg-primary);
  background-image: 
    radial-gradient(circle at 15% 15%, rgba(6, 182, 212, 0.05) 0%, transparent 40%),
    radial-gradient(circle at 85% 85%, rgba(16, 185, 129, 0.05) 0%, transparent 40%);
  color: var(--text-primary);
  font-family: var(--font-arabic);
  min-height: 100vh;
  overflow-x: hidden;
  line-height: 1.5;
  direction: rtl;
}

/* Scrollbar */
::-webkit-scrollbar {
  width: 6px;
  height: 6px;
}
::-webkit-scrollbar-track {
  background: var(--bg-primary);
}
::-webkit-scrollbar-thumb {
  background: #1e293b;
  border-radius: 4px;
}
::-webkit-scrollbar-thumb:hover {
  background: #334155;
}

/* ==========================================================================
   Header & Top HUD
   ========================================================================== */
.top-nav {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 24px;
  background: rgba(13, 19, 34, 0.92);
  backdrop-filter: var(--glass-blur);
  border-bottom: 1px solid var(--border-subtle);
  position: sticky;
  top: 0;
  z-index: 100;
}

.brand-section {
  display: flex;
  align-items: center;
  gap: 14px;
}

.logo-badge {
  width: 42px;
  height: 42px;
  border-radius: var(--radius-sm);
  background: linear-gradient(135deg, var(--accent-cyan), var(--accent-green));
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 900;
  font-size: 1.25rem;
  color: #000;
  box-shadow: 0 0 18px var(--accent-green-glow);
}

.brand-info h1 {
  font-size: 1.2rem;
  font-weight: 800;
  letter-spacing: 0.5px;
  display: flex;
  align-items: center;
  gap: 8px;
}

.version-pill {
  font-size: 0.7rem;
  padding: 2px 8px;
  border-radius: 20px;
  background: rgba(6, 182, 212, 0.15);
  color: var(--accent-cyan);
  border: 1px solid rgba(6, 182, 212, 0.3);
  font-family: var(--font-mono);
}

.brand-subtitle {
  font-size: 0.75rem;
  color: var(--text-muted);
}

.hud-metrics {
  display: flex;
  align-items: center;
  gap: 20px;
}

.hud-stat {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
}

.hud-label {
  font-size: 0.68rem;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.hud-value {
  font-family: var(--font-mono);
  font-size: 0.9rem;
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: 6px;
}

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--accent-green);
  box-shadow: 0 0 8px var(--accent-green);
  animation: pulse-glow 2s infinite;
  display: inline-block;
}

.circuit-breaker-badge {
  background: rgba(16, 185, 129, 0.12);
  color: var(--accent-green);
  padding: 6px 12px;
  border-radius: var(--radius-sm);
  border: 1px solid rgba(16, 185, 129, 0.3);
  font-size: 0.78rem;
  font-weight: 700;
  display: flex;
  align-items: center;
  gap: 8px;
}

.nav-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

.btn {
  padding: 8px 16px;
  border-radius: var(--radius-sm);
  font-size: 0.82rem;
  font-weight: 700;
  cursor: pointer;
  border: none;
  transition: all 0.2s ease;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-family: var(--font-arabic);
}

.btn-primary {
  background: linear-gradient(135deg, var(--accent-green), #059669);
  color: #000;
  box-shadow: 0 0 12px var(--accent-green-glow);
}
.btn-primary:hover {
  transform: translateY(-1px);
  box-shadow: 0 0 18px var(--accent-green-glow);
}

.btn-outline {
  background: rgba(255,255,255,0.03);
  color: var(--text-secondary);
  border: 1px solid var(--border-subtle);
}
.btn-outline:hover {
  background: var(--bg-tertiary);
  color: var(--text-primary);
  border-color: rgba(255, 255, 255, 0.2);
}

/* ==========================================================================
   Main Grid Layout
   ========================================================================== */
.terminal-container {
  display: grid;
  grid-template-columns: 330px 1fr 350px;
  grid-gap: 16px;
  padding: 16px;
  height: calc(100vh - 68px);
  overflow: hidden;
}

.column {
  display: flex;
  flex-direction: column;
  gap: 16px;
  overflow-y: auto;
}

.column-center {
  display: flex;
  flex-direction: column;
  gap: 16px;
  overflow: hidden;
}

/* Card Component */
.card {
  background: var(--bg-card);
  backdrop-filter: var(--glass-blur);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  padding: 14px 16px;
  box-shadow: var(--shadow-card);
  position: relative;
}

.card-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 12px;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--border-subtle);
}

.card-title {
  font-size: 0.85rem;
  font-weight: 700;
  color: var(--text-primary);
  text-transform: uppercase;
  letter-spacing: 0.6px;
  display: flex;
  align-items: center;
  gap: 8px;
}

.card-title i {
  color: var(--accent-cyan);
}

/* ==========================================================================
   Confluence Master Score Banner & Radar
   ========================================================================== */
.confluence-master-card {
  background: linear-gradient(180deg, rgba(17, 26, 46, 0.95), rgba(13, 19, 34, 0.95));
  border: 1px solid var(--border-glow);
  text-align: center;
}

.score-hud-container {
  display: flex;
  align-items: center;
  justify-content: space-around;
  padding: 10px 0;
}

.radial-gauge {
  position: relative;
  width: 120px;
  height: 120px;
}

.radial-gauge svg {
  width: 120px;
  height: 120px;
  transform: rotate(-90deg);
}

.gauge-bg {
  fill: none;
  stroke: rgba(255, 255, 255, 0.06);
  stroke-width: 10;
}

.gauge-progress {
  fill: none;
  stroke: var(--accent-green);
  stroke-width: 10;
  stroke-linecap: round;
  stroke-dasharray: 314;
  stroke-dashoffset: 62.8;
  transition: stroke-dashoffset 0.6s ease, stroke 0.4s ease;
  filter: drop-shadow(0 0 8px var(--accent-green-glow));
}

.gauge-center-text {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  display: flex;
  flex-direction: column;
  align-items: center;
}

.gauge-score {
  font-family: var(--font-mono);
  font-size: 1.8rem;
  font-weight: 800;
  color: var(--accent-green);
}

.gauge-subtext {
  font-size: 0.65rem;
  color: var(--text-muted);
  text-transform: uppercase;
}

.confluence-verdict {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
}

.execution-badge {
  padding: 8px 14px;
  border-radius: var(--radius-sm);
  font-size: 0.85rem;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  display: flex;
  align-items: center;
  gap: 8px;
}

.execution-badge.approved {
  background: rgba(16, 185, 129, 0.18);
  color: var(--accent-green);
  border: 1px solid var(--accent-green);
  box-shadow: 0 0 16px var(--accent-green-glow);
  animation: pulse-border 2s infinite;
}

.execution-badge.rejected {
  background: rgba(244, 63, 94, 0.15);
  color: var(--accent-red);
  border: 1px solid rgba(244, 63, 94, 0.4);
}

/* 4-Layer Breakdown Matrix */
.layers-matrix {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-top: 14px;
}

.layer-row {
  background: rgba(255, 255, 255, 0.02);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  transition: all 0.2s ease;
}

.layer-row:hover {
  background: rgba(255, 255, 255, 0.04);
  border-color: rgba(255, 255, 255, 0.12);
}

.layer-top {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 6px;
}

.layer-name {
  font-size: 0.8rem;
  font-weight: 700;
  display: flex;
  align-items: center;
  gap: 6px;
}

.layer-weight {
  font-size: 0.7rem;
  color: var(--text-muted);
  font-family: var(--font-mono);
}

.layer-status {
  font-family: var(--font-mono);
  font-size: 0.75rem;
  font-weight: 700;
  padding: 2px 6px;
  border-radius: 4px;
}

.layer-status.active {
  background: rgba(16, 185, 129, 0.2);
  color: var(--accent-green);
}

.layer-status.inactive {
  background: rgba(148, 163, 184, 0.1);
  color: var(--text-muted);
}

.layer-progress-bar {
  height: 4px;
  background: rgba(255, 255, 255, 0.06);
  border-radius: 2px;
  overflow: hidden;
}

.layer-progress-fill {
  height: 100%;
  background: var(--accent-green);
  transition: width 0.4s ease;
}

.layer-meta {
  font-size: 0.7rem;
  color: var(--text-secondary);
  margin-top: 4px;
  display: flex;
  justify-content: space-between;
  font-family: var(--font-mono);
}

/* Market Regime Card */
.regime-radar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 12px;
  background: rgba(6, 182, 212, 0.06);
  border: 1px solid rgba(6, 182, 212, 0.2);
  border-radius: var(--radius-sm);
  margin-bottom: 10px;
}

.regime-tag {
  font-family: var(--font-mono);
  font-size: 0.8rem;
  font-weight: 700;
  color: var(--accent-cyan);
}

.regime-metrics {
  font-size: 0.72rem;
  color: var(--text-secondary);
  font-family: var(--font-mono);
}

/* ==========================================================================
   Center Panel: Main Chart & Controls
   ========================================================================== */
.chart-container-card {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 400px;
  padding: 12px;
}

.chart-toolbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 8px;
  flex-wrap: wrap;
  gap: 8px;
}

.asset-selector-group {
  display: flex;
  gap: 6px;
}

.asset-pill {
  padding: 4px 10px;
  border-radius: var(--radius-sm);
  background: var(--bg-secondary);
  border: 1px solid var(--border-subtle);
  color: var(--text-secondary);
  font-size: 0.75rem;
  font-weight: 700;
  cursor: pointer;
  transition: all 0.2s ease;
  font-family: var(--font-arabic);
}

.asset-pill:hover {
  color: var(--text-primary);
  border-color: rgba(255, 255, 255, 0.2);
}

.asset-pill.active {
  background: rgba(6, 182, 212, 0.18);
  color: var(--accent-cyan);
  border-color: var(--accent-cyan);
}

.chart-indicators-legend {
  display: flex;
  gap: 12px;
  font-size: 0.72rem;
}

.legend-item {
  display: flex;
  align-items: center;
  gap: 5px;
  color: var(--text-secondary);
}

.legend-color {
  width: 10px;
  height: 10px;
  border-radius: 2px;
}

.legend-fvg-bull { background: rgba(16, 185, 129, 0.5); border: 1px solid var(--accent-green); }
.legend-fvg-bear { background: rgba(244, 63, 94, 0.5); border: 1px solid var(--accent-red); }
.legend-bsl { background: var(--accent-cyan); }
.legend-ssl { background: var(--accent-purple); }

.canvas-wrapper {
  flex: 1;
  position: relative;
  width: 100%;
  min-height: 280px;
  background: #090e1a;
  border-radius: var(--radius-sm);
  border: 1px solid rgba(255, 255, 255, 0.04);
}

#mainCandleCanvas, #cvdCanvas {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
}

.subchart-card {
  height: 160px;
  padding: 10px 12px;
  display: flex;
  flex-direction: column;
}

.subchart-wrapper {
  flex: 1;
  position: relative;
  background: #090e1a;
  border-radius: var(--radius-sm);
}

/* ==========================================================================
   Right Panel: Risk Manager, Execution, & Telegram Feed
   ========================================================================== */
.form-group {
  margin-bottom: 10px;
}

.form-label {
  display: flex;
  justify-content: space-between;
  font-size: 0.72rem;
  color: var(--text-secondary);
  margin-bottom: 4px;
}

.form-input {
  width: 100%;
  background: var(--bg-secondary);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
  padding: 6px 10px;
  color: var(--text-primary);
  font-family: var(--font-mono);
  font-size: 0.82rem;
  outline: none;
  transition: border-color 0.2s ease;
  direction: ltr;
  text-align: right;
}

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

.risk-calc-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  grid-gap: 8px;
  margin-bottom: 12px;
}

.calc-stat-box {
  background: rgba(255, 255, 255, 0.02);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
  padding: 8px;
  text-align: center;
}

.calc-stat-label {
  font-size: 0.65rem;
  color: var(--text-muted);
  text-transform: uppercase;
}

.calc-stat-value {
  font-family: var(--font-mono);
  font-size: 1rem;
  font-weight: 700;
  color: var(--accent-cyan);
  margin-top: 2px;
}

/* Telegram Mock Feed */
.telegram-feed-card {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 240px;
}

.telegram-chat-window {
  flex: 1;
  background: #0c121e;
  border-radius: var(--radius-sm);
  padding: 10px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 8px;
  font-family: var(--font-arabic);
  border: 1px solid rgba(255, 255, 255, 0.03);
}

.tg-bubble {
  background: #1e293b;
  border-radius: 8px 8px 0px 8px;
  padding: 10px 12px;
  font-size: 0.75rem;
  border-right: 3px solid var(--accent-cyan);
  box-shadow: 0 2px 8px rgba(0,0,0,0.3);
  animation: fadeIn 0.3s ease;
}

.tg-bubble.buy { border-right-color: var(--accent-green); }
.tg-bubble.sell { border-right-color: var(--accent-red); }

.tg-header {
  display: flex;
  justify-content: space-between;
  color: var(--accent-cyan);
  font-weight: 700;
  font-size: 0.72rem;
  margin-bottom: 4px;
  font-family: var(--font-mono);
}

.tg-body {
  white-space: pre-line;
  line-height: 1.5;
  color: #e2e8f0;
}

.tg-time {
  text-align: left;
  font-size: 0.65rem;
  color: var(--text-muted);
  margin-top: 4px;
  font-family: var(--font-mono);
}

/* ==========================================================================
   Modals (Backtest & Architecture)
   ========================================================================== */
.modal-backdrop {
  position: fixed;
  top: 0;
  left: 0;
  width: 100vw;
  height: 100vh;
  background: rgba(0, 0, 0, 0.85);
  backdrop-filter: var(--glass-blur);
  z-index: 1000;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.modal-backdrop.open {
  display: flex !important;
}

.modal-content {
  background: var(--bg-secondary);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  width: 100%;
  max-width: 850px;
  max-height: 88vh;
  overflow-y: auto;
  padding: 24px;
  box-shadow: 0 16px 48px rgba(0, 0, 0, 0.7);
  position: relative;
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 20px;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--border-subtle);
}

.modal-close-btn {
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 1.5rem;
  cursor: pointer;
  line-height: 1;
}
.modal-close-btn:hover {
  color: var(--text-primary);
}

.metrics-summary-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  grid-gap: 12px;
  margin-bottom: 20px;
}

.metric-card {
  background: var(--bg-card);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
  padding: 12px;
  text-align: center;
}

.metric-title {
  font-size: 0.72rem;
  color: var(--text-muted);
  text-transform: uppercase;
}

.metric-val {
  font-family: var(--font-mono);
  font-size: 1.3rem;
  font-weight: 700;
  color: var(--accent-green);
  margin-top: 4px;
}

/* Animations */
@keyframes pulse-glow {
  0% { transform: scale(0.95); opacity: 0.8; }
  50% { transform: scale(1.15); opacity: 1; filter: drop-shadow(0 0 10px var(--accent-green)); }
  100% { transform: scale(0.95); opacity: 0.8; }
}

@keyframes pulse-border {
  0% { box-shadow: 0 0 8px var(--accent-green-glow); }
  50% { box-shadow: 0 0 20px var(--accent-green-glow); }
  100% { box-shadow: 0 0 8px var(--accent-green-glow); }
}

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

/* Responsive */
@media (max-width: 1200px) {
  .terminal-container {
    grid-template-columns: 280px 1fr 300px;
  }
}

@media (max-width: 900px) {
  .terminal-container {
    grid-template-columns: 1fr;
    height: auto;
    overflow-y: visible;
  }
}
