/* ============================================================
   Relay — Design System
   Friendly & approachable: rounded, soft colors, warm neutrals
   ============================================================ */

/* ---- self-hosted display faces ------------------------------------------
   The webfonts are also requested from Google in App.razor (which additionally
   supplies Cairo for Arabic), but the two Latin faces that carry the whole look
   are self-hosted so the app still renders as designed when the CDN is blocked
   — the same approach, and the same files, as the ERP reference project.
   Declared here rather than @import'ed: an @import at the top of a stylesheet
   is fetched only after this file arrives, which delays first paint. */
@font-face {
  font-family: 'Hanken Grotesk';
  font-style: normal;
  font-weight: 400 800;
  font-display: swap;
  src: url('/fonts/HankenGrotesk.woff2') format('woff2');
}
@font-face {
  font-family: 'Newsreader';
  font-style: normal;
  font-weight: 400 600;
  font-display: swap;
  src: url('/fonts/Newsreader.woff2') format('woff2');
}

: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;
  /* Arabic UI face — the Latin faces above carry no Arabic glyphs. */
  --font-ar: "Cairo", "Segoe UI", "Tahoma", "Arial", sans-serif;

  /* Focus ring — one token so every control rings identically. */
  --ring: 0 0 0 3px var(--primary-soft2);
}

[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-inline-end: 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-inline-end: 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: start; 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-inline-start: 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-inline-start: 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);
  background: var(--surface);
  box-shadow: var(--ring);
}

/* ---- currency entry -------------------------------------------------------
   A price field carries its currency so the number is never ambiguous, matching how a
   stored amount prints via Money(). The wrapper is deliberately LTR: a number input is
   already forced LTR in Arabic (see the RTL section), so its digits begin at the left
   edge in both languages, and an inline-start symbol therefore lands immediately before
   them rather than stranded at the far side of the field. The symbol is decoration, so
   it never swallows a click meant for the input. */
.money-field { position: relative; direction: ltr; }
.money-field > .input { padding-inline-start: 30px; }
.money-field > .money-sym {
  position: absolute; inset-inline-start: 12px; top: 0;
  height: var(--control-h);
  display: flex; align-items: center;
  color: var(--ink-3); font-weight: 600;
  pointer-events: none;
}

/* ---- keyboard focus -------------------------------------------------------
   Only inputs used to show a focus ring, so tabbing through buttons, chips,
   table rows and nav items gave no visible indication of position. :focus-visible
   keeps mouse clicks clean while restoring a clear keyboard affordance. */
.btn:focus-visible,
.chip:focus-visible,
.nav-item:focus-visible,
.seg button:focus-visible,
.tbl tbody tr:focus-visible,
button.card:focus-visible,
a:focus-visible,
[tabindex]:focus-visible {
  outline: none;
  box-shadow: var(--ring);
  border-radius: var(--r-sm);
}

/* Windows high-contrast mode ignores box-shadow — keep a real outline there. */
@media (forced-colors: active) {
  .btn:focus-visible,
  .chip:focus-visible,
  .nav-item:focus-visible,
  a:focus-visible,
  [tabindex]:focus-visible { outline: 2px solid Highlight; outline-offset: 2px; }
}
.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-inline-end: 36px;
  cursor: pointer;
}

/* ---------- Tables ---------- */
.tbl { width: 100%; border-collapse: collapse; }
.tbl th {
  text-align: start; 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; }

/* Toasts — transient notices at the top of the screen, above the modal layer. */
.toast-host {
  position: fixed; inset-block-start: 24px; inset-inline-end: 24px; z-index: 60;
  display: flex; flex-direction: column; align-items: flex-end; gap: 10px;
  pointer-events: none;
}
.toast {
  display: flex; align-items: center; gap: 10px;
  padding: 12px 16px; border-radius: var(--r-lg);
  box-shadow: var(--sh-pop);
  font-size: 14px; font-weight: 700;
  max-width: 360px;
}
.toast > svg { flex: none; }
/* Green for success, red for failure — same tokens as .badge-ok / .badge-bad. */
.toast-ok  { background: var(--ok-soft);  border: 1px solid var(--ok);  color: oklch(0.45 0.12 155); }
.toast-bad { background: var(--bad-soft); border: 1px solid var(--bad); color: oklch(0.48 0.15 25); }

/* 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 {
    /* minmax(0, …) rather than a bare 1fr: a 1fr track is floored at the min-content
       width of its items, so the top bar — whose labels do not wrap — was widening the
       single column past the viewport and scrolling the whole document sideways. This
       caps the track at the screen and lets the items shrink inside it instead. */
    grid-template-columns: minmax(0, 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-inline-end: 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; }

  /* A six- or seven-column table cannot fit a phone, so let it scroll inside its own
     card — the same treatment the bulk-upload table already carries inline. Without a
     container the widest row stretches the document instead, and a horizontally
     scrolling page hurts RTL more than LTR: the viewport opens at the left edge, which
     in Arabic is the *end* of every row, so a phone lands mid-sentence. Arabic runs
     longer than English at the same size, so it overflows further for the same data. */
  .card:has(.tbl) { overflow-x: auto; }
}


  .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-inline-start: 20px; }
  input[type="range"] { cursor: pointer; }

/* ============================================================
   Arabic / RTL
   Layout mirroring is handled by CSS logical properties in the
   base rules above (margin-inline / padding-inline / border-inline
   / text-align:start), so `dir="rtl"` flips everything on its own.
   Only genuinely direction-specific things live here: the Arabic
   font stack, bidi isolation for mixed content, and mirroring of
   directional glyphs.
   ============================================================ */
/* `dir` sits on <html>, but the base rule sets font-family on <body> too, so
   body must be targeted explicitly or it keeps the Latin-only stack.
   Cairo is a purpose-built Arabic face (same one the ERP project uses); the
   previous Segoe UI / Tahoma stack was a generic system fallback and read as
   noticeably less finished than the Latin side. */
[dir="rtl"],
[dir="rtl"] body {
  font-family: var(--font-ar);
}

/* Serif display face has no Arabic coverage, so headings would drop to an
   unrelated fallback — give them the Arabic face at a heavier weight instead,
   which preserves the display/body contrast the Latin design relies on. */
[dir="rtl"] .page-title,
[dir="rtl"] .brand-name,
[dir="rtl"] .stat-num { font-family: var(--font-ar); font-weight: 700; }

/* Mixed Arabic/English: isolate runs whose internal direction is always
   LTR (money, codes, IDs, numbers) so the surrounding RTL text cannot
   reorder them — this is what stops "$1,200" becoming "1,200$". */
.mono,
.stat-num,
.num,
.kbd { unicode-bidi: isolate; }

/* Tabular figures so amounts stack in a straight column instead of jittering
   with each digit's natural width — the same treatment ERP gives its money and
   numeric cells. Applies to both languages. */
.stat-num,
.num,
.mono,
.tbl td .num,
.cellmoney { font-variant-numeric: tabular-nums; font-feature-settings: "tnum" 1; }

/* Directional glyphs must point the other way in RTL. */
[dir="rtl"] .icon-dir { transform: scaleX(-1); }

/* Native controls that don't inherit logical padding for their own chrome. */
[dir="rtl"] .select { background-position: left 12px center; }

/* Numbers, dates and times are always entered left-to-right, even in Arabic.
   Without this the caret jumps and "2026-06-01" renders reversed. */
[dir="rtl"] input[type="number"],
[dir="rtl"] input[type="date"],
[dir="rtl"] input[type="time"],
[dir="rtl"] input[type="range"] { direction: ltr; text-align: start; }

/* Free-text fields carry dir="auto" in markup so the first strong character
   decides alignment — an Arabic answer aligns right, an English one left. */

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