:root {
  --bg: #f4f6f5;
  --panel: #ffffff;
  --ink: #17201d;
  --muted: #5d6b66;
  --line: #e1e7e4;
  --brand: #0f766e;
  --brand-ink: #ffffff;
  --brand-soft: #e3f3f1;
  --ok: #15803d;
  --ok-soft: #e5f6ea;
  --warn: #b45309;
  --warn-soft: #fdf1e1;
  --err: #b91c1c;
  --err-soft: #fde8e8;
  --code-bg: #0f1a17;
  --code-ink: #d7f2ea;
  --radius: 12px;
  --shadow: 0 1px 2px rgba(16, 24, 22, .06), 0 4px 16px rgba(16, 24, 22, .05);
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0d1412; --panel: #141d1a; --ink: #e6efec; --muted: #9aaba5; --line: #24312d;
    --brand: #2dd4bf; --brand-ink: #062320; --brand-soft: #123330;
    --ok: #4ade80; --ok-soft: #10301d; --warn: #fbbf24; --warn-soft: #33270e; --err: #f87171; --err-soft: #3a1616;
    --code-bg: #08100e; --shadow: none;
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg); color: var(--ink);
  font-family: "Segoe UI", Tahoma, "Noto Sans Arabic", "Geeza Pro", Arial, sans-serif;
  font-size: 15px; line-height: 1.6;
}
a { color: var(--brand); }
code, pre, .mono { font-family: Consolas, "Cascadia Mono", "SF Mono", monospace; direction: ltr; unicode-bidi: isolate; }
.boot { padding: 40px; text-align: center; color: var(--muted); }

/* التخطيط */
.layout { display: grid; grid-template-columns: 240px 1fr; min-height: 100vh; }
.side { background: var(--panel); border-inline-end: 1px solid var(--line); padding: 18px 12px; position: sticky; top: 0; height: 100vh; overflow: auto; }
.brand { display: flex; gap: 10px; align-items: center; font-weight: 700; font-size: 17px; padding: 4px 8px 18px; }
.brand img { width: 30px; height: 30px; }
.nav a { display: flex; align-items: center; gap: 8px; padding: 9px 12px; border-radius: 9px; color: var(--ink); text-decoration: none; margin-bottom: 2px; }
.nav a:hover { background: var(--bg); }
.nav a.active { background: var(--brand-soft); color: var(--brand); font-weight: 600; }
.nav .sep { height: 1px; background: var(--line); margin: 12px 6px; }
.side .who { font-size: 13px; color: var(--muted); padding: 10px 12px; }
.main { padding: 26px 30px 60px; max-width: 1150px; width: 100%; }
.topbar { display: none; }
h1 { font-size: 23px; margin: 0 0 4px; }
h2 { font-size: 18px; margin: 0 0 12px; }
h3 { font-size: 15px; margin: 0 0 8px; }
.sub { color: var(--muted); margin: 0 0 22px; }

/* عناصر */
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px 20px; box-shadow: var(--shadow); margin-bottom: 18px; }
.grid { display: grid; gap: 16px; }
.grid.cols-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid.cols-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid.cols-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.row.between { justify-content: space-between; }
.stack > * + * { margin-top: 10px; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.center { text-align: center; }
.hidden { display: none !important; }

.btn { appearance: none; border: 1px solid var(--line); background: var(--panel); color: var(--ink); padding: 8px 14px; border-radius: 9px; font: inherit; cursor: pointer; display: inline-flex; gap: 6px; align-items: center; text-decoration: none; }
.btn:hover { border-color: var(--brand); }
.btn.primary { background: var(--brand); color: var(--brand-ink); border-color: var(--brand); font-weight: 600; }
.btn.big { padding: 13px 22px; font-size: 16px; }
.btn.danger { color: var(--err); }
.btn.danger:hover { border-color: var(--err); }
.btn.sm { padding: 4px 10px; font-size: 13px; }
.btn:disabled { opacity: .55; cursor: not-allowed; }

label { display: block; font-weight: 600; font-size: 14px; margin-bottom: 4px; }
.field { margin-bottom: 14px; }
.hint { font-size: 12.5px; color: var(--muted); margin-top: 3px; }
input[type=text], input[type=email], input[type=password], input[type=tel], input[type=url], select, textarea {
  width: 100%; padding: 9px 11px; border: 1px solid var(--line); border-radius: 9px; background: var(--bg); color: var(--ink); font: inherit;
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--brand); outline-offset: 0; border-color: transparent; }
input.ltr { direction: ltr; text-align: left; }
textarea { min-height: 80px; resize: vertical; }
.check { display: flex; gap: 8px; align-items: flex-start; font-weight: 400; }
.check input { margin-top: 5px; }

.badge { display: inline-flex; align-items: center; gap: 6px; padding: 2px 10px; border-radius: 999px; font-size: 13px; font-weight: 600; background: var(--bg); color: var(--muted); white-space: nowrap; }
.badge::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: currentColor; }
.badge.ok { background: var(--ok-soft); color: var(--ok); }
.badge.warn { background: var(--warn-soft); color: var(--warn); }
.badge.err { background: var(--err-soft); color: var(--err); }
.badge.info { background: var(--brand-soft); color: var(--brand); }
.badge.pulse::before { animation: pulse 1.2s infinite; }
@keyframes pulse { 50% { opacity: .25; } }

.alert { padding: 10px 14px; border-radius: 10px; margin: 10px 0; font-size: 14px; }
.alert.err { background: var(--err-soft); color: var(--err); }
.alert.warn { background: var(--warn-soft); color: var(--warn); }
.alert.ok { background: var(--ok-soft); color: var(--ok); }
.alert.info { background: var(--brand-soft); color: var(--ink); }

table { width: 100%; border-collapse: collapse; font-size: 14px; }
th, td { text-align: start; padding: 8px 10px; border-bottom: 1px solid var(--line); vertical-align: top; }
th { color: var(--muted); font-weight: 600; font-size: 13px; }
.table-wrap { overflow-x: auto; }
td.wrap { max-width: 340px; word-break: break-word; }

pre.code { background: var(--code-bg); color: var(--code-ink); padding: 14px 16px; border-radius: 10px; overflow-x: auto; font-size: 13px; line-height: 1.55; margin: 0; text-align: left; white-space: pre; }
.code-box { position: relative; margin: 8px 0 14px; }
.code-box .copy { position: absolute; top: 8px; left: 8px; }
.code-box pre.code { padding-left: 64px; }
.secret { display: flex; gap: 8px; align-items: center; background: var(--bg); border: 1px dashed var(--brand); border-radius: 10px; padding: 8px 10px; }
.secret code { flex: 1; overflow-x: auto; white-space: nowrap; font-size: 13.5px; }

.tabs { display: flex; gap: 6px; border-bottom: 1px solid var(--line); margin-bottom: 16px; }
.tabs button { background: none; border: none; padding: 9px 14px; font: inherit; color: var(--muted); cursor: pointer; border-bottom: 2px solid transparent; }
.tabs button.active { color: var(--brand); border-bottom-color: var(--brand); font-weight: 600; }

/* بطاقات الأرقام */
.inst { display: flex; flex-direction: column; gap: 10px; }
.inst .name { font-weight: 700; font-size: 16px; }
.inst .phone { direction: ltr; text-align: right; color: var(--muted); }

/* شاشة الربط */
.connect { display: grid; grid-template-columns: 340px 1fr; gap: 26px; align-items: start; }
.qr-box { width: 340px; height: 340px; border-radius: 14px; border: 1px solid var(--line); background: #fff; display: grid; place-items: center; }
.qr-box img { width: 320px; height: 320px; image-rendering: pixelated; }
.qr-box .wait { color: #5d6b66; text-align: center; padding: 20px; }
.pair-code { font-size: 38px; letter-spacing: 6px; font-weight: 700; direction: ltr; text-align: center; background: var(--brand-soft); color: var(--brand); padding: 16px; border-radius: 12px; font-family: Consolas, monospace; }
.steps { padding-inline-start: 20px; margin: 0; }
.steps li { margin-bottom: 6px; }
.success-hero { text-align: center; padding: 10px 0 4px; }
.success-hero .big-ok { font-size: 44px; }

.stat .n { font-size: 28px; font-weight: 700; }
.stat .l { color: var(--muted); font-size: 13px; }

/* المصادقة */
.auth { min-height: 100vh; display: grid; place-items: center; padding: 20px; }
.auth .card { width: 100%; max-width: 420px; }

/* نافذة منبثقة */
.modal-bg { position: fixed; inset: 0; background: rgba(0, 0, 0, .45); display: grid; place-items: center; padding: 16px; z-index: 50; }
.modal { background: var(--panel); border-radius: 14px; width: 100%; max-width: 560px; max-height: 92vh; overflow: auto; padding: 22px; box-shadow: 0 20px 60px rgba(0, 0, 0, .3); }

.toast { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); background: var(--ink); color: var(--panel); padding: 10px 18px; border-radius: 10px; z-index: 60; max-width: 90vw; }
.toast.err { background: var(--err); color: #fff; }

@media (max-width: 900px) {
  .layout { grid-template-columns: 1fr; }
  .side { position: static; height: auto; display: none; }
  .side.open { display: block; }
  .topbar { display: flex; justify-content: space-between; align-items: center; padding: 10px 16px; background: var(--panel); border-bottom: 1px solid var(--line); }
  .main { padding: 18px 16px 50px; }
  .grid.cols-2, .grid.cols-3 { grid-template-columns: 1fr; }
  .grid.cols-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .connect { grid-template-columns: 1fr; }
  .qr-box { width: 100%; max-width: 340px; margin: 0 auto; }
}
