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

:root {
    --bg: #f7f7f8;
    --sidebar-bg: #1e1e2e;
    --sidebar-text: #cdd6f4;
    --sidebar-hover: #313244;
    --sidebar-active: #45475a;
    --msg-user-bg: #2563eb;
    --msg-user-text: #fff;
    --msg-ai-bg: #fff;
    --msg-ai-text: #1e1e2e;
    --input-bg: #fff;
    --input-border: #e0e0e0;
    --primary: #2563eb;
    --text: #1e1e2e;
    --text-secondary: #6b7280;
    --border-radius: 12px;
}

html, body {
    height: 100%;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    background: var(--bg);
    color: var(--text);
}

.app {
    display: flex;
    height: 100%;
    overflow: hidden;
}

/* Sidebar */
.sidebar {
    width: 260px;
    background: var(--sidebar-bg);
    color: var(--sidebar-text);
    display: flex;
    flex-direction: column;
    flex-shrink: 0;
    transition: transform 0.3s;
}

.sidebar-header {
    padding: 16px;
    border-bottom: 1px solid var(--sidebar-hover);
}

.sidebar-header h2 {
    font-size: 16px;
    margin-bottom: 12px;
    font-weight: 600;
}

.new-chat-btn {
    width: 100%;
    padding: 10px;
    border: 1px solid var(--sidebar-hover);
    border-radius: 8px;
    background: transparent;
    color: var(--sidebar-text);
    cursor: pointer;
    font-size: 14px;
    transition: background 0.2s;
}

.new-chat-btn:hover {
    background: var(--sidebar-hover);
}

.conversation-list {
    flex: 1;
    overflow-y: auto;
    padding: 8px;
}

.conv-item {
    padding: 10px 12px;
    border-radius: 8px;
    cursor: pointer;
    font-size: 13px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    transition: background 0.2s;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.conv-item:hover {
    background: var(--sidebar-hover);
}

.conv-item.active {
    background: var(--sidebar-active);
}

.conv-item .conv-id {
    font-size: 11px;
    color: #888;
    margin-right: 6px;
    flex-shrink: 0;
}

.conv-item .conv-title {
    overflow: hidden;
    text-overflow: ellipsis;
    flex: 1;
}

.conv-item .delete-btn {
    display: none;
    background: none;
    border: none;
    color: var(--sidebar-text);
    cursor: pointer;
    font-size: 16px;
    padding: 0 4px;
    opacity: 0.6;
}

.conv-item:hover .delete-btn {
    display: block;
}

.conv-item .delete-btn:hover {
    opacity: 1;
}

/* Main */
.main {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-width: 0;
}

.main-header {
    padding: 12px 16px;
    border-bottom: 1px solid var(--input-border);
    display: flex;
    align-items: center;
    gap: 12px;
    background: #fff;
}

.menu-btn {
    display: none;
    background: none;
    border: none;
    font-size: 20px;
    cursor: pointer;
    color: var(--text);
}

.gi-badge {
    font-size: 11px;
    color: #10b981;
    background: #ecfdf5;
    padding: 3px 8px;
    border-radius: 6px;
    border: 1px solid #a7f3d0;
    font-weight: 500;
}

/* Provider toggle */
.provider-toggle {
    display: flex;
    align-items: center;
    gap: 6px;
    margin-left: 4px;
}

.toggle-label {
    font-size: 11px;
    color: var(--text-secondary);
    cursor: pointer;
    transition: color 0.2s;
    user-select: none;
}

.toggle-label.active {
    color: var(--text);
    font-weight: 600;
}

.toggle-switch {
    width: 36px;
    height: 20px;
    background: #10b981;
    border-radius: 10px;
    cursor: pointer;
    position: relative;
    transition: background 0.3s;
}

.toggle-switch.claude {
    background: #c084fc;
}

.toggle-knob {
    width: 16px;
    height: 16px;
    background: #fff;
    border-radius: 50%;
    position: absolute;
    top: 2px;
    right: 2px;
    transition: right 0.3s, left 0.3s;
    box-shadow: 0 1px 3px rgba(0,0,0,0.2);
}

.toggle-switch.claude .toggle-knob {
    right: auto;
    left: 2px;
}

/* Pinned sidebar items */
.conv-item.pinned-item {
    font-weight: 500;
}

.conv-item .conv-icon {
    flex-shrink: 0;
    display: flex;
    align-items: center;
    margin-right: 6px;
    color: #a3a3a3;
}

.conv-item.pinned-item .conv-icon {
    color: #10b981;
}

.demo-label {
    font-size: 10px;
    color: #10b981;
    background: rgba(16,185,129,0.1);
    padding: 1px 5px;
    border-radius: 4px;
    margin-right: 4px;
    white-space: nowrap;
}

.conv-item .pin-btn {
    display: none;
    background: none;
    border: none;
    cursor: pointer;
    padding: 0 2px;
    color: #a3a3a3;
    flex-shrink: 0;
    line-height: 0;
    transition: color 0.2s;
}

.conv-item:hover .pin-btn {
    display: flex;
    align-items: center;
}

.conv-item .pin-btn:hover {
    color: #10b981;
}

.conv-item .pin-btn.pinned {
    color: #10b981;
}

.icon-pin, .icon-demo {
    display: block;
}

.sidebar-separator {
    height: 1px;
    background: var(--sidebar-hover);
    margin: 4px 8px;
}

.rename-input {
    flex: 1;
    min-width: 0;
    background: var(--sidebar-hover);
    border: 1px solid #6366f1;
    border-radius: 4px;
    color: var(--sidebar-text);
    font-size: 13px;
    padding: 2px 6px;
    outline: none;
}

.disclaimer {
    font-size: 11px;
    color: var(--text-secondary);
    margin-left: auto;
}

/* Messages */
.messages {
    flex: 1;
    overflow-y: auto;
    padding: 24px 16px;
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.welcome {
    text-align: center;
    margin: auto;
    color: var(--text-secondary);
}

.welcome h1 {
    font-size: 28px;
    margin-bottom: 8px;
    color: var(--text);
}

.message {
    display: flex;
    gap: 12px;
    max-width: 800px;
    width: 100%;
    margin: 0 auto;
}

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

.message .avatar {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 14px;
    flex-shrink: 0;
}

.message.user .avatar {
    background: var(--msg-user-bg);
    color: #fff;
}

.message.assistant .avatar {
    background: #10b981;
    color: #fff;
}

.message .bubble {
    padding: 12px 16px;
    border-radius: var(--border-radius);
    max-width: 75%;
    line-height: 1.6;
    font-size: 14px;
    word-wrap: break-word;
}

.message.user .bubble {
    background: var(--msg-user-bg);
    color: var(--msg-user-text);
    border-bottom-right-radius: 4px;
}

.message.assistant .bubble {
    background: var(--msg-ai-bg);
    color: var(--msg-ai-text);
    border-bottom-left-radius: 4px;
    box-shadow: 0 1px 3px rgba(0,0,0,0.08);
}

.message .bubble img {
    max-width: 100%;
    border-radius: 8px;
    margin-top: 8px;
}

/* Thinking collapsible */
.thinking-block {
    margin-bottom: 8px;
    border: 1px solid var(--input-border);
    border-radius: 8px;
    overflow: hidden;
}

.thinking-header {
    padding: 6px 12px;
    background: var(--bg);
    cursor: pointer;
    font-size: 12px;
    color: var(--text-secondary);
    display: flex;
    align-items: center;
    gap: 6px;
    user-select: none;
}

.thinking-header::before {
    content: '\25B6';
    font-size: 10px;
    transition: transform 0.2s;
}

.thinking-block.open .thinking-header::before {
    transform: rotate(90deg);
}

.thinking-content {
    display: none;
    padding: 8px 12px;
    font-size: 13px;
    color: var(--text-secondary);
    border-top: 1px solid var(--input-border);
    white-space: pre-wrap;
}

.thinking-block.open .thinking-content {
    display: block;
}

/* Streaming cursor */
.streaming-cursor::after {
    content: '\2588';
    animation: blink 1s infinite;
    color: var(--text-secondary);
}

@keyframes blink {
    0%, 50% { opacity: 1; }
    51%, 100% { opacity: 0; }
}

/* Markdown in messages */
.bubble h1, .bubble h2, .bubble h3 { margin: 8px 0 4px; }
.bubble p { margin: 4px 0; }
.bubble ul, .bubble ol { padding-left: 20px; margin: 4px 0; }
.bubble code {
    background: #f1f5f9;
    padding: 2px 5px;
    border-radius: 4px;
    font-size: 13px;
}
.bubble pre {
    background: #1e293b;
    color: #e2e8f0;
    padding: 12px;
    border-radius: 8px;
    overflow-x: auto;
    margin: 8px 0;
}
.bubble pre code {
    background: none;
    padding: 0;
    color: inherit;
    font-size: 13px;
}
.bubble blockquote {
    border-left: 3px solid var(--primary);
    padding-left: 12px;
    color: var(--text-secondary);
    margin: 8px 0;
}

/* Input area */
.input-area {
    padding: 12px 16px 20px;
    border-top: 1px solid var(--input-border);
    background: #fff;
}

.image-preview {
    display: none;
    margin-bottom: 8px;
    position: relative;
    max-width: 800px;
    margin-left: auto;
    margin-right: auto;
}

.image-preview.active {
    display: inline-block;
}

.image-preview img {
    max-height: 80px;
    border-radius: 8px;
    border: 1px solid var(--input-border);
}

.remove-image {
    position: absolute;
    top: -6px;
    right: -6px;
    width: 20px;
    height: 20px;
    border-radius: 50%;
    background: #ef4444;
    color: #fff;
    border: none;
    cursor: pointer;
    font-size: 14px;
    line-height: 1;
    display: flex;
    align-items: center;
    justify-content: center;
}

.input-row {
    display: flex;
    align-items: flex-end;
    gap: 8px;
    max-width: 800px;
    margin: 0 auto;
    background: var(--input-bg);
    border: 1px solid var(--input-border);
    border-radius: 12px;
    padding: 8px 12px;
    transition: border-color 0.2s;
}

.input-row.streaming {
    border-color: var(--primary);
}

.input-row textarea {
    flex: 1;
    border: none;
    outline: none;
    resize: none;
    font-size: 14px;
    font-family: inherit;
    line-height: 1.5;
    max-height: 150px;
    background: transparent;
}

.attach-btn, .send-btn, .stop-btn {
    background: none;
    border: none;
    cursor: pointer;
    color: var(--text-secondary);
    padding: 4px;
    border-radius: 6px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: color 0.2s, background 0.2s;
}

.send-btn[hidden], .stop-btn[hidden] {
    display: none;
}

.attach-btn:hover {
    color: var(--primary);
    background: var(--bg);
}

.send-btn {
    color: var(--primary);
}

.send-btn:disabled {
    color: var(--input-border);
    cursor: default;
}

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

.stop-btn {
    color: #ef4444;
}

.stop-btn:hover {
    background: #fef2f2;
}

/* Streaming hint */
.streaming-hint {
    display: none;
    align-items: center;
    gap: 8px;
    max-width: 800px;
    margin: 6px auto 0;
    font-size: 12px;
    color: var(--text-secondary);
}

.streaming-hint.active {
    display: flex;
}

.dot-loader {
    display: inline-flex;
    gap: 3px;
}

.dot-loader::before,
.dot-loader::after {
    content: '';
    width: 5px;
    height: 5px;
    border-radius: 50%;
    background: var(--primary);
    animation: dotPulse 1.2s infinite;
}

.dot-loader::after {
    animation-delay: 0.4s;
}

@keyframes dotPulse {
    0%, 80%, 100% { opacity: 0.3; transform: scale(0.8); }
    40% { opacity: 1; transform: scale(1); }
}

/* Toast notification */
.toast {
    position: fixed;
    top: 20px;
    left: 50%;
    transform: translateX(-50%);
    background: #1e293b;
    color: #fff;
    padding: 10px 20px;
    border-radius: 8px;
    font-size: 14px;
    z-index: 300;
    box-shadow: 0 4px 12px rgba(0,0,0,0.2);
    animation: toastIn 0.3s ease, toastOut 0.3s ease 2.7s forwards;
}

@keyframes toastIn {
    from { opacity: 0; transform: translateX(-50%) translateY(-10px); }
    to { opacity: 1; transform: translateX(-50%) translateY(0); }
}

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

/* Mobile */
@media (max-width: 768px) {
    .sidebar {
        position: fixed;
        left: 0;
        top: 0;
        bottom: 0;
        z-index: 100;
        transform: translateX(-100%);
    }

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

    .menu-btn {
        display: block;
    }

    .message .bubble {
        max-width: 85%;
    }

    .modal-container {
        width: 95%;
        max-height: 90vh;
    }
}

/* Overlay for mobile sidebar */
.overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.4);
    z-index: 99;
}

.overlay.show {
    display: block;
}

/* Error message in bubble */
.error-msg {
    color: #ef4444;
    font-size: 14px;
    line-height: 1.5;
}

/* Retry button */
.retry-btn {
    display: inline-block;
    margin-top: 8px;
    padding: 4px 14px;
    border: 1px solid #ef4444;
    border-radius: 6px;
    background: transparent;
    color: #ef4444;
    font-size: 13px;
    cursor: pointer;
    transition: background 0.2s, color 0.2s;
}

.retry-btn:hover {
    background: #ef4444;
    color: #fff;
}

/* Tool-call searching status */
.tool-status {
    display: flex;
    align-items: center;
    gap: 8px;
    color: var(--text-secondary);
    font-size: 13px;
}

.dot-loader-sm {
    display: inline-flex;
    gap: 2px;
}

.dot-loader-sm::before,
.dot-loader-sm::after {
    content: '';
    width: 4px;
    height: 4px;
    border-radius: 50%;
    background: var(--primary);
    animation: dotPulse 1.2s infinite;
}

.dot-loader-sm::after {
    animation-delay: 0.4s;
}

/* Security warning modal */
.security-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: 500;
    align-items: center;
    justify-content: center;
}

.security-overlay.active {
    display: flex;
}

.security-modal {
    background: #fff;
    border-radius: 12px;
    padding: 28px 32px;
    max-width: 420px;
    width: 90%;
    text-align: center;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.2);
}

.security-modal .warn-icon {
    font-size: 40px;
    margin-bottom: 12px;
}

.security-modal h3 {
    color: #dc2626;
    margin-bottom: 8px;
    font-size: 18px;
}

.security-modal p {
    color: var(--text-secondary);
    font-size: 14px;
    line-height: 1.6;
    margin-bottom: 20px;
}

.security-modal .warn-count {
    color: #dc2626;
    font-weight: 600;
}

.security-modal .ack-btn {
    background: var(--primary);
    color: #fff;
    border: none;
    border-radius: 8px;
    padding: 10px 32px;
    font-size: 14px;
    cursor: pointer;
    transition: background 0.2s;
}

.security-modal .ack-btn:hover {
    background: #1d4ed8;
}

/* Ban overlay */
.ban-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.7);
    z-index: 600;
    align-items: center;
    justify-content: center;
}

.ban-overlay.active {
    display: flex;
}

.ban-modal {
    background: #fff;
    border-radius: 12px;
    padding: 32px;
    max-width: 400px;
    width: 90%;
    text-align: center;
}

.ban-modal h3 {
    color: #dc2626;
    margin-bottom: 12px;
}

.ban-modal p {
    color: var(--text-secondary);
    font-size: 14px;
    line-height: 1.6;
}
