:root {
  --bg: #050a18;
  --surface: rgba(255, 255, 255, 0.035);
  --surface-2: rgba(255, 255, 255, 0.06);
  --border: rgba(148, 170, 220, 0.14);
  --text: #f1f5fb;
  --muted: #8b98b4;
  --accent: #4f8cff;
  --story: #f59e0b;
  --reel: #ec4899;
  --feed: #3b82f6;
  --ok: #34d399;
  --warn: #fbbf24;
  --danger: #f87171;
  --purple: #a78bfa;
  --cyan: #22d3ee;
  --heat: 79, 140, 255;
  color-scheme: dark;
}

* { box-sizing: border-box; }

html { background: var(--bg); }
body {
  margin: 0;
  min-height: 100vh;
  color: var(--text);
  font: 14px/1.5 Inter, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background:
    radial-gradient(1100px 520px at 0% 0%, rgba(30, 90, 200, 0.28), transparent 60%),
    radial-gradient(900px 500px at 100% 10%, rgba(20, 70, 150, 0.2), transparent 60%),
    var(--bg);
  background-attachment: fixed;
}

h1 { margin: 0; font-size: 20px; letter-spacing: -0.01em; }
h1 a { color: inherit; text-decoration: none; }
h2 { margin: 0 0 12px; font-size: 15px; font-weight: 600; }
p { margin: 0; }
.muted { color: var(--muted); }
.small { font-size: 12px; margin-top: 10px; }
.small.top { margin: -6px 0 12px; }
.view { display: grid; gap: 16px; }
[hidden] { display: none !important; }

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
  max-width: 1328px;
  margin: 0 auto;
  padding: 24px 24px 8px;
}

.live { display: flex; align-items: center; gap: 8px; color: var(--muted); font-size: 13px; white-space: nowrap; }
.live .dot { width: 9px; height: 9px; border-radius: 50%; background: var(--muted); }
.live.on .dot { background: var(--ok); box-shadow: 0 0 10px var(--ok); animation: pulse 2s infinite; }
.live.off .dot { background: var(--danger); }
@keyframes pulse { 50% { opacity: .35; } }

main { max-width: 1328px; margin: 0 auto; padding: 16px 24px 56px; display: grid; gap: 16px; }

.banner {
  padding: 12px 16px;
  border-radius: 12px;
  border: 1px solid rgba(251, 191, 36, 0.45);
  background: rgba(251, 191, 36, 0.08);
}
.banner code { word-break: break-all; color: var(--warn); }

.toolbar { display: flex; flex-wrap: wrap; gap: 16px; align-items: end; }
.toolbar label { display: grid; gap: 4px; font-size: 12px; color: var(--muted); }

select, input, button, a.button {
  font: inherit;
  color: var(--text);
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 8px 12px;
}
select option { background: #0d1528; color: var(--text); }
input::placeholder { color: var(--muted); }
button, a.button { cursor: pointer; text-decoration: none; display: inline-block; }
button:hover, a.button:hover { border-color: var(--accent); }
button.primary { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600; }
button.link, a.link {
  border: 0; background: none; padding: 0; color: var(--accent);
  cursor: pointer; text-decoration: none; font-size: 13px; border-radius: 0;
}
button.link.danger { color: var(--danger); }

.card, .kpi {
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.05), rgba(255, 255, 255, 0.02));
  border: 1px solid var(--border);
  border-radius: 16px;
  min-width: 0;
}
.card { padding: 18px; }
.card-head { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: center; gap: 12px; margin-bottom: 12px; }
.card-head h2 { margin: 0; }
.chart { position: relative; height: 280px; }

.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 12px; }
.kpi { padding: 14px 16px; }
.kpi .label { color: var(--muted); font-size: 12px; display: flex; align-items: center; gap: 6px; }
.kpi .value { font-size: 26px; font-weight: 650; line-height: 1.2; margin-top: 4px; letter-spacing: -0.02em; }
.kpi .sub { color: var(--muted); font-size: 12px; }
.swatch { width: 9px; height: 9px; border-radius: 3px; display: inline-block; }

.grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 16px; }
.span-2 { grid-column: span 2; }
@media (max-width: 900px) {
  .grid { grid-template-columns: minmax(0, 1fr); }
  .span-2 { grid-column: auto; }
}

.add-form { display: flex; flex-wrap: wrap; gap: 8px; }
.add-form input { width: 170px; }

.heatmap { display: grid; grid-template-columns: auto repeat(24, minmax(0, 1fr)); gap: 3px; font-size: 11px; color: var(--muted); }
.heatmap .cell { aspect-ratio: 1; border-radius: 3px; min-height: 12px; background: rgba(var(--heat), var(--a, .06)); }
.heatmap .row-label { padding-right: 6px; display: flex; align-items: center; }
.heatmap .col-label { text-align: center; }

.activity { list-style: none; margin: 0; padding: 0; max-height: 330px; overflow-y: auto; display: grid; gap: 12px; }
.activity li { display: grid; grid-template-columns: auto 1fr auto; gap: 10px; align-items: center; }
.activity .caption { color: var(--muted); font-size: 12px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.activity .meta { min-width: 0; }
.activity .avatar { width: 30px; height: 30px; font-size: 13px; }
.empty { color: var(--muted); padding: 24px 0; text-align: center; }

.tag { font-size: 11px; font-weight: 600; padding: 2px 8px; border-radius: 999px; color: #fff; white-space: nowrap; display: inline-block; }
.tag.story { background: var(--story); color: #1a1205; }
.tag.reel { background: var(--reel); }
.tag.feed { background: var(--feed); }

.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 10px 8px; border-bottom: 1px solid var(--border); white-space: nowrap; }
th { font-size: 11px; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: .04em; }
tr:last-child td { border-bottom: 0; }
.num { text-align: right; font-variant-numeric: tabular-nums; }
.who { display: flex; align-items: center; gap: 10px; }
.avatar {
  width: 34px; height: 34px; border-radius: 50%; object-fit: cover; flex: none;
  background: var(--surface-2); border: 1px solid var(--border);
  display: grid; place-items: center; font-weight: 600; color: var(--muted);
}
.pill { font-size: 12px; padding: 2px 9px; border-radius: 999px; border: 1px solid currentColor; }
.pill.connected { color: var(--ok); }
.pill.pending, .pill.demo { color: var(--muted); }
.pill.expired, .pill.error { color: var(--danger); }
.actions { display: flex; gap: 12px; }

.toasts { position: fixed; right: 16px; bottom: 16px; display: grid; gap: 8px; z-index: 10; }
.toast {
  background: #16233f; color: var(--text); border: 1px solid var(--border); padding: 10px 14px; border-radius: 12px;
  max-width: 360px; box-shadow: 0 10px 30px rgba(0, 0, 0, .5);
}
.toast.error { background: #4a1620; border-color: var(--danger); }

/* ---- Dias sem postagem ---- */
.legend { margin-left: 10px; white-space: nowrap; }
.day { display: inline-block; width: 14px; height: 14px; border-radius: 4px; vertical-align: -2px; flex: none; }
.day.posted { background: var(--ok); }
.day.missed { background: var(--danger); }
.day.nodata, .day.pending { background: rgba(255, 255, 255, 0.1); }
.gap-row { display: grid; grid-template-columns: 250px 1fr; gap: 6px 16px; padding: 12px 0; border-top: 1px solid var(--border); align-items: center; }
.gap-row:first-child { border-top: 0; }
.gap-row .strip { display: flex; flex-wrap: wrap; gap: 3px; }
.gap-row .summary { display: flex; gap: 10px; align-items: center; }
.gap-row .summary strong { font-size: 18px; }
.gap-dates { grid-column: 1 / -1; font-size: 12px; color: var(--muted); }
.gap-dates b { color: var(--danger); font-weight: 600; }
@media (max-width: 700px) { .gap-row { grid-template-columns: 1fr; } }

/* ---- Insights do perfil ---- */
.profile-head { display: flex; flex-wrap: wrap; align-items: center; gap: 14px; }
.profile-head .avatar { width: 56px; height: 56px; font-size: 22px; }
.profile-head h2 { margin: 0; font-size: 20px; }
.profile-head .back { margin-right: 6px; }
.profile-head .stats { margin-left: auto; display: flex; align-items: center; gap: 24px; text-align: right; }
.profile-head .stats strong { display: block; font-size: 18px; }
.tops { display: grid; grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); gap: 16px; }
.top-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 10px; }
.top-list li { display: grid; grid-template-columns: 18px 36px 1fr auto; gap: 8px; align-items: center; }
.top-list .rank { color: var(--muted); font-weight: 600; }
.top-list .meta { min-width: 0; font-size: 12px; }
.top-list .caption { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.top-list .metric { font-weight: 650; font-variant-numeric: tabular-nums; }
.thumb {
  width: 36px; height: 36px; border-radius: 8px; object-fit: cover; flex: none; display: block;
  background: var(--surface-2); border: 1px solid var(--border);
}
th[data-sort] { cursor: pointer; user-select: none; }
th[data-sort].sorted::after { content: " ↓"; }
th[data-sort].sorted.asc::after { content: " ↑"; }
td.caption-cell { max-width: 280px; overflow: hidden; text-overflow: ellipsis; }
td.caption-cell .thumb { display: inline-block; vertical-align: middle; margin-right: 8px; width: 28px; height: 28px; }
