:root {
  --bg: #f6f7f9;
  --surface: #ffffff;
  --surface-2: #f1f3f6;
  --border: #e3e6eb;
  --text: #16181d;
  --muted: #646b78;
  --accent: #4f46e5;
  --accent-soft: #eef0ff;
  --ok: #15803d;
  --ok-soft: #e7f6ec;
  --warn: #b45309;
  --warn-soft: #fdf3e2;
  --bad: #b91c1c;
  --bad-soft: #fde9e9;
  --fb: #1f5fd1;
  --ig: #c13584;
  --th: #222222;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 1px 3px rgba(16, 24, 40, .08);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1115;
    --surface: #171a20;
    --surface-2: #1e222a;
    --border: #2a2f39;
    --text: #e8eaee;
    --muted: #9aa1ad;
    --accent: #8b85ff;
    --accent-soft: #24234a;
    --ok: #4ade80;
    --ok-soft: #13291b;
    --warn: #fbbf24;
    --warn-soft: #2d2410;
    --bad: #f87171;
    --bad-soft: #321616;
    --fb: #5b8ff0;
    --ig: #e46aae;
    --th: #d0d0d0;
    --shadow: none;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg);
  color: var(--text);
  font: 14px/1.5 ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3 { margin: 0; line-height: 1.25; }
h1 { font-size: 20px; font-weight: 650; }
h2 { font-size: 15px; font-weight: 600; }
h3 { font-size: 13px; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
code, .mono { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 12.5px; }
.boot { display: grid; place-items: center; height: 100vh; color: var(--muted); }

/* ── Layout ── */
.shell { display: grid; grid-template-columns: 220px 1fr; min-height: 100vh; }
.side {
  background: var(--surface); border-right: 1px solid var(--border);
  padding: 16px 12px; position: sticky; top: 0; height: 100vh; display: flex; flex-direction: column; gap: 4px;
}
.logo { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 16px; padding: 4px 8px 16px; }
.logo img { width: 28px; height: 28px; }
.nav a {
  display: flex; align-items: center; gap: 10px; padding: 8px 10px; border-radius: 8px; color: var(--text); font-weight: 500;
}
.nav a:hover { background: var(--surface-2); text-decoration: none; }
.nav a.active { background: var(--accent-soft); color: var(--accent); }
.nav svg { width: 18px; height: 18px; flex: none; }
.side .spacer { flex: 1; }
.side .foot { font-size: 12px; color: var(--muted); padding: 8px 10px; }
.main { padding: 24px 28px 64px; max-width: 1240px; width: 100%; }
.page-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 20px; flex-wrap: wrap; }
.page-head .sub { color: var(--muted); margin-top: 2px; }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.grow { flex: 1; }
.grid { display: grid; gap: 16px; }
.g2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.g3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.g4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.compose-grid { display: grid; grid-template-columns: minmax(0, 1.4fr) minmax(0, 1fr); gap: 16px; align-items: start; }

.mobile-bar { display: none; }

/* ── Cards ── */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); }
.card-pad { padding: 16px; }
.card-head { display: flex; align-items: center; justify-content: space-between; padding: 14px 16px; border-bottom: 1px solid var(--border); gap: 8px; }
.card-body { padding: 16px; }
.stack > * + * { margin-top: 12px; }
.empty { color: var(--muted); text-align: center; padding: 28px 12px; }
.banner { padding: 10px 14px; border-radius: 8px; margin-bottom: 16px; border: 1px solid; }
.banner.warn { background: var(--warn-soft); border-color: transparent; color: var(--warn); }
.banner.bad { background: var(--bad-soft); border-color: transparent; color: var(--bad); }
.banner.ok { background: var(--ok-soft); border-color: transparent; color: var(--ok); }
.muted { color: var(--muted); }
.small { font-size: 12px; }

/* ── KPI tiles ── */
.kpi { padding: 14px 16px; }
.kpi .label { color: var(--muted); font-size: 12px; font-weight: 500; }
.kpi .value { font-size: 24px; font-weight: 650; margin-top: 2px; font-variant-numeric: tabular-nums; }
.kpi .delta { font-size: 12px; margin-top: 2px; }
.delta.up { color: var(--ok); }
.delta.down { color: var(--bad); }

/* ── Forms ── */
label.field { display: block; }
label.field > span { display: block; font-size: 12px; font-weight: 600; color: var(--muted); margin-bottom: 4px; }
input[type=text], input[type=password], input[type=url], input[type=datetime-local], input[type=search], select, textarea {
  width: 100%; padding: 8px 10px; border-radius: 8px; border: 1px solid var(--border); background: var(--surface);
  color: var(--text); font: inherit;
}
textarea { min-height: 160px; resize: vertical; line-height: 1.55; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: -1px; border-color: transparent; }
select.inline { width: auto; padding: 6px 8px; }
.row > input[type=url], .row > input[type=search] { flex: 1; width: auto; min-width: 0; }
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px; padding: 8px 14px; border-radius: 8px;
  border: 1px solid var(--border); background: var(--surface); color: var(--text); font: inherit; font-weight: 550; cursor: pointer;
  white-space: nowrap;
}
.btn:hover { background: var(--surface-2); text-decoration: none; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { filter: brightness(1.08); }
.btn.danger { color: var(--bad); }
.btn.sm { padding: 4px 10px; font-size: 12.5px; }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.seg { display: inline-flex; border: 1px solid var(--border); border-radius: 8px; overflow: hidden; }
.seg button { border: 0; background: var(--surface); color: var(--muted); padding: 6px 12px; font: inherit; font-weight: 550; cursor: pointer; }
.seg button + button { border-left: 1px solid var(--border); }
.seg button.on { background: var(--accent-soft); color: var(--accent); }

/* ── Badges ── */
.badge { display: inline-flex; align-items: center; gap: 4px; padding: 1px 8px; border-radius: 999px; font-size: 11.5px; font-weight: 600; background: var(--surface-2); color: var(--muted); }
.badge.draft { background: var(--surface-2); color: var(--muted); }
.badge.scheduled { background: var(--accent-soft); color: var(--accent); }
.badge.publishing, .badge.pending { background: var(--warn-soft); color: var(--warn); }
.badge.published, .badge.active { background: var(--ok-soft); color: var(--ok); }
.badge.failed, .badge.partial, .badge.error { background: var(--bad-soft); color: var(--bad); }
.pf { display: inline-grid; place-items: center; width: 22px; height: 22px; border-radius: 6px; font-size: 10px; font-weight: 800; color: #fff; flex: none; }
.pf.facebook { background: var(--fb); }
.pf.instagram { background: var(--ig); }
.pf.threads { background: var(--th); color: var(--surface); }
.dot { width: 8px; height: 8px; border-radius: 50%; display: inline-block; flex: none; }

/* ── Tables ── */
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 10px 12px; border-bottom: 1px solid var(--border); vertical-align: top; }
th { font-size: 12px; color: var(--muted); font-weight: 600; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
tr:last-child td { border-bottom: 0; }
tr.click { cursor: pointer; }
tr.click:hover td { background: var(--surface-2); }
.excerpt { max-width: 420px; overflow: hidden; text-overflow: ellipsis; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
.table-wrap { overflow-x: auto; }

/* ── Calendar ── */
.cal { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); border-top: 1px solid var(--border); border-left: 1px solid var(--border); }
.cal .dow { padding: 8px; font-size: 12px; color: var(--muted); font-weight: 600; border-right: 1px solid var(--border); border-bottom: 1px solid var(--border); background: var(--surface-2); }
.cal .day { min-height: 112px; padding: 6px; border-right: 1px solid var(--border); border-bottom: 1px solid var(--border); background: var(--surface); cursor: pointer; display: flex; flex-direction: column; gap: 3px; }
.cal .day:hover { background: var(--surface-2); }
.cal .day.other { background: var(--bg); }
.cal .day.other .n { opacity: .45; }
.cal .day .n { font-size: 12px; font-weight: 600; color: var(--muted); }
.cal .day.today .n { color: #fff; background: var(--accent); border-radius: 999px; padding: 0 7px; align-self: flex-start; }
.chip { display: flex; align-items: center; gap: 5px; font-size: 11.5px; padding: 2px 6px; border-radius: 6px; background: var(--surface-2); border-left: 3px solid var(--accent); overflow: hidden; white-space: nowrap; }
.chip .t { font-weight: 600; font-variant-numeric: tabular-nums; }
.chip .x { overflow: hidden; text-overflow: ellipsis; }
.chip.failed, .chip.partial { background: var(--bad-soft); }
.chip.published { opacity: .8; }

/* ── Composer ── */
.acct-pick { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 8px; }
.acct-pick label { display: flex; align-items: center; gap: 8px; padding: 8px 10px; border: 1px solid var(--border); border-radius: 8px; cursor: pointer; }
.acct-pick label.on { border-color: var(--accent); background: var(--accent-soft); }
.acct-pick input { margin: 0; }
.counter { font-size: 12px; color: var(--muted); font-variant-numeric: tabular-nums; }
.counter.over { color: var(--bad); font-weight: 600; }
.drop { border: 1.5px dashed var(--border); border-radius: 10px; padding: 18px; text-align: center; color: var(--muted); cursor: pointer; }
.drop.hover { border-color: var(--accent); background: var(--accent-soft); }
.thumbs { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 10px; }
.thumb { position: relative; width: 84px; height: 84px; border-radius: 8px; overflow: hidden; background: var(--surface-2); border: 1px solid var(--border); }
.thumb img, .thumb video { width: 100%; height: 100%; object-fit: cover; display: block; }
.thumb button { position: absolute; top: 3px; right: 3px; width: 22px; height: 22px; border-radius: 50%; border: 0; background: rgba(0,0,0,.65); color: #fff; cursor: pointer; line-height: 1; }
.thumb .tag { position: absolute; left: 4px; bottom: 4px; background: rgba(0,0,0,.65); color: #fff; font-size: 10px; padding: 0 5px; border-radius: 4px; }
.errors { background: var(--bad-soft); color: var(--bad); border-radius: 8px; padding: 10px 14px; }
.errors ul { margin: 4px 0 0; padding-left: 18px; }
.preview { border: 1px solid var(--border); border-radius: 10px; padding: 12px; background: var(--surface); }
.preview .who { display: flex; align-items: center; gap: 8px; font-weight: 600; margin-bottom: 8px; }
.preview .txt { white-space: pre-wrap; word-break: break-word; font-size: 13.5px; }
.preview .img { margin-top: 8px; border-radius: 8px; overflow: hidden; aspect-ratio: 1 / 1; background: var(--surface-2); }
.preview .img img, .preview .img video { width: 100%; height: 100%; object-fit: cover; display: block; }
.ovr { margin-top: 8px; }
details summary { cursor: pointer; color: var(--accent); font-weight: 550; }

/* ── Charts ── */
.chart { width: 100%; height: 240px; position: relative; }
.chart svg { width: 100%; height: 100%; display: block; overflow: visible; }
.chart .grid-line { stroke: var(--border); stroke-width: 1; }
.chart .axis { fill: var(--muted); font-size: 11px; }
.chart .line { fill: none; stroke: var(--accent); stroke-width: 2; }
.chart .area { fill: var(--accent); opacity: .12; }
.chart .pt { fill: var(--accent); }
.chart .hover-line { stroke: var(--muted); stroke-dasharray: 3 3; }
.tip { position: absolute; pointer-events: none; background: var(--text); color: var(--surface); font-size: 12px; padding: 5px 8px; border-radius: 6px; white-space: nowrap; transform: translate(-50%, -110%); }
.bar-row { display: grid; grid-template-columns: 110px 1fr 70px; gap: 10px; align-items: center; margin: 8px 0; }
.bar-track { height: 10px; background: var(--surface-2); border-radius: 999px; overflow: hidden; }
.bar-fill { height: 100%; border-radius: 999px; }

/* ── Login ── */
.login { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login .card { width: 100%; max-width: 360px; padding: 28px; }
.login img { width: 40px; height: 40px; }

/* ── Toast & modal ── */
.toast { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%) translateY(20px); background: var(--text); color: var(--surface); padding: 10px 16px; border-radius: 8px; opacity: 0; transition: .2s; pointer-events: none; z-index: 50; max-width: calc(100vw - 32px); }
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
.toast.bad { background: var(--bad); color: #fff; }
.modal-bg { position: fixed; inset: 0; background: rgba(0,0,0,.45); display: grid; place-items: center; z-index: 40; padding: 16px; }
.modal { width: 100%; max-width: 520px; max-height: calc(100vh - 32px); overflow: auto; }
.copy { display: flex; gap: 6px; }
.copy input { font-family: ui-monospace, monospace; font-size: 12px; }
ol.steps { padding-left: 18px; margin: 8px 0 0; }
ol.steps li { margin-bottom: 6px; }
.avatar { width: 28px; height: 28px; border-radius: 50%; object-fit: cover; background: var(--surface-2); flex: none; }

/* ── Responsive ── */
@media (max-width: 980px) {
  .g4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .g3, .g2, .compose-grid { grid-template-columns: minmax(0, 1fr); }
}
@media (max-width: 760px) {
  .shell { grid-template-columns: 1fr; }
  .side { display: none; position: fixed; z-index: 30; width: 240px; box-shadow: 0 0 40px rgba(0,0,0,.3); }
  .side.open { display: flex; }
  .mobile-bar { display: flex; align-items: center; gap: 10px; padding: 10px 16px; background: var(--surface); border-bottom: 1px solid var(--border); position: sticky; top: 0; z-index: 20; }
  .main { padding: 16px 16px 64px; }
  .cal .day { min-height: 72px; padding: 4px; }
  .chip .x { display: none; }
  .bar-row { grid-template-columns: 80px 1fr 56px; }
}
