:root {
  --bg: #0a0a0a;
  --bg-panel: #131313;
  --bg-card: #1a1a1a;
  --border: #2a2a2a;
  --gold: #d4af37;
  --gold-light: #f0d479;
  --gold-dark: #a8871f;
  --text: #e8e8e8;
  --text-dim: #9a9a9a;
  --green: #22c55e;
  --red: #ef4444;
  --blue: #3498db;
  --purple: #9b59b6;
  --font: 'Segoe UI', system-ui, -apple-system, sans-serif;
}

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

body {
  font-family: var(--font);
  background: radial-gradient(ellipse at 50% -20%, #1d1808 0%, var(--bg) 60%);
  color: var(--text);
  min-height: 100vh;
}

.app { max-width: 1440px; margin: 0 auto; padding: 16px; }

.header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 14px 20px;
  border-bottom: 1px solid var(--gold-dark);
  background: linear-gradient(180deg, #16120a, #0c0c0c);
}

.logo { display: flex; align-items: center; gap: 14px; }
.logo-icon {
  font-size: 30px;
  color: var(--gold);
  text-shadow: 0 0 14px rgba(212, 175, 55, 0.7);
}
.logo-text h1 { font-size: 22px; letter-spacing: 2px; }
.logo-text h1 span { color: var(--gold); }
.logo-text p { font-size: 11px; color: var(--text-dim); letter-spacing: 1px; }

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

.status-pill {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 5px 12px;
  font-size: 12px;
  color: var(--text-dim);
  background: var(--bg-card);
}
.status-pill .dot {
  width: 8px; height: 8px; border-radius: 50%;
  background: var(--green);
  box-shadow: 0 0 6px var(--green);
}
.status-pill.live .dot { background: var(--gold); box-shadow: 0 0 8px var(--gold); }

.btn {
  cursor: pointer;
  border: 1px solid var(--border);
  background: var(--bg-card);
  color: var(--text);
  padding: 8px 14px;
  border-radius: 6px;
  font-size: 13px;
  transition: all 0.15s ease;
}
.btn:hover { border-color: var(--gold-dark); color: var(--gold-light); }
.hidden { display: none !important; }
.btn-ghost { background: transparent; }
.btn-small { padding: 4px 9px; font-size: 12px; }
.btn-gold {
  background: linear-gradient(180deg, var(--gold-light), var(--gold));
  color: #1a1405;
  font-weight: 700;
  border: 1px solid var(--gold);
}
.btn-gold:hover { box-shadow: 0 0 14px rgba(212, 175, 55, 0.5); }
.btn-danger {
  background: linear-gradient(180deg, #f87171, var(--red));
  color: #fff;
  font-weight: 700;
  border: 1px solid var(--red);
}
.btn-danger:hover { box-shadow: 0 0 12px rgba(239, 68, 68, 0.5); color: #fff; }
.btn-danger.halt { animation: pulse-red 1.2s infinite; }
@keyframes pulse-red {
  0%, 100% { box-shadow: 0 0 0 0 rgba(239, 68, 68, 0.6); }
  50% { box-shadow: 0 0 16px 4px rgba(239, 68, 68, 0.35); }
}

.main { padding: 16px 0; }

.controls {
  display: flex;
  flex-wrap: wrap;
  gap: 14px;
  align-items: flex-end;
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 14px 16px;
  margin-bottom: 16px;
}

.market-tabs { display: flex; gap: 6px; width: 100%; }
.market-tab {
  flex: 1;
  cursor: pointer;
  text-align: center;
  padding: 9px 8px;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--bg-card);
  color: var(--text-dim);
  font-size: 13px;
  font-weight: 600;
  letter-spacing: 1px;
  text-transform: uppercase;
  transition: all 0.15s ease;
}
.market-tab:hover { border-color: var(--gold-dark); color: var(--gold-light); }
.market-tab.active {
  background: linear-gradient(180deg, #1f1a08, #171204);
  color: var(--gold);
  border-color: var(--gold-dark);
  box-shadow: inset 0 0 12px rgba(212, 175, 55, 0.15);
}

.selectors { display: flex; gap: 12px; align-items: flex-end; flex-wrap: wrap; }

.field { display: flex; flex-direction: column; gap: 5px; }
.field span { font-size: 11px; color: var(--text-dim); text-transform: uppercase; letter-spacing: 1px; }
.field select, .field input {
  background: var(--bg-card);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 8px 10px;
  border-radius: 6px;
  font-size: 14px;
  min-width: 150px;
}
.field select:focus, .field input:focus { outline: none; border-color: var(--gold-dark); }

.price-strip { margin-left: auto; display: flex; align-items: center; gap: 10px; padding: 8px 12px; border: 1px solid var(--border); border-radius: 8px; background: var(--bg-card); }
.price-label { font-size: 11px; color: var(--text-dim); text-transform: uppercase; letter-spacing: 1px; }
.price-value { font-size: 20px; font-weight: 700; color: var(--gold); font-variant-numeric: tabular-nums; }
.price-change { font-size: 13px; font-weight: 600; }

.workspace { display: grid; grid-template-columns: 1fr 360px; gap: 16px; margin-bottom: 16px; }

.panel {
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: 10px;
  overflow: hidden;
}
.panel-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  background: #101010;
}
.panel-header h2 { font-size: 14px; letter-spacing: 1px; text-transform: uppercase; color: var(--gold-light); }
.panel-actions { display: flex; align-items: center; gap: 10px; }
.stat-inline { font-size: 12px; color: var(--text-dim); }
.signal-time { font-size: 12px; color: var(--text-dim); }

.chart-container { position: relative; height: 520px; }
#chart { width: 100%; height: 100%; display: block; }
.chart-legend { display: flex; gap: 12px; }
.legend-item { display: flex; align-items: center; gap: 5px; font-size: 11px; color: var(--text-dim); }
.swatch { width: 14px; height: 3px; border-radius: 2px; display: inline-block; }

.analyzing-overlay {
  position: absolute; inset: 0;
  display: flex; align-items: center; justify-content: center;
  background: rgba(10, 10, 10, 0.82);
  backdrop-filter: blur(2px);
  z-index: 5;
}
.analyzing-overlay.hidden { display: none; }
.analyzing-inner { text-align: center; }
.spinner {
  width: 56px; height: 56px; margin: 0 auto 18px;
  border: 4px solid #2a2a2a;
  border-top-color: var(--gold);
  border-radius: 50%;
  animation: spin 0.9s linear infinite;
  box-shadow: 0 0 24px rgba(212, 175, 55, 0.25);
}
@keyframes spin { to { transform: rotate(360deg); } }
.analyzing-title { font-size: 18px; letter-spacing: 2px; color: var(--gold-light); text-transform: uppercase; margin-bottom: 16px; }
.analyzing-hint { font-size: 12px; color: var(--text-dim); margin-top: 14px; letter-spacing: 1px; }

.confluence-tracker {
  display: flex; justify-content: center; gap: 6px; flex-wrap: wrap; max-width: 480px; margin: 0 auto;
}
.tracker-chip {
  font-size: 11px;
  padding: 5px 10px;
  border: 1px solid var(--border);
  border-radius: 14px;
  color: var(--text-dim);
  background: var(--bg-card);
  transition: all 0.2s ease;
}
.tracker-chip.done { border-color: var(--gold-dark); color: var(--gold); box-shadow: 0 0 8px rgba(212, 175, 55, 0.3); }
.tracker-chip.fail { border-color: var(--red); color: var(--red); }

.signal-card { padding: 16px; min-height: 280px; }
.signal-card.empty { display: flex; align-items: center; justify-content: center; }
.empty-hint { color: var(--text-dim); font-size: 13px; text-align: center; }

.rec-badge {
  font-size: 22px; font-weight: 800; text-align: center;
  letter-spacing: 3px; padding: 14px; border-radius: 8px; margin-bottom: 12px;
}
.rec-badge.buy { color: var(--green); border: 1px solid rgba(34,197,94,0.4); background: rgba(34,197,94,0.08); text-shadow: 0 0 12px rgba(34,197,94,0.5); }
.rec-badge.sell { color: var(--red); border: 1px solid rgba(239,68,68,0.4); background: rgba(239,68,68,0.08); text-shadow: 0 0 12px rgba(239,68,68,0.5); }
.rec-badge.wait { color: var(--gold); border: 1px solid rgba(212,175,55,0.4); background: rgba(212,175,55,0.08); text-shadow: 0 0 12px rgba(212,175,55,0.4); }

.rec-opp { text-align: center; font-size: 13px; color: var(--text-dim); margin-bottom: 12px; }

.signal-metrics { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-bottom: 14px; }
.metric {
  background: var(--bg-card); border: 1px solid var(--border); border-radius: 8px; padding: 10px;
}
.metric .label { font-size: 10px; color: var(--text-dim); text-transform: uppercase; letter-spacing: 1px; }
.metric .value { font-size: 18px; font-weight: 700; margin-top: 3px; font-variant-numeric: tabular-nums; }
.metric .value.good { color: var(--green); }
.metric .value.warn { color: var(--gold); }
.metric .value.bad { color: var(--red); }

.score-bar { height: 8px; border-radius: 4px; background: #222; overflow: hidden; margin-top: 6px; }
.score-bar-fill { height: 100%; border-radius: 4px; transition: width 0.5s ease; }
.score-bar-fill.buy { background: linear-gradient(90deg, #166534, var(--green)); }
.score-bar-fill.sell { background: linear-gradient(90deg, #7f1d1d, var(--red)); }
.score-bar-fill.neutral { background: linear-gradient(90deg, #713f12, var(--gold)); }

.signal-desc { font-size: 13px; color: var(--text-dim); margin-bottom: 12px; line-height: 1.5; }

.signal-times { font-size: 13px; margin-bottom: 12px; }
.signal-times .row { display: flex; justify-content: space-between; padding: 4px 0; border-bottom: 1px dashed #222; }
.signal-times .k { color: var(--text-dim); }
.signal-times .v { font-weight: 600; color: var(--gold-light); }

.explanation {
  font-size: 12px; line-height: 1.65; color: var(--text-dim);
  background: var(--bg-card); border: 1px solid var(--border);
  border-radius: 8px; padding: 10px; white-space: pre-line; max-height: 240px; overflow: auto;
}

.tradeable-note {
  margin-top: 12px; padding: 10px; border-radius: 8px; font-size: 13px; text-align: center;
}
.tradeable-note.ok { border: 1px solid rgba(34,197,94,0.4); color: var(--green); background: rgba(34,197,94,0.06); }
.tradeable-note.no { border: 1px solid rgba(239,68,68,0.4); color: var(--red); background: rgba(239,68,68,0.06); }

.lower-grid { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 16px; }

.confluence-list, .history-list, .logs-list { list-style: none; max-height: 360px; overflow: auto; padding: 8px; }
.confluence-list li {
  display: flex; justify-content: space-between; gap: 10px;
  padding: 8px 10px; border-bottom: 1px solid #1f1f1f; font-size: 12px;
}
.confluence-list .c-name { color: var(--text); flex: 1; }
.confluence-list .c-reason { color: var(--text-dim); flex: 2; }
.confluence-list .c-dir { font-weight: 700; text-align: right; min-width: 62px; }
.c-dir.buy { color: var(--green); }
.c-dir.sell { color: var(--red); }
.c-dir.neutral { color: var(--text-dim); }

.history-list li {
  display: flex; justify-content: space-between; align-items: center;
  padding: 8px 10px; border-bottom: 1px solid #1f1f1f; font-size: 12px;
}
.history-list .h-sym { font-weight: 700; color: var(--gold-light); }
.history-list .h-dir { font-weight: 600; }
.history-list .h-dir.buy { color: var(--green); }
.history-list .h-dir.sell { color: var(--red); }
.history-list .h-dir.neutral { color: var(--gold); }
.history-list .h-badge { padding: 2px 8px; border-radius: 10px; font-size: 11px; }
.history-list .h-badge.acerto { background: rgba(34,197,94,0.15); color: var(--green); }
.history-list .h-badge.erro { background: rgba(239,68,68,0.15); color: var(--red); }
.history-list .h-badge.pending { background: rgba(212,175,55,0.15); color: var(--gold); }
.history-list .h-meta { color: var(--text-dim); }

.logs-list li {
  padding: 6px 10px; border-bottom: 1px solid #1f1f1f; font-size: 11px;
  font-family: 'Consolas', monospace; color: var(--text-dim); white-space: pre-wrap; word-break: break-all;
}
.logs-list li .log-type { color: var(--gold); font-weight: 700; }

.footer { text-align: center; padding: 20px; color: var(--text-dim); font-size: 12px; border-top: 1px solid #1a1a1a; margin-top: 16px; }

.modal {
  position: fixed; inset: 0; background: rgba(0,0,0,0.7); z-index: 50;
  display: flex; align-items: center; justify-content: center; padding: 20px;
}
.modal.hidden { display: none; }
.modal-body { width: 100%; max-width: 560px; max-height: 85vh; overflow: auto; background: var(--bg-panel); border: 1px solid var(--gold-dark); border-radius: 12px; }
.modal-header { display: flex; justify-content: space-between; align-items: center; padding: 14px 18px; border-bottom: 1px solid var(--border); }
.modal-header h2 { font-size: 16px; color: var(--gold-light); }
.modal-content { padding: 18px; display: flex; flex-direction: column; gap: 12px; }
.hint-text { font-size: 12px; color: var(--text-dim); line-height: 1.6; }
.settings-group { border: 1px solid var(--border); border-radius: 8px; padding: 12px; }
.settings-group h3 { font-size: 13px; color: var(--gold); margin-bottom: 10px; letter-spacing: 1px; text-transform: uppercase; }
.settings-row { display: flex; align-items: center; justify-content: space-between; padding: 6px 0; font-size: 13px; }
.settings-row input[type="number"] { width: 80px; background: var(--bg-card); border: 1px solid var(--border); color: var(--text); padding: 5px 8px; border-radius: 5px; }
.settings-row input[type="checkbox"] { width: 18px; height: 18px; accent-color: var(--gold); }
.settings-row .w { font-size: 12px; color: var(--text-dim); }
.toggle-row { display: flex; align-items: center; gap: 8px; }

.automation-panel { margin-top: 16px; }
.mode-badge {
  font-size: 12px; font-weight: 700; letter-spacing: 1px;
  padding: 4px 12px; border-radius: 20px;
  border: 1px solid var(--gold-dark); color: var(--gold-light);
  background: rgba(212, 175, 55, 0.08);
}
.mode-badge.halt { color: #fff; border-color: var(--red); background: rgba(239, 68, 68, 0.15); }
.safety-banner {
  margin: 10px 16px; padding: 10px 14px; border-radius: 8px;
  background: rgba(239, 68, 68, 0.12); border: 1px solid var(--red);
  color: #fecaca; font-size: 13px;
}
.automation-grid {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
  gap: 14px; padding: 16px;
}
.automation-live {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 14px; padding: 0 16px 16px;
}
.auto-card { background: var(--bg-card); border: 1px solid var(--border); border-radius: 8px; padding: 12px; }
.auto-card h3 { font-size: 12px; color: var(--gold); text-transform: uppercase; letter-spacing: 1px; margin-bottom: 10px; }
.auto-fields { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.auto-fields .field { margin-bottom: 4px; }
.auto-stats, .auto-draft, .auto-positions, .auto-records { font-size: 12px; color: var(--text-dim); line-height: 1.7; }
.auto-stats b, .auto-draft b { color: var(--gold-light); }
.auto-row { display: flex; justify-content: space-between; gap: 8px; padding: 3px 0; border-bottom: 1px dashed var(--border); }
.auto-row:last-child { border-bottom: none; }
.pos-win { color: var(--green); }
.pos-loss { color: var(--red); }
.pos-open { color: var(--gold); }
.btn-confirm { margin-top: 8px; margin-right: 8px; }
.deriv-account { margin: 4px 0 8px; }
.auto-actions { display: flex; gap: 8px; margin-top: 10px; }
.auto-actions .btn { flex: 1; }
.btn-block { width: 100%; margin-top: 8px; }
.tag-demo { color: var(--gold-light); }
.tag-real { color: var(--green); }
.toast {
  margin-top: 10px; padding: 10px 12px; border-radius: 8px;
  background: rgba(34, 197, 94, 0.12); border: 1px solid var(--green);
  color: #86efac; font-size: 13px; font-weight: 700; text-align: center;
  animation: toast-in 0.25s ease;
}
.toast.error { background: rgba(239, 68, 68, 0.12); border-color: var(--red); color: #fecaca; }
@keyframes toast-in {
  from { opacity: 0; transform: translateY(-4px); }
  to { opacity: 1; transform: translateY(0); }
}

@media (max-width: 1100px) {
  .workspace { grid-template-columns: 1fr; }
  .lower-grid { grid-template-columns: 1fr; }
  .price-strip { margin-left: 0; }
}

@media (max-width: 600px) {
  .automation-grid, .automation-live { grid-template-columns: 1fr; padding-left: 10px; padding-right: 10px; }
  .auto-fields { grid-template-columns: 1fr; }
  .auto-actions { flex-direction: column; }
  .auto-actions .btn { flex: none; width: 100%; }
  .auto-card { padding: 10px; }
  .btn { min-height: 44px; }
  .field input { min-height: 44px; font-size: 16px; }
  .auto-row { flex-wrap: wrap; padding: 5px 0; }
}
