/* WhatsApp-Web-style design system shared by every page. Light + dark, LTR + RTL. */
/* Cairo (SIL OFL), self-hosted. "CairoAr" covers Arabic only, so Arabic text is always Cairo; "Cairo" also covers Latin for the Arabic UI. */
@font-face { font-family: "CairoAr"; src: url(fonts/cairo-arabic.woff2) format("woff2"); font-weight: 200 1000; font-display: swap; unicode-range: U+0600-06FF, U+0750-077F, U+0870-0891, U+0897-08E1, U+08E3-08FF, U+200C-200E, U+2010-2011, U+204F, U+2E41, U+FB50-FDFF, U+FE70-FE74, U+FE76-FEFC; }
@font-face { font-family: "Cairo"; src: url(fonts/cairo-arabic.woff2) format("woff2"); font-weight: 200 1000; font-display: swap; unicode-range: U+0600-06FF, U+0750-077F, U+0870-0891, U+0897-08E1, U+08E3-08FF, U+200C-200E, U+2010-2011, U+204F, U+2E41, U+FB50-FDFF, U+FE70-FE74, U+FE76-FEFC; }
@font-face { font-family: "Cairo"; src: url(fonts/cairo-latin.woff2) format("woff2"); font-weight: 200 1000; font-display: swap; unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD; }

:root, :root[data-theme="light"] {
  --green: #00a884; --green-strong: #008069; --green-soft: #d9fdd3; --badge: #25d366; --badge-text: #fff;
  --bg-app: #eae6df; --bg-rail: #f0f2f5; --bg-panel: #ffffff; --bg-header: #f0f2f5; --bg-chat: #efeae2;
  --bg-input: #f0f2f5; --bg-hover: #f5f6f6; --bg-active: #f0f2f5; --bg-elevated: #ffffff;
  --bubble-in: #ffffff; --bubble-out: #d9fdd3; --chip: #ffffff; --chip-text: #54656f;
  --text: #111b21; --text-2: #667781; --icon: #54656f; --border: #e9edef; --border-strong: #d1d7db;
  --link: #027eb5; --tick-read: #53bdeb; --danger: #ea0038; --warn-bg: #fff3c4; --warn-text: #6b5300;
  --ok-bg: #d9fdd3; --ok-text: #0b5d3b; --err-bg: #ffe5e9; --err-text: #9b0d2c;
  --shadow-1: 0 1px .5px rgba(11, 20, 26, .13); --shadow-2: 0 2px 5px rgba(11, 26, 30, .26), 0 2px 10px rgba(11, 26, 30, .16);
  --wall-stroke: #000; --wall-opacity: .06;
  color-scheme: light;
}
:root[data-theme="dark"] {
  --green: #00a884; --green-strong: #00a884; --green-soft: #005c4b; --badge: #00a884; --badge-text: #111b21;
  --bg-app: #0c1317; --bg-rail: #202c33; --bg-panel: #111b21; --bg-header: #202c33; --bg-chat: #0b141a;
  --bg-input: #202c33; --bg-hover: #202c33; --bg-active: #2a3942; --bg-elevated: #233138;
  --bubble-in: #202c33; --bubble-out: #005c4b; --chip: #182229; --chip-text: #8696a0;
  --text: #e9edef; --text-2: #8696a0; --icon: #aebac1; --border: #222d34; --border-strong: #313d45;
  --link: #53bdeb; --tick-read: #53bdeb; --danger: #f15c6d; --warn-bg: #3a3000; --warn-text: #ffd279;
  --ok-bg: #0a332c; --ok-text: #8ff0c9; --err-bg: #3d0b16; --err-text: #ffb3c1;
  --shadow-1: 0 1px .5px rgba(11, 20, 26, .3); --shadow-2: 0 2px 5px rgba(0, 0, 0, .4), 0 2px 10px rgba(0, 0, 0, .3);
  --wall-stroke: #fff; --wall-opacity: .035;
  color-scheme: dark;
}
@media (prefers-color-scheme: dark) {
  :root[data-theme="system"] {
    --green: #00a884; --green-strong: #00a884; --green-soft: #005c4b; --badge: #00a884; --badge-text: #111b21;
    --bg-app: #0c1317; --bg-rail: #202c33; --bg-panel: #111b21; --bg-header: #202c33; --bg-chat: #0b141a;
    --bg-input: #202c33; --bg-hover: #202c33; --bg-active: #2a3942; --bg-elevated: #233138;
    --bubble-in: #202c33; --bubble-out: #005c4b; --chip: #182229; --chip-text: #8696a0;
    --text: #e9edef; --text-2: #8696a0; --icon: #aebac1; --border: #222d34; --border-strong: #313d45;
    --link: #53bdeb; --tick-read: #53bdeb; --danger: #f15c6d; --warn-bg: #3a3000; --warn-text: #ffd279;
    --ok-bg: #0a332c; --ok-text: #8ff0c9; --err-bg: #3d0b16; --err-text: #ffb3c1;
    --shadow-1: 0 1px .5px rgba(11, 20, 26, .3); --shadow-2: 0 2px 5px rgba(0, 0, 0, .4), 0 2px 10px rgba(0, 0, 0, .3);
    --wall-stroke: #fff; --wall-opacity: .035;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  font-family: "CairoAr", "Segoe UI", "Helvetica Neue", Helvetica, "Lucida Grande", Arial, Ubuntu, Cantarell, "Fira Sans", sans-serif;
  font-size: 14.2px; line-height: 1.4; color: var(--text); background: var(--bg-app);
  -webkit-font-smoothing: antialiased; overflow: hidden;
}
button, input, textarea, select { font: inherit; color: inherit; }
:root[lang="ar"] body { font-family: "Cairo", "Segoe UI", Tahoma, sans-serif; }
a { color: var(--link); text-decoration: none; }
a:hover { text-decoration: underline; }
.hidden { display: none !important; }
.muted { color: var(--text-2); }
.small { font-size: 12.5px; }
.ic { display: block; flex: none; fill: currentColor; }
[dir="rtl"] .flip-rtl { transform: scaleX(-1); }
.dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; vertical-align: middle; margin-inline-end: 6px; flex: none; }
code { font-family: Consolas, "SF Mono", Menlo, monospace; font-size: 12.5px; background: var(--bg-input); padding: 1px 6px; border-radius: 4px; }

/* ---------- App shell: rail + main ---------- */
.wa-app { display: flex; height: 100vh; height: 100dvh; max-width: 1920px; margin: 0 auto; background: var(--bg-panel); overflow: hidden; box-shadow: 0 6px 18px rgba(11, 20, 26, .05); }
.rail { width: 64px; flex: none; background: var(--bg-rail); border-inline-end: 1px solid var(--border); display: flex; flex-direction: column; align-items: center; padding: 10px 0; gap: 4px; z-index: 5; }
.rail .group { display: flex; flex-direction: column; align-items: center; gap: 4px; width: 100%; }
.rail .spacer { flex: 1; }
.rail-btn { position: relative; width: 40px; height: 40px; border-radius: 50%; display: flex; align-items: center; justify-content: center; color: var(--icon); background: none; border: 0; cursor: pointer; }
.rail-btn:hover { background: var(--bg-active); text-decoration: none; }
.rail-btn.active { background: var(--bg-active); color: var(--text); }
.rail-btn .badge { position: absolute; top: 0; inset-inline-end: -2px; transform: scale(.85); }
.rail-sep { width: 32px; height: 1px; background: var(--border-strong); margin: 4px 0; }
.rail .me-avatar { width: 34px; height: 34px; font-size: 14px; }
.tip { position: relative; }
.tip:hover::after {
  content: attr(data-tip); position: absolute; inset-inline-start: 50px; top: 50%; transform: translateY(-50%);
  background: var(--bg-elevated); color: var(--text); box-shadow: var(--shadow-2); padding: 5px 10px; border-radius: 6px;
  white-space: nowrap; font-size: 13px; pointer-events: none; z-index: 50;
}
.wa-main { flex: 1; display: flex; min-width: 0; min-height: 0; }

.avatar { --c: #dfe5e7; width: 49px; height: 49px; flex: none; border-radius: 50%; background: var(--c); color: #fff; display: flex; align-items: center; justify-content: center; font-weight: 600; font-size: 18px; overflow: hidden; }
.avatar.ph { background: #dfe5e7; color: #fff; }
:root[data-theme="dark"] .avatar.ph { background: #6a7175; }
.avatar .ic { width: 70%; height: 70%; margin-top: 18%; }
.badge { background: var(--badge); color: var(--badge-text); border-radius: 12px; min-width: 20px; height: 20px; padding: 0 6px; font-size: 12px; font-weight: 600; display: inline-flex; align-items: center; justify-content: center; flex: none; line-height: 1; }

.icon-btn { background: none; border: 0; width: 40px; height: 40px; border-radius: 50%; cursor: pointer; color: var(--icon); display: inline-flex; align-items: center; justify-content: center; flex: none; }
.icon-btn:hover { background: rgba(0, 0, 0, .06); text-decoration: none; }
:root[data-theme="dark"] .icon-btn:hover { background: rgba(255, 255, 255, .07); }
.icon-btn:disabled { opacity: .35; cursor: default; background: none; }
.icon-btn.active { background: var(--bg-active); }

.btn { display: inline-flex; align-items: center; gap: 6px; border: 1px solid var(--border-strong); background: var(--bg-panel); color: var(--green-strong); border-radius: 24px; padding: 8px 20px; cursor: pointer; font-weight: 500; white-space: nowrap; }
.btn:hover { background: var(--bg-hover); text-decoration: none; }
.btn.primary { background: var(--green); border-color: var(--green); color: #fff; }
:root[data-theme="dark"] .btn.primary { color: #111b21; }
.btn.primary:hover { filter: brightness(.95); }
.btn.danger { color: var(--danger); border-color: var(--border-strong); }
.btn.sm { padding: 4px 12px; font-size: 13px; }
.btn:disabled { opacity: .5; cursor: default; }
.btn .ic { width: 18px; height: 18px; }

.chip { border: 1px solid transparent; background: var(--bg-input); color: var(--text-2); border-radius: 18px; padding: 4px 12px; cursor: pointer; font-size: 14px; white-space: nowrap; flex: none; display: inline-flex; align-items: center; gap: 6px; }
.chip:hover { background: var(--bg-active); }
.chip.active { background: #e7fce3; color: #008069; }
:root[data-theme="dark"] .chip.active { background: #0a332c; color: #00a884; }
.chip .badge { height: 18px; min-width: 18px; font-size: 11px; }

/* Forms */
.field { display: block; margin-bottom: 14px; }
.field > span { display: block; font-size: 13px; color: var(--green-strong); margin-bottom: 4px; }
input.inp, select.inp, textarea.inp, .field input:not([type=checkbox]):not([type=color]), .field select, .field textarea {
  display: block; width: 100%; padding: 9px 12px; border: 0; border-bottom: 2px solid var(--border-strong); background: transparent;
  color: var(--text); outline: none; border-radius: 0;
}
.field input:focus, .field select:focus, .field textarea:focus, input.inp:focus { border-bottom-color: var(--green); }
.field select option { background: var(--bg-panel); }
.check { display: inline-flex; align-items: center; gap: 8px; cursor: pointer; margin-inline-end: 18px; margin-bottom: 8px; }
.check input { accent-color: var(--green); width: 17px; height: 17px; }
input[type=color] { width: 48px; height: 32px; border: 1px solid var(--border-strong); border-radius: 6px; background: none; padding: 2px; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 24px; }
.grid3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 0 24px; }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.row > .grow { flex: 1; min-width: 180px; }
.search-box { display: flex; align-items: center; gap: 12px; background: var(--bg-input); border-radius: 8px; padding: 0 12px; height: 36px; color: var(--icon); }
.search-box input { flex: 1; border: 0; background: transparent; outline: none; min-width: 0; height: 100%; }
.search-box .ic { width: 18px; height: 18px; }

/* Alerts & toast */
.alert { padding: 10px 14px; border-radius: 8px; margin-bottom: 14px; background: var(--ok-bg); color: var(--ok-text); }
.alert.err { background: var(--err-bg); color: var(--err-text); }
.alert.warn { background: var(--warn-bg); color: var(--warn-text); }
.toast { position: fixed; bottom: 28px; left: 50%; transform: translateX(-50%); background: #323739; color: #fff; padding: 12px 22px; border-radius: 8px; z-index: 300; box-shadow: var(--shadow-2); max-width: 90vw; font-size: 14px; }
.toast.err { background: #b3261e; }

/* Dialogs (WhatsApp modal style) */
.dialog { border: 0; border-radius: 12px; padding: 22px 24px; width: min(460px, 94vw); background: var(--bg-elevated); color: var(--text); box-shadow: var(--shadow-2); }
.dialog.wide { width: min(940px, 96vw); }
.dialog::backdrop { background: rgba(11, 20, 26, .55); }
:root[data-theme="dark"] .dialog::backdrop { background: rgba(0, 0, 0, .7); }
.dialog h3 { margin: 0 0 18px; font-size: 19px; font-weight: 500; }
.dlg-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 20px; }

/* Menus */
.menu { position: absolute; background: var(--bg-elevated); box-shadow: var(--shadow-2); border-radius: 6px; padding: 9px 0; min-width: 200px; z-index: 60; }
.menu button, .menu a { display: flex; align-items: center; gap: 12px; width: 100%; text-align: start; background: none; border: 0; padding: 10px 24px; cursor: pointer; color: var(--text); font-size: 14.5px; }
.menu button:hover, .menu a:hover { background: var(--bg-hover); text-decoration: none; }
.menu .danger { color: var(--danger); }
.menu .ic { width: 20px; height: 20px; color: var(--icon); }

/* ---------- Admin / content pages ---------- */
.page-wrap { flex: 1; display: flex; flex-direction: column; min-width: 0; background: var(--bg-panel); }
.page-head { height: 60px; flex: none; display: flex; align-items: center; gap: 14px; padding: 0 24px; background: var(--bg-header); border-bottom: 1px solid var(--border); }
.page-head h1 { font-size: 19px; font-weight: 500; margin: 0; flex: 1; }
.page-body { flex: 1; overflow-y: auto; padding: 22px 24px 40px; background: var(--bg-chat); }
.page-body > .inner { max-width: 1200px; margin: 0 auto; }
.card { background: var(--bg-panel); border-radius: 10px; padding: 20px 22px; margin-bottom: 18px; box-shadow: var(--shadow-1); overflow-x: auto; }
.card h2 { font-size: 16px; font-weight: 600; margin: 0 0 12px; }
.card > p:first-of-type { margin-top: 0; }
.table { width: 100%; border-collapse: collapse; font-size: 14px; }
.table th, .table td { padding: 10px; border-bottom: 1px solid var(--border); text-align: start; vertical-align: middle; }
.table th { color: var(--text-2); font-weight: 500; font-size: 13px; white-space: nowrap; }
.table tr:hover td { background: var(--bg-hover); }
.table.kv th { width: 180px; }
.table tr.inactive td { opacity: .5; }
.table .actions { white-space: nowrap; text-align: end; }
.table .actions form { display: inline; }
.table td.num, .table th.num { text-align: end; font-variant-numeric: tabular-nums; }
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 14px; margin-bottom: 18px; }
.stat { background: var(--bg-panel); border-radius: 10px; padding: 16px 18px; box-shadow: var(--shadow-1); }
.stat b { display: block; font-size: 26px; font-weight: 600; color: var(--green-strong); font-variant-numeric: tabular-nums; }
.stat span { color: var(--text-2); font-size: 13px; }
.pill { display: inline-block; font-size: 11.5px; padding: 2px 9px; border-radius: 10px; background: var(--bg-input); color: var(--text-2); margin-inline-end: 4px; white-space: nowrap; }
.pill.green, .pill.APPROVED, .pill.read, .pill.delivered { background: var(--ok-bg); color: var(--ok-text); }
.pill.red, .pill.REJECTED, .pill.failed { background: var(--err-bg); color: var(--err-text); }
.pill.amber, .pill.PENDING, .pill.pending { background: var(--warn-bg); color: var(--warn-text); }
.checklist { list-style: none; padding: 0; margin: 12px 0 0; line-height: 2; }
.checklist .ic { display: inline-block; vertical-align: -5px; width: 20px; height: 20px; margin-inline-end: 6px; }
.ok-ic { color: var(--green); } .warn-ic { color: #e6a700; }
.err-text { color: var(--danger); font-size: 12.5px; }
pre.raw { max-height: 420px; overflow: auto; font-size: 12px; background: var(--bg-input); padding: 12px; border-radius: 6px; direction: ltr; text-align: left; }
details summary { cursor: pointer; }
.pager { display: flex; gap: 8px; justify-content: center; margin-top: 14px; align-items: center; }
.tpl-card { border: 1px solid var(--border); border-radius: 8px; padding: 12px 14px; margin-bottom: 10px; }
.tpl-card .body { white-space: pre-wrap; background: var(--bg-input); padding: 8px 10px; border-radius: 6px; margin-top: 8px; font-size: 13.5px; }

/* Auth pages */
.auth-wrap { min-height: 100vh; overflow-y: auto; display: flex; flex-direction: column; align-items: center; background: var(--bg-app); }
.auth-band { width: 100%; height: 222px; background: var(--green-strong); flex: none; }
:root[data-theme="dark"] .auth-band { background: #0c1317; }
.auth-card { width: min(460px, 92vw); margin-top: -150px; background: var(--bg-panel); border-radius: 10px; box-shadow: var(--shadow-2); padding: 34px 38px 30px; margin-bottom: 40px; }
.auth-card.wide { width: min(760px, 94vw); }
.auth-logo { display: flex; align-items: center; gap: 12px; color: var(--green); font-weight: 600; font-size: 17px; margin-bottom: 26px; }
.auth-logo span { color: var(--text); }
.auth-card h1 { font-size: 24px; font-weight: 300; margin: 0 0 22px; }
.auth-foot { margin-top: 18px; display: flex; justify-content: space-between; gap: 10px; font-size: 13px; }
fieldset { border: 1px solid var(--border); border-radius: 8px; padding: 14px 16px 4px; margin: 0 0 16px; }
legend { padding: 0 6px; color: var(--text-2); font-size: 13px; }

/* Docs */
.docs-layout { display: grid; grid-template-columns: 250px 1fr; gap: 18px; align-items: start; }
.docs-nav { position: sticky; top: 0; padding: 10px; }
.docs-nav a { display: block; padding: 9px 12px; border-radius: 6px; color: var(--text); }
.docs-nav a:hover { background: var(--bg-hover); text-decoration: none; }
.docs-nav a.active { background: var(--bg-active); color: var(--green-strong); font-weight: 600; }
.doc-body { line-height: 1.7; font-size: 15px; padding: 26px 34px; }
.doc-body h1 { font-size: 26px; font-weight: 600; margin-top: 0; }
.doc-body h2 { font-size: 20px; margin-top: 30px; padding-bottom: 6px; border-bottom: 1px solid var(--border); }
.doc-body h3 { font-size: 16.5px; margin-top: 22px; }
.doc-body table { border-collapse: collapse; width: 100%; margin: 12px 0; font-size: 14px; }
.doc-body th, .doc-body td { border: 1px solid var(--border); padding: 7px 10px; text-align: start; vertical-align: top; }
.doc-body th { background: var(--bg-input); }
.doc-body pre { background: var(--bg-input); padding: 12px 14px; border-radius: 8px; overflow-x: auto; font-size: 13px; }
.doc-body pre code { background: none; padding: 0; }
.doc-body blockquote { margin: 12px 0; padding: 8px 16px; border-inline-start: 4px solid var(--green); background: var(--bg-input); border-radius: 4px; }
.doc-body img { max-width: 100%; }

/* ---------- Mobile ---------- */
@media (max-width: 800px) {
  .wa-app { flex-direction: column-reverse; }
  .rail { width: 100%; height: 58px; flex-direction: row; padding: 0 6px; border-inline-end: 0; border-top: 1px solid var(--border); justify-content: space-around; }
  .rail .group { flex-direction: row; width: auto; }
  .rail .spacer, .rail-sep, .rail .desk-only { display: none; }
  .tip:hover::after { display: none; }
  .wa-app.show-chat .rail { display: none; }
  .page-head { padding: 0 14px; }
  .page-body { padding: 14px 10px 30px; }
  .grid2, .grid3 { grid-template-columns: 1fr; }
  .docs-layout { grid-template-columns: 1fr; }
  .docs-nav { position: static; }
  .doc-body { padding: 18px; }
  .card { padding: 16px; }
}
