/* ==========================================================================
   ONLINE EXAM MANAGEMENT SYSTEM - UNIVERSAL MOBILE RESPONSIVE STYLESHEET
   Comprehensive mobile responsiveness across all devices (320px to 1200px+)
   ========================================================================== */

/* ==========================================================================
   1. GLOBAL MOBILE SAFETY & TOUCH OPTIMIZATION
   ========================================================================== */
html {
    -webkit-text-size-adjust: 100%;
    -moz-text-size-adjust: 100%;
    text-size-adjust: 100%;
    box-sizing: border-box;
}

*, *::before, *::after {
    box-sizing: inherit;
}

body {
    overflow-x: hidden !important;
    width: 100% !important;
    max-width: 100vw !important;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

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

/* Prevent iOS auto-zoom on input focus by ensuring minimum 16px font size on mobile */
@media screen and (max-width: 768px) {
    input[type="text"],
    input[type="password"],
    input[type="email"],
    input[type="number"],
    input[type="tel"],
    input[type="date"],
    input[type="datetime-local"],
    input[type="search"],
    select,
    textarea {
        font-size: 16px !important;
        max-width: 100% !important;
    }
}

/* Touch targets */
button,
.btn,
.nav-link,
a.button,
input[type="button"],
input[type="submit"] {
    touch-action: manipulation;
}

/* Universal Table Responsiveness */
.table-responsive,
.grid-container,
.results-table-container,
.table-wrapper,
.candidate-table-wrap,
.table-wrap {
    width: 100% !important;
    max-width: 100% !important;
    overflow-x: auto !important;
    -webkit-overflow-scrolling: touch !important;
    margin-bottom: 1rem;
    position: relative;
}

.table-responsive table,
.results-table-container table,
.grid-container table {
    width: 100% !important;
    min-width: 600px;
}

@media screen and (max-width: 576px) {
    .table-responsive table,
    .results-table-container table,
    .grid-container table {
        font-size: 13px !important;
    }
    
    .table-responsive th,
    .table-responsive td,
    .results-table-container th,
    .results-table-container td {
        padding: 8px 10px !important;
        white-space: nowrap;
    }
}

/* ==========================================================================
   2. ADMIN MASTER MOBILE LAYOUT & SIDEBAR DRAWER
   ========================================================================== */

/* Mobile Hamburger Toggle Button */
.mobile-sidebar-toggle,
.mobile-student-toggle {
    display: none;
    align-items: center;
    justify-content: center;
    width: 42px;
    height: 42px;
    min-width: 42px;
    background: #ffffff;
    border: 1px solid #e2e8f0;
    border-radius: 10px;
    color: #1e3a8a;
    font-size: 22px;
    cursor: pointer;
    box-shadow: 0 2px 5px rgba(0,0,0,0.06);
    transition: all 0.2s ease;
    padding: 0;
    flex-shrink: 0;
}

.mobile-sidebar-toggle:hover,
.mobile-student-toggle:hover {
    background: #f1f5f9;
    color: #2563eb;
    transform: translateY(-1px);
}

/* Backdrop for Mobile Sidebar */
.admin-sidebar-backdrop,
.student-sidebar-backdrop {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background: rgba(15, 23, 42, 0.6);
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
    z-index: 9998;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.3s ease, visibility 0.3s ease;
}

.admin-sidebar-backdrop.active,
.student-sidebar-backdrop.active {
    opacity: 1;
    visibility: visible;
}

/* Admin Responsive Breakpoints */
@media screen and (max-width: 992px) {
    .mobile-sidebar-toggle {
        display: flex !important;
    }

    .layout {
        position: relative !important;
        width: 100% !important;
        height: auto !important;
        min-height: 100vh !important;
        display: block !important;
        overflow-x: hidden !important;
    }

    body {
        overflow-y: auto !important;
        overflow-x: hidden !important;
    }

    /* Transform Admin Sidebar into an Offcanvas Drawer */
    .layout > .sidebar,
    .sidebar {
        position: fixed !important;
        top: 0 !important;
        left: 0 !important;
        bottom: 0 !important;
        width: 280px !important;
        min-width: 280px !important;
        max-width: 85vw !important;
        height: 100vh !important;
        z-index: 9999 !important;
        transform: translateX(-100%) !important;
        transition: transform 0.32s cubic-bezier(0.16, 1, 0.3, 1) !important;
        box-shadow: 10px 0 35px rgba(0, 0, 0, 0.25) !important;
    }

    .layout > .sidebar.mobile-open,
    .sidebar.mobile-open {
        transform: translateX(0) !important;
    }

    .sidebar-header {
        display: flex !important;
        align-items: center !important;
        justify-content: space-between !important;
        padding: 22px 20px !important;
    }

    .sidebar-header h2 {
        font-size: 20px !important;
    }

    .sidebar-close-btn {
        display: flex !important;
        align-items: center;
        justify-content: center;
        width: 34px;
        height: 34px;
        background: rgba(255, 255, 255, 0.15);
        border: none;
        border-radius: 8px;
        color: #ffffff;
        font-size: 18px;
        cursor: pointer;
    }

    .nav {
        padding: 14px 12px !important;
    }

    .nav a {
        font-size: 14px !important;
        padding: 12px 14px !important;
        justify-content: flex-start !important;
    }

    .nav .icon {
        margin-right: 10px !important;
    }

    .nav a span,
    .user-name,
    .user-role {
        display: block !important;
    }

    .main-area {
        width: 100% !important;
        min-width: 100% !important;
        height: auto !important;
        min-height: 100vh !important;
        overflow: visible !important;
    }

    .top-header {
        height: 70px !important;
        min-height: 70px !important;
        padding: 0 16px !important;
        gap: 10px !important;
    }

    .header-left {
        gap: 10px !important;
        min-width: 0 !important;
        flex: 1 !important;
    }

    .header-logo {
        width: 40px !important;
        height: 40px !important;
        min-width: 40px !important;
    }

    .header-title h1 {
        font-size: 16px !important;
        white-space: nowrap !important;
        overflow: hidden !important;
        text-overflow: ellipsis !important;
        max-width: 260px !important;
    }

    .header-title span {
        font-size: 9.5px !important;
        padding: 2px 6px !important;
    }

    .header-right {
        gap: 8px !important;
    }

    .admin-info {
        display: none !important;
    }

    .admin-icon {
        width: 40px !important;
        height: 40px !important;
    }

    .profile-arrow {
        display: none !important;
    }

    .header-logout {
        height: 36px !important;
        padding: 0 12px !important;
        font-size: 12px !important;
    }

    .header-logout span {
        display: inline !important;
    }

    .content {
        padding: 16px 12px !important;
        overflow: visible !important;
        height: auto !important;
        min-height: calc(100vh - 70px) !important;
    }
}

@media screen and (max-width: 480px) {
    .header-title h1 {
        font-size: 14px !important;
        max-width: 140px !important;
    }

    .header-title span {
        display: none !important;
    }

    .header-logout span {
        display: none !important;
    }

    .header-logout {
        width: 36px !important;
        min-width: 36px !important;
        padding: 0 !important;
        border-radius: 50% !important;
    }

    .profile-menu {
        right: -10px !important;
        width: 210px !important;
    }

    .content {
        padding: 12px 8px !important;
    }
}

/* ==========================================================================
   3. STUDENT MASTER MOBILE LAYOUT & RESPONSIVENESS
   ========================================================================== */
@media screen and (max-width: 992px) {
    .mobile-student-toggle {
        display: inline-flex !important;
        align-items: center !important;
        justify-content: center !important;
        width: 40px !important;
        height: 40px !important;
        min-width: 40px !important;
        background: #ffffff !important;
        border: 1.5px solid #e2e8f0 !important;
        border-radius: 10px !important;
        color: #1e3a8a !important;
        font-size: 22px !important;
        cursor: pointer !important;
        pointer-events: auto !important;
        z-index: 100 !important;
        padding: 0 !important;
        flex-shrink: 0 !important;
        box-shadow: 0 2px 6px rgba(15, 23, 42, 0.08) !important;
    }

    .layout {
        display: block !important;
        position: relative !important;
        width: 100% !important;
        max-width: 100vw !important;
        min-height: 100vh !important;
        overflow-x: hidden !important;
    }

    /* Transform Student Sidebar into an Offcanvas Drawer on Mobile */
    .layout > .sidebar,
    .sidebar,
    body.result-mode .sidebar,
    body:has(#pnlResult) .sidebar,
    body:has(#pnlResults) .sidebar,
    body:has(.result-card) .sidebar,
    body:has(.practice-test-results) .sidebar,
    body.exam-finished .sidebar {
        position: fixed !important;
        top: 0 !important;
        left: 0 !important;
        bottom: 0 !important;
        width: 280px !important;
        min-width: 280px !important;
        max-width: 85vw !important;
        height: 100vh !important;
        z-index: 99999 !important;
        transform: translateX(-100%) !important;
        transition: transform 0.32s cubic-bezier(0.16, 1, 0.3, 1) !important;
        padding: 24px 18px !important;
        overflow-y: auto !important;
        box-shadow: 10px 0 35px rgba(0, 0, 0, 0.3) !important;
    }

    .layout > .sidebar.mobile-open,
    .sidebar.mobile-open,
    body.result-mode .sidebar.mobile-open,
    body:has(#pnlResult) .sidebar.mobile-open,
    body:has(#pnlResults) .sidebar.mobile-open,
    body:has(.result-card) .sidebar.mobile-open,
    body:has(.practice-test-results) .sidebar.mobile-open,
    body.exam-finished .sidebar.mobile-open {
        transform: translateX(0) !important;
    }

    .sidebar-close-btn {
        display: flex !important;
        align-items: center !important;
        justify-content: center !important;
        width: 34px !important;
        height: 34px !important;
        background: rgba(255, 255, 255, 0.18) !important;
        border: none !important;
        border-radius: 8px !important;
        color: #ffffff !important;
        font-size: 18px !important;
        cursor: pointer !important;
    }

    .sidebar a {
        display: flex !important;
        width: 100% !important;
        margin: 0 0 8px 0 !important;
        padding: 13px 16px !important;
        font-size: 15px !important;
    }

    /* Fix Content Offset on Mobile - Never shift to the right */
    .layout > .content,
    .content,
    body.result-mode .content,
    body:has(#pnlResult) .content,
    body:has(#pnlResults) .content,
    body:has(.result-card) .content,
    body:has(.practice-test-results) .content,
    body.exam-finished .content {
        margin-left: 0 !important;
        width: 100% !important;
        min-width: 100% !important;
        max-width: 100vw !important;
        padding: 0 !important;
        box-sizing: border-box !important;
    }

    .top-bar {
        min-height: 64px !important;
        height: auto !important;
        padding: 8px 12px !important;
        gap: 8px !important;
        width: 100% !important;
        box-sizing: border-box !important;
    }

    .header-left {
        gap: 8px !important;
        flex: 1 !important;
        min-width: 0 !important;
    }

    .header-logo {
        width: 38px !important;
        height: 38px !important;
        min-width: 38px !important;
        border-radius: 8px !important;
    }

    .header-title-main {
        font-size: 14px !important;
        white-space: nowrap !important;
        overflow: hidden !important;
        text-overflow: ellipsis !important;
        max-width: 160px !important;
        display: block !important;
    }

    .header-title-sub {
        font-size: 10.5px !important;
    }

    .header-right {
        gap: 8px !important;
        flex-shrink: 0 !important;
    }

    .student-avatar {
        width: 36px !important;
        height: 36px !important;
        font-size: 15px !important;
    }

    .student-name,
    .student-name-text {
        display: none !important;
    }

    .logout-btn {
        min-height: 34px !important;
        height: 34px !important;
        padding: 0 10px !important;
        font-size: 12px !important;
    }

    .page-content {
        padding: 12px 8px !important;
        width: 100% !important;
        box-sizing: border-box !important;
    }
}

@media screen and (max-width: 480px) {
    .header-title-main {
        font-size: 13px !important;
        max-width: 120px !important;
    }

    .header-title-sub {
        display: none !important;
    }

    .top-bar {
        padding: 6px 8px !important;
        gap: 6px !important;
    }

    .header-left {
        gap: 6px !important;
    }

    .logout-btn {
        padding: 0 8px !important;
        font-size: 11px !important;
    }

    .page-content {
        padding: 8px 4px !important;
    }
}

/* ==========================================================================
   4. DASHBOARD & STATS GRIDS RESPONSIVENESS
   ========================================================================== */
@media screen and (max-width: 992px) {
    .stat-cards-grid,
    .dashboard-stats,
    .metrics-grid,
    .stats-row {
        grid-template-columns: repeat(2, minmax(0, 1fr)) !important;
        gap: 14px !important;
    }

    .overview-stats {
        grid-template-columns: repeat(2, minmax(0, 1fr)) !important;
        gap: 12px !important;
    }
}

@media screen and (max-width: 576px) {
    .stat-cards-grid,
    .dashboard-stats,
    .metrics-grid,
    .stats-row,
    .overview-stats {
        grid-template-columns: 1fr !important;
        gap: 10px !important;
    }

    .stat-card,
    .metric-card,
    .stat {
        padding: 14px !important;
        min-height: auto !important;
    }
}

/* ==========================================================================
   5. EXAM & PRACTICE TEST CARDS RESPONSIVENESS
   ========================================================================== */
.exams-grid,
.test-cards-grid,
.practice-grid,
.exam-list-grid {
    display: grid !important;
    grid-template-columns: repeat(auto-fill, minmax(min(100%, 320px), 1fr)) !important;
    gap: 18px !important;
}

@media screen and (max-width: 600px) {
    .exams-grid,
    .test-cards-grid,
    .practice-grid,
    .exam-list-grid {
        grid-template-columns: 1fr !important;
        gap: 14px !important;
    }

    .exam-card,
    .test-card {
        padding: 16px !important;
    }

    .exam-card-header h3,
    .test-card-header h3 {
        font-size: 1.2rem !important;
    }
}

/* ==========================================================================
   6. EXAM TAKING INTERFACE (TakeExam.aspx & TakePracticeExam.aspx)
   ========================================================================== */
@media screen and (max-width: 768px) {
    .take-exam,
    .take-practice-test {
        padding: 8px !important;
        max-width: 100% !important;
    }

    .exam-header {
        padding: 14px 12px !important;
        border-radius: 12px !important;
        margin-bottom: 12px !important;
    }

    .exam-title {
        flex-direction: row !important;
        flex-wrap: wrap !important;
        justify-content: space-between !important;
        align-items: center !important;
        gap: 8px !important;
    }

    .exam-title h2 {
        font-size: 1.25rem !important;
        line-height: 1.3 !important;
    }

    .timer {
        font-size: 0.95rem !important;
        padding: 5px 10px !important;
    }

    .question-container {
        padding: 14px 12px !important;
        border-radius: 14px !important;
    }

    .question-header {
        flex-direction: row !important;
        justify-content: space-between !important;
        align-items: center !important;
        gap: 8px !important;
    }

    .question-text {
        font-size: 1.05rem !important;
        line-height: 1.45 !important;
        padding: 12px 10px !important;
    }

    /* Radio and Checkbox Option Cards for touch screens */
    .option-item,
    .option-label {
        padding: 12px 14px !important;
        min-height: 48px !important;
        display: flex !important;
        align-items: center !important;
        gap: 12px !important;
        border-radius: 10px !important;
        margin-bottom: 10px !important;
    }

    .option-item input[type="radio"],
    .option-label input[type="radio"] {
        width: 20px !important;
        height: 20px !important;
        min-width: 20px !important;
        margin: 0 !important;
    }

    .option-text {
        font-size: 0.95rem !important;
        line-height: 1.35 !important;
        word-break: break-word !important;
    }

    /* Question Navigator Palette */
    .question-navigation {
        display: grid !important;
        grid-template-columns: repeat(auto-fill, minmax(36px, 1fr)) !important;
        gap: 6px !important;
        padding: 10px 6px !important;
    }

    .nav-btn,
    .question-btn {
        width: 36px !important;
        height: 36px !important;
        font-size: 13px !important;
        border-radius: 8px !important;
        padding: 0 !important;
        display: flex !important;
        align-items: center !important;
        justify-content: center !important;
    }

    /* Action Buttons in Exam */
    .exam-controls,
    .exam-bottom-bar {
        display: flex !important;
        flex-direction: column-reverse !important;
        gap: 10px !important;
        margin-top: 16px !important;
    }

    .exam-actions {
        display: grid !important;
        grid-template-columns: 1fr 1fr !important;
        grid-template-rows: auto auto auto !important;
        gap: 10px 12px !important;
        width: 100% !important;
        margin-top: 14px !important;
        padding-top: 14px !important;
        border-top: 1px solid #e2e8f0 !important;
        box-sizing: border-box !important;
    }

    .exam-actions .action-left,
    .exam-actions .action-right {
        display: contents !important;
    }

    .exam-actions .btn-prev {
        grid-column: 1 / 2 !important;
        grid-row: 1 !important;
        width: 100% !important;
        min-height: 44px !important;
        height: 44px !important;
        padding: 8px 16px !important;
        font-size: 14px !important;
        font-weight: 750 !important;
        border-radius: 11px !important;
        background: #f1f5f9 !important;
        color: #1e293b !important;
        border: 1.5px solid #cbd5e1 !important;
        display: inline-flex !important;
        align-items: center !important;
        justify-content: center !important;
        box-shadow: 0 2px 5px rgba(15, 23, 42, 0.05) !important;
    }

    .exam-actions .btn-prev.disabled,
    .exam-actions .btn-prev[disabled] {
        opacity: 0.45 !important;
        cursor: not-allowed !important;
        background: #f8fafc !important;
        border-color: #e2e8f0 !important;
        color: #94a3b8 !important;
    }

    .exam-actions .btn-next {
        grid-column: 2 / 3 !important;
        grid-row: 1 !important;
        width: 100% !important;
        min-height: 44px !important;
        height: 44px !important;
        padding: 8px 16px !important;
        font-size: 14px !important;
        font-weight: 750 !important;
        border-radius: 11px !important;
        background: linear-gradient(135deg, #2563eb, #1d4ed8) !important;
        color: #ffffff !important;
        border: none !important;
        display: inline-flex !important;
        align-items: center !important;
        justify-content: center !important;
        box-shadow: 0 4px 12px rgba(37, 99, 235, 0.28) !important;
    }

    .exam-actions .btn-submit {
        grid-column: 1 / -1 !important;
        grid-row: 2 !important;
        width: 100% !important;
        min-height: 46px !important;
        height: 46px !important;
        padding: 10px 18px !important;
        font-size: 15px !important;
        font-weight: 800 !important;
        border-radius: 11px !important;
        background: linear-gradient(135deg, #16a34a, #15803d) !important;
        color: #ffffff !important;
        border: none !important;
        display: inline-flex !important;
        align-items: center !important;
        justify-content: center !important;
        box-shadow: 0 5px 16px rgba(22, 163, 74, 0.32) !important;
        letter-spacing: 0.2px !important;
    }

    .exam-actions .btn-cancel {
        grid-column: 1 / -1 !important;
        grid-row: 3 !important;
        width: 100% !important;
        min-height: 36px !important;
        height: 36px !important;
        padding: 6px 14px !important;
        font-size: 12px !important;
        font-weight: 700 !important;
        border-radius: 9px !important;
        background: #fff5f5 !important;
        color: #dc2626 !important;
        border: 1px solid #fecaca !important;
        display: inline-flex !important;
        align-items: center !important;
        justify-content: center !important;
    }

    .exam-controls button,
    .exam-controls .btn {
        width: 100% !important;
        min-height: 44px !important;
        font-size: 14px !important;
        justify-content: center !important;
    }

    /* Modals & Dialogs on Mobile */
    .exam-modal-card,
    .modal-dialog,
    .confirm-dialog {
        width: min(94vw, 480px) !important;
        max-width: 94vw !important;
        margin: 10px auto !important;
        padding: 20px 16px !important;
    }
}

/* ==========================================================================
   7. FORM FILTERS, SEARCH BARS & ACTION TOOLBARS
   ========================================================================== */
@media screen and (max-width: 768px) {
    .filter-bar,
    .search-filter-wrap,
    .toolbar-actions,
    .action-row,
    .form-row,
    .controls-wrapper {
        display: flex !important;
        flex-direction: column !important;
        align-items: stretch !important;
        gap: 10px !important;
        width: 100% !important;
    }

    .filter-bar input,
    .filter-bar select,
    .filter-bar button,
    .search-filter-wrap input,
    .search-filter-wrap select,
    .search-filter-wrap button {
        width: 100% !important;
        min-width: 100% !important;
    }

    .btn-group,
    .button-group {
        display: flex !important;
        flex-direction: column !important;
        width: 100% !important;
        gap: 8px !important;
    }

    .btn-group .btn,
    .button-group .btn {
        border-radius: 8px !important;
        width: 100% !important;
    }
}

/* ==========================================================================
   8. PUBLIC PAGES (Home, Courses, Training, Exams, Error, 404, Join)
   ========================================================================== */
@media screen and (max-width: 768px) {
    .hero-section,
    .home-hero {
        padding: 40px 16px !important;
        text-align: center !important;
    }

    .hero-title,
    .home-hero h1 {
        font-size: 1.85rem !important;
        line-height: 1.25 !important;
    }

    .hero-subtitle {
        font-size: 1rem !important;
    }

    .courses-grid,
    .training-grid,
    .features-grid {
        grid-template-columns: 1fr !important;
        gap: 16px !important;
    }

    .join-card {
        width: 100% !important;
        max-width: 100% !important;
        border-radius: 16px !important;
    }

    .footer-main {
        display: flex !important;
        flex-direction: column !important;
        gap: 28px !important;
    }
}

/* ==========================================================================
   9. CERTIFICATE VIEW RESPONSIVENESS (Certificate.aspx)
   ========================================================================== */
@media screen and (max-width: 768px) {
    body.certificate-body,
    .certificate-page-body {
        padding: 12px 6px !important;
    }

    .certificate-container {
        width: 100% !important;
        max-width: 100% !important;
        padding: 16px 12px !important;
        overflow-x: auto !important;
    }

    .certificate {
        padding: 20px 14px !important;
        min-width: 300px !important;
    }

    .certificate h1 {
        font-size: 1.4rem !important;
    }

    .certificate h2 {
        font-size: 1.15rem !important;
    }

    .download-area {
        width: 100% !important;
        margin-bottom: 16px !important;
    }

    .download-btn {
        width: 100% !important;
        padding: 12px 20px !important;
        font-size: 14px !important;
    }
}

/* ==========================================================================
   10. ACTIVE EXAM & PRACTICE EXAM (TakeExam.aspx & TakePracticeExam.aspx)
   ========================================================================== */
@media screen and (max-width: 992px) {
    body:has(.exam-panel),
    body:has(.practice-exam-page) {
        overflow-y: auto !important;
        height: auto !important;
    }

    .practice-exam-page {
        height: auto !important;
        min-height: calc(100vh - 72px) !important;
        max-height: none !important;
        overflow: visible !important;
        padding: 10px 10px 90px 10px !important;
    }

    .exam-panel {
        height: auto !important;
        min-height: auto !important;
        display: flex !important;
        flex-direction: column !important;
        gap: 12px !important;
    }

    .question-card {
        height: auto !important;
        min-height: auto !important;
        max-height: none !important;
        overflow: visible !important;
        padding: 16px 14px 20px 14px !important;
        margin-bottom: 24px !important;
    }
}
