@import url('https://fonts.googleapis.com/css2?family=Hanken+Grotesk:wght@400;500;600;700;800&family=Newsreader:wght@400;500;600&family=JetBrains+Mono:wght@400;500;600&display=swap');
/* ============================================================
   Relay — Design System
   Friendly & approachable: rounded, soft colors, warm neutrals
   ============================================================ */

:root {
  /* Claude-style warm cream ramp */
  --bg:        oklch(0.935 0.012 83);
  --bg-sunk:   oklch(0.915 0.014 83);
  --surface:   oklch(0.99 0.004 83);
  --surface-2: oklch(0.955 0.009 83);
  --line:      oklch(0.885 0.012 83);
  --line-soft: oklch(0.915 0.01 83);

  --ink:       oklch(0.305 0.014 55);
  --ink-2:     oklch(0.46 0.014 55);
  --ink-3:     oklch(0.60 0.012 55);

  /* Primary — Claude clay / terracotta (overridable by tweaks) */
  --primary:      oklch(0.64 0.123 42);
  --primary-ink:  oklch(0.515 0.13 40);
  --primary-soft: oklch(0.925 0.032 52);
  --primary-soft2: oklch(0.875 0.052 50);
  --on-primary:   oklch(0.99 0.006 80);

  /* Secondary accent — muted dusty blue, used sparingly */
  --accent:      oklch(0.62 0.07 240);
  --accent-soft: oklch(0.93 0.025 240);

  /* Semantic — warmed, muted to sit on cream */
  --ok:        oklch(0.58 0.1 150);
  --ok-soft:   oklch(0.93 0.035 150);
  --warn:      oklch(0.7 0.11 70);
  --warn-soft: oklch(0.93 0.05 75);
  --bad:       oklch(0.58 0.15 28);
  --bad-soft:  oklch(0.93 0.04 30);
  --info:      var(--primary);
  --info-soft: var(--primary-soft);

  /* Radius */
  --r-xs: 8px;
  --r-sm: 10px;
  --r-md: 14px;
  --r-lg: 18px;
  --r-xl: 24px;
  --r-pill: 999px;

  /* Shadows — soft, layered */
  --sh-1: 0 1px 2px oklch(0.4 0.03 55 / 0.04), 0 1px 3px oklch(0.4 0.03 55 / 0.05);
  --sh-2: 0 2px 4px oklch(0.4 0.03 55 / 0.04), 0 6px 16px oklch(0.4 0.03 55 / 0.07);
  --sh-3: 0 8px 24px oklch(0.4 0.03 55 / 0.09), 0 2px 6px oklch(0.4 0.03 55 / 0.05);
  --sh-pop: 0 16px 44px oklch(0.32 0.04 55 / 0.16);

  /* Density (overridable) */
  --pad: 20px;
  --gap: 16px;
  --row-h: 48px;
  --control-h: 42px;

  --font: "Hanken Grotesk", ui-sans-serif, system-ui, sans-serif;
  --serif: "Newsreader", Georgia, "Times New Roman", serif;
  --mono: "JetBrains Mono", ui-monospace, monospace;
}

[data-density="compact"] {
  --pad: 14px;
  --gap: 10px;
  --row-h: 40px;
  --control-h: 36px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

#root { height: 100%; }

button { font-family: inherit; }
input, textarea, select { font-family: inherit; }

::selection { background: var(--primary-soft2); }

/* Scrollbars */
*::-webkit-scrollbar { width: 11px; height: 11px; }
*::-webkit-scrollbar-thumb {
  background: oklch(0.84 0.015 70);
  border-radius: 999px;
  border: 3px solid transparent;
  background-clip: padding-box;
}
*::-webkit-scrollbar-thumb:hover { background: oklch(0.76 0.025 60); background-clip: padding-box; }

/* ---------- Layout ---------- */
.app {
  display: grid;
  grid-template-columns: 248px 1fr;
  grid-template-rows: 64px 1fr;
  grid-template-areas: "brand topbar" "sidebar main";
  height: 100%;
  min-height: 0;
}

.brand-cell {
  grid-area: brand;
  display: flex;
  align-items: center;
  gap: 11px;
  padding: 0 20px;
  border-right: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
  background: var(--surface);
}
.brand-mark {
  width: 32px; height: 32px;
  border-radius: 10px;
  background: linear-gradient(145deg, var(--primary), var(--primary-ink));
  display: grid; place-items: center;
  color: var(--on-primary);
  box-shadow: var(--sh-1);
  flex: none;
}
.brand-name { font-family: var(--serif); font-weight: 600; font-size: 18px; letter-spacing: -0.01em; white-space: nowrap; }
.brand-sub { font-size: 11px; color: var(--ink-3); font-weight: 500; margin-top: -1px; white-space: nowrap; }

.topbar {
  grid-area: topbar;
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 0 22px;
  border-bottom: 1px solid var(--line);
  background: var(--surface);
}

.sidebar {
  grid-area: sidebar;
  border-right: 1px solid var(--line);
  background: var(--surface);
  padding: 16px 12px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.main {
  grid-area: main;
  overflow-y: auto;
  background: var(--bg);
  min-width: 0;
}
.main-inner { max-width: 1120px; margin: 0 auto; padding: 28px 32px 80px; }
.main-inner.wide { max-width: 100%; }

/* ---------- Nav ---------- */
.nav-group-label {
  font-size: 11px; font-weight: 700; letter-spacing: 0.06em;
  text-transform: uppercase; color: var(--ink-3);
  padding: 14px 12px 6px;
}
.nav-item {
  display: flex; align-items: center; gap: 11px;
  padding: 9px 12px;
  border-radius: var(--r-sm);
  color: var(--ink-2);
  font-weight: 600; font-size: 14px;
  cursor: pointer;
  border: none; background: none; text-align: left; width: 100%;
  transition: background .12s, color .12s;
}
.nav-item:hover { background: var(--surface-2); color: var(--ink); }
.nav-item.active { background: var(--primary-soft); color: var(--primary-ink); }
.nav-item.active svg { color: var(--primary); }
.nav-item svg { color: var(--ink-3); flex: none; }
.nav-item .count {
  margin-left: auto;
  font-size: 11px; font-weight: 700;
  background: var(--primary); color: var(--on-primary);
  min-width: 20px; height: 20px; border-radius: 999px;
  display: grid; place-items: center; padding: 0 6px;
}
.nav-item.active .count { background: var(--primary); }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  height: var(--control-h); padding: 0 16px;
  border-radius: var(--r-sm);
  border: 1px solid transparent;
  font-weight: 700; font-size: 14px;
  cursor: pointer; white-space: nowrap;
  transition: transform .08s, background .12s, box-shadow .12s, border-color .12s;
}
.btn:active { transform: translateY(1px); }
.btn-primary { background: var(--primary); color: var(--on-primary); box-shadow: var(--sh-1); }
.btn-primary:hover { background: var(--primary-ink); }
.btn-ghost { background: var(--surface); color: var(--ink); border-color: var(--line); }
.btn-ghost:hover { background: var(--surface-2); border-color: var(--ink-3); }
.btn-soft { background: var(--primary-soft); color: var(--primary-ink); }
.btn-soft:hover { background: var(--primary-soft2); }
.btn-ok { background: var(--ok); color: white; }
.btn-ok:hover { filter: brightness(0.95); }
.btn-bad { background: var(--surface); color: var(--bad); border-color: color-mix(in oklch, var(--bad) 35%, var(--line)); }
.btn-bad:hover { background: var(--bad-soft); }
.btn-sm { height: 34px; padding: 0 12px; font-size: 13px; border-radius: var(--r-xs); }
.btn-icon { width: var(--control-h); padding: 0; }
.btn:disabled { opacity: 0.45; cursor: not-allowed; }

/* ---------- Cards ---------- */
.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
  box-shadow: var(--sh-1);
}
.card-pad { padding: var(--pad); }
.card-h {
  padding: 16px var(--pad);
  border-bottom: 1px solid var(--line-soft);
  display: flex; align-items: center; gap: 12px;
}
.card-title { font-weight: 700; font-size: 16px; letter-spacing: -0.01em; }

/* ---------- Badges / pills ---------- */
.badge {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 3px 10px; border-radius: var(--r-pill);
  font-size: 12px; font-weight: 700; line-height: 1.4;
  border: 1px solid transparent;
}
.badge .dot { width: 7px; height: 7px; border-radius: 999px; background: currentColor; }
.badge-ok   { background: var(--ok-soft); color: oklch(0.45 0.12 155); }
.badge-warn { background: var(--warn-soft); color: oklch(0.5 0.1 60); }
.badge-bad  { background: var(--bad-soft); color: oklch(0.48 0.15 25); }
.badge-info { background: var(--primary-soft); color: var(--primary-ink); }
.badge-neutral { background: var(--surface-2); color: var(--ink-2); border-color: var(--line); }

.chip {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 5px 11px; border-radius: var(--r-pill);
  font-size: 12.5px; font-weight: 600;
  background: var(--surface-2); color: var(--ink-2);
  border: 1px solid var(--line);
}

/* ---------- Forms ---------- */
.field { display: flex; flex-direction: column; gap: 7px; }
.label { font-weight: 700; font-size: 13.5px; color: var(--ink); }
.label .req { color: var(--bad); margin-left: 2px; }
.hint { font-size: 12.5px; color: var(--ink-3); }
.input, .textarea, .select {
  width: 100%;
  height: var(--control-h);
  padding: 0 13px;
  border-radius: var(--r-sm);
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--ink);
  font-size: 14px;
  transition: border-color .12s, box-shadow .12s;
  outline: none;
}
.textarea { height: auto; padding: 11px 13px; min-height: 84px; resize: vertical; line-height: 1.5; }
.input:focus, .textarea:focus, .select:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-soft);
}
.select {
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%23999' stroke-width='2.5' 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: right 12px center;
  padding-right: 36px;
  cursor: pointer;
}

/* ---------- Tables ---------- */
.tbl { width: 100%; border-collapse: collapse; }
.tbl th {
  text-align: left; font-size: 11.5px; font-weight: 700; letter-spacing: 0.04em;
  text-transform: uppercase; color: var(--ink-3);
  padding: 11px 16px; border-bottom: 1px solid var(--line);
}
.tbl td { padding: 13px 16px; border-bottom: 1px solid var(--line-soft); font-size: 14px; }
.tbl tr:last-child td { border-bottom: none; }
.tbl tbody tr { cursor: pointer; transition: background .1s; }
.tbl tbody tr:hover { background: var(--surface-2); }

/* ---------- Avatar ---------- */
.avatar {
  width: 34px; height: 34px; border-radius: 999px;
  display: grid; place-items: center;
  font-weight: 700; font-size: 13px; color: white;
  flex: none; letter-spacing: 0.02em;
}
.avatar-sm { width: 26px; height: 26px; font-size: 11px; }
.avatar-lg { width: 44px; height: 44px; font-size: 16px; }

/* ---------- Misc ---------- */
.mono { font-family: var(--mono); }
.muted { color: var(--ink-3); }
.page-title { font-family: var(--serif); font-size: 30px; font-weight: 500; letter-spacing: -0.018em; }
.page-sub { color: var(--ink-2); font-size: 14.5px; margin-top: 6px; }
.divider { height: 1px; background: var(--line-soft); border: none; margin: 0; }

.stat-num { font-family: var(--serif); font-size: 32px; font-weight: 500; letter-spacing: -0.02em; line-height: 1; }
.kbd {
  font-family: var(--mono); font-size: 11px; font-weight: 600;
  background: var(--surface-2); border: 1px solid var(--line);
  border-radius: 6px; padding: 1px 6px; color: var(--ink-2);
}

.seg {
  display: inline-flex; background: var(--surface-2);
  border: 1px solid var(--line); border-radius: var(--r-sm);
  padding: 3px;
}
.seg button {
  border: none; background: none; cursor: pointer;
  padding: 6px 13px; border-radius: 7px;
  font-weight: 700; font-size: 13px; color: var(--ink-2);
}
.seg button.on { background: var(--surface); color: var(--ink); box-shadow: var(--sh-1); }

@keyframes pop-in { from { transform: translateY(8px) scale(0.99); } to { transform: none; } }
@keyframes fade-in { from { transform: translateY(4px); } to { transform: none; } }
.pop-in { animation: pop-in .22s cubic-bezier(.2,.7,.3,1) both; }
.fade-in { animation: fade-in .2s ease both; }

/* Modal */
.scrim {
  position: fixed; inset: 0; background: oklch(0.3 0.02 285 / 0.4);
  backdrop-filter: blur(3px);
  display: grid; place-items: center; z-index: 50; padding: 24px;
  animation: fade-in .15s ease both;
}
.modal {
  background: var(--surface); border-radius: var(--r-xl);
  box-shadow: var(--sh-pop); width: 100%; max-width: 560px;
  max-height: 88vh; overflow: hidden; display: flex; flex-direction: column;
  animation: pop-in .2s cubic-bezier(.2,.7,.3,1) both;
}

/* Drag/drop builder states */
.dropzone { transition: background .12s, border-color .12s; }
.dropzone.over { background: var(--primary-soft); border-color: var(--primary) !important; }
.dragging { opacity: 0.4; }

/* Responsive */
@media (max-width: 880px) {
  .app {
    grid-template-columns: 1fr;
    grid-template-rows: 56px 1fr auto;
    grid-template-areas: "topbar" "main" "sidebar";
  }
  .brand-cell { display: none; }
  .sidebar {
    flex-direction: row; overflow-x: auto; padding: 8px;
    border-right: none; border-top: 1px solid var(--line); gap: 4px;
  }
  .nav-group-label { display: none; }
  .nav-item { flex-direction: column; gap: 3px; font-size: 10.5px; padding: 6px 10px; min-width: 64px; text-align: center; }
  .nav-item .count { position: absolute; }
  .main-inner { padding: 18px 16px 40px; }
}


  .rt-area:empty:before { content: attr(data-ph); color: var(--ink-3); }
  .rt-area h3 { font-size: 15px; margin: 6px 0; font-weight: 800; }
  .rt-area ul { margin: 6px 0; padding-left: 20px; }
  input[type="range"] { cursor: pointer; }

/* ============================================================
   Arabic / RTL overrides
   CSS Grid auto-flips columns when dir="rtl" — only directional
   borders, absolute offsets, and text-align need explicit fixes.
   ============================================================ */
[dir="rtl"] {
  font-family: "Segoe UI", "Tahoma", "Arial", var(--font);
}

[dir="rtl"] .brand-cell,
[dir="rtl"] .sidebar {
  border-right: none;
  border-left: 1px solid var(--line);
}

[dir="rtl"] .nav-item { text-align: right; }

[dir="rtl"] .topbar > div:last-child > div.pop-in,
[dir="rtl"] .pop-in[style*="right:0"] { right: auto !important; left: 0 !important; }

[dir="rtl"] .input { text-align: right; }
[dir="rtl"] .input[style*="padding-left:38px"] { padding-left: 14px !important; padding-right: 38px; }
[dir="rtl"] .input + span,
[dir="rtl"] [style*="left:13px"] { left: auto !important; right: 13px; }

[dir="rtl"] .tbl th,
[dir="rtl"] .tbl td { text-align: right; }
[dir="rtl"] .tbl td[style*="text-align:right"],
[dir="rtl"] .tbl th[style*="text-align:right"] { text-align: left !important; }

[dir="rtl"] .badge,
[dir="rtl"] .chip { direction: rtl; }

[dir="rtl"] [style*="margin-left:auto"] { margin-left: 0 !important; margin-right: auto; }

@media (max-width: 760px) {
  [dir="rtl"] .sidebar { border-left: none; }
}
