/* ==========================================
   MOBILE RESPONSIVE FIXES FOR CHEMWANI
   ========================================== */

/* ==========================================
   1. BASE VIEWPORT & RESET
   ========================================== */
   
* {
    box-sizing: border-box;
}

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

body {
    overflow-x: hidden;
    width: 100%;
}

img {
    max-width: 100%;
    height: auto;
}

/* ==========================================
   2. SIDEBAR & MAIN CONTENT (Dashboard)
   ========================================== */

@media screen and (max-width: 768px) {
    /* Mobile sidebar toggle button */
    .sidebar-toggle {
        display: block !important;
        position: fixed;
        top: 65px;
        left: 10px;
        z-index: 999;
        background: #333;
        color: white;
        border: none;
        padding: 10px 15px;
        border-radius: 5px;
        cursor: pointer;
        font-size: 16px;
    }
    
    /* Make sidebar toggleable on mobile */
    .sidenav {
        width: 0 !important;
        position: fixed;
        z-index: 1000;
        top: 60px;
        left: 0;
        background-color: #111;
        overflow-x: hidden;
        transition: 0.3s;
        padding-top: 20px;
        height: calc(100% - 60px);
    }
    
    .sidenav.active {
        width: 250px !important;
        padding: 20px 10px;
    }
    
    .sidenav a {
        padding: 8px 8px 8px 16px;
        text-decoration: none;
        font-size: 18px;
        color: #818181;
        display: block;
        transition: 0.3s;
        white-space: nowrap;
    }
    
    /* Main content - no margin on mobile */
    .main {
        margin-left: 0 !important;
        padding: 70px 10px 10px 10px !important;
        width: 100%;
    }
    
    /* Welcome section */
    .main h2 {
        font-size: 1.5rem;
    }
}

@media screen and (min-width: 769px) {
    .sidebar-toggle {
        display: none !important;
    }
    
    .sidenav {
        width: 200px !important;
    }
}

/* ==========================================
   3. CARDS & CONTAINERS
   ========================================== */

@media screen and (max-width: 768px) {
    .card {
        margin: 10px 5px !important;
        max-width: 100% !important;
    }
    
    .card-header {
        font-size: 14px;
        padding: 10px;
    }
    
    .card-body {
        padding: 10px;
    }
    
    .card-title {
        font-size: 16px;
    }
    
    .col-lg-1, .col-lg-2, .col-lg-3, .col-lg-4, 
    .col-lg-5, .col-lg-6, .col-lg-7, .col-lg-8,
    .col-lg-9, .col-lg-10, .col-lg-11, .col-lg-12 {
        width: 100% !important;
        padding: 5px !important;
        flex: 0 0 100%;
        max-width: 100%;
    }
    
    .container {
        padding-left: 10px;
        padding-right: 10px;
        max-width: 100%;
    }
    
    .row {
        margin-left: 0 !important;
        margin-right: 0 !important;
        flex-direction: column;
    }
}

/* ==========================================
   4. QUIZ MODE FIXES
   ========================================== */

@media screen and (max-width: 768px) {
    /* Quiz header */
    div[style*="background:#3D4A5D"] {
        padding: 10px 5px !important;
    }
    
    div[style*="background:#3D4A5D"] h2 {
        font-size: 16px !important;
        text-align: center;
        margin-bottom: 5px;
    }
    
    /* Timer */
    div[style*="float:right"][style*="width:150px"],
    div[style*="float:right; margin-right:10px"] {
        float: none !important;
        width: 100% !important;
        text-align: center;
        margin: 5px 0 !important;
        font-size: 14px !important;
    }
    
    div[style*="float:left"] {
        float: none !important;
        text-align: center;
        width: 100%;
    }
    
    /* Question sidebar - move below questions on mobile */
    .col-lg-3[style*="position: absolute"],
    div[style*="position: absolute"][style*="right: 0.5%"] {
        position: relative !important;
        width: 100% !important;
        right: auto !important;
        top: auto !important;
        height: auto !important;
        margin-top: 20px;
        margin-bottom: 100px;
        border: 1px solid #73AD21 !important;
    }
    
    /* Main quiz area */
    div[style*="margin-left: 1%"],
    div[style*="margin-right: 35%"] {
        margin-left: 5px !important;
        margin-right: 5px !important;
        margin-bottom: 20px !important;
        width: calc(100% - 10px) !important;
    }
    
    /* Bottom button bar */
    div[style*="position:fixed; bottom:0px"] {
        height: auto !important;
        min-height: 60px;
        padding: 8px 5px !important;
        display: flex;
        flex-wrap: wrap;
        justify-content: center;
        gap: 5px;
    }
    
    div[style*="position:fixed; bottom:0px"] button,
    div[style*="position:fixed; bottom:0px"] .btn {
        font-size: 11px !important;
        padding: 6px 10px !important;
        margin: 2px !important;
        flex: 1 1 auto;
        min-width: 70px;
        max-width: 100px;
    }
    
    /* Question number buttons */
    button.btn[style*="background: grey"],
    button.btn[id*="qbtn"] {
        min-width: 35px !important;
        min-height: 35px !important;
        font-size: 12px !important;
        margin: 3px !important;
        padding: 5px !important;
    }
    
    /* Calculator */
    #containment-wrapper {
        width: 100% !important;
        padding: 5px !important;
        position: fixed;
        top: 60px;
        left: 0;
        z-index: 1001;
    }
    
    #draggable {
        width: 100% !important;
        left: 0 !important;
        right: 0 !important;
        top: 0 !important;
        position: relative !important;
    }
    
    #draggable iframe {
        width: 100% !important;
        height: 300px !important;
    }
    
    #draggable .calci,
    .calci {
        width: calc(100% - 20px) !important;
        margin-top: -277px !important;
        margin-left: 10px !important;
        font-size: 12px !important;
        padding: 5px;
    }
    
    /* Calculator link */
    div[style*="position: fixed; right:0px"] {
        position: fixed !important;
        right: 5px !important;
        top: 65px !important;
        z-index: 100;
        background: rgba(255,255,255,0.9);
        padding: 5px;
        border-radius: 5px;
    }
    
    div[style*="position: fixed; right:0px"] img {
        max-width: 25px;
    }
    
    div[style*="position: fixed; right:0px"] a {
        font-size: 12px;
    }
}

/* ==========================================
   5. YEAR PAPERS & QUESTIONS
   ========================================== */

@media screen and (max-width: 768px) {
    /* Question tables */
    table {
        width: 100% !important;
        font-size: 14px;
    }
    
    /* Options table - stack vertically */
    table[style*="width:80%"],
    table[cellpadding="10px"] {
        width: 100% !important;
        margin-left: 0 !important;
        margin-right: 0 !important;
        display: block;
    }
    
    table[style*="width:80%"] tbody,
    table[cellpadding="10px"] tbody {
        display: block;
        width: 100%;
    }
    
    table[style*="width:80%"] tr,
    table[cellpadding="10px"] tr {
        display: block;
        margin-bottom: 5px;
    }
    
    table[style*="width:80%"] td,
    table[cellpadding="10px"] td {
        display: block;
        width: 100% !important;
        padding: 10px !important;
        border-bottom: 1px solid #eee;
        text-align: left !important;
    }
    
    /* Option cells - make clickable area larger */
    .opt, .opt-msq {
        padding: 12px 10px !important;
        display: block;
        width: 100%;
        cursor: pointer;
        background: #f9f9f9;
        margin-bottom: 5px;
        border-radius: 5px;
    }
    
    .opt:active, .opt-msq:active {
        background: #e0e0e0;
    }
    
    /* Buttons */
    .btn {
        font-size: 14px;
        padding: 10px 15px;
        margin: 5px 2px;
        display: inline-block;
    }
    
    .center {
        text-align: center;
    }
    
    /* Collapse cards */
    .collapse .card-body {
        padding: 15px 10px;
        font-size: 14px;
    }
    
    /* Solution images */
    .collapse img,
    div[id*="view_solution"] img {
        max-width: 100% !important;
        height: auto !important;
    }
}

/* ==========================================
   6. NAVBAR RESPONSIVE
   ========================================== */

@media screen and (max-width: 768px) {
    .navbar {
        padding: 0.3rem 0.5rem !important;
    }
    
    .navbar-brand {
        font-size: 1.1rem !important;
    }
    
    .navbar-toggler {
        padding: 0.25rem 0.5rem;
        font-size: 1rem;
    }
    
    .navbar-nav {
        margin-top: 10px;
    }
    
    .nav-item {
        margin-bottom: 5px;
    }
    
    .dropdown-menu {
        max-height: 250px;
        overflow-y: auto;
    }
    
    .form-inline {
        flex-direction: column;
        width: 100%;
        padding: 10px 0;
    }
    
    .form-inline input[type="search"],
    .form-inline .form-control {
        width: 100% !important;
        margin-bottom: 10px;
        font-size: 16px; /* Prevents zoom on iOS */
    }
    
    .form-inline button {
        width: 100%;
    }
    
    /* User dropdown */
    .nav-item.dropdown.my-lg-0 {
        margin-top: 10px;
        border-top: 1px solid #444;
        padding-top: 10px;
    }
}

/* ==========================================
   7. LOGIN & FORMS
   ========================================== */

@media screen and (max-width: 768px) {
    fieldset {
        padding: 15px;
        margin: 10px;
    }
    
    fieldset legend {
        font-size: 1.5rem;
    }
    
    .form-group {
        margin-bottom: 15px;
    }
    
    .form-control {
        font-size: 16px !important; /* Prevents zoom on iOS */
        padding: 12px;
    }
    
    .pappu, .hero-info-butt {
        margin-left: 0 !important;
        margin-right: 0 !important;
        transform: none !important;
        width: 100%;
        max-width: 300px;
        text-align: center;
        padding: 1rem 1.5rem !important;
        font-size: 1rem !important;
        display: inline-block;
    }
    
    /* Alert messages */
    .alert {
        font-size: 14px;
        padding: 10px;
    }
}

/* ==========================================
   8. TABLES & DATA DISPLAY
   ========================================== */

@media screen and (max-width: 768px) {
    /* Analytics/Report tables */
    table[style*="margin-left:auto"],
    table[style*="margin-left: auto"] {
        margin-left: 0 !important;
        margin-right: 0 !important;
        width: 100% !important;
        font-size: 11px;
        display: block;
        overflow-x: auto;
    }
    
    table th, table td {
        padding: 6px 4px !important;
        font-size: 11px;
    }
    
    /* Quiz result table */
    table[style*="border: 1px solid black"] {
        display: block;
        overflow-x: auto;
        white-space: nowrap;
    }
}

/* ==========================================
   9. SCROLLABLE CONTENT
   ========================================== */

@media screen and (max-width: 768px) {
    .scrollable-menu {
        max-height: 200px !important;
    }
    
    div[style*="overflow-y:auto"],
    div[style*="overflow-y: auto"] {
        max-height: 250px;
    }
    
    /* Quiz question list scrollable area */
    div[style*="max-height:60%"] {
        max-height: 150px !important;
    }
}

/* ==========================================
   10. IMAGES & MEDIA
   ========================================== */

@media screen and (max-width: 768px) {
    iframe {
        max-width: 100%;
        width: 100% !important;
    }
    
    /* Feedback iframe */
    iframe[src*="google.com/forms"] {
        width: 100% !important;
        height: 800px !important;
    }
    
    img[src*="calci.png"] {
        max-width: 25px !important;
        height: auto;
    }
}

/* ==========================================
   11. UTILITY CLASSES
   ========================================== */

@media screen and (max-width: 768px) {
    .mobile-hide {
        display: none !important;
    }
    
    .mobile-show {
        display: block !important;
    }
    
    .mobile-full-width {
        width: 100% !important;
    }
    
    .mobile-text-center {
        text-align: center !important;
    }
    
    br + br {
        display: none;
    }
}

/* ==========================================
   12. TYPOGRAPHY ADJUSTMENTS
   ========================================== */

@media screen and (max-width: 768px) {
    h1 {
        font-size: 1.8rem !important;
    }
    
    h2 {
        font-size: 1.5rem !important;
    }
    
    h3 {
        font-size: 1.3rem !important;
    }
    
    h4 {
        font-size: 1.1rem !important;
    }
    
    p, li, td, th {
        font-size: 14px;
    }
}

/* ==========================================
   13. LANDSCAPE MODE FIXES
   ========================================== */

@media screen and (max-width: 768px) and (orientation: landscape) {
    .sidenav {
        height: calc(100vh - 60px);
    }
    
    /* Make bottom bar scrollable in landscape */
    div[style*="position:fixed; bottom:0px"] {
        position: relative !important;
        margin-top: 20px;
    }
}

/* ==========================================
   14. TOUCH IMPROVEMENTS
   ========================================== */

@media screen and (max-width: 768px) {
    /* Larger tap targets */
    a, button, .btn, .nav-link, .dropdown-item {
        min-height: 44px;
        display: inline-flex;
        align-items: center;
    }
    
    .dropdown-item {
        padding: 12px 15px;
    }
}