/* Modal overlay and container */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: rgba(0, 0, 0, 0.5);
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 16px;
    z-index: 1000;
}

.modal-overlay[hidden] {
    display: none;
}

.modal {
    background-color: var(--bg-elevated);
    border: 1px solid var(--border);
    border-radius: 8px;
    width: 100%;
    max-width: 450px;
    max-height: 90vh;
    overflow-y: auto;
}

.modal-large {
    max-width: 95vw;
    width: 95vw;
    height: 90vh;
    max-height: 90vh;
    display: flex;
    flex-direction: column;
}

.modal-xl {
    max-width: 800px;
    width: 95vw;
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 16px;
    border-bottom: 1px solid var(--bg-recessed);
}

.modal-header h2 {
    color: var(--text-emphasis);
    font-size: 1.25rem;
}

.modal-close {
    font-size: 1.5rem;
    line-height: 1;
    background: transparent;
    border: none;
    cursor: pointer;
    padding: 8px;
    border-radius: 4px;
    transition: background-color 0.1s linear;
    color: var(--text-primary);
}

.modal-close:hover {
    background-color: var(--bg-recessed);
}

.modal-body {
    padding: 16px;
    flex: 1;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
}

.modal-actions {
    display: flex;
    justify-content: flex-end;
    gap: 8px;
    padding: 16px;
    border-top: 1px solid var(--bg-recessed);
}

/* Legacy modal pattern: .modal as overlay with .modal-content inside
   Used by collections.html and decks.html */
.modal[hidden] {
    display: none !important;
}

.modal > .modal-content {
    background-color: var(--bg-elevated);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 24px;
    width: 90%;
    max-width: 400px;
}

/* When .modal contains .modal-content, .modal is the overlay */
.modal:has(> .modal-content) {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.5);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 1000;
    /* Reset inner modal styles */
    border: none;
    border-radius: 0;
    max-width: none;
    max-height: none;
    overflow: visible;
}

.modal > .modal-content .modal-header {
    margin-bottom: 20px;
    padding: 0;
    border-bottom: none;
}

.modal > .modal-content .modal-header h2 {
    margin: 0;
}
