/* ============================================
   CMA OMBESSA - Transaction Pages Responsive
   Services de l'État & Pharmacie mobile styles
   ============================================ */

/* ============================================
   MOBILE BASE STYLES (< 480px)
   ============================================ */

/* ----------------------------------------
   Mini Stats Row - Compact 3-column
   ---------------------------------------- */
.mini-stats-row {
    grid-template-columns: repeat(3, 1fr) !important;
    gap: var(--space-2);
}

.mini-stat-card {
    padding: var(--space-2) var(--space-3);
    flex-direction: column;
    align-items: center;
    text-align: center;
    gap: var(--space-1);
}

.mini-stat-icon {
    width: 32px;
    height: 32px;
}

.mini-stat-icon svg {
    width: 16px;
    height: 16px;
}

.mini-stat-content {
    text-align: center;
}

.mini-stat-value {
    font-size: var(--text-sm);
}

.mini-stat-label {
    font-size: 10px;
    line-height: 1.2;
}

/* ----------------------------------------
   Transaction Layout - Cart at bottom
   ---------------------------------------- */
.transaction-layout {
    display: flex !important;
    flex-direction: column;
    gap: var(--space-4);
}

/* Form comes first */
.transaction-form-card {
    order: 0;
}

/* Cart comes after form */
.cart-card {
    order: 1;
    position: static !important;
}

/* ----------------------------------------
   Transaction Form Card
   ---------------------------------------- */
.transaction-form-header {
    padding: var(--space-3) var(--space-4);
}

.transaction-form-title {
    font-size: var(--text-base);
}

.transaction-form-badge {
    font-size: 10px;
    padding: 2px 8px;
}

.transaction-form-body {
    padding: var(--space-4);
}

/* ----------------------------------------
   Patient Info Section
   ---------------------------------------- */
.info-section {
    padding: var(--space-3);
    margin-bottom: var(--space-4);
}

.info-section-title {
    font-size: var(--text-xs);
    margin-bottom: var(--space-3);
}

/* Form grid - single column on mobile */
.form-grid,
.form-grid-2,
.form-grid-3 {
    grid-template-columns: 1fr !important;
    gap: var(--space-3);
}

/* Touch-friendly form inputs */
.form-label {
    font-size: var(--text-xs);
    margin-bottom: var(--space-1);
}

.form-input,
.form-select {
    height: 48px;
    font-size: 16px; /* Prevents iOS zoom */
    padding: var(--space-3);
    border-radius: var(--radius-md);
}

.form-input::placeholder {
    font-size: 14px;
}

/* ----------------------------------------
   Service Selection Section
   ---------------------------------------- */
.selection-section {
    margin-top: var(--space-4);
}

.selection-header {
    flex-direction: column;
    align-items: flex-start;
    gap: var(--space-2);
    margin-bottom: var(--space-3);
}

.selection-header h4 {
    font-size: var(--text-sm);
}

/* Stack selection inputs vertically */
.selection-input-group {
    flex-direction: column;
    gap: var(--space-2);
}

.selection-input-group .form-input,
.selection-input-group .form-select {
    width: 100%;
}

.selection-input-group .quantity-input {
    width: 100%;
    text-align: center;
}

.btn-add-item {
    width: 100%;
    height: 48px;
    font-size: var(--text-sm);
    justify-content: center;
}

/* ----------------------------------------
   Form Actions
   ---------------------------------------- */
.transaction-form-actions {
    flex-direction: column;
    gap: var(--space-2);
    margin-top: var(--space-4);
}

.transaction-form-actions .btn {
    width: 100%;
    height: 48px;
    justify-content: center;
}

/* ----------------------------------------
   Cart Card - Compact
   ---------------------------------------- */
.cart-card {
    border-radius: var(--radius-lg);
}

.cart-header {
    padding: var(--space-3) var(--space-4);
}

.cart-title {
    font-size: var(--text-sm);
}

.cart-count {
    font-size: 10px;
    min-width: 20px;
    height: 20px;
}

.cart-body {
    padding: var(--space-3);
    max-height: 200px;
}

.cart-empty {
    padding: var(--space-4);
}

.cart-empty-icon {
    width: 48px;
    height: 48px;
}

.cart-empty-icon svg {
    width: 24px;
    height: 24px;
}

.cart-empty-text {
    font-size: var(--text-xs);
}

/* Cart items compact */
.cart-item {
    padding: var(--space-2);
    gap: var(--space-2);
}

.cart-item-icon {
    width: 32px;
    height: 32px;
}

.cart-item-icon svg {
    width: 14px;
    height: 14px;
}

.cart-item-name {
    font-size: var(--text-xs);
}

.cart-item-qty {
    font-size: 10px;
}

.cart-item-remove {
    width: 28px;
    height: 28px;
    min-width: 28px;
}

/* Cart footer */
.cart-footer {
    padding: var(--space-3);
}

.cart-total-label {
    font-size: var(--text-xs);
}

.cart-total-value {
    font-size: var(--text-lg);
}

.cart-actions {
    gap: var(--space-2);
    margin-top: var(--space-3);
}

.cart-actions .btn {
    height: 44px;
    font-size: var(--text-sm);
}

/* ----------------------------------------
   Available Items Grid Card
   ---------------------------------------- */
.items-grid-card {
    margin-top: var(--space-4);
}

.items-grid-header {
    padding: var(--space-3);
    flex-direction: column;
    align-items: stretch;
    gap: var(--space-3);
}

.items-grid-title {
    font-size: var(--text-sm);
}

.items-grid-search {
    width: 100%;
    order: 1;
}

.items-grid-search input {
    height: 40px;
    font-size: 16px;
}

/* ----------------------------------------
   Category Tabs - Scrollable with indicators
   ---------------------------------------- */
.category-tabs {
    padding: var(--space-2) var(--space-3);
    gap: var(--space-2);
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
    position: relative;
}

.category-tabs::-webkit-scrollbar {
    display: none;
}

/* Scroll fade indicators */
.category-tabs::before,
.category-tabs::after {
    content: '';
    position: absolute;
    top: 0;
    bottom: 0;
    width: 24px;
    pointer-events: none;
    z-index: 1;
}

.category-tabs::before {
    left: 0;
    background: linear-gradient(to right, var(--gray-50), transparent);
}

.category-tabs::after {
    right: 0;
    background: linear-gradient(to left, var(--gray-50), transparent);
}

.category-tab {
    padding: var(--space-2) var(--space-3);
    font-size: var(--text-xs);
    white-space: nowrap;
    flex-shrink: 0;
}

/* ----------------------------------------
   Items Grid - 2 columns, compact
   ---------------------------------------- */
.items-grid-body {
    padding: var(--space-3);
    max-height: 350px;
}

.items-grid {
    grid-template-columns: repeat(2, 1fr) !important;
    gap: var(--space-2);
}

.item-card {
    padding: var(--space-3);
    border-radius: var(--radius-md);
}

.item-card-icon {
    width: 36px;
    height: 36px;
    margin-bottom: var(--space-2);
}

.item-card-icon svg {
    width: 18px;
    height: 18px;
}

.item-card-name {
    font-size: var(--text-xs);
    margin-bottom: var(--space-1);
    -webkit-line-clamp: 2;
}

.item-card-price {
    font-size: var(--text-sm);
}

.item-card-stock {
    font-size: 9px;
    padding: 2px 6px;
    margin-top: var(--space-1);
}

/* Always show add button on mobile (touch devices) */
.item-card-add {
    opacity: 1 !important;
    width: 28px;
    height: 28px;
    top: var(--space-2);
    right: var(--space-2);
}

.item-card-add svg {
    width: 14px;
    height: 14px;
}

/* ============================================
   LARGER MOBILE (480px+)
   ============================================ */
@media (min-width: 480px) {
    /* Mini stats slightly larger */
    .mini-stat-card {
        padding: var(--space-3);
    }

    .mini-stat-icon {
        width: 36px;
        height: 36px;
    }

    .mini-stat-value {
        font-size: var(--text-base);
    }

    .mini-stat-label {
        font-size: var(--text-xs);
    }

    /* Form body more padding */
    .transaction-form-body {
        padding: var(--space-5);
    }

    .info-section {
        padding: var(--space-4);
    }

    /* Selection input group - row on larger mobile */
    .selection-input-group {
        flex-direction: row;
        flex-wrap: wrap;
    }

    .selection-input-group .form-select {
        flex: 1;
        min-width: 150px;
    }

    .selection-input-group .quantity-input {
        width: 80px;
    }

    .btn-add-item {
        width: auto;
        padding: 0 var(--space-4);
    }

    /* Cart body taller */
    .cart-body {
        max-height: 250px;
    }

    /* Items grid */
    .items-grid {
        gap: var(--space-3);
    }

    .item-card {
        padding: var(--space-4);
    }
}

/* ============================================
   TABLET (768px+)
   ============================================ */
@media (min-width: 768px) {
    /* Mini stats - horizontal layout */
    .mini-stat-card {
        flex-direction: row;
        text-align: left;
        padding: var(--space-4);
    }

    .mini-stat-icon {
        width: 44px;
        height: 44px;
    }

    .mini-stat-content {
        text-align: left;
    }

    .mini-stat-value {
        font-size: var(--text-xl);
    }

    /* Transaction layout - 2 columns */
    .transaction-layout {
        display: grid !important;
        grid-template-columns: 1fr 320px;
        flex-direction: unset;
    }

    .transaction-form-card {
        order: unset;
    }

    .cart-card {
        order: unset;
        position: sticky !important;
        top: calc(var(--header-height, 64px) + var(--space-4));
    }

    /* Form grid - 2 columns */
    .form-grid-2 {
        grid-template-columns: repeat(2, 1fr) !important;
    }

    .transaction-form-header {
        padding: var(--space-4) var(--space-5);
    }

    .transaction-form-body {
        padding: var(--space-6);
    }

    /* Form actions row */
    .transaction-form-actions {
        flex-direction: row;
    }

    .transaction-form-actions .btn {
        width: auto;
    }

    /* Category tabs - no fade needed */
    .category-tabs::before,
    .category-tabs::after {
        display: none;
    }

    /* Items grid - 3 columns */
    .items-grid {
        grid-template-columns: repeat(3, 1fr) !important;
    }

    .items-grid-header {
        flex-direction: row;
        align-items: center;
    }

    .items-grid-search {
        width: 240px;
        order: unset;
    }
}

/* ============================================
   DESKTOP (1024px+)
   ============================================ */
@media (min-width: 1024px) {
    /* Transaction layout - wider cart */
    .transaction-layout {
        grid-template-columns: 1fr 380px;
    }

    /* Items grid - 4 columns */
    .items-grid {
        grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)) !important;
    }

    .items-grid-search {
        width: 280px;
    }

    /* Cart body taller */
    .cart-body {
        max-height: 350px;
    }

    /* Hide add button until hover on desktop */
    .item-card-add {
        opacity: 0;
    }

    .item-card:hover .item-card-add {
        opacity: 1;
    }
}

/* ============================================
   LARGE DESKTOP (1200px+)
   ============================================ */
@media (min-width: 1200px) {
    .mini-stat-card {
        padding: var(--space-5);
    }

    .transaction-form-body {
        padding: var(--space-6);
    }

    .info-section {
        padding: var(--space-5);
    }
}

/* ============================================
   LANDSCAPE MOBILE
   ============================================ */
@media (max-width: 767px) and (orientation: landscape) {
    /* Mini stats in single row */
    .mini-stats-row {
        grid-template-columns: repeat(3, 1fr) !important;
    }

    .mini-stat-card {
        flex-direction: row;
        padding: var(--space-2) var(--space-3);
    }

    .mini-stat-icon {
        width: 28px;
        height: 28px;
    }

    .mini-stat-value {
        font-size: var(--text-sm);
    }

    /* Shorter cart */
    .cart-body {
        max-height: 150px;
    }

    /* Items grid body shorter */
    .items-grid-body {
        max-height: 200px;
    }
}

/* ============================================
   TOUCH DEVICE OPTIMIZATIONS
   ============================================ */
@media (hover: none) and (pointer: coarse) {
    /* Always show add button */
    .item-card-add {
        opacity: 1 !important;
    }

    /* Larger touch targets */
    .cart-item-remove {
        width: 36px;
        height: 36px;
        min-width: 36px;
    }

    .category-tab {
        min-height: 40px;
        display: flex;
        align-items: center;
    }

    /* Remove hover effects */
    .item-card:hover {
        transform: none;
    }

    .mini-stat-card:hover {
        transform: none;
    }
}

/* ============================================
   ACCESSIBILITY - REDUCED MOTION
   ============================================ */
@media (prefers-reduced-motion: reduce) {
    .item-card,
    .mini-stat-card,
    .cart-item {
        transition: none;
    }
}

/* ============================================
   AUTOCOMPLETE DROPDOWN - MOBILE FIX
   ============================================ */
.autocomplete-dropdown {
    max-height: 200px;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
}

@media (max-width: 480px) {
    .autocomplete-dropdown {
        position: fixed;
        left: var(--space-4);
        right: var(--space-4);
        max-height: 50vh;
        z-index: var(--z-modal);
        border-radius: var(--radius-lg);
        box-shadow: var(--shadow-xl);
    }
}
