/* Copyright (c) Zhmara X. All rights reserved.
   Proprietary and confidential. Unauthorized copying of this file, via any medium, is prohibited. See LICENSE.txt. */

/* Document line pickers (LineWarehousePicker / LineStockPicker): small labelled chips under the line's item. */

.line-picker {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 6px;
    margin-top: 6px;
}

.lp-field {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    height: 30px;
    margin: 0;
    padding: 0 4px 0 10px;
    border: 1px solid var(--bs-border-color, #dee2e6);
    border-radius: 999px;
    background: var(--bs-tertiary-bg, #f8f9fa);
    font-size: .8125rem;
    line-height: 1;
    cursor: pointer;
    transition: border-color .15s, box-shadow .15s, background-color .15s;
}

[dir="rtl"] .lp-field {
    padding: 0 10px 0 4px;
}

.lp-field:hover {
    border-color: rgba(var(--bs-primary-rgb, 13, 110, 253), .45);
    background: var(--bs-body-bg, #fff);
}

.lp-field:focus-within {
    border-color: var(--bs-primary, #0d6efd);
    background: var(--bs-body-bg, #fff);
    box-shadow: 0 0 0 3px rgba(var(--bs-primary-rgb, 13, 110, 253), .15);
}

.lp-field > i {
    color: var(--bs-primary, #0d6efd);
    font-size: .875rem;
}

.lp-field > .lp-label {
    color: var(--bs-secondary-color, #6c757d);
    font-weight: 500;
    white-space: nowrap;
}

.lp-field > select {
    min-width: 70px;
    max-width: 190px;
    height: 100%;
    padding: 0 22px 0 2px;
    border: 0;
    outline: 0;
    -webkit-appearance: none;
    appearance: none;
    background: transparent url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'%3e%3cpath fill='none' stroke='%236c757d' stroke-linecap='round' stroke-linejoin='round' stroke-width='2' d='m2 5 6 6 6-6'/%3e%3c/svg%3e") no-repeat right 6px center / 10px 10px;
    color: var(--bs-body-color, #212529);
    font-size: .8125rem;
    font-weight: 600;
    cursor: pointer;
    text-overflow: ellipsis;
}

[dir="rtl"] .lp-field > select {
    padding: 0 2px 0 22px;
    background-position: left 6px center;
}

/* Nothing chosen yet (variant / batch / warehouse): amber hint. */
.lp-field.lp-empty {
    border-color: var(--bs-warning, #ffc107);
    background: var(--bs-warning-bg-subtle, #fff3cd);
}

.lp-field.lp-empty > i {
    color: var(--bs-warning-text-emphasis, #997404);
}

.lp-field:has(select:disabled) {
    opacity: .65;
    cursor: default;
}

.lp-field select:disabled {
    cursor: default;
}

.lp-add {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 30px;
    height: 30px;
    padding: 0;
    border: 1px dashed rgba(var(--bs-primary-rgb, 13, 110, 253), .6);
    border-radius: 50%;
    background: transparent;
    color: var(--bs-primary, #0d6efd);
    transition: background-color .15s, color .15s;
}

.lp-add:hover,
.lp-add.active {
    border-style: solid;
    background: var(--bs-primary, #0d6efd);
    color: #fff;
}

.lp-stock {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    height: 30px;
    padding: 0 10px;
    border-radius: 999px;
    background: var(--bs-success-bg-subtle, #d1e7dd);
    color: var(--bs-success-text-emphasis, #0a3622);
    font-size: .8125rem;
    font-weight: 600;
    white-space: nowrap;
}

.lp-stock.lp-stock-out {
    background: var(--bs-danger-bg-subtle, #f8d7da);
    color: var(--bs-danger-text-emphasis, #58151c);
}

/* New batch pop-up (LineStockPicker). Fixed on screen so the line table never clips it; its layer (z-index) is in layers.css. */
.lp-modal-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(15, 23, 42, .45);
}

.lp-modal {
    position: fixed;
    top: 50%;
    left: 50%;
    width: min(440px, calc(100vw - 32px));
    transform: translate(-50%, -50%);
    border-radius: 10px;
    background: var(--bs-body-bg, #fff);
    box-shadow: 0 20px 50px rgba(0, 0, 0, .25);
    text-align: start;
    white-space: normal;
}

.lp-modal-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 12px;
    padding: 16px 18px 12px;
    border-bottom: 1px solid var(--bs-border-color, #dee2e6);
}

.lp-modal-body {
    display: flex;
    flex-direction: column;
    gap: 12px;
    padding: 16px 18px;
}

.lp-modal-footer {
    display: flex;
    justify-content: flex-end;
    gap: 8px;
    padding: 12px 18px 16px;
    border-top: 1px solid var(--bs-border-color, #dee2e6);
}

.lp-nb-dates {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
}

.lp-modal .lp-nb-field {
    display: flex;
    flex-direction: column;
    gap: 4px;
    margin: 0;
}

.lp-modal .lp-nb-field > span {
    color: var(--bs-secondary-color, #6c757d);
    font-size: .8125rem;
    font-weight: 500;
}

/* Wider chip for long names (account). */
.lp-field.lp-wide > select {
    max-width: 260px;
}

/* Document line table (Purchase Bill, Sales Invoice): each line is its own <tbody> with two rows -
   main row (item, variant / batch, qty, rate, tax, discount, amount) and a second row split in 3
   (description, warehouse, account). Lines are separated by a border instead of stripes. */
.doc-lines > tbody > tr > td {
    padding-top: 14px;
    padding-bottom: 14px;
    vertical-align: top;
}

.doc-lines > tbody.dl-line > tr.dl-main > td {
    padding-bottom: 6px;
    border-bottom: 0;
}

.doc-lines > tbody.dl-line > tr.dl-sub > td {
    padding-top: 0;
    padding-bottom: 14px;
    border-bottom: 1px solid var(--bs-border-color, #dee2e6);
}

.doc-lines > tbody.dl-line:hover > tr > td {
    --bs-table-bg-state: rgba(var(--bs-primary-rgb, 13, 110, 253), .03);
}

.doc-lines .dl-item {
    width: 200px;
    min-width: 160px;
    max-width: 220px;
}

/* Long item names wrap onto at most two lines (full name on hover). */
.doc-lines .dl-name {
    display: -webkit-box;
    overflow: hidden;
    padding-top: 7px;
    color: var(--bs-emphasis-color, #000);
    font-weight: 600;
    line-height: 1.35;
    white-space: normal;
    word-break: break-word;
    -webkit-box-orient: vertical;
    -webkit-line-clamp: 2;
}

/* Variant, unit, batch and "+" on one line. */
.doc-lines .dl-opts .line-picker {
    flex-wrap: nowrap;
    margin-top: 0;
}

.doc-lines .dl-sub-grid {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 10px;
    align-items: center;
}

@media (max-width: 767.98px) {
    .doc-lines .dl-sub-grid {
        grid-template-columns: minmax(0, 1fr);
    }
}

.doc-lines .dl-sub-grid .line-picker {
    margin-top: 0;
}

.doc-lines .dl-sub-grid .lp-field {
    width: 100%;
}

.doc-lines .dl-sub-grid .lp-field > select {
    flex: 1 1 auto;
    max-width: none;
}

.doc-lines .dl-qty {
    width: 140px;
    flex-wrap: nowrap;
}

.doc-lines .dl-qty > .input-group-text {
    max-width: 70px;
    overflow: hidden;
    font-size: .75rem;
    text-overflow: ellipsis;
}

.doc-lines .dl-hint {
    display: block;
    margin-top: 4px;
    color: var(--bs-secondary-color, #6c757d);
    font-size: .75rem;
}

.doc-lines .dl-amount {
    display: block;
    padding-top: 7px;
    font-size: .9375rem;
    font-weight: 700;
    white-space: nowrap;
}

.doc-lines .dl-actions {
    width: 1%;
    padding-top: 18px;
}

/* "Select an item" list: goods and services share one row layout - name, then a badge (stock or "Service"). */
.options li.item-option {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    height: auto;
    min-height: 36px;
    padding: 6px 12px;
}

.item-option .io-name {
    flex: 1 1 auto;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.item-option .io-badge {
    flex-shrink: 0;
    padding: 2px 10px;
    border-radius: 999px;
    font-size: .75rem;
    font-weight: 600;
    white-space: nowrap;
}

.item-option .io-stock {
    background: var(--bs-success-bg-subtle, #d1e7dd);
    color: var(--bs-success-text-emphasis, #0a3622);
}

.item-option .io-out {
    background: var(--bs-danger-bg-subtle, #f8d7da);
    color: var(--bs-danger-text-emphasis, #58151c);
}

.item-option .io-service {
    background: var(--bs-info-bg-subtle, #cff4fc);
    color: var(--bs-info-text-emphasis, #055160);
}

/* Document header (master) as a grid: the stacked "label | field" rows become cards of label-above-field,
   3 per row on wide screens, 2 on tablets, 1 on phones. Anything that is not a field row
   (bank payment box, alerts, tables) spans the full width. Notes (textarea) span the full width too. */
.doc-master {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 0 24px;
    align-items: start;
}

.doc-master.row {
    display: grid;
    margin-left: 0;
    margin-right: 0;
}

/* Bootstrap .row (loaded after this file) gives its children gutter padding and a top margin - not wanted in the grid. */
.doc-master.row > * {
    margin-top: 0;
    padding-left: 0;
    padding-right: 0;
}

@media (max-width: 1199.98px) {
    .doc-master {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }
}

@media (max-width: 767.98px) {
    .doc-master {
        grid-template-columns: minmax(0, 1fr);
    }
}

.doc-master > * {
    grid-column: 1 / -1;
}

.doc-master > .row {
    grid-column: auto;
    display: flex;
    flex-direction: column;
    min-width: 0;
    margin: 0 0 16px;
}

.doc-master > .row > * {
    flex: none;
    width: 100%;
    max-width: 100%;
    padding-left: 0;
    padding-right: 0;
}

.doc-master > .row > .col-form-label {
    padding-top: 0;
    padding-bottom: 6px;
    font-weight: 500;
}

/* Field rows are the direct .row children (form-group row, input-block row, row form-group ...). */
/* The supplier / customer picker floats; keep it inside its cell. */
.doc-master > .row > div {
    display: flow-root;
}

.doc-master > .row:has(textarea) {
    grid-column: 1 / -1;
}

/* Read-only chip (variant / batch on return lines - they come from the original document). */
.lp-field.lp-static {
    padding: 0 12px 0 10px;
    font-weight: 600;
    cursor: default;
}

.lp-field.lp-static:hover {
    border-color: var(--bs-border-color, #dee2e6);
    background: var(--bs-tertiary-bg, #f8f9fa);
}

/* Two-option toggle (Income / Outcome: Customer | Supplier). The radio inputs stay for binding but are hidden. */
.zx-segment {
    display: flex;
    gap: 4px;
    height: 38px;
    padding: 3px;
    border: 1px solid var(--bs-border-color, #dee2e6);
    border-radius: 8px;
    background: var(--bs-tertiary-bg, #f8f9fa);
}

.zx-segment-opt {
    position: relative;
    display: flex;
    flex: 1 1 0;
    align-items: center;
    justify-content: center;
    gap: 6px;
    margin: 0;
    border-radius: 6px;
    color: var(--bs-secondary-color, #6c757d);
    font-size: .875rem;
    font-weight: 500;
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
    transition: background-color .15s, color .15s, box-shadow .15s;
}

.zx-segment-opt input {
    position: absolute;
    width: 1px;
    height: 1px;
    opacity: 0;
    pointer-events: none;
}

.zx-segment-opt:hover {
    color: var(--bs-body-color, #212529);
}

.zx-segment-opt.active {
    background: var(--bs-primary, #0d6efd);
    color: #fff;
    box-shadow: 0 1px 3px rgba(0, 0, 0, .15);
}

.zx-segment-opt:has(input:focus-visible) {
    outline: 2px solid rgba(var(--bs-primary-rgb, 13, 110, 253), .5);
    outline-offset: 1px;
}

/* Amount box with its currency code (MoneyCode). */
.money-group {
    flex-wrap: nowrap;
}

.money-group > .money-code {
    min-width: 46px;
    justify-content: center;
    color: var(--bs-secondary-color, #6c757d);
    font-size: .75rem;
    font-weight: 600;
    letter-spacing: .02em;
}
