/* ==========================================
   MOBILE-FIRST RESPONSIVE DESIGN
   Touch-friendly, Mobile-optimized
   ========================================== */

/* ===== MOBILE BASE (< 768px) ===== */

/* Touch-friendly interactive elements */
@media (max-width: 767px) {
    /* Minimum touch target size (48px recommended) */
    button,
    .btn,
    a.btn,
    input[type="submit"],
    input[type="checkbox"],
    input[type="radio"],
    select {
        min-height: 48px;
        min-width: 48px;
    }

    /* Larger text inputs for better readability */
    input[type="text"],
    input[type="number"],
    input[type="email"],
    input[type="password"],
    textarea,
    select {
        font-size: 16px; /* Prevents zoom on iOS */
        padding: 12px 16px;
    }

    /* ===== NAVBAR - MOBILE ===== */
    .navbar {
        padding: 12px 0;
        position: sticky;
        top: 0;
        z-index: 1000;
    }

    .nav-container {
        padding: 0 16px;
        flex-wrap: wrap;
    }

    .nav-container h1 {
        font-size: 18px;
    }

    .nav-right {
        gap: 8px;
    }

    .nav-right span {
        font-size: 14px;
        max-width: 120px;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
    }

    /* ===== CONTAINER - MOBILE ===== */
    .container {
        margin: 16px auto;
        padding: 16px;
        border-radius: var(--radius-md);
        max-width: 100%;
    }

    /* ===== TABS - MOBILE (Horizontal Scroll) ===== */
    .tabs {
        display: flex;
        overflow-x: auto;
        overflow-y: hidden;
        -webkit-overflow-scrolling: touch;
        scrollbar-width: none; /* Firefox */
        -ms-overflow-style: none; /* IE/Edge */
        gap: 8px;
        padding: 0 16px 16px 16px;
        margin: 0 -16px 16px -16px;
    }

    .tabs::-webkit-scrollbar {
        display: none; /* Chrome/Safari */
    }

    .tab-btn {
        flex-shrink: 0;
        min-width: 120px;
        padding: 12px 20px;
        font-size: 14px;
        border-radius: var(--radius-lg);
        white-space: nowrap;
    }

    /* ===== TABLES → CARDS ON MOBILE ===== */
    .data-table-wrapper {
        margin: 0 -16px;
    }

    .data-table {
        display: block;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        white-space: nowrap;
    }

    /* Alternative: Convert to cards */
    .data-table.mobile-cards {
        display: block;
    }

    .data-table.mobile-cards thead {
        display: none;
    }

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

    .data-table.mobile-cards tr {
        margin-bottom: 16px;
        background: var(--bg-elevated);
        border-radius: var(--radius-md);
        box-shadow: var(--shadow-sm);
        padding: 16px;
    }

    .data-table.mobile-cards td {
        display: flex;
        justify-content: space-between;
        align-items: center;
        padding: 8px 0;
        border-bottom: 1px solid var(--border-light);
        white-space: normal;
        text-align: right;
    }

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

    .data-table.mobile-cards td::before {
        content: attr(data-label);
        font-weight: 600;
        flex-shrink: 0;
        margin-right: 16px;
        color: var(--text-secondary);
    }

    /* ===== BUTTONS - MOBILE ===== */
    .button-group {
        flex-direction: column;
        gap: 12px;
    }

    .btn {
        width: 100%;
        justify-content: center;
    }

    /* ===== FORMS - MOBILE ===== */
    .form-group {
        margin-bottom: 16px;
    }

    .form-group label {
        font-size: 14px;
        margin-bottom: 8px;
    }

    /* Grid forms → Stack on mobile */
    .form-grid,
    [style*="grid-template-columns"] {
        display: flex !important;
        flex-direction: column !important;
        gap: 16px !important;
    }

    /* ===== EXCHANGE RATE SECTION - MOBILE ===== */
    #invoiceTab .glass-card,
    #invoiceTab [style*="gradient"] {
        padding: 16px !important;
        margin: 0 -16px 16px -16px !important;
        border-radius: 0 !important;
    }

    #invoiceTab [style*="grid-template-columns"] {
        display: flex !important;
        flex-direction: column !important;
    }

    /* ===== INVOICE SECTIONS - MOBILE ===== */
    #invoiceSummarySection > div {
        margin: 0 !important;
    }

    #invoiceSummarySection [style*="grid"] {
        display: flex !important;
        flex-direction: column !important;
        gap: 12px !important;
    }

    /* ===== PRODUCT GRID - MOBILE ===== */
    .product-grid {
        grid-template-columns: 1fr !important;
        gap: 16px;
    }

    .product-card {
        padding: 16px;
    }

    /* ===== SECTION HEADERS - MOBILE ===== */
    .section-header {
        flex-direction: column;
        align-items: flex-start;
        gap: 16px;
    }

    .section-header h2,
    .section-header h3 {
        font-size: 20px;
    }

    /* ===== MODALS - MOBILE (Full Screen) ===== */
    .modal-content {
        width: 100vw !important;
        height: 100vh !important;
        max-width: none !important;
        margin: 0 !important;
        border-radius: 0 !important;
    }

    .modal-header,
    .modal-body,
    .modal-footer {
        padding: 16px !important;
    }

    /* ===== SCROLLABLE TABLES ===== */
    .table-scroll {
        position: relative;
    }

    .table-scroll::after {
        content: '→ Scroll →';
        position: absolute;
        right: 0;
        top: 50%;
        transform: translateY(-50%);
        background: var(--gradient-accent);
        color: white;
        padding: 4px 12px;
        border-radius: var(--radius-md);
        font-size: 12px;
        font-weight: 600;
        pointer-events: none;
        opacity: 0.8;
    }

    /* ===== IMAGE GALLERY - MOBILE ===== */
    .image-gallery {
        grid-template-columns: 1fr !important;
    }

    /* ===== CALCULATOR - MOBILE ===== */
    #calculatorTableContainer {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }

    /* ===== STATUS MESSAGES - MOBILE ===== */
    #invoiceParsingStatus,
    #bulkUpdateStatus,
    .status-message {
        margin: 0 -16px;
        border-radius: 0;
        padding: 16px;
    }

    /* ===== TYPOGRAPHY - MOBILE ===== */
    h1 {
        font-size: 24px;
    }

    h2 {
        font-size: 20px;
    }

    h3 {
        font-size: 18px;
    }

    p {
        font-size: 14px;
        line-height: 1.6;
    }

    /* ===== SPACING ADJUSTMENTS ===== */
    .space-y-lg {
        margin-top: 16px !important;
        margin-bottom: 16px !important;
    }
}

/* ===== TABLET (768px - 1023px) ===== */
@media (min-width: 768px) and (max-width: 1023px) {
    .container {
        max-width: 95%;
        padding: 24px;
    }

    .nav-container h1 {
        font-size: 20px;
    }

    /* 2-column layout for forms */
    .form-grid-2 {
        grid-template-columns: repeat(2, 1fr);
    }

    /* Tables: Show all but with smaller fonts */
    .data-table {
        font-size: 13px;
    }

    .data-table th,
    .data-table td {
        padding: 10px;
    }

    /* Product grid: 2 columns */
    .product-grid {
        grid-template-columns: repeat(2, 1fr);
    }
}

/* ===== DESKTOP (> 1024px) ===== */
@media (min-width: 1024px) {
    /* Hover effects only on desktop */
    .btn:hover {
        transform: translateY(-2px);
        box-shadow: var(--shadow-lg);
    }

    .elevated-card:hover {
        transform: translateY(-4px);
        box-shadow: var(--shadow-xl);
    }

    .data-table tr:hover {
        background: var(--hover-overlay);
        box-shadow: var(--shadow-sm);
    }

    /* Better tab spacing */
    .tabs {
        gap: 16px;
    }

    .tab-btn {
        min-width: 140px;
    }
}

/* ===== LANDSCAPE MOBILE ===== */
@media (max-width: 767px) and (orientation: landscape) {
    .navbar {
        padding: 8px 0;
    }

    .nav-container h1 {
        font-size: 16px;
    }

    .modal-content {
        overflow-y: auto;
    }
}

/* ===== UTILITY CLASSES ===== */

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

@media (min-width: 768px) {
    .hide-mobile {
        display: block !important;
    }
}

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

@media (min-width: 768px) {
    .show-mobile {
        display: none !important;
    }
}

/* Mobile-friendly padding */
.mobile-padding {
    padding: 16px;
}

@media (min-width: 768px) {
    .mobile-padding {
        padding: 24px;
    }
}

/* Mobile-friendly margins */
.mobile-margin {
    margin: 16px 0;
}

@media (min-width: 768px) {
    .mobile-margin {
        margin: 24px 0;
    }
}

/* Full width on mobile */
.mobile-full {
    width: 100%;
}

@media (min-width: 768px) {
    .mobile-full {
        width: auto;
    }
}

/* ===== ACCESSIBILITY - MOBILE ===== */

/* Larger click areas for accessibility */
@media (max-width: 767px) {
    a,
    button,
    .clickable {
        padding: 12px;
        margin: 4px 0;
    }

    /* Better focus indicators */
    *:focus-visible {
        outline: 3px solid var(--color-accent-primary);
        outline-offset: 2px;
    }

    /* 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;
        }
    }
}

/* ===== SAFE AREA (iPhone notch, etc.) ===== */
@supports (padding: max(0px)) {
    .container,
    .navbar,
    .modal-content {
        padding-left: max(16px, env(safe-area-inset-left));
        padding-right: max(16px, env(safe-area-inset-right));
    }

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