/* ============================================================
   ChordexBio Careers Portal — style.css
   Responsive: mobile-first, min-width: 320px
   ============================================================ */

/* --- Reset & Base ----------------------------------------- */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --color-primary:      #1a5ca8;
  --color-primary-dk:   #144a8a;
  --color-primary-lt:   #e8f0fb;
  --color-accent:       #0d8c6e;
  --color-accent-lt:    #e1f5ee;
  --color-danger:       #c0392b;
  --color-danger-lt:    #fdecea;
  --color-warn:         #b7770a;
  --color-warn-lt:      #fef3d7;
  --color-success:      #1a7a4a;
  --color-success-lt:   #e8f5ef;
  --color-onboard:      #8b459f;
  --color-onboard-lt:   #f5eefa;
  --color-text:         #1a1a1a;
  --color-text-muted:   #5a5a5a;
  --color-border:       #d0d5dd;
  --color-bg:           #f8f9fc;
  --color-surface:      #ffffff;
  --color-surface-2:    #f1f3f7;
  --radius:             8px;
  --radius-lg:          12px;
  --shadow-sm:          0 1px 3px rgba(0,0,0,.08);
  --shadow-md:          0 4px 12px rgba(0,0,0,.10);
  --font:               -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  --transition:         0.15s ease;
}

html { scroll-behavior: smooth; }
body {
  font-family: var(--font);
  font-size: 16px;
  line-height: 1.6;
  color: var(--color-text);
  background: var(--color-bg);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}
a { color: var(--color-primary); text-decoration: none; }
a:hover { text-decoration: underline; }
img { max-width: 100%; height: auto; }
h1 { font-size: clamp(1.4rem, 4vw, 2rem); font-weight: 700; line-height: 1.2; }
h2 { font-size: clamp(1.1rem, 3vw, 1.4rem); font-weight: 600; }
h3 { font-size: 1.05rem; font-weight: 600; }

/* --- Layout ----------------------------------------------- */
.container {
  width: 100%;
  max-width: 1100px;
  margin: 0 auto;
  padding: 0 1rem;
}
@media (min-width: 640px)  { .container { padding: 0 1.5rem; } }
@media (min-width: 1024px) { .container { padding: 0 2rem; } }

.main-content {
  flex: 1;
  padding: 1.5rem 0 3rem;
}

/* --- Site Header ------------------------------------------ */
.site-header {
  background: var(--color-surface);
  border-bottom: 1px solid var(--color-border);
  position: sticky;
  top: 0;
  z-index: 100;
  box-shadow: var(--shadow-sm);
}
.site-header__inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  height: 60px;
}
.site-header__logo {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  font-weight: 700;
  font-size: 1.05rem;
  color: var(--color-text);
  text-decoration: none;
}
.site-header__logo img {
  width: 36px;
  height: 36px;
  border-radius: 6px;
  object-fit: contain;
}
.site-header__logo span span { color: var(--color-primary); }
.site-header__nav {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-wrap: wrap;
}
.site-header__nav a:not(.btn) {
  padding: 0.3rem 0.6rem;
  border-radius: var(--radius);
  color: var(--color-text-muted);
  font-size: 0.9rem;
  transition: color var(--transition), background var(--transition);
}
.site-header__nav a:not(.btn):hover {
  color: var(--color-primary);
  background: var(--color-primary-lt);
  text-decoration: none;
}

/* Mobile nav toggle */
.mobile-menu-btn {
  display: none;
  flex-direction: column;
  gap: 5px;
  background: none;
  border: none;
  cursor: pointer;
  padding: 6px;
}
.mobile-menu-btn span {
  display: block;
  width: 22px;
  height: 2px;
  background: var(--color-text);
  border-radius: 2px;
  transition: var(--transition);
}
@media (max-width: 640px) {
  .mobile-menu-btn { display: flex; }
  .site-header__nav {
    display: none;
    position: absolute;
    top: 60px;
    left: 0;
    right: 0;
    background: var(--color-surface);
    border-bottom: 1px solid var(--color-border);
    padding: 1rem;
    flex-direction: column;
    align-items: flex-start;
    gap: 0.5rem;
    box-shadow: var(--shadow-md);
  }
  .site-header.nav-open .site-header__nav { display: flex; }
  .site-header__nav a { width: 100%; }
}

/* --- Site Footer ------------------------------------------ */
.site-footer {
  background: var(--color-surface);
  border-top: 1px solid var(--color-border);
  padding: 1.5rem 0;
  font-size: 0.85rem;
  color: var(--color-text-muted);
}
.site-footer__inner {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  align-items: center;
  gap: 0.8rem;
}
.site-footer__links { display: flex; flex-wrap: wrap; gap: 1rem; }
.site-footer__links a { color: var(--color-text-muted); font-size: 0.85rem; }
.site-footer__links a:hover { color: var(--color-primary); }

/* --- Buttons ---------------------------------------------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  padding: 0.55rem 1.2rem;
  border-radius: var(--radius);
  font-size: 0.9rem;
  font-weight: 500;
  border: 1px solid transparent;
  cursor: pointer;
  text-decoration: none;
  transition: background var(--transition), border-color var(--transition), opacity var(--transition);
  white-space: nowrap;
}
.btn:hover { text-decoration: none; }
.btn:disabled { opacity: 0.55; cursor: not-allowed; }
.btn--primary  { background: var(--color-primary); color: #fff; border-color: var(--color-primary); }
.btn--primary:hover { background: var(--color-primary-dk); border-color: var(--color-primary-dk); }
.btn--outline  { background: transparent; color: var(--color-primary); border-color: var(--color-primary); }
.btn--outline:hover { background: var(--color-primary-lt); }
.btn--danger   { background: var(--color-danger); color: #fff; border-color: var(--color-danger); }
.btn--success  { background: var(--color-accent); color: #fff; border-color: var(--color-accent); }
.btn--ghost    { background: transparent; color: var(--color-text-muted); border-color: var(--color-border); }
.btn--ghost:hover { background: var(--color-surface-2); }
.btn--onboard  { background: var(--color-onboard); color: #fff; border-color: var(--color-onboard); }
.btn--onboard:hover { background: #7a3d8c; border-color: #7a3d8c; }
.btn--sm  { padding: 0.35rem 0.8rem; font-size: 0.82rem; }
.btn--lg  { padding: 0.75rem 1.8rem; font-size: 1rem; }
.btn--block { width: 100%; }

/* --- Forms ------------------------------------------------ */
.form-group { margin-bottom: 1.2rem; }
.form-label {
  display: block;
  font-size: 0.875rem;
  font-weight: 500;
  margin-bottom: 0.35rem;
  color: var(--color-text);
}
.form-label .req { color: var(--color-danger); margin-left: 2px; }
.form-control {
  display: block;
  width: 100%;
  padding: 0.55rem 0.75rem;
  font-size: 0.95rem;
  font-family: var(--font);
  color: var(--color-text);
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  transition: border-color var(--transition), box-shadow var(--transition);
}
.form-control:focus {
  outline: none;
  border-color: var(--color-primary);
  box-shadow: 0 0 0 3px rgba(26,92,168,.15);
}
textarea.form-control { min-height: 100px; resize: vertical; }
.form-hint  { font-size: 0.8rem; color: var(--color-text-muted); margin-top: 0.3rem; }
.form-error { font-size: 0.8rem; color: var(--color-danger); margin-top: 0.3rem; }
.form-row { display: flex; gap: 1rem; flex-wrap: wrap; }
.form-row .form-group { flex: 1; min-width: 200px; }
.form-check { display: flex; align-items: flex-start; gap: 0.6rem; margin-bottom: 0.8rem; }
.form-check input[type="checkbox"] { margin-top: 3px; flex-shrink: 0; width: 16px; height: 16px; accent-color: var(--color-primary); }
.form-check label { font-size: 0.9rem; cursor: pointer; }
.form-check label a { color: var(--color-primary); }

/* File upload input */
.cv-upload-input {
  padding: 0.4rem 0.75rem;
  font-size: 0.9rem;
  cursor: pointer;
  background: var(--color-surface);
}
.cv-upload-input::file-selector-button {
  padding: 0.3rem 0.8rem;
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  background: var(--color-surface-2);
  color: var(--color-text);
  font-size: 0.85rem;
  cursor: pointer;
  margin-right: 0.75rem;
  transition: background var(--transition);
}
.cv-upload-input::file-selector-button:hover { background: var(--color-primary-lt); }

/* --- Cards ------------------------------------------------ */
.card {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
  overflow: hidden;
}
.card__body   { padding: 1.25rem; }
.card__header { padding: 1rem 1.25rem; border-bottom: 1px solid var(--color-border); background: var(--color-surface-2); }
.card__footer { padding: 1rem 1.25rem; border-top: 1px solid var(--color-border); background: var(--color-surface-2); }

/* --- Badges ----------------------------------------------- */
.badge {
  display: inline-block;
  padding: 0.2rem 0.6rem;
  border-radius: 20px;
  font-size: 0.78rem;
  font-weight: 500;
  white-space: nowrap;
}
.badge--blue    { background: #dbeafe; color: #1e40af; }
.badge--green   { background: #d1fae5; color: #065f46; }
.badge--teal    { background: #ccfbf1; color: #0f766e; }
.badge--yellow  { background: #fef9c3; color: #854d0e; }
.badge--red     { background: #fee2e2; color: #991b1b; }
.badge--gray    { background: #f1f5f9; color: #475569; }
.badge--purple  { background: #f3e8ff; color: #7e22ce; }

/* --- Flash messages --------------------------------------- */
.flash {
  padding: 0.75rem 1rem;
  border-radius: var(--radius);
  margin-bottom: 1rem;
  font-size: 0.9rem;
  border-left: 4px solid;
}
.flash--success { background: var(--color-success-lt); border-color: var(--color-accent);   color: #155534; }
.flash--error   { background: var(--color-danger-lt);  border-color: var(--color-danger);   color: #7f1d1d; }
.flash--warning { background: var(--color-warn-lt);    border-color: var(--color-warn);     color: #78350f; }
.flash--info    { background: var(--color-primary-lt); border-color: var(--color-primary);  color: var(--color-primary-dk); }

/* --- Tables ----------------------------------------------- */
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
table.data-table { width: 100%; border-collapse: collapse; font-size: 0.9rem; }
.data-table th, .data-table td {
  padding: 0.7rem 0.9rem;
  text-align: left;
  border-bottom: 1px solid var(--color-border);
  white-space: nowrap;
}
.data-table th {
  background: var(--color-surface-2);
  font-weight: 600;
  font-size: 0.82rem;
  color: var(--color-text-muted);
  text-transform: uppercase;
  letter-spacing: 0.03em;
}
.data-table td.wrap { white-space: normal; }
.data-table tr:hover td { background: var(--color-primary-lt); }

/* --- Page layouts ----------------------------------------- */
.page-header {
  padding: 1.5rem 0 1rem;
  border-bottom: 1px solid var(--color-border);
  margin-bottom: 1.5rem;
}
.page-header__inner {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
}
.page-header h1 { margin: 0; }

/* --- Onboarding Banner ------------------------------------ */
.onboarding-banner {
  background: var(--color-onboard);
  border-radius: var(--radius-lg);
  padding: 1.5rem;
  margin-bottom: 1.5rem;
  color: #fff;
  box-shadow: 0 4px 20px rgba(139,69,159,.35);
}
.onboarding-banner h2 { color: #fff; }
.onboarding-banner a  { color: #f0d6ff; }
.onboarding-banner a:hover { color: #fff; }
.onboarding-banner .form-label { color: #f0d6ff; }
.onboarding-banner .form-control {
  background: rgba(255,255,255,0.95);
  border-color: rgba(255,255,255,0.4);
}
.onboarding-banner .form-control:focus {
  border-color: #fff;
  box-shadow: 0 0 0 3px rgba(255,255,255,0.3);
}
.onboarding-banner .form-hint { color: rgba(255,255,255,0.7); }

/* Onboarding step panel */
.onboarding-step {
  background: rgba(255,255,255,0.12);
  border-radius: var(--radius);
  padding: 1.2rem;
  margin-bottom: 1rem;
}
.onboarding-step h3 { color: #fff; margin: 0 0 0.75rem; font-size: 1rem; }

/* --- Job Listings ----------------------------------------- */
.search-bar {
  display: flex;
  gap: 0.75rem;
  flex-wrap: wrap;
  margin-bottom: 1.5rem;
  align-items: flex-end;
}
.search-bar .form-group { margin: 0; flex: 1; min-width: 160px; }
.search-bar .btn { align-self: flex-end; }

.jobs-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 1rem;
}
@media (min-width: 640px)  { .jobs-grid { grid-template-columns: 1fr 1fr; } }
@media (min-width: 1024px) { .jobs-grid { grid-template-columns: 1fr 1fr 1fr; } }

.job-card {
  display: flex;
  flex-direction: column;
  height: 100%;
  transition: box-shadow var(--transition), transform var(--transition);
}
.job-card:hover {
  box-shadow: var(--shadow-md);
  transform: translateY(-2px);
}
.job-card__body { flex: 1; padding: 1.1rem; }
.job-card__title { font-size: 1rem; font-weight: 600; margin-bottom: 0.25rem; }
.job-card__org { font-size: 0.85rem; color: var(--color-text-muted); margin-bottom: 0.6rem; }
.job-card__meta { display: flex; flex-wrap: wrap; gap: 0.4rem; margin-bottom: 0.6rem; }
.job-card__desc {
  font-size: 0.88rem;
  color: var(--color-text-muted);
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.job-card__footer {
  padding: 0.75rem 1.1rem;
  border-top: 1px solid var(--color-border);
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.job-card__deadline { font-size: 0.8rem; color: var(--color-text-muted); }

/* --- Job detail ------------------------------------------- */
.job-detail-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 1.5rem;
}
@media (min-width: 768px) {
  .job-detail-grid { grid-template-columns: 1fr 280px; }
  .job-detail-sidebar { grid-row: 1; grid-column: 2; }
}
.job-section { margin-bottom: 1.5rem; }
.job-section h2 { margin-bottom: 0.6rem; padding-bottom: 0.4rem; border-bottom: 1px solid var(--color-border); }
.job-section ul { padding-left: 1.4rem; }
.job-section li { margin-bottom: 0.3rem; font-size: 0.95rem; }

/* --- Application / CV Builder ----------------------------- */
.cv-section-card {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  margin-bottom: 1rem;
}
.cv-section-card__header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.85rem 1rem;
  background: var(--color-surface-2);
  border-bottom: 1px solid var(--color-border);
  border-radius: var(--radius-lg) var(--radius-lg) 0 0;
  cursor: pointer;
}
.cv-section-card__header h3 { margin: 0; font-size: 0.95rem; }
.cv-section-card__toggle { font-size: 1.2rem; color: var(--color-text-muted); line-height: 1; transition: transform var(--transition); }
.cv-section-card.collapsed .cv-section-card__toggle { transform: rotate(-90deg); }
.cv-section-card.collapsed .cv-section-card__body { display: none; }
.cv-section-card__body { padding: 1rem; }

.add-section-btn {
  width: 100%;
  padding: 0.65rem;
  border: 2px dashed var(--color-border);
  background: transparent;
  color: var(--color-text-muted);
  border-radius: var(--radius);
  cursor: pointer;
  font-size: 0.9rem;
  transition: border-color var(--transition), color var(--transition);
}
.add-section-btn:hover { border-color: var(--color-primary); color: var(--color-primary); }

/* --- Dashboard -------------------------------------------- */
.dashboard-grid { display: grid; grid-template-columns: 1fr; gap: 1rem; }
@media (min-width: 640px) { .dashboard-grid { grid-template-columns: 1fr 1fr; } }

.stat-card {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  padding: 1.2rem;
  text-align: center;
}
.stat-card__number { font-size: 2rem; font-weight: 700; color: var(--color-primary); line-height: 1; }
.stat-card__label  { font-size: 0.85rem; color: var(--color-text-muted); margin-top: 0.3rem; }

/* --- Auth pages ------------------------------------------- */
.auth-wrapper { display: flex; justify-content: center; align-items: flex-start; padding: 2rem 1rem; }
.auth-box { width: 100%; max-width: 440px; }
.auth-box__logo { text-align: center; margin-bottom: 1.5rem; }
.auth-box__logo img { width: 56px; height: 56px; border-radius: 10px; }
.auth-box__logo h1 { font-size: 1.3rem; margin-top: 0.5rem; }

/* --- Admin panel ------------------------------------------ */
.admin-layout { display: grid; grid-template-columns: 1fr; gap: 1.5rem; }
@media (min-width: 900px) { .admin-layout { grid-template-columns: 220px 1fr; } }

.admin-sidebar {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  padding: 1rem;
  height: fit-content;
}
.admin-sidebar nav a {
  display: block;
  padding: 0.5rem 0.75rem;
  border-radius: var(--radius);
  font-size: 0.9rem;
  color: var(--color-text-muted);
  transition: background var(--transition), color var(--transition);
  margin-bottom: 0.25rem;
}
.admin-sidebar nav a:hover,
.admin-sidebar nav a.active {
  background: var(--color-primary-lt);
  color: var(--color-primary);
  text-decoration: none;
}
.admin-sidebar__section {
  font-size: 0.72rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--color-text-muted);
  padding: 0.5rem 0.75rem 0.25rem;
  margin-top: 0.5rem;
}

/* --- Pagination ------------------------------------------- */
.pagination { display: flex; flex-wrap: wrap; gap: 0.3rem; justify-content: center; padding: 1.5rem 0 0.5rem; }
.pagination a, .pagination span {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  border-radius: var(--radius);
  border: 1px solid var(--color-border);
  font-size: 0.85rem;
  background: var(--color-surface);
  color: var(--color-text-muted);
  text-decoration: none;
  transition: var(--transition);
}
.pagination a:hover { background: var(--color-primary-lt); border-color: var(--color-primary); color: var(--color-primary); }
.pagination span.active { background: var(--color-primary); border-color: var(--color-primary); color: #fff; }

/* --- Misc ------------------------------------------------- */
.divider { border: none; border-top: 1px solid var(--color-border); margin: 1.5rem 0; }
.text-muted   { color: var(--color-text-muted); }
.text-center  { text-align: center; }
.mt-1 { margin-top: 0.5rem; }
.mt-2 { margin-top: 1rem; }
.mt-3 { margin-top: 1.5rem; }
.mb-1 { margin-bottom: 0.5rem; }
.mb-2 { margin-bottom: 1rem; }
.mb-3 { margin-bottom: 1.5rem; }
.gap-sm { gap: 0.5rem; }
.d-flex { display: flex; }
.align-center { align-items: center; }
.justify-between { justify-content: space-between; }
.flex-wrap { flex-wrap: wrap; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0,0,0,0); }

/* Consent highlight box */
.consent-box {
  background: var(--color-primary-lt);
  border: 1px solid #b8d1f0;
  border-radius: var(--radius);
  padding: 1rem 1.1rem;
  margin-bottom: 0.75rem;
}
.consent-box.consent-box--research {
  background: var(--color-accent-lt);
  border-color: #a7d9c9;
}
.consent-box.consent-box--onboard {
  background: var(--color-onboard-lt);
  border-color: #d9b3ea;
}

/* CV preview styles */
.cv-preview-wrapper {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  padding: 2rem;
  font-size: 0.9rem;
}
.cv-preview-name { font-size: 1.4rem; font-weight: 700; }
.cv-preview-headline { color: var(--color-text-muted); margin-bottom: 1rem; }
.cv-preview-section { margin-top: 1.2rem; }
.cv-preview-section h3 {
  font-size: 0.82rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--color-primary);
  border-bottom: 2px solid var(--color-primary);
  padding-bottom: 0.25rem;
  margin-bottom: 0.7rem;
}
.cv-preview-entry { margin-bottom: 0.8rem; }
.cv-preview-entry-title { font-weight: 600; }
.cv-preview-entry-sub { font-size: 0.85rem; color: var(--color-text-muted); }
.cv-preview-entry-desc { margin-top: 0.25rem; font-size: 0.88rem; }

@media print {
  .site-header, .site-footer, .btn, .form-group { display: none !important; }
  .cv-preview-wrapper { border: none; padding: 0; box-shadow: none; }
}

/* ============================================================
   Mobile / UX refinements (v2) — additive, do not remove rules above
   ============================================================ */

/* 1. Prevent any rogue inline element from pushing the page wider
      than the viewport on small screens (the #1 cause of "expands to the right"). */
html, body { overflow-x: hidden; }
img, table, pre, code { max-width: 100%; }
.container, .card, .table-wrap { max-width: 100%; }

/* 2. Raise the mobile-nav breakpoint so admin/superuser nav (which has many
      links) collapses into the hamburger before it starts wrapping awkwardly. */
@media (max-width: 860px) {
  .mobile-menu-btn { display: flex; }
  .site-header__nav {
    display: none;
    position: absolute;
    top: 60px;
    left: 0;
    right: 0;
    background: var(--color-surface);
    border-bottom: 1px solid var(--color-border);
    padding: 0.75rem 1rem 1rem;
    flex-direction: column;
    align-items: stretch;
    gap: 0.25rem;
    box-shadow: var(--shadow-md);
    max-height: calc(100vh - 60px);
    overflow-y: auto;
  }
  .site-header.nav-open .site-header__nav { display: flex; }
  .site-header__nav a { width: 100%; padding: 0.65rem 0.75rem; }
  .site-header__nav a.btn { justify-content: center; margin-top: 0.25rem; }
}

/* 3. Tap targets — meet 40px minimum on touch devices without bloating desktop. */
@media (max-width: 640px) {
  .btn { min-height: 40px; padding: 0.6rem 1rem; }
  .btn--sm { min-height: 36px; padding: 0.45rem 0.85rem; font-size: 0.85rem; }
  .form-control { min-height: 42px; font-size: 1rem; } /* 16px prevents iOS zoom-on-focus */
  .pagination a, .pagination span { width: 40px; height: 40px; }
}

/* 4. Page header — stack title + actions cleanly on mobile, give actions room. */
@media (max-width: 640px) {
  .page-header { padding: 1rem 0 0.75rem; margin-bottom: 1rem; }
  .page-header__inner { flex-direction: column; align-items: flex-start; gap: 0.6rem; }
  .page-header h1 { font-size: 1.35rem; }
  .page-header__inner > .btn,
  .page-header__inner > a.btn,
  .page-header__inner > form { width: 100%; }
  .page-header__inner > .btn,
  .page-header__inner > a.btn { justify-content: center; }
}

/* 5. Admin sidebar — turn vertical nav into a horizontal scrollable pill bar
      on mobile so it doesn't eat half the viewport before content starts. */
@media (max-width: 899px) {
  .admin-sidebar {
    padding: 0.6rem 0.75rem;
    border-radius: var(--radius);
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }
  .admin-sidebar nav {
    display: flex;
    flex-wrap: nowrap;
    gap: 0.35rem;
    width: max-content;
    min-width: 100%;
  }
  .admin-sidebar nav a {
    margin: 0;
    padding: 0.45rem 0.85rem;
    white-space: nowrap;
    border: 1px solid var(--color-border);
    background: var(--color-surface);
    font-size: 0.85rem;
  }
  .admin-sidebar nav a.active {
    background: var(--color-primary);
    color: #fff;
    border-color: var(--color-primary);
  }
  .admin-sidebar__section {
    padding: 0.4rem 0.5rem 0.25rem;
    margin-top: 0.25rem;
    font-size: 0.65rem;
  }
  /* Stack sections (Navigation / Filter) vertically but each row scrolls horizontally */
  .admin-sidebar { display: flex; flex-direction: column; gap: 0.25rem; }
}

/* 6. Data tables — keep the horizontal-scroll behavior, but signal it visually
      with a soft right-edge fade so users know to swipe, and tighten the
      cell padding/font on mobile so more content fits. */
.table-wrap {
  position: relative;
  border-radius: var(--radius);
}
@media (max-width: 640px) {
  .data-table { font-size: 0.82rem; }
  .data-table th, .data-table td { padding: 0.55rem 0.65rem; }
  .data-table th { font-size: 0.72rem; }
  /* Scroll-hint shadow on the right edge */
  
  .table-wrap {
    display: block; /* Ensure it's a block container */
    width: 100%;
    overflow-x: auto !important;
    -webkit-overflow-scrolling: touch;
    position: relative;
  }

  /* 2. Force the table to be wider than the screen */
  .data-table {
    display: table !important; /* Force standard table behavior */
    width: auto !important;     /* Allow it to expand beyond 100% */
    min-width: 800px !important; /* Adjust this number based on your column count */
    table-layout: fixed;        /* Optional: Forces strictly defined column widths */
  }

  /* 3. Prevent text from wrapping into a vertical "squeeze" */
  .data-table td, .data-table th {
    white-space: nowrap; /* Prevents text from breaking into multiple lines */
    text-overflow: ellipsis;
    overflow: hidden;
  }

  /* 4. Allow specific columns to wrap if they are too long even in scroll view */
  .data-table td.wrap {
    white-space: normal; 
    min-width: 250px; /* Give the job title enough room */
  }
}

/* 7. Action button clusters in table rows — guarantee they wrap and stretch
      cleanly on narrow viewports; primary action stays visually dominant. */
.action-row, td .action-row,
td > div[style*="display:flex"] {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
}
@media (max-width: 480px) {
  td .action-row .btn,
  td > div[style*="display:flex"] > form,
  td > div[style*="display:flex"] > .btn { width: 100%; }
  td > div[style*="display:flex"] > form .btn { width: 100%; }
}

/* 8. Search/filter bars — make the search input dominant, button full-width
      under it on mobile rather than competing for a tiny sliver. */
@media (max-width: 480px) {
  .search-bar { gap: 0.5rem; }
  .search-bar .btn { width: 100%; align-self: stretch; }
  form[action$="applicants.php"] .btn,
  form[action$="applications.php"] .btn,
  form[action$="jobs.php"] .btn { min-width: 100%; }
}

/* 9. Forms — stack rows on mobile (was wrapping at 200px which made labels
      land at awkward widths between 320–480px). */
@media (max-width: 480px) {
  .form-row { gap: 0; }
  .form-row .form-group { flex: 1 1 100%; min-width: 0; margin-bottom: 1rem; }
}

/* 10. Cards — slightly tighter on mobile so content has room to breathe. */
@media (max-width: 480px) {
  .card__body   { padding: 1rem; }
  .card__header { padding: 0.85rem 1rem; }
  .card__footer { padding: 0.85rem 1rem; }
}

/* 11. Stat cards — 2-up on phones, single column was wasting vertical space. */
@media (max-width: 640px) {
  .dashboard-grid { grid-template-columns: 1fr 1fr; gap: 0.75rem; }
  .stat-card { padding: 0.9rem 0.75rem; }
  .stat-card__number { font-size: 1.5rem; }
  .stat-card__label  { font-size: 0.78rem; }
}

/* 12. Badges — make state badges visually consistent and ensure they don't
       stretch row height when they wrap inside dense tables. */
.badge { line-height: 1.4; vertical-align: middle; }
@media (max-width: 640px) {
  .badge { font-size: 0.72rem; padding: 0.18rem 0.5rem; }
}

/* 13. Auth pages — better vertical rhythm on small screens, full-width submit. */
@media (max-width: 480px) {
  .auth-wrapper { padding: 1rem 0.75rem 2rem; }
  .auth-box__logo h1 { font-size: 1.15rem; }
  .auth-box .btn[type="submit"],
  .auth-box .btn--primary { width: 100%; justify-content: center; }
}

/* 14. Job cards — slightly tighter on phones so two key bits (title + meta)
       are above the fold. */
@media (max-width: 480px) {
  .job-card__body { padding: 0.9rem; }
  .job-card__footer { padding: 0.65rem 0.9rem; flex-wrap: wrap; gap: 0.5rem; }
  .job-card__footer .btn { width: 100%; }
}

/* 15. Onboarding banner — keep prominence but reclaim padding on mobile. */
@media (max-width: 480px) {
  .onboarding-banner { padding: 1.1rem; border-radius: var(--radius); }
  .onboarding-step   { padding: 0.9rem; }
}

/* 16. Magic-link / inline-flex result rows — stop the input + copy button
       from wrapping into a tiny sliver. */
@media (max-width: 480px) {
  div[id="magic-link-result"] input.form-control { width: 100%; min-width: 0; }
  div[id="magic-link-result"] .btn { width: 100%; }
}

/* 17. Visually emphasize the primary action when surrounded by ghost/outline
       siblings (action clusters). Adds a subtle lift without changing color. */
.btn--primary { box-shadow: 0 1px 0 rgba(20,74,138,0.25); }
.btn--primary:hover { box-shadow: 0 2px 0 rgba(20,74,138,0.35); }

/* 18. Sticky bottom action bar utility (opt-in: add class .sticky-actions to
       a button row at the bottom of long forms). */
.sticky-actions {
  position: sticky;
  bottom: 0;
  background: var(--color-surface);
  padding: 0.75rem 1rem;
  margin: 1rem -1rem 0;
  border-top: 1px solid var(--color-border);
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
  z-index: 10;
}
@media (max-width: 480px) {
  .sticky-actions .btn { flex: 1 1 100%; }
}

/* 19. Page-level safety: any container with inline flex that includes a long
       readonly URL/email won't blow out the layout. */
input[readonly].form-control { word-break: break-all; }

/* 20. Accessibility — focus-visible ring on interactive elements. */
.btn:focus-visible,
.form-control:focus-visible,
.site-header__nav a:focus-visible,
.admin-sidebar nav a:focus-visible {
  outline: 2px solid var(--color-primary);
  outline-offset: 2px;
}

/* ============================================================
   Onboarding portal — additive overrides (purple primary accents)
   ============================================================ */
.site-header--onboard .site-header__logo span span { color: var(--color-onboard); }
.site-header--onboard { box-shadow: 0 1px 0 var(--color-border), 0 4px 12px rgba(139,69,159,.05); }
.site-header__user { font-size: 0.85rem; color: var(--color-text-muted); margin-right: 0.25rem; }

/* Onboarding workflow checklist */
.progress-wrap { background: var(--color-surface); border: 1px solid var(--color-border); border-radius: var(--radius-lg); padding: 1.25rem; margin-bottom: 1.5rem; }
.progress-bar  { height: 10px; background: var(--color-surface-2); border-radius: 999px; overflow: hidden; margin: 0.5rem 0; }
.progress-bar__fill { height: 100%; background: linear-gradient(90deg, var(--color-onboard), var(--color-primary)); transition: width .3s ease; }
.progress-meta { display:flex; justify-content:space-between; font-size:0.85rem; color: var(--color-text-muted); }

.module-list { display: grid; gap: 0.85rem; }
.module-row {
  display: grid; grid-template-columns: 38px 1fr auto; gap: 0.9rem; align-items: center;
  background: var(--color-surface); border: 1px solid var(--color-border);
  border-left: 4px solid var(--color-onboard);
  border-radius: var(--radius-lg); padding: 0.9rem 1rem; transition: var(--transition);
}
.module-row:hover { box-shadow: var(--shadow-md); transform: translateY(-1px); }
.module-row--done { border-left-color: var(--color-success); background: var(--color-success-lt); }
.module-row--inprog { border-left-color: var(--color-warn); }
.module-num {
  width: 32px; height: 32px; border-radius: 50%;
  background: var(--color-onboard-lt); color: var(--color-onboard);
  display: flex; align-items: center; justify-content: center; font-weight: 700; font-size: 0.85rem;
}
.module-row--done .module-num { background: var(--color-success-lt); color: var(--color-success); }
.module-title { font-weight: 600; font-size: 0.96rem; }
.module-summary { font-size: 0.85rem; color: var(--color-text-muted); margin-top: 2px; }
.module-meta { display: flex; gap: 0.4rem; margin-top: 0.4rem; align-items: center; flex-wrap: wrap; }

/* Category accent strip */
.module-row[data-cat="core"]        { border-left-color: var(--color-onboard); }
.module-row[data-cat="operational"] { border-left-color: var(--color-primary); }
.module-row[data-cat="training"]    { border-left-color: #0d8c6e; }
.module-row[data-cat="performance"] { border-left-color: var(--color-warn); }
.module-row[data-cat="policy"]      { border-left-color: var(--color-danger); }

/* Module view (single module page) */
.module-view { display: grid; grid-template-columns: 1fr; gap: 1rem; }
@media (min-width: 900px){ .module-view { grid-template-columns: 1fr 280px; } }
.module-block { background: var(--color-surface); border: 1px solid var(--color-border); border-radius: var(--radius-lg); padding: 1.25rem; }
.module-block + .module-block { margin-top: 0.85rem; }
.module-block h2 { margin-bottom: 0.5rem; }
.module-block h3 { margin-bottom: 0.4rem; }
.module-block .prose { font-size: 0.95rem; line-height: 1.65; }
.module-block .prose p { margin-bottom: 0.8rem; }
.module-block .prose ul, .module-block .prose ol { padding-left: 1.4rem; margin-bottom: 0.8rem; }

/* Signature pad */
.sig-pad-wrap { border: 1px dashed var(--color-border); border-radius: var(--radius); padding: 0.5rem; background: #fff; }
.sig-pad { width: 100%; height: 160px; touch-action: none; display: block; background: #fff; }

/* Admin builder (drag/drop block list) */
.builder-canvas { background: var(--color-surface-2); border-radius: var(--radius-lg); padding: 1rem; min-height: 200px; }
.builder-block {
  background: var(--color-surface); border: 1px solid var(--color-border);
  border-radius: var(--radius); padding: 0.85rem 1rem; margin-bottom: 0.6rem;
  display: grid; grid-template-columns: 24px 1fr auto; gap: 0.75rem; align-items: start;
}
.builder-block.dragging { opacity: 0.45; }
.builder-block.drag-over { border-color: var(--color-onboard); box-shadow: 0 0 0 3px rgba(139,69,159,.15); }
.builder-block .handle { cursor: grab; color: var(--color-text-muted); font-size: 1.1rem; line-height: 1.2; user-select: none; }
.builder-block .handle:active { cursor: grabbing; }
.builder-block__type { font-size: 0.7rem; text-transform: uppercase; letter-spacing: .05em; color: var(--color-onboard); font-weight: 700; }
.builder-block__actions { display: flex; gap: 0.3rem; }
.builder-add-row { display: flex; flex-wrap: wrap; gap: 0.35rem; margin-top: 0.75rem; }
.builder-add-row button { font-size: 0.8rem; }

/* Two-pane workflow builder (library | role pipeline) */
.workflow-builder { display: grid; grid-template-columns: 1fr; gap: 1rem; }
@media (min-width: 900px){ .workflow-builder { grid-template-columns: 1fr 1fr; } }
.wf-col { background: var(--color-surface); border: 1px solid var(--color-border); border-radius: var(--radius-lg); padding: 0.85rem; min-height: 320px; }
.wf-col h3 { margin-bottom: 0.6rem; font-size: 0.95rem; }
.wf-item { background: var(--color-surface-2); border: 1px solid var(--color-border); border-radius: var(--radius); padding: 0.55rem 0.7rem; margin-bottom: 0.4rem; display:flex; align-items:center; gap:0.5rem; cursor: grab; }
.wf-item.dragging { opacity: 0.5; }
.wf-item .handle { color: var(--color-text-muted); }
.wf-item .req-toggle { margin-left: auto; font-size: 0.75rem; }

/* Knowledge hub category tabs */
.cat-tabs { display: flex; flex-wrap: wrap; gap: 0.4rem; margin-bottom: 1rem; }
.cat-tab { padding: 0.4rem 0.85rem; border-radius: 999px; background: var(--color-surface-2); border: 1px solid var(--color-border); font-size: 0.85rem; color: var(--color-text-muted); cursor: pointer; }
.cat-tab.active { background: var(--color-onboard); color: #fff; border-color: var(--color-onboard); }
