:root {
  --bg: #fbf6ec;
  --surface: #ffffff;
  --surface-2: #f4ecdc;
  --ink: #1d2340;
  --ink-2: #4b5170;
  --muted: #8a8ea3;
  --line: #e7dcc6;
  --navy: #01042d;
  --gold: #e3a92b;
  --gold-ink: #6b4a00;
  --accent: #3a4fb8;
  --ok: #1f7a4d;
  --ok-bg: #e2f3e9;
  --warn: #9a5b00;
  --warn-bg: #fdf0d5;
  --bad: #b3261e;
  --bad-bg: #fbe4e2;
  --ig: #c13584;
  --tt: #111111;
  --radius: 12px;
  --shadow: 0 1px 2px rgba(29, 35, 64, 0.06), 0 4px 16px rgba(29, 35, 64, 0.06);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0d1024;
    --surface: #161a33;
    --surface-2: #1e2342;
    --ink: #eef0fb;
    --ink-2: #b8bcd6;
    --muted: #8187a8;
    --line: #2b3157;
    --gold-ink: #f3c66a;
    --accent: #8fa0ff;
    --ok: #6fd3a0;
    --ok-bg: #12352a;
    --warn: #f3c66a;
    --warn-bg: #3a2e12;
    --bad: #ff8f86;
    --bad-bg: #3d1a1a;
    --ig: #ff6fb8;
    --tt: #e9e9e9;
    color-scheme: dark;
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--ink);
}
a { color: var(--accent); }
button, input, select, textarea { font: inherit; color: inherit; }
h1, h2, h3 { margin: 0 0 8px; line-height: 1.2; }
h2 { font-size: 20px; }
h3 { font-size: 15px; }

/* ---------- shell */
.top {
  position: sticky; top: 0; z-index: 5;
  display: flex; align-items: center; gap: 16px; flex-wrap: wrap;
  padding: 10px 20px; background: var(--navy); color: #fff;
}
.brand { font-weight: 700; letter-spacing: 0.2px; }
.brand span { color: var(--gold); }
.top nav { display: flex; gap: 4px; flex-wrap: wrap; flex: 1; }
.top nav a { color: #d7dbf5; text-decoration: none; padding: 6px 10px; border-radius: 8px; }
.top nav a.on, .top nav a:hover { background: rgba(255, 255, 255, 0.12); color: #fff; }
.top .logout { color: #aab0d8; font-size: 13px; }
main { max-width: 1240px; margin: 0 auto; padding: 20px; }

[hidden] { display: none !important; }
.btn, button {
  border: 1px solid var(--line); background: var(--surface); color: var(--ink);
  padding: 7px 14px; border-radius: 9px; cursor: pointer; white-space: nowrap; text-decoration: none; display: inline-block;
}
button.primary, .btn.primary { background: var(--gold); border-color: var(--gold); color: #2a1d00; font-weight: 600; }
button.danger { color: var(--bad); }
button:disabled { opacity: 0.5; cursor: default; }
.btn-row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }

.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; box-shadow: var(--shadow); }
.grid2 { display: grid; grid-template-columns: minmax(0, 1.25fr) minmax(0, 1fr); gap: 16px; }
@media (max-width: 900px) { .grid2 { grid-template-columns: minmax(0, 1fr); } }
.stack > * + * { margin-top: 12px; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.spacer { flex: 1; }
label { display: block; font-weight: 600; font-size: 13px; color: var(--ink-2); }
label > input, label > select, label > textarea { display: block; width: 100%; margin-top: 4px; font-weight: 400; }
input[type=text], input[type=password], input[type=datetime-local], select, textarea {
  border: 1px solid var(--line); background: var(--surface); border-radius: 8px; padding: 8px 10px;
}
textarea { min-height: 120px; resize: vertical; }
.check { display: flex; gap: 8px; align-items: flex-start; font-weight: 400; color: var(--ink); }
.check > input { display: inline-block; width: auto; margin: 3px 0 0; flex: none; }
.counter { font-weight: 400; font-size: 12px; color: var(--muted); float: right; }
.counter.over { color: var(--bad); font-weight: 600; }

.pill { display: inline-flex; align-items: center; gap: 4px; padding: 1px 8px; border-radius: 99px; font-size: 12px; font-weight: 600; background: var(--surface-2); color: var(--ink-2); }
.pill.draft { background: var(--surface-2); }
.pill.scheduled { background: #e3e7ff; color: #2b3a99; }
.pill.publishing, .pill.processing, .pill.pending { background: var(--warn-bg); color: var(--warn); }
.pill.published, .pill.inbox { background: var(--ok-bg); color: var(--ok); }
.pill.partial { background: var(--warn-bg); color: var(--warn); }
.pill.failed { background: var(--bad-bg); color: var(--bad); }
@media (prefers-color-scheme: dark) { .pill.scheduled { background: #263170; color: #c9d1ff; } }
.pf { display: inline-grid; place-items: center; width: 18px; height: 18px; border-radius: 5px; font-size: 10px; font-weight: 800; color: #fff; }
.pf.instagram { background: var(--ig); }
.pf.tiktok { background: var(--tt); color: var(--bg); }

.notice { border-radius: 10px; padding: 10px 12px; font-size: 14px; }
.notice.bad { background: var(--bad-bg); color: var(--bad); }
.notice.warn { background: var(--warn-bg); color: var(--warn); }
.notice.ok { background: var(--ok-bg); color: var(--ok); }
.notice ul { margin: 4px 0 0; padding-left: 18px; }
#toast { position: fixed; bottom: 18px; left: 50%; transform: translateX(-50%); z-index: 20; max-width: 90vw; }

/* ---------- calendar */
.cal-head { display: flex; align-items: center; gap: 10px; margin-bottom: 12px; flex-wrap: wrap; }
.cal-head h2 { margin: 0; min-width: 170px; }
.cal-layout { display: grid; grid-template-columns: minmax(0, 1fr) 260px; gap: 16px; }
@media (max-width: 980px) { .cal-layout { grid-template-columns: minmax(0, 1fr); } }
.cal { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); gap: 4px; }
.cal .dow { font-size: 12px; font-weight: 700; color: var(--muted); text-align: center; padding: 4px 0; }
.day { min-height: 112px; background: var(--surface); border: 1px solid var(--line); border-radius: 10px; padding: 6px; display: flex; flex-direction: column; gap: 4px; cursor: pointer; }
.day.other { opacity: 0.45; }
.day.today { border-color: var(--gold); box-shadow: inset 0 0 0 1px var(--gold); }
.day.drop { background: var(--surface-2); }
.day .num { font-size: 12px; font-weight: 700; color: var(--ink-2); }
.chip { display: flex; gap: 4px; align-items: center; font-size: 12px; padding: 3px 5px; border-radius: 7px; background: var(--surface-2); border-left: 3px solid var(--muted); cursor: grab; overflow: hidden; }
.chip .t { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; flex: 1; }
.chip.scheduled { border-left-color: var(--accent); }
.chip.published, .chip.inbox { border-left-color: var(--ok); }
.chip.partial, .chip.publishing { border-left-color: var(--gold); }
.chip.failed { border-left-color: var(--bad); }
.chip .pf { width: 14px; height: 14px; font-size: 8px; border-radius: 4px; }
.drafts .chip { margin-bottom: 6px; padding: 6px 8px; }
@media (max-width: 640px) {
  .day { min-height: 64px; padding: 4px; }
  .day .chip .t, .day .chip .pf { display: none; }
}

/* ---------- editor */
.media-groups { display: grid; gap: 12px; }
.media-group { border: 1px dashed var(--line); border-radius: 10px; padding: 10px; }
.media-group.dragover { background: var(--surface-2); }
.thumbs { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 8px; }
.thumb { position: relative; width: 92px; }
.thumb img, .thumb video { width: 92px; height: 120px; object-fit: cover; border-radius: 8px; background: var(--surface-2); display: block; }
.thumb .idx { position: absolute; top: 4px; left: 4px; background: rgba(1, 4, 45, 0.75); color: #fff; font-size: 11px; padding: 0 6px; border-radius: 99px; }
.thumb .tools { display: flex; justify-content: space-between; margin-top: 2px; }
.thumb .tools button { border: 0; background: none; cursor: pointer; padding: 2px 6px; color: var(--ink-2); }
.target { border: 1px solid var(--line); border-radius: 10px; padding: 12px; }
.target h3 { display: flex; gap: 8px; align-items: center; }
.creator { display: flex; gap: 10px; align-items: center; }
.creator img { width: 36px; height: 36px; border-radius: 50%; }
.preview-strip { display: flex; gap: 6px; overflow-x: auto; padding-bottom: 4px; }
.preview-strip img, .preview-strip video { height: 140px; border-radius: 8px; }

/* ---------- tables + analytics */
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th, td { padding: 8px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: middle; }
th { font-size: 12px; color: var(--muted); font-weight: 700; cursor: pointer; user-select: none; white-space: nowrap; }
td.n, th.n { text-align: right; font-variant-numeric: tabular-nums; }
.table-wrap { overflow-x: auto; }
td img.cover { width: 40px; height: 52px; object-fit: cover; border-radius: 6px; display: block; }
td .cap { max-width: 360px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 16px; }
.stat .big { font-size: 34px; font-weight: 800; font-variant-numeric: tabular-nums; }
.stat .delta { font-size: 13px; color: var(--ink-2); }
.chart { position: relative; }
.chart svg { display: block; width: 100%; height: 140px; overflow: visible; }
.chart .tip { position: absolute; pointer-events: none; background: var(--navy); color: #fff; font-size: 12px; padding: 4px 8px; border-radius: 6px; transform: translate(-50%, -110%); white-space: nowrap; display: none; }
.chart .axis { fill: var(--muted); font-size: 10px; }
.chart .grid { stroke: var(--line); stroke-width: 1; }
.chart .line { fill: none; stroke: var(--accent); stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.chart .dot { fill: var(--accent); stroke: var(--surface); stroke-width: 2; }
.chart .cross { stroke: var(--muted); stroke-dasharray: 3 3; }

/* ---------- accounts */
.acct { display: flex; gap: 14px; align-items: center; }
.acct img { width: 52px; height: 52px; border-radius: 50%; background: var(--surface-2); }
ol.steps { padding-left: 20px; margin: 6px 0; }
ol.steps li { margin: 4px 0; }
code { background: var(--surface-2); padding: 1px 5px; border-radius: 5px; font-size: 13px; }

/* ---------- login */
body.login { display: grid; place-items: center; min-height: 100vh; background: var(--navy); }
.login-card { background: var(--surface); padding: 28px; border-radius: 16px; width: min(360px, 92vw); display: grid; gap: 14px; box-shadow: var(--shadow); }
.login-card h1 { font-size: 22px; }
.login-card h1 span { color: var(--gold-ink); }
.login-card .error { color: var(--bad); margin: 0; }
@media (max-width: 640px) {
  .top { padding: 8px 12px; gap: 8px; }
  .top nav { order: 3; flex-basis: 100%; overflow-x: auto; flex-wrap: nowrap; }
  .brand { flex: 1; }
  main { padding: 12px; }
}
