:root {
  color-scheme: light;
  --bg: #f6f6f4;
  --surface: #ffffff;
  --surface-2: #f1f1ee;
  --border: #e3e2dd;
  --text: #17171a;
  --text-2: #55545a;
  --muted: #8a8990;
  --accent: #2a78d6;
  --accent-ink: #ffffff;
  --accent-soft: #e6effb;
  --good: #1a7f37;
  --good-soft: #e3f4e8;
  --warn: #9a6700;
  --warn-soft: #fff4d6;
  --bad: #c62828;
  --bad-soft: #fde7e7;
  --s1: #2a78d6; --s2: #eb6834; --s3: #1baf7a; --s4: #eda100;
  --s5: #e87ba4; --s6: #008300; --s7: #6250d6; --s8: #e34948;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(0,0,0,.04), 0 4px 16px rgba(0,0,0,.04);
  --nav-h: 64px;
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Inter, Roboto, sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #111113; --surface: #1a1a1d; --surface-2: #232327; --border: #2e2e33;
    --text: #f0efec; --text-2: #c3c2b7; --muted: #8d8c93;
    --accent: #3987e5; --accent-soft: #1b2a3f;
    --good: #4cc26b; --good-soft: #16301f; --warn: #e0b341; --warn-soft: #3a2f10; --bad: #ff6b6b; --bad-soft: #3d1a1a;
    --s1: #3987e5; --s2: #d95926; --s3: #199e70; --s4: #c98500;
    --s5: #d55181; --s6: #0ca30c; --s7: #9085e9; --s8: #e66767;
    --shadow: none;
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #111113; --surface: #1a1a1d; --surface-2: #232327; --border: #2e2e33;
  --text: #f0efec; --text-2: #c3c2b7; --muted: #8d8c93;
  --accent: #3987e5; --accent-soft: #1b2a3f;
  --good: #4cc26b; --good-soft: #16301f; --warn: #e0b341; --warn-soft: #3a2f10; --bad: #ff6b6b; --bad-soft: #3d1a1a;
  --s1: #3987e5; --s2: #d95926; --s3: #199e70; --s4: #c98500;
  --s5: #d55181; --s6: #0ca30c; --s7: #9085e9; --s8: #e66767;
  --shadow: none;
}

* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--text); }
body { font-size: 15px; line-height: 1.45; -webkit-font-smoothing: antialiased; overflow-x: hidden; }
a { color: var(--accent); text-decoration: none; }
h1 { font-size: 24px; margin: 0; letter-spacing: -.01em; }
h2 { font-size: 17px; margin: 0 0 12px; }
h3 { font-size: 15px; margin: 0 0 8px; }
p { margin: 0 0 8px; }
small, .small { font-size: 13px; }
.muted { color: var(--muted); }
.text-2 { color: var(--text-2); }
.num { font-variant-numeric: tabular-nums; }
.hidden { display: none !important; }

/* ---------- layout */
.app { display: flex; min-height: 100vh; }
.sidebar {
  width: 232px; flex-shrink: 0; background: var(--surface); border-right: 1px solid var(--border);
  padding: 20px 12px; position: sticky; top: 0; height: 100vh; display: flex; flex-direction: column; gap: 2px;
}
.brand-logo { display: flex; align-items: center; gap: 10px; font-weight: 700; padding: 4px 10px 18px; }
.brand-logo .dot { width: 28px; height: 28px; border-radius: 8px; background: var(--accent); display: grid; place-items: center; color: #fff; font-size: 14px; }
.nav-link {
  display: flex; align-items: center; gap: 10px; padding: 9px 10px; border-radius: 10px; color: var(--text-2); font-weight: 500;
}
.nav-link:hover { background: var(--surface-2); }
.nav-link.active { background: var(--accent-soft); color: var(--accent); }
.nav-link svg { width: 20px; height: 20px; flex-shrink: 0; }
.nav-link .count { margin-left: auto; background: var(--bad); color: #fff; border-radius: 999px; font-size: 11px; padding: 1px 7px; font-weight: 700; }
.sidebar .spacer { flex: 1; }

.main { flex: 1; min-width: 0; padding: 28px 32px 48px; max-width: 1240px; }
.page-head { display: flex; align-items: center; gap: 12px; margin-bottom: 20px; flex-wrap: wrap; }
.page-head .actions { margin-left: auto; display: flex; gap: 8px; flex-wrap: wrap; }

.tabbar { display: none; }
@media (max-width: 899px) {
  .sidebar { display: none; }
  .main { padding: 16px 16px calc(var(--nav-h) + 24px + env(safe-area-inset-bottom)); padding-top: calc(16px + env(safe-area-inset-top)); }
  .tabbar {
    display: flex; position: fixed; bottom: 0; left: 0; right: 0; z-index: 50; background: var(--surface);
    border-top: 1px solid var(--border); padding-bottom: env(safe-area-inset-bottom);
  }
  .tabbar a { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 8px 0 6px; font-size: 11px; color: var(--muted); position: relative; }
  .tabbar a.active { color: var(--accent); }
  .tabbar svg { width: 24px; height: 24px; }
  .tabbar .count { position: absolute; top: 4px; left: calc(50% + 6px); background: var(--bad); color: #fff; border-radius: 999px; font-size: 10px; padding: 0 5px; font-weight: 700; }
  .tabbar .plus span { background: var(--accent); color: #fff; width: 44px; height: 32px; border-radius: 12px; display: grid; place-items: center; }
  h1 { font-size: 22px; }
}

/* ---------- components */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 18px; box-shadow: var(--shadow); }
.card + .card { margin-top: 16px; }
.grid > .card { margin-top: 0; }
.grid { display: grid; gap: 16px; }
.grid-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.kpis { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 12px; margin-bottom: 16px; }
@media (max-width: 1100px) { .kpis { grid-template-columns: repeat(3, minmax(0, 1fr)); } }
@media (max-width: 899px) { .grid-2, .grid-3 { grid-template-columns: minmax(0, 1fr); } .kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
.kpi { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 16px; }
.kpi .label { font-size: 13px; color: var(--text-2); }
.kpi .value { font-size: 26px; font-weight: 700; letter-spacing: -.02em; margin-top: 2px; }
.kpi .sub { font-size: 12px; color: var(--muted); }
.kpi.alert .value { color: var(--bad); }
a.kpi { color: inherit; display: block; }

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

label { display: block; font-size: 13px; font-weight: 600; color: var(--text-2); margin: 12px 0 6px; }
label:first-child { margin-top: 0; }
.hint { font-size: 12px; color: var(--muted); margin-top: 4px; font-weight: 400; }
input[type=text], input[type=password], input[type=number], input[type=datetime-local], input[type=url], select, textarea {
  width: 100%; border: 1px solid var(--border); background: var(--surface); color: var(--text); border-radius: 10px; padding: 9px 12px;
  font: inherit; font-size: 16px; /* evita zoom no iOS */
}
textarea { min-height: 90px; resize: vertical; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: -1px; border-color: transparent; }
.row { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; }
.row > .grow { flex: 1; min-width: 160px; }
.switch { display: inline-flex; align-items: center; gap: 10px; cursor: pointer; font-weight: 500; color: var(--text); margin: 8px 0; }
.switch input { width: 40px; height: 24px; appearance: none; background: var(--border); border-radius: 999px; position: relative; cursor: pointer; transition: .15s; flex-shrink: 0; }
.switch input::after { content: ""; position: absolute; top: 3px; left: 3px; width: 18px; height: 18px; border-radius: 50%; background: #fff; transition: .15s; }
.switch input:checked { background: var(--accent); }
.switch input:checked::after { left: 19px; }

.badge { display: inline-flex; align-items: center; gap: 4px; padding: 2px 8px; border-radius: 999px; font-size: 12px; font-weight: 600; background: var(--surface-2); color: var(--text-2); white-space: nowrap; }
.badge.good { background: var(--good-soft); color: var(--good); }
.badge.warn { background: var(--warn-soft); color: var(--warn); }
.badge.bad { background: var(--bad-soft); color: var(--bad); }
.badge.info { background: var(--accent-soft); color: var(--accent); }
.pf { display: inline-grid; place-items: center; width: 22px; height: 22px; border-radius: 6px; font-size: 10px; font-weight: 800; color: #fff; flex-shrink: 0; }
.pf.instagram { background: linear-gradient(45deg, #f09433, #dc2743 50%, #bc1888); }
.pf.facebook { background: #1877f2; }
.pf.tiktok { background: #111; box-shadow: inset 0 0 0 1px #444; }
.avatar { width: 40px; height: 40px; border-radius: 50%; object-fit: cover; background: var(--surface-2); flex-shrink: 0; }
.avatar-wrap { position: relative; flex-shrink: 0; }
.avatar-wrap .pf { position: absolute; right: -4px; bottom: -4px; width: 18px; height: 18px; font-size: 8px; border: 2px solid var(--surface); }
.delta.up { color: var(--good); }
.delta.down { color: var(--bad); }

.list { display: flex; flex-direction: column; }
.list-item { display: flex; gap: 12px; align-items: center; padding: 12px 0; border-top: 1px solid var(--border); }
.list-item:first-child { border-top: 0; padding-top: 0; }
.list-item .grow { flex: 1; min-width: 0; }
.ellipsis { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.clamp-2 { display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }

.acc-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 12px; margin-bottom: 16px; }
.acc-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px; }
.acc-card .head { display: flex; gap: 10px; align-items: center; }
.acc-card .stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; margin-top: 12px; text-align: center; }
.acc-card .stats div { background: var(--surface-2); border-radius: 8px; padding: 6px 0; }
.acc-card .stats b { display: block; font-size: 15px; }
.acc-card .stats span { font-size: 11px; color: var(--muted); }

.tabs { display: flex; gap: 4px; background: var(--surface-2); padding: 4px; border-radius: 12px; overflow-x: auto; margin-bottom: 16px; scrollbar-width: none; }
.tabs button { border: 0; background: transparent; padding: 7px 12px; border-radius: 9px; font: inherit; font-weight: 600; font-size: 14px; color: var(--text-2); cursor: pointer; white-space: nowrap; }
.tabs button.active { background: var(--surface); color: var(--text); box-shadow: var(--shadow); }
.tabs .n { font-size: 12px; color: var(--muted); margin-left: 4px; }

/* ---------- calendário */
.cal { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; background: var(--border); gap: 1px; }
.cal .dow { background: var(--surface-2); text-align: center; font-size: 12px; font-weight: 600; color: var(--muted); padding: 6px 0; }
.cal .day { background: var(--surface); min-height: 112px; padding: 6px; cursor: pointer; display: flex; flex-direction: column; gap: 3px; min-width: 0; }
.cal .day:hover { background: var(--surface-2); }
.cal .day.other { background: var(--bg); }
.cal .day.other .d { color: var(--muted); }
.cal .day .d { font-size: 12px; font-weight: 600; }
.cal .day.today .d { background: var(--accent); color: #fff; border-radius: 999px; width: 22px; height: 22px; display: grid; place-items: center; }
.chip { font-size: 11.5px; padding: 3px 6px; border-radius: 6px; background: var(--surface-2); border-left: 3px solid var(--accent); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--text); }
.chip.published { opacity: .7; }
.chip.failed, .chip.partial { background: var(--bad-soft); }
@media (max-width: 899px) {
  .cal .day { min-height: 58px; padding: 4px; }
  .cal .chip { font-size: 0; padding: 0; height: 6px; border-left-width: 0; border-radius: 3px; background: var(--chip-color, var(--accent)); }
}

/* ---------- editor de postagem */
.editor { display: grid; grid-template-columns: minmax(0, 1.4fr) minmax(0, 1fr); gap: 16px; align-items: start; }
@media (max-width: 1000px) { .editor { grid-template-columns: minmax(0, 1fr); } }
.acc-picker { display: flex; flex-wrap: wrap; gap: 8px; }
.acc-pick { display: inline-flex; align-items: center; gap: 8px; border: 1px solid var(--border); border-radius: 999px; padding: 4px 12px 4px 4px; cursor: pointer; font-size: 14px; font-weight: 500; background: var(--surface); }
.acc-pick.on { border-color: var(--accent); background: var(--accent-soft); }
.acc-pick img { width: 26px; height: 26px; border-radius: 50%; }
.media-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(96px, 1fr)); gap: 8px; }
.media-item { position: relative; aspect-ratio: 1; border-radius: 10px; overflow: hidden; background: var(--surface-2); }
.media-item img, .media-item video { width: 100%; height: 100%; object-fit: cover; }
.media-item .rm { position: absolute; top: 4px; right: 4px; width: 24px; height: 24px; border-radius: 50%; border: 0; background: rgba(0,0,0,.6); color: #fff; cursor: pointer; font-size: 14px; line-height: 1; }
.media-item .idx { position: absolute; left: 4px; top: 4px; background: rgba(0,0,0,.6); color: #fff; border-radius: 6px; font-size: 11px; padding: 0 5px; }
.dropzone { border: 2px dashed var(--border); border-radius: 12px; display: grid; place-items: center; aspect-ratio: 1; cursor: pointer; color: var(--muted); font-size: 13px; text-align: center; padding: 6px; }
.dropzone:hover, .dropzone.drag { border-color: var(--accent); color: var(--accent); }
.seg { display: inline-flex; background: var(--surface-2); border-radius: 10px; padding: 3px; }
.seg button { border: 0; background: transparent; padding: 6px 12px; border-radius: 8px; font: inherit; font-size: 14px; font-weight: 600; color: var(--text-2); cursor: pointer; }
.seg button.on { background: var(--surface); color: var(--text); box-shadow: var(--shadow); }
.preview-phone { background: var(--surface-2); border-radius: 18px; padding: 12px; }
.preview-phone .pm { aspect-ratio: 4/5; background: var(--border); border-radius: 10px; overflow: hidden; }
.preview-phone .pm img, .preview-phone .pm video { width: 100%; height: 100%; object-fit: cover; }
.preview-phone .cap { white-space: pre-wrap; font-size: 13px; margin-top: 8px; max-height: 220px; overflow: auto; }

/* ---------- comentários */
.cmt { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px; display: grid; grid-template-columns: minmax(0, 1fr) 72px; gap: 12px; }
.cmt + .cmt { margin-top: 12px; }
.cmt .who { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; font-size: 13px; color: var(--text-2); }
.cmt .text { font-size: 15px; margin: 8px 0; white-space: pre-wrap; word-break: break-word; }
.cmt .thumb { width: 72px; height: 72px; border-radius: 8px; object-fit: cover; background: var(--surface-2); }
.cmt .ai { background: var(--surface-2); border-radius: 10px; padding: 10px; margin-top: 8px; grid-column: 1 / -1; }
.cmt .ai textarea { min-height: 70px; background: var(--surface); }
.cmt .ai .why { font-size: 12.5px; color: var(--text-2); margin-bottom: 8px; }
.cmt .acts { display: flex; gap: 8px; margin-top: 8px; flex-wrap: wrap; }
.cmt .err { color: var(--bad); font-size: 13px; }

/* ---------- gráficos */
.chart { position: relative; width: 100%; }
.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: 16px; }
.chart .tip {
  position: absolute; pointer-events: none; background: var(--surface); border: 1px solid var(--border); border-radius: 10px;
  padding: 8px 10px; font-size: 12.5px; box-shadow: 0 4px 16px rgba(0,0,0,.12); white-space: nowrap; z-index: 5; transform: translate(-50%, -100%);
}
.chart .tip .sw { display: inline-block; width: 8px; height: 8px; border-radius: 2px; margin-right: 6px; }
.legend { display: flex; flex-wrap: wrap; gap: 6px 14px; font-size: 13px; color: var(--text-2); margin-top: 8px; }
.legend span { display: inline-flex; align-items: center; gap: 6px; }
.legend i { width: 10px; height: 10px; border-radius: 3px; display: inline-block; }
.empty { text-align: center; color: var(--muted); padding: 28px 12px; font-size: 14px; }
.empty b { display: block; color: var(--text-2); font-size: 15px; margin-bottom: 4px; }

table.tbl { width: 100%; border-collapse: collapse; font-size: 14px; }
.tbl th { text-align: left; font-size: 12px; color: var(--muted); font-weight: 600; padding: 8px 6px; border-bottom: 1px solid var(--border); }
.tbl td { padding: 8px 6px; border-bottom: 1px solid var(--border); vertical-align: middle; }
.tbl td.r, .tbl th.r { text-align: right; }
.tbl-wrap { overflow-x: auto; }
.tbl img { width: 40px; height: 40px; border-radius: 6px; object-fit: cover; background: var(--surface-2); }

/* ---------- modal / toast / login */
.modal-bg { position: fixed; inset: 0; background: rgba(0,0,0,.45); z-index: 100; display: grid; place-items: center; padding: 16px; }
.modal { background: var(--surface); border-radius: 18px; width: 100%; max-width: 560px; max-height: calc(100vh - 32px); overflow: auto; padding: 20px; }
.modal .foot { display: flex; gap: 8px; justify-content: flex-end; margin-top: 18px; flex-wrap: wrap; }
@media (max-width: 899px) { .modal-bg { align-items: end; padding: 0; } .modal { border-radius: 18px 18px 0 0; padding-bottom: calc(20px + env(safe-area-inset-bottom)); } }
.toasts { position: fixed; top: calc(12px + env(safe-area-inset-top)); left: 50%; transform: translateX(-50%); z-index: 200; display: flex; flex-direction: column; gap: 8px; width: min(92vw, 420px); }
.toast { background: var(--text); color: var(--bg); padding: 10px 14px; border-radius: 12px; font-size: 14px; box-shadow: 0 6px 24px rgba(0,0,0,.2); }
.toast.error { background: var(--bad); color: #fff; }
.login { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login .card { width: 100%; max-width: 360px; }
.spinner { width: 16px; height: 16px; border: 2px solid currentColor; border-right-color: transparent; border-radius: 50%; animation: spin .7s linear infinite; display: inline-block; }
@keyframes spin { to { transform: rotate(360deg); } }
.loading { display: grid; place-items: center; padding: 60px 0; color: var(--muted); }
.copy { display: flex; gap: 6px; }
.copy input { font-family: ui-monospace, Menlo, monospace; font-size: 13px; }
.notice { background: var(--warn-soft); color: var(--warn); border-radius: 10px; padding: 10px 12px; font-size: 13.5px; margin-bottom: 12px; }
.notice.info { background: var(--accent-soft); color: var(--accent); }
.steps { padding-left: 18px; margin: 6px 0; font-size: 14px; color: var(--text-2); }
.steps li { margin-bottom: 4px; }
code { background: var(--surface-2); padding: 1px 5px; border-radius: 5px; font-size: 13px; }

.savebar { position: sticky; bottom: 0; background: var(--bg); padding: 12px 0; margin-top: 8px; z-index: 10; }
@media (max-width: 899px) { .savebar { bottom: calc(var(--nav-h) + env(safe-area-inset-bottom)); } }
