/**
 * Mobile Responsive Enhancements
 * Additional mobile-specific styles for optimal mobile experience
 * Include this file after other stylesheets
 */

/* ===== VIEWPORT AND BASE MOBILE STYLES ===== */

/* Prevent text size adjustment on orientation change */
html {
    -webkit-text-size-adjust: 100%;
    -ms-text-size-adjust: 100%;
    text-size-adjust: 100%;
}

/* Smooth scrolling for mobile */
html {
    scroll-behavior: smooth;
}

/* Prevent horizontal scroll */
body {
    overflow-x: hidden;
    width: 100%;
}

/* ===== MOBILE TYPOGRAPHY ===== */

@media (max-width: 768px) {
    /* Adjust base font size for readability */
    html {
        font-size: 14px;
    }

    /* Improve text readability */
    body {
        -webkit-font-smoothing: antialiased;
        -moz-osx-font-smoothing: grayscale;
    }

    /* Adjust heading sizes */
    h1 { font-size: 1.75rem; }
    h2 { font-size: 1.5rem; }
    h3 { font-size: 1.25rem; }
    h4 { font-size: 1.1rem; }
    h5 { font-size: 1rem; }
    h6 { font-size: 0.9rem; }

    /* Improve paragraph spacing */
    p {
        line-height: 1.6;
        margin-bottom: 1rem;
    }
}

/* ===== MOBILE NAVIGATION ===== */

@media (max-width: 768px) {
    /* Hamburger menu improvements */
    .menubutton {
        padding: 0.75rem;
        min-width: 44px;
        min-height: 44px;
        display: flex;
        align-items: center;
        justify-content: center;
    }

    /* Menu items */
    #menu {
        width: 100%;
        max-width: 300px;
        right: 0;
        top: 5rem;
        border-radius: 0 0 8px 8px;
    }

    #menuitems h3 {
        padding: 1rem;
        font-size: 1rem;
    }
}

/* ===== MOBILE FORMS ===== */

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

    /* Full-width form controls */
    .form-control,
    .form-select {
        width: 100%;
        max-width: 100%;
    }

    /* Stack form rows */
    .form-row {
        flex-direction: column;
        gap: 1rem;
    }

    /* Form buttons */
    .form-actions button {
        width: 100%;
        margin: 0.5rem 0;
        padding: 0.75rem 1rem;
        font-size: 1rem;
    }

    /* Form labels */
    .form-label {
        font-size: 0.9rem;
        margin-bottom: 0.5rem;
    }
}

/* ===== MOBILE TABLES ===== */

@media (max-width: 768px) {
    /* Horizontal scroll for tables */
    .table-responsive {
        display: block;
        width: 100%;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }

    /* Compact table styling */
    table {
        font-size: 0.85rem;
    }

    th, td {
        padding: 0.5rem 0.25rem;
        white-space: nowrap;
    }

    /* Hide less important columns on mobile */
    .hide-mobile {
        display: none !important;
    }

    /* Show mobile-only content */
    .show-mobile {
        display: block !important;
    }
}

/* ===== MOBILE BUTTONS ===== */

@media (max-width: 768px) {
    /* Touch-friendly button sizing */
    button,
    .btn,
    input[type="button"],
    input[type="submit"] {
        min-height: 44px;
        padding: 0.75rem 1rem;
        font-size: 0.95rem;
    }

    /* Full-width buttons on mobile */
    .btn-block-mobile {
        width: 100%;
        display: block;
    }

    /* Button groups */
    .btn-group {
        display: flex;
        flex-direction: column;
        gap: 0.5rem;
    }

    .btn-group button {
        width: 100%;
    }
}

/* ===== MOBILE MODALS ===== */

@media (max-width: 768px) {
    /* Full-screen modals on mobile */
    .modal-dialog {
        margin: 0;
        max-width: 100%;
        height: 100vh;
    }

    .modal-content {
        height: 100vh;
        border-radius: 0;
        border: none;
    }

    .modal-header {
        padding: 1rem;
        border-radius: 0;
    }

    .modal-title {
        font-size: 1.25rem;
    }

    .modal-body {
        padding: 1rem;
        overflow-y: auto;
        flex: 1;
    }

    .modal-footer {
        padding: 1rem;
        flex-direction: column;
        gap: 0.5rem;
    }

    .modal-footer button {
        width: 100%;
    }
}

/* ===== MOBILE CARDS ===== */

@media (max-width: 768px) {
    .card {
        margin-bottom: 1rem;
        border-radius: 8px;
    }

    .card-header,
    .card-body,
    .card-footer {
        padding: 1rem;
    }

    /* Card grids */
    .card-grid {
        grid-template-columns: 1fr;
        gap: 1rem;
    }
}

/* ===== MOBILE SPACING ===== */

@media (max-width: 768px) {
    /* Reduce spacing on mobile */
    .container,
    .container-fluid {
        padding-left: 1rem;
        padding-right: 1rem;
    }

    /* Section spacing */
    section {
        padding: 1rem 0;
    }

    /* Margin utilities */
    .m-mobile-0 { margin: 0 !important; }
    .mt-mobile-0 { margin-top: 0 !important; }
    .mb-mobile-0 { margin-bottom: 0 !important; }
    .ml-mobile-0 { margin-left: 0 !important; }
    .mr-mobile-0 { margin-right: 0 !important; }

    .p-mobile-0 { padding: 0 !important; }
    .pt-mobile-0 { padding-top: 0 !important; }
    .pb-mobile-0 { padding-bottom: 0 !important; }
    .pl-mobile-0 { padding-left: 0 !important; }
    .pr-mobile-0 { padding-right: 0 !important; }
}

/* ===== MOBILE IMAGES ===== */

@media (max-width: 768px) {
    img {
        max-width: 100%;
        height: auto;
    }

    /* Responsive images */
    .img-responsive {
        width: 100%;
        height: auto;
    }
}

/* ===== MOBILE UTILITIES ===== */

@media (max-width: 768px) {
    /* Text alignment */
    .text-mobile-center { text-align: center !important; }
    .text-mobile-left { text-align: left !important; }
    .text-mobile-right { text-align: right !important; }

    /* Display utilities */
    .d-mobile-none { display: none !important; }
    .d-mobile-block { display: block !important; }
    .d-mobile-flex { display: flex !important; }

    /* Flex utilities */
    .flex-mobile-column { flex-direction: column !important; }
    .flex-mobile-row { flex-direction: row !important; }
}

/* ===== SMALL MOBILE DEVICES ===== */

@media (max-width: 480px) {
    html {
        font-size: 13px;
    }

    /* Tighter spacing */
    .container,
    .container-fluid {
        padding-left: 0.75rem;
        padding-right: 0.75rem;
    }

    /* Smaller buttons */
    button,
    .btn {
        padding: 0.625rem 0.875rem;
        font-size: 0.875rem;
    }

    /* Compact cards */
    .card-header,
    .card-body,
    .card-footer {
        padding: 0.75rem;
    }

    /* Smaller modals */
    .modal-header,
    .modal-body,
    .modal-footer {
        padding: 0.75rem;
    }
}

/* ===== LANDSCAPE ORIENTATION ===== */

@media (max-width: 896px) and (orientation: landscape) {
    /* Reduce vertical spacing in landscape */
    #header {
        padding: 0.5rem 1rem;
    }

    #footer {
        padding: 0.5rem 1rem;
    }

    /* Compact modals in landscape */
    .modal-header,
    .modal-footer {
        padding: 0.75rem 1rem;
    }

    .modal-body {
        padding: 1rem;
    }

    /* Scrollable content */
    .modal-body,
    .card-body {
        max-height: 60vh;
        overflow-y: auto;
    }
}

/* ===== TOUCH DEVICE OPTIMIZATIONS ===== */

@media (hover: none) and (pointer: coarse) {
    /* Remove hover effects */
    *:hover {
        transition: none;
    }

    /* Larger touch targets */
    a,
    button,
    input[type="button"],
    input[type="submit"],
    .btn,
    .clickable {
        min-height: 44px;
        min-width: 44px;
    }

    /* Checkbox and radio sizing */
    input[type="checkbox"],
    input[type="radio"] {
        width: 24px;
        height: 24px;
    }

    /* Active states for touch feedback */
    button:active,
    .btn:active,
    a:active {
        opacity: 0.7;
        transform: scale(0.98);
    }

    /* Prevent text selection on buttons */
    button,
    .btn {
        -webkit-user-select: none;
        user-select: none;
        -webkit-tap-highlight-color: transparent;
    }
}

/* ===== ACCESSIBILITY ON MOBILE ===== */

@media (max-width: 768px) {
    /* Focus indicators */
    *:focus {
        outline: 2px solid var(--primary-blue, #1f5f7a);
        outline-offset: 2px;
    }

    /* Skip to content link */
    .skip-to-content {
        position: absolute;
        top: -40px;
        left: 0;
        background: var(--primary-blue, #1f5f7a);
        color: white;
        padding: 8px;
        text-decoration: none;
        z-index: 100;
    }

    .skip-to-content:focus {
        top: 0;
    }
}

/* ===== PERFORMANCE OPTIMIZATIONS ===== */

/* Reduce animations on mobile for better performance */
@media (max-width: 768px) {
    * {
        animation-duration: 0.2s !important;
        transition-duration: 0.2s !important;
    }
}

/* Reduce motion for users who prefer it */
@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
        scroll-behavior: auto !important;
    }
}

/* ===== PRINT STYLES ===== */

@media print {
    /* Hide non-essential elements */
    #header,
    #footer,
    #menu,
    .btn,
    button,
    .no-print {
        display: none !important;
    }

    /* Full width for content */
    #mainbody {
        width: 100%;
        margin: 0;
        padding: 0;
    }

    /* Optimize tables for print */
    table {
        page-break-inside: avoid;
    }

    /* Ensure links are visible */
    a[href]:after {
        content: " (" attr(href) ")";
    }
}

/* ===== DARK MODE SUPPORT ON MOBILE ===== */

@media (max-width: 768px) and (prefers-color-scheme: dark) {
    /* Adjust colors for dark mode */
    body {
        background-color: #1a1a1a;
        color: #e0e0e0;
    }

    .card,
    .modal-content {
        background-color: #2d2d2d;
        color: #e0e0e0;
    }

    input,
    select,
    textarea {
        background-color: #3a3a3a;
        color: #e0e0e0;
        border-color: #555;
    }
}
