:root {
  --brand: #00815a;
  --brand-600: #006f49;
  --brand-700: #00572e;
  --brand-50: #ebf9f2;
  --brand-100: #d0f1e1;
  --ink: #13161c;
  --ink-2: #3f4349;
  --ink-3: #66696f;
  --ink-4: #a2a5aa;
  --line: #dfe1e5;
  --line-2: #edeef1;
  --bg: #f8f9fb;
  --surface: #ffffff;
  --sunken: #f2f3f6;
  --warn: #915200;
  --warn-bg: #fff3db;
  --err: #b02a2d;
  --err-bg: #ffece9;
  --ok: #036639;
  --ok-bg: #e3f8e9;
  --blue: #1e4b8d;
  --blue-bg: #d5e6ff;
  --r: 14px;
  --shadow: 0 1px 2px rgba(19, 22, 28, .06), 0 0 0 1px rgba(19, 22, 28, .04);
  --shadow-2: 0 24px 48px -16px rgba(19, 22, 28, .22);
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  font-family: 'Noto Kufi Arabic', system-ui, sans-serif;
  font-size: 14px;
  line-height: 1.7;
  color: var(--ink);
  background: var(--bg);
}
h1, h2, h3, h4 { font-family: 'Readex Pro', 'Noto Kufi Arabic', sans-serif; margin: 0; line-height: 1.4; }
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--brand-600); }
[hidden] { display: none !important; }

.shell { display: grid; grid-template-columns: 232px minmax(0, 1fr); min-height: 100vh; }

/* ---------- side ---------- */
.side { background: var(--surface); border-inline-end: 1px solid var(--line); display: flex; flex-direction: column; position: sticky; top: 0; height: 100vh; }
.brand { padding: 20px 20px 14px; display: flex; flex-direction: column; }
.brand-mark { font-family: 'Readex Pro', sans-serif; font-weight: 700; font-size: 24px; color: var(--brand); line-height: 1.2; }
.brand-sub { font-size: 12px; color: var(--ink-3); }
#nav { display: flex; flex-direction: column; gap: 2px; padding: 6px 10px; flex: 1; overflow: auto; }
.nav-item { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 9px 12px; border-radius: 10px; border: 0; background: none; cursor: pointer; text-align: start; color: var(--ink-2); font-weight: 500; }
.nav-item:hover { background: var(--sunken); }
.nav-item.on { background: var(--brand-50); color: var(--brand-700); font-weight: 600; }
.nav-count { background: var(--brand); color: #fff; border-radius: 99px; font-size: 11px; padding: 0 7px; min-width: 20px; text-align: center; line-height: 20px; }
.side-foot { padding: 12px 16px 16px; font-size: 12px; color: var(--ink-3); border-top: 1px solid var(--line-2); }

/* ---------- main ---------- */
.main { min-width: 0; display: flex; flex-direction: column; }
.top { display: flex; align-items: center; gap: 12px; padding: 16px 28px; border-bottom: 1px solid var(--line); background: var(--surface); position: sticky; top: 0; z-index: 5; }
.top h1 { font-size: 19px; flex: 1; }
.top-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.menu-btn { display: none; border: 1px solid var(--line); background: var(--surface); border-radius: 10px; width: 38px; height: 38px; cursor: pointer; }
.view { padding: 22px 28px 60px; max-width: 1240px; width: 100%; }

.grid { display: grid; gap: 14px; }
.g4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.g2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.card { background: var(--surface); border-radius: var(--r); box-shadow: var(--shadow); padding: 16px 18px; min-width: 0; }
.card h3 { font-size: 15px; margin-bottom: 10px; }
.section-title { font-size: 15px; margin: 26px 0 10px; }
.muted { color: var(--ink-3); }
.small { font-size: 12px; }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.spread { justify-content: space-between; }
.grow { flex: 1; min-width: 0; }

.stat { cursor: pointer; border: 0; text-align: start; }
.stat:hover { box-shadow: 0 0 0 2px var(--brand-100); }
.stat-n { font-family: 'Readex Pro', sans-serif; font-size: 30px; font-weight: 700; line-height: 1.2; }
.stat-l { color: var(--ink-3); font-size: 13px; }

/* ---------- buttons & fields ---------- */
.btn { border: 1px solid var(--line); background: var(--surface); border-radius: 10px; padding: 7px 14px; cursor: pointer; font-weight: 600; font-size: 13px; white-space: nowrap; }
.btn:hover { background: var(--sunken); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn-primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn-primary:hover { background: var(--brand-600); }
.btn-danger { color: var(--err); border-color: #f0c4c1; }
.btn-warn { color: var(--warn); border-color: #f0d9a8; }
.btn-sm { padding: 4px 10px; font-size: 12px; }
.field { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.field label { font-size: 12px; color: var(--ink-3); font-weight: 500; }
input[type=text], input[type=number], input[type=date], input[type=search], select, textarea {
  border: 1px solid var(--line); border-radius: 10px; padding: 8px 12px; background: var(--surface); width: 100%; min-width: 0;
}
textarea { resize: vertical; min-height: 84px; line-height: 1.8; }
input:focus, select:focus, textarea:focus, .btn:focus-visible, .nav-item:focus-visible { outline: 3px solid rgba(0, 129, 90, .25); outline-offset: 1px; border-color: var(--brand); }

.chips { display: flex; gap: 6px; flex-wrap: wrap; }
.chip { border: 1px solid var(--line); background: var(--surface); border-radius: 99px; padding: 3px 12px; cursor: pointer; font-size: 12.5px; color: var(--ink-2); }
.chip.on { background: var(--ink); border-color: var(--ink); color: #fff; }

.pill { display: inline-block; border-radius: 99px; padding: 1px 10px; font-size: 12px; font-weight: 600; white-space: nowrap; }
.st-draft { background: var(--sunken); color: var(--ink-2); }
.st-approved-internal { background: var(--warn-bg); color: var(--warn); }
.st-needs-changes { background: var(--err-bg); color: var(--err); }
.st-approved-owner { background: var(--ok-bg); color: var(--ok); }
.st-published { background: var(--blue-bg); color: var(--blue); }
.tag { display: inline-block; border-radius: 6px; padding: 0 8px; font-size: 12px; background: var(--sunken); color: var(--ink-2); white-space: nowrap; }
.tag.plat { background: var(--brand-50); color: var(--brand-700); font-weight: 600; }

/* ---------- content list ---------- */
.filters { display: flex; flex-direction: column; gap: 10px; margin-bottom: 16px; }
.filter-row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.filter-row > .lbl { font-size: 12px; color: var(--ink-3); width: 52px; flex-shrink: 0; }
.day-head { margin: 18px 0 8px; font-family: 'Readex Pro', sans-serif; font-weight: 600; font-size: 14px; color: var(--ink-2); }
.post { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 10px; align-items: start; background: var(--surface); border-radius: var(--r); box-shadow: var(--shadow); padding: 12px 16px; margin-bottom: 8px; cursor: pointer; border: 0; width: 100%; text-align: start; }
.post:hover { box-shadow: 0 0 0 2px var(--brand-100); }
.post-meta { display: flex; gap: 6px; flex-wrap: wrap; align-items: center; margin-bottom: 4px; }
.post-text { color: var(--ink-2); display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; white-space: pre-line; }
.empty { text-align: center; color: var(--ink-3); padding: 40px 10px; }

/* ---------- calendar ---------- */
.cal { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); gap: 6px; }
.cal-h { font-size: 12px; color: var(--ink-3); text-align: center; padding: 4px 0; }
.cal-d { background: var(--surface); border-radius: 10px; box-shadow: var(--shadow); min-height: 104px; padding: 6px; display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.cal-d.off { background: transparent; box-shadow: none; }
.cal-d.today { box-shadow: 0 0 0 2px var(--brand); }
.cal-n { font-size: 12px; color: var(--ink-3); font-weight: 600; }
.cal-p { border: 0; border-radius: 6px; padding: 2px 6px; font-size: 11.5px; text-align: start; cursor: pointer; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; width: 100%; }

/* ---------- drawer ---------- */
.drawer-back { position: fixed; inset: 0; background: rgba(19, 22, 28, .35); z-index: 20; }
.drawer { position: fixed; top: 0; bottom: 0; inset-inline-end: 0; width: min(640px, 100vw); background: var(--surface); z-index: 21; box-shadow: var(--shadow-2); display: flex; flex-direction: column; }
.drawer-head { padding: 16px 20px; border-bottom: 1px solid var(--line); display: flex; gap: 10px; align-items: flex-start; }
.drawer-body { padding: 18px 20px; overflow: auto; flex: 1; }
.drawer-foot { padding: 12px 20px; border-top: 1px solid var(--line); display: flex; gap: 8px; flex-wrap: wrap; background: var(--surface); }
.block { margin-bottom: 20px; }
.block-h { display: flex; justify-content: space-between; align-items: center; margin-bottom: 6px; }
.block-h h4 { font-size: 13px; color: var(--ink-3); font-weight: 600; }
.copybox { background: var(--sunken); border-radius: 10px; padding: 12px 14px; white-space: pre-wrap; overflow-wrap: anywhere; }
.kv { display: grid; grid-template-columns: 92px minmax(0, 1fr); gap: 4px 12px; font-size: 13px; }
.kv dt { color: var(--ink-3); }
.kv dd { margin: 0; overflow-wrap: anywhere; }

/* ---------- tables ---------- */
.table-wrap { overflow-x: auto; }
table { border-collapse: collapse; width: 100%; font-size: 13px; }
th, td { text-align: start; padding: 8px 10px; border-bottom: 1px solid var(--line-2); vertical-align: top; }
th { color: var(--ink-3); font-weight: 600; font-size: 12px; white-space: nowrap; }
td.num, th.num { text-align: end; font-variant-numeric: tabular-nums; white-space: nowrap; }
.bar { height: 8px; border-radius: 99px; background: var(--sunken); overflow: hidden; min-width: 80px; }
.bar > i { display: block; height: 100%; background: var(--brand); border-radius: 99px; }
.bar.over > i { background: var(--err); }
.form-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 10px; }
.notice { border-radius: 10px; padding: 10px 14px; background: var(--brand-50); color: var(--brand-700); font-size: 13px; }
.notice.warn { background: var(--warn-bg); color: var(--warn); }

/* ---------- replies / team ---------- */
.reply { background: var(--surface); border-radius: var(--r); box-shadow: var(--shadow); padding: 12px 16px; margin-bottom: 8px; }
.reply-h { display: flex; justify-content: space-between; gap: 8px; align-items: center; margin-bottom: 4px; }
.reply-t { font-weight: 600; }
.reply p { margin: 0; white-space: pre-wrap; color: var(--ink-2); }
.log { background: #13161c; color: #e7e9ee; border-radius: 10px; padding: 12px 14px; font-family: ui-monospace, 'SF Mono', Menlo, monospace; font-size: 12px; direction: ltr; text-align: start; white-space: pre-wrap; overflow-wrap: anywhere; max-height: 340px; overflow: auto; unicode-bidi: plaintext; }
code, .mono { font-family: ui-monospace, 'SF Mono', Menlo, monospace; font-size: 12.5px; direction: ltr; unicode-bidi: isolate; }

/* ---------- docs ---------- */
.docs { display: grid; grid-template-columns: 260px minmax(0, 1fr); gap: 16px; align-items: start; }
.doc-list { position: sticky; top: 84px; max-height: calc(100vh - 110px); overflow: auto; }
.doc-group { font-size: 12px; color: var(--ink-3); margin: 12px 0 4px; font-weight: 600; }
.doc-link { display: block; width: 100%; text-align: start; border: 0; background: none; padding: 5px 8px; border-radius: 8px; cursor: pointer; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.doc-link:hover { background: var(--sunken); }
.doc-link.on { background: var(--brand-50); color: var(--brand-700); font-weight: 600; }
.md { overflow-wrap: anywhere; }
.md h1 { font-size: 21px; margin: 0 0 12px; }
.md h2 { font-size: 17px; margin: 24px 0 8px; padding-top: 14px; border-top: 1px solid var(--line-2); }
.md h3 { font-size: 15px; margin: 18px 0 6px; }
.md h4 { font-size: 14px; margin: 14px 0 4px; }
.md p { margin: 0 0 10px; }
.md ul, .md ol { margin: 0 0 10px; padding-inline-start: 22px; }
.md li { margin-bottom: 3px; }
.md blockquote { margin: 0 0 10px; padding: 8px 14px; border-inline-start: 3px solid var(--brand-100); background: var(--bg); border-radius: 0 8px 8px 0; color: var(--ink-2); }
.md pre { background: var(--sunken); border-radius: 10px; padding: 12px 14px; overflow: auto; direction: ltr; text-align: start; unicode-bidi: plaintext; }
.md code { background: var(--sunken); border-radius: 5px; padding: 0 5px; }
.md pre code { background: none; padding: 0; }
.md hr { border: 0; border-top: 1px solid var(--line); margin: 18px 0; }
.md table { margin-bottom: 12px; }

.toast { position: fixed; bottom: 22px; left: 50%; transform: translateX(-50%); background: var(--ink); color: #fff; padding: 9px 18px; border-radius: 99px; z-index: 40; font-size: 13px; box-shadow: var(--shadow-2); max-width: 90vw; }
.toast.err { background: var(--err); }

@media (max-width: 900px) {
  .shell { grid-template-columns: minmax(0, 1fr); }
  .side { position: fixed; z-index: 30; inset-block: 0; inset-inline-start: 0; width: 240px; transform: translateX(100%); transition: transform .2s; }
  .side.open { transform: none; box-shadow: var(--shadow-2); }
  .menu-btn { display: block; }
  .top { padding: 12px 16px; }
  .view { padding: 16px 16px 60px; }
  .g4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .g2, .docs, .form-grid { grid-template-columns: minmax(0, 1fr); }
  .form-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .doc-list { position: static; max-height: 240px; }
  .cal-d { min-height: 70px; }
}

/* ---------- login (hosted) ---------- */
.login-body { display: grid; place-items: center; min-height: 100vh; padding: 20px; }
.login-card { width: min(380px, 100%); padding: 28px 26px; }
.login-form { display: flex; flex-direction: column; gap: 14px; margin-top: 22px; }
.login-btn { padding: 10px 14px; font-size: 14px; }
.login-msg { color: var(--err); font-size: 13px; min-height: 22px; }
.sync-ok { color: var(--ok); }
.sync-bad { color: var(--err); }

/* ---------- generated designs ---------- */
.designs { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; }
.design { display: flex; flex-direction: column; gap: 6px; align-items: stretch; }
.design img { width: 100%; height: auto; display: block; border-radius: 8px; box-shadow: var(--shadow); background: var(--sunken); }
.design .btn { text-align: center; text-decoration: none; color: var(--ink); }
