:root {
  color-scheme: dark;
  --bg: #0f1115;
  --surface-1: #161a20;
  --surface-2: #1d222a;
  --surface-3: #2a313c;
  --border: #2c333e;
  --text-1: #e8eaed;
  --text-2: #9aa3af;
  --text-3: #6b7480;
  --accent: #3987e5;
  --accent-2: #2a78d6;
  --good: #0ca30c;
  --good-text: #3ecf6e;
  --critical: #d03b3b;
  --critical-text: #f07070;
  --warning: #fab219;

  --chart-bg: #12151a;
  --chart-grid: #1c2129;
  --chart-axis: #2c333e;
  --candle-up: #1fa67a;
  --candle-down: #e04a4a;
  --candle-up-border: #1fa67a;
  --candle-down-border: #e04a4a;
  --candle-wick: #8a929e;
  --price-up: #1fa67a;
  --price-down: #e04a4a;
  --live-bg: #1c3b2a;
  --ema: #eda100;
  --buy: #3987e5;
  --sell: #e66767;
  --position: #c98500;
  --crosshair: #6b7480;
  --day-sep: #4a5361;

  --radius: 8px;
  font-family: system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  font-size: 14px;
}

/* Tema dia: fundo claro, barras de alta brancas e de baixa pretas */
:root[data-theme="light"] {
  color-scheme: light;
  --bg: #f3f4f6;
  --surface-1: #ffffff;
  --surface-2: #f1f3f5;
  --surface-3: #e2e6eb;
  --border: #d3d8df;
  --text-1: #14171c;
  --text-2: #565e6b;
  --text-3: #8a919c;
  --accent: #2a78d6;
  --accent-2: #2a78d6;
  --good-text: #0a7d33;
  --critical-text: #c42f2f;

  --chart-bg: #ffffff;
  --chart-grid: #eef0f3;
  --chart-axis: #c9ced6;
  --candle-up: #ffffff;
  --candle-down: #111111;
  --candle-up-border: #111111;
  --candle-down-border: #111111;
  --candle-wick: #111111;
  --price-up: #168a5f;
  --price-down: #c93636;
  --ema: #d17a00;
  --buy: #2a78d6;
  --sell: #d03b3b;
  --position: #a86d00;
  --crosshair: #8a919c;
  --day-sep: #9aa1ab;
  --live-bg: #dcf2e3;
}

/* Tema do gráfico, independente do tema da tela (ex.: boleta escura com gráfico de fundo branco, como no Profit).
   O gráfico lê as cores do próprio contêiner, então estas variáveis só valem dentro dele. */
.chart-wrap[data-chart-theme="light"] {
  --surface-1: #ffffff; --surface-2: #f1f3f5; --surface-3: #e2e6eb; --border: #d3d8df;
  --text-1: #14171c; --text-2: #565e6b; --text-3: #8a919c; --accent: #2a78d6;
  --chart-bg: #ffffff; --chart-grid: #eef0f3; --chart-axis: #c9ced6;
  --candle-up: #ffffff; --candle-down: #111111; --candle-up-border: #111111; --candle-down-border: #111111; --candle-wick: #111111;
  --price-up: #168a5f; --price-down: #c93636; --ema: #d17a00;
  --buy: #2a78d6; --sell: #d03b3b; --position: #a86d00; --crosshair: #8a919c; --day-sep: #9aa1ab;
  color-scheme: light; color: var(--text-1);
}
.chart-wrap[data-chart-theme="dark"] {
  --surface-1: #161a20; --surface-2: #1d222a; --surface-3: #2a313c; --border: #2c333e;
  --text-1: #e8eaed; --text-2: #9aa3af; --text-3: #6b7480; --accent: #3987e5;
  --chart-bg: #12151a; --chart-grid: #1c2129; --chart-axis: #2c333e;
  --candle-up: #1fa67a; --candle-down: #e04a4a; --candle-up-border: #1fa67a; --candle-down-border: #e04a4a; --candle-wick: #8a929e;
  --price-up: #1fa67a; --price-down: #e04a4a; --ema: #eda100;
  --buy: #3987e5; --sell: #e66767; --position: #c98500; --crosshair: #6b7480; --day-sep: #4a5361;
  color-scheme: dark; color: var(--text-1);
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; background: var(--bg); color: var(--text-1); }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3 { margin: 0 0 12px; font-weight: 600; }
h1 { font-size: 22px; } h2 { font-size: 17px; } h3 { font-size: 14px; color: var(--text-2); }

button, .btn {
  font: inherit; color: var(--text-1); background: var(--surface-3); border: 1px solid var(--border);
  border-radius: 6px; padding: 7px 12px; cursor: pointer; display: inline-flex; align-items: center; gap: 6px;
  text-decoration: none; white-space: nowrap;
}
button:hover, .btn:hover { filter: brightness(1.15); text-decoration: none; }
:root[data-theme="light"] button:hover, :root[data-theme="light"] .btn:hover { filter: brightness(0.93); }
button:disabled { opacity: .5; cursor: default; filter: none; }
button.primary, .btn.primary { background: var(--accent-2); border-color: var(--accent-2); color: #fff; }
/* Boleta no padrão do Profit: compra âmbar, venda verde, zerar vermelho, demais cinza (iguais nos dois temas) */
button.buy { background: #ffa000; border-color: #e08d00; color: #1a1a1a; font-weight: 600; }
button.sell { background: #0e874e; border-color: #0b7442; color: #fff; font-weight: 600; }
button.pf-zero { background: #db3c2a; border-color: #c23324; color: #fff; font-weight: 600; }
button.pf-gray { background: #a3a3a3; border-color: #8f8f8f; color: #141414; font-weight: 600; }
.side-buy { color: #d98a00; font-weight: 700; }
.side-sell { color: #0e874e; font-weight: 700; }
.qty-quick { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; }
.qty-quick button { justify-content: center; padding: 4px 0; }
button.ghost { background: transparent; }
button.small, .btn.small { padding: 4px 8px; font-size: 12px; }
button.active { outline: 2px solid var(--accent); outline-offset: -2px; }

input, select, textarea {
  font: inherit; color: var(--text-1); background: var(--surface-1); border: 1px solid var(--border);
  border-radius: 6px; padding: 7px 9px; min-width: 0;
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
label { color: var(--text-2); font-size: 12px; display: flex; flex-direction: column; gap: 4px; }
label.inline { flex-direction: row; align-items: center; gap: 6px; font-size: 13px; }
.history-checks { display: flex; flex-direction: column; gap: 6px; max-height: 260px; overflow-y: auto; }
.history-checks label.inline input { width: auto; }
.history-checks .h-new { margin-top: 4px; }
.swatches { display: inline-flex; gap: 3px; align-items: center; }
.swatch { width: 16px; height: 16px; min-width: 0; padding: 0; border-radius: 3px; border: 1px solid rgba(0,0,0,.25); }
.tag-input { display: flex; flex-wrap: wrap; gap: 4px; align-items: center; padding: 4px; border: 1px solid var(--border); border-radius: 6px; background: var(--surface-1); }
.tag-input input { flex: 1; min-width: 120px; border: none; background: transparent; padding: 4px; }
.tag-input .chip button { border: none; background: none; padding: 0 0 0 2px; min-width: 0; cursor: pointer; color: inherit; }
.study-card { cursor: pointer; display: flex; flex-direction: column; gap: 6px; color: inherit; text-decoration: none; }
.study-card .sel { width: 18px; height: 18px; margin: 2px 0 0; cursor: pointer; }
.study-card:hover { border-color: var(--accent); }
.study-desc { margin: 0; display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; }
.label-picks { display: flex; flex-wrap: wrap; gap: 4px; margin-top: -4px; }
.label-picks .chip { cursor: pointer; color: inherit; font: inherit; font-size: 12px; }
.label-picks .chip.on { background: var(--accent); border-color: var(--accent); color: #fff; }
.chip-setup { border-color: var(--accent); }
.chip-exit { border-style: dashed; }
.trade-labels { cursor: pointer; }
.chip { display: inline-block; padding: 1px 8px; border: 1px solid var(--border); border-radius: 10px; background: var(--surface-2);
  font-size: 12px; white-space: nowrap; margin: 1px 0; }

.topbar {
  display: flex; align-items: center; gap: 16px; padding: 10px 16px; border-bottom: 1px solid var(--border);
  background: var(--surface-1);
}
.topbar .brand { font-weight: 700; color: var(--text-1); }
.topbar nav { display: flex; gap: 14px; flex: 1; }
.topbar nav a { color: var(--text-2); }
.topbar nav a.active { color: var(--text-1); font-weight: 600; }
.topbar .user { color: var(--text-2); }

.container { max-width: 1180px; margin: 0 auto; padding: 20px 16px 60px; }
.grid { display: grid; gap: 16px; }
.grid.cols-3 { grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); }
.grid.cols-4 { grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); }
.card { background: var(--surface-1); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; }
.card p { color: var(--text-2); margin: 0 0 12px; }
.stack { display: flex; flex-direction: column; gap: 10px; }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.muted { color: var(--text-2); }
.small { font-size: 12px; }
.pos { color: var(--good-text); }
.neg { color: var(--critical-text); }
.error { color: var(--critical-text); min-height: 18px; font-size: 13px; }
.badge { font-size: 11px; padding: 2px 7px; border-radius: 10px; background: var(--surface-3); color: var(--text-2); }
.badge.live { background: var(--live-bg); color: var(--good-text); }

table { width: 100%; border-collapse: collapse; font-size: 13px; }
th, td { text-align: left; padding: 7px 8px; border-bottom: 1px solid var(--border); }
th { color: var(--text-2); font-weight: 500; font-size: 12px; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
.table-wrap { overflow-x: auto; }

.auth-box { max-width: 380px; margin: 8vh auto; }
.tabs { display: flex; gap: 4px; margin-bottom: 16px; }
.tabs button { flex: 1; }

/* ---------- Simulação ---------- */
body.sim { height: 100vh; overflow: hidden; display: flex; flex-direction: column; }
.sim-header { display: flex; align-items: center; gap: 12px; padding: 8px 12px; border-bottom: 1px solid var(--border); background: var(--surface-1); flex-wrap: wrap; }
.sim-header .asset { font-weight: 700; font-size: 15px; }
.sim-body { flex: 1; display: grid; grid-template-columns: 1fr 300px; min-height: 0; }
.chart-col { display: flex; flex-direction: column; min-width: 0; min-height: 0; }
.toolbar { display: flex; gap: 3px; padding: 5px 8px; border-bottom: 1px solid var(--border); flex-wrap: wrap; align-items: center; background: var(--surface-1); }
.toolbar .sep { width: 1px; height: 22px; background: var(--border); margin: 0 3px; }
.toolbar button.small { padding: 4px 7px; }
.toolbar input[type=color] { width: 30px; height: 28px; padding: 2px; }
.toolbar select { padding: 4px 6px; font-size: 12px; }
.toolbar .group-label { font-size: 11px; color: var(--text-3); margin-left: 2px; }
.ctx-menu { position: fixed; z-index: 40; background: var(--surface-1); border: 1px solid var(--border); border-radius: 6px; padding: 4px; min-width: 150px; box-shadow: 0 6px 20px rgba(0,0,0,.35); }
.ctx-menu button { display: block; width: 100%; text-align: left; background: transparent; border: 0; padding: 6px 10px; }
.ctx-menu button:hover { background: var(--surface-3); filter: none; }
.text-editor { position: absolute; z-index: 10; background: var(--surface-1); border: 1px solid var(--accent); padding: 3px 6px; min-width: 160px; }
.chart-area { flex: 1; display: flex; min-height: 0; }
.drawbar { display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 6px 4px; border-right: 1px solid var(--border); background: var(--surface-1); overflow-y: auto; }
.drawbar button { width: 34px; height: 34px; padding: 0; justify-content: center; background: transparent; border-color: transparent; color: var(--text-2); }
.drawbar button:hover { background: var(--surface-3); color: var(--text-1); filter: none; }
.drawbar button.active { background: var(--surface-3); color: var(--accent); outline: none; }
.drawbar button:disabled { opacity: .35; background: transparent; color: var(--text-2); }
.drawbar .sep { width: 22px; height: 1px; background: var(--border); margin: 4px 0; }
.chart-wrap { flex: 1; position: relative; min-height: 200px; min-width: 0; }
.chart-canvas { display: block; outline: none; touch-action: none; }
.hint { font-size: 11px; color: var(--text-3); padding: 4px 10px; border-top: 1px solid var(--border); }
.side { border-left: 1px solid var(--border); background: var(--surface-1); overflow-y: auto; overflow-x: hidden; min-width: 0; display: flex; flex-direction: column; }
.panel { padding: 12px; border-bottom: 1px solid var(--border); }
.panel h3 { margin-bottom: 8px; display: flex; justify-content: space-between; align-items: center; }
.boleta-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
.boleta-grid .full { grid-column: 1 / -1; }
.boleta-grid > *, .boleta-grid input { min-width: 0; width: 100%; justify-content: center; }
.boleta-grid label.inline { justify-content: flex-start; }
.boleta-grid label.inline input { width: auto; }
.qty-row { display: flex; gap: 4px; align-items: stretch; }
.qty-row button { width: 40px; flex: none; justify-content: center; }
.qty-row input { width: 100%; text-align: center; font-size: 16px; font-weight: 600; }
.kv { display: grid; grid-template-columns: auto 1fr; gap: 4px 10px; font-size: 13px; }
.kv span:nth-child(even) { text-align: right; font-variant-numeric: tabular-nums; }
.advance-btn { font-size: 15px; padding: 9px 18px; }
.list-mini { font-size: 12px; }
.list-mini td { padding: 4px; }

.modal-back { position: fixed; inset: 0; background: rgba(0,0,0,.6); display: flex; align-items: center; justify-content: center; z-index: 50; padding: 16px; }
.modal { background: var(--surface-1); border: 1px solid var(--border); border-radius: var(--radius); padding: 20px; width: 100%; max-width: 440px; max-height: calc(100vh - 32px); overflow-y: auto; }
.modal.wide { max-width: 820px; }
.modal-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 12px; }
.modal-head h2 { margin: 0; }
.toast { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); background: var(--surface-3); border: 1px solid var(--border); padding: 10px 16px; border-radius: 6px; z-index: 60; }

/* ---------- Estatísticas ---------- */
.stat { background: var(--surface-2); border-radius: 6px; padding: 10px 12px; }
.stat .label { font-size: 11px; color: var(--text-2); }
.stat .value { font-size: 18px; font-weight: 600; font-variant-numeric: tabular-nums; margin-top: 2px; }
.chart-box { position: relative; height: 240px; }
.chart-box.short { height: 140px; }
.chart-box canvas { width: 100%; height: 100%; display: block; }
.tooltip { position: absolute; pointer-events: none; background: var(--surface-3); border: 1px solid var(--border); border-radius: 6px; padding: 6px 9px; font-size: 12px; white-space: nowrap; z-index: 5; }

/* ---------- Boleta mobile (só aparece em telas estreitas) ---------- */
.mboleta, .sheet-back, .sheet-head { display: none; }
button.buy-outline { border-color: #ffa000; color: #c77d00; background: transparent; }
button.sell-outline { border-color: #0e874e; color: #0e874e; background: transparent; }
button.buy-outline.active { background: #ffa000; color: #1a1a1a; outline: none; }
button.sell-outline.active { background: #0e874e; color: #fff; outline: none; }

@media (max-width: 900px) {
  body.sim { height: 100vh; height: 100dvh; }
  .sim-header { flex-wrap: nowrap; overflow-x: auto; gap: 8px; padding: 6px 8px; scrollbar-width: none; }
  .sim-header > * { flex: none; }
  .sim-header #date, .sim-header #advance { display: none; }
  .sim-header button, .sim-header .btn { padding: 5px 9px; font-size: 13px; }
  .sim-body { display: flex; flex-direction: column; }
  .chart-col { flex: 1; }
  .toolbar { flex-wrap: nowrap; overflow-x: auto; scrollbar-width: none; }
  .toolbar > * { flex: none; }
  .drawbar button { width: 30px; height: 30px; }
  .hint { display: none; }

  .mboleta {
    display: flex; flex-direction: column; gap: 6px; padding: 6px 8px calc(6px + env(safe-area-inset-bottom));
    border-top: 1px solid var(--border); background: var(--surface-1);
  }
  .mb-status { display: flex; align-items: center; gap: 6px; }
  .mb-pos { flex: 1; min-width: 0; font-size: 13px; font-variant-numeric: tabular-nums; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .mb-advance { padding: 8px 14px; font-size: 15px; }
  .mb-back { padding: 8px 12px; font-size: 15px; }
  .mb-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; }
  .mb-grid > button { justify-content: center; min-height: 42px; padding: 6px 4px; white-space: normal; line-height: 1.15; text-align: center; }
  .mb-grid .mb-qty { grid-column: span 2; }
  .mb-qty button { width: 42px; }
  .mb-qty input { font-size: 16px; } /* 16px evita o zoom automático do iOS ao focar */

  /* O painel lateral vira uma gaveta que sobe do rodapé */
  .side {
    position: fixed; left: 0; right: 0; bottom: 0; z-index: 30; max-height: 80vh; max-height: 80dvh;
    border-left: 0; border-top: 1px solid var(--border); border-radius: 12px 12px 0 0;
    box-shadow: 0 -8px 30px rgba(0,0,0,.4); transform: translateY(105%); transition: transform .2s ease;
    padding-bottom: env(safe-area-inset-bottom);
  }
  body.sheet-open .side { transform: none; }
  .sheet-head { display: flex; justify-content: space-between; align-items: center; padding: 10px 12px 0; position: sticky; top: 0; background: var(--surface-1); z-index: 1; }
  body.sheet-open .sheet-back { display: block; position: fixed; inset: 0; z-index: 29; background: rgba(0,0,0,.45); }
  .boleta-grid input { font-size: 16px; }

  .toast { bottom: auto; top: 56px; max-width: calc(100vw - 32px); text-align: center; }
}

/* ---------- Campeonatos ---------- */
.rules { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 8px; }
.rank-row { cursor: pointer; }
.rank-row:hover td { background: var(--surface-2); }
.progress { height: 6px; background: var(--surface-3); border-radius: 3px; overflow: hidden; min-width: 60px; }
.progress > div { height: 100%; background: var(--accent); }
.flag { color: var(--warning); }
.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 12px; }
.help { font-size: 11px; color: var(--text-3); }

/* ---------- Admin ---------- */
.admin-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; }
.admin-head h1 { margin: 0; }
.seg { display: inline-flex; border: 1px solid var(--border); border-radius: 6px; overflow: hidden; }
.seg button { border: 0; border-radius: 0; background: transparent; color: var(--text-2); padding: 6px 12px; }
.seg button + button { border-left: 1px solid var(--border); }
.seg button.on { background: var(--surface-3); color: var(--text-1); font-weight: 600; }
.admin-tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--border); overflow-x: auto; scrollbar-width: none; }
.admin-tabs button { background: transparent; border: 0; border-bottom: 2px solid transparent; border-radius: 0; color: var(--text-2); padding: 8px 12px; }
.admin-tabs button.on { color: var(--text-1); border-bottom-color: var(--accent); font-weight: 600; }
.kpis { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; }
.admin-error:empty { display: none; }
.kpi { background: var(--surface-1); border: 1px solid var(--border); border-radius: var(--radius); padding: 12px 14px; }
.kpi .label { font-size: 12px; color: var(--text-2); }
.kpi .value { font-size: 24px; font-weight: 650; font-variant-numeric: tabular-nums; margin-top: 4px; }
.kpi .sub { font-size: 11px; color: var(--text-3); margin-top: 2px; }
.charts { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 460px), 1fr)); gap: 16px; }
.chart-card h2 { font-size: 14px; margin: 0 0 2px; }
.chart-card .note { font-size: 11px; color: var(--text-3); margin-bottom: 8px; }
.svgchart { position: relative; width: 100%; }
.svgchart svg { display: block; width: 100%; overflow: visible; }
.svgchart text { fill: var(--text-3); font-size: 10px; font-variant-numeric: tabular-nums; }
.svgchart .grid-line { stroke: var(--chart-grid); }
.svgchart .base-line { stroke: var(--chart-axis); }
.svgchart .bar { fill: var(--accent); }
.svgchart .bar.dim { opacity: .35; }
.svgchart .hit:hover + .bar, .svgchart .bar.hover { fill: var(--accent-2); filter: brightness(1.2); }
.svgchart .line { fill: none; stroke: var(--accent); stroke-width: 2; }
.svgchart .area { fill: var(--accent); opacity: .12; }
.svgchart .dot { fill: var(--accent); stroke: var(--surface-1); stroke-width: 2; }
.svgchart .cross { stroke: var(--crosshair); stroke-dasharray: 3 3; }
.svgchart .tooltip b { font-variant-numeric: tabular-nums; }
.hbar-row { display: grid; grid-template-columns: 60px 1fr 44px; gap: 8px; align-items: center; font-size: 12px; padding: 3px 0; }
.hbar-row .track { height: 14px; }
.hbar-row .fill { height: 100%; background: var(--accent); border-radius: 0 4px 4px 0; min-width: 2px; }
.hbar-row .v { text-align: right; font-variant-numeric: tabular-nums; color: var(--text-2); }
.admin-table tr.click { cursor: pointer; }
.admin-table tr.click:hover td { background: var(--surface-2); }
.admin-table th.sort { cursor: pointer; user-select: none; }
.admin-table th.sort:hover { color: var(--text-1); }
.badge.warn { background: color-mix(in srgb, var(--warning) 22%, transparent); color: var(--warning); }
.badge.bad { background: color-mix(in srgb, var(--critical) 22%, transparent); color: var(--critical-text); }
.meter { height: 6px; background: var(--surface-3); border-radius: 3px; overflow: hidden; margin-top: 6px; }
.meter > div { height: 100%; background: var(--accent); }
.meter.hot > div { background: var(--warning); }
@media (max-width: 760px) { .kpis { grid-template-columns: repeat(2, 1fr); } }
@media (max-width: 600px) {
  .topbar { flex-wrap: wrap; row-gap: 6px; }
  .topbar nav { order: 3; flex-basis: 100%; }
  .kpi .value { font-size: 20px; }
  .admin-table .hide-sm { display: none; }
}

/* Lista de campeonatos: no celular só nome (com resumo), situação e ação */
.champ-list .show-sm { display: none; }
@media (max-width: 700px) {
  .champ-list .hide-sm { display: none; }
  .champ-list .show-sm { display: inline; }
}
