/*
 * Modern UI mobile layer: off-canvas drawer, backdrop, touch targets,
 * safe areas and table scroll affordances.
 */

#sidebarBackdrop {
  display: none;
}

.tb-nav-trigger {
  position: fixed;
  right: 20px;
  bottom: calc(20px + env(safe-area-inset-bottom));
  z-index: 500;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 44px;
  padding: 0 16px;
  border: 1px solid var(--tb-nav-trigger-border);
  border-radius: 999px;
  background: var(--tb-nav-trigger-bg);
  color: var(--tb-nav-trigger-fg);
  box-shadow: var(--tb-shadow);
  font-size: 0.9rem;
  font-weight: 600;
  line-height: 1;
  cursor: pointer;
  transition: box-shadow var(--tb-transition), background-color var(--tb-transition), border-color var(--tb-transition);
}

.tb-nav-trigger:hover,
.tb-nav-trigger:focus-visible {
  box-shadow: var(--tb-shadow-lg);
}

.tb-nav-trigger:focus-visible {
  outline: 2px solid var(--tb-focus);
  outline-offset: 2px;
}

.tb-nav-trigger:active {
  transform: translateY(1px);
}

.tb-nav-trigger__label {
  white-space: nowrap;
}

.tb-sidebar-open .tb-nav-trigger {
  visibility: hidden;
  pointer-events: none;
}

@media (max-width: 768px) {
  #sidebar {
    position: fixed;
    top: 0;
    left: 0;
    width: min(82vw, 300px);
    min-width: 0;
    max-width: none;
    height: 100vh;
    height: 100dvh;
    margin-left: 0;
    padding-bottom: env(safe-area-inset-bottom);
    transform: translateX(-100%);
    box-shadow: var(--tb-shadow-lg);
    z-index: 1040;
  }

  #sidebar.active {
    margin-left: 0;
    transform: translateX(0);
  }

  #sidebar.tb-sheet {
    top: auto;
    bottom: 0;
    left: 0;
    right: 0;
    width: 100%;
    min-width: 0;
    max-width: none;
    height: auto;
    max-height: 88vh;
    max-height: 88dvh;
    margin-left: 0;
    padding-bottom: 0;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    border-radius: 16px 16px 0 0;
    transform: translateY(100%);
  }

  #sidebar.tb-sheet.active {
    transform: translateY(0);
  }

  .tb-sheet-handle {
    flex: 0 0 auto;
    display: flex;
    align-items: center;
    justify-content: center;
    height: 16px;
    touch-action: none;
    cursor: grab;
  }

  .tb-sheet-handle span {
    display: block;
    width: 36px;
    height: 4px;
    border-radius: 2px;
    background: var(--tb-sidebar-muted);
    opacity: 0.6;
  }

  #sidebar.tb-sheet .tb-sheet-body {
    flex: 1 1 auto;
    min-height: 0;
    overflow-y: auto;
    overscroll-behavior: contain;
    padding-bottom: calc(env(safe-area-inset-bottom) + 8px);
  }

  #sidebar.tb-sheet .sidebar-header,
  #sidebar.tb-sheet .clock {
    display: none;
  }

  #sidebarBackdrop {
    display: block;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
    opacity: 0;
    visibility: hidden;
    transition: opacity var(--tb-transition), visibility var(--tb-transition);
    z-index: 1035;
  }

  #sidebarBackdrop.active {
    opacity: 1;
    visibility: visible;
  }

  body.tb-sidebar-open {
    overflow: hidden;
  }

  #content {
    padding: 0.75rem;
    padding-left: max(0.75rem, env(safe-area-inset-left));
    padding-right: max(0.75rem, env(safe-area-inset-right));
    padding-bottom: max(0.75rem, env(safe-area-inset-bottom));
  }

  .navbar {
    padding: 6px 10px;
  }

  #topnavtitle {
    max-width: 46vw;
    font-size: 0.92rem;
  }

  /* Table scroll is contained and signposted with a soft right-edge fade. */
  .table-responsive {
    -webkit-overflow-scrolling: touch;
    background-image: linear-gradient(to right, rgba(0, 0, 0, 0), var(--tb-border));
    background-position: right center;
    background-repeat: no-repeat;
    background-size: 18px 100%;
  }

  .table-responsive > .table > thead > tr > th:first-child,
  .table-responsive > .table > tbody > tr > td:first-child {
    position: sticky;
    left: 0;
    background-color: var(--tb-surface);
    box-shadow: 1px 0 0 var(--tb-table-border);
    z-index: 1;
  }

  .table-responsive > .table-striped > tbody > tr:nth-child(even of :where(:not(.d-none):not(.collapse))) > td:first-child {
    background-color: var(--tb-table-stripe-bg);
  }
}

@media (pointer: coarse) {
  #sidebar ul li a,
  #sidebar ul li a.dropdown-toggle {
    min-height: 44px;
  }

  .btn,
  .nav-link,
  .navbar-btn,
  .theme-toggle {
    min-height: 44px;
    min-width: 44px;
  }

  .form-control,
  .custom-select,
  input,
  select,
  textarea {
    font-size: 16px;
  }
}

@media (hover: hover) and (pointer: fine) {
  .table-responsive > .table > tbody > tr:hover > td:first-child {
    background-color: var(--tb-table-hover-bg);
  }
}

@media (max-width: 768px) {
  .attendance-tabs.nav-tabs {
    flex-wrap: nowrap;
    gap: 1px;
    overflow-x: visible;
  }

  .attendance-tabs .nav-item {
    flex: 1 1 0;
    min-width: 0;
  }

  .attendance-tabs .nav-link {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 100%;
    padding: 0.5rem 0.25rem;
    font-size: 0.95rem;
    line-height: 1.2;
    white-space: nowrap;
  }

  .attendance-day-picker {
    display: flex;
  }

  .attendance-tabs .nav-link,
  .attendance-day-chip,
  .attendance-cell,
  #AttendanceModal .btn {
    min-height: 44px;
  }

  #AttendanceModal .attendance-student-toggle {
    min-height: 44px;
  }
}

@media (max-width: 359px) {
  .attendance-tabs .nav-link {
    font-size: 0.9rem;
    padding-left: 0.2rem;
    padding-right: 0.2rem;
  }
}
