:root {
  --bg: #f4f5f9;
  --card: #ffffff;
  --text: #171923;
  --muted: #6b7280;
  --line: #e5e7eb;
  --brand: #4f46e5;
  --brand-soft: #eef2ff;
  --ok: #059669;
  --ok-soft: #d1fae5;
  --warn: #b45309;
  --warn-soft: #fef3c7;
  --bad: #dc2626;
  --bad-soft: #fee2e2;
  --info: #2563eb;
  --info-soft: #dbeafe;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(0, 0, 0, .04), 0 4px 16px rgba(0, 0, 0, .04);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1117;
    --card: #181b24;
    --text: #e8eaf0;
    --muted: #9aa1b2;
    --line: #2a2f3c;
    --brand: #818cf8;
    --brand-soft: #23264a;
    --ok: #34d399;
    --ok-soft: #0f2e25;
    --warn: #fbbf24;
    --warn-soft: #33290f;
    --bad: #f87171;
    --bad-soft: #3a1717;
    --info: #60a5fa;
    --info-soft: #172743;
    --shadow: none;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: "Segoe UI", Tahoma, "Noto Kufi Arabic", "Noto Sans Arabic", system-ui, sans-serif;
  font-size: 15px;
  line-height: 1.6;
}
a { color: var(--brand); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3 { margin: 0; line-height: 1.3; }
h1 { font-size: 22px; }
h2 { font-size: 18px; }
h3 { font-size: 16px; }

/* ---------- layout ---------- */
.topbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; gap: 16px;
  padding: 10px 20px;
  background: var(--card);
  border-bottom: 1px solid var(--line);
}
.logo { font-weight: 700; font-size: 17px; white-space: nowrap; }
.logo span { color: var(--brand); }
nav { display: flex; gap: 4px; flex: 1; overflow-x: auto; }
nav a {
  padding: 7px 14px; border-radius: 10px; color: var(--muted); white-space: nowrap; font-weight: 500;
}
nav a:hover { background: var(--bg); text-decoration: none; }
nav a.active { background: var(--brand-soft); color: var(--brand); }
main { max-width: 1180px; margin: 0 auto; padding: 24px 16px 60px; }
.page-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 20px; flex-wrap: wrap; }

.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 18px;
}
.grid { display: grid; gap: 16px; }
.grid-2 { grid-template-columns: repeat(auto-fill, minmax(min(100%, 520px), 1fr)); }
.stack { display: flex; flex-direction: column; gap: 16px; }
.row { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.spacer { flex: 1; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.section-title { margin: 28px 0 12px; }

/* ---------- KPIs ---------- */
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 12px; }
.kpi { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; box-shadow: var(--shadow); }
.kpi .n { font-size: 28px; font-weight: 700; font-variant-numeric: tabular-nums; }
.kpi .l { color: var(--muted); font-size: 13px; }
.kpi.ok .n { color: var(--ok); }
.kpi.info .n { color: var(--info); }
.kpi.warn .n { color: var(--warn); }
.kpi.bad .n { color: var(--bad); }

/* ---------- brand card ---------- */
.brand-head { display: flex; align-items: center; gap: 10px; margin-bottom: 14px; }
.dot { width: 12px; height: 12px; border-radius: 50%; flex: none; background: var(--brand); }
.mini-kpis { display: grid; grid-template-columns: repeat(5, 1fr); gap: 8px; margin-bottom: 14px; }
.mini-kpis div { background: var(--bg); border-radius: 10px; padding: 8px; text-align: center; }
.mini-kpis b { display: block; font-size: 20px; font-variant-numeric: tabular-nums; }
.mini-kpis span { font-size: 12px; color: var(--muted); }
.mini-kpis .ok b { color: var(--ok); }
.mini-kpis .info b { color: var(--info); }
.mini-kpis .warn b { color: var(--warn); }
.mini-kpis .bad b { color: var(--bad); }

table { width: 100%; border-collapse: collapse; font-size: 14px; }
th { text-align: start; font-weight: 500; color: var(--muted); font-size: 12px; padding: 6px 6px; border-bottom: 1px solid var(--line); }
td { padding: 8px 6px; border-bottom: 1px solid var(--line); font-variant-numeric: tabular-nums; }
tr:last-child td { border-bottom: 0; }
.table-wrap { overflow-x: auto; }

/* ---------- platform badges ---------- */
.pf { display: inline-flex; align-items: center; gap: 6px; font-weight: 500; white-space: nowrap; }
.pf svg { width: 18px; height: 18px; flex: none; }
.pf-youtube svg { color: #ff0000; }
.pf-tiktok svg { color: var(--text); }
.pf-instagram svg { color: #e1306c; }
.pf-x svg { color: var(--text); }

.avatar { width: 34px; height: 34px; border-radius: 50%; object-fit: cover; background: var(--bg); flex: none; }

/* ---------- badges ---------- */
.badge { display: inline-flex; align-items: center; gap: 4px; padding: 2px 10px; border-radius: 999px; font-size: 12px; font-weight: 600; white-space: nowrap; }
.b-draft { background: var(--bg); color: var(--muted); border: 1px solid var(--line); }
.b-scheduled, .b-pending { background: var(--info-soft); color: var(--info); }
.b-publishing { background: var(--warn-soft); color: var(--warn); }
.b-published { background: var(--ok-soft); color: var(--ok); }
.b-partial { background: var(--warn-soft); color: var(--warn); }
.b-failed { background: var(--bad-soft); color: var(--bad); }

/* ---------- buttons & forms ---------- */
button, .btn {
  font: inherit; cursor: pointer;
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 8px 16px; border-radius: 10px;
  border: 1px solid var(--line); background: var(--card); color: var(--text);
  font-weight: 500; white-space: nowrap;
}
button:hover, .btn:hover { border-color: var(--brand); text-decoration: none; }
button:disabled { opacity: .5; cursor: not-allowed; }
.primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.primary:hover { filter: brightness(1.08); }
.danger { color: var(--bad); }
.danger:hover { border-color: var(--bad); }
.sm { padding: 4px 10px; font-size: 13px; border-radius: 8px; }
.ghost { border-color: transparent; background: transparent; }

label { display: block; font-weight: 500; margin-bottom: 6px; }
input[type=text], input[type=password], input[type=datetime-local], select, textarea {
  width: 100%; font: inherit; color: var(--text);
  padding: 10px 12px; border-radius: 10px;
  border: 1px solid var(--line); background: var(--card);
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--brand); outline-offset: -1px; border-color: transparent; }
textarea { min-height: 150px; resize: vertical; }
input[type=number] { width: 70px; font: inherit; color: var(--text); padding: 9px 8px; border-radius: 10px; border: 1px solid var(--line); background: var(--card); text-align: center; }
.goal-input { display: flex; align-items: center; gap: 6px; }
.brand-head { flex-wrap: wrap; }
input[type=color] { width: 44px; height: 40px; padding: 2px; border: 1px solid var(--line); border-radius: 10px; background: var(--card); }
.field { margin-bottom: 16px; }
.hint { font-size: 12px; color: var(--muted); margin-top: 4px; }
.hint.bad { color: var(--bad); }

.choices { display: flex; flex-wrap: wrap; gap: 8px; }
.choice {
  display: inline-flex; align-items: center; gap: 8px; margin: 0;
  padding: 8px 14px; border: 1px solid var(--line); border-radius: 12px; cursor: pointer; font-weight: 500;
  background: var(--card);
}
.choice:has(input:checked) { border-color: var(--brand); background: var(--brand-soft); }
.choice.disabled { opacity: .5; cursor: not-allowed; }
.choice input { margin: 0; accent-color: var(--brand); }

.drop {
  border: 2px dashed var(--line); border-radius: var(--radius); padding: 22px; text-align: center; cursor: pointer;
  color: var(--muted);
}
.drop:hover, .drop.over { border-color: var(--brand); color: var(--brand); }
.drop input { display: none; }
.preview { max-width: 100%; max-height: 320px; border-radius: 12px; display: block; margin: 0 auto; background: #000; }
.progress { height: 8px; border-radius: 99px; background: var(--bg); overflow: hidden; margin-top: 10px; }
.progress > div { height: 100%; width: 0; background: var(--brand); transition: width .2s; }

.compose { display: grid; grid-template-columns: minmax(0, 1fr) 340px; gap: 16px; align-items: start; }
@media (max-width: 900px) { .compose { grid-template-columns: 1fr; } .mini-kpis { grid-template-columns: repeat(3, 1fr); } }

/* ---------- post list ---------- */
.post { display: grid; grid-template-columns: 88px minmax(0, 1fr); gap: 14px; }
.thumb { width: 88px; height: 88px; border-radius: 10px; object-fit: cover; background: var(--bg); display: flex; align-items: center; justify-content: center; color: var(--muted); font-size: 12px; overflow: hidden; }
.thumb video, .thumb img { width: 100%; height: 100%; object-fit: cover; }
.caption { white-space: pre-wrap; overflow-wrap: anywhere; display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; }
.targets { display: flex; flex-direction: column; gap: 4px; margin-top: 8px; }
.target { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; font-size: 13px; }
.target .err { color: var(--bad); font-size: 12px; overflow-wrap: anywhere; }
.target .note { color: var(--muted); font-size: 12px; }

.list-item { display: flex; align-items: center; gap: 10px; padding: 10px 0; border-bottom: 1px solid var(--line); }
.list-item:last-child { border-bottom: 0; }

.empty { text-align: center; padding: 40px 16px; color: var(--muted); }
.alert { padding: 12px 16px; border-radius: 12px; margin-bottom: 16px; }
.alert.warn { background: var(--warn-soft); color: var(--warn); }
.alert.bad { background: var(--bad-soft); color: var(--bad); }
.alert.info { background: var(--info-soft); color: var(--info); }
code { font-family: Consolas, monospace; font-size: 12px; background: var(--bg); padding: 1px 6px; border-radius: 6px; direction: ltr; unicode-bidi: embed; overflow-wrap: anywhere; }

/* ---------- weekly goal ---------- */
.goal { background: var(--bg); border-radius: 12px; padding: 10px 12px; margin-bottom: 14px; }
.goal .row { gap: 12px; }
.goalbar { display: flex; height: 10px; border-radius: 99px; background: var(--line); overflow: hidden; margin: 8px 0 6px; }
.goalbar .done { background: var(--ok); }
.goalbar .planned { background: var(--info); }
.ok-text { color: var(--ok); font-weight: 600; }
.info-text { color: var(--info); font-weight: 600; }
.warn-text { color: var(--warn); font-weight: 600; }
.goal-row { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 12px; margin-bottom: 16px; }
.goal-chip { padding: 12px 14px; }

/* ---------- calendar ---------- */
.week { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); gap: 8px; }
@media (max-width: 1000px) { .week { grid-template-columns: 1fr; } }
.day { background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 8px; min-height: 180px; display: flex; flex-direction: column; gap: 6px; }
.day.today { border-color: var(--brand); box-shadow: 0 0 0 1px var(--brand); }
.day.past { opacity: .75; }
.day-head { font-size: 13px; font-weight: 600; color: var(--muted); padding-bottom: 4px; border-bottom: 1px solid var(--line); }
.day.today .day-head { color: var(--brand); }
.cal-item { display: block; background: var(--bg); border-radius: 8px; padding: 6px 8px; color: var(--text); border-inline-start: 4px solid var(--brand); }
.cal-item:hover { text-decoration: none; filter: brightness(.97); }
.cal-item .badge { font-size: 10px; padding: 0 6px; }
.cal-item .pf svg { width: 14px; height: 14px; }
.cal-title { font-size: 13px; overflow: hidden; text-overflow: ellipsis; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow-wrap: anywhere; }
.day-add { margin-top: auto; text-align: center; padding: 6px; border: 1px dashed var(--line); border-radius: 8px; color: var(--muted); font-size: 13px; }
.day-add:hover { border-color: var(--brand); color: var(--brand); text-decoration: none; }

/* ---------- cover ---------- */
.cover-box { margin-top: 12px; padding: 12px; border: 1px solid var(--line); border-radius: 12px; }
.cover-thumb { width: 72px; height: 96px; object-fit: cover; border-radius: 8px; background: #000; }

/* ---------- toast ---------- */
#toast {
  position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%) translateY(120px);
  background: var(--text); color: var(--bg); padding: 12px 20px; border-radius: 12px; z-index: 50;
  transition: transform .25s, opacity .25s; max-width: calc(100% - 32px); font-weight: 500;
  opacity: 0; visibility: hidden;
}
#toast.show { transform: translateX(-50%) translateY(0); opacity: 1; visibility: visible; }
#toast.bad { background: var(--bad); color: #fff; }

/* ---------- login ---------- */
.login-wrap { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 16px; }
.login { width: 100%; max-width: 380px; }
.login h1 { margin-bottom: 4px; }
.login p { margin: 0 0 20px; }
.login button { width: 100%; margin-top: 4px; padding: 11px; }
.err-box { color: var(--bad); min-height: 22px; font-size: 14px; margin-bottom: 8px; }

/* public privacy / terms pages */
.legal { max-width: 760px; margin: 40px auto; padding: 0 16px 40px; line-height: 1.7; }
.legal h1 { margin-bottom: 8px; }
.legal h2 { font-size: 18px; margin-top: 24px; }
.legal hr { border: 0; border-top: 1px solid var(--line); margin: 32px 0; }
