/* Modal Styles */
.modal {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.6);
    backdrop-filter: blur(2px);
    z-index: 1000;
    justify-content: center;
    align-items: center;
    padding: 1rem;
    overflow-y: auto;
}

.modal-content {
    background: var(--bg-primary);
    border-radius: 12px;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.2);
    max-width: 600px;
    width: 100%;
    max-height: 90vh;
    overflow-y: auto;
    position: relative;
    margin: auto;
}

.modal-content.modal-large {
    max-width: 900px;
}

.modal-header {
    padding: 1.5rem;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: var(--bg-secondary);
    border-radius: 12px 12px 0 0;
}

.modal-header.success {
    background: linear-gradient(135deg, var(--green), color-mix(in srgb, var(--green) 85%, black));
    color: white;
    border-bottom-color: transparent;
}

.modal-header.error {
    background: linear-gradient(135deg, var(--red), color-mix(in srgb, var(--red) 85%, black));
    color: white;
    border-bottom-color: transparent;
}

.modal-header h3 {
    margin: 0;
    font-size: 1.25rem;
    font-weight: 600;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.modal-header.success h3,
.modal-header.error h3 {
    color: white;
}

.modal-close {
    background: none;
    border: none;
    font-size: 1.5rem;
    cursor: pointer;
    color: var(--text-secondary);
    padding: 0.5rem;
    border-radius: 6px;
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
}

.modal-close:hover {
    background: rgba(0, 0, 0, 0.1);
    color: var(--text-primary);
}

.modal-header.success .modal-close,
.modal-header.error .modal-close {
    color: rgba(255, 255, 255, 0.8);
}

.modal-header.success .modal-close:hover,
.modal-header.error .modal-close:hover {
    background: rgba(255, 255, 255, 0.2);
    color: white;
}

.modal-body {
    padding: 1.5rem;
}

.modal-body p {
    margin: 0 0 1rem 0;
    color: var(--text-primary);
    line-height: 1.6;
}

.modal-body p:last-child {
    margin-bottom: 0;
}

.modal-actions {
    display: flex;
    gap: 1rem;
    justify-content: flex-end;
    margin-top: 2rem;
    padding-top: 1rem;
    border-top: 1px solid var(--border-color);
}

/* Modal Animation */
.modal {
    animation: fadeIn 0.2s ease-out;
}

.modal-content {
    animation: slideIn 0.3s ease-out;
}

@keyframes fadeIn {
    from {
        opacity: 0;
    }
    to {
        opacity: 1;
    }
}

@keyframes slideIn {
    from {
        opacity: 0;
        transform: translateY(-20px) scale(0.95);
    }
    to {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

/* Success Modal Specific Styles */
.modal-header.success i {
    font-size: 1.5rem;
    animation: successPulse 0.6s ease-out;
}

@keyframes successPulse {
    0% {
        transform: scale(0.8);
        opacity: 0.8;
    }
    50% {
        transform: scale(1.1);
        opacity: 1;
    }
    100% {
        transform: scale(1);
        opacity: 1;
    }
}

/* Error Modal Specific Styles */
.modal-header.error i {
    font-size: 1.5rem;
    animation: errorShake 0.5s ease-out;
}

@keyframes errorShake {
    0%, 100% {
        transform: translateX(0);
    }
    25% {
        transform: translateX(-5px);
    }
    75% {
        transform: translateX(5px);
    }
}

/* Form in Modal */
.modal form {
    margin: 0;
}

.modal .form-group {
    margin-bottom: 1rem;
}

.modal .form-group:last-child {
    margin-bottom: 0;
}

.modal .form-label {
    display: block;
    margin-bottom: 0.5rem;
    font-weight: 500;
    color: var(--text-primary);
}

.modal .form-control {
    width: 100%;
    box-sizing: border-box;
}

.modal textarea.form-control {
    resize: vertical;
    min-height: 80px;
}

/* Responsive Modal */
@media (max-width: 768px) {
    .modal {
        padding: 0.5rem;
        align-items: flex-start;
        padding-top: 2rem;
    }
    
    .modal-content {
        width: 100%;
        max-width: none;
        margin: 0;
        border-radius: 12px 12px 0 0;
        max-height: calc(100vh - 2rem);
    }
    
    .modal-content.modal-large {
        max-width: none;
    }
    
    .modal-header,
    .modal-body {
        padding: 1rem;
    }
    
    .modal-actions {
        flex-direction: column;
        gap: 0.75rem;
    }
    
    .modal-actions .btn {
        width: 100%;
        justify-content: center;
    }
}

@media (max-width: 480px) {
    .modal {
        padding: 0;
        align-items: stretch;
    }
    
    .modal-content {
        border-radius: 0;
        height: 100vh;
        max-height: none;
    }
    
    .modal-header {
        border-radius: 0;
        position: sticky;
        top: 0;
        z-index: 1;
    }
    
    .modal-body {
        flex: 1;
        overflow-y: auto;
    }
}

/* Dark Theme Adjustments */
[data-theme="dark"] .modal {
    background: rgba(0, 0, 0, 0.8);
}

[data-theme="dark"] .modal-content {
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.5);
}

/* High Contrast Adjustments */
[data-contrast="high"] .modal {
    background: rgba(0, 0, 0, 0.9);
}

[data-contrast="high"] .modal-content {
    border: 2px solid var(--text-primary);
}

[data-contrast="high"] .modal-header {
    border-bottom: 2px solid var(--text-primary);
}

[data-contrast="high"] .modal-close {
    border: 1px solid var(--text-primary);
}

/* Custom Modal Types */
.modal-info .modal-header {
    background: linear-gradient(135deg, var(--blue), color-mix(in srgb, var(--blue) 85%, black));
    color: white;
    border-bottom-color: transparent;
}

.modal-warning .modal-header {
    background: linear-gradient(135deg, var(--orange), color-mix(in srgb, var(--orange) 85%, black));
    color: white;
    border-bottom-color: transparent;
}

/* Loading States in Modal */
.modal-loading {
    position: relative;
}

.modal-loading::after {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(255, 255, 255, 0.8);
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 12px;
    z-index: 1;
}

[data-theme="dark"] .modal-loading::after {
    background: rgba(0, 0, 0, 0.8);
}

/* Prevent scroll when modal is open */
body.modal-open {
    overflow: hidden;
}

/* Preview specific styles */
.all-kpis-preview {
    max-height: 60vh;
    overflow-y: auto;
}

.kpi-preview-section {
    margin-bottom: 2rem;
    padding: 1.5rem;
    border: 2px solid var(--border-color);
    border-radius: 8px;
    background: var(--bg-secondary);
}

.kpi-preview-section:last-child {
    margin-bottom: 0;
}

.kpi-preview-section h3 {
    margin-top: 0;
    color: var(--text-primary);
    font-size: 1.2rem;
    font-weight: 600;
    padding-bottom: 0.5rem;
    border-bottom: 1px solid var(--border-color);
}

.preview-section {
    margin-bottom: 1.5rem;
}

.preview-section:last-child {
    margin-bottom: 0;
}

.preview-section h4 {
    margin: 0 0 1rem 0;
    color: var(--text-primary);
    font-size: 1rem;
    font-weight: 600;
}

.preview-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 0.75rem;
}

.preview-grid div {
    padding: 0.5rem 0;
    color: var(--text-secondary);
}

.preview-grid strong {
    color: var(--text-primary);
    margin-right: 0.5rem;
}

.preview-section p {
    margin: 0;
    padding: 0.75rem;
    background: var(--bg-primary);
    border-radius: 6px;
    border: 1px solid var(--border-color);
    color: var(--text-secondary);
    line-height: 1.5;
}
