/* ============================================================
   اتصال — Atsal Voice Platform
   واجهة عربية RTL، متجاوبة، تدعم الوضع الفاتح والداكن.
   خطوط النظام فقط — لا موارد خارجية (يعمل بلا إنترنت).
   ============================================================ */

:root {
  --bg: #f6f7f9;
  --surface: #ffffff;
  --surface-2: #fbfcfd;
  --border: #e3e7ec;
  --border-strong: #cbd3dc;
  --text: #16202b;
  --text-dim: #5d6b7a;
  --text-faint: #8b98a7;

  --brand: #0d7f74;
  --brand-dark: #0a635a;
  --brand-light: #e6f4f2;

  --ok: #17795e;
  --ok-bg: #e4f4ee;
  --warn: #9a6400;
  --warn-bg: #fdf2dc;
  --bad: #b3261e;
  --bad-bg: #fdeceb;
  --wait: #1f5c9e;
  --wait-bg: #e8f1fb;

  --radius: 10px;
  --radius-lg: 14px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .05), 0 1px 3px rgba(16, 24, 40, .06);
  --shadow-lg: 0 4px 16px rgba(16, 24, 40, .08);
  --sidebar-w: 258px;

  --font: "Segoe UI", "Tahoma", "Dubai", "Noto Naskh Arabic", "Arial", sans-serif;
  --mono: "Cascadia Mono", "Consolas", "Courier New", monospace;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0f1419;
    --surface: #171d25;
    --surface-2: #1c232c;
    --border: #2a333f;
    --border-strong: #3a4552;
    --text: #e6ebf1;
    --text-dim: #9aa8b8;
    --text-faint: #6d7c8d;

    --brand: #3fbfae;
    --brand-dark: #2fa294;
    --brand-light: #10312e;

    --ok: #5ed4a8;      --ok-bg: #0e2c22;
    --warn: #e3b25f;    --warn-bg: #33270e;
    --bad: #f08a82;     --bad-bg: #351715;
    --wait: #78b4f0;    --wait-bg: #10243a;

    --shadow: 0 1px 2px rgba(0,0,0,.3);
    --shadow-lg: 0 4px 18px rgba(0,0,0,.4);
  }
}

* { box-sizing: border-box; }

html, body {
  margin: 0; padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.65;
  -webkit-text-size-adjust: 100%;
}

a { color: var(--brand); text-decoration: none; }
a:hover { text-decoration: underline; }

.skip {
  position: absolute; right: -9999px; top: 0;
  background: var(--brand); color: #fff; padding: 10px 16px; z-index: 100;
}
.skip:focus { right: 8px; top: 8px; }

/* ---------------- الهيكل ---------------- */
.shell { display: flex; min-height: 100vh; }

.sidebar {
  width: var(--sidebar-w);
  flex: 0 0 var(--sidebar-w);
  background: var(--surface);
  border-left: 1px solid var(--border);
  display: flex; flex-direction: column;
  position: sticky; top: 0; height: 100vh; overflow-y: auto;
}

.brand { display: flex; align-items: center; gap: 11px; padding: 20px 18px 16px; }
.brand-mark {
  width: 38px; height: 38px; flex: 0 0 38px;
  background: var(--brand); color: #fff;
  border-radius: 10px; display: grid; place-items: center;
}
.brand-mark svg { width: 21px; height: 21px; }
.brand-text { display: flex; flex-direction: column; line-height: 1.3; min-width: 0; }
.brand-text strong { font-size: 17px; letter-spacing: -.2px; }
.brand-text span { font-size: 11.5px; color: var(--text-faint); }

.nav { flex: 1; padding: 4px 10px 12px; }
.nav-group { margin-bottom: 14px; }
.nav-group-title {
  font-size: 10.5px; font-weight: 700; letter-spacing: .06em;
  color: var(--text-faint); padding: 6px 10px 5px; text-transform: uppercase;
}
.nav-item {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 10px; margin-bottom: 1px;
  border-radius: 8px; color: var(--text-dim);
  font-size: 14px; transition: background .12s, color .12s;
}
.nav-item:hover { background: var(--surface-2); color: var(--text); text-decoration: none; }
.nav-item.active { background: var(--brand-light); color: var(--brand-dark); font-weight: 600; }
.nav-item svg { width: 17px; height: 17px; flex: 0 0 17px; opacity: .85; }

.sidebar-foot { padding: 12px; border-top: 1px solid var(--border); }
.org-chip {
  display: flex; flex-direction: column; gap: 6px;
  padding: 10px; background: var(--surface-2);
  border: 1px solid var(--border); border-radius: 9px; margin-bottom: 9px;
}
.org-name { font-size: 12.5px; font-weight: 600; }

.content { flex: 1; min-width: 0; display: flex; flex-direction: column; }

.topbar {
  display: flex; align-items: center; gap: 14px;
  padding: 13px 24px; background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 20;
}
.topbar h1 { font-size: 18px; margin: 0; font-weight: 650; flex: 1; letter-spacing: -.2px; }
.topbar-right { display: flex; align-items: center; gap: 10px; }

.avatar {
  width: 32px; height: 32px; border-radius: 50%;
  background: var(--brand); color: #fff;
  display: grid; place-items: center; font-weight: 700; font-size: 14px;
}

.menu-toggle {
  display: none; background: none; border: none; cursor: pointer;
  color: var(--text-dim); padding: 4px;
}
.menu-toggle svg { width: 22px; height: 22px; }

.main { padding: 22px 24px 60px; flex: 1; max-width: 1320px; width: 100%; }

.mode-banner {
  background: var(--warn-bg); color: var(--warn);
  padding: 9px 24px; font-size: 13px;
  border-bottom: 1px solid var(--border);
}
.kill-banner {
  background: var(--bad-bg); color: var(--bad);
  padding: 9px 24px; font-size: 13px; font-weight: 600;
  border-bottom: 1px solid var(--border);
}

/* ---------------- البطاقات ---------------- */
.card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius-lg); box-shadow: var(--shadow);
  margin-bottom: 18px; overflow: hidden;
}
.card-head {
  display: flex; align-items: center; justify-content: space-between;
  gap: 12px; padding: 14px 18px; border-bottom: 1px solid var(--border);
  background: var(--surface-2);
}
.card-head h2 { font-size: 15px; margin: 0; font-weight: 650; }
.card-body { padding: 18px; }
.card-body > :first-child { margin-top: 0; }
.card-body > :last-child { margin-bottom: 0; }

.grid { display: grid; gap: 16px; }
.grid-2 { grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); }
.grid-3 { grid-template-columns: repeat(auto-fit, minmax(230px, 1fr)); }
.grid-4 { grid-template-columns: repeat(auto-fit, minmax(185px, 1fr)); }

/* ---------------- الإحصاءات ---------------- */
.stat {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 15px 16px;
}
.stat-label { font-size: 12.5px; color: var(--text-dim); margin-bottom: 5px; }
.stat-value { font-size: 26px; font-weight: 700; letter-spacing: -.5px; line-height: 1.2; }
.stat-sub { font-size: 11.5px; color: var(--text-faint); margin-top: 3px; }
.stat-ok .stat-value { color: var(--ok); }
.stat-bad .stat-value { color: var(--bad); }
.stat-warn .stat-value { color: var(--warn); }
.stat-brand .stat-value { color: var(--brand); }

/* ---------------- الجداول ---------------- */
.table-wrap { overflow-x: auto; margin: 0 -18px; padding: 0 18px; }
.table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
.table th {
  text-align: right; font-weight: 650; font-size: 12px;
  color: var(--text-dim); padding: 9px 11px;
  border-bottom: 1.5px solid var(--border); white-space: nowrap;
}
.table td { padding: 10px 11px; border-bottom: 1px solid var(--border); vertical-align: middle; }
.table tbody tr:last-child td { border-bottom: none; }
.table tbody tr:hover { background: var(--surface-2); }
.table .num { font-variant-numeric: tabular-nums; }

.empty {
  padding: 44px 20px; text-align: center;
  color: var(--text-faint); font-size: 14px;
}

.pager {
  display: flex; align-items: center; justify-content: center;
  gap: 14px; padding: 14px 0 2px;
}
.pager-info { font-size: 12.5px; color: var(--text-dim); }

/* ---------------- الشارات ---------------- */
.pill {
  display: inline-block; padding: 2px 9px; border-radius: 20px;
  font-size: 11.5px; font-weight: 600; white-space: nowrap;
}
.pill-ok { background: var(--ok-bg); color: var(--ok); }
.pill-warn { background: var(--warn-bg); color: var(--warn); }
.pill-bad { background: var(--bad-bg); color: var(--bad); }
.pill-wait { background: var(--wait-bg); color: var(--wait); }
.pill-muted { background: var(--surface-2); color: var(--text-faint); border: 1px solid var(--border); }

.badge {
  display: inline-block; padding: 2px 8px; border-radius: 6px;
  font-size: 10.5px; font-weight: 700; letter-spacing: .02em;
}
.badge-test { background: var(--warn-bg); color: var(--warn); }
.badge-live { background: var(--ok-bg); color: var(--ok); }

/* ---------------- النماذج ---------------- */
.field { margin-bottom: 15px; }
.field label {
  display: block; font-size: 13px; font-weight: 600;
  margin-bottom: 5px; color: var(--text);
}
.field .hint { font-size: 11.5px; color: var(--text-faint); margin-top: 4px; line-height: 1.5; }

input[type=text], input[type=email], input[type=password], input[type=tel],
input[type=number], input[type=url], input[type=datetime-local], input[type=date],
input[type=file], select, textarea {
  width: 100%; padding: 9px 11px;
  border: 1px solid var(--border-strong); border-radius: 8px;
  background: var(--surface); color: var(--text);
  font-family: inherit; font-size: 14px; line-height: 1.5;
  transition: border-color .12s, box-shadow .12s;
}
input:focus, select:focus, textarea:focus {
  outline: none; border-color: var(--brand);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--brand) 16%, transparent);
}
textarea { resize: vertical; min-height: 90px; line-height: 1.8; }
input:disabled, select:disabled, textarea:disabled {
  background: var(--surface-2); color: var(--text-faint); cursor: not-allowed;
}

.check { display: flex; align-items: flex-start; gap: 8px; margin-bottom: 9px; }
.check input { width: auto; margin-top: 3px; flex: 0 0 auto; }
.check label { margin: 0; font-weight: 500; font-size: 13.5px; }

.row { display: flex; gap: 14px; flex-wrap: wrap; }
.row > * { flex: 1 1 200px; min-width: 0; }

/* ---------------- الأزرار ---------------- */
.btn, .btn-ghost, .btn-danger, .btn-sm {
  display: inline-flex; align-items: center; justify-content: center; gap: 7px;
  padding: 9px 17px; border-radius: 8px; border: 1px solid transparent;
  font-family: inherit; font-size: 14px; font-weight: 600;
  cursor: pointer; transition: background .12s, border-color .12s, opacity .12s;
  text-decoration: none; white-space: nowrap;
}
.btn { background: var(--brand); color: #fff; }
.btn:hover { background: var(--brand-dark); text-decoration: none; }
.btn:disabled { opacity: .5; cursor: not-allowed; }

.btn-ghost {
  background: var(--surface); color: var(--text);
  border-color: var(--border-strong);
}
.btn-ghost:hover { background: var(--surface-2); text-decoration: none; }

.btn-danger { background: var(--bad); color: #fff; }
.btn-danger:hover { opacity: .88; text-decoration: none; }

.btn-sm { padding: 5px 11px; font-size: 12.5px; }
.btn-block { width: 100%; }

.btn-row { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }

/* ---------------- التنبيهات ---------------- */
.alert {
  padding: 11px 14px; border-radius: 9px;
  font-size: 13.5px; margin-bottom: 16px; border: 1px solid transparent;
}
.alert-ok { background: var(--ok-bg); color: var(--ok); border-color: color-mix(in srgb, var(--ok) 25%, transparent); }
.alert-error { background: var(--bad-bg); color: var(--bad); border-color: color-mix(in srgb, var(--bad) 25%, transparent); }
.alert-warn { background: var(--warn-bg); color: var(--warn); border-color: color-mix(in srgb, var(--warn) 25%, transparent); }
.alert-info { background: var(--wait-bg); color: var(--wait); border-color: color-mix(in srgb, var(--wait) 25%, transparent); }

/* ---------------- الشيفرة ---------------- */
code, pre, .mono { font-family: var(--mono); font-size: 12.5px; direction: ltr; }
code {
  background: var(--surface-2); padding: 1px 5px;
  border-radius: 4px; border: 1px solid var(--border);
  unicode-bidi: embed;
}
pre {
  background: var(--surface-2); border: 1px solid var(--border);
  border-radius: 9px; padding: 13px 15px; overflow-x: auto;
  text-align: left; direction: ltr; line-height: 1.6; margin: 0 0 14px;
}
pre code { background: none; border: none; padding: 0; }

.secret-box {
  display: flex; align-items: center; gap: 9px;
  background: var(--warn-bg); border: 1px solid var(--warn);
  border-radius: 9px; padding: 12px 14px; margin: 12px 0;
}
.secret-box code {
  flex: 1; background: var(--surface); font-size: 13px;
  padding: 7px 10px; overflow-x: auto; white-space: nowrap;
}

/* ---------------- تسجيل الدخول ---------------- */
.auth-wrap {
  min-height: 100vh; display: grid; place-items: center;
  padding: 24px; background: var(--bg);
}
.auth-card {
  width: 100%; max-width: 400px; background: var(--surface);
  border: 1px solid var(--border); border-radius: 16px;
  padding: 34px 30px; box-shadow: var(--shadow-lg);
}
.auth-brand { text-align: center; margin-bottom: 26px; }
.auth-brand .brand-mark { margin: 0 auto 12px; width: 50px; height: 50px; }
.auth-brand .brand-mark svg { width: 27px; height: 27px; }
.auth-brand h1 { font-size: 22px; margin: 0 0 4px; }
.auth-brand p { font-size: 13px; color: var(--text-dim); margin: 0; }

/* ---------------- عناصر متنوعة ---------------- */
.section-title {
  font-size: 13px; font-weight: 700; color: var(--text-dim);
  margin: 26px 0 12px; padding-bottom: 7px;
  border-bottom: 1px solid var(--border);
}
.section-title:first-child { margin-top: 0; }

.kv { display: grid; grid-template-columns: minmax(120px, auto) 1fr; gap: 8px 16px; font-size: 13.5px; }
.kv dt { color: var(--text-dim); }
.kv dd { margin: 0; font-weight: 500; word-break: break-word; }

.progress {
  height: 7px; background: var(--surface-2);
  border-radius: 20px; overflow: hidden; border: 1px solid var(--border);
}
.progress-bar { height: 100%; background: var(--brand); transition: width .3s; }
.progress-bar.warn { background: var(--warn); }
.progress-bar.bad { background: var(--bad); }

.dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; margin-left: 6px; }
.dot-ok { background: var(--ok); }
.dot-bad { background: var(--bad); }
.dot-warn { background: var(--warn); }
.dot-muted { background: var(--text-faint); }

.tabs { display: flex; gap: 3px; border-bottom: 1px solid var(--border); margin-bottom: 18px; overflow-x: auto; }
.tab {
  padding: 9px 15px; font-size: 13.5px; font-weight: 600;
  color: var(--text-dim); border-bottom: 2px solid transparent;
  white-space: nowrap;
}
.tab:hover { color: var(--text); text-decoration: none; }
.tab.active { color: var(--brand); border-bottom-color: var(--brand); }

.muted { color: var(--text-dim); }
.faint { color: var(--text-faint); }
.small { font-size: 12.5px; }
.nowrap { white-space: nowrap; }
.ltr { direction: ltr; text-align: left; unicode-bidi: embed; }
.center { text-align: center; }
.mt { margin-top: 16px; }
.mb { margin-bottom: 16px; }

/* ---------------- التجاوب ---------------- */
@media (max-width: 900px) {
  .sidebar {
    position: fixed; right: 0; top: 0; z-index: 50;
    transform: translateX(100%); transition: transform .22s ease;
    box-shadow: var(--shadow-lg);
  }
  .sidebar.open { transform: translateX(0); }
  .menu-toggle { display: block; }
  .main { padding: 16px 14px 50px; }
  .topbar { padding: 11px 14px; }
  .topbar h1 { font-size: 16px; }
  .mode-banner, .kill-banner { padding: 8px 14px; font-size: 12px; }
  .card-body { padding: 14px; }
  .table-wrap { margin: 0 -14px; padding: 0 14px; }
  .stat-value { font-size: 22px; }
}

@media print {
  .sidebar, .topbar, .btn-row, .pager { display: none; }
  .card { border: 1px solid #ccc; box-shadow: none; break-inside: avoid; }
}
