/* ==========================================================================
   GLOBAL_STYLE.CSS - HARDENED MOBILE-BROWSER-FIRST DESIGN ENGINE
   ========================================================================== */

html {
    background-color: #0b0f14;
    min-height: 100%;
}

body {
    margin: 0;
    padding: 0;
    min-height: 100%;
    color: #e4e6eb;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    position: relative;
    background: transparent;
}

/* 🚀 STABLE MODERN STEP-AND-REPEAT BACKGROUND VECTOR ENGINE */
body::before {
    content: "";
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    width: 100vw;
    height: 100vh;
    z-index: -2;
    background-image: url('happyscannerbg.png');
    background-repeat: repeat; 
    background-position: center top;
    background-size: 640px auto;
    opacity: 0.12; 
    pointer-events: none;
}

/* 🛡️ HIGHER PANEL ISOLATION FOR EXTENDED MOBILE CONTRAST */
.panel { 
    background: rgba(20, 26, 35, 0.92) !important;
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border: 1px solid #242f41; 
    border-radius: 14px; 
    padding: 20px; 
    margin-bottom: 24px; 
    height: fit-content; 
}

/* 📱 SOLIDIFIED FLUID VIEWPORT CONTAINER FOR MOBILE BROWSERS FIRST */
.container, .app-wrapper, .import-wrapper, .ticket-manager-container, #index-container { 
    width: 100%;
    max-width: 1200px;
    margin: 0 auto; 
    display: flex; 
    flex-direction: column;
    box-sizing: border-box;
    padding-top: calc(20px + env(safe-area-inset-top)) !important;
    padding-bottom: calc(115px + env(safe-area-inset-bottom)) !important; 
    padding-left: calc(16px + env(safe-area-inset-left)) !important;
    padding-right: calc(16px + env(safe-area-inset-right)) !important;
}

/* 🎯 CAMERA VIEWFINDER SCALING RULES FOR INDEX.PHP */
#interactive, 
.scanner-container, 
div[style*="background-color:"][style*="height:"] {
    max-height: 40vh !important; 
    min-height: 240px !important;
    border-radius: 20px;
    overflow: hidden;
}

/* Synchronized Header blocks */
.admin-header, header { 
    border-bottom: 1px solid #242f41; 
    padding-bottom: 14px; 
    margin-bottom: 18px; 
    display: flex; 
    flex-direction: column;
    gap: 6px;
    flex-shrink: 0;
}
.admin-header h1, header h1 { color: #FFE400; margin: 0; font-size: 1.8rem; font-weight: 900; }
.admin-header p, header p { margin: 0; color: #8a94a6; font-size: 0.85rem; line-height: 1.4; }

@media(min-width: 768px) {
    .admin-header, header { flex-direction: row; justify-content: space-between; align-items: center; }
    .admin-header h1, header h1 { font-size: 2.2rem; }
}

/* Hardened Form Controls: Fixed at 16px to prevent iOS auto-zoom compression bugs */
.input-ctrl, .input-field, .select-field, select, textarea, .input-text, .search-input { 
    background: #0b0f14; 
    border: 1px solid #242f41; 
    border-radius: 10px; 
    height: 50px; 
    padding: 0 14px; 
    color: #fff; 
    font-size: 1rem; 
    width: 100%; 
    box-sizing: border-box; 
    outline: none; 
    font-family: inherit;
    transition: border-color 0.2s ease;
}
.input-ctrl:focus, .input-field:focus, .select-field:focus, select:focus, textarea:focus, .input-text:focus, .search-input:focus { 
    border-color: #FFE400; 
}

textarea { height: 100px; padding: 12px; resize: vertical; }
h2 { margin-top: 0; font-size: 1.25rem; border-left: 4px solid #FFE400; padding-left: 10px; color: #fff; margin-bottom: 16px; }

/* Grid Matrix Layout modules */
.mapping-grid, .layout-grid, .form-row { display: grid; grid-template-columns: 1fr; gap: 16px; background: #0b0f14; padding: 16px; border-radius: 12px; margin-bottom: 20px; }
@media(min-width: 580px) { .mapping-grid, .form-row { grid-template-columns: 1fr 1fr; } }
@media(min-width: 850px) { .layout-grid { grid-template-columns: 1fr 1.8fr; background: transparent; padding: 0; } }

/* Universal Buttons styling */
.btn-execute, .btn-submit, .btn-login, .btn-scan { 
    background: linear-gradient(135deg, #FFE400 0%, #ccb700 100%); 
    color: #0b0f14; 
    border: none; 
    height: 52px; 
    border-radius: 12px; 
    font-size: 1rem; 
    font-weight: bold; 
    width: 100%; 
    cursor: pointer; 
    box-shadow: 0 4px 15px rgba(255, 228, 0, 0.15); 
    display: flex;
    align-items: center;
    justify-content: center;
    font-family: inherit;
}

/* Responsive Data Tables formatting */
table { width: 100%; border-collapse: collapse; text-align: left; font-size: 0.95rem; }
th { background: #1c2431; color: #8a94a6; font-weight: 600; padding: 12px; }
td { padding: 14px 12px; border-bottom: 1px solid #1c2431; color: #d1d5db; vertical-align: top; }

@media (max-width: 767px) { 
    table, thead, tbody, th, td, tr { display: block; width: 100%; } 
    thead { display: none; } 
    tr { background: #0b0f14; border: 1px solid #242f41; border-radius: 12px; padding: 12px; margin-bottom: 12px; } 
    td { border: none; padding: 6px 0; display: flex; justify-content: space-between; align-items: center; } 
    td::before { content: attr(data-label); font-weight: 600; color: #8a94a6; font-size: 0.8rem; text-transform: uppercase; } 
}

/* 📱 RELIABLE BOTTOM NAVIGATION DECK FOR THE FLUID MOBILE FLOW */
.bottom-nav-bar { 
    position: fixed; 
    bottom: 0; 
    left: 0; 
    right: 0; 
    height: calc(76px + env(safe-area-inset-bottom)); 
    background: rgba(20, 26, 35, 0.98); 
    border-top: 1px solid #1f2937; 
    display: flex; 
    align-items: center; 
    justify-content: space-around; 
    padding: 0 10px calc(12px + env(safe-area-inset-bottom)) 10px; 
    z-index: 99995; 
    backdrop-filter: blur(20px); 
    -webkit-backdrop-filter: blur(20px); 
    box-sizing: border-box;
}
.nav-item { display: flex; flex-direction: column; align-items: center; justify-content: center; flex: 1; height: 100%; text-decoration: none; color: #8a94a6; background: transparent; border: none; cursor: pointer; padding: 0; margin: 0; min-width: 0; }
.nav-icon { font-size: 1.3rem; margin-bottom: 2px; display: block; text-align: center; }
.nav-label { font-size: 0.65rem; font-weight: 700; text-transform: uppercase; letter-spacing: 0.2px; display: block; text-align: center; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; width: 100%; }
.nav-item.active-admin-tab, .nav-item.active-scan-tab { color: #FFE400; }
.nav-item.logout-tab { color: #f87171; }

.gate-badge {
    background: rgba(255, 228, 0, 0.12);
    color: #FFE400;
    border: 1px solid rgba(255, 228, 0, 0.3);
    padding: 3px 8px;
    border-radius: 5px;
    font-size: 0.8rem;
    font-weight: bold;
    display: inline-flex;
    align-items: center;
    gap: 4px;
}

.alert {
    padding: 16px 20px;
    border-radius: 12px;
    margin-bottom: 24px;
    font-weight: 700;
    font-size: 0.95rem;
    display: flex;
    align-items: center;
    gap: 10px;
    box-sizing: border-box;
    width: 100%;
    animation: slideDownFade 0.4s ease forwards;
    line-height: 1.5;
}

.alert-success { background: rgba(16, 185, 129, 0.15); color: #34d399; border: 1px solid rgba(16, 185, 129, 0.3); box-shadow: 0 4px 15px rgba(16, 185, 129, 0.05); }
.alert-error { background: rgba(239, 68, 68, 0.15); color: #f87171; border: 1px solid rgba(239, 68, 68, 0.3); box-shadow: 0 4px 15px rgba(239, 68, 68, 0.05); }

@keyframes slideDownFade {
    from { opacity: 0; transform: translateY(-15px); }
    to { opacity: 1; transform: translateY(0); }
}

/* 🎯 BRAND NEW: INTELLIGENT KEYBOARD TRIGGER HOOK MATRIX */
/* When device vertical room drops beneath 460px (like when a mobile keyboard pops open) */
@media (max-height: 460px) {
    /* 1. Hide the fixed navigation menu cleanly out of sight */
    .bottom-nav-bar {
        display: none !important;
    }
    
    /* 2. Expand the Chat Overlay card to claim 100% of maximum viewport dimensions */
    .nav-chat-modal-card {
        height: 100vh !important;
        margin-bottom: 0 !important;
        border-radius: 0 !important;
        border: none !important;
        position: fixed !important;
        top: 0 !important;
        left: 0 !important;
        right: 0 !important;
        bottom: 0 !important;
        max-width: none !important;
    }
    
    /* 3. Give the inner message list context max heights to fit perfectly next to the open keyboard */
    #nav-chat-scroll-viewport {
        max-height: calc(100vh - 110px) !important;
    }
}