:root {
  --bg: #f7f3f0;
  --surface: #ffffff;
  --surface-2: #fbf8f6;
  --ink: #2b1f2a;
  --ink-2: #6b5c69;
  --ink-3: #9a8c98;
  --line: #ebe3df;
  --brand: #8a3b5c;
  --brand-ink: #ffffff;
  --brand-soft: #f6e8ee;
  --ok: #2f7d5b;
  --ok-soft: #e4f3ec;
  --warn: #a8641a;
  --warn-soft: #fbeedd;
  --bad: #b23b3b;
  --bad-soft: #f9e3e3;
  --info: #3b5f8a;
  --info-soft: #e5edf7;
  --radius: 12px;
  --shadow: 0 1px 2px rgba(43, 31, 42, .06), 0 4px 16px rgba(43, 31, 42, .04);
  font-family: "IBM Plex Sans Arabic", "Segoe UI", Tahoma, sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--ink);
  font-size: 15px;
  line-height: 1.6;
}
a { color: var(--brand); }
button, input, select, textarea { font: inherit; color: inherit; }

/* ---------- layout ---------- */
.app { display: grid; grid-template-columns: 240px 1fr; min-height: 100vh; }
.side {
  background: var(--ink);
  color: #f3ebef;
  padding: 24px 16px;
  position: sticky; top: 0; height: 100vh;
  display: flex; flex-direction: column; gap: 24px;
}
.brand { padding: 0 8px; }
.brand-name { font-size: 18px; font-weight: 700; }
.brand-sub { font-size: 13px; color: #bfaebb; }
.nav { display: flex; flex-direction: column; gap: 2px; }
.nav a {
  color: #d9ccd5; text-decoration: none;
  padding: 9px 12px; border-radius: 8px;
  display: flex; align-items: center; justify-content: space-between;
}
.nav a:hover { background: rgba(255, 255, 255, .06); color: #fff; }
.nav a.active { background: rgba(255, 255, 255, .12); color: #fff; font-weight: 600; }
.nav .count {
  background: var(--warn); color: #fff; font-size: 12px;
  min-width: 22px; padding: 0 6px; border-radius: 99px; text-align: center;
}
.side-foot { margin-top: auto; font-size: 12px; color: #9e8e9a; padding: 0 8px; }

.main { padding: 28px 32px 60px; max-width: 1180px; width: 100%; }
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; margin-bottom: 20px; flex-wrap: wrap; }
.page-head h1 { margin: 0; font-size: 24px; }
.page-head p { margin: 2px 0 0; color: var(--ink-2); }

/* ---------- surfaces ---------- */
.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 20px;
}
.card + .card, .stack > * + * { margin-top: 16px; }
.card h2 { margin: 0 0 4px; font-size: 17px; }
.card .hint { color: var(--ink-2); margin: 0 0 14px; font-size: 14px; }
.grid { display: grid; gap: 16px; }
.grid.kpis { grid-template-columns: repeat(4, 1fr); }
.grid.two { grid-template-columns: 1fr 1fr; }

.kpi { padding: 16px 18px; }
.kpi .label { color: var(--ink-2); font-size: 13px; }
.kpi .value { font-size: 28px; font-weight: 700; line-height: 1.2; margin-top: 4px; font-variant-numeric: tabular-nums; }
.kpi .sub { color: var(--ink-3); font-size: 12px; }
.kpi.accent { background: var(--brand); color: var(--brand-ink); border-color: var(--brand); }
.kpi.accent .label, .kpi.accent .sub { color: #f1d9e3; }

/* ---------- forms ---------- */
.row { display: flex; gap: 10px; flex-wrap: wrap; align-items: end; }
.field { display: flex; flex-direction: column; gap: 4px; min-width: 160px; }
.field label { font-size: 13px; color: var(--ink-2); }
input, select, textarea {
  border: 1px solid var(--line); background: var(--surface);
  border-radius: 8px; padding: 9px 12px; outline: none;
}
input:focus, select:focus, textarea:focus { border-color: var(--brand); box-shadow: 0 0 0 3px var(--brand-soft); }
textarea { min-height: 130px; resize: vertical; width: 100%; direction: ltr; text-align: left; }

.btn {
  border: 1px solid var(--line); background: var(--surface);
  border-radius: 8px; padding: 8px 14px; cursor: pointer;
  display: inline-flex; align-items: center; gap: 6px; white-space: nowrap;
  text-decoration: none; color: var(--ink);
}
.btn:hover { background: var(--surface-2); }
.btn.primary { background: var(--brand); border-color: var(--brand); color: var(--brand-ink); }
.btn.primary:hover { filter: brightness(1.08); }
.btn.ok { background: var(--ok); border-color: var(--ok); color: #fff; }
.btn.danger { color: var(--bad); }
.btn.small { padding: 4px 10px; font-size: 13px; }
.btn:disabled { opacity: .5; cursor: default; }

.chip {
  border: 1px solid var(--line); background: var(--surface);
  border-radius: 99px; padding: 3px 11px; font-size: 13px; cursor: pointer;
}
.chip.on { background: var(--brand-soft); border-color: var(--brand); color: var(--brand); font-weight: 600; }

/* ---------- badges ---------- */
.badge { display: inline-block; font-size: 12px; padding: 1px 9px; border-radius: 99px; background: var(--surface-2); color: var(--ink-2); border: 1px solid var(--line); }
.badge.queued { }
.badge.assigned { background: var(--info-soft); color: var(--info); border-color: transparent; }
.badge.followed { background: var(--warn-soft); color: var(--warn); border-color: transparent; }
.badge.followed_back { background: var(--ok-soft); color: var(--ok); border-color: transparent; }
.badge.unfollowed { background: var(--bad-soft); color: var(--bad); border-color: transparent; }
.badge.skipped { color: var(--ink-3); }

/* ---------- task list ---------- */
.progress { height: 8px; background: var(--line); border-radius: 99px; overflow: hidden; margin: 10px 0 4px; }
.progress > span { display: block; height: 100%; background: var(--ok); border-radius: 99px; transition: width .3s; }

.tasks { display: flex; flex-direction: column; gap: 8px; }
.task {
  display: grid; grid-template-columns: 1fr auto; gap: 10px; align-items: center;
  border: 1px solid var(--line); border-radius: 10px; padding: 10px 14px; background: var(--surface);
}
.task.done { background: var(--surface-2); }
.task.done .handle { color: var(--ink-2); }
.task .handle { font-weight: 600; direction: ltr; unicode-bidi: isolate; text-decoration: none; color: var(--ink); }
.task .handle:hover { color: var(--brand); text-decoration: underline; }
.task .meta { font-size: 12px; color: var(--ink-3); display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin-top: 2px; }
.task .actions { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; justify-content: flex-end; }

/* ---------- tables ---------- */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th, td { text-align: right; padding: 9px 10px; border-bottom: 1px solid var(--line); vertical-align: middle; }
th { font-weight: 600; color: var(--ink-2); font-size: 13px; background: var(--surface-2); }
td.num, th.num { text-align: left; font-variant-numeric: tabular-nums; }
td .ltr { direction: ltr; unicode-bidi: isolate; }
tbody tr:hover { background: var(--surface-2); }

/* ---------- misc ---------- */
.empty { text-align: center; color: var(--ink-2); padding: 28px 12px; }
.empty strong { display: block; color: var(--ink); font-size: 16px; margin-bottom: 4px; }
.steps { margin: 0; padding-inline-start: 20px; color: var(--ink-2); }
.steps li { margin: 6px 0; }
.steps li.done { color: var(--ok); text-decoration: line-through; }
.muted { color: var(--ink-3); }
.section-title { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 10px; }
.section-title h2 { margin: 0; }

.chart { width: 100%; height: 200px; display: block; }
.legend { display: flex; gap: 16px; font-size: 13px; color: var(--ink-2); margin-top: 8px; }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-inline-end: 6px; vertical-align: middle; }

.toast {
  position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%) translateY(20px);
  background: var(--ink); color: #fff; padding: 10px 18px; border-radius: 10px;
  opacity: 0; transition: all .25s; pointer-events: none; z-index: 50; box-shadow: var(--shadow);
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
.toast.error { background: var(--bad); }

@media (max-width: 900px) {
  .app { grid-template-columns: 1fr; }
  .side { position: static; height: auto; padding: 14px; gap: 10px; }
  .nav { flex-direction: row; flex-wrap: wrap; }
  .side-foot { display: none; }
  .main { padding: 18px 14px 50px; }
  .grid.kpis { grid-template-columns: repeat(2, 1fr); }
  .grid.two { grid-template-columns: 1fr; }
  .task { grid-template-columns: 1fr; }
  .task .actions { justify-content: flex-start; }
}

/* ===================== v2 additions ===================== */
[hidden] { display: none !important; }

/* auth */
.auth { min-height: 100vh; display: grid; place-items: center; padding: 24px; background: var(--ink); }
.auth-card {
  width: 100%; max-width: 400px; background: var(--surface); border-radius: 16px; padding: 28px;
  display: flex; flex-direction: column; gap: 12px; box-shadow: 0 20px 60px rgba(0, 0, 0, .3);
}
.auth-card h1 { margin: 0; font-size: 20px; }
.auth-card .hint { margin: 0; }
.auth-card hr { border: 0; border-top: 1px solid var(--line); width: 100%; margin: 4px 0; }
.auth-brand { font-size: 28px; font-weight: 700; color: var(--brand); }
.btn.block { width: 100%; justify-content: center; padding: 11px; }

/* sidebar */
.client-switch {
  margin-top: 6px; width: 100%; background: rgba(255, 255, 255, .08); color: #fff;
  border: 1px solid rgba(255, 255, 255, .15); padding: 7px 10px;
}
.client-switch option { color: var(--ink); }
.client-switch:disabled { opacity: 1; }
.side-foot { display: flex; flex-direction: column; gap: 4px; }
.link { background: none; border: 0; padding: 0; color: #d9ccd5; cursor: pointer; text-align: start; text-decoration: underline; }
.link:hover { color: #fff; }

/* layout helpers */
.grow { flex: 1; min-width: 200px; }
.nowrap { white-space: nowrap; }
.small { font-size: 12px; }
.strong { font-weight: 600; }
.ltr { direction: ltr; unicode-bidi: isolate; }
.stack-form .field { min-width: 0; }
.loading { color: var(--ink-3); padding: 40px; text-align: center; }
textarea.rtl { direction: rtl; text-align: right; }
code { background: var(--surface-2); border: 1px solid var(--line); border-radius: 6px; padding: 1px 6px; font-size: 13px; }
.btn.ghost { border-color: transparent; background: transparent; color: var(--ink-2); }
.btn.ghost:hover { background: var(--surface-2); }
.alert {
  background: var(--warn-soft); color: var(--warn); border: 1px solid #f1d6b0;
  border-radius: 10px; padding: 10px 14px; margin-bottom: 16px;
}
.alert a { color: inherit; font-weight: 600; }
.error-text { color: var(--bad); font-size: 13px; margin-top: 4px; }
.note-cell { max-width: 200px; font-size: 13px; color: var(--ink-2); }
.caption-cell { max-width: 380px; }
.badge.draft { }
.badge.scheduled { background: var(--info-soft); color: var(--info); border-color: transparent; }
.badge.publishing { background: var(--warn-soft); color: var(--warn); border-color: transparent; }
.badge.published { background: var(--ok-soft); color: var(--ok); border-color: transparent; }
.badge.failed { background: var(--bad-soft); color: var(--bad); border-color: transparent; }
.badge + .badge { margin-inline-start: 4px; }
.checks { display: flex; flex-wrap: wrap; gap: 8px 16px; }
.check { display: inline-flex; align-items: center; gap: 6px; font-size: 14px; color: var(--ink); }
.steps.small li { margin: 3px 0; font-size: 14px; }

/* modal */
.modal-backdrop {
  position: fixed; inset: 0; background: rgba(43, 31, 42, .45); z-index: 40;
  display: grid; place-items: center; padding: 20px; overflow-y: auto;
}
.modal { background: var(--surface); border-radius: 14px; width: 100%; max-width: 640px; padding: 20px 22px; box-shadow: 0 20px 60px rgba(0, 0, 0, .25); }
.modal-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 14px; }
.modal-head h2 { margin: 0; font-size: 18px; }

/* tabs */
.tabs { display: flex; gap: 4px; margin-bottom: 16px; border-bottom: 1px solid var(--line); }
.tabs a { padding: 8px 16px; text-decoration: none; color: var(--ink-2); border-bottom: 2px solid transparent; margin-bottom: -1px; }
.tabs a.on { color: var(--brand); border-color: var(--brand); font-weight: 600; }

/* media + inbox */
.thumb { width: 52px; height: 52px; object-fit: cover; border-radius: 8px; background: var(--surface-2); display: inline-grid; place-items: center; font-size: 11px; color: var(--ink-2); }
.thumb.vid { border: 1px solid var(--line); }
.thumb-cell { width: 60px; }
.media-head { display: flex; gap: 12px; align-items: center; margin-bottom: 12px; }
.comments { display: flex; flex-direction: column; gap: 10px; }
.comment { border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; }
.comment.hidden-c { opacity: .6; }
.comment-text { margin: 4px 0; }
.reply { margin: 4px 16px 0 0; padding-inline-start: 10px; border-inline-start: 2px solid var(--line); font-size: 14px; color: var(--ink-2); }
.reply-row { margin-top: 8px; align-items: center; }
.reply-row input { padding: 6px 10px; }
.thread { display: flex; flex-direction: column; gap: 6px; margin: 8px 0; max-height: 320px; overflow-y: auto; }
.bubble { align-self: flex-start; background: var(--surface-2); border: 1px solid var(--line); border-radius: 12px; padding: 6px 12px; max-width: 75%; }
.bubble.me { align-self: flex-end; background: var(--brand-soft); border-color: transparent; }

/* print (reports → PDF) */
@media print {
  .side, .page-head .row, .btn, .tabs, .toast { display: none !important; }
  .app { display: block; }
  .main { padding: 0; max-width: none; }
  body { background: #fff; }
  .card { box-shadow: none; break-inside: avoid; }
}
