/**
 * Mobile & Tablet Responsive Styles for Retail Solutions
 * Apply this to all 1_*.html pages for consistent mobile experience
 * QUALITY CONTROLLED - Does not override existing functionality
 */

/* ==============================================
   UNIVERSAL LOGOUT BUTTON - CENTERED
   ============================================== */
.rs-logout-btn {
    position: fixed;
    top: 20px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 9999;
    background: linear-gradient(135deg, #dc3545 0%, #c82333 100%);
    color: white !important;
    border: none;
    padding: 12px 24px;
    border-radius: 8px;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    box-shadow: 0 4px 12px rgba(220, 53, 69, 0.3);
    transition: all 0.3s ease;
    display: flex;
    align-items: center;
    gap: 8px;
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    text-decoration: none;
}

.rs-logout-btn:hover {
    background: linear-gradient(135deg, #c82333 0%, #bd2130 100%);
    transform: translateX(-50%) translateY(-2px);
    box-shadow: 0 6px 16px rgba(220, 53, 69, 0.4);
    color: white !important;
}

.rs-logout-btn:active {
    transform: translateX(-50%) translateY(0);
    box-shadow: 0 2px 8px rgba(220, 53, 69, 0.3);
}

.rs-logout-btn i {
    font-size: 16px;
}

.rs-logout-text {
    display: inline;
}

.rs-logout-icon-only {
    display: none;
}

/* Mobile: Show X icon only */
@media (max-width: 768px) {
    .rs-logout-btn {
        padding: 12px;
        border-radius: 50%;
        width: 48px;
        height: 48px;
        top: 15px;
        left: 50%;
        transform: translateX(-50%);
        justify-content: center;
    }
    
    .rs-logout-btn:hover {
        transform: translateX(-50%) translateY(-2px);
    }
    
    .rs-logout-btn:active {
        transform: translateX(-50%) translateY(0);
    }
    
    .rs-logout-text {
        display: none;
    }
    
    .rs-logout-icon-only {
        display: inline;
        font-size: 20px;
    }
    
    .rs-logout-btn i.fa-sign-out-alt {
        display: none;
    }
}

/* Small mobile */
@media (max-width: 480px) {
    .rs-logout-btn {
        width: 44px;
        height: 44px;
        padding: 10px;
        top: 10px;
        left: 50%;
        transform: translateX(-50%);
    }
    
    .rs-logout-btn:hover {
        transform: translateX(-50%) translateY(-2px);
    }
    
    .rs-logout-btn:active {
        transform: translateX(-50%) translateY(0);
    }
    
    .rs-logout-icon-only {
        font-size: 18px;
    }
}

/* ==============================================
   MOBILE FIRST - BASE RESPONSIVE RULES
   ============================================== */

/* Ensure viewport is set correctly */
@viewport {
    width: device-width;
    zoom: 1.0;
}

/* Prevent horizontal scroll on mobile */
body {
    overflow-x: hidden;
    -webkit-overflow-scrolling: touch;
}

/* Make all containers fluid on mobile */
.container, .container-fluid {
    padding-left: 15px;
    padding-right: 15px;
}

/* Responsive images */
img {
    max-width: 100%;
    height: auto;
}

/* ==============================================
   TABLET (768px - 1024px)
   ============================================== */
@media (max-width: 1024px) {
    /* Reduce padding on larger elements */
    .dashboard-card,
    .mie-bg-container,
    .container {
        padding: 1.5rem !important;
    }
    
    /* Stack grids more aggressively */
    .menu-grid {
        grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)) !important;
        gap: 1rem !important;
    }
    
    /* Make tables scrollable */
    .table-responsive {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }
    
    table {
        min-width: 600px;
    }
    
    /* Adjust form grids for tablet */
    .form-grid {
        grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)) !important;
    }
}

/* ==============================================
   MOBILE (max 768px)
   ============================================== */
@media (max-width: 768px) {
    /* Body adjustments */
    body {
        font-size: 14px;
        padding: 0;
    }
    
    /* Dashboard card - full width on mobile */
    .dashboard-card {
        border-radius: 0 !important;
        padding: 1.5rem !important;
        box-shadow: none !important;
        max-width: 100% !important;
        margin: 0 !important;
    }
    
    /* Menu grids - single column on mobile */
    .menu-grid {
        grid-template-columns: 1fr !important;
        gap: 1rem !important;
    }
    
    /* Menu items - reduce padding */
    .menu-item {
        padding: 1.5rem 1rem !important;
    }
    
    .menu-item i {
        font-size: 2rem !important;
    }
    
    .menu-item h3 {
        font-size: 1rem !important;
    }
    
    /* Logo section */
    .logo-section img,
    .header-logo-section img {
        max-width: 100px !important;
    }
    
    .logo-section h1,
    .header-logo-section h1 {
        font-size: 1.5rem !important;
    }
    
    /* Page headers */
    .page-header {
        padding: 1rem !important;
        flex-direction: column !important;
        text-align: center !important;
    }
    
    .page-title {
        font-size: 1.25rem !important;
        margin-top: 0.5rem !important;
    }
    
    /* Containers */
    .mie-bg-container,
    .sms-container,
    .container {
        padding: 1rem !important;
        margin: 0 !important;
    }
    
    /* Form sections */
    .form-section {
        padding: 1rem !important;
        margin-bottom: 1rem !important;
    }
    
    .form-section h3 {
        font-size: 1.1rem !important;
    }
    
    /* Form grids - stack on mobile */
    .form-grid {
        grid-template-columns: 1fr !important;
        gap: 1rem !important;
    }
    
    /* Stats grids */
    .stats-grid {
        grid-template-columns: 1fr !important;
        gap: 1rem !important;
    }
    
    .stat-card {
        padding: 1rem !important;
    }
    
    .stat-card .value {
        font-size: 2rem !important;
    }
    
    /* Tabs - make scrollable horizontally */
    .tabs {
        overflow-x: auto;
        overflow-y: hidden;
        -webkit-overflow-scrolling: touch;
        flex-wrap: nowrap !important;
        gap: 0.5rem !important;
        padding-bottom: 0.5rem;
    }
    
    .tab-btn {
        white-space: nowrap;
        padding: 0.75rem 1rem !important;
        font-size: 0.9rem !important;
        min-width: auto;
    }
    
    /* Tables - make scrollable */
    .table-responsive {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        margin-bottom: 1rem;
    }
    
    table {
        font-size: 0.85rem !important;
        min-width: 600px;
    }
    
    table th,
    table td {
        padding: 0.5rem !important;
        white-space: nowrap;
    }
    
    /* Buttons */
    .btn {
        padding: 0.5rem 1rem !important;
        font-size: 0.9rem !important;
    }
    
    .btn-group {
        flex-wrap: wrap !important;
    }
    
    /* Modals */
    .modal-dialog {
        margin: 0.5rem !important;
        max-width: calc(100% - 1rem) !important;
    }
    
    .modal-body {
        padding: 1rem !important;
    }
    
    /* Cards */
    .card {
        margin-bottom: 1rem !important;
    }
    
    .card-body {
        padding: 1rem !important;
    }
    
    /* Header sections with status */
    .form-section {
        flex-direction: column !important;
        text-align: left !important;
    }
    
    #connectionStatus {
        margin-top: 1rem !important;
        text-align: left !important;
    }
    
    /* SMS Portal specific */
    header {
        padding: 1rem !important;
        flex-direction: column !important;
        gap: 0.5rem !important;
    }
    
    .header-stats {
        width: 100%;
        justify-content: space-around !important;
        flex-wrap: wrap !important;
    }
    
    .stat-display {
        text-align: center !important;
    }
    
    /* Recipient selection */
    .recipient-section {
        margin-bottom: 1rem !important;
    }
    
    /* Select2 dropdowns */
    .select2-container {
        width: 100% !important;
    }
    
    /* Charts */
    canvas {
        max-height: 250px !important;
    }
}

/* ==============================================
   SMALL MOBILE (max 480px)
   ============================================== */
@media (max-width: 480px) {
    /* Even smaller text */
    body {
        font-size: 13px;
    }
    
    /* Minimal padding */
    .dashboard-card,
    .mie-bg-container,
    .container,
    .form-section {
        padding: 0.75rem !important;
    }
    
    /* Menu items - compact */
    .menu-item {
        padding: 1rem !important;
    }
    
    .menu-item i {
        font-size: 1.75rem !important;
        margin-bottom: 0.5rem !important;
    }
    
    .menu-item h3 {
        font-size: 0.95rem !important;
    }
    
    .menu-item p {
        font-size: 0.75rem !important;
    }
    
    /* Logo */
    .logo-section img,
    .header-logo-section img {
        max-width: 80px !important;
    }
    
    .logo-section h1,
    .header-logo-section h1 {
        font-size: 1.25rem !important;
    }
    
    /* Stat cards - more compact */
    .stat-card .value {
        font-size: 1.75rem !important;
    }
    
    .stat-card h3 {
        font-size: 0.75rem !important;
    }
    
    /* Tables */
    table {
        font-size: 0.75rem !important;
    }
    
    table th,
    table td {
        padding: 0.25rem !important;
    }
    
    /* Buttons - stack vertically */
    .btn-group {
        display: flex;
        flex-direction: column !important;
    }
    
    .btn-group .btn {
        width: 100% !important;
        margin-bottom: 0.5rem !important;
    }
    
    /* Tabs - smaller */
    .tab-btn {
        padding: 0.5rem 0.75rem !important;
        font-size: 0.85rem !important;
    }
}

/* ==============================================
   LANDSCAPE MOBILE (orientation)
   ============================================== */
@media (max-height: 500px) and (orientation: landscape) {
    /* Reduce vertical spacing in landscape */
    .dashboard-card {
        padding: 1rem !important;
    }
    
    .logo-section {
        margin-bottom: 1rem !important;
    }
    
    .menu-grid {
        gap: 0.75rem !important;
    }
    
    .menu-item {
        padding: 1rem 0.75rem !important;
    }
    
    .menu-item i {
        font-size: 1.5rem !important;
        margin-bottom: 0.5rem !important;
    }
}

/* ==============================================
   PRINT STYLES
   ============================================== */
@media print {
    /* Hide navigation and interactive elements */
    .menu-grid,
    .tabs,
    .btn,
    button {
        display: none !important;
    }
    
    /* Optimize for printing */
    body {
        background: white !important;
    }
    
    .dashboard-card,
    .mie-bg-container {
        box-shadow: none !important;
        padding: 0 !important;
    }
}

/* ==============================================
   ACCESSIBILITY ENHANCEMENTS
   ============================================== */

/* Increase tap targets on touch devices */
@media (hover: none) and (pointer: coarse) {
    .btn,
    .menu-item,
    .tab-btn,
    a {
        min-height: 44px;
        min-width: 44px;
    }
    
    /* Larger form inputs */
    input,
    select,
    textarea {
        min-height: 44px !important;
        font-size: 16px !important; /* Prevents zoom on iOS */
    }
}

/* Focus styles for keyboard navigation */
*:focus {
    outline: 2px solid #0056b3;
    outline-offset: 2px;
}

/* Smooth scrolling */
html {
    scroll-behavior: smooth;
}

/* ==============================================
   APP HERO BAR - MOBILE RESPONSIVE
   Handles the injected hero bar from hero-bar-injector.js
   ============================================== */
.app-hero-bar {
    border-radius: 0 !important;
    width: 100% !important;
    box-sizing: border-box !important;
}

.app-hero-brand,
.app-hero-page,
.app-hero-logout {
    min-width: 0;
}

@media (max-width: 768px) {
    .app-hero-bar {
        display: flex !important;
        flex-wrap: wrap !important;
        align-items: center !important;
        justify-content: space-between !important;
        padding: 10px 12px !important;
        gap: 8px !important;
        margin-bottom: 0 !important;
    }

    .app-hero-brand {
        flex: 0 0 auto !important;
    }

    .app-hero-brand span {
        display: none;
    }

    .app-hero-brand img {
        width: 24px !important;
        height: 24px !important;
    }

    .app-hero-page {
        order: 3 !important;
        flex: 1 0 100% !important;
        font-size: 0.82rem !important;
        text-align: left !important;
        white-space: normal !important;
        line-height: 1.3 !important;
        padding-top: 2px;
        max-width: 100% !important;
    }

    .app-hero-logout {
        flex: 0 0 auto !important;
        align-self: flex-start !important;
        padding: 6px 10px !important;
        font-size: 0.72rem !important;
        line-height: 1.1 !important;
        white-space: nowrap !important;
        max-width: 100% !important;
    }
}

@media (max-width: 480px) {
    .app-hero-bar {
        padding: 9px 10px !important;
    }

    .app-hero-page {
        font-size: 0.76rem !important;
    }

    .app-hero-logout {
        padding: 6px 9px !important;
        font-size: 0.68rem !important;
        border-radius: 7px !important;
    }
}

/* ==============================================
   TEST PAGES - MOBILE RESPONSIVE
   ============================================== */
@media (max-width: 768px) {
    /* Options - remove left margin that causes overflow */
    .options {
        margin-left: 0 !important;
        margin-top: 10px;
    }

    /* Question blocks */
    .question-block {
        padding: 14px !important;
        margin-bottom: 20px !important;
    }

    /* Form rows - stack on mobile */
    .form-row {
        grid-template-columns: 1fr !important;
    }

    /* Results modal */
    .results-content {
        padding: 20px 14px !important;
        border-radius: 12px;
    }

    .score-display {
        font-size: 52px !important;
    }

    .result-status {
        font-size: 20px !important;
    }

    /* Submit button - full width */
    .btn-submit {
        width: 100% !important;
        padding: 14px 20px !important;
    }

    .btn-close {
        width: 100% !important;
    }

    /* Answer key grid - single column */
    .answer-key-grid {
        grid-template-columns: 1fr !important;
    }
}

@media (max-width: 480px) {
    .question-text {
        font-size: 13px !important;
    }

    .option label {
        font-size: 13px !important;
    }

    .question-number {
        width: 26px !important;
        height: 26px !important;
        font-size: 12px !important;
    }

    .score-display {
        font-size: 44px !important;
    }
}
