/* Copied from prototypes/shared/components.css (approved in A-02). Keep both in sync. */
/*
 * Shared UI components: page header, cards, fields, buttons, table, badges,
 * pagination, alerts, empty state, dialog, toasts, and loading/disabled/busy
 * states. dashboard-kit.css restyles them for the approved dashboard theme.
 * All colors come from tokens.css; directions use logical properties.
 */

/* ---------- Page header ---------- */
.page-header {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  justify-content: space-between;
  gap: var(--space-3);
  margin-block-end: var(--space-5);
}
.page-header h1 { margin: 0; font-size: var(--text-xl); }
.page-header p { margin: var(--space-1) 0 0; color: var(--color-text-muted); }
.page-header__actions { display: flex; gap: var(--space-2); flex-wrap: wrap; }

/* ---------- Card ---------- */
.card {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  padding: var(--space-5);
  margin-block-end: var(--space-5);
}
.card__header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: var(--space-3);
  margin-block-end: var(--space-4);
}
.card__header h2 { margin: 0; font-size: var(--text-lg); }

/* ---------- Stats ---------- */
.stats {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: var(--space-3);
  margin-block-end: var(--space-5);
}
.stat {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  padding: var(--space-4);
}
.stat__label { color: var(--color-text-muted); font-size: var(--text-sm); }
.stat__value { font-size: var(--text-xl); font-weight: 700; }

/* ---------- Toolbar (filters) ---------- */
.toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2);
  align-items: end;
  margin-block-end: var(--space-4);
}
.toolbar .field { margin: 0; min-width: 180px; flex: 1 1 180px; }
.toolbar .field--narrow { flex: 0 1 160px; min-width: 140px; }

/* ---------- Form fields ---------- */
.field { display: grid; gap: var(--space-1); margin-block-end: var(--space-4); }
.field label { font-size: var(--text-sm); font-weight: 600; }
.field input,
.field select,
.field textarea {
  font: inherit;
  width: 100%;
  padding: var(--space-2) var(--space-3);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  background: var(--color-surface);
  color: var(--color-text);
}
.field__hint { font-size: var(--text-xs); color: var(--color-text-muted); }
.field__error { font-size: var(--text-xs); color: var(--color-danger); display: flex; gap: var(--space-1); }
.field--invalid input,
.field--invalid select { border-color: var(--color-danger); background: #fdf3f2; }
.form-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 0 var(--space-4);
}
/* A clear gap between a form's fields (or the content above) and its buttons: 15px everywhere. */
.form-actions { display: flex; gap: var(--space-2); justify-content: flex-start; flex-wrap: wrap; margin-block-start: 15px; }

/* ---------- Buttons (additions to base.css) ---------- */
.button--danger { background: var(--color-danger); color: #fff; }
.button--sm { padding-block: 2px; padding-inline: var(--space-3); font-size: var(--text-sm); }
.icon-button {
  display: inline-grid;
  place-items: center;
  inline-size: 36px;
  block-size: 36px;
  border: 1px solid transparent;
  border-radius: var(--radius-md);
  background: transparent;
  color: inherit;
  cursor: pointer;
}
.icon-button:hover { background: rgba(0, 0, 0, 0.06); }
.icon { inline-size: 20px; block-size: 20px; flex: none; }
/* Arrow-like icons: --mirror points forward, --back points backward,
   in reading direction (chevron is drawn pointing right). */
[dir="rtl"] .icon--mirror { transform: scaleX(-1); }
.icon--back { transform: scaleX(-1); }
[dir="rtl"] .icon--back { transform: none; }

/* ---------- Table ---------- */
.table-wrap {
  position: relative; /* keeps visually-hidden headers inside the scroll box */
  overflow-x: auto;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  background: var(--color-surface);
}
.table { width: 100%; border-collapse: collapse; min-width: 680px; }
.table th,
.table td {
  text-align: start;
  padding: var(--space-3) var(--space-4);
  border-block-end: 1px solid var(--color-border);
  vertical-align: middle;
}
.table th {
  font-size: var(--text-sm);
  color: var(--color-text-muted);
  font-weight: 600;
  background: var(--color-surface-muted);
}
.table tr:last-child td { border-block-end: 0; }
.table .nowrap { white-space: nowrap; }
.table td:first-child { min-inline-size: 180px; }
.table td.actions { white-space: nowrap; text-align: end; }

/* ---------- Badges ---------- */
.badge {
  display: inline-block;
  font-size: var(--text-xs);
  font-weight: 600;
  padding: 2px var(--space-2);
  border-radius: 999px;
  background: var(--color-surface-muted);
  color: var(--color-text-muted);
  white-space: nowrap;
}
.badge--success { background: #e6f4ec; color: var(--color-success); }
.badge--warning { background: #fff3e0; color: var(--color-warning); }
.badge--danger { background: #fdecea; color: var(--color-danger); }
.badge--info { background: #e8f0fd; color: var(--color-info); }

/* ---------- Progress ---------- */
.progress { display: flex; align-items: center; gap: var(--space-2); min-width: 140px; }
.progress__bar {
  flex: 1;
  block-size: 6px;
  background: var(--color-surface-muted);
  border-radius: 999px;
  overflow: hidden;
}
.progress__bar span { display: block; block-size: 100%; background: var(--brand2, var(--color-primary)); }
.progress__value { font-size: var(--text-xs); color: var(--color-text-muted); min-width: 3ch; }

/* ---------- Pagination ---------- */
.pagination {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: var(--space-3);
  flex-wrap: wrap;
  padding-block-start: var(--space-3);
  font-size: var(--text-sm);
  color: var(--color-text-muted);
}
.pagination__pages { display: flex; gap: var(--space-1); }
.pagination__pages button {
  min-inline-size: 32px;
  block-size: 32px;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  background: var(--color-surface);
  font: inherit;
  cursor: pointer;
}
.pagination__pages button[aria-current="page"] {
  background: var(--color-primary);
  border-color: var(--color-primary);
  color: var(--color-primary-contrast);
}

/* ---------- Alerts ---------- */
.alert {
  display: flex;
  gap: var(--space-3);
  align-items: flex-start;
  padding: var(--space-3) var(--space-4);
  border-radius: var(--radius-md);
  border-inline-start: 4px solid var(--color-info);
  background: #eef4fd;
  margin-block-end: var(--space-4);
}
.alert--success { border-color: var(--color-success); background: #ebf6ef; }
.alert--danger { border-color: var(--color-danger); background: #fdeeec; }
.alert--warning { border-color: var(--color-warning); background: #fff6e8; }
.alert p { margin: 0; }

/* ---------- Empty state ---------- */
.empty-state {
  text-align: center;
  padding: var(--space-7) var(--space-4);
  color: var(--color-text-muted);
}
.empty-state .icon { inline-size: 40px; block-size: 40px; margin-block-end: var(--space-3); }
.empty-state h3 { color: var(--color-text); }

/* ---------- Dialog ---------- */
.dialog {
  border: 0;
  border-radius: var(--radius-lg);
  padding: var(--space-5);
  max-inline-size: min(440px, calc(100vw - 32px));
  box-shadow: var(--shadow-md);
  color: var(--color-text);
}
.dialog::backdrop { background: rgba(16, 24, 40, 0.45); }
.dialog h2 { font-size: var(--text-lg); }
.dialog .form-actions { justify-content: flex-end; margin-block-start: var(--space-4); }

/* ---------- Toasts ---------- */
/* Toasts appear at the top center of the screen (user decision, A-02 review). */
.toasts {
  position: fixed;
  inset-block-start: var(--space-4);
  inset-inline-start: 50%;
  transform: translateX(-50%);
  display: grid;
  gap: var(--space-2);
  z-index: 400; /* above side panels, overlays and menus */
  inline-size: max-content;
  max-inline-size: min(440px, calc(100vw - 32px));
}
[dir="rtl"] .toasts { transform: translateX(50%); }
.toast { animation: toast-in 0.2s ease-out; }
@keyframes toast-in { from { opacity: 0; translate: 0 -8px; } to { opacity: 1; translate: 0 0; } }
@media (prefers-reduced-motion: reduce) { .toast { animation: none; } }
.toast {
  display: flex;
  gap: var(--space-3);
  align-items: flex-start;
  padding: var(--space-3) var(--space-4);
  border-radius: var(--radius-md);
  background: var(--color-text);
  color: #fff;
  box-shadow: var(--shadow-md);
}
.toast--success { border-inline-start: 4px solid var(--color-success); }
.toast--danger { border-inline-start: 4px solid var(--color-danger); }

/* ---------- Disabled and busy states ---------- */
.button:disabled,
.button[aria-disabled="true"] { opacity: 0.5; cursor: not-allowed; filter: none; }
/* Busy: shown while a request is in flight; the button is also disabled so a
   second click cannot submit twice. */
.button.is-busy { opacity: 0.85; cursor: progress; }
.spinner {
  inline-size: 16px;
  block-size: 16px;
  border: 2px solid currentColor;
  border-inline-end-color: transparent;
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  flex: none;
}
@keyframes spin { to { transform: rotate(360deg); } }
.field input:disabled,
.field select:disabled,
.field textarea:disabled { background: var(--color-surface-muted); color: var(--color-text-muted); cursor: not-allowed; }
.field--disabled label { color: var(--color-text-muted); }

/* ---------- Loading skeleton ---------- */
.skeleton {
  display: block;
  block-size: 12px;
  border-radius: 6px;
  background: linear-gradient(90deg, var(--color-surface-muted) 25%, #e9edf3 50%, var(--color-surface-muted) 75%);
  background-size: 200% 100%;
  animation: shimmer 1.4s ease-in-out infinite;
}
@keyframes shimmer { from { background-position: 100% 0; } to { background-position: -100% 0; } }
@media (prefers-reduced-motion: reduce) {
  .skeleton, .spinner { animation-duration: 3s; }
}

.visually-hidden {
  position: absolute !important;
  inline-size: 1px;
  block-size: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

/* ---------- A person's record under category headings (_PersonFields; user decision 2026-11-09) ---------- */
.person-sec { border: 0; padding: 0; margin: 0 0 var(--space-5, 20px); min-inline-size: 0; }
.person-sec + .person-sec { border-block-start: 1px solid var(--color-border); padding-block-start: var(--space-4); }
.person-sec__title { padding: 0; margin-block-end: var(--space-3); font-size: 15px; font-weight: 700; }
.person-sec__sub { margin: var(--space-3) 0 var(--space-2); font-size: var(--text-sm); color: var(--color-text-muted); }
.person-sec .form-grid { gap: var(--space-3) var(--space-4); }
.person-sec .form-grid + .form-grid { margin-block-start: var(--space-3); }
.person-sec .uk-req { color: #e11d48; }
.person-sec .form-grid.uk-name4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
@media (max-width: 900px) { .person-sec .form-grid.uk-name4 { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
