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

.modal.active {
    opacity: 1;
    display: block;
}

/* Make modal more compact and responsive with proper scrolling */
.modal-content {
    background-color: #fefefe;
    margin: 1% auto;
    padding: 15px;
    border-radius: 6px;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.2);
    width: 98%;
    max-width: 1200px;
    transform: translateY(-20px);
    transition: transform 0.3s ease;
    position: relative;
    max-height: 90vh; 
    overflow-y: auto; 
    overflow-x: hidden;
}

.modal.active .modal-content {
    transform: translateY(0);
}

/* Fix for iOS Safari bounce effect */
.modal-content::-webkit-scrollbar {
    -webkit-appearance: none;
    width: 7px;
}

.modal-content::-webkit-scrollbar-thumb {
    border-radius: 4px;
    background-color: rgba(0, 0, 0, .3);
}

/* Keep close button always visible */
.modal-close {
    position: sticky;
    top: 0;
    right: 10px;
    float: right;
    font-size: 20px;
    color: #aaa;
    cursor: pointer;
    z-index: 10;
    margin-bottom: 10px;
    background-color: inherit;
    padding: 5px;
}

.modal-close:hover {
    color: #333;
}

[data-theme="dark"] .modal-content {
    background-color: #1e293b;
    color: #f1f5f9;
}

[data-theme="dark"] .modal-close {
    color: #9ca3af;
}

[data-theme="dark"] .modal-close:hover {
    color: #f1f5f9;
}

/* More compact styles for preview content */
.preview-container {
    padding: 0.25rem;
    font-size: 0.85rem;
}

.preview-header {
    margin-bottom: 2px;
    padding-bottom: 2px;
    border-bottom: 1px solid #e2e8f0;
}

.preview-header h2 {
    font-size: 0.7rem;
    margin-bottom: 2px;
}

.preview-header p {
    font-size: 0.6rem;
    color: #64748b;
    margin: 0;
}

/* Improved preview data layout - more columns on larger screens */
.preview-data {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: 0.5rem;
}

/* Section spacing adjustments */
.preview-section {
    margin-bottom: 0.5rem;
    padding: 0.25rem;
    border-radius: 4px;
}

.preview-section h3 {
    font-size: 0.9rem;
    margin: 0 0 0.35rem 0;
    padding-bottom: 0.2rem;
    border-bottom: 1px dashed #e2e8f0;
}

/* More compact field layout */
.preview-field {
    margin-bottom: 3px;
    display: flex;
    flex-direction: row;
    align-items: baseline;
    flex-wrap: wrap;
}

.preview-label {
    font-weight: 600;
    font-size: 0.7rem;
    color: #64748b;
    flex: 0 0 40%;
    padding-right: 0.5rem;
}

.preview-value {
    font-size: 0.8rem;
    flex: 0 0 60%;
    word-break: break-word;
}

[data-theme="dark"] .preview-header {
    border-bottom-color: #334155;
}

[data-theme="dark"] .preview-section h3 {
    border-bottom-color: #334155;
}

[data-theme="dark"] .preview-label {
    color: #94a3b8;
}

.actions {
    margin-top: 2px;
    padding-top: 2px;
    border-top: 1px solid #e2e8f0;
    text-align: right;
}

[data-theme="dark"] .actions {
    border-top-color: #334155;
}

.actions button {
    padding: 0.35rem 0.65rem;
    font-size: 0.8rem;
    margin-left: 0.3rem;
}

/* Editable field styles - more compact */
.preview-value.editable {
    cursor: pointer;
    position: relative;
    padding: 0.15rem 0.25rem;
    border-radius: 3px;
    transition: background-color 0.2s;
}

.preview-value.editable:hover {
    background-color: rgba(59, 130, 246, 0.1);
}

.preview-value.editable:hover::after {
    content: '✎';
    position: absolute;
    right: 0;
    top: 50%;
    transform: translateY(-50%);
    font-size: 0.65rem;
    color: #3b82f6;
}

.preview-value.edited {
    background-color: rgba(16, 185, 129, 0.1);
}

.editable-input {
    width: 100%;
    padding: 0.15rem 0.25rem;
    font-size: 0.8rem;
    border: 1px solid #d1d5db;
    border-radius: 3px;
    background-color: white;
}

[data-theme="dark"] .editable-input {
    background-color: #1e293b;
    color: #f1f5f9;
    border-color: #475569;
}

.editable-input:focus {
    outline: none;
    border-color: #3b82f6;
    box-shadow: 0 0 0 2px rgba(59, 130, 246, 0.3);
}

textarea.editable-input {
    resize: vertical;
    min-height: 50px;
}

/* Entity info section - more compact */
.entity-info {
    display: flex;
    gap: 0.5rem;
    margin-bottom: 0.75rem;
}

@media (max-width: 768px) {
    .entity-info {
        flex-direction: column;
        gap: 0.5rem;
    }
}

.entity-card {
    flex: 1;
    border: 1px solid #e2e8f0;
    border-radius: 6px;
    padding: 0.5rem;
    background-color: rgba(59, 130, 246, 0.02);
    position: relative;
}

.entity-card h3 {
    font-size: 0.85rem;
    margin: 0 0 0.35rem 0;
    color: #3b82f6;
    border-bottom: 1px dashed #e2e8f0;
    padding-bottom: 0.2rem;
}

.entity-field {
    display: flex;
    flex-direction: column;
    margin-bottom: 0.25rem;
}

.entity-label {
    font-size: 0.65rem;
    font-weight: 600;
    color: #64748b;
    margin-bottom: 0.1rem;
}

.entity-value {
    font-size: 0.8rem;
    cursor: pointer;
    padding: 0.15rem;
    border-radius: 3px;
    transition: background-color 0.2s;
}

.entity-value:hover {
    background-color: rgba(59, 130, 246, 0.1);
}

.entity-value:hover::after {
    content: '✎';
    position: absolute;
    right: 0.5rem;
    font-size: 0.65rem;
    color: #3b82f6;
}

.entity-value.edited {
    background-color: rgba(16, 185, 129, 0.1);
}

[data-theme="dark"] .entity-card {
    border-color: #334155;
    background-color: rgba(59, 130, 246, 0.05);
}

[data-theme="dark"] .entity-card h3 {
    border-bottom-color: #334155;
}

[data-theme="dark"] .entity-label {
    color: #94a3b8;
}

/* Improve mobile responsiveness */
@media (max-width: 480px) {
    .preview-label {
        flex: 0 0 100%;
        margin-bottom: 0.1rem;
    }
    
    .preview-value {
        flex: 0 0 100%;
    }
    
    .preview-data {
        grid-template-columns: 1fr;
    }
    
    .actions button {
        padding: 0.3rem 0.5rem;
        font-size: 0.75rem;
    }
    
    .modal-content {
        padding: 10px;
        margin: 0 auto;
        max-height: 100vh; /* Full height on mobile */
        height: 100vh;
        border-radius: 0; /* Remove border radius on mobile for full screen */
        overflow-y: auto;
    }
    
    /* Fix for bottom area visibility */
    .preview-container {
        padding-bottom: 60px; /* Add padding to ensure content is visible */
    }
    
    /* Keep actions visible at the bottom */
    .actions {
        position: sticky;
        bottom: 0;
        background-color: inherit;
        padding: 10px 0;
        margin-top: 15px;
        box-shadow: 0 -2px 10px rgba(0, 0, 0, 0.1);
    }
}

/* Fix for dark mode on mobile */
@media (max-width: 480px) {
    [data-theme="dark"] .actions {
        background-color: #1e293b;
        box-shadow: 0 -2px 10px rgba(0, 0, 0, 0.3);
    }
    
    [data-theme="dark"] .modal-close {
        background-color: #1e293b;
    }
}
