/* ============================================================
   admin.css
   DMO Connect — Admin Portal styles
   Used exclusively by AdminPortalWorker.js
   All classes prefixed .ap- to avoid collisions.
   ============================================================ */

/* ── Shell ────────────────────────────────────────────────────── */
.ap-shell {
  display: flex;
  flex-direction: column;
  height: 100%;
  overflow: hidden;
  background: var(--bg, #f8fafc);
  font-family: 'DM Sans', system-ui, sans-serif;
}
.theme-dark .ap-shell { background: #0a0a0f; }

/* ── Top bar ──────────────────────────────────────────────────── */
.ap-topbar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 14px 16px 0;
  flex-shrink: 0;
}

.ap-topbar-title {
  font-size: .8rem;
  font-weight: 800;
  letter-spacing: .06em;
  text-transform: uppercase;
  color: var(--text-tertiary, #8E8E93);
  flex-shrink: 0;
}

/* ── View tabs ────────────────────────────────────────────────── */
.ap-tabs {
  display: flex;
  gap: 4px;
  background: rgba(0,0,0,.05);
  border-radius: 10px;
  padding: 3px;
  margin-left: auto;
}
.theme-dark .ap-tabs { background: rgba(255,255,255,.07); }

.ap-tab {
  border: none;
  background: none;
  padding: 6px 12px;
  border-radius: 8px;
  font-size: .8rem;
  font-weight: 600;
  color: var(--text-tertiary, #8E8E93);
  cursor: pointer;
  font-family: inherit;
  transition: background .15s, color .15s;
  display: inline-flex;
  align-items: center;
  gap: 5px;
  white-space: nowrap;
}
.ap-tab--active {
  background: #fff;
  color: var(--accent, #007AFF);
  box-shadow: 0 1px 4px rgba(0,0,0,.10);
}
.theme-dark .ap-tab--active {
  background: #1e293b;
  color: var(--accent, #007AFF);
}

/* ── Content area (scrollable) ────────────────────────────────── */
.ap-content {
  flex: 1;
  overflow-y: auto;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
  padding: 14px 14px 100px;
}

/* ── Loading spinner ──────────────────────────────────────────── */
.ap-loading {
  display: flex;
  justify-content: center;
  padding: 60px 0;
}
.ap-spinner {
  width: 26px; height: 26px;
  border: 3px solid rgba(0,0,0,.10);
  border-top-color: var(--accent, #007AFF);
  border-radius: 50%;
  animation: ap-spin .7s linear infinite;
}
@keyframes ap-spin { to { transform: rotate(360deg); } }
.theme-dark .ap-spinner {
  border-color: rgba(255,255,255,.10);
  border-top-color: var(--accent, #007AFF);
}

/* ── Empty state ──────────────────────────────────────────────── */
.ap-empty {
  text-align: center;
  padding: 40px 20px;
  color: var(--text-tertiary, #8E8E93);
  font-size: .88rem;
}

/* ═══════════════════════════════════════════════════════════════
   DASHBOARD
   ═══════════════════════════════════════════════════════════════ */

.ap-dashboard {
  display: flex;
  flex-direction: column;
  gap: 18px;
  max-width: 1200px;
  margin-inline: auto;
  width: 100%;
}

.ap-stats-grid {
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  gap: 10px;
}
@media (max-width: 900px) {
  .ap-stats-grid { grid-template-columns: repeat(3, 1fr); }
}

.ap-stat-card {
  background: #fff;
  border-radius: 14px;
  padding: 14px 12px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  box-shadow: 0 1px 6px rgba(0,0,0,.06);
}
.theme-dark .ap-stat-card {
  background: #1a1a2e;
  box-shadow: 0 1px 6px rgba(0,0,0,.25);
}

.ap-stat-card--accent { border-top: 3px solid var(--accent, #007AFF); }
.ap-stat-card--warn   { border-top: 3px solid #f59e0b; }

.ap-stat-val {
  font-size: 1.55rem;
  font-weight: 800;
  color: var(--text-primary, #1C1C1E);
  font-family: 'DM Mono', monospace;
  line-height: 1;
}
.ap-stat-label {
  font-size: .66rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .05em;
  color: var(--text-tertiary, #8E8E93);
  text-align: center;
}

.ap-section {
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.ap-section-title {
  font-size: .75rem;
  font-weight: 700;
  letter-spacing: .06em;
  text-transform: uppercase;
  color: var(--text-tertiary, #8E8E93);
}

.ap-mini-bar {
  height: 4px;
  background: rgba(0,0,0,.07);
  border-radius: 99px;
  overflow: hidden;
  min-width: 48px;
}
.theme-dark .ap-mini-bar { background: rgba(255,255,255,.09); }

.ap-mini-bar-fill { height: 100%; border-radius: 99px; transition: width .3s ease; }
.ap-mini-bar-fill--low  { background: #22c55e; }
.ap-mini-bar-fill--half { background: #f59e0b; }
.ap-mini-bar-fill--full { background: #ef4444; }

.ap-cap-badge {
  display: inline-flex;
  align-items: center;
  padding: 2px 9px;
  border-radius: 99px;
  font-size: .72rem;
  font-weight: 700;
  font-family: 'DM Mono', monospace;
  background: rgba(0,0,0,.05);
  color: var(--text-secondary, #3C3C43);
}
.ap-cap-badge--partial { background: rgba(0,122,255,.10); color: var(--accent, #007AFF); }
.ap-cap-badge--full    { background: rgba(239,68,68,.12); color: #ef4444; }
.theme-dark .ap-cap-badge { background: rgba(255,255,255,.08); color: var(--text-secondary); }

.ap-dist-name   { font-size: .86rem; font-weight: 600; color: var(--text-primary); }
.ap-dist-region { font-size: .72rem; color: var(--text-tertiary); margin-top: 1px; }

.ap-unplaced-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
  background: rgba(245,158,11,.06);
  border: 1px solid rgba(245,158,11,.20);
  border-radius: 12px;
  padding: 10px 12px;
}
.theme-dark .ap-unplaced-list { background: rgba(245,158,11,.08); }

.ap-unplaced-row { display: flex; align-items: center; gap: 10px; }
.ap-unplaced-name { font-size: .85rem; font-weight: 600; color: var(--text-primary); }
.ap-unplaced-sub  { font-size: .72rem; color: var(--text-tertiary); }
.ap-unplaced-info { display: flex; flex-direction: column; gap: 1px; }

/* ═══════════════════════════════════════════════════════════════
   STUDENTS VIEW
   ═══════════════════════════════════════════════════════════════ */

.ap-students {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.ap-toolbar {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.ap-search-wrap {
  flex: 1;
  min-width: 140px;
  position: relative;
  display: flex;
  align-items: center;
}
.ap-search-icon {
  position: absolute;
  left: 10px;
  color: var(--text-tertiary);
  pointer-events: none;
}
.ap-search {
  width: 100%;
  background: #fff;
  border: 1.5px solid rgba(0,0,0,.10);
  border-radius: 99px;
  padding: 8px 12px 8px 32px;
  font-size: .83rem;
  font-family: inherit;
  color: var(--text-primary);
  outline: none;
  transition: border-color .15s, box-shadow .15s;
}
.ap-search:focus {
  border-color: var(--accent, #007AFF);
  box-shadow: 0 0 0 3px rgba(0,122,255,.10);
}
.theme-dark .ap-search {
  background: #1a1a2e;
  border-color: rgba(255,255,255,.10);
  color: #fff;
}

.ap-select {
  background: #fff;
  border: 1.5px solid rgba(0,0,0,.10);
  border-radius: 8px;
  padding: 8px 10px;
  font-size: .82rem;
  font-family: inherit;
  color: var(--text-primary);
  outline: none;
  cursor: pointer;
  transition: border-color .15s;
}
.ap-select:focus { border-color: var(--accent, #007AFF); }
.theme-dark .ap-select {
  background: #1a1a2e;
  border-color: rgba(255,255,255,.10);
  color: #fff;
}

/* ── Buttons ──────────────────────────────────────────────────── */
.ap-btn {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 8px 14px;
  border-radius: 8px;
  border: none;
  font-size: .8rem;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  white-space: nowrap;
  transition: opacity .15s, transform .1s, background .15s;
  -webkit-tap-highlight-color: transparent;
}
.ap-btn:active { transform: scale(.97); }

.ap-btn--outline {
  background: none;
  border: 1.5px solid var(--accent, #007AFF);
  color: var(--accent, #007AFF);
}
.ap-btn--outline:hover { background: rgba(0,122,255,.07); }

.ap-btn--primary {
  background: var(--accent, #007AFF);
  color: #fff;
  border: none;
}
.ap-btn--primary:hover   { opacity: .9; }
.ap-btn--primary:disabled { opacity: .5; cursor: not-allowed; }

.ap-btn--reset {
  background: rgba(245,158,11,.10);
  color: #b45309;
  border: 1px solid rgba(245,158,11,.25);
  padding: 4px 9px;
  font-size: .72rem;
  border-radius: 6px;
}
.ap-btn--reset:hover    { background: rgba(245,158,11,.18); }
.ap-btn--reset:disabled { opacity: .45; cursor: not-allowed; }
.theme-dark .ap-btn--reset {
  background: rgba(245,158,11,.12);
  color: #fbbf24;
  border-color: rgba(245,158,11,.20);
}

/* ── Assign District button ─────────────────────────────────────── */
.ap-btn--assign {
  background: rgba(0,122,255,.08);
  color: var(--accent, #007AFF);
  border: 1px solid rgba(0,122,255,.22);
  padding: 4px 9px;
  font-size: .72rem;
  border-radius: 6px;
}
.ap-btn--assign:hover { background: rgba(0,122,255,.16); }

/* Confirm assign (green) */
.ap-btn--assign-confirm {
  background: #22c55e;
  color: #fff;
  border: none;
  padding: 5px 11px;
  font-size: .75rem;
  border-radius: 6px;
}
.ap-btn--assign-confirm:hover   { background: #16a34a; }
.ap-btn--assign-confirm:disabled { opacity: .5; cursor: not-allowed; }

/* Cancel assign (neutral) */
.ap-btn--assign-cancel {
  background: rgba(0,0,0,.06);
  color: var(--text-secondary);
  border: none;
  padding: 5px 9px;
  font-size: .75rem;
  border-radius: 6px;
}
.ap-btn--assign-cancel:hover { background: rgba(0,0,0,.12); }
.theme-dark .ap-btn--assign-cancel { background: rgba(255,255,255,.09); }

/* ── Assign district inline wrapper ─────────────────────────────── */
.ap-assign-wrap {
  display: flex;
  align-items: center;
  gap: 5px;
  flex-wrap: wrap;
  min-width: 0;
}

.ap-select--assign {
  padding: 5px 8px;
  font-size: .76rem;
  border-radius: 6px;
  min-width: 140px;
  max-width: 200px;
}

/* Full districts shown in muted italic inside the select */
.ap-opt--full { color: #ef4444; font-style: italic; }

/* ── Table ────────────────────────────────────────────────────── */
.ap-table-wrap {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  border-radius: 12px;
  box-shadow: 0 1px 6px rgba(0,0,0,.07);
  background: #fff;
}
.theme-dark .ap-table-wrap {
  background: #1a1a2e;
  box-shadow: 0 1px 6px rgba(0,0,0,.25);
}

.ap-table {
  width: 100%;
  border-collapse: collapse;
  font-size: .83rem;
}

.ap-th {
  padding: 10px 12px;
  text-align: left;
  font-size: .68rem;
  font-weight: 700;
  letter-spacing: .06em;
  text-transform: uppercase;
  color: var(--text-tertiary);
  border-bottom: 1px solid rgba(0,0,0,.07);
  white-space: nowrap;
  background: rgba(0,0,0,.02);
}
.theme-dark .ap-th {
  border-bottom-color: rgba(255,255,255,.07);
  background: rgba(255,255,255,.03);
}

.ap-th--center { text-align: center; }

.ap-th--sortable {
  cursor: pointer;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
  transition: color .12s;
}
.ap-th--sortable:hover { color: var(--accent, #007AFF); }
.ap-th--sortable svg   { vertical-align: middle; margin-left: 3px; }

.ap-tr {
  border-bottom: 1px solid rgba(0,0,0,.05);
  transition: background .10s;
}
.ap-tr:last-child { border-bottom: none; }
.ap-tr:hover { background: rgba(0,122,255,.03); }
.theme-dark .ap-tr { border-bottom-color: rgba(255,255,255,.05); }
.theme-dark .ap-tr:hover { background: rgba(255,255,255,.04); }

.ap-td {
  padding: 10px 12px;
  color: var(--text-primary);
  vertical-align: middle;
}

.ap-td--center  { text-align: center; }
.ap-td--mono    { font-family: 'DM Mono', monospace; font-size: .78rem; }
.ap-td--muted   { color: var(--text-tertiary); font-size: .78rem; }
.ap-td--actions { white-space: nowrap; }

.ap-empty-row {
  padding: 24px;
  text-align: center;
  color: var(--text-tertiary);
}

/* ── Student cell ─────────────────────────────────────────────── */
.ap-student-cell {
  display: flex;
  align-items: center;
  gap: 9px;
  min-width: 140px;
}
.ap-student-name  { font-size: .85rem; font-weight: 600; color: var(--text-primary); }
.ap-student-email { font-size: .72rem; color: var(--text-tertiary); }

/* ── Avatars ──────────────────────────────────────────────────── */
.ap-av {
  width: 28px; height: 28px;
  border-radius: 50%;
  flex-shrink: 0;
  display: grid;
  place-items: center;
}
.ap-av--img  { object-fit: cover; border: 1.5px solid rgba(0,0,0,.07); }
.ap-av--init { font-size: .6rem; font-weight: 700; color: #fff; }
.ap-av--more {
  background: rgba(0,0,0,.08);
  font-size: .6rem; font-weight: 700;
  color: var(--text-tertiary);
  margin-left: -6px;
}
.ap-td--avatars { min-width: 80px; }
.ap-td--avatars .ap-av { margin-left: -6px; }
.ap-td--avatars .ap-av:first-child { margin-left: 0; }
.ap-td--avatars > .ap-av,
.ap-td--avatars > .ap-av--more { display: inline-grid; }

/* ── Chips ────────────────────────────────────────────────────── */
.ap-dist-chip {
  display: inline-flex;
  align-items: center;
  padding: 3px 9px;
  border-radius: 99px;
  background: rgba(0,122,255,.10);
  color: var(--accent, #007AFF);
  font-size: .74rem;
  font-weight: 600;
  white-space: nowrap;
}

.ap-unplaced-chip {
  display: inline-flex;
  align-items: center;
  padding: 3px 9px;
  border-radius: 99px;
  background: rgba(245,158,11,.10);
  color: #b45309;
  font-size: .74rem;
  font-weight: 600;
}
.theme-dark .ap-unplaced-chip { background: rgba(245,158,11,.14); color: #fbbf24; }

.ap-no-action { color: var(--text-tertiary); font-size: .78rem; }

/* ── Action group ─────────────────────────────────────────────── */
.ap-action-group {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 4px;
}

/* ── Promote / Demote buttons ─────────────────────────────────── */
.ap-btn--promote {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 4px 10px;
  border-radius: 20px;
  font-size: .72rem;
  font-weight: 700;
  cursor: pointer;
  border: 1.5px solid var(--accent, #007aff);
  color: var(--accent, #007aff);
  background: color-mix(in srgb, var(--accent, #007aff) 8%, transparent);
  transition: background .15s, transform .12s;
  white-space: nowrap;
  font-family: inherit;
}
.ap-btn--promote:hover    { background: color-mix(in srgb, var(--accent, #007aff) 16%, transparent); }
.ap-btn--promote:active   { transform: scale(.9); }
.ap-btn--promote:disabled { opacity: .45; cursor: default; }

.ap-btn--demote {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 4px 10px;
  border-radius: 20px;
  font-size: .72rem;
  font-weight: 700;
  cursor: pointer;
  border: 1.5px solid #ef4444;
  color: #ef4444;
  background: rgba(239,68,68,.08);
  transition: background .15s, transform .12s;
  white-space: nowrap;
  font-family: inherit;
}
.ap-btn--demote:hover    { background: rgba(239,68,68,.15); }
.ap-btn--demote:active   { transform: scale(.9); }
.ap-btn--demote:disabled { opacity: .45; cursor: default; }

/* ── Role chip ────────────────────────────────────────────────── */
.ap-role-chip {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 20px;
  font-size: .68rem;
  font-weight: 700;
  letter-spacing: .02em;
  text-transform: capitalize;
}
.ap-role-chip--admin {
  background: color-mix(in srgb, var(--accent, #007aff) 12%, transparent);
  color: var(--accent, #007aff);
  border: 1px solid color-mix(in srgb, var(--accent, #007aff) 25%, transparent);
}
.ap-role-chip--student {
  background: rgba(34,197,94,.10);
  color: #16a34a;
  border: 1px solid rgba(34,197,94,.25);
}
.ap-role-chip--supervisor {
  background: rgba(168,85,247,.10);
  color: #9333ea;
  border: 1px solid rgba(168,85,247,.25);
}

/* ── Avatar colors ────────────────────────────────────────────── */
.ap-av.av-color-blue   { background: #3b82f6; }
.ap-av.av-color-green  { background: #22c55e; }
.ap-av.av-color-purple { background: #a855f7; }
.ap-av.av-color-orange { background: #f97316; }
.ap-av.av-color-pink   { background: #ec4899; }
.ap-av.av-color-teal   { background: #14b8a6; }

/* ── Refresh button ───────────────────────────────────────────── */
.ap-refresh-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  border: none;
  background: rgba(0,122,255,.08);
  color: var(--accent, #007aff);
  border-radius: 50%;
  width: 32px; height: 32px;
  cursor: pointer;
  flex-shrink: 0;
  transition: background .15s, transform .15s, opacity .15s;
  -webkit-tap-highlight-color: transparent;
}
.ap-refresh-btn:hover   { background: rgba(0,122,255,.15); }
.ap-refresh-btn:active  { transform: scale(.88); }
.ap-refresh-btn:disabled { opacity: .5; cursor: default; }

.ap-refresh-btn--spinning svg {
  animation: ap-spin .7s linear infinite;
}

/* ═══════════════════════════════════════════════════════════════
   SETTINGS VIEW
   ═══════════════════════════════════════════════════════════════ */

.ap-settings {
  display: flex;
  flex-direction: column;
  gap: 18px;
  max-width: 680px;
  margin-inline: auto;
  width: 100%;
}

/* ── Section card ─────────────────────────────────────────────── */
.ap-settings-section {
  background: #fff;
  border-radius: 16px;
  padding: 20px;
  box-shadow: 0 1px 8px rgba(0,0,0,.07);
  display: flex;
  flex-direction: column;
  gap: 16px;
}
.theme-dark .ap-settings-section {
  background: #1a1a2e;
  box-shadow: 0 1px 8px rgba(0,0,0,.28);
}

.ap-settings-section--info {
  background: rgba(0,0,0,.02);
  box-shadow: none;
  border: 1px solid rgba(0,0,0,.07);
}
.theme-dark .ap-settings-section--info {
  background: rgba(255,255,255,.03);
  border-color: rgba(255,255,255,.07);
}

/* ── Section header ───────────────────────────────────────────── */
.ap-settings-section-header {
  display: flex;
  align-items: flex-start;
  gap: 12px;
}

.ap-settings-section-icon {
  width: 36px; height: 36px;
  border-radius: 10px;
  background: rgba(0,122,255,.10);
  color: var(--accent, #007AFF);
  display: grid;
  place-items: center;
  flex-shrink: 0;
}
.theme-dark .ap-settings-section-icon {
  background: rgba(0,122,255,.15);
}

.ap-settings-section-title {
  font-size: .95rem;
  font-weight: 700;
  color: var(--text-primary);
  line-height: 1.3;
}
.ap-settings-section-sub {
  font-size: .76rem;
  color: var(--text-tertiary);
  margin-top: 3px;
  line-height: 1.5;
}

/* ── Strictness option cards ──────────────────────────────────── */
.ap-strictness-options {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.ap-strictness-option {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  padding: 14px 16px;
  border-radius: 12px;
  border: 1.5px solid rgba(0,0,0,.08);
  cursor: pointer;
  transition: border-color .15s, background .15s, box-shadow .15s;
  background: rgba(0,0,0,.015);
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}
.theme-dark .ap-strictness-option {
  border-color: rgba(255,255,255,.07);
  background: rgba(255,255,255,.025);
}

.ap-strictness-option:hover {
  border-color: rgba(0,122,255,.35);
  background: rgba(0,122,255,.04);
}

.ap-strictness-option--active {
  border-color: var(--accent, #007AFF);
  background: rgba(0,122,255,.06);
  box-shadow: 0 0 0 3px rgba(0,122,255,.10);
}
.theme-dark .ap-strictness-option--active {
  background: rgba(0,122,255,.10);
}

/* Custom radio dot */
.ap-strictness-radio {
  display: grid;
  place-items: center;
  width: 18px; height: 18px;
  border-radius: 50%;
  border: 2px solid rgba(0,0,0,.18);
  flex-shrink: 0;
  margin-top: 2px;
  transition: border-color .15s;
  position: relative;
}
.theme-dark .ap-strictness-radio { border-color: rgba(255,255,255,.25); }

.ap-strictness-option--active .ap-strictness-radio {
  border-color: var(--accent, #007AFF);
}

.ap-strictness-radio-dot {
  width: 8px; height: 8px;
  border-radius: 50%;
  background: var(--accent, #007AFF);
  opacity: 0;
  transform: scale(0.4);
  transition: opacity .15s, transform .15s;
}
.ap-strictness-option--active .ap-strictness-radio-dot {
  opacity: 1;
  transform: scale(1);
}

.ap-visually-hidden {
  position: absolute; width: 1px; height: 1px;
  padding: 0; margin: -1px; overflow: hidden;
  clip: rect(0,0,0,0); border: 0;
}

.ap-strictness-body { flex: 1; min-width: 0; }

.ap-strictness-label {
  font-size: .88rem;
  font-weight: 700;
  color: var(--text-primary);
  display: flex;
  align-items: center;
  gap: 6px;
}
.ap-strictness-icon { font-size: 1rem; line-height: 1; }

.ap-strictness-desc {
  font-size: .76rem;
  color: var(--text-tertiary);
  margin-top: 4px;
  line-height: 1.55;
}

/* ── Save row ─────────────────────────────────────────────────── */
.ap-settings-save-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding-top: 4px;
}

.ap-settings-status {
  font-size: .8rem;
  font-weight: 600;
  transition: opacity .2s;
}
.ap-settings-status--ok    { color: #16a34a; }
.ap-settings-status--error { color: #ef4444; }

/* ── Info grid (config display) ───────────────────────────────── */
.ap-settings-info-grid {
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.ap-settings-info-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 8px 0;
  border-bottom: 1px solid rgba(0,0,0,.05);
  font-size: .83rem;
}
.ap-settings-info-row:last-child { border-bottom: none; }
.theme-dark .ap-settings-info-row { border-bottom-color: rgba(255,255,255,.05); }

.ap-settings-info-label {
  color: var(--text-tertiary);
  font-size: .78rem;
}
.ap-settings-info-val {
  color: var(--text-primary);
  font-weight: 600;
  font-family: 'DM Mono', monospace;
  font-size: .8rem;
}

/* ═══════════════════════════════════════════════════════════════
   RESPONSIVE
   ═══════════════════════════════════════════════════════════════ */

@media (max-width: 480px) {
  .ap-stats-grid {
    grid-template-columns: repeat(3, 1fr);
    gap: 7px;
  }
  .ap-stat-val   { font-size: 1.25rem; }
  .ap-stat-label { font-size: .6rem; }

  /* Hide Full Name and Role columns on very small screens */
  .ap-table--students .ap-th:nth-child(3),
  .ap-table--students .ap-td:nth-child(3),
  .ap-table--students .ap-th:nth-child(4),
  .ap-table--students .ap-td:nth-child(4) {
    display: none;
  }

  .ap-toolbar { flex-wrap: wrap; }
  .ap-search-wrap { min-width: 100%; }

  .ap-assign-wrap { flex-wrap: wrap; }
  .ap-select--assign { min-width: 100%; max-width: 100%; }

  .ap-settings { max-width: 100%; }
  .ap-settings-section { padding: 14px; }
}

@media (min-width: 900px) {
  .ap-topbar  { padding: 18px 28px 0; }
  .ap-content { padding: 20px 28px 28px; }
  .ap-toolbar { flex-wrap: nowrap; }
  .ap-table--students { font-size: .9rem; }
}

@media (min-width: 1200px) {
  .ap-topbar  { padding: 20px 40px 0; }
  .ap-content { padding: 24px 40px 40px; }
}

/* ═══════════════════════════════════════════════════════════════
   INBOX  (UserWorker — inbox button, conversation list, thread)
   ═══════════════════════════════════════════════════════════════ */

/* ── Inbox trigger button (in user card hero row) ─────────────── */
.up-inbox-btn {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 38px;
  height: 38px;
  border-radius: 50%;
  border: none;
  background: color-mix(in srgb, var(--accent, #007AFF) 10%, transparent);
  color: var(--accent, #007AFF);
  cursor: pointer;
  flex-shrink: 0;
  margin-left: auto;
  transition: background .15s, transform .12s;
  -webkit-tap-highlight-color: transparent;
}
.up-inbox-btn:hover  { background: color-mix(in srgb, var(--accent, #007AFF) 18%, transparent); }
.up-inbox-btn:active { transform: scale(.88); }

/* ── Unread count badge ───────────────────────────────────────── */
.up-inbox-badge {
  position: absolute;
  top: -3px;
  right: -3px;
  min-width: 17px;
  height: 17px;
  padding: 0 4px;
  background: var(--danger, #ef4444);
  color: #fff;
  font-size: .6rem;
  font-weight: 800;
  border-radius: 999px;
  display: flex;
  align-items: center;
  justify-content: center;
  line-height: 1;
  border: 2px solid var(--bg, #f8fafc);
  pointer-events: none;
}
.theme-dark .up-inbox-badge { border-color: #0a0a0f; }

/* ── Conversation list rows ───────────────────────────────────── */
/* Most styling is inline; .inbox-row is the hover/tap target. */
.inbox-row {
  -webkit-tap-highlight-color: transparent;
  user-select: none;
}
.inbox-row:hover  { background: color-mix(in srgb, var(--accent, #007AFF)  5%, transparent) !important; }
.inbox-row:active { background: color-mix(in srgb, var(--accent, #007AFF) 10%, transparent) !important; }

/* ── Thread bubble list container ─────────────────────────────── */
/* JS appends bubbles here via .inbox-thread-list selector. */
.inbox-thread-list {
  display: flex;
  flex-direction: column;
  overflow-y: auto;
  padding: 14px 14px 10px;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
}

/* ── Chat bubbles (real-time appended by subscribeMessages) ───── */
.inbox-bubble {
  max-width: 78%;
  padding: 9px 13px;
  font-size: .88rem;
  line-height: 1.5;
  word-break: break-word;
  margin-bottom: 8px;
  box-shadow: var(--shadow-sm, 0 1px 4px rgba(0,0,0,.08));
  animation: inbox-bubble-in .18s ease;
}
@keyframes inbox-bubble-in {
  from { opacity: 0; transform: translateY(6px) scale(.97); }
  to   { opacity: 1; transform: none; }
}

.inbox-bubble.mine {
  align-self: flex-end;
  background: var(--accent, #007AFF);
  color: #fff;
  border-radius: 16px 16px 4px 16px;
  border: none;
}
.inbox-bubble.theirs {
  align-self: flex-start;
  background: var(--bg-elevated, #f2f2f7);
  color: var(--text-primary, #1C1C1E);
  border-radius: 16px 16px 16px 4px;
  border: 1px solid var(--border, rgba(0,0,0,.08));
}
.theme-dark .inbox-bubble.theirs {
  background: #1e293b;
  border-color: rgba(255,255,255,.08);
  color: #f1f5f9;
}

/* ═══════════════════════════════════════════════════════════════
   ADMIN INBOX VIEW  (.ap-inbox-*)
   ═══════════════════════════════════════════════════════════════ */

/* ── Tab badge (unread count on Inbox tab) ────────────────────── */
.ap-tab-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 16px;
  height: 16px;
  padding: 0 4px;
  background: var(--danger, #ef4444);
  color: #fff;
  font-size: .58rem;
  font-weight: 800;
  border-radius: 999px;
  line-height: 1;
  margin-left: 4px;
}

/* ── Inbox shell ──────────────────────────────────────────────── */
.ap-inbox {
  display: flex;
  flex-direction: column;
  max-width: 680px;
  margin-inline: auto;
  width: 100%;
  background: #fff;
  border-radius: 16px;
  box-shadow: 0 1px 8px rgba(0,0,0,.07);
  overflow: hidden;
}
.theme-dark .ap-inbox {
  background: #1a1a2e;
  box-shadow: 0 1px 8px rgba(0,0,0,.28);
}

/* ── Inbox header ─────────────────────────────────────────────── */
.ap-inbox-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px 11px;
  border-bottom: 1px solid var(--separator, rgba(0,0,0,.07));
}
.theme-dark .ap-inbox-header { border-bottom-color: rgba(255,255,255,.06); }

.ap-inbox-count {
  font-size: .72rem;
  font-weight: 700;
  letter-spacing: .06em;
  text-transform: uppercase;
  color: var(--text-tertiary, #8E8E93);
  display: flex;
  align-items: center;
  gap: 6px;
}
.ap-inbox-unread-pill {
  background: var(--danger, #ef4444);
  color: #fff;
  border-radius: 999px;
  padding: 1px 7px;
  font-size: .6rem;
  font-weight: 800;
}
.ap-inbox-refresh { margin: 0; }

/* ── Conversation list ────────────────────────────────────────── */
.ap-inbox-list { display: flex; flex-direction: column; }

.ap-inbox-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 13px 16px;
  cursor: pointer;
  border-bottom: 1px solid var(--separator, rgba(0,0,0,.06));
  transition: background .12s;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}
.ap-inbox-row:last-child { border-bottom: none; }
.ap-inbox-row:hover  { background: color-mix(in srgb, var(--accent, #007AFF)  5%, transparent); }
.ap-inbox-row:active { background: color-mix(in srgb, var(--accent, #007AFF) 10%, transparent); }
.theme-dark .ap-inbox-row { border-bottom-color: rgba(255,255,255,.05); }

.ap-inbox-avatar {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  flex-shrink: 0;
  background: var(--accent, #007AFF);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: .95rem;
  font-weight: 800;
}
.ap-inbox-avatar--unread {
  box-shadow: 0 0 0 2.5px var(--bg, #fff), 0 0 0 4.5px var(--accent, #007AFF);
}
.theme-dark .ap-inbox-avatar--unread { box-shadow: 0 0 0 2.5px #1a1a2e, 0 0 0 4.5px var(--accent, #007AFF); }

.ap-inbox-meta    { flex: 1; min-width: 0; }

.ap-inbox-name-row {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-bottom: 3px;
}
.ap-inbox-name {
  font-size: .9rem;
  font-weight: 600;
  color: var(--text-primary, #1C1C1E);
  flex: 1;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.ap-inbox-name--unread { font-weight: 800; }
.ap-inbox-time {
  font-size: .65rem;
  color: var(--text-tertiary, #8E8E93);
  flex-shrink: 0;
}

.ap-inbox-preview-row {
  display: flex;
  align-items: center;
  gap: 6px;
}
.ap-inbox-preview {
  font-size: .78rem;
  flex: 1;
  color: var(--text-tertiary, #8E8E93);
  font-weight: 400;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.ap-inbox-preview--unread { color: var(--text-primary, #1C1C1E); font-weight: 600; }
.ap-inbox-dot {
  min-width: 18px;
  height: 18px;
  padding: 0 5px;
  background: var(--accent, #007AFF);
  color: #fff;
  border-radius: 999px;
  font-size: .6rem;
  font-weight: 800;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* ── Thread shell ─────────────────────────────────────────────── */
.ap-inbox-thread-shell {
  display: flex;
  flex-direction: column;
  max-width: 680px;
  margin-inline: auto;
  width: 100%;
  background: #fff;
  border-radius: 16px;
  box-shadow: 0 1px 8px rgba(0,0,0,.07);
  overflow: hidden;
  height: calc(100dvh - 160px);
  min-height: 400px;
}
.theme-dark .ap-inbox-thread-shell {
  background: #1a1a2e;
  box-shadow: 0 1px 8px rgba(0,0,0,.28);
}

.ap-inbox-thread-topbar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 16px;
  border-bottom: 1px solid var(--separator, rgba(0,0,0,.07));
  flex-shrink: 0;
}
.theme-dark .ap-inbox-thread-topbar { border-bottom-color: rgba(255,255,255,.06); }

.ap-inbox-back {
  display: flex;
  align-items: center;
  gap: 4px;
  background: none;
  border: none;
  cursor: pointer;
  color: var(--accent, #007AFF);
  font-size: .88rem;
  font-weight: 700;
  font-family: inherit;
  padding: 4px 0;
  flex-shrink: 0;
  -webkit-tap-highlight-color: transparent;
}
.ap-inbox-thread-name {
  flex: 1;
  text-align: center;
  font-size: .9rem;
  font-weight: 800;
  color: var(--text-primary, #1C1C1E);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* ── Bubbles area ─────────────────────────────────────────────── */
.ap-inbox-bubbles {
  flex: 1;
  overflow-y: auto;
  padding: 14px 14px 10px;
  display: flex;
  flex-direction: column;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
}

.ap-inbox-thread-start {
  text-align: center;
  font-size: .64rem;
  font-weight: 700;
  letter-spacing: .06em;
  text-transform: uppercase;
  color: var(--text-tertiary, #8E8E93);
  align-self: center;
  margin-bottom: 10px;
  padding: 3px 10px;
  background: var(--bg, #f8fafc);
  border-radius: 999px;
}
.theme-dark .ap-inbox-thread-start { background: #0f172a; }

.ap-inbox-bubble-wrap {
  display: flex;
  flex-direction: column;
  margin-bottom: 8px;
}
.ap-inbox-bubble-wrap.mine   { align-items: flex-end; }
.ap-inbox-bubble-wrap.theirs { align-items: flex-start; }

.ap-inbox-bubble {
  max-width: 78%;
  padding: 9px 13px;
  font-size: .88rem;
  line-height: 1.5;
  word-break: break-word;
  box-shadow: 0 1px 4px rgba(0,0,0,.08);
  animation: ap-bubble-in .16s ease;
}
@keyframes ap-bubble-in {
  from { opacity: 0; transform: translateY(5px) scale(.97); }
  to   { opacity: 1; transform: none; }
}
.ap-inbox-bubble.mine {
  background: var(--accent, #007AFF);
  color: #fff;
  border-radius: 16px 16px 4px 16px;
}
.ap-inbox-bubble.theirs {
  background: var(--bg-elevated, #f2f2f7);
  color: var(--text-primary, #1C1C1E);
  border-radius: 16px 16px 16px 4px;
  border: 1px solid var(--border, rgba(0,0,0,.08));
}
.theme-dark .ap-inbox-bubble.theirs {
  background: #0f172a;
  border-color: rgba(255,255,255,.08);
  color: #f1f5f9;
}
.ap-inbox-bubble-time {
  font-size: .6rem;
  color: var(--text-tertiary, #8E8E93);
  margin-top: 3px;
  padding: 0 3px;
}

/* ── Compose bar ──────────────────────────────────────────────── */
.ap-inbox-compose {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  padding: 8px 12px 10px;
  border-top: 1px solid var(--separator, rgba(0,0,0,.07));
  flex-shrink: 0;
}
.theme-dark .ap-inbox-compose { border-top-color: rgba(255,255,255,.06); }

.ap-inbox-ta {
  flex: 1;
  resize: none;
  overflow: hidden;
  padding: 9px 12px;
  border: 1.5px solid var(--border, rgba(0,0,0,.1));
  border-radius: 999px;
  background: var(--bg, #f8fafc);
  color: var(--text-primary, #1C1C1E);
  font-size: .88rem;
  font-family: inherit;
  outline: none;
  line-height: 1.4;
  min-height: 38px;
  max-height: 100px;
  transition: border-color .15s;
}
.ap-inbox-ta:focus { border-color: var(--accent, #007AFF); }
.theme-dark .ap-inbox-ta {
  background: #0f172a;
  border-color: rgba(255,255,255,.10);
  color: #f1f5f9;
}

.ap-inbox-send {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  flex-shrink: 0;
  background: var(--accent, #007AFF);
  color: #fff;
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: opacity .15s, transform .1s;
  -webkit-tap-highlight-color: transparent;
}
.ap-inbox-send:hover  { opacity: .88; }
.ap-inbox-send:active { transform: scale(.9); }
