:root {
  --bg: #f6f5f2;
  --surface: #ffffff;
  --surface-2: #f0eee9;
  --border: #e2dfd8;
  --text: #1d1b18;
  --muted: #6d685f;
  --accent: #c2410c;
  --accent-ink: #ffffff;
  --accent-soft: #fbe9df;
  --ok: #15803d;
  --ok-soft: #e3f3e8;
  --warn: #a16207;
  --warn-soft: #fbf1d9;
  --err: #b91c1c;
  --err-soft: #fbe4e4;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(0,0,0,.04), 0 4px 16px rgba(0,0,0,.04);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #151412;
    --surface: #1e1c1a;
    --surface-2: #26241f;
    --border: #35322c;
    --text: #efece6;
    --muted: #a39d92;
    --accent: #fb923c;
    --accent-ink: #1a0f06;
    --accent-soft: #3a2416;
    --ok: #4ade80;
    --ok-soft: #173322;
    --warn: #facc15;
    --warn-soft: #3a3110;
    --err: #f87171;
    --err-soft: #3b1a1a;
    --shadow: none;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, Roboto, sans-serif;
}
a { color: var(--accent); }
code { background: var(--surface-2); padding: 1px 5px; border-radius: 4px; font-size: 13px; }
h1 { font-size: 22px; margin: 0; letter-spacing: -.01em; }
h2 { font-size: 15px; margin: 0 0 12px; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.hidden { display: none !important; }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }

/* topo */
.topbar {
  position: sticky; top: 0; z-index: 5;
  display: flex; align-items: center; gap: 20px;
  padding: 10px 24px; background: var(--surface); border-bottom: 1px solid var(--border);
}
.brand { font-weight: 650; display: flex; align-items: center; gap: 8px; white-space: nowrap; }
.logo { display: grid; place-items: center; width: 28px; height: 28px; border-radius: 8px; background: var(--accent); color: var(--accent-ink); font-size: 15px; }
.tabs { display: flex; gap: 2px; overflow-x: auto; }
.tabs button { background: none; border: 0; padding: 8px 12px; border-radius: 8px; color: var(--muted); font: inherit; cursor: pointer; white-space: nowrap; }
.tabs button:hover { background: var(--surface-2); color: var(--text); }
.tabs button.active { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.account { margin-left: auto; font-size: 13px; white-space: nowrap; }
.pill { display: inline-flex; align-items: center; gap: 6px; padding: 3px 10px; border-radius: 999px; font-size: 12.5px; font-weight: 550; }
.pill.ok { background: var(--ok-soft); color: var(--ok); }
.pill.err { background: var(--err-soft); color: var(--err); }
.pill.warn { background: var(--warn-soft); color: var(--warn); }
.pill.neutral { background: var(--surface-2); color: var(--muted); }

main { max-width: 1120px; margin: 0 auto; padding: 24px; }
.tab { display: none; }
.tab.active { display: block; }
.section-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin-bottom: 18px; flex-wrap: wrap; }

.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 18px; margin-bottom: 16px; box-shadow: var(--shadow); }

/* botoes e campos */
button { font: inherit; cursor: pointer; }
.primary, .ghost, .danger {
  border-radius: 8px; padding: 8px 14px; font-weight: 550; border: 1px solid transparent;
}
.primary { background: var(--accent); color: var(--accent-ink); }
.primary:hover { filter: brightness(1.06); }
.primary:disabled { opacity: .6; cursor: progress; }
.ghost { background: var(--surface); color: var(--text); border-color: var(--border); }
.ghost:hover { background: var(--surface-2); }
.danger { background: none; color: var(--err); border-color: var(--border); }
.link { background: none; border: 0; color: var(--accent); padding: 0; }
.icon-btn { background: none; border: 1px solid transparent; border-radius: 6px; padding: 4px 8px; color: var(--muted); font-size: 13px; }
.icon-btn:hover { border-color: var(--border); color: var(--text); background: var(--surface-2); }

label { display: block; font-size: 13px; font-weight: 550; margin: 12px 0 5px; }
label.check { display: flex; align-items: center; gap: 8px; font-weight: 450; font-size: 14px; }
input:not([type=checkbox]):not([type=radio]), select, textarea {
  width: 100%; padding: 8px 10px; border-radius: 8px; border: 1px solid var(--border);
  background: var(--surface); color: var(--text); font: inherit;
}
select { width: auto; }
.grid-2 select, .dialog select { width: 100%; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: -1px; border-color: transparent; }
textarea { resize: vertical; }
fieldset { border: 1px solid var(--border); border-radius: var(--radius); padding: 4px 16px 14px; margin: 16px 0; }
legend { font-weight: 650; padding: 0 6px; font-size: 14px; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 14px; }
.seg { display: flex; gap: 16px; margin-top: 8px; flex-wrap: wrap; }
.seg label { display: flex; gap: 6px; align-items: center; margin: 0; font-weight: 450; font-size: 14px; }
.error { color: var(--err); font-size: 13.5px; min-height: 1em; }
.copy { display: flex; gap: 8px; }

/* estatisticas */
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; margin-bottom: 16px; }
.stat { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 16px; box-shadow: var(--shadow); }
.stat .label { font-size: 12.5px; color: var(--muted); }
.stat .value { font-size: 26px; font-weight: 650; letter-spacing: -.02em; margin-top: 2px; font-variant-numeric: tabular-nums; }
.stat .sub { font-size: 12px; color: var(--muted); }
.banner { border-radius: var(--radius); padding: 12px 16px; margin-bottom: 16px; background: var(--warn-soft); color: var(--text); border: 1px solid var(--border); }

.chart { display: flex; align-items: flex-end; gap: 3px; height: 140px; padding-top: 8px; }
.chart .bar { flex: 1; min-width: 4px; background: var(--accent); border-radius: 3px 3px 0 0; position: relative; opacity: .85; }
.chart .bar:hover { opacity: 1; }
.chart .bar.zero { background: var(--border); }
.chart-empty { color: var(--muted); font-size: 14px; padding: 30px 0; text-align: center; width: 100%; }

/* tabelas */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th { text-align: left; font-weight: 550; color: var(--muted); font-size: 12.5px; padding: 8px 10px; border-bottom: 1px solid var(--border); white-space: nowrap; }
td { padding: 10px; border-bottom: 1px solid var(--border); vertical-align: top; }
tr:last-child td { border-bottom: 0; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
.clip { max-width: 260px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.errtext { color: var(--err); font-size: 12.5px; margin-top: 3px; max-width: 320px; }
.empty { color: var(--muted); padding: 24px; text-align: center; }

/* automacoes */
.layout-2 { display: grid; grid-template-columns: 220px 1fr; gap: 16px; align-items: start; }
.folders { padding: 12px; }
.folders-head { display: flex; justify-content: space-between; align-items: center; padding: 2px 6px 8px; }
.folders ul { list-style: none; margin: 0; padding: 0; }
.folders li { display: flex; align-items: center; justify-content: space-between; padding: 6px 8px; border-radius: 7px; cursor: pointer; font-size: 14px; gap: 6px; }
.folders li:hover { background: var(--surface-2); }
.folders li.active { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.folders li .count { color: var(--muted); font-size: 12px; }
.folders li .folder-actions { display: none; }
.folders li:hover .folder-actions { display: inline-flex; }
.auto-list { display: grid; gap: 12px; }
.auto { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 16px; box-shadow: var(--shadow); }
.auto.off { opacity: .7; }
.auto-top { display: flex; justify-content: space-between; gap: 12px; align-items: flex-start; }
.auto h3 { margin: 0; font-size: 15.5px; }
.auto .meta { font-size: 13px; color: var(--muted); margin-top: 4px; }
.kw { display: inline-block; background: var(--surface-2); border-radius: 6px; padding: 1px 7px; font-size: 12.5px; margin: 2px 3px 0 0; }
.auto-stats { display: flex; gap: 18px; font-size: 13px; margin-top: 10px; color: var(--muted); flex-wrap: wrap; }
.auto-stats b { color: var(--text); font-variant-numeric: tabular-nums; }
.auto-actions { display: flex; gap: 2px; flex-wrap: wrap; justify-content: flex-end; }

/* switch */
.switch { position: relative; width: 38px; height: 22px; flex: none; }
.switch input { opacity: 0; width: 0; height: 0; }
.switch span { position: absolute; inset: 0; background: var(--border); border-radius: 999px; transition: .15s; cursor: pointer; }
.switch span::before { content: ""; position: absolute; width: 16px; height: 16px; left: 3px; top: 3px; background: #fff; border-radius: 50%; transition: .15s; }
.switch input:checked + span { background: var(--ok); }
.switch input:checked + span::before { transform: translateX(16px); }

/* seletor de posts */
.post-picker { display: grid; grid-template-columns: repeat(auto-fill, minmax(96px, 1fr)); gap: 8px; margin: 12px 0 4px; max-height: 280px; overflow-y: auto; padding: 2px; }
.post { position: relative; aspect-ratio: 1; border-radius: 8px; overflow: hidden; border: 2px solid transparent; cursor: pointer; background: var(--surface-2); }
.post img { width: 100%; height: 100%; object-fit: cover; display: block; }
.post .cap { position: absolute; inset: auto 0 0 0; font-size: 10.5px; padding: 3px 5px; background: linear-gradient(transparent, rgba(0,0,0,.7)); color: #fff; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.post.sel { border-color: var(--accent); }
.post.sel::after { content: "✓"; position: absolute; top: 4px; right: 4px; width: 20px; height: 20px; border-radius: 50%; background: var(--accent); color: var(--accent-ink); display: grid; place-items: center; font-size: 12px; font-weight: 700; }
.post-picker .note { grid-column: 1 / -1; font-size: 13.5px; color: var(--muted); }

/* dialogos */
.dialog { border: 1px solid var(--border); border-radius: 14px; padding: 0; width: min(560px, calc(100vw - 32px)); background: var(--surface); color: var(--text); box-shadow: 0 20px 60px rgba(0,0,0,.25); }
.dialog.wide { width: min(760px, calc(100vw - 32px)); }
.dialog::backdrop { background: rgba(20,18,15,.45); }
.dlg-head { display: flex; justify-content: space-between; align-items: center; padding: 16px 20px; border-bottom: 1px solid var(--border); }
.dlg-head h2 { margin: 0; font-size: 17px; }
.close { font-size: 18px; color: var(--muted); }
.dlg-body { padding: 4px 20px 12px; max-height: calc(100vh - 190px); overflow-y: auto; }
.dlg-foot { display: flex; justify-content: flex-end; gap: 8px; padding: 14px 20px; border-top: 1px solid var(--border); }

.sim-box { margin-top: 14px; border-radius: 10px; padding: 12px 14px; background: var(--surface-2); font-size: 14px; }
.bubble { background: var(--surface); border: 1px solid var(--border); border-radius: 14px; padding: 10px 12px; margin-top: 8px; white-space: pre-wrap; }
.bubble .btn-preview { display: block; text-align: center; margin-top: 8px; padding: 7px; border-top: 1px solid var(--border); color: var(--accent); font-weight: 600; }

/* conexao */
.steps { padding-left: 20px; margin: 0 0 4px; }
.steps li { margin-bottom: 6px; }
.checks { list-style: none; padding: 0; margin: 14px 0 0; display: grid; gap: 6px; font-size: 14px; }
.checks li::before { margin-right: 8px; font-weight: 700; }
.checks li.ok::before { content: "✓"; color: var(--ok); }
.checks li.bad::before { content: "✕"; color: var(--err); }
.page-option { display: flex; justify-content: space-between; align-items: center; gap: 12px; border: 1px solid var(--border); border-radius: 8px; padding: 10px 12px; margin-top: 10px; }
.conn { display: flex; align-items: center; gap: 14px; flex-wrap: wrap; }
.conn .who { font-size: 16px; font-weight: 600; }

.pager { text-align: center; }
.toast { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%) translateY(20px); background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 10px; font-size: 14px; opacity: 0; pointer-events: none; transition: .2s; max-width: calc(100vw - 32px); }
.toast.show { opacity: 1; transform: translateX(-50%); }
.toast.err { background: var(--err); color: #fff; }

@media (max-width: 760px) {
  .topbar { flex-wrap: wrap; padding: 10px 16px; gap: 8px; }
  .tabs { order: 3; width: 100%; }
  main { padding: 16px; }
  .layout-2 { grid-template-columns: 1fr; }
  .grid-2 { grid-template-columns: 1fr; }
  .auto-top { flex-direction: column; }
  .auto-actions { justify-content: flex-start; }
}
