/* --- CSS Variables for Theming --- */
:root {
    --bg-color: #1c1c1c;
    --header-bg: rgba(28, 28, 28, 0.9);
    --header-hover-bg: rgba(40, 40, 40, 0.9);
    --header-active-bg: rgba(50, 50, 50, 0.9);
    --focused-bg: rgba(20, 20, 50, 0.9);
    --border-color: rgba(255, 255, 255, 0.05);
    --text-color: #dcdcdc;
    --code-bg: #1a1a1a;
    --code-text-color: #f5f5f5;
    --highlight-bg: #2f2f2f;
    --hover-bg: rgba(128, 128, 255, 0.1);
    --scrollbar-thumb: #555;
    --scrollbar-track: #1e1e1e;
    --button-bg: #2a2a2a;
    --button-hover-bg: rgba(0, 119, 255, 0);
    --burger-line-color: #ddd;
    --burger-line-hover-color: #777;
    --burger-line-dark: #fff;
    --spinner-border: rgba(0, 0, 0, 0.2);
    --spinner-border-top: #555;
}

/* --- Debug Window Styles --- */
.debug-window {
    position: fixed;
    top: 5%;
    left: 50%;
    transform: translate(-50%, 0);
    width: 600px;
    height: 500px;
    background: var(--bg-color);
    color: var(--text-color);
    font-family: 'Fira Code', monospace;
    border-radius: 6px;
    border: 1px solid var(--border-color);
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
    padding: 10px;
    z-index: 1000;
    overflow: hidden;
    box-sizing: border-box;
    white-space: pre-wrap;
    scrollbar-width: none;
    transition: transform 0.2s ease, box-shadow 0.2s ease;
    animation: fadeIn 0.3s ease-in-out;
}

.debug-window::-webkit-scrollbar {
    display: none;
}

.debug-window:hover {
    transform: translateX(-50%) scale(1.01);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.5);
}

.debug-window.focused {
    box-shadow: 0 0 8px rgba(149, 149, 149, 0.6);
    border-color: rgb(75, 75, 75);
}

/* --- Debug Header Styles --- */
.debug-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 4px 8px;
    background: var(--header-bg);
    border-radius: 6px 6px 0 0;
    position: sticky;
    top: 0;
    z-index: 1001;
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.3);
    cursor: grab;
    transition: background 0.2s, box-shadow 0.2s, transform 0.2s;
    backdrop-filter: blur(4px) saturate(120%);
    margin-bottom: 4px;
}

.debug-header:hover {
    background: var(--header-hover-bg);
    transform: translateY(-1px);
}

.debug-header:active {
    cursor: grabbing;
    background: var(--header-active-bg);
}

.debug-header.focused {
    box-shadow: 0 0 8px rgba(0, 150, 255, 0.5);
    background: var(--focused-bg);
}

.debug-title {
    font-weight: 500;
    font-size: 0.85em;
    color: #f0f0f0;
}

/* --- Close Button Styles --- */
.close-debug-window {
    background: transparent;
    border: none;
    font-size: 1em;
    color: #aaaaaa;
    cursor: pointer;
    transition: color 0.2s, transform 0.2s;
}

.close-debug-window:hover {
    color: #ff5e5e;
    transform: scale(1.1);
}

.close-debug-window:active {
    transform: scale(1);
}

/* --- Debug Code Styles --- */
.debug-code {
    background: var(--code-bg);
    color: var(--code-text-color);
    font-size: 0.85em;
    line-height: 1.5;
    border-radius: 6px;
    padding: 10px;
    overflow-x: auto;
    box-shadow: 0 3px 10px rgba(0, 0, 0, 0.4);
    transition: transform 0.2s, box-shadow 0.2s;
}

.debug-code:hover {
    transform: scale(1.01);
    box-shadow: 0 6px 15px rgba(0, 0, 0, 0.5);
}

/* --- Debug Content Styles --- */
.debug-content {
    display: none;
    padding: 14px;
    margin: 10px 0;
    background: #282c34;
    border-radius: 5px;
    color: var(--text-color);
    font-family: 'Fira Code', 'Consolas', monospace;
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.5);
    transition: opacity 0.4s, visibility 0.4s;
    opacity: 0;
    visibility: hidden;
}

.debug-content.active-content {
    display: block;
    opacity: 1;
    visibility: visible;
}

/* --- Debug Content Wrapper --- */
.debug-content-wrapper {
    display: flex;
    flex-direction: column;
    overflow-y: auto;
    height: 400px;
    padding: 12px;
    background-color: #1e1e1e;
    border-radius: 6px;
    scrollbar-width: thin;
    scrollbar-color: var(--scrollbar-thumb) var(--scrollbar-track);
    transition: height 0.3s ease-in-out;
    scroll-behavior: smooth;
}

.debug-content-wrapper::-webkit-scrollbar {
    width: 10px;
}

.debug-content-wrapper::-webkit-scrollbar-thumb {
    background-color: var(--scrollbar-thumb);
    border-radius: 10px;
    border: 2px solid var(--scrollbar-track);
}

/* --- Syntax Highlighting --- */
.debug-content code,
.code-content {
    color: #dcdcaa;
    background-color: #1e1e1e;
    padding: 2px 4px;
    border-radius: 3px;
}

.keyword {
    color: #4fc3f7;
    font-weight: bold;
}

.string {
    color: #f78c6c;
}

.comment {
    color: #6a9955;
    font-style: italic;
    opacity: 0.8;
}

.function-name {
    color: #ffc66d;
}

/* --- Line Numbering --- */
.line-number {
    color: #888;
    margin-right: 8px;
    min-width: 25px;
    text-align: right;
    user-select: none;
    font-family: 'Courier New', monospace;
    font-size: 0.8em;
    opacity: 0.8;
}

/* --- Highlight Line --- */
.highlight-line {
    background-color: var(--highlight-bg);
    width: 100%;
    padding: 8px 12px;
    border-radius: 5px;
    transition: background-color 0.2s, box-shadow 0.2s;
}

.highlight-line:hover {
    background-color: #444;
    box-shadow: 0 0 10px rgba(255, 255, 255, 0.1);
}

/* --- Code Line Styles --- */
.code-line {
    position: relative;
    padding: 2px 0;
    transition: background-color 0.3s ease-out;
    font-family: 'Fira Code', monospace;
    font-size: 0.95em;
    line-height: 1.5;
    display: flex;
    align-items: baseline;
}

.code-line:hover {
    background-color: var(--hover-bg);
}

.code-line-wrapper {
    display: flex;
    align-items: flex-start;
    padding: 5px 0;
}

/* --- Debug Tab Header --- */
.debug-tab-header {
    display: flex;
    justify-content: space-between;
    background-color: #242424;
    padding: 8px;
    border-bottom: 1px solid #555;
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.3);
    border-radius: 6px 6px 0 0;
}

/* --- Debug Tabs --- */
.debug-tab {
    background: none;
    border: none;
    color: #ffffff;
    padding: 6px 12px;
    cursor: pointer;
    font-family: 'Arial', sans-serif;
    font-size: 0.85em;
    transition: background-color 0.2s, transform 0.2s;
    border-radius: 4px;
}

.debug-tab:hover {
    transform: scale(1.03);
}

.debug-tab.active-tab {
    background-color: #555;
    font-weight: bold;
    box-shadow: inset 0 0 5px rgba(0, 0, 0, 0.5);
}

/* --- Spinner Styles --- */
.spinner {
    border: 3px solid var(--spinner-border);
    border-top: 3px solid var(--spinner-border-top);
    border-radius: 50%;
    width: 16px;
    height: 16px;
    animation: spin 1s linear infinite;
    display: inline-block;
    vertical-align: middle;
    margin-right: 5px;
}

/* --- Response Container --- */
#response-container {
    display: none;
}

/* --- Toggle Dark Mode Button --- */
.toggle-dark-mode {
    margin-left: 10px;
    padding: 5px 10px;
    background-color: transparent;
    color: white;
    border: none;
    cursor: pointer;
    border-radius: 5px;
    transition: background-color 0.3s;
}

.toggle-dark-mode:hover {
    background-color: var(--button-hover-bg);
}

/* --- Button Styles --- */
button {
    background: var(--button-bg);
    color: #f5f5f5;
    border: none;
    border-radius: 6px;
    padding: 4px 10px;
    font-size: 0.8em;
    cursor: pointer;
    transition: all 0.2s;
    box-shadow: 1px 1px 3px rgba(0, 0, 0, 0.2);
}

button:hover {
    box-shadow: 2px 2px 5px rgba(0, 0, 0, 0.3);
    transform: translateY(-1px);
}

button:active {
    box-shadow: inset 1px 1px 3px rgba(0, 0, 0, 0.3);
    transform: translateY(1px);
}

/* --- Cursor Styles --- */
.cursor-default,
.cursor-code {
    display: inline-block;
    animation: pulse 1s ease-in-out infinite;
}

/* Streaming cursor for chunk-based text display - Matches thinking indicator */
.streaming-cursor {
    display: inline-block;
    width: 12px;
    height: 12px;
    background: rgba(255, 255, 255, 0.85);
    margin-left: 6px;
    vertical-align: middle;
    border-radius: 50%;
    animation: chatgpt-pulse 1.5s ease-in-out infinite;
    /* Keep cursor visible above fixed composer */
    scroll-margin-bottom: calc(var(--composer-reserved-height, 150px) + 40px);
}

/* Mobile: same size, adjust scroll margin */
@media (max-width: 768px) {
    .streaming-cursor {
        scroll-margin-bottom: calc(var(--composer-reserved-height, 120px) + 60px + env(safe-area-inset-bottom, 0px));
    }
}

/* Pulsing animation - same as thinking indicator */
@keyframes chatgpt-pulse {
    0%, 100% {
        transform: scale(1);
        opacity: 0.4;
    }
    50% {
        transform: scale(1.3);
        opacity: 1;
    }
}

/* Gemini-style fade-in effect for streaming text */
.stream-fade-in {
    animation: streamFadeIn 0.3s ease-out forwards;
}

@keyframes streamFadeIn {
    from {
        opacity: 0;
        filter: blur(2px);
        transform: translateY(1px);
    }
    to {
        opacity: 1;
        filter: blur(0);
        transform: translateY(0);
    }
}


/* --- Hidden Elements --- */
.hidden {
    display: none;
}

/* --- Burger Menu Styles --- */
.burger-menu {
    cursor: pointer;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    width: 18px;
    height: 14px;
    background: none;
    border: none;
    padding: 0;
    transition: transform 0.2s ease;
}

.burger-menu .line {
    width: 100%;
    height: 2px;
    background-color: var(--burger-line-color);
    transition: background-color 0.2s;
    border-radius: 2px;
}

.burger-menu:hover {
    transform: rotate(3deg);
}

.burger-menu:hover .line {
    background-color: var(--burger-line-hover-color);
}

.code-window.dark-mode .burger-menu .line {
    background-color: var(--burger-line-dark);
}

/* --- Responsive Adjustments --- */
@media (max-width: 768px) {
    .text-message {
        margin: 15px 0;
        max-width: 100%;
    }

    .debug-content-wrapper {
        height: auto;
    }
}

@media (max-width: 600px) {
    .debug-window {
        width: 95%;
        height: auto;
    }

    .message-container {
        width: 95%;
    }

    .user-message {
        max-width: 95%;
        padding: 0.8rem;
    }

    .user-message .message-content {
        padding: 0.8rem 1rem;
        font-size: 0.9rem;
    }
}

/* --- Animations --- */
@keyframes spin {
    to { transform: rotate(360deg); }
}

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

@keyframes fadeIn {
    from { opacity: 0; transform: translate(-50%, -10px); }
    to { opacity: 1; transform: translate(-50%, 0); }
}

@keyframes fadeInWithEnhancedBlur {
    from {
        opacity: 0;
        filter: blur(5px);
    }
    to {
        opacity: 1;
        filter: blur(0);
    }
}

@keyframes fadeOutWithBlur {
    from {
        opacity: 1;
        filter: blur(0);
    }
    to {
        opacity: 0;
        filter: blur(5px);
    }
}

.fade-in {
    animation: fadeInWithEnhancedBlur 1.5s cubic-bezier(0.25, 1, 0.5, 1) forwards;
}

.fade-out {
    animation: fadeOutWithBlur 1.5s cubic-bezier(0.25, 1, 0.5, 1) forwards;
}
