/* --- THEME COLORS START --- */
:root {
    --bg-primary: #212121;
    --bg-secondary: #171717;
    --bg-tertiary: #2d2d2d;
    --bg-tertiary-hover: #333333;
    --bg-interactive: #3d3d3d;
    --bg-interactive-hover: #4d4d4d;
    --bg-user-message: #333333;
    --bg-code: #1e1e1e;

    --text-primary: rgba(255, 255, 255, 0.9);
    --text-secondary: #8a8a8a;
    --text-tertiary: #676767;
    --text-white: #fff;
    --text-code: #e06c75;

    --border-primary: #2d2d2d;
    --border-interactive: #3d3d3d;
    --border-code: #3d3d3d;

    --accent-primary: #6366f1;
    --accent-primary-hover: #5558e3;
    --accent-error: #ef4444;

    --shadow-color: rgba(0, 0, 0, 0.4);
    --shadow-color-light: rgba(0, 0, 0, 0.3);
    --shadow-color-heavy: rgba(0, 0, 0, 0.6);
    --overlay-color: rgba(0, 0, 0, 0.5);

    --send-btn-bg: #676767;
    --send-btn-color: #212121;
    --send-btn-bg-hover: #7a7a7a;
    --send-btn-bg-active: #fff;
    --send-btn-color-active: #212121;
}

body.light-theme {
    --bg-primary: #FFFFFF;
    --bg-secondary: #F7F7F8;
    --bg-tertiary: #FFFFFF;
    --bg-tertiary-hover: #F7F7F8;
    --bg-interactive: #ECECEC;
    --bg-interactive-hover: #E0E0E0;
    --bg-user-message: #F0F0F0;
    --bg-code: #F7F7F8;

    --text-primary: #202123;
    --text-secondary: #6E6E80;
    --text-tertiary: #A0A0A0;
    --text-white: #fff;
    --text-code: #d12f2f;

    --border-primary: #E5E5E5;
    --border-interactive: #D9D9E3;
    --border-code: #E5E5E5;

    --shadow-color: rgba(0, 0, 0, 0.1);
    --shadow-color-light: rgba(0, 0, 0, 0.08);
    --shadow-color-heavy: rgba(0, 0, 0, 0.15);
    --overlay-color: rgba(0, 0, 0, 0.4);

    --send-btn-bg: #D1D1D1;
    --send-btn-color: #333;
    --send-btn-bg-hover: #C0C0C0;
    --send-btn-bg-active: #212121;
    --send-btn-color-active: #fff;
}

/* --- THEME COLORS END --- */

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

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Helvetica Neue', 'Arial', sans-serif;
    background: var(--bg-primary);
    color: var(--text-primary);
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    overscroll-behavior: none;
    -webkit-tap-highlight-color: transparent;
}

.app-container {
    display: flex;
    height: 100vh;
    height: 100dvh;
    position: relative;
    will-change: transform;
    contain: layout style;
}

.sidebar {
    width: 260px;
    background: var(--bg-secondary);
    display: flex;
    flex-direction: column;
    padding: 12px;
    border-right: 1px solid var(--border-primary);
    position: fixed;
    left: 0;
    top: 0;
    bottom: 0;
    z-index: 1000;
    transform: translateX(-100%);
    transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    will-change: transform;
}

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

.sidebar-header {
    margin-bottom: 8px;
    position: relative;
}

.logo-dropdown {
    display: flex;
    align-items: center;
    padding: 12px;
    cursor: pointer;
    border-radius: 8px;
    transition: background 0.2s ease;
    position: relative;
    -webkit-tap-highlight-color: transparent;
}

.logo-dropdown:hover {
    background: var(--bg-tertiary);
}

.logo-text {
    font-size: 18px;
    font-weight: 600;
    color: var(--text-primary);
    flex: 1;
}

.model-badge {
    font-size: 11px;
    color: var(--text-secondary);
    background: var(--bg-tertiary);
    padding: 2px 8px;
    border-radius: 4px;
    margin-left: 8px;
    font-weight: 500;
}

.chevron {
    width: 16px;
    height: 16px;
    color: var(--text-secondary);
    transition: transform 0.2s ease;
    margin-left: 8px;
}

.chevron.open {
    transform: rotate(180deg);
}

.model-dropdown {
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    background: var(--bg-tertiary);
    border-radius: 12px;
    margin-top: 8px;
    padding: 8px;
    max-height: 400px;
    overflow-y: auto;
    z-index: 2000;
    box-shadow: 0 8px 24px var(--shadow-color);
    display: none;
}

.model-dropdown.show {
    display: block;
    animation: slideDown 0.25s cubic-bezier(0.32, 0.72, 0, 1);
}

@keyframes slideDown {
    from {
        opacity: 0;
        transform: translateY(-8px) scale(0.98);
    }

    to {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

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

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

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

.model-section-title {
    font-size: 11px;
    font-weight: 600;
    color: var(--text-secondary);
    padding: 8px 12px 4px 12px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.model-item {
    padding: 10px 12px;
    border-radius: 8px;
    cursor: pointer;
    transition: background 0.2s ease;
    display: flex;
    align-items: center;
    justify-content: space-between;
    -webkit-tap-highlight-color: transparent;
}

.model-item:hover {
    background: var(--bg-interactive);
}

.model-item.selected {
    background: var(--bg-interactive);
}

.model-info {
    flex: 1;
}

.model-name {
    font-size: 14px;
    color: var(--text-primary);
    margin-bottom: 2px;
}

.model-description {
    font-size: 12px;
    color: var(--text-secondary);
}

.model-check {
    width: 18px;
    height: 18px;
    color: var(--accent-primary);
    display: none;
}

.model-item.selected .model-check {
    display: block;
}

.sidebar-nav {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 4px;
    overflow-y: auto;
}

.sidebar-nav::-webkit-scrollbar {
    width: 6px;
}

.sidebar-nav::-webkit-scrollbar-track {
    background: transparent;
}

.sidebar-nav::-webkit-scrollbar-thumb {
    background: var(--bg-interactive-hover);
    border-radius: 3px;
}

.nav-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px;
    color: var(--text-secondary);
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.2s ease;
    font-size: 14px;
    position: relative;
    -webkit-tap-highlight-color: transparent;
}

.nav-item:hover {
    background: var(--bg-tertiary);
    color: var(--text-primary);
}

.nav-item.active {
    background: var(--bg-tertiary);
    color: var(--text-primary);
}

.nav-item svg {
    width: 20px;
    height: 20px;
    flex-shrink: 0;
}

.nav-item-text {
    flex: 1;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.delete-chat-btn {
    width: 24px;
    height: 24px;
    border: none;
    background: transparent;
    color: var(--text-secondary);
    border-radius: 4px;
    cursor: pointer;
    display: none;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
    padding: 0;
    -webkit-tap-highlight-color: transparent;
}

.nav-item:hover .delete-chat-btn {
    display: flex;
}

.delete-chat-btn:hover {
    background: var(--bg-interactive);
    color: var(--accent-error);
}

.sidebar-section-title {
    font-size: 12px;
    color: var(--text-secondary);
    padding: 12px;
    font-weight: 600;
}

.sidebar-footer {
    padding: 8px;
    display: flex;
    align-items: center;
    gap: 12px;
    cursor: pointer;
    border-radius: 8px;
    transition: background 0.2s ease;
    border-top: 1px solid var(--border-primary);
    margin-top: 8px;
    padding-top: 12px;
    position: relative;
    -webkit-tap-highlight-color: transparent;
}

.sidebar-footer:hover {
    background: var(--bg-tertiary);
}

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

.user-name {
    flex: 1;
    font-size: 14px;
    color: var(--text-primary);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.more-options {
    color: var(--text-secondary);
    flex-shrink: 0;
}

.user-menu {
    position: absolute;
    bottom: 100%;
    left: 8px;
    right: 8px;
    background: var(--bg-tertiary);
    border-radius: 12px;
    padding: 8px;
    margin-bottom: 8px;
    box-shadow: 0 8px 24px var(--shadow-color);
    display: none;
    animation: slideUp 0.2s cubic-bezier(0.4, 0, 0.2, 1);
    z-index: 2001;
}

.user-menu.show {
    display: block;
}

@keyframes slideUp {
    from {
        opacity: 0;
        transform: translateY(8px) scale(0.98);
    }

    to {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

.user-menu-item {
    padding: 10px 12px;
    border-radius: 8px;
    cursor: pointer;
    transition: background 0.2s ease;
    display: flex;
    align-items: center;
    gap: 12px;
    color: var(--text-primary);
    font-size: 14px;
    -webkit-tap-highlight-color: transparent;
}

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

.user-menu-item svg {
    width: 18px;
    height: 18px;
    color: var(--text-secondary);
}

.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: var(--overlay-color);
    z-index: 3000;
    display: none;
    align-items: center;
    justify-content: center;
    animation: fadeIn 0.2s ease;
    padding: 20px;
}

.modal-overlay.show {
    display: flex;
}

@keyframes fadeIn {
    from {
        opacity: 0;
    }

    to {
        opacity: 1;
    }
}

.modal {
    background: var(--bg-tertiary);
    border-radius: 16px;
    padding: 24px;
    max-width: 400px;
    width: 100%;
    box-shadow: 0 16px 48px var(--shadow-color-heavy);
    animation: modalIn 0.3s cubic-bezier(0.32, 0.72, 0, 1);
}

@keyframes modalIn {
    from {
        opacity: 0;
        transform: scale(0.95) translateY(8px);
    }

    to {
        opacity: 1;
        transform: scale(1) translateY(0);
    }
}

.modal-title {
    font-size: 18px;
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: 16px;
}

.modal-input {
    width: 100%;
    padding: 12px;
    background: var(--bg-secondary);
    border: 1px solid var(--border-interactive);
    border-radius: 8px;
    color: var(--text-primary);
    font-size: 16px;
    font-family: inherit;
    outline: none;
    transition: border-color 0.2s ease;
}

.modal-input:focus {
    border-color: var(--accent-primary);
}

.modal-buttons {
    display: flex;
    gap: 8px;
    margin-top: 16px;
    justify-content: flex-end;
}

.modal-btn {
    padding: 10px 20px;
    border-radius: 8px;
    border: none;
    cursor: pointer;
    font-size: 14px;
    font-weight: 500;
    transition: all 0.2s ease;
    -webkit-tap-highlight-color: transparent;
    min-height: 44px;
}

.modal-btn.cancel {
    background: transparent;
    color: var(--text-secondary);
}

.modal-btn.cancel:hover {
    background: var(--bg-interactive);
}

.modal-btn.save {
    background: var(--accent-primary);
    color: var(--text-white);
}

.modal-btn.save:hover {
    background: var(--accent-primary-hover);
}

.sidebar-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: var(--overlay-color);
    z-index: 999;
    display: none;
    opacity: 0;
    transition: opacity 0.3s ease;
}

.sidebar-overlay.show {
    display: block;
    opacity: 1;
}

.main-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    position: relative;
    margin-left: 0;
    transition: margin-left 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    width: 100%;
    overflow: hidden;
}

.main-content.sidebar-open {
    margin-left: 260px;
}

.chat-header {
    padding: 12px 20px;
    display: flex;
    align-items: center;
    gap: 12px;
    border-bottom: 1px solid var(--border-primary);
    background: var(--bg-primary);
    z-index: 10;
}

.sidebar-toggle {
    width: 36px;
    height: 36px;
    min-width: 36px;
    border: none;
    background: transparent;
    color: var(--text-secondary);
    border-radius: 8px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
    -webkit-tap-highlight-color: transparent;
}

.sidebar-toggle:hover {
    background: var(--bg-tertiary);
    color: var(--text-primary);
}

.header-new-chat {
    width: 36px;
    height: 36px;
    min-width: 36px;
    border: none;
    background: transparent;
    color: var(--text-secondary);
    border-radius: 8px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
    -webkit-tap-highlight-color: transparent;
}

.header-new-chat:hover {
    background: var(--bg-tertiary);
    color: var(--text-primary);
}

.header-model-selector {
    position: relative;
}

.header-model-btn {
    padding: 8px 16px;
    border: 1px solid var(--border-primary);
    background: var(--bg-secondary);
    color: var(--text-primary);
    border-radius: 8px;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 14px;
    transition: all 0.2s ease;
    max-width: 200px;
    -webkit-tap-highlight-color: transparent;
}

.header-model-btn:hover {
    background: var(--bg-tertiary);
}

.header-model-name {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.header-model-dropdown {
    position: absolute;
    top: calc(100% + 8px);
    left: 0;
    background: var(--bg-tertiary);
    border-radius: 12px;
    padding: 8px;
    max-height: 400px;
    overflow-y: auto;
    z-index: 2000;
    box-shadow: 0 8px 24px var(--shadow-color);
    display: none;
    min-width: 300px;
}

.header-model-dropdown.show {
    display: block;
    animation: slideDown 0.2s cubic-bezier(0.4, 0, 0.2, 1);
}

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

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

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

.chat-area {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    display: flex;
    flex-direction: column;
    position: relative;
    -webkit-overflow-scrolling: touch;
    scroll-behavior: auto;
}

.chat-area::-webkit-scrollbar {
    width: 8px;
}

.chat-area::-webkit-scrollbar-track {
    background: transparent;
}

.chat-area::-webkit-scrollbar-thumb {
    background: var(--bg-interactive);
    border-radius: 4px;
    transition: background 0.2s ease;
}

.chat-area::-webkit-scrollbar-thumb:hover {
    background: var(--bg-interactive-hover);
}

.welcome-state {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 40px 20px 180px 20px;
    animation: welcomeFadeIn 0.5s cubic-bezier(0.32, 0.72, 0, 1);
    min-height: 100%;
}

@keyframes welcomeFadeIn {
    from {
        opacity: 0;
        transform: translateY(12px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.welcome-heading {
    font-size: 36px;
    font-weight: 400;
    color: var(--text-primary);
    margin-bottom: 48px;
    text-align: center;
    width: 100%;
    display: flex;
    justify-content: center;
    align-items: center;
}

.suggestion-grid {
    display: none;
    grid-template-columns: repeat(2, 1fr);
    gap: 12px;
    max-width: 800px;
    width: 100%;
}

.suggestion-card {
    background: var(--bg-tertiary);
    padding: 16px;
    border-radius: 16px;
    cursor: pointer;
    transition: transform 0.2s cubic-bezier(0.32, 0.72, 0, 1), background 0.2s ease, box-shadow 0.2s ease;
    border: 1px solid var(--border-primary);
    -webkit-tap-highlight-color: transparent;
}

.suggestion-card:active {
    transform: scale(0.98);
}

.suggestion-card:hover {
    background: var(--bg-tertiary-hover);
    transform: translateY(-3px);
    box-shadow: 0 8px 24px var(--shadow-color-light);
}

.suggestion-card p {
    font-size: 14px;
    line-height: 1.5;
    color: var(--text-secondary);
}

.messages-container {
    flex: 1;
    padding: 40px 20px 20px 20px;
    max-width: 900px;
    margin: 0 auto;
    width: 100%;
}

.message-group {
    margin-bottom: 40px;
    animation: messageSlideIn 0.35s cubic-bezier(0.32, 0.72, 0, 1);
}

@keyframes messageSlideIn {
    from {
        opacity: 0;
        transform: translateY(16px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.message-group.user {
    display: flex;
    justify-content: flex-end;
    gap: 12px;
}

.user-message-bubble {
    background: var(--bg-user-message);
    padding: 12px 16px;
    border-radius: 24px;
    max-width: 70%;
    position: relative;
}

.user-message-text {
    font-size: 15px;
    line-height: 1.5;
    color: var(--text-primary);
    word-wrap: break-word;
}

.message-actions {
    display: flex;
    flex-direction: column;
    gap: 4px;
    opacity: 0;
    transition: opacity 0.2s ease;
}

.message-group.user:hover .message-actions {
    opacity: 1;
}

.message-action-btn {
    width: 28px;
    height: 28px;
    min-width: 28px;
    min-height: 28px;
    border: none;
    background: transparent;
    color: var(--text-secondary);
    border-radius: 6px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
    -webkit-tap-highlight-color: transparent;
}

.message-action-btn:hover {
    background: var(--bg-tertiary);
    color: var(--text-primary);
}

.message-group.assistant {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
}

.assistant-message-content {
    max-width: 100%;
    width: 100%;
}

.thinking-section {
    background: var(--bg-tertiary);
    border-radius: 12px;
    margin-bottom: 16px;
    overflow: hidden;
    border: 1px solid var(--border-primary);
}

.thinking-header {
    padding: 12px 16px;
    display: flex;
    align-items: center;
    gap: 8px;
    cursor: pointer;
    transition: background 0.2s ease;
    -webkit-tap-highlight-color: transparent;
}

.thinking-header:hover {
    background: var(--bg-tertiary-hover);
}

.thinking-icon,
.thinking-toggle {
    width: 16px;
    height: 16px;
    color: var(--text-secondary);
}

.thinking-label {
    flex: 1;
    font-size: 13px;
    color: var(--text-secondary);
    font-weight: 500;
}

.thinking-toggle {
    transition: transform 0.2s ease;
}

.thinking-toggle.expanded {
    transform: rotate(180deg);
}

.thinking-content {
    font-size: 14px;
    line-height: 1.6;
    color: var(--text-secondary);
    display: grid;
    grid-template-rows: 0fr;
    transition: grid-template-rows 0.3s cubic-bezier(0.32, 0.72, 0, 1), padding 0.3s cubic-bezier(0.32, 0.72, 0, 1);
    padding: 0 16px;
}

.thinking-content>* {
    overflow: hidden;
}

.thinking-content.show {
    grid-template-rows: 1fr;
    padding: 0 16px 16px 16px;
}

.thinking-spinner {
    display: inline-flex;
    gap: 4px;
    align-items: center;
}

.thinking-spinner span {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: var(--text-secondary);
    animation: thinkingPulse 1.4s infinite ease-in-out;
}

.thinking-spinner span:nth-child(2) {
    animation-delay: 0.2s;
}

.thinking-spinner span:nth-child(3) {
    animation-delay: 0.4s;
}

@keyframes thinkingPulse {

    0%,
    60%,
    100% {
        opacity: 0.3;
        transform: scale(1);
    }

    30% {
        opacity: 1;
        transform: scale(1.2);
    }
}

.assistant-message-text {
    font-size: 15px;
    line-height: 1.7;
    color: var(--text-primary);
    word-wrap: break-word;
    overflow-wrap: break-word;
}

.assistant-message-text p {
    margin-bottom: 16px;
}

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

.assistant-message-text h1,
.assistant-message-text h2,
.assistant-message-text h3,
.assistant-message-text h4 {
    margin-top: 24px;
    margin-bottom: 12px;
    font-weight: 600;
    line-height: 1.3;
}

.assistant-message-text h1 {
    font-size: 28px;
}

.assistant-message-text h2 {
    font-size: 24px;
}

.assistant-message-text h3 {
    font-size: 20px;
}

.assistant-message-text h4 {
    font-size: 16px;
}

.assistant-message-text ul,
.assistant-message-text ol {
    margin: 12px 0;
    padding-left: 24px;
}

.assistant-message-text li {
    margin: 8px 0;
    line-height: 1.6;
}

.assistant-message-text blockquote {
    margin: 16px 0;
    padding: 12px 20px;
    border-left: 4px solid var(--border-interactive);
    background: var(--bg-tertiary);
    border-radius: 4px;
}

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

.code-block-wrapper {
    margin: 16px 0;
    border-radius: 8px;
    overflow: hidden;
    background: var(--bg-code);
    border: 1px solid var(--border-code);
}

.code-block-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 8px 16px;
    background: var(--bg-tertiary);
    border-bottom: 1px solid var(--border-code);
}

.code-language {
    font-size: 12px;
    color: var(--text-secondary);
    text-transform: uppercase;
    font-weight: 600;
    letter-spacing: 0.5px;
}

.code-copy-btn {
    padding: 6px 12px;
    background: transparent;
    border: 1px solid var(--border-interactive);
    color: var(--text-secondary);
    border-radius: 4px;
    cursor: pointer;
    font-size: 12px;
    display: flex;
    align-items: center;
    gap: 6px;
    transition: all 0.2s ease;
    -webkit-tap-highlight-color: transparent;
    min-height: 32px;
}

.code-copy-btn:hover {
    background: var(--bg-interactive);
    color: var(--text-primary);
    border-color: var(--bg-interactive-hover);
}

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

.assistant-message-text pre {
    margin: 0;
    padding: 16px;
    background: var(--bg-code);
    overflow-x: auto;
    font-family: 'SF Mono', 'Monaco', 'Inconsolata', 'Roboto Mono', 'Courier New', monospace;
    font-size: 14px;
    line-height: 1.6;
    -webkit-overflow-scrolling: touch;
}

.assistant-message-text pre code {
    background: transparent;
    padding: 0;
    border-radius: 0;
    font-family: inherit;
    display: block;
}

.assistant-message-text code {
    background: var(--bg-interactive);
    padding: 3px 6px;
    border-radius: 4px;
    font-family: 'SF Mono', 'Monaco', 'Inconsolata', 'Roboto Mono', 'Courier New', monospace;
    font-size: 13px;
    color: var(--text-code);
}

.hljs {
    background: var(--bg-code);
    color: #abb2bf;
}

.light-theme .hljs {
    color: #383a42;
}

.assistant-actions {
    display: flex;
    gap: 8px;
    margin-top: 12px;
    opacity: 1;
    transition: opacity 0.2s ease;
    flex-wrap: wrap;
}

.assistant-action-btn {
    padding: 8px 14px;
    border: none;
    background: var(--bg-tertiary);
    color: var(--text-secondary);
    border-radius: 6px;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 13px;
    transition: all 0.2s ease;
    -webkit-tap-highlight-color: transparent;
    min-height: 36px;
}

.assistant-action-btn:hover {
    background: var(--bg-tertiary-hover);
    color: var(--text-primary);
}

.assistant-action-btn svg {
    width: 14px;
    height: 14px;
}

.typing-indicator {
    display: inline-flex;
    gap: 5px;
    align-items: center;
    padding: 12px 0;
}

.typing-indicator span {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--text-tertiary);
    animation: typingBounce 1.2s infinite ease-in-out;
}

.typing-indicator span:nth-child(2) {
    animation-delay: 0.15s;
}

.typing-indicator span:nth-child(3) {
    animation-delay: 0.3s;
}

@keyframes typingBounce {

    0%,
    80%,
    100% {
        transform: translateY(0);
        opacity: 0.4;
    }

    40% {
        transform: translateY(-8px);
        opacity: 1;
    }
}

.bottom-controls {
    position: fixed;
    bottom: 140px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 100;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 12px;
    pointer-events: none;
}

@keyframes fadeInUp {
    from {
        opacity: 0;
        transform: translateY(10px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.stop-generating {
    padding: 10px 20px;
    border-radius: 24px;
    background: var(--bg-tertiary-hover);
    border: 1px solid var(--border-interactive);
    color: var(--text-primary);
    cursor: pointer;
    display: none;
    align-items: center;
    gap: 8px;
    box-shadow: 0 4px 12px var(--shadow-color-light);
    transition: all 0.2s ease;
    font-size: 14px;
    -webkit-tap-highlight-color: transparent;
    min-height: 44px;
    pointer-events: auto;
}

.stop-generating.show {
    display: flex;
    animation: fadeInUp 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.stop-generating:active {
    transform: scale(0.98);
}

.stop-generating:hover {
    background: var(--bg-interactive);
}

.stop-generating svg {
    width: 16px;
    height: 16px;
}

.scroll-to-bottom {
    width: 44px;
    height: 44px;
    min-width: 44px;
    min-height: 44px;
    border-radius: 50%;
    background: var(--bg-tertiary-hover);
    border: 1px solid var(--border-interactive);
    color: var(--text-primary);
    cursor: pointer;
    display: none;
    align-items: center;
    justify-content: center;
    box-shadow: 0 4px 16px var(--shadow-color-light);
    transition: transform 0.2s cubic-bezier(0.32, 0.72, 0, 1), background 0.2s ease, box-shadow 0.2s ease;
    -webkit-tap-highlight-color: transparent;
    pointer-events: auto;
}

.scroll-to-bottom.show {
    display: flex;
    animation: scrollBtnIn 0.3s cubic-bezier(0.32, 0.72, 0, 1);
}

@keyframes scrollBtnIn {
    from {
        opacity: 0;
        transform: translateY(12px) scale(0.9);
    }

    to {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

.scroll-to-bottom:active {
    transform: scale(0.92);
}

.scroll-to-bottom:hover {
    background: var(--bg-interactive);
    box-shadow: 0 6px 20px var(--shadow-color);
}

.input-area {
    padding: 20px;
    display: flex;
    justify-content: center;
    background: var(--bg-primary);
    padding-bottom: max(20px, env(safe-area-inset-bottom));
}

.input-container {
    width: 100%;
    max-width: 800px;
    position: relative;
}

.input-wrapper {
    background: var(--bg-tertiary);
    border: 1px solid var(--border-primary);
    border-radius: 28px;
    display: flex;
    align-items: flex-end;
    padding: 12px 12px 12px 20px;
    gap: 12px;
    transition: background 0.2s ease, box-shadow 0.2s ease;
}

.input-wrapper:focus-within {
    background: var(--bg-tertiary);
    box-shadow: 0 0 0 2px var(--border-interactive);
}

.message-input {
    flex: 1;
    background: transparent;
    border: none;
    outline: none;
    color: var(--text-primary);
    font-size: 16px;
    font-family: inherit;
    resize: none;
    max-height: 200px;
    line-height: 24px;
    padding: 6px 0;
}

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

.send-button {
    width: 36px;
    height: 36px;
    min-width: 36px;
    min-height: 36px;
    border-radius: 50%;
    border: none;
    background: var(--send-btn-bg);
    color: var(--send-btn-color);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
    flex-shrink: 0;
    -webkit-tap-highlight-color: transparent;
}

.send-button:active {
    transform: scale(0.95);
}

.send-button:hover:not(:disabled) {
    background: var(--send-btn-bg-hover);
}

.send-button.active {
    background: var(--send-btn-bg-active);
    color: var(--send-btn-color-active);
}

.send-button.active:hover {
    opacity: 0.9;
}

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

.toast {
    position: fixed;
    top: 20px;
    right: 20px;
    padding: 16px 20px;
    border-radius: 12px;
    box-shadow: 0 4px 12px var(--shadow-color-light);
    animation: slideInRight 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    z-index: 4000;
    max-width: 400px;
    display: flex;
    align-items: center;
    gap: 12px;
}

.toast.error {
    background: var(--accent-error);
    color: #fff;
}

.toast.success {
    background: #10a37f;
    color: #fff;
}

.toast.warning {
    background: #f59e0b;
    color: #fff;
}

@keyframes slideInRight {
    from {
        transform: translateX(100%);
        opacity: 0;
    }

    to {
        transform: translateX(0);
        opacity: 1;
    }
}

@media (max-width: 768px) {
    body {
        overscroll-behavior-y: none;
    }

    .sidebar {
        width: 280px;
        max-width: 85vw;
        box-shadow: 2px 0 12px var(--shadow-color);
    }

    .main-content.sidebar-open {
        margin-left: 0;
    }

    .chat-header {
        padding: 10px 16px;
        position: sticky;
        top: 0;
        backdrop-filter: blur(10px);
        background: color-mix(in srgb, var(--bg-primary) 90%, transparent);
    }

    .header-model-selector {
        display: none !important;
    }

    .welcome-heading {
        font-size: 24px;
        margin-bottom: 32px;
    }

    .suggestion-grid {
        grid-template-columns: 1fr;
        gap: 10px;
    }

    .suggestion-card {
        padding: 14px;
    }

    .suggestion-card:hover {
        transform: none;
    }

    .messages-container {
        padding: 24px 16px 16px 16px;
    }

    .message-group {
        margin-bottom: 32px;
    }

    .user-message-bubble {
        max-width: 85%;
        padding: 10px 14px;
        border-radius: 20px;
    }

    .user-message-text,
    .assistant-message-text {
        font-size: 15px;
    }

    .message-actions {
        opacity: 1;
    }

    .message-action-btn {
        width: 32px;
        height: 32px;
        min-width: 32px;
        min-height: 32px;
    }

    .assistant-message-text h1 {
        font-size: 24px;
    }

    .assistant-message-text h2 {
        font-size: 20px;
    }

    .assistant-message-text h3 {
        font-size: 18px;
    }

    .code-block-header {
        padding: 8px 12px;
    }

    .code-copy-btn {
        font-size: 11px;
        padding: 6px 10px;
    }

    .assistant-message-text pre {
        padding: 12px;
        font-size: 13px;
    }

    .assistant-actions {
        opacity: 1;
    }

    .assistant-action-btn {
        padding: 8px 12px;
        min-height: 40px;
        font-size: 13px;
    }

    .input-area {
        padding: 16px;
        padding-bottom: max(16px, env(safe-area-inset-bottom));
    }

    .input-wrapper {
        border-radius: 24px;
        padding: 10px 10px 10px 16px;
    }

    .message-input {
        font-size: 16px;
        line-height: 22px;
    }

    .send-button {
        width: 38px;
        height: 38px;
        min-width: 38px;
        min-height: 38px;
    }

    .bottom-controls {
        bottom: 120px;
    }

    .stop-generating {
        min-height: 48px;
        padding: 12px 24px;
        font-size: 15px;
    }

    .scroll-to-bottom {
        width: 48px;
        height: 48px;
        min-width: 48px;
        min-height: 48px;
    }

    .modal-overlay {
        padding: 16px;
        align-items: flex-end;
    }

    .modal {
        padding: 20px;
        border-bottom-left-radius: 0;
        border-bottom-right-radius: 0;
        margin-bottom: -16px;
        animation: slideInUp 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    }

    @keyframes slideInUp {
        from {
            transform: translateY(100%);
        }

        to {
            transform: translateY(0);
        }
    }

    .modal-input {
        font-size: 16px;
        padding: 14px;
    }

    .modal-btn {
        padding: 12px 24px;
        font-size: 15px;
    }

    .toast {
        top: auto;
        bottom: 20px;
        left: 16px;
        right: 16px;
        max-width: none;
        animation: slideInUp 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    }

    .nav-item {
        padding: 14px 12px;
        min-height: 48px;
    }

    .delete-chat-btn {
        display: flex;
        width: 32px;
        height: 32px;
        min-width: 32px;
        min-height: 32px;
    }

    .sidebar-toggle,
    .header-new-chat {
        width: 40px;
        height: 40px;
        min-width: 40px;
        min-height: 40px;
    }

    .thinking-header {
        padding: 14px 16px;
        min-height: 48px;
    }

    .chat-area {
        overscroll-behavior: contain;
    }

    .app-container {
        height: 100vh;
        height: 100dvh;
    }

    .chat-area::-webkit-scrollbar,
    .sidebar-nav::-webkit-scrollbar,
    .model-dropdown::-webkit-scrollbar {
        display: none;
    }

    .header-model-dropdown {
        position: fixed;
        top: auto;
        bottom: 0;
        left: 0;
        right: 0;
        max-height: 70vh;
        border-radius: 20px 20px 0 0;
        padding: 12px 8px;
        margin: 0;
    }

    .header-model-dropdown.show {
        animation: slideInUp 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    }
}

@media (max-width: 400px) {
    .welcome-heading {
        font-size: 20px;
    }

    .user-message-bubble {
        max-width: 90%;
    }

    .input-area {
        padding: 12px;
        padding-bottom: max(12px, env(safe-area-inset-bottom));
    }

    .messages-container {
        padding: 20px 12px 12px 12px;
    }
}

@media (max-width: 768px) and (orientation: landscape) {
    .welcome-state {
        padding: 20px 20px 140px 20px;
    }

    .welcome-heading {
        font-size: 20px;
        margin-bottom: 24px;
    }

    .suggestion-grid {
        grid-template-columns: repeat(2, 1fr);
    }
}

@media (min-width: 769px) and (max-width: 1024px) {
    .sidebar {
        width: 280px;
    }

    .main-content.sidebar-open {
        margin-left: 280px;
    }

    .suggestion-grid {
        grid-template-columns: repeat(2, 1fr);
        max-width: 700px;
    }
}

@supports (padding: max(0px)) {
    .chat-header {
        padding-left: max(20px, env(safe-area-inset-left));
        padding-right: max(20px, env(safe-area-inset-right));
        padding-top: max(12px, env(safe-area-inset-top));
    }

    .sidebar {
        padding-top: max(12px, env(safe-area-inset-top));
        padding-bottom: max(12px, env(safe-area-inset-bottom));
        padding-left: max(12px, env(safe-area-inset-left));
    }
}