* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

@view-transition {
    navigation: auto;
}

:root {
    --primary: #374151;
    --primary-hover: #1f2937;
    --primary-light: #e5e7eb;
    --background: #ffffff;
    --background-secondary: #fafafa;
    --background-tertiary: #f4f4f4;
    --border: #d1d5db;
    --border-hover: #9ca3af;
    --text-primary: #111827;
    --text-secondary: #4b5563;
    --text-tertiary: #6b7280;
    --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
    --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.08), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
    --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.08), 0 4px 6px -2px rgba(0, 0, 0, 0.05);
    --shadow-xl: 0 20px 25px -5px rgba(0, 0, 0, 0.08), 0 10px 10px -5px rgba(0, 0, 0, 0.04);
    --radius-sm: 6px;
    --radius-md: 10px;
    --radius-lg: 16px;
    --radius-xl: 24px;
    --transition-fast: 0.15s ease;
    --transition-normal: 0.25s ease;
    --transition-slow: 0.35s ease;
    --sidebar-width: 280px;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Inter', 'SF Pro Display', Oxygen, Ubuntu, Cantarell, sans-serif;
    min-height: 100vh;
    background: #e5e7eb;
    font-feature-settings: 'cv11', 'ss01';
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

#app {
    width: 100%;
    height: 100%;
}

.app-container {
    width: 100%;
    min-height: 100vh;
    display: flex;
    background: var(--background);
    box-shadow: var(--shadow-xl);
}

.sidebar {
    width: var(--sidebar-width);
    background: var(--background-secondary);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    flex-shrink: 0;
    height: 100vh;
    position: fixed;
    left: 0;
    top: 0;
    z-index: 100;
    transform: translateX(0);
}

.sidebar-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    backdrop-filter: blur(4px);
    z-index: 999;
    display: none;
}

.sidebar-overlay.show {
    display: block;
    animation: overlayFadeIn 0.2s ease-out;
}

.sidebar-header {
    height: 64px;
    padding: 0 20px;
    border-bottom: 1px solid var(--border);
    background: rgba(255, 255, 255, 0.8);
    backdrop-filter: blur(8px);
    display: flex;
    align-items: center;
}

.sidebar-footer {
    padding: 16px 12px;
    border-top: 1px solid var(--border);
    background: rgba(255, 255, 255, 0.8);
    backdrop-filter: blur(8px);
}

.new-chat-button {
    width: 100%;
    padding: 9px 20px;
    background: var(--primary);
    color: white;
    border: none;
    border-radius: var(--radius-md);
    font-size: 15px;
    font-weight: 600;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 10px;
    transition: all var(--transition-normal);
    box-shadow: var(--shadow-sm);
    letter-spacing: 0.015em;
}

.new-chat-button:hover {
    background: var(--primary-hover);
    transform: translateY(-2px);
    box-shadow: var(--shadow-md);
}

.new-chat-button:hover {
    background: var(--primary-hover);
    transform: translateY(-2px);
    box-shadow: var(--shadow-md);
}

.new-chat-button:active {
    transform: translateY(0);
}

.new-chat-icon {
    width: 20px;
    height: 20px;
}

.conversations-list {
    flex: 1;
    overflow-y: auto;
    padding: 12px;
    position: relative;
}

.conversations-list::-webkit-scrollbar {
    width: 6px;
}

.conversations-list::-webkit-scrollbar-track {
    background: transparent;
}

.conversations-list::-webkit-scrollbar-thumb {
    background: var(--border-hover);
    border-radius: 3px;
}

.conversations-list::-webkit-scrollbar-thumb:hover {
    background: var(--text-tertiary);
}

.conversation-tab {
    padding: 4px 0px 4px 16px;
    border-radius: var(--radius-md);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: space-between;
    transition: all var(--transition-fast);
    margin-bottom: 4px;
    border: 1px solid transparent;
    view-transition-name: var(--tab-name);
}

.conversations-list {
    view-transition-name: conversation-list;
}

.conversation-tab:hover {
    background: var(--background-tertiary);
    border-color: var(--border);
}

.conversation-tab.active {
    background: linear-gradient(135deg, var(--primary-light) 0%, #cffafe 100%);
    border-color: var(--primary);
    color: var(--primary);
}

.new-chat-icon {
    width: 20px;
    height: 20px;
}

.conversations-list {
    flex: 1;
    overflow-y: auto;
    padding: 12px;
}

.conversations-list::-webkit-scrollbar {
    width: 6px;
}

.conversations-list::-webkit-scrollbar-track {
    background: transparent;
}

.conversations-list::-webkit-scrollbar-thumb {
    background: var(--border-hover);
    border-radius: 3px;
}

.conversations-list::-webkit-scrollbar-thumb:hover {
    background: var(--text-tertiary);
}

.conversation-title {
    flex: 1;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    font-size: 14px;
    font-weight: 500;
    letter-spacing: 0.01em;
}

.conversation-menu {
    position: relative;
}

.conversation-menu-btn {
    background: transparent;
    border: none;
    color: inherit;
    cursor: pointer;
    padding: 6px 10px;
    border-radius: var(--radius-sm);
    transition: all var(--transition-fast);
    opacity: 0.6;
}

.conversation-menu-btn i {
    width: 18px;
    height: 18px;
}

/*
.conversation-menu-btn:hover {
    background: rgba(0, 0, 0, 0.05);
    opacity: 1;
}
 */

.conversation-dropdown {
    position: absolute;
    background: white;
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-lg);
    min-width: 140px;
    z-index: 3000;
    display: none;
    overflow: hidden;
}

.conversation-dropdown.show {
    display: block;
    animation: dropdownFadeIn 0.2s ease-out;
}

@keyframes dropdownFadeIn {
    from {
        opacity: 0;
        transform: translateY(-8px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.conversation-dropdown-item {
    width: 100%;
    padding: 12px 16px;
    text-align: left;
    border: none;
    background: transparent;
    cursor: pointer;
    font-size: 14px;
    color: var(--text-primary);
    transition: all var(--transition-fast);
}

.conversation-dropdown-item:hover {
    background: var(--background-secondary);
    color: var(--primary);
}

.conversation-dropdown-item.delete-btn {
    color: #ef4444;
}

.conversation-dropdown-item.delete-btn:hover {
    background: #fef2f2;
    color: #dc2626;
}

.main {
    margin-left: var(--sidebar-width);
    min-height: 100vh;
    position: relative;
    flex: 1;
    background-color: var(--background-secondary);
    display: flex;
    flex-direction: column;
    min-width: 0;
}

.chat-header {
    height: 64px;
    z-index: 1000;
    padding: 0 24px;
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    background: rgba(255, 255, 255, 0.8);
    backdrop-filter: blur(8px);
    position: sticky;
    top: 0;
}

.header-left {
    display: flex;
    align-items: center;
    gap: 12px;
}

.header-center {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
}

.header-left .model-selector {
    max-width: 250px;
}

.mobile-menu-btn {
    background: transparent;
    border: none;
    color: var(--text-primary);
    cursor: pointer;
    padding: 8px;
    border-radius: var(--radius-sm);
    display: none;
    align-items: center;
    justify-content: center;
    transition: all var(--transition-fast);
}

.mobile-menu-btn:hover {
    background: var(--background-tertiary);
}

.mobile-menu-btn i {
    width: 24px;
    height: 24px;
}

.mobile-menu-btn:focus {
    outline: 2px solid var(--primary);
    outline-offset: 2px;
}

.chat-title {
    font-size: 20px;
    font-weight: 700;
    color: var(--primary);
    letter-spacing: -0.02em;
}

.header-new-chat {
    background: var(--primary);
    color: white;
    border: none;
    border-radius: 50%;
    width: 37.98px;
    height: 37.98px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all var(--transition-normal);
    box-shadow: var(--shadow-sm);
}

.header-new-chat:hover {
    background: var(--primary-hover);
    transform: scale(1.08) rotate(90deg);
    box-shadow: var(--shadow-md);
}

.header-new-chat i {
    width: 20px;
    height: 20px;
}

.header-new-chat:hover {
    transform: scale(1.08) rotate(90deg);
    box-shadow: var(--shadow-md);
}

.chat-container {
    flex: 1;
    display: flex;
    flex-direction: column;
    width: 100%;
}

#model-selector-container {
    background: transparent;
}

.model-selector {
    display: flex;
    align-items: center;
    gap: 10px;
    width: 100%;
}

.header-center .model-selector {
    width: 100%;
    max-width: 400px;
}

.model-selector select {
    flex: 1;
    padding: 8px 14px;
    border: 0px solid var(--border);
    border-radius: var(--radius-md);
    font-size: 14px;
    font-family: inherit;
    background: white;
    cursor: pointer;
    outline: none;
    transition: all var(--transition-fast);
    color: var(--text-primary);
    font-weight: 500;
}

.model-selector select:hover {
    background-color: var(--primary-light);
}

.model-selector select:focus {
    background-color: var(--primary-light);
}

.model-selector select option {
    background: white;
    border-radius: var(--radius-md);
}

.model-select-wrapper {
    position: relative;
    width: 100%;
}

.model-select-trigger {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    flex: 1;
    padding: 8px 14px;
    border: 0px solid var(--border);
    border-radius: var(--radius-md);
    font-size: 14px;
    font-family: inherit;
    background: white;
    cursor: pointer;
    outline: none;
    transition: all var(--transition-fast);
    color: var(--text-primary);
    font-weight: 500;
}

.model-select-trigger:hover {
    background-color: var(--primary-light);
}

.model-select-trigger:focus {
    background-color: var(--primary-light);
    box-shadow: 0 0 0 2px var(--primary);
}

.model-select-value {
    flex: 1;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.model-select-arrow {
    flex-shrink: 0;
    color: var(--text-secondary);
    transition: transform var(--transition-fast);
}

.model-select-wrapper.open .model-select-arrow {
    transform: rotate(180deg);
}

.model-select-dropdown {
    position: absolute;
    top: calc(100% + 4px);
    left: 0;
    right: 0;
    background: white;
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-lg);
    z-index: 1000;
    display: none;
    overflow: hidden;
    max-height: 300px;
    overflow-y: auto;
}

.model-select-dropdown.show {
    display: block;
    animation: dropdownFadeIn 0.15s ease-out;
}

.model-select-dropdown::-webkit-scrollbar {
    width: 6px;
}

.model-select-dropdown::-webkit-scrollbar-track {
    background: transparent;
}

.model-select-dropdown::-webkit-scrollbar-thumb {
    background: var(--border-hover);
    border-radius: 3px;
}

.model-select-dropdown::-webkit-scrollbar-thumb:hover {
    background: var(--text-tertiary);
}

.model-select-option {
    padding: 10px 14px;
    cursor: pointer;
    transition: background var(--transition-fast);
    color: var(--text-primary);
    font-size: 14px;
    font-weight: 500;
}

.model-select-option:hover {
    background: var(--primary-light);
}

.model-select-option.selected {
    background: var(--primary-light);
    color: var(--primary);
    font-weight: 600;
}

.messages-container {
    position: relative;
    padding: 24px;
    scroll-behavior: smooth;
    background: var(--background-secondary);
    flex: 1;
    display: flex;
    flex-direction: column;
}

.messages-list {
    max-width: 800px;
    margin: 0 auto;
    display: flex;
    flex-direction: column;
    gap: 20px;
    flex: 1;
    width: 100%;
}

.new-session-indicator {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    flex: 1;
    color: var(--text-tertiary);
    text-align: center;
    padding: 40px 20px;
}

.new-session-icon {
    margin-bottom: 24px;
    opacity: 0.5;
}

.new-session-icon svg {
    stroke: var(--text-tertiary);
}

.new-session-title {
    font-size: 22px;
    font-weight: 600;
    color: var(--text-secondary);
    margin-bottom: 8px;
}

.new-session-hint {
    font-size: 15px;
    color: var(--text-tertiary);
}

.message {
    display: flex;
    width: 100%;
    animation: messageFadeIn 0.3s ease-out;
}

@keyframes messageFadeIn {
    from {
        opacity: 0;
        transform: translateY(10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.message-user {
    justify-content: flex-end;
}

.message-user .message-wrapper {
    align-items: flex-end;
}

.message-assistant {
    justify-content: flex-start;
}

.message-assistant .message-wrapper {
    align-items: flex-start;
}

.message-user .message-content {
    background: var(--primary-light);
    border-radius: var(--radius-lg) var(--radius-lg) 0 var(--radius-lg);
    padding: 16px 20px;
    max-width: 70%;
    word-wrap: break-word;
    color: var(--text-primary);
    box-shadow: var(--shadow-sm);
    border: 1px solid var(--border);
}

.message-assistant {
    justify-content: flex-start;
}

.message-assistant .message-wrapper {
    align-items: flex-start;
}

.message-assistant .message-content {
    background: transparent;
    padding: 8px 0;
    max-width: 100%;
    width: 100%;
    word-wrap: break-word;
    line-height: 1.7;
    color: var(--text-primary);
}

.message-assistant .message-content {
    background: transparent;
    padding: 8px 0;
    max-width: 100%;
    width: 100%;
    word-wrap: break-word;
    line-height: 1.7;
    color: var(--text-primary);
}

.message-error {
    justify-content: flex-start;
}

.message-error .message-content {
    background: #fef2f2;
    border: 1px solid #fecaca;
    border-radius: var(--radius-md);
    padding: 16px 20px;
    max-width: 100%;
    width: 100%;
    color: #991b1b;
}

.message-error strong {
    color: #dc2626;
    font-weight: 600;
}

.message-content h1,
.message-content h2,
.message-content h3,
.message-content h4,
.message-content h5,
.message-content h6 {
    margin-top: 1.5em;
    margin-bottom: 0.75em;
    font-weight: 700;
    line-height: 1.3;
    letter-spacing: -0.02em;
}

.message-content h1 { font-size: 2em; }
.message-content h2 { font-size: 1.75em; }
.message-content h3 { font-size: 1.5em; }
.message-content h4 { font-size: 1.25em; }
.message-content h5 { font-size: 1.1em; }
.message-content h6 { font-size: 1em; }

.message-content h1:first-child,
.message-content h2:first-child,
.message-content h3:first-child,
.message-content h4:first-child,
.message-content h5:first-child,
.message-content h6:first-child {
    margin-top: 0;
}

.message-content p {
    margin-bottom: 1em;
}

.message-content p:last-child {
    margin-bottom: 0;
}

.message-content ul,
.message-content ol {
    margin-bottom: 1em;
    padding-left: 2em;
}

.message-content ul {
    list-style-type: disc;
}

.message-content ol {
    list-style-type: decimal;
}

.message-content li {
    margin-bottom: 0.4em;
}

.message-content strong {
    font-weight: 700;
    color: var(--text-primary);
}

.message-content em {
    font-style: italic;
}

.message-content a {
    color: var(--primary);
    text-decoration: none;
    border-bottom: 1px solid transparent;
    transition: all var(--transition-fast);
}

.message-content a:hover {
    color: var(--primary-hover);
    border-bottom-color: var(--primary);
}

.message-content blockquote {
    margin: 1em 0;
    padding-left: 1.2em;
    border-left: 4px solid var(--primary);
    background: var(--primary-light);
    border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
    color: var(--text-secondary);
}

.message-content blockquote p:last-child {
    margin-bottom: 0;
}

.message-content hr {
    margin: 2em 0;
    border: none;
    border-top: 2px solid var(--border);
}

.message-content pre {
    margin: 1em 0;
    padding: 1.2em;
    /*
    background: #1e293b;
     */
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    overflow-x: auto;
    font-size: 0.9em;
    box-shadow: var(--shadow-sm);
}

.message-content code {
    background: var(--background-tertiary);
    padding: 0.2em 0.5em;
    border-radius: 4px;
    font-family: 'JetBrains Mono', 'Fira Code', ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
    font-size: 0.9em;
    color: var(--text-primary);
}

.message-content pre code {
    background: transparent;
    padding: 0;
    border-radius: 0;
}

.thinking-indicator {
    display: inline-flex;
    gap: 0.2em;
    align-items: center;
    vertical-align: -0.1em;
    margin-left: 0.2em;
}

.ellipsis-dot {
    background: var(--primary);
    animation: ellipsisPulse 1s ease-in-out infinite;
    display: inline-block;
    width: 0.3em;
    height: 0.3em;
    border-radius: 50%;
}

.ellipsis-dot:nth-child(1) { animation-delay: 0s; }
.ellipsis-dot:nth-child(2) { animation-delay: 0.2s; }
.ellipsis-dot:nth-child(3) { animation-delay: 0.4s; }

@keyframes ellipsisPulse {
    0%, 100% { opacity: 0.3; }
    50% { opacity: 1; }
}

.thinking-indicator.hidden {
    display: none;
}

.action-history {
    margin-bottom: 12px;
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    background: var(--background-secondary);
    overflow: hidden;
}

.action-history-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 8px 12px;
    cursor: pointer;
    user-select: none;
}

.action-history-summary {
    font-size: 12px;
    color: var(--text-tertiary);
    font-weight: 500;
}

.action-history-toggle {
    background: transparent;
    border: none;
    cursor: pointer;
    padding: 4px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--text-tertiary);
    transition: transform var(--transition-fast);
}

.action-history[data-expanded="true"] .action-history-chevron {
    transform: rotate(180deg);
}

.action-history-details {
    display: none;
    border-top: 1px solid var(--border);
    padding: 8px 0;
}

.action-history[data-expanded="true"] .action-history-details {
    display: block;
}

.action-step {
    padding: 8px 12px;
    border-bottom: 1px solid var(--border);
}

.action-step:last-child {
    border-bottom: none;
}

.action-step-header {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 4px;
}

.action-step-icon {
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--text-tertiary);
}

.action-step-name {
    font-size: 12px;
    font-weight: 600;
    color: var(--text-secondary);
}

.action-step-args {
    font-family: 'SF Mono', Monaco, Consolas, 'Courier New', monospace;
    font-size: 11px;
    color: var(--text-tertiary);
    background: var(--background-tertiary);
    padding: 8px;
    border-radius: var(--radius-sm);
    overflow-x: auto;
    margin: 4px 0 0 0;
    white-space: pre-wrap;
    word-break: break-word;
}

.action-step-content {
    font-size: 12px;
    color: var(--text-tertiary);
    line-height: 1.5;
    font-style: italic;
}

.action-step-tool-call .action-step-icon {
    color: var(--primary);
}

.action-step-reasoning .action-step-icon {
    color: #8b5cf6;
}

.message-content .table-wrapper {
    overflow-x: auto;
    margin: 1em 0;
    border-radius: var(--radius-md);
    border: 1px solid var(--border);
}

.message-content table {
    border-collapse: separate;
    border-spacing: 0;
    width: 100%;
    display: table;
}

.message-content th,
.message-content td {
    border-bottom: 1px solid var(--border);
    border-right: 1px solid var(--border);
    padding: 0.75em 1em;
}

.message-content th:last-child,
.message-content td:last-child {
    border-right: none;
}

.message-content tr:last-child td {
    border-bottom: none;
}

.message-content th {
    background: var(--background-secondary);
    font-weight: 700;
    color: var(--text-primary);
}

.message-wrapper {
    display: flex;
    flex-direction: column;
    gap: 6px;
    width: 100%;
    position: relative;
}

.message-controls {
    display: flex;
    align-items: center;
    gap: 6px;
    opacity: 0;
    transition: opacity var(--transition-normal);
    font-size: 12px;
    color: var(--text-tertiary);
}

.message-footer {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    margin-top: 4px;
}

.message-user .message-footer {
    flex-direction: row;
}

.message-assistant .message-footer {
    flex-direction: row;
}

.message:hover .message-controls {
        opacity: 1;
    }

    // Show controls permanently when streaming completes on last assistant message
    // This makes copy and try-again buttons immediately available without requiring hover
    .message-assistant.controls-visible .message-controls {
        opacity: 1;
    }

    // Hide controls on other assistant messages when not hovered (reduces clutter)
    .message.message-assistant:not(.controls-visible):not(:hover) .message-controls {
        opacity: 0;
    }

.message-copy-btn,
.message-edit-btn,
.message-try-again-btn,
.reaction-trigger {
    background: transparent;
    border: 1px solid transparent;
    cursor: pointer;
    padding: 6px;
    border-radius: var(--radius-sm);
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
    opacity: 0.7;
    transition: all var(--transition-fast);
    width: 24px;
    height: 24px;
}

.reaction-trigger svg {
    width: 16px;
    height: 16px;
}

.message-copy-btn::after,
.message-edit-btn::after,
.message-try-again-btn::after {
    content: attr(data-tooltip);
    position: absolute;
    bottom: calc(100% + 8px);
    left: 50%;
    transform: translateX(-50%);
    background: var(--text-primary);
    color: white;
    padding: 6px 10px;
    border-radius: var(--radius-sm);
    font-size: 12px;
    white-space: nowrap;
    pointer-events: none;
    opacity: 0;
    visibility: hidden;
    transition: all var(--transition-fast);
    z-index: 100;
    font-weight: 500;
}

.message-copy-btn:hover::after,
.message-edit-btn:hover::after,
.message-try-again-btn:hover::after {
    opacity: 1;
    visibility: visible;
}

.message-copy-btn:hover,
.message-edit-btn:hover,
.message-try-again-btn:hover {
    opacity: 1;
    background: var(--background-tertiary);
    color: var(--primary);
}

.message-copy-btn svg,
.message-edit-btn svg,
.message-try-again-btn svg {
    width: 16px;
    height: 16px;
}

.message-copied {
    color: #10b981 !important;
    background: rgba(16, 185, 129, 0.1) !important;
    border: 1px solid rgba(16, 185, 129, 0.2) !important;
    border-radius: var(--radius-sm);
    padding: 2px;
    opacity: 1 !important;
}

.message-timestamp {
    margin-left: auto;
    font-size: 12px;
    color: var(--text-tertiary);
    font-weight: 500;
}

.edit-mode-wrapper {
    display: flex;
    flex-direction: column;
    gap: 10px;
    padding: 16px 20px;
    background: var(--primary-light);
    border-radius: var(--radius-lg) var(--radius-lg) 0 var(--radius-lg);
    max-width: 100%;
    border: 1px solid var(--border);
}

.edit-textarea {
    width: 100%;
    border: none;
    background: transparent;
    padding: 0;
    font-size: 15px;
    font-family: inherit;
    resize: vertical;
    min-height: 70px;
    max-height: 200px;
    color: var(--text-primary);
    line-height: 1.6;
}

.edit-textarea:focus {
    outline: none;
}

.edit-buttons {
    display: flex;
    gap: 8px;
    justify-content: flex-end;
}

.edit-save-btn,
.edit-cancel-btn {
    padding: 8px 16px;
    border: none;
    border-radius: var(--radius-sm);
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: all var(--transition-fast);
}

.edit-save-btn {
    background: var(--primary);
    color: white;
}

.edit-save-btn:hover {
    background: var(--primary-hover);
    transform: translateY(-1px);
    box-shadow: var(--shadow-sm);
}

.edit-save-btn:hover {
    transform: translateY(-1px);
    box-shadow: var(--shadow-sm);
}

.edit-cancel-btn {
    background: var(--background-tertiary);
    color: var(--text-secondary);
}

.edit-cancel-btn:hover {
    background: var(--border);
}

.message-controls.editing {
    opacity: 1;
}

.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.6);
    backdrop-filter: blur(4px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    animation: overlayFadeIn 0.2s ease-out;
}

@keyframes overlayFadeIn {
    from {
        opacity: 0;
    }
    to {
        opacity: 1;
    }
}

.modal {
    background: white;
    border-radius: var(--radius-xl);
    box-shadow: var(--shadow-xl);
    max-width: 520px;
    width: 90%;
    overflow: hidden;
    animation: modalSlideUp 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

@keyframes modalSlideUp {
    from {
        opacity: 0;
        transform: translateY(20px) scale(0.98);
    }
    to {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

.modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 24px;
    border-bottom: 1px solid var(--border);
    background: var(--background-secondary);
}

.modal-header h3 {
    margin: 0;
    font-size: 20px;
    font-weight: 700;
    color: var(--text-primary);
    letter-spacing: -0.02em;
}

.modal-close {
    background: transparent;
    border: none;
    font-size: 28px;
    color: var(--text-tertiary);
    cursor: pointer;
    width: 36px;
    height: 36px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    transition: all var(--transition-fast);
}

.modal-close:hover {
    background: var(--background-tertiary);
    color: var(--text-primary);
}

.modal-body {
    padding: 28px;
}

.modal-body p {
    margin: 0 0 20px 0;
    font-size: 15px;
    color: var(--text-secondary);
    line-height: 1.6;
}

.try-again-options {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.try-again-btn {
    display: flex;
    align-items: center;
    gap: 14px;
    padding: 18px 20px;
    background: var(--background-secondary);
    border: 2px solid var(--border);
    border-radius: var(--radius-md);
    font-size: 15px;
    color: var(--text-primary);
    cursor: pointer;
    transition: all var(--transition-normal);
    text-align: left;
    font-weight: 500;
}

.try-again-btn:hover {
    background: var(--background-tertiary);
    border-color: var(--primary);
    color: var(--primary);
    transform: translateY(-2px);
    box-shadow: var(--shadow-md);
}

.try-again-btn .option-icon {
    width: 24px;
    height: 24px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--primary);
}

.try-again-btn span {
    flex: 1;
}

.input-area-wrapper {
    position: sticky;
    bottom: 0;
    background: linear-gradient(to top, var(--background-secondary) 0%, transparent 100%);
    padding: 24px 24px 24px 24px;
    z-index: 10;
}

.input-area {
    display: flex;
    flex-direction: column;
    /*
    align-items: end;
     */
    gap: 10px;
    padding: 20px;
    border: 1px solid var(--border);
    border-radius: 36px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.08);
    max-width: 800px;
    margin: 0 auto;
    width: 100%;
    background: white;
}

/* 
   IMPORTANT: Remove all browser default focus indicators from textarea
   - Browsers add a default dark rectangular focus ring on textarea focus
   - This conflicts with our custom input-wrapper border styling
   - Using !important to override browser-specific focus styles that are hard to target
   - Targeting :focus, :focus-visible, and :focus-within for cross-browser support
   - Also removing box-shadows that browsers add to focused elements
   */
.message-input {
    flex: 1;
    border: none;
    padding: 14px 58px 14px 58px;
    font-size: 15px;
    font-family: inherit;
    resize: none;
    outline: none !important;
    outline-width: 0 !important;
    outline-style: none !important;
    outline-color: transparent !important;
    -webkit-outline: none;
    min-height: 50px;
    max-height: 200px;
    overflow-y: auto;
    transition: all var(--transition-fast);
    background: transparent;
    color: var(--text-primary);
    line-height: 1.5;
    -webkit-appearance: none;
    -moz-appearance: none;
    appearance: none;
}

/* Focus removal styles - prevents browser's default focus ring appearance */
.message-input:focus,
.message-input:focus-visible,
.message-input:focus-within {
    outline: none !important;
    outline-width: 0 !important;
    border: none !important;
    box-shadow: none !important;
    -webkit-box-shadow: none !important;
}

.message-input::placeholder {
    color: var(--text-tertiary);
}

.message-input:hover {
    border: none !important;
}

.message-input:-webkit-autofill,
.message-input:-webkit-autofill:hover,
.message-input:-webkit-autofill:focus,
.message-input:-webkit-autofill:active {
    -webkit-box-shadow: 0 0 0 30px white inset !important;
    -webkit-text-fill-color: var(--text-primary) !important;
    caret-color: var(--text-primary) !important;
    transition: background-color 5000s ease-in-out 0s;
}

.message-input::-webkit-scrollbar {
    width: 6px;
}

.message-input::-webkit-scrollbar-track {
    background: transparent;
}

.message-input::-webkit-scrollbar-thumb {
    background: var(--border-hover);
    border-radius: 3px;
}

.message-input::-webkit-scrollbar-thumb:hover {
    background: var(--text-tertiary);
}

/*
   Input wrapper handles border and focus styling for the entire input area
   - Moving focus indicators from textarea to wrapper for cleaner appearance
   - The wrapper gets the focus ring (via box-shadow) when child textarea is focused
   - outline: none !important prevents browser's default focus indicators on the wrapper
   */
.input-wrapper {
    flex: 1;
    position: relative;
    display: flex;
    min-height: 50px;
    border: 2px solid var(--border);
    border-radius: var(--radius-lg);
    background: var(--background-secondary);
    outline: none !important;
}

/* When textarea inside wrapper is focused, style the wrapper instead of textarea */
.input-wrapper:focus-within {
    outline: none !important;
    border-color: var(--primary);
    background: white;
    box-shadow: 0 0 0 4px rgba(55, 65, 81, 0.15);
}

.input-wrapper:hover:not(:focus-within) {
    border-color: var(--border-hover);
    outline: none !important;
}

.message-input.editing {
    padding-right: 44px;
    border-color: var(--warning-color, #f59e0b);
}

.cancel-edit-btn {
    position: absolute;
    right: 10px;
    top: 50%;
    transform: translateY(-50%);
    width: 28px;
    height: 28px;
    border: none;
    background: transparent;
    border-radius: var(--radius-md);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    color: var(--text-secondary);
    transition: all var(--transition-fast);
}

.cancel-edit-btn:hover {
    background: var(--background-tertiary);
    color: var(--text-primary);
}

.cancel-edit-btn svg {
    width: 18px;
    height: 18px;
}

.send-button {
    padding: 0;
    background: var(--primary);
    color: white;
    border: none;
    border-radius: 50%;
    font-size: 15px;
    font-weight: 600;
    cursor: pointer;
    width: 44px;
    height: 44px;
    position: absolute;
    right: 6px;
    bottom: 3px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all var(--transition-normal);
    box-shadow: var(--shadow-sm);
}

.send-button:hover:not(:disabled) {
    background: var(--primary-hover);
    transform: translateY(-2px);
    box-shadow: var(--shadow-md);
}

.input-wrapper:focus-within .attachment-button {
    background: white;
}

.send-button:active:not(:disabled) {
    transform: translateY(0);
}

.send-button:disabled {
    background: var(--background-tertiary);
    color: var(--text-tertiary);
    cursor: not-allowed;
    box-shadow: none;
}

.hidden {
    display: none !important;
}

.scroll-to-bottom-btn {
    position: fixed;
    bottom: 140px;
    left: calc(50% + var(--sidebar-width) / 2);
    transform: translateX(-50%);
    background: var(--primary);
    color: white;
    border: none;
    border-radius: 50%;
    width: 44px;
    height: 44px;
    cursor: pointer;
    box-shadow: var(--shadow-lg);
    transition: all var(--transition-fast);
    z-index: 100;
}

.scroll-to-bottom-btn:hover {
    background: var(--primary-hover);
    box-shadow: var(--shadow-xl);
}

.image-input {
    display: none !important;
}

.attachment-button {
    padding: 0;
    background: var(--background-secondary);
    color: var(--text-primary);
    border: none;
    border-radius: 50%;
    cursor: pointer;
    width: 44px;
    height: 44px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all var(--transition-normal);
}

.attachment-button i {
    width: 20px;
    height: 20px;
}

.attachment-button:hover:not(:disabled) {
    background: var(--background-tertiary);
    transform: translateY(-2px);
    box-shadow: var(--shadow-sm);
}

.attachment-button:active:not(:disabled) {
    transform: translateY(0);
}

.attachment-button:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.attachment-button[data-images-pending="true"] {
    color: var(--primary);
    background: var(--primary-light);
}

.attachment-button[data-images-pending="true"]::after {
    content: '';
    position: absolute;
    top: 6px;
    right: 6px;
    width: 10px;
    height: 10px;
    background: var(--primary);
    border-radius: 50%;
    border: 2px solid white;
    animation: pulse 2s infinite;
    box-shadow: 0 0 0 3px rgba(55, 65, 81, 0.15);
}

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

.attachment-area {
    position: absolute;
    left: 6px;
    bottom: 3px;
    display: flex;
    align-items: center;
    gap: 8px;
}

.image-budget {
    position: absolute;
    right: calc(24px + 36px);
    bottom: 6px;
    font-size: 11px;
    color: var(--text-secondary);
    white-space: nowrap;
    padding: 2px 6px;
    background: var(--background-secondary);
    border-radius: var(--radius-sm);
    opacity: 0.8;
    pointer-events: none;
}

.image-budget.budget-exceeded {
    color: var(--error);
    background: rgba(220, 38, 38, 0.1);
}

.input-area.drag-over {
    background: var(--background-tertiary);
    border-radius: var(--radius-lg);
    border: 2px dashed var(--primary);
    animation: dragPulse 1.5s ease-in-out infinite;
}

@keyframes dragPulse {
    0%, 100% { border-color: var(--primary); background: var(--background-tertiary); }
    50% { border-color: var(--primary-hover); background: var(--background-secondary); }
}

.image-preview {
    max-width: 100%;
    width: 100%;
}

.image-preview.hidden {
    display: none !important;
}

.preview-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 0 8px 0;
    border-bottom: 1px solid var(--border);
}

.preview-count {
    font-size: 14px;
    font-weight: 600;
    color: var(--text-primary);
    display: flex;
    align-items: center;
    gap: 8px;
}

.preview-count i {
    width: 16px;
    height: 16px;
    color: var(--primary);
}

.preview-budget {
    font-size: 12px;
    color: var(--text-secondary);
    margin-left: auto;
    margin-right: 8px;
}

.clear-images-btn {
    background: white;
    border: 1px solid #fecaca;
    color: #dc2626;
    cursor: pointer;
    padding: 8px 14px;
    border-radius: var(--radius-sm);
    font-weight: 600;
    transition: all var(--transition-fast);
    box-shadow: var(--shadow-sm);
}

.clear-images-btn i {
    width: 18px;
    height: 18px;
}

.clear-images-btn:hover {
    background: #dc2626;
    color: white;
    box-shadow: var(--shadow-md);
    transform: translateY(-1px);
}

.clear-images-btn:active {
    transform: translateY(0);
}

.preview-thumbnails {
    display: flex;
    gap: 14px;
    flex-wrap: wrap;
    padding: 16px 20px;
    background: var(--background);
}

.preview-thumbnail {
    position: relative;
    width: 110px;
    height: 110px;
    border-radius: var(--radius-md);
    overflow: hidden;
    border: 2px solid var(--border);
    box-shadow: var(--shadow-sm);
    transition: all var(--transition-normal);
    animation: thumbnailFadeIn 0.3s ease-out;
}

@keyframes thumbnailFadeIn {
    from {
        opacity: 0;
        transform: scale(0.85);
    }
    to {
        opacity: 1;
        transform: scale(1);
    }
}

.preview-thumbnail:hover {
    border-color: var(--primary);
    box-shadow: var(--shadow-lg);
    transform: translateY(-2px);
}

.preview-thumbnail img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    transition: transform var(--transition-normal);
}

.preview-thumbnail:hover img {
    transform: scale(1.1);
}

.remove-image-btn {
    position: absolute;
    top: 6px;
    right: 6px;
    width: 28px;
    height: 28px;
    background: rgba(0, 0, 0, 0.7);
    color: white;
    border: none;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all var(--transition-fast);
    opacity: 0.6;
    transform: scale(1);
    box-shadow: var(--shadow-md);
    padding: 0;
}

.remove-image-btn i {
    width: 18px;
    height: 18px;
}

.preview-thumbnail:hover .remove-image-btn {
    opacity: 1;
}

.remove-image-btn:hover {
    background: #dc2626;
    transform: scale(1.15);
}

.remove-image-btn:active {
    transform: scale(0.95);
}

.message-images {
    display: flex;
    gap: 12px;
    flex-wrap: wrap;
    margin-bottom: 12px;
    padding: 14px;
    background: var(--background-secondary);
    border-radius: var(--radius-lg);
    border: 1px solid var(--border);
}

.message-image {
    max-width: 180px;
    max-height: 180px;
    border-radius: var(--radius-md);
    cursor: pointer;
    transition: all var(--transition-normal);
    box-shadow: var(--shadow-sm);
    object-fit: cover;
}

.message-image:hover {
    transform: scale(1.05);
    box-shadow: var(--shadow-lg);
}

.image-lightbox {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.95);
    backdrop-filter: blur(8px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 2000;
    animation: fadeIn 0.2s ease-out;
}

@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

.image-lightbox img {
    max-width: 90vw;
    max-height: 90vh;
    object-fit: contain;
    border-radius: var(--radius-lg);
    box-shadow: 0 20px 50px rgba(0, 0, 0, 0.5);
    animation: zoomIn 0.3s ease-out;
}

@keyframes zoomIn {
    from {
        transform: scale(0.9);
    }
    to {
        transform: scale(1);
    }
}

.lightbox-close {
    position: absolute;
    top: 24px;
    right: 24px;
    width: 50px;
    height: 50px;
    background: rgba(255, 255, 255, 0.1);
    border: 1px solid rgba(255, 255, 255, 0.2);
    border-radius: 50%;
    color: white;
    font-size: 28px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all var(--transition-normal);
    backdrop-filter: blur(10px);
}

.lightbox-close:hover {
    background: rgba(255, 255, 255, 0.2);
    transform: scale(1.1);
}

.lightbox-nav {
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    width: 50px;
    height: 50px;
    background: rgba(255, 255, 255, 0.1);
    border: 1px solid rgba(255, 255, 255, 0.2);
    border-radius: 50%;
    color: white;
    font-size: 24px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all var(--transition-normal);
    backdrop-filter: blur(10px);
}

.lightbox-nav:hover {
    background: rgba(255, 255, 255, 0.2);
    transform: translateY(-50%) scale(1.1);
}

.lightbox-nav.prev {
    left: 24px;
}

.lightbox-nav.next {
    right: 24px;
}

.lightbox-nav:disabled {
    opacity: 0.2;
    cursor: not-allowed;
}

.lightbox-nav:disabled:hover {
    background: rgba(255, 255, 255, 0.1);
    transform: translateY(-50%) scale(1);
}

.lightbox-counter {
    position: absolute;
    bottom: 36px;
    left: 50%;
    transform: translateX(-50%);
    background: rgba(0, 0, 0, 0.6);
    color: white;
    padding: 10px 20px;
    border-radius: 24px;
    font-size: 15px;
    font-weight: 600;
    backdrop-filter: blur(10px);
}

.lightbox-download {
    position: absolute;
    bottom: 36px;
    right: 36px;
    width: 50px;
    height: 50px;
    background: rgba(255, 255, 255, 0.1);
    border: 1px solid rgba(255, 255, 255, 0.2);
    border-radius: 50%;
    color: white;
    font-size: 18px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all var(--transition-normal);
    backdrop-filter: blur(10px);
}

.lightbox-download:hover {
    background: rgba(255, 255, 255, 0.2);
    transform: scale(1.1);
}

.message-content .katex {
    font-size: 1.1em;
}

.message-content .katex-display {
    margin: 2em 0;
    overflow-x: auto;
    overflow-y: hidden;
    text-align: center;
}

.message-content .katex-display > .katex {
    text-align: initial;
}

.math-error {
    background: #fef2f2;
    border: 1px solid #fecaca;
    border-radius: var(--radius-sm);
    padding: 4px 8px;
    color: #dc2626;
    font-family: 'JetBrains Mono', 'Courier New', monospace;
}

.message-content pre {
    position: relative;
}

.message-content pre .hljs {
    background: #ffffff;
    padding: 1.2em;
}

.message-content pre code {
    font-size: 0.9em;
    line-height: 1.6;
}

.message-content pre code.language-plaintext {
    font-family: 'JetBrains Mono', ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
}

.code-block-wrapper {
    position: relative;
    margin: 1em 0;
    background-color: white;
}

.code-block-wrapper pre {
    margin: 0;
}

.code-copy-btn {
    position: absolute;
    top: 8px;
    right: 8px;
    width: 32px;
    height: 32px;
    background: rgba(255, 255, 255, 0.1);
    border: 1px solid rgba(255, 255, 255, 0.2);
    border-radius: var(--radius-sm);
    color: rgba(100, 100, 100, 0.7);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all var(--transition-fast);
    z-index: 10;
}

.code-block-wrapper:hover .code-copy-btn {
    opacity: 1;
}

.code-copy-btn:hover {
    background: rgba(255, 255, 255, 0.2);
    color: white;
    border-color: rgba(255, 255, 255, 0.3);
}

.code-copy-btn::after {
    content: attr(data-tooltip);
    position: absolute;
    bottom: calc(100% + 6px);
    left: 50%;
    transform: translateX(-50%);
    background: var(--text-primary);
    color: white;
    padding: 4px 8px;
    border-radius: var(--radius-sm);
    font-size: 11px;
    white-space: nowrap;
    pointer-events: none;
    opacity: 0;
    visibility: hidden;
    transition: all var(--transition-fast);
    z-index: 100;
}

.code-copy-btn:hover::after {
    opacity: 1;
    visibility: visible;
}

.code-copy-btn.copied {
    background: rgba(16, 185, 129, 0.2) !important;
    color: #10b981 !important;
    border-color: rgba(16, 185, 129, 0.3) !important;
    opacity: 1 !important;
}

.code-copy-btn svg {
    width: 16px;
    height: 16px;
}

.mermaid-diagram {
    text-align: center;
    margin: 2em 0;
    overflow-x: auto;
}

.mermaid-diagram svg {
    max-width: 100%;
    height: auto;
}

.mermaid-error {
    background: #fef2f2;
    border: 1px solid #fecaca;
    border-radius: var(--radius-sm);
    padding: 1.2em;
    color: #dc2626;
}

.mermaid-error code {
        color: #dc2626;
        font-family: 'JetBrains Mono', 'Courier New', monospace;
        background: transparent;
    }

.sidebar.closed {
    transform: translateX(-100%);
}

.sidebar.open {
    transform: translateX(0);
}

@media (max-width: 1023px) {
    .input-area-wrapper {
        padding: 16px;
    }

    .input-area {
        flex-direction: column;
        flex-wrap: wrap;
        gap: 8px;
        padding: 16px;
        border-radius: 32px;
        margin: 0;
    }

}

@media (max-width: 767px) {
    .main {
        margin-left: 0;
    }
    
    .scroll-to-bottom-btn {
        left: 50%;
    }
    
    .app-container {
        flex-direction: column;
    }

    .sidebar {
        position: fixed;
        top: 0;
        left: 0;
        bottom: 0;
        z-index: 1500;
        transform: translateX(-100%);
        transition: transform var(--transition-normal);
        box-shadow: var(--shadow-xl);
        background: var(--background-secondary);
        width: var(--sidebar-width);
        opacity: 0;
        visibility: hidden;
        height: 100vh;
    }

    .sidebar.open {
        transform: translateX(0) !important;
        opacity: 1;
        visibility: visible;
    }

    .mobile-menu-btn {
        display: flex;
    }

    .chat-title {
        font-size: 18px;
    }

    .header-center .model-selector {
        max-width: 180px;
    }

    .chat-header,
    .messages-container,
    .input-area,
    .image-preview {
        padding-left: 16px;
        padding-right: 16px;
    }

    .messages-container {
        padding: 16px;
    }

    .messages-list {
        gap: 16px;
    }

    .message-user .message-content {
        max-width: 90%;
        padding: 12px 16px;
    }

    .message-assistant .message-content {
        padding: 4px 0;
    }

    .message-content h1 { font-size: 1.6em; }
    .message-content h2 { font-size: 1.4em; }
    .message-content h3 { font-size: 1.2em; }
    .message-content h4 { font-size: 1.1em; }
    .message-content h5 { font-size: 1.05em; }
    .message-content h6 { font-size: 1em; }

    .message-content pre {
        font-size: 0.85em;
        padding: 1em;
        overflow-x: auto;
    }

    .message-content table {
        font-size: 0.9em;
    }

    .message-content th,
    .message-content td {
        padding: 0.6em 0.8em;
    }

    .message-input {
        min-height: 44px;
        font-size: 16px;
    }

    .attachment-button,
    .send-button {
        width: 44px;
        height: 44px;
        min-height: 44px;
        min-width: 44px;
        padding: 0;
    }

    .attachment-button i,
    .send-button i {
        width: 20px;
        height: 20px;
    }

    #send-icon,
    #stop-icon {
        font-size: 14px;
    }

    .scroll-to-bottom-btn {
        width: 40px;
        height: 40px;
        right: 16px;
    }

    .modal {
        max-width: 95%;
        margin: 16px;
    }

    .modal-header,
    .modal-body {
        padding: 20px;
    }

    .preview-thumbnails {
        flex-wrap: wrap;
    }

    .preview-thumbnail {
        width: 90px;
        height: 90px;
    }

    .message-images {
        padding: 10px;
    }

    .message-image {
        max-width: 120px;
        max-height: 120px;
    }

    .lightbox-close,
    .lightbox-nav,
    .lightbox-download {
        width: 44px;
        height: 44px;
    }

    .lightbox-close {
        top: 16px;
        right: 16px;
    }

    .lightbox-nav.prev {
        left: 16px;
    }

    .lightbox-nav.next {
        right: 16px;
    }

    .lightbox-counter {
        bottom: 20px;
        padding: 8px 16px;
        font-size: 14px;
    }

    .lightbox-download {
        bottom: 20px;
        right: 20px;
    }

    .message-copy-btn,
    .message-edit-btn,
    .message-try-again-btn {
        width: 36px;
        height: 36px;
        padding: 8px;
    }

    .message-copy-btn svg,
    .message-edit-btn svg,
    .message-try-again-btn svg {
        width: 18px;
        height: 18px;
    }

    .message-timestamp {
        font-size: 11px;
    }
}

@media (min-width: 768px) and (max-width: 1023px) {
    .chat-title {
        font-size: 19px;
    }

    .messages-container {
        padding: 20px;
    }

    .input-area {
        padding: 16px;
        margin: 0;
        border-radius: 32px;
    }

    .model-selector {
        padding: 12px 20px;
    }
}

@media (min-width: 1024px) {
    .mobile-menu-btn {
        display: none !important;
    }

    .sidebar-overlay {
        display: none !important;
    }
}

@media (max-width: 480px) {
    .chat-header {
        padding: 12px 16px;
    }

    .chat-title {
        font-size: 16px;
    }

    .header-new-chat {
        width: 36px;
        height: 36px;
    }

    .header-new-chat i {
        width: 18px;
        height: 18px;
    }

    .model-selector select {
        font-size: 14px;
        padding: 8px 12px;
    }

    .input-area-wrapper {
        padding: 10px 14px 25px 14px;
    }

    .image-budget {
        right: calc(14px + 32px);
    }

    .attachment-button i,
    .send-button i {
        width: 18px;
        height: 18px;
    }

    .message-content h1 { font-size: 1.4em; }
    .message-content h2 { font-size: 1.25em; }
    .message-content h3 { font-size: 1.1em; }

    .message-content ul,
    .message-content ol {
        padding-left: 1.5em;
    }

    .conversation-tab {
        padding: 12px 14px;
    }

    .conversation-title {
        font-size: 13px;
    }

    .modal-header h3 {
        font-size: 18px;
    }

    .modal-body p {
        font-size: 14px;
    }

    .try-again-btn {
        padding: 14px 16px;
        font-size: 14px;
    }
}

.conversation-menu-btn.streaming {
    animation: menu-pulse 1s infinite;
}

.conversation-menu-btn.streaming i {
    animation: icon-pulse 1s infinite;
}

@keyframes menu-pulse {
    0%, 100% {
        opacity: 0.3;
    }
    50% {
        opacity: 1;
    }
}

@keyframes icon-pulse {
    0%, 100% {
        color: currentColor;
    }
    50% {
        color: var(--primary, #2563eb);
    }
}

/* Auth Loading */
.auth-loading {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: var(--background);
    z-index: 9999;
}

.spinner {
    width: 40px;
    height: 40px;
    border: 4px solid var(--border);
    border-top-color: var(--primary);
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

/* Auth Guard */
.auth-guard {
    display: flex;
    align-items: center;
    justify-content: center;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: var(--background);
    z-index: 1000;
}

.auth-box {
    text-align: center;
    padding: 2rem;
}

.auth-box h1 {
    margin-bottom: 0.5rem;
    color: var(--text-primary);
}

.auth-box p {
    margin-bottom: 2rem;
    color: var(--text-secondary);
}

.auth-button {
    width: 100%;
    padding: 0.75rem 1.5rem;
    margin: 0.5rem 0;
    border: none;
    border-radius: var(--radius-md);
    background: var(--primary);
    color: white;
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.2s;
}

.auth-button:hover {
    background: var(--primary-hover);
}

.auth-button.secondary {
    background: transparent;
    border: 2px solid var(--border);
    color: var(--text-primary);
}

.auth-button.secondary:hover {
    background: var(--background-secondary);
}

/* Auth Pages */
.auth-page {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    background: var(--background);
    padding: 1rem;
}

.auth-card {
    width: 100%;
    max-width: 400px;
    padding: 2rem;
    background: var(--background-secondary);
    border-radius: var(--radius-lg);
    border: 1px solid var(--border);
}

.auth-card h1 {
    margin: 0 0 1.5rem 0;
    text-align: center;
    color: var(--text-primary);
}

.form-group {
    margin-bottom: 1.25rem;
}

.form-group label {
    display: block;
    margin-bottom: 0.5rem;
    font-weight: 500;
    color: var(--text-primary);
}

.form-group input {
    width: 100%;
    padding: 0.75rem;
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    background: var(--background);
    color: var(--text-primary);
    font-size: 1rem;
}

.form-group input:focus {
    outline: none;
    border-color: var(--primary);
}

.form-group small {
    display: block;
    margin-top: 0.25rem;
    font-size: 0.875rem;
    color: var(--text-secondary);
}

.form-actions {
    display: flex;
    gap: 0.5rem;
    margin-top: 1.5rem;
}

.form-actions button {
    flex: 1;
}

.auth-error {
    margin-top: 1rem;
    padding: 0.75rem;
    background: #fef2f2;
    color: #991b1b;
    border-radius: var(--radius-md);
    text-align: center;
    font-size: 0.875rem;
}

/* User Menu */
.user-menu {
    position: relative;
}

.user-menu-button {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.5rem;
    padding: 0.5rem 0.75rem;
    background: var(--background-secondary);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    cursor: pointer;
    color: var(--text-primary);
    width: 100%;
}

.sidebar-footer .user-menu-button {
    width: 100%;
}

.user-menu-button:hover {
    background: var(--background-tertiary);
}

.user-avatar {
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--primary);
    color: white;
    border-radius: 50%;
    font-weight: 600;
    font-size: 0.875rem;
}

.user-email {
    font-size: 0.875rem;
    color: var(--text-primary);
}

.sidebar-footer .user-email {
    display: none;
}

.user-dropdown {
    position: absolute;
    top: calc(100% + 0.5rem);
    right: 0;
    width: 280px;
    background: var(--background-secondary);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
    z-index: 100;
    overflow: hidden;
}

.sidebar-footer .user-dropdown {
    right: auto;
    left: 0;
    width: 260px;
    bottom: calc(100% + 0.5rem);
    top: auto;
}

.user-info {
    padding: 1rem;
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.user-avatar-large {
    width: 48px;
    height: 48px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--primary);
    color: white;
    border-radius: 50%;
    font-weight: 600;
    font-size: 1.125rem;
}

.user-email-large {
    flex: 1;
    font-size: 0.875rem;
    font-weight: 500;
    color: var(--text-primary);
    overflow: hidden;
    text-overflow: ellipsis;
}

.user-divider {
    height: 1px;
    background: var(--border);
    margin: 0;
}

.user-menu-item {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    width: 100%;
    padding: 0.75rem 1rem;
    background: transparent;
    border: none;
    color: var(--text-primary);
    cursor: pointer;
    font-size: 0.875rem;
}

.user-menu-item:hover {
    background: var(--background-tertiary);
}

.user-menu-item i {
    width: 16px;
    height: 16px;
}

/* Header Right */
.header-right {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

/* Pull to Refresh */
.pull-to-refresh-container {
    background: linear-gradient(0deg, var(--background-secondary) 0%, var(--background) 100%);
    border-top: 1px solid var(--border);
}

.pull-to-refresh-content {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 60px;
    gap: 6px;
    transition: transform 0.1s ease-out;
}

.refresh-icon {
    color: var(--primary);
    transition: transform 0.1s ease-out;
}

.refresh-icon.spinning {
    animation: spin 1s linear infinite;
}

.chat-header,
.messages-container,
.input-area {
    transition: transform 0.1s ease-out;
}

@media (min-width: 768px) {
    .pull-to-refresh-container {
        display: none;
    }
}

.reaction-bubbles {
    display: flex;
    align-items: center;
    gap: 4px;
    flex-shrink: 0;
}

.reaction-bubble {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 24px;
    height: 24px;
    padding: 0 6px;
    background: white;
    border: 1px solid var(--border);
    border-radius: 12px;
    font-size: 14px;
    box-shadow: var(--shadow-sm);
    cursor: pointer;
    transition: all var(--transition-fast);
}

.reaction-bubble:hover {
    transform: scale(1.1);
    box-shadow: var(--shadow-md);
}

.reaction-bubble-assistant {
    background: var(--background-tertiary);
}

.reaction-picker {
    --emoji-size: 1.25rem;
    --emoji-padding: 0.375rem;
    --num-columns: 8;
    --category-emoji-size: 1.25rem;
    --category-button-padding: 0.5rem;
    
    border-radius: var(--radius-md);
    border: 1px solid var(--border);
    box-shadow: var(--shadow-lg);
    background: var(--background);
    max-width: 320px;
}

.reaction-picker::part(search) {
    border-radius: var(--radius-sm);
    border: 1px solid var(--border);
    padding: 8px 12px;
    font-size: 14px;
    margin: 8px;
}

.reaction-picker::part(search):focus {
    outline: none;
    border-color: var(--primary);
}

.reaction-picker::part(category-buttons) {
    padding: 4px 8px;
    border-bottom: 1px solid var(--border);
}

.reaction-picker::part(category-button) {
    padding: 6px;
    border-radius: var(--radius-sm);
    transition: background var(--transition-fast);
}

.reaction-picker::part(category-button):hover {
    background: var(--background-tertiary);
}

.reaction-picker::part(category-button).active {
    background: var(--primary-light);
}

.reaction-picker::part(emoji-grid) {
    padding: 8px;
}

.reaction-picker::part(emoji) {
    border-radius: var(--radius-sm);
    transition: background var(--transition-fast);
}

.reaction-picker::part(emoji):hover {
    background: var(--background-tertiary);
}

.message-wrapper {
    position: relative;
}

.message[data-can-react="true"] .reaction-trigger {
    position: absolute;
    top: 8px;
    right: 8px;
    width: 28px;
    height: 28px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--background);
    border: 1px solid var(--border);
    border-radius: 50%;
    opacity: 0;
    cursor: pointer;
    transition: opacity var(--transition-fast);
    z-index: 10;
}

.message[data-can-react="true"]:hover .reaction-trigger,
.message[data-can-react="true"].touch-active .reaction-trigger {
    opacity: 1;
}

.message[data-can-react="true"] .reaction-trigger:hover {
    background: var(--background-tertiary);
}

.message[data-can-react="true"] .reaction-trigger svg {
    width: 16px;
    height: 16px;
    color: var(--text-secondary);
}

.disregard-indicator {
    display: inline-flex;
    align-items: center;
    color: var(--text-tertiary);
    margin: 0 4px;
}

.disregard-indicator svg {
    width: 16px;
    height: 16px;
}
