/**
 * Hikari Code Response Styles
 * Matches Esmerald theme colors and design
 */

/* Code response container styling */
.message.code-response {
    background: var(--glass-background, rgba(8, 8, 8, 0.85)) !important;
    backdrop-filter: blur(10px) !important;
    -webkit-backdrop-filter: blur(10px) !important;
    border: none !important;
    border-radius: 16px !important;
    padding: 16px !important;
    margin: 8px 0 !important;
    max-width: 85% !important;
    align-self: flex-start !important;
    position: relative !important;
    overflow: hidden !important;
    box-shadow: none !important;
}

/* Remove border animation for cleaner look */
.message.code-response::before {
    display: none;
}

@keyframes codeResponseGlow {
    0%, 100% { opacity: 0.3; }
    50% { opacity: 0.6; }
}

/* Brief response text */
.code-brief {
    color: var(--text-primary, #a4b1cd) !important;
    margin-bottom: 12px !important;
    font-size: 14px !important;
    line-height: 1.4 !important;
    font-weight: 500 !important;
}

/* Code container */
.code-container {
    position: relative !important;
    background: #0f1724 !important;
    border: none !important;
    border-radius: 8px !important;
    overflow: hidden !important;
    margin: 8px 0 !important;
    box-shadow: none !important;
}

/* Code header */
.code-header {
    display: flex !important;
    justify-content: space-between !important;
    align-items: center !important;
    padding: 8px 12px !important;
    background: #1a2332 !important;
    border-bottom: none !important;
    font-size: 12px !important;
    min-height: 36px !important;
}

/* Language label */
.code-header span {
    color: #a4b1cd !important;
    font-weight: 400 !important;
    text-transform: lowercase !important;
    letter-spacing: 0px !important;
    font-family: inherit !important;
    font-size: 11px !important;
}

/* Copy button */
.code-header button {
    background: transparent !important;
    border: 1px solid #313f55 !important;
    color: #a4b1cd !important;
    padding: 4px 8px !important;
    border-radius: 4px !important;
    cursor: pointer !important;
    font-size: 11px !important;
    transition: all 0.2s ease !important;
    font-family: 'Space Mono', monospace !important;
}

.code-header button:hover {
    background: rgba(159, 239, 0, 0.1) !important;
    border-color: #9fef00 !important;
    color: #9fef00 !important;
    transform: translateY(-1px) !important;
}

.code-header button:active {
    transform: translateY(0) !important;
    background: rgba(159, 239, 0, 0.2) !important;
}

/* Code content */
.code-content {
    margin: 0 !important;
    padding: 16px !important;
    overflow-x: auto !important;
    color: #a4b1cd !important;
    font-family: 'Fira Code', 'Monaco', 'Menlo', 'SF Mono', monospace !important;
    font-size: 13px !important;
    line-height: 1.5 !important;
    background: transparent !important;
    white-space: pre-wrap !important;
    word-wrap: break-word !important;
    tab-size: 4 !important;
}

/* Custom scrollbar for code content */
.code-content::-webkit-scrollbar {
    height: 6px !important;
    background: rgba(49, 63, 85, 0.3) !important;
}

.code-content::-webkit-scrollbar-thumb {
    background: #9fef00 !important;
    border-radius: 3px !important;
}

.code-content::-webkit-scrollbar-thumb:hover {
    background: #c5f467 !important;
}

/* Code explanation */
.code-explanation {
    color: var(--text-secondary, #888) !important;
    font-size: 12px !important;
    margin-top: 8px !important;
    padding-top: 8px !important;
    border-top: 1px solid #313f55 !important;
    font-style: italic !important;
    line-height: 1.4 !important;
}

/* Syntax highlighting colors matching Esmerald theme */
.code-content .keyword {
    color: #569CD6 !important; /* Blue for keywords */
}

.code-content .string {
    color: #D2FF77 !important; /* Green for strings */
}

.code-content .comment {
    color: #889eda !important; /* Light blue for comments */
    font-style: italic !important;
}

.code-content .number {
    color: #A4B1CD !important; /* Light blue for numbers */
}

.code-content .function {
    color: #ffda96 !important; /* Orange for functions */
}

.code-content .operator {
    color: #f4f4f4 !important; /* White for operators */
}

.code-content .tag {
    color: #ff8f8f !important; /* Pink for HTML tags */
}

.code-content .attribute {
    color: #9CDCFE !important; /* Light blue for attributes */
}

.code-content .property {
    color: #9CDCFE !important; /* Light blue for CSS properties */
}

.code-content .value {
    color: #D2FF77 !important; /* Green for CSS values */
}

.code-content .selector {
    color: #ffda96 !important; /* Orange for CSS selectors */
}

.code-content .variable {
    color: #9CDCFE !important; /* Light blue for variables */
}

.code-content .type {
    color: #5deed1 !important; /* Cyan for types */
}

.code-content .control-flow {
    color: #d79bff !important; /* Purple for control flow */
}

/* Mobile responsiveness */
@media screen and (max-width: 768px) {
    .message.code-response {
        max-width: 95% !important;
        padding: 12px !important;
    }

    .code-content {
        font-size: 12px !important;
        padding: 12px !important;
    }

    .code-header {
        padding: 6px 8px !important;
        font-size: 11px !important;
    }

    .code-header button {
        padding: 3px 6px !important;
        font-size: 10px !important;
    }

    .code-brief {
        font-size: 13px !important;
        margin-bottom: 8px !important;
    }
}

/* Animation for new code responses */
@keyframes slideInCode {
    from {
        opacity: 0;
        transform: translateY(20px) scale(0.95);
    }
    to {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

.message.code-response {
    animation: slideInCode 0.4s ease-out !important;
}

/* Loading state for code responses */
.code-response.loading .code-container {
    position: relative !important;
}

.code-response.loading .code-container::after {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(15, 23, 36, 0.8) !important;
    backdrop-filter: blur(2px) !important;
    display: flex !important;
    align-items: center !important;
    justify-content: center !important;
    z-index: 10 !important;
}

.code-response.loading .code-container::before {
    content: '⚡ Generating code...';
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    color: #9fef00 !important;
    font-size: 14px !important;
    z-index: 11 !important;
    animation: pulse 1.5s ease-in-out infinite !important;
}

@keyframes pulse {
    0%, 100% { opacity: 0.6; }
    50% { opacity: 1; }
}

/* Error state for code responses */
.code-response.error .code-container {
    border-color: #ff3e3e !important;
    background: rgba(255, 62, 62, 0.05) !important;
}

.code-response.error .code-header {
    background: rgba(255, 62, 62, 0.1) !important;
    color: #ff8f8f !important;
}

/* Success state indicator */
.code-response.success .code-header span::after {
    content: ' ✓';
    color: #9fef00 !important;
}

/* High contrast mode support */
@media (prefers-contrast: high) {
    .code-container {
        border-color: rgba(255, 255, 255, 0.6) !important;
    }
    
    .code-header button {
        border-color: rgba(255, 255, 255, 0.4) !important;
    }

    .code-content {
        color: #ffffff !important;
    }
}

/* Reduced motion support */
@media (prefers-reduced-motion: reduce) {
    .message.code-response {
        animation: none !important;
    }

    .message.code-response::before {
        animation: none !important;
        opacity: 0.4 !important;
    }

    .code-response.loading .code-container::before {
        animation: none !important;
    }
}

/* Focus states for accessibility */
.code-header button:focus {
    outline: 2px solid #9fef00 !important;
    outline-offset: 2px !important;
}

/* Print styles */
@media print {
    .message.code-response {
        background: white !important;
        color: black !important;
        border: 1px solid #ccc !important;
        box-shadow: none !important;
        break-inside: avoid !important;
    }

    .code-container {
        background: #f8f8f8 !important;
        border: 1px solid #ddd !important;
    }

    .code-header {
        background: #e8e8e8 !important;
        color: #333 !important;
    }

    .code-content {
        color: #333 !important;
    }

    .code-header button {
        display: none !important;
    }
}

/* Integration with existing chat styles */
#chat-window .message.code-response {
    align-self: flex-start !important;
    margin-left: 0 !important;
    margin-right: auto !important;
}

/* Ensure proper stacking */
.message.code-response {
    z-index: 1 !important;
    position: relative !important;
}

/* Dark theme enhancement */
@media (prefers-color-scheme: dark) {
    .code-container {
        background: #0a0e16 !important;
    }

    .code-header {
        background: #161d2b !important;
    }
}