/* ============================================================= */
/* TRANSFER & MODAL STYLESHEET (V4.2 - Updated for Material MS)  */
/* Organized by Group & Number                                   */
/* ============================================================= */

/* ============================================================= */
/* 1. MODAL CONTAINER, FOOTER & BUTTON CONSISTENCY               */
/* ============================================================= */

/* Shared Container Logic */
#transfer-job-modal .modal-container,
#standard-job-modal .modal-container,
#ms-new-material-modal .modal-container, /* <--- ADDED THIS */
#im-batch-search-modal .modal-container,
#im-invoice-entry-modal .modal-container,
#im-add-payment-modal .modal-container {
    max-width: 900px !important;
    width: 95% !important;
    padding: 0 !important;
    display: flex;
    flex-direction: column;
    height: auto !important;
    max-height: 90vh !important;
    border-radius: 8px;
    background: #fff;
    overflow: visible !important;
}

/* Content Area */
#transfer-job-modal .modal-content,
#standard-job-modal .modal-content,
#ms-new-material-modal .modal-content, /* <--- ADDED THIS */
#im-batch-search-modal .modal-content,
#im-invoice-entry-modal .modal-content,
#im-add-payment-modal .modal-content {
    padding: 20px 30px !important;
    overflow-y: auto !important;
    overflow-x: visible !important;
    flex-grow: 1;
}

/* FIX: give space for bottom dropdowns (Choices.js) */
#transfer-job-modal .modal-content,
#ms-new-material-modal .modal-content { /* <--- ADDED THIS */
  padding-bottom: 260px !important;
}


/* --- [FIX] Footer Styling (White Background) --- */
#transfer-job-modal .modal-footer,
#standard-job-modal .modal-footer,
#ms-new-material-modal .modal-footer, /* <--- ADDED THIS */
#im-batch-search-modal .modal-footer,
#im-invoice-entry-modal .modal-footer,
#im-add-payment-modal .modal-footer {
    padding: 15px 25px !important;
    background-color: #ffffff !important; /* Changed from Grey to White */
    border-top: 1px solid #eee;           /* Subtle separator line */
    display: flex;
    justify-content: flex-end;
    align-items: center;
    gap: 10px;
    border-radius: 0 0 8px 8px;
}

/* --- [FIX] Footer Buttons (Uniform Size) --- */
#standard-job-modal .modal-footer button,
#ms-new-material-modal .modal-footer button, /* <--- ADDED THIS */
#transfer-job-modal .modal-footer button {
    height: 40px !important;        /* Fixed consistent height */
    min-width: 90px !important;     /* Minimum width so they don't look squashed */
    padding: 0 20px !important;     /* Consistent padding */
    font-size: 0.95rem !important;
    border-radius: 4px !important;
    display: inline-flex !important;
    align-items: center;
    justify-content: center;
    line-height: 1 !important;
    margin: 0 !important;           /* Remove random margins */
}

/* ============================================================= */
/* 2. UNIVERSAL BLUE HEADER THEME (FIXED BUTTONS)                */
/* ============================================================= */

/* Apply Blue Theme to Transfer, Batch, Payment, and STANDARD JOB Modals */
#transfer-job-modal .modal-header,
#im-batch-search-modal .modal-header,
#im-invoice-entry-modal .modal-header,
#im-add-payment-modal .modal-header,
#ms-new-material-modal .modal-header, /* <--- ADDED THIS */
#standard-job-modal .modal-header {
    background-color: #003A5C !important; /* Brand Blue */
    color: #ffffff !important;             /* White Text */
    border-bottom: 3px solid #002a48;      /* Darker 3D Border */
    border-radius: 8px 8px 0 0;            /* Rounded Top Corners */
    padding: 15px 25px !important;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

/* Title Text */
#transfer-job-modal h2,
#im-batch-search-modal h2,
#im-invoice-entry-modal h2,
#im-add-payment-modal h2,
#ms-new-material-modal h2, /* <--- ADDED THIS */
#standard-job-modal h2 {
    color: #ffffff !important;
    font-size: 1.2rem !important;
    font-weight: 700;
    margin: 0 !important;
}

/* --- [FIX START] Split Header and Footer Button Styles --- */

/* 1. Header Close Button (The 'X') - Transparent & Big */
#transfer-job-modal .modal-header .modal-close-btn,
#im-batch-search-modal .modal-header .modal-close-btn,
#im-invoice-entry-modal .modal-header .modal-close-btn,
#im-add-payment-modal .modal-header .modal-close-btn,
#ms-new-material-modal .modal-header .modal-close-btn, /* <--- ADDED THIS */
#standard-job-modal .modal-header .modal-close-btn {
    color: #ffffff !important;
    opacity: 0.8;
    font-size: 1.8rem;
    line-height: 1;
    background: none !important;
    border: none !important;
    cursor: pointer;
    padding: 0 10px;
}

#transfer-job-modal .modal-header .modal-close-btn:hover,
#im-batch-search-modal .modal-header .modal-close-btn:hover,
#im-invoice-entry-modal .modal-header .modal-close-btn:hover,
#im-add-payment-modal .modal-header .modal-close-btn:hover,
#ms-new-material-modal .modal-header .modal-close-btn:hover, /* <--- ADDED THIS */
#standard-job-modal .modal-header .modal-close-btn:hover {
    opacity: 1;
    background-color: rgba(255, 255, 255, 0.1) !important;
    border-radius: 50%;
}

/* 2. Footer Cancel Button (The actual Button) - Grey Background */
#transfer-job-modal .modal-footer .modal-close-btn,
#standard-job-modal .modal-footer .modal-close-btn,
#im-batch-search-modal .modal-footer .modal-close-btn,
#ms-new-material-modal .modal-footer .modal-close-btn, /* <--- ADDED THIS */
#im-invoice-entry-modal .modal-footer .modal-close-btn,
#im-add-payment-modal .modal-footer .modal-close-btn {
    background-color: #6c757d !important; /* Grey Background */
    color: #ffffff !important;             /* White Text */
    font-size: 0.95rem !important;
    opacity: 1 !important;
    width: auto !important;
    height: auto !important;
    border-radius: 4px !important;
    padding: 10px 20px !important;
    line-height: normal !important;
    border: none !important;
    cursor: pointer;
}

#transfer-job-modal .modal-footer .modal-close-btn:hover,
#ms-new-material-modal .modal-footer .modal-close-btn:hover, /* <--- ADDED THIS */
#standard-job-modal .modal-footer .modal-close-btn:hover {
    background-color: #5a6268 !important; /* Darker Grey on Hover */
}
/* --- [FIX END] --- */

/* ============================================================= */
/* 3. GRID SYSTEM (COMPACT & ALIGNED)                            */
/* ============================================================= */

.transfer-2col-grid {
    display: grid !important;
    grid-template-columns: 1fr 1fr !important;
    gap: 15px !important; /* Horizontal gap between columns */
    align-items: start !important;
}

.transfer-col {
    display: flex;
    flex-direction: column;
    /* This 'gap' controls vertical space between fields.
       Reduced to 8px for a compact look. */
    gap: 8px !important;
}

/* Mobile Override */
@media (max-width: 768px) {
    .transfer-2col-grid {
        grid-template-columns: 1fr !important;
        gap: 10px !important;
    }
}

/* ============================================================= */
/* 4. INPUTS, FORMS & FLOATING FOCUS EFFECT                      */
/* ============================================================= */

/* Group Spacing - Ensures rows start at the same vertical position */
#transfer-job-modal .form-group,
#ms-new-material-modal .form-group, /* <--- ADDED THIS */
#standard-job-modal .form-group {
    margin-bottom: 15px !important; /* Fixed gap between rows */
    width: 100%;
}

/* Labels - Uniform height and spacing */
#transfer-job-modal label,
#ms-new-material-modal label, /* <--- ADDED THIS */
#standard-job-modal label {
    font-size: 0.8rem !important;
    margin-bottom: 4px !important;
    color: #555;
    font-weight: 600;
    display: block;
    line-height: 1.2 !important;
}

/* --- UNIVERSAL FIELD STYLING (The Alignment Fix) --- */
#transfer-job-modal input,
#transfer-job-modal select,
#transfer-job-modal textarea,
#transfer-job-modal .choices__inner,
#standard-job-modal input,
#standard-job-modal select,
#standard-job-modal .choices__inner,
#ms-new-material-modal input, /* <--- ADDED THIS */
#ms-new-material-modal select, /* <--- ADDED THIS */
#ms-new-material-modal .choices__inner { /* <--- ADDED THIS */
    /* Dimensions */
    min-height: 36px !important;
    height: 36px !important;
    width: 100% !important;

    /* Content Alignment */
    padding: 6px 10px !important;
    font-size: 0.9rem !important;
    line-height: normal !important;

    /* Borders & Background */
    border: 1px solid #ccc !important;
    border-radius: 4px !important;
    background-color: #fff !important;
    box-sizing: border-box !important;

    /* Smooth Transition for the Float Effect */
    transition: all 0.2s ease-in-out !important;
}

/* --- THE FLOATING HIGHLIGHT EFFECT --- */
#transfer-job-modal input:focus,
#transfer-job-modal select:focus,
#transfer-job-modal textarea:focus,
#transfer-job-modal .choices.is-focused .choices__inner,
#standard-job-modal input:focus,
#standard-job-modal select:focus,
#standard-job-modal textarea:focus,
#standard-job-modal .choices.is-focused .choices__inner,
#ms-new-material-modal input:focus, /* <--- ADDED THIS */
#ms-new-material-modal select:focus, /* <--- ADDED THIS */
#ms-new-material-modal .choices.is-focused .choices__inner { /* <--- ADDED THIS */
    outline: none !important;
    border-color: #003A5C !important;
    background-color: #ffffff !important;

    /* The "Floating" Shadow */
    box-shadow: 0 4px 12px rgba(0, 58, 92, 0.15) !important;

    /* The Physical Lift */
    transform: translateY(-2px) !important;
}

/* Textarea Exception (Needs more height) */
#transfer-job-modal textarea,
#standard-job-modal textarea {
    height: 60px !important;
    resize: vertical;
}

/* ============================================================= */
/* 5. DROPDOWN FIXES (CHOICES.JS ALIGNMENT)                      */
/* ============================================================= */

/* Remove default wrapper margin so it aligns with standard inputs */
#transfer-job-modal .choices,
#ms-new-material-modal .choices, /* <--- ADDED THIS */
#standard-job-modal .choices {
    margin-bottom: 0 !important;
    overflow: visible !important;
}

/* Fix the inner container to behave like a standard input */
#transfer-job-modal .choices__inner,
#ms-new-material-modal .choices__inner, /* <--- ADDED THIS */
#standard-job-modal .choices__inner {
    display: flex !important;
    align-items: center !important;
    margin: 0 !important;
    border: 1px solid #ccc !important;
    background-color: #fff !important;
}

/* Fix the dropdown list z-index and shadow */
#transfer-job-modal .choices__list--dropdown,
#ms-new-material-modal .choices__list--dropdown, /* <--- ADDED THIS */
#standard-job-modal .choices__list--dropdown {
    z-index: 9999 !important;
    border: 1px solid #003A5C !important;
    box-shadow: 0 10px 20px rgba(0,0,0,0.15) !important;
    margin-top: 2px !important; /* Slight gap for visual clarity */
}

/* ============================================================= */
/* 6. HIGHLIGHTS & VISUAL FEEDBACK                               */
/* ============================================================= */

/* Blue Highlight for Required/Active Fields */
.input-required-highlight {
    border: 4px solid #003A5C !important; /* Brand Blue Border */
    background-color: #e3f2fd !important; /* Light Blue Tint */
    box-shadow: 0 0 8px rgba(0, 58, 92, 0.3); /* Blue Glow */
    transition: all 0.3s ease;
}

.input-required-highlight + label::after {
    color: #003A5C;
}

/* Sender Required Warning (Yellow) */
.sender-required {
    background-color: #fffde7 !important;
    border: 1px solid #fdd835 !important;
}

/* ============================================================= */
/* 7. PRINT STYLES (BARCODE VISIBILITY)                          */
/* ============================================================= */

@media print {
    /* Ensure Barcodes are visible ONLY if they have a source */
    #wb-barcode-approver[src=""],
    #wb-barcode-approver:not([src]),
    #wb-barcode-receiver[src=""],
    #wb-barcode-receiver:not([src]) {
        display: none !important;
    }

    /* Ensure text visibility */
    #wb-esn-text, #wb-receiver-esn-text {
        color: #000 !important;
        visibility: visible !important;
    }

    /* Ensure containers don't collapse if we need them */
    #transfer-waybill-template {
        -webkit-print-color-adjust: exact !important;
        print-color-adjust: exact !important;
    }
}

/* ============================================================= */
/* 8. ATTACHMENT FIELD FIX (ALIGNED)                             */
/* ============================================================= */

/* 1. Input Field */
#standard-job-modal #job-attachment {
    width: auto !important;
    flex-grow: 1 !important;
    margin-bottom: 0 !important;
    height: 36px !important; /* Matches other inputs */
}

/* 2. View Button */
#standard-job-modal #job-attachment-view-btn {
    width: 36px !important;
    min-width: 36px !important;
    height: 36px !important;
    padding: 0 !important;
    display: flex !important;
    align-items: center !important;
    justify-content: center !important;
    flex-shrink: 0 !important;
    margin-bottom: 0 !important;

    /* Add Float Effect to Button too for consistency */
    transition: all 0.2s ease-in-out !important;
}

#standard-job-modal #job-attachment-view-btn:hover {
    transform: translateY(-2px) !important;
    box-shadow: 0 4px 8px rgba(0,0,0,0.2) !important;
}

/* 3. Center Icon */
#standard-job-modal #job-attachment-view-btn i {
    font-size: 1rem !important;
    line-height: 1 !important;
    margin: 0 !important;
}

/* ============================================================= */
/* 9. FINAL POLISH: ALIGNMENT & REMOVE SPINNERS                  */
/* ============================================================= */

/* A. Remove Up/Down Arrows from Number Inputs */
input[type=number]::-webkit-inner-spin-button,
input[type=number]::-webkit-outer-spin-button {
    -webkit-appearance: none;
    margin: 0;
}
input[type=number] {
    -moz-appearance: textfield; /* Firefox */
}

/* B. Force Perfect Row Alignment */
/* 1. Prevent labels from wrapping to 2 lines (which breaks alignment) */
#standard-job-modal label {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    height: 16px; /* Fixed Label Height */
    line-height: 16px;
    margin-bottom: 4px !important;
}

/* 2. Force Groups to exact same vertical size */
#standard-job-modal .form-group {
    height: 60px !important; /* Fixed Container Height (Label + Input + Margin) */
    margin-bottom: 0 !important;
    overflow: visible;
}

/* 3. Attachment Row Exception (It's special, so we let it be auto) */
#standard-job-modal .form-group:has(#job-attachment) {
    height: auto !important;
}

/* A. Remove Up/Down Arrows from Number Inputs */
input[type=number]::-webkit-inner-spin-button,
input[type=number]::-webkit-outer-spin-button {
    -webkit-appearance: none;
    margin: 0;
}
input[type=number] {
    -moz-appearance: textfield; /* Firefox */
}

/* --- CRITICAL FIX: Hide buttons when JS adds .hidden class --- */
#standard-job-modal .modal-footer button.hidden,
#ms-new-material-modal .modal-footer button.hidden, /* <--- ADDED THIS */
#transfer-job-modal .modal-footer button.hidden {
    display: none !important;
}

/* Allow Choices dropdown to overlay above other modal content */
#transfer-job-modal .choices,
#ms-new-material-modal .choices { /* <--- ADDED THIS */
  overflow: visible !important;
}

#transfer-job-modal .choices__list--dropdown,
#transfer-job-modal .choices__list[aria-expanded="true"],
#ms-new-material-modal .choices__list--dropdown, /* <--- ADDED THIS */
#ms-new-material-modal .choices__list[aria-expanded="true"] { /* <--- ADDED THIS */
  z-index: 99999 !important;
}

/* ============================================================= */
/* 10. CHOICES.JS: ALWAYS SHOW DROPDOWNS (AUTO UP/DOWN)           */
/* ============================================================= */
/* When a Choices dropdown opens inside a scrollable modal, it can be clipped.
   We temporarily unlock overflow via a class added by JS (.choices-open),
   and we explicitly support the .is-flipped (drop-up) state. */

#transfer-job-modal .modal-content.choices-open,
#ms-new-material-modal .modal-content.choices-open { /* <--- ADDED THIS */
    overflow: visible !important;
}

#transfer-job-modal .choices__list--dropdown,
#transfer-job-modal .choices__list[aria-expanded="true"] {
    z-index: 999999 !important;
}

/* Default dropdown (down) */
#transfer-job-modal .choices[data-type*="select-one"] .choices__list--dropdown {
    top: 100% !important;
    bottom: auto !important;
}

/* Flipped dropdown (up) */
#transfer-job-modal .choices[data-type*="select-one"].is-flipped .choices__list--dropdown {
    top: auto !important;
    bottom: 100% !important;
}
/* ============================================================= */
/* CRITICAL PRINT FIX: FORCE TEMPLATE VISIBILITY                 */
/* ============================================================= */
@media print {
    /* 1. Hide the normal app interface */
    body.printing-waybill #app-container,
    body.printing-waybill .workdesk-sidebar,
    body.printing-waybill .workdesk-main,
    body.printing-waybill .modal-overlay {
        display: none !important;
        visibility: hidden !important;
    }

    /* 2. Reset Body constraints */
    body.printing-waybill {
        background: white !important;
        overflow: visible !important;
        height: auto !important;
    }

    /* 3. Force the Template to appear */
    body.printing-waybill #transfer-waybill-template {
        display: block !important;
        visibility: visible !important;

        /* Override the hiding method */
        position: absolute !important;
        left: 0 !important;
        top: 0 !important;
        margin: 0 !important;

        /* Ensure it fits */
        width: 100% !important;
        z-index: 99999 !important;

        /* Force Colors */
        -webkit-print-color-adjust: exact !important;
        print-color-adjust: exact !important;
    }

    /* 4. Ensure content inside is visible */
    body.printing-waybill #transfer-waybill-template * {
        visibility: visible !important;
    }
}

/* ============================================================= */
/* 11. MULTI-TRANSACTION BATCH STYLES (Added V5.0)               */
/* ============================================================= */

/* Multi-List Container */
#tf-multi-list-container {
    background: #f9f9f9;
    padding: 10px;
    border-radius: 4px;
    border: 1px solid #ddd;
}

/* Table Header */
#tf-batch-table th {
    background-color: #003A5C !important;
    color: white !important;
    font-size: 0.85rem;
    padding: 8px;
    text-align: left;
}

/* Table Cells */
#tf-batch-table td {
    background-color: white;
    font-size: 0.9rem;
    padding: 8px;
    border-bottom: 1px solid #eee;
}

/* Add Button Hover State */
#tf-add-to-list-btn:hover {
    background-color: #e0a800 !important;
}

/* Radio Button Toggle Alignment */
input[name="tf-mode"] {
    width: auto !important;
    height: auto !important;
    margin-right: 5px !important;
    min-height: auto !important;
    display: inline-block !important;
}

