:root {
  --bg: #f5f6f8;
  --surface: #ffffff;
  --surface-2: #f0f2f5;
  --text: #1b1f24;
  --muted: #5b6470;
  --border: #e2e5ea;
  --accent: #c2410c;
  --accent-hover: #9a3412;
  --accent-soft: #fff1e8;
  --ok: #1a7f37;
  --ok-soft: #e8f5ec;
  --info: #0b5cad;
  --info-soft: #e7f0fb;
  --warn: #8a5a00;
  --warn-soft: #fff6dc;
  --danger: #b42318;
  --danger-soft: #fdecea;
  --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 1px 3px rgba(16, 24, 40, .08);
  --radius: 12px;
  --focus: 0 0 0 3px rgba(194, 65, 12, .35);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1216; --surface: #171b21; --surface-2: #1e232b; --text: #e8eaed; --muted: #a2aab4; --border: #2b313a;
    --accent: #f97316; --accent-hover: #fb923c; --accent-soft: #2a1a10;
    --ok: #4ade80; --ok-soft: #12261a; --info: #60a5fa; --info-soft: #0f1d30; --warn: #fbbf24; --warn-soft: #2a2210;
    --danger: #f87171; --danger-soft: #2c1414; --shadow: none; --focus: 0 0 0 3px rgba(249, 115, 22, .45);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; }
body {
  font: 15px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  background: var(--bg); color: var(--text); -webkit-font-smoothing: antialiased;
}
a { color: var(--accent); }
:focus-visible { outline: none; box-shadow: var(--focus); border-radius: 6px; }
.skip { position: absolute; left: -999px; top: 8px; background: var(--surface); padding: 8px 12px; z-index: 10; }
.skip:focus { left: 8px; }

/* Estrutura */
.shell { display: grid; grid-template-columns: 232px 1fr; min-height: 100vh; }
.sidebar {
  background: var(--surface); border-right: 1px solid var(--border); padding: 20px 14px; position: sticky; top: 0;
  height: 100vh; display: flex; flex-direction: column; gap: 22px;
}
.brand { display: flex; align-items: center; gap: 10px; padding: 0 8px; }
.brand-mark { width: 34px; height: 34px; border-radius: 9px; background: var(--accent); color: #fff; display: grid; place-items: center; font-size: 14px; }
.brand-text { display: flex; flex-direction: column; line-height: 1.15; }
.brand-text small { color: var(--muted); }
nav { display: flex; flex-direction: column; gap: 2px; }
nav a {
  display: flex; align-items: center; gap: 10px; padding: 9px 12px; border-radius: 8px; color: var(--text);
  text-decoration: none; font-weight: 500;
}
nav a span { width: 18px; text-align: center; color: var(--muted); }
nav a:hover { background: var(--surface-2); }
nav a[aria-current="page"] { background: var(--accent-soft); color: var(--accent); }
nav a[aria-current="page"] span { color: var(--accent); }
.sidebar-foot { margin-top: auto; display: flex; flex-direction: column; gap: 8px; }
main { padding: 28px 32px 64px; max-width: 1280px; width: 100%; min-width: 0; outline: none; }

@media (max-width: 860px) {
  .shell { grid-template-columns: 1fr; }
  .sidebar { position: sticky; height: auto; flex-direction: row; align-items: center; padding: 10px 12px; gap: 12px; overflow-x: auto; z-index: 5; border-right: 0; border-bottom: 1px solid var(--border); }
  .brand-text, .sidebar-foot { display: none; }
  nav { flex-direction: row; }
  nav a { white-space: nowrap; padding: 8px 10px; }
  main { padding: 18px 16px 48px; }
}

/* Cabeçalho de página */
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; flex-wrap: wrap; margin-bottom: 22px; }
.page-head h1 { margin: 0; font-size: 26px; letter-spacing: -.01em; }
.page-head p { margin: 4px 0 0; color: var(--muted); }
.actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
h2 { font-size: 17px; margin: 0 0 12px; }
h3 { font-size: 15px; margin: 0 0 8px; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 12.5px; }

/* Cartões */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); padding: 18px 20px; }
.stack { display: flex; flex-direction: column; gap: 18px; }
.grid-2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); gap: 18px; }
.kpis { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 14px; }
.kpi { display: flex; flex-direction: column; gap: 4px; text-decoration: none; color: inherit; }
.kpi .label { color: var(--muted); font-size: 13px; font-weight: 500; }
.kpi .value { font-size: 30px; font-weight: 700; letter-spacing: -.02em; line-height: 1.1; }
.kpi .detail { color: var(--muted); font-size: 12.5px; }
a.kpi:hover { border-color: var(--accent); }
.kpi.danger .value { color: var(--danger); }

.banner { display: flex; gap: 12px; align-items: flex-start; padding: 12px 16px; border-radius: 10px; border: 1px solid; margin-bottom: 18px; }
.banner.warn { background: var(--warn-soft); border-color: color-mix(in srgb, var(--warn) 30%, transparent); }
.banner.info { background: var(--info-soft); border-color: color-mix(in srgb, var(--info) 30%, transparent); }
.banner.danger { background: var(--danger-soft); border-color: color-mix(in srgb, var(--danger) 30%, transparent); }
.banner strong { display: block; }

/* Botões */
.btn {
  appearance: none; border: 1px solid var(--border); background: var(--surface); color: var(--text); border-radius: 8px;
  padding: 8px 14px; font: inherit; font-weight: 600; font-size: 14px; cursor: pointer; display: inline-flex; align-items: center;
  gap: 6px; text-decoration: none; white-space: nowrap; min-height: 38px;
}
.btn:hover { background: var(--surface-2); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); }
.btn.danger { color: var(--danger); }
.btn.ghost { border-color: transparent; background: transparent; }
.btn.lg { padding: 11px 20px; font-size: 15px; }
.btn.sm { padding: 4px 10px; min-height: 30px; font-size: 13px; }
.btn:disabled, .btn[aria-disabled="true"] { opacity: .5; cursor: not-allowed; }

/* Formulários */
label { font-size: 13px; font-weight: 600; color: var(--muted); display: block; margin-bottom: 4px; }
input[type="text"], input[type="url"], input[type="search"], input[type="number"], input[type="date"], input[type="time"], select, textarea {
  width: 100%; font: inherit; color: var(--text); background: var(--surface); border: 1px solid var(--border); border-radius: 8px;
  padding: 8px 10px; min-height: 38px;
}
textarea { resize: vertical; min-height: 64px; }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--accent); box-shadow: var(--focus); }
.field { display: flex; flex-direction: column; }
.form-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: 14px; }
.inline { display: flex; gap: 8px; align-items: flex-end; flex-wrap: wrap; }
.inline .field { flex: 1 1 260px; }
.checks { display: flex; flex-wrap: wrap; gap: 8px; }
.check {
  display: inline-flex; align-items: center; gap: 8px; border: 1px solid var(--border); border-radius: 999px; padding: 6px 12px;
  font-size: 14px; font-weight: 500; color: var(--text); cursor: pointer; margin: 0; background: var(--surface);
}
.check:has(input:checked) { border-color: var(--accent); background: var(--accent-soft); }
.check:has(input:disabled) { opacity: .55; cursor: not-allowed; }
.hint { font-size: 12.5px; color: var(--muted); margin-top: 4px; }
fieldset { border: 0; padding: 0; margin: 0; }
legend { font-size: 13px; font-weight: 700; color: var(--muted); margin-bottom: 6px; padding: 0; }

/* Selos */
.badge {
  display: inline-flex; align-items: center; gap: 4px; font-size: 12px; font-weight: 600; padding: 2px 8px; border-radius: 999px;
  background: var(--surface-2); color: var(--muted); white-space: nowrap; border: 1px solid transparent;
}
.badge.ok { background: var(--ok-soft); color: var(--ok); }
.badge.info { background: var(--info-soft); color: var(--info); }
.badge.warn { background: var(--warn-soft); color: var(--warn); }
.badge.danger { background: var(--danger-soft); color: var(--danger); }
.badge.accent { background: var(--accent-soft); color: var(--accent); }
.badge.outline { background: transparent; border-color: var(--border); }

/* Acervo */
.toolbar { display: grid; grid-template-columns: 2fr repeat(4, 1fr); gap: 10px; margin-bottom: 14px; }
@media (max-width: 960px) { .toolbar { grid-template-columns: 1fr 1fr; } .toolbar .search { grid-column: 1 / -1; } }
.vgrid { display: grid; grid-template-columns: repeat(auto-fill, minmax(178px, 1fr)); gap: 14px; }
.vcard { background: var(--surface); border: 1px solid var(--border); border-radius: 10px; overflow: hidden; display: flex; flex-direction: column; }
.thumb { position: relative; aspect-ratio: 3 / 4; background: var(--surface-2); }
.thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.thumb-ph { width: 100%; height: 100%; display: grid; place-items: center; color: var(--muted); font-size: 26px; }
.thumb .dur { position: absolute; right: 6px; bottom: 6px; background: rgba(0, 0, 0, .72); color: #fff; font-size: 12px; font-weight: 600; padding: 1px 6px; border-radius: 4px; }
.thumb .flags { position: absolute; left: 6px; top: 6px; display: flex; gap: 4px; flex-wrap: wrap; }
.vbody { padding: 10px; display: flex; flex-direction: column; gap: 6px; }
.vname { font-weight: 600; font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.vmeta { color: var(--muted); font-size: 12px; }
.chips { display: flex; gap: 4px; flex-wrap: wrap; }
.pager { display: flex; align-items: center; justify-content: center; gap: 12px; margin-top: 18px; }
.list { display: flex; flex-direction: column; }
.list-row { display: flex; align-items: center; gap: 14px; padding: 12px 0; border-top: 1px solid var(--border); flex-wrap: wrap; }
.list-row:first-child { border-top: 0; }
.list-row .grow { flex: 1 1 260px; min-width: 0; }
.ellipsis { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.copy { display: inline-flex; gap: 6px; align-items: center; background: var(--surface-2); border-radius: 6px; padding: 2px 8px; }

/* Canais */
.cgrid { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 16px; }
.channel-head { display: flex; justify-content: space-between; gap: 10px; align-items: flex-start; margin-bottom: 12px; }
.channel-head strong { display: block; font-size: 16px; }
.pf { display: inline-grid; place-items: center; width: 34px; height: 34px; border-radius: 9px; color: #fff; font-weight: 800; font-size: 12px; flex: none; }
.pf.facebook { background: #1877f2; }
.pf.instagram { background: linear-gradient(45deg, #f58529, #dd2a7b 50%, #8134af); }
.pf.youtube { background: #e62117; }
.pf.tiktok { background: #111; box-shadow: inset 2px 0 0 #25f4ee, inset -2px 0 0 #fe2c55; }
.row { display: flex; gap: 10px; align-items: center; }

/* Tabelas */
.table-wrap { overflow-x: auto; border: 1px solid var(--border); border-radius: 10px; background: var(--surface); }
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th, td { padding: 10px 12px; text-align: left; vertical-align: top; border-bottom: 1px solid var(--border); }
th { font-size: 12px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); background: var(--surface-2); position: sticky; top: 0; }
tr:last-child td { border-bottom: 0; }
tr.day td { background: var(--surface-2); font-weight: 700; font-size: 13px; padding: 8px 12px; }
tr.selected td { background: color-mix(in srgb, var(--accent-soft) 70%, transparent); }
td .mini { width: 44px; height: 58px; border-radius: 6px; object-fit: cover; background: var(--surface-2); display: block; }
td textarea { min-height: 56px; font-size: 13px; }
td input[type="text"] { font-size: 13px; }
.col-check { width: 36px; }
.col-thumb { width: 60px; }
.sticky-bar {
  position: sticky; top: 0; z-index: 3; background: color-mix(in srgb, var(--bg) 92%, transparent); backdrop-filter: blur(6px);
  padding: 10px 0; margin-bottom: 10px; display: flex; gap: 8px; flex-wrap: wrap; align-items: center; border-bottom: 1px solid var(--border);
}
@media (max-width: 860px) { .sticky-bar { top: 56px; } }
.summary { display: flex; gap: 10px; flex-wrap: wrap; margin-bottom: 14px; }
.summary .pill { background: var(--surface); border: 1px solid var(--border); border-radius: 10px; padding: 8px 14px; }
.summary .pill b { display: block; font-size: 20px; }
.summary .pill span { font-size: 12px; color: var(--muted); }
.tiles { display: grid; grid-template-columns: repeat(auto-fill, minmax(130px, 1fr)); gap: 10px; margin-bottom: 16px; }
.tile { text-align: left; border: 1px solid var(--border); background: var(--surface); border-radius: 10px; padding: 10px 12px; cursor: pointer; font: inherit; color: inherit; }
.tile b { display: block; font-size: 22px; }
.tile span { font-size: 12.5px; color: var(--muted); }
.tile[aria-pressed="true"] { border-color: var(--accent); background: var(--accent-soft); }

.empty { text-align: center; padding: 40px 16px; color: var(--muted); }
.empty strong { display: block; color: var(--text); font-size: 16px; margin-bottom: 4px; }
.steps { margin: 0; padding-left: 20px; display: flex; flex-direction: column; gap: 6px; }
.steps li.done { color: var(--muted); text-decoration: line-through; }
details summary { cursor: pointer; font-weight: 600; }

/* Avisos */
.toasts { position: fixed; right: 16px; bottom: 16px; display: flex; flex-direction: column; gap: 8px; z-index: 20; max-width: min(420px, calc(100vw - 32px)); }
.toast { background: var(--text); color: var(--bg); padding: 10px 14px; border-radius: 10px; box-shadow: 0 6px 20px rgba(0,0,0,.2); font-size: 14px; }
.toast.error { background: var(--danger); color: #fff; }
.toast.ok { background: var(--ok); color: #fff; }
.spinner { display: inline-block; width: 14px; height: 14px; border: 2px solid currentColor; border-right-color: transparent; border-radius: 50%; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .spinner { animation: none; } }
.loading { padding: 40px; text-align: center; color: var(--muted); }

/* ---------- Fase 3: envio, progresso, fluxo e legenda ---------- */
.run-flag { text-decoration: none; }
.flow { display: flex; flex-wrap: wrap; gap: 6px; list-style: none; padding: 0; margin: 0 0 18px; counter-reset: flow; }
.flow li { counter-increment: flow; display: flex; align-items: center; gap: 6px; padding: 5px 10px 5px 6px; border-radius: 999px;
  border: 1px solid var(--border); background: var(--surface); font-size: 13px; color: var(--muted); }
.flow li::before { content: counter(flow); width: 20px; height: 20px; border-radius: 50%; display: grid; place-items: center;
  background: var(--surface-2); font-size: 11.5px; font-weight: 700; }
.flow li.done { color: var(--ok); }
.flow li.done::before { content: '✓'; background: var(--ok-soft); color: var(--ok); }
.flow li.current { color: var(--text, inherit); border-color: var(--accent); background: var(--accent-soft); font-weight: 600; }
.flow li.current::before { background: var(--accent); color: #fff; }
.dispatch { margin-bottom: 18px; }
.dispatch-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; flex-wrap: wrap; }
.dispatch-head h2 { margin: 0 0 2px; font-size: 17px; }
.progress { height: 12px; border-radius: 999px; background: var(--surface-2); overflow: hidden; margin: 14px 0 8px; border: 1px solid var(--border); }
.progress > span { display: block; height: 100%; width: 0; background: var(--accent); transition: width .4s ease; }
.progress.done > span { background: var(--ok); }
.progress.mini { height: 6px; margin: 6px 0 0; }
.dispatch-nums { display: flex; flex-wrap: wrap; gap: 6px 18px; font-size: 13.5px; }
.dispatch-nums b { font-size: 15px; }
.dispatch-current { margin-top: 12px; padding: 10px 12px; border-radius: 8px; background: var(--surface-2); font-size: 13px; }
.dispatch-current .ellipsis { max-width: 100%; }
.dispatch-actions { margin-top: 12px; }
.legend { margin: 0 0 18px; }
.legend summary { cursor: pointer; font-weight: 600; font-size: 14px; }
.legend dl { display: grid; grid-template-columns: max-content 1fr; gap: 8px 14px; margin: 12px 0 0; font-size: 13px; }
.legend dt { margin: 0; }
.legend dd { margin: 0; color: var(--muted); }
@media (max-width: 640px) { .legend dl { grid-template-columns: 1fr; } .legend dd { margin-bottom: 6px; } }
.row-actions { display: flex; gap: 4px; flex-wrap: wrap; margin-top: 6px; }
.err { color: var(--danger); }
.match { margin-top: 4px; padding: 6px 8px; border-radius: 6px; background: var(--warn-soft); }
.send-box { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
dialog.modal { border: 1px solid var(--border); border-radius: var(--radius); padding: 20px; background: var(--surface); color: inherit; width: min(420px, calc(100vw - 32px)); box-shadow: var(--shadow); }
dialog.modal::backdrop { background: rgba(0, 0, 0, .35); }
dialog.modal h2 { margin: 0 0 6px; font-size: 18px; }
.sticky-bar .grow { flex: 1 1 auto; }
.details-cell { min-width: 220px; }
.nowrap { white-space: nowrap; }
.vname-cell { max-width: 240px; }
.tiles a.tile { text-decoration: none; }
.filters { margin-bottom: 12px; }
.filters .field.filter { flex: 0 1 200px; }
.inline .grow { flex: 1 1 auto; }
.dispatch-head > div { min-width: 0; }
.dispatch-head .row, .dispatch-current .row { flex-wrap: wrap; }

/* v0.6: ficha de conferência da publicação real; grupos por marca; seleção de identidade */
dialog.modal:has(.facts) { width: min(620px, calc(100vw - 32px)); }
.facts { display: grid; grid-template-columns: max-content 1fr; gap: 6px 14px; margin: 0; font-size: 14px; }
.facts dt { color: var(--muted); font-weight: 600; }
.facts dd { margin: 0; overflow-wrap: anywhere; white-space: pre-wrap; }
.brand-group { padding: 8px 0; border-top: 1px solid var(--border); }
.brand-group:first-child { border-top: 0; }
.match .row-actions select { max-width: 100%; min-width: 0; flex: 1 1 220px; }
@media (max-width: 520px) { .facts { grid-template-columns: 1fr; } .facts dt { margin-top: 6px; } }

/* v0.7 — lote real, fila e relatório */
dialog.modal.wide { width: min(860px, calc(100vw - 32px)); max-height: calc(100vh - 48px); overflow: auto; }
.queue { margin-top: 12px; font-size: 13px; }
.queue summary, .runs summary { cursor: pointer; font-weight: 600; }
.q-list { list-style: none; margin: 8px 0 0; padding: 0; display: grid; gap: 4px; }
.q-row { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 10px; padding: 5px 8px; border-radius: 6px; background: var(--surface-2); }
.q-icon { width: 1.2em; text-align: center; font-weight: 700; }
.q-scheduled .q-icon, .q-published .q-icon { color: var(--ok, #1a7f37); }
.q-failed .q-icon, .q-action_required .q-icon { color: var(--danger, #b42318); }
.q-name { font-weight: 600; }
.q-file { max-width: 260px; color: var(--muted); }
.q-state { margin-left: auto; white-space: nowrap; }
.q-err { flex-basis: 100%; font-size: 12.5px; }
.runs { margin-bottom: 18px; }

/* ---------- Analytics (v0.9) ---------- */
.an-status { display: flex; flex-wrap: wrap; gap: 6px 18px; margin: -6px 0 4px; }
.an-filters input[type=date], .an-filters select { width: auto; }
.section-head { display: flex; flex-wrap: wrap; align-items: baseline; gap: 6px 14px; }
.section-head h2 { margin: 0; }
.kpi.ok .value { color: var(--ok); }
.an-charts { display: grid; grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); gap: 18px; }
.an-charts h3 { font-size: 14px; margin: 0 0 6px; color: var(--muted); font-weight: 600; }
.chart { width: 100%; height: auto; display: block; }
.chart .grid { stroke: var(--border); stroke-width: 1; }
.chart .axis { fill: var(--muted); font-size: 11px; }
.chart .line { fill: none; stroke: var(--accent); stroke-width: 2.2; }
.chart .dot { fill: var(--accent); }
.chart .bar { fill: var(--accent); opacity: .85; }
.chart-empty { padding: 28px 0; text-align: center; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.num-bar { display: flex; align-items: center; justify-content: flex-end; gap: 8px; }
.hbar { display: inline-block; width: 90px; height: 6px; border-radius: 3px; background: var(--surface-2); overflow: hidden; vertical-align: middle; }
.hbar > span { display: block; height: 100%; background: var(--accent); }
.demo-row { display: grid; grid-template-columns: 110px 1fr 64px; align-items: center; gap: 8px; }
.demo-row .hbar { width: 100%; }
@media (max-width: 640px) { .demo-row { grid-template-columns: 90px 1fr 56px; } }
td.key { white-space: nowrap; font-weight: 600; }

/* ---------- Login (v0.9.1) ---------- */
.row.wrap { flex-wrap: wrap; }
.auth-body { min-height: 100vh; background: var(--bg); }
.auth-wrap { min-height: 100vh; display: flex; flex-direction: column; align-items: center; justify-content: center; padding: 24px 16px; gap: 14px; }
.auth-card { width: 100%; max-width: 420px; padding: 28px 26px; }
.auth-brand { margin-bottom: 18px; }
.auth-title { font-size: 22px; margin: 0 0 4px; letter-spacing: -.01em; }
.auth-card .field input { width: 100%; font-size: 16px; } /* 16px evita zoom automático no iPhone */
.auth-card .btn.lg { width: 100%; justify-content: center; }
.auth-qr { display: flex; justify-content: center; padding: 8px; background: #fff; border-radius: 10px; border: 1px solid var(--border); }
.auth-qr img { width: 220px; height: 220px; image-rendering: pixelated; }
.auth-codes { columns: 2; gap: 18px; padding-left: 22px; margin: 0; font-size: 15px; line-height: 1.9; }
.auth-foot { text-align: center; max-width: 420px; }
.sidebar-foot .account { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.sidebar-foot .account a { font-size: 13px; color: var(--muted); text-decoration: none; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 150px; }
.sidebar-foot .account a:hover { color: var(--accent); }
