/* ===========================================
   Modals & Dialogs
   =========================================== */

/* Modal Overlay */
.modal-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: var(--overlay-bg);
    z-index: 2000;
    align-items: center;
    justify-content: center;
}

.modal-overlay.active {
    display: flex;
}

/* Modal Content */
.modal-content {
    background: var(--c-bg);
    border-radius: 12px;
    max-width: 600px;
    width: 90%;
    max-height: 80vh;
    overflow: auto;
    padding: 1.5rem;
}

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

.modal-header h3 {
    margin: 0;
    font-size: 1rem;
}

.modal-close {
    background: none;
    border: none;
    font-size: 1.5rem;
    cursor: pointer;
    color: var(--text-muted);
}

.modal-body pre {
    background: var(--surface);
    padding: 1rem;
    border-radius: 8px;
    white-space: pre-wrap;
    font-size: 0.85rem;
    max-height: 400px;
    overflow: auto;
}

/* Shared overlay rule for templates using class="modal" (toggled inline via
   JS: style.display = 'flex' | 'none'). Without this, the modal would render
   in normal document flow and break the page layout. */
.modal {
    position: fixed;
    inset: 0;
    background: var(--overlay-bg);
    z-index: 2000;
    align-items: center;
    justify-content: center;
}

.modal .modal-content {
    box-shadow: var(--shadow-widget);
}

.modal-actions {
    display: flex;
    justify-content: flex-end;
    gap: 0.5rem;
    margin-top: 1rem;
    flex-wrap: wrap;
}

.btn-secondary {
    background: var(--surface);
    color: var(--c-text);
    border: 1px solid var(--border-light);
    /* Self-sufficient box model (matches .btn-primary) so it styles links
       too, not just <button> elements that inherit Pico's defaults. */
    display: inline-block;
    padding: 0.6rem 1.25rem;
    border-radius: 6px;
    font-weight: 600;
    font-size: 0.9rem;
    cursor: pointer;
    text-decoration: none;
}
.btn-secondary:hover {
    background: color-mix(in srgb, var(--surface), var(--c-text) 8%);
}

/* Preview Modal (Dialog) */
.preview-modal {
    border: none;
    border-radius: 8px;
    padding: 0;
    max-width: 700px;
    width: 90%;
    box-shadow: var(--shadow-widget);
}

.preview-modal::backdrop {
    background: var(--overlay-bg);
}

.preview-modal article {
    margin: 0;
    border: none;
    border-radius: 8px;
}

.preview-modal header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1rem 1.5rem;
    background: var(--surface-alt);
    border-bottom: 1px solid var(--border);
    border-radius: 8px 8px 0 0;
    font-weight: 600;
}

.preview-modal .close-btn {
    background: none;
    border: none;
    font-size: 1.5rem;
    cursor: pointer;
    padding: 0;
    line-height: 1;
    color: var(--text-secondary);
    order: 2;
}

.preview-modal .close-btn:hover {
    color: var(--text-primary);
}

.preview-modal #preview-content {
    padding: 1.5rem;
    max-height: 60vh;
    overflow-y: auto;
}

.preview-modal .preview-content {
    white-space: pre-wrap;
    font-family: inherit;
    font-size: 0.9rem;
    line-height: 1.6;
    background: var(--input-bg);
    padding: 1rem;
    border-radius: 4px;
    border: 1px solid var(--border);
}

.preview-modal footer {
    padding: 1rem 1.5rem;
    background: var(--surface-alt);
    border-top: 1px solid var(--border);
    border-radius: 0 0 8px 8px;
    text-align: right;
}

.preview-modal footer button {
    margin: 0;
}
