/*
 * ALMOMANI — components
 * --------------------------------------------------------------------------
 * The single component layer (Phase 3 consolidation). Order inside this file:
 *   1. Bootstrap bridge (design tokens -> Bootstrap --bs-* variables; formerly bridge.css)
 *   2. Base components (links, buttons, cards, forms, tables, badges, alerts, dropdowns, tabs, pagination, progress)
 *   3. Forms, sections & action bars   4. Data tables   5. Surface layering, buttons, KPI, cards, feeds, empty states
 *   6. Person / status / chips / row actions   7. Toolbars & search   8. Overview widgets (dashboard)
 * Formerly refine.css and polish.css; their rules now live next to the base definition they used to override.
 * Tokens only, no raw colours; logical properties only (English LTR and Arabic RTL share one rule set).
 */

/* ===================================================================== 1. Bootstrap bridge ===================================================================== */
:root,
[data-bs-theme="light"],
[data-bs-theme="dark"] {
  --bs-font-sans-serif: var(--font-sans);
  --bs-body-font-family: var(--font-sans);
  --bs-body-font-size: var(--fs-md);
  --bs-body-line-height: var(--lh-body);
  --bs-body-bg: var(--bg);
  --bs-body-color: var(--text);
  --bs-emphasis-color: var(--text);
  --bs-secondary-color: var(--text-muted);
  --bs-secondary-bg: var(--surface-3);
  --bs-tertiary-color: var(--text-muted);
  --bs-tertiary-bg: var(--surface-2);
  --bs-heading-color: var(--text);
  --bs-border-color: var(--border);
  --bs-border-color-translucent: var(--border);
  --bs-border-radius: var(--radius-sm);
  --bs-border-radius-sm: var(--radius-sm);
  --bs-border-radius-lg: var(--radius-md);
  --bs-border-radius-xl: var(--radius-lg);
  --bs-link-color: var(--link);
  --bs-link-color-rgb: 168, 0, 0;
  --bs-link-hover-color: var(--link-hover);
  --bs-link-hover-color-rgb: 125, 0, 0;
  --bs-code-color: var(--brand-text);
  --bs-highlight-bg: var(--warning-bg);
  --bs-focus-ring-color: var(--brand-tint-strong);

  /* Semantic colours (fills). Text variants are handled in components.css */
  --bs-primary: var(--brand-red);
  --bs-primary-rgb: 186, 0, 0;
  --bs-success: var(--success-solid);
  --bs-danger: var(--danger-solid);
  --bs-warning: var(--warning-solid);
  --bs-info: var(--info-solid);

  --bs-primary-text-emphasis: var(--brand-text);
  --bs-success-text-emphasis: var(--success-text);
  --bs-danger-text-emphasis: var(--danger-text);
  --bs-warning-text-emphasis: var(--warning-text);
  --bs-info-text-emphasis: var(--info-text);

  --bs-primary-bg-subtle: var(--brand-tint);
  --bs-success-bg-subtle: var(--success-bg);
  --bs-danger-bg-subtle: var(--danger-bg);
  --bs-warning-bg-subtle: var(--warning-bg);
  --bs-info-bg-subtle: var(--info-bg);

  --bs-primary-border-subtle: var(--brand-tint-strong);
  --bs-success-border-subtle: var(--success-border);
  --bs-danger-border-subtle: var(--danger-border);
  --bs-warning-border-subtle: var(--warning-border);
  --bs-info-border-subtle: var(--info-border);

  --bs-form-valid-color: var(--success-text);
  --bs-form-valid-border-color: var(--success-solid);
  --bs-form-invalid-color: var(--danger-text);
  --bs-form-invalid-border-color: var(--danger-solid);
}

/* ---------- Components: wire Bootstrap component variables to tokens ---------- */

.card {
  --bs-card-bg: var(--surface);
  --bs-card-border-color: var(--border);
  --bs-card-border-radius: var(--radius-md);
  --bs-card-inner-border-radius: calc(var(--radius-md) - 1px);
  --bs-card-cap-bg: var(--surface-2);
  --bs-card-cap-color: var(--text);
  --bs-card-color: var(--text);
  --bs-card-spacer-y: var(--card-pad);
  --bs-card-spacer-x: var(--card-pad);
  box-shadow: var(--shadow-sm);
}

.table {
  --bs-table-color: var(--text);
  --bs-table-bg: transparent;
  --bs-table-border-color: var(--border);
  --bs-table-striped-color: var(--text);
  --bs-table-striped-bg: var(--surface-2);
  --bs-table-active-color: var(--text);
  --bs-table-active-bg: var(--brand-tint);
  --bs-table-hover-color: var(--text);
  --bs-table-hover-bg: var(--brand-tint);
}

.dropdown-menu {
  --bs-dropdown-bg: var(--surface);
  --bs-dropdown-color: var(--text);
  --bs-dropdown-border-color: var(--border);
  --bs-dropdown-border-radius: var(--radius-md);
  --bs-dropdown-link-color: var(--text);
  --bs-dropdown-link-hover-color: var(--text);
  --bs-dropdown-link-hover-bg: var(--surface-3);
  --bs-dropdown-link-active-color: var(--on-brand);
  --bs-dropdown-link-active-bg: var(--brand-red);
  --bs-dropdown-header-color: var(--text-muted);
  --bs-dropdown-divider-bg: var(--border);
  --bs-dropdown-box-shadow: var(--shadow-lg);
  --bs-dropdown-padding-y: var(--space-2);
  --bs-dropdown-item-padding-x: var(--space-4);
  --bs-dropdown-item-padding-y: var(--space-2);
}

.modal {
  --bs-modal-bg: var(--surface);
  --bs-modal-color: var(--text);
  --bs-modal-border-color: var(--border);
  --bs-modal-border-radius: var(--radius-lg);
  --bs-modal-inner-border-radius: calc(var(--radius-lg) - 1px);
  --bs-modal-header-border-color: var(--border);
  --bs-modal-footer-border-color: var(--border);
  --bs-modal-box-shadow: var(--shadow-lg);
}
.modal-backdrop { --bs-backdrop-bg: rgb(0 0 0); --bs-backdrop-opacity: 0.6; }

.list-group {
  --bs-list-group-bg: var(--surface);
  --bs-list-group-color: var(--text);
  --bs-list-group-border-color: var(--border);
  --bs-list-group-border-radius: var(--radius-md);
  --bs-list-group-action-color: var(--text);
  --bs-list-group-action-hover-color: var(--text);
  --bs-list-group-action-hover-bg: var(--surface-2);
  --bs-list-group-action-active-bg: var(--surface-3);
  --bs-list-group-action-active-color: var(--text);
  --bs-list-group-active-bg: var(--brand-red);
  --bs-list-group-active-border-color: var(--brand-red);
  --bs-list-group-active-color: var(--on-brand);
  --bs-list-group-disabled-bg: var(--surface-2);
  --bs-list-group-disabled-color: var(--text-muted);
}

.pagination {
  --bs-pagination-color: var(--text);
  --bs-pagination-bg: var(--surface);
  --bs-pagination-border-color: var(--border);
  --bs-pagination-hover-color: var(--text);
  --bs-pagination-hover-bg: var(--surface-3);
  --bs-pagination-hover-border-color: var(--border-strong);
  --bs-pagination-focus-color: var(--text);
  --bs-pagination-focus-bg: var(--surface-3);
  --bs-pagination-focus-box-shadow: var(--focus-ring);
  --bs-pagination-active-color: var(--on-brand);
  --bs-pagination-active-bg: var(--brand-red);
  --bs-pagination-active-border-color: var(--brand-red);
  --bs-pagination-disabled-color: var(--text-muted);
  --bs-pagination-disabled-bg: var(--surface-2);
  --bs-pagination-disabled-border-color: var(--border);
  --bs-pagination-border-radius: var(--radius-sm);
}

.nav-tabs {
  --bs-nav-tabs-border-color: var(--border);
  --bs-nav-tabs-link-hover-border-color: var(--border) var(--border) var(--border);
  --bs-nav-tabs-link-active-color: var(--text);
  --bs-nav-tabs-link-active-bg: var(--surface);
  --bs-nav-tabs-link-active-border-color: var(--border) var(--border) var(--surface);
  --bs-nav-link-color: var(--text-muted);
  --bs-nav-link-hover-color: var(--text);
}
.nav-pills {
  --bs-nav-pills-link-active-color: var(--on-brand);
  --bs-nav-pills-link-active-bg: var(--brand-red);
  --bs-nav-link-color: var(--text-muted);
  --bs-nav-link-hover-color: var(--text);
}

.breadcrumb {
  --bs-breadcrumb-divider-color: var(--text-muted);
  --bs-breadcrumb-item-active-color: var(--text-muted);
}

.progress {
  --bs-progress-bg: var(--surface-3);
  --bs-progress-bar-bg: var(--brand-red);
  --bs-progress-bar-color: var(--on-brand);
  --bs-progress-border-radius: var(--radius-pill);
}

.accordion {
  --bs-accordion-bg: var(--surface);
  --bs-accordion-color: var(--text);
  --bs-accordion-border-color: var(--border);
  --bs-accordion-btn-color: var(--text);
  --bs-accordion-btn-bg: var(--surface);
  --bs-accordion-active-color: var(--text);
  --bs-accordion-active-bg: var(--surface-2);
  --bs-accordion-btn-focus-box-shadow: var(--focus-ring);
}

.toast {
  --bs-toast-bg: var(--surface);
  --bs-toast-color: var(--text);
  --bs-toast-border-color: var(--border);
  --bs-toast-header-bg: var(--surface-2);
  --bs-toast-header-color: var(--text-muted);
  --bs-toast-header-border-color: var(--border);
}

.offcanvas {
  --bs-offcanvas-bg: var(--surface);
  --bs-offcanvas-color: var(--text);
  --bs-offcanvas-border-color: var(--border);
}

/* Bootstrap's close-button glyph is dark by default; invert in dark theme */
[data-bs-theme="dark"] .btn-close { filter: invert(1) grayscale(100%) brightness(200%); }

/* ===================================================================== 2. Base components ===================================================================== */
/* Arabic script must never be letter-spaced or upper-cased (breaks letter joining) */
:lang(ar) *,
[dir="rtl"] * { letter-spacing: normal !important; text-transform: none !important; }

/* =====================================================================
 *  Links & text
 * ===================================================================== */
a { color: var(--link); text-decoration: none; transition: color var(--dur-fast) var(--ease); }
a:hover { color: var(--link-hover); text-decoration: underline; text-underline-offset: 3px; }
.link { color: var(--link); margin: 0; text-decoration: underline; text-underline-offset: 3px; }
:where(p a:not(.btn):not(.dropdown-item), li a:not(.btn):not(.dropdown-item):not(.sidebar__link), .auth-card__sub a) { text-decoration: underline; text-underline-offset: 3px; }
.page-header__title a, .breadcrumb a, .result-item h2 a, .app-footer a { text-decoration: none; }
.breadcrumb a:hover { text-decoration: underline; }
.link:hover { color: var(--link-hover); }

.text-muted, .muted { color: var(--text-muted) !important; }
.text-secondary { color: var(--text-muted) !important; }
.text-primary, .primary, .primary1, .link-primary { color: var(--brand-text) !important; }
.text-danger, .danger, .title-danger { color: var(--danger-text) !important; }
.text-success, .success { color: var(--success-text) !important; }
.text-warning { color: var(--warning-text) !important; }
.text-info { color: var(--info-text) !important; }
.text-orange { color: var(--warning-text) !important; }          /* legacy utility */
.text-dark { color: var(--text) !important; }
.text-right { text-align: end !important; }
.text-left { text-align: start !important; }

.bg-white { background-color: var(--surface) !important; }
.bg-light, .bg-light-warning { background-color: var(--surface-2) !important; color: var(--text) !important; }
.bg-secondary { background-color: var(--surface-3) !important; color: var(--text) !important; }
.bg-dark { background-color: var(--sidebar-bg) !important; color: var(--sidebar-text-strong) !important; }
.bg-primary { background-color: var(--brand-red) !important; color: var(--on-brand) !important; }
.bg-orange { background-color: var(--warning-bg) !important; color: var(--warning-text) !important; }
.bg-purple { background-color: var(--info-bg) !important; color: var(--info-text) !important; }
.bg-error { background-color: var(--danger-bg) !important; }
.bg-correct { background-color: var(--success-bg) !important; }
.bg-danger { background-color: var(--danger-solid) !important; color: var(--on-brand) !important; }
.bg-success { background-color: var(--success-solid) !important; color: var(--on-brand) !important; }
.bg-info, .bg-sub-info { background-color: var(--info-solid) !important; color: var(--on-brand) !important; }
.border { border-color: var(--border) !important; }
.border-bottom, .border-top { border-color: var(--border) !important; }
hr { border-color: var(--border); opacity: 1; }
.small, small { color: inherit; }
code { color: var(--brand-text); }

/* Legacy page-title / section-title classes → current typography */
.title-1, .header-title-xl, .header-title, .header-title-md {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  margin: 0 0 var(--space-6);
  font-size: var(--fs-2xl);
  font-weight: var(--fw-bold);
  letter-spacing: -0.01em;
  color: var(--text);
  text-transform: none;
}
.title-1 > i, .header-title-xl > i { color: var(--brand-text); font-size: 0.85em; }
.header-title, .header-title-md { font-size: var(--fs-xl); }
.title-line { height: 3px; width: 56px; margin: 0 auto var(--space-5); border-radius: var(--radius-pill); background: var(--brand-red); }
.result-title { font-weight: var(--fw-bold); }

/* =====================================================================
 *  Icons — FontAwesome glyphs inherit colour/size; no circular chips
 * ===================================================================== */
.fas, .far, .fab, .fa, .fa-solid, .fa-regular, .fa-brands { line-height: 1; }
.dropdown-item > i { width: 1.25em; margin-inline-end: var(--space-2); text-align: center; color: var(--text-muted); }
.dropdown-item.text-danger > i { color: inherit; }
.fa-1-5x { font-size: 1.5em; }
.icon-chip {
  display: inline-flex; align-items: center; justify-content: center;
  width: 32px; height: 32px; border-radius: var(--radius-md);
  background: var(--brand-tint); color: var(--brand-text); flex: none;
}

/* =====================================================================
 *  Buttons
 * ===================================================================== */
.btn {
  --bs-btn-padding-x: var(--space-4);
  --bs-btn-padding-y: 0.35rem;
  --bs-btn-font-size: var(--fs-sm);
  --bs-btn-font-weight: var(--fw-medium);
  --bs-btn-border-radius: var(--radius-sm);
  --bs-btn-focus-box-shadow: var(--focus-ring);
  min-height: var(--control-h);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5em;
  line-height: 1.3;
  transition: background-color var(--dur-fast) var(--ease), border-color var(--dur-fast) var(--ease), color var(--dur-fast) var(--ease), box-shadow var(--dur-fast) var(--ease);
}
.btn:hover { text-decoration: none; }
.btn-sm { --bs-btn-padding-x: var(--space-3); --bs-btn-padding-y: 0.2rem; --bs-btn-font-size: var(--fs-xs); min-height: var(--control-h-sm); }
.btn-lg, .btn-large { --bs-btn-padding-x: var(--space-6); --bs-btn-padding-y: 0.5rem; --bs-btn-font-size: var(--fs-md); min-height: var(--control-h-lg); }
.btn-block { display: flex; width: 100%; }
.btn-rounded { border-radius: var(--radius-pill); }
@media (pointer: coarse) { .btn { min-height: var(--touch-target); } }

.btn-primary {
  --bs-btn-color: var(--on-brand);
  --bs-btn-bg: var(--brand-red);
  --bs-btn-border-color: var(--brand-red);
  --bs-btn-hover-color: var(--on-brand);
  --bs-btn-hover-bg: var(--brand-red-strong);
  --bs-btn-hover-border-color: var(--brand-red-strong);
  --bs-btn-active-color: var(--on-brand);
  --bs-btn-active-bg: var(--brand-red-deep);
  --bs-btn-active-border-color: var(--brand-red-deep);
  --bs-btn-disabled-color: var(--on-brand);
  --bs-btn-disabled-bg: var(--brand-red);
  --bs-btn-disabled-border-color: var(--brand-red);
}
.btn-outline-primary {
  --bs-btn-color: var(--brand-text);
  --bs-btn-border-color: var(--brand-text);
  --bs-btn-hover-color: var(--on-brand);
  --bs-btn-hover-bg: var(--brand-red);
  --bs-btn-hover-border-color: var(--brand-red);
  --bs-btn-active-color: var(--on-brand);
  --bs-btn-active-bg: var(--brand-red-strong);
  --bs-btn-active-border-color: var(--brand-red-strong);
  --bs-btn-disabled-color: var(--text-muted);
  --bs-btn-disabled-border-color: var(--border);
}
/* Neutral buttons (secondary / light / dark / default .btn) */
.btn-secondary, .btn-light, .btn-dark, .btn-outline-secondary, .btn-outline-dark, .btn-outline-white {
  --bs-btn-color: var(--text);
  --bs-btn-bg: var(--surface);
  --bs-btn-border-color: var(--border-strong);
  --bs-btn-hover-color: var(--text);
  --bs-btn-hover-bg: var(--surface-3);
  --bs-btn-hover-border-color: var(--border-strong);
  --bs-btn-active-color: var(--text);
  --bs-btn-active-bg: var(--surface-3);
  --bs-btn-active-border-color: var(--border-strong);
  --bs-btn-disabled-color: var(--text-muted);
  --bs-btn-disabled-bg: var(--surface-2);
  --bs-btn-disabled-border-color: var(--border);
}
.btn-dark { --bs-btn-bg: var(--surface-3); }
/* Soft semantic buttons (AA text on tinted background) */
.btn-success, .btn-warning, .btn-info, .btn-danger, .btn-outline-danger, .btn-outline-success {
  --_c: var(--success-text); --_bg: var(--success-bg); --_bd: var(--success-border);
  --bs-btn-color: var(--_c);
  --bs-btn-bg: var(--_bg);
  --bs-btn-border-color: var(--_bd);
  --bs-btn-hover-color: var(--_c);
  --bs-btn-hover-bg: var(--_bg);
  --bs-btn-hover-border-color: var(--_c);
  --bs-btn-active-color: var(--_c);
  --bs-btn-active-bg: var(--_bg);
  --bs-btn-active-border-color: var(--_c);
}
.btn-warning { --_c: var(--warning-text); --_bg: var(--warning-bg); --_bd: var(--warning-border); }
.btn-info { --_c: var(--info-text); --_bg: var(--info-bg); --_bd: var(--info-border); }
.btn-danger, .btn-outline-danger { --_c: var(--danger-text); --_bg: var(--danger-bg); --_bd: var(--danger-border); }
.btn-link { --bs-btn-color: var(--link); --bs-btn-hover-color: var(--link-hover); }
.btn-close:focus { box-shadow: var(--focus-ring); }

/* Table / list action icons (legacy .update / .delete / .download-btn) */
.update-delete { display: inline-flex; gap: var(--space-1); }
.update-delete a, .update-delete button, .download-btn, .edit-btn {
  display: inline-flex; align-items: center; justify-content: center; gap: var(--space-1);
  min-width: var(--control-h-sm); min-height: var(--control-h-sm); padding: 0 var(--space-3);
  border-radius: var(--radius-sm); border: 1px solid var(--border);
  background: var(--surface); color: var(--text); font-size: var(--fs-sm); font-weight: var(--fw-medium);
}
.update-delete a:hover, .update-delete button:hover, .download-btn:hover, .edit-btn:hover { background: var(--surface-3); text-decoration: none; color: var(--text); }
.update-delete a.delete, .update-delete button.delete { color: var(--danger-text); cursor: pointer; }
.update-delete a.delete:hover, .update-delete button.delete:hover { background: var(--danger-bg); border-color: var(--danger-border); }
.update-delete a.update { color: var(--info-text); }
.update-delete a.update:hover { background: var(--info-bg); border-color: var(--info-border); }

/* =====================================================================
 *  Cards
 * ===================================================================== */
.card { overflow: hidden; }
.card-header { font-weight: var(--fw-semibold); border-block-end: 1px solid var(--border); }
.card-footer { background: var(--surface-2); border-block-start: 1px solid var(--border); }
.card-title { font-weight: var(--fw-semibold); }
.card.card-hover { transition: border-color var(--dur) var(--ease), box-shadow var(--dur) var(--ease), transform var(--dur) var(--ease); }
.card.card-hover:hover { border-color: var(--border-strong); box-shadow: var(--shadow-md); }
/* Legacy section header bar ("form-title") → quiet card header */
.form-title {
  display: flex; align-items: center; gap: var(--space-2);
  margin: 0;
  padding: var(--space-3) var(--card-pad);
  font-size: var(--fs-md); font-weight: var(--fw-semibold);
  background: var(--surface-2); color: var(--text);
  border: 1px solid var(--border); border-block-end: 0;
  border-start-start-radius: var(--radius-md); border-start-end-radius: var(--radius-md);
}
.form-title > i { color: var(--brand-text); }
.card > .form-title { border: 0; border-block-end: 1px solid var(--border); border-radius: 0; }
.form-title + .table-responsive, .form-title + .table-shadow { margin-block-start: 0; }
.news, .events { background: var(--surface-2) !important; color: var(--text) !important; }

/* Stat card (dashboard) */
.stat-card { display: flex; flex-direction: row; align-items: center; gap: var(--space-3); padding: var(--card-pad); height: 100%; }
.stat-card__icon { width: 36px; height: 36px; border-radius: var(--radius-md); display: inline-flex; align-items: center; justify-content: center; font-size: var(--fs-lg); flex: none; background: var(--brand-tint); color: var(--brand-text); }
.stat-card__label { margin: 0; font-size: var(--fs-sm); color: var(--text-muted); }
.stat-card__value { margin: 0; font-size: var(--fs-3xl); font-weight: var(--fw-bold); line-height: 1.1; font-variant-numeric: tabular-nums; }
.stat-card--info .stat-card__icon { background: var(--info-bg); color: var(--info-text); }
.stat-card--success .stat-card__icon { background: var(--success-bg); color: var(--success-text); }
.stat-card--warning .stat-card__icon { background: var(--warning-bg); color: var(--warning-text); }

/* =====================================================================
 *  Forms
 * ===================================================================== */
.form-label, label { font-size: var(--fs-sm); font-weight: var(--fw-medium); color: var(--text); margin-block-end: var(--space-2); }
.form-control, .form-select, .au-input, select, textarea, input[type="text"], input[type="email"], input[type="password"], input[type="number"], input[type="date"], input[type="search"], input[type="url"], input[type="tel"] {
  font-family: inherit;
}
.form-control, .form-select, .au-input {
  min-height: var(--control-h);
  padding: 0.35rem 0.7rem;
  font-size: var(--fs-md);
  color: var(--text);
  background-color: var(--surface);
  border: 1px solid var(--border-input);
  border-radius: var(--radius-sm);
  box-shadow: none;
}
.form-control::placeholder, .au-input::placeholder { color: var(--text-muted); opacity: 0.85; }
.form-control:hover:not(:disabled):not(:focus), .form-select:hover:not(:disabled):not(:focus) { border-color: var(--text-muted); }
.form-control:focus, .form-select:focus, .au-input:focus { background-color: var(--surface); color: var(--text); border-color: var(--focus); box-shadow: var(--focus-ring); outline: 0; }
.form-control:disabled, .form-control[readonly], .form-select:disabled { background-color: var(--surface-2); color: var(--text-muted); opacity: 1; }
textarea.form-control { min-height: 88px; }
.form-select { background-position: right 0.75rem center; }
[dir="rtl"] .form-select { background-position: left 0.75rem center; padding-inline-end: 0.8rem; padding-inline-start: 2.25rem; }
[data-bs-theme="dark"] .form-select {
  --bs-form-select-bg-img: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'%3e%3cpath fill='none' stroke='%23a7abb4' stroke-linecap='round' stroke-linejoin='round' stroke-width='2' d='m2 5 6 6 6-6'/%3e%3c/svg%3e");
}
.form-text, .helptext, .form-group small { color: var(--text-muted); font-size: var(--fs-sm); }
.form-group { margin-block-end: var(--space-4); }
.form-check-input { background-color: var(--surface); border-color: var(--border-input); }
.form-check-input:checked { background-color: var(--brand-red); border-color: var(--brand-red); }
.form-check-input:focus { border-color: var(--focus); box-shadow: var(--focus-ring); }
.form-check-label { font-weight: var(--fw-regular); margin: 0; }
.input-group-text { background: var(--surface-2); color: var(--text-muted); border: 1px solid var(--border-input); }
.input-group > .btn { min-height: var(--control-h); }
.input-group-prepend { display: contents; }
.is-invalid, .was-validated :invalid { border-color: var(--danger-solid) !important; }
.invalid-feedback, .errorlist, .text-danger.small { color: var(--danger-text); font-size: var(--fs-sm); }
.errorlist { list-style: none; padding: 0; margin: var(--space-1) 0 0; }
.asteriskField { color: var(--brand-text); margin-inline-start: 2px; }
.form-box { padding: var(--card-pad); background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-md); }
.form-group-no-border { border: 0; }
input[type="file"].form-control { padding: 0.3rem 0.5rem; }
input[type="file"]::file-selector-button { margin-inline-end: var(--space-3); padding: 0.2rem 0.7rem; border: 1px solid var(--border-strong); border-radius: var(--radius-sm); background: var(--surface-3); color: var(--text); font-weight: var(--fw-medium); cursor: pointer; }
input[type="checkbox"], input[type="radio"] { accent-color: var(--brand-red); }

/* Bare Django widgets (rendered without .form-control) get the same look */
:where(form) :where(input:not([type]), input[type="text"], input[type="email"], input[type="password"], input[type="number"], input[type="date"], input[type="time"], input[type="datetime-local"], input[type="search"], input[type="url"], input[type="tel"], select, textarea):not(.form-control):not(.form-select):not(.au-input) {
  min-height: var(--control-h); padding: 0.35rem 0.7rem; font-size: var(--fs-md); color: var(--text);
  background-color: var(--surface); border: 1px solid var(--border-input); border-radius: var(--radius-sm);
}
:where(form) :where(input, select, textarea):not(.form-control):not(.form-select):focus { border-color: var(--focus); box-shadow: var(--focus-ring); outline: 0; }
.auth-card :where(input:not([type="checkbox"]):not([type="radio"]):not([type="submit"]), select, textarea) { width: 100%; }

/* Switch (legacy .switch markup, restyled with tokens) */
.switch { position: relative; display: inline-block; vertical-align: middle; width: 48px; height: 26px; margin: 0; }
.switch .switch-input { position: absolute; inset: 0; opacity: 0; width: 100%; height: 100%; margin: 0; cursor: pointer; z-index: 2; }
.switch .switch-label { position: absolute; inset: 0; margin: 0; border-radius: var(--radius-pill); background: var(--surface-3); border: 1px solid var(--border-strong); transition: background-color var(--dur) var(--ease); }
.switch .switch-label::before, .switch .switch-label::after { content: none !important; }
.switch .switch-handle { position: absolute; inset-block-start: 3px; inset-inline-start: 3px; width: 18px; height: 18px; border-radius: 50%; background: var(--text-muted); transition: transform var(--dur) var(--ease), background-color var(--dur) var(--ease); }
.switch .switch-input:checked ~ .switch-label { background: var(--brand-red); border-color: var(--brand-red); }
.switch .switch-input:checked ~ .switch-handle { transform: translateX(22px); background: var(--on-brand); }
[dir="rtl"] .switch .switch-input:checked ~ .switch-handle { transform: translateX(-22px); }
.switch .switch-input:focus-visible ~ .switch-label { box-shadow: var(--focus-ring); }

/* =====================================================================
 *  Tables
 * ===================================================================== */
.table { margin-block-end: 0; font-size: var(--fs-sm); vertical-align: middle; }
.table > :not(caption) > * > * { padding: 0.7rem var(--space-3); border-bottom-color: var(--border); background-color: var(--bs-table-bg); }
.table > thead > tr > th {
  background: var(--surface-2);
  color: var(--text-muted);
  font-size: var(--fs-xs);
  font-weight: var(--fw-semibold);
  letter-spacing: 0.05em;
  text-transform: uppercase;
  white-space: nowrap;
  border-bottom: 1px solid var(--border-strong);
}
.table > tbody > tr { transition: background-color var(--dur-fast) var(--ease); }
.table > tbody > tr > td > a:not(.btn):not(.dropdown-item) { display: inline; padding: 0; font-weight: var(--fw-medium); }
.table > tbody > tr:last-child > * { border-bottom: 0; }
.table-light, .table-light > * > * { --bs-table-bg: transparent; --bs-table-color: var(--text); }
.table-dark { --bs-table-bg: var(--sidebar-bg); --bs-table-color: var(--sidebar-text-strong); }
.table-bordered > :not(caption) > * > * { border-inline: 1px solid var(--border); }
.table-striped > tbody > tr:nth-of-type(odd) > * { --bs-table-bg-type: var(--surface-2); color: var(--text); }
.table .success, .table tr.success > td { background: var(--success-bg) !important; color: var(--text); }
.table-warning { --bs-table-bg: var(--warning-bg); --bs-table-color: var(--text); }
.table-success { --bs-table-bg: var(--success-bg); --bs-table-color: var(--text); }
.table-danger { --bs-table-bg: var(--danger-bg); --bs-table-color: var(--text); }
.table-info { --bs-table-bg: var(--info-bg); --bs-table-color: var(--text); }
.table input { max-width: 130px; }

/* Responsive tables: legacy wrappers become a bordered card */
.table-responsive, .table-shadow {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-sm);
  -webkit-overflow-scrolling: touch;
}
.table-responsive > .table-shadow, .table-shadow > .table-shadow, .table-responsive .table-responsive { border: 0; box-shadow: none; border-radius: 0; }
.table-responsive > .table, .table-shadow > .table { margin: 0; }
.form-title + .table-responsive { border-start-start-radius: 0; border-start-end-radius: 0; }
.table-title { margin: var(--space-4) 0; font-size: var(--fs-md); font-weight: var(--fw-semibold); color: var(--text); text-transform: none; padding: 0; }
.table-responsive:focus-visible { outline: 2px solid var(--focus); }

/* Stacked "card rows" for small screens: opt-in with .table-stack */
@media (max-width: 575.98px) {
  .table-stack thead { display: none; }
  .table-stack tbody tr { display: block; padding: var(--space-3) var(--space-4); border-bottom: 1px solid var(--border); }
  .table-stack tbody td { display: flex; justify-content: space-between; gap: var(--space-4); padding: var(--space-1) 0 !important; border: 0 !important; text-align: end; }
  .table-stack tbody td::before { content: attr(data-label); color: var(--text-muted); font-weight: var(--fw-medium); text-align: start; }
}

/* =====================================================================
 *  Badges / pills
 * ===================================================================== */
.badge { font-weight: var(--fw-semibold); font-size: var(--fs-xs); padding: 0.35em 0.7em; border-radius: var(--radius-pill); border: 1px solid transparent; }
.badge.bg-primary, .badge.text-bg-primary { background: var(--brand-tint-strong) !important; color: var(--brand-text) !important; }
.badge.bg-secondary, .badge.text-bg-secondary { background: var(--surface-3) !important; color: var(--text) !important; border-color: var(--border); }
.badge.bg-success, .badge.text-bg-success { background: var(--success-bg) !important; color: var(--success-text) !important; border-color: var(--success-border); }
.badge.bg-warning, .badge.text-bg-warning { background: var(--warning-bg) !important; color: var(--warning-text) !important; border-color: var(--warning-border); }
.badge.bg-danger, .badge.text-bg-danger { background: var(--danger-bg) !important; color: var(--danger-text) !important; border-color: var(--danger-border); }
.badge.bg-info, .badge.text-bg-info { background: var(--info-bg) !important; color: var(--info-text) !important; border-color: var(--info-border); }
.badge.bg-light, .badge.text-bg-light, .badge.bg-dark { background: var(--surface-3) !important; color: var(--text) !important; border-color: var(--border); }
.badge-dot::before { content: ""; display: inline-block; width: 6px; height: 6px; margin-inline-end: 6px; border-radius: 50%; background: currentColor; }
.color-indicator { display: inline-block; width: 10px; height: 10px; border-radius: 3px; vertical-align: baseline; }

/* =====================================================================
 *  Alerts & toasts
 * ===================================================================== */
.alert {
  --bs-alert-padding-x: var(--space-4);
  --bs-alert-padding-y: var(--space-3);
  --bs-alert-border-radius: var(--radius-md);
  display: flex; align-items: flex-start; gap: var(--space-3);
  border-width: 1px; border-style: solid;
  font-size: var(--fs-sm);
}
.alert > i { margin-block-start: 0.2em; flex: none; }
.alert > .alert-body { flex: 1 1 auto; min-width: 0; }
.alert-success { background: var(--success-bg); border-color: var(--success-border); color: var(--success-text); }
.alert-warning { background: var(--warning-bg); border-color: var(--warning-border); color: var(--warning-text); }
.alert-info { background: var(--info-bg); border-color: var(--info-border); color: var(--info-text); }
.alert-danger, .alert-error { background: var(--danger-bg); border-color: var(--danger-border); color: var(--danger-text); }
.alert a { color: inherit; text-decoration: underline; font-weight: var(--fw-medium); }
.alert p:last-child { margin-bottom: 0; }

.toast-region {
  position: fixed;
  inset-block-start: calc(var(--topbar-height) + var(--space-3));
  inset-inline-end: var(--space-4);
  z-index: 1090;
  display: flex; flex-direction: column; gap: var(--space-2);
  width: min(380px, calc(100vw - 2 * var(--space-4)));
  pointer-events: none;
}
.toast-item {
  pointer-events: auto;
  display: flex; align-items: flex-start; gap: var(--space-3);
  padding: var(--space-3) var(--space-4);
  background: var(--surface); color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-lg);
  font-size: var(--fs-sm);
  animation: toast-in var(--dur) var(--ease);
}
.toast-item i { margin-block-start: 0.2em; }
.toast-item--success i { color: var(--success-text); }
.toast-item--warning i { color: var(--warning-text); }
.toast-item--error i { color: var(--danger-text); }
.toast-item--info i { color: var(--info-text); }
.toast-item__body { flex: 1; min-width: 0; }
.toast-item__close { background: none; border: 0; padding: 2px 6px; color: var(--text-muted); border-radius: var(--radius-sm); cursor: pointer; }
.toast-item__close:hover { color: var(--text); background: var(--surface-3); }
.toast-item.is-leaving { opacity: 0; transform: translateY(-6px); transition: opacity var(--dur) var(--ease), transform var(--dur) var(--ease); }
@keyframes toast-in { from { opacity: 0; transform: translateY(-8px); } to { opacity: 1; transform: none; } }

/* =====================================================================
 *  Dropdowns, modals, tabs, breadcrumbs, pagination, list groups
 * ===================================================================== */
.dropdown-menu { padding-block: var(--space-2); font-size: var(--fs-sm); margin-block-start: var(--space-1) !important; }
.dropdown-item { display: flex; align-items: center; border-radius: var(--radius-sm); margin-inline: var(--space-2); width: auto; padding-block: 0.5rem; }
.dropdown-item.active, .dropdown-item[aria-checked="true"] { background: var(--brand-tint-strong); color: var(--brand-text); font-weight: var(--fw-medium); }
.dropdown-item[aria-checked="true"]::after { content: "\f00c"; font-family: "Font Awesome 6 Free"; font-weight: 900; margin-inline-start: auto; padding-inline-start: var(--space-3); }
.dropdown-item:focus-visible { outline-offset: -2px; }
.dropdown-item.text-danger:hover { background: var(--danger-bg); }
.dropdown-header { font-size: var(--fs-xs); text-transform: uppercase; letter-spacing: 0.06em; }

.modal-header, .modal-footer { padding: var(--space-4) var(--space-5); }
.modal-body { padding: var(--space-5); }
.modal-title { font-weight: var(--fw-semibold); }

.nav-tabs { border-block-end: 1px solid var(--border); gap: var(--space-1); }
.nav-tabs .nav-link { border: 0; border-block-end: 2px solid transparent; border-radius: 0; padding: var(--space-3) var(--space-4); font-weight: var(--fw-medium); color: var(--text-muted); margin-block-end: -1px; background: transparent; }
.nav-tabs .nav-link:hover { color: var(--text); border-block-end-color: var(--border-strong); }
.nav-tabs .nav-link.active { color: var(--brand-text); background: transparent; border-block-end-color: var(--brand-red); }
.nav-pills .nav-link { border-radius: var(--radius-sm); font-weight: var(--fw-medium); }
.nav-pills .nav-link:not(.active):hover { background: var(--surface-3); color: var(--text); }
.tab-content { padding-block-start: var(--space-5); }

.breadcrumb { --bs-breadcrumb-divider: "›"; flex-wrap: wrap; row-gap: var(--space-1); margin: 0 0 var(--space-2); padding: 0; font-size: var(--fs-xs); background: transparent; }
[dir="rtl"] .breadcrumb { --bs-breadcrumb-divider: "‹"; }
.breadcrumb-item a { color: var(--text-muted); }
.breadcrumb-item a:hover { color: var(--text); }
.breadcrumb-item.active { color: var(--text); font-weight: var(--fw-medium); }
.breadcrumb-item + .breadcrumb-item::before { color: var(--text-muted); }
nav[aria-label="breadcrumb"] { --bs-breadcrumb-divider: "›" !important; }
[dir="rtl"] nav[aria-label="breadcrumb"] { --bs-breadcrumb-divider: "‹" !important; }

.pagination { gap: var(--space-1); flex-wrap: wrap; }
/* Legacy hand-written pagination (<div class="pagination"><a>…) */
.content-center { display: flex; justify-content: center; margin-block: var(--space-6); }
.pagination > a { display: inline-flex; align-items: center; justify-content: center; min-width: 38px; min-height: 38px; padding: 0 var(--space-3); border: 1px solid var(--border); border-radius: var(--radius-sm); background: var(--surface); color: var(--text); font-size: var(--fs-sm); font-weight: var(--fw-medium); }
.pagination > a:hover { background: var(--surface-3); text-decoration: none; color: var(--text); }
.pagination > a.pagination-active { background: var(--brand-red); border-color: var(--brand-red); color: var(--on-brand); }
.page-link { border-radius: var(--radius-sm) !important; min-width: 38px; text-align: center; font-size: var(--fs-sm); font-weight: var(--fw-medium); }
.pagination-active, .page-item.active .page-link { background: var(--brand-red); border-color: var(--brand-red); color: var(--on-brand); }

.list-group-item { padding: var(--space-3) var(--space-4); }
.well { padding: var(--space-4); background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--radius-md); }

/* =====================================================================
 *  Progress, loading, empty states
 * ===================================================================== */
.progress { height: 8px; }
.progress-bar { background-color: var(--brand-red); }
.progress-bar-striped { background-image: linear-gradient(45deg, rgba(255,255,255,.18) 25%, transparent 25%, transparent 50%, rgba(255,255,255,.18) 50%, rgba(255,255,255,.18) 75%, transparent 75%, transparent); background-size: 1rem 1rem; }
.progress--lg { height: 12px; }

.spinner-border { color: var(--brand-red); }
.skeleton { display: block; border-radius: var(--radius-sm); background: linear-gradient(90deg, var(--surface-3) 25%, var(--surface-2) 37%, var(--surface-3) 63%); background-size: 400% 100%; animation: skeleton 1.4s ease infinite; min-height: 1em; }
@keyframes skeleton { from { background-position: 100% 50%; } to { background-position: 0 50%; } }
@media (prefers-reduced-motion: reduce) { .skeleton { animation: none; } }

.empty-state { text-align: center; padding: var(--space-8) var(--space-4); color: var(--text-muted); }
.empty-state__icon { display: inline-flex; align-items: center; justify-content: center; width: 48px; height: 48px; margin-block-end: var(--space-3); border-radius: 50%; background: var(--brand-tint); color: var(--brand-text); font-size: var(--fs-xl); }
.empty-state__title { margin: 0 0 var(--space-1); font-size: var(--fs-md); font-weight: var(--fw-semibold); color: var(--text); }
.empty-state__text { margin: 0 auto var(--space-4); max-width: 46ch; }

/* =====================================================================
 *  Avatar
 * ===================================================================== */
.avatar { display: inline-flex; width: 32px; height: 32px; border-radius: 50%; overflow: hidden; background: var(--surface-3); border: 2px solid var(--border); flex: none; }
.avatar img { width: 100%; height: 100%; object-fit: cover; }
.avatar-md { width: 48px; height: 48px; }
.avatar-lg { width: 80px; height: 80px; }

/* =====================================================================
 *  Theme toggle / language select / search (top bar controls)
 * ===================================================================== */
.icon-btn {
  display: inline-flex; align-items: center; justify-content: center;
  width: var(--control-h); height: var(--control-h); padding: 0;
  border: 1px solid transparent; border-radius: var(--radius-sm);
  background: transparent; color: var(--text-muted);
  transition: background-color var(--dur-fast) var(--ease), color var(--dur-fast) var(--ease), border-color var(--dur-fast) var(--ease);
  cursor: pointer;
}
.icon-btn:hover { background: var(--surface-3); color: var(--text); }
.icon-btn.show { background: var(--surface-3); color: var(--text); }
@media (pointer: coarse) { .icon-btn { width: var(--touch-target); height: var(--touch-target); } }

.theme-toggle .theme-icon { display: none; }
html[data-theme-pref="light"] .theme-toggle .theme-icon--light,
html[data-theme-pref="dark"] .theme-toggle .theme-icon--dark,
html[data-theme-pref="system"] .theme-toggle .theme-icon--system { display: inline-block; }

.lang-select { min-height: var(--control-h); padding: 0.35rem 2rem 0.35rem 0.7rem; font-size: var(--fs-sm); font-weight: var(--fw-medium); color: var(--text); background-color: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-sm); max-width: 150px; }
[dir="rtl"] .lang-select { padding: 0.35rem 0.7rem 0.35rem 2rem; }

.search-field { position: relative; display: flex; }
.search-field .form-control { padding-inline-start: 2.5rem; background: var(--surface-2); border-color: var(--border); }
.search-field__icon { position: absolute; inset-block: 0; inset-inline-start: var(--space-3); display: flex; align-items: center; color: var(--text-muted); pointer-events: none; }
.search-field .form-control:focus { background: var(--surface); }

.user-chip { display: inline-flex; align-items: center; gap: var(--space-2); padding: 3px; padding-inline-end: var(--space-3); border-radius: var(--radius-pill); border: 1px solid var(--border); background: var(--surface); color: var(--text); font-size: var(--fs-sm); font-weight: var(--fw-medium); cursor: pointer; }
.user-chip:hover { background: var(--surface-3); }
.user-chip .avatar { width: 28px; height: 28px; border-width: 1px; }
.user-menu { min-width: 16rem; }
.user-menu__head { padding: var(--space-3) var(--space-4); }
.user-menu__name { font-weight: var(--fw-semibold); margin: 0; }
.user-menu__meta { margin: 0; font-size: var(--fs-xs); color: var(--text-muted); }

/* Status icons inside tables / lists */
.table .fa-check-circle, .table .fa-circle-check { color: var(--success-text); }
.table .fa-times-circle, .table .fa-circle-xmark { color: var(--danger-text); }
.table i.primary { font-style: normal; font-weight: var(--fw-semibold); font-size: inherit !important; }
.table .dropstart > .btn, .table .dropdown > .btn { color: var(--text-muted); }
.table .dropstart > .btn:hover, .table .dropdown > .btn:hover { background: var(--surface-3); color: var(--text); }

/* Button rows inside forms (e.g. Save … Cancel) */
.form-group:has(> .btn) { display: flex; flex-wrap: wrap; align-items: center; gap: var(--space-3); margin-block-start: var(--space-4); }
.form-group > .btn + .btn { margin-inline-start: auto; }

/* Legacy small label / pill (.info-text) */
.info-text { display: inline-block; padding: 0.15rem 0.6rem; border-radius: var(--radius-pill); background: var(--surface-3); color: var(--text); font-size: var(--fs-xs); font-style: normal; font-weight: var(--fw-semibold); border: 1px solid var(--border); }
.info-text.title-danger { background: var(--danger-bg); color: var(--danger-text); border-color: var(--danger-border); }
.dashboard-description p { margin-block-end: var(--space-2); }

/* Destructive actions are POST forms (CSRF-protected); render them inline like the links they replaced */
.inline-form { display: inline; margin: 0; }
li > .inline-form, .dropdown-menu > .inline-form { display: block; }
button.dropdown-item { background: none; border: 0; text-align: start; width: calc(100% - 2 * var(--space-2)); cursor: pointer; }

/* Student approvals: status tabs use the themed tab look without link underlines */
.nav-tabs li a.nav-link:not(.btn):not(.dropdown-item):not(.sidebar__link), .pagination li a.page-link:not(.btn):not(.dropdown-item):not(.sidebar__link) { text-decoration: none; }

/* Busy state of a submit button while its form is being sent (static/js/main.js) */
.btn.is-busy, input.is-busy { cursor: progress; opacity: 0.85; }
.btn.is-busy::before {
  content: ""; display: inline-block; width: 0.9em; height: 0.9em; margin-inline-end: 0.5em; vertical-align: -0.1em;
  border: 2px solid currentColor; border-inline-end-color: transparent; border-radius: 50%;
  animation: btn-busy-spin 0.7s linear infinite;
}
@keyframes btn-busy-spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .btn.is-busy::before { animation: none; } }

/* ===================================================================== 3. Forms: sections, grid, action bar ===================================================================== */
/* ---------- 3. Forms: sections, grid, action bar ---------- */
.form-card { overflow: visible; }
.form-card > .form-title { border-start-start-radius: var(--radius-md); border-start-end-radius: var(--radius-md); }
.form-card__body { padding: var(--card-pad) var(--space-5); display: grid; gap: var(--space-5); }
.form-section { margin: 0; padding: 0 0 var(--space-5); border: 0; border-block-end: 1px solid var(--border); min-width: 0; }
.form-section:last-of-type { padding-block-end: 0; border-block-end: 0; }
.form-section__title {
  float: none; width: auto; display: flex; align-items: center; gap: var(--space-2);
  margin: 0 0 var(--space-4); padding: 0;
  font-size: var(--fs-md); font-weight: var(--fw-semibold); color: var(--text);
}
.form-section__title > i { color: var(--brand-text); width: 1.25em; text-align: center; }
/* crispy wraps each field in .mb-3: the grid gap already provides the vertical rhythm */
.form-section .row > [class*="col"] > .mb-3,
.form-section > .mb-3 { margin-block-end: 0 !important; }
.form-section .form-label, .form-section label.form-label, .form-section .form-label.requiredField, .form-section legend.col-form-label { margin-block-end: var(--space-2); padding: 0; font-size: var(--fs-sm); font-weight: var(--fw-medium); float: none; width: auto; }
.form-section .form-text, .form-section small.form-text { display: block; margin-block-start: var(--space-2); line-height: 1.45; }
.form-section .invalid-feedback, .form-section .text-danger { margin-block-start: var(--space-2); font-size: var(--fs-sm); }
.form-section .form-check { display: flex; flex-wrap: wrap; align-items: flex-start; gap: var(--space-1) var(--space-3); padding-inline-start: 0; margin: 0; }
.form-section .form-check > .form-text { flex: 1 1 100%; margin-block-start: 0; margin-inline-start: calc(1.15rem + var(--space-3)); }
.form-section .form-check-input { flex: none; float: none; margin: 0.2rem 0 0; width: 1.15rem; height: 1.15rem; }
.form-section .form-check-label { font-weight: var(--fw-medium); }
.form-section .form-check .form-text { margin-block-start: var(--space-1); }
.form-section .form-select, .form-section .form-control { width: 100%; }
/* identifiers and secrets are always typed left-to-right, whatever the page direction */
input[type="tel"], input[name$="phone"], input[name$="username"], input[type="password"], input[name$="whatsapp"] { direction: ltr; }
[dir="rtl"] input[type="tel"]::placeholder, [dir="rtl"] input[name$="phone"]::placeholder { text-align: end; }
[dir="rtl"] input[type="tel"], [dir="rtl"] input[name$="phone"], [dir="rtl"] input[name$="username"],
[dir="rtl"] input[type="password"], [dir="rtl"] input[name$="whatsapp"] { text-align: start; }
.form-actions {
  display: flex; flex-wrap: wrap; align-items: center; gap: var(--space-3);
  padding: var(--space-3) var(--space-5);
  background: var(--surface-2); border-block-start: 1px solid var(--border);
  position: sticky; inset-block-end: 0; z-index: 2;
}
.form-actions .btn { min-width: 120px; }
.form-card .alert { margin: 0; }
.form-card .form-select { padding-inline-end: 2.25rem; }

.account-chip { display: flex; align-items: center; gap: var(--space-3); padding: var(--space-4) var(--space-5); background: var(--surface-2); border-block-end: 1px solid var(--border); }
.account-chip__avatar { flex: none; width: 36px; height: 36px; border-radius: 50%; display: inline-flex; align-items: center; justify-content: center; background: var(--brand-tint); color: var(--brand-text); }
.account-chip__text { display: flex; flex-direction: column; min-width: 0; line-height: 1.35; }
.account-chip__text strong, .account-chip__text span { overflow-wrap: anywhere; }

@media (max-width: 575.98px) {
  .form-card__body { padding: var(--space-4); gap: var(--space-5); }
  .form-actions { padding: var(--space-4); }
  .form-actions .btn { flex: 1 1 100%; }
  .account-chip { padding: var(--space-4); }
}


/* ===================================================================== 4. Data tables ===================================================================== */
/* ---------- 5. Admin tables ---------- */
.table td .badge { vertical-align: middle; }
.table td .cell-value { display: inline-flex; align-items: center; flex-wrap: wrap; gap: var(--space-2); }
@media (max-width: 767.98px) { .table-stack td .cell-value { justify-content: flex-end; } }
.table td .cell-id, .table td .cell-ltr { font-variant-numeric: tabular-nums; direction: ltr; unicode-bidi: isolate; display: inline-block; }
.table td .dropdown > .btn-icon-only, .btn-icon-only { width: var(--control-h-sm); min-width: var(--control-h-sm); padding: 0; }
.table td.cell-actions { white-space: nowrap; }
.table td.cell-actions > * { margin-inline-end: var(--space-1); }
.table td { overflow-wrap: anywhere; }
.table .dropdown-menu { min-width: 14rem; padding-block: var(--space-2); }
.table .dropdown-item { display: flex; align-items: center; gap: var(--space-3); padding: var(--space-1) var(--space-3); min-height: var(--control-h); }
.table .dropdown-item > i { width: 1.1em; text-align: center; color: var(--text-muted); flex: none; }
.table .dropdown-item.text-danger > i { color: inherit; }
.table .dropdown-divider { margin-block: var(--space-2); }
.table .inline-form { margin: 0; }
.table .inline-form .dropdown-item { width: 100%; background: none; border: 0; text-align: start; }
/* the action menu can never be clipped by the table's scroll container */
.table-responsive { overflow-x: auto; }
.table-responsive .dropdown-menu.position-fixed { z-index: 1055; }

/* Phones & small tablets: every row becomes a labelled card, so no column (and no action button) is ever
   hidden behind a sideways scroll. Opt-in with .table-stack + data-label on each cell. */
@media (max-width: 767.98px) {
  .table-responsive:has(> .table-stack) { overflow: visible; background: transparent; border: 0; box-shadow: none; }
  .table-stack, .table-stack tbody { display: block; width: 100%; }
  .table-stack thead { display: none; }
  .table-stack tbody tr {
    display: grid; gap: var(--space-2); padding: var(--space-4);
    margin-block-end: var(--space-3);
    background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-md); box-shadow: var(--shadow-sm);
  }
  .table-stack tbody tr:last-child { margin-block-end: 0; }
  .table-stack tbody td {
    display: flex; align-items: center; justify-content: space-between; gap: var(--space-4);
    padding: var(--space-1) 0 !important; border: 0 !important; text-align: end; background: transparent !important;
    min-width: 0;
  }
  .table-stack tbody td::before {
    content: attr(data-label); flex: none; max-width: 40%;
    color: var(--text-muted); font-size: var(--fs-xs); font-weight: var(--fw-semibold); text-align: start;
    text-transform: uppercase; letter-spacing: 0.04em;
  }
  .table-stack tbody td[data-label=""]::before, .table-stack tbody td:not([data-label])::before { content: none; }
  .table-stack tbody td:not([data-label]) { display: block; text-align: start; }
  .table-stack tbody td[data-label="#"] { display: none; }
  .table-stack tbody td:last-child { margin-block-start: var(--space-2); padding-block-start: var(--space-3) !important; border-block-start: 1px solid var(--border) !important; justify-content: flex-end; }
  .table-stack tbody td:last-child::before { margin-inline-end: auto; }
  .table-stack td.cell-actions { white-space: normal; flex-wrap: wrap; justify-content: flex-end; }
  .table-stack .dropdown-menu { position: absolute; }
}


/* ===================================================================== 5. Surface layering, buttons, KPI, cards ===================================================================== */
/* ---------- 1. Surface layering ---------- */
.card { box-shadow: var(--surface-shadow); }
.card > .form-title,
.card > .card-head { background: var(--surface-2); }

.count-pill {
  display: inline-flex; align-items: center; min-height: 24px; padding: 0 var(--space-2);
  border-radius: var(--radius-pill); border: 1px solid var(--border);
  background: var(--surface-3); color: var(--text-muted);
  font-size: var(--fs-xs); font-weight: var(--fw-semibold); font-variant-numeric: tabular-nums; letter-spacing: 0;
}

/* ---------- 3. Buttons ---------- */
.btn > i { font-size: 0.95em; }
.btn:active:not(:disabled):not(.disabled) { transform: translateY(1px); }
.btn-primary { box-shadow: 0 1px 0 rgba(0, 0, 0, 0.18); }
.btn-secondary:hover:not(:disabled):not(.disabled) { border-color: var(--text-muted); }
.btn-ghost {
  --bs-btn-color: var(--text-muted); --bs-btn-bg: transparent; --bs-btn-border-color: transparent;
  --bs-btn-hover-color: var(--text); --bs-btn-hover-bg: var(--surface-3); --bs-btn-hover-border-color: transparent;
  --bs-btn-active-color: var(--text); --bs-btn-active-bg: var(--surface-3); --bs-btn-active-border-color: transparent;
}
.icon-btn:active { transform: translateY(1px); }
.icon-btn--sm { width: var(--control-h-sm); height: var(--control-h-sm); }
.icon-btn--brand:hover { background: var(--brand-tint); color: var(--brand-text); }

/* ---------- 4. KPI tiles ---------- */
.kpi-grid { display: grid; gap: var(--space-3); grid-template-columns: repeat(auto-fit, minmax(176px, 1fr)); margin-block-end: var(--section-gap); }
.kpi-grid--lead { grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); margin-block-end: var(--space-3); }
.kpi {
  position: relative; display: flex; flex-direction: column; gap: var(--space-2);
  min-width: 0; height: 100%; padding: var(--space-3) var(--card-pad);
  color: var(--text); text-decoration: none;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-md);
  box-shadow: var(--surface-shadow);
  transition: border-color var(--dur) var(--ease), box-shadow var(--dur) var(--ease), transform var(--dur) var(--ease), background-color var(--dur) var(--ease);
}
.kpi__top { display: flex; align-items: center; justify-content: space-between; gap: var(--space-3); }
.kpi__label { margin: 0; font-size: var(--fs-xs); font-weight: var(--fw-medium); color: var(--text-muted); }
.kpi__icon {
  display: inline-grid; place-items: center; flex: none; width: 28px; height: 28px;
  border-radius: var(--radius-sm); background: var(--brand-tint); color: var(--brand-text); font-size: var(--fs-sm);
}
.kpi__value { margin: 0; font-size: var(--fs-3xl); font-weight: var(--fw-bold); line-height: 1; letter-spacing: -0.02em; font-variant-numeric: tabular-nums; }
.kpi__meta { margin: 0; min-height: 1.25em; font-size: var(--fs-xs); color: var(--text-muted); }
.kpi__go {
  position: absolute; inset-block-end: var(--space-4); inset-inline-end: var(--space-4);
  color: var(--text-muted); opacity: 0; transform: translateX(-4px);
  transition: opacity var(--dur) var(--ease), transform var(--dur) var(--ease), color var(--dur) var(--ease);
}
[dir="rtl"] .kpi__go { transform: translateX(4px); }
a.kpi { cursor: pointer; }
a.kpi:hover { color: var(--text); text-decoration: none; border-color: var(--border-strong); box-shadow: var(--edge), var(--shadow-md); transform: translateY(-1px); }
a.kpi:hover .kpi__go, a.kpi:focus-visible .kpi__go { opacity: 1; transform: none; color: var(--brand-text); }
a.kpi:active { transform: translateY(0); }
a.kpi:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; border-radius: var(--radius-md); }
.kpi--success .kpi__icon { background: var(--success-bg); color: var(--success-text); }
.kpi--warning .kpi__icon { background: var(--warning-bg); color: var(--warning-text); }
.kpi--info .kpi__icon { background: var(--info-bg); color: var(--info-text); }
/* "needs attention": a tile that has work waiting wears a status edge; a tile with nothing to do stays calm */
.kpi--attention.is-pending .kpi__value { color: var(--warning-text); }
.kpi--attention { flex-direction: row; align-items: center; justify-content: space-between; }
.kpi--attention .kpi__top { justify-content: flex-start; }
.kpi--attention .kpi__value { font-size: var(--fs-3xl); }
.kpi--attention .kpi__go { position: static; opacity: 1; transform: none; margin-inline-start: var(--space-2); }

/* summary bar (overall progress) */
.summary-card { padding: var(--space-3) var(--card-pad); display: grid; gap: var(--space-2); margin-block-end: var(--section-gap); }
.summary-card__row { display: flex; align-items: baseline; justify-content: space-between; gap: var(--space-4); flex-wrap: wrap; }
.summary-card__title { margin: 0; font-size: var(--fs-sm); font-weight: var(--fw-semibold); }
.summary-card__figure { font-size: var(--fs-xl); font-weight: var(--fw-bold); font-variant-numeric: tabular-nums; letter-spacing: -0.01em; }
.summary-card .progress { height: 6px; }
.summary-card__hint { margin: 0; font-size: var(--fs-sm); color: var(--text-muted); }

/* ---------- 5. Card headers, chart cards, activity feed, empty states ---------- */
.card-head { display: flex; align-items: center; justify-content: space-between; gap: var(--space-3); padding-block: var(--space-2); padding-inline: var(--card-pad) var(--space-2); border-block-end: 1px solid var(--border); }
.card-head__title { margin: 0; display: flex; align-items: center; gap: var(--space-2); font-size: var(--fs-sm); font-weight: var(--fw-semibold); min-width: 0; }
.card-head__title > i { color: var(--brand-text); font-size: 0.95em; }
.card-head__tools { display: flex; align-items: center; gap: var(--space-1); flex: none; }

.chart-grid { display: grid; gap: var(--space-3); grid-template-columns: repeat(auto-fit, minmax(min(100%, 420px), 1fr)); margin-block-end: var(--section-gap); }
.chart-card { display: flex; flex-direction: column; }
.chart-card .card-head .chart-card__expand { position: static; opacity: 1; }
.chart-card .card-body { flex: 1 1 auto; min-height: 200px; display: flex; flex-direction: column; justify-content: center; }
.chart-card.is-expanded { display: flex; flex-direction: column; }
.chart-card.is-expanded .card-body { height: auto; flex: 1 1 0; min-height: 0; }
.chart-card .empty-state { padding-block: var(--space-6); }

.empty-state--sm { padding: var(--space-6) var(--space-4); }
.empty-state--sm .empty-state__icon { width: 36px; height: 36px; font-size: var(--fs-md); margin-block-end: var(--space-2); }
.empty-state--sm .empty-state__text { margin-block-end: 0; font-size: var(--fs-sm); }

.feed { list-style: none; margin: 0; padding: 0; max-height: 360px; overflow-y: auto; }
.feed__item { display: flex; align-items: center; gap: var(--space-3); padding: var(--space-2) var(--card-pad); border-block-end: 1px solid var(--border); transition: background-color var(--dur-fast) var(--ease); }
.feed__item:last-child { border-block-end: 0; }
.feed__item:hover { background: var(--surface-2); }
.feed__icon { display: inline-grid; place-items: center; flex: none; width: 26px; height: 26px; border-radius: var(--radius-pill); background: var(--brand-tint); color: var(--brand-text); font-size: var(--fs-xs); }
.feed__text { flex: 1 1 auto; min-width: 0; font-size: var(--fs-sm); overflow-wrap: anywhere; }
.feed__time { flex: none; font-size: var(--fs-xs); color: var(--text-muted); font-variant-numeric: tabular-nums; white-space: nowrap; }
@media (max-width: 575.98px) {
  .feed__item { align-items: flex-start; flex-wrap: wrap; }
  .feed__time { flex-basis: 100%; padding-inline-start: calc(26px + var(--space-3)); }
}

/* ---------- 6. Data tables ---------- */
.data-table { --bs-table-hover-bg: var(--surface-2); }
.data-table > thead > tr > th { padding-block: var(--space-2); }
.data-table > tbody > tr:hover > * { background-color: var(--surface-2); }
.data-table > tbody > tr > td { vertical-align: middle; }
.data-table .col-actions { width: 1%; white-space: nowrap; text-align: end; }

.person { display: flex; align-items: center; gap: var(--space-3); min-width: 0; text-align: start; }
.person__avatar {
  display: inline-grid; place-items: center; flex: none; width: 28px; height: 28px; border-radius: var(--radius-pill);
  background: var(--brand-tint); color: var(--brand-text); font-size: var(--fs-xs); font-weight: var(--fw-semibold); letter-spacing: 0;
}
.person__body { display: flex; flex-direction: column; min-width: 0; line-height: 1.35; }
.person__name { font-weight: var(--fw-semibold); color: var(--text); overflow-wrap: anywhere; }
a.person__name:hover { color: var(--brand-text); }
.person__meta { font-size: var(--fs-xs); color: var(--text-muted); }

.status-pill {
  display: inline-flex; align-items: center; gap: var(--space-2); min-height: 24px; padding: 0 var(--space-3);
  border: 1px solid var(--border); border-radius: var(--radius-pill); background: var(--surface-3); color: var(--text-muted);
  font-size: var(--fs-xs); font-weight: var(--fw-semibold); white-space: nowrap;
}
.status-pill::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.status-pill--success { background: var(--success-bg); border-color: var(--success-border); color: var(--success-text); }
.status-pill--warning { background: var(--warning-bg); border-color: var(--warning-border); color: var(--warning-text); }
.status-pill--danger { background: var(--danger-bg); border-color: var(--danger-border); color: var(--danger-text); }

.chips { display: flex; flex-wrap: wrap; align-items: center; gap: var(--space-1); }
.chip {
  display: inline-flex; align-items: center; max-width: 16rem; min-height: 22px; padding: 0 var(--space-2);
  border-radius: var(--radius-sm); border: 1px solid var(--border); background: var(--surface-3); color: var(--text);
  font-size: var(--fs-xs); font-weight: var(--fw-medium); overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.chip--more { color: var(--text-muted); font-variant-numeric: tabular-nums; }
a.chip:hover { text-decoration: none; border-color: var(--border-strong); background: var(--surface-2); color: var(--brand-text); }
.chip--action { max-width: none; border-style: dashed; color: var(--brand-text); background: transparent; }

.row-actions { display: inline-flex; align-items: center; justify-content: flex-end; gap: var(--space-1); }
.row-actions .btn-icon-only { min-height: var(--control-h-sm); }
.table td.cell-muted { color: var(--text-muted); }

/* ---------- 7. Toolbar (filter bar), dropdowns, navigation details ---------- */
/* Toolbar / filter bar: one row of controls above a list */
.filter-bar { display: flex; flex-wrap: wrap; align-items: center; gap: var(--space-2) var(--space-3); padding: var(--space-3); margin-block-end: var(--space-3); background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-md); box-shadow: var(--surface-shadow); }
.filter-bar input, .filter-bar select { min-height: var(--control-h); padding: 0.3rem 0.7rem; background: var(--surface); color: var(--text); border: 1px solid var(--border-input); border-radius: var(--radius-sm); }
.filter-bar input:focus, .filter-bar select:focus { border-color: var(--focus); box-shadow: var(--focus-ring); outline: 0; }
.filter-bar__field { flex: 1 1 180px; min-width: 0; }
.filter-bar__field > * , .filter-bar__field > input, .filter-bar__field > select { width: 100%; }
.filter-bar > .btn { flex: 0 0 auto; min-height: var(--control-h); }
.filter-bar .au-input { width: 100%; }
.filter-bar__clear { color: var(--text-muted); }
.filter-bar--students .filter-bar__field--grow { flex: 2 1 260px; }
.filter-bar--students select { padding-inline-end: 2rem; }
@media (max-width: 575.98px) {
  .filter-bar { padding: var(--space-3); }
  .filter-bar__field, .filter-bar > .btn { flex: 1 1 100%; }
}

.table-responsive, .table-shadow { box-shadow: var(--surface-shadow); }


/* ===================================================================== 7. Toolbars & search ===================================================================== */
.search-field__kbd {
  position: absolute; inset-block: 50%; inset-inline-end: var(--space-3); transform: translateY(-50%);
  display: inline-flex; align-items: center; justify-content: center; min-width: 22px; height: 22px; padding: 0 6px;
  border: 1px solid var(--border-strong); border-radius: var(--radius-sm); background: var(--surface);
  color: var(--text-muted); font-family: var(--font-mono); font-size: var(--fs-xs); line-height: 1; pointer-events: none;
}
.search-field .form-control:focus ~ .search-field__kbd,
.search-field .form-control:not(:placeholder-shown) ~ .search-field__kbd { display: none; }
@media (pointer: coarse) { .search-field__kbd { display: none; } }

/* ===================================================================== 8. Overview widgets (dashboards) ===================================================================== */
/* A calm pending tile uses a neutral edge; a tile with work waiting glows with the brand red, in both themes */
.kpi--attention.is-pending .kpi__value { color: var(--brand-text); }
.kpi--attention.is-pending .kpi__icon { background: var(--brand-tint-strong); color: var(--brand-text); }
.kpi:not(.kpi--attention) .kpi__go { display: none; }
.chart-card canvas { width: 100% !important; max-height: 220px; }
.chart-card.is-expanded canvas { max-height: none; }
.card .card-head { background: var(--surface-2); }
@media (max-width: 575.98px) {
  .kpi { padding: var(--space-3); }
  .card-head { padding-inline-start: var(--space-3); }
}

/* ---- Shared ⋯ row-action menu (Task 6) ---- */
.rowmenu { display: inline-block; flex: none; }
.rowmenu__btn { inline-size: 2.25rem; block-size: 2.25rem; padding: 0; display: inline-flex; align-items: center; justify-content: center; color: var(--text-muted); }
.rowmenu__btn:hover, .rowmenu__btn[aria-expanded="true"] { color: var(--text); background: var(--surface-2, var(--brand-tint)); }
.rowmenu__list { min-width: 12rem; z-index: 1055; }
.rowmenu__list .dropdown-item { display: flex; align-items: center; gap: var(--space-2); min-block-size: 2.25rem; }
.rowmenu__list .dropdown-item.text-danger { color: var(--danger-text) !important; }
.rowmenu__list .inline-form { display: block; margin: 0; }
.rowmenu__list .inline-form .dropdown-item { inline-size: 100%; background: none; border: 0; text-align: start; }
@media (pointer: coarse) { .rowmenu__btn { inline-size: 2.75rem; block-size: 2.75rem; } .rowmenu__list .dropdown-item { min-block-size: 2.75rem; } }

/* ---- Shared list bar / pager / empty polish (Task 6) ---- */
.list-bar { display: flex; flex-wrap: wrap; align-items: center; gap: var(--space-2) var(--space-3); margin-block-end: var(--space-3); }
.list-bar .btn-ghost { white-space: nowrap; }
@media (max-width: 575.98px) { .list-bar > form, .list-bar .search { flex: 1 1 100%; } }
.pagination { gap: var(--space-1); margin: 0; }
.pagination .page-link { border-radius: var(--radius-md); min-inline-size: 2.25rem; text-align: center; }
