/* ========================================================================== 
   ICYLAB OS - Finanzas sobre contrato visual CRM
   Sólo contiene variantes funcionales de Billing. El layout proviene de
   09-crm-ui.css y no se redefine por módulo.
   ========================================================================== */

/* General ---------------------------------------------------------------- */
.billing-phase-content,
.manual-issuer-content {
    gap: 0 !important;
}


.billing-page-header-actions .btn-primary,
.billing-page-header-actions .btn-success,
#billingDocumentsMain #reloadDocumentsBtn,
#billingReceiveMain #reloadReceiveBtn,
#billingReceivablesMain #reloadReceivablesBtn,
#billingPayablesMain #reloadPayablesBtn,
#billingCustomerAgingMain #reloadCustomerAgingBtn,
#billingSupplierAgingMain #reloadAgingBtn {
    background: var(--color-primary) !important;
    border-color: var(--color-primary) !important;
    color: var(--text-inverse) !important;
}

.billing-alert {
    flex: 0 0 auto;
    margin: 0 0 var(--space-4);
    padding: 12px 14px;
    border: 1px solid #bfdbfe;
    border-radius: var(--radius-xl);
    background: #eff6ff;
    color: #1e3a8a;
}

[data-theme="dark"] .billing-alert {
    background: rgba(30, 64, 175, .12);
    border-color: rgba(96, 165, 250, .32);
    color: #bfdbfe;
}

.billing-muted {
    margin: 0;
    color: var(--text-muted);
    font-size: .86rem;
}

/* Page-specific filter grids --------------------------------------------- */
#billingDocumentsMain .crm-ui-filter,
#billingReceivablesMain .crm-ui-filter,
#billingPayablesMain .crm-ui-filter {
    --crm-filter-columns: minmax(280px, 1fr) 220px minmax(300px, 360px);
}

#billingCustomerAgingMain .crm-ui-filter,
#billingSupplierAgingMain .crm-ui-filter {
    --crm-filter-columns: minmax(280px, 1fr) 220px 220px;
}

#billingReceiveMain .crm-ui-filter {
    --crm-filter-columns: minmax(150px, 1.05fr) minmax(180px, 1.25fr) minmax(130px, .9fr) minmax(100px, .7fr) minmax(180px, 1.25fr) 124px;
}

#billingReceiveMain .crm-ui-filter #receivePo,
#billingReceiveMain .crm-ui-filter-actions {
    grid-column: span 1;
}

@media (min-width: 981px) and (max-width: 1280px) {
    #billingReceiveMain .crm-ui-filter {
        --crm-filter-columns: repeat(3, minmax(0, 1fr));
    }

    #billingReceiveMain .crm-ui-filter #receivePo {
        grid-column: span 2;
    }

    #billingReceiveMain .crm-ui-filter-actions {
        grid-column: span 1;
    }
}

/* Tabs ------------------------------------------------------------------- */
.receive-tabs {
    flex: 0 0 auto;
    display: flex;
    gap: 8px;
    align-items: center;
    width: 100%;
    margin: 0 0 var(--space-4);
    padding: 2px 0;
    overflow-x: auto;
    overflow-y: hidden;
    scrollbar-width: none;
}

.receive-tabs::-webkit-scrollbar {
    display: none;
}

.receive-tab {
    min-height: 40px;
    padding: 0 14px;
    border: 1px solid transparent;
    border-radius: var(--radius-full);
    background: transparent;
    color: var(--text-secondary);
    font-weight: 700;
    white-space: nowrap;
    cursor: pointer;
}

.receive-tab:hover {
    background: var(--surface-2);
}

.receive-tab.is-active {
    background: #e0f2fe;
    border-color: #bae6fd;
    color: #0369a1;
}

/* KPI values inherit the shared CRM .kpi-card component. ---------------- */

/* Bulk bars -------------------------------------------------------------- */
.billing-bulkbar > div:first-child,
.receive-bulk-actions {
    min-width: 0;
}

.billing-bulkbar > div:first-child {
    display: flex;
    align-items: center;
    gap: 14px;
    flex-wrap: wrap;
}

:is(.receivables-actions,.payables-actions,.receive-bulk-actions) {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 8px;
    flex-wrap: nowrap;
}

.receive-selected-count {
    min-height: 40px;
    display: inline-flex;
    align-items: center;
    padding: 0 11px;
    border: 1px solid var(--border-default);
    border-radius: var(--radius-md);
    background: var(--surface-2);
    color: var(--text-primary);
    font-size: .86rem;
    font-weight: 700;
}

.receive-info-note {
    flex: 0 0 auto;
    padding: 12px 16px;
    border-top: 1px solid #bae6fd;
    background: #e0f2fe;
    color: #0369a1;
    font-size: .86rem;
}

/* Table widths ----------------------------------------------------------- */
.documents-table {
    --crm-mobile-columns: 82px minmax(0, 1fr) 94px 64px;
}

.receivables-table,
.payables-table,
.receive-table {
    --crm-mobile-columns: 46px minmax(0, 1fr) 94px 64px;
}

.customer-aging-table,
.aging-table {
    --crm-mobile-columns: minmax(0, 1fr) 104px 64px;
}

.documents-table .col-folio { width: 90px; }
.documents-table .col-client { width: 22%; }
.documents-table .col-total { width: 120px; }
.documents-table .col-action { width: 76px; }

.receivables-table .col-select,
.payables-table .col-select,
.receive-table .col-select { width: 46px; text-align: center; }

.receivables-table .col-counterparty,
.payables-table .col-counterparty,
.receive-table .col-counterparty { width: 22%; }

.receivables-table .col-balance,
.payables-table .col-balance { width: 118px; }

.receive-table .col-amount { width: 118px; }

.receivables-table .col-action,
.payables-table .col-action,
.receive-table .col-action,
.customer-aging-table .col-action,
.aging-table .col-action { width: 76px; text-align: center; }

.documents-money,
.receivables-table .money,
.payables-number,
.customer-aging-money,
.aging-money {
    text-align: right;
    white-space: nowrap;
    font-weight: 700;
}

/* Normalise generated action buttons ------------------------------------ */
:is(.documents-table,.receivables-table,.payables-table,.receive-table,.customer-aging-table,.aging-table) .btn[data-id],
:is(.documents-table,.receivables-table,.payables-table,.receive-table,.customer-aging-table,.aging-table) .btn[data-receive-id],
:is(.documents-table,.receivables-table,.payables-table,.receive-table,.customer-aging-table,.aging-table) .btn[data-receivable-detail],
:is(.documents-table,.receivables-table,.payables-table,.receive-table,.customer-aging-table,.aging-table) .btn[data-payable-detail],
:is(.documents-table,.receivables-table,.payables-table,.receive-table,.customer-aging-table,.aging-table) .btn[data-aging-detail],
:is(.documents-table,.receivables-table,.payables-table,.receive-table,.customer-aging-table,.aging-table) .btn[data-customer-aging-detail] {
    width: 40px !important;
    min-width: 40px !important;
    max-width: 40px !important;
    height: 40px !important;
    min-height: 40px !important;
    padding: 0 !important;
    border: 1px solid var(--border-default) !important;
    border-radius: var(--radius-lg) !important;
    background: var(--surface-1) !important;
    color: var(--text-primary) !important;
    font-size: 0 !important;
}

/* Billing-only feedback -------------------------------------------------- */
.billing-save-confirmation {
    display: inline-flex;
    align-items: center;
    gap: 7px;
    padding: 0 8px;
    color: #15803d;
    font-weight: 800;
}

/* Receive detail --------------------------------------------------------- */
.receive-decision-grid {
    grid-template-columns: minmax(0, 1fr) minmax(360px, 46%);
}

.receive-pdf-box {
    height: 100%;
    min-height: 520px;
    padding: 12px;
    display: flex;
    flex-direction: column;
    gap: 8px;
    border-radius: var(--radius-xl);
    background: #222;
}

.receive-pdf-frame {
    width: 100%;
    min-height: 480px;
    height: 100%;
    border: 0;
    border-radius: var(--radius-lg);
    background: #fff;
}

/* Manual issuer ---------------------------------------------------------- */
.manual-launch-card {
    flex: 0 0 auto;
    margin: 0 0 var(--space-4);
}

.manual-type-grid {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 14px;
}

.manual-type-card {
    min-width: 0;
    display: flex;
    gap: 14px;
    align-items: flex-start;
    padding: 18px;
    border: 1px solid var(--border-default);
    border-radius: var(--radius-xl);
    background: var(--surface-1);
    box-shadow: var(--shadow-sm);
}

.manual-environment-badge {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    min-height: 40px;
    padding: 0 13px;
    border: 1px solid var(--border-default);
    border-radius: var(--radius-full);
    background: var(--surface-1);
    color: var(--text-secondary);
    font-size: .84rem;
    font-weight: 700;
}

.manual-environment-badge > span {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: #f59e0b;
}

.manual-environment-badge.is-production > span {
    background: #16a34a;
}

.manual-action-card {
    min-height: 230px;
    display: flex;
    flex-direction: column;
    align-items: stretch;
    gap: 14px;
    transition: transform .16s ease, border-color .16s ease, box-shadow .16s ease;
}

.manual-action-card:hover {
    transform: translateY(-2px);
    border-color: color-mix(in srgb, var(--color-primary) 40%, var(--border-default));
    box-shadow: var(--shadow-md);
}

.manual-card-icon {
    width: 44px;
    height: 44px;
    display: grid;
    place-items: center;
    border-radius: 13px;
    background: color-mix(in srgb, var(--color-primary) 10%, var(--surface-1));
}

.manual-card-copy {
    flex: 1 1 auto;
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.manual-card-copy strong {
    font-size: 1.02rem;
}

.manual-card-copy span {
    color: var(--text-secondary);
    line-height: 1.45;
}

.manual-card-actions {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
}

.manual-card-actions .btn {
    min-height: 38px;
    flex: 1 1 auto;
}

.manual-card-actions-compact .btn {
    flex-basis: calc(50% - 4px);
    padding-inline: 10px;
    font-size: .78rem;
}

.manual-commercial-card {
    margin-top: var(--space-4);
    border-color: color-mix(in srgb, var(--color-primary) 25%, var(--border-default));
}

.manual-commercial-row,
.manual-commercial-copy {
    display: flex;
    align-items: center;
    gap: 16px;
}

.manual-commercial-row {
    justify-content: space-between;
}

.manual-commercial-copy {
    min-width: 0;
}

.manual-commercial-copy h3,
.manual-commercial-copy p {
    margin: 3px 0 0;
}

.manual-commercial-icon {
    width: 48px;
    height: 48px;
    display: grid;
    place-items: center;
    flex: 0 0 auto;
    border-radius: 14px;
    background: color-mix(in srgb, var(--color-primary) 11%, var(--surface-1));
    color: var(--color-primary);
}

.manual-commercial-icon svg {
    width: 25px;
    height: 25px;
}

.manual-stepbar {
    flex: 0 0 auto;
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 10px;
    margin-bottom: 18px;
}

.manual-stepbar span {
    padding: 11px 12px;
    border: 1px solid var(--border-default);
    border-radius: var(--radius-full);
    background: var(--surface-1);
    text-align: center;
    font-size: .86rem;
    font-weight: 700;
}

.manual-stepbar span.is-active {
    background: var(--color-primary);
    border-color: var(--color-primary);
    color: var(--text-inverse);
}

/* Responsive ------------------------------------------------------------- */
@media (max-width: 980px), (hover: none) and (pointer: coarse) {
    body #billingReceiveMain .crm-ui-filter {
        grid-template-columns: repeat(2, minmax(0, 1fr)) !important;
    }

    body #billingReceiveMain .crm-ui-filter #receivePo,
    body #billingReceiveMain .crm-ui-filter-actions {
        grid-column: span 1 !important;
    }

    .receive-tabs {
        margin-bottom: var(--space-3);
    }

    .crm-ui-table-toolbar-copy {
        display: none;
    }

    .crm-ui-bulkbar,
    .receive-results-head {
        flex-direction: row;
        align-items: center;
    }

    .billing-bulkbar > div:first-child {
        flex: 1 1 auto;
        gap: 6px 12px;
    }

    :is(.receivables-actions,.payables-actions,.receive-bulk-actions) {
        flex: 0 0 auto;
    }

    :is(.receivables-actions,.payables-actions,.receive-bulk-actions) .btn {
        width: 42px;
        min-width: 42px;
        max-width: 42px;
        height: 42px;
        min-height: 42px;
        padding: 0;
        font-size: 0;
    }

    :is(.receivables-actions,.payables-actions,.receive-bulk-actions) .btn span {
        display: none;
    }

    .receive-selected-count {
        min-width: 42px;
        padding: 0 10px;
    }

    .receive-info-note {
        padding: 10px 12px;
        font-size: .78rem;
        line-height: 1.35;
    }

    .crm-ui-mobile-table .crm-mobile-hidden {
        display: none !important;
    }

    .crm-ui-mobile-table .crm-mobile-primary strong,
    .crm-ui-mobile-table .crm-mobile-primary span:first-child {
        display: block;
        width: 100%;
        min-width: 0;
        max-width: 100%;
        font-size: .82rem;
        line-height: 1.12;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
    }

    .crm-ui-mobile-table .crm-mobile-metric strong {
        font-size: .82rem;
        white-space: nowrap;
    }

    .billing-modal-box .crm-ui-inner-table-wrap {
        max-height: 300px;
        overflow-y: auto;
        overflow-x: hidden;
    }

    .billing-modal-box .crm-ui-inner-table {
        width: 100%;
        min-width: 0;
        max-width: 100%;
        table-layout: fixed;
        font-size: .76rem;
    }

    .receive-pdf-box {
        min-height: 420px;
    }

    .manual-stepbar {
        display: flex;
        overflow-x: auto;
        gap: 8px;
    }

    .manual-stepbar span {
        min-width: 128px;
    }
}

/* ========================================================================== 
   Billing domain components on top of the CRM visual contract
   ========================================================================== */

.billing-environment-control {
    min-width: 0;
    display: inline-flex;
    align-items: center;
    gap: 8px;
    color: var(--text-secondary);
}

.billing-environment-control > svg,
.billing-environment-control > i {
    width: 18px;
    height: 18px;
    flex: 0 0 auto;
}

.billing-alert-info {
    border-color: #bfdbfe;
    background: #eff6ff;
    color: #1e3a8a;
}

.billing-alert-warning,
.documents-warning,
.receive-warning,
.manual-alert-warning {
    border-color: #fed7aa;
    background: #fff7ed;
    color: #9a3412;
}

.billing-alert-success,
.documents-success,
.manual-alert-success {
    border-color: #bbf7d0;
    background: #f0fdf4;
    color: #166534;
}

.billing-alert-error,
.documents-layer-error,
.manual-alert-error {
    border-color: #fecaca;
    background: #fef2f2;
    color: #991b1b;
}

[data-theme="dark"] :is(.billing-alert-info,.billing-alert-warning,.billing-alert-success,.billing-alert-error,.documents-warning,.documents-success,.documents-layer-error,.receive-warning,.manual-alert) {
    background: color-mix(in srgb, currentColor 9%, var(--surface-1));
    border-color: color-mix(in srgb, currentColor 28%, var(--border-default));
}

.documents-muted,
.receivables-muted,
.payables-muted,
.receive-muted,
.customer-aging-muted,
.aging-muted {
    color: var(--text-muted);
    font-size: .86rem;
}

/* Status tokens ----------------------------------------------------------- */
.documents-pill,
.receivables-status,
.payables-status,
.receive-status,
.customer-aging-pill,
.aging-pill {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 24px;
    max-width: 100%;
    padding: 4px 9px;
    border-radius: var(--radius-full);
    background: #eef2ff;
    color: #3730a3;
    font-size: .74rem;
    font-weight: 800;
    line-height: 1.05;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.documents-pill.credit_note,
.receivables-status.pagado,
.payables-status.pagado,
.receive-status.approved,
.receive-status.approved_with_observations,
.receive-status.merchandise_received,
.customer-aging-pill.is-ok,
.aging-pill.is-ok {
    background: #dcfce7;
    color: #166534;
}

.documents-pill.debit_note,
.receivables-status.parcial,
.payables-status.parcial,
.receive-status.pending,
.customer-aging-pill.is-warning,
.aging-pill.is-warning {
    background: #fef3c7;
    color: #92400e;
}

.receivables-status.atrasado,
.payables-status.vencido,
.receive-status.rejected,
.receive-status.error,
.customer-aging-pill.is-danger,
.aging-pill.is-danger {
    background: #fee2e2;
    color: #991b1b;
}

.documents-pill.dispatch_guide {
    background: #e0f2fe;
    color: #075985;
}

.documents-pill.export {
    background: #f3e8ff;
    color: #6b21a8;
}

.receivables-status.incobrable,
.receivables-status.anulado,
.payables-status.rechazado,
.payables-status.anulado {
    background: var(--surface-2);
    color: var(--text-secondary);
}

/* CRM-like table text and controls --------------------------------------- */
:is(.documents-table,.receivables-table,.payables-table,.receive-table,.customer-aging-table,.aging-table) input[type="checkbox"],
.billing-modal-box input[type="checkbox"] {
    width: 17px;
    height: 17px;
    accent-color: var(--color-primary);
}

:is(.documents-table,.receivables-table,.payables-table,.receive-table,.customer-aging-table,.aging-table) tbody tr[hidden],
:is(.documents-table,.receivables-table,.payables-table,.receive-table,.customer-aging-table,.aging-table) tbody tr.is-filter-hidden {
    display: none !important;
}

.billing-selection-summary {
    min-width: 0;
}

.billing-selection-summary strong,
.billing-selection-summary span {
    min-width: 0;
}

/* Documents -------------------------------------------------------------- */
.documents-flow-steps,
.guide-steps {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 8px;
    margin-bottom: 14px;
}

.guide-steps {
    grid-template-columns: repeat(5, minmax(0, 1fr));
}

.documents-flow-step,
.guide-step {
    min-width: 0;
    padding: 8px 10px;
    border: 1px solid var(--border-default);
    border-radius: var(--radius-full);
    background: var(--surface-1);
    color: var(--text-secondary);
    text-align: center;
    font-size: .75rem;
    font-weight: 800;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.documents-flow-step.active,
.guide-step.active,
.guide-source-tab.active {
    border-color: var(--color-primary);
    background: var(--color-primary);
    color: var(--text-inverse);
}

.documents-layer-error {
    display: none;
    margin-bottom: 12px;
    padding: 11px 13px;
    border: 1px solid;
    border-radius: var(--radius-lg);
}

.documents-layer-error.show {
    display: block;
}

.documents-confirm-card,
.documents-readonly,
.receivables-readonly,
.payables-readonly-status,
.payables-resolution {
    min-width: 0;
    padding: 11px 12px;
    border: 1px solid var(--border-default);
    border-radius: var(--radius-lg);
    background: var(--surface-2);
    color: var(--text-primary);
}

.documents-confirm-card {
    padding: 16px;
    background: var(--surface-1);
}

.documents-file-actions,
.receivables-file-actions,
.receive-pdf-toolbar {
    min-width: 0;
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
}

.documents-preview-frame,
.manual-preview-frame {
    width: 100%;
    height: min(60vh, 680px);
    border: 1px solid var(--border-default);
    border-radius: var(--radius-lg);
    background: #fff;
}

.guide-source-tabs {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
    margin-bottom: 12px;
}

.guide-source-list {
    display: grid;
    gap: 10px;
    margin-top: 12px;
}

.guide-source-item {
    min-width: 0;
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    align-items: center;
    gap: 12px;
    padding: 12px;
    border: 1px solid var(--border-default);
    border-radius: var(--radius-lg);
    background: var(--surface-1);
}

.guide-source-meta {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
    color: var(--text-muted);
    font-size: .84rem;
}

.guide-lines-table {
    width: 100%;
    border-collapse: collapse;
}

.guide-lines-table th,
.guide-lines-table td {
    padding: 9px;
    border-bottom: 1px solid var(--border-subtle);
    text-align: left;
    vertical-align: middle;
}

.guide-preview-note {
    margin-bottom: 12px;
    padding: 11px 13px;
    border: 1px solid #bfdbfe;
    border-radius: var(--radius-lg);
    background: #eff6ff;
    color: #1e3a8a;
}

/* Receivables / Payables ------------------------------------------------- */
.receivables-number,
.payables-number {
    white-space: nowrap;
    text-align: right;
    font-weight: 700;
}

.receivables-grid,
.payables-grid,
.payables-grid-3,
.receive-result-grid,
.receive-form-grid,
.receive-bulk-grid {
    min-width: 0;
}

.receivables-history-wrap,
.payables-history-wrap,
.customer-aging-detail-wrap,
.aging-detail-table-wrap,
.receive-lines-wrap,
.manual-lines-wrap {
    max-width: 100%;
}

.payables-resolution {
    margin-top: 12px;
}

/* Receive DTE ------------------------------------------------------------ */
.receive-bulk-summary,
.receive-bulk-doc {
    min-width: 0;
    padding: 14px;
    border: 1px solid var(--border-default);
    border-radius: var(--radius-lg);
    background: var(--surface-1);
}

.receive-bulk-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 12px;
}

.receive-pdf-toolbar {
    justify-content: space-between;
    color: #fff;
    font-size: .86rem;
}

.receive-glossary {
    display: grid;
    gap: 8px;
    margin-top: 10px;
    color: var(--text-muted);
    font-size: .82rem;
}

.receive-dot {
    display: inline-block;
    width: 8px;
    height: 8px;
    margin-right: 6px;
    border-radius: 50%;
    background: currentColor;
}

.receive-row-check {
    display: grid;
    place-items: center;
}

/* Manual issuer ---------------------------------------------------------- */
.manual-launch-filter {
    --crm-filter-columns: 150px minmax(260px, 1fr) auto;
}

.manual-launch-field {
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.manual-launch-field > .label {
    display: none;
}

.manual-launch-action .btn {
    height: 44px;
    min-height: 44px;
    white-space: nowrap;
}

.manual-types-card .card-body {
    flex: 1 1 auto;
    min-height: 0;
    overflow-y: auto;
    overflow-x: hidden;
    padding: var(--space-4);
}

.manual-type-card svg,
.manual-type-card i {
    width: 24px;
    height: 24px;
    flex: 0 0 auto;
    color: var(--color-primary);
}

.manual-type-card > div {
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: 5px;
}

.manual-type-card span {
    color: var(--text-secondary);
    font-size: .88rem;
    line-height: 1.35;
}

.manual-panel {
    margin-bottom: 14px;
}

.manual-panel h3 {
    margin: 0 0 14px;
}

.manual-grid {
    grid-template-columns: repeat(3, minmax(0, 1fr)) !important;
}

.manual-grid-2 {
    grid-template-columns: repeat(2, minmax(0, 1fr)) !important;
}

.manual-search-row,
.manual-quote-selector-row {
    min-width: 0;
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    gap: 10px;
    align-items: end;
}

.manual-search-results {
    display: grid;
    gap: 8px;
    max-height: 220px;
    margin-top: 10px;
    overflow-y: auto;
}

.manual-search-item,
.search-result-item {
    width: 100%;
    min-width: 0;
    padding: 11px 13px;
    border: 1px solid var(--border-default);
    border-radius: var(--radius-lg);
    background: var(--surface-1);
    color: var(--text-primary);
    text-align: left;
    cursor: pointer;
}

.manual-search-item strong,
.search-result-item strong {
    display: block;
}

.manual-search-item small,
.manual-search-item span,
.search-result-item small,
.search-result-item span {
    display: block;
    margin-top: 2px;
    color: var(--text-secondary);
    font-size: .78rem;
}

.manual-search-item.is-muted,
.search-result-item.is-muted {
    cursor: default;
}

.manual-autocomplete-wrap {
    position: relative;
    min-width: 0;
}

.manual-autocomplete-results {
    position: absolute;
    z-index: 40;
    top: calc(100% + 6px);
    left: 0;
    right: 0;
    display: none;
    max-height: 260px;
    margin: 0;
    overflow-y: auto;
    border: 1px solid var(--border-default);
    border-radius: var(--radius-lg);
    background: var(--surface-1);
    box-shadow: var(--shadow-lg);
}

.manual-autocomplete-results.show {
    display: grid;
}

.manual-autocomplete-results .search-result-item {
    border: 0;
    border-bottom: 1px solid var(--border-subtle);
    border-radius: 0;
}

.manual-master-data-note {
    margin-top: 12px;
    color: var(--text-secondary);
    font-size: .86rem;
}

.manual-empty-lines {
    padding: 24px;
    border-radius: var(--radius-lg);
    background: var(--surface-2);
    color: var(--text-secondary);
    text-align: center;
}

.manual-product-selector-row {
    margin-bottom: 14px;
}

.manual-lines-table-quote .manual-primary-line td {
    vertical-align: top;
}

.manual-lines-table-quote .manual-advanced-line td {
    padding-top: 0;
    background: var(--surface-2);
}

.manual-line-adjustments {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 10px;
    padding: 10px 0 14px;
}

.manual-line-adjustments .manual-field > span {
    font-size: .7rem;
}

.manual-line-description {
    min-width: 220px;
}

.manual-line-total {
    white-space: nowrap;
    font-weight: 800;
}

.manual-alert {
    margin-bottom: 14px;
    padding: 14px 16px;
    border: 1px solid var(--border-default);
    border-radius: var(--radius-lg);
}

.manual-alert-info {
    border-color: #a9cffb;
    background: #eef6ff;
    color: #174b86;
}

.manual-source-selected {
    padding: 14px;
    border: 1px solid color-mix(in srgb, var(--color-primary) 45%, transparent);
    border-radius: var(--radius-lg);
    background: color-mix(in srgb, var(--color-primary) 6%, var(--surface-1));
}

.manual-hidden {
    display: none !important;
}

/* Purchase orders -------------------------------------------------------- */
.purchase-orders-page {
    gap: var(--space-4);
}

.po-information {
    margin: 0;
}

.po-filter-form {
    display: grid;
    grid-template-columns: minmax(260px, 1fr) 190px auto auto;
    gap: 10px;
    padding: var(--space-3);
}

.po-table-scroll {
    overflow: auto;
}

.po-table {
    min-width: 920px;
}

.po-table td > strong,
.po-table td > small {
    display: block;
}

.po-table td > small {
    margin-top: 4px;
    color: var(--text-muted);
}

.po-row-actions {
    display: flex;
    justify-content: flex-end;
    gap: 7px;
}

.po-empty {
    min-height: 220px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 8px;
    color: var(--text-muted);
}

.po-empty svg {
    width: 34px;
    height: 34px;
}

.po-modal-box {
    width: min(1220px, calc(100vw - 32px));
    height: min(850px, calc(100vh - 32px));
}

.po-modal-body {
    overflow-y: auto;
}

.po-stepbar {
    grid-template-columns: repeat(4, minmax(0, 1fr));
}

.po-wizard-panel {
    padding: 20px;
    border: 1px solid var(--border-default);
    border-radius: var(--radius-xl);
    background: var(--surface-1);
}

.po-field {
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: 7px;
}

.po-field > span,
.po-email-form label > span {
    color: var(--text-secondary);
    font-size: .82rem;
    font-weight: 700;
}

.po-field-wide {
    grid-column: span 2;
}

.po-search-results {
    display: flex;
    flex-direction: column;
    gap: 7px;
    max-height: 390px;
    margin-top: 12px;
    overflow-y: auto;
}

.po-product-results:empty {
    display: none;
}

.po-search-option {
    width: 100%;
    min-height: 62px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    padding: 11px 14px;
    border: 1px solid var(--border-default);
    border-radius: var(--radius-lg);
    background: var(--surface-1);
    color: var(--text-primary);
    text-align: left;
    cursor: pointer;
}

.po-search-option:hover {
    border-color: var(--color-primary);
    background: color-mix(in srgb, var(--color-primary) 5%, var(--surface-1));
}

.po-search-option span:first-child,
.po-search-option small {
    display: flex;
    flex-direction: column;
    gap: 3px;
}

.po-search-option small,
.po-search-hint {
    color: var(--text-muted);
}

.po-search-hint {
    padding: 22px;
    text-align: center;
}

.po-search-error {
    color: var(--color-danger);
}

.po-selected-summary {
    display: flex;
    flex: 1 1 auto;
    flex-direction: column;
    gap: 3px;
}

.po-selected-summary span {
    color: var(--text-muted);
    font-size: .82rem;
}

.po-product-toolbar {
    display: grid;
    grid-template-columns: minmax(260px, 1fr) auto;
    gap: 12px;
    align-items: end;
}

.po-items-scroll {
    margin-top: 14px;
    overflow-x: auto;
}

.po-items-editor,
.po-review-table {
    width: 100%;
    min-width: 880px;
    border-collapse: collapse;
}

.po-items-editor th,
.po-items-editor td,
.po-review-table th,
.po-review-table td {
    padding: 9px 7px;
    border-bottom: 1px solid var(--border-default);
    text-align: left;
    vertical-align: middle;
}

.po-items-editor th,
.po-review-table th {
    color: var(--text-muted);
    font-size: .75rem;
    text-transform: uppercase;
}

.po-items-editor .input {
    min-width: 76px;
}

.po-items-editor .po-line-description {
    min-width: 240px;
}

.po-editor-total {
    display: flex;
    justify-content: flex-end;
    align-items: baseline;
    gap: 14px;
    padding-top: 15px;
}

.po-editor-total strong {
    font-size: 1.2rem;
}

.po-form-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 15px;
}

.po-review-layout {
    display: grid;
    grid-template-columns: minmax(0, 1fr) 300px;
    gap: 16px;
    align-items: start;
}

.po-review-meta {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 10px;
    margin-top: 18px;
}

.po-review-meta > span {
    display: flex;
    flex-direction: column;
    gap: 4px;
    padding: 11px;
    border-radius: var(--radius-lg);
    background: var(--surface-2);
}

.po-review-meta small,
.po-review-table small {
    display: block;
    color: var(--text-muted);
}

.po-total-card {
    padding: 20px;
    border: 1px solid color-mix(in srgb, var(--color-primary) 30%, var(--border-default));
    border-radius: var(--radius-xl);
    background: color-mix(in srgb, var(--color-primary) 4%, var(--surface-1));
}

.po-total-card > span,
.po-total-card > strong {
    display: block;
}

.po-total-card > strong {
    margin-top: 7px;
    font-size: 1.45rem;
}

.po-total-card dl {
    margin: 20px 0;
}

.po-total-card dl div {
    display: flex;
    justify-content: space-between;
    padding: 7px 0;
    border-bottom: 1px solid var(--border-default);
}

.po-total-card p {
    display: flex;
    gap: 7px;
    color: var(--text-muted);
    font-size: .8rem;
    line-height: 1.45;
}

.po-result {
    max-width: 620px;
    margin: 30px auto;
    text-align: center;
}

.po-result-icon {
    width: 64px;
    height: 64px;
    display: grid;
    place-items: center;
    margin: 0 auto 16px;
    border-radius: 50%;
    background: #dcfce7;
    color: #15803d;
}

.po-result-total {
    display: flex;
    justify-content: center;
    align-items: baseline;
    gap: 10px;
    margin: 24px 0;
}

.po-result-total strong {
    font-size: 1.35rem;
}

.po-result-actions {
    display: flex;
    justify-content: center;
    gap: 10px;
    flex-wrap: wrap;
}

.po-email-box {
    width: min(680px, calc(100vw - 32px));
}

.po-email-form {
    display: flex;
    flex-direction: column;
    gap: 14px;
}

.po-email-form label {
    display: flex;
    flex-direction: column;
    gap: 7px;
}

/* Responsive domain rules ------------------------------------------------ */
@media (max-width: 1280px) {
    .billing-kpi-grid.crm-ui-kpis {
        grid-template-columns: repeat(3, minmax(0, 1fr));
    }

    .manual-type-grid {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }

    .manual-grid,
    .manual-grid-2 {
        grid-template-columns: repeat(2, minmax(0, 1fr)) !important;
    }
}

@media (max-width: 980px), (hover: none) and (pointer: coarse) {
    .billing-alert {
        margin-bottom: var(--space-3);
        padding: 10px 12px;
        font-size: .78rem;
        line-height: 1.35;
    }


    .documents-flow-steps,
    .guide-steps {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }

    .customer-aging-payment-grid,
    .aging-payment-grid,
    .receive-bulk-grid {
        grid-template-columns: minmax(0, 1fr);
    }

    .manual-launch-filter {
        grid-template-columns: minmax(0, 1fr) !important;
    }

    .manual-type-grid {
        grid-template-columns: minmax(0, 1fr);
    }

    .manual-action-card {
        min-height: 0;
    }

    .manual-commercial-row {
        align-items: stretch;
        flex-direction: column;
    }

    .po-filter-form,
    .po-product-toolbar,
    .po-form-grid,
    .po-review-layout {
        grid-template-columns: minmax(0, 1fr);
    }

    .po-field-wide {
        grid-column: span 1;
    }

    .po-stepbar {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }

    .po-modal-box {
        width: 100vw;
        height: 100vh;
        max-height: none;
        border-radius: 0;
    }

    .manual-grid,
    .manual-grid-2 {
        grid-template-columns: minmax(0, 1fr) !important;
    }

    .manual-line-adjustments {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }

    .billing-modal-footer .modal-footer-actions-left .btn {
        width: 44px !important;
        min-width: 44px !important;
        max-width: 44px !important;
        padding: 0 !important;
        flex: 0 0 44px !important;
    }

    .billing-modal-footer .modal-footer-actions-left .btn span {
        display: none !important;
    }

    .billing-modal-footer:has(.modal-footer-actions-right .btn:nth-child(3)) .modal-footer-actions-right .btn {
        width: 44px !important;
        min-width: 44px !important;
        max-width: 44px !important;
        padding: 0 !important;
        flex: 0 0 44px !important;
    }

    .billing-modal-footer:has(.modal-footer-actions-right .btn:nth-child(3)) .modal-footer-actions-right .btn span {
        display: none !important;
    }

    /* Modal tables: keep two or three decision fields and the action. */
    .documents-lines th:nth-child(1),
    .documents-lines td:nth-child(1),
    .documents-lines th:nth-child(4),
    .documents-lines td:nth-child(4),
    .documents-lines th:nth-child(5),
    .documents-lines td:nth-child(5) {
        display: none;
    }

    .documents-lines th:nth-child(2),
    .documents-lines td:nth-child(2) { width: auto; }
    .documents-lines th:nth-child(3),
    .documents-lines td:nth-child(3) { width: 70px; }
    .documents-lines th:nth-child(6),
    .documents-lines td:nth-child(6) { width: 92px; }

    .documents-history--references th:nth-child(1),
    .documents-history--references td:nth-child(1),
    .documents-history--references th:nth-child(3),
    .documents-history--references td:nth-child(3) { display: none; }

    .documents-history--notes th:nth-child(2),
    .documents-history--notes td:nth-child(2),
    .documents-history--notes th:nth-child(5),
    .documents-history--notes td:nth-child(5),
    .documents-history--notes th:nth-child(6),
    .documents-history--notes td:nth-child(6) { display: none; }

    .documents-history--guides th:nth-child(1),
    .documents-history--guides td:nth-child(1),
    .documents-history--guides th:nth-child(2),
    .documents-history--guides td:nth-child(2),
    .documents-history--guides th:nth-child(5),
    .documents-history--guides td:nth-child(5) { display: none; }

    :is(.receivables-history,.payables-payment-history) th:nth-child(4),
    :is(.receivables-history,.payables-payment-history) td:nth-child(4),
    :is(.receivables-history,.payables-payment-history) th:nth-child(5),
    :is(.receivables-history,.payables-payment-history) td:nth-child(5),
    :is(.receivables-history,.payables-payment-history) th:nth-child(6),
    :is(.receivables-history,.payables-payment-history) td:nth-child(6) {
        display: none;
    }

    :is(.receivables-history,.payables-payment-history) th:nth-child(1),
    :is(.receivables-history,.payables-payment-history) td:nth-child(1) { width: 82px; }
    :is(.receivables-history,.payables-payment-history) th:nth-child(2),
    :is(.receivables-history,.payables-payment-history) td:nth-child(2) { width: 92px; }

    /* Aging cliente: Folio + Saldo + Acción. */
    .customer-aging-detail--documents th:nth-child(1),
    .customer-aging-detail--documents td:nth-child(1),
    .customer-aging-detail--documents th:nth-child(2),
    .customer-aging-detail--documents td:nth-child(2),
    .customer-aging-detail--documents th:nth-child(4),
    .customer-aging-detail--documents td:nth-child(4),
    .customer-aging-detail--documents th:nth-child(5),
    .customer-aging-detail--documents td:nth-child(5),
    .customer-aging-detail--documents th:nth-child(6),
    .customer-aging-detail--documents td:nth-child(6),
    .customer-aging-detail--documents th:nth-child(8),
    .customer-aging-detail--documents td:nth-child(8),
    .customer-aging-detail--documents th:nth-child(9),
    .customer-aging-detail--documents td:nth-child(9) {
        display: none;
    }

    /* Aging proveedor: Folio + Saldo + Acción. */
    .aging-detail-table--documents th:nth-child(2),
    .aging-detail-table--documents td:nth-child(2),
    .aging-detail-table--documents th:nth-child(3),
    .aging-detail-table--documents td:nth-child(3),
    .aging-detail-table--documents th:nth-child(4),
    .aging-detail-table--documents td:nth-child(4),
    .aging-detail-table--documents th:nth-child(5),
    .aging-detail-table--documents td:nth-child(5),
    .aging-detail-table--documents th:nth-child(6),
    .aging-detail-table--documents td:nth-child(6),
    .aging-detail-table--documents th:nth-child(8),
    .aging-detail-table--documents td:nth-child(8),
    .aging-detail-table--documents th:nth-child(9),
    .aging-detail-table--documents td:nth-child(9) {
        display: none;
    }

    .customer-aging-detail--documents th:nth-child(3),
    .customer-aging-detail--documents td:nth-child(3),
    .aging-detail-table--documents th:nth-child(1),
    .aging-detail-table--documents td:nth-child(1) { width: 92px; }

    :is(.customer-aging-detail--documents,.aging-detail-table--documents) th:nth-child(7),
    :is(.customer-aging-detail--documents,.aging-detail-table--documents) td:nth-child(7) { width: 96px; }
    :is(.customer-aging-detail--documents,.aging-detail-table--documents) th:nth-child(10),
    :is(.customer-aging-detail--documents,.aging-detail-table--documents) td:nth-child(10) { width: 72px; }

    :is(.customer-aging-detail--history,.aging-detail-table--history) th:nth-child(4),
    :is(.customer-aging-detail--history,.aging-detail-table--history) td:nth-child(4) {
        display: none;
    }

    .receive-lines th:nth-child(2),
    .receive-lines td:nth-child(2),
    .receive-lines th:nth-child(4),
    .receive-lines td:nth-child(4),
    .receive-lines th:nth-child(6),
    .receive-lines td:nth-child(6) {
        display: none;
    }

    .receive-lines th:nth-child(3),
    .receive-lines td:nth-child(3) { width: 76px; }
    .receive-lines th:nth-child(5),
    .receive-lines td:nth-child(5) { width: 108px; }

    .manual-lines-table th:nth-child(2),
    .manual-lines-table td:nth-child(2),
    .manual-lines-table th:nth-child(4),
    .manual-lines-table td:nth-child(4),
    .manual-lines-table th:nth-child(6),
    .manual-lines-table td:nth-child(6) {
        display: none;
    }

    .manual-lines-table th:nth-child(3),
    .manual-lines-table td:nth-child(3) { width: 64px; }
    .manual-lines-table th:nth-child(5),
    .manual-lines-table td:nth-child(5) { width: 88px; }
    .manual-lines-table th:nth-child(7),
    .manual-lines-table td:nth-child(7) { width: 48px; text-align: center; }

    .manual-lines-table .input,
    .manual-line-description {
        width: 100%;
        min-width: 0 !important;
        padding: 8px 6px;
        font-size: .78rem;
    }

    .manual-advanced-line td {
        display: table-cell !important;
    }
}

@media (max-width: 360px) {
    .manual-line-adjustments {
        grid-template-columns: minmax(0, 1fr);
    }
}

/* Receive DTE: CRM-density adaptation ----------------------------------- */
.receive-mobile-tab-control {
    display: none;
}

@media (min-width: 981px) {
    body #billingReceiveMain .filter-bar-container.crm-ui-filter {
        --crm-filter-columns: minmax(170px, 1.05fr) minmax(190px, 1.15fr) minmax(140px, .9fr) 120px minmax(190px, 1.1fr) 124px;
    }

    body #billingReceiveMain .filter-bar-container.crm-ui-filter #receivePo,
    body #billingReceiveMain .filter-bar-container.crm-ui-filter .crm-ui-filter-actions {
        grid-column: auto !important;
    }

    body #billingReceiveMain .filter-bar-container.crm-ui-filter .crm-ui-filter-actions .btn {
        width: 100%;
    }

    body #billingReceiveMain .receive-results-head {
        min-height: 56px;
        padding: 8px 12px;
    }

    body #billingReceiveMain .receive-info-note {
        min-height: 32px;
        padding: 7px 12px;
        font-size: .78rem;
        line-height: 1.2;
    }
}

@media (max-width: 980px), (hover: none) and (pointer: coarse) {
    body #billingReceiveMain .crm-ui-page-header-copy p {
        display: none !important;
    }

    body #billingReceiveMain .receive-tabs {
        display: none !important;
    }

    body #billingReceiveMain .receive-mobile-tab-control {
        flex: 0 0 auto;
        display: block;
        width: 100%;
        margin: 0 0 8px;
    }

    body #billingReceiveMain .receive-mobile-tab-control select {
        width: 100%;
        height: 44px;
        min-height: 44px;
        border: 1px solid var(--border-default);
        border-radius: var(--radius-lg);
        padding: 0 38px 0 13px;
        background: var(--surface-1);
        color: var(--text-primary);
        font: inherit;
        font-weight: 700;
    }

    body #billingReceiveMain .filter-bar-container.crm-ui-filter {
        grid-template-columns: repeat(2, minmax(0, 1fr)) !important;
    }

    body #billingReceiveMain .filter-bar-container.crm-ui-filter > :first-child,
    body #billingReceiveMain .filter-bar-container.crm-ui-filter > :nth-child(2) {
        grid-column: 1 / -1 !important;
    }

    body #billingReceiveMain .filter-bar-container.crm-ui-filter #receivePo,
    body #billingReceiveMain .filter-bar-container.crm-ui-filter .crm-ui-filter-actions {
        grid-column: auto !important;
    }

    body #billingReceiveMain .filter-bar-container.crm-ui-filter .crm-ui-filter-actions .btn {
        width: 100% !important;
        min-width: 0 !important;
        padding-inline: 8px !important;
    }

    body #billingReceiveMain .receive-results-head {
        min-height: 56px !important;
        padding: 7px 8px !important;
    }

    body #billingReceiveMain .receive-selected-count {
        min-height: 40px;
        padding-inline: 8px;
        font-size: .76rem;
    }
}

@media (max-width: 760px) and (max-height: 700px) {
    body #billingReceiveMain .receive-mobile-tab-control {
        margin-bottom: 6px;
    }

    body #billingReceiveMain .receive-mobile-tab-control select {
        height: 40px;
        min-height: 40px;
    }

    body #billingReceiveMain .receive-info-note {
        display: none !important;
    }

    body #billingReceiveMain .receive-results-head {
        min-height: 48px !important;
        height: 48px !important;
        padding: 4px 6px !important;
    }

    body #billingReceivablesMain .crm-ui-bulkbar-summary,
    body #billingPayablesMain .crm-ui-bulkbar-summary {
        display: grid !important;
        grid-template-columns: minmax(0, 1fr) !important;
        align-content: center !important;
    }

    body #billingReceivablesMain .crm-ui-bulkbar-summary > span,
    body #billingPayablesMain .crm-ui-bulkbar-summary > span {
        font-size: .72rem !important;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
    }
}

@media (max-width: 980px), (hover: none) and (pointer: coarse) {
    /* The explanatory note remains available on desktop; on mobile the
       internal table viewport has priority, matching Cotizaciones. */
    body #billingReceiveMain .receive-info-note {
        display: none !important;
    }
}

/* Receive DTE: the CRM mobile table card starts directly with the bulk bar. */
@media (max-width: 980px), (hover: none) and (pointer: coarse) {
    body #billingReceiveMain .receive-results-head .receive-results-copy {
        display: none !important;
    }

    body #billingReceiveMain .receive-results-head .receive-bulk-actions {
        flex: 1 1 auto !important;
        width: 100% !important;
        min-width: 0 !important;
        justify-content: space-between !important;
    }
}

/* CRM parity cleanup: Cotizaciones no agrega una franja auxiliar bajo la tabla
   y sus campos de fecha no superponen placeholders artificiales. */
.billing-filter-date-group .crm-ui-date-field > em {
    display: none !important;
}

.billing-table-scroll::after,
.billing-table-card .crm-ui-table-scroll::after {
    content: none !important;
    display: none !important;
}


/* ICYLAB Billing v6.18 — grouped document tables */
.billing-document-groups{display:flex;flex-direction:column;gap:16px;min-width:0;padding-bottom:24px}
.billing-document-group{overflow:hidden;min-width:0;margin:0}
.billing-document-group-header{display:flex;align-items:center;justify-content:space-between;gap:16px;padding:16px 18px;border-bottom:1px solid var(--border-color,#e5e7eb);background:var(--surface,#fff)}
.billing-document-group-header h3{margin:0;font-size:1rem;line-height:1.25}
.billing-document-group-header p{margin:4px 0 0;color:var(--text-muted,#6b7280);font-size:.82rem}
.billing-document-group-count{display:inline-flex;align-items:center;justify-content:center;min-width:34px;height:28px;padding:0 10px;border-radius:999px;background:var(--surface-muted,#f3f4f6);font-weight:700;font-size:.82rem}
.billing-document-group-scroll{max-height:360px;overflow:auto;overscroll-behavior:contain}
.billing-document-group-scroll table{min-width:1080px;margin:0}
.billing-document-group-scroll thead th{position:sticky;top:0;z-index:2;background:var(--surface,#fff)}
.billing-document-loading{padding:28px;text-align:center;color:var(--text-muted,#6b7280)}
.receivables-status.no_aplica,.payables-status.no_aplica{background:#eef2f7;color:#52606d}
@media(max-width:768px){.billing-document-group-header{padding:13px 14px;align-items:flex-start}.billing-document-group-header p{font-size:.76rem}.billing-document-group-scroll{max-height:420px}.billing-document-group-scroll table{min-width:100%}}


/* ICYLAB Billing v6.19 — document-family table viewports
   The page scrolls vertically between document families, while each family
   keeps its own sticky-header viewport capped at approximately ten rows. */
body .app-main.crm-ui-main > #documentsMain.crm-ui-page-content.crm-ui-page,
body .app-main.crm-ui-main > #receivablesMain.crm-ui-page-content.crm-ui-page,
body .app-main.crm-ui-main > #payablesMain.crm-ui-page-content.crm-ui-page {
    overflow-y: auto !important;
    overflow-x: hidden !important;
    overscroll-behavior-y: contain !important;
    scrollbar-gutter: stable;
}

body .app-main.crm-ui-main #documentsGroups.billing-document-groups,
body .app-main.crm-ui-main #receivablesGroups.billing-document-groups,
body .app-main.crm-ui-main #payablesGroups.billing-document-groups {
    flex: 0 0 auto !important;
    min-height: 0 !important;
    width: 100% !important;
}

body .app-main.crm-ui-main .billing-document-group.crm-ui-table-card {
    flex: 0 0 auto !important;
    min-height: 0 !important;
    height: auto !important;
    max-height: none !important;
    overflow: hidden !important;
}

body .app-main.crm-ui-main .billing-document-group > .billing-document-group-scroll.crm-ui-table-scroll {
    flex: 0 0 auto !important;
    min-height: 154px !important;
    height: auto !important;
    max-height: min(796px, 72dvh) !important;
    overflow-y: auto !important;
    overflow-x: hidden !important;
    overscroll-behavior: contain !important;
    scrollbar-gutter: stable;
    -webkit-overflow-scrolling: touch !important;
}

body .app-main.crm-ui-main .billing-document-group-scroll .crm-ui-table thead tr {
    height: 56px;
}

@media (min-width: 981px) {
    body .app-main.crm-ui-main .billing-document-group-scroll .crm-ui-table tbody tr:not(.empty-state-row) {
        height: 74px;
        min-height: 74px;
    }
}

@media (max-width: 980px), (hover: none) and (pointer: coarse) {
    body .app-main.crm-ui-main > #documentsMain.crm-ui-page-content.crm-ui-page,
    body .app-main.crm-ui-main > #receivablesMain.crm-ui-page-content.crm-ui-page,
    body .app-main.crm-ui-main > #payablesMain.crm-ui-page-content.crm-ui-page {
        overflow-y: auto !important;
        overflow-x: hidden !important;
    }

    body .app-main.crm-ui-main .billing-document-group > .billing-document-group-scroll.crm-ui-table-scroll {
        min-height: 132px !important;
        max-height: min(680px, 68dvh) !important;
    }
}
.billing-actions-menu{position:relative}.billing-actions-menu>summary{list-style:none;cursor:pointer}.billing-actions-menu>summary::-webkit-details-marker{display:none}.billing-actions-menu__panel{position:absolute;right:0;top:calc(100% + 6px);z-index:80;display:grid;min-width:245px;padding:6px;border:1px solid var(--border-color,#d9e1ea);border-radius:10px;background:var(--surface,#fff);box-shadow:0 12px 28px rgba(15,23,42,.18)}.billing-actions-menu__panel button{display:flex;gap:9px;align-items:center;padding:10px 12px;border:0;border-radius:7px;background:transparent;color:inherit;text-align:left;cursor:pointer}.billing-actions-menu__panel button:hover,.billing-actions-menu__panel button:focus-visible{background:var(--surface-muted,#eef3f8)}.billing-actions-menu__panel svg{width:17px;height:17px}.billing-actions-menu[open]>summary{background:var(--surface-muted,#eef3f8)}

/* ICYLAB Billing v9.1.2 - compact accounting tables inspired by the
   operational density of FACTO while preserving ICYLAB's light headers. */
.billing-table-indicators {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 8px;
    min-height: 34px;
    margin: -2px 0 2px;
}

.billing-table-indicator {
    display: inline-flex;
    align-items: center;
    gap: 7px;
    min-height: 32px;
    padding: 6px 10px;
    border: 1px solid var(--border-default, #d9e1ea);
    border-radius: 999px;
    background: var(--surface-1, #fff);
    color: var(--text-secondary, #475569);
    font-size: .78rem;
    line-height: 1;
}

.billing-table-indicator svg { width: 15px; height: 15px; }
.billing-table-indicator strong { color: var(--text-primary, #111827); }
.billing-table-indicator.is-danger { border-color: #fecaca; background: #fff7f7; color: #b42318; }
.billing-table-indicator.is-warning { border-color: #fde68a; background: #fffdf3; color: #9a6700; }
.billing-table-indicator.is-neutral { background: var(--surface-2, #f7f9fb); }

.billing-reference-table-controls {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    min-height: 46px;
    padding: 8px 14px;
    border-bottom: 1px solid var(--border-subtle, #e5e7eb);
    background: #fff;
    color: #475569;
    font-size: .78rem;
}

.billing-reference-page-size,
.billing-reference-pagination {
    display: inline-flex;
    align-items: center;
    gap: 8px;
}

.billing-reference-page-size select {
    min-width: 76px;
    height: 32px;
    padding: 0 28px 0 10px;
    border: 1px solid var(--border-default, #d9e1ea);
    border-radius: 8px;
    background: #fff;
    color: #111827;
    font: inherit;
}

.billing-reference-pagination button {
    min-height: 32px;
    padding: 0 10px;
    border: 1px solid var(--border-default, #d9e1ea);
    border-radius: 8px;
    background: #fff;
    color: #111827;
    font: inherit;
    font-weight: 650;
    cursor: pointer;
}

.billing-reference-pagination button:hover:not(:disabled),
.billing-reference-pagination button:focus-visible {
    border-color: var(--color-primary, #00c83c);
    background: var(--color-primary-soft, #ecfff1);
}

.billing-reference-pagination button:disabled {
    opacity: .42;
    cursor: not-allowed;
}

body .app-main.crm-ui-main .billing-document-group > .billing-reference-table-scroll.crm-ui-table-scroll {
    min-height: 0 !important;
    max-height: none !important;
    overflow-x: auto !important;
    overflow-y: visible !important;
    scrollbar-gutter: auto !important;
}

body .app-main.crm-ui-main .billing-reference-table {
    width: 100%;
    min-width: 1420px !important;
    table-layout: auto !important;
    border-collapse: collapse;
}

body .app-main.crm-ui-main .billing-reference-table thead th {
    position: sticky;
    top: 0;
    z-index: 12;
    height: 42px !important;
    padding: 9px 10px !important;
    border-bottom: 1px solid var(--border-default, #d9e1ea) !important;
    background: #f7f9fb !important;
    color: #111827 !important;
    font-size: .7rem !important;
    font-weight: 750 !important;
    line-height: 1 !important;
    letter-spacing: .045em !important;
    text-transform: uppercase !important;
    white-space: nowrap;
}

body .app-main.crm-ui-main .billing-reference-table tbody tr:not(.empty-state-row) {
    height: 48px !important;
    min-height: 48px !important;
}

body .app-main.crm-ui-main .billing-reference-table tbody td {
    height: 48px;
    padding: 8px 10px !important;
    border-bottom: 1px solid var(--border-subtle, #edf0f3);
    background: var(--surface-1, #fff);
    font-size: .79rem;
    white-space: nowrap;
}

body .app-main.crm-ui-main .billing-reference-table tbody tr:hover td {
    background: var(--surface-2, #f7f9fb);
}

body .app-main.crm-ui-main .billing-reference-table tfoot th,
body .app-main.crm-ui-main .billing-reference-table tfoot td {
    position: static !important;
    height: 44px;
    padding: 9px 10px !important;
    border-top: 2px solid var(--color-primary, #00c83c) !important;
    border-bottom: 0 !important;
    background: #ecfff1 !important;
    color: #111827 !important;
    font-size: .78rem;
    font-weight: 750;
    white-space: nowrap;
}

body .app-main.crm-ui-main .billing-reference-table tfoot th { text-align: left; }
body .app-main.crm-ui-main .billing-reference-table tfoot td { text-align: right; }

/* These headers stay light in every color scheme by product decision. */
body .app-main.crm-ui-main .billing-document-group > .billing-document-group-header {
    background: #fff !important;
    color: #111827 !important;
}

body .app-main.crm-ui-main .billing-document-group > .billing-document-group-header h3 {
    color: #111827 !important;
}

body .app-main.crm-ui-main .billing-document-group > .billing-document-group-header p {
    color: #667085 !important;
}

body .app-main.crm-ui-main .billing-document-group > .billing-document-group-header .billing-document-group-count {
    background: #f2f4f7 !important;
    color: #344054 !important;
}

body .app-main.crm-ui-main .billing-reference-table thead .icy-table-sort-button {
    color: #111827 !important;
}

.documents-table th:nth-child(n+5):nth-child(-n+11) .icy-table-sort-button,
.receivables-table th:nth-child(n+6):nth-child(-n+12) .icy-table-sort-button,
.payables-table th:nth-child(n+6):nth-child(-n+12) .icy-table-sort-button {
    justify-content: flex-end;
}

.documents-table td:nth-child(n+5):nth-child(-n+11),
.receivables-table td:nth-child(n+6):nth-child(-n+12),
.payables-table td:nth-child(n+6):nth-child(-n+12) {
    text-align: right;
    font-variant-numeric: tabular-nums;
}

.billing-reference-table .col-select { width: 42px; text-align: center; }
.billing-reference-table .col-date { width: 96px; }
.billing-reference-table .col-document,
.billing-reference-table .col-folio { width: 118px; }
.billing-reference-table .col-counterparty,
.billing-reference-table .col-client { min-width: 210px; }
.billing-reference-table .col-status { min-width: 134px; }
.billing-reference-table .crm-ui-action-cell { width: 72px; overflow: visible !important; text-align: center; }

.billing-row-actions { display: inline-block; position: relative; }
.billing-row-actions > summary {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 4px;
    width: 48px;
    height: 32px;
    padding: 0 7px;
    border: 1px solid #00ad35;
    border-radius: 8px;
    background: var(--color-primary, #00c83c);
    color: #fff;
    list-style: none;
    cursor: pointer;
    box-shadow: 0 1px 2px rgba(0, 122, 40, .16);
}

.billing-row-actions > summary::-webkit-details-marker { display: none; }
.billing-row-actions > summary svg:first-child { width: 16px; height: 16px; }
.billing-row-actions > summary svg:last-child { width: 13px; height: 13px; }
.billing-row-actions[open] > summary,
.billing-row-actions > summary:hover { background: #00ad35; }

.billing-row-actions__panel {
    position: fixed;
    z-index: 2100;
    display: none;
    width: max-content;
    min-width: 220px;
    max-width: min(290px, calc(100vw - 16px));
    padding: 6px;
    border: 1px solid var(--border-default, #d9e1ea);
    border-radius: 10px;
    background: var(--surface-1, #fff);
    box-shadow: 0 16px 36px rgba(15, 23, 42, .2);
}

.billing-row-actions[open] > .billing-row-actions__panel { display: grid; }
.billing-row-actions__panel button,
.billing-row-actions__panel a {
    display: flex;
    align-items: center;
    gap: 9px;
    width: 100%;
    min-height: 38px;
    padding: 8px 10px;
    border: 0;
    border-radius: 7px;
    background: transparent;
    color: var(--text-primary, #111827);
    font: inherit;
    font-size: .82rem;
    text-align: left;
    text-decoration: none;
    cursor: pointer;
}

.billing-row-actions__panel button:hover,
.billing-row-actions__panel button:focus-visible,
.billing-row-actions__panel a:hover,
.billing-row-actions__panel a:focus-visible {
    background: var(--surface-2, #f7f9fb);
}

.billing-row-actions__panel svg { width: 16px; height: 16px; color: var(--text-secondary, #475569); }

.documents-financial-status {
    display: inline-flex;
    align-items: center;
    min-height: 24px;
    padding: 4px 8px;
    border-radius: 999px;
    background: #eef2f7;
    color: #52606d;
    font-size: .7rem;
    font-weight: 700;
}

.documents-financial-status.pagado { background: #e9fbea; color: #237a31; }
.documents-financial-status.atrasado { background: #fff0f0; color: #b42318; }
.documents-financial-status.parcial { background: #fff8df; color: #8a6100; }
.documents-financial-status.por_cobrar { background: #eef4ff; color: #315a91; }

@media (max-width: 980px) {
    .billing-reference-table-controls {
        align-items: stretch;
        flex-direction: column;
        padding: 10px 12px;
    }

    .billing-reference-page-size,
    .billing-reference-pagination { justify-content: space-between; }
    .billing-reference-pagination { flex-wrap: wrap; }
    .billing-table-indicators { margin-top: 0; }

    body .app-main.crm-ui-main .billing-reference-table.crm-ui-mobile-table,
    body .app-main.crm-ui-main .billing-reference-table.crm-ui-mobile-table thead,
    body .app-main.crm-ui-main .billing-reference-table.crm-ui-mobile-table tbody,
    body .app-main.crm-ui-main .billing-reference-table.crm-ui-mobile-table tfoot {
        display: table !important;
        width: 100% !important;
        min-width: 1420px !important;
        max-width: none !important;
        table-layout: auto !important;
    }

    body .app-main.crm-ui-main .billing-reference-table.crm-ui-mobile-table thead,
    body .app-main.crm-ui-main .billing-reference-table.crm-ui-mobile-table tbody,
    body .app-main.crm-ui-main .billing-reference-table.crm-ui-mobile-table tfoot {
        display: table-row-group !important;
    }

    body .app-main.crm-ui-main .billing-reference-table.crm-ui-mobile-table tfoot { display: table-footer-group !important; }
    body .app-main.crm-ui-main .billing-reference-table.crm-ui-mobile-table tr { display: table-row !important; }
    body .app-main.crm-ui-main .billing-reference-table.crm-ui-mobile-table th,
    body .app-main.crm-ui-main .billing-reference-table.crm-ui-mobile-table td,
    body .app-main.crm-ui-main .billing-reference-table.crm-ui-mobile-table .crm-mobile-hidden {
        display: table-cell !important;
        width: auto !important;
        max-width: none !important;
        padding: 8px 10px !important;
        overflow: visible !important;
    }
}
