/* Loan Cards */
.loan-cards {
    display: grid;
    gap: 1rem;
}

.loan-card {
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: 0.75rem;
    padding: 1rem;
    cursor: pointer;
    transition: border-color 0.2s, box-shadow 0.2s;
    box-shadow: 0 1px 3px rgba(0,0,0,0.08);
}

.loan-card:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-md);
    transition: all 0.3s cubic-bezier(0.16, 1, 0.3, 1);
}

.loan-card-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    margin-bottom: 0.75rem;
}

.loan-card-title {
    font-weight: 600;
}

.loan-card-body {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
    gap: 0.75rem;
    font-size: 0.875rem;
}

.loan-card-field {
    display: flex;
    flex-direction: column;
}

.loan-card-field-label {
    font-size: 0.75rem;
    color: var(--text-muted);
    text-transform: uppercase;
}

/* Calendar */
.calendar-view-toggle {
    display: flex;
    gap: 0;
    border-bottom: 1px solid var(--border-color);
    margin-bottom: 1.5rem;
}

.toggle-btn {
    padding: 0.75rem 1.25rem;
    font-size: 0.85rem;
    font-weight: 500;
    color: var(--text-secondary);
    background: none;
    border: none;
    border-bottom: 2px solid transparent;
    cursor: pointer;
    transition: all 0.2s ease;
}

.toggle-btn:hover {
    color: var(--text-primary);
}

.toggle-btn.active {
    color: var(--primary);
    border-bottom-color: var(--primary);
}

.toggle-icon {
    font-size: 1rem;
}

.upcoming-event-item {
    display: flex;
    align-items: center;
    padding: 1rem;
    border-bottom: 1px solid var(--border-color);
    cursor: pointer;
    transition: background-color 0.15s;
}

.upcoming-event-item:hover {
    background-color: var(--bg-tertiary);
}

.upcoming-event-item:last-child {
    border-bottom: none;
}

.upcoming-event-date {
    min-width: 100px;
    text-align: center;
    padding-right: 1rem;
    border-right: 1px solid var(--border-color);
    margin-right: 1rem;
}

.upcoming-event-date-day {
    font-size: 1.5rem;
    font-weight: 700;
    line-height: 1;
}

.upcoming-event-date-month {
    font-size: 0.75rem;
    color: var(--text-muted);
    text-transform: uppercase;
}

.upcoming-event-date-year {
    font-size: 0.7rem;
    color: var(--text-muted);
}

.upcoming-event-info {
    flex: 1;
}

.upcoming-event-title {
    font-weight: 600;
    margin-bottom: 0.25rem;
}

.upcoming-event-details {
    font-size: 0.85rem;
    color: var(--text-muted);
}

.upcoming-event-type {
    padding: 0.25rem 0.5rem;
    border-radius: var(--radius);
    font-size: 0.75rem;
    font-weight: 600;
}

.upcoming-event-type.start {
    background: var(--lender-primary);
    color: white;
}

.upcoming-event-type.end {
    background: var(--borrower-primary);
    color: white;
}

.upcoming-event-days {
    text-align: right;
    min-width: 80px;
}

.upcoming-event-days-num {
    font-size: 1.25rem;
    font-weight: 600;
}

.upcoming-event-days-label {
    font-size: 0.7rem;
    color: var(--text-muted);
}

.upcoming-empty {
    padding: 2rem;
    text-align: center;
    color: var(--text-muted);
}

.upcoming-section-title {
    padding: 0.75rem 1rem;
    background: var(--bg-tertiary);
    font-weight: 600;
    font-size: 0.85rem;
    color: var(--text-secondary);
    border-bottom: 1px solid var(--border-color);
}

.calendar-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1rem;
}

.calendar-nav {
    display: flex;
    align-items: center;
    gap: 1rem;
}

.calendar-title {
    font-size: 1.25rem;
    font-weight: 600;
    min-width: 180px;
    text-align: center;
}

.calendar-grid {
    display: grid;
    grid-template-columns: repeat(7, 1fr);
    gap: 1px;
    background: var(--border-color);
    border: 1px solid var(--border-color);
    border-radius: 0.5rem;
    overflow: hidden;
}

.calendar-day-header {
    background: var(--bg-tertiary);
    padding: 0.5rem;
    text-align: center;
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--text-secondary);
}

.calendar-day {
    background: var(--bg-secondary);
    min-height: 100px;
    padding: 0.5rem;
    position: relative;
}

.calendar-day.other-month {
    background: var(--bg-primary);
    color: var(--text-muted);
}

.calendar-day.today {
    background: rgba(58, 79, 192, 0.06);
}

.calendar-day-number {
    font-size: 0.875rem;
    font-weight: 500;
    margin-bottom: 0.25rem;
}

.calendar-events {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.calendar-event {
    font-size: 0.7rem;
    padding: 2px 4px;
    border-radius: 2px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    cursor: pointer;
}

.calendar-event.lender {
    background: var(--lender-primary);
    color: white;
}

.calendar-event.borrower {
    background: var(--borrower-primary);
    color: white;
}

.calendar-event.end-date {
    opacity: 0.8;
}

.calendar-event.finished {
    background: var(--text-muted) !important;
    color: var(--bg-secondary) !important;
    opacity: 0.7;
}

/* Filters */
.filters {
    display: flex;
    flex-wrap: wrap;
    gap: 0.75rem;
    margin-bottom: 1rem;
}

.filter-group {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.filter-group label {
    font-size: 0.8rem;
    color: var(--text-secondary);
}

.filter-group select {
    padding: 0.375rem 0.75rem;
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: 0.375rem;
    color: var(--text-primary);
    font-size: 0.875rem;
}

/* Loan Detail View */
.loan-detail-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    margin-bottom: 1.5rem;
    flex-wrap: wrap;
    gap: 1rem;
}

.loan-detail-title {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.loan-detail-amount {
    font-size: 2rem;
    font-weight: 700;
}

.loan-detail-actions {
    display: flex;
    gap: 0.5rem;
    margin-left: auto;
    flex-shrink: 0;
    align-self: flex-start;
}

.detail-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
    gap: 1rem;
}

.detail-section {
    background: var(--bg-tertiary);
    border-radius: 0.5rem;
    padding: 1rem;
}

.detail-section-title {
    font-size: 0.8rem;
    text-transform: uppercase;
    color: var(--text-secondary);
    margin-bottom: 0.75rem;
    letter-spacing: 0.05em;
}

.detail-row {
    display: flex;
    justify-content: space-between;
    padding: 0.375rem 0;
    border-bottom: 1px solid var(--border-color);
    gap: 0.5rem;
}

.detail-row:last-child {
    border-bottom: none;
}

.detail-label {
    color: var(--text-secondary);
    font-size: 0.875rem;
    flex-shrink: 0;
}

.detail-value {
    font-weight: 500;
    font-size: 0.875rem;
    word-break: break-all;
    text-align: right;
    min-width: 0;
}

/* LTV Monitor */
.ltv-monitor {
    background: var(--bg-tertiary);
    border-radius: 0.5rem;
    padding: 1.25rem;
}

.ltv-display {
    text-align: center;
    margin-bottom: 1rem;
}

.ltv-percentage {
    font-size: 3rem;
    font-weight: 700;
    line-height: 1;
}

.ltv-label {
    font-size: 0.875rem;
    color: var(--text-secondary);
}

.ltv-bar {
    height: 8px;
    background: var(--surface-2);
    border-radius: 4px;
    overflow: hidden;
    margin: 1rem 0;
    position: relative;
}

.ltv-bar-fill {
    height: 100%;
    border-radius: 4px;
    transition: width 0.3s, background-color 0.3s;
}

.ltv-bar-markers {
    display: flex;
    justify-content: space-between;
    font-size: 0.7rem;
    color: var(--text-muted);
    margin-top: 0.25rem;
}

.ltv-info-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0.75rem;
    margin-top: 1rem;
}

.ltv-info-item {
    text-align: center;
    padding: 0.5rem;
    background: var(--bg-secondary);
    border-radius: 0.375rem;
    box-shadow: 0 1px 3px rgba(0,0,0,0.08);
}

.ltv-info-label {
    font-size: 0.7rem;
    color: var(--text-muted);
    text-transform: uppercase;
}

.ltv-info-value {
    font-weight: 600;
    font-size: 0.9rem;
}

/* Repayment Section */
.repayment-form {
    display: flex;
    gap: 0.75rem;
    margin-bottom: 1rem;
    flex-wrap: wrap;
}

.repayment-form .form-input {
    flex: 1;
    min-width: 120px;
}

.repayment-list {
    max-height: 300px;
    overflow-y: auto;
}

.repayment-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.75rem;
    background: var(--bg-secondary);
    border-radius: 0.375rem;
    margin-bottom: 0.5rem;
    box-shadow: 0 1px 3px rgba(0,0,0,0.08);
}

.repayment-amount {
    font-weight: 600;
}

.repayment-date {
    font-size: 0.8rem;
    color: var(--text-muted);
}

.repayment-type {
    font-size: 0.75rem;
    padding: 0.125rem 0.375rem;
    border-radius: 0.25rem;
    background: var(--bg-tertiary);
}

.repayment-txid {
    font-size: 0.7rem;
    color: var(--accent);
    text-decoration: none;
    margin-left: 0.5rem;
}

.repayment-txid:hover {
    text-decoration: underline;
}

.repayment-days {
    font-size: 0.75rem;
    color: var(--ltv-safe);
    background: rgba(5, 150, 105, 0.08);
    padding: 0.125rem 0.375rem;
    border-radius: 0.25rem;
}

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

.repayment-table th,
.repayment-table td {
    padding: 0.75rem;
    text-align: left;
    border-bottom: 1px solid var(--border-color);
}

.repayment-table th {
    background: var(--bg-tertiary);
    font-weight: 600;
    font-size: 0.85rem;
    color: var(--text-secondary);
}

.repayment-table th.sortable {
    cursor: pointer;
    user-select: none;
}

.repayment-table th.sortable:hover {
    color: var(--text-primary);
    background: var(--bg-secondary);
}

.repayment-table th .sort-icon {
    opacity: 0.4;
    margin-left: 0.25rem;
}

.repayment-table th.sorted-asc .sort-icon,
.repayment-table th.sorted-desc .sort-icon {
    opacity: 1;
}

.repayment-table tbody tr:hover {
    background: var(--bg-tertiary);
}

.repayment-table td:last-child {
    text-align: center;
    width: 40px;
}

/* Loans Table */
.loans-table-wrapper {
    overflow-x: auto;
}

.loans-table {
    width: 100%;
    border-collapse: collapse;
    min-width: 950px;
}

.loans-table td {
    white-space: nowrap;
    font-variant-numeric: tabular-nums;
}

.loans-table th,
.loans-table td {
    padding: 0.75rem 0.5rem;
    text-align: left;
    border-bottom: 1px solid var(--border-color);
}

.loans-table th {
    background: var(--bg-tertiary);
    font-weight: 500;
    font-size: 0.75rem;
    color: var(--text-secondary);
    white-space: nowrap;
    text-transform: uppercase;
    letter-spacing: 0.06em;
}

.loans-table th.sortable {
    cursor: pointer;
    user-select: none;
}

.loans-table th.sortable:hover {
    color: var(--text-primary);
    background: var(--bg-secondary);
}

.loans-table th .sort-icon {
    opacity: 0.4;
    margin-left: 0.25rem;
}

.loans-table th.sorted-asc .sort-icon,
.loans-table th.sorted-desc .sort-icon {
    opacity: 1;
}

.loans-table tbody tr {
    cursor: pointer;
    transition: background 0.15s;
}

.loans-table tbody tr:hover {
    background: var(--bg-tertiary);
}

.loans-table tbody tr:active {
    transform: translateY(1px);
}

.loans-table .counterparty-cell {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.loans-table .counterparty-name {
    font-weight: 500;
    white-space: normal;
    max-width: 100px;
}

.loans-table .amount-cell {
    font-weight: 600;
}

.loans-table .separator-row td {
    border-top: 1px solid var(--border-color);
    padding: 0.75rem;
    background: transparent;
}

.loans-table .totals-row {
    background: var(--bg-tertiary);
    font-weight: 600;
}

.loans-table .totals-row td {
    border-top: 2px solid var(--border-color);
    padding: 0.75rem 0.5rem;
}

.loans-table .totals-row .totals-label {
    font-size: 0.85rem;
    color: var(--text-secondary);
    text-transform: uppercase;
}

.loans-table .date-cell {
    font-size: 0.85rem;
    color: var(--text-secondary);
    white-space: nowrap;
}

.repayment-actions {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.btn-delete-repayment {
    background: transparent;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    font-size: 1.2rem;
    padding: 0.25rem;
    line-height: 1;
    border-radius: 0.25rem;
    transition: all 0.2s;
}

.btn-delete-repayment:hover {
    color: var(--ltv-danger);
    background: rgba(220, 38, 38, 0.08);
}

.btn-edit-repayment {
    background: transparent;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    font-size: 0.9rem;
    padding: 0.25rem;
    line-height: 1;
    border-radius: 0.25rem;
    transition: all 0.2s;
}

.btn-edit-repayment:hover {
    color: var(--accent);
    background: rgba(58, 79, 192, 0.08);
}

.repayment-info {
    display: flex;
    flex-direction: row;
    align-items: center;
    gap: 0.5rem;
    flex-wrap: wrap;
}

.btn-group {
    display: flex;
    gap: 0.5rem;
    flex-wrap: wrap;
}

/* Statistics Charts */
.chart-container {
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: 0.5rem;
    padding: 1rem;
    margin-bottom: 1rem;
    box-shadow: 0 1px 3px rgba(0,0,0,0.08);
}

.chart-title {
    font-size: 0.875rem;
    color: var(--text-secondary);
    margin-bottom: 0.75rem;
}

.simple-bar-chart {
    display: flex;
    align-items: flex-end;
    height: 150px;
    gap: 0.5rem;
    padding-top: 1rem;
}

.bar-item {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
}

.bar {
    width: 100%;
    max-width: 40px;
    border-radius: 4px 4px 0 0;
    transition: height 0.3s;
}

.bar.lender {
    background: var(--lender-primary);
}

.bar.borrower {
    background: var(--borrower-primary);
}

.bar-label {
    font-size: 0.7rem;
    color: var(--text-muted);
    margin-top: 0.25rem;
    text-align: center;
}

/* Import/Export */
/* Backup Summary */
.backup-summary {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
    gap: 1rem;
    padding: 1rem;
}

.backup-stat {
    text-align: center;
    padding: 1rem;
    background: var(--bg-secondary);
    border-radius: 0.5rem;
    box-shadow: 0 1px 3px rgba(0,0,0,0.08);
}

.backup-stat-value {
    font-size: 1.75rem;
    font-weight: 700;
    color: var(--text-primary);
}

.backup-stat-value.text-success {
    color: var(--lender-primary);
}

.backup-stat-label {
    font-size: 0.8rem;
    color: var(--text-muted);
    margin-top: 0.25rem;
}

.backup-stat-icon {
    font-size: 1.25rem;
    margin-bottom: 0.25rem;
}

.import-area {
    border: 2px dashed var(--border-color);
    border-radius: 0.5rem;
    padding: 2rem;
    text-align: center;
    transition: border-color 0.2s;
    background: var(--bg-secondary);
}

.import-area:hover {
    border-color: var(--accent);
}

.import-area.dragover {
    border-color: var(--accent);
    background: rgba(58, 79, 192, 0.06);
}

.import-icon {
    font-size: 2.5rem;
    margin-bottom: 0.5rem;
}

.file-input {
    display: none;
}

/* Stablecoins */
.stablecoins-table {
    width: 100%;
    border-collapse: collapse;
    min-width: 700px;
}

.stablecoins-table th,
.stablecoins-table td {
    padding: 0.75rem 0.5rem;
    text-align: left;
    border-bottom: 1px solid var(--border-color);
}

.stablecoins-table th {
    background: var(--bg-tertiary);
    font-weight: 500;
    font-size: 0.75rem;
    color: var(--text-secondary);
    white-space: nowrap;
    text-transform: uppercase;
    letter-spacing: 0.06em;
}

.stablecoins-table tbody tr:hover {
    background: var(--bg-tertiary);
}

.chain-badge {
    display: inline-block;
    padding: 0.15rem 0.5rem;
    border-radius: 4px;
    font-size: 0.7rem;
    font-weight: 500;
    background: var(--surface-2);
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.03em;
}

.chain-badge.chain-liquid,
.chain-badge.chain-tron,
.chain-badge.chain-ethereum,
.chain-badge.chain-lightning,
.chain-badge.chain-bitcoin {
    background: var(--surface-2);
    color: var(--text-secondary);
}

.source-badge {
    display: inline-block;
    padding: 0.125rem 0.375rem;
    border-radius: 0.25rem;
    font-size: 0.7rem;
    background: var(--surface-2);
    color: var(--text-muted);
    text-transform: uppercase;
    font-weight: 400;
}

/* Stagger animation */
/* A7: stagger delay capped via min() in CSS, JS caps --i at 10 */
.stagger-item {
    opacity: 0;
    animation: staggerIn 0.4s cubic-bezier(0.16, 1, 0.3, 1) forwards;
    animation-delay: calc(var(--i, 0) * 40ms);
}

@keyframes staggerIn {
    from { opacity: 0; transform: translateY(12px); }
    to { opacity: 1; transform: translateY(0); }
}

/* Platform badges */
.platform-badge {
    display: inline-flex;
    align-items: center;
    gap: 0.25rem;
    padding: 0.125rem 0.5rem;
    border-radius: 4px;
    font-size: 0.7rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.04em;
}
.platform-hodlhodl  { background: var(--surface-2); color: var(--text-secondary); }
.platform-debifi    { background: var(--surface-2); color: var(--text-secondary); }
.platform-lendasat  { background: var(--surface-2); color: var(--text-secondary); }
.platform-firefish  { background: var(--surface-2); color: var(--text-secondary); }

/* Dashboard Bento */
.dashboard-bento {
    display: grid;
    grid-template-columns: 2fr 1fr 1fr;
    gap: 1rem;
    margin-bottom: 1.5rem;
}
.dashboard-bento .hero-card {
    background: var(--surface-1);
    border: 1px solid rgba(0,0,0,0.06);
    border-radius: 12px;
    padding: 1.5rem;
    box-shadow: var(--shadow-sm);
    transition: all 0.3s cubic-bezier(0.16, 1, 0.3, 1);
}
.dashboard-bento .hero-card:hover {
    box-shadow: var(--shadow-md);
}
.hero-card .hero-label {
    text-transform: uppercase;
    letter-spacing: 0.08em;
    font-size: 0.75rem;
    color: var(--text-secondary);
    font-weight: 500;
    margin-bottom: 0.5rem;
}
.hero-card .hero-value {
    font-family: 'JetBrains Mono', 'SF Mono', monospace;
    font-size: clamp(1.5rem, 3vw, 2.5rem);
    letter-spacing: -0.03em;
    line-height: 1.1;
    color: var(--text-primary);
    font-weight: 600;
}
.hero-card .hero-sub {
    font-size: 0.8rem;
    color: var(--text-secondary);
    margin-top: 0.5rem;
}
.hero-card .hero-value.text-success { color: var(--ltv-safe); }
.hero-card .hero-value.text-warning { color: var(--borrower-primary); }
.hero-card .hero-value.text-danger { color: var(--ltv-danger); }

/* Secondary stats row */
.dashboard-stats-row {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
    gap: 0.75rem;
    margin-bottom: 1.5rem;
}
.dashboard-stats-row .mini-stat {
    background: var(--surface-1);
    border: 1px solid rgba(0,0,0,0.06);
    border-radius: 8px;
    padding: 1rem;
    box-shadow: var(--shadow-sm);
}
.mini-stat .mini-stat-label {
    text-transform: uppercase;
    letter-spacing: 0.06em;
    font-size: 0.75rem;
    color: var(--text-muted);
    font-weight: 500;
    margin-bottom: 0.25rem;
}
.mini-stat .mini-stat-value {
    font-family: 'JetBrains Mono', monospace;
    font-size: 1.1rem;
    font-weight: 600;
    color: var(--text-primary);
}
.mini-stat .mini-stat-sub {
    font-size: 0.75rem;
    color: var(--text-secondary);
    margin-top: 0.125rem;
}

/* Chart cards */
.dashboard-charts {
    display: grid;
    grid-template-columns: 3fr 2fr;
    gap: 1rem;
    margin-bottom: 1.5rem;
}
.chart-card {
    background: var(--surface-1);
    border: 1px solid rgba(0,0,0,0.06);
    border-radius: 12px;
    padding: 1.5rem;
    box-shadow: var(--shadow-sm);
}
.chart-card-header {
    margin-bottom: 1rem;
}
.chart-card-sm {
    /* smaller chart card */
}

/* Chart container (consistent height) */
.chart-container {
    position: relative;
    height: 300px;
}

/* ========================================
   Analytics — Liquidity Metrics
   ======================================== */
.liquidity-metrics-card {
    background: var(--surface-1);
    border: 1px solid rgba(0,0,0,0.06);
    border-radius: 12px;
    padding: 1.5rem;
    box-shadow: var(--shadow-sm);
    margin-bottom: 2rem;
}
.liquidity-metrics-header {
    margin-bottom: 1rem;
}
.liquidity-metrics-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 1rem;
}
.liquidity-metrics-grid .stat-card {
    box-shadow: none;
    border: 1px solid var(--border-color);
    background: var(--surface-2);
}

/* ========================================
   Analytics — Section spacing
   ======================================== */
#analytics-overview .stats-grid {
    margin-bottom: 2rem;
}
#analytics-overview .dashboard-charts {
    margin-top: 2rem;
}

/* ========================================
   Analytics — stat-value tabular nums
   ======================================== */
.stat-value {
    font-variant-numeric: tabular-nums;
}

/* ========================================
   Analytics Portfolio — Comparison card
   ======================================== */
.portfolio-comparison-card {
    background: var(--surface-1);
    border: 1px solid rgba(0,0,0,0.06);
    border-radius: 12px;
    padding: 1.5rem;
    box-shadow: var(--shadow-sm);
    margin-bottom: 1.5rem;
    overflow-x: auto;
}
.portfolio-comparison-card .comparison-title {
    margin-bottom: 1rem;
}

/* LTV Gauge (linear) */
.ltv-gauge {
    position: relative;
    height: 8px;
    background: var(--surface-2);
    border-radius: 4px;
    margin-top: 0.75rem;
    overflow: visible;
}
.ltv-gauge-fill {
    height: 100%;
    border-radius: 4px;
    transition: width 0.6s cubic-bezier(0.16, 1, 0.3, 1);
}
.ltv-gauge-marker {
    position: absolute;
    top: -4px;
    width: 1px;
    height: 16px;
    background: var(--text-muted);
    opacity: 0.5;
}
.ltv-gauge-marker-label {
    position: absolute;
    top: 14px;
    font-size: 0.75rem;
    color: var(--text-muted);
    transform: translateX(-50%);
}

/* Portfolio view */
.portfolio-group-cards {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
    gap: 1rem;
    margin-bottom: 1.5rem;
}
.portfolio-group-card {
    background: var(--surface-1);
    border: 1px solid rgba(0,0,0,0.06);
    border-radius: 12px;
    padding: 1.5rem;
    box-shadow: var(--shadow-sm);
}
.portfolio-group-card .group-name {
    font-weight: 600;
    font-size: 1.1rem;
    margin-bottom: 0.75rem;
    color: var(--text-primary);
}
.portfolio-group-card .group-stats {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0.5rem;
}
.portfolio-group-card .group-stat-label {
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--text-muted);
}
.portfolio-group-card .group-stat-value {
    font-family: 'JetBrains Mono', monospace;
    font-weight: 600;
    font-size: 0.95rem;
}
.portfolio-comparison-table {
    width: 100%;
    border-collapse: collapse;
}
.portfolio-comparison-table th,
.portfolio-comparison-table td {
    padding: 0.75rem 0.5rem;
    text-align: left;
    border-bottom: 1px solid var(--border-color);
}
.portfolio-comparison-table th {
    background: var(--bg-tertiary);
    font-weight: 600;
    font-size: 0.75rem;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.04em;
}
.portfolio-comparison-table tbody tr:hover {
    background: var(--bg-tertiary);
}

/* ========================================
   Loan List Improvements
   ======================================== */

/* A. Platform badge in loan rows */
.loan-row-platform {
    display: inline-flex;
    align-items: center;
    padding: 0.1rem 0.375rem;
    border-radius: 3px;
    font-size: 0.65rem;
    font-weight: 500;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    margin-left: 0.375rem;
    vertical-align: middle;
    background: var(--surface-2) !important;
    color: var(--text-secondary) !important;
}

/* B. Loan status left border for health — REMOVED in v9 (B1 noise reduction) */

/* C. Quick actions on hover — now in dedicated column */
.loans-table .actions-cell {
    width: 100px;
    min-width: 100px;
    padding: 0;
    position: relative;
}
.loans-table .actions-th {
    width: 100px;
    min-width: 100px;
}
.loan-row-actions {
    display: flex;
    gap: 0.25rem;
    opacity: 0;
    transition: opacity 0.15s;
    position: absolute;
    right: 0.5rem;
    top: 50%;
    transform: translateY(-50%);
}
.loans-table tbody tr {
    position: relative;
}
.loans-table tbody tr:hover .loan-row-actions,
.loans-table tbody tr:focus-within .loan-row-actions,
.loans-table tbody tr:focus .loan-row-actions {
    opacity: 1;
}
.loan-row-action-btn {
    background: var(--surface-1);
    border: 1px solid var(--border-color);
    border-radius: 4px;
    padding: 0.2rem 0.35rem;
    font-size: 0.75rem;
    cursor: pointer;
    color: var(--text-secondary);
    line-height: 1;
    transition: all 0.15s;
}
.loan-row-action-btn:hover {
    background: var(--accent);
    color: white;
    border-color: var(--accent);
}
.loan-row-action-btn.action-delete:hover {
    background: var(--ltv-danger);
    border-color: var(--ltv-danger);
}

/* D. Active sort column highlight */
.loans-table th.sort-active {
    color: var(--text-primary);
    background: var(--bg-secondary);
}
.loans-table th.sort-active .sort-icon {
    opacity: 1;
    color: var(--accent);
}

/* E. Summary/totals row improvements */
.loans-table .totals-row {
    background: var(--bg-tertiary);
    font-weight: 600;
}
.loans-table .totals-row td {
    border-top: 2px solid var(--border-color);
    padding: 0.75rem 0.5rem;
}

/* ========================================
   Loan Detail View Improvements
   ======================================== */

/* F. Detail header redesign */
.loan-detail-header-v2 {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    margin-bottom: 1.5rem;
    flex-wrap: wrap;
    gap: 1rem;
}
.loan-detail-identity {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    flex-wrap: wrap;
}
.loan-detail-name {
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--text-primary);
    margin-bottom: 0.75rem;
}
.loan-detail-meta-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 0.5rem;
}
.loan-detail-badges {
    display: flex;
    gap: 0.5rem;
    align-items: center;
    flex-wrap: wrap;
}
.loan-detail-actions {
    display: flex;
    gap: 0.5rem;
    flex-shrink: 0;
}

/* Key metrics hero row */
.loan-detail-hero-row {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
    gap: 0.75rem;
    margin-bottom: 1.5rem;
}
.loan-detail-hero-card {
    background: var(--surface-1);
    border: 1px solid rgba(0,0,0,0.06);
    border-radius: 10px;
    padding: 1.25rem;
    text-align: center;
    box-shadow: var(--shadow-sm);
    transition: transform 0.2s ease, box-shadow 0.2s ease;
}
.loan-detail-hero-card:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-md);
}
.loan-detail-hero-label {
    text-transform: uppercase;
    letter-spacing: 0.06em;
    font-size: 0.8rem;
    color: var(--text-muted);
    font-weight: 500;
    margin-bottom: 0.5rem;
}
.loan-detail-hero-num {
    font-family: 'JetBrains Mono', monospace;
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--text-primary);
}
.loan-detail-hero-sub {
    font-size: 0.7rem;
    color: var(--text-muted);
    margin-top: 0.25rem;
}

/* G. Copy button */
.copy-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 24px;
    height: 24px;
    background: var(--bg-tertiary);
    border: 1px solid var(--border-color);
    border-radius: 4px;
    cursor: pointer;
    color: var(--text-muted);
    font-size: 0.7rem;
    margin-left: 0.375rem;
    transition: all 0.15s;
    vertical-align: middle;
}
.copy-btn:hover {
    background: var(--accent);
    color: white;
    border-color: var(--accent);
}

/* H. Repayment timeline */
.repayment-timeline {
    position: relative;
    padding-left: 2rem;
}
.repayment-timeline::before {
    content: '';
    position: absolute;
    left: 0.75rem;
    top: 0;
    bottom: 0;
    width: 2px;
    background: var(--border-color);
}
.repayment-timeline-item {
    position: relative;
    margin-bottom: 1rem;
    padding: 0.75rem 1rem;
    background: var(--surface-1);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    box-shadow: var(--shadow-sm);
}
.repayment-timeline-item::before {
    content: '';
    position: absolute;
    left: -1.625rem;
    top: 1rem;
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background: var(--ltv-safe);
    border: 2px solid var(--surface-1);
    box-shadow: 0 0 0 2px var(--border-color);
}
.repayment-timeline-item.full-repayment::before {
    background: var(--ltv-safe);
    width: 12px;
    height: 12px;
    left: -1.69rem;
}
.repayment-timeline-item.partial-repayment::before {
    background: var(--ltv-caution);
}
.repayment-timeline-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 0.25rem;
}
.repayment-timeline-amount {
    font-family: 'JetBrains Mono', monospace;
    font-weight: 600;
    font-size: 1rem;
    color: var(--ltv-safe);
}
.repayment-timeline-type {
    font-size: 0.7rem;
    padding: 0.125rem 0.375rem;
    border-radius: 0.25rem;
    background: var(--bg-tertiary);
    text-transform: uppercase;
    font-weight: 600;
}
.repayment-timeline-meta {
    display: flex;
    gap: 1rem;
    font-size: 0.8rem;
    color: var(--text-secondary);
    flex-wrap: wrap;
}
.repayment-timeline-actions {
    display: flex;
    gap: 0.25rem;
    margin-top: 0.5rem;
}

/* I. LTV gauge in detail (larger version) */
.ltv-gauge-large {
    position: relative;
    height: 12px;
    background: var(--surface-2);
    border-radius: 6px;
    margin: 1rem 0;
    overflow: visible;
}
.ltv-gauge-large .ltv-gauge-fill {
    height: 100%;
    border-radius: 6px;
    transition: width 0.6s cubic-bezier(0.16, 1, 0.3, 1);
}
.ltv-gauge-large .ltv-gauge-marker {
    position: absolute;
    top: -6px;
    width: 1px;
    height: 24px;
    background: var(--text-muted);
    opacity: 0.5;
}
.ltv-gauge-large .ltv-gauge-marker-label {
    position: absolute;
    top: 20px;
    font-size: 0.7rem;
    color: var(--text-muted);
    transform: translateX(-50%);
}

/* J. Loan metadata footer */
.loan-metadata-footer {
    display: flex;
    flex-wrap: wrap;
    gap: 1.5rem;
    padding: 0.75rem 1rem;
    background: var(--bg-tertiary);
    border-radius: 8px;
    margin-top: 1rem;
    font-size: 0.75rem;
    color: var(--text-muted);
}
.loan-metadata-item {
    display: flex;
    align-items: center;
    gap: 0.375rem;
}
.loan-metadata-label {
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

/* NAV Breakdown */
.nav-breakdown {
    margin-top: 1rem;
    padding-top: 1rem;
    border-top: 1px solid var(--border-color);
}
.nav-breakdown-row {
    display: flex;
    justify-content: space-between;
    padding: 0.3rem 0;
    font-size: 0.85rem;
    color: var(--text-secondary);
}
.nav-breakdown-total {
    border-top: 1px solid var(--border-color);
    padding-top: 0.5rem;
    margin-top: 0.25rem;
    font-weight: 600;
    color: var(--text-primary);
}

/* Year Quick-Select Buttons */
.year-buttons {
    display: flex;
    gap: 0.25rem;
    flex-wrap: wrap;
}
.year-buttons-container .year-buttons {
    margin-bottom: 0;
}
.year-btn {
    padding: 0.4rem 0.75rem;
    border: 1px solid var(--border-color);
    border-radius: 6px;
    background: var(--surface-1);
    color: var(--text-secondary);
    font-size: 0.8rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s ease;
}
.year-btn:hover {
    border-color: var(--primary);
    color: var(--primary);
}
.year-btn.active {
    background: var(--primary);
    color: #fff;
    border-color: var(--primary);
}

/* Settings Redesign */
.settings-group {
    margin-bottom: 2rem;
}
.settings-group:last-child {
    margin-bottom: 0;
}
.settings-group-title {
    text-transform: uppercase;
    letter-spacing: 0.08em;
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--text-muted);
    margin-bottom: 1rem;
    padding-bottom: 0.5rem;
    border-bottom: 1px solid var(--border-color);
}
.settings-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.75rem 0;
    border-bottom: 1px solid var(--border-color);
}
.settings-row:last-child {
    border-bottom: none;
}
.settings-label {
    font-size: 0.9rem;
    color: var(--text-primary);
}
.settings-desc {
    font-size: 0.75rem;
    color: var(--text-muted);
    margin-top: 0.125rem;
}

/* Completed loans toggle row */
.completed-toggle-row {
    transition: background 0.15s;
}
.completed-toggle-row:hover td {
    background: var(--bg-secondary) !important;
}

/* Liquidated loan row: subtle visual differentiation */
/* Liquidated loan row: subtle opacity */
.loan-row-liquidated {
    opacity: 0.8;
}
.loan-row-liquidated:hover {
    opacity: 1;
}
.loan-counterparty-liquidated {
    text-decoration: line-through;
    text-decoration-color: var(--text-secondary);
    color: var(--text-secondary) !important;
}

/* Small dot indicator for liquidated loans */
.loan-liquidated-dot {
    display: inline-block;
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: var(--text-muted);
    margin-left: 0.35rem;
    vertical-align: middle;
    opacity: 0.7;
}

/* A8: LTV gauge inline value */
.ltv-gauge-value {
    position: absolute;
    right: 4px;
    top: 50%;
    transform: translateY(-50%);
    font-size: 0.6rem;
    font-weight: 700;
    font-family: 'JetBrains Mono', monospace;
    color: var(--text-primary);
}

/* A6: Mobile totals summary */
.mobile-totals-summary { display: none; }

/* B1: Reduced noise — normal weight for table cells */
.loans-table td {
    font-weight: 400;
    font-size: 0.85rem;
}
.loans-table td.font-mono {
    font-size: 0.8rem;
    letter-spacing: -0.02em;
}
.loans-table .amount-cell {
    font-weight: 500;
}
.loans-table .pct-sub {
    font-size: 0.7rem;
    color: var(--text-muted);
    margin-left: 0.25rem;
}

/* ========================================
   Settings Card Redesign (Iteration 11)
   ======================================== */
.settings-card {
    background: var(--surface-1);
    border: 1px solid var(--border-color);
    border-radius: 12px;
    padding: 1.5rem;
    margin-bottom: 1rem;
    box-shadow: var(--shadow-sm);
}
.settings-card-header {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    margin-bottom: 1rem;
}
.settings-card-icon {
    width: 40px;
    height: 40px;
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}
.settings-card-icon.export { background: rgba(58, 79, 192, 0.1); color: var(--primary); }
.settings-card-icon.import { background: rgba(5, 150, 105, 0.1); color: var(--ltv-safe); }
.settings-card-icon.danger { background: rgba(220, 38, 38, 0.1); color: var(--ltv-danger); }

.import-area-polished {
    border: 2px dashed var(--border-color);
    border-radius: 12px;
    padding: 2rem;
    text-align: center;
    background: var(--surface-0);
    transition: all 0.2s ease;
    cursor: pointer;
}
.import-area-polished:hover {
    border-color: var(--primary);
    background: rgba(58, 79, 192, 0.03);
}
.import-area-polished:active {
    background: rgba(58, 79, 192, 0.06);
    transform: scale(0.99);
}
.import-area-polished.dragover {
    border-color: var(--accent);
    background: rgba(58, 79, 192, 0.06);
}

.danger-card {
    border-color: rgba(220, 38, 38, 0.2);
    background: rgba(220, 38, 38, 0.02);
}

/* ========================================
   Loan Detail Section Cards (Iteration 11)
   ======================================== */
.loan-detail-section {
    background: var(--surface-1);
    border: 1px solid var(--border-color);
    border-radius: 12px;
    padding: 1.25rem;
    margin-bottom: 1.5rem;
    box-shadow: var(--shadow-sm);
}
.loan-detail-section-title {
    text-transform: uppercase;
    letter-spacing: 0.06em;
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--text-muted);
    margin-bottom: 1rem;
}
.loan-detail-header.status-active { border-left: 3px solid var(--primary); }
.loan-detail-header.status-completed { border-left: 3px solid var(--ltv-safe); }
.loan-detail-header.status-liquidated { border-left: 3px solid var(--ltv-danger); }

/* ========================================
   Year Buttons Container (Iteration 11)
   ======================================== */
.year-buttons-container {
    background: var(--surface-1);
    border: 1px solid var(--border-color);
    border-radius: 10px;
    padding: 0.75rem;
    margin-bottom: 1.5rem;
    display: flex;
    align-items: center;
    gap: 0.75rem;
    flex-wrap: wrap;
}
.year-buttons-label {
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--text-muted);
    font-weight: 500;
}

@media (max-width: 768px) {
    .dashboard-bento {
        grid-template-columns: 1fr;
    }
    .dashboard-charts {
        grid-template-columns: 1fr;
    }
    .dashboard-stats-row {
        grid-template-columns: 1fr 1fr;
    }
    .loan-detail-hero-row {
        grid-template-columns: 1fr 1fr;
    }
    /* Change 7: 5th hero card spans full width on mobile */
    .loan-detail-hero-row > :last-child {
        grid-column: 1 / -1;
    }
    .loan-row-actions {
        opacity: 1;
    }
    .mobile-totals-summary {
        display: grid;
        grid-template-columns: 1fr 1fr;
        gap: 0.5rem;
        margin-top: 1rem;
    }
    /* Hide actions column on mobile (already shown inline) */
    .loans-table .actions-cell,
    .loans-table .actions-th {
        display: none;
    }
}

/* ========================================
   Loans Table Column Stability (U3)
   ======================================== */
.loans-table th,
.loans-table td {
    min-width: 80px;
}
.loans-table .col-earned {
    min-width: 90px;
    text-align: right;
    font-variant-numeric: tabular-nums;
}

/* ========================================
   Detail Toggle (Iteration 12 - Change 2)
   ======================================== */
.detail-toggle {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    padding: 0.75rem;
    margin: 1.5rem 0;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    cursor: pointer;
    color: var(--text-secondary);
    font-size: 0.8rem;
    font-weight: 500;
    transition: all 0.2s ease;
    background: var(--surface-1);
    width: 100%;
}
.detail-toggle:hover {
    color: var(--primary);
    border-color: var(--primary);
}
.detail-toggle .chevron {
    transition: transform 0.2s ease;
    font-size: 0.6rem;
}
.detail-toggle.open .chevron { transform: rotate(180deg); }

#loanAdvancedSection {
    margin-top: 0.5rem;
    margin-bottom: 2rem;
    padding-bottom: 1rem;
    border-bottom: 1px solid var(--border-color);
}
#loanAdvancedSection .loan-detail-section {
    margin-bottom: 1.5rem;
}

.repayment-timeline {
    margin-top: 0.5rem;
}

/* ========================================
   Pre-signed TX Section
   ======================================== */
/* Space before TX section in loan detail */
.ps-loan-section {
    margin-top: 2rem;
    padding-top: 1.5rem;
    border-top: 1px solid var(--border-color);
}

.ps-tx-section .form-hint {
    font-size: 0.75rem;
    color: var(--text-muted);
}

/* ========================================
   Card-within-Card Fix (Iteration 12 - Change 7)
   ======================================== */
.loan-detail-section .inner-section {
    border-top: 1px solid var(--border-color);
    padding-top: 1rem;
    margin-top: 1rem;
}

/* ========================================
   Loan Detail V3 — Premium Redesign
   ======================================== */

/* --- Hero Banner --- */
.ld3-hero {
    position: relative;
    background: var(--surface-1);
    border: 1px solid rgba(0,0,0,0.06);
    border-radius: 12px;
    overflow: hidden;
    margin-bottom: 1.5rem;
    box-shadow: var(--shadow-sm);
    animation: ld3-fadeUp 0.35s cubic-bezier(0.16, 1, 0.3, 1) backwards;
}
.ld3-hero-accent {
    height: 3px;
    width: 100%;
    position: relative;
    overflow: hidden;
}
.ld3-hero-accent::after {
    display: none;
}
/* Stagger entrance animation for metrics */
.ld3-metric {
    animation: ld3-fadeUp 0.4s cubic-bezier(0.16, 1, 0.3, 1) backwards;
}
.ld3-metric:nth-child(1) { animation-delay: 0.05s; }
.ld3-metric:nth-child(2) { animation-delay: 0.1s; }
.ld3-metric:nth-child(3) { animation-delay: 0.15s; }
.ld3-metric:nth-child(4) { animation-delay: 0.2s; }
.ld3-metric:nth-child(5) { animation-delay: 0.25s; }
@keyframes ld3-fadeUp {
    from { opacity: 0; transform: translateY(8px); }
    to { opacity: 1; transform: translateY(0); }
}
.ld3-hero-accent.status-active { background: var(--primary); }
.ld3-hero-accent.status-completed { background: var(--ltv-safe); }
.ld3-hero-accent.status-liquidated { background: var(--ltv-danger); }

.ld3-hero-body {
    padding: 1.5rem 1.75rem 1.25rem;
}
[data-theme="dark"] .ld3-hero-body {
    background: transparent;
}
.ld3-hero-top {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 1rem;
    margin-bottom: 1.25rem;
}
.ld3-hero-identity {
    flex: 1;
    min-width: 0;
}
.ld3-counterparty {
    font-size: 1.5rem;
    font-weight: 600;
    color: var(--text-primary);
    line-height: 1.2;
    margin-bottom: 0.5rem;
    letter-spacing: -0.01em;
    display: flex;
    align-items: center;
    gap: 0.625rem;
}
.ld3-badges {
    display: flex;
    gap: 0.5rem;
    align-items: center;
    flex-wrap: wrap;
}
.ld3-badge {
    display: inline-flex;
    align-items: center;
    gap: 0.25rem;
    padding: 0.15rem 0.5rem;
    border-radius: 4px;
    font-size: 0.65rem;
    font-weight: 500;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    background: var(--surface-2);
    color: var(--text-secondary);
    border: none;
}
.ld3-badge-platform {
    background: var(--surface-2);
    color: var(--text-secondary) !important;
}
.ld3-badge-role {
    background: var(--surface-2);
    color: var(--text-secondary);
}
.ld3-badge-status {
    background: var(--surface-2);
    color: var(--text-secondary);
}
.ld3-badge-status.status-active { color: var(--text-secondary); background: var(--surface-2); }
.ld3-badge-status.status-completed { color: var(--ltv-safe); background: rgba(52, 211, 153, 0.06); }
.ld3-badge-status.status-liquidated { color: var(--ltv-danger); background: rgba(239, 68, 68, 0.06); }

.ld3-actions {
    display: flex;
    gap: 0.375rem;
    flex-shrink: 0;
}
.ld3-actions .btn {
    font-size: 0.8rem;
    padding: 0.4rem 0.75rem;
    border-radius: 8px;
}

/* --- Amount + LTV Summary Row --- */
.ld3-summary-row {
    display: flex;
    align-items: center;
    gap: 1.5rem;
    padding: 1rem 0 0;
    border-top: 1px solid var(--border-color);
    flex-wrap: wrap;
}
.ld3-amount-block {
    flex-shrink: 0;
}
.ld3-amount-label {
    font-size: 0.7rem;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--text-muted);
    font-weight: 500;
    margin-bottom: 0.25rem;
}
.ld3-amount-value {
    font-family: 'JetBrains Mono', 'SF Mono', monospace;
    font-size: clamp(1.5rem, 3vw, 2rem);
    font-weight: 600;
    color: var(--text-primary);
    letter-spacing: -0.03em;
    line-height: 1.1;
}
.ld3-amount-currency {
    font-size: 0.75rem;
    color: var(--text-muted);
    font-weight: 400;
    margin-top: 0.125rem;
}
.ld3-ltv-compact {
    flex: 1;
    min-width: 200px;
}
.ld3-ltv-header {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    margin-bottom: 0.375rem;
}
.ld3-ltv-label {
    font-size: 0.7rem;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--text-muted);
    font-weight: 500;
}
.ld3-ltv-number {
    font-family: 'JetBrains Mono', monospace;
    font-size: 1rem;
    font-weight: 600;
}
.ld3-ltv-track {
    position: relative;
    height: 8px;
    background: var(--surface-2);
    border-radius: 4px;
    overflow: visible;
}
.ld3-ltv-fill {
    height: 100%;
    border-radius: 4px;
    transition: width 0.8s cubic-bezier(0.16, 1, 0.3, 1);
    position: relative;
}
.ld3-ltv-fill::after {
    content: '';
    position: absolute;
    right: 0;
    top: 50%;
    transform: translateY(-50%);
    width: 14px;
    height: 14px;
    border-radius: 50%;
    background: inherit;
    border: 2px solid var(--surface-1);
    box-shadow: 0 0 0 1px var(--border-color);
}
.ld3-ltv-markers {
    display: flex;
    justify-content: space-between;
    margin-top: 0.375rem;
    padding: 0 0.125rem;
}
.ld3-ltv-marker {
    font-size: 0.6rem;
    color: var(--text-muted);
    cursor: default;
    position: relative;
}
.ld3-ltv-marker::before {
    content: '';
    position: absolute;
    top: -0.625rem;
    left: 50%;
    transform: translateX(-50%);
    width: 1px;
    height: 4px;
    background: var(--text-muted);
    opacity: 0.4;
}

/* --- Alert Banner --- */
.ld3-alert {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.625rem 1rem;
    border-radius: 8px;
    margin-bottom: 1.25rem;
    font-size: 0.8rem;
    font-weight: 400;
}
.ld3-alert-icon {
    flex-shrink: 0;
    width: 20px;
    height: 20px;
}
.ld3-alert.warning {
    background: rgba(251, 191, 36, 0.08);
    border: 1px solid rgba(251, 191, 36, 0.2);
    color: var(--ltv-caution);
}
.ld3-alert.danger {
    background: rgba(239, 68, 68, 0.08);
    border: 1px solid rgba(239, 68, 68, 0.2);
    color: var(--ltv-danger);
}

/* --- Metrics Grid --- */
.ld3-metrics {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
    gap: 0.75rem;
    margin-bottom: 2rem;
}
.ld3-metric {
    background: var(--surface-1);
    border: 1px solid rgba(0,0,0,0.06);
    border-radius: 8px;
    padding: 1rem;
    position: relative;
    box-shadow: var(--shadow-sm);
    transition: transform 0.2s cubic-bezier(0.16, 1, 0.3, 1), box-shadow 0.2s ease;
    overflow: hidden;
}
.ld3-metric-minibar {
    margin-top: 0.5rem;
    height: 3px;
    background: var(--surface-2);
    border-radius: 2px;
    overflow: hidden;
}
.ld3-metric-minibar-fill {
    height: 100%;
    border-radius: 2px;
    transition: width 0.6s cubic-bezier(0.16, 1, 0.3, 1);
}
.ld3-metric-label {
    text-transform: uppercase;
    letter-spacing: 0.06em;
    font-size: 0.75rem;
    color: var(--text-muted);
    font-weight: 500;
    margin-bottom: 0.25rem;
    display: flex;
    align-items: center;
    gap: 0.375rem;
}
.ld3-metric-value {
    font-family: 'JetBrains Mono', monospace;
    font-size: 1.1rem;
    font-weight: 600;
    color: var(--text-primary);
    line-height: 1.2;
}
.ld3-metric-sub {
    font-size: 0.75rem;
    color: var(--text-secondary);
    margin-top: 0.125rem;
    font-family: 'Inter', sans-serif;
    font-weight: 400;
}
.ld3-metric-accent {
    display: none;
}

/* --- Progress Bar (loan timeline) --- */
.ld3-progress-section {
    margin-bottom: 2rem;
    padding-top: 0.25rem;
}
.ld3-progress-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 0.5rem;
}
.ld3-progress-label {
    font-size: 0.75rem;
    color: var(--text-secondary);
    font-weight: 500;
}
.ld3-progress-dates {
    display: flex;
    gap: 1rem;
    font-size: 0.7rem;
    color: var(--text-muted);
}
.ld3-progress-track {
    height: 6px;
    background: var(--surface-2);
    border-radius: 3px;
    overflow: hidden;
}
.ld3-progress-fill {
    height: 100%;
    border-radius: 3px;
    background: var(--primary);
    transition: width 0.6s cubic-bezier(0.16, 1, 0.3, 1);
}
.ld3-progress-meta {
    display: flex;
    justify-content: space-between;
    margin-top: 0.375rem;
    font-size: 0.7rem;
    color: var(--text-muted);
}

/* --- Two-column detail layout --- */
.ld3-columns {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1.5rem;
    margin-bottom: 2rem;
}

/* --- Section Cards V3 --- */
.ld3-section {
    background: var(--surface-1);
    border: 1px solid rgba(0,0,0,0.06);
    border-radius: 12px;
    padding: 1.25rem;
    margin-bottom: 1.25rem;
    box-shadow: var(--shadow-sm);
}
.ld3-section-title {
    text-transform: uppercase;
    letter-spacing: 0.06em;
    font-size: 0.75rem;
    font-weight: 500;
    color: var(--text-secondary);
    margin-bottom: 1rem;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}
.ld3-section-title svg {
    opacity: 0.4;
    flex-shrink: 0;
}

/* --- Detail Rows V3 --- */
.ld3-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.5rem 0;
    gap: 0.75rem;
}
.ld3-row + .ld3-row {
    border-top: 1px solid var(--border-color);
}
.ld3-row-label {
    font-size: 0.8rem;
    color: var(--text-muted);
    flex-shrink: 0;
    font-weight: 400;
}
.ld3-row-value {
    font-size: 0.8rem;
    font-weight: 500;
    color: var(--text-primary);
    text-align: right;
    word-break: break-all;
    min-width: 0;
}
.ld3-row-value.mono {
    font-family: 'JetBrains Mono', monospace;
    font-size: 0.8rem;
}

/* --- Repayment Timeline V3 --- */
.ld3-repayments-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1rem;
    flex-wrap: wrap;
    gap: 0.5rem;
}
.ld3-repayments-header h3 {
    text-transform: uppercase;
    letter-spacing: 0.06em;
    font-size: 0.75rem;
    font-weight: 500;
    color: var(--text-secondary);
    margin: 0;
}
.ld3-repayments-actions {
    display: flex;
    gap: 0.375rem;
    flex-wrap: wrap;
}

.ld3-timeline {
    position: relative;
    padding-left: 2rem;
}
.ld3-timeline::before {
    content: '';
    position: absolute;
    left: 7px;
    top: 8px;
    bottom: 8px;
    width: 2px;
    background: linear-gradient(to bottom, var(--border-color), transparent);
    border-radius: 1px;
}
.ld3-timeline-item {
    position: relative;
    margin-bottom: 0.75rem;
    padding: 0.75rem 1rem;
    background: var(--surface-2);
    border-radius: 8px;
    transition: background 0.15s ease;
}
.ld3-timeline-item:hover {
    background: var(--bg-tertiary);
}
.ld3-timeline-item::before {
    content: '';
    position: absolute;
    left: -1.625rem;
    top: 1.05rem;
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background: var(--primary);
    border: 2px solid var(--surface-1);
    z-index: 1;
}
.ld3-timeline-item.partial::before {
    background: var(--text-muted);
}
.ld3-timeline-top {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 0.25rem;
}
.ld3-timeline-amount {
    font-family: 'JetBrains Mono', monospace;
    font-weight: 600;
    font-size: 0.95rem;
    color: var(--text-primary);
}
.ld3-timeline-type {
    font-size: 0.65rem;
    padding: 0.125rem 0.4rem;
    border-radius: 4px;
    background: var(--surface-2);
    color: var(--text-secondary);
    font-weight: 500;
    text-transform: uppercase;
    letter-spacing: 0.04em;
}
.ld3-timeline-item.partial .ld3-timeline-type {
    background: var(--surface-2);
    color: var(--text-muted);
}
.ld3-timeline-meta {
    display: flex;
    gap: 0.75rem;
    font-size: 0.75rem;
    color: var(--text-muted);
    flex-wrap: wrap;
    align-items: center;
}
.ld3-timeline-meta a {
    color: var(--accent);
    text-decoration: none;
    font-family: 'JetBrains Mono', monospace;
    font-size: 0.7rem;
}
.ld3-timeline-meta a:hover {
    text-decoration: underline;
}
.ld3-timeline-edit {
    display: flex;
    gap: 0.25rem;
    margin-left: auto;
}
.ld3-timeline-edit button {
    background: none;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    padding: 0.125rem 0.25rem;
    border-radius: 4px;
    font-size: 0.8rem;
    transition: color 0.15s ease, background 0.15s ease;
}
.ld3-timeline-edit button:hover {
    color: var(--text-primary);
    background: var(--surface-1);
}
@media (max-width: 768px) {
    .ld3-timeline-edit button {
        min-width: 36px;
        min-height: 36px;
        display: inline-flex;
        align-items: center;
        justify-content: center;
    }
}

/* --- Empty state V3 --- */
.ld3-empty {
    text-align: center;
    padding: 2rem 1rem;
    color: var(--text-muted);
}
.ld3-empty-icon {
    font-size: 1.5rem;
    margin-bottom: 0.5rem;
    opacity: 0.4;
}
.ld3-empty-text {
    font-size: 0.85rem;
}

/* --- Health summary sentence --- */
.ld3-health-summary {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.5rem 0;
    font-size: 0.8rem;
    color: var(--text-secondary);
    margin-bottom: 1rem;
}
.ld3-health-summary.safe-state { }
.ld3-health-summary.warning-state { }
.ld3-health-summary.danger-state { }
.ld3-health-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    flex-shrink: 0;
}
.ld3-health-dot.safe { background: var(--ltv-safe); }
.ld3-health-dot.caution { background: var(--ltv-caution); }
.ld3-health-dot.warning { background: var(--ltv-warning); }
.ld3-health-dot.danger { background: var(--ltv-danger); }
.ld3-health-dot.critical { background: var(--ltv-danger); animation: pulse 1.5s ease infinite; }

/* --- Metadata Footer V3 --- */
.ld3-footer {
    display: flex;
    flex-wrap: wrap;
    gap: 1.25rem;
    padding: 0.75rem 0;
    border-top: 1px solid var(--border-color);
    font-size: 0.7rem;
    color: var(--text-muted);
    margin-top: 1rem;
}
.ld3-footer-item {
    display: flex;
    align-items: center;
    gap: 0.3rem;
}
.ld3-footer-label {
    font-weight: 500;
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

/* --- Dark mode refinements --- */
[data-theme="dark"] .ld3-hero {
    border-color: var(--border-color);
}
[data-theme="dark"] .ld3-metric {
    border-color: var(--border-color);
}
[data-theme="dark"] .ld3-section {
    border-color: var(--border-color);
}
[data-theme="dark"] .ld3-timeline-item {
    background: rgba(255, 255, 255, 0.03);
}
[data-theme="dark"] .ld3-timeline-item:hover {
    background: rgba(255, 255, 255, 0.06);
}
[data-theme="dark"] .ld3-footer {
    border-top-color: var(--border-color);
}

/* --- Responsive --- */
@media (max-width: 900px) {
    .ld3-columns {
        grid-template-columns: 1fr;
    }
}
@media (max-width: 768px) {
    .ld3-metrics {
        grid-template-columns: 1fr 1fr;
    }
    .ld3-counterparty {
        font-size: 1.375rem;
    }
    .ld3-amount-value {
        font-size: 1.5rem;
    }
    .ld3-hero-body {
        padding: 1.25rem 1.25rem 1rem;
    }
    .ld3-hero-top {
        flex-direction: column;
        gap: 0.75rem;
    }
    .ld3-actions {
        width: 100%;
        justify-content: flex-start;
    }
    .ld3-summary-row {
        flex-direction: column;
        align-items: flex-start;
        gap: 1rem;
    }
    .ld3-ltv-compact {
        width: 100%;
        min-width: unset;
    }
}
@media (max-width: 480px) {
    .ld3-metrics {
        grid-template-columns: 1fr 1fr;
        gap: 0.5rem;
    }
    .ld3-metric {
        padding: 0.75rem 0.875rem;
    }
    .ld3-metric-value {
        font-size: 1.05rem;
    }
    .ld3-metric-label {
        font-size: 0.625rem;
    }
    .ld3-repayments-actions {
        width: 100%;
    }
    .ld3-repayments-actions .btn {
        flex: 1;
        justify-content: center;
        font-size: 0.75rem;
    }
    .ld3-timeline {
        padding-left: 1.5rem;
    }
    .ld3-timeline-item::before {
        left: -1.25rem;
        width: 8px;
        height: 8px;
    }
    .ld3-timeline::before {
        left: 5px;
    }
}
@media (max-width: 360px) {
    .ld3-actions .btn {
        font-size: 0.7rem;
        padding: 0.3rem 0.5rem;
    }
}

/* ========================================
   Year Buttons Mobile Scroll (Iteration 12 - Change 6)
   ======================================== */
@media (max-width: 480px) {
    .year-buttons {
        flex-wrap: nowrap;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        scrollbar-width: none;
    }
    .year-buttons::-webkit-scrollbar { display: none; }
}

/* ========================================
   OMV Calculator (Iteration 12 - U2)
   ======================================== */
.omv-calculator {
    max-width: 100%;
}
.omv-title {
    font-size: 1.5rem;
    font-weight: 700;
    margin-bottom: 0.25rem;
}
.omv-subtitle {
    color: var(--text-secondary);
    font-size: 0.875rem;
    margin-bottom: 2rem;
}
.omv-card {
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: 12px;
    padding: 1.5rem;
    margin-bottom: 1.25rem;
}
.omv-card-title {
    font-size: 0.8rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-secondary);
    margin-bottom: 1rem;
}
.omv-input-row {
    display: flex;
    gap: 1rem;
    flex-wrap: wrap;
    align-items: flex-end;
    margin-bottom: 1.25rem;
}
.omv-input-field {
    flex: 1;
    min-width: 130px;
}
.omv-input-field label {
    display: block;
    font-size: 0.75rem;
    font-weight: 500;
    color: var(--text-secondary);
    margin-bottom: 0.25rem;
}
.omv-input-field input {
    font-family: 'JetBrains Mono', 'SF Mono', monospace;
    font-size: 1rem;
    padding: 0.5rem 0.75rem;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    background: var(--bg-primary);
    color: var(--text-primary);
    width: 100%;
    text-align: right;
}
.omv-input-field input:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(58, 79, 192, 0.1);
}
.omv-unit {
    font-size: 0.7rem;
    color: var(--text-muted);
    margin-top: 0.15rem;
}
.omv-derived-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.6rem 0;
    border-top: 1px solid var(--border-color);
    font-size: 0.85rem;
}
.omv-derived-row .omv-label { color: var(--text-secondary); }
.omv-derived-row .omv-value {
    font-family: 'JetBrains Mono', monospace;
    font-weight: 600;
    color: var(--primary);
}
.omv-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.85rem;
}
.omv-table th {
    text-align: right;
    font-size: 0.7rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-secondary);
    padding: 0.5rem 0.75rem;
    border-bottom: 2px solid var(--border-color);
}
.omv-table td {
    padding: 0.5rem 0.75rem;
    text-align: right;
    font-family: 'JetBrains Mono', monospace;
    font-size: 0.8rem;
    border-bottom: 1px solid var(--border-color);
}
.omv-table td:first-child {
    text-align: left;
    font-weight: 600;
}
tr.omv-breakeven { background: rgba(58, 79, 192, 0.08); }
tr.omv-negative td { color: var(--ltv-danger); }
tr.omv-positive td { color: var(--ltv-safe); }
tr.omv-breakeven td { color: var(--primary); font-weight: 600; }
.omv-insight {
    font-size: 0.8rem;
    color: var(--text-secondary);
    margin-top: 1rem;
    padding: 0.75rem 1rem;
    border-left: 3px solid var(--primary);
    background: rgba(58, 79, 192, 0.06);
    border-radius: 0 8px 8px 0;
}
.omv-insight strong { color: var(--text-primary); }
@media (max-width: 600px) {
    .omv-input-row { flex-direction: column; }
    .omv-input-field { min-width: 100%; }
    .omv-table { font-size: 0.75rem; }
    .omv-table td, .omv-table th { padding: 0.4rem 0.5rem; }
}

/* OMV condensed on mobile — show only 1, 3, 6, 9, 12 */
@media (max-width: 480px) {
    .omv-table.omv-condensed tbody tr:nth-child(2),
    .omv-table.omv-condensed tbody tr:nth-child(4),
    .omv-table.omv-condensed tbody tr:nth-child(5),
    .omv-table.omv-condensed tbody tr:nth-child(7),
    .omv-table.omv-condensed tbody tr:nth-child(8),
    .omv-table.omv-condensed tbody tr:nth-child(10),
    .omv-table.omv-condensed tbody tr:nth-child(11) {
        display: none;
    }
}

/* SR-only utility */
.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0,0,0,0);
    border: 0;
}

/* Portfolio copy button */
.copy-portfolio-btn {
    background: none;
    border: none;
    cursor: pointer;
    color: var(--text-muted);
    padding: 2px 4px;
    margin-left: 4px;
    vertical-align: middle;
    opacity: 0.5;
    transition: opacity 0.2s;
}
.copy-portfolio-btn:hover {
    opacity: 1;
    color: var(--text-primary);
}
.copy-portfolio-btn svg {
    width: 14px;
    height: 14px;
    vertical-align: middle;
}

/* ========================================
   Pre-signed TX Calculator
   ======================================== */
.ps-calculator {
    max-width: 100%;
}
.ps-loan-select-row {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    margin-bottom: 1rem;
    flex-wrap: wrap;
}
.ps-loan-select-row label {
    font-size: 0.8rem;
    font-weight: 500;
    color: var(--text-secondary);
    white-space: nowrap;
}
.ps-loan-select-row select {
    flex: 1;
    min-width: 200px;
    padding: 0.4rem 0.6rem;
    border-radius: 6px;
    border: 1px solid var(--border-color);
    background: var(--bg-primary);
    color: var(--text-primary);
    font-size: 0.8rem;
}
.ps-highlight-row td {
    color: var(--text-primary);
}
.presigned-phases { margin: 1rem 0; }
.phase-row {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    margin-bottom: 0.5rem;
}
.phase-label {
    min-width: 180px;
    font-size: 0.8rem;
    color: var(--text-secondary);
}
.phase-bar {
    height: 28px;
    border-radius: 4px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #fff;
    font-size: 0.75rem;
    font-weight: 600;
    font-family: 'JetBrains Mono', monospace;
    min-width: 48px;
    transition: width 0.3s ease;
}
.phase-ltv {
    font-size: 0.75rem;
    font-family: 'JetBrains Mono', monospace;
    color: var(--text-muted);
    white-space: nowrap;
}
.ps-explanation {
    margin-top: 1rem;
    padding: 0.75rem 1rem;
    background: var(--bg-tertiary);
    border-radius: 8px;
    font-size: 0.8rem;
    color: var(--text-secondary);
    line-height: 1.5;
}
.ps-explanation p { margin: 0.25rem 0; }
@media (max-width: 640px) {
    .phase-label { min-width: 120px; font-size: 0.7rem; }
    .phase-bar { height: 24px; font-size: 0.65rem; min-width: 40px; }
    .ps-loan-select-row { flex-direction: column; align-items: flex-start; }
    .ps-loan-select-row select { width: 100%; }
}

/* ========================================
   Capital Flows (Iteration 23)
   ======================================== */
.capital-hero {
    display: grid;
    grid-template-columns: 1fr;
    gap: 1rem;
    margin-bottom: 1.5rem;
}
.capital-hero .hero-card {
    text-align: center;
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: 0.75rem;
    padding: 1.25rem;
    box-shadow: 0 1px 3px rgba(0,0,0,0.08);
    transition: transform 0.2s, box-shadow 0.2s;
}
.capital-hero .hero-card:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-md);
}
.capital-stats-row {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 1rem;
    margin-bottom: 1.5rem;
}
.capital-stats-row .stat-card {
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: 0.75rem;
    padding: 1rem;
    box-shadow: 0 1px 3px rgba(0,0,0,0.08);
}
.capital-stats-row .stat-label {
    font-size: 0.8rem;
    color: var(--text-muted);
    margin-bottom: 0.25rem;
}
.capital-stats-row .stat-value {
    font-size: 1.25rem;
    font-weight: 600;
}
.capital-stats-row .stat-sub {
    font-size: 0.75rem;
    color: var(--text-secondary);
    margin-top: 0.25rem;
}
.capital-actions {
    display: flex;
    gap: 0.75rem;
    margin-bottom: 1.5rem;
}
.capital-events-section {
    margin-top: 1.5rem;
}
.capital-events-section .section-title {
    font-size: 1rem;
    font-weight: 600;
    margin-bottom: 1rem;
}
.capital-events-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.85rem;
}
.capital-events-table th {
    text-align: left;
    padding: 0.5rem 0.75rem;
    border-bottom: 2px solid var(--border-color);
    font-weight: 600;
    font-size: 0.75rem;
    text-transform: uppercase;
    color: var(--text-muted);
}
.capital-events-table td {
    padding: 0.5rem 0.75rem;
    border-bottom: 1px solid var(--border-color);
    vertical-align: middle;
}
.capital-events-table tbody tr:hover {
    background: var(--bg-tertiary);
}
.capital-event-type-badge {
    display: inline-block;
    padding: 0.15rem 0.5rem;
    border-radius: 4px;
    font-size: 0.75rem;
    font-weight: 500;
    background: var(--bg-tertiary);
    color: var(--text-secondary);
}
.capital-event-type-badge.badge-deposit { background: rgba(52, 199, 89, 0.15); color: var(--ltv-safe); }
.capital-event-type-badge.badge-withdrawal { background: rgba(255, 59, 48, 0.15); color: var(--ltv-danger); }
.capital-event-type-badge.badge-interest_earned { background: rgba(52, 199, 89, 0.15); color: var(--ltv-safe); }
.capital-event-type-badge.badge-loan_disbursed { background: rgba(0, 122, 255, 0.15); color: var(--accent-color); }
.capital-event-type-badge.badge-loan_repaid { background: rgba(0, 122, 255, 0.15); color: var(--accent-color); }
.capital-event-type-badge.badge-swap_cost { background: rgba(255, 149, 0, 0.15); color: var(--ltv-caution); }
.capital-event-type-badge.badge-origination_fee { background: rgba(255, 149, 0, 0.15); color: var(--ltv-caution); }
.capital-event-type-badge.badge-liquidation_proceeds { background: rgba(255, 59, 48, 0.15); color: var(--ltv-danger); }
.source-badge {
    display: inline-block;
    padding: 0.1rem 0.4rem;
    border-radius: 3px;
    font-size: 0.7rem;
    font-weight: 500;
}
.source-backfill {
    background: var(--bg-tertiary);
    color: var(--text-muted);
}
.source-manual {
    background: rgba(0, 122, 255, 0.1);
    color: var(--accent-color);
}
.source-loan-funded {
    background: rgba(255, 149, 0, 0.1);
    color: #e68a00;
}
.source-loan-repayment {
    background: rgba(52, 199, 89, 0.1);
    color: #28a745;
}
.source-btc-conversion {
    background: rgba(247, 147, 26, 0.1);
    color: #f7931a;
}
.backfill-prompt {
    background: var(--bg-secondary);
    border: 1px dashed var(--border-color);
    border-radius: 0.75rem;
    padding: 1.25rem;
    text-align: center;
    margin-bottom: 1.5rem;
}
.backfill-prompt .backfill-prompt-text {
    font-size: 0.9rem;
    color: var(--text-secondary);
    margin-bottom: 1rem;
    line-height: 1.5;
}
.capital-waterfall-section {
    margin-bottom: 1.5rem;
}
.capital-waterfall-section .section-title {
    font-size: 1rem;
    font-weight: 600;
    margin-bottom: 1rem;
}
.capital-waterfall-chart-container {
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: 0.75rem;
    padding: 1rem;
    height: 300px;
    position: relative;
}
.source-inferred {
    background: rgba(255, 149, 0, 0.15);
    color: var(--ltv-caution);
}
.inferred-row {
    opacity: 0.7;
    font-style: italic;
}
@media (max-width: 640px) {
    .capital-stats-row { grid-template-columns: 1fr 1fr; }
    .capital-actions { flex-direction: column; }
    .capital-events-table { font-size: 0.75rem; }
    .capital-events-table th, .capital-events-table td { padding: 0.4rem 0.5rem; }
    .capital-waterfall-chart-container { height: 220px; }
}

/* ========================================
   Bitcoin Holdings Tab
   ======================================== */
.btc-status-badge {
    display: inline-block;
    padding: 0.15rem 0.5rem;
    border-radius: 999px;
    font-size: 0.75rem;
    font-weight: 500;
}
.btc-status-pending {
    background: rgba(255, 179, 0, 0.15);
    color: var(--ltv-caution, #f5a623);
}
.btc-status-converted {
    background: rgba(52, 199, 89, 0.15);
    color: var(--ltv-safe, #34c759);
}

/* ========================================
   BBD Calculator (v47)
   ======================================== */
.bbd-presets {
    display: flex;
    gap: 0.5rem;
    margin-bottom: 1.5rem;
    flex-wrap: wrap;
}
.bbd-preset-btn {
    padding: 0.4rem 1rem;
    border-radius: 20px;
    border: 1px solid var(--border-color);
    background: var(--surface-1);
    color: var(--text-secondary);
    font-size: 0.8rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.15s ease;
}
.bbd-preset-btn:hover, .bbd-preset-btn:focus {
    border-color: var(--primary);
    color: var(--primary);
    background: rgba(58, 79, 192, 0.06);
}
.bbd-preset-btn.active {
    border-color: var(--primary);
    background: var(--primary);
    color: #fff;
}
.bbd-hero-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
    gap: 0.75rem;
    margin-bottom: 1.5rem;
}
.bbd-hero-card {
    padding: 0.75rem;
    background: var(--surface-1);
    border-radius: 8px;
    border: 1px solid rgba(0,0,0,0.06);
}
.bbd-hero-card .stat-label {
    font-size: 0.7rem;
    margin-bottom: 0.25rem;
}
.bbd-hero-card .stat-value {
    font-size: 1.1rem;
}
.bbd-hero-card .bbd-hero-sub {
    font-size: 0.7rem;
    color: var(--text-muted);
    margin-top: 0.15rem;
}
.bbd-status-badge {
    display: inline-block;
    padding: 0.15rem 0.5rem;
    border-radius: 12px;
    font-size: 0.7rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.03em;
}
.bbd-status-safe { background: rgba(52, 199, 89, 0.15); color: var(--ltv-safe); }
.bbd-status-caution { background: rgba(255, 179, 0, 0.15); color: var(--ltv-caution, #f5a623); }
.bbd-status-critical { background: rgba(255, 59, 48, 0.15); color: var(--ltv-danger); }
.bbd-status-failed { background: rgba(255, 59, 48, 0.25); color: var(--ltv-danger); font-weight: 700; }
.bbd-stress-card {
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: 12px;
    padding: 1.25rem;
    margin-bottom: 1.25rem;
}
.bbd-stress-row {
    display: flex;
    gap: 0.75rem;
    align-items: flex-end;
    flex-wrap: wrap;
}
.bbd-stress-row .omv-input-field { min-width: 100px; flex: 0 0 auto; }
.bbd-stress-result {
    padding: 0.75rem 1rem;
    border-radius: 8px;
    margin-top: 0.75rem;
    font-size: 0.85rem;
    font-weight: 500;
}
.bbd-stress-survives {
    background: rgba(52, 199, 89, 0.1);
    border-left: 3px solid var(--ltv-safe);
    color: var(--ltv-safe);
}
.bbd-stress-fails {
    background: rgba(255, 59, 48, 0.1);
    border-left: 3px solid var(--ltv-danger);
    color: var(--ltv-danger);
}
.bbd-input-group-label {
    font-size: 0.7rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-muted);
    margin-bottom: 0.5rem;
    margin-top: 0.75rem;
}
.bbd-input-group-label:first-child { margin-top: 0; }
/* BBD calculator: force consistent 4-column grid for all input rows */
#bbdCalculatorContent .omv-input-row {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 1rem;
    align-items: end;
}
#bbdCalculatorContent .omv-input-field {
    min-width: 0;
}
@media (max-width: 768px) {
    #bbdCalculatorContent .omv-input-row {
        grid-template-columns: repeat(2, 1fr);
    }
}
@media (max-width: 480px) {
    #bbdCalculatorContent .omv-input-row {
        grid-template-columns: 1fr;
    }
}
.omv-input-field select {
    font-family: 'JetBrains Mono', 'SF Mono', monospace;
    font-size: 0.9rem;
    padding: 0.5rem 0.75rem;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    background: var(--bg-primary);
    color: var(--text-primary);
    width: 100%;
}
.omv-input-field select:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(58, 79, 192, 0.1);
}
.bbd-chart-container {
    position: relative;
    height: 280px;
    margin-bottom: 1.5rem;
}
.bbd-table-row-caution { background: rgba(255, 179, 0, 0.06); }
.bbd-table-row-critical { background: rgba(255, 59, 48, 0.06); }
.bbd-table-row-failed { background: rgba(255, 59, 48, 0.12); }
@media (max-width: 600px) {
    .bbd-hero-grid { grid-template-columns: repeat(2, 1fr); }
    .bbd-hero-card .stat-value { font-size: 0.95rem; }
    .bbd-stress-row { flex-direction: column; }
    .bbd-stress-row .omv-input-field { min-width: 100%; }
}
/* BBD Status Card */
.bbd-status-card {
    background: var(--surface-1);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    padding: 1.25rem;
    margin-bottom: 1.25rem;
}
.bbd-status-card.bbd-status-empty {
    border-style: dashed;
}
.bbd-status-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1rem;
}
.bbd-status-header .omv-card-title { margin-bottom: 0; }
.bbd-autofill-btn {
    white-space: nowrap;
}
.bbd-status-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
    gap: 0.75rem;
}
.bbd-status-metric {
    background: var(--surface-2, rgba(0,0,0,0.03));
    border-radius: 6px;
    padding: 0.75rem;
}
.bbd-status-metric .stat-label {
    font-size: 0.7rem;
    margin-bottom: 0.25rem;
}
.bbd-status-metric .stat-value {
    font-size: 1rem;
}
.bbd-status-sub {
    font-size: 0.7rem;
    color: var(--text-muted);
    font-weight: 400;
}
/* BBD History */
.bbd-history-summary {
    display: flex;
    flex-wrap: wrap;
    gap: 1rem 2rem;
    margin-bottom: 1rem;
    padding-bottom: 0.75rem;
    border-bottom: 1px solid var(--border-color);
}
.bbd-history-stat {
    display: flex;
    gap: 0.5rem;
    align-items: baseline;
    font-size: 0.8rem;
}
.bbd-history-stat .stat-label {
    font-size: 0.75rem;
}
.bbd-history-table td, .bbd-history-table th {
    padding: 0.4rem 0.5rem;
}

@media (max-width: 480px) {
    .bbd-hero-grid { grid-template-columns: 1fr 1fr; gap: 0.5rem; }
    .bbd-presets { justify-content: center; }
    .bbd-projection-table tr[data-bbd-minor="1"] { display: none; }
    .bbd-status-grid { grid-template-columns: 1fr 1fr; gap: 0.5rem; }
    .bbd-status-verdict { grid-column: 1 / -1; }
    .bbd-status-header { flex-direction: column; gap: 0.5rem; align-items: flex-start; }
    .bbd-status-metric .stat-value { font-size: 0.9rem; }
    .bbd-history-summary { flex-direction: column; gap: 0.5rem; }
}
