/* AI Chat Web UI - ChatGPT-like dark theme */

:root {
    --bg-primary: #212121;
    --bg-secondary: #171717;
    --bg-sidebar: #171717;
    --bg-input: #2f2f2f;
    --bg-hover: #2f2f2f;
    --bg-active: #424242;
    --bg-user-msg: #2f2f2f;
    --bg-assistant-msg: transparent;
    --bg-tool-call: #1a1a2e;
    --text-primary: #ececec;
    --text-secondary: #b4b4b4;
    --text-muted: #8e8e8e;
    --border-color: #424242;
    --accent: #10a37f;
    --accent-hover: #0d8c6d;
    --error: #ef4444;
    --warning: #f59e0b;
    --code-bg: #1e1e1e;
    --scrollbar-thumb: #424242;
    --scrollbar-track: transparent;
}

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

html, body {
    height: 100%;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    background: var(--bg-primary);
    color: var(--text-primary);
    overflow: hidden;
}

/* Scrollbar */
::-webkit-scrollbar {
    width: 6px;
}
::-webkit-scrollbar-track {
    background: var(--scrollbar-track);
}
::-webkit-scrollbar-thumb {
    background: var(--scrollbar-thumb);
    border-radius: 3px;
}

/* Layout */
.app-container {
    display: flex;
    height: 100vh;
}

/* Sidebar */
.sidebar {
    width: 260px;
    min-width: 260px;
    background: var(--bg-sidebar);
    display: flex;
    flex-direction: column;
    border-right: 1px solid var(--border-color);
}

.sidebar-header {
    padding: 12px;
}

.btn-new-chat {
    width: 100%;
    padding: 10px 16px;
    background: var(--bg-input);
    color: var(--text-primary);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    cursor: pointer;
    font-size: 14px;
    text-align: left;
    transition: background 0.15s;
}
.btn-new-chat:hover {
    background: var(--bg-hover);
}

.sidebar-search {
    padding: 0 12px 8px;
}
.sidebar-search input {
    width: 100%;
    padding: 8px 12px;
    background: var(--bg-input);
    color: var(--text-primary);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    font-size: 13px;
    outline: none;
}
.sidebar-search input:focus {
    border-color: var(--accent);
}
.sidebar-search input::placeholder {
    color: var(--text-muted);
}

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

.conversation-item {
    padding: 10px 12px;
    border-radius: 8px;
    cursor: pointer;
    font-size: 13px;
    color: var(--text-secondary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    transition: background 0.15s;
    position: relative;
    display: flex;
    align-items: center;
    gap: 8px;
}
.conversation-item:hover {
    background: var(--bg-hover);
}
.conversation-item.active {
    background: var(--bg-active);
    color: var(--text-primary);
}

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

.conversation-item .conv-actions {
    display: none;
    gap: 4px;
    flex-shrink: 0;
}
.conversation-item:hover .conv-actions {
    display: flex;
}

.conv-actions button {
    background: none;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    padding: 2px 4px;
    font-size: 12px;
    border-radius: 4px;
}
.conv-actions button:hover {
    color: var(--text-primary);
    background: var(--bg-primary);
}

.sidebar-footer {
    padding: 12px;
    border-top: 1px solid var(--border-color);
    font-size: 12px;
    color: var(--text-muted);
}

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

.setup-banner {
    padding: 12px 20px;
    background: var(--warning);
    color: #000;
    text-align: center;
    font-size: 14px;
}
.setup-banner code {
    background: rgba(0,0,0,0.1);
    padding: 2px 6px;
    border-radius: 3px;
}

/* Messages */
.messages-container {
    flex: 1;
    overflow-y: auto;
    padding: 20px 0;
}

.welcome-message {
    text-align: center;
    padding: 80px 20px;
    color: var(--text-secondary);
}
.welcome-message h2 {
    font-size: 24px;
    margin-bottom: 12px;
    color: var(--text-primary);
}
.welcome-tips {
    margin-top: 24px;
    text-align: left;
    display: inline-block;
}
.welcome-tips ul {
    list-style: none;
    padding: 0;
    margin-top: 8px;
}
.welcome-tips li {
    padding: 4px 0;
    font-size: 13px;
}

.message {
    padding: 16px 0;
    max-width: 800px;
    margin: 0 auto;
    width: 100%;
    padding-left: 20px;
    padding-right: 20px;
}

.message-role {
    font-size: 13px;
    font-weight: 600;
    margin-bottom: 6px;
    color: var(--text-secondary);
}
.message.user .message-role {
    color: var(--accent);
}

.message-content {
    line-height: 1.6;
    font-size: 15px;
    word-wrap: break-word;
    overflow-wrap: break-word;
}

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

.message-content ul, .message-content ol {
    margin: 8px 0;
    padding-left: 24px;
}

.message-content li {
    margin: 4px 0;
}

.message-content table {
    border-collapse: collapse;
    margin: 12px 0;
    width: 100%;
}
.message-content th, .message-content td {
    border: 1px solid var(--border-color);
    padding: 8px 12px;
    text-align: left;
}
.message-content th {
    background: var(--bg-input);
}

/* Code blocks */
.message-content pre {
    position: relative;
    margin: 12px 0;
    border-radius: 8px;
    overflow: hidden;
}

.code-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 6px 12px;
    background: #1a1a1a;
    font-size: 12px;
    color: var(--text-muted);
}

.btn-copy-code {
    background: none;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    font-size: 12px;
    padding: 2px 8px;
    border-radius: 4px;
}
.btn-copy-code:hover {
    color: var(--text-primary);
    background: var(--bg-hover);
}

.message-content pre code {
    display: block;
    padding: 12px 16px;
    background: var(--code-bg);
    overflow-x: auto;
    font-family: 'Consolas', 'Monaco', 'Courier New', monospace;
    font-size: 13px;
    line-height: 1.5;
}

.message-content code {
    background: var(--code-bg);
    padding: 2px 6px;
    border-radius: 4px;
    font-family: 'Consolas', 'Monaco', 'Courier New', monospace;
    font-size: 13px;
}
.message-content pre code {
    padding: 12px 16px;
    border-radius: 0;
}

/* Message actions */
.message-actions {
    margin-top: 8px;
    display: flex;
    gap: 8px;
    opacity: 0;
    transition: opacity 0.15s;
}
.message:hover .message-actions {
    opacity: 1;
}

.btn-copy-message {
    background: none;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    font-size: 12px;
    padding: 4px 8px;
    border-radius: 4px;
}
.btn-copy-message:hover {
    color: var(--text-primary);
    background: var(--bg-hover);
}

/* Tool calls */
.tool-call {
    margin: 8px 0;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    background: var(--bg-tool-call);
    overflow: hidden;
}
.tool-call summary {
    padding: 8px 12px;
    cursor: pointer;
    font-size: 13px;
    color: var(--text-secondary);
    list-style: none;
}
.tool-call summary::-webkit-details-marker {
    display: none;
}
.tool-call summary::before {
    content: '\25B6 ';
    font-size: 10px;
    margin-right: 6px;
}
.tool-call[open] summary::before {
    content: '\25BC ';
}
.tool-call .tool-content {
    padding: 8px 12px;
    border-top: 1px solid var(--border-color);
    font-size: 13px;
}
.tool-call .tool-content pre {
    margin: 4px 0;
}
.tool-call .tool-spinner {
    display: inline-block;
    width: 12px;
    height: 12px;
    border: 2px solid var(--text-muted);
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: spin 0.6s linear infinite;
    margin-left: 8px;
    vertical-align: middle;
}

/* Attachments on messages */
.message-attachments {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-top: 8px;
}
.attachment-chip {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 6px 10px;
    background: var(--bg-input);
    border-radius: 6px;
    font-size: 12px;
    color: var(--text-secondary);
}
.attachment-chip img {
    max-width: 120px;
    max-height: 80px;
    border-radius: 4px;
}

/* Thinking indicator */
.thinking-indicator {
    display: flex;
    align-items: center;
    gap: 4px;
    padding: 8px 0;
    color: var(--text-muted);
    font-size: 13px;
}
.thinking-dot {
    width: 6px;
    height: 6px;
    background: var(--text-muted);
    border-radius: 50%;
    animation: pulse 1.4s infinite;
}
.thinking-dot:nth-child(2) { animation-delay: 0.2s; }
.thinking-dot:nth-child(3) { animation-delay: 0.4s; }

@keyframes pulse {
    0%, 80%, 100% { transform: scale(0.6); opacity: 0.4; }
    40% { transform: scale(1); opacity: 1; }
}

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

/* Input area */
.input-area {
    border-top: 1px solid var(--border-color);
    padding: 16px 20px;
    max-width: 800px;
    margin: 0 auto;
    width: 100%;
}

.attachment-previews {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-bottom: 8px;
}
.attachment-previews:empty {
    display: none;
    margin: 0;
}

.attachment-preview {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 6px 10px;
    background: var(--bg-input);
    border: 1px solid var(--border-color);
    border-radius: 6px;
    font-size: 12px;
    color: var(--text-secondary);
}
.attachment-preview .remove-attachment {
    background: none;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    font-size: 14px;
    padding: 0 2px;
}
.attachment-preview .remove-attachment:hover {
    color: var(--error);
}
.attachment-preview img {
    max-width: 48px;
    max-height: 32px;
    border-radius: 3px;
}

.input-row {
    display: flex;
    align-items: flex-end;
    gap: 8px;
    background: var(--bg-input);
    border-radius: 12px;
    padding: 8px 12px;
    border: 1px solid var(--border-color);
}
.input-row:focus-within {
    border-color: var(--accent);
}

#message-input {
    flex: 1;
    background: transparent;
    border: none;
    color: var(--text-primary);
    font-size: 15px;
    line-height: 1.5;
    resize: none;
    outline: none;
    max-height: 200px;
    font-family: inherit;
}
#message-input::placeholder {
    color: var(--text-muted);
}

.btn-attach, .btn-send, .btn-stop {
    background: none;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    padding: 4px;
    border-radius: 6px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}
.btn-attach:hover, .btn-send:hover {
    color: var(--text-primary);
}
.btn-send {
    color: var(--accent);
}
.btn-send:hover {
    color: var(--accent-hover);
}
.btn-send:disabled {
    color: var(--text-muted);
    cursor: default;
}
.btn-stop {
    color: var(--error);
}
.btn-stop:hover {
    color: #dc2626;
}

/* Error messages */
.error-message {
    padding: 8px 12px;
    background: rgba(239, 68, 68, 0.1);
    border: 1px solid var(--error);
    border-radius: 6px;
    color: var(--error);
    font-size: 13px;
    margin-top: 8px;
}

.btn-retry {
    background: none;
    border: 1px solid var(--error);
    color: var(--error);
    cursor: pointer;
    padding: 4px 10px;
    border-radius: 4px;
    font-size: 12px;
    margin-top: 6px;
}
.btn-retry:hover {
    background: rgba(239, 68, 68, 0.1);
}

/* Loading state */
.loading-spinner {
    display: flex;
    justify-content: center;
    padding: 20px;
}
.loading-spinner::after {
    content: '';
    width: 24px;
    height: 24px;
    border: 3px solid var(--border-color);
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

/* Drag and drop overlay */
.drag-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(16, 163, 127, 0.1);
    border: 3px dashed var(--accent);
    display: none;
    z-index: 100;
    pointer-events: none;
    align-items: center;
    justify-content: center;
    font-size: 18px;
    color: var(--accent);
}
.drag-overlay.active {
    display: flex;
}

/* Rename input */
.rename-input {
    background: var(--bg-input);
    border: 1px solid var(--accent);
    color: var(--text-primary);
    padding: 2px 6px;
    border-radius: 4px;
    font-size: 13px;
    width: 100%;
    outline: none;
}

/* Empty states */
.empty-state {
    text-align: center;
    padding: 20px;
    color: var(--text-muted);
    font-size: 13px;
}

/* Please wait indicator */
.please-wait {
    font-size: 12px;
    color: var(--text-muted);
    text-align: center;
    padding: 4px;
    animation: fadeInOut 2s ease-in-out;
}

@keyframes fadeInOut {
    0%, 100% { opacity: 0; }
    20%, 80% { opacity: 1; }
}

/* Settings button in sidebar footer */
.sidebar-footer {
    display: flex;
    align-items: center;
    gap: 8px;
}
.btn-settings {
    display: flex;
    align-items: center;
    gap: 6px;
    background: none;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    padding: 4px 8px;
    border-radius: 6px;
    font-size: 13px;
}
.btn-settings:hover {
    color: var(--text-primary);
    background: var(--bg-hover);
}
.mcp-status {
    font-size: 11px;
    color: var(--text-muted);
    margin-left: auto;
}

/* Settings modal */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.6);
    z-index: 200;
    display: flex;
    align-items: center;
    justify-content: center;
}
.modal {
    background: var(--bg-primary);
    border: 1px solid var(--border-color);
    border-radius: 12px;
    width: 520px;
    max-width: 90vw;
    max-height: 80vh;
    display: flex;
    flex-direction: column;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.4);
}
.modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 20px;
    border-bottom: 1px solid var(--border-color);
}
.modal-header h3 {
    font-size: 16px;
    font-weight: 600;
}
.modal-close {
    background: none;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    font-size: 20px;
    padding: 0 4px;
    border-radius: 4px;
}
.modal-close:hover {
    color: var(--text-primary);
    background: var(--bg-hover);
}
.modal-body {
    padding: 20px;
    overflow-y: auto;
    flex: 1;
}
.setting-group {
    margin-bottom: 20px;
}
.setting-group:last-child {
    margin-bottom: 0;
}
.setting-group label {
    display: block;
    font-size: 13px;
    font-weight: 600;
    color: var(--text-secondary);
    margin-bottom: 6px;
}
.setting-group select,
.setting-group textarea,
.setting-group input[type="text"] {
    width: 100%;
    padding: 8px 12px;
    background: var(--bg-input);
    color: var(--text-primary);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    font-size: 14px;
    font-family: inherit;
    outline: none;
}
.setting-group select:focus,
.setting-group textarea:focus,
.setting-group input[type="text"]:focus {
    border-color: var(--accent);
}
.setting-group textarea {
    resize: vertical;
    min-height: 80px;
}
.setting-hint {
    display: block;
    font-size: 11px;
    color: var(--text-muted);
    margin-top: 4px;
}
.model-suggestions {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin-top: 8px;
    max-height: 140px;
    overflow-y: auto;
}
.model-chip {
    padding: 4px 10px;
    background: var(--bg-input);
    border: 1px solid var(--border-color);
    border-radius: 16px;
    font-size: 12px;
    color: var(--text-secondary);
    cursor: pointer;
    transition: all 0.15s;
    white-space: nowrap;
}
.model-chip:hover {
    border-color: var(--accent);
    color: var(--text-primary);
}
.model-chip.active {
    border-color: var(--accent);
    background: rgba(16, 163, 127, 0.15);
    color: var(--accent);
}
.modal-footer {
    display: flex;
    justify-content: flex-end;
    gap: 8px;
    padding: 12px 20px;
    border-top: 1px solid var(--border-color);
}
.btn-modal-cancel {
    padding: 8px 16px;
    background: var(--bg-input);
    color: var(--text-secondary);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    cursor: pointer;
    font-size: 13px;
}
.btn-modal-cancel:hover {
    background: var(--bg-hover);
    color: var(--text-primary);
}
.btn-modal-save {
    padding: 8px 16px;
    background: var(--accent);
    color: #fff;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    font-size: 13px;
    font-weight: 600;
}
.btn-modal-save:hover {
    background: var(--accent-hover);
}

/* Responsive */
@media (max-width: 768px) {
    .sidebar {
        width: 0;
        min-width: 0;
        overflow: hidden;
        transition: width 0.2s;
    }
    .sidebar.open {
        width: 260px;
        min-width: 260px;
    }
}
