/* css/components.css - DSP components (.dsp-*). Built on tokens.css / typography.css / layout.css.
   Opt-in classes: existing pages keep their legacy classes until migrated phase by phase. Presentation only. */

/* ---------- Focus (global): one visible ring for every interactive element ---------- */
:where(a, button, input, select, textarea, summary, [tabindex]):focus-visible {
  outline: 2px solid var(--c-focus);
  outline-offset: 2px;
}

/* ---------- Button ---------- */
.dsp-btn {
  display: inline-flex; align-items: center; justify-content: center; gap: var(--s-2);
  min-height: 40px; padding: 0 var(--s-4);
  font: 600 var(--fs-button)/1.2 var(--font-sans);
  color: var(--c-text); background: var(--c-surface);
  border: 1px solid var(--c-border-strong); border-radius: var(--r-sm);
  text-decoration: none; cursor: pointer; white-space: nowrap;
  transition: background-color 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);
}
.dsp-btn:hover { background: var(--c-bg); }
.dsp-btn:active { transform: translateY(1px); }
.dsp-btn--primary { color: var(--c-text-on-primary); background: var(--c-primary); border-color: var(--c-primary); }
.dsp-btn--primary:hover { background: var(--c-primary-hover); border-color: var(--c-primary-hover); }
.dsp-btn--secondary { color: var(--c-primary); background: var(--c-primary-soft); border-color: transparent; }
.dsp-btn--secondary:hover { background: #d4eaf1; }
.dsp-btn--ghost { color: var(--c-text-secondary); background: transparent; border-color: transparent; }
.dsp-btn--ghost:hover { background: var(--c-bg); color: var(--c-text); }
.dsp-btn--danger { color: #fff; background: var(--c-danger); border-color: var(--c-danger); }
.dsp-btn--danger:hover { background: #8f1c12; border-color: #8f1c12; }
.dsp-btn--sm { min-height: 32px; padding: 0 var(--s-3); font-size: var(--fs-label); }
.dsp-btn--lg { min-height: 48px; padding: 0 var(--s-6); font-size: 1rem; }
.dsp-btn--block { width: 100%; }
.dsp-btn[disabled], .dsp-btn[aria-disabled="true"] { opacity: .55; cursor: not-allowed; transform: none; }
.dsp-btn[aria-busy="true"] { position: relative; color: transparent; pointer-events: none; }
.dsp-btn[aria-busy="true"]::after {
  content: ""; position: absolute; width: 16px; height: 16px; border-radius: 50%;
  border: 2px solid currentColor; border-color: #fff transparent #fff transparent;
  animation: dsp-spin .7s linear infinite;
}
.dsp-btn--secondary[aria-busy="true"]::after, .dsp-btn:not(.dsp-btn--primary):not(.dsp-btn--danger)[aria-busy="true"]::after { border-color: var(--c-primary) transparent var(--c-primary) transparent; }
@keyframes dsp-spin { to { transform: rotate(360deg); } }

.dsp-icon-btn {
  display: inline-grid; place-items: center; width: 40px; height: 40px;
  color: var(--c-text-secondary); background: transparent; border: 1px solid transparent; border-radius: var(--r-sm); cursor: pointer;
  transition: background-color var(--t-fast) var(--ease), color var(--t-fast) var(--ease);
}
.dsp-icon-btn:hover { background: var(--c-bg); color: var(--c-text); }
.dsp-icon-btn--danger:hover { background: var(--c-danger-bg); color: var(--c-danger); }
.dsp-icon-btn--success:hover { background: var(--c-success-bg); color: var(--c-success); }

/* ---------- Form fields ---------- */
.dsp-field { display: flex; flex-direction: column; gap: var(--s-1); min-width: 0; }
.dsp-label { font: 600 var(--fs-label)/var(--lh-label) var(--font-sans); color: var(--c-text); }
.dsp-hint { font-size: var(--fs-caption); line-height: var(--lh-caption); color: var(--c-text-muted); }
.dsp-error { font-size: var(--fs-caption); line-height: var(--lh-caption); color: var(--c-danger); font-weight: 500; }
.dsp-input, .dsp-select, .dsp-textarea {
  width: 100%; min-height: 40px; padding: 0 var(--s-3);
  font: 400 var(--fs-body)/1.4 var(--font-sans); color: var(--c-text);
  background: var(--c-surface); border: 1px solid var(--c-border-strong); border-radius: var(--r-sm);
  transition: border-color var(--t-fast) var(--ease), box-shadow var(--t-fast) var(--ease);
}
.dsp-textarea { min-height: 96px; padding: var(--s-2) var(--s-3); resize: vertical; }
.dsp-input::placeholder, .dsp-textarea::placeholder { color: var(--c-text-muted); }
.dsp-input:hover, .dsp-select:hover, .dsp-textarea:hover { border-color: var(--c-text-muted); }
.dsp-input:focus-visible, .dsp-select:focus-visible, .dsp-textarea:focus-visible { outline: none; border-color: var(--c-focus); box-shadow: 0 0 0 3px rgba(26, 143, 176, .25); }
.dsp-input[aria-invalid="true"], .dsp-select[aria-invalid="true"], .dsp-textarea[aria-invalid="true"] { border-color: var(--c-danger); }
.dsp-input:disabled, .dsp-select:disabled, .dsp-textarea:disabled { background: var(--c-bg); color: var(--c-text-muted); cursor: not-allowed; }
.dsp-search { position: relative; display: block; }
.dsp-search > i, .dsp-search > svg { position: absolute; left: var(--s-3); top: 50%; transform: translateY(-50%); color: var(--c-text-muted); pointer-events: none; }
.dsp-search > .dsp-input { padding-left: calc(var(--s-3) * 2 + 14px); }

/* ---------- Card / StatCard ---------- */
.dsp-card { background: var(--c-surface); border: 1px solid var(--c-border); border-radius: var(--r-md); box-shadow: var(--e-1); }
.dsp-card__body { padding: var(--s-5); }
.dsp-card__header { display: flex; align-items: center; justify-content: space-between; gap: var(--s-3); padding: var(--s-4) var(--s-5); border-bottom: 1px solid var(--c-border); }
.dsp-card__title { font: 600 var(--fs-h3)/var(--lh-h3) var(--font-sans); margin: 0; color: var(--c-text); }
.dsp-stat { display: flex; flex-direction: column; gap: var(--s-1); padding: var(--s-4) var(--s-5); }
.dsp-stat__label { font: 500 var(--fs-label)/var(--lh-label) var(--font-sans); color: var(--c-text-secondary); }
.dsp-stat__value { font: 700 1.625rem/1.2 var(--font-sans); color: var(--c-text); font-variant-numeric: tabular-nums; letter-spacing: -0.01em; }
.dsp-stat__delta { font-size: var(--fs-caption); color: var(--c-text-muted); }

/* ---------- Badge / Avatar ---------- */
.dsp-badge { display: inline-flex; align-items: center; gap: 6px; padding: 2px var(--s-2); font: 600 var(--fs-caption)/1.4 var(--font-sans); border-radius: var(--r-pill); color: var(--c-info); background: var(--c-info-bg); white-space: nowrap; }
.dsp-badge--success { color: var(--c-success); background: var(--c-success-bg); }
.dsp-badge--warning { color: var(--c-warning); background: var(--c-warning-bg); }
.dsp-badge--danger { color: var(--c-danger); background: var(--c-danger-bg); }
.dsp-badge--neutral { color: var(--c-text-secondary); background: var(--c-bg); border: 1px solid var(--c-border); }
.dsp-avatar { display: inline-grid; place-items: center; width: 36px; height: 36px; border-radius: 50%; background: var(--c-primary-soft); color: var(--c-primary); font: 600 var(--fs-label)/1 var(--font-sans); overflow: hidden; flex: none; }
.dsp-avatar img { width: 100%; height: 100%; object-fit: cover; }
.dsp-avatar--lg { width: 64px; height: 64px; font-size: 1.25rem; }

/* ---------- Tabs ---------- */
.dsp-tabs { display: flex; gap: var(--s-1); border-bottom: 1px solid var(--c-border); overflow-x: auto; }
.dsp-tab { padding: var(--s-3) var(--s-4); font: 600 var(--fs-button)/1 var(--font-sans); color: var(--c-text-secondary); background: none; border: 0; border-bottom: 2px solid transparent; margin-bottom: -1px; cursor: pointer; white-space: nowrap; }
.dsp-tab:hover { color: var(--c-text); }
.dsp-tab[aria-selected="true"] { color: var(--c-primary); border-bottom-color: var(--c-primary); }

/* ---------- Data table (+ mobile card mode: add .dsp-table--cards and data-label on each td) ---------- */
.dsp-table-wrap { overflow-x: auto; max-width: 100%; background: var(--c-surface); border: 1px solid var(--c-border); border-radius: var(--r-md); }
.dsp-table { width: 100%; border-collapse: collapse; font-size: var(--fs-body-sm); }
.dsp-table caption { text-align: left; padding: var(--s-3) var(--s-4); font-weight: 600; }
.dsp-table th { position: sticky; top: 0; padding: var(--s-3) var(--s-4); text-align: left; font: 600 var(--fs-label)/var(--lh-label) var(--font-sans); color: var(--c-text-secondary); background: var(--c-bg); border-bottom: 1px solid var(--c-border); white-space: nowrap; }
.dsp-table td { padding: var(--s-3) var(--s-4); border-bottom: 1px solid var(--c-border); vertical-align: middle; }
.dsp-table tbody tr:last-child td { border-bottom: 0; }
.dsp-table tbody tr:hover { background: #fafbfc; }
.dsp-table .dsp-num { text-align: right; font-variant-numeric: tabular-nums; }
@media (max-width: 640px) {
  .dsp-table--cards thead { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
  .dsp-table--cards, .dsp-table--cards tbody, .dsp-table--cards tr, .dsp-table--cards td { display: block; width: 100%; }
  .dsp-table--cards tr { padding: var(--s-3) var(--s-4); border-bottom: 1px solid var(--c-border); }
  .dsp-table--cards td { display: flex; justify-content: space-between; gap: var(--s-4); padding: var(--s-1) 0; border: 0; text-align: right; }
  .dsp-table--cards td::before { content: attr(data-label); flex: none; color: var(--c-text-muted); font-weight: 600; text-align: left; }
}

/* ---------- Pagination ---------- */
.dsp-pagination { display: flex; align-items: center; justify-content: space-between; gap: var(--s-3); padding: var(--s-3) var(--s-4); font-size: var(--fs-body-sm); color: var(--c-text-secondary); }
.dsp-pagination__pages { display: flex; gap: var(--s-1); }

/* ---------- States: empty / loading / error ---------- */
.dsp-state { display: flex; flex-direction: column; align-items: center; gap: var(--s-2); padding: var(--s-8) var(--s-5); text-align: center; color: var(--c-text-secondary); }
.dsp-state__icon { font-size: 1.75rem; color: var(--c-text-muted); }
.dsp-state__title { font: 600 var(--fs-h3)/var(--lh-h3) var(--font-sans); color: var(--c-text); margin: 0; }
.dsp-state--error .dsp-state__icon { color: var(--c-danger); }
.dsp-skeleton { display: block; height: 14px; border-radius: var(--r-sm); background: linear-gradient(90deg, var(--c-border) 25%, #eef2f6 50%, var(--c-border) 75%); background-size: 200% 100%; animation: dsp-shimmer 1.3s linear infinite; }
@keyframes dsp-shimmer { to { background-position: -200% 0; } }

/* ---------- Page header / section header / breadcrumb ---------- */
.dsp-page-header { display: flex; flex-wrap: wrap; align-items: flex-end; justify-content: space-between; gap: var(--s-3) var(--s-4); margin-bottom: var(--s-5); }
.dsp-page-header__title { margin: 0; font: 700 var(--fs-h1)/var(--lh-h1) var(--font-sans); letter-spacing: -0.015em; color: var(--c-text); }
.dsp-page-header__sub { margin: var(--s-1) 0 0; color: var(--c-text-secondary); font-size: var(--fs-body-sm); }
.dsp-page-header__actions { display: flex; flex-wrap: wrap; gap: var(--s-2); }
.dsp-section-header { display: flex; align-items: center; justify-content: space-between; gap: var(--s-3); margin: var(--s-6) 0 var(--s-3); }
.dsp-section-header h2, .dsp-section-header h3 { margin: 0; font: 600 var(--fs-h3)/var(--lh-h3) var(--font-sans); }
.dsp-breadcrumb { display: flex; flex-wrap: wrap; gap: var(--s-2); margin: 0 0 var(--s-2); padding: 0; list-style: none; font-size: var(--fs-caption); color: var(--c-text-muted); }
.dsp-breadcrumb li + li::before { content: "/"; margin-right: var(--s-2); }
.dsp-breadcrumb a { color: var(--c-text-secondary); text-decoration: none; }
.dsp-breadcrumb a:hover { color: var(--c-primary); text-decoration: underline; }

/* ---------- Dialog (Modal / ConfirmDialog; built by js/core/ui.js) ---------- */
.dsp-overlay { position: fixed; inset: 0; z-index: 1000; display: grid; place-items: center; padding: var(--s-4); background: rgba(15, 27, 42, .5); animation: dsp-fade var(--t-base) var(--ease); }
.dsp-dialog { width: min(440px, 100%); max-height: calc(100vh - 32px); overflow: auto; background: var(--c-surface-elevated); border-radius: var(--r-lg); box-shadow: var(--e-3); padding: var(--s-6); animation: dsp-pop var(--t-slow) var(--ease); }
.dsp-dialog__title { margin: 0 0 var(--s-2); font: 650 var(--fs-h3)/var(--lh-h3) var(--font-sans); color: var(--c-text); }
.dsp-dialog__body { margin: 0 0 var(--s-5); color: var(--c-text-secondary); font-size: var(--fs-body); overflow-wrap: anywhere; }
.dsp-dialog__actions { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: var(--s-2); }
@media (max-width: 480px) {
  .dsp-overlay { align-items: end; padding: 0; }
  .dsp-dialog { width: 100%; border-radius: var(--r-lg) var(--r-lg) 0 0; }
  .dsp-dialog__actions .dsp-btn { flex: 1 1 auto; }
}
@keyframes dsp-fade { from { opacity: 0; } }
@keyframes dsp-pop { from { opacity: 0; transform: translateY(8px) scale(.98); } }

/* ---------- Toast ---------- */
.dsp-toasts { position: fixed; z-index: 1100; right: var(--s-4); bottom: var(--s-4); display: flex; flex-direction: column; gap: var(--s-2); width: min(380px, calc(100vw - 32px)); pointer-events: none; }
.dsp-toast { display: flex; align-items: flex-start; gap: var(--s-3); padding: var(--s-3) var(--s-4); background: var(--c-surface-elevated); border: 1px solid var(--c-border); border-left: 4px solid var(--c-info); border-radius: var(--r-md); box-shadow: var(--e-2); font-size: var(--fs-body-sm); color: var(--c-text); pointer-events: auto; animation: dsp-pop var(--t-base) var(--ease); overflow-wrap: anywhere; }
.dsp-toast--success { border-left-color: var(--c-success); }
.dsp-toast--warning { border-left-color: var(--c-warning); }
.dsp-toast--error { border-left-color: var(--c-danger); }
.dsp-toast__msg { flex: 1; }
.dsp-toast__close { flex: none; background: none; border: 0; padding: 0 var(--s-1); font-size: 1.1rem; line-height: 1; color: var(--c-text-muted); cursor: pointer; }
/* phones: dialogs are bottom sheets, so toasts go to the top where they never cover the buttons */
@media (max-width: 480px) { .dsp-toasts { right: var(--s-4); left: var(--s-4); top: calc(var(--s-4) + env(safe-area-inset-top, 0px)); bottom: auto; width: auto; } }

/* ---------- Utilities ---------- */
.dsp-sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

@media (pointer: coarse) {
  .dsp-btn, .dsp-icon-btn, .dsp-input, .dsp-select, .dsp-tab { min-height: var(--tap); }
  .dsp-icon-btn { min-width: var(--tap); }
}
@media (prefers-reduced-motion: reduce) {
  .dsp-btn, .dsp-icon-btn, .dsp-input, .dsp-overlay, .dsp-dialog, .dsp-toast { transition: none; animation: none; }
  .dsp-skeleton { animation: none; }
  .dsp-btn[aria-busy="true"]::after { animation-duration: 1.6s; }
}

/* ---- images in support messages (js/core/support-images.js): the thumbnail inside a bubble, and the chosen image above the reply box */
.chat-image { display: block; max-width: 100%; margin: 0 0 6px; padding: 0; border: 0; border-radius: 10px; overflow: hidden; background: rgba(15, 27, 42, 0.08); color: inherit; font: inherit; cursor: zoom-in; }
.chat-image:last-child { margin-bottom: 0; }
.chat-image img { display: block; width: 100%; height: 100%; object-fit: cover; }
.chat-image:disabled { cursor: default; }
.chat-image:focus-visible { outline: none; box-shadow: var(--focus-ring); }
.chat-image-note { display: grid; place-items: center; width: 100%; height: 100%; padding: 8px; font-size: 0.75rem; line-height: 1.3; text-align: center; opacity: 0.85; }
.chat-attach { display: flex; align-items: center; gap: var(--s-2); max-width: 100%; margin-bottom: var(--s-2); padding: 6px; border: 1px solid var(--c-border); border-radius: var(--r-md); background: var(--c-bg); }
.chat-attach[hidden] { display: none; }
.chat-attach img { flex: none; width: 48px; height: 48px; border-radius: var(--r-sm); object-fit: cover; background: var(--c-surface); }
.chat-attach-name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 0.86rem; color: var(--c-text-secondary); }
.chat-attach-remove { flex: none; display: inline-grid; place-items: center; width: 44px; height: 44px; border: 0; border-radius: 50%; background: none; color: var(--c-text-secondary); font-size: 1rem; cursor: pointer; }
.chat-attach-remove:hover { background: var(--c-danger-bg); color: var(--c-danger); }
.chat-attach-remove:focus-visible { outline: none; box-shadow: var(--focus-ring); }
.chat-attach-btn { flex: none; display: inline-grid; place-items: center; width: 44px; height: 44px; border: 1px solid var(--c-border-strong); border-radius: 14px; background: var(--c-surface); color: var(--c-text-secondary); font-size: 1.05rem; cursor: pointer; }
.chat-attach-btn:hover { background: var(--c-primary-soft); color: var(--c-primary); border-color: var(--c-primary); }
.chat-attach-btn:focus-visible { outline: none; box-shadow: var(--focus-ring); }
.chat-attach-btn:disabled { opacity: 0.6; cursor: progress; }
.chat-attach-btn[hidden] { display: none; }

/* ---- profile pictures (one set of rules for every avatar; js/core/photos.js showPhoto fills them)
   A profile photo is stored as a square and shown in a circle: it always fills its circle (cover), is never stretched, and a picture that cannot be
   loaded becomes the person's initials. --avatar-pos moves the visible part for a picture that is not square (legacy photos). Document previews
   (Student ID, Class Card) keep their own shape and are not avatars. Sizes: the small one in menus, .dsp-avatar--lg, and .dsp-avatar--profile. */
.dsp-avatar img, img.dsp-avatar, .sidebar-profile img, .profile-image { display: block; border-radius: 50%; object-fit: cover; object-position: var(--avatar-pos, center); background: var(--c-primary-soft); }
.dsp-avatar img, .profile-image { width: 100%; height: 100%; }
img.dsp-avatar { padding: 0; }
.dsp-avatar--sm { width: 32px; height: 32px; }
.dsp-avatar--profile { width: var(--avatar-profile, 112px); height: var(--avatar-profile, 112px); }
:root { --avatar-profile: 112px; }
@media (min-width: 600px) { :root { --avatar-profile: 124px; } }
@media (min-width: 1024px) { :root { --avatar-profile: 136px; } }

/* "Position your photo" (js/core/photo-crop.js) */
.photo-crop { width: min(400px, 100%); }
.photo-crop__help { margin: 0 0 var(--s-4); color: var(--c-text-secondary); font-size: var(--fs-body); line-height: 1.5; }
.photo-crop__stage { position: relative; width: min(280px, 100%); aspect-ratio: 1; margin: 0 auto var(--s-4); border-radius: var(--r-md); overflow: hidden; background: var(--c-bg); cursor: grab; touch-action: none; user-select: none; -webkit-user-select: none; }
.photo-crop__stage.dragging { cursor: grabbing; }
.photo-crop__stage:focus-visible { outline: none; box-shadow: var(--focus-ring); }
.photo-crop__canvas { display: block; width: 100%; height: 100%; }
/* the circle the app shows; outside it (the corners) is dimmed but still part of the printed square */
.photo-crop__ring { position: absolute; inset: 0; border-radius: 50%; box-shadow: 0 0 0 999px rgba(15, 27, 42, 0.45); border: 2px solid rgba(255, 255, 255, 0.9); pointer-events: none; }
.photo-crop__zoom { display: flex; align-items: center; gap: var(--s-3); margin: 0 0 var(--s-5); font-weight: 600; font-size: var(--fs-label, 0.875rem); color: var(--c-text-secondary); }
.photo-crop__zoom input { flex: 1; min-width: 0; height: 44px; margin: 0; accent-color: var(--c-primary); }
