:root {
  --bg: #05070c;
  --bg-2: #0a0f1a;
  --panel: rgba(14, 20, 34, 0.72);
  --panel-2: rgba(22, 30, 50, 0.85);
  --line: rgba(120, 160, 255, 0.13);
  --line-2: rgba(120, 160, 255, 0.24);
  --text: #e6edf7;
  --muted: #8a97ad;
  --dim: #5d6a80;
  --ember: #ff7a45;
  --ember-2: #ffb08a;
  --cyan: #3de0ff;
  --violet: #9b7bff;
  --green: #3dffa8;
  --amber: #ffc940;
  --red: #ff4d6d;
  --glow-ember: 0 0 18px rgba(255, 122, 69, 0.45);
  --glow-cyan: 0 0 18px rgba(61, 224, 255, 0.35);
  --font: "Readex Pro", "Segoe UI", "Geeza Pro", Arial, sans-serif;
  --mono: "JetBrains Mono", ui-monospace, Menlo, monospace;
  color-scheme: dark;
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: radial-gradient(1200px 600px at 85% -10%, rgba(255, 122, 69, 0.10), transparent 60%),
              radial-gradient(900px 500px at 0% 10%, rgba(61, 224, 255, 0.08), transparent 60%), var(--bg);
  color: var(--text); font-family: var(--font); font-size: 14px; line-height: 1.55; min-height: 100vh;
  -webkit-font-smoothing: antialiased;
}
.grid-bg {
  position: fixed; inset: 0; pointer-events: none; z-index: 0;
  background-image: linear-gradient(var(--line) 1px, transparent 1px), linear-gradient(90deg, var(--line) 1px, transparent 1px);
  background-size: 48px 48px; opacity: 0.25;
  mask-image: radial-gradient(ellipse at 50% 0%, black 20%, transparent 75%);
}
[hidden] { display: none !important; }
.mono { font-family: var(--mono); font-variant-numeric: tabular-nums; }
.muted { color: var(--muted); }
.dim { color: var(--dim); }
.small { font-size: 12px; }
a { color: var(--cyan); }
h1, h2 { margin: 0; font-weight: 600; }
h2 { font-size: 15px; letter-spacing: 0.2px; }
code { background: rgba(255, 255, 255, 0.05); padding: 1px 6px; border-radius: 4px; }

.glass {
  position: relative; background: var(--panel); border: 1px solid var(--line); border-radius: 14px;
  backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px); padding: 18px;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.04), 0 10px 40px rgba(0, 0, 0, 0.35);
}
.glass::before {
  content: ""; position: absolute; inset: 0; border-radius: inherit; pointer-events: none;
  background: linear-gradient(120deg, rgba(61, 224, 255, 0.10), transparent 30%, transparent 70%, rgba(255, 122, 69, 0.10));
  mask: linear-gradient(#000 0 0) content-box, linear-gradient(#000 0 0); -webkit-mask-composite: xor; mask-composite: exclude; padding: 1px;
}
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 14px; flex-wrap: wrap; }

.brand { font-family: var(--mono); font-weight: 700; letter-spacing: 2px; font-size: 13px; direction: ltr; white-space: nowrap; }
.brand .chev { color: var(--ember); text-shadow: var(--glow-ember); }

.btn {
  font: inherit; color: var(--text); background: var(--panel-2); border: 1px solid var(--line-2); border-radius: 8px;
  padding: 9px 16px; cursor: pointer; text-decoration: none; display: inline-flex; align-items: center; gap: 6px;
  transition: border-color 0.15s, box-shadow 0.15s, background 0.15s;
}
.btn:hover { border-color: var(--cyan); box-shadow: var(--glow-cyan); }
.btn:focus-visible, input:focus-visible, select:focus-visible, .seg:focus-visible, tr:focus-visible { outline: 2px solid var(--cyan); outline-offset: 2px; }
.btn.primary { background: linear-gradient(135deg, #ff7a45, #e2522a); border-color: transparent; color: #140904; font-weight: 600; }
.btn.primary:hover { box-shadow: var(--glow-ember); }
.btn.ghost { background: transparent; }
.btn.small { padding: 5px 10px; font-size: 12px; }
.btn.good { border-color: rgba(61, 255, 168, 0.4); color: var(--green); }
.btn.bad { border-color: rgba(255, 77, 109, 0.4); color: var(--red); }
.btn[disabled] { opacity: 0.4; cursor: default; box-shadow: none; }

input, select, textarea {
  font: inherit; color: var(--text); background: rgba(5, 8, 14, 0.7); border: 1px solid var(--line-2); border-radius: 8px; padding: 8px 10px;
}
input::placeholder { color: var(--dim); }
label { display: grid; gap: 6px; font-size: 13px; color: var(--muted); }
label.check { display: inline-flex; align-items: center; gap: 6px; white-space: nowrap; }
.error { color: var(--red); min-height: 1.4em; margin: 0; }

/* ── الدخول ── */
.login { min-height: 100vh; display: grid; place-items: center; padding: 16px; position: relative; z-index: 1; }
.login-card { width: 100%; max-width: 400px; display: grid; gap: 14px; padding: 28px; }
.login-card h1 { font-size: 22px; }
.login-card p { margin: 0; }

/* ── الرأس ── */
.top {
  position: sticky; top: 0; z-index: 20; display: flex; align-items: center; gap: 16px; padding: 10px 20px;
  background: rgba(5, 7, 12, 0.82); backdrop-filter: blur(14px); border-bottom: 1px solid var(--line);
}
.cohorts { display: flex; gap: 6px; overflow-x: auto; flex: 1; scrollbar-width: none; }
.cohorts button {
  font: inherit; font-size: 12px; font-variant-numeric: tabular-nums; color: var(--muted); background: transparent; border: 1px solid var(--line);
  border-radius: 999px; padding: 4px 12px; cursor: pointer; white-space: nowrap;
}
.cohorts button[aria-pressed="true"] { color: var(--bg); background: var(--cyan); border-color: var(--cyan); box-shadow: var(--glow-cyan); }
.cohorts button .n { opacity: 0.75; margin-inline-start: 8px; padding-inline-start: 8px; border-inline-start: 1px solid currentColor; }
.top-end { display: flex; align-items: center; gap: 12px; }
.countdown { color: var(--ember-2); font-size: 12px; white-space: nowrap; font-family: var(--font); font-variant-numeric: tabular-nums; }
.me { color: var(--muted); font-size: 12px; white-space: nowrap; }
.live-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--green); box-shadow: 0 0 10px var(--green); animation: pulse 2s infinite; }
.live-dot.stale { background: var(--amber); box-shadow: 0 0 10px var(--amber); }
@keyframes pulse { 50% { opacity: 0.35; } }

.wrap { position: relative; z-index: 1; max-width: 1480px; margin: 0 auto; padding: 20px; display: grid; grid-template-columns: minmax(0, 1fr); gap: 18px; }
/* عنصر الشبكة يأخذ عرض أوسع أبنائه افتراضياً، والجدول ٩٨٠ بكسل: بلا هذا تتّسع الصفحة كلّها على الجوال */
.wrap > *, .hero > * { min-width: 0; }

/* ── الحضور المتوقَّع والمؤشّرات ── */
.hero { display: grid; grid-template-columns: minmax(300px, 380px) 1fr; gap: 18px; }
.gauge-body { display: flex; align-items: center; gap: 18px; }
.gauge { width: 150px; height: 150px; flex: none; }
.gauge .big { font-family: var(--mono); font-size: 26px; font-weight: 700; fill: var(--text); }
.gauge .lbl { font-size: 9px; fill: var(--muted); }
.legend { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; flex: 1; }
.legend li { display: flex; align-items: center; gap: 8px; justify-content: space-between; }
.legend .sw { width: 10px; height: 10px; border-radius: 3px; display: inline-block; margin-inline-end: 6px; }
.legend .v { font-family: var(--mono); font-weight: 600; }

.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 12px; }
.kpi { padding: 14px 16px; display: grid; gap: 4px; align-content: start; }
.kpi .k { color: var(--muted); font-size: 12px; }
.kpi .v { font-family: var(--mono); font-size: 28px; font-weight: 700; line-height: 1.1; }
.kpi .v .u { font-size: 14px; color: var(--muted); margin-inline-start: 2px; }
.kpi .sub { font-size: 11px; color: var(--dim); }
.kpi .lever { font-size: 11px; color: var(--muted); border-top: 1px dashed var(--line); padding-top: 6px; margin-top: 4px; }
.kpi .lever b { color: var(--ember-2); font-weight: 500; }
.kpi.accent .v { color: var(--cyan); text-shadow: var(--glow-cyan); }
.kpi.hot .v { color: var(--ember); text-shadow: var(--glow-ember); }
.kpi .bar { height: 3px; background: rgba(255, 255, 255, 0.06); border-radius: 2px; overflow: hidden; }
.kpi .bar i { display: block; height: 100%; background: linear-gradient(90deg, var(--cyan), var(--violet)); }

/* ── القمع ── */
.funnel { display: grid; gap: 6px; }
.f-row { display: grid; grid-template-columns: 170px 1fr 120px; align-items: center; gap: 12px; padding: 4px 0; cursor: pointer; border-radius: 6px; }
.f-row:hover .f-bar i { filter: brightness(1.25); }
.f-name { display: flex; align-items: center; gap: 8px; font-size: 13px; white-space: nowrap; }
.f-name .tag { font-size: 10px; }
.f-bar { position: relative; height: 22px; background: rgba(255, 255, 255, 0.03); border-radius: 4px; overflow: hidden; border: 1px solid var(--line); }
.f-bar i { position: absolute; inset-block: 0; inset-inline-start: 0; border-radius: 3px; transition: width 0.6s cubic-bezier(.2, .8, .2, 1); }
.f-bar i.auto { background: linear-gradient(270deg, rgba(61, 224, 255, 0.95), rgba(155, 123, 255, 0.75)); box-shadow: var(--glow-cyan); }
.f-bar i.manual { background: linear-gradient(270deg, rgba(255, 122, 69, 0.95), rgba(255, 201, 64, 0.7)); box-shadow: var(--glow-ember); }
.f-bar i.win { background: linear-gradient(270deg, rgba(61, 255, 168, 0.95), rgba(61, 224, 255, 0.6)); box-shadow: 0 0 18px rgba(61, 255, 168, 0.5); }
.f-bar b { position: absolute; inset-inline-start: 8px; top: 50%; transform: translateY(-50%); font-family: var(--mono); font-size: 12px; color: #04060a; font-weight: 700; mix-blend-mode: normal; }
.f-bar b.out { color: var(--text); }
.f-conv { font-family: var(--mono); font-size: 12px; color: var(--muted); text-align: start; white-space: nowrap; }
.f-conv .drop { color: var(--red); }
.tag { display: inline-block; padding: 1px 7px; border-radius: 999px; font-size: 11px; border: 1px solid var(--line-2); }
.tag.auto { color: var(--cyan); border-color: rgba(61, 224, 255, 0.4); }
.tag.manual { color: var(--ember); border-color: rgba(255, 122, 69, 0.4); }

/* ── الشرائح ── */
.segments { display: flex; flex-wrap: wrap; gap: 8px; }
.seg {
  font: inherit; font-size: 13px; color: var(--text); background: rgba(255, 255, 255, 0.03); border: 1px solid var(--line-2);
  border-radius: 999px; padding: 6px 14px; cursor: pointer; display: inline-flex; gap: 8px; align-items: center;
}
.seg .n { font-family: var(--mono); color: var(--cyan); font-weight: 600; }
.seg.zero { opacity: 0.45; }
.seg[aria-selected="true"] { border-color: var(--ember); box-shadow: var(--glow-ember); background: rgba(255, 122, 69, 0.12); }
.seg[aria-selected="true"] .n { color: var(--ember-2); }
.seg-hint { margin: 10px 0 0; min-height: 1.3em; }

/* ── الجدول ── */
.toolbar .filters { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.toolbar input[type="search"] { min-width: 260px; }
.table-scroll { overflow-x: auto; margin: 0 -18px; padding: 0 18px; position: relative; }
table.leads { width: 100%; border-collapse: separate; border-spacing: 0; min-width: 980px; }
.leads th { text-align: start; font-weight: 500; color: var(--muted); font-size: 12px; padding: 8px 10px; border-bottom: 1px solid var(--line-2); white-space: nowrap; }
.leads td { padding: 10px; border-bottom: 1px solid var(--line); vertical-align: middle; }
.leads tbody tr { cursor: pointer; transition: background 0.12s; }
.leads tbody tr:hover { background: rgba(61, 224, 255, 0.05); }
.leads tbody tr.test { opacity: 0.5; }
.leads .id { font-family: var(--mono); color: var(--dim); font-size: 12px; }
.who b { display: block; font-weight: 500; }
.who span { color: var(--dim); font-size: 12px; direction: ltr; unicode-bidi: plaintext; }
.pill { display: inline-flex; align-items: center; gap: 6px; padding: 3px 10px; border-radius: 999px; font-size: 12px; white-space: nowrap; border: 1px solid; }
.pill.s-auto { color: var(--cyan); border-color: rgba(61, 224, 255, 0.35); background: rgba(61, 224, 255, 0.07); }
.pill.s-manual { color: var(--ember-2); border-color: rgba(255, 122, 69, 0.45); background: rgba(255, 122, 69, 0.1); }
.pill.s-win { color: var(--green); border-color: rgba(61, 255, 168, 0.45); background: rgba(61, 255, 168, 0.1); }
.pill.s-review { color: var(--amber); border-color: rgba(255, 201, 64, 0.4); background: rgba(255, 201, 64, 0.08); }
.pill.s-off { color: var(--dim); border-color: var(--line-2); }
.pill.s-lost { color: var(--red); border-color: rgba(255, 77, 109, 0.4); background: rgba(255, 77, 109, 0.08); }
.coming { display: flex; align-items: center; gap: 8px; white-space: nowrap; }
.coming .dot { width: 9px; height: 9px; border-radius: 50%; flex: none; }
.c-yes .dot { background: var(--green); box-shadow: 0 0 8px var(--green); }
.c-maybe .dot { background: var(--amber); box-shadow: 0 0 8px var(--amber); }
.c-no .dot { background: var(--red); box-shadow: 0 0 8px var(--red); }
.c-unknown .dot { background: transparent; border: 1px dashed var(--dim); }
.sig { display: inline-flex; gap: 3px; }
.sig i { width: 5px; height: 12px; border-radius: 1px; background: rgba(255, 255, 255, 0.08); }
.sig i.on { background: var(--green); box-shadow: 0 0 6px rgba(61, 255, 168, 0.6); }
.calls { font-size: 12px; color: var(--muted); white-space: nowrap; }
.calls .ok { color: var(--green); }
.calls .no { color: var(--red); }
.nba { font-size: 13px; }
.nba.urgent { color: var(--ember-2); }
.nba.urgent::before { content: "●"; color: var(--ember); text-shadow: var(--glow-ember); margin-inline-end: 6px; font-size: 10px; vertical-align: 1px; }
.nba.auto { color: var(--dim); }
.att { display: flex; gap: 6px; }
.empty { text-align: center; padding: 24px; margin: 0; }
.leads .att-col, .leads td.att-col { display: none; }
.show-att .leads .att-col { display: table-cell; }

.foot { display: flex; justify-content: space-between; flex-wrap: wrap; gap: 8px; padding: 4px 4px 24px; }

/* ── البطاقة الجانبية ── */
.scrim { position: fixed; inset: 0; background: rgba(0, 0, 0, 0.5); z-index: 30; backdrop-filter: blur(2px); }
.drawer { position: fixed; inset-block: 0; inset-inline-end: 0; width: min(560px, 100vw); z-index: 40; padding: 10px; }
.drawer-inner { height: 100%; overflow-y: auto; border-radius: 14px; background: rgba(10, 14, 24, 0.96); padding: 22px; animation: slide 0.22s ease-out; }
@keyframes slide { from { transform: translateX(-24px); opacity: 0; } }
.close { position: sticky; top: 0; float: left; z-index: 2; }
.d-head h3 { font-size: 20px; margin: 0 0 4px; }
.d-contact { display: flex; flex-wrap: wrap; gap: 8px 14px; font-size: 13px; color: var(--muted); margin-bottom: 16px; }
.d-contact a, .d-contact span { direction: ltr; unicode-bidi: plaintext; }
.d-sec { border-top: 1px solid var(--line); padding: 14px 0; }
.d-sec h4 { margin: 0 0 10px; font-size: 13px; color: var(--muted); font-weight: 500; }
.track { display: flex; gap: 3px; margin: 6px 0 4px; }
.track i { flex: 1; height: 6px; border-radius: 2px; background: rgba(255, 255, 255, 0.07); }
.track i.on.auto { background: var(--cyan); box-shadow: 0 0 8px rgba(61, 224, 255, 0.6); }
.track i.on.manual { background: var(--ember); box-shadow: 0 0 8px rgba(255, 122, 69, 0.6); }
.track i.on.win { background: var(--green); box-shadow: 0 0 8px rgba(61, 255, 168, 0.6); }
.kv { display: grid; grid-template-columns: 140px 1fr; gap: 6px 10px; font-size: 13px; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; }
.moves { display: flex; flex-wrap: wrap; gap: 6px; }
.moves .btn.current { border-color: var(--ember); color: var(--ember-2); box-shadow: var(--glow-ember); }
.move-extra { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-top: 10px; }
.move-extra .full { grid-column: 1 / -1; }
.lost-row { display: flex; gap: 6px; margin-top: 10px; flex-wrap: wrap; }
.timeline { list-style: none; margin: 0; padding: 0; position: relative; }
.timeline::before { content: ""; position: absolute; inset-block: 6px; inset-inline-start: 5px; width: 1px; background: var(--line-2); }
.timeline li { position: relative; padding: 0 22px 14px 0; padding-inline-start: 22px; padding-inline-end: 0; }
.timeline li::before { content: ""; position: absolute; inset-inline-start: 0; top: 6px; width: 11px; height: 11px; border-radius: 50%; background: var(--bg); border: 2px solid var(--cyan); }
.timeline li.k-event::before { border-color: var(--ember); }
.timeline li.k-call::before { border-color: var(--violet); }
.timeline li.k-attend::before, .timeline li.k-invite::before { border-color: var(--green); }
.timeline li.future { opacity: 0.6; }
.timeline li.undone { opacity: 0.45; text-decoration: line-through; }
.timeline .t { font-size: 11px; color: var(--dim); }
.timeline .a { font-size: 13px; }
.timeline .s { font-size: 12px; color: var(--muted); }
.timeline .facts { margin: 4px 0 0; padding: 0; list-style: none; font-size: 12px; color: var(--text); display: flex; flex-wrap: wrap; gap: 4px; }
.timeline .facts li { padding: 1px 8px; border: 1px solid var(--line-2); border-radius: 999px; }
.timeline .facts li::before { display: none; }

.users { list-style: none; margin: 0; padding: 0; display: grid; gap: 10px; }
.users .user { display: flex; justify-content: space-between; gap: 12px; align-items: center; padding: 10px 12px; border: 1px solid var(--line); border-radius: 10px; }
.users .user.off { opacity: 0.55; }
.link-box { display: flex; gap: 8px; }
.link-box input { flex: 1; min-width: 0; font-family: var(--mono); font-size: 12px; }

.toast {
  position: fixed; bottom: 20px; inset-inline-start: 50%; transform: translateX(50%); z-index: 50; background: var(--panel-2);
  border: 1px solid var(--cyan); box-shadow: var(--glow-cyan); padding: 10px 18px; border-radius: 10px;
}
.toast.err { border-color: var(--red); box-shadow: 0 0 18px rgba(255, 77, 109, 0.4); }

@media (max-width: 1056px) {
  .hero { grid-template-columns: 1fr; }
  .f-row { grid-template-columns: 120px 1fr 90px; }
}
@media (max-width: 672px) {
  .wrap { padding: 16px; gap: 14px; }
  .top { flex-wrap: wrap; padding: 10px 16px; gap: 8px; }
  .cohorts { order: 3; flex-basis: 100%; }
  .top-end { margin-inline-start: auto; }
  .me { display: none; }
  .gauge-body { flex-direction: column; align-items: stretch; }
  .gauge { margin: 0 auto; }
  .kpis { grid-template-columns: 1fr 1fr; }
  .kpi .v { font-size: 22px; }
  .f-row { grid-template-columns: 96px 1fr 64px; gap: 8px; }
  .f-name .tag { display: none; }
  .toolbar input[type="search"] { min-width: 0; width: 100%; }
  .toolbar .filters { width: 100%; }
  .kv { grid-template-columns: 110px 1fr; }
  .move-extra { grid-template-columns: 1fr; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before { animation: none !important; transition: none !important; }
}
