:root {
  --bg: #0d1117;
  --bg-elev: #151b23;
  --bg-soft: #1b2230;
  --line: #262e3d;
  --text: #e6edf3;
  --muted: #8b98a9;
  --accent: #3fb6a8;
  --accent-dim: #266b63;
  --up: #35c48b;
  --down: #f0596b;
  --warn: #e3b341;
  --radius: 10px;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 14px/1.5 "Segoe UI", Roboto, -apple-system, "Helvetica Neue", Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
}

.hidden { display: none !important; }

/* ---------------------------------------------------------------- topbar */
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  gap: 16px; flex-wrap: wrap;
  padding: 12px 20px;
  background: var(--bg-elev);
  border-bottom: 1px solid var(--line);
  position: sticky; top: 0; z-index: 20;
}
.brand { display: flex; align-items: center; gap: 10px; }
.brand .logo { font-size: 22px; }
.brand strong { display: block; letter-spacing: .3px; }
.brand small { color: var(--muted); font-size: 12px; }

.toolbar { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
select, input[type="date"], input[type="text"], input[type="number"] {
  background: var(--bg-soft); color: var(--text);
  border: 1px solid var(--line); border-radius: 8px;
  padding: 7px 10px; font-size: 13px; font-family: inherit;
}
select:focus, input:focus { outline: 1px solid var(--accent); }

button, .btn {
  background: var(--bg-soft); color: var(--text);
  border: 1px solid var(--line); border-radius: 8px;
  padding: 7px 12px; font-size: 13px; cursor: pointer;
  font-family: inherit; text-decoration: none; display: inline-block;
}
button:hover, .btn:hover { border-color: var(--accent-dim); }
button.primary { background: var(--accent); border-color: var(--accent); color: #06201d; font-weight: 600; }
button.primary:hover { filter: brightness(1.08); }
button.danger { color: var(--down); }

.presets { display: flex; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; }
.presets button { border: 0; border-radius: 0; padding: 7px 11px; background: var(--bg-soft); }
.presets button.active { background: var(--accent-dim); color: #fff; }

/* abas de ano do grafico de ganho mensal */
.year-tabs { display: flex; gap: 2px; }
.year-tabs button {
  background: none; border: 0; border-bottom: 2px solid transparent;
  border-radius: 0; padding: 4px 10px; color: var(--muted);
  font-size: 13px; font-weight: 600; letter-spacing: .3px;
}
.year-tabs button:hover { color: var(--text); }
.year-tabs button.active { color: var(--warn); border-bottom-color: var(--warn); }

/* ------------------------------------------------------------------ tabs */
.tabs {
  display: flex; gap: 4px; padding: 0 20px;
  background: var(--bg-elev); border-bottom: 1px solid var(--line);
  position: sticky; top: 61px; z-index: 19; overflow-x: auto;
}
.tabs button {
  background: none; border: 0; border-bottom: 2px solid transparent;
  border-radius: 0; padding: 11px 14px; color: var(--muted); white-space: nowrap;
}
.tabs button.active { color: var(--text); border-bottom-color: var(--accent); }

main { padding: 20px; max-width: 1600px; margin: 0 auto; }
.tab { display: none; }
.tab.active { display: block; }

/* ------------------------------------------------------------------ cards */
.card {
  background: var(--bg-elev); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 16px; margin-bottom: 16px;
}
.card-head {
  display: flex; align-items: baseline; justify-content: space-between;
  gap: 12px; flex-wrap: wrap; margin-bottom: 12px;
}
.card-head h3 { margin: 0; font-size: 14px; font-weight: 600; letter-spacing: .2px; }
.hint { color: var(--muted); font-size: 12px; }
.row-actions { display: flex; align-items: center; gap: 10px; }
.grid-2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(420px, 1fr)); gap: 16px; }
.explain { color: var(--muted); font-size: 13px; margin: 0 0 14px; max-width: 90ch; }

.chart-box { position: relative; height: 260px; }
.chart-box.tall { height: 380px; }

/* ------------------------------------------------------------------- kpis */
.kpis {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(165px, 1fr));
  gap: 12px; margin-bottom: 16px;
}
.kpi {
  background: var(--bg-elev); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 12px 14px;
}
.kpi .label { color: var(--muted); font-size: 11px; text-transform: uppercase; letter-spacing: .6px; }
.kpi .value { font-size: 21px; font-weight: 600; margin-top: 4px; font-variant-numeric: tabular-nums; }
.kpi .sub { color: var(--muted); font-size: 12px; margin-top: 2px; }

.up { color: var(--up); }
.down { color: var(--down); }
.dim { color: var(--muted); }
.warn { color: var(--warn); }

/* ----------------------------------------------------------------- tables */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th, td { padding: 8px 10px; text-align: right; white-space: nowrap; border-bottom: 1px solid var(--line); }
th:first-child, td:first-child, th.left, td.left { text-align: left; }
th {
  color: var(--muted); font-weight: 500; font-size: 11px;
  text-transform: uppercase; letter-spacing: .5px;
  position: sticky; top: 0; background: var(--bg-elev);
}
tbody tr:hover { background: var(--bg-soft); }
td.num { font-variant-numeric: tabular-nums; }
.tag {
  display: inline-block; padding: 1px 7px; border-radius: 20px;
  background: var(--bg-soft); border: 1px solid var(--line);
  font-size: 11px; color: var(--muted);
}
.dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; margin-right: 7px; }

.pager { display: flex; align-items: center; gap: 12px; justify-content: center; margin-top: 12px; }
.pager span { color: var(--muted); font-size: 12px; }

.kv { display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); gap: 6px 20px; }
.kv div { display: flex; justify-content: space-between; gap: 12px; padding: 5px 0; border-bottom: 1px solid var(--line); }
.kv span:first-child { color: var(--muted); }
.kv span:last-child { font-variant-numeric: tabular-nums; }

/* -------------------------------------------------------------- ea cards */
.cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); gap: 12px; margin-bottom: 16px; }
.ea-card {
  background: var(--bg-elev); border: 1px solid var(--line);
  border-left: 3px solid var(--accent); border-radius: var(--radius); padding: 14px;
}
.ea-card h4 { margin: 0 0 2px; font-size: 14px; display: flex; align-items: center; gap: 8px; }
.ea-card .net { font-size: 22px; font-weight: 600; font-variant-numeric: tabular-nums; margin: 6px 0 10px; }
.ea-card .net-pct { font-size: 13px; font-weight: 500; margin-left: 8px; }
.ea-card .metrics { display: grid; grid-template-columns: 1fr 1fr; gap: 4px 12px; font-size: 12px; }
.ea-card .metrics div { display: flex; justify-content: space-between; }
.ea-card .metrics span:first-child { color: var(--muted); }
.ea-card .metrics .frac { font-size: 10px; opacity: .8; margin-left: 4px; }
.badge { font-size: 11px; padding: 1px 7px; border-radius: 20px; background: var(--bg-soft); color: var(--muted); }
.badge.live { background: rgba(53,196,139,.15); color: var(--up); }

/* ------------------------------------------------------------------ forms */
.rule-form { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 14px; }
.rule-form input[name="pattern"] { flex: 2 1 240px; }
.rule-form input[name="ea_name"] { flex: 1 1 180px; }
.rule-form input[name="priority"] { width: 90px; }
.rule-form input { background: var(--bg-soft); color: var(--text); border: 1px solid var(--line); border-radius: 8px; padding: 7px 10px; }

/* ------------------------------------------------------------------ misc */
.empty { text-align: center; padding: 70px 20px; color: var(--muted); }
.empty h2 { color: var(--text); font-size: 18px; }
.empty p { max-width: 60ch; margin: 10px auto 22px; }
code { background: var(--bg-soft); padding: 1px 5px; border-radius: 4px; font-size: 12px; }

.toast {
  position: fixed; right: 20px; bottom: 20px; z-index: 60;
  background: var(--bg-soft); border: 1px solid var(--accent-dim);
  padding: 12px 16px; border-radius: var(--radius); max-width: 420px;
  box-shadow: 0 12px 32px rgba(0,0,0,.5);
}
.toast.error { border-color: var(--down); }

.loader {
  position: fixed; inset: 0; z-index: 70; display: flex;
  align-items: center; justify-content: center; gap: 12px; flex-direction: column;
  background: rgba(13,17,23,.75); color: var(--muted);
}
.spinner {
  width: 34px; height: 34px; border-radius: 50%;
  border: 3px solid var(--line); border-top-color: var(--accent);
  animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

@media (max-width: 720px) {
  .tabs { top: 105px; }
  .chart-box { height: 220px; }
}
