/* ====================================
   Mobile-First Enhancements
   OnStock Inventory Management System
   ==================================== */

/* Touch-Friendly Minimum Tap Targets (44x44px minimum per Apple/Google guidelines) */
.btn,
button,
a.action-btn,
.mobile-menu-btn,
.theme-toggle {
    min-height: 44px;
    min-width: 44px;
    touch-action: manipulation; /* Prevents double-tap zoom */
}

/* Enhanced Mobile Navigation */
@media (max-width: 640px) {
    /* Hamburger menu improvements */
    .mobile-menu-btn {
        padding: 12px;
        border-radius: 8px;
        transition: background 0.2s ease;
    }

    .mobile-menu-btn:active {
        background: var(--border-light);
        transform: scale(0.95);
    }

    /* Improved mobile menu */
    .nav-menu {
        background: var(--card-bg);
        border-radius: 12px;
        margin-top: 0.75rem;
        padding: 0.5rem;
        box-shadow: var(--shadow-lg);
        border: 1px solid var(--border-color);
    }

    .nav-menu li {
        margin: 0;
    }

    .nav-menu a {
        padding: 12px 16px;
        font-size: 16px; /* Prevents zoom on iOS */
        display: flex;
        align-items: center;
        gap: 8px;
    }

    .nav-menu a:active {
        background: var(--accent-color);
        color: white;
        transform: scale(0.98);
    }
}

/* Mobile-Optimized Tables */
@media (max-width: 768px) {
    /* Table wrapper with scroll indicators */
    .table-container {
        position: relative;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        border-radius: 8px;
        margin: 1rem 0;
    }

    /* Scroll shadow indicators */
    .table-container::before,
    .table-container::after {
        content: '';
        position: absolute;
        top: 0;
        bottom: 0;
        width: 20px;
        pointer-events: none;
        z-index: 2;
        transition: opacity 0.3s;
    }

    .table-container::before {
        left: 0;
        background: linear-gradient(to right, rgba(0,0,0,0.05), transparent);
    }

    .table-container::after {
        right: 0;
        background: linear-gradient(to left, rgba(0,0,0,0.05), transparent);
    }

    /* Table adjustments */
    .table {
        min-width: 600px;
        font-size: 14px;
    }

    .table th,
    .table td {
        padding: 12px 8px;
        white-space: nowrap;
    }

    .table th {
        position: sticky;
        top: 0;
        background: var(--card-bg);
        z-index: 10;
        box-shadow: 0 2px 2px -1px rgba(0, 0, 0, 0.1);
    }

    /* Mobile card view for tables (alternative view) */
    .mobile-card-view {
        display: block;
    }

    .mobile-card-item {
        background: var(--card-bg);
        border: 1px solid var(--border-color);
        border-radius: 12px;
        padding: 16px;
        margin-bottom: 12px;
        box-shadow: var(--shadow-sm);
        transition: all 0.2s ease;
    }

    .mobile-card-item:active {
        transform: scale(0.98);
        box-shadow: var(--shadow-md);
    }

    .mobile-card-header {
        font-weight: 600;
        font-size: 16px;
        color: var(--text-primary);
        margin-bottom: 12px;
        padding-bottom: 8px;
        border-bottom: 2px solid var(--border-color);
    }

    .mobile-card-row {
        display: flex;
        justify-content: space-between;
        padding: 6px 0;
        font-size: 14px;
    }

    .mobile-card-label {
        color: var(--text-secondary);
        font-weight: 500;
    }

    .mobile-card-value {
        color: var(--text-primary);
        font-weight: 600;
        text-align: right;
    }
}

/* Mobile-Optimized Forms */
@media (max-width: 640px) {
    .form-group {
        margin-bottom: 1.25rem;
    }

    /* Prevent iOS zoom on input focus */
    input,
    select,
    textarea {
        font-size: 16px !important; /* Prevents zoom */
        padding: 14px 12px;
    }

    label {
        font-size: 14px;
        margin-bottom: 6px;
    }

    /* Better input spacing */
    input[type="text"],
    input[type="number"],
    input[type="email"],
    input[type="password"],
    select,
    textarea {
        width: 100%;
        border-radius: 10px;
    }

    /* Form buttons */
    .btn-group {
        display: flex;
        flex-direction: column;
        gap: 10px;
        margin-top: 1.5rem;
    }

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

    /* Improved textarea */
    textarea {
        min-height: 120px;
        resize: vertical;
    }
}

/* Mobile-Optimized Cards */
@media (max-width: 640px) {
    .card {
        padding: 1.25rem;
        margin-bottom: 1rem;
        border-radius: 12px;
    }

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

    /* Grid layouts stack on mobile */
    .grid {
        grid-template-columns: 1fr;
        gap: 1rem;
    }

    /* Stat cards */
    .stat-card {
        padding: 1.5rem 1rem;
    }

    .stat-value {
        font-size: 2rem;
    }

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

/* Mobile-Optimized Buttons */
@media (max-width: 640px) {
    .btn {
        padding: 12px 20px;
        font-size: 15px;
        border-radius: 10px;
        width: auto;
    }

    /* Full-width primary actions on mobile */
    .btn-block,
    .action-btn-primary {
        width: 100%;
        display: flex;
        justify-content: center;
    }

    /* Button groups */
    .header-actions {
        display: flex;
        flex-direction: column;
        gap: 8px;
        width: 100%;
    }

    .header-actions .btn,
    .header-actions .action-btn {
        width: 100%;
    }
}

/* Improved Touch Feedback */
@media (hover: none) and (pointer: coarse) {
    /* Touch device specific */
    .btn:active,
    button:active,
    a:active {
        transform: scale(0.96);
        opacity: 0.9;
    }

    .card:active {
        transform: scale(0.99);
    }

    /* Remove hover states on touch devices */
    .btn:hover::before {
        left: -100%;
    }
}

/* Mobile Alert Styling */
@media (max-width: 640px) {
    .alert {
        padding: 12px 14px;
        font-size: 14px;
        border-radius: 8px;
        margin-bottom: 1rem;
    }
}

/* Mobile Modal/Dialog Improvements */
@media (max-width: 640px) {
    .modal-content {
        margin: 1rem;
        border-radius: 16px;
        max-height: calc(100vh - 2rem);
        overflow-y: auto;
    }

    .modal-header {
        padding: 1.25rem 1rem;
        font-size: 1.125rem;
    }

    .modal-body {
        padding: 1rem;
    }

    .close-btn {
        min-width: 44px;
        min-height: 44px;
        display: flex;
        align-items: center;
        justify-content: center;
    }
}

/* Mobile Dashboard Improvements */
@media (max-width: 640px) {
    .dashboard-header {
        flex-direction: column;
        align-items: stretch;
        gap: 1rem;
    }

    .header-info h1 {
        font-size: 1.5rem;
        line-height: 1.3;
    }

    .subtitle {
        font-size: 0.875rem;
    }

    /* Compact metrics */
    .compact-overview {
        display: grid;
        grid-template-columns: repeat(2, 1fr);
        gap: 0.75rem;
        margin: 1rem 0;
    }

    .compact-metric {
        padding: 1rem 0.75rem;
        border-radius: 10px;
    }

    .compact-icon {
        font-size: 1.5rem;
    }

    .compact-number {
        font-size: 1.5rem;
    }

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

/* Mobile Typography */
@media (max-width: 640px) {
    body {
        font-size: 14px;
        line-height: 1.5;
    }

    h1 {
        font-size: 1.75rem;
        line-height: 1.2;
    }

    h2 {
        font-size: 1.5rem;
        line-height: 1.3;
    }

    h3 {
        font-size: 1.25rem;
        line-height: 1.4;
    }

    h4 {
        font-size: 1.125rem;
    }

    p {
        font-size: 0.9375rem;
        line-height: 1.6;
    }
}

/* Prevent Text Selection on Buttons (better mobile UX) */
.btn,
button,
.mobile-menu-btn,
.nav-menu a {
    -webkit-user-select: none;
    user-select: none;
    -webkit-tap-highlight-color: transparent;
}

/* Safe Area Insets for Notched Devices */
@supports (padding: max(0px)) {
    .navbar {
        padding-left: max(1rem, env(safe-area-inset-left));
        padding-right: max(1rem, env(safe-area-inset-right));
    }

    .container {
        padding-left: max(1rem, env(safe-area-inset-left));
        padding-right: max(1rem, env(safe-area-inset-right));
    }
}

/* Horizontal Scroll Indicators for Tables */
.table-scroll-indicator {
    display: none;
    text-align: center;
    padding: 8px;
    background: var(--accent-color);
    color: white;
    font-size: 12px;
    border-radius: 8px 8px 0 0;
    animation: bounce 2s infinite;
}

@media (max-width: 768px) {
    .table-scroll-indicator {
        display: block;
    }
}

@keyframes bounce {
    0%, 100% {
        transform: translateX(0);
    }
    50% {
        transform: translateX(10px);
    }
}

/* Loading States for Mobile */
.loading-spinner {
    display: inline-block;
    width: 20px;
    height: 20px;
    border: 3px solid rgba(255, 255, 255, 0.3);
    border-radius: 50%;
    border-top-color: white;
    animation: spin 1s linear infinite;
}

@keyframes spin {
    to {
        transform: rotate(360deg);
    }
}

/* Pull to Refresh Indicator (Visual Only) */
.pull-refresh-indicator {
    position: fixed;
    top: 60px;
    left: 50%;
    transform: translateX(-50%);
    background: var(--accent-color);
    color: white;
    padding: 8px 16px;
    border-radius: 20px;
    font-size: 14px;
    box-shadow: var(--shadow-lg);
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s ease;
    z-index: 1001;
}

/* Mobile Search Improvements */
@media (max-width: 640px) {
    .search-container {
        width: 100%;
        margin-bottom: 1rem;
    }

    input[type="search"],
    input[placeholder*="Search"] {
        font-size: 16px;
        padding: 12px 16px;
        border-radius: 10px;
        width: 100%;
    }

    /* Dropdown search results */
    .item-search-dropdown {
        max-height: 60vh;
        border-radius: 12px;
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
    }

    .item-search-result {
        padding: 12px 14px;
        font-size: 14px;
    }
}

/* Mobile Action Sheets (bottom sheet style) */
@media (max-width: 640px) {
    .action-sheet {
        position: fixed;
        bottom: 0;
        left: 0;
        right: 0;
        background: var(--card-bg);
        border-radius: 20px 20px 0 0;
        padding: 1.5rem 1rem;
        box-shadow: 0 -4px 12px rgba(0, 0, 0, 0.15);
        transform: translateY(100%);
        transition: transform 0.3s ease;
        z-index: 1002;
    }

    .action-sheet.active {
        transform: translateY(0);
    }

    .action-sheet-handle {
        width: 40px;
        height: 4px;
        background: var(--border-color);
        border-radius: 2px;
        margin: 0 auto 1rem;
    }
}

/* Improved List Items for Mobile */
@media (max-width: 640px) {
    .list-item {
        padding: 14px 12px;
        border-bottom: 1px solid var(--border-color);
        transition: background 0.2s ease;
    }

    .list-item:active {
        background: var(--border-light);
    }

    .list-item-title {
        font-size: 16px;
        font-weight: 600;
        color: var(--text-primary);
        margin-bottom: 4px;
    }

    .list-item-subtitle {
        font-size: 14px;
        color: var(--text-secondary);
    }

    .list-item-actions {
        display: flex;
        gap: 8px;
        margin-top: 8px;
    }

    .list-item-actions .btn {
        flex: 1;
        padding: 8px 12px;
        font-size: 13px;
    }
}

/* Swipe Actions Indicator (visual hint) */
.swipe-hint {
    font-size: 12px;
    color: var(--text-muted);
    text-align: center;
    padding: 8px;
    animation: fadeInOut 3s ease-in-out infinite;
}

@keyframes fadeInOut {
    0%, 100% {
        opacity: 0.5;
    }
    50% {
        opacity: 1;
    }
}

/* Floating Action Button (FAB) for mobile */
.fab {
    position: fixed;
    bottom: 24px;
    right: 24px;
    width: 56px;
    height: 56px;
    border-radius: 50%;
    background: var(--gradient-brand);
    color: white;
    border: none;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 24px;
    cursor: pointer;
    transition: all 0.3s ease;
    z-index: 999;
}

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

@media (min-width: 641px) {
    .fab {
        display: none;
    }
}

/* Bottom Navigation Bar (alternative to top nav on mobile) */
@media (max-width: 640px) {
    .bottom-nav {
        position: fixed;
        bottom: 0;
        left: 0;
        right: 0;
        background: var(--card-bg);
        border-top: 1px solid var(--border-color);
        padding: 8px 0 calc(8px + env(safe-area-inset-bottom));
        display: flex;
        justify-content: space-around;
        z-index: 1000;
        box-shadow: 0 -2px 10px rgba(0, 0, 0, 0.1);
    }

    .bottom-nav-item {
        flex: 1;
        display: flex;
        flex-direction: column;
        align-items: center;
        gap: 4px;
        padding: 8px;
        color: var(--text-secondary);
        text-decoration: none;
        font-size: 11px;
        transition: all 0.2s ease;
    }

    .bottom-nav-item:active {
        background: var(--border-light);
        border-radius: 8px;
    }

    .bottom-nav-item.active {
        color: var(--accent-color);
    }

    .bottom-nav-icon {
        font-size: 20px;
    }

    /* Add padding to body when bottom nav is present */
    body.has-bottom-nav {
        padding-bottom: calc(60px + env(safe-area-inset-bottom));
    }
}

/* Dark Mode Mobile Adjustments */
[data-theme="dark"] .mobile-card-item {
    background: var(--card-bg);
    border-color: var(--border-color);
}

[data-theme="dark"] .list-item:active {
    background: var(--primary-light);
}

[data-theme="dark"] .action-sheet {
    background: var(--card-bg);
    box-shadow: 0 -4px 12px rgba(0, 0, 0, 0.5);
}

[data-theme="dark"] .bottom-nav {
    background: var(--primary-dark);
    border-top-color: var(--border-color);
}

/* Accessibility: Focus indicators for keyboard navigation */
@media (min-width: 641px) {
    *:focus-visible {
        outline: 2px solid var(--accent-color);
        outline-offset: 2px;
    }
}

/* Performance: Hardware acceleration for animations */
.btn,
.card,
.mobile-menu-btn,
.mobile-card-item,
.list-item {
    will-change: transform;
}
