/* ═══════════════════════════════════════════════════════════════
   Rawj Pro — design tokens + components
   ═══════════════════════════════════════════════════════════════ */

:root {
  /* Light Pro — defaults */
  --bg:        #FAF9F6;
  --surface:   #FFFFFF;
  --surface-2: #F4F2EC;
  --ink:       #14171A;
  --ink-2:     #2A2F35;
  --muted:     #6B7280;
  --muted-2:   #9AA0A6;
  --line:      rgba(20,23,26,0.08);
  --line-2:    rgba(20,23,26,0.14);
  --primary:        oklch(0.50 0.10 165);
  --primary-ink:    #ffffff;
  --primary-soft:   oklch(0.95 0.025 165);
  --accent:         oklch(0.72 0.15 70);
  --accent-soft:    oklch(0.96 0.04 75);
  --danger:         oklch(0.58 0.20 27);
  --danger-soft:    oklch(0.95 0.04 27);
  --success:        oklch(0.58 0.13 155);
  --success-soft:   oklch(0.95 0.04 155);
  --warn:           oklch(0.72 0.15 70);
  --warn-soft:      oklch(0.96 0.04 75);
  --info:           oklch(0.55 0.13 245);
  --info-soft:      oklch(0.95 0.03 245);
  --shadow-sm: 0 1px 2px rgba(20,23,26,.04), 0 0 0 .5px rgba(20,23,26,.06);
  --shadow:    0 1px 2px rgba(20,23,26,.05), 0 8px 24px -8px rgba(20,23,26,.10), 0 0 0 .5px rgba(20,23,26,.06);
  --shadow-lg: 0 24px 60px -16px rgba(20,23,26,.18), 0 0 0 .5px rgba(20,23,26,.06);
  --radius:    14px;
  --radius-sm: 8px;
  --radius-lg: 20px;
  --space:     12px;
  --font-ar: "IBM Plex Sans Arabic", "IBM Plex Sans", system-ui, sans-serif;
  --font-ltn: "IBM Plex Sans", "IBM Plex Sans Arabic", system-ui, sans-serif;
  --font-mono: "IBM Plex Mono", ui-monospace, monospace;
}

[data-theme="dark"] {
  --bg:        #0E1012;
  --surface:   #15181C;
  --surface-2: #1C2025;
  --ink:       #F2F2EE;
  --ink-2:     #D8D8D2;
  --muted:     #8B9098;
  --muted-2:   #5C6166;
  --line:      rgba(255,255,255,0.07);
  --line-2:    rgba(255,255,255,0.13);
  --primary:        oklch(0.66 0.13 165);
  --primary-ink:    #0E1012;
  --primary-soft:   oklch(0.28 0.06 165);
  --accent:         oklch(0.78 0.14 70);
  --accent-soft:    oklch(0.32 0.06 70);
  --danger:         oklch(0.68 0.20 27);
  --danger-soft:    oklch(0.30 0.08 27);
  --success:        oklch(0.70 0.13 155);
  --success-soft:   oklch(0.28 0.06 155);
  --warn:           oklch(0.78 0.14 70);
  --warn-soft:      oklch(0.32 0.06 70);
  --info:           oklch(0.70 0.13 245);
  --info-soft:      oklch(0.28 0.06 245);
  --shadow-sm: 0 1px 2px rgba(0,0,0,.3), 0 0 0 .5px rgba(255,255,255,.05);
  --shadow:    0 1px 2px rgba(0,0,0,.3), 0 8px 24px -8px rgba(0,0,0,.4), 0 0 0 .5px rgba(255,255,255,.05);
  --shadow-lg: 0 24px 60px -16px rgba(0,0,0,.5), 0 0 0 .5px rgba(255,255,255,.05);
}

[data-density="compact"]  { --space: 8px;  }
[data-density="comfy"]    { --space: 16px; }

* { box-sizing: border-box; }
html, body, #root { margin: 0; padding: 0; height: 100%; }
body {
  font-family: var(--font-ar);
  background: var(--bg);
  color: var(--ink);
  -webkit-font-smoothing: antialiased;
  font-feature-settings: "ss01", "cv11";
  font-size: 14px;
  line-height: 1.45;
}
[dir="ltr"] body { font-family: var(--font-ltn); }

button { font: inherit; color: inherit; cursor: default; }
a { color: inherit; text-decoration: none; }
.mono { font-family: var(--font-mono); font-variant-numeric: tabular-nums; }
.num  { font-variant-numeric: tabular-nums; font-feature-settings: "tnum"; }

/* ─── App shell ─────────────────────────────────── */
.app { display: grid; grid-template-columns: 240px 1fr; min-height: 100vh; background: var(--bg); }
[dir="ltr"] .app { grid-template-columns: 240px 1fr; }
.app[data-mobile="true"] { grid-template-columns: 1fr; }
.app[data-mobile="true"] .sidenav { display: none; }

.sidenav {
  background: var(--surface);
  border-inline-end: 1px solid var(--line);
  display: flex; flex-direction: column;
  padding: 18px 14px; gap: 6px;
  position: sticky; top: 0; height: 100vh; overflow-y: auto;
}
.brand { display: flex; align-items: center; gap: 10px; padding: 4px 8px 18px; }
.brand-mark {
  width: 30px; height: 30px; border-radius: 8px;
  background:
    radial-gradient(circle at 30% 30%, var(--accent), transparent 55%),
    linear-gradient(135deg, var(--primary), color-mix(in oklch, var(--primary) 60%, #000));
  display: grid; place-items: center;
  color: #fff; font-weight: 700; font-size: 13px;
  font-family: var(--font-ltn);
  box-shadow: inset 0 1px 0 rgba(255,255,255,.25);
}
.brand-name { display: flex; flex-direction: column; line-height: 1.1; }
.brand-name b { font-size: 14px; font-weight: 600; letter-spacing: -.01em; }
.brand-name span { font-size: 10.5px; color: var(--muted); font-family: var(--font-ltn); letter-spacing: .04em; }

.nav-group { font-size: 10.5px; font-weight: 600; letter-spacing: .08em; text-transform: uppercase; color: var(--muted-2); padding: 14px 10px 6px; }

.nav-item {
  display: flex; align-items: center; gap: 10px;
  padding: 9px 10px; border-radius: 10px;
  color: var(--ink-2); font-size: 13.5px;
  border: 0; background: transparent; width: 100%;
  text-align: start;
}
.nav-item:hover { background: var(--surface-2); }
.nav-item[aria-current="page"] { background: var(--primary-soft); color: var(--primary); font-weight: 600; }
.nav-item[aria-current="page"] svg { color: var(--primary); }
.nav-item .badge-pill { margin-inline-start: auto; background: var(--danger); color: #fff; font-size: 10.5px; padding: 1px 6px; border-radius: 999px; font-family: var(--font-ltn); font-weight: 600; }
.nav-item svg { width: 16px; height: 16px; flex: none; color: var(--muted); }
.nav-item[aria-current="page"]:hover { background: var(--primary-soft); }

.user-card {
  margin-top: auto;
  display: flex; align-items: center; gap: 10px;
  padding: 10px; border-radius: 12px; background: var(--surface-2);
  border: 1px solid var(--line);
}
.avatar { width: 32px; height: 32px; border-radius: 50%;
  background: linear-gradient(135deg, var(--primary), var(--accent));
  color: #fff; display: grid; place-items: center; font-size: 12px; font-weight: 600;
  font-family: var(--font-ltn);
}
.user-card .who { font-size: 12.5px; font-weight: 600; }
.user-card .role { font-size: 10.5px; color: var(--muted); }

/* ─── Top bar ───────────────────────────────────── */
.topbar {
  display: flex; align-items: center; gap: 14px;
  padding: 14px 28px;
  background: var(--bg);
  border-bottom: 1px solid var(--line);
  position: sticky; top: 0; z-index: 5; backdrop-filter: blur(8px);
}
.topbar h1 { font-size: 19px; font-weight: 600; margin: 0; letter-spacing: -.01em; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.topbar > div:first-child { min-width: 0; flex: 1 1 auto; overflow: hidden; }
.topbar .crumb { font-size: 12px; color: var(--muted); margin-bottom: 1px; font-weight: 500; }
.topbar-actions { margin-inline-start: auto; display: flex; align-items: center; gap: 8px; }
.search {
  display: flex; align-items: center; gap: 8px;
  height: 34px; padding: 0 12px;
  border: 1px solid var(--line); border-radius: 10px;
  background: var(--surface); width: 280px;
  color: var(--muted);
}
.search input { border: 0; background: transparent; outline: 0; flex: 1; color: var(--ink); font: inherit; }
.search kbd {
  font-family: var(--font-ltn); font-size: 10.5px; padding: 1px 5px;
  border: 1px solid var(--line); border-radius: 4px; color: var(--muted);
  background: var(--bg);
}

/* ─── Page ─────────────────────────────────────── */
.page { padding: 28px; max-width: 1400px; }
@media (max-width: 720px) { .page { padding: 18px; } .topbar { padding: 14px 18px; } .search { display: none; } }

.row { display: flex; gap: 12px; align-items: center; }
.col { display: flex; flex-direction: column; gap: 12px; }
.gap-sm { gap: 6px; } .gap-lg { gap: 20px; }

/* ─── Buttons / chips ──────────────────────────── */
.btn {
  display: inline-flex; align-items: center; gap: 8px;
  height: 34px; padding: 0 14px; border-radius: 10px;
  border: 1px solid var(--line-2); background: var(--surface);
  font-size: 13px; font-weight: 500; color: var(--ink);
  white-space: nowrap;
}
.btn:hover { background: var(--surface-2); }
.btn-primary { background: var(--primary); color: var(--primary-ink); border-color: transparent; font-weight: 600; }
.btn-primary:hover { background: color-mix(in oklch, var(--primary) 90%, #000); }
.btn-ghost { border-color: transparent; background: transparent; }
.btn-ghost:hover { background: var(--surface-2); }
.btn-danger { background: var(--danger); color: #fff; border-color: transparent; font-weight: 600; }
.btn-lg { height: 42px; padding: 0 18px; font-size: 14px; border-radius: 12px; }
.btn-sm { height: 28px; padding: 0 10px; font-size: 12px; border-radius: 8px; }
.btn svg { width: 14px; height: 14px; }

.chip {
  display: inline-flex; align-items: center; gap: 6px;
  height: 22px; padding: 0 8px; border-radius: 6px;
  font-size: 11.5px; font-weight: 500;
  background: var(--surface-2); color: var(--ink-2);
  font-family: var(--font-ltn);
}
.chip.ar { font-family: var(--font-ar); }
.chip-success { background: var(--success-soft); color: var(--success); }
.chip-danger  { background: var(--danger-soft);  color: var(--danger); }
.chip-warn    { background: var(--warn-soft);    color: var(--warn); }
.chip-info    { background: var(--info-soft);    color: var(--info); }
.chip-dot::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }

/* ─── Card ──────────────────────────────────────── */
.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 18px;
}
.card-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 14px; gap: 10px; }
.card-title { font-size: 14px; font-weight: 600; margin: 0; }
.card-sub { font-size: 12px; color: var(--muted); }

/* ─── KPI tile ─────────────────────────────────── */
.kpi {
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 16px 18px;
  display: flex; flex-direction: column; gap: 8px; min-width: 0;
}
.kpi-label { font-size: 12px; color: var(--muted); display: flex; align-items: center; gap: 6px; }
.kpi-value { font-size: 26px; font-weight: 600; letter-spacing: -.01em; line-height: 1.1; }
.kpi-value .unit { font-size: 13px; color: var(--muted); margin-inline-start: 4px; font-weight: 500; }
.kpi-foot { display: flex; align-items: center; gap: 8px; font-size: 11.5px; color: var(--muted); }
.delta-up   { color: var(--success); font-weight: 600; }
.delta-down { color: var(--danger);  font-weight: 600; }

/* ─── Table ─────────────────────────────────────── */
.tbl { width: 100%; border-collapse: collapse; font-size: 13px; }
.tbl th { text-align: start; font-weight: 500; color: var(--muted); padding: 10px 12px; border-bottom: 1px solid var(--line); font-size: 11.5px; letter-spacing: .04em; text-transform: uppercase; }
.tbl td { padding: 14px 12px; border-bottom: 1px solid var(--line); }
.tbl tr:last-child td { border-bottom: 0; }
.tbl tr:hover td { background: var(--surface-2); }

/* ─── Platform pill ─────────────────────────────── */
.plat { width: 22px; height: 22px; border-radius: 6px; display: grid; place-items: center; color: #fff; font-weight: 700; font-size: 11px; flex: none; font-family: var(--font-ltn); }
.plat-meta  { background: linear-gradient(135deg,#0866FF,#7B2CBF); }
.plat-google{ background: #fff; color: #4285F4; border: 1px solid var(--line); font-weight: 800; }
.plat-tiktok{ background: #000; }
.plat-snap  { background: #FFFC00; color: #000; }

/* ─── Status dot ───────────────────────────────── */
.dot { width: 8px; height: 8px; border-radius: 50%; flex: none; }
.dot-success { background: var(--success); box-shadow: 0 0 0 3px var(--success-soft); }
.dot-danger  { background: var(--danger);  box-shadow: 0 0 0 3px var(--danger-soft);  animation: pulse 1.6s infinite; }
.dot-warn    { background: var(--warn);    box-shadow: 0 0 0 3px var(--warn-soft); }
.dot-muted   { background: var(--muted-2); }
@keyframes pulse { 0%,100%{box-shadow:0 0 0 3px var(--danger-soft);} 50%{box-shadow:0 0 0 6px transparent;} }

/* ─── Toggle / segmented ───────────────────────── */
.seg {
  display: inline-flex; padding: 3px; gap: 2px;
  background: var(--surface-2); border-radius: 9px;
  border: 1px solid var(--line);
}
.seg button {
  border: 0; background: transparent; padding: 5px 12px; font-size: 12px;
  border-radius: 6px; color: var(--muted); font-weight: 500;
}
.seg button[aria-pressed="true"] { background: var(--surface); color: var(--ink); box-shadow: var(--shadow-sm); font-weight: 600; }

.switch { width: 34px; height: 20px; border-radius: 999px; background: var(--line-2); position: relative; flex: none; transition: background .15s; cursor: default; }
.switch::after { content: ""; position: absolute; top: 2px; inset-inline-start: 2px; width: 16px; height: 16px; border-radius: 50%; background: #fff; box-shadow: 0 1px 2px rgba(0,0,0,.2); transition: inset-inline-start .15s; }
.switch[aria-checked="true"] { background: var(--primary); }
.switch[aria-checked="true"]::after { inset-inline-start: 16px; }

/* ─── Sparkline / chart helpers ────────────────── */
.spark { height: 36px; width: 100%; display: block; }
.bar-bg { fill: var(--line); }
.bar-fg { fill: var(--primary); }
.line-stroke { stroke: var(--primary); stroke-width: 2; fill: none; }
.line-area { fill: var(--primary); opacity: .12; }

/* ─── Misc ─────────────────────────────────────── */
.divider { height: 1px; background: var(--line); margin: 0; }
.muted { color: var(--muted); }
.tag-ar { font-family: var(--font-ar); }
.tag-en { font-family: var(--font-ltn); }

.placeholder {
  background: repeating-linear-gradient(135deg, var(--surface-2) 0 8px, var(--surface) 8px 16px);
  border: 1px dashed var(--line-2); border-radius: var(--radius);
  display: grid; place-items: center; color: var(--muted);
  font-family: var(--font-mono); font-size: 11px; padding: 20px;
}

/* ─── Mobile frame preview ─────────────────────── */
.mobile-stage {
  display: grid; place-items: center; padding: 40px;
  background: linear-gradient(180deg, var(--surface-2), var(--bg));
  min-height: 100vh;
}
.iphone {
  width: 390px; height: 780px; border-radius: 46px;
  background: var(--bg); box-shadow: var(--shadow-lg), 0 0 0 12px #1d1f22, 0 0 0 13px #2c2f33;
  position: relative; overflow: hidden;
}
.iphone-status {
  position: absolute; top: 0; inset-inline: 0; height: 44px;
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 28px 0; font-size: 13px; font-family: var(--font-ltn);
  font-weight: 600;
}
.iphone-notch {
  position: absolute; top: 10px; left: 50%; transform: translateX(-50%);
  width: 110px; height: 30px; background: #000; border-radius: 18px;
}
.iphone-content { padding: 56px 0 0; height: 100%; overflow-y: auto; }
