/* assets/css/app.css
   Staff dashboard shell + shared interaction components. Loaded by partials/head.php after site.css (whose
   :root tokens it uses). Sections:
     1. App shell layout (sidebar + main column)       5. Content area, page footer, skip link
     2. Sidebar (brand, nav sections, collapse rail)   6. Filter bars
     3. Drawer (< 1024px)                              7. Toasts and modals (ui.js)
     4. Top bar and user menu                          8. Overview tiles        9. Print
   All directions use logical properties, so the sidebar sits on the start side: left in English, right in Arabic. */

/* =========================================================================================== 1. App shell */
html.has-shell {
  --shell-sidebar: 16rem;      /* expanded sidebar */
  --shell-rail: 4.5rem;        /* collapsed icon rail */
  --shell-topbar: 3.5rem;
}
html.has-shell body {
  background: var(--c-canvas);
}
@media (min-width: 1024px) {
  html.has-shell.sidebar-collapsed {
    --shell-sidebar: var(--shell-rail);
  }
}
.app-main {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  margin-inline-start: var(--shell-sidebar);
  transition: margin-inline-start 0.2s var(--ease);
}

/* =========================================================================================== 2. Sidebar */
.app-sidebar {
  position: fixed;
  inset-block: 0;
  inset-inline-start: 0;
  z-index: 40;
  width: var(--shell-sidebar);
  display: flex;
  flex-direction: column;
  background: var(--c-surface);
  border-inline-end: 1px solid var(--c-border);
  transition: width 0.2s var(--ease), transform 0.25s var(--ease), visibility 0s linear 0s;
}
.sidebar-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  height: 4.25rem;
  padding-inline: 1.125rem 0.75rem;
  border-bottom: 1px solid var(--c-border);
  flex-shrink: 0;
}
.sidebar-brand {
  display: flex;
  align-items: center;
  min-width: 0;
  border-radius: var(--radius);
}
.sidebar-brand .brand-full {
  height: 2.75rem;
  width: auto;
  max-width: 100%;
}
/* Rail: only the shield of the logo (the image is cropped, it never flips in RTL). */
.brand-mark {
  display: none;
  width: 1.625rem;
  height: 2.5rem;
  overflow: hidden;
  direction: ltr;
}
.brand-mark img {
  height: 2.5rem;
  width: auto;
  max-width: none;
  margin-left: -0.375rem;
}
.sidebar-nav {
  flex: 1 1 auto;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 0.875rem 0.75rem 1rem;
  scrollbar-width: thin;
  scrollbar-color: #cdd5df transparent;
}
.nav-section + .nav-section {
  margin-top: 1rem;
}
.nav-heading {
  padding-inline: 0.75rem;
  margin: 0 0 0.375rem;
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--c-muted);
  letter-spacing: 0.01em;
}
.nav-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 0.125rem;
}
.nav-link {
  position: relative;
  display: flex;
  align-items: center;
  gap: 0.75rem;
  width: 100%;
  min-height: 2.25rem;
  padding: 0.4375rem 0.75rem;
  border: 0;
  border-radius: var(--radius);
  background: transparent;
  color: #334155;
  font-size: 0.875rem;
  font-weight: 500;
  line-height: 1.25rem;
  text-align: start;
  text-decoration: none;
  cursor: pointer;
  transition: background-color 0.15s ease, color 0.15s ease;
}
.nav-icon {
  width: 1.25rem;
  height: 1.25rem;
  flex-shrink: 0;
  color: #64748b;
  transition: color 0.15s ease;
}
.nav-label {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.nav-link:hover {
  background: var(--c-subtle);
  color: var(--c-ink);
}
.nav-link:hover .nav-icon {
  color: var(--c-ink);
}
/* Active page: navy pill, orange icon and a small orange notch on the start edge. */
.nav-link[aria-current="page"] {
  background: var(--c-ink);
  color: #ffffff;
  font-weight: 600;
}
.nav-link[aria-current="page"] .nav-icon {
  color: var(--c-accent);
}
.nav-link[aria-current="page"]::before {
  content: '';
  position: absolute;
  inset-inline-start: -0.75rem;
  top: 0.5rem;
  bottom: 0.5rem;
  width: 3px;
  border-start-end-radius: 3px;
  border-end-end-radius: 3px;
  background: var(--c-accent);
}
.sidebar-foot {
  flex-shrink: 0;
  padding: 0.5rem 0.75rem 0.75rem;
  border-top: 1px solid var(--c-border);
}
.collapse-btn {
  color: var(--c-muted);
}
.collapse-icon {
  transition: transform 0.2s var(--ease);
}
[dir="rtl"] .collapse-icon {
  transform: scaleX(-1);
}
.sidebar-head .sidebar-close {
  display: none;
}

/* Collapsed rail (desktop only). Labels stay in the DOM (visually hidden) so links keep their accessible names;
   app-shell.js shows a tooltip on hover / keyboard focus. */
@media (min-width: 1024px) {
  html.sidebar-collapsed .sidebar-head {
    justify-content: center;
    padding-inline: 0;
  }
  html.sidebar-collapsed .brand-full {
    display: none;
  }
  html.sidebar-collapsed .brand-mark {
    display: block;
  }
  html.sidebar-collapsed .sidebar-nav {
    padding-inline: 0.75rem;
  }
  html.sidebar-collapsed .nav-link {
    justify-content: center;
    padding-inline: 0;
  }
  html.sidebar-collapsed .nav-label,
  html.sidebar-collapsed .nav-heading {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
  }
  html.sidebar-collapsed .nav-section + .nav-section {
    margin-top: 0.625rem;
    padding-top: 0.625rem;
    border-top: 1px solid var(--c-border);
  }
  html.sidebar-collapsed .collapse-icon {
    transform: scaleX(-1);
  }
  html.sidebar-collapsed[dir="rtl"] .collapse-icon {
    transform: none;
  }
}
.shell-tooltip {
  position: fixed;
  z-index: 90;
  max-width: 16rem;
  padding: 0.3rem 0.6rem;
  border-radius: var(--radius-sm);
  background: var(--c-ink);
  color: #ffffff;
  font-size: 0.75rem;
  font-weight: 600;
  line-height: 1.25rem;
  white-space: nowrap;
  pointer-events: none;
  box-shadow: var(--shadow-md);
}

/* =========================================================================================== 3. Drawer */
.sidebar-backdrop {
  position: fixed;
  inset: 0;
  z-index: 35;
  background: rgba(15, 23, 42, 0.45);
  animation: shell-fade 0.2s ease;
}
@media (max-width: 1023.98px) {
  .app-main {
    margin-inline-start: 0;
  }
  .app-sidebar {
    width: min(18rem, 86vw);
    transform: translateX(-100%);
    visibility: hidden;
    box-shadow: none;
    transition: transform 0.25s var(--ease), visibility 0s linear 0.25s;
  }
  [dir="rtl"] .app-sidebar {
    transform: translateX(100%);
  }
  html.drawer-open .app-sidebar {
    transform: none;
    visibility: visible;
    box-shadow: var(--shadow-lg);
    transition: transform 0.25s var(--ease), visibility 0s linear 0s;
  }
  html.drawer-open {
    overflow: hidden;
  }
  .sidebar-head .sidebar-close {
    display: inline-flex;
  }
  .sidebar-foot {
    display: none;
  }
}
@keyframes shell-fade {
  from { opacity: 0; }
}

/* =========================================================================================== 4. Top bar + user menu */
.app-topbar {
  position: sticky;
  top: 0;
  z-index: 30;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  height: var(--shell-topbar);
  padding-inline: 1.5rem;
  background: rgba(255, 255, 255, 0.94);
  border-bottom: 1px solid var(--c-border);
  -webkit-backdrop-filter: saturate(1.4) blur(8px);
  backdrop-filter: saturate(1.4) blur(8px);
}
.topbar-spacer {
  flex: 1 1 auto;
}
.app-topbar .topbar-menu,
.app-topbar .topbar-brand {
  display: none;
}
.topbar-brand img {
  height: 2.125rem;
  width: auto;
}
.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 2.5rem;
  height: 2.5rem;
  flex-shrink: 0;
  border: 0;
  border-radius: var(--radius);
  background: transparent;
  color: var(--c-ink);
  cursor: pointer;
}
.icon-btn:hover {
  background: var(--c-subtle);
}
.icon-btn .icon {
  width: 1.375rem;
  height: 1.375rem;
}
.topbar-btn {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  min-height: 2.5rem;
  padding: 0.375rem 0.75rem;
  border-radius: var(--radius);
  color: #334155;
  font-size: 0.875rem;
  font-weight: 600;
  text-decoration: none;
}
.topbar-btn:hover {
  background: var(--c-subtle);
  color: var(--c-ink);
}
.topbar-btn .icon {
  color: #64748b;
}
.user-menu {
  position: relative;
}
.user-menu-btn {
  display: flex;
  align-items: center;
  gap: 0.625rem;
  min-height: 2.5rem;
  max-width: 16rem;
  padding: 0.25rem 0.5rem 0.25rem 0.25rem;
  border: 1px solid transparent;
  border-radius: 9999px;
  background: transparent;
  color: var(--c-text);
  text-align: start;
  cursor: pointer;
}
[dir="rtl"] .user-menu-btn {
  padding: 0.25rem 0.25rem 0.25rem 0.5rem;
}
.user-menu-btn:hover,
.user-menu-btn[aria-expanded="true"] {
  background: var(--c-subtle);
  border-color: var(--c-border);
}
.avatar {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 2rem;
  height: 2rem;
  flex-shrink: 0;
  border-radius: 9999px;
  background: var(--c-ink);
  color: #ffffff;
  font-size: 0.75rem;
  font-weight: 700;
  letter-spacing: 0.02em;
  box-shadow: 0 0 0 2px #ffffff, 0 0 0 3.5px var(--c-accent);
}
.user-menu-text {
  display: flex;
  flex-direction: column;
  min-width: 0;
  line-height: 1.2;
}
.user-name {
  font-size: 0.8125rem;
  font-weight: 600;
  color: var(--c-ink);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.user-role {
  font-size: 0.75rem;
  color: var(--c-muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.user-menu-caret {
  color: #64748b;
  transition: transform 0.15s ease;
}
.user-menu-btn[aria-expanded="true"] .user-menu-caret {
  transform: rotate(180deg);
}
.user-menu-panel {
  position: absolute;
  top: calc(100% + 0.5rem);
  inset-inline-end: 0;
  z-index: 50;
  width: 16rem;
  padding: 0.375rem;
  background: var(--c-surface);
  border: 1px solid var(--c-border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  animation: shell-pop 0.14s var(--ease);
}
.user-menu-head {
  padding: 0.5rem 0.625rem 0.625rem;
  margin-bottom: 0.25rem;
  border-bottom: 1px solid var(--c-border);
}
.user-menu-name {
  font-size: 0.875rem;
  font-weight: 700;
  color: var(--c-ink);
  overflow-wrap: anywhere;
}
.user-menu-email {
  margin-top: 0.25rem;
  font-size: 0.8125rem;
  color: var(--c-muted);
  overflow-wrap: anywhere;
  text-align: start;
}
.menu-item {
  display: flex;
  align-items: center;
  gap: 0.625rem;
  width: 100%;
  min-height: 2.5rem;
  padding: 0.5rem 0.625rem;
  border: 0;
  border-radius: var(--radius);
  background: transparent;
  color: #b91c1c;
  font-size: 0.875rem;
  font-weight: 600;
  text-align: start;
  cursor: pointer;
}
.menu-item:hover {
  background: #fef2f2;
}
@keyframes shell-pop {
  from { opacity: 0; transform: translateY(-4px); }
}
@media (max-width: 1023.98px) {
  .app-topbar {
    padding-inline: 0.5rem 0.75rem;
  }
  .app-topbar .topbar-menu {
    display: inline-flex;
  }
  .app-topbar .topbar-brand {
    display: flex;
    align-items: center;
  }
}
@media (max-width: 639.98px) {
  .user-menu-text,
  .user-menu-caret {
    display: none;
  }
  .user-menu-btn {
    padding: 0.25rem;
  }
  [dir="rtl"] .user-menu-btn {
    padding: 0.25rem;
  }
  .topbar-btn {
    padding-inline: 0.5rem;
  }
  .topbar-brand img {
    height: 1.875rem;
  }
}

/* =========================================================================================== 5. Content area */
.app-content {
  flex: 1 0 auto;
  width: 100%;
  max-width: 100rem;
  margin-inline: auto;
  padding: 1.5rem 1.5rem 2rem;
}
.app-content > * + * {
  margin-top: 1.25rem;
}
@media (max-width: 639.98px) {
  .app-content {
    padding: 1rem 1rem 1.5rem;
  }
  .app-content > * + * {
    margin-top: 1rem;
  }
}
.app-footer {
  padding: 1rem 1.5rem 1.25rem;
  font-size: 0.75rem;
  color: var(--c-muted);
  text-align: center;
}
.skip-link {
  position: fixed;
  top: 0.5rem;
  inset-inline-start: 0.5rem;
  z-index: 100;
  padding: 0.5rem 0.875rem;
  border-radius: var(--radius);
  background: var(--c-ink);
  color: #ffffff;
  font-size: 0.875rem;
  font-weight: 600;
  transform: translateY(-200%);
}
.skip-link:focus {
  transform: none;
}

/* =========================================================================================== 6. Filter bars
   <div class="filter-bar" data-filter-bar> <div class="filter-field filter-search">label+input</div>
   <div class="filter-field">label+select</div> ... <div class="filter-meta"><span id="count"></span></div></div>
   ui.js adds a "Clear filters" button that appears once any filter differs from its default. */
.filter-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  gap: 0.75rem 1rem;
}
.filter-bar + * {
  margin-top: 1rem;
}
.filter-field {
  flex: 0 1 13rem;
  min-width: 10rem;
}
.filter-field.filter-search {
  flex: 1 1 18rem;
  max-width: 28rem;
}
.filter-meta {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  min-height: 2.375rem;
  margin-inline-start: auto;
  font-size: 0.8125rem;
  color: var(--c-muted);
}
.filter-clear {
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
  min-height: 2.375rem;
}
.field-search {
  padding-inline-start: 2.25rem;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23768194' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Ccircle cx='11' cy='11' r='7'/%3E%3Cpath d='m20 20-3.5-3.5'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-size: 1rem 1rem;
  background-position: left 0.75rem center;
}
[dir="rtl"] .field-search {
  background-position: right 0.75rem center;
}
@media (max-width: 639.98px) {
  .filter-field,
  .filter-field.filter-search {
    flex: 1 1 100%;
    max-width: none;
  }
  .filter-meta {
    margin-inline-start: 0;
    width: 100%;
    justify-content: space-between;
  }
}

/* Pager under paged tables (email log, audit log). */
.pager {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem 1rem;
  margin-top: 1rem;
}
.pager-info {
  font-size: 0.8125rem;
  color: var(--c-muted);
}
.pager-buttons {
  display: flex;
  gap: 0.5rem;
}

/* =========================================================================================== 7. Toasts + modals */
/* Toasts sit at the bottom of the start side, next to (never over) the sidebar. */
@media (min-width: 1024px) {
  html.has-shell #toast-container {
    inset-inline-start: calc(var(--shell-sidebar) + 1rem);
  }
}
#toast-container {
  max-width: calc(100vw - 2rem);
}
.toast {
  pointer-events: auto;
  display: flex;
  align-items: flex-start;
  gap: 0.625rem;
  width: 22rem;
  max-width: 100%;
  padding: 0.75rem 0.5rem 0.75rem 0.875rem;
  background: var(--c-surface);
  color: var(--c-text);
  border: 1px solid var(--c-border);
  border-inline-start: 4px solid var(--toast-tone, var(--c-ink));
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  font-size: 0.875rem;
  line-height: 1.4;
  animation: toast-in 0.2s var(--ease);
}
[dir="rtl"] .toast {
  padding: 0.75rem 0.875rem 0.75rem 0.5rem;
}
.toast-success { --toast-tone: #16a34a; }
.toast-info    { --toast-tone: var(--c-ink); }
.toast-error   { --toast-tone: #dc2626; }
.toast > .icon {
  margin-top: 0.0625rem;
  color: var(--toast-tone);
}
.toast-msg {
  flex: 1 1 auto;
  min-width: 0;
  overflow-wrap: anywhere;
}
.toast-close {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 1.5rem;
  height: 1.5rem;
  margin-top: -0.125rem;
  border: 0;
  border-radius: var(--radius-sm);
  background: transparent;
  color: #64748b;
  cursor: pointer;
}
.toast-close:hover {
  background: var(--c-subtle);
  color: var(--c-ink);
}
@keyframes toast-in {
  from { opacity: 0; transform: translateY(8px); }
}

/* Every dialog (ui.js helpers and the page-specific panels) gets .modal-overlay / .modal-card from ui.js. */
.modal-overlay {
  background: rgba(15, 23, 42, 0.5) !important;
  animation: shell-fade 0.15s ease;
}
.modal-card {
  box-shadow: var(--shadow-lg) !important;
  animation: modal-in 0.18s var(--ease);
  overscroll-behavior: contain;
}
html.modal-open {
  overflow: hidden;
}
@keyframes modal-in {
  from { opacity: 0; transform: translateY(10px) scale(0.985); }
}
/* Phones: dialogs become a bottom sheet that can use (almost) the full height. */
@media (max-width: 639.98px) {
  .modal-overlay {
    align-items: flex-end !important;
    padding: 0 !important;
  }
  .modal-card {
    max-width: none !important;
    width: 100% !important;
    max-height: 94vh !important;
    border-radius: 1rem 1rem 0 0 !important;
    animation-name: sheet-in;
  }
  @keyframes sheet-in {
    from { transform: translateY(24px); opacity: 0.6; }
  }
}
.modal-close {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 2.25rem;
  height: 2.25rem;
  margin-inline-end: -0.5rem;
  border: 0;
  border-radius: var(--radius);
  background: transparent;
  color: #64748b;
  cursor: pointer;
}
.modal-close:hover {
  background: var(--c-subtle);
  color: var(--c-ink);
}
.confirm-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 2.5rem;
  height: 2.5rem;
  border-radius: 9999px;
  background: #fee2e2;
  color: #b91c1c;
  flex-shrink: 0;
}
.confirm-icon .icon {
  width: 1.25rem;
  height: 1.25rem;
}

/* =========================================================================================== 8. Overview */
.attention-grid {
  display: grid;
  grid-template-columns: repeat(1, minmax(0, 1fr));
  gap: 0.75rem;
}
@media (min-width: 560px) {
  .attention-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (min-width: 1280px) {
  .attention-grid { grid-template-columns: repeat(4, minmax(0, 1fr)); }
}
@media (min-width: 1280px) {
  .attention-grid:has(#tile-ready:not([hidden])) { grid-template-columns: repeat(5, minmax(0, 1fr)); }
}
.attention-card {
  --tone: #334155;
  --tone-bg: #eef2f6;
  display: flex;
  align-items: flex-start;
  gap: 0.875rem;
  padding: 1rem 1.125rem;
  background: var(--c-surface);
  border: 1px solid var(--c-border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
  color: inherit;
  text-decoration: none;
  transition: border-color 0.15s ease, box-shadow 0.15s ease, transform 0.15s ease;
}
.attention-card[hidden] { display: none; }
.attention-card:hover {
  border-color: var(--c-border-strong);
  box-shadow: var(--shadow-md);
}
.attention-card[data-tone="warn"]   { --tone: #b45309; --tone-bg: #fff4e5; }
.attention-card[data-tone="danger"] { --tone: #b91c1c; --tone-bg: #fdecec; }
.attention-card[data-tone="info"]   { --tone: #1d4ed8; --tone-bg: #e8effc; }
.attention-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 2.5rem;
  height: 2.5rem;
  flex-shrink: 0;
  border-radius: var(--radius);
  background: var(--tone-bg);
  color: var(--tone);
}
.attention-icon .icon {
  width: 1.25rem;
  height: 1.25rem;
}
.attention-body {
  min-width: 0;
}
.attention-count {
  font-size: 1.75rem;
  font-weight: 700;
  line-height: 1.1;
  color: var(--c-ink);
  font-variant-numeric: tabular-nums;
}
.attention-label {
  margin-top: 0.125rem;
  font-size: 0.875rem;
  font-weight: 600;
  color: var(--c-ink);
}
.attention-note {
  margin-top: 0.125rem;
  font-size: 0.75rem;
  color: var(--c-muted);
}
.stat-strip {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  border: 1px solid var(--c-border);
  border-radius: var(--radius);
  overflow: hidden;
}
.stat-item {
  display: block;
  padding: 0.875rem 1rem;
  color: inherit;
  text-decoration: none;
  transition: background-color 0.15s ease;
}
.stat-item + .stat-item {
  border-inline-start: 1px solid var(--c-border);
}
.stat-item:hover {
  background: #f7f9fb;
}
.stat-value {
  font-size: 1.5rem;
  font-weight: 700;
  line-height: 1.15;
  color: var(--c-ink);
  font-variant-numeric: tabular-nums;
}
.stat-label {
  margin-top: 0.125rem;
  font-size: 0.8125rem;
  color: var(--c-muted);
}
@media (max-width: 479.98px) {
  .stat-strip {
    grid-template-columns: repeat(1, minmax(0, 1fr));
  }
  .stat-item + .stat-item {
    border-inline-start: 0;
    border-top: 1px solid var(--c-border);
  }
}

/* =========================================================================================== 9. Print
   The shell never prints (certificate-print.php prints only the certificate sheet). */
@media print {
  .app-sidebar,
  .sidebar-backdrop,
  .app-topbar,
  .skip-link,
  .shell-tooltip {
    display: none !important;
  }
  .app-main {
    margin: 0 !important;
    min-height: 0;
  }
  .app-content {
    max-width: none;
    padding: 0;
  }
  html.has-shell body {
    background: #ffffff !important;
  }
}
@media (prefers-reduced-motion: reduce) {
  .app-sidebar,
  .app-main {
    transition: none !important;
  }
}

/* =========================================================================================== 10. Backup restore wizard
   backup.php card "Restore from a backup file" (assets/js/backup-restore.js). Logical properties only (RTL safe). */
.rs-notes {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.75rem;
  margin-bottom: 1rem;
}
.rs-note {
  padding: 0.75rem 0.875rem;
  border-radius: var(--radius);
  border: 1px solid var(--c-border);
  font-size: 0.8125rem;
  line-height: 1.5;
}
.rs-note h3 { font-weight: 700; margin-bottom: 0.25rem; font-size: 0.875rem; }
.rs-note-safe { background: #f0fdf4; border-color: #bbf7d0; color: #14532d; }
.rs-note-risk { background: #fff7ed; border-color: #fed7aa; color: #7c2d12; }
.rs-mock {
  margin-bottom: 1rem;
  padding: 0.5rem 0.75rem;
  border-radius: var(--radius);
  background: #fff7ed;
  border: 1px dashed var(--c-accent);
  color: var(--c-accent-ink);
  font-size: 0.8125rem;
}
.rs-mock[hidden] { display: none; }
.rs-stepper {
  display: flex;
  gap: 0.5rem;
  margin: 0 0 1.25rem;
  padding: 0;
  list-style: none;
}
.rs-step {
  flex: 1 1 0;
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.5rem 0.625rem;
  border-radius: var(--radius);
  border: 1px solid var(--c-border);
  background: #ffffff;
  color: var(--c-muted);
  font-size: 0.8125rem;
  font-weight: 600;
}
.rs-step-num {
  flex: none;
  display: inline-grid;
  place-items: center;
  width: 1.5rem;
  height: 1.5rem;
  border-radius: 9999px;
  background: var(--c-subtle);
  color: var(--c-muted);
  font-size: 0.75rem;
  font-weight: 700;
}
.rs-step-label { min-width: 0; overflow-wrap: anywhere; }
.rs-step.is-current { border-color: var(--c-ink); color: var(--c-ink); box-shadow: inset 0 -3px 0 var(--c-accent); }
.rs-step.is-current .rs-step-num { background: var(--c-ink); color: #ffffff; }
.rs-step.is-done { color: var(--c-ink); }
.rs-step.is-done .rs-step-num { background: #16a34a; color: #ffffff; }
.rs-title { font-size: 1rem; font-weight: 700; color: var(--c-ink); margin-bottom: 0.75rem; outline: none; }
.rs-panel { min-height: 6rem; }
.rs-line { display: flex; align-items: center; gap: 0.5rem; font-size: 0.875rem; color: var(--c-text); margin: 0.5rem 0; }
.rs-line .icon, .rs-ok .icon, .rs-error .icon, .rs-warn .icon, .rs-result .icon, .rs-danger-title .icon { flex: none; width: 1.25rem; height: 1.25rem; }
.rs-spin {
  flex: none;
  display: inline-block;
  width: 1.1rem;
  height: 1.1rem;
  border: 2.5px solid #d5dce5;
  border-top-color: var(--c-ink);
  border-radius: 9999px;
  animation: imc-spin 0.8s linear infinite;
}
.rs-drop {
  padding: 1.75rem 1rem;
  text-align: center;
  border: 2px dashed var(--c-border-strong);
  border-radius: var(--radius-lg);
  background: #fafbfc;
  transition: border-color 0.15s ease, background-color 0.15s ease;
}
.rs-drop.is-over { border-color: var(--c-ink); background: var(--c-subtle); }
.rs-drop-title { font-weight: 700; color: var(--c-ink); }
.rs-drop-or { font-size: 0.8125rem; color: var(--c-muted); margin: 0.375rem 0 0.625rem; }
.rs-error, .rs-warn, .rs-ok, .rs-result {
  display: flex;
  align-items: flex-start;
  gap: 0.5rem;
  margin: 0 0 0.75rem;
  padding: 0.625rem 0.75rem;
  border-radius: var(--radius);
  font-size: 0.875rem;
  line-height: 1.45;
}
.rs-error { background: #fef2f2; border: 1px solid #fecaca; color: #991b1b; }
.rs-warn { background: #fffbeb; border: 1px solid #fde68a; color: #78350f; margin-top: 0.75rem; }
.rs-ok { background: #f0fdf4; border: 1px solid #bbf7d0; color: #14532d; }
.rs-result { font-weight: 600; }
.rs-result.is-ok { background: #f0fdf4; border: 1px solid #bbf7d0; color: #14532d; }
.rs-result.is-warn { background: #fffbeb; border: 1px solid #fde68a; color: #78350f; }
.rs-result.is-error { background: #fef2f2; border: 1px solid #fecaca; color: #991b1b; }
.rs-facts { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 0.5rem 1.25rem; margin: 0 0 1rem; font-size: 0.875rem; }
.rs-facts > div { min-width: 0; }
.rs-facts dt { font-size: 0.75rem; color: var(--c-muted); }
.rs-facts dd { font-weight: 600; color: var(--c-text); }
.rs-actions { display: flex; flex-wrap: wrap; gap: 0.5rem; justify-content: flex-end; margin-top: 1rem; }
.rs-table td, .rs-table th { font-variant-numeric: tabular-nums; }
.rs-table .rs-total td { font-weight: 700; background: var(--c-subtle); }
.rs-blocked { display: inline-block; margin-inline-start: 0.5rem; }
.rs-modes { display: grid; gap: 0.625rem; border: 0; padding: 0; margin: 0 0 0.875rem; }
.rs-mode {
  display: flex;
  gap: 0.75rem;
  align-items: flex-start;
  padding: 0.75rem 0.875rem;
  border: 1px solid var(--c-border-strong);
  border-radius: var(--radius);
  background: #ffffff;
  cursor: pointer;
}
.rs-mode input { flex: none; margin-top: 0.25rem; width: 1.1rem; height: 1.1rem; accent-color: var(--c-ink); }
.rs-mode strong { display: block; color: var(--c-ink); font-size: 0.9375rem; }
.rs-mode small { display: block; color: var(--c-muted); font-size: 0.8125rem; line-height: 1.45; margin-top: 0.125rem; }
.rs-mode.is-selected { border-color: var(--c-ink); box-shadow: 0 0 0 1px var(--c-ink); background: #f7f9fb; }
.rs-mode-danger.is-selected { border-color: #b91c1c; box-shadow: 0 0 0 1px #b91c1c; background: #fef2f2; }
.rs-mode:focus-within { outline: 2px solid var(--c-focus); outline-offset: 2px; }
.rs-danger {
  margin: 0 0 0.875rem;
  padding: 0.75rem 0.875rem;
  border: 1px solid #fca5a5;
  background: #fef2f2;
  border-radius: var(--radius);
  color: #7f1d1d;
  font-size: 0.875rem;
  line-height: 1.5;
}
.rs-danger[hidden] { display: none; }
.rs-danger-title { display: flex; gap: 0.5rem; align-items: center; font-weight: 700; margin-bottom: 0.25rem; color: #991b1b; }
.rs-confirm { max-width: 16rem; margin-top: 0.375rem; border-color: #b91c1c; }
.rs-summary { font-size: 1rem; font-weight: 600; color: var(--c-ink); margin: 0.5rem 0 0.25rem; }
.rs-progress { margin: 0.75rem 0; }
.rs-bar { height: 0.75rem; border-radius: 9999px; background: var(--c-subtle); overflow: hidden; border: 1px solid var(--c-border); }
.rs-bar > span { display: block; height: 100%; width: 0; background: var(--c-ink); transition: width 0.2s var(--ease); }
.rs-overall { font-size: 0.8125rem; color: var(--c-muted); margin-top: 0.375rem; font-variant-numeric: tabular-nums; }
.rs-tbls { list-style: none; margin: 0.75rem 0 0; padding: 0; border: 1px solid var(--c-border); border-radius: var(--radius); background: #ffffff; }
.rs-tbl { display: flex; align-items: center; gap: 0.75rem; padding: 0.4rem 0.75rem; font-size: 0.8125rem; }
.rs-tbl + .rs-tbl { border-top: 1px solid var(--c-border); }
.rs-tbl-name { flex: 1 1 auto; min-width: 0; font-weight: 600; text-align: start; overflow-wrap: anywhere; }
.rs-tbl-rows { color: var(--c-muted); font-variant-numeric: tabular-nums; }
.rs-tbl-status { flex: none; min-width: 7rem; text-align: end; color: var(--c-muted); }
.rs-tbl.is-run .rs-tbl-status { color: var(--c-ink); font-weight: 700; }
.rs-tbl.is-done .rs-tbl-status { color: #15803d; font-weight: 600; }
.rs-tbl.is-fail .rs-tbl-status { color: #b91c1c; font-weight: 700; }
.rs-tbl.is-cancel .rs-tbl-status { color: #92400e; }
.rs-cli { margin-top: 1.25rem; padding-top: 0.75rem; border-top: 1px solid var(--c-border); font-size: 0.875rem; }
.rs-cli summary { cursor: pointer; font-weight: 600; color: var(--c-muted); }
@media (max-width: 640px) {
  .rs-notes { grid-template-columns: minmax(0, 1fr); }
  .rs-stepper { gap: 0.25rem; }
  .rs-step { flex-direction: column; justify-content: flex-start; text-align: center; gap: 0.25rem; padding: 0.5rem 0.25rem; font-size: 0.6875rem; }
  .rs-facts { grid-template-columns: minmax(0, 1fr); }
  .rs-actions { flex-direction: column-reverse; }
  .rs-actions .btn { width: 100%; justify-content: center; }
  .rs-tbl-status { min-width: 5.5rem; }
  .rs-confirm { max-width: none; }
}
@media (prefers-reduced-motion: reduce) {
  .rs-spin { animation: none; }
  .rs-bar > span, .rs-drop { transition: none; }
}

/* ---------- Image uploader + thumbnails (program images, trainer photos) ----------
   The frame always reserves its area (aspect-ratio), so choosing / loading a picture never shifts the layout. */
.img-thumb {
  position: relative;
  width: 100%;
  aspect-ratio: 16 / 9;
  overflow: hidden;
  border-radius: var(--radius-md, 0.5rem);
  background: linear-gradient(135deg, var(--c-ink), var(--c-ink-2));
  color: var(--c-accent);
}
.img-thumb img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
}
.img-thumb-letter {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 2rem;
  font-weight: 700;
}
.photo-avatar {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  width: 3rem;
  height: 3rem;
  overflow: hidden;
  border-radius: 9999px;
  background: var(--c-ink);
  color: #ffffff;
  font-size: 0.875rem;
  font-weight: 700;
  letter-spacing: 0.02em;
}
.photo-avatar img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
}
.photo-avatar-sm {
  width: 2rem;
  height: 2rem;
  font-size: 0.6875rem;
}

.img-up {
  display: flex;
  flex-wrap: wrap;
  gap: 1rem;
  align-items: flex-start;
}
.img-up-frame {
  position: relative;
  flex: 0 0 auto;
  width: 100%;
  max-width: 20rem;
  aspect-ratio: 16 / 9;
  overflow: hidden;
  border: 2px dashed var(--c-border-strong);
  border-radius: 0.625rem;
  background: var(--c-subtle);
  cursor: pointer;
  transition: border-color 0.15s, background-color 0.15s;
}
.img-up-frame.is-square {
  width: 8rem;
  max-width: 8rem;
  aspect-ratio: 1 / 1;
}
.img-up-frame:hover,
.img-up-frame:focus-visible,
.img-up-frame.is-over {
  border-color: var(--c-accent);
  background: #fff7ed;
}
.img-up-frame.has-image {
  border-style: solid;
  border-color: var(--c-border);
  background: var(--c-ink);
}
.img-up-frame img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
}
.img-up-empty {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.25rem;
  padding: 0.5rem;
  text-align: center;
  font-size: 0.75rem;
  color: var(--c-muted);
}
.img-up-initials {
  font-size: 1.75rem;
  font-weight: 700;
  color: var(--c-ink);
}
.img-up-busy {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  background: rgba(255, 255, 255, 0.85);
  font-size: 0.75rem;
  color: var(--c-ink);
}
.img-up-spinner {
  width: 1.5rem;
  height: 1.5rem;
  border: 3px solid #d5dce5;
  border-top-color: var(--c-ink);
  border-radius: 9999px;
  animation: imc-spin 0.8s linear infinite;
}
.img-up-body {
  flex: 1 1 14rem;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}
.img-up-error {
  color: #b91c1c;
  font-size: 0.8125rem;
}
.img-up-status {
  color: var(--c-muted);
  font-size: 0.8125rem;
}
@media (prefers-reduced-motion: reduce) {
  .img-up-spinner { animation-duration: 2.4s; }
}

/* =========================================================================================== 11. Certificates: issuing, filters, counts
   Direct ("manual") certificates (certificate-issue.js), filter chips and counts (certificates.js, employees.js,
   companies.js), certificate strip of a group (groups.js). Logical properties only (RTL). */
.badge-manual { background: #ede9fe; color: #5b21b6; border-color: #ddd6fe; }

.field-error {
  margin-top: 0.25rem;
  font-size: 0.75rem;
  color: #b91c1c;
}
.field-error[hidden] { display: none; }
.field[aria-invalid="true"] {
  border-color: #dc2626;
  box-shadow: 0 0 0 1px #dc2626;
}

/* Removable filter chips under the filter bar */
.filter-chips {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem;
}
.filter-chips[hidden] { display: none; }
.filter-chip {
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
  max-width: 100%;
  padding: 0.125rem 0.25rem 0.125rem 0.625rem;
  border: 1px solid var(--c-border-strong, #cfd6de);
  border-radius: 9999px;
  background: var(--c-subtle, #f3f5f8);
  font-size: 0.8125rem;
  color: var(--c-ink);
}
[dir="rtl"] .filter-chip { padding: 0.125rem 0.625rem 0.125rem 0.25rem; }
.filter-chip > span {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.filter-chip button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 1.5rem;
  height: 1.5rem;
  border-radius: 9999px;
  color: var(--c-muted);
}
.filter-chip button:hover { background: #dfe4ea; color: var(--c-ink); }
.empty-how { margin: 0.5rem auto 0; max-width: 34rem; font-size: 0.8125rem; line-height: 1.5; }
.empty-how p + p { margin-top: 0.25rem; }

/* Employee typeahead in the issue dialog */
.combo { position: relative; }
.combo-list {
  position: absolute;
  inset-inline: 0;
  top: calc(100% + 0.25rem);
  z-index: 30;
  max-height: 15rem;
  overflow-y: auto;
  margin: 0;
  padding: 0.25rem;
  list-style: none;
  background: var(--c-surface, #fff);
  border: 1px solid var(--c-border-strong, #cfd6de);
  border-radius: var(--radius, 0.5rem);
  box-shadow: var(--shadow-lg, 0 10px 30px rgba(15, 23, 42, 0.18));
}
.combo-list[hidden] { display: none; }
.combo-option {
  display: flex;
  flex-direction: column;
  gap: 0.0625rem;
  padding: 0.4rem 0.625rem;
  border-radius: 0.375rem;
  cursor: pointer;
}
.combo-option[aria-selected="true"], .combo-option:hover { background: var(--c-subtle, #f3f5f8); }
.combo-empty { padding: 0.5rem 0.625rem; font-size: 0.8125rem; color: var(--c-muted); }
.combo-picked {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  padding: 0.5rem 0.75rem;
  border: 1px solid var(--c-border-strong, #cfd6de);
  border-radius: var(--radius, 0.5rem);
  background: var(--c-subtle, #f3f5f8);
}
.combo-picked[hidden] { display: none; }
.combo-picked-body { display: flex; flex-direction: column; min-width: 0; }

.issue-preview {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 0.375rem 0.75rem;
  padding: 0.625rem 0.75rem;
  border: 1px dashed #b9c3cf;
  border-radius: var(--radius, 0.5rem);
  background: #f8fafc;
}
.issue-preview-label { font-size: 0.8125rem; color: var(--c-muted); }
.issue-preview strong { font-size: 1.0625rem; color: var(--c-ink); }
.issue-summary { display: grid; gap: 0.5rem; margin-top: 0.75rem; }
.issue-summary > div {
  display: grid;
  grid-template-columns: minmax(7rem, 10rem) 1fr;
  gap: 0.5rem;
  padding-bottom: 0.5rem;
  border-bottom: 1px solid var(--c-border, #e2e8f0);
}
.issue-summary dt { font-size: 0.75rem; color: var(--c-muted); }
.issue-summary dd { font-weight: 500; min-width: 0; overflow-wrap: anywhere; }
.issue-done { display: flex; flex-direction: column; align-items: center; gap: 0.375rem; padding: 0.5rem 0; text-align: center; }
.issue-done-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 3rem;
  height: 3rem;
  border-radius: 9999px;
  background: #dcfce7;
  color: #166534;
}
.issue-done-icon .icon { width: 1.5rem; height: 1.5rem; }
.issue-done-number {
  font-size: 1.5rem;
  font-weight: 700;
  letter-spacing: 0.02em;
  color: var(--c-ink);
  user-select: all;
}
@media (max-width: 639.98px) {
  .issue-summary > div { grid-template-columns: 1fr; gap: 0.125rem; }
}

/* Certificate count in the employee / company lists */
.cert-count {
  display: inline-flex;
  align-items: center;
  gap: 0.375rem;
  font-weight: 600;
  text-decoration: none;
  font-variant-numeric: tabular-nums;
}
.cert-count.is-zero { font-weight: 400; color: var(--c-muted); }
.cert-dot {
  display: inline-block;
  width: 0.625rem;
  height: 0.625rem;
  border-radius: 9999px;
  flex-shrink: 0;
}
.cert-dot.is-expired { background: #dc2626; }
.cert-dot.is-expiring { background: #f59e0b; }

/* Certificates summary of a group (groups.js) */
.cert-strip {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem 1rem;
  padding: 0.75rem 1rem;
  border: 1px solid #bfdbfe;
  border-radius: var(--radius-lg, 0.75rem);
  background: #eff6ff;
}
.cert-strip.is-ready { border-color: #fcd9a8; background: #fff7ea; }
.cert-strip-text { display: flex; flex-wrap: wrap; align-items: center; gap: 0.25rem 1rem; font-size: 0.875rem; }
.cert-strip-text strong { font-variant-numeric: tabular-nums; }
.bulk-progress { width: 100%; }
.badge-ready { background: #fff4e5; color: #92400e; border-color: #fcd9a8; }

/* Certificates block at the top of the employee / company detail panels (certificate-ui.js) */
.cert-section {
  border: 1px solid var(--c-border, #e2e8f0);
  border-inline-start: 4px solid var(--c-accent, #fc8f34);
  border-radius: var(--radius-lg, 0.75rem);
  padding: 0.875rem 1rem;
  background: #fff;
}
.cert-section-head {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem 1rem;
  margin-bottom: 0.625rem;
}
.cert-section-empty {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 0.5rem;
  padding: 0.25rem 0 0.25rem;
  color: var(--c-muted);
  font-size: 0.875rem;
}

/* Document hand-over: nothing here prints */
@media print { .filter-chips, .combo-list { display: none !important; } }

/* =========================================================================================== 12. Certificate types
   Attendance & hours vs exam (migration 2026102304): type badges, the radio cards of the program form. Logical properties only (RTL). */
.badge-type-attendance { background: #e0f2fe; color: #075985; border-color: #bae6fd; }
.badge-type-exam { background: #fef3c7; color: #92400e; border-color: #fde68a; }

.type-cards { display: grid; grid-template-columns: 1fr; gap: 0.625rem; }
@media (min-width: 640px) { .type-cards { grid-template-columns: 1fr 1fr; } }
.type-card {
  position: relative;
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  padding: 0.75rem 1rem;
  padding-inline-start: 2.5rem;
  border: 2px solid var(--c-border, #e2e8f0);
  border-radius: var(--radius-lg, 0.75rem);
  background: #fff;
  cursor: pointer;
  min-height: 3.5rem;
}
.type-card:hover { border-color: #cbd5e1; }
.type-card input[type="radio"] { position: absolute; inset-inline-start: 0.875rem; top: 1rem; width: 1.125rem; height: 1.125rem; accent-color: #fc8f34; }
.type-card:has(input:checked) { border-color: #fc8f34; background: #fff7ea; }
.type-card:has(input:focus-visible) { outline: 2px solid #162839; outline-offset: 2px; }
.type-card-title { font-weight: 700; color: #162839; }
.type-card-desc { font-size: 0.8125rem; color: #475569; line-height: 1.35; }
.type-warning {
  margin-top: 0.5rem;
  padding: 0.625rem 0.875rem;
  border: 1px solid #fcd34d;
  border-radius: var(--radius-lg, 0.75rem);
  background: #fffbeb;
  color: #92400e;
  font-size: 0.875rem;
}
.type-warning[hidden] { display: none; }
.col-dim { color: #94a3b8; }

/* Group results: attended-hours input with its "/ N h" suffix */
.hours-entry { display: inline-flex; align-items: center; gap: 0.5rem; }
.hours-of { font-size: 0.8125rem; color: #64748b; white-space: nowrap; }
.field[aria-invalid="true"] { border-color: #dc2626; }

/* =========================================================================================== 13. Program form (add / edit program)
   programs.js builds the dialog with openFormModal(..., { size: 'form' }): a 45rem card; the header and footer are fixed,
   the tabs and the error summary sit under the header, only .pf-body scrolls. Sections: names, identifiers (Auto / Edited
   chips + reset), duration, certificate type, image. Logical properties only, so RTL mirrors by itself. */
.pf-modal {
  width: 100%;
  max-width: 45rem;
}
.pf-modal > * { flex-shrink: 0; }
.pf-modal > .pf-body {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
}
.pf-modal :is(button, a, input, select, textarea, summary):focus-visible {
  outline: 2px solid var(--c-focus);
  outline-offset: 2px;
}

.pf-tabs {
  display: flex;
  gap: 0.25rem;
  padding-inline: 1.5rem;
  border-bottom: 1px solid var(--c-border);
  background: var(--c-surface);
  overflow-x: auto;
  overflow-y: hidden;
  scrollbar-width: thin;
}
.pf-tab {
  flex: none;
  margin-bottom: -1px;
  padding: 0.625rem 0.875rem;
  border: 0;
  border-bottom: 2px solid transparent;
  background: transparent;
  color: var(--c-muted);
  font-size: 0.875rem;
  font-weight: 500;
  white-space: nowrap;
  cursor: pointer;
}
.pf-tab:hover { color: var(--c-ink); }
.pf-tab.is-active {
  color: var(--c-ink);
  font-weight: 700;
  border-bottom-color: var(--c-accent);
}

.pf-summary {
  margin: 0.75rem 1.5rem 0;
  padding: 0.625rem 0.875rem;
  border: 1px solid #fecaca;
  border-radius: var(--radius);
  background: #fef2f2;
  color: #991b1b;
  font-size: 0.8125rem;
}
.pf-summary[hidden] { display: none; }
.pf-summary ul { margin: 0.25rem 0 0; padding-inline-start: 1.25rem; list-style: disc; }
.pf-summary a { color: inherit; text-decoration: underline; }

.pf-section + .pf-section {
  margin-top: 1.5rem;
  padding-top: 1.5rem;
  border-top: 1px solid var(--c-border);
}
.pf-section-title {
  margin: 0 0 0.75rem;
  font-size: 0.9375rem;
  font-weight: 700;
  color: var(--c-ink);
}
.pf-section-title + .pf-section-note { margin-top: -0.5rem; }
.pf-section-note {
  margin: 0 0 0.75rem;
  font-size: 0.8125rem;
  color: var(--c-muted);
}
.pf-grid-2,
.pf-grid-3 {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 1rem;
}
@media (min-width: 640px) {
  .pf-grid-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .pf-grid-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}
.pf-field { min-width: 0; }
.pf-req { margin-inline-start: 0.2rem; color: #dc2626; }

/* Identifier fields: label + Auto / Edited chip + reset button on one line */
.pf-label-row {
  display: flex;
  align-items: center;
  gap: 0.375rem;
  min-height: 1.5rem;
  margin-bottom: 0.3rem;
}
.pf-label-row .field-label {
  flex: 0 1 auto;
  min-width: 0;
  margin-bottom: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.pf-chip, .pf-reset { flex: none; white-space: nowrap; }
.pf-chip {
  padding: 0.0625rem 0.5rem;
  border-radius: 9999px;
  background: #e3f4e8;
  color: #166534;
  font-size: 0.625rem;
  font-weight: 600;
  line-height: 1.25rem;
}
.pf-chip.is-edited { background: #fff1de; color: #8a4300; }
.pf-reset {
  margin-inline-start: auto;
  padding: 0 0.375rem;
  min-height: 1.5rem;
  border: 1px solid var(--c-border-strong);
  border-radius: var(--radius-sm);
  background: var(--c-surface);
  color: var(--c-ink);
  font-size: 0.6875rem;
  font-weight: 600;
  cursor: pointer;
}
.pf-reset:hover { background: var(--c-subtle); }
.pf-reset[hidden] { display: none; }
.pf-number { font-weight: 600; color: var(--c-ink); white-space: nowrap; }
.pf-field input[name="abbreviation"] { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; }

/* Number input with its unit inside, at the end side */
.pf-suffix-wrap { position: relative; }
.pf-suffix-wrap .field { padding-inline-end: 4rem; }
.pf-suffix {
  position: absolute;
  inset-inline-end: 0.75rem;
  top: 50%;
  transform: translateY(-50%);
  font-size: 0.8125rem;
  color: var(--c-muted);
  pointer-events: none;
}

/* Certificate type cards: the explanation below belongs to the selected card only */
.pf-section .type-card { transition: border-color 0.15s, background-color 0.15s, box-shadow 0.15s; }
.pf-section .type-card:has(input:checked) { box-shadow: 0 0 0 1px #fc8f34; }
.pf-type-rule {
  margin: 0.625rem 0 0;
  padding-inline-start: 0.625rem;
  border-inline-start: 3px solid var(--c-accent);
  font-size: 0.8125rem;
  color: var(--c-text);
}

/* Image: bordered block, preview on one side, actions and help on the other (stacked on phones) */
.pf-image-block {
  padding: 1rem;
  border: 1px solid var(--c-border);
  border-radius: var(--radius-lg);
  background: #fafbfd;
}
.pf-image-block .img-up { gap: 1rem 1.25rem; }
.pf-image-block .img-up-frame { width: 100%; max-width: none; }
@media (min-width: 640px) {
  .pf-image-block .img-up-frame { flex: 0 0 13rem; width: 13rem; }
}

@media (max-width: 639.98px) {
  .pf-tabs { padding-inline: 0.5rem; gap: 0; scrollbar-width: none; }
  .pf-tabs::-webkit-scrollbar { display: none; }
  .pf-tab { padding-inline: 0.625rem; font-size: 0.8125rem; }
  .pf-modal .pf-footer { flex-direction: row; padding: 0.75rem 1rem; }
  .pf-modal .pf-footer .btn { flex: 1 1 0; }
  .pf-modal .pf-footer > :last-child { order: 2; }
  .pf-summary { margin-inline: 1rem; }
  .pf-modal .pf-body { padding-inline: 1rem; }
  .pf-reset { min-height: 2rem; padding-inline: 0.625rem; font-size: 0.75rem; }
}

/* =========================================================================================== 14. Late trainees, tags on programs, type-change dialog
   (migration 2026102308) */
.badge-late { background: #eef2ff; color: #3730a3; border-color: #c7d2fe; white-space: nowrap; }

/* Inline "+ New tag" of the program form (Tags tab) */
.pf-newtag-toggle {
  display: inline-flex; align-items: center; min-height: 2.25rem; padding: 0.25rem 0.875rem;
  border: 1px dashed #94a3b8; border-radius: 9999px; background: #fff; color: #162839;
  font-size: 0.875rem; font-weight: 600; cursor: pointer;
}
.pf-newtag-toggle:hover { background: #f8fafc; border-color: #fc8f34; }
.pf-newtag-toggle[aria-expanded="true"] { background: #fff7ea; border-color: #fc8f34; border-style: solid; }
.pf-newtag {
  margin-top: 0.75rem; padding: 0.75rem; border: 1px solid #e2e8f0; border-radius: 0.75rem; background: #f8fafc;
}
.pf-newtag[hidden] { display: none; }
.pf-newtag-row { display: grid; grid-template-columns: 1fr; gap: 0.625rem; align-items: end; }
.pf-newtag-actions { display: flex; flex-wrap: wrap; gap: 0.5rem; }
@media (min-width: 640px) {
  .pf-newtag-row { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr) auto; }
}
.pf-newtag .field-error { margin-top: 0.5rem; }

/* Type-change dialog (programs.js): choose what happens to existing groups / certificates */
.tc-intro { margin: 0; color: #162839; font-weight: 600; }
.tc-counts { margin: 0; padding: 0.5rem 0.75rem; border-radius: 0.5rem; background: #f1f5f9; color: #334155; }
.tc-options { display: grid; gap: 0.625rem; }
.tc-option {
  position: relative; display: grid; gap: 0.125rem; padding: 0.75rem 0.875rem 0.75rem 2.5rem;
  border: 1px solid #e2e8f0; border-radius: 0.75rem; background: #fff; cursor: pointer;
}
[dir="rtl"] .tc-option { padding: 0.75rem 2.5rem 0.75rem 0.875rem; }
.tc-option input[type="radio"] { position: absolute; inset-inline-start: 0.875rem; top: 0.95rem; width: 1.125rem; height: 1.125rem; accent-color: #fc8f34; }
.tc-option:has(input:checked) { border-color: #fc8f34; background: #fff7ea; box-shadow: 0 0 0 1px #fc8f34; }
.tc-option:has(input:focus-visible) { outline: 2px solid #162839; outline-offset: 2px; }
.tc-option.is-disabled { opacity: 0.6; cursor: not-allowed; background: #f8fafc; }
.tc-option-title { font-weight: 700; color: #162839; }
.tc-option-desc { font-size: 0.8125rem; color: #475569; line-height: 1.4; }

/* Campaign editor: the live preview stays in view while the form scrolls (wide screens only). */
@media (min-width: 1024px) { .camp-sticky { position: sticky; top: 0; align-self: start; } }

/* Arabic: values forced to LTR (numbers, dates, hours) keep the reading edge of their label instead of jumping to the left */
html[dir="rtl"] dd[dir="ltr"],
html[dir="rtl"] td[dir="ltr"] { text-align: right; }
