/* ============================================================
   WorkFlow — Design System
   Cool gray-green palette with teal accent, dark sidebar.
   Typography: Space Grotesk (display), IBM Plex Sans (body),
   IBM Plex Mono (data/labels). Fonts loaded from Google in
   App.razor; Cairo carries Arabic.
   ============================================================ */

:root {
  /* Cool gray-green ramp */
  --bg:        #F2F5F4;
  --bg-sunk:   #EDF2F1;
  --surface:   #FFFFFF;
  --surface-2: #F7FAF9;
  --line:      #DDE6E4;
  --line-soft: #EDF2F1;

  --ink:       #0F1F1C;
  --ink-2:     #4E605C;
  --ink-3:     #7C8C89;

  /* Primary — teal */
  --primary:      #0D9488;
  --primary-ink:  #0A6E63;
  --primary-soft: #DDF3EF;
  --primary-soft2: rgba(13,148,136,.15);
  --on-primary:   #FFFFFF;

  /* Secondary accent — cool blue, used sparingly */
  --accent:      #3B82F6;
  --accent-soft: #DBEAFE;

  /* Semantic */
  --ok:        #15803D;
  --ok-soft:   #DCFCE7;
  --warn:      #A16207;
  --warn-soft: #FEF9C3;
  --bad:       #DC2626;
  --bad-soft:  #FEE2E2;
  --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 */
  --sh-1: 0 1px 2px rgba(15,31,28,.05);
  --sh-2: 0 2px 4px rgba(15,31,28,.04), 0 6px 16px rgba(15,31,28,.07);
  --sh-3: 0 8px 24px rgba(15,31,28,.09), 0 2px 6px rgba(15,31,28,.05);
  --sh-pop: 0 16px 44px rgba(15,31,28,.16);

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

  --font: "IBM Plex Sans", ui-sans-serif, system-ui, sans-serif;
  --display: "Space Grotesk", ui-sans-serif, system-ui, sans-serif;
  --mono: "IBM Plex Mono", ui-monospace, monospace;
  /* Arabic UI face */
  --font-ar: "Cairo", "Segoe UI", "Tahoma", "Arial", sans-serif;

  /* Dark sidebar tokens */
  --sidebar-bg: #0F1F1C;
  --sidebar-ink: rgba(255,255,255,.85);
  --sidebar-ink-2: rgba(255,255,255,.6);
  --sidebar-ink-3: #628A83;
  --sidebar-hover: rgba(255,255,255,.08);
  --sidebar-active: rgba(13,148,136,.18);
  --sidebar-line: rgba(255,255,255,.06);

  /* Focus ring */
  --ring: 0 0 0 3px rgba(13,148,136,.25);
}

[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-soft); }

/* Scrollbars */
*::-webkit-scrollbar { width: 11px; height: 11px; }
*::-webkit-scrollbar-thumb {
  background: #C5CDCB;
  border-radius: 999px;
  border: 3px solid transparent;
  background-clip: padding-box;
}
*::-webkit-scrollbar-thumb:hover { background: #A8B2AF; 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(--sidebar-line);
  border-bottom: 1px solid var(--sidebar-line);
  background: var(--sidebar-bg);
  color: #FFFFFF;
}
.brand-mark {
  width: 32px; height: 32px;
  border-radius: 9px;
  background: linear-gradient(135deg, #0D9488, #5EBFA8);
  display: grid; place-items: center;
  color: #FFFFFF;
  box-shadow: 0 2px 8px rgba(13,148,136,.35);
  flex: none;
}
.brand-name { font-family: var(--display); font-weight: 700; font-size: 18px; letter-spacing: -0.01em; white-space: nowrap; color: #FFFFFF; }
.brand-sub { font-size: 11px; color: var(--sidebar-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: rgba(255,255,255,.85);
  backdrop-filter: blur(10px);
}

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

/* Dark sidebar scrollbar */
.sidebar::-webkit-scrollbar-thumb {
  background: rgba(255,255,255,.15);
}
.sidebar::-webkit-scrollbar-thumb:hover {
  background: rgba(255,255,255,.25);
}

.main {
  grid-area: main;
  overflow-y: auto;
  background: var(--bg);
  min-width: 0;
}
.main-inner { max-width: 1120px; margin: 0 auto; padding: 24px clamp(14px,3vw,28px) 70px; }
.main-inner.wide { max-width: 100%; }

/* ---------- Nav ---------- */
.nav-group-label {
  font-family: var(--mono);
  font-size: 9.5px; font-weight: 600; letter-spacing: 0.14em;
  text-transform: uppercase; color: var(--sidebar-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(--sidebar-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(--sidebar-hover); color: var(--sidebar-ink); }
.nav-item.active { background: var(--sidebar-active); color: #FFFFFF; }
.nav-item.active svg { color: #0D9488; }
.nav-item svg { color: var(--sidebar-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: 0 4px 12px rgba(13,148,136,.3); }
.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: #F5BEBE; }
.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-md);
  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-family: var(--display); 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: #15803D; }
.badge-warn { background: var(--warn-soft); color: #A16207; }
.badge-bad  { background: var(--bad-soft); color: #DC2626; }
.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 ---- */
.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 ---- */
.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);
}

@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='%237C8C89' 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-family: var(--mono); font-size: 11px; font-weight: 600; letter-spacing: 0.06em;
  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(--display); font-size: 30px; font-weight: 700; 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(--display); font-size: 32px; font-weight: 700; 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 */
.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; }
.toast-ok  { background: var(--ok-soft);  border: 1px solid var(--ok);  color: #15803D; }
.toast-bad { background: var(--bad-soft); border: 1px solid var(--bad); color: #DC2626; }
.toast-warn { background: var(--warn-soft); border: 1px solid var(--warn); color: #A16207; }

/* Modal */
.scrim {
  position: fixed; inset: 0; background: rgba(15,31,28,.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: 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(--sidebar-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; }

  .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
   ============================================================ */
[dir="rtl"],
[dir="rtl"] body {
  font-family: var(--font-ar);
}

[dir="rtl"] .page-title,
[dir="rtl"] .brand-name,
[dir="rtl"] .stat-num { font-family: var(--font-ar); font-weight: 700; }

.mono,
.stat-num,
.num,
.kbd { unicode-bidi: isolate; }

.stat-num,
.num,
.mono,
.tbl td .num,
.cellmoney { font-variant-numeric: tabular-nums; font-feature-settings: "tnum" 1; }

[dir="rtl"] .icon-dir { transform: scaleX(-1); }

[dir="rtl"] .select { background-position: left 12px center; }

[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; }

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