/* ============================================
   MOBILE APP-LIKE RESPONSIVE STYLES
   HIC Market - Mobile First Design
   ============================================ */

/* Base Mobile Optimizations */
@media (max-width: 768px) {
    /* Prevent zoom on input focus */
    input, select, textarea {
        font-size: 16px !important;
    }
    
    /* Smooth scrolling */
    html {
        scroll-behavior: smooth;
        -webkit-overflow-scrolling: touch;
    }
    
    body {
        overflow-x: hidden;
        -webkit-tap-highlight-color: transparent;
    }
    
    /* Remove default margins */
    .container, .container-fluid {
        padding-left: 15px;
        padding-right: 15px;
    }
    
    /* Full width buttons */
    .btn-block-mobile {
        width: 100%;
        display: block;
    }
}

/* ============================================
   CHAT MOBILE RESPONSIVE
   ============================================ */
@media (max-width: 768px) {
    /* Vendor Messages Page */
    #wrapper {
        flex-direction: column;
        max-width: 100%;
        box-shadow: none;
    }
    
    /* Hide sidebar on mobile */
    #sidebar-wrapper {
        display: none;
    }
    
    /* Mobile Navigation */
    #page-content-wrapper {
        width: 100% !important;
        margin: 0 !important;
    }
    
    #page-content-wrapper .navbar {
        display: flex !important;
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        z-index: 1000;
        background: #00a884;
        color: white;
        padding: 10px 15px;
        box-shadow: 0 2px 5px rgba(0,0,0,0.1);
    }
    
    /* Chat Container Mobile */
    .chat-container {
        flex-direction: column;
        height: calc(100vh - 60px);
        margin-top: 60px;
    }
    
    /* Chat List Mobile */
    .chat-list {
        width: 100% !important;
        height: 100%;
        display: flex;
        flex-direction: column;
    }
    
    .chat-list.hidden-mobile {
        display: none !important;
    }
    
    .chat-list-header {
        position: sticky;
        top: 0;
        z-index: 100;
        background: #00a884;
        color: white;
        padding: 15px;
    }
    
    .chat-list-header h5 {
        color: white;
        margin: 0;
        font-size: 18px;
    }
    
    .chat-list-items {
        flex: 1;
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
    }
    
    .chat-item {
        padding: 12px 15px;
        border-bottom: 1px solid #e9ecef;
        cursor: pointer;
        transition: background 0.2s;
    }
    
    .chat-item:active {
        background: #f0f2f5;
    }
    
    .chat-avatar {
        width: 50px;
        height: 50px;
        border-radius: 50%;
        margin-right: 12px;
    }
    
    .chat-info {
        flex: 1;
        min-width: 0;
    }
    
    .chat-name {
        font-weight: 600;
        font-size: 16px;
        margin-bottom: 4px;
    }
    
    .chat-preview {
        font-size: 14px;
        color: #667781;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
    }
    
    .chat-time {
        font-size: 12px;
        color: #667781;
    }
    
    /* Chat Window Mobile */
    .chat-window {
        display: none;
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        z-index: 2000;
        background: #efeae2;
        flex-direction: column;
    }
    
    .chat-window.active {
        display: flex !important;
    }
    
    .chat-header {
        position: sticky;
        top: 0;
        z-index: 100;
        background: #00a884;
        color: white;
        padding: 12px 15px;
        display: flex;
        align-items: center;
        gap: 15px;
        box-shadow: 0 2px 5px rgba(0,0,0,0.1);
    }
    
    .chat-back-btn {
        background: none;
        border: none;
        color: white;
        font-size: 24px;
        padding: 0;
        cursor: pointer;
        display: flex;
        align-items: center;
    }
    
    .chat-header-info {
        flex: 1;
        min-width: 0;
    }
    
    .chat-header-name {
        font-weight: 600;
        font-size: 16px;
        margin: 0;
        color: white;
    }
    
    .chat-header-status {
        font-size: 13px;
        color: rgba(255,255,255,0.8);
        margin: 0;
    }
    
    /* Chat Messages Area */
    .chat-messages {
        flex: 1;
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
        padding: 15px 10px;
        display: flex;
        flex-direction: column;
        gap: 8px;
    }
    
    /* Message Bubbles */
    .message-bubble {
        max-width: 85%;
        padding: 8px 12px;
        border-radius: 8px;
        word-wrap: break-word;
        word-break: break-word;
        overflow-wrap: break-word;
        white-space: normal;
        overflow: visible;
        position: relative;
        clear: both;
        margin-bottom: 4px;
    }
    
    .message-sent {
        background: #d9fdd3;
        align-self: flex-end;
        margin-left: auto;
        border-radius: 8px 8px 0 8px;
    }
    
    .message-received {
        background: white;
        align-self: flex-start;
        margin-right: auto;
        border-radius: 8px 8px 8px 0;
    }
    
    .message-text {
        font-size: 14px;
        line-height: 1.4;
        margin-bottom: 4px;
    }
    
    .message-time {
        font-size: 11px;
        color: #667781;
        text-align: right;
        margin-top: 4px;
    }
    
    /* Chat Input Area */
    .chat-input-area {
        position: sticky;
        bottom: 0;
        background: #f0f2f5;
        padding: 8px 10px;
        display: flex;
        align-items: center;
        gap: 8px;
        box-shadow: 0 -2px 5px rgba(0,0,0,0.05);
    }
    
    .chat-input-wrapper {
        flex: 1;
        background: white;
        border-radius: 24px;
        padding: 8px 15px;
        display: flex;
        align-items: center;
    }
    
    .chat-input-wrapper input {
        flex: 1;
        border: none;
        outline: none;
        font-size: 15px;
        padding: 0;
    }
    
    .chat-send-btn {
        background: #00a884;
        color: white;
        border: none;
        border-radius: 50%;
        width: 45px;
        height: 45px;
        display: flex;
        align-items: center;
        justify-content: center;
        cursor: pointer;
        transition: background 0.2s;
    }
    
    .chat-send-btn:active {
        background: #008f6f;
    }
    
    .chat-send-btn i {
        font-size: 18px;
    }
}

/* ============================================
   NAVIGATION MOBILE
   ============================================ */
@media (max-width: 768px) {
    /* Hide desktop navigation */
    .navbar-expand-lg {
        padding: 10px 15px;
    }
    
    .navbar-collapse {
        position: fixed;
        top: 0;
        left: -100%;
        width: 280px;
        height: 100vh;
        background: white;
        z-index: 9999;
        transition: left 0.3s ease;
        box-shadow: 2px 0 10px rgba(0,0,0,0.1);
        overflow-y: auto;
    }
    
    .navbar-collapse.show {
        left: 0;
    }
    
    /* Mobile Menu Overlay */
    .mobile-menu-overlay {
        display: none;
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        background: rgba(0,0,0,0.5);
        z-index: 9998;
    }
    
    .mobile-menu-overlay.show {
        display: block;
    }
    
    /* Hamburger Menu */
    .navbar-toggler {
        border: none;
        padding: 5px;
    }
    
    .navbar-toggler:focus {
        box-shadow: none;
    }
}

/* ============================================
   PRODUCT CARDS MOBILE
   ============================================ */
@media (max-width: 768px) {
    .product-card {
        margin-bottom: 15px;
    }
    
    .product-card img {
        height: 200px;
        object-fit: cover;
    }
    
    .product-card .card-body {
        padding: 12px;
    }
    
    .product-card .card-title {
        font-size: 14px;
        margin-bottom: 8px;
    }
    
    .product-card .price {
        font-size: 16px;
        font-weight: 600;
    }
    
    .product-card .btn {
        font-size: 13px;
        padding: 8px 12px;
    }
}

/* ============================================
   FORMS MOBILE
   ============================================ */
@media (max-width: 768px) {
    .form-control, .form-select {
        font-size: 16px;
        padding: 12px;
        border-radius: 8px;
    }
    
    .btn {
        padding: 12px 20px;
        font-size: 16px;
        border-radius: 8px;
    }
    
    .btn-lg {
        padding: 15px 25px;
        font-size: 18px;
    }
    
    label {
        font-size: 14px;
        margin-bottom: 6px;
    }
}

/* ============================================
   MODALS MOBILE
   ============================================ */
@media (max-width: 768px) {
    .modal-dialog {
        margin: 0;
        max-width: 100%;
        height: 100vh;
    }
    
    .modal-content {
        height: 100%;
        border-radius: 0;
        border: none;
    }
    
    .modal-header {
        padding: 15px;
        border-bottom: 1px solid #dee2e6;
    }
    
    .modal-body {
        padding: 15px;
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
    }
    
    .modal-footer {
        padding: 15px;
        border-top: 1px solid #dee2e6;
    }
}

/* ============================================
   TABLES MOBILE
   ============================================ */
@media (max-width: 768px) {
    .table-responsive {
        border: none;
        -webkit-overflow-scrolling: touch;
    }
    
    .table {
        font-size: 14px;
    }
    
    .table th, .table td {
        padding: 10px 8px;
        white-space: nowrap;
    }
    
    /* Card-style tables for mobile */
    .table-mobile-card {
        display: block;
    }
    
    .table-mobile-card thead {
        display: none;
    }
    
    .table-mobile-card tbody {
        display: block;
    }
    
    .table-mobile-card tr {
        display: block;
        margin-bottom: 15px;
        border: 1px solid #dee2e6;
        border-radius: 8px;
        padding: 12px;
        background: white;
    }
    
    .table-mobile-card td {
        display: block;
        text-align: right;
        padding: 8px 0;
        border: none;
    }
    
    .table-mobile-card td::before {
        content: attr(data-label);
        float: left;
        font-weight: 600;
        color: #666;
    }
}

/* ============================================
   BOTTOM NAVIGATION (APP-LIKE)
   ============================================ */
@media (max-width: 768px) {
    .bottom-nav {
        position: fixed;
        bottom: 0;
        left: 0;
        right: 0;
        background: white;
        border-top: 1px solid #dee2e6;
        display: flex;
        justify-content: space-around;
        padding: 8px 0;
        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;
        padding: 8px;
        color: #666;
        text-decoration: none;
        font-size: 12px;
        transition: color 0.2s;
    }
    
    .bottom-nav-item i {
        font-size: 20px;
        margin-bottom: 4px;
    }
    
    .bottom-nav-item.active {
        color: #00a884;
    }
    
    .bottom-nav-item:active {
        background: #f0f2f5;
    }
    
    /* Add padding to body when bottom nav is present */
    body.has-bottom-nav {
        padding-bottom: 60px;
    }
}

/* ============================================
   PULL TO REFRESH
   ============================================ */
@media (max-width: 768px) {
    .pull-to-refresh {
        position: relative;
    }
    
    .pull-to-refresh-indicator {
        position: absolute;
        top: -50px;
        left: 50%;
        transform: translateX(-50%);
        width: 40px;
        height: 40px;
        display: flex;
        align-items: center;
        justify-content: center;
        transition: top 0.3s;
    }
    
    .pull-to-refresh-indicator.active {
        top: 10px;
    }
}

/* ============================================
   TOUCH FEEDBACK
   ============================================ */
@media (max-width: 768px) {
    .touchable {
        cursor: pointer;
        -webkit-tap-highlight-color: rgba(0,0,0,0.1);
        transition: background 0.1s;
    }
    
    .touchable:active {
        background: rgba(0,0,0,0.05);
    }
    
    /* Card touch feedback */
    .card.touchable:active {
        transform: scale(0.98);
        transition: transform 0.1s;
    }
}

/* ============================================
   LOADING STATES
   ============================================ */
@media (max-width: 768px) {
    .skeleton-loader {
        background: linear-gradient(90deg, #f0f0f0 25%, #e0e0e0 50%, #f0f0f0 75%);
        background-size: 200% 100%;
        animation: loading 1.5s infinite;
    }
    
    @keyframes loading {
        0% { background-position: 200% 0; }
        100% { background-position: -200% 0; }
    }
}

/* ============================================
   SAFE AREA INSETS (iPhone X+)
   ============================================ */
@supports (padding: max(0px)) {
    @media (max-width: 768px) {
        .chat-header,
        .navbar {
            padding-top: max(12px, env(safe-area-inset-top));
        }
        
        .chat-input-area,
        .bottom-nav {
            padding-bottom: max(8px, env(safe-area-inset-bottom));
        }
    }
}

/* ============================================
   LANDSCAPE MODE
   ============================================ */
@media (max-width: 768px) and (orientation: landscape) {
    .chat-messages {
        padding: 10px;
    }
    
    .chat-header {
        padding: 8px 15px;
    }
    
    .chat-input-area {
        padding: 6px 10px;
    }
}

/* ============================================
   ACCESSIBILITY
   ============================================ */
@media (max-width: 768px) {
    /* Larger touch targets */
    button, a, input[type="button"], input[type="submit"] {
        min-height: 44px;
        min-width: 44px;
    }
    
    /* Focus visible for keyboard navigation */
    *:focus-visible {
        outline: 2px solid #00a884;
        outline-offset: 2px;
    }
}
