/* Modern Modal/Overlay System */
.modal-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    /* style.css applies padding to body > *; ensure overlays are truly edge-to-edge */
    padding: 0;
    margin: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.6);
    backdrop-filter: blur(4px);
    z-index: 9998;
    animation: fadeIn 0.2s ease;
}

.modal-overlay.active {
    display: flex;
    align-items: center;
    justify-content: center;
    /* Keep a consistent gutter around modals (matches app container padding) */
    padding: var(--container-pad, 20px);
}

.modal {
    display: none;
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    /* style.css applies padding to body > *; remove it for the fixed modal */
    padding: 0;
    margin: 0;
    background: var(--surface);
    border-radius: var(--radius-lg);
    /* Ensure child backgrounds (like colored headers) follow the rounded corners */
    overflow: hidden;
    box-shadow: var(--shadow-xl);
    z-index: 9999;
    /* Use most of the viewport width while keeping consistent side gutters */
    width: calc(100vw - (2 * var(--container-pad, 20px)));
    max-width: calc(100vw - (2 * var(--container-pad, 20px)));
    max-height: calc(100vh - (2 * var(--container-pad, 20px)));
    animation: slideUp 0.3s ease;
}

.modal.active {
    display: block;
}

body.modal-open {
    overflow: hidden;
}

@keyframes slideUp {
    from {
        opacity: 0;
        transform: translate(-50%, -45%);
    }
    to {
        opacity: 1;
        transform: translate(-50%, -50%);
    }
}

.modal-header {
    padding: 20px 24px;
    border-bottom: 2px solid var(--border-color);
    display: flex;
    align-items: center;
    justify-content: space-between;
    width: 100%;
    box-sizing: border-box;
    /* The modal container clips children (overflow:hidden), so keep the header square
       so its background fills all the way into the rounded corners. */
}

.modal-header h2 {
    margin: 0;
    font-size: 1.5em;
    color: var(--text-primary);
    font-weight: 700;
}

.modal-close {
    background: none;
    border: none;
    font-size: 28px;
    color: var(--text-secondary);
    cursor: pointer;
    padding: 0;
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    transition: all var(--transition-fast);
}

.modal-close:hover {
    background: var(--danger-color);
    color: white;
    transform: rotate(90deg);
}

.modal-body {
    padding: 24px;
    color: var(--text-primary);
    max-height: 70vh;
    overflow: auto;
}

.modal-footer {
    padding: 16px 24px;
    border-top: 2px solid var(--border-color);
    display: flex;
    gap: 12px;
    justify-content: flex-end;
    border-radius: 0 0 var(--radius-lg) var(--radius-lg);
}

/* Report preview: tab bar + panels (Reports -> Guest Visit Log preview)
   Kept in modal.css because the preview is rendered inside the report preview modal.
   Uses theme variables so it automatically honors Light/Dark mode. */
#reportPreviewBody .cvltabs-bar {
    display: flex;
    flex-wrap: wrap;
    gap: var(--space-2);
    margin: 0 0 var(--space-3);
    padding: var(--space-2);
    background: var(--background);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-sm);
}

#reportPreviewBody .cvltabs-bar button[role="tab"] {
    appearance: none;
    -webkit-appearance: none;
    border: 1px solid var(--border-color);
    background: var(--surface);
    color: var(--text-primary);
    border-radius: var(--radius-md);
    padding: 10px 12px;
    font: inherit;
    font-weight: 650;
    line-height: 1;
    cursor: pointer;
    box-shadow: var(--shadow-sm);
    transition:
        transform var(--transition-fast),
        box-shadow var(--transition-fast),
        background var(--transition-fast),
        border-color var(--transition-fast),
        color var(--transition-fast);
}

#reportPreviewBody .cvltabs-bar button[role="tab"]:hover {
    transform: translateY(-1px);
    border-color: var(--primary-color);
    box-shadow: var(--shadow-md);
}

#reportPreviewBody .cvltabs-bar button[role="tab"]:active {
    transform: translateY(0);
    box-shadow: var(--shadow-sm);
}

/* Active tab: use the same primary gradient language as tables and other UI */
#reportPreviewBody .cvltabs-bar button[role="tab"][aria-selected="true"],
#reportPreviewBody .cvltabs-bar button[role="tab"].active {
    background: linear-gradient(135deg, var(--primary-color) 0%, var(--primary-dark) 100%);
    border-color: var(--primary-dark);
    color: #fff;
}

/* Panels */
#reportPreviewBody .cvltab-panel {
    display: none;
}

#reportPreviewBody .cvltab-panel.active {
    display: block;
}

/* Success Modal */
.modal.success .modal-header {
    background: linear-gradient(135deg, var(--success-color) 0%, #229954 100%);
    color: white;
}

.modal.success .modal-header h2 {
    color: white;
}

/* Error Modal */
.modal.error .modal-header {
    background: linear-gradient(135deg, var(--danger-color) 0%, #c0392b 100%);
    color: white;
}

.modal.error .modal-header h2 {
    color: white;
}

/* Warning Modal */
.modal.warning .modal-header {
    background: linear-gradient(135deg, var(--warning-color) 0%, #e67e22 100%);
    color: white;
}

.modal.warning .modal-header h2 {
    color: white;
}

/* Info Modal */
.modal.info .modal-header {
    background: linear-gradient(135deg, var(--accent-color) 0%, #2980b9 100%);
    color: white;
}

.modal.info .modal-header h2 {
    color: white;
}

/* Responsive modal sizing
   NOTE: The modal is now primarily constrained by viewport width minus gutters.
   Keep min-width unset to avoid forcing overflow on smaller screens. */

/* Dark mode overrides for modals */
@media (prefers-color-scheme: dark) {
    .modal-overlay {
        background: rgba(0, 0, 0, 0.85);
    }
    
    .modal {
        background: var(--surface);
    }
    
    .modal-header {
        background: var(--surface);
        border-bottom-color: var(--border-color);
    }
    
    .modal-body {
        color: var(--text-primary);
    }
    
    .modal-footer {
        border-top-color: var(--border-color);
    }
    
    .modal-close {
        color: var(--text-secondary);
    }
    
    .modal-close:hover {
        background: var(--danger-color);
        color: white;
    }
}
