/* =========================================
   Custom Compact Header Styles (Mobile Optimized)
   ========================================= */

.editor-header-grid {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

@media (min-width: 992px) {
    .editor-header-grid {
        flex-direction: row;
        align-items: stretch;
    }

    .editor-header-grid>div {
        flex: 1;
        width: 0;
        /* Ensure strictly equal width */
        min-width: 0;
        /* Prevent overflow */
    }
}

.editor-client-section,
.editor-meta-section,
.editor-transport-section {
    background: #ffffff;
    border: 1px solid #cbd5e1;
    /* Enabled border */
    /* border-radius: 12px; */
    padding: 0.33rem;
    /* Compact padding for better spacing */
    display: flex;
    flex-direction: column;
    justify-content: flex-start;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.02);
    /* Added subtle shadow */
}

/* Header Titles */
.editor-section-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 0.25rem;
    padding: 0 0.25rem;
}

.editor-section-title {
    font-size: 0.82rem;
    font-weight: 700;
    color: #475569;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    margin: 0;
}

.editor-action-btn,
.editor-action-link {
    font-size: 0.82rem;
    color: #EF7722;
    background: none;
    border: none;
    padding: 0;
    cursor: pointer;
    font-weight: 600;
    text-decoration: none;
}

.editor-action-btn:hover,
.editor-action-link:hover {
    text-decoration: underline;
    color: #d35f12;
}

/* Compact Flex Rows */
.editor-flex-row {
    display: flex;
    gap: 0.5rem;
    margin-top: 0.25rem;
}

.editor-flex-row .form-group-invoice {
    margin-bottom: 0;
}

/* Compact Grid for Meta Section */
.editor-meta-grid {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    background: #fcfcfc;
    border: 1px solid #eff2f6;
    border-radius: 8px;
    padding: 0.5rem;
}

.editor-meta-item {
    flex: 1;
    min-width: 100px;
    /* Ensure they don't get too small */
    margin-bottom: 0 !important;
}

/* Compact Input Styles */
.editor-input {
    padding: 0.35rem 0.6rem !important;
    font-size: 0.8rem !important;
    min-height: 28px !important;
    /* Force smaller height */
    height: 35px !important;
    border-radius: 6px !important;
    border: 1px solid #cbd5e1 !important;
    background: #ffffff !important;
    box-shadow: none !important;
}

.editor-input:focus {
    border-color: #BBE0EF !important;
    /* Keep original border color on focus */
    box-shadow: none !important;
    /* Remove shadow/glow */
    outline: none !important;
}

textarea.editor-input {
    min-height: 50px !important;
    height: 50px !important;
    /* Single line appearance initially */
    line-height: 1.2;
    padding-top: 0.4rem !important;
}

/* Labels */
.editor-label {
    font-size: 0.82rem;
    color: #64748b;
    margin-bottom: 0.1rem;
    display: block;
    font-weight: 500;
}

.editor-checkbox-label {
    font-size: 0.82rem;
    color: #334155;
    display: flex;
    align-items: center;
    gap: 0.35rem;
    cursor: pointer;
}

/* Search Bar Specifics */
.editor-search-wrapper {
    position: relative;
}

.editor-search-icon {
    position: absolute;
    left: 0.6rem;
    top: 50%;
    transform: translateY(-50%);
    font-size: 0.82rem;
    color: #94a3b8;
    pointer-events: none;
    z-index: 5;
}

.editor-search-field {
    padding-left: 2rem !important;
    /* Space for icon */
}

.editor-add-btn {
    position: absolute;
    right: 4px;
    top: 4px;
    width: 24px;
    height: 24px;
    border: none;
    background: #cbd5e1;
    color: #475569;
    border-radius: 4px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.2s;
}

.editor-add-btn:hover {
    background: #EF7722;
    color: white;
}

.editor-add-btn i {
    font-size: 0.82rem;
}

/* Hidden Order Details Panel */
.editor-order-panel {
    background: #ffffff;
    border-top: 1px dashed #cbd5e1;
    margin-top: 0.5rem !important;
}

/* Party Suggestions positioning */
.party-suggestions {
    position: absolute;
    top: 100%;
    left: 0;
    /* right: 0; REMOVED to allow wider suggestions list than parent */
    z-index: 1050;
    margin-top: 4px;
    max-height: 350px;
    overflow-y: auto !important;
    background: #fff;
    border-radius: 8px;
    box-shadow: 0 10px 25px rgba(0, 0, 0, 0.1);
    display: block;
}

/* Custom Scrollbar */
.party-suggestions::-webkit-scrollbar {
    width: 6px;
    display: block;
}

.party-suggestions::-webkit-scrollbar-track {
    background: #f1f5f9;
    border-radius: 10px;
}

.party-suggestions::-webkit-scrollbar-thumb {
    background: #cbd5e1;
    border-radius: 10px;
}

/* =========================================
   Transport Section Specific Styles
   ========================================= */

.card-transport-section {
    background: #ffffff;
    border: 1px solid #eff2f6;
    border-radius: 12px;
    padding: 0.75rem;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.02);
}

.label-tiny {
    font-size: 0.82rem;
    color: #64748b;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.02em;
    margin-bottom: 0.15rem;
    display: block;
}

/* Override input-compact height specifically for transport section to be even smaller as requested */
.card-transport-section .input-compact {
    min-height: 28px !important;
    height: 28px !important;
    font-size: 0.82rem !important;
    padding: 0.25rem 0.5rem !important;
    background: #fcfcfc !important;
    border-color: #cbd5e1;
}

.card-transport-section .input-compact:focus {
    border-color: #cbd5e1 !important;
    box-shadow: none !important;
}

.card-transport-section .row.g-2 {
    --bs-gutter-y: 0.5rem;
}

/* =========================================
   Compact Barcode Scanner Styles (White Theme)
   ========================================= */

.barcode-scanner-compact {
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: #e2e2e2;
    /* White background */
    padding: 0.5rem 0.75rem;
    border-radius: 8px;
    margin-bottom: 0.5rem;
    color: #1e293b;
    /* Dark text */
    border: 1px solid #cbd5e1;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.05);
}

.scanner-left {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.scanner-right {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

/* Status Indicator */
.scanner-dot-compact {
    width: 28px;
    height: 28px;
    border-radius: 6px;
    background: #f1f5f9;
    /* Light background */
    display: flex;
    align-items: center;
    justify-content: center;
    color: #94a3b8;
    position: relative;
    font-size: 0.8rem;
    transition: all 0.3s;
}

.scanner-dot-compact.active {
    background: #ecfdf5;
    color: #10b981;
    box-shadow: 0 0 0 1px rgba(16, 185, 129, 0.2);
}

.status-pulse-compact {
    display: none;
    position: absolute;
    top: -2px;
    right: -2px;
    width: 8px;
    height: 8px;
    background: #10b981;
    border-radius: 50%;
    box-shadow: 0 0 0 2px #ffffff;
    animation: pulse-compact 2s infinite;
}

.scanner-dot-compact.active .status-pulse-compact {
    display: block;
}

@keyframes pulse-compact {
    0% {
        transform: scale(0.95);
        box-shadow: 0 0 0 2px #ffffff, 0 0 0 0 rgba(16, 185, 129, 0.7);
    }

    70% {
        transform: scale(1);
        box-shadow: 0 0 0 2px #ffffff, 0 0 0 6px rgba(16, 185, 129, 0);
    }

    100% {
        transform: scale(0.95);
        box-shadow: 0 0 0 2px #ffffff, 0 0 0 0 rgba(16, 185, 129, 0);
    }
}

/* Text */
.scanner-text-group {
    display: flex;
    flex-direction: column;
}

.scanner-title-compact {
    font-size: 0.62rem;
    font-weight: 700;
    margin: 0;
    color: #334155;
    /* Dark color */
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.scanner-subtitle-compact {
    font-size: 0.62rem;
    color: #64748b;
}

/* Button */
.btn-camera-compact {
    background: #ffffff;
    color: #fc7126;
    border: 1px solid #dbeafe;
    padding: 0.35rem 0.75rem;
    border-radius: 6px;
    font-size: 0.82rem;
    font-weight: 600;
    text-transform: uppercase;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 0.4rem;
    transition: all 0.2s;
}

.btn-camera-compact:hover {
    background: #ff7606;
    color: white;
    border-color: #ff7606;
}

.btn-camera-compact i {
    font-size: 0.82rem;
}

/* Divider & Settings Icon */
.scanner-divider {
    width: 1px;
    height: 20px;
    background: #cbd5e1;
    margin: 0 0.25rem;
}

.btn-settings-icon {
    width: 28px;
    height: 28px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: #ffffff;
    border: 1px solid #cbd5e1;
    border-radius: 6px;
    color: #64748b;
    cursor: pointer;
    transition: all 0.2s;
}

/* =========================================
   Mobile Optimized Items Table Row (Flat Structure via Flexbox)
   ========================================= */

/* =========================================
   Mobile Optimized Items Table Row (Flat Structure via Flexbox)
   ========================================= */

@media (max-width: 768px) {

    /* Transform Table for Mobile */
    .invoice-items-table,
    .invoice-items-table tbody,
    .invoice-items-table tr {
        display: block;
        width: 100%;
    }

    .invoice-items-table thead {
        display: none;
        /* Hide standard headers */
    }

    .invoice-items-table tr.item-row {
        background: #fdd7b070;
        border: 1px solid #f1f5f9;
        border-radius: 12px;
        margin-bottom: 0.75rem;
        padding: 0.75rem;
        padding-top: 1rem;
        /* Space for delete btn */
        box-shadow: 0 2px 4px rgba(0, 0, 0, 0.02);
        position: relative;
        display: flex;
        flex-wrap: wrap;
        /* Allows flow */
        align-items: flex-start;
        gap: 2%;
        /* Gap between columns */
        overflow: visible !important;
    }

    /* Helper: Reset CD Defaults for Mobile */
    .invoice-items-table td {
        display: block;
        border: none;
        background: transparent;
        padding: 0;
        width: 100%;
    }

    /* Hide desktop-specific cells */
    .row-index-cell,
    .desktop-action-cell,
    .desktop-total-cell {
        display: none !important;
    }

    /* Position Delete Button Top Right (Floating Half-Out) */
    .action-cell {
        position: absolute !important;
        top: -10px !important;
        right: -10px !important;
        width: auto !important;
        height: auto !important;
        background: transparent !important;
        z-index: 100;
        padding: 0 !important;
        overflow: visible !important;
    }

    .action-cell .btn-remove-row {
        background: #fee2e2 !important;
        color: #dc2626 !important;
        width: 30px !important;
        height: 30px !important;
        min-width: 30px !important;
        min-height: 30px !important;
        border-radius: 50% !important;
        display: flex !important;
        align-items: center !important;
        justify-content: center !important;
        box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06) !important;
        border: 2px solid white !important;
        padding: 0 !important;
        flex-shrink: 0 !important;
    }

    .action-cell .btn-remove-row i {
        font-size: 0.82rem;
    }

    /* --- Top Row: Item + Qty --- */
    /* Force side-by-side using specific percentages */
    .col-item-main {
        width: 63% !important;
        order: 1;
    }

    .col-qty-main {
        width: 35% !important;
        order: 2;
    }

    .col-qty-main .qty-stepper {
        justify-content: flex-end;
        /* Align right on mobile */
    }

    /* Tweaks for compact inputs */
    .col-item-main input,
    .col-qty-main input {
        font-weight: 600;
        color: #1e293b;
    }

    /* --- Second Row: Mobile Actions (More link + Total) --- */
    .col-mobile-actions {
        width: 100%;
        order: 3;
        margin-top: 0.5rem;
        display: block !important;
        background: transparent;
        /* Removed background */
        border-radius: 0;
        padding: 0.25rem 0.5rem;
        /* Reduced padding */
        border: none;
        /* Removed border */
        /* Ensure it breaks to new line */
        flex-basis: 100%;
    }

    .mobile-row-summary {
        display: flex;
        align-items: center;
        justify-content: space-between;
        width: 100%;
    }

    /* Styled Link for "More/Less" */
    .more-link {
        color: #EF7722;
        font-weight: 600;
        font-size: 0.85rem;
        text-decoration: none;
        cursor: pointer;
        display: inline-flex;
        align-items: center;
        gap: 4px;
    }

    .more-link:hover {
        text-decoration: underline;
    }

    .mob-row-total-display {
        font-size: 0.85rem;
        color: #1e293b;
    }

    .mob-row-total-display .label {
        color: #64748b;
        font-size: 0.82rem;
        margin-right: 4px;
    }

    /* --- Collapsible Cells (Strictly Hidden by default) --- */
    /* Use high specificity to ensure they are hidden initially */
    .invoice-items-table tr:not(.row-expanded) .mobile-collapsible,
    .mobile-collapsible {
        display: none !important;
        order: 4;
        width: 48% !important;
        /* Force 2 columns with !important to override td 100% */
        margin-top: 0.5rem;
        margin-right: 0;
        /* Clear margins */
    }

    /* GLOBAL MOBILE FIX: Hide data-labels for Item and Qty specifically, but allow others */
    .col-item-main::before,
    .col-qty-main::before,
    .col-mobile-actions::before {
        display: none !important;
    }

    /* Override rule: ensure mobile-collapsible keeps its pseudos */
    .mobile-collapsible::before {
        content: attr(data-label);
        font-size: 0.82rem;
        color: #64748b;
        font-weight: 700;
        text-transform: uppercase;
        margin-bottom: 0px !important;
        margin-right: 6px;
        display: inline-block !important;
        /* Force show */
        white-space: nowrap;
        min-width: 40px;
    }

    /* When Expanded - Reveal them and use Flexbox Grid behavior */
    .item-row.row-expanded .mobile-collapsible:not(.col-hidden) {
        display: flex !important;
        /* Flex to align label/input side-by-side */
        align-items: center;
        justify-content: space-between;
        animation: fadeIn 0.3s ease;
        margin-bottom: 0.25rem;
        /* Reduced margin for compactness */
        gap: 4px;
        background: #ffffff;
        /* Slight bg to distinguish fields */
        padding: 4px 6px;
        border-radius: 6px;
        border: 1px solid #f1f5f9;
        min-height: 28px;
    }

    /* Special case: Batch cell is full width in expanded view - Keep stacked or custom */
    .item-row.row-expanded .col-batch {
        width: 100% !important;
        order: 5;
        display: block !important;
        /* Batch remains block/vertical if needed */
        background: transparent;
        border: none;
        padding: 0;
    }

    /* Input Styling inside cells for Mobile */
    .mobile-collapsible input,
    .mobile-collapsible select {
        font-size: 0.8rem !important;
        /* Slightly smaller */
        padding: 0.2rem 0.4rem !important;
        width: auto !important;
        /* Let flex handle width */
        flex: 1;
        /* Take remaining space */
        height: 28px !important;
        /* Force compact height */
        min-height: 28px !important;
        margin: 0 !important;
        background: #fff;
    }

    @keyframes fadeIn {
        from {
            opacity: 0;
            transform: translateY(-5px);
        }

        to {
            opacity: 1;
            transform: translateY(0);
        }
    }
}

@media (min-width: 769px) {

    /* Restore Table Layout */
    .col-mobile-actions {
        display: none !important;
    }

    .invoice-items-table tr.item-row {
        display: table-row;
    }

    .invoice-items-table td {
        display: table-cell;
        width: auto !important;
        background: #fdd7b070;
        transition: background-color 0.2s ease;
        /* Reset widths */
        position: static !important;
        /* Reset relative/absolute */
    }

    /* Active Row Highlighting (Override General TD BG) */
    .invoice-items-table tr.item-row:focus-within td,
    .invoice-items-table tr.active-row td {
        background: #ffffff !important;
        color: #000000 !important;
    }

    .invoice-items-table tr.item-row:focus-within input,
    .invoice-items-table tr.active-row input,
    .invoice-items-table tr.item-row:focus-within select,
    .invoice-items-table tr.active-row select {
        background: #ffffff !important;
        color: #000000 !important;
    }

    /* Ensure collapsible cells are shown standard table-cell on desktop */
    .mobile-collapsible:not(.col-hidden) {
        display: table-cell !important;
    }

    /* Hide the pseudo-element labels on desktop if using them */
    .mobile-collapsible::before {
        display: none;
    }

    /* Restore delete button standard pos */
    .action-cell {
        position: static !important;
        background: transparent !important;
        width: auto;
    }
}

/* ==========================================================================
   GLOBAL PREMIUM DESIGN STANDARDIZATION (Consistent Radius & Padding)
   ========================================================================== */

/* 1. Header Sections (Consistent 10px Border Radius & 12px Padding) */
.editor-client-section,
.editor-meta-section,
.editor-transport-section {
    /* border-radius: 10px !important; */
    border-radius: 0 0 10px 10px !important;
    padding: 12px !important;
    border: 1px solid #cbd5e1 !important;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.04) !important;
    background: #ffffff !important;
}

/* 2. Inner Inputs and Nested Grids (Consistent 8px Proportional Inner Radius) */
.editor-input,
textarea.editor-input,
.editor-meta-grid {
    border-radius: 8px !important;
}

textarea.editor-input {
    padding: 10px 12px !important;
}

/* Mobile override for header sections border-radius */
@media (max-width: 768px) {

    .editor-client-section,
    .editor-meta-section,
    .editor-transport-section {
        border-radius: 0 !important;
    }
}