/* NexifyERP - Professional Form Styling */
/* Consistent form styling across all modules */

/* ==================== Numeric alignment ==================== */
/* Every numeric input is right-aligned by default so digits line up
   Excel-style. Override with `class="... text-left"` for the rare
   number field that should stay left (barcodes, IMEI, etc.). */
input[type="number"] {
    text-align: right;
}

/* ==================== Form Inputs ==================== */
.form-input,
input[type="text"],
input[type="email"],
input[type="password"],
input[type="number"],
input[type="date"],
input[type="datetime-local"],
input[type="time"],
input[type="tel"],
input[type="url"],
input[type="search"],
textarea,
select {
    width: 100%;
    padding: 0.5rem 0.75rem;
    font-size: 0.875rem;
    line-height: 1.5;
    height: 2.5rem; /* 40px - consistent height for all inputs */
    color: #374151;
    background-color: #ffffff;
    border: 1px solid #d1d5db;
    border-radius: 0.375rem;
    transition: border-color 0.15s ease-in-out, box-shadow 0.15s ease-in-out;
}

/* Textarea needs auto height */
textarea {
    height: auto;
    padding: 0.75rem 1rem !important; /* Explicit padding for textarea */
}

/* Focus State */
.form-input:focus,
input[type="text"]:focus,
input[type="email"]:focus,
input[type="password"]:focus,
input[type="number"]:focus,
input[type="date"]:focus,
input[type="datetime-local"]:focus,
input[type="time"]:focus,
input[type="tel"]:focus,
input[type="url"]:focus,
input[type="search"]:focus,
textarea:focus,
select:focus {
    outline: none;
    border-color: #3b82f6;
    box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.1);
}

/* Disabled State */
.form-input:disabled,
input[type="text"]:disabled,
input[type="email"]:disabled,
input[type="password"]:disabled,
input[type="number"]:disabled,
input[type="date"]:disabled,
input[type="datetime-local"]:disabled,
input[type="time"]:disabled,
textarea:disabled,
select:disabled {
    background-color: #f9fafb;
    border-color: #e5e7eb;
    color: #9ca3af;
    cursor: not-allowed;
}

/* ==================== Textarea ==================== */
textarea {
    min-height: 80px;
    resize: vertical;
    padding: 0.75rem 1rem !important; /* Explicit left/right padding */
}

/* ==================== Select Dropdown ==================== */
select {
    /* Match exact height with inputs */
    height: 2.5rem; /* 40px */
    padding: 0.5rem 2.5rem 0.5rem 1rem !important; /* top right bottom left - explicit padding */
    background-image: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' fill='none' viewBox='0 0 20 20'%3e%3cpath stroke='%236b7280' stroke-linecap='round' stroke-linejoin='round' stroke-width='1.5' d='M6 8l4 4 4-4'/%3e%3c/svg%3e");
    background-position: right 0.5rem center;
    background-repeat: no-repeat;
    background-size: 1.5em 1.5em;
    appearance: none;
    -webkit-appearance: none;
    -moz-appearance: none;
}

select::-ms-expand {
    display: none;
}

/* Multiple select */
select[multiple] {
    height: auto;
    min-height: 5rem;
    padding: 0.75rem 1rem !important; /* Consistent padding for multiple select */
    background-image: none;
}

/* Select option padding */
select option {
    padding: 0.5rem 1rem; /* Padding for dropdown options */
}

/* ==================== Checkbox & Radio ==================== */
input[type="checkbox"],
input[type="radio"] {
    width: 1rem;
    height: 1rem;
    border: 1px solid #d1d5db;
    border-radius: 0.25rem;
    color: #3b82f6;
    cursor: pointer;
    transition: all 0.15s ease-in-out;
}

input[type="radio"] {
    border-radius: 50%;
}

input[type="checkbox"]:checked,
input[type="radio"]:checked {
    background-color: #3b82f6;
    border-color: #3b82f6;
}

input[type="checkbox"]:focus,
input[type="radio"]:focus {
    outline: none;
    box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.1);
}

/* ==================== Form Labels ==================== */
.form-label,
label {
    display: inline-block;
    font-size: 0.875rem;
    font-weight: 500;
    color: #374151;
    margin-bottom: 0.375rem;
}

/* ==================== Input with Icon ==================== */
.input-icon-wrapper {
    position: relative;
}

.input-icon-wrapper .icon-left {
    position: absolute;
    left: 0.75rem;
    top: 50%;
    transform: translateY(-50%);
    color: #9ca3af;
    pointer-events: none;
}

.input-icon-wrapper .icon-right {
    position: absolute;
    right: 0.75rem;
    top: 50%;
    transform: translateY(-50%);
    color: #9ca3af;
    pointer-events: none;
}

.input-icon-wrapper.has-icon-left input {
    padding-left: 2.5rem;
}

.input-icon-wrapper.has-icon-right input {
    padding-right: 2.5rem;
}

/* ==================== Error State ==================== */
.form-input.error,
input.error,
textarea.error,
select.error {
    border-color: #ef4444;
}

.form-input.error:focus,
input.error:focus,
textarea.error:focus,
select.error:focus {
    border-color: #ef4444;
    box-shadow: 0 0 0 3px rgba(239, 68, 68, 0.1);
}

.form-error,
.error-message {
    color: #ef4444;
    font-size: 0.875rem;
    margin-top: 0.25rem;
}

/* ==================== Success State ==================== */
.form-input.success,
input.success,
textarea.success,
select.success {
    border-color: #10b981;
}

.form-input.success:focus,
input.success:focus,
textarea.success:focus,
select.success:focus {
    border-color: #10b981;
    box-shadow: 0 0 0 3px rgba(16, 185, 129, 0.1);
}

/* ==================== Form Groups ==================== */
.form-group {
    margin-bottom: 1rem;
}

.form-group label {
    display: block;
    margin-bottom: 0.5rem;
}

/* ==================== Input Sizes ==================== */
.form-input-sm,
input.form-input-sm,
select.form-input-sm,
textarea.form-input-sm {
    padding: 0.375rem 0.625rem;
    font-size: 0.8125rem;
    height: 2rem; /* 32px */
}

textarea.form-input-sm {
    height: auto;
    padding: 0.5rem 0.75rem !important; /* Proper padding for small textarea */
}

select.form-input-sm {
    padding: 0.375rem 2.25rem 0.375rem 0.875rem !important; /* More left padding */
}

select.form-input-sm option {
    padding: 0.375rem 0.875rem;
}

.form-input-lg,
input.form-input-lg,
select.form-input-lg,
textarea.form-input-lg {
    padding: 0.625rem 0.875rem;
    font-size: 1rem;
    height: 3rem; /* 48px */
}

textarea.form-input-lg {
    height: auto;
    padding: 0.875rem 1.125rem !important; /* Proper padding for large textarea */
}

select.form-input-lg {
    padding: 0.625rem 2.75rem 0.625rem 1.125rem !important; /* More left padding */
}

select.form-input-lg option {
    padding: 0.625rem 1.125rem;
}

/* ==================== Read-only State ==================== */
.form-input:read-only,
input:read-only,
textarea:read-only {
    background-color: #f9fafb;
    cursor: default;
}

/* ==================== Required Field Indicator ==================== */
.required,
label .required {
    color: #ef4444;
    margin-left: 0.125rem;
}

/* ==================== Help Text ==================== */
.form-help,
.help-text {
    color: #6b7280;
    font-size: 0.8125rem;
    margin-top: 0.25rem;
}

/* ==================== File Input ==================== */
input[type="file"] {
    padding: 0.375rem 0.5rem;
    font-size: 0.875rem;
    cursor: pointer;
}

input[type="file"]::-webkit-file-upload-button {
    padding: 0.375rem 0.75rem;
    margin-right: 0.75rem;
    background-color: #f3f4f6;
    border: 1px solid #d1d5db;
    border-radius: 0.375rem;
    cursor: pointer;
    transition: background-color 0.15s ease-in-out;
}

input[type="file"]::-webkit-file-upload-button:hover {
    background-color: #e5e7eb;
}

/* ==================== Search Input ==================== */
input[type="search"] {
    padding-right: 2.5rem;
}

input[type="search"]::-webkit-search-cancel-button {
    -webkit-appearance: none;
    appearance: none;
}

/* ==================== Form Buttons ==================== */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0.5rem 1rem;
    font-size: 0.875rem;
    font-weight: 500;
    line-height: 1.5;
    border-radius: 0.375rem;
    border: 1px solid transparent;
    cursor: pointer;
    transition: all 0.15s ease-in-out;
}

.btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.btn-primary {
    background-color: #3b82f6;
    color: #ffffff;
}

.btn-primary:hover:not(:disabled) {
    background-color: #2563eb;
}

.btn-secondary {
    background-color: #6b7280;
    color: #ffffff;
}

.btn-secondary:hover:not(:disabled) {
    background-color: #4b5563;
}

.btn-success {
    background-color: #10b981;
    color: #ffffff;
}

.btn-success:hover:not(:disabled) {
    background-color: #059669;
}

.btn-danger {
    background-color: #ef4444;
    color: #ffffff;
}

.btn-danger:hover:not(:disabled) {
    background-color: #dc2626;
}

.btn-outline {
    background-color: transparent;
    border: 1px solid #d1d5db;
    color: #374151;
}

.btn-outline:hover:not(:disabled) {
    background-color: #f9fafb;
}

/* ==================== Select2 ==================== */
/* Single Select */
.select2-container--default .select2-selection--single {
    background-color: #fff;
    border: 1px solid #d1d5db;
    border-radius: 0.375rem;
    height: 38px;
}

.select2-container--default .select2-selection--single .select2-selection__rendered {
    color: #374151;
    line-height: 36px;
    padding-left: 12px;
    padding-right: 32px;
}

.select2-container--default .select2-selection--single .select2-selection__clear {
    position: absolute;
    top: 50%;
    right: 28px;
    transform: translateY(-50%);
    margin: 0;
    padding: 0;
    line-height: 1;
    font-size: 16px;
    color: #6b7280;
    float: none;
}

.select2-container--default .select2-selection--single .select2-selection__arrow {
    top: 50%;
    height: 20px;
    transform: translateY(-50%);
}

/* ==================== yajra datatable issue ==================== */
table.dataTable th.text-center,
table.dataTable td.text-center {
    text-align: center !important;
}

table.dataTable th.text-right,
table.dataTable td.text-right {
    text-align: right !important;
}

/* ==================== Responsive Design ==================== */
@media (max-width: 640px) {
    .form-input,
    input,
    textarea,
    select {
        font-size: 1rem; /* Prevents zoom on iOS */
    }
}
/* ==================== modal ==================== */
.modal-content {
    background: white;
    border-radius: 0.75rem;
    box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.1), 0 10px 10px -5px rgba(0, 0, 0, 0.04);
    max-width: 100%;
    min-width: 35rem;
    padding: 1.5rem;
}

/* ==================== File Inputs ==================== */
/* Style native file input so the "Choose File" button reads as part of the
   same bordered container. Matches the phone-input "+880" badge pattern —
   gray-50 background on the left, single vertical divider, one border around
   the whole thing. Values track .form-input above so every field on a form
   sits at the same height (2.5rem) and uses the same border color/radius. */
input[type="file"] {
    width: 100%;
    height: 2.5rem;
    padding: 0;
    font-size: 0.875rem;
    line-height: 1.5;
    color: #374151;
    background-color: #ffffff;
    border: 1px solid #d1d5db;
    border-radius: 0.375rem;
    overflow: hidden;
    transition: border-color 0.15s ease-in-out, box-shadow 0.15s ease-in-out;
}
input[type="file"]:focus {
    outline: none;
    border-color: #3b82f6;
    box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.1);
}
input[type="file"]:disabled {
    background-color: #f9fafb;
    color: #9ca3af;
    cursor: not-allowed;
}
input[type="file"]::file-selector-button {
    height: 100%;
    padding: 0 1rem;
    margin-right: 0.75rem;
    font-size: 0.875rem;
    color: #374151;
    background-color: #f9fafb;
    border: 0;
    border-right: 1px solid #d1d5db;
    cursor: pointer;
    transition: background-color 0.15s ease-in-out;
}
input[type="file"]::file-selector-button:hover {
    background-color: #f3f4f6;
}

/* ==================== Mobile list-page ergonomics ==================== *
 * Two rules only, both gated behind max-width: 767px — desktop layout
 * is literally unreachable and unchanged.
 *
 * 1. Filter forms collapse behind a toggle button (mobile-list.js injects
 *    the button and manages the `.mobile-filter-collapsed` class).
 * 2. Tables become horizontally scrollable containers on narrow screens
 *    without any HTML change — merchant finger-scrolls to see wide columns.
 */
.mobile-filter-toggle { display: none; }

/* ==================== DataTables toolbar (all viewports) ====================
   Length dropdown + search input on ONE compact row. Without these overrides,
   the global `select { width: 100%; height: 2.5rem }` at the top of this file
   stretches the length dropdown to fill its <label>, which forces the "Show"
   and "entries" text nodes to wrap onto separate lines — creating the tall
   stacked-vertical toolbar. These rules pin the length select to 70px and
   the filter input to a compact height so both stay inline.

   Previously scoped to @media (max-width: 767px) — moved to top-level because
   desktop suffered the same stacking bug. Nothing here is mobile-only. */
.dataTables_wrapper .dataTables_length,
.dataTables_wrapper .dataTables_filter {
    text-align: left !important;
    margin: 0 0 8px 0 !important;
    padding: 0;
}
.dataTables_wrapper .dataTables_length { float: left !important;  width: auto !important; }
.dataTables_wrapper .dataTables_filter { float: right !important; width: auto !important; }
.dataTables_wrapper .dataTables_filter label {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    margin: 0;
    font-size: 0.75rem;
    line-height: 30px;
    color: #6b7280;
}
.dataTables_wrapper .dataTables_length label {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    margin: 0;
    font-size: 0;
    line-height: 30px;
    color: #6b7280;
}
.dataTables_wrapper .dataTables_length label::before {
    content: 'Show';
    font-size: 0.75rem;
}
.dataTables_wrapper .dataTables_length select,
.dataTables_wrapper .dataTables_length option,
.dataTables_wrapper .dataTables_filter input {
    height: 30px !important;
    padding: 4px 8px !important;
    font-size: 0.75rem !important;
    line-height: 1 !important;
    border: 1px solid #d1d5db;
    border-radius: 4px;
    background: #fff;
    vertical-align: middle;
    box-sizing: border-box;
}
.dataTables_wrapper .dataTables_length select {
    width: 70px !important;
    min-width: 70px !important;
    margin-left: 4px;
}
.dataTables_wrapper .dataTables_filter input {
    width: 130px !important;
    margin-left: 4px;
}
.dataTables_wrapper .dataTables_info,
.dataTables_wrapper .dataTables_paginate { clear: both; }

@media (max-width: 767px) {
    .mobile-filter-toggle {
        display: flex;
        width: 100%;
        justify-content: space-between;
        align-items: center;
        padding: 10px 14px;
        background: #f3f4f6;
        border: 1px solid #d1d5db;
        border-radius: 6px;
        margin-bottom: 12px;
        font-weight: 500;
        color: #374151;
        cursor: pointer;
        font-size: 0.875rem;
    }
    .mobile-filter-toggle .mft-badge {
        background: #3b82f6; color: #fff;
        padding: 2px 8px; border-radius: 10px;
        font-size: 0.75rem; min-width: 22px; text-align: center;
        display: inline-block;
    }
    .mobile-filter-collapsed { display: none !important; }

    /* Table horizontal scroll on mobile. display:block converts the table
       into a scrollable container while preserving all cell/row semantics
       for merchant reading. nowrap keeps rows on one line so the horizontal
       scroll is meaningful (not visually collapsed).
       :not(.dataTable) — DataTables handles its own overflow via the
       Responsive plugin (column hiding + expander rows). Applying
       display:block on a DataTable would break its column layout and
       leave empty width on narrow screens. */
    table:not(.dataTable) {
        display: block;
        overflow-x: auto;
        white-space: nowrap;
        -webkit-overflow-scrolling: touch;
        max-width: 100%;
    }
    /* When the page already wraps its table in an .overflow-x-auto div,
       let the wrapper handle horizontal scroll and keep the table in
       native table-layout. Otherwise we'd get two nested scroll containers
       and mobile finger-scroll behaves unpredictably. */
    .overflow-x-auto > table:not(.dataTable) {
        display: table;
        white-space: normal;
    }
    .dataTables_wrapper {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }

    /* --------------------------------------------------------------
       Block A: page header (title + primary action) stacks vertically.
       Uses :has(h1) — descendant, not direct child — to catch all
       header variants across 66 list pages:
         • Variant A: <div class="flex justify-between"><h1>..</h1><a/></div>
         • Variant B: <div class="flex justify-between"><div><h1/><p/></div><a/></div>
         • Variant C: <div class="flex items-center justify-between">..<div><h1/></div>..</div>
       Safe against inner-card headers with <h2> — those don't match.
       Verified no list page has more than one <h1>.
       -------------------------------------------------------------- */
    /* Header stays HORIZONTAL on mobile — button remains to the right
       of the title. Title flex-shrinks (min-w-0 + ellipsis) so it can't
       push the button off-screen; button gets compact padding + smaller
       font, flex-shrink:0 so it never squishes. Applies to all three
       header variants — direct h1, wrapped h1, and alt-class-order. */
    .flex.justify-between:has(h1) {
        align-items: center;
        gap: 0.5rem;
        /* NO flex-direction change — row layout preserved */
    }
    /* Title container — flexes, shrinkable. Direct h1 OR wrapping div. */
    .flex.justify-between:has(h1) > h1,
    .flex.justify-between:has(h1) > div:has(> h1) {
        flex: 1 1 auto;
        min-width: 0;
    }
    .flex.justify-between:has(h1) h1 {
        font-size: 1rem;
        line-height: 1.5rem;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
    }
    /* Action button — compact, never shrinks. Covers direct child + wrapped
       button patterns (Variants A/B/C). */
    .flex.justify-between:has(h1) > a,
    .flex.justify-between:has(h1) > button,
    .flex.justify-between:has(h1) > div > a.btn,
    .flex.justify-between:has(h1) > div > button.btn,
    .flex.justify-between:has(h1) > div > a[class*="bg-"],
    .flex.justify-between:has(h1) > div > button[class*="bg-"] {
        flex-shrink: 0;
        padding: 6px 10px !important;
        font-size: 0.75rem !important;
        white-space: nowrap;
        display: inline-flex;
        align-items: center;
    }

    /* Block B: DataTables toolbar rules moved to top-level (line ~522)
       so they apply on desktop too. See the "DataTables toolbar (all
       viewports)" section above the mobile media query. */

    /* Pagination compact on mobile. Buttons shrink, "Previous"/"Next"
       text collapsed to ‹ / › arrows to fit more page numbers in a row.
       Container already centers by DataTables default. */
    .dataTables_wrapper .dataTables_paginate {
        padding: 8px 0 !important;
        font-size: 0.75rem !important;
    }
    .dataTables_wrapper .dataTables_paginate .paginate_button {
        padding: 4px 10px !important;
        font-size: 0.75rem !important;
        margin: 2px !important;
        min-width: 28px;
        text-align: center;
    }
    /* Replace "Previous" and "Next" with arrow glyphs on mobile — saves
       ~120px of width so more numeric page buttons fit on one row. */
    .dataTables_wrapper .dataTables_paginate .paginate_button.previous,
    .dataTables_wrapper .dataTables_paginate .paginate_button.next {
        font-size: 0 !important;
        padding: 4px 10px !important;
    }
    .dataTables_wrapper .dataTables_paginate .paginate_button.previous::before {
        content: '‹';
        font-size: 1.1rem;
        line-height: 1;
    }
    .dataTables_wrapper .dataTables_paginate .paginate_button.next::before {
        content: '›';
        font-size: 1.1rem;
        line-height: 1;
    }
    /* Info row (Showing X of Y): smaller on mobile */
    .dataTables_wrapper .dataTables_info {
        font-size: 0.7rem !important;
        padding: 6px 0 !important;
    }
}