/* Reset and base styles */
*, *:before, *:after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    font-family: Arial, sans-serif;
    background-color: var(--tg-theme-bg-color);
    color: var(--tg-theme-text-color);
    -webkit-tap-highlight-color: transparent;
    -webkit-touch-callout: none;
    -webkit-user-select: none;
    user-select: none;
}

.content {
    padding: 16px;
    padding-bottom: 80px;
    width: 100%;
    max-width: 100%;
    margin: 0 auto;
}

/* Top bar */
.top-bar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 12px;
    width: 100%;
}

.page-title {
    font-size: 24px;
    font-weight: 600;
}

.create-request-btn {
    background-color: var(--tg-theme-button-color);
    color: var(--tg-theme-button-text-color);
    border: none;
    border-radius: 8px;
    padding: 8px 16px;
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
}

/* Filter section - REMOVED CONFLICTING STYLES */
.filter-section {
    margin-bottom: 12px;
    width: 100%;
}

/* REMOVED collection-filter select styles that were conflicting */

/* Requests section */
.requests-section {
    background: var(--tg-theme-secondary-bg-color);
    border-radius: 12px;
    overflow: hidden;
    padding: 12px;
    width: 100%;
    margin-top: 8px;
}

.requests-list {
    display: grid;
    grid-template-columns: 1fr;
    gap: 10px;
    width: 100%;
}

.loan-request-card {
    background: var(--tg-theme-bg-color);
    border-radius: 8px;
    overflow: hidden;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
    display: flex;
    flex-direction: column;
    width: 100%;
}

.request-header {
    display: flex;
    padding: 12px;
    align-items: center;
    gap: 12px;
    border-bottom: 1px solid rgba(var(--tg-theme-hint-color-rgb), 0.2);
    width: 100%;
}

/* Gift preview in loan request cards */
.request-header .gift-preview {
    width: 48px;
    height: 48px;
    border-radius: 8px;
    overflow: hidden;
    background-color: rgba(var(--tg-theme-hint-color-rgb), 0.1);
    flex-shrink: 0;
}

.gift-container {
    width: 100%;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
}

.gift-preview img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    max-height: 100%;
    max-width: 100%;
}

.request-title {
    flex: 1;
    min-width: 0;
}

.collection-name {
    font-size: 16px;
    font-weight: 600;
    margin-bottom: 4px;
    color: var(--tg-theme-text-color);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.gift-number {
    font-size: 12px;
    color: var(--tg-theme-hint-color);
}

.borrower-info {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 12px;
    color: var(--tg-theme-hint-color);
}

.borrower-info a {
    color: var(--tg-theme-link-color, var(--tg-theme-button-color));
    text-decoration: none;
}

.request-details {
    padding: 12px;
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    grid-template-areas:
        "days apr floor"
        "amount liquidation interest"
        "risk risk total";
    gap: 12px;
    width: 100%;
}

.detail-item {
    display: flex;
    flex-direction: column;
}

.detail-label {
    font-size: 12px;
    color: var(--tg-theme-hint-color);
    margin-bottom: 4px;
}

.detail-value {
    font-size: 14px;
    font-weight: 500;
}

.days-item { grid-area: days; }
.apr-item { grid-area: apr; }
.floor-item { grid-area: floor; }
.amount-item { grid-area: amount; }
.liquidation-item { grid-area: liquidation; }
.interest-item { grid-area: interest; }
.risk-item { grid-area: risk; }
.total-item { 
    grid-area: total; 
    margin-top: 8px;
    padding-top: 8px;
    border-top: 1px solid rgba(var(--tg-theme-hint-color-rgb), 0.2);
}

.total-item .detail-value {
    font-weight: 600;
    font-size: 16px;
}

.request-actions {
    padding: 12px;
    border-top: 1px solid rgba(var(--tg-theme-hint-color-rgb), 0.2);
    width: 100%;
}

.give-ton-btn {
    width: 100%;
    background-color: var(--tg-theme-button-color);
    color: var(--tg-theme-button-text-color);
    border: none;
    border-radius: 8px;
    padding: 12px;
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
}

.give-ton-btn.disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

/* Loading indicator */
.loading-indicator, .gift-loading-indicator {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 24px;
    gap: 16px;
    color: var(--tg-theme-hint-color);
}

.spinner {
    width: 30px;
    height: 30px;
    border: 3px solid rgba(var(--tg-theme-hint-color-rgb), 0.2);
    border-top-color: var(--tg-theme-button-color);
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

/* No requests message */
.no-requests-message, .no-gifts-message {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 40px 24px;
    text-align: center;
    color: var(--tg-theme-hint-color);
}

.no-requests-message i {
    font-size: 48px;
    margin-bottom: 16px;
    opacity: 0.6;
}

.no-requests-message p, .no-gifts-message p {
    font-size: 16px;
}

/* Modal styles */
.modal {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.5);
    z-index: 1000;
    overflow-y: auto;
}

.modal-content {
    background-color: var(--tg-theme-bg-color);
    border-radius: 12px;
    width: 90%;
    max-width: 500px;
    margin: 20px auto;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    overflow: hidden;
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 16px;
    border-bottom: 1px solid rgba(var(--tg-theme-hint-color-rgb), 0.2);
}

.modal-header h2 {
    font-size: 18px;
    font-weight: 600;
}

.close-modal {
    background: none;
    border: none;
    font-size: 24px;
    cursor: pointer;
    color: var(--tg-theme-hint-color);
}

.modal-body {
    padding: 16px;
    max-height: calc(80vh - 120px);
    overflow-y: auto;
}

.modal-footer {
    display: flex;
    justify-content: flex-end;
    gap: 12px;
    padding: 16px;
    border-top: 1px solid rgba(var(--tg-theme-hint-color-rgb), 0.2);
}

.modal-footer button {
    padding: 10px 16px;
    border-radius: 8px;
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
}

.back-button, .cancel-button {
    background-color: var(--tg-theme-secondary-bg-color);
    color: var(--tg-theme-text-color);
    border: 1px solid var(--tg-theme-button-color);
}

.next-button, .submit-button, .confirm-button {
    background-color: var(--tg-theme-button-color);
    color: var(--tg-theme-button-text-color);
    border: none;
}

/* Gift selection section */
.gift-selection-section h3 {
    font-size: 16px;
    font-weight: 600;
    margin-bottom: 16px;
}

.gift-filter {
    margin-bottom: 16px;
    width: 100%;
}

.gift-filter select {
    width: 100%;
    padding: 10px;
    border-radius: 8px;
    border: 1px solid rgba(var(--tg-theme-hint-color-rgb), 0.3);
    background-color: var(--tg-theme-secondary-bg-color);
    color: var(--tg-theme-text-color);
    font-size: 14px;
}

.gifts-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 12px;
    max-height: 300px;
    overflow-y: auto;
    width: 100%;
}

.gift-card {
    background-color: var(--tg-theme-secondary-bg-color);
    border-radius: 8px;
    overflow: hidden;
    cursor: pointer;
    position: relative;
}

.gift-card.selected {
    border: 2px solid var(--tg-theme-button-color);
}

.gift-card-preview {
    width: 100%;
    padding-top: 100%; /* 1:1 aspect ratio */
    position: relative;
}

.gift-card-preview img {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    max-width: 100%;
    max-height: 100%;
    object-fit: cover;
}

.gift-card-info {
    padding: 8px;
    font-size: 12px;
}

.gift-card-collection {
    color: var(--tg-theme-text-color);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    font-weight: 500;
}

.gift-card-number {
    color: var(--tg-theme-hint-color);
}

.gift-card-floor {
    font-weight: 600;
    margin-top: 4px;
}

/* Loan terms section */
.loan-terms-section {
    animation: fadeIn 0.3s ease;
    width: 100%;
}

@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

.selected-gift-preview {
    display: flex;
    gap: 16px;
    margin-bottom: 24px;
    align-items: center;
    width: 100%;
}

.gift-preview-container {
    width: 80px;
    height: 80px;
    border-radius: 8px;
    overflow: hidden;
    background-color: rgba(var(--tg-theme-hint-color-rgb), 0.1);
    flex-shrink: 0;
}

.gift-details {
    flex: 1;
    min-width: 0;
}

.gift-details .gift-collection {
    font-size: 16px;
    font-weight: 600;
    margin-bottom: 4px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.gift-details .gift-number {
    font-size: 14px;
    color: var(--tg-theme-hint-color);
}

.loan-parameters {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 16px;
    margin-bottom: 24px;
    width: 100%;
}

.parameter-group {
    width: 100%;
}

.parameter-group label {
    display: block;
    font-size: 14px;
    margin-bottom: 8px;
    color: var(--tg-theme-text-color);
}

.form-control {
    width: 100%;
    padding: 10px;
    border-radius: 8px;
    border: 1px solid rgba(var(--tg-theme-hint-color-rgb), 0.3);
    background-color: var(--tg-theme-secondary-bg-color);
    color: var(--tg-theme-text-color);
    font-size: 14px;
}

.loan-summary {
    background-color: var(--tg-theme-secondary-bg-color);
    border-radius: 12px;
    padding: 16px;
    margin-bottom: 24px;
    width: 100%;
}

.summary-item {
    display: flex;
    justify-content: space-between;
    margin-bottom: 8px;
    width: 100%;
}

.summary-item.total {
    margin-top: 16px;
    padding-top: 8px;
    border-top: 1px solid rgba(var(--tg-theme-hint-color-rgb), 0.2);
}

.summary-label {
    font-size: 14px;
    color: var(--tg-theme-hint-color);
}

.summary-value {
    font-size: 14px;
    font-weight: 500;
}

.summary-item.total .summary-value {
    font-size: 16px;
    font-weight: 600;
}

.risk-warning, .confirmation-warning {
    display: flex;
    gap: 12px;
    padding: 12px;
    background-color: rgba(var(--tg-theme-hint-color-rgb), 0.1);
    border-radius: 8px;
    color: var(--tg-theme-text-color);
    width: 100%;
}

.risk-warning i, .confirmation-warning i {
    color: #f39c12;
    font-size: 16px;
    flex-shrink: 0;
    margin-top: 2px;
}

.risk-warning p, .confirmation-warning p {
    font-size: 12px;
    line-height: 1.4;
}

/* Confirmation modal */
.confirmation-content {
    display: flex;
    flex-direction: column;
    gap: 16px;
    width: 100%;
}

.confirmation-details {
    background-color: var(--tg-theme-secondary-bg-color);
    border-radius: 12px;
    padding: 16px;
    width: 100%;
}

.confirmation-item {
    display: flex;
    justify-content: space-between;
    margin-bottom: 8px;
    width: 100%;
}

.confirmation-item.total {
    margin-top: 16px;
    padding-top: 8px;
    border-top: 1px solid rgba(var(--tg-theme-hint-color-rgb), 0.2);
}

.confirmation-label {
    font-size: 14px;
    color: var(--tg-theme-hint-color);
}

.confirmation-value {
    font-size: 14px;
    font-weight: 500;
    max-width: 60%;
    text-align: right;
    word-break: break-word;
}

.confirmation-item.total .confirmation-value {
    font-size: 16px;
    font-weight: 600;
}

/* Navigation tabs */
.loans-nav {
    display: flex;
    background: var(--tg-theme-secondary-bg-color);
    border-radius: 12px;
    overflow: hidden;
    margin-bottom: 12px;
    width: 100%;
}

.nav-tab {
    flex: 1;
    padding: 10px;
    text-align: center;
    background: none;
    border: none;
    color: var(--tg-theme-hint-color);
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    position: relative;
    text-decoration: none;
}

.nav-tab.active {
    color: var(--tg-theme-text-color);
}

.nav-tab.active::after {
    content: '';
    position: absolute;
    bottom: 0;
    left: 0;
    width: 100%;
    height: 2px;
    background-color: var(--tg-theme-button-color);
}

/* Constrained gift container styles */
.gift-container {
    position: relative;
    max-width: 100%;
    max-height: 100%;
    overflow: hidden;
}

.gift-container .gift-background,
.gift-container .pattern-overlay,
.gift-container .lottie-container {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    max-width: 100vw;
    max-height: 100vh;
}

.gift-container .gift-background {
    z-index: 1;
}

.gift-container .pattern-overlay {
    z-index: 1.5;
}

.gift-container .lottie-container {
    z-index: 2;
}

.request-header .gift-preview .gift-container .gift-details {
    display: none;
}

/* Responsive styles */
@media (max-width: 480px) {
    .content {
        padding: 12px;
    }
    
    .gifts-grid {
        grid-template-columns: repeat(2, 1fr);
    }

    .loan-parameters {
        grid-template-columns: 1fr;
        gap: 12px;
    }
    
    .selected-gift-preview {
        flex-direction: column;
        align-items: flex-start;
    }
    
    .gift-preview-container {
        width: 100%;
        height: auto;
        aspect-ratio: 1/1;
        margin-bottom: 12px;
    }
    
    .confirmation-value {
        max-width: 50%;
    }
}

/* Remove the select style that conflicts with the component */
.collection-filter select {
    display: none;
}

/* Make filter match collection page styling */
#collection-filter {
    font-size: 12px;
}

#collection-filter .collection-filter-header {
    padding: 8px;
    font-size: 12px;
    font-weight: normal;
}

#collection-filter .collection-name {
    font-size: 10px;
    font-weight: normal;
}

#collection-filter .collection-stats {
    font-size: 9px;
}

#collection-filter .header-left span {
    font-weight: normal;
}

#collection-filter .collection-item {
    padding: 6px;
}

#collection-filter .collection-list {
    padding: 8px;
    gap: 6px;
}

#collection-filter .collection-preview {
    width: 30px;
    height: 30px;
}

#collection-filter .collection-checkbox,
#collection-filter .select-all-checkbox {
    width: 16px;
    height: 16px;
}

/* Tighten up spacing */
.filter-section {
    margin: 8px 0;
}

/* Fix for request header layout */
.request-header {
    display: flex;
    flex-direction: row;
    padding: 12px;
    align-items: flex-start; /* Align items to the top */
    gap: 12px;
    border-bottom: 1px solid rgba(var(--tg-theme-hint-color-rgb), 0.2);
    width: 100%;
}

.request-title {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
}

.borrower-info {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 11px;
    color: var(--tg-theme-hint-color);
    margin-top: 2px;
}


/* Fix for gift card styles in the create loan modal */

/* Make the gift card display properly */
.gift-card-preview {
    position: relative;
    width: 100%;
    padding-top: 100%; /* Maintain aspect ratio */
    background: var(--tg-theme-bg-color);
    border-radius: 8px 8px 0 0;
    overflow: hidden;
}

.gift-card .gift-container {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    max-width: 100%;
    max-height: 100%;
}

/* Remove the visible traits in gift cards */
.gift-card .gift-container .gift-details {
    display: none !important;
}

/* Restore normal text in gift card info */
.gift-card-info {
    padding: 8px;
    font-size: 12px;
    background-color: var(--tg-theme-secondary-bg-color);
}

.gift-card-collection {
    color: var(--tg-theme-text-color);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    font-weight: 500;
}

.gift-card-number {
    color: var(--tg-theme-hint-color);
}

.gift-card-floor {
    font-weight: 600;
    margin-top: 4px;
}

/* Fix selected card style */
.gift-card.selected {
    border: 2px solid var(--tg-theme-button-color);
}

/* Ensure gifts grid has correct spacing */
.gifts-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 12px;
    max-height: 300px;
    overflow-y: auto;
    width: 100%;
    padding: 2px;
}

/* Fix for loan terms confirmation screen */

/* Fix the gift preview container */
.selected-gift-preview {
    display: flex;
    gap: 16px;
    margin-bottom: 24px;
    align-items: center;
    width: 100%;
}

.gift-preview-container {
    width: 80px;
    height: 80px;
    border-radius: 8px;
    overflow: hidden;
    background-color: rgba(var(--tg-theme-hint-color-rgb), 0.1);
    flex-shrink: 0;
    position: relative;
}

.gift-preview-container .gift-container {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
}

/* Hide gift details in the preview */
.gift-preview-container .gift-container .gift-details {
    display: none !important;
}

/* Fix loan terms section layout */
.loan-terms-section {
    animation: fadeIn 0.3s ease;
    width: 100%;
    padding: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
}

/* Fix the gift details text */
.gift-details {
    flex: 1;
    min-width: 0;
}

.gift-details .gift-collection {
    font-size: 16px;
    font-weight: 600;
    margin-bottom: 4px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.gift-details .gift-number {
    font-size: 14px;
    color: var(--tg-theme-hint-color);
}

/* Make trait overlays not show on the confirmation screen */
.gift-container .trait-overlay {
    display: none !important;
}

/* Fix modal footer buttons */
.modal-footer {
    display: flex;
    justify-content: space-between; /* Changed to space-between for better button spacing */
    padding: 16px;
    border-top: 1px solid rgba(var(--tg-theme-hint-color-rgb), 0.2);
    width: 100%;
    margin-top: auto;
}

.modal-footer button {
    padding: 12px 24px;
    border-radius: 8px;
    font-size: 16px;
    font-weight: 500;
    cursor: pointer;
    min-width: 100px;
}

.back-button {
    background-color: var(--tg-theme-secondary-bg-color);
    color: var(--tg-theme-text-color);
    border: 1px solid var(--tg-theme-button-color);
}

.submit-button {
    background-color: var(--tg-theme-button-color);
    color: var(--tg-theme-button-text-color);
    border: none;
}

/* Bottom loading indicator for infinite scroll */
.bottom-loading-indicator {
    display: flex;
    flex-direction: row;
    align-items: center;
    justify-content: center;
    padding: 16px;
    gap: 8px;
    color: var(--tg-theme-hint-color);
    margin-top: 12px;
    width: 100%;
}

.bottom-loading-indicator .spinner {
    width: 24px;
    height: 24px;
    border: 3px solid rgba(var(--tg-theme-hint-color-rgb), 0.2);
    border-top-color: var(--tg-theme-button-color);
    border-radius: 50%;
    animation: spin 1s linear infinite;
}