/* ==========================================================================
   Base: reset, typography, shell layout (top bar + side rail + outlet), RTL.
   Only logical properties (inline-start/end) so Arabic mirrors for free.
   ========================================================================== */

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }
body {
  margin: 0;
  font-family: var(--font);
  font-size: var(--fs);
  line-height: 1.45;
  color: var(--ink);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  overflow-x: hidden;
}
img, svg { display: block; max-width: 100%; }
svg.ic { width: 16px; height: 16px; flex: none; }
kbd { white-space: nowrap; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
a { color: var(--primary-strong); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3, h4 { margin: 0; line-height: 1.25; font-weight: 700; letter-spacing: -.01em; }
h1 { font-size: var(--fs-2xl); }
h2 { font-size: var(--fs-xl); }
h3 { font-size: var(--fs-lg); }
h4 { font-size: var(--fs-md); }
p { margin: 0; }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; border-radius: 6px; }
::selection { background: var(--teal-200); color: var(--navy-800); }
.num, .money, td.n, th.n { font-variant-numeric: tabular-nums; }
/* Codes, numbers and IBANs keep LTR inside Arabic text */
.ltr { direction: ltr; unicode-bidi: isolate; display: inline-block; }
.muted { color: var(--ink-3); }
.soft { color: var(--ink-2); }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }
[hidden] { display: none !important; }

/* Arabic reads better slightly larger and with more line height */
html[lang="ar"] body { font-size: 13.5px; line-height: 1.55; }
html[lang="ar"] h1, html[lang="ar"] h2, html[lang="ar"] h3 { letter-spacing: 0; }

/* ---------- Shell ---------- */
.app {
  min-height: 100vh;
  display: grid;
  grid-template-columns: var(--rail-w) minmax(0, 1fr);
  grid-template-rows: var(--topbar-h) minmax(0, 1fr);
  grid-template-areas: "top top" "rail main";
}
.app.rail-collapsed { grid-template-columns: var(--rail-w-collapsed) minmax(0, 1fr); }

/* Top bar (brand navy) */
.topbar {
  grid-area: top;
  position: sticky; top: 0; z-index: 40;
  display: flex; align-items: center; gap: 12px;
  padding-inline: 12px 16px;
  background: var(--brand-navy);
  color: var(--ink-inverse);
  box-shadow: 0 1px 0 rgba(255,255,255,.06), 0 6px 18px rgba(10,23,29,.18);
}
.topbar .brand { display: flex; align-items: center; gap: 10px; min-width: 0; padding-inline-end: 8px; }
.topbar .brand img { height: 30px; width: auto; }
.topbar .brand.plate img { height: 32px; background: #fff; border-radius: 9px; padding: 3px 8px; }
.topbar .brand .product {
  font-size: 12px; font-weight: 600; color: #9fd5d7; letter-spacing: .04em;
  padding: 3px 8px; border: 1px solid rgba(159,213,215,.35); border-radius: 999px; white-space: nowrap;
}
.topbar .icon-btn { color: #d7e6ea; }
.topbar .icon-btn:hover { background: rgba(255,255,255,.08); color: #fff; }
.topbar .spacer { flex: 1; }

.search-trigger {
  flex: 0 1 460px; min-width: 0;
  display: flex; align-items: center; gap: 10px;
  height: 32px; padding-inline: 12px;
  border-radius: 8px;
  border: 1px solid rgba(255,255,255,.14);
  background: rgba(255,255,255,.07);
  color: #c4d6dc; text-align: start;
  transition: background .15s var(--ease), border-color .15s var(--ease);
}
.search-trigger:hover { background: rgba(255,255,255,.11); border-color: rgba(255,255,255,.24); }
.search-trigger svg { width: 18px; height: 18px; }
.search-trigger span { flex: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.search-trigger kbd { background: rgba(255,255,255,.12); color: #e6f1f3; border-color: transparent; }

.top-chip {
  display: inline-flex; align-items: center; gap: 6px;
  height: 32px; padding-inline: 10px; border-radius: 8px;
  background: transparent; border: 1px solid rgba(255,255,255,.14); color: #e6f1f3; white-space: nowrap;
}
.top-chip:hover { background: rgba(255,255,255,.08); }
.lang-toggle { font-weight: 700; min-width: 44px; justify-content: center; }
.role-chip { padding-inline: 4px 10px; gap: 8px; }
.role-chip .avatar { width: 28px; height: 28px; font-size: 12px; }
.role-chip .who { display: flex; flex-direction: column; line-height: 1.15; text-align: start; }
.role-chip .who b { font-size: 13px; }
.role-chip .who small { font-size: 11px; color: #9fd5d7; }
.bell { position: relative; }
.bell .dot {
  position: absolute; inset-block-start: 6px; inset-inline-end: 6px;
  min-width: 16px; height: 16px; padding-inline: 4px; border-radius: 999px;
  background: var(--brand-red); color: #fff; font-size: 10px; font-weight: 700; line-height: 16px; text-align: center;
  box-shadow: 0 0 0 2px var(--brand-navy);
}

/* Side rail */
.rail {
  grid-area: rail;
  position: sticky; top: var(--topbar-h);
  height: calc(100vh - var(--topbar-h));
  overflow-y: auto; overflow-x: hidden;
  background: var(--surface);
  border-inline-end: 1px solid var(--line);
  padding: 10px 8px 14px;
  display: flex; flex-direction: column; gap: 4px;
  scrollbar-width: thin;
}
.rail .group-label {
  font-size: 11px; font-weight: 700; color: var(--ink-3); text-transform: uppercase; letter-spacing: .06em;
  padding: 10px 10px 4px;
}
html[lang="ar"] .rail .group-label { text-transform: none; letter-spacing: 0; font-size: 12px; }
.nav-item {
  display: flex; align-items: center; gap: 12px;
  min-height: 34px; padding: 6px 12px; border-radius: 9px;
  color: var(--ink-2); font-weight: 500; line-height: 1.3;
  border: 0; background: transparent; width: 100%; text-align: start;
  position: relative;
}
.nav-item:hover { background: var(--surface-3); color: var(--ink); text-decoration: none; }
.nav-item .ico { flex: none; width: 20px; height: 20px; }
.nav-item .label { flex: 1; min-width: 0; overflow-wrap: anywhere; } /* long names wrap to a second line instead of being cut */
.nav-item .kbd-hint { font-size: 11px; color: var(--ink-3); font-family: var(--font-mono); }
.nav-item .count {
  min-width: 22px; height: 20px; padding-inline: 6px; border-radius: 999px;
  background: var(--accent-soft); color: var(--critical); font-size: 11px; font-weight: 700; line-height: 20px; text-align: center;
}
.nav-item[aria-current="page"] { background: var(--primary-soft); color: var(--primary-strong); font-weight: 600; }
.nav-item[aria-current="page"]::before {
  content: ""; position: absolute; inset-inline-start: -10px; inset-block: 8px; width: 4px; border-radius: 0 4px 4px 0;
  background: var(--primary);
}
html[dir="rtl"] .nav-item[aria-current="page"]::before { border-radius: 4px 0 0 4px; }
.rail .rail-foot { margin-top: auto; padding: 12px; border-top: 1px solid var(--line); display: grid; gap: 8px; }
.rail .rail-foot img { height: 30px; width: auto; opacity: .9; margin-inline-start: 8px; }
.rail .rail-foot .btn { justify-content: flex-start; }
.app.rail-collapsed .rail .label,
.app.rail-collapsed .rail .kbd-hint,
.app.rail-collapsed .rail .group-label,
.app.rail-collapsed .rail .rail-foot { display: none; }
.app.rail-collapsed .nav-item { justify-content: center; padding: 0; height: 34px; }
.app.rail-collapsed .nav-item .count { position: absolute; inset-block-start: 2px; inset-inline-end: 6px; min-width: 16px; height: 16px; line-height: 16px; font-size: 10px; padding-inline: 3px; }

/* Main outlet */
.main { grid-area: main; min-width: 0; padding: var(--gutter); padding-bottom: 96px; }
.page { max-width: 1600px; margin-inline: auto; animation: page-in .28s var(--ease); }
@keyframes page-in { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }
@media (prefers-reduced-motion: reduce) { *, *::before, *::after { animation: none !important; transition: none !important; } }

.page-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-bottom: 12px; }
.page-head .titles { min-width: 0; flex: 1 1 420px; }
.page-head .eyebrow { font-size: 11.5px; font-weight: 600; color: var(--primary-strong); margin-bottom: 2px; display: flex; gap: 6px; align-items: center; }
.page-head p { color: var(--ink-3); margin-top: 2px; max-width: 90ch; font-size: 12.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.page-head .actions { display: flex; gap: 8px; flex-wrap: wrap; }

/* Mobile bottom bar */
.tabbar { display: none; }

/* Demo ribbon (this is a simulation) — lives in the top bar */
.demo-ribbon {
  display: flex; align-items: center; gap: 8px;
  padding: 6px 10px; border-radius: 999px;
  background: rgba(255,255,255,.06); border: 1px dashed rgba(255,255,255,.22);
  font-size: 12px; color: #c4d6dc; white-space: nowrap;
}
.demo-ribbon .pulse { width: 8px; height: 8px; border-radius: 50%; background: var(--warning); box-shadow: 0 0 0 3px var(--warning-soft); }
.demo-ribbon button { border: 0; background: none; color: #7fd3d6; font-weight: 700; padding: 0 4px; }

/* ---------- Responsive shell ---------- */
@media (max-width: 1180px) {
  .demo-ribbon .txt { display: none; }
  .app { grid-template-columns: var(--rail-w-collapsed) minmax(0, 1fr); }
  .app .rail .label, .app .rail .kbd-hint, .app .rail .group-label, .app .rail .rail-foot { display: none; }
  .app .nav-item { justify-content: center; padding: 0; height: 34px; }
  .app .nav-item .count { position: absolute; inset-block-start: 2px; inset-inline-end: 6px; min-width: 16px; height: 16px; line-height: 16px; font-size: 10px; padding-inline: 3px; }
  .role-chip .who { display: none; }
}
@media (max-width: 760px) {
  :root { --gutter: 16px; --topbar-h: 56px; }
  .app { grid-template-columns: minmax(0, 1fr); grid-template-areas: "top" "main"; }
  .rail { display: none; }
  .topbar .brand .product, .top-chip.date-chip, .theme-btn, .topbar .collapse-btn { display: none; }
  .topbar .brand img { height: 28px; }
  .search-trigger { flex: 1; }
  .search-trigger span, .search-trigger kbd { display: none; }
  .search-trigger { flex: 0 0 38px; justify-content: center; padding: 0; }
  .topbar .spacer { flex: 1; }
  .tabbar {
    display: grid; grid-template-columns: repeat(5, 1fr);
    position: fixed; inset-inline: 0; inset-block-end: 0; z-index: 45;
    background: var(--surface); border-top: 1px solid var(--line);
    padding: 6px 6px calc(6px + env(safe-area-inset-bottom));
    box-shadow: 0 -6px 18px rgba(16,34,42,.08);
  }
  .tabbar a { display: flex; flex-direction: column; align-items: center; gap: 2px; font-size: 11px; color: var(--ink-3); padding: 4px 0; border-radius: 10px; }
  .tabbar a svg { width: 22px; height: 22px; }
  .tabbar a[aria-current="page"] { color: var(--primary-strong); background: var(--primary-soft); }
  .tabbar a.fab { justify-self: center; width: 54px; height: 54px; justify-content: center; color: #fff; background: var(--brand-teal); margin-block-start: -22px; border-radius: 50%; box-shadow: 0 8px 20px rgba(25,134,139,.4), 0 0 0 4px var(--surface); padding: 0; }
  .demo-ribbon { display: none; }
  .main { padding-bottom: 120px; }
}

/* ---------- Print ---------- */
@media print {
  body { background: #fff; }
  .topbar, .rail, .tabbar, .demo-ribbon, .no-print, .toast-stack { display: none !important; }
  .app { display: block; }
  .main { padding: 0; }
}
