/**
 * Mobile UX Improvements
 * Global mobile-first CSS for touch targets, forms, modals, and safe areas
 */

/* ============================================
   Safe Areas (iPhone notch, etc.)
   ============================================ */
@supports (padding: env(safe-area-inset-top)) {
    body {
        padding-top: env(safe-area-inset-top);
        padding-bottom: env(safe-area-inset-bottom);
        padding-left: env(safe-area-inset-left);
        padding-right: env(safe-area-inset-right);
    }
}

/* ============================================
   Touch Action & Behavior
   ============================================ */
@media (pointer: coarse) {

    /* Prevent text selection on interactive elements */
    button,
    a,
    .card,
    .nav-item,
    .tab {
        -webkit-user-select: none;
        user-select: none;
        -webkit-tap-highlight-color: transparent;
    }

    /* Minimum 44x44px touch targets */
    button,
    a,
    input[type="submit"],
    input[type="button"],
    .btn,
    [role="button"],
    select {
        min-height: 44px;
    }

    /* Improve scrolling */
    .scrollable,
    .table-responsive,
    .card-list {
        -webkit-overflow-scrolling: touch;
        overscroll-behavior: contain;
    }

    /* Prevent double-tap zoom on buttons */
    button,
    a {
        touch-action: manipulation;
    }
}

/* ============================================
   Improved Forms on Mobile
   ============================================ */
@media (max-width: 768px) {

    input,
    textarea,
    select {
        font-size: 16px !important;
        /* Prevents iOS zoom on focus */
        border-radius: 12px;
        padding: 14px 16px;
    }

    label {
        font-size: 0.9rem;
        font-weight: 600;
        margin-bottom: 6px;
        display: block;
    }

    .field,
    .form-group {
        margin-bottom: 16px;
    }

    textarea {
        min-height: 100px;
        resize: vertical;
    }

    select {
        -webkit-appearance: none;
        appearance: none;
        background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%2394a3b8' d='M6 8L1 3h10z'/%3E%3C/svg%3E");
        background-repeat: no-repeat;
        background-position: right 14px center;
        padding-right: 36px;
    }
}

/* ============================================
   Full-Screen Modals on Mobile
   ============================================ */
@media (max-width: 768px) {

    .modal,
    .modal-overlay,
    [class*="modal"] {
        border-radius: 0 !important;
    }

    .modal-content,
    [class*="modal-content"],
    [class*="modal-body"] {
        max-height: 90vh;
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
    }
}

/* ============================================
   Table Responsiveness
   ============================================ */
@media (max-width: 768px) {

    .table-responsive,
    table {
        display: block;
        width: 100%;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }

    table {
        min-width: 600px;
    }

    th,
    td {
        white-space: nowrap;
        padding: 10px 12px;
        font-size: 0.85rem;
    }
}

/* ============================================
   Better Typography on Small Screens
   ============================================ */
@media (max-width: 480px) {
    h1 {
        font-size: 1.6rem !important;
        line-height: 1.3;
    }

    h2 {
        font-size: 1.3rem !important;
    }

    h3 {
        font-size: 1.1rem !important;
    }

    p,
    li,
    span {
        font-size: 0.9rem;
        line-height: 1.6;
    }

    /* Improve readability */
    body {
        -webkit-font-smoothing: antialiased;
        -moz-osx-font-smoothing: grayscale;
    }
}

/* ============================================
   Card & Content Spacing
   ============================================ */
@media (max-width: 768px) {

    .card,
    .section-card,
    [class*="-card"] {
        padding: 16px !important;
        border-radius: 16px !important;
        margin-bottom: 12px;
    }

    .container {
        padding-left: 16px;
        padding-right: 16px;
    }
}

/* ============================================
   Bottom Navigation Safe Space
   ============================================ */
@media (max-width: 768px) {
    body {
        padding-bottom: 75px;
        /* Space for bottom nav */
    }

    footer {
        margin-bottom: 70px;
    }
}

/* ============================================
   Admin/Helper Panel Mobile Fixes
   ============================================ */
@media (max-width: 768px) {

    /* Admin sidebar → bottom or collapsed */
    .admin-sidebar,
    .sidebar {
        position: fixed;
        bottom: 0;
        left: 0;
        right: 0;
        top: auto;
        height: auto;
        flex-direction: row;
        overflow-x: auto;
        z-index: 1000;
        padding: 8px;
        gap: 8px;
    }

    .admin-sidebar .nav-item,
    .sidebar .nav-item {
        flex-shrink: 0;
        font-size: 0.75rem;
        padding: 8px 12px;
    }

    .admin-main,
    .main-content {
        margin-left: 0;
        padding-bottom: 80px;
    }

    /* Badge improvements */
    .badge,
    .status-badge,
    [class*="badge"] {
        font-size: 0.7rem;
        padding: 3px 8px;
        border-radius: 8px;
    }
}

/* ============================================
   Portfolio Page Mobile
   ============================================ */
@media (max-width: 768px) {

    /* Gallery grid */
    .gallery-grid {
        grid-template-columns: repeat(2, 1fr) !important;
        gap: 8px !important;
    }

    .gallery-item {
        border-radius: 12px !important;
    }

    /* Profile header stack */
    .profile-header {
        flex-direction: column;
        text-align: center;
        gap: 16px;
    }

    .profile-photo {
        width: 100px !important;
        height: 100px !important;
    }

    /* Stats inline */
    .portfolio-stats {
        flex-wrap: wrap;
        justify-content: center;
        gap: 8px;
    }

    .stat-item {
        flex: 0 0 auto;
    }

    /* Certificate cards */
    .certificates-section .certificate-item {
        padding: 12px !important;
    }
}

/* ============================================
   Smooth Animations Reduction
   ============================================ */
@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;
    }
}

/* ============================================
   Focus Styles for Accessibility
   ============================================ */
:focus-visible {
    outline: 2px solid #8b5cf6;
    outline-offset: 2px;
    border-radius: 4px;
}

button:focus-visible,
a:focus-visible {
    box-shadow: 0 0 0 3px rgba(139, 92, 246, 0.3);
}