html,
body {
  max-width: 100%;
  overflow-x: hidden;
}

img,
video,
iframe {
  max-width: 100%;
}

@media (max-width: 991.98px) {
  .pcoded-header {
    width: 100%;
    margin-left: 0;
    min-height: 60px;
  }

  .pcoded-header .m-header {
    display: flex;
    align-items: center;
    min-height: 60px;
    padding: 0 12px;
  }

  .pcoded-header .m-header .b-brand {
    max-width: calc(100% - 50px);
    overflow: hidden;
  }

  .pcoded-header .m-header .b-brand .b-bg {
    width: auto;
    height: auto;
    background: none;
    border-radius: 0;
  }

  .pcoded-header .m-header .b-brand img {
    max-width: 150px;
    width: auto;
    height: auto;
    max-height: 34px;
  }

  .pcoded-header .navbar-nav > li {
    padding: 0 6px;
  }

  .pcoded-header .navbar-nav > li:last-child {
    padding-right: 12px;
  }

  .pcoded-header .topbar-title {
    display: inline-block;
    max-width: 42vw;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    font-size: 16px;
  }

  /* Second header band: keep it a compact toolbar with the title visible */
  .pcoded-header .navbar-nav.me-auto li {
    display: block;
  }

  .pcoded-header .navbar-nav.me-auto li:has(.full-screen) {
    display: none;
  }

  .pcoded-header .m-header {
    height: 60px;
    min-height: 60px;
  }

  .pcoded-header .collapse.navbar-collapse {
    min-height: 50px;
  }

  .pcoded-header .collapse.navbar-collapse .navbar-nav > li {
    min-height: 50px;
    max-height: 50px;
  }

  .pcoded-header .collapse.navbar-collapse .navbar-nav > li > a,
  .pcoded-header .collapse.navbar-collapse .navbar-nav > li .dropdown-toggle {
    line-height: 50px;
  }

  .pcoded-header .navbar-nav.ms-auto > li {
    display: flex;
    align-items: center;
    min-height: 50px;
  }

  .pcoded-navbar {
    position: fixed;
    z-index: 1031;
    top: 0;
    left: -260px;
    width: 260px;
    height: 100vh;
    transition: left .2s ease-in-out;
  }

  .pcoded-navbar.mob-open {
    left: 0;
  }

  .pcoded-main-container {
    margin-left: 0;
    padding: 12px;
  }

  .pcoded-content,
  .pcoded-inner-content,
  .page-wrapper {
    padding: 0;
  }

  .card-block,
  .card-body {
    padding: 16px;
  }

  .table-responsive {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }

  .form-control,
  .custom-select,
  select {
    max-width: 100%;
  }

  .btn {
    margin-bottom: 6px;
  }
}

@media (max-width: 575.98px) {
  .pcoded-header .ms-auto > li:not(:last-child) {
    display: none;
  }

  .pcoded-header .topbar-title {
    max-width: 34vw;
  }

  .page-header-title h5,
  .card-header h5 {
    font-size: 16px;
  }

  .row > [class*="col-"] {
    width: 100%;
    flex: 0 0 100%;
    max-width: 100%;
  }
}

/* Student list has a dedicated touch-friendly card representation. Keep the
   desktop DataTable available above the mobile breakpoint. */
@media (max-width: 767px) {
  .student-list-table {
    display: none !important;
  }

  .student-mobile-list {
    display: grid !important;
    gap: 12px;
    width: 100%;
  }

  .student-mobile-list ~ .dataTables_wrapper,
  .student-mobile-list + .dataTables_wrapper,
  .student-mobile-list + * {
    display: none !important;
  }

  .student-mobile-list + * { margin-top: 0; }

  /* The table is immediately before the mobile list in the student view. */
  .student-mobile-list {
    position: relative;
  }

  .student-mobile-list .student-mobile-card {
    display: block;
    width: 100%;
    box-sizing: border-box;
  }

  .student-mobile-card__bottom {
    min-height: 44px;
  }

  .student-mobile-card__bottom .btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    min-width: 86px;
    min-height: 42px;
    padding: 8px 14px;
    border: 0;
    border-radius: 22px;
    box-shadow: 0 4px 10px rgba(37, 99, 235, .18);
    font-size: 13px;
  }

  .student-mobile-card__bottom .btn:active {
    transform: scale(.97);
  }

  .student-mobile-card__bottom .badge {
    display: inline-flex;
    align-items: center;
    min-height: 26px;
  }

  /* Page actions become a compact mobile toolbar instead of a row that
     overflows the card. */
  .student-list-table ~ .student-mobile-list { margin-top: 0; }
  .page-wrapper .card-block > .btn,
  .page-wrapper .card-block > form.d-inline .btn {
    margin: 3px 4px 3px 0;
    border-radius: 22px;
  }

  .student-mobile-list + .student-mobile-card { display: block; }
}

/* ---------- PWA / touch refinements ---------- */

/* Keep content clear of notches and home indicator when installed */
@media (display-mode: standalone) {
  .pcoded-header {
    padding-top: env(safe-area-inset-top);
  }

  .pcoded-navbar {
    padding-top: env(safe-area-inset-top);
  }

  .pcoded-main-container {
    padding-bottom: calc(12px + env(safe-area-inset-bottom));
  }
}

@media (max-width: 991.98px) {
  /* Comfortable touch targets. Sidebar links stay block: the template
     absolutely positions .pcoded-mtext beside the inline icon. */
  .pcoded-navbar .pcoded-inner-navbar li > a,
  .pcoded-navbar .pcoded-m-link {
    min-height: 44px;
  }

  .dropdown-item,
  .nav-link {
    min-height: 44px;
    display: flex;
    align-items: center;
  }

  .btn,
  button[type="submit"] {
    min-height: 44px;
  }

  .form-control,
  .custom-select,
  select,
  input[type="text"],
  input[type="email"],
  input[type="password"],
  input[type="number"],
  input[type="date"],
  textarea {
    min-height: 44px;
    font-size: 16px; /* prevents iOS zoom-on-focus */
  }

  .select2-container {
    width: 100% !important;
    max-width: 100%;
  }

  /* Wide tables scroll horizontally instead of breaking layout */
  .card-body > table,
  .card-block > table,
  .table-container > table,
  table:not(.table-responsive table):not(.dataTables_wrapper table) {
    display: block;
    width: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }

  .dataTables_wrapper {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    border: 0;
    background: transparent;
  }

  /* Shared list-page treatment: every admin table remains usable on a phone
     without forcing the whole page wider than the viewport. */
  .table-responsive,
  .dataTables_wrapper .dataTables_scroll {
    width: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: thin;
    border-radius: 10px;
  }

  .table-responsive > table,
  .dataTables_wrapper table {
    min-width: 680px;
  }

  .table-responsive .table,
  .dataTables_wrapper .table {
    font-size: 12px;
  }

  .table-responsive .table th,
  .table-responsive .table td,
  .dataTables_wrapper .table th,
  .dataTables_wrapper .table td {
    padding: 9px 10px;
    white-space: nowrap;
  }

  .table-responsive .table thead th:first-child,
  .table-responsive .table tbody td:first-child {
    position: sticky;
    left: 0;
    z-index: 1;
    background: #fff;
  }

  .table-responsive .table thead th:first-child {
    background: #f8fafc;
    z-index: 2;
  }

  .dataTables_wrapper .dataTables_filter,
  .dataTables_wrapper .dataTables_length,
  .dataTables_wrapper .dt-buttons {
    float: none;
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 8px;
    margin: 8px 0;
  }

  .dataTables_wrapper .dataTables_filter input {
    width: min(100%, 220px);
    min-height: 40px;
  }

  .dataTables_wrapper .dataTables_info,
  .dataTables_wrapper .dataTables_paginate {
    float: none;
    display: block;
    margin: 10px 0 0;
    text-align: left;
  }

  /* Modals fit small screens */
  .modal-dialog {
    margin: 12px;
    max-width: calc(100% - 24px);
  }

  .modal-body,
  .modal-footer {
    flex-wrap: wrap;
  }

  h1, h2, h3, h4, h5, h6, p, a, span, li, td, th, label {
    overflow-wrap: break-word;
  }

  .auth-logo {
    left: 12px;
    top: 8px;
  }

  .auth-wrapper .auth-content {
    padding: 12px;
  }
}

@media (max-width: 575.98px) {
  .pcoded-header .navbar-nav > li > a {
    padding: 8px;
  }

  .btn-group,
  .btn-group-vertical {
    flex-wrap: wrap;
  }

  .page-header {
    flex-direction: column;
    align-items: flex-start;
    gap: 8px;
  }
}

