/**
 * Mobile App - Unified responsive styles for Pharmacy system
 * Modern shopping app look across all pages
 */

:root {
    --mobile-primary: #2563eb;
    --mobile-primary-dark: #1d4ed8;
    --mobile-success: #10b981;
    --mobile-warning: #f59e0b;
    --mobile-danger: #ef4444;
    --mobile-bg: #f8fafc;
    --mobile-card: #ffffff;
    --mobile-text: #1f2937;
    --mobile-text-muted: #64748b;
    --mobile-border: #e5e7eb;
    --mobile-nav-height: 56px;
    --mobile-safe-top: env(safe-area-inset-top, 0);
    --mobile-safe-bottom: env(safe-area-inset-bottom, 0);
}

/* 防止横向滚动条：100vw 等会触发溢出 */
html, body {
    overflow-x: hidden;
    max-width: 100%;
}

/* Base mobile enhancements */
@media (max-width: 768px) {
    html {
        -webkit-text-size-adjust: 100%;
        touch-action: manipulation;
    }

    /* 隐藏滚动条，确保内容仍可上下滑动 */
    html, body {
        scrollbar-width: none;
        -ms-overflow-style: none;
        -webkit-overflow-scrolling: touch;
    }
    html::-webkit-scrollbar,
    body::-webkit-scrollbar {
        display: none;
    }

    /* Only add bottom padding when mobile bottom nav exists */
    body.has-mobile-nav {
        padding-bottom: calc(var(--mobile-nav-height) + var(--mobile-safe-bottom) + 20px);
    }

    body {
        -webkit-tap-highlight-color: transparent;
    }

    /* Touch-friendly tap targets (min 44px) */
    .nav-link, .dropdown-item {
        min-height: 44px;
        display: flex;
        align-items: center;
    }

    .btn:not(.btn-sm) { min-height: 44px; }
    .btn-sm { min-height: 36px; }
    .form-control, .form-select { min-height: 44px; font-size: 16px; }

    /* Prevent zoom on input focus (iOS) */
    input, select, textarea {
        font-size: 16px !important;
    }

    /* Safe area for notched devices */
    .navbar.fixed-top, .app-header {
        padding-top: var(--mobile-safe-top);
    }

    .mobile-bottom-nav {
        padding-bottom: var(--mobile-safe-bottom);
    }
}

/* Mobile bottom navigation bar */
.mobile-bottom-nav {
    display: none;
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    height: calc(var(--mobile-nav-height) + var(--mobile-safe-bottom));
    background: var(--mobile-card);
    border-top: 1px solid var(--mobile-border);
    z-index: 1030;
    box-shadow: 0 -2px 10px rgba(0,0,0,0.08);
}

@media (max-width: 768px) {
    .mobile-bottom-nav {
        display: flex;
        justify-content: space-around;
        align-items: flex-start;
        padding-top: 8px;
        min-width: 0;
        overflow-x: hidden;
    }
}

.mobile-nav-item {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 6px 2px;
    color: var(--mobile-text-muted);
    text-decoration: none;
    font-size: 10px;
    font-weight: 500;
    transition: color 0.2s;
    -webkit-tap-highlight-color: transparent;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 100%;
}

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

.mobile-nav-item i {
    font-size: 18px;
    margin-bottom: 2px;
    flex-shrink: 0;
}

@media (max-width: 360px) {
    .mobile-nav-item {
        font-size: 9px;
        padding: 6px 1px;
    }
    .mobile-nav-item i {
        font-size: 16px;
    }
}

.mobile-nav-item .badge {
    position: absolute;
    top: 2px;
    right: 50%;
    margin-right: -24px;
    font-size: 10px;
    min-width: 18px;
    height: 18px;
    padding: 0 5px;
    display: flex;
    align-items: center;
    justify-content: center;
}

/* Mobile app container */
.mobile-app-wrap {
    max-width: 100%;
    margin: 0 auto;
}

@media (max-width: 768px) {
    .mobile-app-wrap {
        padding-left: 12px;
        padding-right: 12px;
    }

    .container {
        max-width: 100%;
        padding-left: 12px;
        padding-right: 12px;
    }
}

/* Mobile-optimized modals */
@media (max-width: 768px) {
    .modal-dialog {
        margin: 10px;
        max-width: calc(100% - 20px);
    }

    .modal-dialog-centered {
        min-height: calc(100% - 20px);
    }

    .modal-content {
        border-radius: 16px;
        max-height: 90vh;
        overflow-y: auto;
    }

    .modal-body {
        padding: 16px;
    }
}

/* Mobile tables - horizontal scroll */
@media (max-width: 768px) {
    .table-responsive {
        -webkit-overflow-scrolling: touch;
        overflow-x: auto;
    }

    .table {
        font-size: 13px;
    }

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

/* Mobile sidebar (admin/analytics) */
@media (max-width: 768px) {
    .sidebar-mobile {
        position: fixed;
        top: 0;
        left: -280px;
        width: 280px;
        height: 100vh;
        z-index: 1040;
        transition: left 0.3s ease;
        overflow-y: auto;
    }

    .sidebar-mobile.show {
        left: 0;
    }

    .sidebar-overlay {
        display: none;
        position: fixed;
        inset: 0;
        background: rgba(0,0,0,0.4);
        z-index: 1035;
    }

    .sidebar-overlay.show {
        display: block;
    }

    .main-content-mobile {
        margin-left: 0 !important;
    }
}

/* Mobile forms */
@media (max-width: 768px) {
    .form-control-lg, .form-select-lg {
        padding: 12px 16px;
        font-size: 16px;
    }

    .btn-lg {
        padding: 14px 20px;
        font-size: 16px;
    }
}

/* Product grid mobile */
@media (max-width: 576px) {
    .products-grid-mobile .col-6 {
        flex: 0 0 50%;
        max-width: 50%;
        padding: 6px;
    }
}

/* Card touch feedback */
@media (max-width: 768px) {
    .product-card, .app-card, .report-card {
        cursor: pointer;
        -webkit-tap-highlight-color: transparent;
    }

    .product-card:active, .app-card:active {
        opacity: 0.95;
    }
}
