/* Optional full-screen loan view (explicit fullScreen: true only) */
.modal-overlay.loan-view-overlay {
    position: fixed;
    inset: 0;
    z-index: 10000;
    display: flex;
    align-items: stretch;
    justify-content: stretch;
    padding: 0;
    margin: 0;
    width: 100%;
    height: 100%;
    height: 100dvh;
    background: rgba(15, 23, 42, 0.55);
    backdrop-filter: blur(2px);
}

.loan-view-overlay .loan-view-modal.modal-content {
    width: 100%;
    max-width: none;
    height: 100%;
    height: 100dvh;
    max-height: none;
    min-height: 0;
    margin: 0;
    border-radius: 0;
    box-shadow: none;
    background: #f8fafc;
}

/* Centered modal loan view dashboard (default for financier) */
.modal-overlay.loan-view-modal-overlay {
    position: fixed;
    inset: 0;
    z-index: 10000;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 1rem;
    background: rgba(15, 23, 42, 0.55);
    backdrop-filter: blur(2px);
}

.loan-view-modal-overlay .loan-view-modal.modal-content {
    width: min(1120px, 94vw);
    max-height: min(92vh, 920px);
    min-height: 0;
    margin: 0;
    border-radius: 16px;
    box-shadow: 0 24px 64px rgba(15, 23, 42, 0.28);
    background: #f8fafc;
    overflow: hidden;
}

.loan-view-dashboard {
    display: flex;
    flex-direction: column;
    flex: 1;
    min-height: 0;
    max-height: min(92vh, 920px);
    background: #f8fafc;
}

.loan-view-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 1rem;
    flex-shrink: 0;
    position: sticky;
    top: 0;
    z-index: 5;
    padding: 1.25rem 1.5rem;
    background: linear-gradient(135deg, #064e3b 0%, #059669 52%, #10b981 100%);
    color: #ecfdf5;
    box-shadow: 0 4px 16px rgba(6, 78, 59, 0.15);
    border-radius: 16px 16px 0 0;
}

.loan-view-header-main {
    display: flex;
    align-items: flex-start;
    gap: 1rem;
    min-width: 0;
}

.loan-view-borrower-avatar {
    width: 56px;
    height: 56px;
    border-radius: 16px;
    background: rgba(255, 255, 255, 0.18);
    border: 1px solid rgba(255, 255, 255, 0.28);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.15rem;
    font-weight: 700;
    flex-shrink: 0;
}

.loan-view-title-block {
    min-width: 0;
}

.loan-view-eyebrow {
    display: block;
    font-size: 0.72rem;
    font-weight: 700;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    opacity: 0.82;
    margin-bottom: 0.25rem;
}

.loan-view-title {
    margin: 0 0 0.35rem;
    font-size: clamp(1.25rem, 2.5vw, 1.6rem);
    line-height: 1.25;
    color: #fff;
    word-break: break-word;
}

.loan-view-subtitle {
    margin: 0;
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.5rem;
    font-size: 0.88rem;
    color: rgba(236, 253, 245, 0.92);
}

.loan-view-context-bar {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 0;
    flex-shrink: 0;
    background: #fff;
    border-bottom: 1px solid #e2e8f0;
}

.loan-view-context-item {
    display: flex;
    flex-direction: column;
    gap: 0.2rem;
    padding: 0.85rem 1.25rem;
    border-right: 1px solid #f1f5f9;
    min-width: 0;
}

.loan-view-context-item:last-child {
    border-right: none;
}

.loan-view-context-label {
    font-size: 0.68rem;
    font-weight: 700;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    color: #94a3b8;
}

.loan-view-context-value {
    font-size: 0.88rem;
    font-weight: 600;
    color: #0f172a;
    line-height: 1.35;
    word-break: break-word;
}

.loan-view-context-value.overdue {
    color: #b91c1c;
}

.loan-view-context-value.soon {
    color: #047857;
}

.loan-view-meta-chips {
    display: flex;
    flex-wrap: wrap;
    gap: 0.45rem;
}

.loan-view-chip {
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
    padding: 0.28rem 0.65rem;
    border-radius: 999px;
    background: rgba(255, 255, 255, 0.14);
    border: 1px solid rgba(255, 255, 255, 0.22);
    font-size: 0.78rem;
    font-weight: 600;
    max-width: 100%;
}

.loan-view-chip i {
    flex-shrink: 0;
}

.loan-view-close {
    width: 44px;
    height: 44px;
    min-width: 44px;
    min-height: 44px;
    border: none;
    border-radius: 999px;
    background: rgba(255, 255, 255, 0.16);
    color: #fff;
    font-size: 1.35rem;
    line-height: 1;
    cursor: pointer;
    flex-shrink: 0;
    transition: background 0.15s ease;
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
}

.loan-view-close:hover,
.loan-view-close:focus-visible {
    background: rgba(255, 255, 255, 0.28);
    outline: none;
}

.loan-view-body {
    flex: 1;
    min-height: 0;
    overflow-x: hidden;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    overscroll-behavior: contain;
    padding: 1.5rem 1.75rem 1.75rem;
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
}

.loan-view-summary-row {
    display: grid;
    grid-template-columns: minmax(0, 1.15fr) minmax(0, 0.85fr);
    gap: 1.25rem;
    align-items: stretch;
}

.loan-view-main-grid {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(280px, 0.85fr);
    gap: 1.25rem;
    align-items: start;
}

.loan-view-main-grid-compact {
    grid-template-columns: minmax(0, 1.1fr) minmax(260px, 0.9fr);
}

.loan-view-transactions-section {
    width: 100%;
    min-width: 0;
}

.loan-view-panel-transactions .loan-view-panel-body-transactions {
    padding: 1.25rem 1.5rem 1.5rem;
}

.loan-view-tx-card-list {
    display: flex;
    flex-direction: column;
    gap: 0.85rem;
}

.loan-view-tx-card {
    background: #fff;
    border: 1px solid #e2e8f0;
    border-radius: 12px;
    padding: 1rem 1.15rem;
    transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.loan-view-tx-card:hover {
    border-color: #cbd5e1;
    box-shadow: 0 2px 8px rgba(15, 23, 42, 0.04);
}

.loan-view-tx-card-top {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    margin-bottom: 0.5rem;
}

.loan-view-tx-date {
    font-size: 0.82rem;
    font-weight: 600;
    color: #64748b;
    white-space: nowrap;
}

.loan-view-tx-amount {
    font-size: 1rem;
    font-weight: 700;
    color: #059669;
    white-space: nowrap;
}

.loan-view-tx-card-title {
    margin: 0 0 0.65rem;
    font-size: 0.95rem;
    font-weight: 600;
    line-height: 1.45;
    color: #0f172a;
    word-break: break-word;
}

.loan-view-tx-card-footer {
    display: flex;
    flex-direction: column;
    gap: 0.55rem;
}

.loan-view-tx-kind {
    display: inline-flex;
    align-self: flex-start;
    align-items: center;
    padding: 0.2rem 0.6rem;
    border-radius: 999px;
    font-size: 0.72rem;
    font-weight: 700;
    background: #f1f5f9;
    color: #475569;
}

.loan-view-tx-kind.marketplace-order {
    background: #fff7ed;
    color: #c2410c;
}

.loan-view-tx-kind.marketplace-sale {
    background: #ecfdf5;
    color: #047857;
}

.loan-view-tx-kind.loan-disbursement {
    background: #eff6ff;
    color: #1d4ed8;
}

.loan-view-tx-parties {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: 0.45rem 1.25rem;
}

.loan-view-tx-party {
    font-size: 0.84rem;
    color: #334155;
    line-height: 1.4;
    word-break: break-word;
}

.loan-view-tx-party-label {
    display: inline-block;
    min-width: 3.25rem;
    margin-right: 0.35rem;
    font-size: 0.68rem;
    font-weight: 700;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    color: #94a3b8;
}

.loan-view-column-count {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 1.35rem;
    padding: 0.1rem 0.45rem;
    border-radius: 999px;
    background: rgba(15, 23, 42, 0.08);
    font-size: 0.75rem;
    font-weight: 700;
}

.financier-marketplace-column.orders .loan-view-column-count {
    background: #ffedd5;
    color: #c2410c;
}

.financier-marketplace-column.sales .loan-view-column-count {
    background: #dcfce7;
    color: #047857;
}

.loan-view-empty-inline {
    padding: 1rem 0;
    text-align: left;
}

.loan-view-main-primary {
    display: flex;
    flex-direction: column;
    gap: 1.25rem;
    min-width: 0;
}

.loan-view-main-secondary {
    min-width: 0;
    position: sticky;
    top: 0;
}

.loan-view-body-inner {
    width: 100%;
    max-width: 1280px;
    margin: 0 auto;
    display: flex;
    flex-direction: column;
    gap: 1.35rem;
}

.loan-view-section {
    display: flex;
    flex-direction: column;
    gap: 0.55rem;
}

.loan-view-section-summary {
    gap: 0.85rem;
}

.loan-view-section-label {
    margin: 0;
    font-size: 0.72rem;
    font-weight: 700;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    color: #64748b;
}

.loan-view-section-summary .loan-view-progress-card {
    margin-bottom: 0;
}

.loan-view-kpi-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 1rem;
    align-content: start;
}

.loan-view-kpi {
    background: #fff;
    border: 1px solid #e2e8f0;
    border-radius: 14px;
    padding: 1.1rem 1.15rem;
    position: relative;
    overflow: hidden;
}

.loan-view-kpi::before {
    content: '';
    position: absolute;
    inset: 0 auto 0 0;
    width: 4px;
    background: var(--loan-kpi-accent, #059669);
}

.loan-view-kpi-amount { --loan-kpi-accent: #2563eb; }
.loan-view-kpi-outstanding { --loan-kpi-accent: #d97706; }
.loan-view-kpi-repaid { --loan-kpi-accent: #16a34a; }
.loan-view-kpi-status { --loan-kpi-accent: #7c3aed; }
.loan-view-kpi-due { --loan-kpi-accent: #0d9488; }

.loan-view-kpi-label {
    display: flex;
    align-items: center;
    gap: 0.35rem;
    font-size: 0.76rem;
    font-weight: 600;
    color: #64748b;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    margin-bottom: 0.35rem;
}

.loan-view-kpi-value {
    font-size: clamp(1rem, 2vw, 1.2rem);
    font-weight: 700;
    color: #0f172a;
    line-height: 1.2;
    word-break: break-word;
}

.loan-view-kpi-status .loan-view-kpi-value {
    font-size: 0.95rem;
    font-weight: 600;
}

.loan-view-kpi-sub {
    margin-top: 0.25rem;
    font-size: 0.78rem;
    color: #64748b;
}

.loan-view-kpi-due.overdue .loan-view-kpi-value {
    color: #b91c1c;
}

.loan-view-kpi-due.soon .loan-view-kpi-value {
    color: #047857;
}

.loan-view-progress-card {
    background: #fff;
    border: 1px solid #e2e8f0;
    border-radius: 14px;
    padding: 1.25rem 1.35rem;
    display: flex;
    flex-direction: column;
    justify-content: center;
    height: 100%;
}

.loan-view-progress-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.75rem;
    margin-bottom: 0.55rem;
    flex-wrap: wrap;
}

.loan-view-progress-head span {
    font-size: 0.84rem;
    color: #64748b;
}

.loan-view-progress-head strong {
    font-size: 0.92rem;
    color: #0f172a;
}

.loan-view-progress-bar {
    height: 12px;
    border-radius: 999px;
    background: #e2e8f0;
    overflow: hidden;
}

.loan-view-progress-fill {
    height: 100%;
    border-radius: inherit;
    background: linear-gradient(90deg, #2563eb, #059669);
    transition: width 0.25s ease;
}

.loan-view-progress-meta {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 0.65rem 1rem;
    margin-top: 0.85rem;
    font-size: 0.84rem;
    color: #64748b;
}

.loan-view-progress-meta span {
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
}

.loan-view-panel {
    background: #fff;
    border: 1px solid #e2e8f0;
    border-radius: 14px;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    min-height: auto;
}

.loan-view-panel-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.75rem;
    padding: 1rem 1.25rem;
    border-bottom: 1px solid #e2e8f0;
    background: #f8fafc;
}

.loan-view-panel-head h3 {
    margin: 0;
    font-size: 0.98rem;
    font-weight: 700;
    color: #0f172a;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    min-width: 0;
    line-height: 1.3;
}

.loan-view-panel-head h3 i {
    color: #059669;
    flex-shrink: 0;
}

.loan-view-panel-count {
    font-size: 0.72rem;
    font-weight: 700;
    padding: 0.18rem 0.5rem;
    border-radius: 999px;
    background: #ecfdf5;
    color: #047857;
    flex-shrink: 0;
}

.loan-view-panel-body {
    padding: 1.15rem 1.25rem 1.25rem;
    overflow: visible;
}

.loan-view-panel-chat {
    display: flex;
    flex-direction: column;
    min-height: 320px;
}

.loan-view-panel-chat .loan-view-panel-body {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-height: 240px;
}

.loan-view-panel-chat .loan-view-chat-feed {
    flex: 1;
    max-height: min(420px, 50vh);
}

.loan-view-chat-feed {
    display: flex;
    flex-direction: column;
    gap: 0.65rem;
    max-height: min(320px, 40vh);
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
}

.loan-view-chat-bubble {
    padding: 0.75rem 0.85rem;
    border-radius: 12px;
    border: 1px solid transparent;
}

.loan-view-chat-bubble.financier {
    background: #eff6ff;
    border-color: #bfdbfe;
}

.loan-view-chat-bubble.borrower {
    background: #f0fdf4;
    border-color: #bbf7d0;
}

.loan-view-chat-meta {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.5rem;
    margin-bottom: 0.35rem;
    flex-wrap: wrap;
}

.loan-view-chat-meta strong {
    font-size: 0.78rem;
    color: #334155;
}

.loan-view-chat-meta span {
    font-size: 0.72rem;
    color: #94a3b8;
}

.loan-view-chat-text {
    white-space: pre-wrap;
    font-size: 0.88rem;
    color: #1e293b;
    line-height: 1.5;
    word-break: break-word;
}

.loan-view-source-badges {
    display: flex;
    flex-wrap: wrap;
    gap: 0.4rem;
    margin-bottom: 0.75rem;
}

.loan-view-source-badge {
    display: inline-flex;
    align-items: center;
    gap: 0.25rem;
    padding: 0.22rem 0.55rem;
    border-radius: 999px;
    background: #eef2ff;
    color: #3730a3;
    font-size: 0.72rem;
    font-weight: 700;
}

.loan-view-table-wrap {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    margin: 0 -0.25rem;
    padding: 0 0.25rem;
}

.loan-view-table {
    width: 100%;
    min-width: 0;
    border-collapse: collapse;
    font-size: 0.86rem;
    table-layout: fixed;
}

.loan-view-table th {
    text-align: left;
    padding: 0.65rem 0.75rem;
    border-bottom: 1px solid #e2e8f0;
    color: #64748b;
    font-size: 0.72rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    background: #f8fafc;
}

.loan-view-table th:nth-child(1),
.loan-view-table td:nth-child(1) {
    width: 18%;
}

.loan-view-table th:nth-child(2),
.loan-view-table td:nth-child(2) {
    width: 38%;
}

.loan-view-table th:nth-child(3),
.loan-view-table td:nth-child(3) {
    width: 26%;
}

.loan-view-table th:nth-child(4),
.loan-view-table td:nth-child(4) {
    width: 18%;
}

.loan-view-td-date {
    white-space: nowrap;
    font-size: 0.82rem;
    color: #64748b;
}

.loan-view-td-details {
    min-width: 0;
}

.loan-view-tx-title {
    font-weight: 600;
    color: #0f172a;
    line-height: 1.35;
    word-break: break-word;
}

.loan-view-tx-meta {
    margin-top: 0.2rem;
    font-size: 0.76rem;
    color: #64748b;
}

.loan-view-td-parties {
    font-size: 0.82rem;
    color: #475569;
    line-height: 1.4;
    word-break: break-word;
}

.loan-view-table td {
    padding: 0.75rem;
    border-bottom: 1px solid #f1f5f9;
    color: #334155;
    vertical-align: top;
    word-break: break-word;
}

.loan-view-table tbody tr:hover {
    background: #f8fafc;
}

.loan-view-table tbody tr:last-child td {
    border-bottom: none;
}

.loan-view-empty {
    text-align: center;
    padding: 1.75rem 1rem;
    color: #94a3b8;
    font-size: 0.88rem;
}

.loan-view-empty i {
    display: block;
    font-size: 1.5rem;
    margin-bottom: 0.5rem;
    opacity: 0.45;
}

.loan-view-status-badge {
    display: inline-flex;
    align-items: center;
    padding: 0.2rem 0.55rem;
    border-radius: 999px;
    font-size: 0.72rem;
    font-weight: 700;
    text-transform: capitalize;
}

.loan-view-status-badge.pending { background: #fef3c7; color: #b45309; }
.loan-view-status-badge.approved { background: #dbeafe; color: #1d4ed8; }
.loan-view-status-badge.active { background: #dcfce7; color: #166534; }
.loan-view-status-badge.repaid { background: #ecfdf5; color: #047857; }
.loan-view-status-badge.rejected { background: #fee2e2; color: #b91c1c; }
.loan-view-status-badge.defaulted { background: #fecaca; color: #991b1b; }

.financier-marketplace-column {
    border: 1px solid #e2e8f0;
    border-radius: 12px;
    padding: 1rem 1.1rem;
    background: #fafafa;
    min-width: 0;
}

.financier-marketplace-column h4 {
    margin: 0 0 0.75rem;
    font-size: 0.9rem;
    display: flex;
    align-items: center;
    gap: 0.4rem;
    color: #0f172a;
}

.financier-marketplace-column.orders {
    border-top: 3px solid #f59e0b;
}

.financier-marketplace-column.sales {
    border-top: 3px solid #16a34a;
}

.financier-marketplace-stack {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 1.25rem;
}

.financier-marketplace-split {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 0.75rem;
}

.loan-view-other-block {
    margin-top: 0.85rem;
    padding-top: 0.85rem;
    border-top: 1px dashed #e2e8f0;
}

.loan-view-other-block h4 {
    margin: 0 0 0.55rem;
    font-size: 0.84rem;
    color: #0f172a;
    display: flex;
    align-items: center;
    gap: 0.35rem;
}

.loan-view-table th.amount-col,
.loan-view-table td.amount-col {
    text-align: right;
    white-space: nowrap;
}

/* Tablet */
@media (max-width: 1024px) {
    .loan-view-modal-overlay .loan-view-modal.modal-content {
        width: min(960px, 94vw);
        max-height: 92vh;
    }

    .loan-view-context-bar {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }

    .loan-view-context-item:nth-child(2) {
        border-right: none;
    }

    .loan-view-context-item:nth-child(1),
    .loan-view-context-item:nth-child(3) {
        border-bottom: 1px solid #f1f5f9;
    }

    .loan-view-summary-row {
        grid-template-columns: 1fr;
    }

    .loan-view-main-grid,
    .loan-view-main-grid-compact {
        grid-template-columns: 1fr;
    }

    .financier-marketplace-stack {
        grid-template-columns: 1fr;
    }

    .loan-view-main-secondary {
        position: static;
    }
}

/* Phone */
@media (max-width: 640px) {
    .modal-overlay.loan-view-modal-overlay {
        padding: 0.5rem;
        align-items: flex-end;
    }

    .loan-view-modal-overlay .loan-view-modal.modal-content {
        width: 100%;
        max-height: 94vh;
        border-radius: 16px 16px 0 0;
    }

    .loan-view-header {
        padding: 1rem;
        border-radius: 16px 16px 0 0;
    }

    .loan-view-header-main {
        gap: 0.75rem;
    }

    .loan-view-borrower-avatar {
        width: 48px;
        height: 48px;
        border-radius: 14px;
        font-size: 1rem;
    }

    .loan-view-title {
        margin-bottom: 0.5rem;
    }

    .loan-view-chip {
        font-size: 0.72rem;
        padding: 0.24rem 0.55rem;
    }

    .loan-view-body {
        padding: 1rem;
        gap: 1.15rem;
    }

    .loan-view-context-bar {
        grid-template-columns: 1fr;
    }

    .loan-view-context-item {
        border-right: none;
        border-bottom: 1px solid #f1f5f9;
        padding: 0.75rem 1rem;
    }

    .loan-view-context-item:last-child {
        border-bottom: none;
    }

    .loan-view-kpi-grid {
        grid-template-columns: 1fr;
        gap: 0.75rem;
    }

    .loan-view-kpi {
        padding: 0.95rem 1rem;
    }

    .loan-view-progress-card {
        padding: 1rem;
    }

    .loan-view-progress-meta {
        grid-template-columns: 1fr;
        gap: 0.45rem;
    }

    .loan-view-panel-head {
        padding: 0.85rem 1rem;
    }

    .loan-view-panel-head h3 {
        font-size: 0.9rem;
    }

    .loan-view-panel-body {
        padding: 0.95rem 1rem 1rem;
    }

    .loan-view-chat-feed {
        max-height: min(280px, 40vh);
    }

    .loan-view-table {
        font-size: 0.8rem;
    }

    .loan-view-table th,
    .loan-view-table td {
        padding: 0.6rem 0.5rem;
    }
}
