:root {
  --bg: #f3f5f8;
  --surface: #ffffff;
  --text: #13202e;
  --muted: #66758a;
  --line: #e2e7ee;
  --brand: #0f2a44;
  --brand-2: #1b4a73;
  --green: #17a34a;
  --red: #dc3b3b;
  --amber: #e2a01b;
  --shadow: 0 6px 24px rgba(15, 42, 68, .08);
  --radius: 16px;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0c1622; --surface: #142232; --text: #e6edf5; --muted: #8fa1b6;
    --line: #22354a; --brand: #0a1c2e; --brand-2: #2d6aa1; --shadow: 0 6px 24px rgba(0,0,0,.35);
  }
}
:root[data-theme="dark"] {
  --bg: #0c1622; --surface: #142232; --text: #e6edf5; --muted: #8fa1b6;
  --line: #22354a; --brand: #0a1c2e; --brand-2: #2d6aa1; --shadow: 0 6px 24px rgba(0,0,0,.35);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; }
body {
  font-family: "IBM Plex Sans Arabic", system-ui, sans-serif;
  background: var(--bg); color: var(--text); font-size: 15px;
  overscroll-behavior: none;
}
button, input, select { font: inherit; color: inherit; }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.center { text-align: center; }
.err { color: var(--red); min-height: 1.2em; margin: 8px 0 0; }

/* ── الدخول */
.login { min-height: 100dvh; display: flex; flex-direction: column; align-items: center; background: var(--bg); }
.login-hero { width: 100%; text-align: center; color: #fff; padding: max(48px, env(safe-area-inset-top)) 16px 84px;
  background: radial-gradient(500px 260px at 85% 0%, rgba(192,132,252,.45), transparent 60%), linear-gradient(135deg, #17124a 0%, #2d1a86 55%, #6a3cf2 100%);
  border-radius: 0 0 36px 36px; }
.login-logo { width: 72px; height: 72px; margin: 0 auto 14px; border-radius: 22px; background: rgba(255,255,255,.14); border: 1px solid rgba(255,255,255,.25);
  display: grid; place-items: center; box-shadow: 0 14px 30px rgba(10, 5, 40, .3); }
.login-logo svg { width: 34px; height: 34px; fill: none; stroke: #fff; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.login-hero h1 { margin: 0 0 6px; font-size: 23px; font-weight: 700; }
.login-hero p { margin: 0; opacity: .8; }
.login-card { background: var(--surface); width: min(420px, calc(100% - 32px)); margin-top: -56px; border-radius: 26px; padding: 26px 22px 22px;
  box-shadow: 0 20px 50px rgba(23, 18, 74, .14); text-align: start; }
.login-card h2 { margin: 0 0 4px; font-size: 20px; }
.login-card > p { margin: 0 0 18px; font-size: 14px; }
.lbl { display: block; font-size: 13px; font-weight: 700; margin: 14px 0 7px; color: var(--text); }
.inp { display: flex; align-items: center; gap: 10px; border: 1.5px solid var(--line); border-radius: 15px; padding: 0 14px; height: 54px; background: var(--bg);
  transition: border-color .15s, box-shadow .15s; }
.inp:focus-within { border-color: #6c47ff; box-shadow: 0 0 0 4px rgba(108, 71, 255, .14); background: var(--surface); }
.inp svg { width: 20px; height: 20px; fill: none; stroke: var(--muted); stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; flex: none; }
.inp input { border: 0; outline: 0; background: none; flex: 1; min-width: 0; height: 100%; font-size: 17px; color: var(--text); }
.inp button { border: 0; background: none; cursor: pointer; padding: 4px; display: grid; place-items: center; }
.btn.big { height: 54px; font-size: 17px; border-radius: 15px; margin-top: 8px; }
.login .btn.primary { background: linear-gradient(135deg, #6c47ff, #8b5cf6); box-shadow: 0 10px 24px rgba(108, 71, 255, .32); }
.login-feats { display: flex; justify-content: center; gap: 8px; flex-wrap: wrap; margin-top: 18px; }
.hero-feats { display: none; }
/* على الكمبيوتر: شاشة مقسومة — النموذج يمين واللوحة البنفسجية يسار */
@media (min-width: 900px) {
  .login { flex-direction: row; align-items: stretch; min-height: 100vh; }
  .login-hero { flex: 1.1; border-radius: 0; display: flex; flex-direction: column; justify-content: center; align-items: flex-start; text-align: start;
    padding: 48px clamp(28px, 5vw, 80px); }
  .login-logo { margin: 0 0 22px; }
  .login-hero h1 { font-size: 34px; }
  .login-hero p { font-size: 16px; }
  .hero-feats { display: grid; gap: 12px; margin-top: 32px; width: 100%; max-width: 440px; }
  .hero-feats div { display: grid; grid-template-columns: 44px 1fr; column-gap: 14px; align-items: center; background: rgba(255,255,255,.08);
    border: 1px solid rgba(255,255,255,.14); border-radius: 18px; padding: 14px 16px; }
  .hero-feats span { grid-row: span 2; width: 44px; height: 44px; border-radius: 13px; background: rgba(255,255,255,.14); display: grid; place-items: center; font-size: 20px; }
  .hero-feats small { opacity: .75; }
  .login-card { order: -1; flex: 1; margin: 0; width: auto; border-radius: 0; box-shadow: none; display: flex; flex-direction: column; justify-content: center;
    align-items: center; padding: 48px clamp(24px, 6vw, 88px); }
  .login-card > * { width: 100%; max-width: 420px; }
  .login-card h2 { font-size: 30px; margin-bottom: 8px; }
  .login-card > p { font-size: 15px; margin-bottom: 22px; }
  .login-feats { justify-content: flex-start; }
}
.login-feats span { font-size: 12px; color: var(--muted); background: var(--bg); border-radius: 20px; padding: 5px 11px; }
label { display: block; text-align: start; font-size: 13px; color: var(--muted); margin: 14px 0 0; }
label input, label select { display: block; width: 100%; margin-top: 6px; padding: 12px 14px; border-radius: 12px;
  border: 1px solid var(--line); background: var(--bg); color: var(--text); font-size: 16px; }
label input:focus { outline: 2px solid var(--brand-2); outline-offset: 0; }

.btn { border: 1px solid var(--line); background: var(--surface); padding: 11px 16px; border-radius: 12px; cursor: pointer; font-weight: 600; margin-top: 14px; }
.btn.primary { background: var(--brand-2); color: #fff; border-color: transparent; }
.btn.danger { color: var(--red); }
.btn.block { width: 100%; }

/* ── التطبيق */
#app { display: flex; flex-direction: column; height: 100dvh; max-width: 560px; margin: 0 auto; }
.top { display: flex; align-items: center; justify-content: space-between; padding: 14px 16px; padding-top: max(14px, env(safe-area-inset-top));
  background: var(--brand); color: #fff; }
.me { display: flex; align-items: center; gap: 10px; }
.me strong { display: block; font-size: 16px; }
.me small { opacity: .8; }
.conn-text { font-size: 12px; opacity: .8; }
.dot { width: 10px; height: 10px; border-radius: 50%; display: inline-block; flex: none; background: #8a96a5; }
.dot.online { background: var(--green); box-shadow: 0 0 0 3px rgba(23,163,74,.2); }
.dot.busy { background: var(--red); }
.dot.offline { background: #8a96a5; }

.banner { background: var(--amber); color: #2a1a00; padding: 10px 16px; font-weight: 600; font-size: 14px; cursor: pointer; text-align: center; }
main { flex: 1; overflow-y: auto; padding: 16px; }

.tabs { display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; background: var(--surface); border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom); }
.tabs button { border: 0; background: none; padding: 9px 0 10px; display: flex; flex-direction: column; align-items: center; gap: 2px;
  font-size: 12px; color: var(--muted); cursor: pointer; position: relative; }
.tabs button span { font-size: 19px; filter: grayscale(1); opacity: .7; }
.tabs button.active { color: var(--brand-2); font-weight: 700; }
.tabs button.active span { filter: none; opacity: 1; }
.badge { position: absolute; top: 4px; inset-inline-start: calc(50% + 6px); background: var(--red); color: #fff; font-style: normal;
  font-size: 11px; min-width: 18px; height: 18px; line-height: 18px; border-radius: 9px; padding: 0 5px; }

/* ── لوحة الأرقام */
.dial-display { text-align: center; padding: 10px 0 6px; }
#dialInput { width: 100%; border: 0; background: none; text-align: center; font-size: 34px; font-weight: 600; letter-spacing: 2px; direction: ltr; outline: none; }
#dialInput::placeholder { font-size: 16px; letter-spacing: 0; font-weight: 400; color: var(--muted); }
.dial-hint { min-height: 22px; color: var(--muted); font-size: 14px; }
.pad { display: grid; grid-template-columns: repeat(3, 1fr); gap: 14px; max-width: 300px; margin: 10px auto; direction: ltr; }
.pad button { aspect-ratio: 1; border-radius: 50%; border: 0; background: var(--surface); box-shadow: var(--shadow);
  font-size: 28px; font-weight: 500; cursor: pointer; max-width: 84px; justify-self: center; width: 100%; }
.pad button:active { background: var(--line); }
.pad-actions { display: grid; grid-template-columns: repeat(3, 1fr); max-width: 300px; margin: 8px auto 0; align-items: center; justify-items: center; }
.ghost-btn { border: 0; background: none; font-size: 26px; color: var(--muted); cursor: pointer; padding: 10px; }

.round { width: 64px; height: 64px; border-radius: 50%; border: 0; display: grid; place-items: center; cursor: pointer; color: #fff; position: relative; }
.round svg { width: 28px; height: 28px; fill: currentColor; }
.round.big { width: 76px; height: 76px; }
.round.big svg { width: 34px; height: 34px; }
.round.green { background: var(--green); }
.round.red { background: var(--red); }
.round.dim { background: rgba(255,255,255,.14); }
.round.dim.on { background: #fff; color: var(--brand); }
.round small { position: absolute; bottom: -22px; font-size: 12px; color: rgba(255,255,255,.8); }
.round-spacer { width: 64px; }
.pulse { animation: pulse 1.4s infinite; }
@keyframes pulse { 0% { box-shadow: 0 0 0 0 rgba(23,163,74,.6); } 70% { box-shadow: 0 0 0 18px rgba(23,163,74,0); } 100% { box-shadow: 0 0 0 0 rgba(23,163,74,0); } }

/* ── القوائم */
.search { width: 100%; padding: 12px 14px; border-radius: 12px; border: 1px solid var(--line); background: var(--surface); font-size: 15px; }
.sec-title { font-size: 13px; color: var(--muted); margin: 18px 4px 8px; font-weight: 600; }
.list { list-style: none; margin: 0; padding: 0; background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden; }
.list:empty::after { content: attr(data-empty); display: block; padding: 18px; text-align: center; color: var(--muted); font-size: 14px; }
.list li { display: flex; align-items: center; gap: 12px; padding: 12px 14px; border-bottom: 1px solid var(--line); cursor: pointer; }
.list li:last-child { border-bottom: 0; }
.list li:active { background: var(--bg); }
.list .av { width: 40px; height: 40px; border-radius: 50%; background: var(--brand-2); color: #fff; display: grid; place-items: center;
  font-weight: 700; flex: none; position: relative; }
.list .av .dot { position: absolute; bottom: 0; inset-inline-end: 0; border: 2px solid var(--surface); width: 12px; height: 12px; box-shadow: none; }
.list .grow { flex: 1; min-width: 0; }
.list .grow b { display: block; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.list .grow small { color: var(--muted); }
.list .end { color: var(--muted); font-size: 12px; text-align: end; flex: none; }
.list li.missed b { color: var(--red); }
.list .ico { font-size: 14px; }

.rec-item { flex-wrap: wrap; cursor: default !important; }
.rec-item .play { border: 0; background: var(--brand-2); color: #fff; border-radius: 20px; padding: 7px 14px; font-weight: 600; cursor: pointer; flex: none; }
.rec-item audio { width: 100%; height: 36px; margin-top: 4px; }
.card { background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow); padding: 16px; margin-bottom: 14px; }
.card h3 { margin: 0 0 4px; font-size: 16px; }
.card .btn { margin-inline-end: 8px; }
.meter { height: 8px; background: var(--line); border-radius: 4px; margin-top: 14px; overflow: hidden; }
.meter i { display: block; height: 100%; width: 0; background: var(--green); transition: width .08s; }

/* ── شاشة المكالمة */
.call-screen { position: fixed; inset: 0; z-index: 20; display: flex; flex-direction: column; justify-content: space-between; align-items: center;
  padding: max(40px, env(safe-area-inset-top)) 16px max(48px, env(safe-area-inset-bottom));
  background: linear-gradient(170deg, var(--brand-2), #081523); color: #fff; }
.call-top { text-align: center; margin-top: 4vh; }
.avatar { width: 108px; height: 108px; border-radius: 50%; background: rgba(255,255,255,.12); display: grid; place-items: center;
  font-size: 42px; font-weight: 700; margin: 14px auto; }
.call-top h2 { margin: 0; font-size: 26px; }
.call-ext { margin: 4px 0; opacity: .75; direction: ltr; }
.call-state { margin: 10px 0 0; font-size: 17px; opacity: .9; font-variant-numeric: tabular-nums; }
.via { font-size: 13px; opacity: .8; min-height: 1.2em; }
.rec { display: inline-block; font-size: 12px; background: rgba(220,59,59,.25); color: #ffb4b4; padding: 4px 10px; border-radius: 20px; margin-bottom: 6px; }
.call-actions { display: flex; gap: 56px; align-items: center; justify-content: center; }

.toast { position: fixed; bottom: calc(84px + env(safe-area-inset-bottom)); left: 50%; transform: translateX(-50%); z-index: 30;
  background: #13202e; color: #fff; padding: 10px 18px; border-radius: 12px; font-size: 14px; box-shadow: var(--shadow); max-width: calc(100% - 32px); text-align: center; }
