/* ==========================================================================
   GLOBAL RESPONSIVE & ZOOM ACCESSIBILITY CORRECTIONS
   Sistem Pengurusan Aduan Bersepadu Kolej Vokasional Kudat
   Preserves 100% existing design, colors, fonts, and branding.
   ========================================================================== */

/* --------------------------------------------------------------------------
   0. Global Box-Sizing & Viewport Boundary Protections
   -------------------------------------------------------------------------- */
html {
    box-sizing: border-box;
    -webkit-text-size-adjust: 100%;
    scroll-behavior: smooth;
}

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

html, body {
    max-width: 100% !important;
    overflow-x: hidden !important;
    position: relative;
}

/* iOS Safe Area Inset Support (iPhone X/XR/11/12/13/14/15/16) */
body {
    padding-bottom: env(safe-area-inset-bottom, 0px);
}

/* Prevent iOS Safari auto-zoom on form focus when font < 16px */
@media screen and (max-width: 768px) {
    input[type="text"],
    input[type="password"],
    input[type="email"],
    input[type="number"],
    input[type="tel"],
    input[type="search"],
    select,
    textarea {
        font-size: 16px !important;
    }
}

/* --------------------------------------------------------------------------
   1. Responsive Modal Layout (Header + Scrollable Body + Fixed Footer)
   -------------------------------------------------------------------------- */
.modal-overlay {
    position: fixed !important;
    top: 0 !important;
    left: 0 !important;
    width: 100% !important;
    height: 100% !important;
    background: rgba(10, 36, 99, 0.55) !important;
    backdrop-filter: blur(4px) !important;
    display: none;
    align-items: center !important;
    justify-content: center !important;
    z-index: 2000 !important;
    padding: clamp(10px, 3vw, 24px) !important;
    box-sizing: border-box !important;
}

.modal-overlay.active {
    display: flex !important;
}

.modal-content {
    background: #ffffff !important;
    border-radius: clamp(12px, 2vw, 20px) !important;
    width: 100% !important;
    max-width: min(95vw, 560px) !important;
    max-height: 90dvh !important;
    box-shadow: 0 15px 50px rgba(0,0,0,0.18) !important;
    display: flex !important;
    flex-direction: column !important;
    overflow: hidden !important;
    position: relative !important;
    box-sizing: border-box !important;
}

.modal-content > form {
    display: flex !important;
    flex-direction: column !important;
    flex: 1 !important;
    min-height: 0 !important;
    height: 100% !important;
    margin: 0 !important;
    box-sizing: border-box !important;
}

.modal-header {
    padding: clamp(14px, 2vw, 22px) clamp(16px, 3vw, 28px) !important;
    border-bottom: 1px solid #EDF2F7 !important;
    display: flex !important;
    justify-content: space-between !important;
    align-items: center !important;
    flex-shrink: 0 !important;
    background: #ffffff !important;
    box-sizing: border-box !important;
}

.modal-body {
    padding: clamp(16px, 3vw, 28px) !important;
    overflow-y: auto !important;
    overflow-x: hidden !important;
    flex: 1 !important;
    min-height: 0 !important;
    -webkit-overflow-scrolling: touch !important;
    box-sizing: border-box !important;
}

.modal-footer {
    padding: clamp(12px, 2vw, 18px) clamp(16px, 3vw, 28px) !important;
    border-top: 1px solid #EDF2F7 !important;
    background: #F8FAFC !important;
    display: flex !important;
    justify-content: flex-end !important;
    gap: 12px !important;
    flex-wrap: wrap !important;
    flex-shrink: 0 !important;
    box-sizing: border-box !important;
}

.modal-footer .btn, 
.modal-footer button {
    min-height: clamp(38px, 8vw, 44px) !important;
    display: inline-flex !important;
    align-items: center !important;
    justify-content: center !important;
    white-space: nowrap !important;
    padding: 8px 18px !important;
    border-radius: 8px !important;
}

/* --------------------------------------------------------------------------
   2. Form Grids & Responsive Fields
   -------------------------------------------------------------------------- */
.form-row {
    display: grid !important;
    grid-template-columns: 1fr 1fr !important;
    gap: 16px !important;
}

@media (max-width: 576px) {
    .form-row {
        grid-template-columns: 1fr !important;
        gap: 12px !important;
    }
    .modal-content {
        max-height: 94dvh !important;
        width: 96% !important;
    }
    .modal-footer {
        justify-content: stretch !important;
    }
    .modal-footer .btn,
    .modal-footer button {
        flex: 1 1 auto !important;
        width: 100% !important;
    }
}

/* --------------------------------------------------------------------------
   3. Triangle Shortcut Navigation Layout (index.php) on Phone Breakdown
   -------------------------------------------------------------------------- */
@media (max-width: 576px) {
    .hero-content .action-row {
        display: grid !important;
        grid-template-columns: repeat(2, auto) !important;
        justify-content: center !important;
        align-items: center !important;
        gap: 12px 16px !important;
        margin-top: 24px !important;
    }
    
    .hero-content .action-btn.primary {
        grid-column: 1 / span 2 !important;
        order: -1 !important;
        justify-self: center !important;
        width: clamp(110px, 32vw, 180px) !important;
        height: clamp(100px, 30vw, 155px) !important;
    }
    
    .hero-content .action-btn:not(.primary) {
        width: clamp(100px, 30vw, 160px) !important;
        height: clamp(90px, 28vw, 140px) !important;
    }
}

/* --------------------------------------------------------------------------
   4. High Zoom Level & Short Screen Protections
   -------------------------------------------------------------------------- */
@media (max-height: 500px) {
    .modal-content {
        max-height: 95dvh !important;
    }
    .modal-header, .modal-footer {
        padding: clamp(8px, 1.5vw, 12px) clamp(12px, 2vw, 16px) !important;
    }
    .modal-body {
        padding: clamp(12px, 2vw, 16px) !important;
    }
}

/* --------------------------------------------------------------------------
   5. Tables & Horizontal Scrolling Protections
   -------------------------------------------------------------------------- */
.table-responsive {
    width: 100% !important;
    overflow-x: auto !important;
    -webkit-overflow-scrolling: touch !important;
    box-sizing: border-box !important;
    position: relative;
}

/* Ensure table contents don't squish unreadably on mobile */
.table-responsive table {
    min-width: 600px;
}

@media (max-width: 768px) {
    .table-section {
        border-radius: 12px !important;
        margin-bottom: 20px !important;
    }
    .table-header {
        padding: 14px 16px !important;
    }
    th, td {
        padding: 10px 14px !important;
        font-size: 0.85rem !important;
    }
}

/* --------------------------------------------------------------------------
   6. Stats, Cards & Badges Wrapping Protections
   -------------------------------------------------------------------------- */
.stat-card {
    min-width: 0 !important;
    flex-wrap: wrap !important;
    gap: 12px !important;
}

.stat-info {
    min-width: 0 !important;
}

.stat-value {
    word-break: break-word !important;
    overflow-wrap: break-word !important;
}

@media (max-width: 768px) {
    .stats-grid {
        grid-template-columns: repeat(2, 1fr) !important;
        gap: 14px !important;
    }
}

@media (max-width: 480px) {
    .stats-grid {
        grid-template-columns: 1fr !important;
        gap: 12px !important;
    }
}

/* --------------------------------------------------------------------------
   7. Top Navigation & Header Responsiveness
   -------------------------------------------------------------------------- */
@media (max-width: 768px) {
    .header {
        padding: 12px 16px !important;
        gap: 10px !important;
    }
    .header-nav {
        width: 100% !important;
        justify-content: space-between !important;
    }
    .nav-tabs {
        padding: 0 12px !important;
        overflow-x: auto !important;
        -webkit-overflow-scrolling: touch !important;
    }
    .nav-tab {
        padding: 12px 14px !important;
        font-size: 0.82rem !important;
    }
    .container {
        padding: 16px 12px !important;
    }
    .control-panel {
        padding: 14px 16px !important;
        flex-direction: column !important;
        align-items: stretch !important;
    }
    .search-group, .panel-actions {
        width: 100% !important;
    }
    .search-group input, 
    .search-group select,
    .search-group .input-control {
        width: 100% !important;
        flex: 1 1 auto !important;
    }
}

/* --------------------------------------------------------------------------
   8. Responsive Buttons & Touch Targets (Min 44px for Accessibility)
   -------------------------------------------------------------------------- */
@media (max-width: 576px) {
    .btn, button.btn, a.btn {
        min-height: 44px !important;
    }
    .action-buttons {
        gap: 8px !important;
    }
    .btn-xs {
        min-height: 36px !important;
        padding: 8px 12px !important;
    }
}

/* --------------------------------------------------------------------------
   9. Media & Image Display Constraints
   -------------------------------------------------------------------------- */
img {
    max-width: 100%;
    height: auto;
}
.profile-circle img,
.logo-area img,
.stat-icon img {
    height: auto;
}
