/* Error modal styles */
.error-modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.7);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 1000;
}
.error-modal-content {
    background-color: var(--bg-dark);
    border: 1px solid var(--border-color);
    border-radius: var(--border-radius);
    padding: 30px;
    width: 90%;
    max-width: 500px;
    text-align: center;
    box-shadow: var(--shadow-lg);
}
.error-modal-content h2 {
    margin-bottom: 20px;
    color: var(--error-color);
}
.error-modal-content p {
    margin-bottom: 25px;
    font-size: 16px;
    line-height: 1.5;
}
.error-button {
    display: inline-block;
    margin: 10px;
    padding: 12px 24px;
    background: var(--primary-gradient);
    color: white;
    border: none;
    border-radius: 30px;
    font-weight: 600;
    cursor: pointer;
    text-decoration: none;
    transition: all 0.2s;
}
.error-button:hover {
    transform: translateY(-2px);
    box-shadow: 0 5px 15px rgba(0, 0, 0, 0.3);
}
.error-button.secondary {
    background: transparent;
    border: 1px solid var(--border-color);
    color: var(--text-primary);
}

/* Add close button to modal*/
.modal-close {
    position: absolute;
    top: 15px;
    right: 15px;
    color: var(--text-secondary);
    background: none;
    border: none;
    font-size: 24px;
    cursor: pointer;
}
.modal-close:hover {
    color: var(--text-primary);
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

@keyframes toolAnimation {
    0% { transform: translateY(0); }
    25% { transform: translateY(-3px); }
    50% { transform: translateY(0); }
    75% { transform: translateY(3px); }
    100% { transform: translateY(0); }
}

@keyframes pulse {
    0% { opacity: 0.6; }
    50% { opacity: 1; }
    100% { opacity: 0.6; }
}

@keyframes tool-dot-pulse {
    0% { opacity: 0.6; }
    50% { opacity: 1; }
    100% { opacity: 0.6; }
}

@keyframes fadeIn {
    0% { opacity: 0; transform: translateY(10px); }
    100% { opacity: 1; transform: translateY(0); }
}

@keyframes fadeOut {
    0% { opacity: 1; transform: translateY(0); }
    100% { opacity: 0; transform: translateY(10px); }
}
:root {
    --primary-gradient: linear-gradient(135deg, #3b82f6, #8b5cf6);
    --bg-dark: #0f172a;
    --bg-darker: #060b18;
    --bg-light: #1e293b;
    --text-primary: #f8fafc;
    --text-secondary: #94a3b8;
    --border-color: #334155;
    --accent-color: #3b82f6;
    --success-color: #10b981;
    --error-color: #ef4444;
    --warning-color: #f59e0b;
    --transition-speed: 0.2s;
    --max-width: 1200px;
    --border-radius: 12px;
    --message-radius: 18px;
    --shadow-sm: 0 1px 3px rgba(0,0,0,0.1);
    --shadow-md: 0 4px 6px rgba(0,0,0,0.1), 0 2px 4px rgba(0,0,0,0.06);
    --shadow-lg: 0 10px 15px rgba(0,0,0,0.1), 0 4px 6px rgba(0,0,0,0.05);
    --shadow-mobile: 0 10px 25px rgba(0,0,0,0.3);
    
    /* Mobile-specific variables */
    --header-height-desktop: 72px;
    --header-height-tablet: 64px;
    --header-height-mobile: 60px;
    --header-height-small: 54px;
    --safe-area-inset-bottom: env(safe-area-inset-bottom, 0px);
    --touch-target-size: 44px; /* Minimum touch target size for accessibility */
    --mobile-max-width: 95%; /* Maximum width for message bubbles on mobile */
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
    background-color: var(--bg-dark);
    color: var(--text-primary);
    height: 100vh;
    height: 100dvh;
    display: flex;
    overflow: hidden;
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
}

/* Optimized logo visibility based on theme */
.dark-mode-logo {
    display: none;
}

.light-mode-logo {
    display: block;
}

/* When dark theme is active */
html.dark-theme .dark-mode-logo {
    display: block;
}

html.dark-theme .light-mode-logo {
    display: none;
}

/* When light theme is active */
html.light-theme .dark-mode-logo {
    display: none;
}

html.light-theme .light-mode-logo {
    display: block;
}

.app-container {
    display: flex;
    width: 100%;
    height: 100vh;
    height: 100dvh;
    position: relative;
    overflow: hidden;
}

/* Chat container styling */
.chat-container {
    flex: 1;
    min-width: 0;
    max-width: 100%;
    display: flex;
    flex-direction: column;
    background: var(--bg-dark);
    position: relative;
    transition: all var(--transition-speed);
}

.chat-messages {
    padding: 32px;
    flex-grow: 1;
    overflow-y: auto;
    scroll-behavior: smooth;
    background: 
        radial-gradient(circle at top right, rgba(59, 130, 246, 0.1), transparent 40%),
        radial-gradient(circle at bottom left, rgba(139, 92, 246, 0.1), transparent 40%);
}

.chat-header {
    padding: 16px 24px;
    width: 100%;
    background: var(--bg-darker);
    color: var(--text-primary);
    display: flex;
    align-items: center;
    gap: 16px;
    border-bottom: 1px solid var(--border-color);
    position: relative;
    z-index: 10;
    backdrop-filter: blur(10px);
    min-height: var(--header-height-desktop);
    transition: min-height var(--transition-speed), padding var(--transition-speed);
}

.chat-header h2 {
    font-size: 1.5rem;
    font-weight: 600;
    background: var(--primary-gradient);
    -webkit-background-clip: text;
    background-clip: text;
    color: transparent;
    margin-right: auto;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    transition: font-size var(--transition-speed);
}

.chat-header img {
    height: 36px;
    width: auto;
    transition: height var(--transition-speed);
}

.chat-header a[title="Ormind Home"] {
    display: flex;
    align-items: center;
    transition: all var(--transition-speed);
    border-radius: 8px;
    padding: 0;
}

.chat-header a[title="Ormind Home"]:hover {
    transform: scale(1.05);
    opacity: 0.8;
}

.chat-header .logo {
    width: 36px;
    height: 36px;
    background: var(--primary-gradient);
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 4px 12px rgba(59, 130, 246, 0.2);
    flex-shrink: 0;
    transition: width var(--transition-speed), height var(--transition-speed);
}

.chat-header .logo i {
    font-size: 1.125rem;
    color: white;
    transition: font-size var(--transition-speed);
}

.chat-messages::-webkit-scrollbar {
    width: 6px;
}

.chat-messages::-webkit-scrollbar-track {
    background: transparent;
}

.chat-messages::-webkit-scrollbar-thumb {
    background: rgba(99, 102, 241, 0.3);
    border-radius: 3px;
    transition: background var(--transition-speed);
}

.chat-messages::-webkit-scrollbar-thumb:hover {
    background: rgba(99, 102, 241, 0.5);
}

.message {
    margin-bottom: 28px;
    opacity: 0;
    transform: translateY(20px);
    animation: fadeIn 0.4s ease forwards;
    position: relative;
}

/* Special animation for post-tool messages */
.message.post-tool-message {
    animation: fadeIn 0.6s ease-out forwards;
    position: relative;
}

@keyframes fadeIn {
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.message-wrapper {
    display: flex;
    gap: 16px;
    align-items: flex-start;
    width: 100%;
    max-width: 900px;
    margin: 0 auto;
    overflow-wrap: break-word;
    word-wrap: break-word;
    transition: gap var(--transition-speed), max-width var(--transition-speed);
}

.user-message .message-wrapper {
    margin-left: auto;
    flex-direction: row-reverse;
}

.avatar {
    width: 40px;
    height: 40px;
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    box-shadow: var(--shadow-sm);
    transition: width var(--transition-speed), 
                height var(--transition-speed),
                border-radius var(--transition-speed);
}

.bot-message .avatar {
    background: var(--primary-gradient);
}

.user-message .avatar {
    background: var(--bg-light);
}

.bot-message .avatar img {
    width: 24px;
    height: 24px;
    transition: width var(--transition-speed), height var(--transition-speed);
}

.message-content {
    padding: 16px 20px;
    border-radius: var(--message-radius);
    position: relative;
    font-size: 1rem;
    box-shadow: var(--shadow-sm);
    max-width: 90%;
    overflow-x: auto;
    transition: padding var(--transition-speed), 
                font-size var(--transition-speed), 
                max-width var(--transition-speed);
}

.user-message .message-content {
    background: var(--primary-gradient);
    color: white;
    border-top-right-radius: 4px;
}

.bot-message .message-content {
    background: var(--bg-light);
    color: var(--text-primary);
    border-top-left-radius: 4px;
    border-left: 3px solid #3b82f6;
}

.message-info {
    display: flex;
    align-items: center;
    margin-top: 6px;
    opacity: 1;
}

.message-timestamp {
    font-size: 0.75rem;
    color: var(--text-secondary);
}

.user-message .message-timestamp {
    text-align: right;
}

.message-feedback {
    display: flex;
    align-items: center;
    margin-left: 12px;
}

.feedback-button {
    background: none;
    border: none;
    font-size: 0.8rem;
    color: var(--text-secondary);
    cursor: pointer;
    padding: 4px;
    border-radius: 4px;
    margin-left: 4px;
    transition: all var(--transition-speed);
}

.feedback-button:hover {
    color: var(--accent-color);
    background-color: rgba(99, 102, 241, 0.1);
}

.thumbs-up:hover {
    color: #4ade80;
}

.thumbs-down:hover {
    color: #f87171;
}

.branch-conversation:hover {
    color: #8b5cf6;
}

.feedback-popup {
    background-color: var(--bg-light);
    border-radius: 8px;
    box-shadow: var(--shadow-md);
    width: 300px;
    overflow: hidden;
}

.feedback-popup-content {
    padding: 12px;
}

.feedback-comment {
    width: 100%;
    min-height: 80px;
    padding: 8px;
    border-radius: 4px;
    border: 1px solid var(--border-color);
    background-color: var(--bg-darker);
    color: var(--text-primary);
    resize: vertical;
    margin-bottom: 10px;
    font-family: inherit;
}

.feedback-popup-buttons {
    display: flex;
    justify-content: flex-end;
    gap: 8px;
}

.feedback-submit, .feedback-cancel {
    padding: 6px 12px;
    border-radius: 4px;
    border: none;
    cursor: pointer;
    font-size: 0.8rem;
    transition: all var(--transition-speed);
}

.feedback-submit {
    background-color: var(--accent-color);
    color: white;
}

.feedback-submit:hover {
    background-color: #4f46e5;
}

.feedback-cancel {
    background-color: transparent;
    color: var(--text-secondary);
    border: 1px solid var(--border-color);
}

.feedback-cancel:hover {
    background-color: rgba(99, 102, 241, 0.1);
}

/* Shortcuts info and tooltip */
.shortcut-info {
    position: absolute;
    right: 60px;
    top: 50%;
    transform: translateY(-50%);
    z-index: 2;
}

.shortcut-info button {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background: none;
    border: none;
    color: var(--text-secondary);
    cursor: pointer;
    transition: all var(--transition-speed);
    display: flex;
    align-items: center;
    justify-content: center;
}

.shortcut-info button:hover {
    color: var(--accent-color);
    background-color: rgba(99, 102, 241, 0.1);
}

.shortcut-tooltip {
    position: absolute;
    bottom: 50px;
    right: -10px;
    width: 300px;
    padding: 16px;
    background: var(--bg-light);
    border-radius: 12px;
    box-shadow: var(--shadow-md);
    border: 1px solid var(--border-color);
    display: none;
    z-index: 100;
}

.shortcut-info:hover .shortcut-tooltip {
    display: block;
}

.shortcut-tooltip p {
    margin-bottom: 10px;
}

.shortcut-tooltip ul {
    padding-left: 20px;
}

.shortcut-tooltip li {
    margin-bottom: 6px;
}

.shortcut-tooltip kbd {
    background-color: var(--bg-darker);
    border: 1px solid var(--border-color);
    border-radius: 4px;
    padding: 2px 6px;
    font-family: monospace;
    font-size: 0.9em;
}

/* Responsive styles for different screen sizes */

/* Tablet styles */
@media screen and (max-width: 1024px) {
    .chat-messages {
        padding: 24px;
    }
    
    .message-wrapper {
        max-width: 100%;
    }
    
    .chat-header {
        min-height: var(--header-height-tablet);
        padding: 14px 20px;
    }
    
    .message-content {
        font-size: 0.95rem;
    }
}

/* Large mobile styles */
@media screen and (max-width: 768px) {
    .chat-messages {
        padding: 20px 16px;
        padding-bottom: calc(20px + var(--safe-area-inset-bottom));
    }
    
    .chat-header {
        min-height: var(--header-height-mobile);
        padding: 12px 16px;
        gap: 12px;
    }
    
    .chat-header h2 {
        font-size: 1.3rem;
    }
    
    .chat-header img {
        height: 32px;
    }
    
    .chat-input {
        padding: 16px;
        padding-bottom: calc(16px + var(--safe-area-inset-bottom));
    }
    
    .input-container {
        gap: 8px;
    }
    
    #messageInput {
        padding: 12px 12px 12px 40px;
        min-height: 48px;
        max-height: 300px;
        border-radius: 24px;
    }
    
    .shortcut-info {
        right: 50px;
    }
    
    .shortcut-tooltip {
        width: 250px;
        right: -50px;
    }
    
    /* Optimized message display for mobile */
    .message-wrapper {
        gap: 12px;
    }
    
    .message-content {
        padding: 14px 16px;
        max-width: var(--mobile-max-width);
        word-break: break-word;
    }
    
    .code-block-wrapper {
        margin: 16px 0;
        max-width: 100%;
        overflow-x: auto;
    }
    
    .run-block {
        margin: 14px 0;
    }
}

/* Small mobile styles */
@media screen and (max-width: 480px) {
    .chat-messages {
        padding: 16px 12px;
    }
    
    .chat-input {
        padding: 12px;
        padding-bottom: calc(12px + var(--safe-area-inset-bottom));
    }
    
    #messageInput {
        padding: 10px 10px 10px 36px;
        font-size: 0.9rem;
        min-height: 44px;
        border-radius: 22px;
    }
    
    #sendButton, #stopButton, #voiceRecordButton, #fileUploadButton {
        width: 42px;
        height: 42px;
    }
    
    .file-upload label {
        width: 30px;
        height: 30px;
    }
    
    .shortcut-info button {
        width: 30px;
        height: 30px;
    }
    
    .shortcut-info {
        right: 46px;
    }
    
    .file-upload {
        left: 10px;
    }
    
    .avatar {
        width: 36px;
        height: 36px;
        border-radius: 10px;
    }
    
    .bot-message .avatar img {
        width: 20px;
        height: 20px;
    }
    
    .message-wrapper {
        gap: 10px;
    }
    
    .message-content {
        padding: 12px 14px;
        font-size: 0.95rem;
        border-radius: 14px;
    }
    
    .bot-message .message-content {
        border-top-left-radius: 4px;
    }
    
    .user-message .message-content {
        border-top-right-radius: 4px;
    }
    
    /* Optimize code display */
    .code-block-header {
        padding: 8px 12px;
        font-size: 0.8rem;
    }
    
    .message-content pre {
        padding: 12px;
        font-size: 0.85em;
        line-height: 1.4;
        max-width: 100%;
        overflow-x: auto;
    }
    
    .code-block-wrapper {
        max-width: 100%;
        margin: 12px 0;
    }
    
    /* Add horizontal scroll indicator for code blocks */
    .code-block-wrapper::after {
        content: "";
        position: absolute;
        bottom: 0;
        right: 0;
        width: 40px;
        height: 30px;
        background: linear-gradient(90deg, transparent, rgba(13, 17, 23, 0.9));
        pointer-events: none;
        opacity: 0;
        transition: opacity 0.3s;
    }
    
    .code-block-wrapper.scrollable::after {
        opacity: 1;
    }
}

/* Extra small mobile styles */
@media screen and (max-width: 360px) {
    .chat-header {
        min-height: var(--header-height-small);
        padding: 10px 12px;
        gap: 8px;
    }
    
    .chat-header h2 {
        font-size: 1.2rem;
    }
    
    .chat-header img {
        height: 28px;
    }
    
    .message-content {
        padding: 10px 12px;
        font-size: 0.9rem;
        max-width: 80%;
    }
    
    .avatar {
        width: 32px;
        height: 32px;
        border-radius: 8px;
    }
    
    .bot-message .avatar img {
        width: 18px;
        height: 18px;
    }
    
    .message-wrapper {
        gap: 8px;
    }
    
    /* Further compress code display */
    .code-block-header {
        padding: 6px 10px;
        font-size: 0.8rem;
    }
    
    .message-content pre code {
        font-size: 0.8em;
        line-height: 1.4;
    }
}

.chat-input {
    padding: 24px 32px;
    background: var(--bg-darker);
    border-top: 1px solid var(--border-color);
    position: relative;
    z-index: 10;
    width: 100%;
    box-shadow: 0 -2px 10px rgba(0, 0, 0, 0.1);
    padding-bottom: calc(24px + var(--safe-area-inset-bottom)); /* Safe area for iPhone X+ */
    transition: padding var(--transition-speed);
}

.input-container {
    display: flex;
    gap: 16px;
    width: 100%;
    max-width: 900px;
    margin: 0 auto;
    position: relative;
    transition: gap var(--transition-speed);
}

/* Left buttons container */
.left-buttons {
    display: flex;
    gap: 8px;
    align-items: center;
}

/* Voice recording and file upload buttons */
#voiceRecordButton, #fileUploadButton {
    width: 48px;
    height: 48px;
    color: white;
    border: none;
    border-radius: 50%;
    cursor: pointer;
    transition: all var(--transition-speed);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.25rem;
    box-shadow: var(--shadow-md);
    min-width: var(--touch-target-size);
    min-height: var(--touch-target-size);
    background: var(--primary-gradient);
}

#voiceRecordButton:hover, #fileUploadButton:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-lg);
}

#voiceRecordButton:active, #fileUploadButton:active {
    transform: translateY(0);
}

#voiceRecordButton.recording {
    background: var(--error-color);
    animation: pulse 1.5s infinite;
}

#fileUploadButton.has-file {
    background: var(--success-color);
}

/* File chips container */
.file-chips-container {
    position: absolute;
    bottom: 100%;
    left: 16px;
    right: 16px;
    margin-bottom: 6px;
    z-index: 3;
}

.file-chips {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    max-height: 80px;
    overflow-y: auto;
    padding: 2px;
}

.file-chip {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    background: var(--accent-color);
    color: white;
    padding: 4px 8px 4px 10px;
    border-radius: 16px;
    font-size: 11px;
    font-weight: 500;
    max-width: 200px;
    animation: slideInUp 0.2s ease-out;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

.file-chip .file-name {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 150px;
}

.file-chip .remove-file {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 16px;
    height: 16px;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.2);
    cursor: pointer;
    transition: background-color 0.2s ease;
    font-size: 10px;
}

.file-chip .remove-file:hover {
    background: rgba(255, 255, 255, 0.3);
}

@keyframes slideInUp {
    from {
        opacity: 0;
        transform: translateY(10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* Clipboard paste feedback styling */
.paste-feedback {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 0.9rem;
    font-weight: 500;
    pointer-events: none;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
}

#messageInput {
    flex-grow: 1;
    padding: 16px 16px 16px 48px;
    border: 2px solid var(--border-color);
    border-radius: 30px;
    outline: none;
    font-size: 1rem;
    background: var(--bg-light);
    color: var(--text-primary);
    transition: all var(--transition-speed);
    font-family: inherit;
    box-shadow: var(--shadow-sm);
    resize: vertical;
    overflow-y: auto;
    min-height: 56px;
    max-height: 400px;
    line-height: 1.5;
    scrollbar-width: thin;
    scrollbar-color: rgba(99, 102, 241, 0.3) transparent;
}

#messageInput::-webkit-scrollbar {
    width: 6px;
}

#messageInput::-webkit-scrollbar-track {
    background: transparent;
}

#messageInput::-webkit-scrollbar-thumb {
    background: rgba(99, 102, 241, 0.3);
    border-radius: 3px;
}

#messageInput::-webkit-scrollbar-thumb:hover {
    background: rgba(99, 102, 241, 0.5);
}

#messageInput:focus {
    border-color: var(--accent-color);
    box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.2);
}

#messageInput::placeholder {
    color: var(--text-secondary);
}

/* Ensure proper handling of RTL languages */
#messageInput {
    text-align: start;
}

/* Explicit RTL text detection for any string with Hebrew/Arabic characters */
/* The :has selector lets us detect at runtime if the input has RTL text */
#messageInput:is([dir="auto"]) {
    unicode-bidi: plaintext;
}

/* Add a marker to debug the direction detection */
#messageInput:is([dir="auto"]):focus {
    caret-color: currentColor;
}

#sendButton, #stopButton {
    width: 48px;
    height: 48px;
    color: white;
    border: none;
    border-radius: 50%;
    cursor: pointer;
    transition: all var(--transition-speed);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.25rem;
    box-shadow: var(--shadow-md);
    min-width: var(--touch-target-size); /* Minimum touch target size */
    min-height: var(--touch-target-size); /* Minimum touch target size */
}

#sendButton {
    background: var(--primary-gradient);
}

#stopButton {
    background: var(--error-color);
    display: none;
}

/* Mode toggle button in header */
#modeToggle {
    background: none;
    border: none;
    color: var(--text-secondary);
    cursor: pointer;
    font-size: 1.125rem;
    transition: all var(--transition-speed);
    display: flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    border-radius: 6px;
}

#modeToggle:hover {
    color: var(--text-primary);
    background: rgba(255, 255, 255, 0.05);
}

#modeToggle.fast-mode {
    background: linear-gradient(135deg, #fbbf24, #f59e0b);
    color: white;
    animation: lightning-pulse 2s infinite;
}

#modeToggle.fast-mode:hover {
    background: linear-gradient(135deg, #f59e0b, #d97706);
}

@keyframes lightning-pulse {
    0%, 100% { 
        box-shadow: 0 0 10px rgba(251, 191, 36, 0.3);
    }
    50% { 
        box-shadow: 0 0 20px rgba(251, 191, 36, 0.6);
    }
}

#sendButton:hover, #stopButton:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-lg);
}

#sendButton:active, #stopButton:active {
    transform: translateY(0);
}

#sendButton:disabled, #stopButton:disabled {
    background: var(--bg-light);
    cursor: not-allowed;
    transform: none;
    box-shadow: none;
}

/* Add haptic feedback via vibration for mobile touch interactions */
@media (hover: none) {
    #sendButton:active, #stopButton:active, .file-upload label:active, .feedback-button:active {
        animation: press-animation 0.2s ease;
    }
    
    @keyframes press-animation {
        0% { transform: scale(1); }
        50% { transform: scale(0.95); }
        100% { transform: scale(1); }
    }
}

.typing-indicator {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 16px 20px;
    background: var(--bg-light);
    border-radius: var(--message-radius);
    color: var(--text-secondary);
    font-size: 1rem;
    border-left: 3px solid #3b82f6;
    box-shadow: var(--shadow-sm);
    border-top-left-radius: 4px;
}

.typing-dot {
    width: 8px;
    height: 8px;
    background: currentColor;
    border-radius: 50%;
    opacity: 0.5;
    animation: typingPulse 1.4s infinite;
}

.typing-dot:nth-child(2) { animation-delay: 0.2s; }
.typing-dot:nth-child(3) { animation-delay: 0.4s; }

@keyframes typingPulse {
    0%, 100% { opacity: 0.5; transform: scale(1); }
    50% { opacity: 1; transform: scale(1.2); }
}

.status-message {
    transition: opacity 0.3s ease;
}

/* Tool Call Animation Styles */
.tool-message {
    display: flex;
    align-items: center;
    padding: 12px 16px;
    background: rgba(59, 130, 246, 0.1);
    border-radius: 8px;
    margin: 12px 0;
    cursor: pointer;
    border-left: 3px solid #3b82f6;
    transition: all 0.2s ease;
    position: relative;
}

.tool-message.with-code {
    padding-right: 40px;
}

.tool-message i {
    margin-right: 10px;
}

.tool-message i.fa-wrench, 
.tool-message i.fa-cogs,
.tool-message i.fa-tools {
    animation: toolAnimation 1.2s ease-in-out infinite;
}

.tool-animation-container {
    display: flex;
    align-items: center;
    margin-left: 10px;
}

.tool-animation-dot {
    width: 6px;
    height: 6px;
    background: currentColor;
    border-radius: 50%;
    margin: 0 2px;
    animation: tool-dot-pulse 1.4s infinite;
}

.tool-animation-dot:nth-child(1) { animation-delay: 0s; }
.tool-animation-dot:nth-child(2) { animation-delay: 0.2s; }
.tool-animation-dot:nth-child(3) { animation-delay: 0.4s; }

.tool-output {
    background: rgba(15, 23, 42, 0.8);
    border-radius: 8px;
    padding: 0;
    margin: 4px 0 16px;
    max-height: 0;
    overflow: hidden;
    transition: all 0.3s ease;
    opacity: 0;
    border-left: 3px solid #3b82f6;
}

.tool-output.visible {
    padding: 16px;
    max-height: 500px;
    opacity: 1;
    overflow: auto;
}

/* Markdown Styling */
.message-content {
    white-space: normal;
    line-height: 1.6;
    max-width: 100%;
    overflow-wrap: break-word;
    word-wrap: break-word;
    word-break: break-word;
    hyphens: auto;
}

.message-content img {
    max-width: 100%;
    height: auto;
    border-radius: 12px;
    display: block;
    margin: 16px 0;
    box-shadow: var(--shadow-md);
}

.message-content p {
    margin-bottom: 0.8em;
}

.message-content p:last-child {
    margin-bottom: 0;
}

/* Pulse animation for scroll button */
@keyframes pulseGlow {
    0% { box-shadow: 0 0 0 0 rgba(59, 130, 246, 0.7); transform: scale(1); }
    50% { box-shadow: 0 0 0 10px rgba(59, 130, 246, 0.3); transform: scale(1.15); }
    100% { box-shadow: 0 0 0 0 rgba(59, 130, 246, 0); transform: scale(1); }
}

#scrollToBottom.pulse-animation {
    animation: pulseGlow 1s infinite;
    background: linear-gradient(135deg, #4f46e5, #3b82f6);
}

.message-content > *:first-child {
    margin-top: 0;
}

.message-content ul, .message-content ol {
    margin: 0.8em 0;
    padding-left: 1.6em;
}

.message-content li {
    margin-bottom: 0.5em;
}

.message-content li:last-child {
    margin-bottom: 0;
}

.message-content code {
    background: rgba(255, 255, 255, 0.1);
    padding: 2px 6px;
    border-radius: 4px;
    font-family: 'SF Mono', Menlo, Monaco, Consolas, monospace;
    font-size: 0.875em;
}

.code-block-wrapper {
    position: relative;
    margin: 20px 0;
    border-radius: 12px;
    overflow: hidden;
    box-shadow: var(--shadow-md);
    max-width: 100%;
}

.code-block-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 16px;
    background: #1a2234;
    font-size: 0.875rem;
    color: var(--text-secondary);
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}

.copy-button {
    background: rgba(255, 255, 255, 0.1);
    border: none;
    color: var(--text-secondary);
    cursor: pointer;
    padding: 6px 12px;
    border-radius: 6px;
    font-size: 0.75rem;
    transition: all var(--transition-speed);
    display: flex;
    align-items: center;
    gap: 6px;
}

.copy-button:hover {
    background: rgba(255, 255, 255, 0.2);
    color: var(--text-primary);
}

.message-content pre {
    background: #0d1117;
    padding: 16px;
    border-radius: 0;
    overflow-x: auto;
    margin: 0;
    max-width: 100%;
    white-space: pre-wrap;
    word-wrap: break-word;
}

.message-content pre code {
    background: none;
    padding: 0;
    border-radius: 0;
    font-size: 0.875em;
    line-height: 1.5;
    white-space: pre-wrap;
    word-break: break-all;
    word-wrap: break-word;
}

.message-content a {
    color: #60a5fa;
    text-decoration: none;
    border-bottom: 1px solid rgba(96, 165, 250, 0.2);
    transition: all var(--transition-speed);
}

.message-content a:hover {
    border-color: currentColor;
    color: #93c5fd;
}

.message-content strong {
    font-weight: 600;
}

.message-content em {
    font-style: italic;
}

.message-content blockquote {
    border-left: 4px solid var(--accent-color);
    margin: 16px 0;
    padding: 8px 16px;
    background: rgba(255, 255, 255, 0.05);
    border-radius: 8px;
}

.message-content h1, .message-content h2, .message-content h3,
.message-content h4, .message-content h5, .message-content h6 {
    margin: 20px 0 14px;
    font-weight: 600;
    line-height: 1.3;
}

.message-content h1 { font-size: 1.75rem; }
.message-content h2 { font-size: 1.5rem; }
.message-content h3 { font-size: 1.25rem; }
.message-content h4 { font-size: 1.125rem; }
.message-content h5 { font-size: 1rem; }
.message-content h6 { font-size: 0.875rem; }

.message-content table {
    border-collapse: collapse;
    margin: 20px 0;
    width: 100%;
    font-size: 0.9375rem;
    box-shadow: var(--shadow-sm);
    border-radius: 8px;
    overflow: hidden;
}

.message-content th, .message-content td {
    border: 1px solid var(--border-color);
    padding: 12px 16px;
    text-align: left;
}

.message-content th {
    background: rgba(255, 255, 255, 0.05);
    font-weight: 500;
}

.message-content tr:nth-child(even) {
    background: rgba(255, 255, 255, 0.02);
}

/* Sidebar Styles */
.sidebar {
    width: 280px;
    height: 100vh;
    height: 100dvh;
    background: var(--bg-darker);
    border-right: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    transition: all var(--transition-speed);
    z-index: 20; /* Increased z-index for mobile */
    flex-shrink: 0;
    overflow: hidden; /* Prevent content from showing during transitions */
}

.sidebar.collapsed {
    width: 0;
    border-right: none;
}

/* Sidebar overlay for mobile */
.sidebar-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: rgba(0, 0, 0, 0.5);
    z-index: 15;
    backdrop-filter: blur(2px);
    -webkit-backdrop-filter: blur(2px);
}

.sidebar-header {
    padding: 16px 24px; /* Match chat-header padding */
    display: flex;
    align-items: center;
    gap: 12px;
    border-bottom: 1px solid var(--border-color);
    min-height: var(--header-height-desktop); /* Match chat-header min-height */
    transition: min-height var(--transition-speed), 
                padding var(--transition-speed);
}

.sidebar-header h3 {
    font-size: 1.1rem;
    font-weight: 600;
    margin-right: auto;
    transition: font-size var(--transition-speed), color var(--transition-speed);
}

/* Sidebar search styles */
.sidebar-search {
    padding: 12px 16px;
    border-bottom: 1px solid var(--border-color);
    background: var(--bg-darker);
}

.search-input-container {
    position: relative;
    display: flex;
    align-items: center;
}

.search-input-container input {
    width: 100%;
    padding: 8px 35px 8px 35px;
    border: 1px solid var(--border-color);
    border-radius: 20px;
    background: var(--bg-dark);
    color: var(--text-color);
    font-size: 0.9rem;
    outline: none;
    transition: border-color 0.2s, box-shadow 0.2s;
}

.search-input-container input:focus {
    border-color: var(--primary-color);
    box-shadow: 0 0 0 2px rgba(var(--primary-color-rgb), 0.2);
}

.search-input-container input::placeholder {
    color: var(--text-muted);
}

.search-icon {
    position: absolute;
    left: 12px;
    color: var(--text-muted);
    font-size: 0.85rem;
    pointer-events: none;
}

.clear-search-btn {
    position: absolute;
    right: 8px;
    background: none;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    padding: 4px;
    border-radius: 50%;
    width: 24px;
    height: 24px;
    display: none;
    align-items: center;
    justify-content: center;
    transition: color 0.2s, background-color 0.2s;
}

.clear-search-btn:hover {
    color: var(--text-color);
    background-color: var(--bg-light);
}


/* New button styles for three-panel navigation */
.mobile-browser-btn-alt {
    position: fixed;
    left: 0;
    top: 50%;
    transform: translateY(-50%);
    width: 36px;
    height: 90px;
    border-radius: 0 18px 18px 0;
    box-shadow: var(--shadow-mobile);
}

.mobile-chat-btn-left {
    position: fixed;
    left: 0;
    top: 50%;
    transform: translateY(-50%);
    width: 36px;
    height: 90px;
    border-radius: 0 18px 18px 0;
    box-shadow: var(--shadow-mobile);
}

.mobile-chat-btn-right {
    position: fixed;
    right: 0;
    top: 50%;
    transform: translateY(-50%);
    width: 36px;
    height: 90px;
    border-radius: 18px 0 0 18px;
    box-shadow: var(--shadow-mobile);
}

.mobile-sidebar-btn-alt {
    position: fixed;
    right: 0;
    top: 50%;
    transform: translateY(-50%);
    width: 36px;
    height: 90px;
    border-radius: 18px 0 0 18px;
    box-shadow: var(--shadow-mobile);
}

@media (max-width: 768px) {
    .sidebar {
        position: fixed;
        left: 0;
        top: 0;
        bottom: 0;
        width: 85%;
        max-width: 320px;
        transform: translateX(-100%);
        transition: transform var(--transition-speed), box-shadow var(--transition-speed);
        border-right: none;
        box-shadow: none;
    }
    
    .sidebar:not(.collapsed) {
        transform: translateX(0);
        box-shadow: var(--shadow-lg);
    }
    
    .sidebar-header {
        padding: 10px 12px; /* Match chat-header padding for mobile */
        background: var(--primary-gradient);
        min-height: var(--header-height-mobile); /* Match chat-header min-height for mobile */
    }
    
    .sidebar-header h3 {
        color: white;
    }
    
    /* Mobile search styles */
    .sidebar-search {
        padding: 8px 12px;
        background: var(--primary-gradient);
    }
    
    .search-input-container input {
        padding: 6px 30px 6px 30px;
        font-size: 0.85rem;
        border-radius: 16px;
        background: rgba(255, 255, 255, 0.1);
        border: 1px solid rgba(255, 255, 255, 0.2);
        color: white;
    }
    
    .search-input-container input::placeholder {
        color: rgba(255, 255, 255, 0.7);
    }
    
    .search-input-container input:focus {
        border-color: rgba(255, 255, 255, 0.4);
        box-shadow: 0 0 0 2px rgba(255, 255, 255, 0.1);
        background: rgba(255, 255, 255, 0.15);
    }
    
    .search-icon {
        left: 10px;
        color: rgba(255, 255, 255, 0.7);
    }
    
    .clear-search-btn {
        right: 6px;
        color: rgba(255, 255, 255, 0.7);
    }
    
    .clear-search-btn:hover {
        color: white;
        background-color: rgba(255, 255, 255, 0.1);
    }
    
}

.logo-small {
    width: 24px;
    height: 24px;
}

.sidebar-new-chat-btn {
    background: var(--primary-gradient);
    color: white;
    border: none;
    width: 32px;
    height: 32px;
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all var(--transition-speed);
    box-shadow: var(--shadow-sm);
}

.sidebar-new-chat-btn:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-md);
}

.sidebar-content {
    flex: 1;
    overflow-y: auto;
    padding: 16px 12px;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.sidebar-content::-webkit-scrollbar {
    width: 4px;
}

.sidebar-content::-webkit-scrollbar-track {
    background: transparent;
}

.sidebar-content::-webkit-scrollbar-thumb {
    background: rgba(99, 102, 241, 0.2);
    border-radius: 2px;
}

.sidebar-content::-webkit-scrollbar-thumb:hover {
    background: rgba(99, 102, 241, 0.4);
}

.sidebar-loading {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 24px 0;
    color: var(--text-secondary);
    gap: 12px;
}

.loading-spinner-small {
    width: 24px;
    height: 24px;
    border: 2px solid rgba(255, 255, 255, 0.1);
    border-radius: 50%;
    border-top-color: var(--accent-color);
    animation: spin 1s infinite linear;
}

.chat-item {
    padding: 12px;
    border-radius: 8px;
    background: var(--bg-light);
    cursor: pointer;
    transition: all var(--transition-speed);
    border-left: 2px solid transparent;
    display: flex;
    flex-direction: column;
    gap: 4px;
    position: relative;
}

.chat-item:hover {
    background: var(--bg-light);
    transform: translateY(-1px);
    box-shadow: var(--shadow-sm);
}

.chat-item.active {
    border-left: 2px solid var(--accent-color);
    background: var(--bg-light);
}

.chat-item-title {
    font-weight: 500;
    font-size: 0.9rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.chat-item-preview {
    font-size: 0.8rem;
    color: var(--text-secondary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.chat-item-date {
    font-size: 0.7rem;
    color: var(--text-secondary);
    margin-top: 4px;
}

.chat-item-delete {
    position: absolute;
    top: 8px;
    right: 8px;
    background: var(--error-color);
    color: white;
    border: none;
    border-radius: 50%;
    width: 20px;
    height: 20px;
    font-size: 0.7rem;
    cursor: pointer;
    display: none;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
}

.chat-item:hover .chat-item-delete {
    display: flex;
}

.chat-item-delete:hover {
    background: #dc3545;
    transform: scale(1.1);
}

/* Notification styles */
.notification {
    position: fixed;
    top: 20px;
    right: 20px;
    background: var(--bg-dark);
    border: 1px solid var(--border-color);
    border-radius: var(--border-radius);
    padding: 16px;
    min-width: 300px;
    max-width: 500px;
    box-shadow: var(--shadow-lg);
    z-index: 1000;
    transform: translateX(100%);
    opacity: 0;
    transition: all 0.3s ease;
}

.notification.show {
    transform: translateX(0);
    opacity: 1;
}

.notification-content {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
}

.notification-close {
    background: none;
    border: none;
    color: var(--text-secondary);
    cursor: pointer;
    font-size: 1.2rem;
    line-height: 1;
    padding: 0;
    width: 20px;
    height: 20px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.notification-close:hover {
    color: var(--text-primary);
}

.notification-success {
    border-left: 4px solid #28a745;
}

.notification-error {
    border-left: 4px solid var(--error-color);
}

.notification-info {
    border-left: 4px solid var(--accent-color);
}

.toggle-sidebar-btn {
    background: none;
    border: none;
    color: var(--text-secondary);
    cursor: pointer;
    width: 36px;
    height: 36px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all var(--transition-speed);
    border-radius: 8px;
    margin-right: 8px;
}

/* Style for the header new chat button */
#headerNewChatBtn {
    margin-right: 16px;
}

.toggle-sidebar-btn:hover {
    background: rgba(255, 255, 255, 0.05);
    color: var(--text-primary);
}

.browser-panel {
    width: 0;
    height: 100vh;
    height: 100dvh;
    background: var(--bg-darker);
    border-left: 1px solid var(--border-color);
    transition: width var(--transition-speed), transform var(--transition-speed);
    position: relative;
    overflow: hidden;
    flex-shrink: 0;
}

.browser-panel.expanded {
    width: 50%;
}

/* Handle chat container sizing when panels are open/closed */
.sidebar:not(.collapsed) ~ .chat-container ~ .browser-panel.expanded {
    width: 40%;
}

/* Adjust toggle button position when both sidebar and browser panel are expanded */
.sidebar:not(.collapsed) ~ .chat-container ~ .browser-panel.expanded + .toggle-panel {
    right: calc(40% + 20px);
}

.sidebar:not(.collapsed) ~ .chat-container {
    flex: 2;
}

.browser-panel.expanded ~ .chat-container .chat-messages {
    padding: 24px 20px;
}

.browser-panel.expanded ~ .chat-container .chat-input {
    padding: 20px 20px;
}

.browser-panel iframe {
    width: 100%;
    height: 100%;
    border: none;
    opacity: 0;
    transition: opacity var(--transition-speed);
}

/* Browser panel overlay for mobile */
.browser-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: rgba(0, 0, 0, 0.5);
    z-index: 15;
    backdrop-filter: blur(2px);
    -webkit-backdrop-filter: blur(2px);
}

/* Browser controls styling */
.browser-controls {
    display: none; /* Hidden by default, shown in mobile view */
    justify-content: space-between;
    align-items: center;
    padding: 12px 16px;
    background: var(--bg-darker);
    border-bottom: 1px solid var(--border-color);
    z-index: 2;
}

.browser-panel.expanded .browser-controls {
    display: flex;
}

.browser-controls button {
    background: var(--bg-light);
    border: none;
    color: var(--text-primary);
    padding: 8px 12px;
    border-radius: 6px;
    cursor: pointer;
    transition: all var(--transition-speed);
    font-size: 0.875rem;
    min-height: var(--touch-target-size);
    min-width: var(--touch-target-size);
    display: flex;
    align-items: center;
    justify-content: center;
}

.browser-controls button:hover {
    background: var(--accent-color);
    color: white;
}

/* Share button in the bottom right corner of browser panel */
.browser-share-btn {
    position: absolute;
    bottom: 20px;
    right: 20px;
    background: var(--primary-gradient);
    color: white;
    border: none;
    width: 48px;
    height: 48px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    font-size: 1.2rem;
    box-shadow: var(--shadow-md);
    z-index: 10;
    transition: all 0.2s ease;
    opacity: 0;
    transform: scale(0.8);
}

.browser-panel.expanded .browser-share-btn {
    opacity: 1;
    transform: scale(1);
}

.browser-share-btn:hover {
    transform: scale(1.1);
    box-shadow: var(--shadow-lg);
}

/* Mobile buttons */
.mobile-browser-btn,
.mobile-sidebar-btn,
.mobile-chat-btn,
.mobile-browser-btn-alt,
.mobile-sidebar-btn-alt,
.mobile-chat-btn-left,
.mobile-chat-btn-right {
    display: none; /* Hidden by default, shown on mobile */
    align-items: center;
    justify-content: center;
    background: var(--primary-gradient);
    color: white;
    border: none;
    cursor: pointer;
    z-index: 1010; /* Higher z-index to ensure visibility */
    opacity: 0.9;
    transition: opacity var(--transition-speed), transform var(--transition-speed);
    min-width: var(--touch-target-size);
    min-height: var(--touch-target-size);
    touch-action: manipulation; /* Improve touch responsiveness */
}

.mobile-chat-btn:hover,
.mobile-chat-btn:focus,
.mobile-chat-btn-left:hover,
.mobile-chat-btn-left:focus,
.mobile-chat-btn-right:hover,
.mobile-chat-btn-right:focus {
    opacity: 1;
}

/* Mobile chat button (center) - for returning to chat when in sidebar or browser */
.mobile-chat-btn {
    position: fixed;
    bottom: 20px;
    left: 50%;
    transform: translateX(-50%);
    width: 56px;
    height: 56px;
    border-radius: 50%;
    box-shadow: var(--shadow-mobile);
    z-index: 100;
}

/* Desktop browser panel styles */
@media (min-width: 769px) {
    /* Hide the entire browser controls div on desktop */
    .browser-controls {
        display: none !important;
    }
    
    /* Hide all mobile buttons on desktop */
    .mobile-chat-btn-right, 
    .mobile-chat-btn-left {
        display: none !important; /* Use !important to ensure they're hidden */
    }
    
    .browser-copy-url-btn:hover {
        transform: translateY(-2px);
        box-shadow: var(--shadow-lg);
    }
    
    .browser-copy-url-btn:active {
        transform: translateY(0);
    }
    
    .browser-panel.expanded iframe {
        margin-top: 0;
        height: 100%;
    }
}

/* Mobile browser panel styles */
@media (max-width: 768px) {
    .browser-panel {
        position: fixed;
        right: 0;
        top: 0;
        bottom: 0;
        width: 100%;
        transform: translateX(100%);
        z-index: 30;
        border-left: none;
    }
    
    .browser-panel.expanded {
        width: 100%;
        transform: translateX(0);
        box-shadow: var(--shadow-lg);
    }
    
    .browser-controls {
        min-height: var(--header-height-mobile);
        align-items: center;
        gap: 10px;
    }
    
    .browser-controls button {
        height: 36px;
        padding: 0 12px;
        font-size: 0.8rem;
    }
    
    /* ALL mobile buttons use the same positioning - only visibility changes based on current panel */
    /* Left side buttons */
    .mobile-chat-btn-left {
        position: fixed;
        left: 0;
        top: 50%;
        transform: translateY(-50%);
        width: 40px;
        height: 90px;
        border-radius: 0 18px 18px 0;
        box-shadow: var(--shadow-mobile);
        z-index: 1200; /* Very high z-index to ensure visibility */
        display: none; /* Hidden by default, shown by specific rules */
    }
    
    /* Right side buttons */
    .mobile-chat-btn-right {
        position: fixed;
        right: 0;
        top: 50%;
        transform: translateY(-50%);
        width: 40px;
        height: 90px;
        border-radius: 18px 0 0 18px;
        box-shadow: var(--shadow-mobile);
        z-index: 1200; /* Very high z-index to ensure visibility */
        display: none; /* Hidden by default, shown by specific rules */
    }
    
    /* Three-panel navigation visibility rules */
    
    /* HISTORY PANEL STATE */
    .sidebar:not(.collapsed) ~ .mobile-chat-btn-right {
        display: flex !important;
    }
    
    /* BROWSER PANEL STATE */
    .browser-panel.expanded ~ .mobile-chat-btn-left {
        display: flex !important;
    }
}

.toggle-panel {
    position: fixed;
    right: 20px;
    top: 50%;
    transform: translateY(-50%);
    width: 48px;
    height: 96px;
    background: var(--primary-gradient);
    border: none;
    border-radius: 24px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    color: white;
    transition: all var(--transition-speed);
    z-index: 1000;
    box-shadow: var(--shadow-lg);
}

.toggle-panel:hover {
    transform: translateY(-52%);
}

.browser-panel.expanded + .toggle-panel {
    right: calc(50% + 20px);
}

/* Keep floating buttons in chat area when browser panel is open */
.browser-panel.expanded ~ .floating-actions {
    right: calc(50% + 24px);
}

/* Run block styles */
.run-block {
    background: rgba(59, 130, 246, 0.1);
    border: 1px solid rgba(59, 130, 246, 0.2);
    border-radius: 12px;
    margin: 16px 0;
    overflow: hidden;
    transition: all var(--transition-speed);
    box-shadow: var(--shadow-sm);
}

.run-block-header {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 12px 16px;
    background: rgba(59, 130, 246, 0.15);
    cursor: pointer;
    user-select: none;
    font-weight: 500;
}

.run-block-header:hover {
    background: rgba(59, 130, 246, 0.2);
}

.run-block-header i {
    transition: transform var(--transition-speed);
}

.run-block.collapsed .run-block-header i {
    transform: rotate(-90deg);
}

.run-block-content {
    padding: 16px;
    font-family: 'SF Mono', Menlo, Monaco, Consolas, monospace;
    font-size: 0.875em;
    line-height: 1.5;
    white-space: pre-wrap;
    max-height: 500px;
    overflow-y: auto;
    transition: all var(--transition-speed);
    background: #0d1117;
    word-break: break-word;
    word-wrap: break-word;
}

.run-block-content code {
    display: block;
    padding: 0;
    background: transparent;
    font-family: inherit;
    white-space: pre-wrap;
    word-break: break-word;
    word-wrap: break-word;
}

.run-block.collapsed .run-block-content {
    max-height: 0;
    padding: 0 16px;
    overflow: hidden;
}

/* Tool execution message styles */
.tool-message {
    background-color: #1e293b; 
    padding: 12px 16px;
    border-radius: 10px;
    margin: 12px 0;
    color: #f8fafc;
    font-weight: 500;
    display: flex;
    align-items: center;
    gap: 10px;
    box-shadow: var(--shadow-sm);
    border-left: 3px solid #3b82f6;
    animation: pulse 2s infinite;
    cursor: pointer;
    transition: all var(--transition-speed);
}

.tool-message:hover {
    background-color: #263548;
}

.tool-message.with-code {
    border-bottom-left-radius: 0;
    border-bottom-right-radius: 0;
    margin-bottom: 0;
    animation: none;
}

.tool-message i {
    margin-right: 6px;
    transition: transform 0.2s;
}

.tool-message.with-code i:first-child {
    transform: rotate(0deg);
}

.tool-output {
    background-color: #0d1117;
    color: #e6edf3;
    padding: 16px;
    border-radius: 10px;
    border-top-left-radius: 0;
    border-top-right-radius: 0;
    margin-top: 0;
    margin-bottom: 12px;
    font-family: 'SF Mono', Menlo, Monaco, Consolas, monospace;
    font-size: 0.875em;
    line-height: 1.5;
    white-space: pre-wrap;
    overflow-x: auto;
    border-left: 3px solid #3b82f6;
    box-shadow: var(--shadow-sm);
    max-height: 400px;
    overflow-y: auto;
    display: none; /* Hidden by default */
    word-break: break-word;
    word-wrap: break-word;
}

.tool-output.visible {
    display: block;
}

@keyframes pulse {
    0% { box-shadow: 0 0 0 0 rgba(59, 130, 246, 0.4); }
    70% { box-shadow: 0 0 0 6px rgba(59, 130, 246, 0); }
    100% { box-shadow: 0 0 0 0 rgba(59, 130, 246, 0); }
}

/* Custom floating action button */
.floating-actions {
    position: fixed;
    right: 24px;
    bottom: 110px;
    display: flex;
    flex-direction: column;
    gap: 16px;
    z-index: 100;
}

.floating-btn {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: var(--primary-gradient);
    color: white;
    border: none;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1rem;
    cursor: pointer;
    transition: all var(--transition-speed);
    box-shadow: var(--shadow-md);
}

.floating-btn:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-lg);
}

.floating-btn:active {
    transform: translateY(0);
}

.floating-btn.active {
    background: var(--primary-gradient);
    color: white;
}

/* Responsive styles */
@media (max-width: 768px) {
    /* Improved sidebar */
    .sidebar {
        position: fixed;
        left: 0;
        top: 0;
        bottom: 0;
        z-index: 1000;
        width: 85%;
        max-width: 300px;
        transform: translateX(-100%);
        transition: transform var(--transition-speed), box-shadow var(--transition-speed);
        border-right: none;
        box-shadow: none;
    }
    
    .sidebar:not(.collapsed) {
        transform: translateX(0);
        box-shadow: var(--shadow-lg);
    }
    
    /* Mobile sidebar button */
    .mobile-sidebar-btn {
        display: flex; /* Show on mobile */
        position: fixed;
        left: 0;
        top: 50%;
        transform: translateY(-50%);
        width: 32px;
        height: 80px;
        border-radius: 0 16px 16px 0;
        background: var(--primary-gradient);
        color: white;
        align-items: center;
        justify-content: center;
        z-index: 100;
        box-shadow: var(--shadow-md);
        cursor: pointer;
        transition: all var(--transition-speed);
    }
    
    .mobile-sidebar-btn:active {
        opacity: 0.9;
    }
    
    /* Improved chat container */
    .chat-container {
        min-width: 100%;
        width: 100%;
    }

    .chat-messages {
        padding: 16px 12px 100px 12px; /* Add bottom padding for mobile buttons */
    }

    .chat-input {
        padding: 16px 12px calc(16px + env(safe-area-inset-bottom)) 12px; /* Add safe area for iOS */
    }

    .message-wrapper {
        max-width: 100%;
    }

    .input-container {
        max-width: 100%;
    }

    /* Better browser panel for mobile */
    .browser-panel {
        width: 0;
    }
    
    .browser-panel.expanded {
        width: 100%;
        position: fixed;
        top: 0;
        right: 0;
        bottom: 0;
        left: 0;
        z-index: 1001;
    }
    
    /* Hide the default toggle panel button */
    .toggle-panel {
        display: none;
    }
    
    
    /* Mobile chat button (center) */
    .mobile-chat-btn {
        display: none; /* Hidden by default */
        position: fixed;
        top: 50%;
        left: 50%;
        transform: translate(-50%, -50%);
        width: 48px;
        height: 48px;
        border-radius: 50%;
        background: var(--primary-gradient);
        color: white;
        align-items: center;
        justify-content: center;
        z-index: 1010; /* Higher than panels */
        box-shadow: var(--shadow-md);
        cursor: pointer;
        transition: all var(--transition-speed);
    }
    
    .mobile-chat-btn:active {
        opacity: 0.9;
    }
    
    /* Improved toggle panel */
    .toggle-panel {
        width: 40px;
        height: 40px;
        border-radius: 50%;
        right: 16px;
        bottom: 80px;
        top: auto;
        transform: none;
    }

    .browser-panel.expanded + .toggle-panel {
        right: 16px;
        bottom: 16px;
        top: auto;
        transform: none;
        background: var(--bg-light);
        color: var(--text-primary);
    }
    
    /* Keep floating buttons in chat area in mobile view */
    .browser-panel.expanded ~ .floating-actions {
        right: 16px;
    }
    
    /* Chat button rules integrated into the three-panel navigation system above */

    .floating-actions {
        bottom: 80px; /* Position above the mobile buttons */
        right: calc(50% - 48px); /* Center horizontally with spacing */
        flex-direction: row; /* Place buttons side by side */
        gap: 16px; /* Space between buttons */
    }
    
    /* Sidebar overlay for better UX */
    .sidebar-overlay {
        display: block;
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        background-color: rgba(0, 0, 0, 0.5);
        z-index: 999;
        opacity: 0;
        visibility: hidden;
        transition: opacity var(--transition-speed), visibility var(--transition-speed);
    }
    
    .sidebar:not(.collapsed) ~ .sidebar-overlay {
        opacity: 1;
        visibility: visible;
    }
    
    /* Show chat button when sidebar is active */
    /* Rules for sidebar navigation integrated into the three-panel system above */
    
    /* Browser panel overlay for better UX */
    .browser-overlay {
        display: block;
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        background-color: rgba(0, 0, 0, 0.5);
        z-index: 999;
        opacity: 0;
        visibility: hidden;
        transition: opacity var(--transition-speed), visibility var(--transition-speed);
    }
    
    .browser-panel.expanded ~ .browser-overlay {
        opacity: 1;
        visibility: visible;
    }
    
    /* Browser panel improvements */
    .browser-controls {
        display: flex;
        justify-content: space-between;
        align-items: center;
        padding: 16px;
        background: var(--primary-gradient);
        position: absolute;
        top: 0;
        left: 0;
        right: 0;
        z-index: 2;
        border-bottom: 1px solid var(--border-color);
    }
    
    .browser-controls button {
        background: rgba(255, 255, 255, 0.2);
        color: white;
        border: none;
        padding: 8px 12px;
        border-radius: 8px;
    }
    
    .browser-controls button:hover {
        background: rgba(255, 255, 255, 0.3);
    }
    
    .browser-panel.expanded iframe {
        margin-top: 60px; /* More space for header */
        height: calc(100% - 60px);
    }
    
    /* Mobile styles for share button */
    .browser-share-btn {
        width: 48px;
        height: 48px;
        font-size: 1.2rem;
    }
    
    /* Message truncation improvements */
    .message-content pre {
        max-width: calc(100vw - 100px);
    }
    
    .code-block-wrapper {
        max-width: calc(100vw - 100px);
    }
}

@media (max-width: 480px) {
    /* Improved header */
    .chat-header {
        padding: 10px 12px;
        min-height: 60px;
        gap: 10px;
    }

    .chat-header img {
        height: 28px;
    }

    .chat-header h2 {
        font-size: 1.2rem;
    }
    
    /* More compact messages */
    .avatar {
        width: 32px;
        height: 32px;
        border-radius: 8px;
    }

    .bot-message .avatar img {
        width: 18px;
        height: 18px;
    }

    .message-wrapper {
        gap: 10px;
        max-width: 95%;
    }

    .message-content {
        font-size: 0.9375rem;
        padding: 10px 12px;
        border-radius: 14px;
    }
    
    /* Fix user message bubbles */
    .user-message .message-content {
        border-top-right-radius: 4px;
    }
    
    .bot-message .message-content {
        border-top-left-radius: 4px;
    }

    .message-timestamp {
        font-size: 0.6875rem;
    }

    .typing-indicator {
        padding: 10px 12px;
        font-size: 0.9375rem;
    }

    .typing-dot {
        width: 6px;
        height: 6px;
    }
    
    /* More optimized input area */
    .chat-input {
        padding: 12px 10px;
    }
    
    .input-container {
        gap: 10px;
    }

    #messageInput {
        padding: 12px 12px 12px 38px;
        font-size: 0.9375rem;
        border-radius: 24px;
    }

    #sendButton, #stopButton, #voiceRecordButton, #fileUploadButton {
        width: 38px;
        height: 38px;
        font-size: 1rem;
    }

    .file-upload {
        left: 12px;
    }
    
    .file-upload label {
        width: 30px;
        height: 30px;
    }

    /* Better code blocks */
    .code-block-header {
        padding: 8px 10px;
    }
    
    .message-content pre {
        padding: 12px;
        font-size: 0.8125rem;
        max-width: calc(100vw - 80px);
    }
    
    .copy-button {
        padding: 4px 8px;
        font-size: 0.6875rem;
    }
    
    /* Tool message improvements */
    .tool-message {
        padding: 10px 12px;
        font-size: 0.875rem;
    }
    
    .tool-output {
        padding: 12px;
        font-size: 0.8125rem;
        max-height: 300px;
    }

    /* Floating buttons */
    .floating-btn {
        width: 36px;
        height: 36px;
        font-size: 0.9rem;
        background: rgba(255, 255, 255, 0.15);
        backdrop-filter: blur(4px);
        border: 1px solid rgba(255, 255, 255, 0.2);
    }

    .floating-actions {
        gap: 16px;
        bottom: calc(80px + env(safe-area-inset-bottom)); /* Add safe area for iOS */
        right: calc(50% - 44px); /* Adjusted for smaller buttons */
    }
    
    /* Mobile buttons - shared properties */
    .mobile-sidebar-btn, .mobile-browser-btn, .mobile-chat-btn {
        border: 1px solid rgba(255, 255, 255, 0.3);
        box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
        z-index: 1010; /* Ensure buttons are on top */
    }
    
    /* Override previous settings */
    .mobile-sidebar-btn, .mobile-browser-btn {
        bottom: auto; /* Remove bottom positioning */
        width: 32px; /* Narrower edge buttons */
        height: 80px; /* Taller edge buttons */
    }
    
    /* Fix browser panel toolbar */
    .browser-controls button {
        padding: 6px 10px;
        font-size: 0.75rem;
    }
    
    /* Better table display */
    .message-content table {
        font-size: 0.8125rem;
    }
    
    .message-content th, .message-content td {
        padding: 8px 10px;
    }
    
    /* Improved run blocks */
    .run-block-header {
        padding: 10px 12px;
        font-size: 0.875rem;
    }
    
    .run-block-content {
        padding: 12px;
        font-size: 0.8125rem;
    }
}

/* Extra small screens */
@media (max-width: 360px) {
    /* Improved height usage */
    .chat-header {
        min-height: 54px;
        padding: 8px 10px;
    }
    
    .sidebar-header {
        padding: 8px 10px; /* Match chat-header padding for smallest screens */
        min-height: 54px; /* Match chat-header min-height for smallest screens */
    }
    .chat-header h2 {
        font-size: 1.1rem;
    }
    
    .message-content {
        font-size: 0.875rem;
        padding: 8px 10px;
    }
    
    .avatar {
        width: 28px;
        height: 28px;
    }
    
    .bot-message .avatar img {
        width: 16px;
        height: 16px;
    }
    
    #messageInput {
        padding: 10px 10px 10px 34px;
        font-size: 0.875rem;
    }
    
    #sendButton, #stopButton, #voiceRecordButton, #fileUploadButton {
        width: 36px;
        height: 36px;
    }
    
    .file-upload {
        left: 10px;
    }
    
    .file-upload label {
        width: 28px;
        height: 28px;
    }
    
    .file-chips-container {
        left: 10px;
        right: 10px;
        margin-bottom: 4px;
    }
    
    .file-chips {
        gap: 4px;
        max-height: 60px;
    }
    
    .file-chip {
        font-size: 10px;
        padding: 3px 6px 3px 8px;
        max-width: 140px;
    }
    
    .file-chip .file-name {
        max-width: 100px;
    }
    
    .file-chip .remove-file {
        width: 14px;
        height: 14px;
        font-size: 9px;
    }
    
    .message-content pre {
        font-size: 0.75rem;
    }
    
    .floating-actions {
        bottom: 64px;
        right: 8px;
        gap: 8px;
    }
    
    .floating-btn {
        width: 32px;
        height: 32px;
        font-size: 0.8rem;
    }
    
    .message-wrapper {
        gap: 8px;
    }
}

/* Light Mode Toggle */
.theme-toggle {
    background: none;
    border: none;
    color: var(--text-secondary);
    cursor: pointer;
    font-size: 1.125rem;
    transition: all var(--transition-speed);
    display: flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    border-radius: 50%;
}

.theme-toggle:hover {
    color: var(--text-primary);
    background: rgba(255, 255, 255, 0.05);
}

/* Light mode */
body.light-mode {
    --bg-dark: #f8fafc;
    --bg-darker: #f1f5f9;
    --bg-light: #e2e8f0;
    --text-primary: #0f172a;
    --text-secondary: #475569;
    --border-color: #cbd5e1;
}

body.light-mode .bot-message .message-content {
    background: #e2e8f0;
    border-left: 3px solid #3b82f6;
}

body.light-mode .code-block-header {
    background: #cbd5e1;
    color: #334155;
}

body.light-mode .message-content code {
    background: rgba(0, 0, 0, 0.05);
    color: #0f172a;
}

body.light-mode .message-content pre {
    background: #f1f5f9;
    color: #0f172a;
}

body.light-mode .message-content pre code {
    color: #0f172a;
}

body.light-mode .hljs {
    background: #f1f5f9;
    color: #0f172a;
}

/* Syntax highlighting overrides for light mode */
body.light-mode .hljs-keyword,
body.light-mode .hljs-selector-tag,
body.light-mode .hljs-subst {
    color: #8250df;
}

body.light-mode .hljs-title,
body.light-mode .hljs-title.class_,
body.light-mode .hljs-title.function_ {
    color: #953800;
}

body.light-mode .hljs-string,
body.light-mode .hljs-doctag,
body.light-mode .hljs-quote {
    color: #0a3069;
}

body.light-mode .hljs-comment,
body.light-mode .hljs-meta {
    color: #6e7781;
}

body.light-mode .hljs-number,
body.light-mode .hljs-literal,
body.light-mode .hljs-variable,
body.light-mode .hljs-template-variable,
body.light-mode .hljs-tag .hljs-attr {
    color: #0550ae;
}

body.light-mode .run-block {
    background: rgba(59, 130, 246, 0.1);
    border: 1px solid rgba(59, 130, 246, 0.2);
}

body.light-mode .run-block-header {
    background: rgba(59, 130, 246, 0.15);
}

body.light-mode .tool-message {
    background: #e2e8f0;
    color: #0f172a;
}

/* Starter messages styling */
.starter-messages {
    margin: 30px auto;
    width: 100%;
    max-width: 900px;
    padding: 0 20px;
}

.starter-header {
    font-size: 1.125rem;
    font-weight: 500;
    margin-bottom: 16px;
    color: var(--text-secondary);
}

.starter-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: 16px;
    margin-bottom: 30px;
}

.starter-card {
    background: var(--bg-light);
    border: 1px solid var(--border-color);
    border-radius: 12px;
    padding: 16px;
    cursor: pointer;
    transition: all var(--transition-speed);
    display: flex;
    align-items: center;
    gap: 12px;
    box-shadow: var(--shadow-sm);
}

.starter-card:hover {
    transform: translateY(-3px);
    box-shadow: var(--shadow-md);
    border-color: var(--accent-color);
}

.starter-card i {
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--primary-gradient);
    color: white;
    border-radius: 8px;
    flex-shrink: 0;
}

.starter-card span {
    font-size: 0.9375rem;
    font-weight: 500;
}

/* Light mode adjustments for starter cards */
body.light-mode .starter-card {
    background: #f1f5f9;
    border-color: #cbd5e1;
}

body.light-mode .starter-card:hover {
    background: #e2e8f0;
}

@media (max-width: 768px) {
    .starter-grid {
        grid-template-columns: 1fr;
    }
    
    /* Hide starter messages on mobile */
    .starter-messages {
        display: none;
    }
}

/* Utility classes */
.hidden {
    display: none !important;
}

/* Drag & Drop Styling */
.drag-area {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: rgba(15, 23, 42, 0.7);
    backdrop-filter: blur(5px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    opacity: 0;
    visibility: hidden;
    transition: all 0.3s ease;
}

.drag-area.active {
    opacity: 1;
    visibility: visible;
}

.drag-container {
    background: var(--bg-light);
    border: 3px dashed var(--accent-color);
    border-radius: 20px;
    padding: 40px;
    text-align: center;
    width: 400px;
    max-width: 90%;
    box-shadow: var(--shadow-lg);
    animation: pulse-border 2s infinite;
}

@keyframes pulse-border {
    0% { border-color: var(--accent-color); }
    50% { border-color: rgba(59, 130, 246, 0.5); }
    100% { border-color: var(--accent-color); }
}

.drag-container i {
    font-size: 3rem;
    color: var(--accent-color);
    margin-bottom: 20px;
}

.drag-container h3 {
    font-size: 1.5rem;
    margin-bottom: 10px;
    color: var(--text-primary);
}

.drag-container p {
    color: var(--text-secondary);
    margin-bottom: 0;
}

/* Thinking Animation Styling */
.thinking-animation {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 15px;
    padding: 15px 10px;
    min-width: 200px;
}

.thinking-brain {
    position: relative;
    width: 40px;
    height: 40px;
}

.thinking-brain:before {
    content: '';
    position: absolute;
    width: 100%;
    height: 100%;
    background: linear-gradient(135deg, #3b82f6, #2563eb);
    border-radius: 40% 60% 70% 30% / 40% 50% 60% 50%;
    animation: morph 3s linear infinite;
}

.thinking-brain i {
    position: relative;
    color: white;
    font-size: 20px;
    display: flex;
    justify-content: center;
    align-items: center;
    height: 100%;
    z-index: 2;
}

.thinking-message {
    font-weight: 500;
    color: var(--text-primary);
}

.thinking-dots {
    display: flex;
    gap: 8px;
}

.thinking-dot {
    width: 8px;
    height: 8px;
    background-color: #3b82f6;
    border-radius: 50%;
    animation: dot-pulse 1.5s infinite ease-in-out;
}

.thinking-dot:nth-child(2) {
    animation-delay: 0.5s;
}

.thinking-dot:nth-child(3) {
    animation-delay: 1s;
}

@keyframes morph {
    0% { border-radius: 40% 60% 70% 30% / 40% 40% 60% 50%; }
    34% { border-radius: 70% 30% 50% 50% / 30% 30% 70% 70%; }
    67% { border-radius: 100% 60% 60% 100% / 100% 100% 60% 60%; }
    100% { border-radius: 40% 60% 70% 30% / 40% 40% 60% 50%; }
}

/* Thinking section styles */
.thinking-section {
    margin: 16px 0;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    background: var(--bg-secondary);
    overflow: hidden;
    transition: all 0.3s ease;
}

.thinking-section.collapsed .thinking-content {
    display: none;
}

.thinking-header {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 12px 16px;
    background: var(--bg-tertiary);
    cursor: pointer;
    user-select: none;
    transition: background-color 0.2s ease;
    border-bottom: 1px solid var(--border-color);
}

.thinking-section.collapsed .thinking-header {
    border-bottom: none;
}

.thinking-header:hover {
    background: var(--hover-color);
}

.thinking-header i.fas.fa-brain {
    color: #9333ea;
    font-size: 16px;
}

.thinking-header span {
    flex: 1;
    font-weight: 500;
    color: var(--text-color);
    font-size: 14px;
}

.thinking-toggle {
    color: var(--text-secondary);
    font-size: 12px;
    transition: transform 0.3s ease;
}

.thinking-section:not(.collapsed) .thinking-toggle {
    transform: rotate(90deg);
}

.thinking-content {
    padding: 16px;
    color: var(--text-secondary);
    font-size: 14px;
    line-height: 1.5;
    border-top: 1px solid var(--border-color);
    animation: expandThinking 0.3s ease-out;
}

.thinking-content p {
    margin: 0 0 12px 0;
}

.thinking-content p:last-child {
    margin-bottom: 0;
}

@keyframes expandThinking {
    from {
        opacity: 0;
        max-height: 0;
        padding-top: 0;
        padding-bottom: 0;
    }
    to {
        opacity: 1;
        max-height: 1000px;
        padding-top: 16px;
        padding-bottom: 16px;
    }
}

@keyframes dot-pulse {
    0%, 100% { transform: scale(0.7); opacity: 0.5; }
    50% { transform: scale(1); opacity: 1; }
}
