/* ═══════════════════════════════════════════════════════════════════════════
   eToro Trading Dashboard — Dark Terminal Theme
   ═══════════════════════════════════════════════════════════════════════════ */

/* ── Variables ─────────────────────────────────────────────────────────────── */
:root {
  --bg-primary:    #0a0a0f;
  --bg-secondary:  #111118;
  --bg-tertiary:   #18181f;
  --bg-card:       #13131a;
  --border:        #252530;
  --border-bright: #353545;

  --accent-green:  #00e87a;
  --accent-red:    #ff3b5c;
  --accent-yellow: #f5c400;
  --accent-blue:   #4d9fff;
  --accent-purple: #a855f7;

  --text-primary:  #e2e2f0;
  --text-secondary:#9090b0;
  --text-muted:    #555570;

  --font-mono: 'JetBrains Mono', 'Fira Code', 'Cascadia Code', 'Consolas', monospace;
  --font-sans: 'Inter', system-ui, -apple-system, sans-serif;

  --radius-sm: 4px;
  --radius:    8px;
  --radius-lg: 12px;

  --shadow: 0 4px 24px rgba(0,0,0,0.6);
  --glow-green: 0 0 12px rgba(0,232,122,0.25);
  --glow-red:   0 0 12px rgba(255,59,92,0.25);
}

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

html { font-size: 14px; scroll-behavior: smooth; }

body {
  background: var(--bg-primary);
  color: var(--text-primary);
  font-family: var(--font-sans);
  min-height: 100vh;
  overflow-x: hidden;
}

::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: var(--bg-secondary); }
::-webkit-scrollbar-thumb { background: var(--border-bright); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-muted); }

/* ── Navbar ─────────────────────────────────────────────────────────────────── */
.navbar {
  position: sticky;
  top: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 0 24px;
  height: 56px;
  background: rgba(10,10,15,0.95);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
}

.navbar-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  font-family: var(--font-mono);
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 0.08em;
  color: var(--accent-green);
  text-decoration: none;
  flex-shrink: 0;
}

.navbar-brand svg { width: 22px; height: 22px; }

.navbar-status {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 4px 12px;
  background: var(--bg-tertiary);
  border: 1px solid var(--border);
  border-radius: 20px;
  font-family: var(--font-mono);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.06em;
}

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--text-muted);
  flex-shrink: 0;
}

.status-dot.running {
  background: var(--accent-green);
  animation: pulse-green 1.8s ease-in-out infinite;
  box-shadow: var(--glow-green);
}

.status-dot.stopped  { background: var(--accent-red); }
.status-dot.backtest { background: var(--accent-yellow); }

@keyframes pulse-green {
  0%, 100% { opacity: 1; transform: scale(1); }
  50%       { opacity: 0.5; transform: scale(0.75); }
}

.navbar-mode {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--text-muted);
  letter-spacing: 0.04em;
}

.navbar-spacer { flex: 1; }

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

/* ── Tabs navigation ─────────────────────────────────────────────────────────── */
.tabs {
  display: flex;
  border-bottom: 1px solid var(--border);
  background: var(--bg-secondary);
  padding: 0 24px;
  gap: 0;
}

.tab-btn {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 12px 18px;
  font-family: var(--font-mono);
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.05em;
  color: var(--text-muted);
  background: none;
  border: none;
  border-bottom: 2px solid transparent;
  cursor: pointer;
  transition: color 0.15s, border-color 0.15s;
  white-space: nowrap;
}

.tab-btn:hover { color: var(--text-secondary); }

.tab-btn.active {
  color: var(--accent-green);
  border-bottom-color: var(--accent-green);
}

.tab-content { display: none; }
.tab-content.active { display: block; }

/* ── Main container ─────────────────────────────────────────────────────────── */
.main { padding: 24px; max-width: 1400px; margin: 0 auto; }

/* ── Buttons ──────────────────────────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 7px 16px;
  font-family: var(--font-mono);
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.05em;
  border: 1px solid var(--border-bright);
  border-radius: var(--radius-sm);
  background: var(--bg-tertiary);
  color: var(--text-primary);
  cursor: pointer;
  transition: all 0.15s;
  white-space: nowrap;
}

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

.btn-green {
  background: rgba(0,232,122,0.12);
  border-color: rgba(0,232,122,0.4);
  color: var(--accent-green);
}
.btn-green:hover { background: rgba(0,232,122,0.2); box-shadow: var(--glow-green); }

.btn-red {
  background: rgba(255,59,92,0.12);
  border-color: rgba(255,59,92,0.4);
  color: var(--accent-red);
}
.btn-red:hover { background: rgba(255,59,92,0.2); box-shadow: var(--glow-red); }

.btn-blue {
  background: rgba(77,159,255,0.12);
  border-color: rgba(77,159,255,0.4);
  color: var(--accent-blue);
}
.btn-blue:hover { background: rgba(77,159,255,0.2); }

.btn:disabled { opacity: 0.35; cursor: not-allowed; pointer-events: none; }

/* ── Cards ────────────────────────────────────────────────────────────────────── */
.card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 20px;
  box-shadow: var(--shadow);
}

.card-title {
  font-family: var(--font-mono);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--text-muted);
  margin-bottom: 16px;
}

/* ── Strategy Cards Grid ─────────────────────────────────────────────────────── */
.strategies-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 16px;
  margin-bottom: 24px;
}

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

.strategy-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 20px;
  position: relative;
  overflow: hidden;
  transition: border-color 0.2s;
}

.strategy-card::before {
  content: '';
  position: absolute;
  top: 0; left: 0; right: 0;
  height: 2px;
  background: var(--border-bright);
  transition: background 0.2s;
}

.strategy-card.running::before   { background: var(--accent-green); }
.strategy-card.stopped::before   { background: var(--accent-red); }
.strategy-card.backtest::before  { background: var(--accent-yellow); }

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

.strategy-label {
  font-family: var(--font-mono);
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--text-muted);
}

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

.strategy-desc {
  font-size: 12px;
  color: var(--text-muted);
  margin-bottom: 14px;
  line-height: 1.5;
}

.badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 3px 10px;
  border-radius: 20px;
  font-family: var(--font-mono);
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.badge-running {
  background: rgba(0,232,122,0.15);
  color: var(--accent-green);
  border: 1px solid rgba(0,232,122,0.3);
}
.badge-stopped {
  background: rgba(255,59,92,0.12);
  color: var(--accent-red);
  border: 1px solid rgba(255,59,92,0.25);
}
.badge-backtest {
  background: rgba(245,196,0,0.12);
  color: var(--accent-yellow);
  border: 1px solid rgba(245,196,0,0.25);
}

.strategy-metrics {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-top: 12px;
}

.metric {
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 8px 10px;
}

.metric-label {
  font-size: 10px;
  color: var(--text-muted);
  letter-spacing: 0.06em;
  text-transform: uppercase;
  margin-bottom: 2px;
}

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

/* ── Dashboard Bottom Row ──────────────────────────────────────────────────── */
.dashboard-bottom {
  display: grid;
  grid-template-columns: 280px 1fr;
  gap: 16px;
}

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

.chart-container {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 240px;
}

.chart-container canvas { max-width: 220px; max-height: 220px; }

.chart-legend {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-top: 12px;
  width: 100%;
}

.legend-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-family: var(--font-mono);
  font-size: 11px;
}

.legend-dot {
  width: 8px; height: 8px;
  border-radius: 2px;
  margin-right: 6px;
  flex-shrink: 0;
}

.legend-label { color: var(--text-secondary); flex: 1; }
.legend-pct   { color: var(--text-primary); font-weight: 700; }

/* ── Tables ───────────────────────────────────────────────────────────────────── */
.table-wrap {
  overflow: auto;
  max-height: 320px;
  border-radius: var(--radius-sm);
}

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

thead th {
  position: sticky;
  top: 0;
  padding: 8px 10px;
  font-family: var(--font-mono);
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-muted);
  background: var(--bg-secondary);
  border-bottom: 1px solid var(--border);
  text-align: left;
  white-space: nowrap;
}

tbody tr {
  border-bottom: 1px solid var(--border);
  transition: background 0.1s;
}

tbody tr:hover { background: var(--bg-tertiary); }
tbody tr:last-child { border-bottom: none; }

tbody td {
  padding: 7px 10px;
  color: var(--text-secondary);
  font-size: 12px;
  max-width: 300px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

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

.cell-buy  { color: var(--accent-green); font-weight: 700; }
.cell-sell { color: var(--accent-red);   font-weight: 700; }

.cell-strategy-a { color: var(--accent-green); }
.cell-strategy-b { color: var(--accent-blue); }
.cell-strategy-c { color: var(--accent-purple); }

/* ── Config Form ───────────────────────────────────────────────────────────── */
.config-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 24px;
  flex-wrap: wrap;
  gap: 12px;
}

.config-title {
  font-family: var(--font-mono);
  font-size: 13px;
  font-weight: 700;
  color: var(--text-primary);
  letter-spacing: 0.04em;
}

.config-subtitle {
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 2px;
}

.config-section {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  margin-bottom: 16px;
  overflow: hidden;
}

.config-section-title {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 12px 20px;
  background: var(--bg-secondary);
  border-bottom: 1px solid var(--border);
  font-family: var(--font-mono);
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--text-muted);
}

.config-section-title .section-icon {
  width: 6px; height: 6px;
  border-radius: 50%;
  flex-shrink: 0;
}

.section-icon-green  { background: var(--accent-green); }
.section-icon-blue   { background: var(--accent-blue); }
.section-icon-purple { background: var(--accent-purple); }
.section-icon-yellow { background: var(--accent-yellow); }
.section-icon-red    { background: var(--accent-red); }
.section-icon-gray   { background: var(--text-muted); }

.config-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 0;
  padding: 4px 0;
}

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

.config-field {
  padding: 12px 20px;
  border-bottom: 1px solid var(--border);
}

.config-field:nth-child(odd)  { border-right: 1px solid var(--border); }
.config-field:last-child,
.config-field:nth-last-child(2):nth-child(odd) { border-bottom: none; }

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

.field-name {
  font-family: var(--font-mono);
  font-size: 11px;
  font-weight: 600;
  color: var(--text-secondary);
  letter-spacing: 0.04em;
}

.field-value-display {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--accent-blue);
  font-weight: 700;
  min-width: 40px;
  text-align: right;
}

input[type="text"],
input[type="password"],
input[type="number"],
select,
textarea {
  width: 100%;
  padding: 7px 10px;
  background: var(--bg-tertiary);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  font-family: var(--font-mono);
  font-size: 12px;
  outline: none;
  transition: border-color 0.15s;
  -webkit-appearance: none;
}

input:focus, select:focus, textarea:focus {
  border-color: var(--accent-blue);
  box-shadow: 0 0 0 2px rgba(77,159,255,0.15);
}

select {
  cursor: pointer;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath fill='%23555570' d='M6 8L0 0h12z'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 10px center;
  padding-right: 28px;
}

select option { background: var(--bg-secondary); }

/* Range slider */
input[type="range"] {
  -webkit-appearance: none;
  width: 100%;
  height: 4px;
  background: var(--border-bright);
  border-radius: 2px;
  border: none;
  padding: 0;
  margin-bottom: 4px;
  cursor: pointer;
}

input[type="range"]:focus { box-shadow: none; border: none; }

input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 14px; height: 14px;
  border-radius: 50%;
  background: var(--accent-blue);
  cursor: pointer;
  transition: transform 0.1s;
}

input[type="range"]::-webkit-slider-thumb:hover { transform: scale(1.2); }

/* Allocation range con colori */
.alloc-a input[type="range"]::-webkit-slider-thumb { background: var(--accent-green); }
.alloc-b input[type="range"]::-webkit-slider-thumb { background: var(--accent-blue); }
.alloc-c input[type="range"]::-webkit-slider-thumb { background: var(--accent-purple); }

.alloc-sum {
  font-family: var(--font-mono);
  font-size: 11px;
  padding: 4px 8px;
  border-radius: var(--radius-sm);
  margin-top: 4px;
  display: inline-block;
}
.alloc-sum.ok    { color: var(--accent-green); background: rgba(0,232,122,0.1); }
.alloc-sum.error { color: var(--accent-red);   background: rgba(255,59,92,0.1); }

/* ── Log Viewer ──────────────────────────────────────────────────────────────── */
.log-controls {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 16px;
  flex-wrap: wrap;
}

.filter-btn {
  padding: 4px 12px;
  font-family: var(--font-mono);
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  background: var(--bg-tertiary);
  border: 1px solid var(--border);
  border-radius: 20px;
  color: var(--text-muted);
  cursor: pointer;
  transition: all 0.15s;
}

.filter-btn:hover  { border-color: var(--text-muted); color: var(--text-secondary); }
.filter-btn.active { background: rgba(77,159,255,0.15); border-color: var(--accent-blue); color: var(--accent-blue); }

.log-auto-scroll {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-left: auto;
  font-size: 11px;
  color: var(--text-muted);
  cursor: pointer;
  user-select: none;
}

.log-auto-scroll input[type="checkbox"] { accent-color: var(--accent-blue); }

.log-table-wrap {
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  overflow: hidden;
}

.log-table-scroll {
  overflow: auto;
  max-height: 520px;
}

#log-empty {
  padding: 40px;
  text-align: center;
  color: var(--text-muted);
  font-family: var(--font-mono);
  font-size: 12px;
}

/* ── Backtest Tab ─────────────────────────────────────────────────────────── */
.backtest-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
}

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

.backtest-chart-wrap {
  height: 260px;
  position: relative;
}

/* ── Notifications ──────────────────────────────────────────────────────────── */
.toast-container {
  position: fixed;
  bottom: 24px;
  right: 24px;
  z-index: 9999;
  display: flex;
  flex-direction: column;
  gap: 8px;
  pointer-events: none;
}

.toast {
  padding: 10px 16px;
  border-radius: var(--radius);
  font-family: var(--font-mono);
  font-size: 12px;
  font-weight: 600;
  box-shadow: var(--shadow);
  animation: toast-in 0.25s ease;
  pointer-events: auto;
  max-width: 360px;
}

.toast-success {
  background: rgba(0,232,122,0.15);
  border: 1px solid rgba(0,232,122,0.4);
  color: var(--accent-green);
}

.toast-error {
  background: rgba(255,59,92,0.15);
  border: 1px solid rgba(255,59,92,0.4);
  color: var(--accent-red);
}

.toast-info {
  background: rgba(77,159,255,0.12);
  border: 1px solid rgba(77,159,255,0.35);
  color: var(--accent-blue);
}

@keyframes toast-in {
  from { transform: translateX(40px); opacity: 0; }
  to   { transform: translateX(0);    opacity: 1; }
}

/* ── Utilities ─────────────────────────────────────────────────────────────── */
.flex         { display: flex; }
.flex-center  { display: flex; align-items: center; }
.gap-8        { gap: 8px; }
.gap-12       { gap: 12px; }
.gap-16       { gap: 16px; }
.mb-16        { margin-bottom: 16px; }
.mb-24        { margin-bottom: 24px; }
.text-muted   { color: var(--text-muted); }
.text-green   { color: var(--accent-green); }
.text-red     { color: var(--accent-red); }
.text-blue    { color: var(--accent-blue); }
.text-mono    { font-family: var(--font-mono); }
.text-sm      { font-size: 12px; }
.text-xs      { font-size: 11px; }

.divider {
  height: 1px;
  background: var(--border);
  margin: 20px 0;
}

/* ── WS connection indicator ─────────────────────────────────────────────── */
.ws-indicator {
  display: flex;
  align-items: center;
  gap: 5px;
  font-family: var(--font-mono);
  font-size: 10px;
  color: var(--text-muted);
}

.ws-dot {
  width: 6px; height: 6px;
  border-radius: 50%;
  background: var(--accent-red);
  transition: background 0.3s;
}

.ws-dot.connected { background: var(--accent-green); }
