/* Custom CSS for DTech Application */

/* -----------------------------------------------------------
   Universal Premium Selector Modals: Premium Card Design
   Used for: Customer, Vehicle, Item, Package Selectors
   ----------------------------------------------------------- */

@media (max-width: 767.98px) {
    /* 1. Base Container & Rows */
    .dt-mobile-cards {
        border: 0 !important;
        background: transparent !important;
    }

    .dt-mobile-cards thead {
        display: none !important; /* Hide column headers on mobile */
    }

    .dt-mobile-cards tbody tr {
        display: block !important;
        background: #fff;
        border: 1px solid #eef2f7 !important;
        border-radius: 16px !important;
        margin-bottom: 1.5rem !important;
        padding: 1.25rem !important;
        box-shadow: 0 10px 15px -3px rgba(0, 0, 0, 0.05), 0 4px 6px -2px rgba(0, 0, 0, 0.05);
        transition: transform 0.2s cubic-bezier(0.4, 0, 0.2, 1);
        position: relative !important;
        padding-top: 3.75rem !important; /* Standardized space for headers */
    }

    .dt-mobile-cards tbody tr:hover {
        transform: translateY(-3px);
        background: #fff !important;
        box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.1), 0 10px 10px -5px rgba(0, 0, 0, 0.04);
    }

    /* 2. Cell Layout (Flex row for data, block for headers/buttons) */
    .dt-mobile-cards tbody td {
        display: flex !important;
        justify-content: space-between;
        align-items: center;
        padding: 0.85rem 0 !important;
        border: 0 !important;
        font-size: 0.95rem;
        color: #334155;
        border-bottom: 1px dashed #f1f5f9 !important;
    }

    .dt-mobile-cards tbody td:last-child {
        border-bottom: 0 !important;
        padding-top: 1.25rem !important;
        margin-top: 0.5rem;
    }

    /* Standard Data Labels */
    .dt-mobile-cards tbody td::before {
        content: attr(data-label);
        font-weight: 600;
        color: #94a3b8;
        font-size: 0.8rem;
        text-transform: uppercase;
        letter-spacing: 0.05em;
        margin-right: 1rem;
    }

    /* 3. Universal Card Header (Identifies first visual field) */
    /* Primary identifiers like Name, Code, Package, Vehicle, Item, Category */
    .dt-mobile-cards tbody td[data-label="Package"],
    .dt-mobile-cards tbody td[data-label="Name"],
    .dt-mobile-cards tbody td[data-label="Item Name"],
    .dt-mobile-cards tbody td[data-label="Item"],
    .dt-mobile-cards tbody td[data-label="Vehicle"],
    .dt-mobile-cards tbody td[data-label="Registration"],
    .dt-mobile-cards tbody td[data-label="Code"] {
        position: absolute !important;
        top: 0;
        left: 0;
        right: 0;
        height: 3.5rem;
        background: linear-gradient(135deg, #f8fafc 0%, #f1f5f9 100%);
        border-bottom: 1px solid #e2e8f0 !important;
        padding: 0 1.5rem !important;
        font-weight: 800 !important;
        color: #0f172a !important;
        font-size: 1.1rem !important;
        display: flex !important;
        align-items: center !important;
        justify-content: flex-start !important;
        border-radius: 16px 16px 0 0;
        text-shadow: 0 1px 0 rgba(255,255,255,0.8);
    }

    /* Hide redundant label in the header */
    .dt-mobile-cards tbody td[data-label="Package"]::before,
    .dt-mobile-cards tbody td[data-label="Name"]::before,
    .dt-mobile-cards tbody td[data-label="Item Name"]::before,
    .dt-mobile-cards tbody td[data-label="Item"]::before,
    .dt-mobile-cards tbody td[data-label="Vehicle"]::before,
    .dt-mobile-cards tbody td[data-label="Registration"]::before,
    .dt-mobile-cards tbody td[data-label="Code"]::before {
        display: none !important;
    }

    /* Specific adjustment for identifying Code vs Name (if both in header range) */
    /* We prioritize Name as the header if possible, else Code */
    .dt-mobile-cards tbody td[data-label="Code"] { z-index: 1; }
    .dt-mobile-cards tbody td[data-label="Name"],
    .dt-mobile-cards tbody td[data-label="Item Name"],
    .dt-mobile-cards tbody td[data-label="Package"],
    .dt-mobile-cards tbody td[data-label="Vehicle"],
    .dt-mobile-cards tbody td[data-label="Item"] { z-index: 2; }

    /* 4. Action/Pick Column: Redesign - Removing bulky labels and buttons for a cleaner look */
    .dt-mobile-cards tbody td[data-label="Pick"],
    .dt-mobile-cards tbody td[data-label="Action"],
    .dt-mobile-cards tbody td[data-label="Actions"] {
        display: block !important;
        padding: 0 !important;
        margin: 0 !important;
        border: 0 !important;
    }

    .dt-mobile-cards tbody td[data-label="Pick"]::before,
    .dt-mobile-cards tbody td[data-label="Action"]::before,
    .dt-mobile-cards tbody td[data-label="Actions"]::before {
        display: none !important;
    }

    /* Move the "Add/Select" button to a more professional position or make it subtle */
    .dt-mobile-cards .btn-select-item,
    .dt-mobile-cards .btn-pick,
    .dt-mobile-cards .add-modal-item,
    .dt-mobile-cards .select-modal-customer {
        position: absolute !important;
        bottom: 1.25rem;
        right: 1.25rem;
        width: auto !important;
        min-width: 100px;
        padding: 0.6rem 1rem !important;
        border-radius: 10px !important;
        font-size: 0.85rem !important;
        box-shadow: 0 4px 12px rgba(37, 99, 235, 0.15) !important;
        z-index: 5;
    }

    /* Special handling for inventory list cards to remove buttons if requested */
    .inventory-cards-mobile .btn-outline-primary,
    .inventory-cards-mobile .btn-outline-danger {
        width: 48% !important;
        margin: 0 !important;
    }

    .inventory-cards-mobile .d-flex.justify-content-end {
        padding-top: 1rem !important;
        border-top: 1px solid #f1f5f9;
        margin-top: 0.5rem;
    }

    /* 5. Input Refinement inside Cards */
    .dt-mobile-cards tbody td:has(.form-control) {
        flex-direction: column !important;
        align-items: flex-start !important;
    }

    .dt-mobile-cards tbody td .form-control {
        margin-top: 0.75rem;
        border-radius: 12px !important;
        padding: 0.85rem 1rem !important;
        background: #f8fafc !important;
        border: 1.5px solid #f1f5f9 !important;
        font-weight: 500;
        width: 100% !important;
    }

    .dt-mobile-cards tbody td .form-control:focus {
        background: #fff !important;
        border-color: #2563eb !important;
        box-shadow: 0 0 0 4px rgba(37, 99, 235, 0.1) !important;
    }

    /* 6. Customer Picker Refinement */
    .customer-picker-box {
        transition: all 0.2s ease-in-out;
    }

    .customer-picker-box:hover {
        background: #f8fafc !important;
        border-color: #4f46e5 !important;
        transform: translateY(-1px);
        box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.05);
    }

    .customer-avatar {
        font-size: 1.2rem;
        transition: all 0.3s ease;
    }

    .item-picker-box {
        transition: all 0.2s ease-in-out;
    }

    .item-picker-box:hover {
        background: #f8fafc !important;
        border-color: #6366f1 !important;
        transform: translateY(-1px);
        box-shadow: 0 4px 6px -1px rgba(99, 102, 241, 0.1);
    }

    /* 7. Basket Table Premium Mobile View */
    @media (max-width: 767.98px) {
        #basketTable.dt-mobile-cards tbody tr {
            padding-top: 1.25rem !important; /* No absolute header for basket items */
        }
        
        #basketTable.dt-mobile-cards tbody td {
            border-bottom: 1px solid #f8fafc !important;
            padding: 0.6rem 0 !important;
        }

        #basketTable.dt-mobile-cards tbody td::before {
            display: none !important; /* We use inline labels for better control in basket */
        }
        
        #basketTable.dt-mobile-cards .remove-item {
            position: absolute;
            top: 1rem;
            right: 1rem;
            padding: 0.5rem !important;
            background: #fff5f5;
            border-radius: 8px;
        }
    }
}

/* Shared Global Modal UI */
.modal-search-wrapper {
    position: relative;
    margin-bottom: 2rem;
}

.modal-search-wrapper .search-icon {
    position: absolute;
    left: 1.25rem;
    top: 50%;
    transform: translateY(-50%);
    color: #94a3b8;
    font-size: 1.1rem;
}

.modal-search-wrapper .form-control {
    padding-left: 3.25rem;
    border-radius: 12px;
    height: 54px;
    border: 1.5px solid #e2e8f0;
    font-size: 1.05rem;
    transition: all 0.2s;
}

.modal-search-wrapper .form-control:focus {
    border-color: #2563eb;
    box-shadow: 0 0 0 4px rgba(37, 99, 235, 0.1);
}

/* -----------------------------------------------------------
   Global Premium Preloader (Glassmorphism + Pulse)
   ----------------------------------------------------------- */
.preloader {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(255, 255, 255, 0.7);
    backdrop-filter: blur(12px) saturate(180%);
    -webkit-backdrop-filter: blur(12px) saturate(180%);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    z-index: 99999;
    transition: opacity 0.6s ease, visibility 0.6s;
}

body.dark-mode .preloader {
    background: rgba(15, 23, 42, 0.8);
}

.preloader.fade-out {
    opacity: 0;
    visibility: hidden;
}

.loader-pulse {
    position: relative;
    width: 80px;
    height: 80px;
    background: var(--primary, #2563eb);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    font-size: 1.5rem;
    box-shadow: 0 0 30px rgba(37, 99, 235, 0.4);
    animation: loaderPulse 2s infinite ease-in-out;
}

.loader-pulse::after {
    content: '';
    position: absolute;
    width: 100%;
    height: 100%;
    border-radius: 50%;
    border: 2px solid var(--primary, #2563eb);
    animation: loaderRipple 2s infinite ease-out;
}

@keyframes loaderPulse {
    0%, 100% { transform: scale(1); box-shadow: 0 0 20px rgba(37, 99, 235, 0.3); }
    50% { transform: scale(1.1); box-shadow: 0 0 50px rgba(37, 99, 235, 0.6); }
}

@keyframes loaderRipple {
    0% { transform: scale(1); opacity: 1; }
    100% { transform: scale(2.5); opacity: 0; }
}

.loader-text {
    margin-top: 2rem;
    font-weight: 700;
    letter-spacing: 0.1em;
    text-transform: uppercase;
    color: #1e293b;
    font-size: 0.85rem;
    animation: loaderTextFade 1.5s infinite alternate;
}

body.dark-mode .loader-text {
    color: #f1f5f9;
}

@keyframes loaderTextFade {
    from { opacity: 0.4; transform: translateY(0); }
    to { opacity: 1; transform: translateY(-3px); }
}

/* Animations */
@keyframes loaderTextFade {
    from { opacity: 0.4; transform: translateY(0); }
    to { opacity: 1; transform: translateY(-3px); }
}

/* -----------------------------------------------------------
   Full-Height & Full-Width XL Modals
   ----------------------------------------------------------- */
.modal-xl {
    max-width: 98% !important;
    width: 98% !important;
    margin: 2vh auto !important;
}

.modal-xl .modal-content {
    height: 96vh !important;
    display: flex !important;
    flex-direction: column !important;
    border-radius: 12px !important;
    overflow: hidden !important;
}

.modal-xl .modal-header {
    flex-shrink: 0 !important;
}

.modal-xl .modal-body {
    flex: 1 1 auto !important;
    overflow-y: auto !important;
}

.modal-xl .modal-footer {
    flex-shrink: 0 !important;
}
/* -----------------------------------------------------------
   Global Page Header Responsive Layout
   ----------------------------------------------------------- */
@media (max-width: 768px) {
    .page-header .d-flex.justify-content-between {
        flex-direction: column !important;
        align-items: flex-start !important;
        gap: 1.25rem !important;
    }
    
    .page-header .title-section {
        width: 100% !important;
    }

    .page-header .action-section {
        width: 100% !important;
        display: flex !important;
        flex-direction: column !important;
        gap: 0.75rem !important;
    }
    
    .page-header .action-section .btn,
    .page-header .action-section a.btn {
        width: 100% !important;
        margin: 0 !important;
        display: flex !important;
        align-items: center !important;
        justify-content: center !important;
        padding: 0.75rem 1rem !important;
        font-size: 0.9rem !important;
    }

    .page-header h1 {
        font-size: 1.25rem !important;
    }

    .page-header p {
        font-size: 0.85rem !important;
    }
}
