/**
 * GEMTS – phones + computers
 * Load after page CSS so these rules win on small screens.
 */

/* ---- Base: fluid layout on all devices ---- */
html {
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
  scroll-behavior: smooth;
}
body {
  overflow-x: hidden;
  max-width: 100vw;
}
img, video, canvas, iframe, svg {
  max-width: 100%;
  height: auto;
}
/* Prevent iOS zoom on focus: inputs need >= 16px */
input, select, textarea, button {
  font-size: max(16px, 1em);
  max-width: 100%;
  box-sizing: border-box;
}
button, .btn, a.btn, .role-tab, .btn-submit {
  min-height: 44px;
  min-width: 44px;
  touch-action: manipulation;
  -webkit-tap-highlight-color: rgba(15, 23, 42, 0.12);
}
table {
  display: block;
  width: 100%;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

/* ---- Login (phones) ---- */
@media (max-width: 900px) {
  html, body {
    height: auto !important;
    min-height: 100%;
    min-height: 100dvh;
    overflow: auto !important;
  }
  .login-shell {
    flex-direction: column !important;
    max-width: 100% !important;
    margin: 0 auto !important;
    padding: 12px !important;
    min-height: auto !important;
  }
  .login-left, .login-right {
    width: 100% !important;
    max-width: 100% !important;
    flex: none !important;
  }
  .login-right {
    order: -1;
    max-height: 28vh;
    overflow: hidden;
  }
  .login-right img {
    width: 100%;
    max-height: 28vh;
    object-fit: cover;
    border-radius: 12px;
  }
  .role-tabs {
    display: grid !important;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
  }
  .role-tab {
    padding: 12px 8px !important;
    font-size: 14px !important;
  }
  .form-panel input {
    width: 100% !important;
    padding: 12px 14px !important;
  }
  .btn-submit {
    width: 100% !important;
    padding: 14px !important;
    font-size: 16px !important;
  }
}

/* ---- Student / staff shells ---- */
@media (max-width: 992px) {
  body.w3-light-grey,
  body {
    max-width: 100% !important;
    margin: 0 !important;
  }
  .w3-main {
    margin-left: 0 !important;
    margin-right: 0 !important;
    padding: 12px !important;
    max-width: 100% !important;
  }
  /* Sidebar is overlay on small screens (W3) — ensure it can hide */
  #mySidebar.w3-collapse {
    width: min(300px, 88vw) !important;
  }
  .w3-bar.w3-top {
    font-size: 14px;
  }
  .stu-actions,
  .sup-actions {
    flex-direction: column !important;
    align-items: stretch !important;
  }
  .stu-actions .btn,
  .stu-actions button,
  .start_btn button {
    width: 100% !important;
  }
  .quiz_box,
  .info_box,
  .result_box {
    width: min(96vw, 540px) !important;
    max-width: 96vw !important;
    left: 50% !important;
    margin-left: 0 !important;
  }
  .quiz_box header .title {
    font-size: 14px !important;
  }
  .option_list .option {
    padding: 12px 10px !important;
    font-size: 15px !important;
  }
  #mapFrame, #mapFrame2, .nabteb-map-wrap iframe {
    height: 200px !important;
    max-height: 32vh !important;
  }
  /* Camera preview */
  #video, video#video, #webcam, .camera video {
    width: 100% !important;
    max-height: 40vh !important;
    object-fit: cover;
  }
}

@media (max-width: 600px) {
  .w3-bar .w3-bar-item {
    padding: 8px 10px !important;
  }
  .info_box.activeInfo,
  .quiz_box.activeQuiz,
  .result_box.activeResult {
    width: 96vw !important;
    max-height: 88vh !important;
    overflow-y: auto !important;
  }
  .gemts-info-modal .modal-dialog,
  #modal1 .modal-dialog,
  #modal4 .modal-dialog {
    width: 94vw !important;
    max-width: 94vw !important;
  }
  /* Chat FAB position safe for thumbs */
  #gemtsHelpFab {
    right: 12px !important;
    bottom: 12px !important;
  }
  #gemtsChatPanel {
    width: min(100vw - 16px, 360px) !important;
    right: 8px !important;
    bottom: 64px !important;
    max-height: 70vh !important;
  }
}

/* ---- Admin dashboard ---- */
@media (max-width: 900px) {
  .min-h-screen.flex,
  body > .flex.min-h-screen {
    flex-direction: column !important;
  }
  aside, .w-64, [class*="w-64"] {
    width: 100% !important;
    max-width: 100% !important;
  }
  main, .flex-1 {
    width: 100% !important;
    padding: 12px !important;
  }
  .grid, .md\:grid-cols-3, .md\:grid-cols-2 {
    grid-template-columns: 1fr !important;
  }
  canvas {
    max-width: 100% !important;
    height: auto !important;
  }
}

/* ---- Landscape phones ---- */
@media (max-height: 480px) and (orientation: landscape) {
  .login-right { display: none !important; }
  .login-shell { padding: 8px !important; }
  #gemtsChatPanel { max-height: 85vh !important; }
}

/* ---- Large screens (computers) ---- */
@media (min-width: 1200px) {
  .login-shell {
    max-width: 1100px;
  }
  .w3-main {
    max-width: 1200px;
  }
}

/* Safe areas (notched phones) */
@supports (padding: env(safe-area-inset-bottom)) {
  body {
    padding-left: env(safe-area-inset-left);
    padding-right: env(safe-area-inset-right);
  }
  .w3-bar.w3-top {
    padding-top: env(safe-area-inset-top);
  }
  #gemtsHelpFab {
    bottom: calc(12px + env(safe-area-inset-bottom)) !important;
  }
}
