/* ══════════════════════════════════════════════════════════════════════════
   base.css — reset, Arabic typography, and shared primitives.
   RTL-native: logical properties only. No `left`/`right` anywhere.
   ══════════════════════════════════════════════════════════════════════════ */

*,
*::before,
*::after { box-sizing: border-box; }

* { margin: 0; padding: 0; }

html { -webkit-text-size-adjust: 100%; }

/* Component `display` rules otherwise win over the UA sheet's [hidden]. */
[hidden] { display: none !important; }

html,
body { block-size: 100%; }

body {
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font-ar);
  font-size: var(--fs-base);
  line-height: var(--lh-body);
  font-weight: var(--fw-normal);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
  font-feature-settings: "kern" 1;
  overflow: hidden;
}

h1, h2, h3, h4 {
  line-height: var(--lh-tight);
  font-weight: var(--fw-semi);
  letter-spacing: -0.005em;
}

h1 { font-size: var(--fs-2xl); }
h2 { font-size: var(--fs-xl); }
h3 { font-size: var(--fs-lg); }
h4 { font-size: var(--fs-base); }

button,
input,
textarea,
select {
  font: inherit;
  color: inherit;
  background: none;
  border: none;
}

button { cursor: pointer; }
button:disabled { cursor: not-allowed; }
textarea { resize: none; }

/* Latin runs inside Arabic must be isolated or the whole line reorders. */
.latin,
.mono {
  direction: ltr;
  unicode-bidi: isolate;
}

.mono {
  font-family: var(--font-mono);
  font-size: 0.92em;
  font-variant-ligatures: none;
}

/* Numerals in tables and scores stay Latin and tabular so columns align. */
.num {
  font-variant-numeric: tabular-nums;
  direction: ltr;
  unicode-bidi: isolate;
}

.icon {
  inline-size: 1em;
  block-size: 1em;
  flex: none;
  vertical-align: -0.125em;
}

/* ── focus ────────────────────────────────────────────────────────────────
   Never removed. A visible ring on every interactive element. */
:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: var(--r-xs);
}

:focus:not(:focus-visible) { outline: none; }

/* ── screen-reader only ──────────────────────────────────────────────────── */
.sr-only {
  position: absolute;
  inline-size: 1px;
  block-size: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
  border: 0;
}

.skip-link {
  position: absolute;
  inset-block-start: -100%;
  inset-inline-start: var(--space-4);
  z-index: var(--z-toast);
  padding: var(--space-2) var(--space-4);
  background: var(--surface);
  color: var(--ink);
  border: 1px solid var(--line-2);
  border-radius: var(--r-sm);
  box-shadow: var(--sh-2);
}

.skip-link:focus { inset-block-start: var(--space-4); }

/* ── scrollbars ──────────────────────────────────────────────────────────── */
.scroll {
  overflow-y: auto;
  overscroll-behavior: contain;
  scrollbar-width: thin;
  scrollbar-color: var(--line-2) transparent;
}

.scroll::-webkit-scrollbar { inline-size: 10px; }
.scroll::-webkit-scrollbar-track { background: transparent; }

.scroll::-webkit-scrollbar-thumb {
  background: var(--line-2);
  border-radius: var(--r-full);
  border: 3px solid var(--bg);
}

/* ── shared primitives ───────────────────────────────────────────────────── */

.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
  box-shadow: var(--sh-1);
}

.chip {
  display: inline-flex;
  align-items: center;
  gap: var(--space-1);
  padding-block: 2px;
  padding-inline: var(--space-2);
  border-radius: var(--r-full);
  font-size: var(--fs-xs);
  line-height: 1.6;
  white-space: nowrap;
}

/* Tool chips stay English, monospace, LTR — inside an RTL line (§4.3). */
.tool-chip {
  background: var(--surface-2);
  border: 1px solid var(--line);
  color: var(--ink-2);
  font-family: var(--font-mono);
  font-size: var(--fs-2xs);
  direction: ltr;
  unicode-bidi: isolate;
  padding-block: 1px;
  padding-inline: var(--space-2);
  border-radius: var(--r-xs);
}

/* Node IDs — the jury cross-checks these against the n8n canvas. */
.node-id {
  font-family: var(--font-mono);
  font-size: var(--fs-2xs);
  color: var(--ink-3);
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: var(--r-xs);
  padding-block: 1px;
  padding-inline: 5px;
  direction: ltr;
  unicode-bidi: isolate;
  letter-spacing: 0.02em;
  flex: none;
}

/* ── buttons ─────────────────────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  min-block-size: 44px;              /* touch target floor */
  padding-block: var(--space-2);
  padding-inline: var(--space-4);
  border-radius: var(--r-md);
  border: 1px solid var(--line-2);
  background: var(--surface);
  color: var(--ink);
  font-size: var(--fs-md);
  font-weight: var(--fw-medium);
  transition: background var(--dur-fast) var(--ease-out),
              border-color var(--dur-fast) var(--ease-out),
              transform var(--dur-fast) var(--ease-out);
}

.btn:hover:not(:disabled) { background: var(--surface-2); }
.btn:active:not(:disabled) { transform: translateY(1px); }
.btn:disabled { opacity: 0.45; }

.btn-primary {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--on-accent);
}

.btn-primary:hover:not(:disabled) {
  background: var(--accent-ink);
  border-color: var(--accent-ink);
  color: var(--on-accent);
}

.btn-danger {
  color: var(--crit);
  border-color: color-mix(in srgb, var(--crit) 35%, var(--line-2));
}

.btn-danger:hover:not(:disabled) { background: var(--crit-soft); }

.btn-quiet {
  min-block-size: 36px;
  border-color: transparent;
  background: transparent;
  color: var(--ink-2);
  font-size: var(--fs-sm);
}

.btn-quiet:hover:not(:disabled) { background: var(--surface-2); color: var(--ink); }

.btn-icon {
  min-block-size: 36px;
  inline-size: 36px;
  padding: 0;
  border-color: transparent;
  background: transparent;
  color: var(--ink-2);
}

.btn-icon:hover:not(:disabled) { background: var(--surface-2); color: var(--ink); }
.btn-icon .icon { font-size: 17px; }

/* ── status pills — colour is always paired with a glyph + word ─────────── */
.pill {
  display: inline-flex;
  align-items: center;
  gap: var(--space-1);
  padding-block: 2px;
  padding-inline: var(--space-2);
  border-radius: var(--r-full);
  font-size: var(--fs-xs);
  font-weight: var(--fw-medium);
  border: 1px solid transparent;
}

.pill-ok   { background: var(--ok-soft);   color: var(--ok);   border-color: color-mix(in srgb, var(--ok) 22%, transparent); }
.pill-warn { background: var(--warn-soft); color: var(--warn); border-color: color-mix(in srgb, var(--warn) 25%, transparent); }
.pill-crit { background: var(--crit-soft); color: var(--crit); border-color: color-mix(in srgb, var(--crit) 25%, transparent); }
.pill-mute { background: var(--surface-2); color: var(--ink-2); border-color: var(--line); }

/* ── motion — subtle tier; disabled wholesale under reduced-motion ─────── */
@keyframes rise {
  from { opacity: 0; transform: translateY(8px); }
  to   { opacity: 1; transform: none; }
}

@keyframes fade {
  from { opacity: 0; }
  to   { opacity: 1; }
}

.rise { animation: rise var(--dur-slow) var(--ease-out) both; }
.fade { animation: fade var(--dur-mid) var(--ease-out) both; }

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 1ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 1ms !important;
    scroll-behavior: auto !important;
  }
}
