:root {
  --bg: #0d1117;
  --panel: #161b22;
  --panel2: #1c232d;
  --line: #2a3340;
  --text: #e6edf3;
  --muted: #8b98a8;
  --green: #22c55e;
  --red: #ef4444;
  --amber: #f59e0b;
  --blue: #3b82f6;
  --radius: 10px;
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--text);
  font: 14px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; }
h1 { font-size: 18px; margin: 0; }
h2 { font-size: 15px; margin: 0 0 10px; }
h3 { font-size: 14px; margin: 0 0 6px; }
code { background: var(--panel2); padding: 1px 5px; border-radius: 4px; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.hidden { display: none !important; }
.mt { margin-top: 18px; }
.pos { color: var(--green); }
.neg { color: var(--red); }

.top { display: flex; flex-wrap: wrap; gap: 14px; align-items: center; justify-content: space-between;
  padding: 12px 20px; border-bottom: 1px solid var(--line); background: var(--panel); position: sticky; top: 0; z-index: 5; }
.brand { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.badge { font-size: 11px; font-weight: 700; padding: 3px 8px; border-radius: 99px; background: var(--panel2);
  border: 1px solid var(--line); letter-spacing: .03em; }
.badge.paper { color: var(--amber); border-color: #5c4310; }
.badge.sim { color: #a5b4fc; border-color: #3c3f7a; }
.badge.real { color: var(--green); border-color: #14532d; }
.clock { display: flex; gap: 14px; align-items: baseline; flex-wrap: wrap; }
.controls { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.speed { color: var(--muted); font-size: 12px; display: flex; gap: 6px; align-items: center; }
select, input { background: var(--panel2); color: var(--text); border: 1px solid var(--line); border-radius: 8px;
  padding: 6px 8px; font: inherit; }
.btn, .seg button { background: var(--panel2); color: var(--text); border: 1px solid var(--line); border-radius: 8px;
  padding: 7px 12px; font: inherit; font-weight: 600; cursor: pointer; }
.btn:hover, .seg button:hover { border-color: #3d4a5c; }
.btn.primary { background: var(--blue); border-color: var(--blue); }
.btn.ok { background: #15803d; border-color: #15803d; }
.btn.danger { background: #7f1d1d; border-color: #991b1b; color: #fee2e2; }
.btn.small { padding: 4px 8px; font-size: 12px; }
.btn:disabled { opacity: .5; cursor: default; }
.seg { display: inline-flex; border-radius: 8px; overflow: hidden; border: 1px solid var(--line); }
.seg button { border: 0; border-radius: 0; }
.seg button.active[data-mode="manual"] { background: var(--blue); }
.seg button.active[data-mode="auto"] { background: #b45309; }

main { padding: 16px 20px 30px; max-width: 1500px; margin: 0 auto; display: flex; flex-direction: column; gap: 14px; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; min-width: 0; }
.cardhead { display: flex; justify-content: space-between; align-items: center; gap: 10px; margin-bottom: 8px; }
.cardhead h2 { margin: 0; }
.grid2 { display: grid; grid-template-columns: minmax(0, 1.6fr) minmax(0, 1fr); gap: 14px; }
@media (max-width: 1000px) { .grid2 { grid-template-columns: minmax(0, 1fr); } }

.kpis { display: grid; grid-template-columns: repeat(6, minmax(0, 1fr)); gap: 10px; }
@media (max-width: 1100px) { .kpis { grid-template-columns: repeat(3, minmax(0, 1fr)); } }
@media (max-width: 600px) { .kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); } main, .top { padding-left: 12px; padding-right: 12px; } .top { position: static; } }
.kpi { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 10px 12px;
  display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.kpi span { color: var(--muted); font-size: 12px; }
.kpi b { font-size: 20px; font-variant-numeric: tabular-nums; }
.bar { height: 6px; background: var(--panel2); border-radius: 99px; overflow: hidden; margin-top: 6px; }
.bar i { display: block; height: 100%; width: 0; background: var(--green); transition: width .3s; }

.banner { padding: 10px 14px; border-radius: var(--radius); font-weight: 600; }
.banner.warn { background: #3b2a08; border: 1px solid #5c4310; color: #fde68a; }

#approvals { border-color: var(--blue); box-shadow: 0 0 0 1px var(--blue) inset; }
.ticket { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 12px; padding: 12px; border-radius: 8px;
  background: var(--panel2); margin-bottom: 8px; align-items: center; }
.ticket .line1 { font-size: 16px; font-weight: 700; }
.ticket .facts { display: flex; flex-wrap: wrap; gap: 4px 16px; margin-top: 4px; color: var(--muted); }
.ticket .facts b { color: var(--text); }
.ticket .actions { display: flex; gap: 8px; }
@media (max-width: 600px) { .ticket { grid-template-columns: minmax(0, 1fr); } }

.chart { height: 360px; width: 100%; }
.chart.small { height: 220px; }

.tablewrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; }
th, td { text-align: left; padding: 6px 8px; border-bottom: 1px solid var(--line); white-space: nowrap; }
th { color: var(--muted); font-weight: 600; font-size: 12px; }
tr.clickable { cursor: pointer; }
tr.clickable:hover td { background: var(--panel2); }
.state { font-size: 11px; font-weight: 700; padding: 2px 7px; border-radius: 99px; background: var(--panel2); }
.state.triggered { color: var(--green); }
.state.waiting { color: #93c5fd; }
.state.forming { color: var(--muted); }
.state.expired { color: var(--muted); text-decoration: line-through; }
.st-executed { color: var(--green); } .st-blocked { color: var(--red); } .st-pending { color: #93c5fd; }
.st-expired, .st-rejected { color: var(--muted); }

.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); margin: -4px 0 12px; overflow-x: auto; }
.tab { background: none; border: 0; color: var(--muted); padding: 8px 12px; font: inherit; font-weight: 600; cursor: pointer;
  border-bottom: 2px solid transparent; }
.tab.active { color: var(--text); border-bottom-color: var(--blue); }
.events { max-height: 420px; overflow-y: auto; font-size: 13px; }
.ev { display: grid; grid-template-columns: 150px 64px minmax(0, 1fr); gap: 10px; padding: 4px 0; border-bottom: 1px solid #1f2731; }
.ev .lvl { font-size: 11px; font-weight: 700; text-transform: uppercase; }
.ev.trade .lvl { color: var(--green); } .ev.signal .lvl { color: #93c5fd; } .ev.warn .lvl { color: var(--amber); }
.ev.error .lvl { color: var(--red); } .ev.info .lvl { color: var(--muted); }
@media (max-width: 600px) { .ev { grid-template-columns: minmax(0, 1fr); gap: 0; } }

.statgrid { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 8px; margin-bottom: 14px; }
.stat { background: var(--panel2); border-radius: 8px; padding: 8px 10px; }
.stat span { display: block; color: var(--muted); font-size: 12px; }
.stat b { font-size: 17px; }
.ask { display: flex; gap: 8px; margin: 8px 0; }
.ask input { flex: 1; min-width: 0; }
.report { background: var(--panel2); border-radius: 8px; padding: 12px 14px; margin-top: 10px; }
.report .meta { color: var(--muted); font-size: 12px; margin-bottom: 6px; }
.report .body { white-space: pre-wrap; }
.danger-zone { margin-top: 18px; padding: 12px; border: 1px solid #5b1d1d; border-radius: 8px; }
footer { text-align: center; padding: 10px; }
.toast { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); background: var(--panel2);
  border: 1px solid var(--line); padding: 10px 16px; border-radius: 8px; z-index: 20; max-width: 90vw; }

.danger-zone.first { margin-top: 0; }
.row { display: flex; gap: 10px; align-items: end; flex-wrap: wrap; }
.row label, .limits label { display: flex; flex-direction: column; gap: 4px; color: var(--muted); font-size: 12px; }
.limits { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 12px; }
.limits input, .limits select, .row input { width: 100%; }
.limits .hint { font-size: 11px; color: var(--muted); }

#positions th, #positions td { padding: 6px 5px; font-size: 13px; }

.state.o-bought { color: var(--green); }
.state.o-pending { color: #93c5fd; }
.state.o-skipped { color: var(--amber); }
.state.o-sold_win { color: var(--green); }
.state.o-sold_loss { color: var(--red); }
.why { font-size: 11px; color: var(--muted); max-width: 230px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; margin-top: 2px; }

/* acceso */
.auth-page { display: flex; align-items: flex-start; justify-content: center; min-height: 100vh; padding: 40px 16px; }
.auth-box { width: 100%; max-width: 440px; background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 22px; display: flex; flex-direction: column; gap: 10px; }
.auth-box h1 { font-size: 20px; }
.auth-step { display: flex; flex-direction: column; gap: 12px; }
.auth-step label, .card-lite label { display: flex; flex-direction: column; gap: 4px; color: var(--muted); font-size: 12px; }
.auth-step input, .card-lite input { width: 100%; font-size: 15px; padding: 9px 10px; }
.steps { margin: 0; padding-left: 18px; color: var(--muted); }
.qr { background: #fff; border-radius: 8px; padding: 8px; align-self: center; line-height: 0; }
.secret { word-break: break-all; }
.codes { background: var(--panel2); border-radius: 8px; padding: 12px; font-size: 15px; letter-spacing: .05em; white-space: pre-wrap; }
.auth-msg { padding: 10px 12px; border-radius: 8px; background: #3b1212; border: 1px solid #7f1d1d; color: #fecaca; }
.auth-msg.ok { background: #0f2e1b; border-color: #14532d; color: #bbf7d0; }
.linkbtn { background: none; border: 0; color: #93c5fd; cursor: pointer; padding: 0; font: inherit; text-align: left; }
.sec-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 12px; }
.card-lite { background: var(--panel2); border-radius: 8px; padding: 12px; display: flex; flex-direction: column; gap: 10px; }
.card-lite h4 { margin: 0; font-size: 14px; }
.sess { padding: 6px 0; border-bottom: 1px solid var(--line); }
