/* ============ SaaS Control Center — mobile-first RTL ============ */
:root {
  --bg: #f4f6f5;
  --surface: #ffffff;
  --surface-2: #eef2f1;
  --text: #15201e;
  --muted: #5d6b68;
  --border: #dde4e2;
  --primary: #0f766e;
  --primary-ink: #ffffff;
  --primary-soft: #d6efec;
  --green: #15803d;   --green-soft: #dcfce7;
  --yellow: #a16207;  --yellow-soft: #fef3c7;
  --red: #b91c1c;     --red-soft: #fee2e2;
  --blue: #1d4ed8;    --blue-soft: #dbeafe;
  --shadow: 0 1px 2px rgba(0,0,0,.05), 0 4px 16px rgba(0,0,0,.05);
  --radius: 14px;
  --drawer-w: 264px;
  color-scheme: light;
}
:root[data-theme="dark"] {
  --bg: #0d1413;
  --surface: #152120;
  --surface-2: #1c2b29;
  --text: #e6eeec;
  --muted: #93a5a1;
  --border: #263735;
  --primary: #2dd4bf;
  --primary-ink: #04201c;
  --primary-soft: #133b37;
  --green: #4ade80;  --green-soft: #12301f;
  --yellow: #facc15; --yellow-soft: #3a3010;
  --red: #f87171;    --red-soft: #3b1717;
  --blue: #93c5fd;   --blue-soft: #172a4a;
  --shadow: 0 1px 2px rgba(0,0,0,.3), 0 4px 16px rgba(0,0,0,.25);
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  font-family: "Noto Sans Arabic", "Segoe UI", Tahoma, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 15px;
  line-height: 1.6;
  -webkit-tap-highlight-color: transparent;
}
a { color: var(--primary); text-decoration: none; }
svg { width: 22px; height: 22px; fill: currentColor; flex-shrink: 0; }
.num, .ltr { direction: ltr; unicode-bidi: isolate; display: inline-block; }

/* ---------- Shell ---------- */
.app { min-height: 100vh; }
.drawer {
  position: fixed; inset-block: 0; inset-inline-start: 0;
  width: var(--drawer-w); max-width: 85vw;
  background: var(--surface); border-inline-end: 1px solid var(--border);
  display: flex; flex-direction: column;
  transform: translateX(100%); transition: transform .25s ease;
  z-index: 50;
}
.drawer.open { transform: translateX(0); }
.backdrop {
  position: fixed; inset: 0; background: rgba(0,0,0,.4);
  opacity: 0; pointer-events: none; transition: opacity .2s; z-index: 40;
}
.backdrop.show { opacity: 1; pointer-events: auto; }
.drawer-head { display: flex; align-items: center; justify-content: space-between; padding: 16px; border-bottom: 1px solid var(--border); }
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; }
.brand-mark { width: 34px; height: 34px; border-radius: 10px; background: var(--primary); color: var(--primary-ink); display: grid; place-items: center; }
.brand-text { font-size: 14px; }
.nav { padding: 8px; overflow-y: auto; flex: 1; }
.nav a {
  display: flex; align-items: center; gap: 12px;
  padding: 12px 14px; margin-bottom: 2px; border-radius: 10px;
  color: var(--text); min-height: 46px;
}
.nav a svg { color: var(--muted); }
.nav a:hover { background: var(--surface-2); }
.nav a.active { background: var(--primary-soft); color: var(--primary); font-weight: 600; }
.nav a.active svg { color: var(--primary); }
.drawer-foot { padding: 14px 16px; border-top: 1px solid var(--border); display: flex; justify-content: space-between; align-items: center; font-size: 13px; }
.link-muted { color: var(--muted); }

.topbar {
  position: sticky; top: 0; z-index: 30;
  display: flex; align-items: center; gap: 8px;
  padding: 10px 12px; padding-top: max(10px, env(safe-area-inset-top));
  background: color-mix(in srgb, var(--surface) 92%, transparent);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--border);
}
.page-title { font-size: 17px; margin: 0; flex: 1; font-weight: 700; }
.icon-btn {
  width: 44px; height: 44px; border-radius: 12px; border: 0;
  background: transparent; color: var(--text); display: grid; place-items: center; cursor: pointer;
}
.icon-btn:hover { background: var(--surface-2); }
.i-sun { display: none; }
[data-theme="dark"] .i-sun { display: block; }
[data-theme="dark"] .i-moon { display: none; }

.content { padding: 14px; padding-bottom: 96px; max-width: 1280px; margin-inline: auto; }

@media (min-width: 1024px) {
  .drawer { transform: none; }
  .drawer-close, .menu-btn, .backdrop { display: none; }
  .main { margin-inline-start: var(--drawer-w); }
  .content { padding: 24px; }
  .fab { display: none; }
}

/* ---------- Cards & grid ---------- */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); padding: 16px; margin-bottom: 14px; }
.card h2, .card h3 { margin: 0 0 12px; font-size: 16px; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 12px; flex-wrap: wrap; }
.card-head h2 { margin: 0; }
.grid { display: grid; gap: 12px; }
.kpis { grid-template-columns: repeat(2, 1fr); margin-bottom: 14px; }
@media (min-width: 720px) { .kpis { grid-template-columns: repeat(4, 1fr); } .grid-2 { grid-template-columns: 1fr 1fr; } }
.kpi { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px; box-shadow: var(--shadow); }
.kpi .label { color: var(--muted); font-size: 12.5px; }
.kpi .value { font-size: 24px; font-weight: 700; margin-top: 2px; direction: ltr; text-align: end; unicode-bidi: plaintext; }
.kpi.green .value { color: var(--green); }
.kpi.yellow .value { color: var(--yellow); }
.kpi.red .value { color: var(--red); }
.muted { color: var(--muted); }
.small { font-size: 12.5px; }

/* ---------- Badges / alerts ---------- */
.badge { display: inline-block; padding: 2px 10px; border-radius: 999px; font-size: 12px; font-weight: 600; white-space: nowrap; }
.badge-active, .badge-paid { background: var(--green-soft); color: var(--green); }
.badge-warning, .badge-pending { background: var(--yellow-soft); color: var(--yellow); }
.badge-expired, .badge-cancelled, .badge-failed, .badge-blocked { background: var(--red-soft); color: var(--red); }
.badge-sent, .badge-info { background: var(--blue-soft); color: var(--blue); }
.alert { padding: 12px 14px; border-radius: 12px; margin-bottom: 12px; font-size: 14px; }
.alert-ok { background: var(--green-soft); color: var(--green); }
.alert-err { background: var(--red-soft); color: var(--red); }
.alert-warn { background: var(--yellow-soft); color: var(--yellow); }
.alert-info { background: var(--blue-soft); color: var(--blue); }

/* ---------- Forms ---------- */
.form-grid { display: grid; gap: 12px; }
@media (min-width: 720px) { .form-grid { grid-template-columns: 1fr 1fr; } .form-grid .full { grid-column: 1 / -1; } }
label { display: block; font-size: 13px; color: var(--muted); margin-bottom: 4px; }
input, select, textarea {
  width: 100%; font: inherit; color: var(--text);
  background: var(--surface-2); border: 1px solid var(--border); border-radius: 10px;
  padding: 10px 12px; min-height: 46px;
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--primary); outline-offset: 0; border-color: transparent; }
textarea { min-height: 90px; }
input[type="checkbox"] { width: auto; min-height: 0; }
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 44px; padding: 8px 16px; border-radius: 10px; border: 1px solid transparent;
  background: var(--primary); color: var(--primary-ink); font: inherit; font-weight: 600; cursor: pointer;
}
.btn:hover { filter: brightness(1.05); }
.btn-ghost { background: var(--surface-2); color: var(--text); border-color: var(--border); }
.btn-danger { background: var(--red); color: #fff; }
.btn-sm { min-height: 36px; padding: 4px 12px; font-size: 13px; }
.btn-block { width: 100%; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; }
.filters { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 12px; }
.filters input, .filters select { flex: 1 1 140px; }
.chips { display: flex; gap: 6px; overflow-x: auto; padding-bottom: 4px; margin-bottom: 12px; }
.chip { white-space: nowrap; padding: 6px 14px; border-radius: 999px; background: var(--surface); border: 1px solid var(--border); color: var(--text); font-size: 13px; }
.chip.on { background: var(--primary); border-color: var(--primary); color: var(--primary-ink); }

/* ---------- Tables → cards on mobile ---------- */
.table { width: 100%; border-collapse: collapse; font-size: 14px; }
.table th, .table td { padding: 10px 8px; text-align: start; border-bottom: 1px solid var(--border); vertical-align: middle; }
.table th { color: var(--muted); font-weight: 500; font-size: 12.5px; }
@media (max-width: 719px) {
  .table thead { display: none; }
  .table, .table tbody, .table tr, .table td { display: block; width: 100%; }
  .table tr { border: 1px solid var(--border); border-radius: 12px; padding: 8px 12px; margin-bottom: 10px; background: var(--surface); }
  .table td { border: 0; padding: 4px 0; display: flex; justify-content: space-between; gap: 12px; }
  .table td::before { content: attr(data-l); color: var(--muted); font-size: 12.5px; }
  .table td.td-main { font-weight: 600; font-size: 15px; }
  .table td.td-main::before { content: none; }
}
.list { list-style: none; margin: 0; padding: 0; }
.list li { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 10px 0; border-bottom: 1px solid var(--border); }
.list li:last-child { border-bottom: 0; }

/* ---------- FAB ---------- */
.fab { position: fixed; inset-inline-end: auto; left: 16px; bottom: max(16px, env(safe-area-inset-bottom)); z-index: 35; }
.fab-btn { width: 58px; height: 58px; border-radius: 18px; border: 0; background: var(--primary); color: var(--primary-ink); box-shadow: 0 8px 24px rgba(15,118,110,.35); display: grid; place-items: center; cursor: pointer; transition: transform .2s; }
.fab-btn svg { width: 28px; height: 28px; }
.fab.open .fab-btn { transform: rotate(45deg); }
.fab-menu { position: absolute; bottom: 70px; left: 0; display: none; flex-direction: column; gap: 8px; min-width: 200px; }
.fab.open .fab-menu { display: flex; }
.fab-menu a { background: var(--surface); color: var(--text); border: 1px solid var(--border); box-shadow: var(--shadow); padding: 12px 16px; border-radius: 12px; font-weight: 500; }

/* ---------- Map ---------- */
#map { height: calc(100vh - 230px); min-height: 380px; border-radius: var(--radius); border: 1px solid var(--border); z-index: 1; }
.legend { display: flex; gap: 14px; flex-wrap: wrap; font-size: 13px; margin-bottom: 10px; }
.dot { width: 12px; height: 12px; border-radius: 50%; display: inline-block; vertical-align: middle; margin-inline-end: 4px; }
.dot-active { background: #16a34a; } .dot-warning { background: #eab308; } .dot-expired { background: #dc2626; }
.leaflet-popup-content { font-family: inherit; direction: rtl; text-align: right; }

/* ---------- Misc ---------- */
.secret { font-family: ui-monospace, monospace; direction: ltr; background: var(--surface-2); border: 1px dashed var(--border); padding: 10px; border-radius: 10px; word-break: break-all; font-size: 13px; user-select: all; }
.score-bar { height: 8px; background: var(--surface-2); border-radius: 999px; overflow: hidden; min-width: 80px; }
.score-bar > span { display: block; height: 100%; background: var(--primary); }
.tip { border-inline-start: 4px solid var(--primary); background: var(--primary-soft); padding: 12px 14px; border-radius: 10px; margin-bottom: 10px; }
.tip strong { display: block; margin-bottom: 2px; }
.chart-box { position: relative; height: 260px; }

/* ---------- Login ---------- */
.auth-wrap { min-height: 100vh; display: grid; place-items: center; padding: 20px; }
.auth-card { width: 100%; max-width: 380px; }
