/* Kryvu System — tokens do brand book (Parametros visuais 2.0.0-draft.1) */
:root {
  --bg:#FBFAF7; --surface:#FFFFFF; --subtle:#F2F0E9; --hover:#ECECE6; --ink:#191B18; --muted:#646960;
  --line:#DEDFD8; --control-line:#858B7F; --accent:#A34427; --accent-soft:#F8EDE7; --action:#191B18; --action-ink:#FBFAF7;
  --positive:#49613B; --positive-soft:#EEF3E9; --warning:#865B14; --warning-soft:#FAF1DC; --danger:#A03426; --danger-soft:#FBEDE9;
  --focus:#A34427; --chart1:#A34427; --chart2:#4F6550; --chart3:#436E85; --chart4:#78537E; --chart5:#8A671C; --chart6:#526467;
  --r-control:6px; --r-card:8px; --r-dialog:12px;
  --sidebar:240px; --header:56px; --control-h:36px; --touch:44px;
  color-scheme: light;
}
/* Igual aos sistemas publicados (dash.kryvu.com): claro por padrão, escuro só pelo botão */
:root[data-theme="dark"] {
  --bg:#141612; --surface:#191B18; --subtle:#22251F; --hover:#2C3028; --ink:#F2F0E9; --muted:#ADB3A4; --line:#373C32;
  --control-line:#737D68; --accent:#E99572; --accent-soft:#35261F; --action:#F2F0E9; --action-ink:#191B18;
  --positive:#ACC799; --positive-soft:#263321; --warning:#E4C47F; --warning-soft:#332D1D; --danger:#F2A491; --danger-soft:#3B2420;
  --focus:#E99572; --chart1:#E99572; --chart2:#ADB59C; --chart3:#8DB8CF; --chart4:#C29ACB; --chart5:#D9BC77; --chart6:#A3BCBD;
  color-scheme: dark;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; height: 100%; }
body { background: var(--bg); color: var(--ink); font: 400 14px/22px Manrope, Arial, sans-serif; -webkit-font-smoothing: antialiased; }
a { color: inherit; }
button, input, select, textarea { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }
.muted { color: var(--muted); }
.meta { font-size: 12px; line-height: 18px; color: var(--muted); }
h1 { font-size: 24px; line-height: 32px; font-weight: 600; margin: 0; letter-spacing: -0.6px; }
.icon-btn { margin-left: auto; width: 36px; height: 36px; flex: none; display: inline-flex; align-items: center; justify-content: center; border: 1px solid var(--line); border-radius: var(--r-control); background: var(--surface); color: var(--ink); cursor: pointer; }
.icon-btn:hover { background: var(--hover); }
h2 { font-size: 16px; line-height: 24px; font-weight: 600; margin: 0; }
h3 { font-size: 14px; line-height: 20px; font-weight: 600; margin: 0; }

/* layout */
.shell { display: grid; grid-template-columns: var(--sidebar) 1fr; min-height: 100vh; }
.sidebar { border-right: 1px solid var(--line); background: var(--surface); display: flex; flex-direction: column; padding: 16px 12px; position: sticky; top: 0; height: 100vh; }
.brand { display: flex; align-items: center; gap: 10px; text-decoration: none; padding: 4px 8px 20px; }
.lockup { height: 22px; width: auto; color: var(--ink); }
.product { font-weight: 600; color: var(--muted); border-left: 1px solid var(--line); padding-left: 10px; }
.nav { display: flex; flex-direction: column; gap: 2px; }
.nav a { text-decoration: none; padding: 8px 10px; border-radius: var(--r-control); font-weight: 500; color: var(--muted); min-height: var(--control-h); display: flex; align-items: center; }
.nav a:hover { background: var(--hover); color: var(--ink); }
.nav a[aria-current="page"] { background: var(--subtle); color: var(--ink); }
.sidebar-foot { margin-top: auto; display: flex; flex-direction: column; gap: 4px; }
.main { min-width: 0; display: flex; flex-direction: column; }
.topbar { height: var(--header); border-bottom: 1px solid var(--line); display: flex; align-items: center; gap: 12px; padding: 0 32px; background: var(--bg); position: sticky; top: 0; z-index: 5; }
.crumbs { color: var(--muted); font-weight: 500; display: flex; gap: 8px; align-items: center; min-width: 0; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.crumbs a { text-decoration: none; }
.crumbs a:hover { color: var(--ink); }
.crumbs .cur { color: var(--ink); overflow: hidden; text-overflow: ellipsis; }
.topbar .menu-btn { display: none; }
.content { padding: 32px; max-width: 1440px; width: 100%; outline: none; }
.page-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; margin-bottom: 24px; flex-wrap: wrap; }
.page-head p { margin: 4px 0 0; }
.stack { display: flex; flex-direction: column; gap: 24px; }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }

/* controles */
.primary, .secondary, .ghost, .danger { border-radius: var(--r-control); min-height: var(--control-h); padding: 0 14px; font-weight: 500; cursor: pointer; display: inline-flex; align-items: center; gap: 8px; justify-content: center; border: 1px solid transparent; text-decoration: none; white-space: nowrap; }
.primary { background: var(--action); color: var(--action-ink); }
.primary:hover { opacity: .88; }
.primary:disabled { opacity: .45; cursor: not-allowed; }
.secondary { background: var(--surface); border-color: var(--line); }
.secondary:hover { background: var(--hover); }
.ghost { background: transparent; color: var(--muted); justify-content: flex-start; }
.ghost:hover { background: var(--hover); color: var(--ink); }
.danger { background: var(--danger-soft); color: var(--danger); }
.field { display: flex; flex-direction: column; gap: 6px; }
.field > span { font-weight: 500; font-size: 13px; }
.field small { color: var(--muted); font-size: 12px; line-height: 18px; }
input[type=text], input[type=number], input[type=password], input[type=url], select, textarea {
  min-height: var(--control-h); border: 1px solid var(--control-line); border-radius: var(--r-control); background: var(--surface); padding: 6px 10px; width: 100%;
}
textarea { min-height: 72px; resize: vertical; }
input[type=color] { width: 44px; height: var(--control-h); border: 1px solid var(--control-line); border-radius: var(--r-control); padding: 2px; background: var(--surface); }
.switch { display: inline-flex; align-items: center; gap: 10px; cursor: pointer; font-weight: 500; }
.switch input { width: 36px; height: 20px; appearance: none; border-radius: 999px; background: var(--control-line); position: relative; cursor: pointer; margin: 0; }
.switch input::after { content: ""; position: absolute; top: 2px; left: 2px; width: 16px; height: 16px; border-radius: 50%; background: var(--surface); }
.switch input:checked { background: var(--accent); }
.switch input:checked::after { left: 18px; }
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: var(--r-control); overflow: hidden; background: var(--surface); }
.seg button { border: 0; background: transparent; padding: 0 12px; min-height: 32px; cursor: pointer; font-weight: 500; color: var(--muted); }
.seg button[aria-pressed="true"] { background: var(--subtle); color: var(--ink); }
.seg button + button { border-left: 1px solid var(--line); }
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); overflow-x: auto; }
.tabs a { text-decoration: none; padding: 10px 12px; font-weight: 500; color: var(--muted); border-bottom: 2px solid transparent; margin-bottom: -1px; white-space: nowrap; }
.tabs a:hover { color: var(--ink); }
.tabs a[aria-current="page"] { color: var(--ink); border-bottom-color: var(--accent); }

/* cards, métricas, tabelas */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-card); padding: 20px; }
.card-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin-bottom: 16px; flex-wrap: wrap; }
.metrics { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 12px; }
.metric { background: var(--surface); padding: 16px; border: 1px solid var(--line); border-radius: var(--r-card); }
.metric .label { color: var(--muted); font-weight: 500; }
.metric .value { font-size: 28px; line-height: 36px; font-weight: 500; margin-top: 4px; font-variant-numeric: tabular-nums; }
.metric .sub { font-size: 12px; line-height: 18px; color: var(--muted); }
.table-wrap { overflow-x: auto; border: 1px solid var(--line); border-radius: var(--r-card); }
table { width: 100%; border-collapse: collapse; background: var(--surface); }
th, td { text-align: left; padding: 0 16px; height: 56px; border-bottom: 1px solid var(--line); white-space: nowrap; }
th { height: 40px; font-weight: 500; color: var(--muted); background: var(--subtle); font-size: 12px; }
tr:last-child td { border-bottom: 0; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
tbody tr.link { cursor: pointer; }
tbody tr.link:hover td { background: var(--hover); }
.badge { display: inline-flex; align-items: center; gap: 6px; border-radius: 999px; padding: 0 8px; font-size: 12px; line-height: 20px; font-weight: 600; background: var(--subtle); color: var(--muted); }
.badge.pos { background: var(--positive-soft); color: var(--positive); }
.badge.warn { background: var(--warning-soft); color: var(--warning); }
.badge.acc { background: var(--accent-soft); color: var(--accent); }
.empty { padding: 48px 16px; text-align: center; color: var(--muted); }
.notice { border-radius: var(--r-card); padding: 12px 16px; background: var(--warning-soft); color: var(--warning); font-weight: 500; }
.notice.info { background: var(--subtle); color: var(--muted); }
.notice.err { background: var(--danger-soft); color: var(--danger); }
.error { color: var(--danger); margin: 0; }
.grid2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; }
.grid3 { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 16px; }
.form-section { display: flex; flex-direction: column; gap: 16px; }
.form-section + .form-section { border-top: 1px solid var(--line); padding-top: 20px; margin-top: 4px; }
.sticky-actions { position: sticky; bottom: 0; background: var(--bg); padding: 12px 0; display: flex; gap: 8px; justify-content: flex-end; border-top: 1px solid var(--line); }
code, .code { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 13px; }
.code { display: block; background: var(--subtle); border: 1px solid var(--line); border-radius: var(--r-control); padding: 12px; white-space: pre-wrap; word-break: break-all; }
.thumb.lg { width: 56px; height: 56px; margin: 0; flex: none; }
.thumb { flex: none; margin: 0; }
.thumb { width: 40px; height: 40px; border-radius: var(--r-control); object-fit: cover; background: var(--subtle); vertical-align: middle; margin-right: 10px; }

/* editor: menu de seções | formulário | prévia */
.editor { display: grid; grid-template-columns: 220px minmax(0, 1fr) 332px; gap: 24px; align-items: start; }
.with-preview { display: grid; grid-template-columns: minmax(0, 1fr) 332px; gap: 24px; align-items: start; }
.secnav { display: flex; flex-direction: column; gap: 2px; position: sticky; top: calc(var(--header) + 16px); }
.secnav button { display: flex; align-items: center; justify-content: space-between; gap: 8px; min-height: 40px; padding: 0 10px; border: 0; border-radius: var(--r-control); background: transparent; color: var(--muted); font-weight: 500; cursor: pointer; text-align: left; white-space: nowrap; }
.secnav button:hover { background: var(--hover); color: var(--ink); }
.secnav button[aria-current] { background: var(--subtle); color: var(--ink); }
.preview { position: sticky; top: calc(var(--header) + 16px); padding: 16px; }
.preview-frame { width: 100%; margin: 0 auto; background: #000; border-radius: var(--r-control); overflow: hidden; }
.preview-frame iframe { display: block; width: 100%; height: 100%; border: 0; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip { position: relative; cursor: pointer; }
.chip input { position: absolute; opacity: 0; inset: 0; width: 100%; height: 100%; margin: 0; cursor: pointer; }
.chip span { display: inline-flex; align-items: center; justify-content: center; min-width: 64px; min-height: var(--control-h); padding: 0 14px; border: 1px solid var(--control-line); border-radius: var(--r-control); background: var(--surface); font-weight: 500; font-variant-numeric: tabular-nums; }
.chip:hover span { background: var(--hover); }
.chip input:checked + span { background: var(--accent-soft); border-color: var(--accent); color: var(--accent); }
.chip input:focus-visible + span { outline: 2px solid var(--focus); outline-offset: 2px; }
@media (max-width: 1280px) {
  .editor { grid-template-columns: 200px minmax(0, 1fr); }
  .editor .preview { grid-column: 1 / -1; grid-row: 1; position: static; }
  .with-preview { grid-template-columns: 1fr; }
  .with-preview .preview { grid-row: 1; position: static; }
}
@media (max-width: 768px) {
  .editor { grid-template-columns: 1fr; }
  .secnav { position: static; flex-direction: row; overflow-x: auto; padding-bottom: 4px; }
  .secnav .badge { display: none; }
}

/* Retenção por cima do vídeo. Segue o catálogo Kryvu: traço 2 px, área leve sem gradiente,
   grade discreta, eixos 12 px tabulares, sombra só na camada flutuante. */
.review-stage { position: relative; width: 100%; aspect-ratio: 16 / 9; min-height: 420px; max-height: 560px; background: #141612; border-radius: var(--r-card); overflow: hidden; }
.review-stage > video { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: contain; cursor: pointer; }
.review-panel { position: absolute; left: 16px; right: 16px; bottom: 16px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-card); box-shadow: 0 8px 24px rgba(20, 22, 18, .28); padding: 12px 16px 10px; }
.review-head { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; margin-bottom: 12px; }
.review-head .icon-btn { margin: 0; }
.review-head .legend { margin-left: auto; }
.review-read { display: flex; align-items: baseline; gap: 8px; min-width: 0; }
.review-pct { font-size: 20px; line-height: 28px; font-weight: 500; font-variant-numeric: tabular-nums; min-width: 64px; }
.review-show { position: absolute; left: 16px; bottom: 16px; }
.legend i.lg-line { width: 14px; height: 2px; border-radius: 0; background: var(--accent); vertical-align: 3px; }
.legend i.lg-pitch { width: 14px; height: 0; border-radius: 0; background: none; border-top: 2px dashed var(--chart3); vertical-align: 3px; }
.legend i.lg-click { width: 5px; height: 10px; border-radius: 1px; background: var(--chart2); }
.review-panel .chart { height: 150px; }
.rc { display: grid; grid-template-columns: 40px minmax(0, 1fr); grid-template-rows: minmax(0, 1fr) 22px; height: 100%; color: var(--muted); font-size: 12px; line-height: 18px; font-variant-numeric: tabular-nums; }
.rc-y { position: relative; }
.rc-y span { position: absolute; right: 8px; transform: translateY(-50%); }
.rc-plot { position: relative; cursor: pointer; touch-action: none; }
.rc .rc-plot > svg { position: absolute; inset: 0; width: 100%; height: 100%; display: block; overflow: visible; }
.rc-grid { stroke: var(--line); stroke-width: 1; opacity: .65; }
.rc-area { fill: var(--accent); opacity: .1; }
.rc-line { fill: none; stroke: var(--accent); stroke-width: 2; stroke-linejoin: round; }
.rc-click { fill: var(--chart2); opacity: .7; }
.rc-pitchline { stroke: var(--chart3); stroke-width: 1.5; stroke-dasharray: 4 4; }
.rc-pitch { position: absolute; top: 2px; margin-left: 6px; color: var(--chart3); font-weight: 600; white-space: nowrap; pointer-events: none; background: var(--surface); padding: 0 4px; border-radius: 4px; }
.rc-x { grid-column: 2; position: relative; }
.rc-x span { position: absolute; top: 4px; transform: translateX(-50%); }
.rc-x span.first { transform: none; }
.rc-x span.last { transform: translateX(-100%); }
.rc-dot { position: absolute; width: 12px; height: 12px; border-radius: 50%; background: var(--accent); border: 2px solid var(--surface); box-shadow: 0 0 0 1px var(--accent); transform: translate(-50%, -50%); pointer-events: none; }
.rc-hover { position: absolute; top: 0; bottom: 0; width: 1px; background: var(--control-line); pointer-events: none; }
.rc-plot .tip { top: 0; transform: translate(-50%, calc(-100% - 6px)); padding: 8px 12px; border-radius: 6px; z-index: 3; }
@media (max-width: 768px) {
  .review-stage { min-height: 460px; aspect-ratio: auto; }
  .review-panel { left: 8px; right: 8px; bottom: 8px; padding: 10px 12px 8px; }
  .review-head .legend { display: none; }
  .review-panel .chart { height: 120px; }
}

/* gráfico */
.chart { position: relative; width: 100%; }
.chart svg { display: block; width: 100%; height: 260px; overflow: visible; }
.chart .grid line { stroke: var(--line); stroke-width: 1; opacity: .65; }
.chart .axis text { fill: var(--muted); font-size: 12px; }
.chart .line { fill: none; stroke: var(--chart1); stroke-width: 2; }
.chart .area { fill: var(--chart1); opacity: .08; }
.chart .pitch line { stroke: var(--chart3); stroke-width: 1.5; stroke-dasharray: 4 4; }
.chart .pitch text { fill: var(--chart3); font-size: 12px; font-weight: 600; }
.chart .clicks rect { fill: var(--chart2); opacity: .55; }
.chart .cursor line { stroke: var(--control-line); stroke-width: 1; }
.chart .cursor circle { fill: var(--chart1); stroke: var(--surface); stroke-width: 2; }
.tip { position: absolute; pointer-events: none; background: var(--action); color: var(--action-ink); border-radius: 6px; padding: 8px 12px; font-size: 12px; line-height: 18px; white-space: nowrap; transform: translate(-50%, -110%); }
.legend { display: flex; gap: 16px; flex-wrap: wrap; font-size: 12px; color: var(--muted); }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 2px; margin-right: 6px; vertical-align: -1px; }

/* upload */
.drop { border: 1.5px dashed var(--control-line); border-radius: var(--r-card); padding: 40px 16px; text-align: center; cursor: pointer; background: var(--surface); }
.drop:hover, .drop.over { background: var(--accent-soft); border-color: var(--accent); }
.progress { height: 8px; background: var(--subtle); border-radius: 999px; overflow: hidden; }
.progress > div { height: 100%; width: 0; background: var(--accent); transition: width .2s; }
.steps { display: flex; flex-direction: column; gap: 8px; margin: 0; padding: 0; list-style: none; }
.steps li { display: flex; gap: 10px; align-items: center; }
.steps li::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: var(--line); flex: none; }
.steps li.doing::before { background: var(--accent); }
.steps li.done::before { background: var(--positive); }

/* dialog / toast */
.dialog { border: 1px solid var(--line); border-radius: var(--r-dialog); background: var(--surface); color: var(--ink); width: min(480px, calc(100% - 32px)); padding: 24px; }
.dialog::backdrop { background: rgba(20, 22, 18, .55); }
.dialog form { display: flex; flex-direction: column; gap: 16px; }
.dialog h2 { font-size: 16px; }
.dialog p { margin: 0; }
.actions { display: flex; gap: 8px; justify-content: flex-end; }
.toast { position: fixed; bottom: 24px; right: 24px; background: var(--action); color: var(--action-ink); padding: 10px 16px; border-radius: var(--r-control); font-weight: 500; z-index: 50; max-width: calc(100% - 48px); }

/* responsivo */
@media (max-width: 1100px) { .grid3 { grid-template-columns: repeat(2, minmax(0, 1fr)); } .content { padding: 24px; } .topbar { padding: 0 24px; } }
@media (max-width: 768px) {
  .shell { grid-template-columns: 1fr; }
  .sidebar { position: fixed; inset: 0 auto 0 0; width: 260px; z-index: 20; transform: translateX(-100%); transition: transform .18s; box-shadow: 0 0 0 100vmax transparent; }
  .sidebar.open { transform: none; box-shadow: 0 0 0 100vmax rgba(20,22,18,.45); }
  .topbar .menu-btn { display: inline-flex; justify-content: center; width: var(--touch); min-height: var(--touch); }
  .content { padding: 16px; }
  .topbar { padding: 0 8px; }
  .grid2, .grid3 { grid-template-columns: 1fr; }
  .chart svg { height: 200px; }
  input[type=text], input[type=number], input[type=password], input[type=url], select, textarea { font-size: 16px; }
  .primary, .secondary { min-height: var(--touch); }
  .metrics { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
  .metric { padding: 12px; }
  .metric .value { font-size: 22px; line-height: 30px; }
}
@media (prefers-reduced-motion: reduce) { * { transition: none !important; animation: none !important; } }
