/*
FILE PURPOSE: All responsive layout and accessibility styling (Design Plan section 8).
Loaded after app.css. Bootstrap 5 utilities and components do the heavy lifting;
this file only adds what Bootstrap does not provide. Mobile-first.
*/

/* 1. Reflow (WCAG 1.4.10, down to 320 CSS px) */
img, svg, canvas, video {
  max-width: 100%;
  height: auto;
}
main, .admin-content, .page-container {
  min-width: 0;
}
.text-break, td, th, .card-text, p, dd, dt {
  overflow-wrap: anywhere;
}
pre, code {
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

/* 2. Focus (WCAG 2.4.7, 1.4.11) - #0B5ED7 on #FFFFFF = 5.84:1, on #F5F7FA = 5.42:1 */
:focus-visible {
  outline: 3px solid #0B5ED7 !important;
  outline-offset: 2px !important;
}
.admin-sidebar :focus-visible,
.navbar-dark :focus-visible {
  /* #FFFFFF on #14283B = 15.10:1 */
  outline: 3px solid #FFFFFF !important;
  outline-offset: 2px !important;
}

.skip-link {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}
.skip-link:focus,
.skip-link:focus-visible {
  position: fixed;
  top: 0.5rem;
  left: 0.5rem;
  z-index: 2050;
  width: auto;
  height: auto;
  margin: 0;
  padding: 0.6rem 1rem;
  overflow: visible;
  clip: auto;
  background-color: #1F4E79; /* #FFFFFF on #1F4E79 = 8.44:1 */
  color: #FFFFFF;
  text-decoration: none;
  border-radius: 0.25rem;
  outline: 3px solid #0B5ED7 !important;
}

/* 3. Touch targets below 768 px (44x44 CSS px minimum) */
@media (max-width: 767.98px) {
  .btn,
  .nav-link,
  .navbar-toggler,
  .btn-close,
  .form-control,
  .form-select,
  .page-link,
  details > summary {
    min-height: 44px;
  }
  .navbar-toggler,
  .btn-close {
    min-width: 44px;
  }
  .form-check {
    min-height: 44px;
    display: flex;
    align-items: center;
    gap: 0.5rem;
  }
  .form-check-input {
    width: 24px;
    height: 24px;
    margin-top: 0;
    flex-shrink: 0;
  }
  .form-check-label {
    min-height: 44px;
    display: inline-flex;
    align-items: center;
  }
}

/* 4. xs (under 576 px) */
@media (max-width: 575.98px) {
  .btn-xs-block {
    display: block;
    width: 100%;
    margin-block: 0.25rem;
  }
  .btn-group-xs-stack {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    width: 100%;
  }
  .auth-card {
    margin-inline: 0.75rem;
  }
  .page-container {
    padding-inline: 0.75rem;
  }
  .stat-card,
  .chart-card {
    width: 100%;
  }
  .modal-dialog {
    margin: 0.5rem;
  }
  .chart-box {
    height: 220px;
  }
}

@media (min-width: 576px) {
  .btn-group-xs-stack {
    display: inline-flex;
    flex-direction: row;
    flex-wrap: wrap;
    gap: 0.5rem;
    align-items: center;
  }
}

/* 5. TABLE CARDS (under 576 px only) */
@media (max-width: 575.98px) {
  .table-stack thead {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
  }
  .table-stack,
  .table-stack tbody {
    display: block;
    width: 100%;
  }
  .table-stack tbody tr {
    display: block;
    border: 1px solid #6C757D; /* #6C757D on #FFFFFF = 4.69:1 */
    border-radius: 0.375rem;
    background-color: #FFFFFF;
    margin-bottom: 0.75rem;
    padding: 0.5rem 0.75rem;
  }
  .table-stack td {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    gap: 1rem;
    border: none;
    padding: 0.35rem 0;
    text-align: right;
  }
  .table-stack td::before {
    content: attr(data-label);
    font-weight: 700;
    text-align: left;
    flex: 0 0 40%;
    color: #212529; /* #212529 on #FFFFFF = 16.10:1 */
  }
  .table-stack td.td-actions {
    flex-direction: column;
    align-items: stretch;
    text-align: left;
    gap: 0.5rem;
  }
  .table-stack td.td-actions::before {
    flex: none;
  }
}

/* 6. Admin shell & offcanvas drawer */
header {
  position: sticky;
  top: 0;
  z-index: 1030;
  width: 100%;
}
.admin-topbar {
  position: sticky;
  top: 0;
  z-index: 1030;
  background-color: #14283B !important; /* #E6EDF3 on #14283B = 12.74:1 */
  color: #E6EDF3;
}
.admin-sidebar,
.admin-sidebar.offcanvas-lg,
aside#adminSidebar {
  background-color: #14283B !important;
  color: #E6EDF3 !important;
}
.admin-sidebar .offcanvas-body {
  background-color: #14283B !important;
}
.admin-sidebar .nav-link,
.admin-sidebar a {
  color: #E6EDF3 !important; /* 12.74:1 on #14283B */
  padding: 0.75rem 1rem;
  min-height: 44px;
  display: flex;
  align-items: center;
  text-decoration: none;
}
.admin-sidebar .nav-link:hover,
.admin-sidebar a:hover {
  background-color: rgba(255, 255, 255, 0.08) !important;
  color: #FFFFFF !important;
}
.admin-sidebar .nav-link.active,
.admin-sidebar a.active,
.admin-sidebar a[aria-current="page"] {
  border-left: 4px solid #FFC107 !important; /* #FFC107 on #14283B = 9.21:1 */
  background-color: rgba(255, 255, 255, 0.12) !important;
  font-weight: 700 !important;
  color: #FFFFFF !important;
}
.admin-content {
  min-width: 0;
  padding: 1rem;
  flex: 1 1 auto;
}

@media (max-width: 991.98px) {
  .admin-sidebar.offcanvas-lg {
    width: 280px;
  }
}

/* 7. md (768 to 991) */
@media (min-width: 768px) and (max-width: 991.98px) {
  .table-responsive {
    overflow-x: auto;
  }
}

/* 8. lg (992 to 1199) */
@media (min-width: 992px) {
  .admin-shell {
    display: flex;
    flex-direction: row;
    align-items: stretch;
    min-height: calc(100vh - 56px);
  }
  .admin-sidebar,
  .admin-sidebar.offcanvas-lg,
  aside#adminSidebar {
    background-color: #14283B !important;
    width: 240px;
    flex: 0 0 240px;
    position: sticky;
    top: 56px;
    height: calc(100vh - 56px);
    overflow-y: auto;
  }
  .admin-content {
    padding: 1.5rem;
  }
}

/* 9. xl (1200 and up) */
.page-container {
  max-width: 1200px;
  margin-inline: auto;
}
@media (min-width: 1200px) {
  .admin-content {
    max-width: 1200px;
  }
}

/* 10. Navbar */
@media (max-width: 991.98px) {
  .navbar-collapse .nav-link {
    width: 100%;
    min-height: 44px;
    display: flex;
    align-items: center;
  }
}
.navbar .nav-link[aria-current="page"],
.navbar .nav-link.active {
  text-decoration: underline;
  text-decoration-thickness: 3px;
  text-underline-offset: 4px;
  font-weight: 600;
}

/* 11. Forced colours and high contrast */
@media (forced-colors: active) {
  .badge,
  .btn,
  .card,
  .stat-card,
  .chart-card,
  .form-control,
  .form-select,
  .form-check-input {
    border: 1px solid CanvasText;
  }
  :focus-visible {
    outline: 3px solid Highlight !important;
  }
}

/* 12. Motion (prefers-reduced-motion) */
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after,
  .offcanvas,
  .offcanvas-lg,
  .collapsing,
  .modal.fade .modal-dialog {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
}

/* 13. Text spacing (WCAG 1.4.12) */
.card,
.stat-card,
.chart-card,
.alert,
.badge,
.btn,
.nav-link {
  height: auto;
}

/* 13b. Registration: Examiner details conditional display */
#examiner-fields {
  display: none;
}
form:has(input[name="role"][value="examiner"]:checked) #examiner-fields {
  display: block;
}

/* 14. Print */
@media print {
  header,
  footer,
  .admin-sidebar,
  .admin-topbar,
  .navbar,
  .btn,
  .table-filter-bar {
    display: none !important;
  }
}
