/* Mobile-First PWA Styles — حس اپ واقعی */

/* پس‌زمینه یکدست؛ safe-area روی هدر/نوار پایین لایه‌ها اعمال می‌شود نه روی body */
html {
    scroll-behavior: smooth;
    -webkit-overflow-scrolling: touch;
    background-color: #ffffff;
}

html, body {
    margin: 0;
    padding: 0;
    background-color: #ffffff;
    min-height: 100%;
    min-height: 100dvh;
    overscroll-behavior-y: none;
}

/* ویجت چت هوش مصنوعی را بالاتر از منوی پایین نگه دار */
.chat-bubble {
    bottom: 82px !important;
}

/* Touch-friendly buttons — except bottom nav icons */
button:not(.nav-item):not(.pwa-btn):not(.pwa-guide-actions button), .btn, a {
    min-height: 44px;
    min-width: 44px;
    touch-action: manipulation;
}

/* Prevent text selection on buttons */
button, .btn {
    -webkit-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
    user-select: none;
    -webkit-tap-highlight-color: transparent;
}

/* Card lists instead of wide tables (RTL, no horizontal scroll) */
.m-cards {
    display: flex;
    flex-direction: column;
    gap: 12px;
    width: 100%;
}
.m-card {
    background: #fff;
    border: 1px solid #f3f4f6;
    border-radius: 16px;
    box-shadow: 0 4px 14px rgba(0, 0, 0, 0.07);
    overflow: hidden;
    direction: rtl;
    text-align: right;
}
.m-card-head {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 10px;
    padding: 14px 14px 8px;
}
.m-card-title {
    margin: 0;
    font-size: 0.98rem;
    font-weight: 700;
    color: #111827;
    word-wrap: break-word;
    line-height: 1.45;
}
.m-card-sub {
    margin: 4px 0 0;
    font-size: 0.82rem;
    color: #6b7280;
}
.m-card-rows {
    padding: 0 14px 12px;
    display: flex;
    flex-direction: column;
    gap: 6px;
}
.m-row {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 10px;
    font-size: 0.85rem;
}
.m-row .k { color: #6b7280; flex-shrink: 0; }
.m-row .v { font-weight: 500; color: #111827; text-align: left; word-wrap: break-word; }
.m-row .v.ok { color: #059669; }
.m-card-foot {
    border-top: 1px solid #f3f4f6;
    padding: 12px 14px;
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    align-items: center;
    justify-content: flex-start;
}

/* Mobile-optimized tables */
@media (max-width: 768px) {
    .modern-table {
        display: block;
        width: 100%;
    }
    
    .modern-table thead {
        display: none;
    }
    
    .modern-table tbody,
    .modern-table tr,
    .modern-table td {
        display: block;
        width: 100%;
    }
    
    .modern-table tr {
        margin-bottom: 16px;
        border: 1px solid #e5e7eb;
        border-radius: 8px;
        padding: 12px;
        background: #ffffff;
    }
    
    .modern-table td {
        text-align: right;
        padding: 8px 0;
        border: none;
        border-bottom: 1px solid #f3f4f6;
    }
    
    .modern-table td:before {
        content: attr(data-label) ": ";
        font-weight: 600;
        color: #6b7280;
        display: inline-block;
        min-width: 100px;
    }
    
    .modern-table td:last-child {
        border-bottom: none;
    }
}

/* Mobile-optimized modals */
@media (max-width: 768px) {
    .modal-content {
        max-width: 100% !important;
        margin: 0 !important;
        border-radius: 16px 16px 0 0 !important;
        max-height: 90vh !important;
    }
    
    .modal-overlay {
        padding: 0 !important;
        align-items: flex-end !important;
    }
}

/* Mobile-optimized forms */
@media (max-width: 768px) {
    .form-input,
    .search-input,
    .search-type-select {
        font-size: 16px !important; /* Prevents zoom on iOS */
    }
    
    .form-group {
        margin-bottom: 20px;
    }
}

/* Mobile navigation improvements */
@media (max-width: 991px) {
    .sidebar__nav {
        transform: translateX(0);
        transition: transform 0.3s ease;
    }
    
    .sidebar__nav.is-active {
        transform: translateX(100%);
    }
}

/* PWA Install Prompt */
.pwa-install-prompt {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    background: #ffffff;
    box-shadow: 0 -2px 10px rgba(0, 0, 0, 0.1);
    padding: 16px;
    padding-bottom: max(16px, env(safe-area-inset-bottom));
    z-index: 1000;
    display: none;
    border-top: 2px solid #059669;
}

.pwa-install-prompt.show {
    display: block;
}

/* Loading indicator for mobile */
.mobile-loading {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    z-index: 9999;
}

/* Swipe gestures support */
.swipeable {
    touch-action: pan-y;
    -webkit-overflow-scrolling: touch;
}

/* فوکوس ملایم هماهنگ با تم اپ (نه قرمز) */
*:focus-visible {
    outline: 2px solid #059669;
    outline-offset: 2px;
}

*:focus:not(:focus-visible) {
    outline: none;
}

/* Mobile-optimized spacing */
@media (max-width: 768px) {
    .container-content {
        padding: 12px !important;
    }
    
    .users-header h2 {
        font-size: 20px !important;
    }
    
    .header-controls {
        gap: 12px !important;
    }
    
    .filter-buttons {
        flex-wrap: wrap;
    }
}

/* Standalone PWA: حذف فاصله‌های اضافه مرورگر */
@media all and (display-mode: standalone) {
    html, body {
        background-color: #ffffff;
        user-select: none;
        -webkit-user-select: none;
    }

    .mobile-app-layout,
    .storeowner-layout {
        min-height: 100dvh;
    }
}
