/* ═══════════════════════════════════════════════════════════════
   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: 34px; height: 34px; border-radius: 9px; flex-shrink: 0;
  background: linear-gradient(145deg, #2ECC84 0%, #1A7A4A 100%);
  display: grid; place-items: center;
  box-shadow:
    0 1px 3px rgba(0,0,0,.18),
    0 4px 12px color-mix(in oklch, var(--primary) 35%, transparent),
    inset 0 1px 0 rgba(255,255,255,.22);
}
.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; }

/* ═══════════════════════════════════════════════════════════════
   Mobile drawer + scrim (sidebar slides in on small screens)
   ═══════════════════════════════════════════════════════════════ */
.scrim {
  position: fixed; inset: 0; background: rgba(0,0,0,.45);
  z-index: 30; opacity: 0; pointer-events: none;
  transition: opacity .18s ease;
}
.scrim.open { opacity: 1; pointer-events: auto; }

.mobile-only { display: none; }
.desktop-only { display: inline-flex; }

/* ═══════════════════════════════════════════════════════════════
   Tablet (≤ 1024px) — 2-col grids collapse
   ═══════════════════════════════════════════════════════════════ */
@media (max-width: 1024px) {
  .app { grid-template-columns: 220px 1fr; }
  .search { width: 200px; }
}

/* ═══════════════════════════════════════════════════════════════
   Mobile (≤ 860px) — drawer nav, stack everything
   ═══════════════════════════════════════════════════════════════ */
@media (max-width: 860px) {
  /* App shell — single column, sidebar becomes drawer */
  .app { grid-template-columns: 1fr; }

  .sidenav {
    position: fixed; top: 0; bottom: 0;
    inset-inline-start: 0;
    width: 280px; max-width: 84vw;
    z-index: 40;
    transform: translateX(-105%);
    transition: transform .22s ease;
    box-shadow: var(--shadow-lg);
  }
  [dir="rtl"] .sidenav { transform: translateX(105%); }
  .sidenav.open { transform: translateX(0); }

  .mobile-only { display: inline-flex; }
  .desktop-only { display: none; }

  /* Topbar — tighter, hide search, show burger */
  .topbar { padding: 10px 14px; gap: 8px; }
  .topbar h1 { font-size: 16px; }
  .topbar .crumb { font-size: 11px; }
  .topbar-actions { gap: 6px; }
  .search { display: none; }
  .seg button { padding: 4px 8px; font-size: 11.5px; }

  /* Page padding */
  .page { padding: 14px; max-width: 100%; }

  /* KPI grids — 2 columns on mobile */
  .page > div[style*="grid-template-columns: repeat(4"],
  .page > div[style*="grid-template-columns: repeat(5"],
  .page > div[style*="grid-template-columns: repeat(3"] {
    grid-template-columns: repeat(2, 1fr) !important;
  }
  .kpi { padding: 12px 14px; }
  .kpi-value { font-size: 20px; }

  /* 2-col page grids → stack */
  .page > div[style*="grid-template-columns: 1.6fr"],
  .page > div[style*="grid-template-columns: 1.2fr"],
  .page > div[style*="grid-template-columns: 1fr 460px"] {
    grid-template-columns: 1fr !important;
  }

  /* Tables — wrap parent card in scroll container on mobile */
  .tbl-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; width: 100%; }
  .tbl-wrap .tbl { min-width: 560px; }
  .tbl { font-size: 12.5px; }
  .tbl th, .tbl td { padding: 10px 8px; white-space: nowrap; }

  /* Cards — slimmer padding */
  .card { padding: 14px; border-radius: 12px; }

  /* Buttons — make tap targets bigger */
  .btn { height: 36px; padding: 0 12px; font-size: 13px; }
  .btn-sm { height: 30px; padding: 0 10px; }
  .btn-lg { height: 44px; }

  /* Sticky preview cards (e.g. Report builder) — un-stick on mobile */
  .page [style*="position: sticky"] { position: static !important; }
}

/* ═══════════════════════════════════════════════════════════════
   Small mobile (≤ 480px) — single column KPIs, stacked headers
   ═══════════════════════════════════════════════════════════════ */
@media (max-width: 480px) {
  .topbar h1 { font-size: 15px; }
  .page { padding: 10px; }

  /* KPIs go single column on tiny screens */
  .page > div[style*="grid-template-columns: repeat(4"],
  .page > div[style*="grid-template-columns: repeat(5"] {
    grid-template-columns: 1fr !important;
  }

  /* Card heads + action rows wrap nicely */
  .card-head { flex-wrap: wrap; }
  .row { flex-wrap: wrap; }

  /* Schedule day buttons shrink */
  .page button[style*="width: 52px"] { width: 38px !important; height: 38px !important; font-size: 13px !important; }
}

/* ═══════════════════════════════════════════════════════════════
   Landing page mobile — hero stacks, hide hero mock
   ═══════════════════════════════════════════════════════════════ */
@media (max-width: 860px) {
  /* Landing hero grid */
  .landing section[style*="grid-template-columns: 1.05fr"],
  .landing section[style*="grid-template-columns: repeat(3"] {
    grid-template-columns: 1fr !important;
    gap: 24px !important;
    padding: 20px 0 !important;
  }
  .landing .hero-mock { display: none !important; }

  /* Landing topbar nav links — hide secondary, keep brand + auth buttons */
  .landing-nav-secondary { display: none !important; }

  /* Landing outer container */
  .landing-shell { padding: 16px !important; }
}

/* ═══════════════════════════════════════════════════════════════
   Auth screens already collapse at 860px in auth.css
   ═══════════════════════════════════════════════════════════════ */
