/* ===== CSS Custom Properties (Dark Theme - Default) ===== */
:root {
    --bg-primary: #0f0f1a;
    --bg-secondary: #1a1a2e;
    --bg-tertiary: #16213e;
    --bg-message-user: #0f3460;
    --bg-message-bot: #1e1e3a;
    --bg-input: #252545;
    --text-primary: #e8e8f0;
    --text-secondary: #9898b0;
    --text-muted: #6a6a85;
    --accent: #4a9eff;
    --accent-hover: #3a8eef;
    --border: #2a2a4a;
    --danger: #ff4757;
    --danger-hover: #e63e4e;
    --success: #2ed573;
    --radius: 12px;
    --radius-sm: 8px;
    --shadow: 0 4px 24px rgba(0, 0, 0, 0.3);
    --sidebar-width: 280px;
}

/* ===== Light Theme ===== */
[data-theme="light"] {
    --bg-primary: #f5f5f7;
    --bg-secondary: #ffffff;
    --bg-tertiary: #e8e8ec;
    --bg-message-user: #d4e4ff;
    --bg-message-bot: #f0f0f5;
    --bg-input: #eaeaf0;
    --text-primary: #1a1a2e;
    --text-secondary: #555570;
    --text-muted: #8888a0;
    --accent: #3a7bd5;
    --accent-hover: #2a6bc5;
    --border: #d0d0e0;
    --danger: #e03e4e;
    --danger-hover: #c83040;
    --success: #1eb563;
    --shadow: 0 4px 24px rgba(0, 0, 0, 0.08);
}

/* ===== Reset & Base ===== */
*, *::before, *::after {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, sans-serif;
    background: var(--bg-primary);
    color: var(--text-primary);
    line-height: 1.6;
    -webkit-font-smoothing: antialiased;
}

a {
    color: var(--accent);
    text-decoration: none;
}

a:hover {
    text-decoration: underline;
}

/* ===== LOGIN PAGE ===== */
.login-body {
    min-height: 100vh;
    min-height: 100dvh;
    display: flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(135deg, var(--bg-primary) 0%, #0a0a1a 100%);
}

[data-theme="light"] .login-body {
    background: linear-gradient(135deg, var(--bg-primary) 0%, #e0e0ea 100%);
}

.login-container {
    width: 100%;
    padding: 20px;
}

.login-card {
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: 16px;
    padding: 40px;
    max-width: 420px;
    margin: 0 auto;
    box-shadow: var(--shadow);
}

.login-title {
    text-align: center;
    font-size: 2rem;
    font-weight: 700;
    color: var(--accent);
    margin-bottom: 4px;
}

.login-subtitle {
    text-align: center;
    color: var(--text-secondary);
    margin-bottom: 28px;
    font-size: 0.95rem;
}

.form-group {
    margin-bottom: 18px;
}

.form-group label {
    display: block;
    font-size: 0.85rem;
    color: var(--text-secondary);
    margin-bottom: 6px;
    font-weight: 500;
}

.form-group input {
    width: 100%;
    padding: 12px 14px;
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    color: var(--text-primary);
    font-size: 0.95rem;
    outline: none;
    transition: border-color 0.2s;
}

.form-group input:focus {
    border-color: var(--accent);
}

.form-group input::placeholder {
    color: var(--text-muted);
}

.btn-primary {
    padding: 12px 24px;
    background: var(--accent);
    color: #fff;
    border: none;
    border-radius: var(--radius-sm);
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.2s;
}

.btn-primary:hover {
    background: var(--accent-hover);
}

.login-card .btn-primary {
    width: 100%;
    margin-top: 8px;
}

.btn-secondary {
    padding: 12px 24px;
    background: transparent;
    color: var(--text-primary);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    font-size: 0.95rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s;
    text-decoration: none;
    display: inline-block;
    text-align: center;
}

.btn-secondary:hover {
    background: var(--bg-input);
    border-color: var(--accent);
    color: var(--accent);
    text-decoration: none;
}

.btn-danger {
    padding: 12px 24px;
    background: var(--danger);
    color: #fff;
    border: none;
    border-radius: var(--radius-sm);
    font-size: 0.95rem;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.2s;
}

.btn-danger:hover {
    background: var(--danger-hover);
}

.error-message {
    background: rgba(255, 71, 87, 0.15);
    border: 1px solid rgba(255, 71, 87, 0.3);
    color: var(--danger);
    padding: 10px 14px;
    border-radius: var(--radius-sm);
    margin-bottom: 18px;
    font-size: 0.9rem;
}

.toggle-text {
    text-align: center;
    margin-top: 20px;
    font-size: 0.9rem;
    color: var(--text-secondary);
}

.toggle-text a {
    font-weight: 600;
    margin-left: 4px;
}

/* ===== CHAT PAGE ===== */
.chat-body {
    display: flex;
    height: 100vh;
    height: 100dvh;
    overflow: hidden;
}

/* ===== SIDEBAR ===== */
.sidebar {
    width: var(--sidebar-width);
    flex-shrink: 0;
    background: var(--bg-secondary);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    transition: transform 0.3s ease;
    z-index: 100;
}

.sidebar-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: 99;
}

.sidebar-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px;
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
}

.sidebar-title {
    font-size: 1.2rem;
    font-weight: 700;
    color: var(--accent);
}

.new-chat-btn {
    width: 36px;
    height: 36px;
    background: transparent;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    color: var(--text-secondary);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
}

.new-chat-btn:hover {
    background: var(--bg-input);
    color: var(--accent);
    border-color: var(--accent);
}

.chat-list {
    flex: 1;
    overflow-y: auto;
    padding: 8px;
}

.chat-list::-webkit-scrollbar {
    width: 4px;
}

.chat-list::-webkit-scrollbar-thumb {
    background: var(--border);
    border-radius: 2px;
}

.chat-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 12px;
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: background 0.15s;
    margin-bottom: 2px;
}

.chat-item:hover {
    background: var(--bg-input);
}

.chat-item.active {
    background: var(--bg-tertiary);
}

.chat-item-title {
    flex: 1;
    font-size: 0.88rem;
    color: var(--text-primary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    margin-right: 8px;
}

.chat-delete-btn {
    width: 24px;
    height: 24px;
    background: transparent;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    font-size: 16px;
    border-radius: 4px;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    transition: all 0.15s;
    flex-shrink: 0;
}

.chat-item:hover .chat-delete-btn {
    opacity: 1;
}

.chat-delete-btn:hover {
    color: var(--danger);
    background: rgba(255, 71, 87, 0.15);
}

.sidebar-footer {
    padding: 12px 16px;
    border-top: 1px solid var(--border);
    flex-shrink: 0;
}

.sidebar-settings-btn {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 12px;
    border-radius: var(--radius-sm);
    color: var(--text-secondary);
    font-size: 0.9rem;
    transition: all 0.15s;
    text-decoration: none;
}

.sidebar-settings-btn:hover {
    background: var(--bg-input);
    color: var(--text-primary);
    text-decoration: none;
}

/* ===== MAIN AREA ===== */
.main-area {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-width: 0;
    background: var(--bg-primary);
}

/* Header */
.app-header {
    flex-shrink: 0;
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 20px;
    border-bottom: 1px solid var(--border);
    background: var(--bg-secondary);
}

.sidebar-toggle {
    display: none;
}

.app-logo {
    flex: 1;
    font-size: 1.1rem;
    font-weight: 600;
    color: var(--text-primary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.user-info {
    display: flex;
    align-items: center;
    gap: 14px;
    flex-shrink: 0;
}

.username {
    font-size: 0.9rem;
    color: var(--text-secondary);
}

/* Messages area */
.chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 20px;
    display: flex;
    flex-direction: column;
    gap: 12px;
    scroll-behavior: smooth;
}

.chat-messages::-webkit-scrollbar {
    width: 6px;
}

.chat-messages::-webkit-scrollbar-track {
    background: transparent;
}

.chat-messages::-webkit-scrollbar-thumb {
    background: var(--border);
    border-radius: 3px;
}

/* Welcome message */
.welcome-message {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    flex: 1;
    text-align: center;
    color: var(--text-secondary);
    gap: 12px;
}

.welcome-icon {
    color: var(--accent);
    opacity: 0.6;
}

.welcome-message h2 {
    font-size: 1.3rem;
    color: var(--text-primary);
    font-weight: 600;
}

.welcome-message p {
    font-size: 0.95rem;
    color: var(--text-muted);
}

/* Message bubbles */
.message {
    max-width: 80%;
    padding: 12px 16px;
    border-radius: var(--radius);
    animation: slideIn 0.25s ease-out;
    word-wrap: break-word;
    overflow-wrap: break-word;
}

.message.user {
    align-self: flex-end;
    background: var(--bg-message-user);
    border-bottom-right-radius: 4px;
}

.message.assistant {
    align-self: flex-start;
    background: var(--bg-message-bot);
    border-bottom-left-radius: 4px;
}

.message.user .msg-label,
.message.assistant .msg-label {
    font-size: 0.75rem;
    color: var(--text-muted);
    margin-bottom: 4px;
    font-weight: 600;
}

.msg-content {
    font-size: 0.95rem;
    line-height: 1.65;
}

.msg-content p {
    margin-bottom: 8px;
}

.msg-content p:last-child {
    margin-bottom: 0;
}

.msg-content code {
    background: rgba(255, 255, 255, 0.08);
    padding: 2px 6px;
    border-radius: 4px;
    font-family: 'Consolas', 'Monaco', 'Courier New', monospace;
    font-size: 0.88em;
}

[data-theme="light"] .msg-content code {
    background: rgba(0, 0, 0, 0.07);
}

.msg-content pre {
    background: rgba(0, 0, 0, 0.3);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 14px;
    overflow-x: auto;
    margin: 10px 0;
    position: relative;
}

[data-theme="light"] .msg-content pre {
    background: rgba(0, 0, 0, 0.05);
}

.msg-content pre code {
    background: none;
    padding: 0;
    font-size: 0.85em;
    line-height: 1.5;
}

/* Copy button on code blocks */
.copy-code-btn {
    position: absolute;
    top: 8px;
    right: 8px;
    padding: 4px 10px;
    background: var(--surface-2);
    color: var(--text-secondary);
    border: 1px solid var(--border);
    border-radius: 4px;
    font-size: 0.75rem;
    cursor: pointer;
    opacity: 0;
    transition: opacity 0.15s;
}

.msg-content pre:hover .copy-code-btn {
    opacity: 1;
}

.copy-code-btn:hover {
    background: var(--accent);
    color: #fff;
    border-color: var(--accent);
}

/* HTML Preview button on code blocks */
.preview-code-btn {
    position: absolute;
    top: 8px;
    right: 80px;
    padding: 4px 10px;
    background: var(--accent);
    color: #fff;
    border: none;
    border-radius: 4px;
    font-size: 0.75rem;
    cursor: pointer;
    opacity: 0;
    transition: opacity 0.15s;
}

.msg-content pre:hover .preview-code-btn {
    opacity: 1;
}

.preview-code-btn:hover {
    opacity: 1;
}

/* User's attached image in message */
.msg-user-image {
    max-width: 200px;
    max-height: 200px;
    border-radius: var(--radius-sm);
    margin-top: 8px;
    display: block;
}

/* Generated image */
.generated-image {
    max-width: 100%;
    border-radius: var(--radius-sm);
    margin-top: 8px;
}

/* Thinking indicator */
.thinking-indicator {
    color: var(--text-muted);
    font-style: italic;
    font-size: 0.9rem;
    padding: 4px 0;
    animation: thinking-pulse 1.8s ease-in-out infinite;
}

@keyframes thinking-pulse {
    0%, 100% { opacity: 0.4; }
    50%       { opacity: 1; }
}

/* Search indicator */
.search-indicator {
    display: flex;
    align-items: center;
    gap: 8px;
    color: var(--accent);
    font-size: 0.85rem;
    padding: 6px 0;
}

.search-indicator .spinner {
    width: 14px;
    height: 14px;
    border: 2px solid var(--border);
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

/* Generating image indicator */
.generating-indicator {
    display: flex;
    align-items: center;
    gap: 8px;
    color: var(--accent);
    font-size: 0.9rem;
    padding: 12px 0;
}

.generating-indicator .spinner {
    width: 16px;
    height: 16px;
    border: 2px solid var(--border);
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

/* Image preview above input */
.image-preview {
    display: none;
    padding: 8px 20px 0;
}

.image-preview.active {
    display: block;
}

.preview-wrapper {
    position: relative;
    display: inline-block;
}

.preview-wrapper img {
    width: 64px;
    height: 64px;
    object-fit: cover;
    border-radius: var(--radius-sm);
    border: 2px solid var(--border);
}

.remove-btn {
    position: absolute;
    top: -6px;
    right: -6px;
    width: 22px;
    height: 22px;
    background: var(--danger);
    color: #fff;
    border: 2px solid var(--bg-primary);
    border-radius: 50%;
    font-size: 14px;
    line-height: 1;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: transform 0.15s;
}

.remove-btn:hover {
    transform: scale(1.15);
}

/* Input area */
.chat-input-area {
    flex-shrink: 0;
    display: flex;
    align-items: flex-end;
    gap: 8px;
    padding: 12px 20px 16px;
    border-top: 1px solid var(--border);
    background: var(--bg-secondary);
}

.icon-btn {
    flex-shrink: 0;
    width: 42px;
    height: 42px;
    background: transparent;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    color: var(--text-secondary);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
}

.icon-btn:hover {
    background: var(--bg-input);
    color: var(--accent);
    border-color: var(--accent);
}

#messageInput {
    flex: 1;
    resize: none;
    max-height: 140px;
    min-height: 42px;
    padding: 10px 14px;
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    color: var(--text-primary);
    font-size: 0.95rem;
    font-family: inherit;
    line-height: 1.5;
    outline: none;
    transition: border-color 0.2s;
    overflow-y: auto;
}

#messageInput:focus {
    border-color: var(--accent);
}

#messageInput::placeholder {
    color: var(--text-muted);
}

.send-btn {
    flex-shrink: 0;
    width: 42px;
    height: 42px;
    background: var(--accent);
    border: none;
    border-radius: var(--radius-sm);
    color: #fff;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s, transform 0.1s;
}

.send-btn:hover {
    background: var(--accent-hover);
}

.send-btn:active {
    transform: scale(0.95);
}

.send-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

/* ===== MODAL ===== */
.modal-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.6);
    z-index: 200;
    align-items: center;
    justify-content: center;
    padding: 20px;
}

.modal-overlay.active {
    display: flex;
}

.modal-content {
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: 16px;
    box-shadow: var(--shadow);
    max-height: 90vh;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 20px;
    border-bottom: 1px solid var(--border);
}

.modal-header h3 {
    font-size: 1.1rem;
    font-weight: 600;
}

.modal-close {
    width: 32px;
    height: 32px;
    background: transparent;
    border: none;
    color: var(--text-muted);
    font-size: 20px;
    cursor: pointer;
    border-radius: 6px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.15s;
}

.modal-close:hover {
    background: var(--bg-input);
    color: var(--text-primary);
}

.modal-body {
    flex: 1;
    overflow: auto;
    padding: 0;
}

.modal-footer {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 10px;
    padding: 14px 20px;
    border-top: 1px solid var(--border);
}

/* HTML Preview Modal */
.html-preview-modal {
    width: 90vw;
    max-width: 900px;
    height: 80vh;
}

.modal-tabs {
    display: flex;
    border-bottom: 1px solid var(--border);
    padding: 0 20px;
}

.modal-tab {
    padding: 10px 16px;
    background: none;
    border: none;
    border-bottom: 2px solid transparent;
    color: var(--text-secondary);
    font-size: 0.9rem;
    cursor: pointer;
    transition: all 0.15s;
}

.modal-tab:hover {
    color: var(--text-primary);
}

.modal-tab.active {
    color: var(--accent);
    border-bottom-color: var(--accent);
}

.preview-pane {
    height: 100%;
}

.preview-pane iframe {
    width: 100%;
    height: 100%;
    border: none;
    background: #fff;
}

.code-pane {
    height: 100%;
    padding: 0;
}

.code-pane textarea {
    width: 100%;
    height: 100%;
    padding: 16px;
    background: var(--bg-primary);
    color: var(--text-primary);
    border: none;
    font-family: 'Consolas', 'Monaco', 'Courier New', monospace;
    font-size: 0.88rem;
    line-height: 1.5;
    resize: none;
    outline: none;
}

.modal-action-btn {
    white-space: nowrap;
}

/* Delete account modal */
.delete-modal {
    width: 90vw;
    max-width: 440px;
}

.delete-modal .modal-body {
    padding: 20px;
}

.delete-modal .modal-body p {
    color: var(--text-secondary);
    font-size: 0.95rem;
    line-height: 1.6;
}

/* ===== SETTINGS PAGE ===== */
.settings-body {
    min-height: 100vh;
    min-height: 100dvh;
    background: var(--bg-primary);
}

.settings-container {
    max-width: 640px;
    margin: 0 auto;
    padding: 20px;
}

.settings-header {
    margin-bottom: 32px;
}

.back-link {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    color: var(--text-secondary);
    font-size: 0.9rem;
    margin-bottom: 16px;
    transition: color 0.15s;
}

.back-link:hover {
    color: var(--accent);
    text-decoration: none;
}

.settings-header h1 {
    font-size: 1.8rem;
    font-weight: 700;
}

.settings-section {
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 24px;
    margin-bottom: 20px;
}

.settings-section h2 {
    font-size: 1.15rem;
    font-weight: 600;
    margin-bottom: 20px;
    color: var(--text-primary);
}

.setting-item {
    margin-bottom: 20px;
}

.setting-item:last-child {
    margin-bottom: 0;
}

.setting-item > label {
    display: block;
    font-size: 0.9rem;
    font-weight: 500;
    color: var(--text-secondary);
    margin-bottom: 8px;
}

.setting-hint {
    font-size: 0.82rem;
    color: var(--text-muted);
    margin-top: 6px;
}

.setting-btn {
    width: 100%;
}

/* Theme toggle */
.theme-toggle {
    display: flex;
    gap: 8px;
}

.theme-btn {
    flex: 1;
    padding: 10px;
    background: var(--bg-input);
    border: 2px solid var(--border);
    border-radius: var(--radius-sm);
    color: var(--text-secondary);
    font-size: 0.9rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s;
    text-align: center;
}

.theme-btn:hover {
    border-color: var(--accent);
    color: var(--text-primary);
}

.theme-btn.active {
    border-color: var(--accent);
    background: var(--accent);
    color: #fff;
}

/* Radio options */
.radio-group {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.radio-option {
    display: flex;
    align-items: flex-start;
    gap: 12px;
    padding: 12px 14px;
    background: var(--bg-input);
    border: 2px solid var(--border);
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: border-color 0.2s;
}

.radio-option:hover {
    border-color: var(--accent);
}

.radio-option:has(input:checked) {
    border-color: var(--accent);
}

.radio-option input[type="radio"] {
    margin-top: 3px;
    accent-color: var(--accent);
    flex-shrink: 0;
}

.radio-label {
    font-size: 0.9rem;
    font-weight: 600;
    color: var(--text-primary);
    display: block;
}

.radio-desc {
    font-size: 0.82rem;
    color: var(--text-muted);
    display: block;
    margin-top: 2px;
}

/* Custom instructions textarea */
.setting-item textarea {
    width: 100%;
    padding: 12px 14px;
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    color: var(--text-primary);
    font-size: 0.92rem;
    font-family: inherit;
    line-height: 1.5;
    resize: vertical;
    outline: none;
    transition: border-color 0.2s;
}

.setting-item textarea:focus {
    border-color: var(--accent);
}

.setting-item textarea::placeholder {
    color: var(--text-muted);
}

/* Danger zone */
.danger-zone {
    padding-top: 20px;
    border-top: 1px solid var(--border);
}

/* Memories list */
.memories-list {
    margin-top: 12px;
}

.memories-empty {
    color: var(--text-muted);
    font-size: 0.9rem;
    font-style: italic;
}

.memory-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 14px;
    background: var(--bg-input);
    border-radius: var(--radius-sm);
    margin-bottom: 8px;
}

.memory-content {
    flex: 1;
    font-size: 0.9rem;
    color: var(--text-primary);
    margin-right: 10px;
}

.memory-delete {
    width: 28px;
    height: 28px;
    background: transparent;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    font-size: 18px;
    border-radius: 4px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: all 0.15s;
}

.memory-delete:hover {
    color: var(--danger);
    background: rgba(255, 71, 87, 0.15);
}

/* ===== Animations ===== */
@keyframes slideIn {
    from {
        opacity: 0;
        transform: translateY(8px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

/* ===== Mobile Responsive ===== */
@media (max-width: 768px) {
    /* Sidebar as overlay on mobile */
    .sidebar {
        position: fixed;
        top: 0;
        left: 0;
        bottom: 0;
        width: var(--sidebar-width);
        transform: translateX(-100%);
    }

    .sidebar.open {
        transform: translateX(0);
    }

    .sidebar-overlay.active {
        display: block;
    }

    .sidebar-toggle {
        display: flex;
    }

    /* Chat */
    .chat-messages {
        padding: 14px;
    }

    .message {
        max-width: 90%;
    }

    .chat-input-area {
        padding: 10px 12px 14px;
        gap: 6px;
    }

    .image-preview {
        padding: 8px 12px 0;
    }

    .app-header {
        padding: 10px 14px;
    }

    .app-logo {
        font-size: 1rem;
    }

    .username {
        display: none;
    }

    /* Login */
    .login-card {
        padding: 28px 24px;
        border-radius: 12px;
    }

    .login-title {
        font-size: 1.7rem;
    }

    /* Settings */
    .settings-container {
        padding: 16px;
    }

    .settings-section {
        padding: 18px;
    }

    .settings-header h1 {
        font-size: 1.5rem;
    }

    /* Modals */
    .html-preview-modal {
        width: 95vw;
        height: 85vh;
    }
}

@media (max-width: 400px) {
    .login-container {
        padding: 12px;
    }

    .login-card {
        padding: 24px 18px;
    }
}

/* Desktop: sidebar always visible */
@media (min-width: 769px) {
    .sidebar-toggle {
        display: none;
    }
}
