/* ============================================================
   Trustfund Pensions — CBT Portal
   Responsive overrides for all devices
   Loaded AFTER all other stylesheets
   ============================================================ */

/* ---------- Global ---------- */
* { min-width: 0; }                          /* allows flex children to shrink */
img, svg, video, table { max-width: 100%; height: auto; }

/* Prevent horizontal scrollbars caused by overflowing tables */
html, body { max-width: 100%; overflow-x: hidden; }

/* On tablets and below, reduce base font sizes slightly */
@media (max-width: 900px) {
  html { font-size: 15px; }
}
@media (max-width: 640px) {
  html { font-size: 14px; }
}

/* ============================================================
   ADMIN SHELL
   ============================================================ */

/* The fixed sidebar takes 260px on desktop. On tablets and phones,
   collapse it off-canvas and expose the hamburger toggle. */
@media (max-width: 992px) {
  .admin-sidebar {
    transform: translateX(-100%);
    width: 260px;                             /* keep same width when open */
  }
  .admin-sidebar.open { transform: translateX(0); }
  .admin-main { margin-left: 0 !important; }
}

/* Tablet range: main padding tightens */
@media (max-width: 900px) {
  .admin-content { padding: 18px 20px 40px; }
  .admin-topbar { padding: 10px 20px; }
}

/* Phone range: further tighten and hide non-essential chrome */
@media (max-width: 640px) {
  .admin-content { padding: 14px; }
  .admin-topbar { padding: 10px 14px; gap: 10px; }

  /* Hide the role text inside the user chip on very small screens */
  .topbar-user .role { display: none; }
  .topbar-user .name { font-size: 12px; }
  .topbar-user .avatar { width: 28px; height: 28px; font-size: 11px; }

  /* Sign-out becomes icon-only */
  .topbar-logout { padding: 6px 10px; font-size: 0; }
  .topbar-logout i { font-size: 14px; margin: 0; }

  /* Page header tightens */
  .page-header { padding: 18px 16px; border-radius: 12px; margin-bottom: 18px; }
  .page-header h1 { font-size: 1.15rem; }
  .page-header p { font-size: 12.5px; }
  .page-header small { font-size: 11px; }
  .page-header .header-actions { width: 100%; justify-content: flex-start; }
  .page-header .btn-header { padding: 7px 12px; font-size: 12px; }
  .page-header .badge-role { font-size: 10.5px; padding: 4px 10px; }

  /* Stat grid: 2 columns on phones */
  .stat-grid { grid-template-columns: repeat(2, 1fr); gap: 10px; margin-bottom: 18px; }
  .stat-card { padding: 14px 16px; border-radius: 10px; }
  .stat-card .stat-number { font-size: 1.4rem; }
  .stat-card .stat-label { font-size: 12px; }
  .stat-card .stat-subtitle { font-size: 10.5px; }
  .stat-card .stat-icon { font-size: 18px; top: 12px; right: 12px; }

  /* Dashboard two-column layout stacks */
  #dashboardColumns,
  .dashboard-columns { grid-template-columns: 1fr !important; gap: 14px !important; }

  /* Panels */
  .panel { border-radius: 10px; margin-bottom: 14px; }
  .panel-head { padding: 12px 16px; }
  .panel-head h2 { font-size: 13.5px; }
  .panel-body { padding: 16px; }
  .panel-body.flush { padding: 0; }

  /* Tables scroll horizontally, keeping first column visible if possible */
  .table-responsive { overflow-x: auto; -webkit-overflow-scrolling: touch; }
  .data-table { font-size: 12.5px; min-width: 620px; }
  .data-table thead th { padding: 10px 12px; font-size: 10.5px; white-space: nowrap; }
  .data-table tbody td { padding: 10px 12px; }

  /* Action cards stack on phones */
  .actions-grid,
  .action-card + .action-card { margin-top: 10px; }
  .action-card { padding: 16px 16px; }

  /* Modal sizing — nearly full screen on phones */
  .modal-dialog, .modal-content { margin: 0; border-radius: 0; min-height: 100vh; }
  .modal-content > div:first-child,
  .modal-body { padding: 16px !important; }
  .modal-footer { padding: 12px 16px !important; flex-wrap: wrap; }
}

/* Very small phones (iPhone SE, 320px wide) */
@media (max-width: 380px) {
  .stat-grid { grid-template-columns: 1fr; }
  .page-header h1 { font-size: 1.05rem; }
  .data-table { font-size: 12px; }
}

/* ============================================================
   MODALS (bootstrap-based admin modals)
   ============================================================ */
@media (max-width: 768px) {
  .modal-dialog { margin: 0.5rem; }
  .modal-content { border-radius: 12px; }
  .modal-body { max-height: 75vh; overflow-y: auto; }
}

/* ============================================================
   FORMS in admin
   ============================================================ */
@media (max-width: 640px) {
  .flabel { font-size: 11px; }
  .finput,
  input[type="text"],
  input[type="email"],
  input[type="tel"],
  input[type="number"],
  input[type="password"],
  select,
  textarea {
    padding: 11px 14px;
    font-size: 15px;                         /* 15px prevents iOS zoom on focus */
    width: 100%;
  }

  /* Form grids collapse to single column */
  form [style*="grid-template-columns"] {
    grid-template-columns: 1fr !important;
    gap: 12px !important;
  }
}

/* ============================================================
   CANDIDATE PAGES
   ============================================================ */

/* ---------- Hero / centered pages ---------- */
/* Footer sits in normal flow — never overlaps content */
.hero-section {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: auto;
  min-height: 100vh;
  min-height: 100dvh;
}

.content-container {
  flex: 1 1 auto;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  width: 100%;
  max-width: 100%;
}

/* Badges, headings, subtitles and strips stay centered and shrink to fit */
.content-container > .badge,
.content-container > .main-heading,
.content-container > .subtitle,
.content-container > .features,
.content-container > .bottom-strip {
  align-self: center;
  max-width: 100%;
}

/* Cards go full width within the container */
.content-container > .code-card,
.content-container > .login-card,
.content-container > .form-card,
.content-container > .instructions-card,
.content-container > .confirm-card,
.content-container > .card {
  align-self: stretch;
  width: 100%;
}

/* Badges never stretch to fill the row */
.badge {
  display: inline-flex !important;
  width: auto !important;
  max-width: max-content !important;
  align-self: center !important;
}

/* Footer sits in flow, no absolute positioning */
.footer {
  position: relative !important;
  bottom: auto !important;
  left: auto !important;
  width: 100%;
  margin-top: auto;
  padding: 18px 12px 6px;
  text-align: center;
  z-index: 2;
}

@media (max-width: 720px) {
  .hero-section { padding: 24px 16px 12px; }

  .logo-container { margin-bottom: 14px; min-height: 44px; }
  .logo-container img { height: 40px; }
  .logo-mark { width: 38px; height: 38px; font-size: 13px; }
  .logo-name { font-size: 15px; }

  .main-heading { font-size: clamp(1.4rem, 5vw + 0.6rem, 1.9rem); }
  .subtitle { font-size: 0.92rem; line-height: 1.55; }

  .badge { font-size: 10.5px; padding: 5px 14px; margin-bottom: 14px; }

  .card, .confirm-card, .instructions-card, .form-card, .login-card, .code-card {
    padding: 20px 18px;
    border-radius: 14px;
  }

  .code-input-row { flex-direction: column; }
  .code-submit { justify-content: center; width: 100%; }

  .features { gap: 10px 14px; }
  .feature-item { font-size: 11.5px; }

  .bottom-strip { gap: 10px 14px; font-size: 11px; padding: 0 8px; }
  .bottom-strip .sep { display: none; }

  /* Long URLs, codes and tokens wrap instead of overflowing */
  .code-help code,
  .link-preview,
  .email-preview,
  .code-sample,
  .token-code {
    word-break: break-all;
    white-space: normal;
    overflow-wrap: anywhere;
  }

  /* Two-column form grids collapse */
  .grid-2, .grid2 {
    grid-template-columns: 1fr !important;
    gap: 12px !important;
  }

  /* Action rows stack */
  .action-row,
  .form-actions,
  .start-actions {
    flex-direction: column;
  }
  .action-row .btn-primary,
  .action-row .btn-home,
  .form-actions .btn-primary,
  .form-actions .code-submit,
  .start-actions .btn-start,
  .start-actions .code-submit {
    width: 100%;
    justify-content: center;
  }

  /* Custom modals become near-fullscreen */
  .modal-overlay { padding: 12px; align-items: flex-start; }
  .modal-box,
  .invite-modal-content {
    margin: 20px auto !important;
    max-width: 100% !important;
    border-radius: 12px !important;
  }
}

@media (max-width: 480px) {
  .hero-section { padding: 18px 12px 10px; }
  .main-heading { font-size: 1.35rem !important; line-height: 1.2; }
  .subtitle { font-size: 0.85rem; }
  .badge { font-size: 10px !important; padding: 4px 12px !important; }
  .logo-mark { width: 32px !important; height: 32px !important; font-size: 11px !important; }
  .logo-name { font-size: 14px !important; }
  .footer { font-size: 10.5px; }
  .bottom-strip { gap: 8px 12px; }
}

/* ---------- Exam layout ---------- */
@media (max-width: 900px) {
  .exam-body {
    grid-template-columns: 1fr !important;
    padding: 14px;
    gap: 14px;
  }
  .nav-panel { position: static !important; order: 2; }
  .question-panel { order: 1; }
  .qgrid { grid-template-columns: repeat(auto-fill, minmax(40px, 1fr)); gap: 6px; }
  .qbtn { font-size: 12px; }
}

@media (max-width: 640px) {
  .exam-topbar {
    padding: 10px 14px;
    gap: 10px;
    flex-wrap: wrap;
  }
  .exam-topbar .brand .mark { width: 32px; height: 32px; font-size: 11px; }
  .exam-topbar .brand .b1 { font-size: 12.5px; }
  .exam-topbar .brand .b2 { font-size: 10px; }
  .candidate-chip {
    font-size: 11px;
    padding: 5px 10px;
    max-width: 100%;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }
  .timer-box { padding: 5px 12px; }
  .timer-box .tl { font-size: 9.5px; }
  .timer-box .tv { font-size: 18px; }

  .qpanel-head { padding: 14px 18px; }
  .qpanel-body { padding: 20px 16px; }
  .qtext { font-size: 15.5px; line-height: 1.5; margin-bottom: 20px; }
  .option-row { padding: 12px 14px; gap: 10px; border-radius: 8px; }
  .opt-letter { width: 26px; height: 26px; font-size: 12px; }
  .opt-text { font-size: 14px; }

  .qactions { flex-direction: column; gap: 10px; align-items: stretch; }
  .qactions .btn-prev,
  .qactions .btn-next { width: 100%; justify-content: center; }
  .save-indicator { order: 2; text-align: center; justify-content: center; }

  /* Nav panel becomes a compact grid on phones */
  .nav-panel { padding: 14px; }
  .nav-panel h3 { font-size: 11px; }
  .nav-legend { gap: 8px; font-size: 10px; }
  .qgrid { grid-template-columns: repeat(auto-fill, minmax(36px, 1fr)); gap: 5px; }
  .qbtn { font-size: 11.5px; }
}

@media (max-width: 400px) {
  .exam-topbar .brand .b2 { display: none; }
  .candidate-chip span {
    max-width: 120px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }
}

/* ============================================================
   TABLES — the biggest offender on mobile
   ============================================================ */
.table-responsive,
div[style*="overflow-x:auto"],
div[style*="overflow-x: auto"] {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  /* subtle scroll hint */
  background:
    linear-gradient(to right, transparent 30%, rgba(0,0,0,0.04) 100%) right center / 24px 100% no-repeat;
}

/* ============================================================
   Ensure absolutely nothing overflows horizontally
   ============================================================ */
html, body, .admin-shell, .admin-main, .admin-content,
.hero-section, .content-container, .exam-body {
  max-width: 100%;
}

/* Kill any accidental wide fixed-width containers */
[style*="min-width"],
[style*="width: 1000"],
[style*="width: 1200"] {
  max-width: 100%;
}

/* ============================================================
   TOUCH-FRIENDLY controls on phones
   ============================================================ */
@media (hover: none) and (pointer: coarse) {
  button, .btn, .pill, .qbtn, a.btn, .code-submit, .btn-login {
    min-height: 40px;
  }
  .btn-sm { min-height: 34px; }
  input, select, textarea {
    min-height: 42px;
    font-size: 15px;                         /* prevents iOS zoom on focus */
  }
}

/* ============================================================
   REDUCED MOTION
   ============================================================ */
@media (prefers-reduced-motion: reduce) {
  .particle, .shape, .content-container,
  .timer-box.danger, .loader-spinner {
    animation: none !important;
  }
}

/* ============================================================
   PRINT (for CSV exports and printable results)
   ============================================================ */
@media print {
  .admin-sidebar, .admin-topbar, .page-header, .bottom-strip, .footer,
  .panel-head a, .actions-row, .header-actions {
    display: none !important;
  }
  .admin-main { margin-left: 0 !important; }
  .admin-content { padding: 0 !important; }
  body { background: #fff !important; color: #000 !important; }
  .stat-card, .panel { box-shadow: none !important; border-color: #ccc !important; }
}