/* Invoice page — document-like grid + Windows-style type modal */

.invoice-page .invoice-customer-meta {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
    gap: 0.75rem 1rem;
    margin-bottom: 1rem;
    padding: 0.85rem 1rem;
    background: rgba(255, 255, 255, 0.55);
    border: 1px solid rgba(0, 0, 0, 0.06);
    border-radius: 10px;
}

.invoice-lookup-field {
    display: flex;
    gap: 0.4rem;
    align-items: stretch;
}

.invoice-lookup-field .form-control {
    flex: 1;
    min-width: 0;
}

.invoice-lookup-field .btn {
    min-width: 2.5rem;
    padding-inline: 0.6rem;
}

.invoice-customer-name-field,
.invoice-address-field {
    grid-column: span 2;
}

/* ===== Invoice items grid: match accounting document ===== */
#webInvoice .accounting-document-table-container {
    max-height: min(52vh, 520px);
}

#webInvoice .accounting-document-table {
    min-width: 1680px;
    width: 100%;
    table-layout: fixed;
    border-collapse: separate;
    border-spacing: 0;
}

#webInvoice .accounting-document-table thead th {
    position: sticky;
    top: 0;
    z-index: 4;
    padding: 8px 6px;
    line-height: 1.2;
    background: linear-gradient(135deg, var(--primary), var(--primary-dark));
    color: #fff;
    font-size: 12.5px;
    font-weight: 700;
    letter-spacing: 0;
    text-align: center;
    vertical-align: middle;
    white-space: nowrap;
}

#webInvoice .accounting-document-table tbody tr {
    background: #fff;
    transition: background .15s ease, box-shadow .15s ease;
}

#webInvoice .accounting-document-table tbody tr:nth-child(even) {
    background: #fafcff;
}

#webInvoice .accounting-document-table tbody tr:hover td {
    background: #f1f7ff;
}

#webInvoice .accounting-document-table tbody tr.selected td {
    background: #e3f2fd;
    box-shadow: inset 0 1px 0 rgba(30, 136, 229, .12), inset 0 -1px 0 rgba(30, 136, 229, .12);
}

#webInvoice .accounting-document-table td {
    height: 48px;
    padding: 0;
    border-bottom: 1px solid #d8e0e8;
    border-left: 1px solid #e5e9ee;
    background: inherit;
    vertical-align: middle;
    text-align: center;
}

#webInvoice .accounting-document-table .form-control,
#webInvoice .accounting-document-table input:not(.wad-cell-input) {
    border: 0 !important;
    box-shadow: none !important;
    background: transparent !important;
    border-radius: 0 !important;
    height: 47px;
    margin: 0;
}

#webInvoice .wad-cell-input {
    width: 100%;
    height: 47px;
    border: 0;
    border-radius: 0;
    background: transparent;
    padding: 0 8px;
    color: var(--text);
    font: inherit;
    font-size: 13px;
    font-weight: 600;
    outline: none;
    text-align: center;
    box-shadow: none;
}

#webInvoice .wad-cell-input:focus {
    position: relative;
    z-index: 2;
    background: #fff;
    box-shadow: inset 0 0 0 2px var(--primary);
}

#webInvoice .wad-cell-input[readonly],
#webInvoice .wad-cell-input.is-computed {
    color: #5f6f7f;
    background: rgba(241, 245, 249, .62);
    font-weight: 700;
}

#webInvoice .wad-cell-input:disabled {
    opacity: 0.72;
    cursor: not-allowed;
}

#webInvoice .wad-account-cell {
    display: flex;
    align-items: center;
    gap: 4px;
    height: 100%;
    min-height: 47px;
    padding: 0 4px 0 6px;
    text-align: right;
}

#webInvoice .wad-account-name {
    flex: 1;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    font-size: 13px;
    font-weight: 600;
    text-align: right;
    padding-inline: 4px;
}

#webInvoice .wad-account-name.is-empty {
    color: #8a97a5;
    font-weight: 500;
}

#webInvoice .wad-account-picker {
    flex: 0 0 auto;
    width: 30px;
    height: 30px;
    border: 0;
    border-radius: 8px;
    background: transparent;
    color: var(--primary);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
}

#webInvoice .wad-account-picker:hover,
#webInvoice .wad-account-picker:focus-visible {
    background: rgba(30, 136, 229, 0.12);
    outline: none;
}

#webInvoice .wad-remove-row {
    width: 32px;
    height: 32px;
    border: 0;
    border-radius: 8px;
    background: transparent;
    color: #c62828;
    font-size: 1.25rem;
    line-height: 1;
    cursor: pointer;
}

#webInvoice .wad-remove-row:hover {
    background: rgba(198, 40, 40, 0.1);
}

/* Column widths */
#webInvoice .wif-col-row { width: 48px; }
#webInvoice .wif-col-store { width: 140px; }
#webInvoice .wif-col-code { width: 130px; }
#webInvoice .wif-col-name { width: 260px; }
#webInvoice .wif-col-qty { width: 78px; }
#webInvoice .wif-col-unit { width: 72px; }
#webInvoice .wif-col-money { width: 118px; }
#webInvoice .wif-col-tax-pct { width: 72px; }
#webInvoice .wif-col-comment { width: 180px; }
#webInvoice .wif-col-actions { width: 44px; }

.invoice-footer {
    margin-top: 1rem;
    padding: 0.9rem 1rem;
    background: rgba(255, 255, 255, 0.7);
    border: 1px solid rgba(0, 0, 0, 0.06);
    border-radius: 10px;
}

.invoice-footer-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
    gap: 0.75rem 1rem;
    align-items: end;
}

.invoice-footer-field {
    display: flex;
    flex-direction: column;
    gap: 0.3rem;
}

.invoice-footer-field label,
.invoice-footer-field > span {
    font-size: 0.82rem;
    color: #5b6470;
}

.invoice-footer-field strong {
    font-size: 1rem;
    color: #1f2933;
    min-height: 2.2rem;
    display: flex;
    align-items: center;
    padding: 0.35rem 0.55rem;
    background: #f7f8fa;
    border-radius: 6px;
    border: 1px solid rgba(0, 0, 0, 0.05);
}

.invoice-footer-net strong {
    background: #e8f7ec;
    color: #146c2e;
    font-size: 1.1rem;
}

.invoice-footer-tax-check {
    justify-content: center;
}

.invoice-check-label {
    display: flex;
    align-items: center;
    gap: 0.45rem;
    font-size: 0.85rem;
    color: #374151;
    cursor: pointer;
    min-height: 2.2rem;
}

/* ===== Invoice type selection modal (card picker, matches payment-type) ===== */
.invoice-type-modal {
    width: min(460px, 100%);
}

.invoice-type-header {
    align-items: flex-start;
}

.invoice-type-body {
    padding: 1rem 1.1rem !important;
    max-height: min(58vh, 420px);
    overflow: auto;
    background: var(--modal-white, #fff);
}

.invoice-type-list {
    list-style: none;
    margin: 0;
    padding: 0;
    display: grid;
    gap: 0.7rem;
}

.invoice-type-card {
    --type-accent: #1e88e5;
    display: grid;
    grid-template-columns: 48px 1fr auto;
    align-items: center;
    gap: 0.85rem;
    width: 100%;
    padding: 0.9rem 1rem;
    border: 1px solid #e2e8f0;
    border-radius: 14px;
    background: #fff;
    text-align: right;
    cursor: pointer;
    font: inherit;
    color: #0f172a;
    transition: border-color .15s ease, box-shadow .15s ease, transform .15s ease;
}

.invoice-type-card:hover {
    border-color: #cbd5e1;
    box-shadow: 0 6px 18px rgba(15, 23, 42, 0.06);
}

.invoice-type-card.is-selected,
.invoice-type-card:focus {
    outline: none;
    transform: translateY(-1px);
    border-color: var(--type-accent);
    box-shadow: 0 0 0 3px color-mix(in srgb, var(--type-accent) 16%, transparent);
}

.invoice-type-card__icon {
    width: 48px;
    height: 48px;
    display: grid;
    place-items: center;
    border-radius: 12px;
    background: color-mix(in srgb, var(--type-accent) 12%, transparent);
    color: var(--type-accent);
}

.invoice-type-card__icon svg {
    width: 24px;
    height: 24px;
}

.invoice-type-card__text {
    display: grid;
    gap: 0.15rem;
    min-width: 0;
}

.invoice-type-card__text strong {
    font-size: 1rem;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.invoice-type-card__text small {
    color: #64748b;
    font-size: 0.8rem;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.invoice-type-card__key {
    width: 28px;
    height: 28px;
    display: grid;
    place-items: center;
    border-radius: 8px;
    background: #f1f5f9;
    color: #475569;
    font-weight: 800;
    font-size: 0.85rem;
}

.invoice-type-card.is-selected .invoice-type-card__key {
    background: color-mix(in srgb, var(--type-accent) 14%, transparent);
    color: var(--type-accent);
}

.invoice-type-message {
    margin: 0 0 0.7rem;
    padding: 12px 14px;
    border-radius: 12px;
    color: #c62828;
    background: #fdecea;
    border: 1px solid #f5c6cb;
    font-weight: 600;
    font-size: 0.9rem;
}

@media (max-width: 900px) {
    .invoice-customer-name-field,
    .invoice-address-field {
        grid-column: span 1;
    }

    #webInvoice .accounting-document-table {
        min-width: 1100px;
    }

    #webInvoice .wif-col-store { width: 110px; }
    #webInvoice .wif-col-name { width: 200px; }
    #webInvoice .wif-col-comment { width: 140px; }
    #webInvoice .wif-col-money { width: 100px; }

    /* ستون‌های ثانویه را در تبلت کوچک‌تر مخفی کن تا اسکرول کوتاه‌تر شود */
    #webInvoice .accounting-document-table thead th:nth-child(10),
    #webInvoice .accounting-document-table tbody td:nth-child(10),
    #webInvoice .accounting-document-table thead th:nth-child(11),
    #webInvoice .accounting-document-table tbody td:nth-child(11),
    #webInvoice .accounting-document-table thead th:nth-child(14),
    #webInvoice .accounting-document-table tbody td:nth-child(14) {
        display: none;
    }

    .invoice-footer-grid {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }

    .invoice-lookup-field .btn {
        min-width: 44px;
        min-height: 44px;
    }
}

@media (max-width: 768px) {
    #webInvoice .accounting-document-table {
        min-width: 920px;
    }

    #webInvoice .accounting-document-table-container {
        max-height: min(55vh, 480px);
        -webkit-overflow-scrolling: touch;
        overscroll-behavior-x: contain;
    }

    /* ستون چسبان: ردیف + کد + نام */
    #webInvoice .accounting-document-table th:nth-child(1),
    #webInvoice .accounting-document-table td:nth-child(1) {
        position: sticky;
        right: 0;
        z-index: 5;
        background: #fff;
        box-shadow: -6px 0 10px -6px rgba(15, 23, 42, .2);
    }

    #webInvoice .accounting-document-table thead th:nth-child(1) {
        z-index: 15;
        background: linear-gradient(135deg, var(--primary), var(--primary-dark));
        color: #fff;
    }

    #webInvoice .accounting-document-table th:nth-child(3),
    #webInvoice .accounting-document-table td:nth-child(3) {
        position: sticky;
        right: 48px;
        z-index: 5;
        background: #fff;
        box-shadow: -6px 0 10px -6px rgba(15, 23, 42, .16);
    }

    #webInvoice .accounting-document-table thead th:nth-child(3) {
        z-index: 15;
        background: linear-gradient(135deg, var(--primary), var(--primary-dark));
        color: #fff;
    }

    #webInvoice .accounting-document-table tbody tr:nth-child(even) td:nth-child(1),
    #webInvoice .accounting-document-table tbody tr:nth-child(even) td:nth-child(3) {
        background: #fafcff;
    }

    #webInvoice .accounting-document-table tbody tr:hover td:nth-child(1),
    #webInvoice .accounting-document-table tbody tr:hover td:nth-child(3) {
        background: #f1f7ff;
    }

    #webInvoice .accounting-document-table tbody tr.selected td:nth-child(1),
    #webInvoice .accounting-document-table tbody tr.selected td:nth-child(3) {
        background: #e3f2fd;
    }

    .invoice-customer-meta {
        grid-template-columns: 1fr;
        padding: 0.75rem;
    }

    .invoice-footer {
        padding: 0.75rem;
    }

    .invoice-footer-field strong {
        min-height: 44px;
        font-size: 0.95rem;
    }

    #webInvoice .accounting-document-table thead th {
        font-size: 11.5px;
        padding: 8px 4px;
    }

    #webInvoice .accounting-document-table td {
        height: 44px;
    }

    #webInvoice .accounting-document-table .form-control,
    #webInvoice .accounting-document-table input:not(.wad-cell-input) {
        height: 43px;
        font-size: 16px !important;
    }
}

@media (max-width: 480px) {
    #webInvoice .accounting-document-table {
        min-width: 820px;
    }

    /* انبار را هم مخفی کن تا فضای حیاتی بماند */
    #webInvoice .accounting-document-table thead th:nth-child(2),
    #webInvoice .accounting-document-table tbody td:nth-child(2) {
        display: none;
    }

    #webInvoice .accounting-document-table th:nth-child(3),
    #webInvoice .accounting-document-table td:nth-child(3) {
        right: 44px;
    }

    .invoice-footer-grid {
        grid-template-columns: 1fr;
    }

    .invoice-type-card {
        grid-template-columns: 44px 1fr auto;
        padding: 0.85rem 0.9rem;
        min-height: 56px;
    }
}
