:root {
  --bg: #f7f1ea;
  --surface: #ffffff;
  --surface-2: #f1e8dd;
  --border: #e3d6c6;
  --text: #2b1d14;
  --muted: #7a6656;
  --accent: #8b4a25;
  --accent-ink: #ffffff;
  --accent-soft: #f3e1d3;
  --danger: #b3261e;
  --ok: #2f6f5e;
  --warn: #a86a00;
  --ig: #c13584;
  --tt: #111111;
  --sc: #e6c200;
  --radius: 12px;
  --shadow: 0 1px 2px rgb(43 29 20 / .06), 0 4px 16px rgb(43 29 20 / .06);
  font-family: 'IBM Plex Sans Arabic', system-ui, -apple-system, 'Segoe UI', Tahoma, sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #1a130e;
    --surface: #241a13;
    --surface-2: #2e2219;
    --border: #3d2e22;
    --text: #f3e7d8;
    --muted: #b49f8b;
    --accent: #d98a55;
    --accent-ink: #1a130e;
    --accent-soft: #3a281c;
    --tt: #e8e8e8;
    --shadow: none;
  }
}
:root[data-theme="dark"] {
  --bg: #1a130e; --surface: #241a13; --surface-2: #2e2219; --border: #3d2e22; --text: #f3e7d8;
  --muted: #b49f8b; --accent: #d98a55; --accent-ink: #1a130e; --accent-soft: #3a281c; --tt: #e8e8e8; --shadow: none;
}

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

/* ---------- top bar ---------- */
.topbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; gap: 16px; flex-wrap: wrap;
  padding: 10px 16px; background: var(--surface); border-bottom: 1px solid var(--border);
}
.brand { display: flex; align-items: center; gap: 8px; font-weight: 700; font-size: 17px; }
.brand-mark { font-size: 20px; }
.tabs { display: flex; gap: 4px; overflow-x: auto; }
.tabs a {
  padding: 6px 14px; border-radius: 999px; text-decoration: none; color: var(--muted); white-space: nowrap; font-weight: 500;
}
.tabs a.active { background: var(--accent); color: var(--accent-ink); }
.me { margin-inline-start: auto; color: var(--muted); font-size: 13px; }
.me b { color: var(--text); font-weight: 600; }

main { padding: 16px; max-width: 1400px; margin: 0 auto; }
.loading, .empty { color: var(--muted); padding: 32px; text-align: center; }

/* ---------- generic ---------- */
.toolbar { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin-bottom: 14px; }
.toolbar h2 { margin: 0 4px; font-size: 20px; min-width: 9ch; }
.toolbar .spacer { flex: 1; }
.btn {
  border: 1px solid var(--border); background: var(--surface); padding: 7px 14px; border-radius: 10px; cursor: pointer;
  display: inline-flex; align-items: center; gap: 6px; font-weight: 500;
}
.btn:hover { border-color: var(--accent); }
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.btn.danger { color: var(--danger); }
.btn.ghost { background: transparent; border-color: transparent; }
.btn[disabled] { opacity: .5; cursor: not-allowed; }
.seg { display: inline-flex; border: 1px solid var(--border); border-radius: 10px; overflow: hidden; }
.seg button { border: 0; background: var(--surface); padding: 7px 12px; cursor: pointer; }
.seg button.on { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
select, input, textarea {
  border: 1px solid var(--border); background: var(--surface); border-radius: 10px; padding: 7px 10px; min-width: 0;
}
textarea { resize: vertical; min-height: 80px; }
select:focus, input:focus, textarea:focus, .btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); }
.muted { color: var(--muted); }
.small { font-size: 12.5px; }

.badge {
  display: inline-flex; align-items: center; justify-content: center; font-size: 10.5px; font-weight: 700;
  min-width: 22px; height: 18px; padding: 0 5px; border-radius: 5px; color: #fff; letter-spacing: .3px; direction: ltr;
}
.badge.instagram { background: var(--ig); }
.badge.tiktok { background: var(--tt); color: var(--bg); }
.badge.snapchat { background: var(--sc); color: #111; }
.pill { display: inline-block; font-size: 12px; padding: 1px 8px; border-radius: 999px; background: var(--surface-2); color: var(--muted); }
.pill.published { background: #dcefe7; color: var(--ok); }
.pill.cancelled { text-decoration: line-through; }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .pill.published { background: #1f3a31; color: #8fd3bb; } }

/* ---------- calendar ---------- */
.cal { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); gap: 1px; background: var(--border); border-radius: var(--radius); overflow: hidden; border: 1px solid var(--border); }
.cal .dow { background: var(--surface-2); padding: 6px; text-align: center; font-size: 12.5px; color: var(--muted); font-weight: 600; }
.cal .day { background: var(--surface); min-height: 112px; padding: 6px; display: flex; flex-direction: column; gap: 4px; position: relative; }
.cal.week .day { min-height: 360px; }
.cal .day.out { background: var(--surface-2); opacity: .7; }
.cal .day.today { box-shadow: inset 0 0 0 2px var(--accent); }
.cal .num { font-size: 12.5px; color: var(--muted); display: flex; justify-content: space-between; align-items: center; }
.cal .day.today .num b { background: var(--accent); color: var(--accent-ink); border-radius: 999px; padding: 0 7px; }
.cal .add { opacity: 0; border: 0; background: var(--accent-soft); color: var(--accent); border-radius: 6px; width: 22px; height: 22px; cursor: pointer; font-size: 16px; line-height: 1; }
.cal .day:hover .add, .cal .add:focus { opacity: 1; }
.chip {
  display: flex; align-items: center; gap: 5px; font-size: 12.5px; padding: 3px 6px; border-radius: 7px; cursor: pointer;
  background: var(--surface-2); border-inline-start: 3px solid var(--c, var(--border)); text-align: start; border-top: 0; border-bottom: 0; border-inline-end: 0; width: 100%;
}
.chip .t { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; flex: 1; }
.chip.published { opacity: .75; }
.chip.published .t::after { content: ' ✓'; color: var(--ok); }
.chip.cancelled .t { text-decoration: line-through; }
.unscheduled { margin-top: 14px; padding: 12px; }
.unscheduled h3 { margin: 0 0 8px; font-size: 15px; }
.unscheduled .list { display: flex; flex-wrap: wrap; gap: 6px; }
.unscheduled .chip { width: auto; }

/* ---------- board ---------- */
.board { display: grid; grid-auto-flow: column; grid-auto-columns: minmax(205px, 1fr); gap: 10px; overflow-x: auto; padding-bottom: 8px; }
.col { background: var(--surface-2); border-radius: var(--radius); padding: 8px; min-height: 300px; display: flex; flex-direction: column; gap: 8px; }
.col.over { outline: 2px dashed var(--accent); }
.col h3 { margin: 2px 4px 4px; font-size: 14px; display: flex; justify-content: space-between; }
.kcard { padding: 10px; display: flex; flex-direction: column; gap: 6px; cursor: grab; border-inline-start: 4px solid var(--c, var(--border)); }
.kcard .title { font-weight: 600; font-size: 14px; }
.kcard .meta { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; font-size: 12px; color: var(--muted); }
.kcard select { font-size: 12.5px; padding: 3px 6px; }
.kcard.dragging { opacity: .4; }

/* ---------- reports ---------- */
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 10px; margin-bottom: 14px; }
.kpi { padding: 14px; }
.kpi .v { font-size: 30px; font-weight: 700; line-height: 1.1; }
.kpi .l { color: var(--muted); font-size: 13px; }
.grid2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); gap: 12px; }
.section { padding: 14px; }
.section h3 { margin: 0 0 10px; font-size: 16px; display: flex; justify-content: space-between; align-items: baseline; gap: 8px; }
.bars { display: flex; flex-direction: column; gap: 7px; }
.bar { display: grid; grid-template-columns: minmax(90px, 34%) 1fr 36px; align-items: center; gap: 8px; font-size: 13.5px; }
.bar .name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bar .track { height: 10px; background: var(--surface-2); border-radius: 999px; overflow: hidden; }
.bar .fill { display: block; height: 100%; background: var(--c, var(--accent)); border-radius: 999px; min-width: 2px; }
.bar .n { font-weight: 700; text-align: end; font-variant-numeric: tabular-nums; }
.bar.zero .n, .bar.zero .name { color: var(--muted); }
.sub { margin-inline-start: 14px; }
.progress .bar { grid-template-columns: minmax(90px, 34%) 1fr 74px; }
.alerts { display: flex; flex-direction: column; gap: 6px; }
.alert { display: flex; gap: 8px; align-items: center; font-size: 13.5px; padding: 6px 10px; border-radius: 8px; background: #fbefd9; color: #6b4500; }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .alert { background: #3a2c12; color: #f0cf8a; } }
table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
th, td { text-align: start; padding: 7px 8px; border-bottom: 1px solid var(--border); vertical-align: top; }
th { color: var(--muted); font-weight: 600; font-size: 12.5px; }
.table-wrap { overflow-x: auto; }

/* ---------- settings ---------- */
.subtabs { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 12px; }
.swatch { display: inline-block; width: 14px; height: 14px; border-radius: 4px; vertical-align: middle; margin-inline-end: 6px; }

/* ---------- modal ---------- */
.modal { border: 0; padding: 0; border-radius: 16px; width: min(640px, calc(100vw - 24px)); max-height: calc(100vh - 32px); background: var(--surface); color: var(--text); box-shadow: 0 20px 60px rgb(0 0 0 / .3); }
.modal::backdrop { background: rgb(20 12 6 / .45); }
.modal form { display: flex; flex-direction: column; max-height: calc(100vh - 32px); }
.modal .scroll { flex: 1 1 auto; min-height: 0; overflow-y: auto; }
.modal .scroll .body { overflow: visible; min-width: 0; }
.modal header { padding: 14px 18px; border-bottom: 1px solid var(--border); display: flex; justify-content: space-between; align-items: center; }
.modal header h2 { margin: 0; font-size: 18px; }
.modal .body { flex: 1 1 auto; min-height: 0; min-width: 0; padding: 16px 18px; overflow-y: auto; display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.modal footer { padding: 12px 18px; border-top: 1px solid var(--border); display: flex; gap: 8px; flex-wrap: wrap; }
.modal footer .spacer { flex: 1; }
.field { display: flex; flex-direction: column; gap: 4px; }
.field.full { grid-column: 1 / -1; }
.field > span { font-size: 13px; color: var(--muted); font-weight: 500; }
.checks { display: flex; flex-wrap: wrap; gap: 6px; }
.checks label { display: inline-flex; align-items: center; gap: 5px; padding: 4px 10px; border: 1px solid var(--border); border-radius: 999px; cursor: pointer; font-size: 13px; }
.checks input { margin: 0; }
.checks label:has(input:checked) { background: var(--accent-soft); border-color: var(--accent); color: var(--accent); }

.toast { position: fixed; bottom: 18px; inset-inline-start: 50%; transform: translateX(50%); background: var(--text); color: var(--bg); padding: 10px 18px; border-radius: 10px; z-index: 50; box-shadow: var(--shadow); max-width: calc(100vw - 32px); }
.toast.error { background: var(--danger); color: #fff; }

/* ---------- mobile ---------- */
@media (max-width: 720px) {
  main { padding: 12px; }
  .topbar { gap: 8px; padding: 8px 12px; }
  .me { display: none; }
  .tabs { width: 100%; order: 3; }
  .cal .day { min-height: 74px; padding: 3px; }
  .cal .chip .t { display: none; }
  .cal .chip { justify-content: center; padding: 2px; }
  .cal .add { opacity: 1; width: 18px; height: 18px; font-size: 13px; }
  .modal .body { grid-template-columns: 1fr; }
  .bar { grid-template-columns: minmax(80px, 38%) 1fr 30px; }
}
