/* ═══════════════════════════════════════════════════════════════
   Colosseum — Mobile Responsive Styles
   Uses existing Tailwind CSS classes + targeted media queries.
   Included AFTER the Tailwind CDN script in every template.
   ═══════════════════════════════════════════════════════════════ */

/* ── 1. Global Reset / Base ──────────────────────────────────── */
*,
*::before,
*::after {
    box-sizing: border-box;
}

html {
    -webkit-text-size-adjust: 100%;
    overflow-x: hidden;
}

body {
    overflow-x: hidden;
    min-width: 320px;
}

img, video, canvas, svg {
    max-width: 100%;
    height: auto;
}

/* ── 2. Mobile Navigation (hamburger) ────────────────────────── */

/* ─ Mobile menu (slide-down drawer) ─ */
.mobile-menu {
    max-height: 0;
    overflow: hidden;
    transition: max-height 0.3s ease-out;
}

.mobile-menu.open {
    max-height: 400px; /* enough for all links */
}

/* ─ Mobile overlay (backdrop) ─ */
.mobile-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.4);
    z-index: 40;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s ease;
}

.mobile-overlay.open {
    opacity: 1;
    pointer-events: auto;
}

/* Hamburger button — hidden on desktop */
.mobile-menu-btn {
    display: none;
    background: none;
    border: none;
    cursor: pointer;
    padding: 0.5rem;
    -webkit-tap-highlight-color: transparent;
    z-index: 60;
    min-width: 2.75rem;       /* 44px touch target */
    min-height: 2.75rem;
    align-items: center;
    justify-content: center;
}

.mobile-menu-btn svg {
    width: 1.5rem;
    height: 1.5rem;
    color: white;
}

/* Desktop nav links container — visible on lg */
.nav-desktop-links {
    display: flex;
    align-items: center;
}

/* Mobile drawer — hidden by default */
.nav-mobile-drawer {
    display: none;
    position: fixed;
    inset: 0;
    z-index: 50;
}

.nav-mobile-drawer.open {
    display: flex;
}

.nav-mobile-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: 50;
}

.nav-mobile-panel {
    position: fixed;
    top: 0;
    right: 0;
    bottom: 0;
    width: min(85vw, 320px);
    z-index: 51;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    transform: translateX(100%);
    transition: transform 0.25s ease-out;
    display: flex;
    flex-direction: column;
}

.nav-mobile-drawer.open .nav-mobile-panel {
    transform: translateX(0);
}

.nav-mobile-panel .mobile-nav-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.75rem 0.75rem 0.75rem 1.25rem;
    border-bottom: 1px solid rgba(255, 255, 255, 0.15);
    min-height: 3.5rem;          /* match nav bar height feel */
    flex-shrink: 0;
}

.nav-mobile-panel .mobile-nav-header h2 {
    font-size: 1rem;
    font-weight: 600;
    color: white;
    margin: 0;
}

.mobile-close-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 2.75rem;       /* 44px — touch-friendly */
    height: 2.75rem;
    flex-shrink: 0;
    background: rgba(255, 255, 255, 0.08);
    border: none;
    border-radius: 0.375rem;
    cursor: pointer;
    color: rgba(255, 255, 255, 0.8);
    -webkit-tap-highlight-color: transparent;
    transition: background-color 0.15s, color 0.15s;
}

.mobile-close-btn:hover,
.mobile-close-btn:active {
    background: rgba(255, 255, 255, 0.18);
    color: white;
}

.mobile-close-btn svg {
    width: 1.25rem;
    height: 1.25rem;
    pointer-events: none;   /* clicks pass through to button */
}

.nav-mobile-panel .mobile-nav-links {
    padding: 0.75rem 0;
    flex: 1;
}

.nav-mobile-panel .mobile-nav-links a,
.nav-mobile-panel .mobile-nav-links button {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.75rem 1.25rem;
    font-size: 0.9375rem;
    color: rgba(255, 255, 255, 0.85);
    text-decoration: none;
    border: none;
    background: none;
    width: 100%;
    text-align: left;
    cursor: pointer;
    transition: background-color 0.15s;
    min-height: 44px; /* Touch-friendly */
}

.nav-mobile-panel .mobile-nav-links a:hover,
.nav-mobile-panel .mobile-nav-links a:active,
.nav-mobile-panel .mobile-nav-links button:hover {
    background: rgba(255, 255, 255, 0.1);
    color: white;
}

.nav-mobile-panel .mobile-nav-links a.active-link {
    background: rgba(255, 255, 255, 0.15);
    color: white;
    font-weight: 600;
}

.nav-mobile-panel .mobile-nav-links .nav-divider {
    height: 1px;
    background: rgba(255, 255, 255, 0.15);
    margin: 0.5rem 1.25rem;
}

/* User info line inside the menu */
.nav-mobile-panel .mobile-nav-links .mobile-user-info {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.5rem 1.25rem;
    font-size: 0.8125rem;
    color: rgba(255, 255, 255, 0.5);
    pointer-events: none;
}

/* Logout link inside the menu */
.nav-mobile-panel .mobile-nav-links a.mobile-logout-link {
    color: #fca5a5; /* red-300 */
    font-weight: 600;
}

.nav-mobile-panel .mobile-nav-links a.mobile-logout-link:hover,
.nav-mobile-panel .mobile-nav-links a.mobile-logout-link:active {
    background: rgba(239, 68, 68, 0.15);
    color: #fecaca; /* red-200 */
}

/* Legacy footer (kept for backward compat with overrides) */
.nav-mobile-panel .mobile-nav-footer {
    padding: 1rem 1.25rem;
    border-top: 1px solid rgba(255, 255, 255, 0.15);
}

.nav-mobile-panel .mobile-nav-footer .user-info {
    font-size: 0.8125rem;
    color: rgba(255, 255, 255, 0.6);
    margin-bottom: 0.75rem;
}

.nav-mobile-panel .mobile-nav-footer a {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 100%;
    padding: 0.625rem 1rem;
    font-size: 0.875rem;
    font-weight: 500;
    border-radius: 0.375rem;
    text-decoration: none;
    color: white;
    transition: background-color 0.15s;
    min-height: 44px;
}

.nav-mobile-panel .mobile-nav-footer a.mobile-logout-btn {
    background-color: rgba(255, 255, 255, 0.15);
    border: 1px solid rgba(255, 255, 255, 0.3);
    font-weight: 600;
    letter-spacing: 0.01em;
}

.nav-mobile-panel .mobile-nav-footer a.mobile-logout-btn:hover,
.nav-mobile-panel .mobile-nav-footer a.mobile-logout-btn:active {
    background-color: rgba(255, 255, 255, 0.25);
    border-color: rgba(255, 255, 255, 0.5);
}

/* Nav right-side content — username + logout */
.nav-right-desktop {
    display: flex;
    align-items: center;
}

@media (max-width: 1023px) {
    .mobile-menu-btn {
        display: inline-flex;
        align-items: center;
        justify-content: center;
    }

    .nav-desktop-links {
        display: none !important;
    }

    .nav-right-desktop {
        display: none !important;
    }
}

/* ── 3. Tables — horizontal scroll wrapper ───────────────────── */
.table-responsive-wrapper {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    margin: 0 -1px;
}

/* Ensure min-w-full tables scroll on mobile */
@media (max-width: 767px) {
    .overflow-x-auto {
        -webkit-overflow-scrolling: touch;
    }

    /* Reduce table cell padding on mobile */
    .overflow-x-auto table th,
    .overflow-x-auto table td {
        padding-left: 0.75rem;
        padding-right: 0.75rem;
        font-size: 0.8125rem;
    }
}

/* ── 4. Forms — Stack on mobile ──────────────────────────────── */
@media (max-width: 639px) {
    /* Force grid to single column */
    .grid.grid-cols-1.md\:grid-cols-2,
    .grid.grid-cols-1.md\:grid-cols-3,
    .grid.grid-cols-1.md\:grid-cols-4,
    .grid.grid-cols-1.md\:grid-cols-5 {
        grid-template-columns: 1fr !important;
    }

    .md\:col-span-2 {
        grid-column: span 1 !important;
    }

    /* Full-width buttons on mobile */
    form button[type="submit"],
    .btn-mobile-full {
        width: 100%;
        justify-content: center;
    }

    /* Touch-friendly inputs */
    input[type="text"],
    input[type="password"],
    input[type="email"],
    input[type="date"],
    input[type="number"],
    input[type="search"],
    input[type="tel"],
    input[type="url"],
    select,
    textarea {
        min-height: 44px;
        font-size: 1rem; /* Prevents iOS zoom */
    }

    /* Full-width selects */
    select {
        max-width: 100%;
    }
}

/* ── 5. Buttons — Touch-friendly ─────────────────────────────── */
@media (max-width: 767px) {
    /* Ensure minimum tap target */
    button, a.inline-flex, [role="button"] {
        min-height: 44px;
    }

    /* Agree/Disagree radio rows */
    .verify-row-actions {
        flex-direction: column;
        gap: 0.5rem;
    }

    .verify-row-actions label {
        min-height: 44px;
        display: flex;
        align-items: center;
        padding: 0.5rem 0.75rem;
    }
}

/* ── 6. Stats Cards ──────────────────────────────────────────── */
@media (max-width: 639px) {
    .grid.grid-cols-1.md\:grid-cols-2.lg\:grid-cols-4,
    .grid.grid-cols-1.md\:grid-cols-3,
    .grid.grid-cols-1.md\:grid-cols-4,
    .grid.grid-cols-2.md\:grid-cols-4 {
        grid-template-columns: 1fr 1fr !important;
    }

    /* Make stat card text smaller */
    .text-3xl {
        font-size: 1.5rem;
    }

    .text-2xl {
        font-size: 1.25rem;
    }
}

@media (max-width: 374px) {
    .grid.grid-cols-2.md\:grid-cols-4,
    .grid.grid-cols-1.md\:grid-cols-2.lg\:grid-cols-4 {
        grid-template-columns: 1fr !important;
    }
}

/* ── 7. Controller — tab navigation via navbar links ─────────── */
/* Desktop: active nav-tab-link gets a subtle underline indicator */
.nav-desktop-links .nav-tab-link {
    position: relative;
    padding-bottom: 0.25rem;
    transition: color 0.15s;
}
.nav-desktop-links .nav-tab-link::after {
    content: '';
    position: absolute;
    left: 0;
    right: 0;
    bottom: -2px;
    height: 2px;
    background: transparent;
    border-radius: 1px;
    transition: background-color 0.15s;
}
.nav-desktop-links .nav-tab-link.text-white.font-bold::after {
    background: rgba(255, 255, 255, 0.7);
}

/* ── 7b. Controller — mobile tab links in hamburger menu ─────── */
.nav-mobile-panel .mobile-nav-links a.mobile-tab-link {
    font-size: 0.9375rem;
    padding: 0.75rem 1.25rem;
    display: flex;
    align-items: center;
    gap: 0.625rem;
}

.nav-mobile-panel .mobile-nav-links a.mobile-tab-link svg {
    flex-shrink: 0;
    opacity: 0.7;
}

.nav-mobile-panel .mobile-nav-links a.mobile-tab-link.active-link {
    background: rgba(255, 255, 255, 0.15);
    color: white;
    font-weight: 600;
    border-left: 3px solid rgba(255, 255, 255, 0.6);
}

.nav-mobile-panel .mobile-nav-links a.mobile-tab-link.active-link svg {
    opacity: 1;
}

/* ── 8. Verify / Observer Form — Mobile ──────────────────────── */
@media (max-width: 767px) {
    /* Section instance blocks: full width */
    .verify-instance-block {
        padding: 0.75rem;
    }

    /* Radio group for agree/disagree — stack vertically */
    .verification-radio-group {
        flex-direction: column;
        gap: 0.375rem;
    }

    .verification-radio-group label {
        min-height: 44px;
        padding: 0.5rem 0.75rem;
        border-radius: 0.375rem;
    }

    /* Disagree correction textarea — full width */
    .disagree-correction {
        width: 100% !important;
        margin-top: 0.5rem;
    }

    /* Submit verification button — full width */
    #submit-verification {
        width: 100%;
        justify-content: center;
    }

    /* Legend — stack on mobile */
    .flex.flex-wrap.gap-6 {
        gap: 0.5rem;
        flex-direction: column;
    }
}

/* ── 9. QR Code Screens ──────────────────────────────────────── */
@media (max-width: 639px) {
    /* QR scanner area */
    #qr-reader {
        width: 100% !important;
        max-width: 100%;
    }

    #qr-reader video {
        width: 100% !important;
    }

    /* QR result card */
    .qr-result-card {
        margin-left: -0.5rem;
        margin-right: -0.5rem;
    }

    /* Scanner buttons full width */
    #btn-start, #btn-stop {
        padding-top: 0.75rem;
        padding-bottom: 0.75rem;
    }
}

/* ── 10. Face Recognition — Camera ───────────────────────────── */
@media (max-width: 639px) {
    .camera-container {
        width: 100%;
        max-width: 100%;
    }

    .camera-container video {
        width: 100%;
        height: auto;
    }

    /* Student info card */
    .student-info-grid {
        grid-template-columns: 1fr !important;
    }
}

/* ── 11. Photo Comparison (resolve form) ─────────────────────── */
@media (max-width: 639px) {
    .flex.gap-8.justify-center {
        flex-direction: column;
        align-items: center;
        gap: 1.5rem;
    }

    .flex.gap-8.justify-center > div {
        width: 100%;
        max-width: 200px;
    }
}

/* ── 12. Admin Dashboard — User management table cards ───────── */
@media (max-width: 639px) {
    /* Actions column — stack buttons */
    td .flex.space-x-2 {
        flex-direction: column;
        gap: 0.375rem;
    }

    td .flex.space-x-2 form {
        width: 100%;
    }

    td .flex.space-x-2 button {
        width: 100%;
        min-height: 36px;
    }

    /* User avatar in table — smaller */
    .flex-shrink-0.h-10.w-10 {
        display: none;
    }
}

/* ── 13. Quick action buttons — wrap on mobile ───────────────── */
@media (max-width: 639px) {
    .flex.flex-wrap.gap-3 {
        flex-direction: column;
    }

    .flex.flex-wrap.gap-3 > a,
    .flex.flex-wrap.gap-3 > button {
        width: 100%;
        justify-content: center;
    }
}

/* ── 14. Page title / heading truncation ─────────────────────── */
@media (max-width: 767px) {
    nav h1 {
        font-size: 1rem;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
        max-width: 55vw;
    }
}

@media (max-width: 374px) {
    nav h1 {
        max-width: 45vw;
        font-size: 0.875rem;
    }
}

/* ── 15. Dialog/Modal — ensure full-screen on mobile ─────────── */
@media (max-width: 639px) {
    .modal-content {
        max-width: 95%;
        max-height: 95%;
    }
}

/* ── 16. Admin Form Builder — mobile adjustments ─────────────── */
@media (max-width: 1023px) {
    /* Stack 3-col layout */
    .grid.grid-cols-1.lg\:grid-cols-3 {
        grid-template-columns: 1fr !important;
    }

    .lg\:col-span-2 {
        grid-column: span 1 !important;
    }
}

@media (max-width: 639px) {
    /* Form builder — questions table: reduce padding */
    .w-full.text-sm th,
    .w-full.text-sm td {
        padding: 0.5rem 0.375rem;
        font-size: 0.75rem;
    }

    /* Hide less critical columns */
    .w-full.text-sm th:nth-child(3),
    .w-full.text-sm td:nth-child(3),
    .w-full.text-sm th:nth-child(6),
    .w-full.text-sm td:nth-child(6) {
        display: none;
    }

    /* Section header — stack */
    .bg-gray-100.px-6.py-4.flex.items-center.justify-between {
        flex-direction: column;
        align-items: flex-start;
        gap: 0.5rem;
    }

    /* Template settings form — stack */
    .flex.flex-wrap.items-end.gap-4 {
        flex-direction: column;
        align-items: stretch;
    }

    .flex.flex-wrap.items-end.gap-4 > div {
        width: 100% !important;
        min-width: 100% !important;
    }

    .flex.flex-wrap.items-end.gap-4 > button {
        width: 100%;
    }
}

/* ── 17. Flex row → column on small screens ──────────────────── */
@media (max-width: 639px) {
    .flex.items-end.gap-4 {
        flex-direction: column;
        align-items: stretch;
    }

    .flex.items-end.gap-4 > .flex-1 {
        width: 100%;
    }

    .flex.items-end.gap-4 > button {
        width: 100%;
    }
}

/* ── 18. Container padding on mobile ─────────────────────────── */
@media (max-width: 639px) {
    .max-w-7xl.mx-auto.py-6.px-4,
    .max-w-5xl.mx-auto.py-6.px-4,
    .max-w-4xl.mx-auto.py-6.px-4,
    .max-w-3xl.mx-auto.py-6.px-4 {
        padding-left: 0.75rem;
        padding-right: 0.75rem;
        padding-top: 1rem;
    }
}

/* ── 19. Admin Test Centers + Edit (Bootstrap hybrid) ────────── */
@media (max-width: 767px) {
    .row {
        flex-direction: column;
    }

    .col-md-5, .col-md-7, .col {
        flex: 0 0 100%;
        max-width: 100%;
    }

    .table-responsive {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }

    .form-control {
        min-height: 44px;
        font-size: 1rem;
    }

    .btn {
        min-height: 44px;
    }
}

/* ── 20. Filter rows — stack on mobile ───────────────────────── */
@media (max-width: 639px) {
    .sm\:p-6 {
        padding: 1rem;
    }
}

/* ── 21. Print styles — keep unchanged ───────────────────────── */
@media print {
    .mobile-menu-btn,
    .nav-mobile-drawer {
        display: none !important;
    }
}
