:root {
  --bg: #f6f7f9;
  --card: #ffffff;
  --text: #111827;
  --muted: #6b7280;
  --line: #e7e9ee;
  --key: #f0f2f5;
  --key-hover: #e4e7ec;
  --primary: #3b6cf6;
  --primary-ink: #ffffff;
  --green: #16a34a;
  --red: #dc2626;
  --amber: #d97706;
  --purple: #7c3aed;
  --slate: #64748b;
  --radius: 14px;
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0e1116;
    --card: #161a21;
    --text: #eceef2;
    --muted: #8b93a1;
    --line: #262b34;
    --key: #1f242c;
    --key-hover: #2a303a;
    --primary: #5b86ff;
  }
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 "IBM Plex Sans Arabic", "Segoe UI", Tahoma, system-ui, sans-serif;
}
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--primary); }
[hidden] { display: none !important; }
.num { direction: ltr; unicode-bidi: isolate; font-variant-numeric: tabular-nums; }
svg.i { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; flex: none; }

/* ---------- buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  padding: 12px 16px; border: 0; border-radius: 12px; cursor: pointer;
  font-weight: 600; text-decoration: none; color: #fff; white-space: nowrap;
}
.btn.primary { background: var(--primary); color: var(--primary-ink); }
.btn.call { background: var(--green); }
.btn.hangup { background: var(--red); }
.btn.ghost { background: var(--key); color: var(--text); }
.btn.ghost:hover { background: var(--key-hover); }
.btn.small { padding: 8px 14px; font-size: 14px; border-radius: 10px; }
.btn:disabled { opacity: .5; cursor: default; }

/* ---------- centered pages (login, setup) ---------- */
body.center { display: grid; place-items: center; padding: 16px; }
.card { background: var(--card); border-radius: 20px; padding: 20px; border: 1px solid var(--line); }
.center .card { width: min(440px, 100%); }
.login h1, .setup h1 { font-size: 22px; margin: 0 0 14px; }
.login form { display: grid; gap: 12px; }
.login input, .setup select, .setup input:not([type=checkbox]) {
  width: 100%; padding: 11px 14px; border-radius: 12px; border: 1px solid var(--line); background: var(--bg);
}
.setup h2 { font-size: 16px; margin: 22px 0 6px; }
.setup section { display: grid; gap: 8px; }
.setup label { display: grid; gap: 4px; font-size: 14px; color: var(--muted); }
.setup label.check { display: flex; align-items: center; gap: 8px; color: var(--text); font-size: 15px; }
.setup label.check input { width: 18px; height: 18px; }
.setup pre { margin: 0; padding: 10px 12px; border-radius: 10px; background: var(--bg); font-size: 13px; white-space: pre-wrap; overflow-wrap: anywhere; direction: ltr; text-align: left; }
.btn.wide { width: 100%; margin-top: 16px; }
.hint { margin: 0; color: var(--muted); font-size: 14px; }
.msg { min-height: 1.5em; color: var(--muted); font-size: 14px; margin: 8px 0 0; }
.link { display: inline-block; margin-top: 18px; text-decoration: none; font-size: 14px; }

/* ---------- app shell ---------- */
body.app { display: grid; grid-template-columns: 250px minmax(0, 1fr) 380px; min-height: 100vh; }
.nav {
  background: var(--card); border-inline-end: 1px solid var(--line);
  display: flex; flex-direction: column; gap: 6px; padding: 18px 14px;
  position: sticky; top: 0; height: 100vh;
}
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 17px; padding: 4px 8px 18px; }
.brand .logo { width: 34px; height: 34px; border-radius: 10px; background: var(--primary); color: #fff; display: grid; place-items: center; }
.nav button, .nav a.navlink {
  display: flex; align-items: center; gap: 10px; padding: 11px 14px; border-radius: 12px;
  border: 1.5px solid transparent; background: none; cursor: pointer; text-align: start; color: var(--muted); text-decoration: none; font-size: 15px;
}
.nav button:hover, .nav a.navlink:hover { background: var(--key); color: var(--text); }
.nav button.active { border-color: var(--primary); color: var(--text); font-weight: 600; background: color-mix(in srgb, var(--primary) 6%, transparent); }
.nav .grow { flex: 1; }
.modem-box { border-top: 1px solid var(--line); padding: 14px 8px 0; display: grid; gap: 6px; font-size: 13px; color: var(--muted); }
.modem-box .row { display: flex; align-items: center; gap: 8px; }
.signal { display: inline-flex; align-items: flex-end; gap: 2px; height: 14px; direction: ltr; }
.signal i { width: 4px; background: var(--key-hover); border-radius: 1px; }
.signal i:nth-child(1) { height: 25%; } .signal i:nth-child(2) { height: 50%; }
.signal i:nth-child(3) { height: 75%; } .signal i:nth-child(4) { height: 100%; }
.signal i.on { background: var(--green); }
.rec-dot { font-size: 11px; font-weight: 700; color: #fff; background: var(--red); padding: 1px 6px; border-radius: 6px; direction: ltr; }

.content { padding: 28px 28px 40px; min-width: 0; }
.page-head h1 { font-size: 28px; margin: 0; }
.page-head p { margin: 4px 0 18px; color: var(--muted); }
.side { padding: 20px; padding-inline-start: 0; display: grid; gap: 16px; align-content: start; position: sticky; top: 0; height: 100vh; overflow: auto; }

@media (max-width: 1200px) {
  body.app { grid-template-columns: 210px minmax(0, 1fr) 340px; }
}
@media (max-width: 980px) {
  body.app { grid-template-columns: 1fr; }
  .nav { order: -2; position: sticky; top: 0; z-index: 5; height: auto; flex-direction: row; flex-wrap: wrap; align-items: center; padding: 10px 12px; border: 0; border-bottom: 1px solid var(--line); }
  .brand { padding: 0 4px; }
  .nav .grow { display: none; }
  .modem-box { border: 0; padding: 0; margin-inline-start: auto; }
  .modem-box .hide-sm { display: none; }
  .nav button, .nav a.navlink { padding: 8px 10px; }
  .nav .label-sm { display: none; }
  .side { position: static; height: auto; padding: 12px 12px 0; order: -1; }
  .content { padding: 16px 12px 32px; }
}

/* ---------- status pills ---------- */
.pills { display: flex; flex-wrap: wrap; gap: 8px; margin: 0 0 14px; }
.pill {
  display: inline-flex; gap: 6px; align-items: center; padding: 6px 14px; border-radius: 999px;
  border: 0; cursor: pointer; font-size: 14px; font-weight: 600;
  --c: var(--slate); color: var(--c); background: color-mix(in srgb, var(--c) 12%, transparent);
}
.pill b { font-variant-numeric: tabular-nums; }
.pill.active { background: var(--c); color: #fff; }
.pill.all { --c: var(--primary); }

/* status colors (pills, chips, bars) */
.s-new { --c: var(--slate); }
.s-no_answer, .s-busy { --c: var(--amber); }
.s-failed, .s-cancelled, .s-missed { --c: var(--slate); }
.s-invalid, .s-wrong_number { --c: #b45309; }
.s-do_not_call { --c: #6b7280; }
.s-answered { --c: #0891b2; }
.s-interested { --c: var(--primary); }
.s-callback { --c: #334155; }
.s-not_interested { --c: #e11d48; }
.s-subscribed { --c: var(--green); }
.s-due { --c: var(--purple); }
@media (prefers-color-scheme: dark) { .s-callback { --c: #cbd5e1; } }

/* ---------- filters ---------- */
.filters { display: grid; grid-template-columns: minmax(200px, 2fr) repeat(3, minmax(130px, 1fr)); gap: 10px; margin-bottom: 12px; }
.filters input, .filters select, .toolbar select {
  padding: 10px 14px; border-radius: 12px; border: 1px solid var(--line); background: var(--card); min-width: 0;
}
@media (max-width: 700px) { .filters { grid-template-columns: 1fr 1fr; } .filters input { grid-column: 1 / -1; } }
.toolbar { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; margin-bottom: 14px; }
.toolbar .spacer { flex: 1; }
.notice { margin: 0 0 12px; padding: 10px 14px; border-radius: 12px; background: color-mix(in srgb, var(--primary) 10%, transparent); font-size: 14px; }

/* ---------- lead cards ---------- */
.leads { list-style: none; margin: 0; padding: 0; border: 1px solid var(--line); border-radius: var(--radius); background: var(--card); overflow: hidden; }
.lead { display: flex; align-items: center; gap: 14px; padding: 16px 18px; border-bottom: 1px solid var(--line); cursor: pointer; }
.lead:last-child { border-bottom: 0; }
.lead:hover { background: color-mix(in srgb, var(--key) 60%, transparent); }
.lead.selected { background: color-mix(in srgb, var(--primary) 7%, transparent); }
.lead-main { flex: 1; min-width: 0; display: grid; gap: 6px; }
.lead-title { display: flex; align-items: center; gap: 6px; font-weight: 700; font-size: 16px; }
.lead-title span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.lead-title svg { color: var(--muted); width: 16px; height: 16px; }
.lead-meta { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 12px; font-size: 14px; color: var(--muted); }
.lead-meta .num { color: var(--text); font-size: 15px; letter-spacing: .3px; }
.cat { font-size: 12px; padding: 2px 8px; border-radius: 6px; color: var(--primary); background: color-mix(in srgb, var(--primary) 10%, transparent); }
.chip { display: inline-block; font-size: 12px; font-weight: 600; padding: 2px 9px; border-radius: 6px; white-space: nowrap;
  --c: var(--slate); color: var(--c); background: color-mix(in srgb, var(--c) 13%, transparent); }
.net { font-size: 11px; padding: 1px 6px; border-radius: 6px; border: 1px solid var(--line); color: var(--muted); direction: ltr; }
.n-vodafone { color: #e60000; border-color: #e6000055; }
.n-etisalat { color: #3a9a3a; border-color: #3a9a3a55; }
.n-orange { color: #ff7900; border-color: #ff790055; }
.n-we { color: #6d28d9; border-color: #6d28d955; }
.lead-actions { display: flex; align-items: center; gap: 8px; }
.icon-btn { width: 42px; height: 42px; border-radius: 50%; border: 1px solid var(--line); background: var(--card); display: grid; place-items: center; color: var(--text); cursor: pointer; text-decoration: none; }
.icon-btn:hover { background: var(--key); }
@media (max-width: 560px) {
  .lead { flex-wrap: wrap; }
  .lead-actions { width: 100%; justify-content: flex-end; }
}
.empty { text-align: center; padding: 48px 12px; color: var(--muted); }
.pager { display: flex; justify-content: center; align-items: center; gap: 12px; margin-top: 14px; color: var(--muted); font-size: 14px; }

/* ---------- tables (calls, stats) ---------- */
.table-wrap { overflow-x: auto; border: 1px solid var(--line); border-radius: var(--radius); background: var(--card); }
table.grid { width: 100%; border-collapse: collapse; font-size: 14px; }
.grid th { text-align: start; font-weight: 600; color: var(--muted); font-size: 13px; padding: 10px 12px; border-bottom: 1px solid var(--line); }
.grid td { padding: 10px 12px; border-bottom: 1px solid var(--line); vertical-align: middle; }
.grid tr:last-child td { border-bottom: 0; }
#callRows tr { cursor: pointer; }
#callRows tr:hover { background: var(--bg); }
.name { font-weight: 600; }
.sub { color: var(--muted); font-size: 12px; }
.nowrap { white-space: nowrap; }
audio { height: 34px; max-width: 260px; direction: ltr; }

/* ---------- dialer ---------- */
.dialer { display: grid; gap: 12px; }
.display { text-align: center; }
#number { width: 100%; border: 0; background: transparent; font-size: 28px; text-align: center; letter-spacing: 1px; outline: none; direction: ltr; }
.status { font-weight: 600; min-height: 1.5em; }
.status.active { color: var(--green); }
.status.incoming { color: var(--primary); animation: pulse 1s infinite alternate; }
.reason { color: var(--muted); font-size: 14px; min-height: 1.5em; }
@keyframes pulse { to { opacity: .4; } }
.keypad { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; direction: ltr; }
.key { font-size: 22px; padding: 10px 0; border: 0; border-radius: 12px; background: var(--key); cursor: pointer; }
.key small { display: block; font-size: 10px; color: var(--muted); letter-spacing: 2px; min-height: 12px; }
.key:hover { background: var(--key-hover); }
.key:active { transform: scale(.97); }
.actions { display: flex; gap: 8px; }
.actions .btn { flex: 1; }
.actions .btn.ghost { flex: 0 0 56px; font-size: 16px; padding: 12px 0; }
.volume { display: flex; align-items: center; gap: 10px; color: var(--muted); font-size: 14px; }
.volume input { flex: 1; }
#keypadBtn { display: none; }
.side.has-contact #keypadBtn { display: inline-flex; }
.side.has-contact:not(.show-keypad) .keypad { display: none; }

/* ---------- contact card ---------- */
.contact { position: relative; display: grid; gap: 8px; font-size: 14px; }
.contact h2 { font-size: 19px; margin: 0; padding-inline-end: 30px; }
.contact p { margin: 0; }
.contact .close { position: absolute; top: 16px; inset-inline-end: 16px; border: 0; background: none; color: var(--muted); font-size: 16px; cursor: pointer; }
.links { display: flex; gap: 12px; flex-wrap: wrap; }
.links a { text-decoration: none; }
.phone-row { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin: 4px 0; }
.phone { font-size: 19px; font-weight: 700; }
.label { font-size: 13px; color: var(--muted); font-weight: 600; margin-top: 6px !important; }
.outcome { border-radius: 12px; transition: background .3s; }
.outcome.ask { background: color-mix(in srgb, var(--primary) 9%, transparent); padding: 10px; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chips button { font-size: 13px; padding: 6px 12px; border-radius: 999px; cursor: pointer; border: 1px solid var(--line); background: var(--bg); }
.chips button.on { border-color: var(--primary); background: color-mix(in srgb, var(--primary) 14%, transparent); font-weight: 700; }
.callback-row { display: flex; gap: 8px; margin-top: 8px; }
.callback-row input, .contact textarea { flex: 1; padding: 9px 12px; border-radius: 10px; border: 1px solid var(--line); background: var(--bg); }
.contact textarea { width: 100%; resize: vertical; }
.history { list-style: none; margin: 0; padding: 0; display: grid; gap: 10px; }
.history li { display: grid; gap: 4px; }
.history audio { width: 100%; max-width: none; }

/* ---------- stats ---------- */
.tiles { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; }
.tile { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; display: grid; gap: 4px; }
.tile span { color: var(--muted); font-size: 13px; }
.tile b { font-size: 26px; font-variant-numeric: tabular-nums; }
.tile small { font-size: 12px; color: var(--muted); font-weight: 400; }
.content h3 { font-size: 16px; margin: 26px 0 10px; }
.bars { display: grid; gap: 8px; background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; }
.barrow { display: grid; grid-template-columns: 120px 1fr 56px; align-items: center; gap: 10px; font-size: 14px; cursor: pointer; }
.barrow b { text-align: end; font-variant-numeric: tabular-nums; }
.track { background: var(--bg); border-radius: 6px; height: 12px; overflow: hidden; }
.fill { height: 100%; border-radius: 6px; --c: var(--slate); background: var(--c); min-width: 2px; }
