:root {
  --bg: #f4f4f1;
  --panel: #ffffff;
  --panel-2: #f0f0ec;
  --text: #16171a;
  --muted: #666a73;
  --line: #e1e1dc;
  --accent: #e10600;
  --accent-ink: #ffffff;
  --good: #1f8a4c;
  --bad: #c0392b;
  --warn: #b7791f;
  --p1: #d4a700;
  --p2: #9aa0a6;
  --p3: #b87333;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(0,0,0,.05), 0 2px 8px rgba(0,0,0,.04);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0e0f11;
    --panel: #17181b;
    --panel-2: #1f2024;
    --text: #ececea;
    --muted: #9a9ea6;
    --line: #2a2c31;
    --accent: #ff2a1f;
    --good: #3ecf7a;
    --bad: #ff6b5b;
    --warn: #f0a93b;
    --shadow: none;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
}
a { color: inherit; }
h1, h2, h3 { line-height: 1.2; margin: 0 0 .6rem; }
h1 { font-size: 1.5rem; letter-spacing: -.01em; }
h2 { font-size: 1.1rem; }
h3 { font-size: .95rem; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: .04em; }
.num, td.num, th.num { font-variant-numeric: tabular-nums; text-align: right; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.hidden { display: none !important; }

/* Topo */
.topbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; gap: 1rem;
  padding: .6rem 1.25rem;
  background: var(--panel); border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: .55rem; text-decoration: none; font-size: 1.05rem; white-space: nowrap; }
.brand b { color: var(--accent); }
.brand-mark {
  width: 22px; height: 22px; border-radius: 5px;
  background:
    conic-gradient(var(--text) 25%, transparent 0 50%, var(--text) 0 75%, transparent 0) 0 0 / 11px 11px,
    var(--accent);
}
nav { display: flex; align-items: center; gap: .15rem; flex-wrap: wrap; margin-left: auto; }
nav a {
  text-decoration: none; padding: .4rem .65rem; border-radius: 7px; color: var(--muted); font-weight: 500;
}
nav a:hover { color: var(--text); background: var(--panel-2); }
nav a.active { color: var(--text); background: var(--panel-2); box-shadow: inset 0 -2px 0 var(--accent); }
.nav-sep { width: 1px; height: 20px; background: var(--line); margin: 0 .4rem; }
.menu-btn { display: none; margin-left: auto; }
body:not(.is-admin) .admin-only { display: none !important; }

main { max-width: 1180px; margin: 0 auto; padding: 1.5rem 1.25rem 4rem; outline: none; }

/* Blocos */
.card {
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 1.1rem 1.2rem; box-shadow: var(--shadow); margin-bottom: 1rem;
}
.grid { display: grid; gap: 1rem; }
.grid-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.row { display: flex; gap: .6rem; align-items: center; flex-wrap: wrap; }
.row.spread { justify-content: space-between; }
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 1rem; margin-bottom: 1rem; flex-wrap: wrap; }
.page-head p { margin: .2rem 0 0; color: var(--muted); }

/* Destaque ao vivo */
.hero {
  display: grid; grid-template-columns: 1.4fr 1fr; gap: 1rem; margin-bottom: 1rem;
}
.hero-main { position: relative; overflow: hidden; }
.hero-main::after {
  content: ""; position: absolute; right: -40px; top: -40px; width: 180px; height: 180px; opacity: .07;
  background: conic-gradient(var(--text) 25%, transparent 0 50%, var(--text) 0 75%, transparent 0) 0 0 / 30px 30px;
  transform: rotate(12deg);
}
.track-name { font-size: 1.7rem; font-weight: 700; letter-spacing: -.02em; margin: .15rem 0 .25rem; }
.stat-row { display: flex; gap: 1.5rem; flex-wrap: wrap; margin-top: .8rem; }
.stat .v { font-size: 1.25rem; font-weight: 650; font-variant-numeric: tabular-nums; }
.stat .k { font-size: .78rem; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }

.pill {
  display: inline-flex; align-items: center; gap: .35rem;
  padding: .15rem .55rem; border-radius: 99px; font-size: .78rem; font-weight: 600;
  background: var(--panel-2); color: var(--muted); border: 1px solid var(--line);
}
.pill.on { color: var(--good); }
.pill.on::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: var(--good); }
.pill.off::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: var(--muted); }
.pill.accent { background: var(--accent); color: var(--accent-ink); border-color: transparent; }
.pill.bad { color: var(--bad); }

/* Tabelas */
.table-wrap { overflow-x: auto; margin: 0 -1.2rem; padding: 0 1.2rem; }
table { width: 100%; border-collapse: collapse; }
th, td { padding: .5rem .6rem; border-bottom: 1px solid var(--line); text-align: left; white-space: nowrap; }
th { font-size: .75rem; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; font-weight: 600; }
tbody tr:last-child td { border-bottom: 0; }
tbody tr.link { cursor: pointer; }
tbody tr.link:hover { background: var(--panel-2); }
td.wrap { white-space: normal; }
.pos { display: inline-grid; place-items: center; min-width: 1.8rem; height: 1.8rem; border-radius: 6px; font-weight: 700; background: var(--panel-2); font-variant-numeric: tabular-nums; }
.pos.p1 { background: var(--p1); color: #16171a; }
.pos.p2 { background: var(--p2); color: #16171a; }
.pos.p3 { background: var(--p3); color: #fff; }
.best { color: #9b59b6; font-weight: 650; }
@media (prefers-color-scheme: dark) { .best { color: #c89bff; } }

/* Formularios */
label.f { display: flex; flex-direction: column; gap: .3rem; font-size: .85rem; color: var(--muted); font-weight: 500; }
label.f > span { display: flex; justify-content: space-between; gap: .5rem; }
input, select, textarea, button {
  font: inherit; color: var(--text);
}
input[type=text], input[type=number], input[type=password], select, textarea {
  width: 100%; padding: .5rem .6rem; border-radius: 8px; border: 1px solid var(--line); background: var(--panel-2);
}
input:focus, select:focus, textarea:focus, button:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
label.check { display: flex; gap: .5rem; align-items: center; font-size: .9rem; cursor: pointer; }
label.check input { width: 1.05rem; height: 1.05rem; accent-color: var(--accent); }
fieldset { border: 1px solid var(--line); border-radius: var(--radius); padding: 1rem; margin: 0 0 1rem; }
legend { padding: 0 .4rem; font-weight: 650; }

button {
  cursor: pointer; border-radius: 8px; padding: .5rem .9rem; font-weight: 600;
  border: 1px solid var(--line); background: var(--panel-2);
}
button:hover { filter: brightness(.97); }
button.primary { background: var(--accent); color: var(--accent-ink); border-color: transparent; }
button.danger { color: var(--bad); }
button.ghost { background: transparent; }
button.sm { padding: .25rem .55rem; font-size: .82rem; }
button:disabled { opacity: .5; cursor: default; }

.list { list-style: none; margin: 0; padding: 0; }
.list li { display: flex; align-items: center; gap: .6rem; padding: .5rem 0; border-bottom: 1px solid var(--line); }
.list li:last-child { border-bottom: 0; }
.list li .grow { flex: 1; min-width: 0; }

.empty { text-align: center; color: var(--muted); padding: 2.5rem 1rem; }
.empty b { display: block; color: var(--text); margin-bottom: .3rem; font-size: 1.05rem; }

.tabs { display: flex; gap: .3rem; border-bottom: 1px solid var(--line); margin-bottom: 1rem; flex-wrap: wrap; }
.tabs button { background: none; border: 0; border-radius: 0; padding: .5rem .8rem; color: var(--muted); }
.tabs button.active { color: var(--text); box-shadow: inset 0 -2px 0 var(--accent); }

#toast {
  position: fixed; left: 50%; bottom: 1.2rem; transform: translateX(-50%) translateY(150%);
  background: var(--text); color: var(--bg); padding: .6rem 1rem; border-radius: 8px; font-weight: 600;
  transition: transform .2s; z-index: 50; max-width: calc(100% - 32px);
}
#toast.show { transform: translateX(-50%) translateY(0); }
#toast.err { background: var(--bad); color: #fff; }

dialog { border: 1px solid var(--line); border-radius: 12px; padding: 0; background: var(--panel); color: var(--text); width: min(420px, calc(100% - 32px)); }
dialog::backdrop { background: rgba(0,0,0,.45); }
dialog form { padding: 1.2rem; display: grid; gap: .8rem; }

.log-line { font: .82rem/1.4 ui-monospace, SFMono-Regular, Consolas, monospace; padding: .25rem 0; border-bottom: 1px solid var(--line); white-space: pre-wrap; word-break: break-word; }

@media (max-width: 860px) {
  .hero, .grid-2, .grid-3 { grid-template-columns: 1fr; }
  .grid-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .menu-btn { display: block; }
  nav { display: none; position: absolute; top: 100%; left: 0; right: 0; flex-direction: column; align-items: stretch;
    background: var(--panel); border-bottom: 1px solid var(--line); padding: .5rem 1rem 1rem; }
  nav.open { display: flex; }
  .nav-sep { width: auto; height: 1px; margin: .3rem 0; }
  main { padding: 1rem 16px 3rem; }
  .card { padding: 1rem; }
  .table-wrap { margin: 0 -1rem; padding: 0 1rem; }
}

/* Formulario completo / pagina Servidor */
.row.nowrap { flex-wrap: nowrap; }
.row.nowrap > input { min-width: 0; }
.add-row { margin-top: .6rem; }
.add-row select, .add-row input { flex: 1 1 180px; width: auto; }
input.sm-input { width: 6.5rem; padding: .3rem .45rem; }
textarea { resize: vertical; }
details.card-details { border: 1px solid var(--line); border-radius: var(--radius); padding: .8rem 1rem; margin-bottom: 1rem; }
details.card-details summary { cursor: pointer; font-weight: 650; }
details.card-details input[type=number] { width: 8rem; }
code { font: .82rem ui-monospace, SFMono-Regular, Consolas, monospace; }
fieldset .grid + .grid, fieldset .grid + label.check, fieldset .tabs + div { margin-top: .8rem; }
fieldset .grid-3 label.check { padding: .15rem 0; }
.sticky-actions { position: sticky; bottom: .8rem; z-index: 5; }
.server-name { margin-top: .4rem; }

/* Links com cara de botao + biblioteca de setups */
a.btn {
  display: inline-flex; align-items: center; justify-content: center; text-decoration: none;
  border-radius: 8px; padding: .5rem .9rem; font-weight: 600; border: 1px solid var(--line); background: var(--panel-2); color: var(--text);
}
a.btn:hover { filter: brightness(.97); }
a.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: transparent; }
.setup-card { display: flex; flex-direction: column; gap: .35rem; margin-bottom: 0; }
.setup-card h2 { margin: 0; }
.setup-card .row:last-child { margin-top: .4rem; }
.setup-notes { margin: .2rem 0; white-space: pre-wrap; }
details.help summary { cursor: pointer; font-weight: 650; }
details.help ol { margin: .6rem 0 .4rem; padding-left: 1.2rem; }
details.help li { margin: .3rem 0; }
details.help code, .setup-card code { word-break: break-all; }
.card.row select { flex: 1 1 220px; width: auto; }

/* Marca DV Racing: topo sempre escuro, logo branca/vermelha */
.topbar {
  --text: #f2f2f2; --muted: #a3a6ad; --panel: #0b0b0c; --panel-2: #1b1c20; --line: #26272c;
  background: #0b0b0c; color: var(--text); border-bottom-color: #26272c;
}
.brand img { display: block; height: 40px; width: auto; }
.brand-tag {
  font-size: .72rem; font-weight: 800; letter-spacing: .12em; color: #fff;
  border: 1px solid #3a3b40; border-radius: 5px; padding: .1rem .4rem;
}
nav a.active { box-shadow: inset 0 -2px 0 var(--accent); }
@media (max-width: 860px) { .brand img { height: 32px; } }

/* Analise de corrida — paleta categorica validada (dataviz), 8 slots em ordem fixa */
:root {
  --s1: #2a78d6; --s2: #eb6834; --s3: #1baf7a; --s4: #eda100;
  --s5: #e87ba4; --s6: #008300; --s7: #4a3aa7; --s8: #e34948;
  --s-other: #c9c9c4; --grid: #ebebe6; --axis: #8a8d94;
}
@media (prefers-color-scheme: dark) {
  :root {
    --s1: #3987e5; --s2: #d95926; --s3: #199e70; --s4: #c98500;
    --s5: #d55181; --s6: #008300; --s7: #9085e9; --s8: #e66767;
    --s-other: #3a3b40; --grid: #25262a; --axis: #7d8088;
  }
}
.tiles { margin-bottom: 1rem; }
.tile { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: .8rem 1rem; }
.tile .k { font-size: .75rem; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; font-weight: 600; }
.tile .v { font-size: 1.25rem; font-weight: 700; font-variant-numeric: tabular-nums; margin-top: .15rem; }
.tile .v.small-v { font-size: 1rem; }
.card .tiles .tile { background: var(--panel-2); border-color: transparent; }
.delta.up { color: var(--good); }
.delta.down { color: var(--bad); }
.pb { color: var(--good); font-weight: 650; }
tr.invalid td { opacity: .55; }
tr.selected td { background: var(--panel-2); }
.bad-text { color: var(--bad); font-weight: 600; }
.mono { font: .85rem ui-monospace, SFMono-Regular, Consolas, monospace; min-width: 3.2rem; }
.incidents li { gap: .8rem; }

.chart { position: relative; }
.chart-svg { width: 100%; height: auto; display: block; }
.chart-svg .grid-line { stroke: var(--grid); stroke-width: 1; }
.chart-svg .axis-label { fill: var(--axis); font-size: 11px; font-variant-numeric: tabular-nums; }
.chart-svg .series-line { fill: none; stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.chart-svg .series-line.other { stroke: var(--s-other); stroke-width: 1.5; }
.chart-svg .series-dot { stroke: var(--panel); stroke-width: 2; }
.chart-svg .crosshair { stroke: var(--axis); stroke-width: 1; stroke-dasharray: 3 3; }
.chart-tip {
  position: absolute; top: 8px; width: 180px; background: var(--panel); border: 1px solid var(--line); border-radius: 8px;
  padding: .45rem .6rem; box-shadow: 0 4px 16px rgba(0,0,0,.15); font-size: .82rem; pointer-events: none; z-index: 2;
}
.tip-row { display: flex; gap: .4rem; align-items: center; }
.tip-row .grow { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.swatch { width: 10px; height: 10px; border-radius: 3px; flex: none; display: inline-block; }
.s1.series-line { stroke: var(--s1); } .s1.series-dot, .swatch.s1 { fill: var(--s1); background: var(--s1); }
.s2.series-line { stroke: var(--s2); } .s2.series-dot, .swatch.s2 { fill: var(--s2); background: var(--s2); }
.s3.series-line { stroke: var(--s3); } .s3.series-dot, .swatch.s3 { fill: var(--s3); background: var(--s3); }
.s4.series-line { stroke: var(--s4); } .s4.series-dot, .swatch.s4 { fill: var(--s4); background: var(--s4); }
.s5.series-line { stroke: var(--s5); } .s5.series-dot, .swatch.s5 { fill: var(--s5); background: var(--s5); }
.s6.series-line { stroke: var(--s6); } .s6.series-dot, .swatch.s6 { fill: var(--s6); background: var(--s6); }
.s7.series-line { stroke: var(--s7); } .s7.series-dot, .swatch.s7 { fill: var(--s7); background: var(--s7); }
.s8.series-line { stroke: var(--s8); } .s8.series-dot, .swatch.s8 { fill: var(--s8); background: var(--s8); }

.chips { display: flex; flex-wrap: wrap; gap: .4rem; }
.chip { display: inline-flex; align-items: center; gap: .4rem; padding: .3rem .65rem; border-radius: 99px; font-size: .85rem; font-weight: 500; color: var(--muted); }
.chip.on { color: var(--text); border-color: var(--text); }
.filters { display: flex; flex-wrap: wrap; gap: .6rem; align-items: center; }
.filters > input[type=text], .filters > select { flex: 1 1 170px; width: auto; }
label.f.inline { flex-direction: row; align-items: center; gap: .4rem; }
label.f.inline input { width: auto; }

/* Menu suspenso de admin */
.admin-menu { position: relative; }
.nav-drop { background: transparent; border: 0; color: var(--muted); font-weight: 600; padding: .4rem .65rem; border-radius: 7px; }
.nav-drop:hover, .nav-drop[aria-expanded="true"] { color: var(--text); background: var(--panel-2); }
.nav-drop.active { color: var(--text); background: var(--panel-2); box-shadow: inset 0 -2px 0 var(--accent); }
.dropdown {
  position: absolute; right: 0; top: calc(100% + 6px); min-width: 230px; z-index: 30;
  background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: .4rem;
  box-shadow: 0 10px 30px rgba(0,0,0,.35); display: flex; flex-direction: column;
}
.dropdown[hidden] { display: none; }
.dropdown a { padding: .45rem .7rem; border-radius: 7px; }
.drop-label { font-size: .7rem; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); padding: .5rem .7rem .2rem; font-weight: 700; }
@media (max-width: 860px) {
  .admin-menu { width: 100%; }
  .nav-drop { width: 100%; text-align: left; }
  .dropdown { position: static; box-shadow: none; border: 0; padding: 0 0 0 .6rem; min-width: 0; }
}

/* Streamers */
.streamer-grid { align-items: start; }
.url-out { font: .85rem ui-monospace, SFMono-Regular, Consolas, monospace; }
.preview-box {
  overflow: auto; border-radius: 8px; padding: 12px; min-height: 120px;
  background: repeating-conic-gradient(#2a2b30 0 25%, #202125 0 50%) 0 0 / 20px 20px;
}
.preview-box iframe { border: 0; display: block; background: transparent; color-scheme: normal; }
a.btn.sm-btn { padding: .25rem .55rem; font-size: .82rem; }

/* DV Conector */
.chart-svg .bar.s1 { fill: var(--s1); }
.ad-card { margin-bottom: .8rem; }
.ad-grid { display: grid; grid-template-columns: 220px 1fr; gap: 1rem; margin-top: .6rem; }
.ad-img { background: var(--panel-2); border-radius: 8px; min-height: 120px; display: grid; place-items: center; overflow: hidden; }
.ad-img img { width: 100%; height: auto; display: block; }
@media (max-width: 860px) { .ad-grid { grid-template-columns: 1fr; } }

.mono-input { font-family: ui-monospace, SFMono-Regular, Consolas, monospace; letter-spacing: .03em; }

.ai-summary { margin: .7rem 0 .3rem; padding: .6rem .8rem; border-radius: 8px; background: var(--panel-2); }
input[type=range] { width: 100%; accent-color: var(--accent); }

.focus-card .chips { margin-top: .6rem; }
