/**
 * Mobile-First Responsive Design
 * Enhanced mobile experience for Abtex Support App
 */

/* ===================================
   MOBILE-SPECIFIC IMPROVEMENTS
   =================================== */

/* Better touch targets for mobile */
@media (max-width: 768px) {

    /* Base improvements */
    body {
        font-size: 16px;
        /* Prevent zoom on iOS */
        -webkit-text-size-adjust: 100%;
        -webkit-font-smoothing: antialiased;
    }

    /* Container adjustments */
    .container {
        padding: 0 1rem;
    }

    /* Typography - smaller on mobile */
    h1 {
        font-size: 1.75rem;
    }

    h2 {
        font-size: 1.5rem;
    }

    h3 {
        font-size: 1.25rem;
    }

    h4 {
        font-size: 1.125rem;
    }

    h5,
    h6 {
        font-size: 1rem;
    }

    /* Navbar - mobile hamburger style */
    .navbar {
        padding: 0.75rem 0;
    }

    .navbar-content {
        flex-direction: column;
        gap: 1rem;
    }

    .navbar-brand {
        font-size: 1.25rem;
    }

    .navbar-menu {
        flex-direction: row;
        flex-wrap: wrap;
        gap: 0.5rem;
        justify-content: center;
        width: 100%;
    }

    .navbar-menu a {
        padding: 0.5rem 0.75rem;
        font-size: 0.875rem;
    }

    /* Cards - better mobile spacing */
    .card {
        padding: 1rem;
        margin-bottom: 1rem;
    }

    .card-header {
        margin-bottom: 1rem;
    }

    .card-title {
        font-size: 1.125rem;
    }

    /* Buttons - larger touch targets */
    .btn {
        padding: 0.875rem 1.5rem;
        font-size: 1rem;
        min-height: 44px;
        /* iOS recommended touch target */
        width: 100%;
        justify-content: center;
    }

    .btn-sm {
        padding: 0.5rem 1rem;
        min-height: 38px;
        font-size: 0.875rem;
    }

    .btn-lg {
        padding: 1rem 2rem;
        min-height: 52px;
        font-size: 1.125rem;
    }

    /* Button groups - stack on mobile */
    .btn-group {
        display: flex;
        flex-direction: column;
        gap: 0.75rem;
    }

    /* Forms - larger inputs for mobile */
    .form-input,
    .form-select,
    .form-textarea {
        padding: 0.875rem;
        font-size: 16px;
        /* Prevent zoom on iOS */
        min-height: 44px;
    }

    .form-select {
        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='%23cbd5e1' d='M6 9L1 4h10z'/%3E%3C/svg%3E");
        background-repeat: no-repeat;
        background-position: right 1rem center;
        background-size: 12px;
        padding-right: 3rem;
    }

    .form-textarea {
        min-height: 120px;
    }

    .form-group {
        margin-bottom: 1.25rem;
    }

    .form-label {
        font-size: 0.875rem;
        margin-bottom: 0.5rem;
    }

    /* Grid - single column on mobile */
    .grid {
        gap: 1rem;
    }

    .grid-2,
    .grid-3,
    .grid-4 {
        grid-template-columns: 1fr;
    }

    /* Tables - responsive scroll */
    .table-container {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        margin: 0 -1rem;
        padding: 0 1rem;
    }

    .table {
        font-size: 0.875rem;
    }

    .table th,
    .table td {
        padding: 0.75rem 0.5rem;
        white-space: nowrap;
    }

    /* Mobile table - card style */
    .table-mobile {
        display: block;
    }

    .table-mobile thead {
        display: none;
    }

    .table-mobile tbody,
    .table-mobile tr {
        display: block;
    }

    .table-mobile tr {
        margin-bottom: 1rem;
        background: var(--glass-bg);
        border-radius: var(--radius-lg);
        padding: 1rem;
    }

    .table-mobile td {
        display: flex;
        justify-content: space-between;
        padding: 0.5rem 0;
        border-bottom: 1px solid var(--border-color);
    }

    .table-mobile td:last-child {
        border-bottom: none;
    }

    .table-mobile td::before {
        content: attr(data-label);
        font-weight: 600;
        color: var(--text-primary);
    }

    /* Modal - full screen on mobile */
    .modal-content {
        width: 100%;
        height: 100%;
        max-height: 100vh;
        max-width: 100vw;
        border-radius: 0;
        margin: 0;
    }

    /* Stats - smaller on mobile */
    .stat-number {
        font-size: 2rem;
    }

    .stat-label {
        font-size: 0.75rem;
    }

    /* Image gallery - 2 columns on mobile */
    .image-gallery {
        grid-template-columns: repeat(2, 1fr);
        gap: 0.75rem;
    }

    .image-gallery img {
        height: 120px;
    }

    /* Timeline - narrower on mobile */
    .timeline {
        padding-left: 1.5rem;
    }

    .timeline-item::before {
        left: -23px;
    }

    /* Badges - smaller on mobile */
    .badge {
        padding: 0.375rem 0.625rem;
        font-size: 0.625rem;
    }

    /* Spacing adjustments */
    .p-xl {
        padding: 1rem;
    }

    .p-lg {
        padding: 0.875rem;
    }

    .mt-xl,
    .mb-xl {
        margin-top: 1.5rem;
        margin-bottom: 1.5rem;
    }

    .mt-lg,
    .mb-lg {
        margin-top: 1rem;
        margin-bottom: 1rem;
    }

    /* Flex utilities - stack on mobile */
    .flex-mobile-col {
        flex-direction: column;
    }

    .gap-mobile-sm {
        gap: 0.5rem;
    }
}

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

/* Hamburger menu for very small screens */
@media (max-width: 480px) {
    .navbar-menu {
        display: none;
        position: absolute;
        top: 100%;
        left: 0;
        right: 0;
        background: var(--bg-secondary);
        border-top: 1px solid var(--border-color);
        flex-direction: column;
        padding: 1rem;
        box-shadow: var(--shadow-lg);
    }

    .navbar-menu.active {
        display: flex;
    }

    .navbar-menu a {
        width: 100%;
        text-align: left;
        padding: 0.75rem 1rem;
    }

    /* Hamburger button */
    .navbar-toggle {
        display: block;
        background: none;
        border: none;
        color: var(--text-primary);
        font-size: 1.5rem;
        cursor: pointer;
        padding: 0.5rem;
        position: absolute;
        right: 1rem;
        top: 50%;
        transform: translateY(-50%);
    }
}

@media (min-width: 481px) {
    .navbar-toggle {
        display: none;
    }
}

/* ===================================
   MOBILE-SPECIFIC COMPONENTS
   =================================== */

/* Bottom navigation for mobile */
.mobile-bottom-nav {
    display: none;
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    background: var(--bg-secondary);
    border-top: 1px solid var(--border-color);
    padding: 0.5rem 0;
    z-index: 1000;
    box-shadow: 0 -4px 6px rgba(0, 0, 0, 0.1);
}

@media (max-width: 768px) {
    .mobile-bottom-nav {
        display: flex;
        justify-content: space-around;
    }

    /* Add padding to body to account for bottom nav */
    body.has-bottom-nav {
        padding-bottom: 70px;
    }
}

.mobile-bottom-nav a {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.25rem;
    color: var(--text-muted);
    font-size: 0.75rem;
    text-decoration: none;
    padding: 0.5rem;
    transition: color var(--transition-fast);
}

.mobile-bottom-nav a.active,
.mobile-bottom-nav a:hover {
    color: var(--primary-color);
}

.mobile-bottom-nav-icon {
    font-size: 1.5rem;
}

/* Floating action button */
.fab {
    position: fixed;
    bottom: 80px;
    right: 1rem;
    width: 56px;
    height: 56px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--primary-color), var(--primary-dark));
    color: white;
    border: none;
    box-shadow: 0 4px 12px rgba(99, 102, 241, 0.4);
    font-size: 1.5rem;
    cursor: pointer;
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 999;
    transition: all var(--transition-fast);
}

@media (max-width: 768px) {
    .fab {
        display: flex;
    }
}

.fab:active {
    transform: scale(0.95);
}

/* Pull to refresh indicator */
.pull-to-refresh {
    display: none;
    position: fixed;
    top: 0;
    left: 50%;
    transform: translateX(-50%);
    background: var(--bg-secondary);
    padding: 0.5rem 1rem;
    border-radius: 0 0 var(--radius-lg) var(--radius-lg);
    box-shadow: var(--shadow-md);
    z-index: 1001;
}

/* Swipe gestures helper */
.swipeable {
    touch-action: pan-y;
    user-select: none;
}

/* ===================================
   MOBILE OPTIMIZATIONS
   =================================== */

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

/* Better link tapping */
a {
    -webkit-tap-highlight-color: rgba(99, 102, 241, 0.2);
}

/* Smooth momentum scrolling */
.modal-content,
.table-container {
    -webkit-overflow-scrolling: touch;
}

/* Hide scrollbars on mobile */
@media (max-width: 768px) {
    ::-webkit-scrollbar {
        display: none;
    }

    * {
        -ms-overflow-style: none;
        scrollbar-width: none;
    }
}

/* Safe area insets for notched devices */
@supports (padding: max(0px)) {
    body {
        padding-left: max(0px, env(safe-area-inset-left));
        padding-right: max(0px, env(safe-area-inset-right));
    }

    .mobile-bottom-nav {
        padding-bottom: max(0.5rem, env(safe-area-inset-bottom));
    }

    .navbar {
        padding-top: max(0.75rem, env(safe-area-inset-top));
    }
}

/* ===================================
   TABLET OPTIMIZATIONS (481px - 768px)
   =================================== */

@media (min-width: 481px) and (max-width: 768px) {
    .grid-2 {
        grid-template-columns: repeat(2, 1fr);
    }

    .grid-3 {
        grid-template-columns: repeat(2, 1fr);
    }

    .btn-group {
        flex-direction: row;
        flex-wrap: wrap;
    }

    .btn-group .btn {
        flex: 1;
        min-width: 150px;
    }
}

/* ===================================
   LANDSCAPE MODE ADJUSTMENTS
   =================================== */

@media (max-width: 768px) and (orientation: landscape) {
    .navbar {
        padding: 0.5rem 0;
    }

    .navbar-brand {
        font-size: 1rem;
    }

    .card {
        padding: 0.875rem;
    }

    .modal-content {
        height: auto;
        max-height: 90vh;
    }
}

/* ===================================
   ACCESSIBILITY IMPROVEMENTS
   =================================== */

/* Larger text for accessibility */
@media (prefers-reduced-motion: reduce) {
    * {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}

/* High contrast mode */
@media (prefers-contrast: high) {
    .btn {
        border: 2px solid currentColor;
    }

    .card {
        border-width: 2px;
    }
}

/* ===================================
   PWA-SPECIFIC MOBILE STYLES
   =================================== */

/* Installed PWA adjustments */
.pwa-installed {
    /* Account for status bar on installed PWA */
    padding-top: env(safe-area-inset-top);
}

.pwa-installed .navbar {
    margin-top: 0;
}

/* Standalone mode (installed as app) */
@media (display-mode: standalone) {

    /* Hide URL-related elements */
    .external-link-icon {
        display: none;
    }

    /* Adjust spacing for app mode */
    body {
        padding-top: env(safe-area-inset-top);
        padding-bottom: env(safe-area-inset-bottom);
    }
}

/* ===================================
   MOBILE LOADING STATES
   =================================== */

@media (max-width: 768px) {
    .loading-overlay {
        backdrop-filter: blur(8px);
    }

    .spinner {
        width: 32px;
        height: 32px;
        border-width: 2px;
    }
}

/* ===================================
   MOBILE-FRIENDLY ALERTS
   =================================== */

@media (max-width: 768px) {
    .alert {
        padding: 0.875rem;
        font-size: 0.875rem;
        margin: 0 -1rem 1rem;
        border-radius: 0;
        border-left-width: 3px;
    }
}

/* ===================================
   MOBILE IMAGE HANDLING
   =================================== */

@media (max-width: 768px) {
    .image-preview {
        max-width: 100%;
        max-height: 150px;
    }

    /* Optimize image loading on mobile */
    img {
        max-width: 100%;
        height: auto;
    }
}

/* ===================================
   MOBILE FORM VALIDATION
   =================================== */

@media (max-width: 768px) {
    .form-error {
        font-size: 0.75rem;
        margin-top: 0.25rem;
    }

    .form-input.error,
    .form-select.error,
    .form-textarea.error {
        border-color: var(--danger-color);
        border-width: 2px;
    }
}

/* ===================================
   NAVBAR POSITIONING FIX
   =================================== */

/* Ensure navbar-content is positioned for absolute children */
@media (max-width: 480px) {
    .navbar-content {
        position: relative;
    }

    .navbar-toggle {
        z-index: 1001;
        -webkit-tap-highlight-color: transparent;
    }

    .navbar-toggle:hover {
        color: var(--primary-color);
    }

    .navbar-toggle:active {
        transform: translateY(-50%) scale(0.95);
    }

    .navbar-menu {
        z-index: 1000;
    }
}

/* Show menu on larger mobile screens (481-768px) */
@media (min-width: 481px) and (max-width: 768px) {
    .navbar-menu {
        display: flex !important;
    }
}

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

/* Mobile tickets list */
.tickets-mobile-list {
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.ticket-mobile-card {
    background: var(--glass-bg);
    backdrop-filter: blur(10px);
    border: 1px solid var(--glass-border);
    border-radius: var(--radius-lg);
    padding: 1rem;
    cursor: pointer;
    transition: all var(--transition-fast);
    -webkit-tap-highlight-color: transparent;
}

.ticket-mobile-card:active {
    transform: scale(0.98);
    background: var(--bg-tertiary);
}

.ticket-mobile-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 0.75rem;
}

.ticket-mobile-id {
    font-weight: 700;
    font-size: 0.875rem;
    color: var(--primary-color);
}

.ticket-mobile-subject {
    font-size: 1rem;
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: 0.75rem;
    line-height: 1.4;
}

.ticket-mobile-meta {
    display: flex;
    justify-content: space-between;
    gap: 1rem;
    margin-bottom: 0.5rem;
}

.ticket-mobile-meta-item {
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
    flex: 1;
}

.ticket-mobile-meta-label {
    font-size: 0.75rem;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.ticket-mobile-meta-item>span:last-child {
    font-size: 0.875rem;
    color: var(--text-secondary);
}

.ticket-mobile-footer {
    margin-top: 0.75rem;
    padding-top: 0.75rem;
    border-top: 1px solid var(--border-color);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.ticket-mobile-date {
    font-size: 0.75rem;
    color: var(--text-muted);
}

/* Fix for filter section on mobile */
@media (max-width: 768px) {
    .flex.justify-between {
        flex-direction: column;
        gap: 1rem;
        align-items: flex-start;
    }

    .flex.justify-between .btn {
        width: 100%;
    }
}

/* ===================================
   ABTEX LOGO BRANDING
   =================================== */

/* Navbar brand with logo */
.navbar-brand {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    font-weight: 700;
}

.navbar-brand::before {
    content: '';
    display: inline-block;
    width: 36px;
    height: 36px;
    background-image: url('/images/icon.svg');
    background-size: contain;
    background-repeat: no-repeat;
    background-position: center;
    border-radius: 8px;
}

@media (max-width: 480px) {
    .navbar-brand::before {
        width: 28px;
        height: 28px;
    }

    .navbar-brand {
        font-size: 1.1rem;
    }
}

/* ===================================
   MOBILE MENU ENHANCEMENTS
   =================================== */

/* Install App button in mobile menu */
@media (max-width: 480px) {
    .install-app-menu-item {
        list-style: none;
        padding: 0.75rem 1rem;
        border-bottom: 1px solid var(--border-color);
    }

    .install-app-btn {
        background: linear-gradient(135deg, var(--primary-color), var(--primary-dark)) !important;
        border: none !important;
        font-weight: 600;
        display: flex;
        align-items: center;
        justify-content: center;
        gap: 0.5rem;
        min-height: 48px;
    }

    .install-app-btn:active {
        transform: scale(0.98);
    }

    /* Menu header with logo */
    .navbar-menu.active::before {
        content: '';
        display: block;
        width: 80px;
        height: 80px;
        margin: 1rem auto;
        background-image: url('/images/icon.svg');
        background-size: contain;
        background-repeat: no-repeat;
        background-position: center;
    }

    /* Better menu spacing */
    .navbar-menu.active {
        padding-top: 0;
    }

    .navbar-menu.active li:first-child {
        margin-top: 1rem;
    }
}
/* ===================================
   APP VERSION LABEL
   =================================== */

.app-version {
    font-size: 0.65rem;
    color: rgba(148, 163, 184, 0.5);
    font-weight: 400;
    letter-spacing: 0.5px;
    user-select: none;
    padding: 2px 6px;
}

@media (max-width: 480px) {
    .app-version {
        display: block;
        text-align: center;
        padding: 0.5rem 0 0.25rem;
        font-size: 0.6rem;
        border-top: 1px solid rgba(148, 163, 184, 0.1);
        margin-top: 0.5rem;
    }
}
