:root {
  --bg: #f4f6f8;
  --surface: #ffffff;
  --surface-2: #f8fafb;
  --border: #e3e8ec;
  --text: #1f2a33;
  --muted: #66737f;
  --primary: #128c7e;
  --primary-dark: #0e6f64;
  --primary-soft: #e3f4f1;
  --danger: #c0392b;
  --danger-soft: #fbe9e7;
  --warning: #b9770e;
  --warning-soft: #fdf3e1;
  --info: #2e6fb7;
  --info-soft: #e6eef8;
  --success: #1e8449;
  --success-soft: #e5f5ec;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 1px 3px rgba(16, 24, 40, .08);
  --sidebar: 240px;
  --topbar: 58px;
  --font: "Segoe UI", "Noto Sans Arabic", Tahoma, "Geeza Pro", Arial, sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body { font-family: var(--font); background: var(--bg); color: var(--text); font-size: 15px; line-height: 1.6; }
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3 { margin: 0 0 .5rem; line-height: 1.3; }
h1 { font-size: 1.35rem; }
h2 { font-size: 1.1rem; }
h3 { font-size: 1rem; }
.ltr { direction: ltr; unicode-bidi: embed; display: inline-block; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.hidden { display: none !important; }
.icon { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; flex-shrink: 0; }

/* ===== layout ===== */
.topbar {
  position: fixed; inset: 0 0 auto 0; height: var(--topbar); z-index: 30;
  background: var(--surface); border-bottom: 1px solid var(--border);
  display: flex; align-items: center; gap: .75rem; padding: 0 .75rem;
}
.brand { display: flex; align-items: center; gap: .5rem; font-weight: 700; color: var(--primary-dark); white-space: nowrap; }
.brand .logo { width: 32px; height: 32px; border-radius: 8px; background: var(--primary); color: #fff; display: grid; place-items: center; }
.topbar .status { display: flex; gap: .5rem; align-items: center; margin-inline-start: auto; font-size: .85rem; flex-wrap: nowrap; overflow: hidden; }
.dot { width: 9px; height: 9px; border-radius: 50%; display: inline-block; background: var(--muted); }
.dot.ok { background: var(--success); }
.dot.bad { background: var(--danger); }
.dot.warn { background: var(--warning); }
.pill { display: inline-flex; align-items: center; gap: .35rem; padding: .2rem .6rem; border-radius: 999px; background: var(--surface-2); border: 1px solid var(--border); white-space: nowrap; }

.sidebar {
  position: fixed; top: var(--topbar); bottom: 0; right: 0; width: var(--sidebar); z-index: 25;
  background: var(--surface); border-left: 1px solid var(--border); padding: .75rem .5rem;
  transform: translateX(100%); transition: transform .2s ease; overflow-y: auto;
}
body.nav-open .sidebar { transform: none; }
.backdrop { position: fixed; inset: var(--topbar) 0 0 0; background: rgba(0,0,0,.3); z-index: 20; display: none; }
body.nav-open .backdrop { display: block; }
.nav a {
  display: flex; align-items: center; gap: .7rem; padding: .6rem .75rem; border-radius: 8px; color: var(--text);
  margin-bottom: 2px; white-space: nowrap; overflow: hidden;
}
.nav a:hover { background: var(--surface-2); text-decoration: none; }
.nav a.active { background: var(--primary-soft); color: var(--primary-dark); font-weight: 600; }
.nav .sep { height: 1px; background: var(--border); margin: .6rem .25rem; }
.main { padding: calc(var(--topbar) + 1rem) .75rem 2rem; max-width: 1280px; margin: 0 auto; }

@media (min-width: 992px) {
  .sidebar { transform: none; }
  .backdrop { display: none !important; }
  .main { margin-right: var(--sidebar); margin-left: 0; padding-inline: 1.5rem; max-width: none; }
  body.nav-collapsed .sidebar { width: 64px; }
  body.nav-collapsed .sidebar .label { display: none; }
  body.nav-collapsed .main { margin-right: 64px; }
}

/* ===== components ===== */
.page-head { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: .75rem; margin-bottom: 1rem; }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); padding: 1rem; margin-bottom: 1rem; }
.card > h2:first-child { margin-bottom: .75rem; }
.grid { display: grid; gap: 1rem; margin-bottom: 1rem; }
.grid > .card { margin-bottom: 0; }
.stats { grid-template-columns: repeat(2, 1fr); }
@media (min-width: 640px) { .stats { grid-template-columns: repeat(3, 1fr); } .grid-2 { grid-template-columns: 1fr 1fr; } }
@media (min-width: 1100px) { .stats { grid-template-columns: repeat(6, 1fr); } }
.stat { padding: .9rem; margin: 0; }
.stat .num { font-size: 1.6rem; font-weight: 700; line-height: 1.2; }
.stat .lbl { color: var(--muted); font-size: .85rem; }
.stat.ok .num { color: var(--success); }
.stat.bad .num { color: var(--danger); }
.stat.warn .num { color: var(--warning); }
.stat.info .num { color: var(--info); }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: .4rem;
  padding: .5rem .9rem; border-radius: 8px; border: 1px solid var(--border); background: var(--surface);
  color: var(--text); font: inherit; font-size: .9rem; cursor: pointer; white-space: nowrap; min-height: 38px;
}
.btn:hover { background: var(--surface-2); text-decoration: none; }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn.primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn.primary:hover { background: var(--primary-dark); }
.btn.danger { color: var(--danger); border-color: #f0c4bf; }
.btn.danger.solid { background: var(--danger); color: #fff; border-color: var(--danger); }
.btn.sm { padding: .25rem .6rem; min-height: 32px; font-size: .85rem; }
.btn.icon-only { padding: .4rem; min-width: 38px; }
.btn.ghost { border-color: transparent; background: transparent; }
.btn .icon { width: 18px; height: 18px; }
.actions { display: flex; flex-wrap: wrap; gap: .4rem; }
.spinner { width: 16px; height: 16px; border: 2px solid currentColor; border-top-color: transparent; border-radius: 50%; animation: spin .8s linear infinite; display: inline-block; }
@keyframes spin { to { transform: rotate(360deg); } }

.badge { display: inline-flex; align-items: center; gap: .3rem; padding: .1rem .55rem; border-radius: 999px; font-size: .78rem; font-weight: 600; white-space: nowrap; background: var(--surface-2); color: var(--muted); border: 1px solid var(--border); }
.badge.ok { background: var(--success-soft); color: var(--success); border-color: transparent; }
.badge.bad { background: var(--danger-soft); color: var(--danger); border-color: transparent; }
.badge.warn { background: var(--warning-soft); color: var(--warning); border-color: transparent; }
.badge.info { background: var(--info-soft); color: var(--info); border-color: transparent; }

.alert { padding: .7rem .9rem; border-radius: 8px; margin-bottom: .75rem; border: 1px solid transparent; display: flex; gap: .6rem; align-items: flex-start; }
.alert.warn { background: var(--warning-soft); color: #7d5208; }
.alert.bad { background: var(--danger-soft); color: #8e2a20; }
.alert.info { background: var(--info-soft); color: #234f82; }
.alert.ok { background: var(--success-soft); color: #145c33; }
.alert .btn { margin-inline-start: auto; }

/* forms */
.form-row { margin-bottom: .9rem; }
label.lbl, .lbl-text { display: block; font-weight: 600; margin-bottom: .3rem; font-size: .9rem; }
.hint { font-size: .8rem; color: var(--muted); margin-top: .25rem; }
.error-text { font-size: .82rem; color: var(--danger); margin-top: .25rem; }
input:not([type]), input[type=text], input[type=password], input[type=tel], input[type=email], input[type=number], input[type=search], input[type=date], input[type=datetime-local], select, textarea {
  width: 100%; padding: .55rem .7rem; border: 1px solid var(--border); border-radius: 8px; font: inherit; background: #fff; color: var(--text);
}
input:focus, select:focus, textarea:focus, .btn:focus-visible, .nav a:focus-visible { outline: 2px solid var(--primary); outline-offset: 1px; border-color: var(--primary); }
textarea { min-height: 120px; resize: vertical; }
input[type=tel], .phone { direction: ltr; text-align: right; }
.filters { display: grid; gap: .5rem; grid-template-columns: 1fr 1fr; margin-bottom: .75rem; }
.filters .wide { grid-column: 1 / -1; }
@media (min-width: 768px) { .filters { grid-template-columns: repeat(6, 1fr); } .filters .wide { grid-column: span 2; } }
.radio-group { display: flex; flex-wrap: wrap; gap: .5rem; }
.radio-group label { display: flex; align-items: center; gap: .4rem; padding: .45rem .8rem; border: 1px solid var(--border); border-radius: 8px; cursor: pointer; background: #fff; }
.radio-group input:checked + span { font-weight: 700; color: var(--primary-dark); }

/* tables -> cards on mobile */
.table-wrap { width: 100%; overflow-x: auto; }
table.tbl { width: 100%; border-collapse: collapse; font-size: .9rem; }
.tbl th, .tbl td { padding: .6rem .5rem; border-bottom: 1px solid var(--border); text-align: right; vertical-align: top; }
.tbl th { background: var(--surface-2); color: var(--muted); font-weight: 600; font-size: .82rem; white-space: nowrap; }
.tbl tr:hover td { background: #fbfcfd; }
@media (max-width: 767px) {
  .tbl thead { display: none; }
  .tbl, .tbl tbody, .tbl tr, .tbl td { display: block; width: 100%; }
  .tbl tr { border: 1px solid var(--border); border-radius: 8px; margin-bottom: .6rem; padding: .4rem .6rem; background: #fff; }
  .tbl td { border: none; padding: .25rem 0; display: flex; gap: .5rem; justify-content: space-between; }
  .tbl td::before { content: attr(data-label); color: var(--muted); font-size: .8rem; flex-shrink: 0; }
  .tbl td.actions-cell { justify-content: flex-end; }
  .tbl td.actions-cell::before { content: none; }
}
.empty { text-align: center; color: var(--muted); padding: 2rem 1rem; }
.pager { display: flex; align-items: center; justify-content: center; gap: .5rem; margin-top: .75rem; }
.truncate { max-width: 260px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; display: inline-block; vertical-align: bottom; }

/* list items */
.list { list-style: none; margin: 0; padding: 0; }
.list li { padding: .55rem 0; border-bottom: 1px solid var(--border); display: flex; gap: .6rem; align-items: flex-start; }
.list li:last-child { border-bottom: none; }
.acc-card { display: flex; flex-direction: column; gap: .5rem; }
.acc-card .top { display: flex; align-items: center; justify-content: space-between; gap: .5rem; }
.kv { display: grid; grid-template-columns: auto 1fr; gap: .2rem .75rem; font-size: .88rem; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; }
.shortcuts { display: flex; gap: .5rem; flex-wrap: wrap; }

/* recipient picker */
.picker { border: 1px solid var(--border); border-radius: 8px; }
.picker .search { border: none; border-bottom: 1px solid var(--border); border-radius: 8px 8px 0 0; }
.picker .opts { max-height: 240px; overflow-y: auto; }
.picker label { display: flex; align-items: center; gap: .5rem; padding: .45rem .7rem; cursor: pointer; border-bottom: 1px solid var(--surface-2); }
.picker label:hover { background: var(--surface-2); }
.chips { display: flex; flex-wrap: wrap; gap: .35rem; margin-top: .5rem; }
.chip { display: inline-flex; align-items: center; gap: .3rem; background: var(--primary-soft); color: var(--primary-dark); border-radius: 999px; padding: .15rem .3rem .15rem .6rem; font-size: .82rem; }
.chip button { border: none; background: transparent; cursor: pointer; color: inherit; padding: 0 .2rem; font-size: 1rem; line-height: 1; }

/* attachments + preview */
.files { display: flex; flex-wrap: wrap; gap: .5rem; margin-top: .5rem; }
.file { border: 1px solid var(--border); border-radius: 8px; padding: .4rem; width: 130px; font-size: .78rem; position: relative; background: #fff; }
.file img { width: 100%; height: 80px; object-fit: cover; border-radius: 6px; display: block; }
.file .doc { height: 80px; display: grid; place-items: center; background: var(--surface-2); border-radius: 6px; font-weight: 700; color: var(--muted); }
.file .name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; margin-top: .25rem; }
.file .rm { position: absolute; top: 4px; left: 4px; background: rgba(255,255,255,.9); border: 1px solid var(--border); border-radius: 50%; width: 24px; height: 24px; cursor: pointer; line-height: 1; }
.wa-preview { background: #e5ddd5; border-radius: 8px; padding: 1rem; min-height: 120px; }
.bubble { background: #dcf8c6; border-radius: 8px; padding: .5rem .7rem; max-width: 90%; margin-inline-start: auto; white-space: pre-wrap; word-break: break-word; box-shadow: 0 1px 1px rgba(0,0,0,.1); margin-bottom: .5rem; }
.bubble img { max-width: 100%; border-radius: 6px; display: block; margin-bottom: .3rem; }
.bubble .doc-line { background: rgba(0,0,0,.05); padding: .4rem; border-radius: 6px; margin-bottom: .3rem; font-size: .85rem; }

/* modal */
.modal-back { position: fixed; inset: 0; background: rgba(15, 23, 30, .45); z-index: 50; display: flex; align-items: flex-end; justify-content: center; }
.modal { background: var(--surface); width: 100%; max-height: 92vh; overflow-y: auto; border-radius: 14px 14px 0 0; padding: 1rem; }
.modal .head { display: flex; align-items: center; justify-content: space-between; margin-bottom: .75rem; }
.modal .foot { display: flex; gap: .5rem; justify-content: flex-start; margin-top: 1rem; flex-wrap: wrap; }
@media (min-width: 640px) {
  .modal-back { align-items: center; }
  .modal { width: min(560px, 94vw); border-radius: 14px; }
  .modal.wide { width: min(860px, 94vw); }
}
.qr-box { display: grid; place-items: center; min-height: 300px; background: var(--surface-2); border-radius: 10px; padding: 1rem; text-align: center; }
.qr-box img { width: 280px; height: 280px; image-rendering: pixelated; background: #fff; padding: 6px; border-radius: 8px; }
.steps { padding-inline-start: 1.2rem; margin: .5rem 0; font-size: .9rem; }

/* toasts */
.toasts { position: fixed; bottom: 1rem; left: 1rem; right: 1rem; z-index: 60; display: flex; flex-direction: column; gap: .5rem; align-items: center; pointer-events: none; }
.toast { pointer-events: auto; background: #22303a; color: #fff; padding: .65rem 1rem; border-radius: 8px; box-shadow: 0 4px 12px rgba(0,0,0,.2); max-width: 480px; width: 100%; }
.toast.ok { background: var(--success); }
.toast.bad { background: var(--danger); }
.toast.warn { background: var(--warning); }
@media (min-width: 640px) { .toasts { right: auto; align-items: flex-start; } }

.loading { display: flex; align-items: center; justify-content: center; gap: .6rem; padding: 2.5rem; color: var(--muted); }

/* login */
.login-wrap { min-height: 100vh; display: grid; place-items: center; padding: 1rem; }
.login-card { width: 100%; max-width: 380px; }
.login-card .brand { justify-content: center; font-size: 1.2rem; margin-bottom: 1rem; }
.login-sub { text-align: center; font-weight: 400; }
.w-100 { width: 100%; }
.mt-1 { margin-top: .75rem; }
.mb-0 { margin-bottom: 0; }
.row-between { display: flex; align-items: center; justify-content: space-between; gap: .5rem; flex-wrap: wrap; }
.wrap-text { white-space: pre-wrap; word-break: break-word; }

/* ===== Roles ===== */
body:not(.is-admin) .admin-only { display: none !important; }
body.is-admin .customer-only { display: none !important; }
.nav .nav-title { font-size: .75rem; color: var(--muted); padding: .2rem .75rem; font-weight: 600; }
body.nav-collapsed .nav .nav-title { display: none; }

/* ===== Plans / billing ===== */
.plans { grid-template-columns: 1fr; }
@media (min-width: 640px) { .plans { grid-template-columns: repeat(2, 1fr); } }
@media (min-width: 1100px) { .plans { grid-template-columns: repeat(3, 1fr); } }
.plan-card { display: flex; flex-direction: column; gap: .5rem; }
.plan-card.current { border-color: var(--primary); box-shadow: 0 0 0 2px var(--primary-soft); }
.plan-card .price { font-size: 1.6rem; font-weight: 700; color: var(--primary-dark); }
.plan-card .price small { font-size: .85rem; color: var(--muted); font-weight: 400; }
.plan-card ul { margin: 0; padding-inline-start: 1.1rem; font-size: .9rem; }
.plan-card .actions { margin-top: auto; }
.meter { height: 8px; border-radius: 999px; background: var(--surface-2); overflow: hidden; margin-top: .3rem; }
.meter > span { display: block; height: 100%; width: 0; background: var(--primary); }
.meter.warn > span { background: var(--warning); }
.meter.bad > span { background: var(--danger); }
.method-box { border: 1px solid var(--border); border-radius: 8px; padding: .7rem; background: var(--surface-2); }
.proof-img { max-width: 100%; max-height: 60vh; border-radius: 8px; border: 1px solid var(--border); display: block; margin: 0 auto; }

/* ===== API ===== */
.code { direction: ltr; text-align: left; background: #1e2a33; color: #e6edf3; border-radius: 8px; padding: .75rem; overflow-x: auto; font-family: ui-monospace, Consolas, monospace; font-size: .82rem; line-height: 1.5; white-space: pre; margin: .5rem 0 1rem; }
.key-box { direction: ltr; font-family: ui-monospace, Consolas, monospace; background: var(--surface-2); border: 1px dashed var(--primary); border-radius: 8px; padding: .6rem; word-break: break-all; user-select: all; }
code.inline { direction: ltr; unicode-bidi: embed; font-family: ui-monospace, Consolas, monospace; background: var(--surface-2); padding: .05rem .35rem; border-radius: 4px; font-size: .85em; }
.check { display: flex; align-items: flex-start; gap: .5rem; font-size: .9rem; cursor: pointer; }
.check input { margin-top: .25rem; }
.row-between > input, .row-between > select { flex: 1 1 220px; width: auto; }
.method-box .key-box { font-family: inherit; font-size: .95rem; unicode-bidi: plaintext; text-align: start; }
.auth-links { text-align: center; margin-top: 1rem; font-size: .9rem; }
