/* =====================================================================
   مجراف · v7 لوحة التحكم — نظام تصميم مبني من الصفر
   لوحة إدارة محورها الجداول · هوية نيلية · RTL · فاتح/داكن
   ===================================================================== */

/* ----------------------------- Tokens ----------------------------- */
:root {
  --brand:        #5b5bf0;
  --brand-2:      #8b5cf6;
  --brand-hover:  #4a4ae0;
  --brand-soft:   #eef0ff;
  --brand-ring:   rgba(91, 91, 240, 0.20);
  --brand-grad:   linear-gradient(135deg, #5b5bf0, #8b5cf6);

  --success: #0ea66f;  --success-soft: #d8f5e9;
  --warn:    #e08a00;  --warn-soft:    #fdeccb;
  --danger:  #e0413c;  --danger-soft:  #fbe0df;
  --info:    #0e90c4;  --info-soft:    #d7eefb;

  --bg:        #eceef5;
  --panel:     #ffffff;
  --panel-2:   #f6f7fb;
  --muted:     #eef0f6;
  --overlay:   rgba(20, 22, 44, 0.42);

  --line:      #e4e6f0;
  --line-2:    #d2d5e6;

  --ink:       #1a1c2e;
  --ink-2:     #565973;
  --ink-3:     #888ca8;
  --on-brand:  #ffffff;

  --font: 'Rubik', system-ui, -apple-system, 'Segoe UI', Tahoma, sans-serif;
  --mono: 'JetBrains Mono', ui-monospace, Consolas, monospace;

  --r-xs: 7px;  --r-sm: 10px;  --r: 13px;  --r-lg: 18px;  --r-xl: 24px;  --r-full: 999px;

  --sh-1: 0 1px 2px rgba(26,28,60,.06);
  --sh-2: 0 4px 14px -4px rgba(26,28,60,.12), 0 2px 5px -3px rgba(26,28,60,.08);
  --sh-3: 0 14px 40px -10px rgba(26,28,60,.22);
  --sh-brand: 0 8px 22px -8px rgba(91,91,240,.5);

  --ease: cubic-bezier(.4,0,.2,1);
  --ease-out: cubic-bezier(.16,1,.3,1);

  --sidebar-w: 260px;
  --topbar-h: 62px;
  color-scheme: light;
}

[data-theme="dark"] {
  --brand:        #888bf6;
  --brand-2:      #a78bfa;
  --brand-hover:  #9a9cf8;
  --brand-soft:   rgba(136,139,246,.13);
  --brand-ring:   rgba(136,139,246,.30);
  --brand-grad:   linear-gradient(135deg, #6366f1, #8b5cf6);

  --success: #34d399;  --success-soft: rgba(52,211,153,.14);
  --warn:    #fbbf24;  --warn-soft:    rgba(251,191,36,.14);
  --danger:  #f87171;  --danger-soft:  rgba(248,113,113,.14);
  --info:    #38bdf8;  --info-soft:    rgba(56,189,248,.14);

  --bg:        #08090f;
  --panel:     #12131c;
  --panel-2:   #171927;
  --muted:     #1b1d2b;
  --overlay:   rgba(0,0,0,.66);

  --line:      #242636;
  --line-2:    #333650;

  --ink:       #ecedfb;
  --ink-2:     #a4a7c4;
  --ink-3:     #6c7090;

  --sh-1: 0 1px 2px rgba(0,0,0,.4);
  --sh-2: 0 4px 14px -4px rgba(0,0,0,.5);
  --sh-3: 0 14px 40px -10px rgba(0,0,0,.6);
  --sh-brand: 0 8px 22px -8px rgba(91,91,240,.4);
  color-scheme: dark;
}

/* ----------------------------- Reset ----------------------------- */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; }
body {
  font-family: var(--font);
  font-size: 14px;
  line-height: 1.6;
  color: var(--ink);
  background: var(--bg);
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
  font-variant-numeric: tabular-nums;
}
a { color: var(--brand); text-decoration: none; }
button { font: inherit; cursor: pointer; border: none; background: none; color: inherit; }
input, select, textarea { font: inherit; color: inherit; }
img, svg { display: block; max-width: 100%; }
ul { list-style: none; }
.num, time, code { font-feature-settings: "tnum" 1, "lnum" 1; unicode-bidi: plaintext; }
::selection { background: var(--brand-ring); }
:focus-visible { outline: 2px solid var(--brand); outline-offset: 2px; border-radius: var(--r-xs); }

::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-thumb { background: var(--line-2); border-radius: 8px; border: 2px solid var(--bg); }
::-webkit-scrollbar-thumb:hover { background: var(--ink-3); }

/* ============================ Auth screen ============================ */
.auth-wrap {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
  background:
    radial-gradient(820px 460px at 16% -8%, rgba(91,91,240,.20), transparent 56%),
    radial-gradient(680px 420px at 92% 108%, rgba(139,92,246,.16), transparent 56%),
    var(--bg);
}
.auth-card {
  width: 100%;
  max-width: 392px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--r-xl);
  box-shadow: var(--sh-3);
  padding: 38px 32px 28px;
}
.auth-logo {
  width: 60px; height: 60px;
  margin: 0 auto 18px;
  border-radius: 18px;
  background: var(--brand-grad);
  box-shadow: var(--sh-brand);
  display: grid; place-items: center;
}
.auth-logo svg { width: 32px; height: 32px; color: #fff; }
.auth-card h1 { text-align: center; font-size: 26px; font-weight: 800; letter-spacing: -.02em; }
.auth-card .sub { text-align: center; color: var(--ink-3); font-size: 13px; margin: 6px 0 24px; }
.auth-alert {
  display: flex; gap: 9px; align-items: flex-start;
  padding: 11px 13px; border-radius: var(--r);
  font-size: 12.5px; margin-bottom: 18px;
}
.auth-alert.err { background: var(--danger-soft); color: var(--danger); }
.auth-alert.info { background: var(--info-soft); color: var(--info); }

/* ============================ App shell ============================ */
.shell { display: grid; grid-template-columns: var(--sidebar-w) 1fr; min-height: 100vh; }

.sidebar {
  background: var(--panel);
  border-inline-end: 1px solid var(--line);
  display: flex; flex-direction: column;
  position: sticky; top: 0; height: 100vh;
  z-index: 40;
}
.sb-brand {
  display: flex; align-items: center; gap: 11px;
  padding: 16px 18px;
  border-bottom: 1px solid var(--line);
}
.sb-brand .mark {
  width: 38px; height: 38px; flex: none;
  border-radius: 11px;
  background: var(--brand-grad);
  box-shadow: var(--sh-brand);
  display: grid; place-items: center;
}
.sb-brand .mark svg { width: 21px; height: 21px; color: #fff; }
.sb-brand .name { font-size: 18px; font-weight: 800; letter-spacing: -.02em; line-height: 1.1; }
.sb-brand .tag { font-size: 11px; color: var(--ink-3); }

.sb-nav { flex: 1; overflow-y: auto; padding: 12px 10px; }
.sb-group { font-size: 10px; font-weight: 700; letter-spacing: .14em; text-transform: uppercase; color: var(--ink-3); padding: 14px 12px 6px; }
.sb-link {
  display: flex; align-items: center; gap: 11px;
  padding: 9px 12px; border-radius: var(--r-sm);
  color: var(--ink-2); font-weight: 500;
  position: relative; margin-bottom: 1px;
  transition: background .12s var(--ease), color .12s var(--ease);
}
.sb-link svg { width: 19px; height: 19px; flex: none; opacity: .85; }
.sb-link:hover { background: var(--muted); color: var(--ink); }
.sb-link.active { background: var(--brand-soft); color: var(--brand); font-weight: 600; }
.sb-link.active::before {
  content: ''; position: absolute; inset-inline-start: -10px; top: 50%;
  transform: translateY(-50%); width: 4px; height: 20px;
  border-radius: 4px; background: var(--brand-grad);
}
.sb-link .count {
  margin-inline-start: auto; font-size: 11px; font-weight: 600;
  background: var(--muted); color: var(--ink-3);
  padding: 1px 8px; border-radius: var(--r-full);
}
.sb-link.active .count { background: var(--brand); color: #fff; }

.sb-foot { border-top: 1px solid var(--line); padding: 10px; }
.userchip {
  display: flex; align-items: center; gap: 10px;
  width: 100%; padding: 8px 10px; border-radius: var(--r);
  transition: background .12s var(--ease);
}
.userchip:hover { background: var(--muted); }
.avatar {
  width: 34px; height: 34px; flex: none; border-radius: 10px;
  background: var(--brand-grad); color: #fff;
  display: grid; place-items: center; font-weight: 700; font-size: 14px;
  box-shadow: var(--sh-brand);
}
.userchip .meta { text-align: start; line-height: 1.25; min-width: 0; flex: 1; }
.userchip .meta strong { display: block; font-size: 13px; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.userchip .meta span { font-size: 11px; color: var(--ink-3); }
.userchip > svg { width: 18px; height: 18px; flex: none; color: var(--ink-3); }
.userchip:hover > svg { color: var(--danger); }

/* main column */
.main { display: flex; flex-direction: column; min-width: 0; }
.topbar {
  height: var(--topbar-h);
  display: flex; align-items: center; gap: 14px;
  padding: 0 22px;
  background: color-mix(in srgb, var(--panel) 84%, transparent);
  backdrop-filter: blur(12px) saturate(1.3);
  -webkit-backdrop-filter: blur(12px) saturate(1.3);
  border-bottom: 1px solid var(--line);
  position: sticky; top: 0; z-index: 30;
}
.topbar .page-h1 { font-size: 18px; font-weight: 700; letter-spacing: -.01em; }
.topbar .grow { flex: 1; }
/* البرغر يظهر فقط في وضع الموبايل/التابلت (≤1024). نستخدم !important لأن
   .iconbtn { display:grid } معرّف بعده فيتغلب عليه بترتيب المصدر. */
.burger { display: none !important; }

.content { padding: 22px; max-width: 1360px; width: 100%; margin: 0 auto; flex: 1; }

/* impersonation banner */
.imp-banner { display: flex; align-items: center; gap: 10px; background: var(--warn-soft); border: 1px solid var(--warn); color: var(--warn); padding: 10px 16px; border-radius: var(--r); margin-bottom: 18px; font-size: 13px; font-weight: 500; }
.imp-banner .imp-ico { width: 18px; height: 18px; flex: none; }
.imp-banner .imp-ico svg { width: 18px; height: 18px; }
.imp-banner strong { font-weight: 700; }
.imp-banner .btn { margin-inline-start: auto; background: var(--warn); color: #fff; border: none; }
.imp-banner .btn:hover { filter: brightness(1.07); }

/* top navigation progress bar */
.nav-progress { position: fixed; top: 0; inset-inline: 0; height: 3px; z-index: 200; background: transparent; pointer-events: none; }
.nav-progress::after { content: ''; display: block; height: 100%; width: 0; background: var(--brand-grad); box-shadow: 0 0 8px var(--brand); transition: width .2s var(--ease); }
.nav-progress.active::after { width: 85%; transition: width 9s cubic-bezier(.1,.6,.2,1); }
.nav-progress.done::after { width: 100%; opacity: 0; transition: width .2s var(--ease), opacity .3s .15s var(--ease); }

/* live scrape banner */
.scrape-banner {
  display: flex; align-items: center; gap: 10px;
  background: var(--brand-grad); color: #fff;
  padding: 10px 16px; border-radius: var(--r);
  box-shadow: var(--sh-brand); margin-bottom: 18px;
  font-size: 13px; font-weight: 500;
}
.scrape-banner .dot { width: 9px; height: 9px; border-radius: 50%; background: #fff; animation: pulse 1.1s infinite; }
.scrape-banner a { color: #fff; text-decoration: underline; margin-inline-start: auto; font-weight: 600; }
.scrape-banner .sb-details { margin-inline-start: auto; font-weight: 700; font-size: 12px; background: rgba(255,255,255,.18); padding: 3px 10px; border-radius: var(--r-full); white-space: nowrap; }
.scrape-banner:hover { filter: brightness(1.05); }
.scrape-banner:hover .sb-details { background: rgba(255,255,255,.3); }
@keyframes pulse { 0%,100% { opacity: 1; } 50% { opacity: .35; } }
/* banner التصنيف — لون مميّز ليُفرّق عن السحب */
.classify-banner { background: linear-gradient(135deg, #7c3aed, #4f46e5); box-shadow: 0 6px 20px -8px rgba(99,49,237,.6); }
/* زر التصنيف وهو يعمل بالخلفية */
#classifyBtn.is-running { border-color: #7c3aed; color: #7c3aed; }
#classifyBtn.is-running svg { animation: spin 1.1s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ============================ Buttons ============================ */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 7px;
  padding: 9px 16px; border-radius: var(--r-sm);
  font-weight: 600; font-size: 13px; white-space: nowrap;
  border: 1.5px solid transparent;
  transition: transform .1s var(--ease), box-shadow .12s var(--ease),
              background .12s var(--ease), border-color .12s var(--ease), filter .12s var(--ease);
}
.btn svg { width: 16px; height: 16px; }
.btn:active { transform: scale(.97); }
.btn:disabled { opacity: .5; pointer-events: none; }
.btn-primary { background: var(--brand-grad); color: #fff; box-shadow: var(--sh-brand); }
.btn-primary:hover { filter: brightness(1.07); transform: translateY(-1px); }
.btn-default { background: var(--panel); border-color: var(--line-2); color: var(--ink-2); }
.btn-default:hover { border-color: var(--brand); color: var(--brand); background: var(--brand-soft); }
.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover { filter: brightness(1.07); }
.btn-ghost { color: var(--ink-2); }
.btn-ghost:hover { background: var(--muted); color: var(--ink); }
.btn-sm { padding: 6px 11px; font-size: 12px; border-radius: var(--r-xs); }
.btn-sm svg { width: 14px; height: 14px; }
.btn-block { width: 100%; }

.iconbtn {
  width: 36px; height: 36px; flex: none;
  border-radius: var(--r-sm);
  display: grid; place-items: center;
  background: var(--panel); border: 1px solid var(--line);
  color: var(--ink-2);
  transition: all .12s var(--ease);
}
.iconbtn:hover { background: var(--muted); border-color: var(--line-2); color: var(--ink); }
.iconbtn svg { width: 18px; height: 18px; }
.iconbtn.sm { width: 30px; height: 30px; border-radius: var(--r-xs); }
.iconbtn.sm svg { width: 15px; height: 15px; }
.iconbtn.danger:hover { background: var(--danger-soft); border-color: var(--danger); color: var(--danger); }
.iconbtn.good:hover { background: var(--success-soft); border-color: var(--success); color: var(--success); }

/* ============================ Forms ============================ */
.field { margin-bottom: 15px; }
.field > label { display: block; font-size: 12px; font-weight: 600; color: var(--ink-2); margin-bottom: 6px; }
.field .hint { font-size: 11.5px; color: var(--ink-3); margin-top: 5px; }
.req { color: var(--danger); }

.inp, .sel, textarea.inp {
  width: 100%;
  padding: 9px 13px;
  background: var(--panel-2);
  border: 1.5px solid var(--line);
  border-radius: var(--r-sm);
  color: var(--ink);
  transition: border-color .12s var(--ease), background .12s var(--ease), box-shadow .12s var(--ease);
}
.inp::placeholder { color: var(--ink-3); }
.inp:hover, .sel:hover { border-color: var(--line-2); }
.inp:focus, .sel:focus, textarea.inp:focus {
  outline: none; background: var(--panel);
  border-color: var(--brand); box-shadow: 0 0 0 4px var(--brand-ring);
}
textarea.inp { resize: vertical; min-height: 78px; line-height: 1.55; }
.sel {
  appearance: none;
  background-image: url("data:image/svg+xml;charset=utf8,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%23888ca8' stroke-width='2.4' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: left 12px center; background-size: 12px;
  padding-inline-start: 32px;
}
.inp-with-icon { position: relative; }
.inp-with-icon svg { position: absolute; inset-inline-start: 12px; top: 50%; transform: translateY(-50%); width: 16px; height: 16px; color: var(--ink-3); pointer-events: none; }
.inp-with-icon .inp { padding-inline-start: 38px; }
.inp-with-icon .pw-eye { position: absolute; inset-inline-end: 8px; top: 50%; transform: translateY(-50%); width: 30px; height: 30px; border-radius: var(--r-xs); display: grid; place-items: center; color: var(--ink-3); }
.inp-with-icon .pw-eye:hover { background: var(--muted); color: var(--ink); }

.check { display: flex; align-items: center; gap: 9px; font-size: 13px; cursor: pointer; }
.check input { width: 17px; height: 17px; accent-color: var(--brand); border-radius: 5px; }

.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.form-actions { display: flex; gap: 10px; justify-content: flex-start; margin-top: 22px; }

/* ============================ Panels / cards ============================ */
.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
  box-shadow: var(--sh-1);
}
.panel-head {
  display: flex; align-items: center; gap: 12px;
  padding: 15px 18px; border-bottom: 1px solid var(--line);
}
.panel-head h2 { font-size: 15px; font-weight: 700; }
.panel-head .grow { flex: 1; }
.panel-body { padding: 18px; }
.panel-body.flush { padding: 0; }

.page-head { display: flex; align-items: flex-start; gap: 14px; margin-bottom: 20px; flex-wrap: wrap; }
.page-head .titles h1 { font-size: 22px; font-weight: 800; letter-spacing: -.02em; }
.page-head .titles p { color: var(--ink-3); font-size: 13px; margin-top: 3px; }
.page-head .actions { margin-inline-start: auto; display: flex; gap: 9px; flex-wrap: wrap; }

/* ============================ Stat cards ============================ */
/* بطاقات الأرقام دائماً متساوية الحجم: 4 لكل صف (تنقسم بانتظام مع 4 أو 8 بطاقات) */
.stat-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 15px; margin-bottom: 20px; }
@media (max-width: 980px) { .stat-grid { grid-template-columns: repeat(2, 1fr); } }
@media (max-width: 520px) { .stat-grid { grid-template-columns: 1fr; } }
/* داخل المودالات (إحصائيات الكلمة) تبقى متجاوبة حسب عرض المودال */
.modal .stat-grid { grid-template-columns: repeat(2, 1fr); }
@media (min-width: 620px) { .modal.lg .stat-grid { grid-template-columns: repeat(4, 1fr); } }
.stat {
  position: relative; overflow: hidden;
  background: var(--panel); border: 1px solid var(--line);
  border-radius: var(--r-lg); padding: 17px; box-shadow: var(--sh-1);
  display: flex; align-items: center; gap: 14px;
  transition: transform .18s var(--ease-out), box-shadow .18s var(--ease-out);
}
.stat:hover { transform: translateY(-2px); box-shadow: var(--sh-2); }
.stat .ico { width: 46px; height: 46px; flex: none; border-radius: 13px; display: grid; place-items: center; background: var(--brand-grad); box-shadow: var(--sh-brand); }
.stat .ico svg { width: 22px; height: 22px; color: #fff; }
.stat .v { font-size: 23px; font-weight: 800; letter-spacing: -.02em; line-height: 1.1; }
.stat .l { font-size: 12.5px; color: var(--ink-3); }
.stat.c2 .ico { background: linear-gradient(135deg,#06b6d4,#0ea5e9); box-shadow: 0 8px 22px -8px rgba(6,182,212,.5); }
.stat.c3 .ico { background: linear-gradient(135deg,#f43f5e,#fb7185); box-shadow: 0 8px 22px -8px rgba(244,63,94,.5); }
.stat.c4 .ico { background: linear-gradient(135deg,#10b981,#34d399); box-shadow: 0 8px 22px -8px rgba(16,185,129,.5); }

/* ============================ DataTable ============================ */
.dt-toolbar { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; padding: 14px 16px; border-bottom: 1px solid var(--line); }
.dt-toolbar .grow { flex: 1; }
.dt-search { position: relative; min-width: 200px; flex: 1 1 220px; max-width: 360px; }
.dt-search svg { position: absolute; inset-inline-start: 11px; top: 50%; transform: translateY(-50%); width: 16px; height: 16px; color: var(--ink-3); }
.dt-search input { width: 100%; padding: 8px 12px; padding-inline-start: 36px; background: var(--panel-2); border: 1.5px solid var(--line); border-radius: var(--r-full); }
.dt-search input:focus { outline: none; background: var(--panel); border-color: var(--brand); box-shadow: 0 0 0 4px var(--brand-ring); }

.dt-scroll { overflow-x: auto; }
.dt { width: 100%; border-collapse: collapse; font-size: 13px; }
/* الأعمدة والبيانات في الوسط لتتراصف تحت بعضها (طلب المستخدم) */
.dt thead th {
  text-align: center; padding: 11px 14px; font-size: 11.5px; font-weight: 700;
  color: var(--ink-3); text-transform: uppercase; letter-spacing: .03em;
  background: var(--panel-2); border-bottom: 1px solid var(--line);
  white-space: nowrap; position: sticky; top: 0; z-index: 1;
}
.dt thead th.sortable { cursor: pointer; user-select: none; }
.dt thead th.sortable:hover { color: var(--ink); }
.dt thead th .sort-ar { font-size: 9px; opacity: .6; margin-inline-start: 3px; }
.dt tbody td { padding: 11px 14px; border-bottom: 1px solid var(--line); vertical-align: middle; text-align: center; }
.dt tbody tr { transition: background .1s var(--ease); }
.dt tbody tr:hover { background: var(--panel-2); }
.dt tbody tr:last-child td { border-bottom: none; }
.dt td.num, .dt th.num { text-align: center; font-variant-numeric: tabular-nums; white-space: nowrap; }
/* النص الطويل: يبقى مقصوصاً لكن في الوسط ليتراصف مع رأس العمود */
.dt td.dt-cell-clip { text-align: center; margin: 0 auto; }
/* عمود الإجراءات يبقى في الوسط أيضاً */
.dt td.actions { text-align: center; }
.dt td.actions { white-space: nowrap; text-align: end; }
.dt td.actions .iconbtn { display: inline-grid; margin-inline-start: 4px; }
.dt .chk { width: 40px; text-align: center; }
.dt .chk input { width: 16px; height: 16px; accent-color: var(--brand); }
.dt-cell-strong { font-weight: 600; }
.dt-cell-sub { font-size: 11.5px; color: var(--ink-3); }
.dt-cell-clip { max-width: 360px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.dt tr.row-muted { opacity: .62; }
.dt tr.row-muted .dt-cell-clip { text-decoration: line-through; text-decoration-color: var(--danger); }

.dt-foot { display: flex; align-items: center; gap: 14px; padding: 12px 16px; border-top: 1px solid var(--line); flex-wrap: wrap; }
.dt-foot .info { font-size: 12.5px; color: var(--ink-3); }
.dt-foot .grow { flex: 1; }
.dt-pager { display: flex; align-items: center; gap: 4px; }
.dt-pager button { min-width: 32px; height: 32px; padding: 0 9px; border-radius: var(--r-xs); color: var(--ink-2); font-weight: 600; font-size: 12.5px; }
.dt-pager button:hover:not(:disabled) { background: var(--muted); color: var(--ink); }
.dt-pager button.active { background: var(--brand-grad); color: #fff; box-shadow: var(--sh-brand); }
.dt-pager button:disabled { opacity: .35; cursor: default; }
.dt-perpage { display: flex; align-items: center; gap: 7px; font-size: 12px; color: var(--ink-3); }
.dt-perpage select { padding: 5px 28px 5px 10px; font-size: 12px; }

.dt-empty, .dt-loading { padding: 52px 20px; text-align: center; color: var(--ink-3); }
.dt-empty .ico { font-size: 36px; margin-bottom: 10px; }
.dt-bulk { display: flex; align-items: center; gap: 10px; padding: 10px 16px; background: var(--brand-soft); border-bottom: 1px solid var(--brand); font-size: 13px; font-weight: 600; }
.dt-bulk .grow { flex: 1; }

/* skeleton rows */
.sk { display: inline-block; height: 12px; border-radius: 6px; background: linear-gradient(90deg, var(--muted) 25%, var(--panel-2) 50%, var(--muted) 75%); background-size: 200% 100%; animation: sk 1.3s infinite; }
@keyframes sk { 0% { background-position: 200% 0; } 100% { background-position: -200% 0; } }

/* ============================ Badges / chips ============================ */
.badge { display: inline-flex; align-items: center; gap: 4px; font-size: 11.5px; font-weight: 600; padding: 3px 9px; border-radius: var(--r-full); background: var(--muted); color: var(--ink-2); white-space: nowrap; }
.badge.ok { background: var(--success-soft); color: var(--success); }
.badge.bad { background: var(--danger-soft); color: var(--danger); }
.badge.warnb { background: var(--warn-soft); color: var(--warn); }
.badge.infob { background: var(--info-soft); color: var(--info); }
.badge.brand { background: var(--brand-soft); color: var(--brand); }
.badge.admin { background: #fdebc8; color: #b06f00; }
[data-theme="dark"] .badge.admin { background: rgba(245,158,11,.16); color: #fbbf24; }
.badge-dot { width: 7px; height: 7px; border-radius: 50%; }

/* ============================ Tabs ============================ */
.tabs { display: inline-flex; gap: 3px; padding: 4px; background: var(--muted); border: 1px solid var(--line); border-radius: var(--r-full); margin-bottom: 18px; flex-wrap: wrap; }
.tab { padding: 7px 16px; border-radius: var(--r-full); font-weight: 600; font-size: 13px; color: var(--ink-3); }
.tab:hover { color: var(--ink); }
.tab.active { background: var(--panel); color: var(--brand); box-shadow: var(--sh-1); }

/* ============================ Modal ============================ */
.modal-overlay {
  position: fixed; inset: 0; z-index: 100;
  background: var(--overlay);
  backdrop-filter: blur(7px); -webkit-backdrop-filter: blur(7px);
  display: flex; align-items: flex-start; justify-content: center;
  padding: 40px 18px; overflow-y: auto;
  opacity: 0; animation: ov-in .18s var(--ease) forwards;
}
@keyframes ov-in { to { opacity: 1; } }
.modal {
  width: 100%; max-width: 540px; margin: auto;
  background: var(--panel); border: 1px solid var(--line);
  border-radius: var(--r-xl); box-shadow: var(--sh-3);
  transform: translateY(20px) scale(.98); opacity: 0;
  animation: md-in .26s var(--ease-out) forwards;
}
.modal.lg { max-width: 820px; }
.modal.sm { max-width: 420px; }
@keyframes md-in { to { transform: translateY(0) scale(1); opacity: 1; } }
.modal-head { display: flex; align-items: center; gap: 12px; padding: 18px 20px; border-bottom: 1px solid var(--line); }
.modal-head h3 { font-size: 17px; font-weight: 700; flex: 1; letter-spacing: -.01em; }
.modal-x { width: 34px; height: 34px; border-radius: var(--r-sm); display: grid; place-items: center; background: var(--muted); color: var(--ink-2); transition: all .12s var(--ease); }
.modal-x:hover { background: var(--danger-soft); color: var(--danger); rotate: 90deg; }
.modal-x svg { width: 17px; height: 17px; }
.modal-body { padding: 20px; }
.modal-body.scroll { max-height: 64vh; overflow-y: auto; }
.modal-foot { display: flex; gap: 10px; justify-content: flex-end; padding: 16px 20px; border-top: 1px solid var(--line); background: var(--panel-2); border-radius: 0 0 var(--r-xl) var(--r-xl); flex-wrap: wrap; }

/* ============================ Toast ============================ */
.toast-wrap { position: fixed; inset-block-end: 20px; inset-inline-start: 20px; z-index: 200; display: flex; flex-direction: column; gap: 10px; max-width: 360px; }
.toast {
  display: flex; align-items: center; gap: 10px;
  padding: 12px 15px; border-radius: var(--r);
  background: var(--panel); border: 1px solid var(--line);
  border-inline-start: 3px solid var(--brand);
  box-shadow: var(--sh-3); font-size: 13px; font-weight: 500;
  animation: tt-in .26s var(--ease-out);
}
.toast.ok { border-inline-start-color: var(--success); }
.toast.err { border-inline-start-color: var(--danger); }
.toast.warn { border-inline-start-color: var(--warn); }
.toast .ico { width: 18px; height: 18px; flex: none; }
.toast.ok .ico { color: var(--success); } .toast.err .ico { color: var(--danger); }
.toast.warn .ico { color: var(--warn); } .toast .ico { color: var(--brand); }
@keyframes tt-in { from { opacity: 0; transform: translateX(-16px); } }
.toast.out { animation: tt-out .2s var(--ease) forwards; }
@keyframes tt-out { to { opacity: 0; transform: translateX(-16px); } }

/* ============================ Misc ============================ */
.muted-text { color: var(--ink-3); }
.pill-row { display: flex; flex-wrap: wrap; gap: 7px; }
.divider { height: 1px; background: var(--line); margin: 16px 0; }
.kv { display: grid; grid-template-columns: max-content 1fr; gap: 8px 16px; font-size: 13px; }
.kv dt { color: var(--ink-3); }
.kv dd { font-weight: 500; }
.notice { padding: 12px 15px; border-radius: var(--r); background: var(--info-soft); color: var(--info); font-size: 12.5px; display: flex; gap: 9px; align-items: flex-start; }
.notice.warn { background: var(--warn-soft); color: var(--warn); }
.empty-card { text-align: center; padding: 56px 20px; color: var(--ink-3); }
.empty-card .ico { font-size: 42px; margin-bottom: 12px; }
.spinner { width: 30px; height: 30px; border: 3px solid var(--line); border-top-color: var(--brand); border-radius: 50%; animation: spin .7s linear infinite; margin: 0 auto; }
@keyframes spin { to { transform: rotate(360deg); } }

/* media grid */
.media-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px,1fr)); gap: 12px; }
.media-tile { position: relative; aspect-ratio: 1; border-radius: var(--r); overflow: hidden; background: var(--muted); border: 1px solid var(--line); cursor: pointer; }
.media-tile img { width: 100%; height: 100%; object-fit: cover; transition: transform .25s var(--ease); }
.media-tile:hover img { transform: scale(1.06); }
.media-tile .play { position: absolute; inset: 0; display: grid; place-items: center; background: rgba(0,0,0,.32); }
.media-tile .play svg { width: 40px; height: 40px; color: #fff; filter: drop-shadow(0 2px 6px rgba(0,0,0,.5)); }
.media-tile.noimg img { display: none; }
.media-tile.noimg::after { content: '🖼'; position: absolute; inset: 0; display: grid; place-items: center; font-size: 28px; opacity: .4; }

/* lightbox — مستعرض وسائط داخل الموقع (صور + فيديو) */
.lightbox { position: fixed; inset: 0; z-index: 150; background: rgba(0,0,0,.92); display: grid; place-items: center; padding: 40px 70px; animation: ov-in .18s var(--ease); }
.lb-stage { display: grid; place-items: center; max-width: 100%; max-height: 100%; }
.lb-img { max-width: 88vw; max-height: 84vh; border-radius: var(--r); box-shadow: 0 20px 60px rgba(0,0,0,.5); }
.lb-video { max-width: 88vw; max-height: 84vh; border-radius: var(--r); background: #000; box-shadow: 0 20px 60px rgba(0,0,0,.5); }
.lb-frame { width: min(88vw, 900px); height: min(84vh, 506px); border: none; border-radius: var(--r); background: #000; box-shadow: 0 20px 60px rgba(0,0,0,.5); }
.lightbox .lb-x, .lightbox .lb-nav { position: absolute; background: rgba(255,255,255,.14); color: #fff; width: 48px; height: 48px; border-radius: 50%; display: grid; place-items: center; backdrop-filter: blur(4px); transition: background .12s var(--ease); }
.lightbox .lb-x svg, .lightbox .lb-nav svg { width: 22px; height: 22px; }
.lightbox .lb-x { top: 22px; inset-inline-end: 22px; }
.lb-navwrap .lb-nav.prev { position: fixed; inset-inline-end: 16px; top: 50%; transform: translateY(-50%); }
.lb-navwrap .lb-nav.next { position: fixed; inset-inline-start: 16px; top: 50%; transform: translateY(-50%); }
.lightbox .lb-x:hover, .lightbox .lb-nav:hover { background: rgba(255,255,255,.3); }
.lb-counter { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); color: #fff; font-size: 13px; font-weight: 600; background: rgba(255,255,255,.12); padding: 5px 14px; border-radius: var(--r-full); backdrop-filter: blur(4px); font-variant-numeric: tabular-nums; }
.lb-fail { color: #fff; text-align: center; padding: 60px 30px; max-width: 360px; }
.lb-fail p { opacity: .85; line-height: 1.7; }
.lb-fail .btn { background: rgba(255,255,255,.14); border-color: rgba(255,255,255,.25); color: #fff; }
.lb-fail .btn:hover { background: rgba(255,255,255,.24); }
@media (max-width: 640px) { .lightbox { padding: 20px 8px; } .lb-navwrap .lb-nav { width: 40px; height: 40px; } }

/* ===== scrape modal ===== */
.sc-mode { display: flex; gap: 16px; margin-bottom: 8px; }
.sc-picker { border: 1px solid var(--line); border-radius: var(--r-sm); padding: 10px; background: var(--panel-2); }
.sc-picker-bar { display: flex; gap: 8px; margin-bottom: 8px; }
.sc-picker-bar .inp { flex: 1; }
.sc-list { max-height: 200px; overflow-y: auto; display: flex; flex-direction: column; gap: 2px; }
.sc-page { display: flex; align-items: center; gap: 9px; padding: 7px 9px; border-radius: var(--r-xs); font-size: 13px; cursor: pointer; }
.sc-page:hover { background: var(--panel); }
.sc-page input { width: 16px; height: 16px; accent-color: var(--brand); flex: none; }
.sc-page-name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sc-page-city { font-size: 11px; color: var(--ink-3); }
.sc-count { font-size: 12px; color: var(--brand); font-weight: 600; margin-top: 8px; }
.sc-presets { display: flex; flex-wrap: wrap; gap: 7px; }
.sc-preset { padding: 7px 13px; border-radius: var(--r-full); border: 1.5px solid var(--line); background: var(--panel); font-weight: 600; font-size: 12.5px; color: var(--ink-2); transition: all .12s var(--ease); }
.sc-preset:hover { border-color: var(--brand); color: var(--brand); }
.sc-preset.active { background: var(--brand-grad); border-color: transparent; color: #fff; box-shadow: var(--sh-brand); }

/* ===== live progress ===== */
.prog-status { font-size: 15px; font-weight: 700; margin-bottom: 12px; }
.prog-bar { height: 10px; border-radius: var(--r-full); background: var(--muted); overflow: hidden; }
.prog-bar-in { height: 100%; width: 0; border-radius: var(--r-full); background: var(--brand-grad); transition: width .4s var(--ease); }
.prog-bar-in.indet { width: 40% !important; animation: indet 1.2s var(--ease) infinite; }
@keyframes indet { 0% { margin-inline-start: -40%; } 100% { margin-inline-start: 100%; } }
.prog-meta { display: flex; justify-content: space-between; font-size: 12.5px; color: var(--ink-3); margin: 8px 0 14px; }
.prog-log { height: 280px; overflow-y: auto; background: var(--panel-2); border: 1px solid var(--line); border-radius: var(--r-sm); padding: 12px; font-family: var(--mono); font-size: 11.5px; line-height: 1.85; }
.pg-line { white-space: pre-wrap; word-break: break-word; }
.pg-error { color: var(--danger); }
.pg-success, .pg-ok { color: var(--success); }
.pg-warn { color: var(--warn); }
.pg-info { color: var(--ink-2); }

/* ===== schedule form ===== */
.sf-detail { margin-top: 10px; padding: 12px; background: var(--panel-2); border: 1px solid var(--line); border-radius: var(--r-sm); }
.sf-detail .hint { margin-top: 0; margin-bottom: 6px; }
.sf-pages { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px,1fr)); gap: 6px 12px; max-height: 180px; overflow-y: auto; padding: 10px; border: 1px solid var(--line); border-radius: var(--r-sm); background: var(--panel-2); }
.sf-pages .check { font-size: 13px; }
.sf-pages .check span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ===== history ===== */
.hist-filters { display: inline-flex; gap: 3px; padding: 4px; background: var(--muted); border: 1px solid var(--line); border-radius: var(--r-full); }
.hist-filter { padding: 6px 14px; border-radius: var(--r-full); font-weight: 600; font-size: 12.5px; color: var(--ink-3); }
.hist-filter:hover { color: var(--ink); }
.hist-filter.active { background: var(--panel); color: var(--brand); box-shadow: var(--sh-1); }
.live-jobs { margin-bottom: 18px; }
.live-job { display: flex; align-items: center; gap: 12px; padding: 14px 16px; background: var(--brand-soft); border: 1px solid var(--brand); border-radius: var(--r); margin-bottom: 10px; }
.live-job .dot { width: 10px; height: 10px; border-radius: 50%; background: var(--brand); animation: pulse 1.1s infinite; flex: none; }
.live-job .grow { flex: 1; }
.live-prog { height: 6px; border-radius: var(--r-full); background: var(--muted); overflow: hidden; margin-top: 6px; }
.live-prog-bar { height: 100%; background: var(--brand-grad); border-radius: var(--r-full); transition: width .4s var(--ease); }

/* ===== settings ===== */
.src-card { margin-bottom: 16px; }
.src-head { display: flex; align-items: center; gap: 12px; }
.src-ico { font-size: 24px; line-height: 1; }
.src-prio { width: 26px; height: 26px; border-radius: 8px; background: var(--brand-soft); color: var(--brand); display: grid; place-items: center; font-weight: 700; font-size: 12px; flex: none; }
.src-extra { margin-top: 14px; padding-top: 14px; border-top: 1px solid var(--line); }
.locked-val { display: flex; align-items: center; gap: 8px; padding: 9px 12px; background: var(--panel-2); border: 1px solid var(--line); border-radius: var(--r-sm); font-family: var(--mono); font-size: 12px; }
.date-fmt-opts { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px,1fr)); gap: 8px; }
.date-fmt { border: 1.5px solid var(--line); border-radius: var(--r-sm); padding: 10px 12px; cursor: pointer; text-align: center; transition: all .12s var(--ease); }
.date-fmt:hover { border-color: var(--line-2); }
.date-fmt.selected { border-color: var(--brand); background: var(--brand-soft); }
.date-fmt strong { display: block; font-size: 13px; }
.date-fmt small { font-size: 11px; color: var(--ink-3); font-family: var(--mono); }
.help-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px,1fr)); gap: 14px; }
.help-card { padding: 18px; border: 1px solid var(--line); border-radius: var(--r-lg); background: var(--panel); }
.help-card .hc-ico { width: 42px; height: 42px; border-radius: 12px; display: grid; place-items: center; font-size: 20px; margin-bottom: 12px; background: var(--brand-soft); }
.help-card h3 { font-size: 14px; font-weight: 700; margin-bottom: 6px; }
.help-card p { font-size: 12.5px; color: var(--ink-3); line-height: 1.7; }

/* ===== advanced export modal ===== */
.exp-block { margin-bottom: 20px; }
.exp-block-title { display: block; font-size: 12px; font-weight: 700; color: var(--ink-2); margin-bottom: 9px; }
.exp-block-head { display: flex; align-items: center; margin-bottom: 6px; }
.exp-block-head .exp-block-title { margin: 0; flex: 1; }
.exp-block-actions { display: flex; gap: 4px; }
.exp-link { font-size: 12px; font-weight: 600; color: var(--brand); padding: 3px 8px; border-radius: var(--r-xs); }
.exp-link:hover { background: var(--brand-soft); }
.exp-help { font-size: 11.5px; color: var(--ink-3); margin-bottom: 9px; }

.exp-banner { display: flex; gap: 12px; align-items: center; padding: 13px 15px; border-radius: var(--r); background: var(--panel-2); border: 1px solid var(--line); margin-bottom: 20px; }
.exp-banner.filtered { background: var(--brand-soft); border-color: var(--brand); }
.exp-banner-ic { width: 36px; height: 36px; flex: none; border-radius: 10px; background: var(--brand-grad); display: grid; place-items: center; box-shadow: var(--sh-brand); }
.exp-banner-ic svg { width: 19px; height: 19px; color: #fff; }
.exp-banner strong { display: block; font-size: 13.5px; }
.exp-banner span { font-size: 12px; color: var(--ink-3); }
.exp-banner b { color: var(--brand); }

.exp-formats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.exp-format input { position: absolute; opacity: 0; pointer-events: none; }
.exp-format-card { border: 1.5px solid var(--line); border-radius: var(--r); padding: 14px 10px; text-align: center; cursor: pointer; transition: all .12s var(--ease); }
.exp-format-card:hover { border-color: var(--line-2); background: var(--panel-2); }
.exp-format input:checked + .exp-format-card { border-color: var(--brand); background: var(--brand-soft); box-shadow: 0 0 0 3px var(--brand-ring); }
.exp-format-ic { font-size: 24px; line-height: 1; margin-bottom: 6px; }
.exp-format-card strong { display: block; font-size: 13.5px; }
.exp-format-card small { font-size: 11px; color: var(--ink-3); }

.exp-fields { display: flex; flex-direction: column; gap: 3px; max-height: 240px; overflow-y: auto; padding: 8px; border: 1px solid var(--line); border-radius: var(--r-sm); background: var(--panel-2); }
.exp-field { display: flex; align-items: center; gap: 9px; padding: 7px 9px; border-radius: var(--r-xs); font-size: 13px; cursor: grab; background: var(--panel); border: 1px solid transparent; }
.exp-field:hover { border-color: var(--line); }
.exp-field.dragging { opacity: .5; }
.exp-field .exp-drag { color: var(--ink-3); font-size: 11px; letter-spacing: -2px; cursor: grab; }
.exp-field input { width: 16px; height: 16px; accent-color: var(--brand); flex: none; }
.exp-field-lbl { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.exp-addcol { display: flex; gap: 8px; margin-top: 10px; }
.exp-addcol .inp { flex: 1; }
.exp-limit { display: flex; align-items: center; gap: 14px; flex-wrap: wrap; padding-top: 4px; }
.exp-limit .check { font-size: 13px; }

/* analytics layout */
.an-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; margin-bottom: 18px; }
@media (max-width: 860px) { .an-grid { grid-template-columns: 1fr; } }
.an-timeline { display: flex; align-items: flex-end; gap: 6px; height: 160px; padding-top: 10px; }
.an-tl-col { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 6px; height: 100%; justify-content: flex-end; min-width: 0; }
.an-tl-bar { width: 100%; max-width: 34px; border-radius: 6px 6px 0 0; background: var(--brand-grad); transition: opacity .15s var(--ease); }
.an-tl-col:hover .an-tl-bar { opacity: .8; }
.an-tl-lbl { font-size: 10px; color: var(--ink-3); white-space: nowrap; transform: rotate(-45deg); transform-origin: center; }
/* تسمية فرعية داخل لوحة الإحصائيات */
.an-sub { font-size: 12.5px; font-weight: 600; color: var(--ink-2); margin-bottom: 8px; }
/* مخطط الساعات (24 عموداً) — أضيق + تسميات أفقية */
.an-hours { gap: 3px; height: 120px; }
.an-hours .an-tl-bar { max-width: 22px; border-radius: 4px 4px 0 0; }
.an-hours .an-tl-lbl { transform: none; font-size: 9px; }

/* simple bar chart (analytics) */
.bars { display: flex; flex-direction: column; gap: 9px; }
.bar-row { display: grid; grid-template-columns: 130px 1fr 56px; align-items: center; gap: 10px; font-size: 12.5px; }
.bar-row .lbl { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--ink-2); }
.bar-track { height: 9px; border-radius: var(--r-full); background: var(--muted); overflow: hidden; }
.bar-fill { height: 100%; border-radius: var(--r-full); background: var(--brand-grad); }
.bar-row .val { text-align: end; font-weight: 600; font-variant-numeric: tabular-nums; }

/* ============================ Responsive ============================ */
@media (max-width: 1024px) {
  .shell { grid-template-columns: 1fr; }
  /* درج جانبي ينزلق من اليمين (RTL) — مواضع فيزيائية صريحة لتفادي
     اختلاف تأويل الخصائص المنطقية بين المتصفحات. */
  .sidebar {
    position: fixed; top: 0; bottom: 0; right: 0; left: auto;
    width: 280px; max-width: 86vw; height: 100vh; height: 100dvh;
    transform: translateX(100%);   /* مخفي خارج الشاشة يميناً */
    transition: transform .26s var(--ease-out);
    box-shadow: var(--sh-3);
    border-inline-end: none; border-inline-start: 1px solid var(--line);
    z-index: 60;
  }
  .sidebar.open { transform: translateX(0); }
  .sb-backdrop {
    position: fixed; inset: 0; background: var(--overlay);
    z-index: 55; opacity: 0; animation: bd-in .2s var(--ease) forwards;
  }
  .burger { display: grid !important; }
  .content { max-width: 100%; }
  /* امنع تمرير الخلفية عندما يكون الدرج مفتوحاً */
  body.drawer-open { overflow: hidden; }
}
@keyframes bd-in { to { opacity: 1; } }

/* tablet (≤768): icon-only topbar buttons + hide page title so dense
   topbars (Pages = import+export+add+trigger) never crowd or overflow.
   السياق يظهر من العنصر النشط في القائمة الجانبية. */
@media (max-width: 768px) {
  .topbar { padding: 0 14px; gap: 8px; }
  .topbar .page-h1 { display: none; }
  .topbar .btn span:not(.badge) { display: none; }
  .topbar .btn { padding: 9px 11px; gap: 0; }
  .topbar .btn .badge { margin-inline-start: 2px; }
}

/* phone */
@media (max-width: 600px) {
  .content { padding: 14px; }
  .topbar { padding: 0 12px; gap: 7px; }

  .form-row { grid-template-columns: 1fr; }
  .page-head { gap: 10px; }
  .page-head .actions { width: 100%; }
  .page-head .actions .btn { flex: 1; justify-content: center; }
  .dt-cell-clip { max-width: 140px; }
  .modal-overlay { padding: 16px 10px; }
  .modal-foot { justify-content: stretch; }
  .modal-foot .btn { flex: 1; }
  /* tabs scroll horizontally instead of wrapping into tall stacks */
  .tabs { display: flex; flex-wrap: nowrap; overflow-x: auto; max-width: 100%; -webkit-overflow-scrolling: touch; scrollbar-width: none; }
  .tabs::-webkit-scrollbar { display: none; }
  .tab { white-space: nowrap; flex: none; }
  /* form pickers single column */
  .sf-pages, .export-fields, .date-fmt-opts, .help-grid { grid-template-columns: 1fr; }
  .exp-formats { grid-template-columns: 1fr; }
  /* keyword/analytics 2-col → 1-col */
  .an-grid { grid-template-columns: 1fr; }
  /* admin filter bars stack */
  .panel-body[style*="flex"] { flex-direction: column; align-items: stretch !important; }
  /* lightbox nav closer to edges */
  .lightbox { padding: 16px 6px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .001ms !important; transition-duration: .001ms !important; }
}
