/* Benerra Academy: components (ui.js) and the app frame (shell.js). Working tokens only.
   Frames are box-shadow insets, radius <= 14 px, no shadows, no gradients, logical properties. */

/* =================================================================== buttons */
.btn {
  position: relative; display: inline-flex; align-items: center; justify-content: center; gap: var(--space-2);
  min-block-size: var(--control-h); max-inline-size: 100%; padding-inline: var(--space-5);
  border: 0; border-radius: var(--radius-control); background: transparent; color: var(--text);
  font-family: var(--font-sans); font-size: var(--fs-body); font-weight: var(--fw-medium); line-height: 1.2;
  text-decoration: none; white-space: nowrap; vertical-align: middle;
  transition: background-color var(--dur-fast) var(--ease-out), color var(--dur-fast) var(--ease-out), box-shadow var(--dur-base) var(--ease-out);
}
.btn__label { min-width: 0; }
.btn .i { flex: none; }
.btn:active:not(:disabled) { transform: translateY(1px); }
.btn--primary { background: var(--brand); color: var(--on-brand); }
.btn--primary:hover { background: var(--brand-hover); }
.btn--secondary { box-shadow: var(--frame-strong); }
.btn--secondary:hover { background: var(--surface-hover); }
.btn--accent { background: var(--accent); color: var(--on-accent); }
.btn--accent:hover { background: var(--accent-hover); box-shadow: var(--glow-cta); }
.btn--accent-outline { box-shadow: var(--frame-accent); color: var(--accent-text); }
.btn--accent-outline:hover { background: var(--accent-soft); }
.btn--ghost:hover { background: var(--surface-hover); }
.btn--danger { box-shadow: var(--frame-danger); color: var(--danger-text); }
.btn--danger:hover { background: var(--danger-soft); }
.btn--sm { min-block-size: var(--control-h-sm); padding-inline: var(--space-4); font-size: var(--fs-sm); }
.btn--lg { min-block-size: var(--control-h-lg); padding-inline: var(--space-6); font-size: var(--fs-h4); }
.btn--icon { inline-size: var(--icon-btn); min-block-size: var(--icon-btn); padding: 0; }
.btn--icon.btn--sm { inline-size: var(--icon-btn-sm); min-block-size: var(--icon-btn-sm); }
.btn--block { display: flex; inline-size: 100%; }
.btn:disabled:not(.is-busy), .btn[aria-disabled="true"]:not(.is-busy) { background: var(--track); color: var(--text-faint); box-shadow: none; }
.btn--ghost:disabled:not(.is-busy) { background: transparent; }
.btn.is-busy { cursor: progress; }
.btn.is-busy > * { visibility: hidden; }
.btn.is-busy::after {
  content: ""; position: absolute; inset-block-start: 50%; inset-inline-start: 50%; inline-size: 16px; block-size: 16px;
  margin-block-start: -8px; margin-inline-start: -8px; border-radius: var(--radius-round);
  border: 2px solid currentColor; border-inline-end-color: transparent; animation: spin 800ms linear infinite;
}
.btn-slot { display: inline-block; flex: none; inline-size: var(--icon-btn); }
.actions { display: flex; flex-wrap: wrap; align-items: center; justify-content: flex-end; gap: var(--space-3); }
@media (max-width: 719px) {
  .actions { flex-direction: column-reverse; align-items: stretch; }
  .actions .btn { inline-size: 100%; }
}

/* =================================================================== fields */
.field { display: flex; flex-direction: column; gap: var(--space-2); min-width: 0; }
.field__label { font-size: var(--fs-xs); font-weight: var(--fw-semibold); letter-spacing: .08em; text-transform: uppercase; color: var(--text-muted); }
.field__optional { margin-inline-start: var(--space-2); font-weight: var(--fw-regular); letter-spacing: 0; text-transform: none; color: var(--text-muted); }
.field__hint { font-size: var(--fs-sm); color: var(--text-muted); }
.field__error { display: flex; align-items: flex-start; gap: var(--space-2); font-size: var(--fs-sm); color: var(--danger-text); }
.field__error .i { margin-block-start: 1px; }
.input, .select {
  inline-size: 100%; min-inline-size: 72px; min-block-size: var(--field-h); padding-inline: var(--space-4);
  border: 0; border-radius: var(--radius-control); background: var(--surface); color: var(--text);
  box-shadow: var(--frame-strong); font-size: var(--fs-body);
  -webkit-appearance: none; appearance: none;
  transition: box-shadow var(--dur-fast) var(--ease-out), background-color var(--dur-base) var(--ease-out);
}
.input::placeholder { color: var(--text-muted); opacity: 1; }
.input:hover, .select:hover { box-shadow: var(--frame-brand); }
.input:focus, .select:focus, .input:focus-visible, .select:focus-visible { outline: none; box-shadow: var(--frame-brand-2), var(--ring-brand); }
.input:disabled, .select:disabled { background: var(--surface-2); color: var(--text-faint); box-shadow: var(--frame); }
.has-error .input, .has-error .select, .input[aria-invalid="true"] { box-shadow: var(--frame-danger); }
.textarea { min-block-size: 120px; padding-block: var(--space-3); line-height: var(--lh-body); resize: vertical; }
.input-wrap { position: relative; min-width: 0; }
.input--with-btn { padding-inline-end: 48px; }
.input-btn {
  position: absolute; inset-block-start: 5px; inset-inline-end: 5px; display: grid; place-items: center;
  inline-size: 36px; block-size: 36px; border: 0; border-radius: 8px; background: transparent; color: var(--text-muted);
}
.input-btn:hover { background: var(--surface-hover); color: var(--text); }
.select-wrap { position: relative; min-width: 0; }
.select { padding-inline-end: 40px; cursor: pointer; }
.select-wrap__arrow { position: absolute; inset-block-start: 50%; inset-inline-end: 14px; transform: translateY(-50%); color: var(--text-muted); pointer-events: none; }

.check { position: relative; display: inline-flex; align-items: flex-start; gap: var(--space-3); min-block-size: 24px; cursor: pointer; max-inline-size: 100%; }
.check__input { position: absolute; inset-block-start: 1px; inset-inline-start: 0; inline-size: 20px; block-size: 20px; margin: 0; opacity: 0; cursor: inherit; }
.check__box {
  display: grid; place-items: center; flex: none; inline-size: 20px; block-size: 20px; margin-block-start: 1px;
  border-radius: 5px; background: var(--surface); color: transparent; box-shadow: var(--frame-strong);
  transition: background-color var(--dur-fast) var(--ease-out), box-shadow var(--dur-fast) var(--ease-out);
}
.check__input:checked + .check__box { background: var(--brand); color: var(--on-brand); box-shadow: none; }
.check__input:focus-visible + .check__box { outline: 2px solid var(--focus); outline-offset: 2px; }
.check:hover .check__box { box-shadow: var(--frame-brand); }
/* a checked checkbox is a filled square with no frame, hovered or not; a checked radio keeps its ring on hover */
.check:not(.check--radio):hover .check__input:checked + .check__box { box-shadow: none; }
.check--radio .check__box { border-radius: var(--radius-round); }
.check--radio .check__input:checked + .check__box { background: var(--surface); box-shadow: inset 0 0 0 6px var(--brand); }
.check__text { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.check__hint { font-size: var(--fs-sm); color: var(--text-muted); }
.check.is-disabled { cursor: not-allowed; color: var(--text-faint); }
.check.is-disabled .check__box { background: var(--surface-2); box-shadow: var(--frame); }

/* =================================================================== tabs, segmented, chips */
.tabs { display: flex; gap: var(--space-6); overflow-x: auto; scrollbar-width: none; box-shadow: inset 0 -1px 0 var(--line); }
.tabs::-webkit-scrollbar { display: none; }
.tab {
  display: inline-flex; align-items: center; gap: var(--space-2); flex: none; min-block-size: 46px; padding-inline: 2px;
  border: 0; background: transparent; color: var(--text-muted); font-weight: var(--fw-medium); white-space: nowrap;
}
.tab:hover { color: var(--text); }
.tab.is-active { color: var(--text); box-shadow: inset 0 -2px 0 var(--brand); }
.tab:focus-visible { outline-offset: -2px; }
.tab__count {
  display: inline-block; min-inline-size: 22px; block-size: 20px; padding-inline: 6px; border-radius: var(--radius-sm);
  background: var(--surface-2); color: var(--text-muted); font-size: var(--fs-xs); font-weight: var(--fw-semibold); line-height: 20px; text-align: center;
}
.tab.is-active .tab__count { background: var(--accent); color: var(--on-accent); }
@media (max-width: 480px) { .tabs { flex-wrap: wrap; column-gap: var(--space-5); overflow: visible; } }

.seg { display: inline-flex; flex-wrap: wrap; gap: 2px; max-inline-size: 100%; padding: 2px; border-radius: var(--radius-control); background: var(--surface-2); box-shadow: var(--frame); }
.seg__item {
  display: inline-flex; align-items: center; justify-content: center; gap: var(--space-2); min-block-size: 36px; padding-inline: var(--space-4);
  border: 0; border-radius: 8px; background: transparent; color: var(--text-2); font-weight: var(--fw-medium); white-space: nowrap;
}
.seg__item:hover { color: var(--text); background: var(--surface-hover); }
.seg__item.is-active { background: var(--brand); color: var(--on-brand); }
.seg__item:focus-visible { outline-offset: 0; }
.seg--sm .seg__item { min-block-size: 30px; padding-inline: var(--space-3); font-size: var(--fs-sm); }

.chips { display: flex; flex-wrap: wrap; gap: var(--space-2); min-width: 0; }
.chip {
  display: inline-flex; align-items: center; gap: var(--space-2); max-inline-size: 100%; min-block-size: 36px; padding-inline: var(--space-4);
  border: 0; border-radius: var(--radius-control); background: transparent; color: var(--text); box-shadow: var(--frame-strong); font-weight: var(--fw-medium);
}
.chip:hover { background: var(--surface-hover); }
.chip__label { min-width: 0; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.chip__count { flex: none; font-size: var(--fs-xs); color: var(--text-muted); }
.chip.is-active { background: var(--brand); color: var(--on-brand); box-shadow: none; }
.chip.is-active .chip__count { color: var(--on-brand); }

/* =================================================================== surfaces */
.card {
  position: relative; display: flex; flex-direction: column; gap: var(--space-3); min-width: 0; padding: var(--space-6);
  border-radius: var(--radius-card); background: var(--surface); box-shadow: var(--frame), var(--shadow-card);
}
.card--accent { box-shadow: var(--bar-accent), var(--frame); }
.card__title { overflow-wrap: anywhere; }
.card__link { color: inherit; text-decoration: none; }
.card__link::after { content: ""; position: absolute; inset: 0; border-radius: inherit; }
.card__link:focus-visible { outline: none; }
.card__link:focus-visible::after { outline: 2px solid var(--focus); outline-offset: 2px; }
.card--link { transition: background-color var(--dur-fast) var(--ease-out); }
.card--link:hover { background: var(--surface-hover); }
.card__text { font-size: var(--fs-body); }
.card__foot { display: flex; flex-wrap: wrap; align-items: center; gap: var(--space-3); margin-block-start: auto; padding-block-start: var(--space-2); }
.section { display: flex; flex-direction: column; gap: var(--space-4); min-width: 0; }
.section + .section { margin-block-start: var(--space-10); }
.section__head { display: flex; flex-wrap: wrap; align-items: baseline; justify-content: space-between; gap: var(--space-3); }

.page-head { display: flex; flex-direction: column; gap: var(--space-3); margin-block-end: var(--space-8); }
.page-head__back { align-self: flex-start; display: inline-flex; align-items: center; gap: 6px; color: var(--text-muted); font-size: var(--fs-sm); font-weight: var(--fw-medium); text-decoration: none; }
.page-head__back:hover { color: var(--text); }
.page-head__row { display: flex; flex-wrap: wrap; align-items: flex-end; justify-content: space-between; gap: var(--space-4) var(--space-6); }
.page-head__main { display: flex; flex-direction: column; gap: var(--space-3); min-width: 0; }
.page-head__bar { display: block; inline-size: 72px; block-size: 3px; border-radius: 2px; background: var(--accent); }
.page-head__aside { display: flex; flex-wrap: wrap; align-items: center; gap: var(--space-3); }

.stat { display: flex; flex-direction: column; gap: var(--space-2); min-width: 0; padding: var(--space-5); border-radius: var(--radius-card); background: var(--surface); box-shadow: var(--frame); }
.stat__label { font-size: var(--fs-sm); font-weight: var(--fw-medium); color: var(--text-2); }
.stat__sub { font-size: var(--fs-xs); }

/* =================================================================== badges, labels */
.badge {
  display: inline-block; max-inline-size: 100%; block-size: 24px; padding-inline: 8px; border-radius: var(--radius-sm);
  font-size: var(--fs-badge); font-weight: var(--fw-semibold); line-height: 24px; letter-spacing: var(--ls-badge); text-transform: uppercase;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; vertical-align: middle; color: var(--text-2); box-shadow: var(--frame-strong);
}
.badge__dot { display: inline-block; inline-size: 6px; block-size: 6px; margin-inline-end: 6px; border-radius: var(--radius-round); background: var(--brand); vertical-align: 1px; }
.badge__icon { margin-inline-end: 4px; vertical-align: -2px; }
.badge--available { color: var(--text); }
.badge--progress { background: var(--brand-soft); color: var(--brand-text); box-shadow: none; }
.badge--passed { background: var(--brand); color: var(--on-brand); box-shadow: none; }
.badge--failed { color: var(--danger-text); box-shadow: var(--frame-danger); }
.badge--warn { background: var(--warn-soft); color: var(--warn-text); box-shadow: none; }
.badge--muted { background: var(--surface-2); color: var(--text-muted); box-shadow: none; }
.badge--accent { background: var(--accent); color: var(--on-accent); box-shadow: none; }
.badge--accent-line { color: var(--accent-text); box-shadow: var(--frame-accent); }
.badge--plain { color: var(--text-2); }
.badge--role { max-inline-size: 200px; }
:lang(ar) .badge, :lang(he) .badge { letter-spacing: 0; text-transform: none; }

.plus-n { display: flex; align-items: center; gap: var(--space-2); min-width: 0; max-inline-size: 100%; }
.plus-n__first { flex: 0 1 auto; min-width: 0; }
.plus-n__more { flex: none; padding-inline: 6px; }

.note { display: flex; align-items: flex-start; gap: var(--space-2); font-size: 13px; line-height: 1.45; color: var(--text-2); }
.note .i { margin-block-start: 1px; color: var(--text-muted); }
.note__text { min-width: 0; }
.note--ok .i { color: var(--brand); }
.note--danger, .note--danger .i { color: var(--danger-text); }
.note--warn, .note--warn .i { color: var(--warn-text); }
.note--faint { color: var(--text-muted); }
.lock-label { display: inline-flex; align-items: center; gap: 6px; max-inline-size: 100%; min-width: 0; font-size: var(--fs-sm); color: var(--text-muted); }
.lock-label .i { flex: none; }

.callout { position: relative; display: flex; flex-direction: column; gap: var(--space-2); padding: var(--space-4) var(--space-5); padding-inline-start: calc(var(--space-5) + 3px); border-radius: var(--radius-card); overflow: hidden; }
.callout::before { content: ""; position: absolute; inset-block: 0; inset-inline-start: 0; inline-size: 3px; }
.callout__head { display: flex; align-items: center; gap: var(--space-2); font-weight: var(--fw-semibold); }
.callout__body { color: var(--text); }
.callout--important { background: var(--accent-soft); }
.callout--important::before { background: var(--accent); }
.callout--important .callout__head { color: var(--accent-text); }
.callout--tip { background: var(--brand-soft); }
.callout--tip::before { background: var(--brand); }
.callout--warning { background: var(--warn-soft); }
.callout--warning::before { background: var(--warn); }
.callout--warning .callout__head { color: var(--warn-text); }

.avatar {
  display: inline-grid; place-items: center; flex: none; inline-size: 36px; block-size: 36px; border-radius: var(--radius-round);
  background: var(--surface-2); color: var(--text); box-shadow: var(--frame); font-size: 13px; font-weight: var(--fw-semibold); letter-spacing: .02em;
}
.avatar--lg { inline-size: 56px; block-size: 56px; font-size: 18px; }

/* =================================================================== progress, stars */
.progress { display: flex; flex-direction: column; gap: var(--space-2); min-width: 0; }
.progress__head { display: flex; align-items: baseline; justify-content: space-between; gap: var(--space-3); font-size: var(--fs-sm); }
.progress__label { color: var(--text-2); }
.progress__value { font-weight: var(--fw-semibold); color: var(--text); }
.progress__track { position: relative; display: block; block-size: 6px; border-radius: 3px; background: var(--track); overflow: hidden; }
.progress--thin .progress__track { block-size: 3px; }
.progress__fill { position: absolute; inset-block: 0; inset-inline-start: 0; inline-size: var(--p, 0%); border-radius: inherit; background: var(--brand); transition: inline-size var(--dur-slow) var(--ease-out); }
.progress--active .progress__fill { animation: progress-breathe 1.6s ease-in-out infinite alternate; }
.progress__foot { font-size: var(--fs-sm); }
@keyframes progress-breathe { from { opacity: 1; } to { opacity: .62; } }

.stars { display: inline-flex; gap: 4px; }
.star { display: inline-grid; place-items: center; inline-size: 40px; block-size: 40px; padding: 0; border: 0; border-radius: var(--radius-control); background: transparent; color: var(--line-strong); }
.star:hover:not(:disabled) { color: var(--brand); }
.star.is-on { color: var(--brand); }
.star.is-on svg { fill: currentColor; }
.stars--readonly { gap: 2px; }
.stars--readonly .star { inline-size: auto; block-size: auto; }

/* =================================================================== states */
.state { display: flex; flex-direction: column; align-items: center; gap: var(--space-3); max-inline-size: 560px; margin-inline: auto; padding-block: var(--space-15); text-align: center; }
.state__icon { display: grid; place-items: center; inline-size: 56px; block-size: 56px; margin-block-end: var(--space-2); border-radius: var(--radius-round); background: var(--surface-2); color: var(--text-muted); box-shadow: var(--frame); }
.state__icon--danger { background: var(--danger-soft); color: var(--danger); }
.state__title { max-inline-size: 36ch; text-wrap: balance; }
.state__text { max-inline-size: 52ch; }
.state__action { display: flex; flex-wrap: wrap; justify-content: center; gap: var(--space-3); margin-block-start: var(--space-3); }
.state--loading { padding-block: var(--space-12); }
.spinner { display: inline-grid; place-items: center; color: var(--text-muted); }
.spinner .i { animation: spin 900ms linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.skel-wrap { display: flex; flex-direction: column; gap: var(--space-3); }
.skel { display: block; border-radius: var(--radius-sm); background: var(--surface-2); animation: skel-pulse 1.4s ease-in-out infinite alternate; }
.skel--lines { block-size: 14px; }
.skel--lines:last-child { inline-size: 60%; }
.skel--rows { block-size: var(--row-table); border-radius: var(--radius-control); }
.skel-wrap--tiles { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 16px; }
.skel--tiles { block-size: 280px; border-radius: var(--radius-card); }
.skel-wrap--cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: var(--gutter); }
.skel--cards { block-size: 200px; border-radius: var(--radius-card); }
.skel--bar { inline-size: 72px; block-size: 3px; }
.skel--title { inline-size: min(420px, 80%); block-size: 36px; }
.skel--line { inline-size: min(560px, 90%); block-size: 16px; }
@keyframes skel-pulse { from { opacity: 1; } to { opacity: .45; } }

/* =================================================================== table (symmetry rule, C4.7.2) */
.dt-wrap { position: relative; min-width: 0; }
.dt-block { position: relative; inline-size: 100%; overflow-x: auto; overscroll-behavior-inline: contain; border-radius: var(--radius-card); background: var(--surface); box-shadow: var(--frame); }
.dt-block::before { content: ""; position: absolute; inset-block-start: 0; inset-inline-start: var(--space-5); z-index: 1; inline-size: 72px; block-size: 3px; background: var(--brand); }
.dt-wrap[data-more]::after {
  content: ""; position: absolute; inset-block: 1px; inset-inline-end: 1px; inline-size: 18px; pointer-events: none;
  background: var(--surface); opacity: .9; box-shadow: inset 1px 0 0 var(--line); border-start-end-radius: var(--radius-card); border-end-end-radius: var(--radius-card);
}
.dt { inline-size: 100%; border-collapse: collapse; table-layout: auto; font-size: var(--fs-sm); }
.dt__caption { padding: var(--space-4) var(--space-5) 0; text-align: start; font-weight: var(--fw-semibold); }
.dt th {
  block-size: 44px; padding-inline: var(--space-4); text-align: start; vertical-align: middle; white-space: nowrap;
  font-size: var(--fs-xs); font-weight: var(--fw-semibold); letter-spacing: .08em; text-transform: uppercase; color: var(--text-muted);
  box-shadow: inset 0 -1px 0 var(--line);
}
.dt td { block-size: var(--row-table); padding-block: 4px; padding-inline: var(--space-4); vertical-align: middle; white-space: nowrap; box-shadow: inset 0 -1px 0 var(--line-soft); }
.dt tbody tr:last-child td { box-shadow: none; }
.dt__cell { display: flex; flex-direction: column; justify-content: center; gap: 2px; min-width: 0; max-block-size: calc(var(--row-table) - 8px); overflow: hidden; }
.dt__cell > .ell, .dt__cell > a, .dt__cell > span { max-inline-size: 100%; }
.dt__cell .btn, .dt__cell .badge, .dt__cell .i { flex: none; }
.dt__ell--fill { inline-size: 100%; max-inline-size: 0; }
.dt__end { text-align: end; }
.dt__end .dt__cell { align-items: flex-end; }
.dt__sort { display: inline-flex; align-items: center; gap: 4px; padding: 0; border: 0; background: transparent; color: inherit; font: inherit; letter-spacing: inherit; text-transform: inherit; }
.dt__sort:hover { color: var(--text); }
.dt th .i { display: inline-block; }
.dt__row--link { position: relative; }
.dt__row--link:hover td { background: var(--surface-hover); }
.dt__link { color: inherit; font-weight: var(--fw-medium); text-decoration: none; }
.dt__link::after { content: ""; position: absolute; inset: 0; }
.dt__link:focus-visible { outline: none; }
.dt__link:focus-visible::after { outline: 2px solid var(--focus); outline-offset: -2px; }
@media (min-width: 1024px) and (max-width: 1399px) { .dt__minor { display: none; } }
@media (max-width: 1023px) {
  .dt, .dt tbody, .dt tr, .dt td { display: block; inline-size: 100%; }
  .dt thead { position: absolute; inline-size: 1px; block-size: 1px; overflow: hidden; clip: rect(0 0 0 0); clip-path: inset(50%); }
  .dt tr { padding: var(--space-3) var(--space-4); box-shadow: inset 0 -1px 0 var(--line-soft); }
  .dt tbody tr:last-child { box-shadow: none; }
  .dt td { display: grid; grid-template-columns: minmax(96px, 34%) minmax(0, 1fr); align-items: center; gap: var(--space-3); block-size: auto; min-block-size: 32px; padding: 2px 0; box-shadow: none; }
  .dt td::before { content: attr(data-label); overflow: hidden; white-space: nowrap; text-overflow: ellipsis; font-size: var(--fs-xs); font-weight: var(--fw-semibold); letter-spacing: .06em; text-transform: uppercase; color: var(--text-muted); }
  .dt__ell--fill { max-inline-size: none; }
  .dt__end { text-align: start; }
  .dt__end .dt__cell { align-items: flex-start; }
  .dt-wrap[data-more]::after { display: none; }
}

/* =================================================================== pagination */
.pagination { display: flex; flex-wrap: wrap; align-items: center; justify-content: center; gap: 6px; margin-block-start: var(--space-6); }
.pagination__item { min-inline-size: 36px; block-size: 36px; padding-inline: 8px; border: 0; border-radius: var(--radius-sm); background: transparent; color: var(--text); box-shadow: var(--frame); font-weight: var(--fw-medium); font-variant-numeric: tabular-nums; }
.pagination__item:hover { background: var(--surface-hover); }
.pagination__item.is-active { background: var(--brand); color: var(--on-brand); box-shadow: none; }
.pagination__gap { min-inline-size: 20px; text-align: center; color: var(--text-muted); }

/* =================================================================== overlays: modal, toast, menu, popover */
html.has-modal, html.has-drawer { overflow: hidden; }
.modal-root { position: fixed; inset: 0; z-index: var(--z-modal); display: grid; place-items: center; padding: var(--space-4); }
.modal-scrim { position: absolute; inset: 0; background: var(--scrim); -webkit-backdrop-filter: blur(2px); backdrop-filter: blur(2px); animation: fade-in var(--dur-base) var(--ease-out); }
.modal {
  position: relative; display: flex; flex-direction: column; inline-size: 100%; max-inline-size: 520px; max-block-size: calc(100dvh - 32px);
  border-radius: var(--radius-card); background: var(--surface); color: var(--text); box-shadow: var(--frame), var(--shadow-modal);
  overflow: hidden; animation: modal-in var(--dur-slow) var(--ease-out);
}
.modal--wide { max-inline-size: 720px; }
.modal__bar { position: absolute; inset-block-start: 0; inset-inline-start: var(--space-6); inline-size: 72px; block-size: 3px; background: var(--accent); }
.modal--danger .modal__bar { background: var(--danger); }
.modal__head { display: flex; align-items: flex-start; justify-content: space-between; gap: var(--space-3); padding: var(--space-6) var(--space-6) var(--space-3); }
.modal__title { min-width: 0; overflow-wrap: anywhere; }
.modal__close { flex: none; margin-block-start: -6px; margin-inline-end: -10px; }
.modal__body { min-block-size: 0; padding: 0 var(--space-6) var(--space-4); }
.modal__text { color: var(--text-2); }
.modal__actions { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: var(--space-3); padding: var(--space-4) var(--space-6) var(--space-6); }
@media (max-width: 519px) {
  .modal-root { place-items: end stretch; padding: 0; }
  .modal { max-inline-size: none; max-block-size: 92dvh; border-end-start-radius: 0; border-end-end-radius: 0; animation-name: sheet-in; }
  .modal__actions { flex-direction: column-reverse; }
  .modal__actions .btn { inline-size: 100%; }
}
@keyframes fade-in { from { opacity: 0; } to { opacity: 1; } }
@keyframes modal-in { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }
@keyframes sheet-in { from { transform: translateY(100%); } to { transform: none; } }

.toast-stack { position: fixed; inset-block-end: var(--space-4); inset-inline-end: var(--space-4); z-index: var(--z-toast); display: flex; flex-direction: column; gap: var(--space-2); inline-size: min(380px, calc(100% - 32px)); }
.toast {
  position: relative; display: flex; align-items: flex-start; gap: var(--space-3); padding: var(--space-2) var(--space-2) var(--space-2) var(--space-4);
  border-radius: var(--radius-control); background: var(--surface); color: var(--text); box-shadow: var(--frame); overflow: hidden;
  animation: modal-in var(--dur-slow) var(--ease-out);
}
.toast::before { content: ""; position: absolute; inset-block: 0; inset-inline-start: 0; inline-size: 3px; background: var(--brand); }
.toast--danger::before { background: var(--danger); }
.toast--warn::before { background: var(--warn); }
.toast--info::before { background: var(--line-strong); }
.toast__icon { margin-block-start: 9px; color: var(--brand); }
.toast--danger .toast__icon { color: var(--danger); }
.toast--warn .toast__icon { color: var(--warn); }
.toast--info .toast__icon { color: var(--text-muted); }
.toast__body { display: flex; flex: 1 1 auto; flex-direction: column; gap: 2px; min-width: 0; padding-block: 8px; font-size: var(--fs-sm); }
.toast__title { font-weight: var(--fw-semibold); }
.toast__close { flex: none; color: var(--text-muted); }

.menu {
  position: fixed; z-index: var(--z-dropdown); min-inline-size: 220px; max-inline-size: min(320px, calc(100% - 16px)); padding: 6px;
  border-radius: var(--radius-control); background: var(--surface); color: var(--text); box-shadow: var(--frame-strong), var(--shadow-pop);
  animation: fade-in var(--dur-fast) var(--ease-out);
}
.menu:focus { outline: none; }
.menu__head { display: flex; flex-direction: column; gap: 2px; min-width: 0; padding: 8px 10px 10px; margin-block-end: 6px; box-shadow: inset 0 -1px 0 var(--line); }
.menu__name { font-weight: var(--fw-semibold); }
.menu__mail { font-size: var(--fs-sm); color: var(--text-muted); }
.menu__item {
  display: flex; align-items: center; gap: 10px; inline-size: 100%; min-block-size: var(--row-nav); padding-inline: 10px;
  border: 0; border-radius: 8px; background: transparent; color: var(--text); font-size: var(--fs-body); font-weight: var(--fw-medium); text-align: start; text-decoration: none;
}
.menu__item:hover { background: var(--surface-hover); }
.menu__item:focus-visible { outline: none; background: var(--surface-hover); box-shadow: inset 0 0 0 2px var(--focus); }
.menu__item[aria-disabled="true"] { color: var(--text-faint); cursor: not-allowed; }
.menu__icon { display: inline-block; flex: none; inline-size: 18px; color: var(--text-muted); }
.menu__label { flex: 1 1 auto; }
.menu__check { flex: none; color: var(--brand); }
.menu__item--danger { color: var(--danger-text); }
.menu__item--danger .menu__icon { color: currentColor; }
.menu__sep { block-size: 1px; margin: 6px 4px; background: var(--line); }

.popover { position: fixed; z-index: var(--z-dropdown); max-inline-size: 300px; padding: var(--space-3) var(--space-4); border-radius: var(--radius-control); background: var(--surface); color: var(--text); box-shadow: var(--frame-strong); font-size: var(--fs-sm); }
.popover:focus { outline: none; }
.popover__link { display: inline-flex; align-items: center; gap: 6px; margin-block-start: var(--space-2); color: var(--brand-text); font-weight: var(--fw-medium); }

/* =================================================================== header (always dark ink, C4.2) */
.shell-header { position: sticky; inset-block-start: 0; z-index: var(--z-header); }
.topbar { background: var(--topbar-bg); color: var(--topbar-text); box-shadow: inset 0 -1px 0 var(--topbar-line); }
.topbar--admin { box-shadow: inset 0 -2px 0 var(--accent); }
.topbar__inner { display: flex; align-items: center; gap: var(--space-4); block-size: var(--topbar-h); }
.topbar__burger { display: none; flex: none; color: var(--topbar-text); }
.topbar__logo { display: inline-flex; flex: none; align-items: center; block-size: 40px; border-radius: 6px; }
.topbar__logo img { display: block; block-size: 22px; inline-size: auto; }
.topbar__sep { display: none; flex: none; inline-size: 1px; block-size: 20px; background: var(--topbar-line); }
.topbar__product { display: none; flex: 0 1 auto; max-inline-size: 220px; font-family: var(--font-serif); font-size: 16px; font-weight: var(--fw-display); letter-spacing: var(--ls-display); color: var(--topbar-text); }
.topbar__nav { display: flex; align-items: stretch; align-self: stretch; gap: var(--space-1); min-width: 0; margin-inline-start: var(--space-3); }
.topbar__link { display: inline-flex; align-items: center; padding-inline: var(--space-3); color: var(--topbar-muted); font-weight: var(--fw-medium); white-space: nowrap; text-decoration: none; transition: color var(--dur-fast) var(--ease-out); }
.topbar__link:hover { color: var(--topbar-text); }
.topbar__link.is-active { color: var(--topbar-text); box-shadow: inset 0 -2px 0 var(--brand); }
.topbar__link--admin, .topbar__link--admin:hover { color: var(--accent-text); }
.topbar__link--admin.is-active { color: var(--accent-text); box-shadow: inset 0 -2px 0 var(--accent); }
.topbar__link:focus-visible { outline-offset: -4px; }
.topbar__right { display: flex; align-items: center; gap: var(--space-3); min-width: 0; margin-inline-start: auto; }
.topbar__role { flex: 0 1 auto; min-width: 0; max-inline-size: 200px; }
.topbar__theme { flex: none; color: var(--topbar-text); }
.topbar__account {
  display: inline-flex; flex: none; align-items: center; gap: var(--space-2); max-inline-size: 240px; block-size: 40px; padding-inline: 2px 6px;
  border: 0; border-radius: var(--radius-control); background: transparent; color: var(--topbar-text);
}
.topbar__account:hover { background: var(--surface-hover); }
.topbar__name { max-inline-size: 160px; font-weight: var(--fw-medium); }
.topbar__chev { color: var(--topbar-muted); }
@media (min-width: 1440px) { .topbar__sep, .topbar__product { display: block; } }
@media (max-width: 1279px) { .topbar__name { display: none; } }
@media (max-width: 899px) {
  .topbar__nav { display: none; }
  .topbar__burger { display: inline-flex; }
  .topbar__inner { gap: var(--space-3); }
}
@media (max-width: 719px) { .topbar__role { display: none; } .topbar__inner { gap: var(--space-2); } }
.lang-btn__code { font-size: 12px; font-weight: var(--fw-semibold); letter-spacing: .04em; }

/* view-as banner (C2.13): dark strip 44 px under the header with an accent line */
/* min-width 0: a grid item of #app, so the strip's one-line text never widens the page column; the text gives way first
   ("…" + title), the role badge keeps up to 45 % of the line; below 720 px the exit button shows its icon only
   (its label stays for screen readers and in the title) */
.shell-viewas { position: sticky; inset-block-start: var(--topbar-h); z-index: calc(var(--z-header) - 1); min-width: 0; }
.viewas { background: var(--surface); color: var(--text); box-shadow: inset 0 -2px 0 var(--accent); }
.viewas__inner { display: flex; align-items: center; gap: var(--space-3); min-width: 0; min-block-size: var(--viewas-h); font-size: var(--fs-sm); }
.viewas__icon { flex: none; color: var(--accent-text); }
.viewas__text { flex: 0 1 auto; min-width: 0; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.viewas__role { flex: none; min-width: 0; max-inline-size: min(200px, 45%); }
.viewas__spacer { flex: 1 1 auto; }
.viewas__exit { flex: none; }
@media (max-width: 719px) {
  .viewas__inner { gap: var(--space-2); }
  .viewas__spacer { display: none; }
  .viewas__exit { margin-inline-start: auto; inline-size: var(--icon-btn-sm); min-block-size: var(--icon-btn-sm); padding-inline: 0; }
  .viewas__exit .btn__label {
    position: absolute; inline-size: 1px; block-size: 1px; margin: -1px; padding: 0;
    overflow: hidden; clip: rect(0 0 0 0); clip-path: inset(50%); white-space: nowrap; border: 0;
  }
}

/* drawer menu (< 900 px, all roles) */
.drawer { position: fixed; inset: 0; z-index: var(--z-drawer); }
.drawer__scrim { position: absolute; inset: 0; background: var(--scrim); animation: fade-in var(--dur-base) var(--ease-out); }
.drawer__panel {
  position: absolute; inset-block: 0; inset-inline-start: 0; display: flex; flex-direction: column; gap: var(--space-2);
  inline-size: min(86vw, 360px); padding: var(--space-3) var(--space-3) var(--space-6); background: var(--bg); color: var(--text); box-shadow: var(--frame);
  animation: drawer-in var(--dur-slow) var(--ease-out);
}
[dir="rtl"] .drawer__panel { animation-name: drawer-in-rtl; }
@keyframes drawer-in { from { transform: translateX(-100%); } to { transform: none; } }
@keyframes drawer-in-rtl { from { transform: translateX(100%); } to { transform: none; } }
.drawer__head { display: flex; justify-content: flex-end; }
.drawer__user { display: grid; grid-template-columns: auto minmax(0, 1fr); align-items: center; gap: var(--space-3); padding: var(--space-2) var(--space-3) var(--space-4); box-shadow: inset 0 -1px 0 var(--line); }
.drawer__who { display: flex; flex-direction: column; min-width: 0; }
.drawer__mail { font-size: var(--fs-sm); color: var(--text-muted); }
.drawer__role { grid-column: 1 / -1; justify-self: start; }
.drawer__nav, .drawer__actions { display: flex; flex-direction: column; gap: 2px; }
.drawer__item {
  position: relative; display: flex; align-items: center; gap: var(--space-3); inline-size: 100%; min-block-size: 48px; padding-inline: var(--space-3);
  border: 0; border-radius: var(--radius-control); background: transparent; color: var(--text); font-size: 16px; font-weight: var(--fw-medium); text-align: start; text-decoration: none;
}
.drawer__item .i { color: var(--text-muted); }
.drawer__item:hover { background: var(--surface-hover); }
.drawer__item.is-active { background: var(--surface-2); }
.drawer__item.is-active::before { content: ""; position: absolute; inset-block: 10px; inset-inline-start: 0; inline-size: 3px; border-radius: 2px; background: var(--brand); }
.drawer__item[data-nav="admin"], .drawer__item[data-nav="admin"] .i { color: var(--accent-text); }
.drawer__item[data-nav="admin"].is-active::before { background: var(--accent); }
.drawer__item--sub { min-block-size: 44px; padding-inline-start: 48px; font-size: var(--fs-body); }
.drawer__item--sub.is-checked { color: var(--text); }
.drawer__chev { margin-inline-start: auto; }
.drawer__sep { block-size: 1px; margin: var(--space-2) var(--space-3); background: var(--line); }

/* =================================================================== form-level error, brand footer */
.form-error { display: flex; align-items: flex-start; gap: var(--space-2); padding: var(--space-3) var(--space-4); border-radius: var(--radius-control); background: var(--danger-soft); color: var(--danger-text); font-size: var(--fs-sm); }
.form-error .i { flex: none; margin-block-start: 1px; }
.brand-footer { display: flex; align-items: center; justify-content: center; gap: var(--space-2); font-size: var(--fs-xs); font-weight: var(--fw-medium); letter-spacing: .16em; text-transform: uppercase; color: var(--text-muted); }
.brand-footer--page { margin-block-start: var(--space-10); }
.boot-spinner { display: grid; place-items: center; min-block-size: 60vh; }
