:root {
  --bg: #f6f7f9;
  --surface: #ffffff;
  --surface-2: #f1f3f6;
  --border: #e3e6eb;
  --text: #14171c;
  --text-2: #5b6370;
  --muted: #8a919c;
  --accent: #2563eb;
  --accent-soft: #e8efff;
  --danger: #dc2626;
  --good: #15803d;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .05);
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1115;
    --surface: #171a20;
    --surface-2: #1e222a;
    --border: #2a2f39;
    --text: #eceff4;
    --text-2: #a7aebb;
    --muted: #7d8492;
    --accent: #5b8cff;
    --accent-soft: #1d2842;
    --danger: #f87171;
    --good: #4ade80;
    --shadow: none;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 14px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
}
a { color: var(--accent); text-decoration: none; }
h1, h2, h3 { margin: 0; line-height: 1.25; }
h1 { font-size: 22px; font-weight: 700; }
h2 { font-size: 16px; font-weight: 650; }
h3 { font-size: 14px; font-weight: 650; }
code, pre { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 12.5px; }

/* ---------- layout ---------- */
.shell { display: grid; grid-template-columns: 220px 1fr; min-height: 100vh; }
.side {
  background: var(--surface);
  border-right: 1px solid var(--border);
  padding: 20px 12px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  position: sticky;
  top: 0;
  height: 100vh;
}
.brand { display: flex; align-items: center; gap: 10px; white-space: nowrap; font-weight: 750; font-size: 16px; padding: 0 10px 18px; }
.brand-mark { width: 28px; height: 28px; border-radius: 8px; background: var(--accent); display: grid; place-items: center; color: #fff; }
.brand-mark svg { width: 14px; height: 14px; margin-left: 2px; }
.nav a { display: flex; align-items: center; gap: 10px; white-space: nowrap; padding: 8px 10px; border-radius: 8px; color: var(--text-2); font-weight: 550; }
.nav a:hover { background: var(--surface-2); color: var(--text); }
.nav a.active { background: var(--accent-soft); color: var(--accent); }
.nav svg { width: 18px; height: 18px; }
.side-foot { margin-top: auto; padding: 10px; font-size: 12px; color: var(--muted); display: flex; flex-direction: column; gap: 6px; word-break: break-all; }
.side-foot button { align-self: flex-start; }

main { padding: 28px 32px 60px; max-width: 1240px; width: 100%; }
.page-head { display: flex; align-items: center; justify-content: space-between; gap: 16px; margin-bottom: 22px; flex-wrap: wrap; }
.page-head .sub { color: var(--text-2); margin-top: 4px; }
.back { display: inline-flex; align-items: center; gap: 4px; color: var(--text-2); font-size: 13px; margin-bottom: 8px; }

@media (max-width: 860px) {
  .shell { grid-template-columns: 1fr; }
  .side { position: static; height: auto; flex-direction: row; align-items: center; padding: 10px 16px; overflow-x: auto; }
  .brand { padding: 0 12px 0 0; }
  .nav { display: flex; gap: 4px; }
  .side-foot { display: none; }
  main { padding: 20px 16px 48px; }
}

/* ---------- componentes ---------- */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); }
.card-pad { padding: 20px; }
.card-head { display: flex; align-items: center; justify-content: space-between; padding: 16px 20px; border-bottom: 1px solid var(--border); gap: 12px; }
.stack { display: flex; flex-direction: column; gap: 16px; }
.row { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.muted { color: var(--muted); }
.text-2 { color: var(--text-2); }
.small { font-size: 12.5px; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  height: 36px; padding: 0 14px; border-radius: 8px; border: 1px solid var(--border);
  background: var(--surface); color: var(--text); font: inherit; font-weight: 600; cursor: pointer;
  white-space: nowrap;
}
.btn:hover { background: var(--surface-2); }
.btn:disabled { opacity: .55; cursor: default; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { filter: brightness(1.07); }
.btn.danger { color: var(--danger); }
.btn.sm { height: 30px; padding: 0 10px; font-size: 13px; }
.btn svg { width: 16px; height: 16px; }

label.field { display: flex; flex-direction: column; gap: 6px; font-weight: 600; font-size: 13px; }
label.field .hint { font-weight: 400; color: var(--muted); font-size: 12px; }
input[type=text], input[type=email], input[type=password], input[type=url], input[type=number], select, textarea {
  height: 38px; padding: 0 12px; border-radius: 8px; border: 1px solid var(--border);
  background: var(--surface); color: var(--text); font: inherit; width: 100%;
}
textarea { height: auto; padding: 10px 12px; resize: vertical; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: -1px; border-color: transparent; }
input[type=color] { width: 44px; height: 38px; padding: 3px; border: 1px solid var(--border); border-radius: 8px; background: var(--surface); cursor: pointer; }
.color-field { display: flex; gap: 8px; }
.color-field input[type=text] { font-family: ui-monospace, monospace; }

.switch { display: flex; align-items: flex-start; gap: 12px; cursor: pointer; padding: 4px 0; }
.switch input { appearance: none; flex: none; width: 36px; height: 20px; border-radius: 999px; background: var(--border); position: relative; cursor: pointer; margin: 1px 0 0; transition: background .15s; }
.switch input::after { content: ""; position: absolute; top: 2px; left: 2px; width: 16px; height: 16px; border-radius: 50%; background: #fff; transition: transform .15s; box-shadow: 0 1px 2px rgba(0,0,0,.2); }
.switch input:checked { background: var(--accent); }
.switch input:checked::after { transform: translateX(16px); }
.switch b { display: block; font-weight: 600; font-size: 13.5px; }
.switch span { display: block; color: var(--muted); font-size: 12.5px; }

.tabs { display: flex; gap: 2px; border-bottom: 1px solid var(--border); margin-bottom: 20px; overflow-x: auto; }
.tabs a { padding: 10px 14px; color: var(--text-2); font-weight: 600; border-bottom: 2px solid transparent; margin-bottom: -1px; white-space: nowrap; }
.tabs a.active { color: var(--accent); border-color: var(--accent); }

.segmented { display: inline-flex; background: var(--surface-2); border-radius: 8px; padding: 3px; gap: 2px; }
.segmented button { border: 0; background: transparent; color: var(--text-2); font: inherit; font-weight: 600; font-size: 13px; padding: 5px 10px; border-radius: 6px; cursor: pointer; }
.segmented button.active { background: var(--surface); color: var(--text); box-shadow: var(--shadow); }

.section { border-top: 1px solid var(--border); padding: 18px 20px; display: flex; flex-direction: column; gap: 14px; }
.section:first-child { border-top: 0; }
.section > h3 { display: flex; align-items: center; justify-content: space-between; }
.sub-fields { display: flex; flex-direction: column; gap: 14px; padding-left: 48px; }
.sub-fields[hidden] { display: none; }

/* ---------- KPIs ---------- */
.kpis { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 12px; margin-bottom: 16px; }
.kpi { padding: 16px 18px; }
.kpi .label { color: var(--text-2); font-size: 12.5px; font-weight: 600; }
.kpi .value { font-size: 26px; font-weight: 700; letter-spacing: -.5px; margin-top: 4px; font-variant-numeric: tabular-nums; }
.kpi .note { color: var(--muted); font-size: 12px; margin-top: 2px; }

/* ---------- tabela ---------- */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 11px 16px; border-bottom: 1px solid var(--border); white-space: nowrap; }
th { font-size: 12px; color: var(--text-2); font-weight: 600; background: var(--surface-2); }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
tbody tr:last-child td { border-bottom: 0; }
tbody tr.link { cursor: pointer; }
tbody tr.link:hover td { background: var(--surface-2); }

/* ---------- vídeos ---------- */
.video-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(250px, 1fr)); gap: 16px; }
.video-card { overflow: hidden; display: flex; flex-direction: column; color: inherit; transition: border-color .15s; }
.video-card:hover { border-color: var(--accent); }
.thumb { aspect-ratio: 16 / 9; background: #0b0d10 center / cover no-repeat; display: grid; place-items: center; color: rgba(255,255,255,.6); }
.thumb svg { width: 36px; height: 36px; }
.video-card .meta { padding: 12px 14px; display: flex; flex-direction: column; gap: 2px; }
.video-card .meta b { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.empty { text-align: center; padding: 56px 20px; color: var(--text-2); display: flex; flex-direction: column; align-items: center; gap: 12px; }
.empty svg { width: 40px; height: 40px; color: var(--muted); }

.editor { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 440px); gap: 20px; align-items: start; }
.preview-col { position: sticky; top: 20px; display: flex; flex-direction: column; gap: 12px; }
.preview-stage { padding: 16px; background: var(--surface-2); border-radius: var(--radius); }
.preview-stage.vertical { max-width: 300px; margin: 0 auto; }
.save-bar { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
@media (max-width: 1060px) {
  .editor { grid-template-columns: 1fr; }
  .preview-col { position: static; order: -1; }
}
@media (max-width: 640px) { .grid-2 { grid-template-columns: 1fr; } .sub-fields { padding-left: 0; } }

.code { position: relative; }
.code pre { margin: 0; background: #0f1319; color: #d5dbe5; padding: 16px; border-radius: 8px; overflow-x: auto; white-space: pre-wrap; word-break: break-all; }
.code .btn { position: absolute; top: 8px; right: 8px; }

.dropzone { border: 1.5px dashed var(--border); border-radius: var(--radius); padding: 28px; text-align: center; color: var(--text-2); cursor: pointer; transition: border-color .15s, background .15s; }
.dropzone.drag, .dropzone:hover { border-color: var(--accent); background: var(--accent-soft); }
.dropzone b { color: var(--text); }
.progress { height: 6px; background: var(--surface-2); border-radius: 999px; overflow: hidden; }
.progress div { height: 100%; background: var(--accent); width: 0; transition: width .2s; }

/* ---------- modal ---------- */
.modal-bg { position: fixed; inset: 0; background: rgba(10, 12, 16, .5); display: grid; place-items: center; padding: 16px; z-index: 50; }
.modal { width: 100%; max-width: 520px; max-height: calc(100vh - 32px); overflow: auto; }
.modal .card-head h2 { font-size: 17px; }
.modal-foot { display: flex; justify-content: flex-end; gap: 8px; padding: 14px 20px; border-top: 1px solid var(--border); }

/* ---------- auth ---------- */
.auth { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.auth .card { width: 100%; max-width: 380px; }
.auth .brand { padding: 0 0 8px; }
.error { color: var(--danger); font-size: 13px; }

/* ---------- gráficos ---------- */
.chart { position: relative; }
.chart svg { display: block; width: 100%; height: auto; overflow: visible; }
.chart .grid line { stroke: var(--border); stroke-width: 1; }
.chart .axis text { fill: var(--muted); font-size: 11px; font-variant-numeric: tabular-nums; }
.chart .series-line { fill: none; stroke: var(--accent); stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.chart .series-area { fill: var(--accent); opacity: .12; }
.chart .bar { fill: var(--accent); }
.chart .bar.dim { opacity: .35; }
.chart .marker-line { stroke: var(--text-2); stroke-width: 1; stroke-dasharray: 3 3; }
.chart .marker-label { fill: var(--text-2); font-size: 11px; font-weight: 600; }
.chart .cross { stroke: var(--text-2); stroke-width: 1; }
.chart .dot { fill: var(--accent); stroke: var(--surface); stroke-width: 2; }
.tooltip {
  position: absolute; pointer-events: none; background: var(--text); color: var(--bg); padding: 6px 9px; border-radius: 6px;
  font-size: 12px; white-space: nowrap; transform: translate(-50%, calc(-100% - 10px)); opacity: 0; transition: opacity .1s; z-index: 2;
}
.tooltip b { font-variant-numeric: tabular-nums; }

#toast {
  position: fixed; bottom: 20px; left: 50%; transform: translate(-50%, 20px); background: var(--text); color: var(--bg);
  padding: 10px 16px; border-radius: 8px; font-weight: 600; opacity: 0; pointer-events: none; transition: all .2s; z-index: 60;
}
#toast.on { opacity: 1; transform: translate(-50%, 0); }
#toast.err { background: var(--danger); color: #fff; }
