/* Answer Box Container */
.answer-box {
    display: none;
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 90%;
    max-width: 1200px;
    height: auto;
    max-height: 90vh;
    background-color: #1e1e1e;
    border-radius: 12px;
    padding: 25px;
    z-index: 1000;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.7);
    overflow: hidden;
    animation: modalFadeIn 0.4s cubic-bezier(0.23, 1, 0.32, 1);
    transition: all 0.3s ease;
    will-change: transform, opacity, width, left;
}

/* Answer Box in Split View */
.answer-box.split-view {
    left: 0;
    transform: translateY(-50%);
    width: calc(50% - 10px);
    max-width: none;
    height: 100vh;
    border-radius: 12px;
    padding: 20px;
    margin-right: 10px;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.7);
    transition: all 0.3s ease;
    will-change: transform, opacity, width, left;
}

/* Modal Backdrop */
.modal-backdrop {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.8);
    z-index: 999;
    animation: backdropFadeIn 0.4s ease-out;
    transition: opacity 0.3s ease;
    will-change: opacity;
}

/* Keyframes for Modal Fade In */
@keyframes modalFadeIn {
    from {
        opacity: 0;
        transform: translate(-50%, -48%) scale(0.95);
    }
    to {
        opacity: 1;
        transform: translate(-50%, -50%) scale(1);
    }
}

/* Keyframes for Backdrop Fade In */
@keyframes backdropFadeIn {
    from {
        opacity: 0;
        background-color: rgba(0, 0, 0, 0);
    }
    to {
        opacity: 1;
        background-color: rgba(0, 0, 0, 0.8);
    }
}

/* Modal Content */
.modal-content {
    height: 100%;
    max-height: calc(90vh - 110px);
    overflow-y: auto;
    padding-right: 10px;
    margin-bottom: 60px;
    scroll-behavior: smooth;
}

/* Custom Scrollbar */
.modal-content::-webkit-scrollbar {
    width: 12px;
}

.modal-content::-webkit-scrollbar-track {
    background: #121212;
    border-radius: 6px;
}

.modal-content::-webkit-scrollbar-thumb {
    background-color: #505050;
    border-radius: 6px;
    border: 2px solid #121212;
    transition: background-color 0.2s ease;
}

.modal-content::-webkit-scrollbar-thumb:hover {
    background-color: #606060;
}

/* Preformatted Text */
.answer-box pre {
    background-color: #121212;
    border-radius: 8px;
    padding: 24px;
    font-family: 'Fira Code', 'JetBrains Mono', 'Source Code Pro', monospace;
    font-size: 16px;
    line-height: 1.7;
    color: #F0F0F0;
    border: 2px solid #4B4B4B;
    box-shadow: 0 6px 15px rgba(0, 0, 0, 0.6);
    width: 100%;
    position: relative;
    transition: box-shadow 0.3s ease, border-color 0.3s ease;
    will-change: box-shadow, border-color;
}

.answer-box pre:hover {
    box-shadow: 0 8px 20px rgba(0, 0, 0, 0.8);
    border-color: #5C5C5C;
}

/* Responsive Design */
@media (min-width: 769px) {
    .answer-box pre {
        white-space: pre-wrap;
        word-wrap: break-word;
    }
}

/* Mobile Optimization */
@media (max-width: 768px) {
    .answer-box {
        width: 95%;
        padding: 15px 10px;
        max-height: 95vh;
        border-radius: 8px;
    }
    
    .modal-content {
        max-height: calc(95vh - 80px);
        padding-right: 5px;
        margin-bottom: 40px;
    }
    
    .answer-box pre {
        white-space: pre;
        overflow-x: auto;
        padding: 15px;
        font-size: 15px;
        line-height: 1.5;
        border-width: 1px;
        border-radius: 6px;
    }
    
    .answer-box.split-view {
        width: 100%;
        left: 0;
        transform: translateY(-50%);
        border-radius: 8px;
        margin-right: 0;
        padding: 15px 10px;
    }
    
    .copy-close-container {
        padding: 8px 10px;
    }
    
    .copy-btn, .close-btn {
        padding: 6px 12px;
        min-height: 30px;
        font-size: 12px;
    }
    
    .modal-content::-webkit-scrollbar {
        width: 6px;
    }
}

/* Copy and Close Buttons Container */
.copy-close-container {
    display: flex;
    justify-content: flex-end;
    gap: 10px;
    padding: 15px 25px;
    position: absolute;
    bottom: 0;
    left: 0;
    width: 100%;
    background-color: #1e1e1e;
    border-top: 1px solid #333;
    transition: background-color 0.3s ease;
}

/* Button Styles */
.copy-btn, .close-btn {
    padding: 10px 18px;
    border: none;
    border-radius: 6px;
    cursor: pointer;
    font-size: 14px;
    font-weight: 500;
    transition: all 0.3s ease;
    min-height: 36px;
    will-change: transform, box-shadow, background-color;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    position: relative;
    overflow: hidden;
}

/* SVG Icon Styling for Buttons */
.btn-icon {
    display: inline-flex;
    width: 16px;
    height: 16px;
    stroke-width: 2;
    stroke: currentColor;
    fill: none;
    stroke-linecap: round;
    stroke-linejoin: round;
    margin-right: 6px;
    transition: transform 0.2s ease;
}

/* Copy Button */
.copy-btn {
    background-color: #238636;
    color: #fff;
}

.copy-btn:hover {
    background-color: #2ea043;
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
}

.copy-btn:hover .btn-icon {
    transform: scale(1.1);
}

.copy-btn:active {
    transform: translateY(0);
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.3);
}

/* Close Button */
.close-btn {
    background-color: #D32F2F;
    color: #fff;
}

.close-btn:hover {
    background-color: #b71c1c;
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
}

.close-btn:hover .btn-icon {
    transform: scale(1.1);
}

.close-btn:active {
    transform: translateY(0);
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.3);
}

/* Copied State Styling */
.copy-btn.copied {
    background-color: #2ea043;
    color: #fff;
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.2);
}

/* Custom copied animation with SVG */
.copy-btn.copied .btn-icon {
    animation: checkmark 0.5s ease forwards;
}

@keyframes checkmark {
    0% {
        opacity: 0;
        transform: scale(0.5);
    }
    50% {
        opacity: 1;
        transform: scale(1.2);
    }
    100% {
        opacity: 1;
        transform: scale(1);
    }
}

/* Remove the previous copied indicator */
.copy-btn.copied::before {
    content: none;
}

/* Ripple Effect */
.copy-btn::after, .close-btn::after {
    content: '';
    position: absolute;
    width: 100%;
    height: 100%;
    top: 0;
    left: 0;
    background: radial-gradient(circle, rgba(255, 255, 255, 0.3) 10%, transparent 10.01%);
    transform: scale(0);
    transition: transform 0.5s ease, opacity 0.5s ease;
    pointer-events: none;
}

.copy-btn:active::after, .close-btn:active::after {
    transform: scale(2);
    opacity: 0;
}

/* SVG Icons as CSS Variables for easier implementation */
:root {
    --copy-icon: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='24' height='24' viewBox='0 0 24 24' fill='none' stroke='white' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Crect x='9' y='9' width='13' height='13' rx='2' ry='2'%3E%3C/rect%3E%3Cpath d='M5 15H4a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h9a2 2 0 0 1 2 2v1'%3E%3C/path%3E%3C/svg%3E");
    --check-icon: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='24' height='24' viewBox='0 0 24 24' fill='none' stroke='white' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='20 6 9 17 4 12'%3E%3C/polyline%3E%3C/svg%3E");
    --close-icon: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='24' height='24' viewBox='0 0 24 24' fill='none' stroke='white' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cline x1='18' y1='6' x2='6' y2='18'%3E%3C/line%3E%3Cline x1='6' y1='6' x2='18' y2='18'%3E%3C/line%3E%3C/svg%3E");
}

/* Apply SVG icons as background images */
.copy-btn::before {
    content: "";
    display: inline-block;
    width: 18px;
    height: 18px;
    background-image: var(--copy-icon);
    background-size: contain;
    background-repeat: no-repeat;
    background-position: center;
    margin-right: 6px;
}

.copy-btn.copied::before {
    content: "";
    background-image: var(--check-icon);
    animation: fadeIn 0.3s ease;
}

.close-btn::before {
    content: "";
    display: inline-block;
    width: 18px;
    height: 18px;
    background-image: var(--close-icon);
    background-size: contain;
    background-repeat: no-repeat;
    background-position: center;
    margin-right: 6px;
}

@keyframes fadeIn {
    0% {
        opacity: 0;
        transform: translateY(-5px);
    }
    100% {
        opacity: 1;
        transform: translateY(0);
    }
}