/* CIYAJ components — framework-agnostic classes (cj-*). Load after tokens.css.
   Layout uses logical properties, so every component mirrors under dir="rtl". */
*, *::before, *::after { box-sizing: border-box; }
body { margin: 0; font-family: var(--font-sans); font-size: 14px; line-height: 22px; background: var(--surface); color: var(--ink); -webkit-font-smoothing: antialiased; }
:lang(ar), [dir="rtl"] { font-family: var(--font-arabic); }
.cj-key, .cj-mono { font-family: var(--font-mono); font-size: 13px; line-height: 20px; font-variant-numeric: tabular-nums; }
.cj-key { font-weight: 500; color: var(--ink); direction: ltr; unicode-bidi: isolate; }
.cj-num { font-variant-numeric: tabular-nums; }
.cj-muted { color: var(--ink-muted); }
.cj-row { display: flex; flex-wrap: wrap; gap: var(--space-3); align-items: center; padding: var(--space-5); }
.cj-stack { display: grid; gap: var(--space-4); padding: var(--space-5); }
.cj-sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* Focus — one ring everywhere on content surfaces */
.cj-btn:focus-visible, .cj-input:focus-visible, .cj-select:focus-visible, .cj-tab:focus-visible,
.cj-tag__remove:focus-visible, .cj-check input:focus-visible + span, .cj-table tbody tr:focus-visible {
  outline: 2px solid transparent; box-shadow: var(--focus-ring);
}

/* ---------- Button ---------- */
.cj-btn { display: inline-flex; align-items: center; justify-content: center; gap: var(--space-2); height: var(--control-md);
  padding-inline: var(--space-4); border-radius: var(--radius-md); border: 1px solid transparent; font: inherit;
  font-size: 13px; line-height: 18px; font-weight: 600; cursor: pointer; white-space: nowrap; text-decoration: none;
  transition: background-color .12s ease-out, border-color .12s ease-out; }
.cj-btn svg { width: var(--icon-sm); height: var(--icon-sm); flex: none; }
.cj-btn--primary { background: var(--action); color: var(--on-action); }
.cj-btn--primary:hover { background: var(--action-hover); }
.cj-btn--secondary { background: var(--surface-raised); color: var(--ink); border-color: var(--line-strong); }
.cj-btn--secondary:hover { background: var(--surface-sunken); }
.cj-btn--quiet { background: transparent; color: var(--ink); }
.cj-btn--quiet:hover { background: var(--surface-sunken); }
.cj-btn--danger { background: var(--status-not-implemented-ink); color: var(--on-action); }
.cj-btn--danger:hover { background: var(--status-not-implemented); }
.cj-btn--sm { height: var(--control-sm); padding-inline: var(--space-3); font-size: 12px; }
.cj-btn--lg { height: var(--control-lg); padding-inline: var(--space-5); font-size: 14px; }
.cj-btn--icon { width: var(--control-md); padding: 0; }
.cj-btn[disabled], .cj-btn[aria-disabled="true"] { background: var(--surface-sunken); color: var(--ink-subtle); border-color: var(--line); cursor: not-allowed; }

/* ---------- Status badge + glyphs ---------- */
.cj-status { display: inline-flex; align-items: center; gap: var(--space-1); height: 24px; padding-inline: 6px 10px;
  border-radius: var(--radius-full); font-size: 12px; line-height: 16px; font-weight: 600; white-space: nowrap; }
.cj-status svg, .cj-glyph { width: 14px; height: 14px; flex: none; }
.cj-status--implemented { background: var(--status-implemented-soft); color: var(--status-implemented-ink); }
.cj-status--partial { background: var(--status-partial-soft); color: var(--status-partial-ink); }
.cj-status--not-implemented { background: var(--status-not-implemented-soft); color: var(--status-not-implemented-ink); }
.cj-status--not-applicable { background: var(--status-not-applicable-soft); color: var(--status-not-applicable-ink); }
.cj-status--not-assessed { background: transparent; color: var(--ink-muted); box-shadow: inset 0 0 0 1px var(--line); }
.cj-status--review { background: var(--info-soft); color: var(--info-ink); }
.cj-status--band-substantial { background: var(--info-soft); color: var(--info-ink); }
/* glyph knock-outs take the badge background */
.cj-status--implemented .cj-knock { stroke: var(--status-implemented-soft); }
.cj-status--not-implemented .cj-knock { stroke: var(--status-not-implemented-soft); }
/* bare dots for dense tables and charts use the fill tokens */
.cj-dot { display: inline-block; width: 10px; height: 10px; border-radius: var(--radius-full); flex: none; }
.cj-dot--implemented { background: var(--status-implemented); }
.cj-dot--partial { background: var(--status-partial); }
.cj-dot--not-implemented { background: var(--status-not-implemented); }
.cj-dot--not-applicable { box-shadow: inset 0 0 0 2px var(--status-not-applicable); }
.cj-dot--not-assessed { border: 1.5px dashed var(--status-not-assessed); }

/* ---------- Tag (framework, control and classification chips) ---------- */
.cj-tag { display: inline-flex; align-items: center; gap: var(--space-1); height: 24px; padding-inline: var(--space-2);
  border-radius: var(--radius-sm); border: 1px solid var(--line); background: var(--surface-raised); color: var(--ink);
  font-family: var(--font-mono); font-size: 12px; line-height: 16px; font-weight: 500; white-space: nowrap; direction: ltr; unicode-bidi: isolate; }
.cj-tag--text { font-family: inherit; font-weight: 500; direction: inherit; }
.cj-tag svg { width: 12px; height: 12px; }
.cj-tag__remove { display: inline-grid; place-items: center; width: 16px; height: 16px; margin-inline-end: -4px; border: 0; padding: 0;
  border-radius: var(--radius-xs); background: transparent; color: var(--ink-muted); cursor: pointer; }
.cj-tag__remove:hover { background: var(--surface-sunken); color: var(--ink); }
.cj-class { display: inline-flex; align-items: center; gap: var(--space-1); height: 22px; padding-inline: 6px; border-radius: var(--radius-sm);
  background: var(--surface-sunken); color: var(--ink); font-size: 11px; line-height: 16px; font-weight: 600; letter-spacing: .06em; text-transform: uppercase; }
.cj-class svg { width: 12px; height: 12px; }

/* ---------- Callout ---------- */
.cj-callout { display: grid; grid-template-columns: 20px 1fr; gap: var(--space-3); padding: var(--space-4); border-radius: var(--radius-lg); color: var(--ink); }
.cj-callout > svg { width: 20px; height: 20px; margin-block-start: 1px; }
.cj-callout p { margin: 0; }
.cj-callout__title { font-weight: 600; margin-block-end: 2px !important; }
.cj-callout--info { background: var(--info-soft); } .cj-callout--info > svg { color: var(--info-ink); }
.cj-callout--success { background: var(--status-implemented-soft); } .cj-callout--success > svg { color: var(--status-implemented-ink); }
.cj-callout--warning { background: var(--status-partial-soft); } .cj-callout--warning > svg { color: var(--status-partial-ink); }
.cj-callout--danger { background: var(--status-not-implemented-soft); } .cj-callout--danger > svg { color: var(--status-not-implemented-ink); }
.cj-callout__actions { display: flex; gap: var(--space-2); margin-block-start: var(--space-3); }

/* ---------- Form field ---------- */
.cj-field { display: grid; gap: 6px; max-width: 420px; }
.cj-field__label { font-size: 13px; line-height: 18px; font-weight: 500; color: var(--ink); }
.cj-field__label .cj-req { color: var(--status-not-implemented-ink); margin-inline-start: 2px; }
.cj-field__help { margin: 0; font-size: 12px; line-height: 16px; color: var(--ink-muted); }
.cj-input, .cj-select { width: 100%; height: var(--control-md); padding-inline: var(--space-3); border-radius: var(--radius-sm);
  border: 1px solid var(--line-strong); background: var(--surface-raised); color: var(--ink); font: inherit; font-size: 14px; }
.cj-input::placeholder { color: var(--ink-subtle); }
.cj-input:hover, .cj-select:hover { border-color: var(--ink-muted); }
.cj-select { appearance: none; padding-inline-end: 32px; background-image: linear-gradient(45deg, transparent 50%, var(--ink-muted) 50%), linear-gradient(135deg, var(--ink-muted) 50%, transparent 50%);
  background-size: 5px 5px; background-repeat: no-repeat; background-position: calc(100% - 17px) 16px, calc(100% - 12px) 16px; }
[dir="rtl"] .cj-select { background-position: 12px 16px, 17px 16px; }
textarea.cj-input { height: auto; min-height: 88px; padding-block: var(--space-2); resize: vertical; }
.cj-field--error .cj-input, .cj-field--error .cj-select { border-color: var(--status-not-implemented-ink); }
.cj-field__error { display: flex; gap: var(--space-1); align-items: center; margin: 0; font-size: 12px; line-height: 16px; color: var(--status-not-implemented-ink); font-weight: 500; }
.cj-field__error svg { width: 14px; height: 14px; flex: none; }
.cj-input[disabled] { background: var(--surface-sunken); color: var(--ink-subtle); border-color: var(--line); }
.cj-check { display: inline-flex; gap: var(--space-2); align-items: center; font-size: 14px; cursor: pointer; }
.cj-check input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.cj-check span { width: 16px; height: 16px; border-radius: var(--radius-sm); border: 1px solid var(--line-strong); background: var(--surface-raised); display: grid; place-items: center; flex: none; }
.cj-check input:checked + span { background: var(--action); border-color: var(--action); }
.cj-check input:checked + span::after { content: ""; width: 8px; height: 4px; border: solid var(--on-action); border-width: 0 0 2px 2px; transform: translateY(-1px) rotate(-45deg); }

/* ---------- Tabs ---------- */
.cj-tabs { display: flex; gap: var(--space-6); border-block-end: 1px solid var(--line); }
.cj-tab { display: inline-flex; align-items: center; gap: var(--space-2); height: 40px; padding: 0; border: 0; background: none; font: inherit;
  font-size: 13px; line-height: 18px; font-weight: 500; color: var(--ink-muted); cursor: pointer; box-shadow: inset 0 -2px 0 transparent; }
.cj-tab:hover { color: var(--ink); }
.cj-tab[aria-selected="true"] { color: var(--ink); font-weight: 600; box-shadow: inset 0 -2px 0 var(--action); }
.cj-count { min-width: 20px; height: 18px; padding-inline: 6px; border-radius: var(--radius-full); background: var(--surface-sunken); color: var(--ink-muted);
  font-size: 11px; line-height: 18px; font-weight: 600; text-align: center; font-variant-numeric: tabular-nums; }
.cj-tab[aria-selected="true"] .cj-count { background: var(--brand-soft); color: var(--ink); }

/* ---------- Card, KPI tile ---------- */
.cj-card { background: var(--surface-raised); border: 1px solid var(--line); border-radius: var(--radius-lg); box-shadow: var(--shadow-sm); padding: var(--space-5); }
.cj-kpi { display: grid; gap: var(--space-1); min-width: 180px; }
.cj-kpi__label { font-size: 13px; line-height: 18px; font-weight: 500; color: var(--ink-muted); }
.cj-kpi__value { font-family: var(--font-display); font-size: 36px; line-height: 40px; font-weight: 600; letter-spacing: -0.01em; color: var(--ink); font-variant-numeric: tabular-nums; }
.cj-kpi__value small { font-size: 18px; font-weight: 600; color: var(--ink-muted); margin-inline-start: 2px; }
.cj-kpi__foot { display: flex; gap: var(--space-1); align-items: center; font-size: 12px; line-height: 16px; color: var(--ink-muted); }
.cj-trend { display: inline-flex; align-items: center; gap: 2px; font-weight: 600; }
.cj-trend svg { width: 14px; height: 14px; }
.cj-trend--good { color: var(--status-implemented-ink); }
.cj-trend--bad { color: var(--status-not-implemented-ink); }
.cj-trend--flat { color: var(--ink-muted); }

/* ---------- Score meter ---------- */
.cj-score { display: grid; gap: var(--space-3); max-width: 420px; }
.cj-score__head { display: flex; justify-content: space-between; align-items: center; gap: var(--space-3); }
.cj-score__value { font-family: var(--font-display); font-size: 36px; line-height: 40px; font-weight: 600; letter-spacing: -0.01em; font-variant-numeric: tabular-nums; }
.cj-score__value small { font-size: 18px; color: var(--ink-muted); }
.cj-meter { position: relative; height: 8px; border-radius: var(--radius-xs); background: var(--surface-sunken); box-shadow: inset 0 0 0 1px var(--line); }
.cj-meter__fill { position: absolute; inset-block: 0; inset-inline-start: 0; border-radius: var(--radius-xs); }
.cj-meter__tick { position: absolute; inset-block: -3px; width: 1px; background: var(--line-strong); }
.cj-meter__scale { position: relative; height: 16px; font-size: 11px; line-height: 16px; color: var(--ink-muted); font-variant-numeric: tabular-nums; }
.cj-meter__scale span { position: absolute; transform: translateX(-50%); }
[dir="rtl"] .cj-meter__scale span { transform: translateX(50%); }
.cj-band--compliant { background: var(--band-compliant); }
.cj-band--substantial { background: var(--band-substantial); }
.cj-band--partial { background: var(--band-partial); }
.cj-band--low { background: var(--band-low); }

/* ---------- Risk matrix ---------- */
.cj-risk { display: grid; grid-template-columns: 28px repeat(5, 56px); grid-auto-rows: 44px; gap: 3px; align-items: stretch; }
.cj-risk__axis { display: grid; place-items: center; font-size: 11px; line-height: 14px; color: var(--ink-muted); font-variant-numeric: tabular-nums; }
.cj-risk__cell { display: grid; place-items: center; border-radius: var(--radius-sm); font-size: 13px; font-weight: 600; font-variant-numeric: tabular-nums; color: var(--on-risk); }
.cj-risk__cell:empty::after { content: ""; }
.cj-risk__cell.r-1 { background: var(--risk-1); } .cj-risk__cell.r-2 { background: var(--risk-2); }
.cj-risk__cell.r-3 { background: var(--risk-3); } .cj-risk__cell.r-4 { background: var(--risk-4); }
.cj-risk__cell.r-5 { background: var(--risk-5); color: var(--on-risk-strong); }
.cj-risk__title { font-size: 12px; line-height: 16px; font-weight: 500; color: var(--ink-muted); }
.cj-sev { display: inline-flex; align-items: center; height: 22px; padding-inline: var(--space-2); border-radius: var(--radius-sm); font-size: 12px; font-weight: 600; color: var(--on-risk); }
.cj-sev.r-1 { background: var(--risk-1); } .cj-sev.r-2 { background: var(--risk-2); } .cj-sev.r-3 { background: var(--risk-3); }
.cj-sev.r-4 { background: var(--risk-4); } .cj-sev.r-5 { background: var(--risk-5); color: var(--on-risk-strong); }

/* ---------- Table ---------- */
.cj-table-wrap { border: 1px solid var(--line); border-radius: var(--radius-lg); overflow: auto; background: var(--surface-raised); }
.cj-table { width: 100%; border-collapse: collapse; font-size: 14px; line-height: 20px; }
.cj-table th { position: sticky; top: 0; background: var(--surface-sunken); color: var(--ink-muted); font-size: 12px; line-height: 16px; font-weight: 600;
  text-align: start; padding: 10px var(--space-4); border-block-end: 1px solid var(--line); white-space: nowrap; }
.cj-table td { padding: 10px var(--space-4); border-block-end: 1px solid var(--line); vertical-align: top; }
.cj-table tbody tr:last-child td { border-block-end: 0; }
.cj-table tbody tr:hover { background: var(--surface-sunken); }
.cj-table tbody tr[aria-selected="true"] { background: var(--brand-soft); }
.cj-table .cj-end { text-align: end; }
.cj-table .cj-cell-title { color: var(--ink); margin-block-start: 2px; }
.cj-table .cj-cell-sub { color: var(--ink-muted); font-size: 12px; line-height: 16px; }
.cj-evcount { display: inline-flex; align-items: center; gap: var(--space-1); color: var(--ink-muted); font-variant-numeric: tabular-nums; }
.cj-evcount svg { width: 14px; height: 14px; }

/* ---------- Evidence card ---------- */
.cj-evidence { display: grid; gap: var(--space-4); max-width: 520px; }
.cj-evidence__head { display: grid; grid-template-columns: 36px 1fr auto; gap: var(--space-3); align-items: start; }
.cj-evidence__icon { width: 36px; height: 36px; border-radius: var(--radius-md); background: var(--brand-soft); color: var(--brand); display: grid; place-items: center; }
.cj-evidence__icon svg { width: 20px; height: 20px; }
.cj-evidence h3 { margin: 2px 0 0; font-size: 15px; line-height: 22px; font-weight: 600; }
.cj-meta { display: grid; grid-template-columns: 112px 1fr; gap: var(--space-2) var(--space-4); margin: 0; font-size: 13px; line-height: 20px; }
.cj-meta dt { color: var(--ink-muted); }
.cj-meta dd { margin: 0; display: flex; flex-wrap: wrap; gap: var(--space-1); align-items: center; }
.cj-evidence__foot { padding-block-start: var(--space-3); border-block-start: 1px solid var(--line); font-size: 12px; line-height: 16px; color: var(--ink-muted); display: flex; justify-content: space-between; gap: var(--space-3); }

/* ---------- App shell ---------- */
.cj-shell { display: grid; grid-template-columns: var(--sidebar-width) 1fr; min-height: 100%; background: var(--surface); }
.cj-sidebar { background: var(--surface-brand); color: var(--on-brand); display: flex; flex-direction: column; padding: var(--space-4) var(--space-3); gap: var(--space-4); border-inline-end: 1px solid transparent; }
[data-theme="dark"] .cj-sidebar { border-inline-end-color: var(--line); }
.cj-sidebar__brand { display: flex; align-items: center; padding: var(--space-1) var(--space-2) var(--space-2); color: var(--on-brand); }
.cj-sidebar__brand svg { height: 22px; width: auto; }
.cj-nav { display: grid; gap: 2px; }
.cj-nav__group { padding: var(--space-3) var(--space-2) var(--space-1); color: var(--on-brand-muted); font-size: 11px; line-height: 16px; font-weight: 600; letter-spacing: .08em; text-transform: uppercase; }
:lang(ar) .cj-nav__group, [dir="rtl"] .cj-nav__group { letter-spacing: 0; text-transform: none; font-size: 12px; }
.cj-nav__item { position: relative; display: flex; align-items: center; gap: var(--space-3); height: 36px; padding-inline: var(--space-3) var(--space-2);
  border-radius: var(--radius-md); color: var(--on-brand); text-decoration: none; font-size: 14px; line-height: 20px; font-weight: 500; }
.cj-nav__item svg { width: var(--icon-md); height: var(--icon-md); flex: none; color: var(--on-brand-muted); }
.cj-nav__item:hover { background: var(--shell-hover); }
.cj-nav__item[aria-current="page"] { background: var(--shell-active); font-weight: 600; }
.cj-nav__item[aria-current="page"] svg { color: var(--on-brand); }
.cj-nav__item[aria-current="page"]::before { content: ""; position: absolute; inset-inline-start: -12px; inset-block: 8px; width: 3px; border-radius: var(--radius-full); background: var(--brand-accent); }
.cj-nav__item:focus-visible { outline: 2px solid var(--on-brand); outline-offset: 2px; }
.cj-nav__item .cj-count { margin-inline-start: auto; background: var(--shell-hover); color: var(--on-brand); }
.cj-sidebar__foot { margin-block-start: auto; display: flex; align-items: center; gap: var(--space-2); padding: var(--space-2); border-radius: var(--radius-md); color: var(--on-brand-muted); font-size: 12px; line-height: 16px; }
.cj-sidebar__foot strong { display: block; color: var(--on-brand); font-size: 13px; font-weight: 600; }
.cj-tenant { width: 28px; height: 28px; border-radius: var(--radius-md); background: var(--shell-active); color: var(--on-brand); display: grid; place-items: center; font-size: 12px; font-weight: 600; flex: none; }
.cj-main { display: flex; flex-direction: column; min-width: 0; }
.cj-topbar { display: flex; align-items: center; gap: var(--space-3); height: 56px; padding-inline: var(--space-8); border-block-end: 1px solid var(--line); background: var(--surface-raised); }
.cj-crumbs { display: flex; gap: var(--space-2); align-items: center; font-size: 13px; color: var(--ink-muted); }
.cj-crumbs b { color: var(--ink); font-weight: 600; }
.cj-search { margin-inline-start: auto; width: 260px; }
.cj-page { padding: var(--space-6) var(--space-8); display: grid; gap: var(--space-5); max-width: var(--content-max); }
.cj-page__head { display: flex; align-items: flex-end; justify-content: space-between; gap: var(--space-4); }
.cj-page__head h1 { margin: 0; }
.cj-eyebrow { font-size: 12px; line-height: 16px; color: var(--ink-muted); margin-block-end: 2px; }
.cj-grid-3 { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: var(--space-4); }

/* ---------- Logo showcase ---------- */
.cj-logo-tiles { display: grid; grid-template-columns: 1fr 1fr; gap: var(--space-3); padding: var(--space-4); }
.cj-logo-tile { display: grid; place-items: center; min-height: 128px; border-radius: var(--radius-lg); border: 1px solid var(--line); background: var(--surface-raised); position: relative; padding: var(--space-6); }
.cj-logo-tile--brand { background: var(--surface-brand); border-color: transparent; }
.cj-logo-tile img { max-width: 100%; }
.cj-logo-tile figcaption { position: absolute; inset-inline-start: var(--space-3); inset-block-end: var(--space-2); font-size: 11px; line-height: 14px; color: var(--ink-muted); }
.cj-logo-tile--brand figcaption { color: var(--on-brand-muted); }
html[data-theme="dark"] .cj-only-light, html:not([data-theme="dark"]) .cj-only-dark { display: none; }

@media (prefers-reduced-motion: reduce) { .cj-btn, .cj-tab { transition: none; } }
.cj-knock { stroke: var(--surface-raised); }
.cj-table td.cj-end, .cj-table th.cj-end { white-space: nowrap; }
