/* ========================================
   OpenClaw Chat - Dual Theme (Light / Dark)
   Clean, simple, soft.
   ======================================== */

/* --- Layout & Shared Variables --- */
:root {
    --sidebar-w: 260px;
    --chat-max-w: 48rem;
    --topbar-h: 48px;
    --input-max-h: 200px;
    --radius: 1.5rem;
    --radius-md: 1rem;
    --radius-sm: 0.5rem;
    --radius-xs: 0.375rem;
    --transition: 0.2s ease;
    --font-sans: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, 'Noto Sans SC', sans-serif;
    --font-mono: 'SF Mono', 'Fira Code', 'Fira Mono', 'Roboto Mono', 'Cascadia Code', monospace;
}

/* --- Dark Theme (default) --- */
:root,
[data-theme="dark"] {
    --bg-main: #212121;
    --bg-sidebar: #171717;
    --bg-input: #303030;
    --bg-hover: #2a2a2a;
    --bg-active: #333333;
    --bg-user-msg: #303030;
    --bg-code: #1a1a1a;
    --bg-modal: #2d2d2d;
    --text-primary: #e3e3e3;
    --text-secondary: #b4b4b4;
    --text-muted: #777;
    --text-on-accent: #fff;
    --accent: #10a37f;
    --accent-hover: #0d8c6d;
    --border: #383838;
    --border-light: #444;
    --error: #ef4444;
    --error-bg: rgba(239, 68, 68, 0.1);
    --warning: #f59e0b;
    --success: #10a37f;
    --scrollbar: #565869;
    --scrollbar-hover: #6e6e80;
    --shadow: 0 2px 10px rgba(0, 0, 0, 0.3);
    --hljs-theme: github-dark;
}

/* --- Light Theme --- */
[data-theme="light"] {
    --bg-main: #ffffff;
    --bg-sidebar: #f7f7f8;
    --bg-input: #f4f4f4;
    --bg-hover: #ececec;
    --bg-active: #e3e3e3;
    --bg-user-msg: #e8f5e9;
    --bg-code: #f6f8fa;
    --bg-modal: #ffffff;
    --text-primary: #1a1a1a;
    --text-secondary: #555;
    --text-muted: #999;
    --text-on-accent: #fff;
    --accent: #0d8c6d;
    --accent-hover: #0a7a5e;
    --border: #e0e0e0;
    --border-light: #d0d0d0;
    --error: #dc2626;
    --error-bg: rgba(220, 38, 38, 0.08);
    --warning: #d97706;
    --success: #0d8c6d;
    --scrollbar: #c0c0c0;
    --scrollbar-hover: #a0a0a0;
    --shadow: 0 2px 10px rgba(0, 0, 0, 0.08);
}

/* --- Reset --- */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 16px; -webkit-text-size-adjust: 100%; }
body {
    font-family: var(--font-sans);
    background: var(--bg-main);
    color: var(--text-primary);
    line-height: 1.6;
    overflow: hidden;
    height: 100dvh;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
button { cursor: pointer; border: none; background: none; color: inherit; font: inherit; }
input, textarea, select {
    font: inherit;
    color: var(--text-primary);
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 0.5rem 0.75rem;
    outline: none;
    transition: border-color var(--transition);
}
input:focus, textarea:focus, select:focus { border-color: var(--accent); }
select { appearance: none; background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%23b4b4b4' stroke-width='2'%3E%3Cpolyline points='6 9 12 15 18 9'/%3E%3C/svg%3E"); background-repeat: no-repeat; background-position: right 0.75rem center; padding-right: 2rem; }

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

/* --- Layout --- */
#app {
    display: flex;
    height: 100dvh;
    overflow: hidden;
}

/* --- Sidebar --- */
.sidebar {
    width: var(--sidebar-w);
    min-width: var(--sidebar-w);
    background: var(--bg-sidebar);
    display: flex;
    flex-direction: column;
    border-right: 1px solid var(--border);
    transition: margin-left var(--transition), opacity var(--transition);
    z-index: 100;
}
.sidebar.collapsed {
    margin-left: calc(-1 * var(--sidebar-w));
    opacity: 0;
    pointer-events: none;
}
.sidebar-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.75rem;
    gap: 0.5rem;
}
.btn-new-chat {
    flex: 1;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.6rem 0.75rem;
    border-radius: var(--radius-sm);
    border: 1px solid var(--border);
    font-size: 0.875rem;
    transition: background var(--transition);
}
.btn-new-chat:hover { background: var(--bg-hover); }
.sidebar-search {
    padding: 0 0.75rem 0.5rem;
}
.sidebar-search input {
    width: 100%;
    font-size: 0.8125rem;
    padding: 0.4rem 0.6rem;
    background: var(--bg-hover);
    border-color: transparent;
}
.sidebar-search input:focus { border-color: var(--accent); }

/* Conversation List */
.conv-list {
    flex: 1;
    overflow-y: auto;
    padding: 0 0.5rem;
}
.conv-group-label {
    font-size: 0.6875rem;
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    padding: 0.75rem 0.75rem 0.25rem;
}
.conv-empty {
    padding: 2rem 1rem;
    text-align: center;
    color: var(--text-muted);
    font-size: 0.875rem;
}
.conv-item {
    display: flex;
    align-items: center;
    padding: 0.55rem 0.75rem;
    margin-bottom: 2px;
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: background var(--transition);
    position: relative;
    group: conv;
}
.conv-item:hover { background: var(--bg-hover); }
.conv-item.active { background: var(--bg-active); }
.conv-item-title {
    flex: 1;
    font-size: 0.875rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    color: var(--text-secondary);
}
.conv-item.active .conv-item-title { color: var(--text-primary); }
.conv-item-actions {
    display: none;
    gap: 0.25rem;
    margin-left: 0.25rem;
}
.conv-item:hover .conv-item-actions { display: flex; }
.conv-item-actions .btn-icon { padding: 0.2rem; }
.conv-item-actions .btn-icon:hover { color: var(--error); }

/* Sidebar Footer */
.sidebar-footer {
    border-top: 1px solid var(--border);
    padding: 0.5rem;
    display: flex;
    flex-direction: column;
    gap: 2px;
}
.btn-footer {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.55rem 0.75rem;
    border-radius: var(--radius-sm);
    font-size: 0.875rem;
    color: var(--text-secondary);
    transition: background var(--transition), color var(--transition);
    width: 100%;
}
.btn-footer:hover { background: var(--bg-hover); color: var(--text-primary); }

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

/* Top Bar */
.topbar {
    height: var(--topbar-h);
    display: flex;
    align-items: center;
    padding: 0 1rem;
    gap: 0.5rem;
    border-bottom: 1px solid transparent;
    flex-shrink: 0;
}
.topbar-center { flex: 1; display: flex; justify-content: center; }
.model-label {
    font-size: 0.875rem;
    color: var(--text-secondary);
    font-weight: 500;
    padding: 0.25rem 0.75rem;
    border-radius: var(--radius-xs);
    background: var(--bg-input);
}

/* Connection Status */
.conn-status {
    display: flex;
    align-items: center;
    gap: 0.375rem;
    font-size: 0.75rem;
    color: var(--text-muted);
    padding: 0.25rem 0.5rem;
    border-radius: var(--radius-xs);
    cursor: pointer;
    transition: background var(--transition);
}
.conn-status:hover { background: var(--bg-hover); }
.status-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--text-muted);
    transition: background 0.3s;
}
.conn-status.disconnected .status-dot { background: var(--text-muted); }
.conn-status.connected .status-dot { background: var(--success); }
.conn-status.connecting .status-dot,
.conn-status.handshaking .status-dot { background: var(--warning); animation: pulse 1.2s infinite; }
.conn-status.error .status-dot { background: var(--error); }

@keyframes pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.4; }
}

/* --- Chat Area --- */
.chat-area {
    flex: 1;
    overflow-y: auto;
    scroll-behavior: smooth;
    position: relative;
}

/* Welcome Screen */
.welcome {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 100%;
    gap: 1rem;
    color: var(--text-secondary);
    padding: 2rem;
}
.welcome.hidden { display: none; }
.welcome-icon {
    width: 72px;
    height: 72px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    background: var(--bg-input);
    color: var(--accent);
}
.welcome h1 { font-size: 1.5rem; font-weight: 600; color: var(--text-primary); }
.welcome p { font-size: 1rem; }

/* Messages */
.messages { display: none; padding-bottom: 1rem; }
.messages.has-messages { display: block; }

.msg {
    padding: 1rem 0;
    animation: fadeIn 0.3s ease;
}
@keyframes fadeIn {
    from { opacity: 0; transform: translateY(8px); }
    to { opacity: 1; transform: translateY(0); }
}
.msg.no-anim { animation: none; }
.msg-inner {
    max-width: var(--chat-max-w);
    margin: 0 auto;
    padding: 0 1.5rem;
    display: flex;
    gap: 1rem;
}

/* User Message */
.msg.user .msg-inner {
    justify-content: flex-end;
}
.msg-bubble {
    max-width: 80%;
    padding: 0.75rem 1rem;
    border-radius: var(--radius) var(--radius) var(--radius-xs) var(--radius);
    background: var(--bg-user-msg);
    font-size: 0.9375rem;
    line-height: 1.6;
    word-wrap: break-word;
}
.msg.user .msg-bubble {
    border-radius: var(--radius) var(--radius) var(--radius) var(--radius-xs);
    background: var(--accent);
    color: var(--text-on-accent);
}
.msg.user .msg-bubble a { color: inherit; text-decoration: underline; }

/* Assistant Message */
.msg.assistant .msg-inner {
    align-items: flex-start;
}
.msg-avatar {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    font-size: 0.75rem;
    background: var(--accent);
    color: white;
    margin-top: 2px;
}
.msg.assistant .msg-content {
    flex: 1;
    min-width: 0;
    font-size: 0.9375rem;
    line-height: 1.75;
}

/* Message files */
.msg-files {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    margin-bottom: 0.5rem;
}
.msg-file-thumb {
    width: 120px;
    height: 120px;
    border-radius: var(--radius-sm);
    overflow: hidden;
    cursor: pointer;
    border: 1px solid var(--border);
}
.msg-file-thumb img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}
.msg-file-item {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.4rem 0.75rem;
    background: var(--bg-code);
    border-radius: var(--radius-xs);
    font-size: 0.8125rem;
    color: var(--text-secondary);
}

/* Markdown content styling */
.msg-content p { margin: 0.5em 0; }
.msg-content p:first-child { margin-top: 0; }
.msg-content p:last-child { margin-bottom: 0; }
.msg-content ul, .msg-content ol { padding-left: 1.5em; margin: 0.5em 0; }
.msg-content li { margin: 0.25em 0; }
.msg-content li > p { margin: 0; }
.msg-content blockquote {
    border-left: 3px solid var(--accent);
    padding-left: 1em;
    color: var(--text-secondary);
    margin: 0.5em 0;
}
.msg-content table {
    border-collapse: collapse;
    margin: 0.75em 0;
    font-size: 0.875rem;
    width: 100%;
    overflow-x: auto;
    display: block;
}
.msg-content th, .msg-content td {
    border: 1px solid var(--border);
    padding: 0.4rem 0.75rem;
    text-align: left;
}
.msg-content th { background: var(--bg-code); font-weight: 600; }
.msg-content hr { border: none; border-top: 1px solid var(--border); margin: 1em 0; }
.msg-content img {
    max-width: 100%;
    border-radius: var(--radius-sm);
    margin: 0.5em 0;
    cursor: pointer;
}
.msg-content h1, .msg-content h2, .msg-content h3,
.msg-content h4, .msg-content h5, .msg-content h6 {
    margin: 1em 0 0.5em;
    font-weight: 600;
    line-height: 1.3;
}
.msg-content h1 { font-size: 1.375rem; }
.msg-content h2 { font-size: 1.25rem; }
.msg-content h3 { font-size: 1.125rem; }

/* Inline code */
.msg-content code:not(pre code) {
    background: var(--bg-code);
    padding: 0.15em 0.4em;
    border-radius: 4px;
    font-family: var(--font-mono);
    font-size: 0.875em;
    color: #e06c75;
}

/* Code blocks */
.code-block {
    position: relative;
    margin: 0.75em 0;
    border-radius: var(--radius-sm);
    overflow: hidden;
    background: var(--bg-code);
    border: 1px solid var(--border);
}
.code-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.4rem 0.75rem;
    background: rgba(255,255,255,0.03);
    border-bottom: 1px solid var(--border);
    font-size: 0.75rem;
    color: var(--text-muted);
}
.code-lang { font-family: var(--font-mono); text-transform: lowercase; }
.btn-copy {
    display: flex;
    align-items: center;
    gap: 0.3rem;
    padding: 0.2rem 0.5rem;
    border-radius: var(--radius-xs);
    font-size: 0.75rem;
    color: var(--text-muted);
    transition: background var(--transition), color var(--transition);
}
.btn-copy:hover { background: var(--bg-hover); color: var(--text-primary); }
.btn-copy.copied { color: var(--success); }
.code-block pre {
    margin: 0;
    padding: 0.75rem 1rem;
    overflow-x: auto;
    font-family: var(--font-mono);
    font-size: 0.8125rem;
    line-height: 1.5;
    tab-size: 4;
}
.code-block pre code {
    font-family: inherit;
    background: none;
    padding: 0;
}

/* Thinking / Tool use indicator */
.msg-thinking {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.5rem 0;
    color: var(--text-muted);
    font-size: 0.8125rem;
}
.thinking-dots span {
    display: inline-block;
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: var(--text-muted);
    animation: bounce 1.4s infinite ease-in-out;
}
.thinking-dots span:nth-child(1) { animation-delay: 0s; }
.thinking-dots span:nth-child(2) { animation-delay: 0.2s; }
.thinking-dots span:nth-child(3) { animation-delay: 0.4s; }
@keyframes bounce {
    0%, 80%, 100% { transform: scale(0.6); opacity: 0.4; }
    40% { transform: scale(1); opacity: 1; }
}

/* Streaming cursor */
.streaming-cursor::after {
    content: '';
    display: inline-block;
    width: 7px;
    height: 1.1em;
    background: var(--text-primary);
    margin-left: 2px;
    vertical-align: text-bottom;
    animation: blink 0.8s infinite;
}
@keyframes blink {
    0%, 100% { opacity: 1; }
    50% { opacity: 0; }
}

/* Error message */
.msg.error .msg-bubble {
    background: var(--error-bg);
    color: var(--error);
    border: 1px solid rgba(239, 68, 68, 0.3);
}

/* Message actions */
.msg-actions {
    display: flex;
    gap: 0.25rem;
    margin-top: 0.5rem;
    opacity: 0;
    transition: opacity var(--transition);
}
.msg:hover .msg-actions { opacity: 1; }
.msg-action-btn {
    display: flex;
    align-items: center;
    gap: 0.25rem;
    padding: 0.2rem 0.4rem;
    border-radius: var(--radius-xs);
    font-size: 0.75rem;
    color: var(--text-muted);
    transition: background var(--transition), color var(--transition);
}
.msg-action-btn:hover { background: var(--bg-hover); color: var(--text-primary); }

/* Scroll to bottom */
.btn-scroll-bottom {
    position: absolute;
    bottom: 140px;
    left: 50%;
    transform: translateX(-50%);
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background: var(--bg-input);
    border: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: var(--shadow);
    transition: opacity var(--transition), background var(--transition);
    z-index: 10;
    color: var(--text-secondary);
}
.btn-scroll-bottom:hover { background: var(--bg-active); }
.btn-scroll-bottom.hidden { opacity: 0; pointer-events: none; }

/* --- Input Area --- */
.input-area {
    padding: 0 1rem 0.75rem;
    flex-shrink: 0;
}

/* File preview */
.file-preview {
    max-width: var(--chat-max-w);
    margin: 0 auto 0.5rem;
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
}
.file-preview.hidden { display: none; }
.file-preview-item {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.4rem 0.6rem;
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    font-size: 0.8125rem;
    color: var(--text-secondary);
    max-width: 200px;
}
.file-preview-item img {
    width: 36px;
    height: 36px;
    border-radius: 4px;
    object-fit: cover;
}
.file-preview-name {
    flex: 1;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.file-preview-remove {
    color: var(--text-muted);
    padding: 2px;
    border-radius: 50%;
    transition: color var(--transition);
    flex-shrink: 0;
}
.file-preview-remove:hover { color: var(--error); }

/* Input box */
.input-box {
    max-width: var(--chat-max-w);
    margin: 0 auto;
    display: flex;
    align-items: flex-end;
    gap: 0.25rem;
    padding: 0.5rem 0.75rem;
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    transition: border-color var(--transition);
}
.input-box:focus-within { border-color: var(--border-light); }
.input-box .btn-attach {
    flex-shrink: 0;
    margin-bottom: 2px;
}
#msg-input {
    flex: 1;
    border: none;
    background: transparent;
    resize: none;
    max-height: var(--input-max-h);
    padding: 0.25rem 0.5rem;
    font-size: 0.9375rem;
    line-height: 1.5;
    outline: none;
    color: var(--text-primary);
}
#msg-input::placeholder { color: var(--text-muted); }
.btn-send, .btn-stop {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: background var(--transition), opacity var(--transition);
    margin-bottom: 2px;
}
.btn-send {
    background: var(--text-primary);
    color: var(--bg-main);
}
.btn-send:disabled {
    opacity: 0.3;
    cursor: not-allowed;
}
.btn-send:not(:disabled):hover { background: #fff; }
.btn-stop {
    background: var(--text-primary);
    color: var(--bg-main);
}
.btn-stop:hover { background: #fff; }

.input-hint {
    text-align: center;
    font-size: 0.75rem;
    color: var(--text-muted);
    margin-top: 0.5rem;
    max-width: var(--chat-max-w);
    margin-left: auto;
    margin-right: auto;
}

/* --- Btn Icon --- */
.btn-icon {
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: var(--radius-sm);
    color: var(--text-secondary);
    transition: background var(--transition), color var(--transition);
    flex-shrink: 0;
}
.btn-icon:hover { background: var(--bg-hover); color: var(--text-primary); }

/* --- Modal --- */
.modal {
    position: fixed;
    inset: 0;
    z-index: 1000;
    display: flex;
    align-items: center;
    justify-content: center;
    animation: fadeIn 0.15s ease;
}
.modal.hidden { display: none; }
.modal-overlay {
    position: absolute;
    inset: 0;
    background: rgba(0, 0, 0, 0.6);
    backdrop-filter: blur(2px);
}
.modal-dialog {
    position: relative;
    background: var(--bg-modal);
    border-radius: var(--radius-md);
    width: 90%;
    max-width: 520px;
    max-height: 85vh;
    display: flex;
    flex-direction: column;
    box-shadow: 0 8px 30px rgba(0,0,0,0.4);
}
.modal-sm { max-width: 380px; }
.modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 1rem 1.25rem;
    border-bottom: 1px solid var(--border);
}
.modal-header h2 { font-size: 1.0625rem; font-weight: 600; }
.btn-modal-close {
    width: 28px;
    height: 28px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: var(--radius-xs);
    color: var(--text-muted);
    transition: background var(--transition), color var(--transition);
}
.btn-modal-close:hover { background: var(--bg-hover); color: var(--text-primary); }
.modal-body {
    padding: 1rem 1.25rem;
    overflow-y: auto;
    flex: 1;
}
.modal-footer {
    display: flex;
    justify-content: flex-end;
    gap: 0.5rem;
    padding: 0.75rem 1.25rem;
    border-top: 1px solid var(--border);
}

/* Settings */
.setting-section { margin-bottom: 1.25rem; }
.setting-section:last-child { margin-bottom: 0; }
.setting-section h3 {
    font-size: 0.8125rem;
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    margin-bottom: 0.75rem;
}
.setting-group { margin-bottom: 0.875rem; }
.setting-group:last-child { margin-bottom: 0; }
.setting-group label {
    display: block;
    font-size: 0.875rem;
    font-weight: 500;
    margin-bottom: 0.375rem;
    color: var(--text-secondary);
}
.setting-group input[type="text"],
.setting-group input[type="password"],
.setting-group select {
    width: 100%;
}
.setting-hint {
    font-size: 0.75rem;
    color: var(--text-muted);
    margin-top: 0.25rem;
}
.input-with-toggle {
    position: relative;
}
.input-with-toggle input { width: 100%; padding-right: 2.5rem; }
.btn-toggle-vis {
    position: absolute;
    right: 0.5rem;
    top: 50%;
    transform: translateY(-50%);
    color: var(--text-muted);
    padding: 0.25rem;
    border-radius: var(--radius-xs);
}
.btn-toggle-vis:hover { color: var(--text-primary); }

/* Toggle switch */
.setting-toggle {
    display: flex !important;
    align-items: center;
    justify-content: space-between;
    cursor: pointer;
}
.setting-toggle input { display: none; }
.toggle-slider {
    width: 40px;
    height: 22px;
    background: var(--border);
    border-radius: 11px;
    position: relative;
    transition: background 0.3s;
    flex-shrink: 0;
}
.toggle-slider::after {
    content: '';
    position: absolute;
    width: 18px;
    height: 18px;
    border-radius: 50%;
    background: var(--text-primary);
    top: 2px;
    left: 2px;
    transition: transform 0.3s;
}
.setting-toggle input:checked + .toggle-slider { background: var(--accent); }
.setting-toggle input:checked + .toggle-slider::after { transform: translateX(18px); }

/* Buttons */
.btn-primary, .btn-secondary, .btn-danger {
    padding: 0.5rem 1rem;
    border-radius: var(--radius-sm);
    font-size: 0.875rem;
    font-weight: 500;
    transition: background var(--transition), opacity var(--transition);
}
.btn-primary { background: var(--accent); color: white; }
.btn-primary:hover { background: var(--accent-hover); }
.btn-secondary { background: var(--bg-input); border: 1px solid var(--border); }
.btn-secondary:hover { background: var(--bg-hover); }
.btn-danger { background: var(--error); color: white; }
.btn-danger:hover { opacity: 0.9; }

/* Image preview modal */
.image-preview-container {
    position: relative;
    max-width: 90vw;
    max-height: 90vh;
    display: flex;
    align-items: center;
    justify-content: center;
}
.image-preview-container img {
    max-width: 90vw;
    max-height: 85vh;
    object-fit: contain;
    border-radius: var(--radius-sm);
}
.btn-image-close {
    position: absolute;
    top: -40px;
    right: 0;
    color: white;
}

/* Debug log */
.debug-panel {
    position: fixed;
    bottom: 0;
    right: 0;
    width: 400px;
    max-height: 300px;
    background: var(--bg-code);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm) 0 0 0;
    font-family: var(--font-mono);
    font-size: 0.6875rem;
    overflow-y: auto;
    z-index: 999;
    display: none;
}
.debug-panel.visible { display: block; }
.debug-entry { padding: 0.2rem 0.5rem; border-bottom: 1px solid var(--border); }
.debug-entry.sent { color: #61afef; }
.debug-entry.received { color: #98c379; }
.debug-entry.error { color: var(--error); }

/* Image loading placeholder */
.file-thumb-loading {
    width: 120px;
    height: 120px;
    background: var(--bg-code);
    border-radius: var(--radius-sm);
    display: flex;
    align-items: center;
    justify-content: center;
    animation: pulse 1.5s infinite;
}

/* Light theme overrides */
[data-theme="light"] .msg.user .msg-bubble {
    background: var(--accent);
    color: var(--text-on-accent);
}
[data-theme="light"] .code-block {
    border-color: var(--border);
}
[data-theme="light"] .msg-content code:not(pre code) {
    background: #eff1f3;
    color: #c7254e;
}
[data-theme="light"] .btn-send {
    background: var(--text-primary);
    color: var(--bg-main);
}
[data-theme="light"] .input-box {
    border-color: var(--border);
}
[data-theme="light"] .sidebar {
    border-right-color: var(--border);
}

/* Theme toggle button */
.btn-theme-toggle {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.55rem 0.75rem;
    border-radius: var(--radius-sm);
    font-size: 0.875rem;
    color: var(--text-secondary);
    transition: background var(--transition), color var(--transition);
    width: 100%;
    cursor: pointer;
}
.btn-theme-toggle:hover { background: var(--bg-hover); color: var(--text-primary); }

/* --- Login Overlay --- */
.login-overlay {
    position: fixed;
    inset: 0;
    z-index: 2000;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--bg-main);
}
.login-overlay.hidden { display: none; }
.login-card {
    width: 90%;
    max-width: 360px;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 1.25rem;
}
.login-icon {
    width: 64px;
    height: 64px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--bg-input);
    color: var(--accent);
}
.login-title {
    font-size: 1.25rem;
    font-weight: 600;
    color: var(--text-primary);
}
.login-form {
    width: 100%;
    display: flex;
    flex-direction: column;
    gap: 1rem;
}
.login-field label {
    display: block;
    font-size: 0.875rem;
    font-weight: 500;
    color: var(--text-secondary);
    margin-bottom: 0.375rem;
}
.login-field input {
    width: 100%;
}
.login-error {
    font-size: 0.8125rem;
    color: var(--error);
    text-align: center;
    margin: 0;
}
.btn-login {
    width: 100%;
    padding: 0.625rem;
    border-radius: var(--radius-sm);
    background: var(--accent);
    color: white;
    font-size: 0.9375rem;
    font-weight: 500;
    transition: background var(--transition), opacity var(--transition);
    cursor: pointer;
    border: none;
}
.btn-login:hover { background: var(--accent-hover); }
.btn-login:disabled { opacity: 0.6; cursor: not-allowed; }

/* --- Utilities --- */
.hidden { display: none !important; }

/* --- Responsive --- */
@media (max-width: 1024px) {
    .sidebar {
        position: fixed;
        left: 0;
        top: 0;
        bottom: 0;
        z-index: 200;
        box-shadow: 2px 0 10px rgba(0,0,0,0.5);
    }
    .sidebar.collapsed {
        margin-left: 0;
        transform: translateX(-100%);
    }
}
@media (max-width: 768px) {
    .msg-inner { padding: 0 1rem; }
    .input-area { padding: 0 0.5rem 0.5rem; }
    .msg-bubble { max-width: 90%; }
    .btn-scroll-bottom { bottom: 120px; }
    .modal-dialog { width: 95%; }
    .debug-panel { width: 100%; }
}
