/* Base: reset, typography hierarchy, RTL/bidi, focus. */
:root {
  /* Legacy aliases — older views still reference these in inline styles. */
  --blue: var(--accent); --green: var(--success); --amber: var(--warning); --red: var(--danger);
  --muted: var(--text-3); --line: var(--border); --card: var(--surface); --nav: var(--nav-bg); --nav2: var(--nav-bg);
}

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font-family: var(--font); font-size: var(--fs-body); line-height: var(--lh);
  -webkit-font-smoothing: antialiased; -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
}
img, svg { vertical-align: middle; }
a { color: inherit; text-decoration: none; }
.content a:not(.btn):not(.tab):not(.card):not(.nav-item):not(.chip) { color: var(--accent-text); }
.content a:not(.btn):not(.tab):not(.card):not(.nav-item):not(.chip):hover { text-decoration: underline; text-underline-offset: 3px; }
.content table a:not(.btn) { color: var(--text); font-weight: 500; }
.content table a:not(.btn):hover { color: var(--accent-text); }
button, input, select, textarea { font: inherit; color: inherit; }
hr { border: 0; border-top: 1px solid var(--border); margin: var(--sp-4) 0; }
::selection { background: var(--accent-soft); }

/* Headings — one scale for the whole system */
h1, h2, h3, h4 { color: var(--text); line-height: 1.35; letter-spacing: 0; }
.content h1 { font-size: var(--fs-page); font-weight: 700; margin: 0 0 var(--sp-1); }
.content h2 { font-size: var(--fs-card); font-weight: 600; margin: 0 0 var(--sp-3); }
.content h3 { font-size: var(--fs-body); font-weight: 600; margin: 0 0 var(--sp-2); }
.content p { margin: 0 0 var(--sp-3); }
b, strong { font-weight: 600; }

/* Text roles */
.muted { color: var(--text-3); }
.text-2, .secondary-text { color: var(--text-2); font-size: var(--fs-secondary); }
.helper, .small, .muted small { font-size: var(--fs-helper); color: var(--text-3); }
small { font-size: var(--fs-helper); }
.overline { font-size: var(--fs-micro); font-weight: 600; letter-spacing: .06em; text-transform: uppercase; color: var(--text-3); }

/* Numbers, codes and Latin terms inside RTL */
.num, .kpi strong, td.num, .stat-value { font-variant-numeric: tabular-nums; }
.code, code, .hash { font-family: var(--font-mono); font-size: 12.5px; }
.code { background: var(--surface-3); border: 1px solid var(--border); border-radius: var(--r-sm); padding: 6px 10px; letter-spacing: .08em; direction: ltr; unicode-bidi: isolate; display: inline-block; }
.hash { max-width: 150px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; direction: ltr; display: inline-block; }
.ltr { direction: ltr; unicode-bidi: isolate; }
bdi, .bdi { unicode-bidi: isolate; }
input[type=email], input[type=url], input[type=tel], input[name=email], input[type=password] { direction: ltr; text-align: right; }
input[type=email]:placeholder-shown, input[name=email]:placeholder-shown { direction: rtl; }

/* Focus — visible for keyboard users, quiet for mouse users */
:focus { outline: none; }
:focus-visible { outline: none; box-shadow: var(--focus-ring); border-radius: var(--r-sm); }

/* Scrollbars */
* { scrollbar-width: thin; scrollbar-color: var(--border-strong) transparent; }
*::-webkit-scrollbar { width: 10px; height: 10px; }
*::-webkit-scrollbar-thumb { background: var(--border-strong); border-radius: 10px; border: 3px solid transparent; background-clip: padding-box; }
*::-webkit-scrollbar-track { background: transparent; }

[hidden] { display: none !important; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0, 0, 0, 0); border: 0; }

/* Icons from /public/ui/icons.svg */
.i { width: 18px; height: 18px; flex: 0 0 auto; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.i.sm { width: 16px; height: 16px; }
.i.lg { width: 22px; height: 22px; }
/* Directional icons point the reading direction in RTL */
.i.flip { transform: scaleX(-1); }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition-duration: .01ms !important; animation-duration: .01ms !important; }
}

/* Mixed Arabic/English: each label/cell/value takes its direction from its own content, so English
   labels, dates ("17/10/2026, 15:48") and codes read correctly, while alignment stays RTL. */
.field label, td, th, .kv dd, .kv dt, .settings-card p, .meta-strip b, .chip, .helper, .comment .meta, .timeline small, .activityItem small, .who-text small, .sidebar-user small, .menu-head small {
  unicode-bidi: plaintext; text-align: right;
}
