/* =====================================================================
   DSTMS - assets/css/components.css
   Buttons, forms, cards, tables, badges, tabs, dialogs (modal and bottom
   sheet), toasts, avatars, progress, skeletons, pagination, and more.
   Uses only the tokens from base.css, so dark.css re-themes everything.
   JavaScript (ui.js) toggles: .is-open, .is-active, .is-loading, [hidden].
   ===================================================================== */

/* ---------- Buttons ---------- */
.btn {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--s2);
  min-height: 44px;
  padding: 0 var(--s4);
  font-weight: 600;
  font-size: 1rem;
  line-height: 1;
  white-space: nowrap;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow-sm);
  text-decoration: none;
  user-select: none;
  transition: background var(--t-fast) var(--ease), border-color var(--t-fast) var(--ease),
              box-shadow var(--t-fast) var(--ease), transform var(--t-fast) var(--ease), color var(--t-fast) var(--ease);
}
.btn:hover { text-decoration: none; background: var(--surface-2); }
.btn:active { transform: translateY(1px); }
.btn:disabled, .btn[aria-disabled="true"] { opacity: .55; pointer-events: none; }

.btn-primary { color: #fff; background: var(--primary); border-color: var(--primary); }
.btn-primary:hover { color: #fff; background: var(--primary-d); border-color: var(--primary-d); }
.btn-ok { color: #fff; background: var(--ok); border-color: var(--ok); }
.btn-ok:hover { color: #fff; filter: brightness(.92); background: var(--ok); }
.btn-danger { color: #fff; background: var(--bad); border-color: var(--bad); }
.btn-danger:hover { color: #fff; filter: brightness(.92); background: var(--bad); }
.btn-ghost { background: transparent; border-color: transparent; box-shadow: none; color: var(--primary); }
.btn-ghost:hover { background: var(--primary-l); }
.btn-soft { background: var(--primary-l); border-color: transparent; color: var(--primary-d); box-shadow: none; }
.btn-soft:hover { filter: brightness(.97); background: var(--primary-l); }
.btn-outline-danger { color: var(--bad); border-color: var(--bad); background: transparent; box-shadow: none; }
.btn-outline-danger:hover { background: var(--bad-bg); }

.btn-sm { min-height: 36px; padding: 0 var(--s3); font-size: .9rem; }
.btn-lg { min-height: 52px; padding: 0 var(--s5); font-size: 1.05rem; }
.btn-block { display: flex; width: 100%; }
.btn-icon { width: 44px; padding: 0; }
.btn-icon.btn-sm { width: 36px; }

.btn-group { display: flex; flex-wrap: wrap; gap: var(--s2); }

/* Loading state: keep size, hide text, show spinner */
.btn.is-loading { color: transparent !important; pointer-events: none; }
.btn.is-loading > * { visibility: hidden; }
.btn.is-loading::after {
  content: "";
  position: absolute;
  width: 1.15em; height: 1.15em;
  border: 2.5px solid rgba(255, 255, 255, .45);
  border-top-color: #fff;
  border-radius: 50%;
  animation: spin .7s linear infinite;
}
.btn:not(.btn-primary):not(.btn-ok):not(.btn-danger).is-loading::after {
  border-color: var(--line); border-top-color: var(--primary);
}
@keyframes spin { to { transform: rotate(360deg); } }

.spinner {
  width: 1.5rem; height: 1.5rem;
  border: 3px solid var(--line);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin .7s linear infinite;
}

/* Floating action button (create). Sits above the bottom tab bar on phones. */
.fab {
  position: fixed;
  right: calc(var(--s4) + var(--safe-right));
  bottom: calc(var(--bottomnav-h) + var(--safe-bottom) + var(--s4));
  z-index: var(--z-nav);
  display: grid; place-items: center;
  width: 56px; height: 56px;
  color: #fff;
  background: linear-gradient(135deg, var(--primary), var(--primary-d));
  border-radius: 50%;
  box-shadow: 0 8px 22px rgba(29, 78, 216, .4);
  transition: transform var(--t-fast) var(--ease);
}
.fab:hover { color: #fff; text-decoration: none; transform: scale(1.05); }
.fab .icon { width: 26px; height: 26px; }
@media (min-width: 1024px) { .fab { bottom: var(--s5); right: var(--s5); } }

/* ---------- Forms ---------- */
.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: var(--s4); min-width: 0; }
.field > label, .label {
  font-size: .9rem; font-weight: 600; color: var(--text-2);
}
.field .req, .label .req { color: var(--bad); margin-left: 2px; }

.input, .select, .textarea {
  width: 100%;
  min-height: 46px;
  padding: 10px 14px;
  font-size: 16px;                 /* stops iOS zoom on focus */
  line-height: 1.4;
  color: var(--text);
  background: var(--surface);
  border: 1.5px solid var(--line);
  border-radius: var(--radius-sm);
  transition: border-color var(--t-fast) var(--ease), box-shadow var(--t-fast) var(--ease), background var(--t-fast) var(--ease);
  appearance: none;
  -webkit-appearance: none;
}
.input::placeholder, .textarea::placeholder { color: var(--muted); opacity: .8; }
.input:hover, .select:hover, .textarea:hover { border-color: #cbd5e1; }
.input:focus, .select:focus, .textarea:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 4px var(--focus);
  outline: none;
}
.input:disabled, .select:disabled, .textarea:disabled, .input[readonly] {
  background: var(--surface-2); color: var(--muted); cursor: not-allowed;
}
.textarea { min-height: 96px; resize: vertical; }
.select {
  padding-right: 40px;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='20' height='20' viewBox='0 0 24 24' fill='none' stroke='%236b7280' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
}
input[type="file"].input { padding: 8px 10px; }
input[type="date"].input, input[type="time"].input, input[type="datetime-local"].input { min-height: 46px; }

.field.has-error .input, .field.has-error .select, .field.has-error .textarea { border-color: var(--bad); }
.field.has-error .input:focus, .field.has-error .select:focus, .field.has-error .textarea:focus { box-shadow: 0 0 0 4px var(--bad-bg); }
.field-error { font-size: .85rem; color: var(--bad); }
.field-help { font-size: .85rem; color: var(--muted); }

/* Input with an icon or button inside */
.input-wrap { position: relative; display: flex; align-items: center; }
.input-wrap .input { padding-left: 44px; }
.input-wrap > .icon { position: absolute; left: 14px; color: var(--muted); pointer-events: none; }
.input-wrap > .input-end { position: absolute; right: 4px; }
.input-wrap.has-end .input { padding-right: 48px; }

.form-row { display: grid; gap: 0 var(--s4); grid-template-columns: 1fr; }
@media (min-width: 640px) { .form-row-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); } .form-row-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); } }

/* Sticky action bar at the bottom of long forms */
.form-actions {
  position: sticky;
  bottom: calc(var(--bottomnav-h) + var(--safe-bottom));
  z-index: var(--z-sticky);
  display: flex; gap: var(--s3); justify-content: flex-end;
  padding: var(--s3) var(--s4);
  margin: var(--s5) calc(var(--s4) * -1) 0;
  background: var(--surface);
  border-top: 1px solid var(--line);
}
@media (min-width: 1024px) { .form-actions { bottom: 0; margin-left: 0; margin-right: 0; border-radius: 0 0 var(--radius) var(--radius); } }
@media (max-width: 479px) { .form-actions .btn { flex: 1; } }

/* Checkbox and radio */
.check { display: flex; align-items: flex-start; gap: var(--s3); min-height: 44px; padding: 8px 0; cursor: pointer; }
.check input[type="checkbox"], .check input[type="radio"] {
  appearance: none; -webkit-appearance: none;
  flex: none; width: 22px; height: 22px; margin: 1px 0 0;
  background: var(--surface);
  border: 2px solid #cbd5e1;
  border-radius: 6px;
  display: grid; place-content: center;
  transition: all var(--t-fast) var(--ease);
  cursor: pointer;
}
.check input[type="radio"] { border-radius: 50%; }
.check input:checked { background: var(--primary); border-color: var(--primary); }
.check input[type="checkbox"]:checked::after {
  content: ""; width: 5px; height: 10px; margin-top: -2px;
  border: solid #fff; border-width: 0 2.5px 2.5px 0; transform: rotate(45deg);
}
.check input[type="radio"]:checked::after { content: ""; width: 8px; height: 8px; background: #fff; border-radius: 50%; }
.check input:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; }
.check input:disabled { opacity: .5; cursor: not-allowed; }

/* Switch */
.switch { display: inline-flex; align-items: center; gap: var(--s3); min-height: 44px; cursor: pointer; }
.switch input {
  appearance: none; -webkit-appearance: none;
  position: relative; flex: none;
  width: 48px; height: 28px;
  background: #cbd5e1; border-radius: var(--radius-pill);
  transition: background var(--t-med) var(--ease); cursor: pointer;
}
.switch input::after {
  content: ""; position: absolute; top: 3px; left: 3px;
  width: 22px; height: 22px; background: #fff; border-radius: 50%;
  box-shadow: 0 1px 3px rgba(0, 0, 0, .3);
  transition: transform var(--t-med) var(--ease);
}
.switch input:checked { background: var(--ok); }
.switch input:checked::after { transform: translateX(20px); }
.switch input:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; }
.switch input:disabled { opacity: .5; cursor: not-allowed; }

/* Search box */
.search { position: relative; display: flex; align-items: center; flex: 1; min-width: 0; }
.search .icon { position: absolute; left: 14px; color: var(--muted); pointer-events: none; }
.search .input { padding-left: 44px; border-radius: var(--radius-pill); background: var(--surface); }

/* Filter chips and priority chips */
.chips { display: flex; gap: var(--s2); overflow-x: auto; padding-bottom: 2px; scrollbar-width: none; }
.chips::-webkit-scrollbar { display: none; }
.chip {
  display: inline-flex; align-items: center; gap: 6px;
  min-height: 36px; padding: 0 var(--s3);
  font-size: .9rem; font-weight: 600; white-space: nowrap;
  color: var(--text-2); background: var(--surface);
  border: 1.5px solid var(--line); border-radius: var(--radius-pill);
  transition: all var(--t-fast) var(--ease);
}
.chip:hover { text-decoration: none; border-color: var(--primary); }
.chip.is-active { color: #fff; background: var(--primary); border-color: var(--primary); }
.chip-high   { --c: var(--bad); }
.chip-medium { --c: var(--warn); }
.chip-low    { --c: var(--ok); }
.chip-high, .chip-medium, .chip-low { border-color: var(--c); color: var(--c); }
.chip-high.is-active, .chip-medium.is-active, .chip-low.is-active { background: var(--c); color: #fff; }

/* Round category letter (F R I E N D S): set --c inline to the category colour */
.cat-badge {
  --c: var(--primary);
  display: inline-grid; place-items: center; flex: none;
  width: 34px; height: 34px;
  font-weight: 700; font-size: .95rem; color: #fff;
  background: var(--c); border-radius: 50%;
}
.cat-badge.sm { width: 26px; height: 26px; font-size: .8rem; }

/* ---------- Cards ---------- */
.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: var(--s4);
  min-width: 0;
}
.card-flush { padding: 0; overflow: hidden; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: var(--s3); margin-bottom: var(--s3); }
.card-title { font-size: 1.05rem; font-weight: 700; }
.card + .card { margin-top: var(--s4); }
.card-link { display: block; color: inherit; transition: transform var(--t-fast) var(--ease), box-shadow var(--t-fast) var(--ease); }
.card-link:hover { text-decoration: none; transform: translateY(-2px); box-shadow: var(--shadow-lg); color: inherit; }

/* Stat card */
.stat { display: flex; align-items: center; gap: var(--s3); }
.stat-icon {
  display: grid; place-items: center; flex: none;
  width: 46px; height: 46px; border-radius: 14px;
  color: var(--primary); background: var(--primary-l);
}
.stat-icon.ok { color: var(--ok); background: var(--ok-bg); }
.stat-icon.warn { color: var(--warn); background: var(--warn-bg); }
.stat-icon.bad { color: var(--bad); background: var(--bad-bg); }
.stat-value { font-size: 1.55rem; font-weight: 700; line-height: 1.15; }
.stat-label { font-size: .85rem; color: var(--muted); }

/* List card: avatar, text, trailing info */
.list { display: flex; flex-direction: column; }
.list-card {
  display: flex; align-items: center; gap: var(--s3);
  padding: var(--s3) var(--s4);
  color: inherit;
  border-bottom: 1px solid var(--line);
  transition: background var(--t-fast) var(--ease);
}
.list-card:last-child { border-bottom: 0; }
a.list-card:hover { text-decoration: none; background: var(--surface-2); color: inherit; }
.list-main { flex: 1; min-width: 0; }
.list-title { font-weight: 600; }
.list-meta { font-size: .85rem; color: var(--muted); }
.list-end { flex: none; text-align: right; }

/* Alerts */
.alert {
  display: flex; gap: var(--s3); align-items: flex-start;
  padding: var(--s3) var(--s4); margin-bottom: var(--s4);
  border-radius: var(--radius-sm); border: 1px solid transparent;
  font-size: .95rem;
}
.alert .icon { margin-top: 2px; }
.alert-ok   { color: #14532d; background: var(--ok-bg);   border-color: #bbf7d0; }
.alert-warn { color: #78350f; background: var(--warn-bg); border-color: #fde68a; }
.alert-bad  { color: #7f1d1d; background: var(--bad-bg);  border-color: #fecaca; }
.alert-info { color: #0c4a6e; background: var(--info-bg); border-color: #bae6fd; }

/* Badges (status colours; classes come from badge_class() in helpers.php) */
.badge {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 2px 10px; min-height: 24px;
  font-size: .78rem; font-weight: 600; line-height: 1.4; white-space: nowrap;
  border-radius: var(--radius-pill);
  color: var(--text-2); background: var(--surface-2); border: 1px solid var(--line);
}
.badge-ok    { color: #166534; background: var(--ok-bg);   border-color: transparent; }
.badge-warn  { color: #92400e; background: var(--warn-bg); border-color: transparent; }
.badge-bad   { color: #991b1b; background: var(--bad-bg);  border-color: transparent; }
.badge-info  { color: #075985; background: var(--info-bg); border-color: transparent; }
.badge-muted { color: var(--muted); background: var(--surface-2); }
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--muted); display: inline-block; }
.dot.ok { background: var(--ok); } .dot.warn { background: var(--warn); } .dot.bad { background: var(--bad); }

/* ---------- Tables ---------- */
.table-wrap { overflow-x: auto; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); box-shadow: var(--shadow); }
.table th, .table td { padding: 12px var(--s4); text-align: left; vertical-align: middle; border-bottom: 1px solid var(--line); }
.table thead th {
  position: sticky; top: 0; z-index: 2;
  font-size: .8rem; font-weight: 700; letter-spacing: .02em; text-transform: uppercase;
  color: var(--muted); background: var(--surface-2); white-space: nowrap;
}
.table tbody tr:last-child td { border-bottom: 0; }
.table tbody tr:hover { background: var(--surface-2); }
.table .num { text-align: right; font-variant-numeric: tabular-nums; }
.table th a { color: inherit; display: inline-flex; align-items: center; gap: 4px; }
.table th a:hover { text-decoration: none; color: var(--primary); }
.table-actions { display: flex; gap: var(--s2); justify-content: flex-end; }

/* On phones every row becomes a card: no sideways scrolling.
   Each <td> needs data-label="Column name". */
@media (max-width: 767px) {
  .table-cards { display: block; }
  .table-cards thead { display: none; }
  .table-cards tbody { display: flex; flex-direction: column; gap: var(--s3); }
  .table-cards tr {
    display: block; padding: var(--s3) var(--s4);
    background: var(--surface); border: 1px solid var(--line);
    border-radius: var(--radius); box-shadow: var(--shadow-sm);
  }
  .table-cards td {
    display: flex; justify-content: space-between; align-items: center; gap: var(--s3);
    padding: 6px 0; border: 0; text-align: right;
  }
  .table-cards td::before {
    content: attr(data-label);
    flex: none; max-width: 45%; text-align: left;
    font-size: .8rem; font-weight: 600; color: var(--muted);
  }
  .table-cards td.cell-title { font-weight: 700; font-size: 1.02rem; text-align: left; justify-content: flex-start; }
  .table-cards td.cell-title::before, .table-cards td.cell-actions::before { display: none; }
  .table-cards td.cell-actions { justify-content: flex-end; padding-top: var(--s2); }
  .table-wrap:has(.table-cards) { border: 0; box-shadow: none; background: transparent; overflow: visible; }
}

/* Permission matrix: table on desktop, one card per menu on phones */
.perm-matrix td.perm-cell { text-align: center; }
.perm-matrix .check { justify-content: center; padding: 0; min-height: 36px; }
@media (max-width: 767px) {
  .perm-matrix td.perm-cell { text-align: right; }
  .perm-matrix .check { justify-content: flex-end; flex-direction: row-reverse; gap: var(--s3); }
}

/* Pagination */
.pager { display: flex; flex-wrap: wrap; gap: var(--s2); align-items: center; justify-content: center; margin-top: var(--s4); }
.pg {
  display: inline-grid; place-items: center;
  min-width: 40px; height: 40px; padding: 0 var(--s3);
  font-weight: 600; color: var(--text-2);
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius-sm);
}
.pg:hover { text-decoration: none; border-color: var(--primary); color: var(--primary); }
.pg.is-active { color: #fff; background: var(--primary); border-color: var(--primary); }
.pg.is-disabled { opacity: .45; pointer-events: none; }
.pager-info { width: 100%; text-align: center; font-size: .85rem; color: var(--muted); }

/* ---------- Tabs ---------- */
.tabs {
  display: flex; gap: var(--s1); overflow-x: auto;
  border-bottom: 1px solid var(--line); margin-bottom: var(--s4);
  scrollbar-width: none;
}
.tabs::-webkit-scrollbar { display: none; }
.tab {
  flex: none; display: inline-flex; align-items: center; gap: 6px;
  min-height: 44px; padding: 0 var(--s4);
  font-weight: 600; color: var(--muted); white-space: nowrap;
  border-bottom: 3px solid transparent; margin-bottom: -1px;
  transition: color var(--t-fast) var(--ease), border-color var(--t-fast) var(--ease);
}
.tab:hover { text-decoration: none; color: var(--primary); }
.tab.is-active { color: var(--primary); border-bottom-color: var(--primary); }
.tab-panel[hidden] { display: none !important; }

/* ---------- Dialogs: a card at the TOP of the screen on phones, centred on desktop ----------
   Phones show the dialog at the top so the on-screen keyboard never covers the fields;
   the body scrolls inside the dialog, and ui.js does not open the keyboard until you tap a field. */
.overlay {
  position: fixed; inset: 0; z-index: var(--z-modal);
  display: flex; align-items: flex-start; justify-content: center;
  padding: calc(var(--safe-top) + 10px) 10px 10px;
  background: var(--overlay);
  opacity: 0; visibility: hidden;
  transition: opacity var(--t-med) var(--ease), visibility var(--t-med);
}
.overlay.is-open { opacity: 1; visibility: visible; }

.modal {
  display: flex; flex-direction: column;
  width: 100%; max-height: calc(100vh - 20px - var(--safe-top)); max-height: calc(100dvh - 20px - var(--safe-top));
  background: var(--surface);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  transform: translateY(-28px);
  transition: transform var(--t-med) var(--ease);
  outline: none;
}
.overlay.is-open .modal { transform: translateY(0); }
.modal-head { display: flex; align-items: center; justify-content: space-between; gap: var(--s3); padding: var(--s3) var(--s4); flex: none; }
.modal-title { font-size: 1.15rem; font-weight: 700; }
.modal-body { flex: 1; min-height: 0; overflow-y: auto; padding: var(--s2) var(--s4) var(--s4); -webkit-overflow-scrolling: touch; overscroll-behavior: contain; }
.modal-foot {
  display: flex; gap: var(--s3); justify-content: flex-end; flex: none;
  padding: var(--s3) var(--s4); border-top: 1px solid var(--line);
}
@media (max-width: 479px) { .modal-foot .btn { flex: 1; } }
@media (min-width: 768px) {
  .overlay { align-items: center; padding: var(--s5); }
  .modal { width: 520px; max-width: 100%; max-height: 92vh; max-height: 92dvh; transform: translateY(14px) scale(.98); }
  .modal-lg { width: 760px; }
  .overlay.is-open .modal { transform: none; }
}

/* Confirm dialog (modal with an icon) */
.confirm-icon {
  display: grid; place-items: center; margin: 0 auto var(--s3);
  width: 56px; height: 56px; border-radius: 50%;
  color: var(--warn); background: var(--warn-bg);
}
.confirm-icon.bad { color: var(--bad); background: var(--bad-bg); }
.confirm-body { text-align: center; padding: var(--s4); }

/* ---------- Dropdown menu (profile menu, row actions) ---------- */
.dropdown { position: relative; display: inline-block; }
.dropdown-menu {
  position: absolute; right: 0; top: calc(100% + 6px); z-index: var(--z-nav);
  min-width: 200px; padding: var(--s2);
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius); box-shadow: var(--shadow-lg);
  opacity: 0; visibility: hidden; transform: translateY(-6px);
  transition: all var(--t-fast) var(--ease);
}
.dropdown.is-open > .dropdown-menu { opacity: 1; visibility: visible; transform: none; }
.menu-item {
  display: flex; align-items: center; gap: var(--s3);
  width: 100%; min-height: 42px; padding: 0 var(--s3);
  color: var(--text); font-weight: 500; text-align: left;
  border-radius: var(--radius-sm);
}
.menu-item:hover { text-decoration: none; background: var(--surface-2); color: var(--text); }
.menu-item.danger { color: var(--bad); }
.menu-sep { height: 1px; margin: var(--s2) 0; background: var(--line); }

/* ---------- Toasts ---------- */
.toasts {
  position: fixed; z-index: var(--z-toast);
  left: 50%; transform: translateX(-50%);
  bottom: calc(var(--bottomnav-h) + var(--safe-bottom) + var(--s3));
  display: flex; flex-direction: column; gap: var(--s2);
  width: min(92vw, 420px); pointer-events: none;
}
@media (min-width: 1024px) { .toasts { left: auto; right: var(--s5); transform: none; bottom: var(--s5); } }
.toast {
  display: flex; align-items: center; gap: var(--s3);
  padding: var(--s3) var(--s4);
  color: #fff; background: #1f2937;
  border-radius: var(--radius-sm); box-shadow: var(--shadow-lg);
  pointer-events: auto;
  animation: toast-in var(--t-med) var(--ease);
}
.toast.ok { background: var(--ok); } .toast.bad { background: var(--bad); }
.toast.warn { background: var(--warn); } .toast.info { background: var(--info); }
.toast.is-leaving { opacity: 0; transform: translateY(8px); transition: all var(--t-med) var(--ease); }
@keyframes toast-in { from { opacity: 0; transform: translateY(12px); } to { opacity: 1; transform: none; } }

/* ---------- Avatar ---------- */
.avatar {
  position: relative; display: inline-grid; place-items: center; flex: none;
  width: 40px; height: 40px; overflow: visible;
  font-weight: 700; font-size: .95rem; color: var(--primary-d);
  background: var(--primary-l); border-radius: 50%;
}
.avatar img { width: 100%; height: 100%; object-fit: cover; border-radius: 50%; }
.avatar-sm { width: 32px; height: 32px; font-size: .8rem; }
.avatar-lg { width: 64px; height: 64px; font-size: 1.3rem; }
.avatar-xl { width: 96px; height: 96px; font-size: 1.9rem; }
.avatar .status {
  position: absolute; right: -1px; bottom: -1px;
  width: 12px; height: 12px; border-radius: 50%;
  background: var(--muted); border: 2px solid var(--surface);
}
.avatar .status.online { background: var(--ok); }

/* ---------- Progress ---------- */
.progress { height: 10px; overflow: hidden; background: var(--line); border-radius: var(--radius-pill); }
.progress > span { display: block; height: 100%; background: linear-gradient(90deg, var(--primary), var(--info)); border-radius: inherit; transition: width var(--t-med) var(--ease); }
.progress.ok > span { background: var(--ok); }
.progress.warn > span { background: var(--warn); }
.progress.bad > span { background: var(--bad); }

/* ---------- Empty state and skeleton ---------- */
.empty { display: flex; flex-direction: column; align-items: center; gap: var(--s3); padding: var(--s7) var(--s4); text-align: center; color: var(--muted); }
.empty .icon { width: 56px; height: 56px; color: var(--line); stroke-width: 1.4; }
.empty-title { font-size: 1.1rem; font-weight: 700; color: var(--text); }

.skeleton {
  display: block; min-height: 1em;
  background: linear-gradient(90deg, var(--line) 25%, var(--surface-2) 37%, var(--line) 63%);
  background-size: 400% 100%;
  border-radius: var(--radius-sm);
  animation: shimmer 1.4s ease infinite;
}
.skeleton-line { height: 14px; margin-bottom: 10px; }
.skeleton-circle { width: 40px; height: 40px; border-radius: 50%; }
.skeleton-card { height: 96px; border-radius: var(--radius); }
@keyframes shimmer { 0% { background-position: 100% 50%; } 100% { background-position: 0 50%; } }

/* ---------- Key/value details ---------- */
.kv { display: grid; grid-template-columns: 1fr; gap: var(--s3) var(--s5); }
@media (min-width: 640px) { .kv { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
.kv dt { font-size: .8rem; font-weight: 600; color: var(--muted); }
.kv dd { font-weight: 500; }

/* ---------- Tooltip-free helpers ---------- */
.divider { display: flex; align-items: center; gap: var(--s3); color: var(--muted); font-size: .85rem; }
.divider::before, .divider::after { content: ""; flex: 1; height: 1px; background: var(--line); }

/* Screen-reader live region for toasts */
.live-region { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }

/* ---------- Member picker (assets/js/member-picker.js) ---------- */
.picker { position: relative; }
.picker-box { position: relative; display: flex; align-items: center; }
.picker-box > .icon { position: absolute; left: 14px; color: var(--muted); pointer-events: none; }
.picker-input { padding-left: 44px; padding-right: 44px; }
.picker-clear {
  position: absolute; right: 6px; display: grid; place-items: center;
  width: 34px; height: 34px; color: var(--muted); border-radius: 50%;
}
.picker-clear:hover { background: var(--surface-2); color: var(--text); }
.picker-list {
  position: absolute; left: 0; right: 0; top: calc(100% + 6px); z-index: var(--z-nav);
  max-height: 240px; overflow-y: auto;
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius); box-shadow: var(--shadow-lg); padding: var(--s1);
}
.picker-item {
  display: flex; align-items: center; gap: var(--s3);
  width: 100%; padding: 8px var(--s3); text-align: left; cursor: pointer;
  border-radius: var(--radius-sm);
}
.picker-item:hover, .picker-item.is-active { background: var(--primary-l); }
.picker-item .avatar { width: 34px; height: 34px; font-size: .8rem; }
.picker-item small { display: block; color: var(--muted); }
.picker-empty { padding: var(--s3); color: var(--muted); font-size: .9rem; }

/* ---------- Permission matrix group headings ---------- */
.perm-group td {
  font-size: .75rem; font-weight: 700; letter-spacing: .06em; text-transform: uppercase;
  color: var(--muted); background: var(--surface-2);
}
.perm-matrix thead th.perm-col { text-align: center; }
.perm-matrix .perm-na { color: var(--line); }
@media (max-width: 767px) {
  .table-cards tr.perm-group { padding: var(--s2) var(--s2) 0; background: transparent; border: 0; box-shadow: none; }
  .table-cards tr.perm-group td { display: block; padding: 6px var(--s3); border-radius: var(--radius-sm); text-align: left; }
  .table-cards tr.perm-group td::before { display: none; }
}

/* ---------- Choice cards (radio options with a description) ---------- */
.choice-grid { display: grid; gap: var(--s3); grid-template-columns: 1fr; }
@media (min-width: 640px) { .choice-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
.choice {
  position: relative; display: block; padding: var(--s4);
  background: var(--surface); border: 2px solid var(--line); border-radius: var(--radius);
  cursor: pointer; transition: border-color var(--t-fast) var(--ease), background var(--t-fast) var(--ease);
}
.choice:hover { border-color: var(--primary); }
.choice input { position: absolute; opacity: 0; pointer-events: none; }
.choice strong { display: block; margin-bottom: 2px; }
.choice .muted { font-size: .9rem; }
.choice:has(input:checked) { border-color: var(--primary); background: var(--primary-l); }
.choice:has(input:focus-visible) { outline: 3px solid var(--focus); outline-offset: 2px; }

/* ---------- Training cards ---------- */
.event-grid { display: grid; gap: var(--s4); grid-template-columns: repeat(auto-fill, minmax(min(100%, 300px), 1fr)); }
.event-card { display: flex; flex-direction: column; overflow: hidden; padding: 0; }
.event-banner {
  position: relative; display: grid; place-items: center; overflow: hidden;
  aspect-ratio: 16 / 9; color: rgba(255, 255, 255, .85); background: var(--primary);
}
.event-banner img { width: 100%; height: 100%; object-fit: cover; }
.event-banner .badge { position: absolute; top: 10px; left: 10px; box-shadow: var(--shadow-sm); }
.event-banner .date-chip {
  position: absolute; top: 10px; right: 10px; display: grid; place-items: center;
  min-width: 48px; padding: 4px 8px; line-height: 1.1; text-align: center;
  font-size: .72rem; font-weight: 700; text-transform: uppercase; letter-spacing: .04em;
  color: var(--text); background: var(--surface); border-radius: var(--radius-sm); box-shadow: var(--shadow);
}
.event-banner .date-chip b { font-size: 1.15rem; letter-spacing: 0; }
.event-body { display: flex; flex-direction: column; flex: 1; gap: var(--s2); padding: var(--s4); }
.event-title { font-size: 1.05rem; font-weight: 700; line-height: 1.3; }
.event-title a { color: inherit; }
.event-meta { display: flex; align-items: center; gap: 6px; font-size: .9rem; color: var(--muted); }
.event-foot { display: flex; flex-wrap: wrap; gap: var(--s2); padding: var(--s3) var(--s4); border-top: 1px solid var(--line); }
.event-foot .btn { flex: 1; }
