/* ==========================================
   قالب یکپارچه جداول گزارش — .rpt-table
   ========================================== */

:root {
    --rpt-header-bg: #2D597D;
    --rpt-header-fg: #ffffff;
    --rpt-row-odd: #FFFFFF;
    --rpt-row-even: #E1ECF4;
    --rpt-row-selected: #2C9DF8;
    --rpt-row-selected-fg: #ffffff;
    --rpt-row-hover: #d6e8f5;
    --rpt-grid-line: #C0C0C0;
}

/* ----- جستجوی سه‌تکه ----- */
.rpt-triple-search {
    display: flex;
    flex-direction: column;
    gap: 8px;
    margin: 12px 0;
    padding: 10px 12px;
    background: #f5f8fb;
    border: 1px solid var(--rpt-grid-line);
    border-radius: 8px;
}

.rpt-triple-search__label {
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--rpt-header-bg);
}

.rpt-triple-search__inputs {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr)) auto;
    gap: 8px;
    align-items: center;
}

.rpt-triple-search__input {
    min-width: 0;
    width: 100%;
}

.rpt-triple-search__clear {
    white-space: nowrap;
    display: inline-flex;
    align-items: center;
    gap: 6px;
}

@media (max-width: 900px) {
    .rpt-triple-search__inputs {
        grid-template-columns: 1fr;
    }
}

/* ----- جدول ----- */
.rpt-table {
    width: 100%;
    min-width: 640px;
    border-collapse: separate;
    border-spacing: 0;
    font-size: 0.9rem;
    background: var(--rpt-row-odd);
}

.rpt-table thead {
    position: sticky;
    top: 0;
    z-index: 10;
}

.rpt-table thead th {
    padding: 10px 14px;
    text-align: center;
    font-weight: 700;
    color: var(--rpt-header-fg) !important;
    background: var(--rpt-header-bg) !important;
    border: 1px solid var(--rpt-grid-line);
    white-space: nowrap;
    user-select: none;
}

.rpt-table thead th.sortable {
    cursor: pointer;
}

.rpt-table thead th.sortable:hover,
.rpt-table thead th:hover {
    filter: brightness(1.08);
}

.rpt-table thead th.num,
.rpt-table thead th.sorted {
    color: var(--rpt-header-fg) !important;
}

.rpt-table .tr-sort-indicator {
    opacity: 0.65;
    color: var(--rpt-header-fg);
}

.rpt-table thead th.sorted .tr-sort-indicator {
    opacity: 1;
    color: #fff;
}

.rpt-table tbody td {
    padding: 10px 14px;
    text-align: center;
    border: 1px solid var(--rpt-grid-line);
    color: var(--text, #333);
    white-space: nowrap;
}

.rpt-table tbody td.num,
.rpt-table thead th.num {
    text-align: left;
    direction: ltr;
}

.rpt-table tbody tr {
    background: var(--rpt-row-odd);
    transition: background 0.12s ease;
}

.rpt-table tbody tr:nth-child(even),
.rpt-table tbody tr.zebra {
    background: var(--rpt-row-even);
}

.rpt-table tbody tr:hover {
    background: var(--rpt-row-hover) !important;
}

.rpt-table tbody tr.selected,
.rpt-table tbody tr.rv-row--selected,
.rpt-table tbody tr:focus {
    background: var(--rpt-row-selected) !important;
    color: var(--rpt-row-selected-fg) !important;
}

.rpt-table tbody tr.selected td,
.rpt-table tbody tr.rv-row--selected td,
.rpt-table tbody tr:focus td {
    background: var(--rpt-row-selected) !important;
    color: var(--rpt-row-selected-fg) !important;
    border-color: var(--rpt-grid-line);
}

.rpt-table tbody tr.selected .taraz-col-mondeh,
.rpt-table tbody tr:focus .taraz-col-mondeh {
    color: var(--rpt-row-selected-fg) !important;
}

.rpt-table tbody tr.selected .ledger-kind-cell,
.rpt-table tbody tr.selected .account-kind-cell,
.rpt-table tbody tr.selected .account-status,
.rpt-table tbody tr.selected .num-bed,
.rpt-table tbody tr.selected .num-bes,
.rpt-table tbody tr.selected .num-remain,
.rpt-table tbody tr:focus .ledger-kind-cell,
.rpt-table tbody tr:focus .account-kind-cell {
    background: transparent !important;
    color: var(--rpt-row-selected-fg) !important;
}

.rpt-table tbody tr.no-results td {
    text-align: center;
    padding: 48px 24px;
    color: var(--text-light, #888);
    font-style: italic;
    white-space: normal;
}

.rpt-table tfoot td {
    font-weight: 700;
    background: #fff8e1;
    border: 1px solid var(--rpt-grid-line);
}

/* ----- نوار ابزار مشترک ----- */
.rpt-actions {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
}

.rpt-actions .btn,
.rpt-btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    white-space: nowrap;
}

/* ----- پنل نمودار ----- */
.rpt-chart-host {
    display: none;
    flex-direction: column;
    gap: 12px;
    padding: 16px;
    background: #fff;
    border: 1px solid var(--rpt-grid-line);
    border-radius: 8px;
    margin: 16px 0;
    min-height: 320px;
}

.rpt-chart-host.is-visible {
    display: flex;
}

.rpt-chart-toolbar {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 12px;
}

.rpt-chart-toolbar label {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    font-size: 0.9rem;
    color: var(--text, #333);
}

.rpt-chart-toolbar select {
    min-width: 140px;
    padding: 6px 10px;
    border: 1px solid var(--rpt-grid-line);
    border-radius: 6px;
    font-family: inherit;
    background: #fff;
}

.rpt-chart-canvas-wrap {
    position: relative;
    width: 100%;
    min-height: 280px;
    max-height: 480px;
}

.rpt-chart-canvas-wrap canvas {
    width: 100% !important;
    max-height: 440px;
}

.rpt-chart-empty {
    text-align: center;
    padding: 48px 16px;
    color: var(--text-light, #888);
}

/* ----- ناحیه اسکرول قابل‌تغییر ارتفاع ----- */
.rpt-table-panel .table-container,
.rpt-table-panel .tr-table-container,
.rpt-table-panel .rpt-scroll,
.rv-table-wrap.rpt-scroll {
    height: var(--rpt-scroll-height, 45vh);
    min-height: 160px;
    max-height: 85vh;
    overflow: auto !important;
    position: relative;
    border: 1px solid var(--rpt-grid-line);
    border-radius: 8px 8px 0 0;
    box-sizing: border-box;
    -webkit-overflow-scrolling: touch;
    overscroll-behavior: contain;
}

.rpt-table-panel .table-container::-webkit-scrollbar,
.rpt-table-panel .tr-table-container::-webkit-scrollbar,
.rpt-table-panel .rpt-scroll::-webkit-scrollbar,
.rv-table-wrap.rpt-scroll::-webkit-scrollbar {
    height: 8px;
    width: 8px;
}

.rpt-table-panel .table-container::-webkit-scrollbar-thumb,
.rpt-table-panel .tr-table-container::-webkit-scrollbar-thumb,
.rpt-table-panel .rpt-scroll::-webkit-scrollbar-thumb,
.rv-table-wrap.rpt-scroll::-webkit-scrollbar-thumb {
    background: #b8c4d2;
    border-radius: 4px;
}

.rpt-resize-handle {
    display: flex;
    align-items: center;
    justify-content: center;
    height: 12px;
    margin: 0 0 8px;
    cursor: ns-resize;
    user-select: none;
    touch-action: none;
    background: linear-gradient(to bottom, #f0f4f8, #e4ebf2);
    border: 1px solid var(--rpt-grid-line);
    border-top: none;
    border-radius: 0 0 8px 8px;
    color: #6b7c8c;
}

.rpt-resize-handle::before {
    content: '';
    width: 40px;
    height: 4px;
    border-radius: 2px;
    background: #9aabba;
    box-shadow: 0 3px 0 #9aabba;
}

.rpt-resize-handle:hover,
.rpt-resize-handle.is-dragging {
    background: #d6e8f5;
}

.rpt-resize-handle:hover::before,
.rpt-resize-handle.is-dragging::before {
    background: var(--rpt-header-bg);
    box-shadow: 0 3px 0 var(--rpt-header-bg);
}

body.rpt-resizing {
    cursor: ns-resize !important;
    user-select: none !important;
}

body.rpt-resizing iframe {
    pointer-events: none;
}

/* وقتی نمودار باز است جدول مخفی شود */
.rpt-table-panel.is-chart-mode .table-container,
.rpt-table-panel.is-chart-mode .tr-table-container,
.rpt-table-panel.is-chart-mode .rpt-grid-only,
.rpt-table-panel.is-chart-mode .table-pagination,
.rpt-table-panel.is-chart-mode .tr-table-toolbar,
.rpt-table-panel.is-chart-mode .rpt-resize-handle {
    display: none !important;
}

.rpt-table-panel.is-chart-mode .rpt-chart-host {
    display: flex;
}

/* ----- ReportView (هم‌تراز با تم گزارش) ----- */
.rv-table.rpt-table,
table.rv-table {
    /* از .rpt-table ارث می‌برد */
}

.rv-table-wrap {
    overflow: auto;
    border: 1px solid var(--rpt-grid-line);
    border-radius: 8px;
}

.rv-table-wrap.rpt-scroll {
    border-radius: 8px 8px 0 0;
}

@media print {
    .rpt-actions,
    .rpt-chart-host,
    .rpt-chart-toolbar,
    .rpt-resize-handle,
    .no-print {
        display: none !important;
    }

    .rpt-table-panel .table-container,
    .rpt-table-panel .tr-table-container,
    .rpt-table-panel .rpt-scroll,
    .rv-table-wrap.rpt-scroll {
        height: auto !important;
        max-height: none !important;
        overflow: visible !important;
        border: none !important;
    }

    .rpt-table thead th {
        background: var(--rpt-header-bg) !important;
        color: #fff !important;
        -webkit-print-color-adjust: exact;
        print-color-adjust: exact;
        position: static !important;
    }

    .rpt-table tbody tr:nth-child(even),
    .rpt-table tbody tr.zebra {
        background: var(--rpt-row-even) !important;
        -webkit-print-color-adjust: exact;
        print-color-adjust: exact;
    }
}

@media (max-width: 992px) {
    .rpt-table {
        min-width: 560px;
        font-size: 0.85rem;
    }

    .rpt-table thead th,
    .rpt-table tbody td {
        padding: 8px 10px;
    }

    .rpt-triple-search {
        margin: 8px 0;
        padding: 10px;
    }

    .rpt-table-panel .table-container,
    .rpt-table-panel .tr-table-container,
    .rpt-table-panel .rpt-scroll,
    .rv-table-wrap.rpt-scroll {
        height: var(--rpt-scroll-height, 50vh);
        min-height: 180px;
    }
}

@media (max-width: 576px) {
    .rpt-table {
        min-width: 480px;
        font-size: 0.8rem;
    }

    .rpt-actions {
        flex-wrap: wrap;
        gap: 8px;
    }

    .rpt-actions .btn,
    .rpt-actions .btn-outline {
        flex: 1 1 calc(50% - 8px);
        min-height: 44px;
    }
}

/* ----- لیست بدهکاران / بستانکاران ----- */
.lbb-table tbody tr.lbb-row-checked {
    background: #fff59d !important;
}

.lbb-table tbody tr.lbb-row-checked.selected td {
    background: #d07606 !important;
}

.lbb-status {
    display: inline-block;
    min-width: 72px;
    padding: 4px 10px;
    border-radius: 6px;
    color: #fff;
    font-weight: 700;
}

.lbb-status--bed {
    background: #004080;
}

.lbb-status--bes {
    background: #800040;
}

.lbb-details {
    margin-top: 12px;
    padding: 8px 12px;
    background: #eef6ff;
    border: 1px solid var(--rpt-grid-line);
    border-radius: 8px;
}

.lbb-details.is-collapsed .lbb-details-body {
    display: none;
}

.lbb-details-toggle {
    display: block;
    width: 100%;
    border: 0;
    background: transparent;
    color: #1565c0;
    font-weight: 700;
    cursor: pointer;
    padding: 4px 0 8px;
}

.lbb-footer {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 12px;
    margin-top: 12px;
}

.lbb-search-group {
    flex: 1 1 420px;
    min-width: 360px;
    max-width: 640px;
}

.lbb-search-group .form-control {
    flex: 1 1 auto;
    min-width: 280px;
    width: 100%;
}

.lbb-checked-summary {
    margin-top: 16px;
}

.lbb-summary {
    margin-top: 16px;
}

@media print {
    .lbb-details,
    .lbb-details-toggle,
    .lbb-footer,
    .lbb-checked-summary,
    .lbb-summary,
    .lbb-tick-col,
    .lbb-check-cell,
    [data-module="list-bed-bes"] .account-header,
    [data-action="open-lbb-filter"],
    [data-action="lbb-remove-filter"],
    [data-action="lbb-excel"],
    [data-action="lbb-print"],
    [data-action="lbb-chart"],
    [data-lbb="search"] {
        display: none !important;
    }

    .lbb-table tbody tr.lbb-row-checked,
    .lbb-table tbody tr.lbb-row-checked.selected td {
        background: transparent !important;
    }

    body.lbb-printing .sidebar,
    body.lbb-printing .sidebar-backdrop,
    body.lbb-printing .header,
    body.lbb-printing .reports-tabs,
    body.lbb-printing .toggle-sidebar {
        display: none !important;
    }

    body.lbb-printing .main-content {
        margin: 0 !important;
    }

    body.lbb-printing .card {
        box-shadow: none !important;
        border: none !important;
    }
}

