/* ===========================
   Connector - Code Agent
   Complete Stylesheet
   =========================== */

:root {
    --bg-primary: #0f0f14;
    --bg-secondary: #1a1a24;
    --bg-tertiary: #24243a;
    --bg-hover: #2a2a42;
    --bg-input: #16161e;
    --text-primary: #e8e8f0;
    --text-secondary: #9898b0;
    --text-muted: #606078;
    --accent: #6c5ce7;
    --accent-hover: #7d6ff0;
    --accent-light: rgba(108, 92, 231, 0.15);
    --danger: #e74c3c;
    --danger-hover: #c0392b;
    --success: #2ecc71;
    --warning: #f39c12;
    --border: #2a2a3e;
    --border-light: #3a3a58;
    --radius: 8px;
    --radius-lg: 12px;
    --shadow: 0 4px 20px rgba(0, 0, 0, 0.3);
    --transition: 0.2s ease;
    --sidebar-width: 280px;
    --font: 'Segoe UI', system-ui, -apple-system, sans-serif;
    --font-mono: 'Cascadia Code', 'Fira Code', 'Consolas', monospace;
}

/* Light Theme */
[data-theme="light"] {
    --bg-primary: #f5f5f7;
    --bg-secondary: #ffffff;
    --bg-tertiary: #e8e8ed;
    --bg-hover: #dddde3;
    --bg-input: #f0f0f4;
    --text-primary: #1a1a2e;
    --text-secondary: #55556a;
    --text-muted: #8888a0;
    --accent: #6c5ce7;
    --accent-hover: #5a4bd6;
    --accent-light: rgba(108, 92, 231, 0.1);
    --danger: #e74c3c;
    --danger-hover: #c0392b;
    --success: #27ae60;
    --warning: #e67e22;
    --border: #d8d8e0;
    --border-light: #c8c8d4;
    --shadow: 0 4px 20px rgba(0, 0, 0, 0.08);
}

*, *::before, *::after {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

html, body {
    height: 100%;
    height: 100dvh;
    overflow: hidden;
}

body {
    font-family: var(--font);
    background: var(--bg-primary);
    color: var(--text-primary);
    font-size: 14px;
    line-height: 1.6;
}

/* Scrollbar */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border-light); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-muted); }

/* ===========================
   Buttons
   =========================== */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 8px 16px;
    border: none;
    border-radius: var(--radius);
    cursor: pointer;
    font-family: var(--font);
    font-size: 13px;
    font-weight: 500;
    transition: all var(--transition);
    text-decoration: none;
    white-space: nowrap;
}

.btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.btn-primary {
    background: var(--accent);
    color: #fff;
}
.btn-primary:hover:not(:disabled) { background: var(--accent-hover); }

.btn-outline {
    background: transparent;
    color: var(--text-secondary);
    border: 1px solid var(--border);
}
.btn-outline:hover:not(:disabled) {
    background: var(--bg-hover);
    color: var(--text-primary);
    border-color: var(--border-light);
}

.btn-danger {
    background: var(--danger);
    color: #fff;
}
.btn-danger:hover:not(:disabled) { background: var(--danger-hover); }

.btn-sm { padding: 5px 10px; font-size: 12px; }
.btn-block { width: 100%; }

/* ===========================
   Forms
   =========================== */
.form-group {
    margin-bottom: 16px;
}

.form-group label {
    display: block;
    margin-bottom: 6px;
    font-size: 13px;
    font-weight: 500;
    color: var(--text-secondary);
}

.form-group input,
.form-group select,
.form-group textarea {
    width: 100%;
    padding: 10px 12px;
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    color: var(--text-primary);
    font-family: var(--font);
    font-size: 14px;
    transition: border-color var(--transition);
}

.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus {
    outline: none;
    border-color: var(--accent);
}

.form-group small {
    display: block;
    margin-top: 4px;
    font-size: 11px;
    color: var(--text-muted);
}

.checkbox-label {
    display: flex !important;
    align-items: center;
    gap: 8px;
    cursor: pointer;
}

.checkbox-label input[type="checkbox"] {
    width: auto;
}

/* ===========================
   Alerts
   =========================== */
.alert {
    padding: 10px 14px;
    border-radius: var(--radius);
    font-size: 13px;
    margin-bottom: 16px;
}

.alert-error {
    background: rgba(231, 76, 60, 0.15);
    color: #e74c3c;
    border: 1px solid rgba(231, 76, 60, 0.3);
}

.alert-success {
    background: rgba(46, 204, 113, 0.15);
    color: #2ecc71;
    border: 1px solid rgba(46, 204, 113, 0.3);
}

/* ===========================
   Badge
   =========================== */
.badge {
    display: inline-block;
    padding: 2px 8px;
    border-radius: 20px;
    font-size: 10px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.badge-admin {
    background: var(--accent-light);
    color: var(--accent);
}

.badge-active {
    background: rgba(46, 204, 113, 0.15);
    color: var(--success);
}

.badge-inactive {
    background: rgba(231, 76, 60, 0.15);
    color: var(--danger);
}

/* ===========================
   Auth Pages
   =========================== */
.auth-body {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    min-height: 100dvh;
    overflow: auto;
    background: linear-gradient(135deg, var(--bg-primary) 0%, #1a1040 100%);
}

.auth-container {
    width: 100%;
    max-width: 420px;
    padding: 20px;
}

.auth-card {
    background: var(--bg-secondary);
    border-radius: var(--radius-lg);
    padding: 32px;
    box-shadow: var(--shadow);
    border: 1px solid var(--border);
    position: relative;
}

.auth-header {
    text-align: center;
    margin-bottom: 24px;
}

.auth-logo {
    font-size: 48px;
    margin-bottom: 8px;
}

.auth-header h1 {
    font-size: 24px;
    font-weight: 700;
    margin-bottom: 4px;
}

.auth-header p {
    color: var(--text-secondary);
    font-size: 13px;
}

.auth-tabs {
    display: flex;
    gap: 0;
    margin-bottom: 20px;
    background: var(--bg-tertiary);
    border-radius: var(--radius);
    padding: 3px;
}

.auth-tab {
    flex: 1;
    padding: 8px;
    border: none;
    background: transparent;
    color: var(--text-secondary);
    font-family: var(--font);
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    border-radius: 6px;
    transition: all var(--transition);
}

.auth-tab.active {
    background: var(--accent);
    color: #fff;
}

/* ===========================
   App Layout (Chat)
   =========================== */
.app-container {
    display: flex;
    height: 100vh;
    height: 100dvh;
}

/* Sidebar */
.sidebar {
    width: var(--sidebar-width);
    min-width: var(--sidebar-width);
    background: var(--bg-secondary);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.sidebar-header {
    padding: 16px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    border-bottom: 1px solid var(--border);
}

.logo {
    font-size: 16px;
    font-weight: 700;
}

.sidebar-conversations {
    flex: 1;
    overflow-y: auto;
    padding: 8px;
}

.sidebar-explorer {
    border-top: 1px solid var(--border);
    padding: 10px 8px;
    max-height: 38vh;
    overflow-y: auto;
}

.explorer-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 8px;
}

.explorer-header h3 {
    font-size: 12px;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.4px;
}

.explorer-list {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.explorer-empty {
    font-size: 12px;
    color: var(--text-muted);
    padding: 6px;
}

.explorer-chat {
    background: var(--bg-primary);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 6px;
}

.explorer-chat-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    cursor: pointer;
    list-style: none;
    gap: 8px;
}

.explorer-chat-header::-webkit-details-marker {
    display: none;
}

.explorer-chat-title {
    font-size: 12px;
    font-weight: 600;
    color: var(--text-primary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.explorer-chat-meta {
    font-size: 11px;
    color: var(--text-muted);
}

.explorer-download-btn,
.explorer-ftp-btn {
    margin-top: 6px;
    width: 100%;
}

.ftp-browse-item:hover {
    background: var(--bg-hover) !important;
}

.explorer-files {
    margin-top: 6px;
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.explorer-file-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    border: 1px solid var(--border);
    border-radius: 6px;
    background: var(--bg-secondary);
    color: var(--text-primary);
    padding: 6px 8px;
    cursor: pointer;
    text-align: left;
}

.explorer-file-item:hover {
    background: var(--bg-hover);
    border-color: var(--border-light);
}

.explorer-file-name {
    font-size: 12px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    max-width: 70%;
}

.explorer-file-lang {
    font-size: 10px;
    color: var(--text-muted);
    text-transform: uppercase;
}

/* Folder tree styles (shared by explorer and pages panel) */
.folder-tree-node {
    margin: 0;
}

.folder-tree-node > summary {
    list-style: none;
}

.folder-tree-node > summary::-webkit-details-marker {
    display: none;
}

.folder-tree-header {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 4px 8px;
    cursor: pointer;
    border-radius: var(--radius);
    font-size: 12px;
    user-select: none;
    color: var(--text-primary);
}

.folder-tree-header:hover {
    background: var(--bg-hover);
}

.folder-tree-icon {
    font-size: 14px;
    flex-shrink: 0;
    transition: transform 0.15s ease;
}

.folder-tree-node:not([open]) > .folder-tree-header .folder-tree-icon {
    transform: rotate(-90deg);
}

.folder-tree-name {
    font-weight: 500;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.folder-tree-children {
    display: flex;
    flex-direction: column;
    gap: 1px;
}

.conv-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    padding: 10px 12px;
    border-radius: var(--radius);
    cursor: pointer;
    font-size: 13px;
    color: var(--text-secondary);
    transition: all var(--transition);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    margin-bottom: 2px;
}

.conv-item-title {
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.conv-item-streaming {
    flex-shrink: 0;
    font-size: 10px;
    font-weight: 700;
    letter-spacing: 0.02em;
    text-transform: uppercase;
    color: var(--accent);
    background: var(--accent-light);
    border: 1px solid var(--accent-light);
    border-radius: 999px;
    padding: 2px 7px;
    animation: convLoadingPulse 1.4s ease-in-out infinite;
}

.conv-item.active .conv-item-streaming {
    color: var(--accent);
    background: rgba(255, 255, 255, 0.7);
}

@keyframes convLoadingPulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.58; }
}

.conv-item:hover {
    background: var(--bg-hover);
    color: var(--text-primary);
}

.conv-item.active {
    background: var(--accent-light);
    color: var(--accent);
}

.sidebar-footer {
    padding: 12px 16px;
    border-top: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.user-info {
    display: flex;
    align-items: center;
    gap: 8px;
}

.user-avatar {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    background: var(--accent);
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 12px;
    font-weight: 600;
}

.user-name {
    font-size: 13px;
    font-weight: 500;
}

.user-actions {
    display: flex;
    gap: 6px;
    flex-wrap: wrap;
}

.sidebar-toggle {
    display: none;
    position: fixed;
    top: 12px;
    left: 12px;
    z-index: 100;
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    color: var(--text-primary);
    font-size: 20px;
    padding: 6px 10px;
    border-radius: var(--radius);
    cursor: pointer;
}

/* Main Content */
.main-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.chat-header {
    padding: 12px 20px;
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    min-height: 52px;
}

.chat-header h2 {
    font-size: 15px;
    font-weight: 600;
}

.chat-actions {
    display: flex;
    gap: 6px;
}

/* ===========================
   Split View
   =========================== */
.split-wrapper {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.split-left {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    min-width: 0;
}

.split-right {
    display: none;
}

/* Active split mode on large screens */
.split-active .split-wrapper {
    flex-direction: row;
}

.split-active .split-left {
    flex: 1 1 50%;
    border-right: 1px solid var(--border);
}

.split-active .split-right {
    display: flex;
    flex-direction: column;
    flex: 1 1 50%;
    min-width: 0;
    overflow: hidden;
}

.split-right-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 16px;
    border-bottom: 1px solid var(--border);
    background: var(--bg-secondary);
    flex-shrink: 0;
}

.split-right-header h3 {
    margin: 0;
    font-size: 14px;
    font-weight: 600;
    color: var(--text-primary);
}

.split-right-actions {
    display: flex;
    gap: 6px;
}

.split-right-content {
    flex: 1;
    overflow-y: auto;
    padding: 0;
    display: flex;
    flex-direction: column;
    gap: 0;
}

.split-right-empty {
    color: var(--text-secondary);
    text-align: center;
    padding: 40px 20px;
    font-size: 13px;
}

.split-loading {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 12px 16px;
    color: var(--accent);
    font-size: 13px;
    background: var(--bg-secondary);
    border-bottom: 1px solid var(--border);
    animation: splitLoadingPulse 2s ease-in-out infinite;
}

.split-loading-badge {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    font-size: 12px;
    font-weight: 400;
    color: var(--accent);
    animation: splitLoadingPulse 2s ease-in-out infinite;
}

@keyframes splitLoadingPulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.6; }
}

.split-code-card {
    background: var(--bg-secondary);
    border-bottom: 1px solid var(--border);
    border-radius: 0;
    overflow: visible;
    display: flex;
    flex-direction: column;
    flex-shrink: 0;
}

.split-code-card-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 4px 12px;
    background: var(--bg-tertiary, var(--bg-hover));
    border-top: 1px solid var(--border);
    border-bottom: 1px solid var(--border);
    font-size: 12px;
    color: var(--text-secondary);
    flex-shrink: 0;
}

.split-code-card-lang {
    font-weight: 600;
    text-transform: uppercase;
    font-size: 11px;
}

.split-code-card-actions {
    display: flex;
    gap: 4px;
}

.split-code-card-actions button {
    background: none;
    border: none;
    color: var(--text-secondary);
    cursor: pointer;
    padding: 2px 6px;
    border-radius: var(--radius);
    font-size: 12px;
}

.split-code-card-actions button:hover {
    background: var(--bg-hover);
    color: var(--text-primary);
}

.split-code-card pre {
    margin: 0;
    padding: 12px;
    overflow-x: auto;
    overflow-y: visible;
    font-size: 13px;
    line-height: 1.5;
    max-height: none;
}

.split-code-card pre code {
    font-family: 'SF Mono', 'Cascadia Code', 'Consolas', monospace;
    white-space: pre;
}

/* Hide split button on small screens */
@media (max-width: 1199px) {
    #splitViewBtn {
        display: none !important;
    }
    .split-active .split-wrapper {
        flex-direction: column;
    }
    .split-active .split-left {
        border-right: none;
    }
    .split-active .split-right {
        display: none;
    }
}

/* In split mode, hide code blocks from chat (they appear in the right pane) */
.split-active .chat-messages pre {
    display: none;
}

/* Chat Messages */
.chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 20px;
    display: flex;
    flex-direction: column;
    gap: 20px;
}

.welcome-message {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    flex: 1;
    text-align: center;
    padding: 40px 20px;
    color: var(--text-secondary);
}

.welcome-icon {
    font-size: 56px;
    margin-bottom: 16px;
}

.welcome-message h2 {
    font-size: 22px;
    color: var(--text-primary);
    margin-bottom: 8px;
}

.welcome-message p {
    font-size: 14px;
    max-width: 400px;
    margin-bottom: 24px;
}

.welcome-suggestions {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
    max-width: 500px;
}

.suggestion-btn {
    padding: 12px 16px;
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    color: var(--text-secondary);
    font-family: var(--font);
    font-size: 12px;
    cursor: pointer;
    text-align: left;
    transition: all var(--transition);
}

.suggestion-btn:hover {
    border-color: var(--accent);
    color: var(--text-primary);
    background: var(--accent-light);
}

/* Message Bubbles */
.message {
    display: flex;
    gap: 12px;
    max-width: 900px;
    width: 100%;
    margin: 0 auto;
}

.message-avatar {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 14px;
    flex-shrink: 0;
    margin-top: 2px;
}

.message.user .message-avatar {
    background: var(--accent);
    color: #fff;
}

.message.assistant .message-avatar {
    background: var(--bg-tertiary);
    color: var(--accent);
}

.message-content {
    flex: 1;
    min-width: 0;
}

.message-role {
    font-size: 12px;
    font-weight: 600;
    margin-bottom: 4px;
    color: var(--text-secondary);
}

.message-body {
    font-size: 14px;
    line-height: 1.7;
    color: var(--text-primary);
}

.message-body p {
    margin-bottom: 12px;
}

.message-body p:last-child {
    margin-bottom: 0;
}

.message-body ul, .message-body ol {
    margin: 8px 0;
    padding-left: 24px;
}

.message-body li {
    margin-bottom: 4px;
}

.message-body strong {
    color: #fff;
}

.message-body code {
    font-family: var(--font-mono);
    font-size: 13px;
    background: var(--bg-tertiary);
    padding: 2px 6px;
    border-radius: 4px;
    color: #f0c674;
}

.message-body pre {
    margin: 12px 0;
    border-radius: var(--radius);
    overflow: hidden;
    position: relative;
}

.message-body pre code {
    display: block;
    padding: 16px;
    background: var(--bg-input);
    overflow-x: auto;
    font-size: 13px;
    line-height: 1.5;
    color: var(--text-primary);
    border: 1px solid var(--border);
    border-radius: var(--radius);
}

.code-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 6px 12px;
    background: var(--bg-tertiary);
    border: 1px solid var(--border);
    border-bottom: none;
    border-radius: var(--radius) var(--radius) 0 0;
    font-size: 11px;
    color: var(--text-muted);
}

.code-header + code {
    border-radius: 0 0 var(--radius) var(--radius) !important;
}

.code-header-actions {
    display: flex;
    gap: 4px;
    align-items: center;
}

.copy-btn, .save-to-page-btn {
    padding: 2px 8px;
    background: transparent;
    border: 1px solid var(--border);
    border-radius: 4px;
    color: var(--text-muted);
    cursor: pointer;
    font-size: 11px;
    font-family: var(--font);
    transition: all var(--transition);
    white-space: nowrap;
}

.copy-btn:hover, .save-to-page-btn:hover {
    background: var(--bg-hover);
    color: var(--text-primary);
}

.save-to-page-btn:hover {
    border-color: var(--accent);
    color: var(--accent);
}

/* Typing indicator */
.typing-status {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 6px 14px;
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: 18px;
    width: fit-content;
    animation: typingPulse 2s ease-in-out infinite;
}

.typing-label {
    font-size: 13px;
    color: var(--text-secondary);
}

.typing-elapsed {
    font-size: 12px;
    color: var(--text-muted);
    font-variant-numeric: tabular-nums;
    min-width: 24px;
}

@keyframes typingPulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.7; }
}

.typing-indicator {
    display: flex;
    gap: 4px;
    padding: 4px 0;
}

.typing-indicator span {
    width: 8px;
    height: 8px;
    background: var(--accent);
    border-radius: 50%;
    animation: typing 1.4s infinite;
}

.typing-indicator span:nth-child(2) { animation-delay: 0.2s; }
.typing-indicator span:nth-child(3) { animation-delay: 0.4s; }

@keyframes typing {
    0%, 60%, 100% { opacity: 0.3; transform: scale(0.8); }
    30% { opacity: 1; transform: scale(1); }
}

/* Retry overlay */
.retry-overlay {
    display: flex;
    justify-content: center;
    padding: 12px 20px;
    margin: 8px 0;
}

.retry-overlay-content {
    display: inline-flex;
    align-items: center;
    gap: 10px;
    padding: 10px 20px;
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: 20px;
    font-size: 13px;
    color: var(--text-secondary);
    animation: splitLoadingPulse 2s ease-in-out infinite;
}

.retry-text strong {
    color: var(--accent);
}

/* Loading indicators */
@keyframes spin {
    to { transform: rotate(360deg); }
}

.loading-spinner {
    display: inline-block;
    width: 14px;
    height: 14px;
    border: 2px solid var(--border);
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: spin 0.7s linear infinite;
    vertical-align: middle;
}

.loading-spinner-lg {
    display: inline-block;
    width: 28px;
    height: 28px;
    border: 3px solid var(--border);
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: spin 0.7s linear infinite;
}

.sidebar-loading {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 16px;
    color: var(--text-muted);
    font-size: 13px;
    justify-content: center;
}

.chat-loading {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 12px;
    padding: 48px 20px;
    color: var(--text-muted);
    font-size: 14px;
}

/* Chat Input */
.chat-input-container {
    padding: 16px 20px;
    border-top: 1px solid var(--border);
    background: var(--bg-primary);
}

.chat-form {
    max-width: 900px;
    margin: 0 auto;
}

.input-wrapper {
    display: flex;
    align-items: flex-end;
    gap: 8px;
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 8px 12px;
    transition: border-color var(--transition);
    flex-wrap: wrap;
}

.model-select-wrapper {
    flex-shrink: 0;
    width: 100%;
    margin-bottom: 2px;
}

.model-select {
    padding: 4px 8px;
    background: var(--bg-tertiary);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    color: var(--text-secondary);
    font-family: var(--font);
    font-size: 12px;
    cursor: pointer;
    outline: none;
    max-width: 250px;
    transition: all var(--transition);
}

.model-select:hover {
    border-color: var(--accent);
    color: var(--text-primary);
}

.model-select:focus {
    border-color: var(--accent);
}

.provider-select {
    padding: 6px 8px;
    background: var(--bg-tertiary);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    color: var(--text-secondary);
    font-family: var(--font);
    font-size: 12px;
    cursor: pointer;
    outline: none;
    flex-shrink: 0;
    min-width: 80px;
    transition: all var(--transition);
}

.provider-select:hover {
    border-color: var(--accent);
    color: var(--text-primary);
}

.provider-select:focus {
    border-color: var(--accent);
}

.input-wrapper:focus-within {
    border-color: var(--accent);
}

.input-wrapper textarea {
    flex: 1;
    border: none;
    background: transparent;
    color: var(--text-primary);
    font-family: var(--font);
    font-size: 14px;
    resize: none;
    outline: none;
    max-height: 150px;
    line-height: 1.5;
    padding: 4px 0;
}

.send-btn {
    width: 36px;
    height: 36px;
    border: none;
    background: var(--accent);
    color: #fff;
    border-radius: var(--radius);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: background var(--transition);
}

.send-btn:hover:not(:disabled) { background: var(--accent-hover); }
.send-btn:disabled { opacity: 0.4; cursor: not-allowed; }

.consistency-check-btn {
    width: 36px;
    height: 36px;
    border: 1px solid var(--border);
    background: transparent;
    color: var(--text-muted);
    border-radius: var(--radius);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    font-size: 16px;
    transition: background var(--transition), color var(--transition), border-color var(--transition);
}
.consistency-check-btn:hover:not(:disabled) {
    background: var(--bg-hover);
    color: var(--text);
    border-color: var(--accent);
}
.consistency-check-btn:disabled { opacity: 0.4; cursor: not-allowed; }

.cancel-response-btn {
    width: 36px;
    height: 36px;
    border: 1px solid #d95c5c;
    background: rgba(217, 92, 92, 0.1);
    color: #d95c5c;
    border-radius: var(--radius);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    font-size: 16px;
    transition: background var(--transition), border-color var(--transition);
}

.cancel-response-btn:hover:not(:disabled) {
    background: rgba(217, 92, 92, 0.2);
    border-color: #c74f4f;
}

.cancel-response-btn:disabled { opacity: 0.4; cursor: not-allowed; }

.regenerate-btn {
    width: 36px;
    height: 36px;
    border: 1px solid var(--border);
    background: transparent;
    color: var(--text-muted);
    border-radius: var(--radius);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    font-size: 15px;
    transition: background var(--transition), color var(--transition), border-color var(--transition);
}

.regenerate-btn:hover:not(:disabled) {
    background: var(--bg-hover);
    color: var(--text);
    border-color: var(--accent);
}

.regenerate-btn:disabled { opacity: 0.4; cursor: not-allowed; }

.input-hint {
    text-align: center;
    font-size: 11px;
    color: var(--text-muted);
    margin-top: 8px;
}

/* ===========================
   Pages/Files Panel
   =========================== */
.pages-toggle-bar {
    margin-bottom: 8px;
}

.pages-toggle-btn {
    font-size: 12px;
}

.pages-panel {
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    margin-bottom: 10px;
    max-height: 50vh;
    overflow-y: auto;
}

.pages-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 14px;
    border-bottom: 1px solid var(--border);
    background: var(--bg-tertiary, var(--bg-hover));
}

.pages-header h3 {
    margin: 0;
    font-size: 13px;
    color: var(--text-primary);
}

.pages-count {
    color: var(--text-muted);
    font-weight: normal;
}

.pages-actions {
    display: flex;
    gap: 6px;
}

.pages-tabs {
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
    padding: 8px 10px;
    max-height: 200px;
    overflow-y: auto;
}

.pages-empty {
    color: var(--text-muted);
    font-size: 12px;
    padding: 4px;
}

.page-tab {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 5px 10px;
    background: var(--bg-primary);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    cursor: pointer;
    font-size: 12px;
    transition: all var(--transition);
}

.page-tab:hover {
    border-color: var(--accent);
    background: var(--bg-hover);
}

.page-tab.active {
    border-color: var(--accent);
    background: rgba(59, 130, 246, 0.1);
}

.page-tab-name {
    color: var(--text-primary);
    font-weight: 500;
}

.page-tab-lang {
    color: var(--text-muted);
    font-size: 10px;
}

.pages-editor {
    padding: 10px 14px;
    border-top: 1px solid var(--border);
}

.page-editor-header {
    display: flex;
    gap: 8px;
    margin-bottom: 8px;
}

.page-filename-input {
    flex: 1;
    padding: 6px 10px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--bg-primary);
    color: var(--text-primary);
    font-family: var(--font-mono, monospace);
    font-size: 13px;
    outline: none;
}

.page-filename-input:focus {
    border-color: var(--accent);
}

.page-language-select {
    padding: 6px 10px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--bg-primary);
    color: var(--text-primary);
    font-size: 12px;
    outline: none;
    min-width: 110px;
}

.page-content-textarea {
    width: 100%;
    padding: 10px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--bg-primary);
    color: var(--text-primary);
    font-family: var(--font-mono, 'Courier New', monospace);
    font-size: 13px;
    line-height: 1.5;
    resize: vertical;
    outline: none;
    tab-size: 4;
    box-sizing: border-box;
}

.page-content-textarea:focus {
    border-color: var(--accent);
}

/* Code View (highlighted read-only view) */
.page-code-view {
    width: 100%;
    max-height: 60vh;
    min-height: 200px;
    overflow: auto;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    margin: 0;
    background: var(--bg-primary);
    font-size: 13px;
    line-height: 1.5;
    box-sizing: border-box;
}

.page-code-view code {
    display: block;
    padding: 10px;
    font-family: var(--font-mono, 'Courier New', monospace);
    font-size: 13px;
    line-height: 1.5;
    tab-size: 4;
    white-space: pre;
    overflow-x: auto;
}

.page-content-flash {
    animation: flashReload 0.6s ease;
}

@keyframes flashReload {
    0% { background: rgba(108, 92, 231, 0.25); }
    100% { background: var(--bg-primary); }
}

.page-editor-actions {
    display: flex;
    gap: 8px;
    margin-top: 8px;
}

/* Version History Panel */
.page-versions-panel {
    margin-top: 10px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--bg-secondary);
    max-height: 250px;
    display: flex;
    flex-direction: column;
}

.page-versions-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 8px 12px;
    border-bottom: 1px solid var(--border);
}

.page-versions-header h4 {
    margin: 0;
    font-size: 13px;
    color: var(--text-primary);
}

.page-versions-list {
    overflow-y: auto;
    flex: 1;
}

.page-version-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 8px 12px;
    border-bottom: 1px solid var(--border);
    gap: 8px;
}

.page-version-item:last-child {
    border-bottom: none;
}

.page-version-item:hover {
    background: var(--bg-hover);
}

.page-version-info {
    display: flex;
    flex-direction: column;
    gap: 2px;
    min-width: 0;
    flex: 1;
}

.page-version-date {
    font-size: 12px;
    color: var(--text-primary);
}

.page-version-by {
    font-size: 11px;
    color: var(--text-secondary);
}

.page-version-file {
    font-size: 11px;
    color: var(--text-muted);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.page-version-actions {
    display: flex;
    gap: 4px;
    flex-shrink: 0;
}

/* ===========================
   Page Documentation Panel
   =========================== */
.page-docs-panel {
    margin-top: 10px;
    border: 1px solid var(--accent);
    border-radius: var(--radius);
    background: var(--bg-secondary);
    max-height: 400px;
    display: flex;
    flex-direction: column;
}

.page-docs-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 8px 12px;
    border-bottom: 1px solid var(--border);
    background: color-mix(in srgb, var(--accent) 8%, transparent);
}

.page-docs-header h4 {
    margin: 0;
    font-size: 13px;
    color: var(--text-primary);
}

.page-docs-actions {
    display: flex;
    gap: 4px;
    align-items: center;
}

.page-docs-content {
    overflow-y: auto;
    flex: 1;
    padding: 12px 16px;
}

.page-docs-rendered {
    font-size: 13px;
    line-height: 1.6;
    color: var(--text-primary);
}

.page-docs-rendered h1,
.page-docs-rendered h2,
.page-docs-rendered h3,
.page-docs-rendered h4 {
    margin-top: 16px;
    margin-bottom: 8px;
    color: var(--text-primary);
}

.page-docs-rendered h1:first-child,
.page-docs-rendered h2:first-child,
.page-docs-rendered h3:first-child {
    margin-top: 0;
}

.page-docs-rendered ul,
.page-docs-rendered ol {
    padding-left: 20px;
    margin: 8px 0;
}

.page-docs-rendered li {
    margin-bottom: 4px;
}

.page-docs-rendered code {
    background: var(--bg-primary);
    padding: 2px 6px;
    border-radius: 4px;
    font-size: 12px;
}

.page-docs-rendered pre {
    background: var(--bg-primary);
    border-radius: var(--radius);
    padding: 12px;
    overflow-x: auto;
    margin: 8px 0;
}

.page-docs-rendered pre code {
    background: none;
    padding: 0;
}

.page-docs-meta {
    font-size: 11px;
    color: var(--text-secondary);
    margin-bottom: 10px;
    padding-bottom: 8px;
    border-bottom: 1px solid var(--border);
}

.page-docs-empty,
.page-docs-error {
    font-size: 13px;
    color: var(--text-secondary);
    padding: 8px 0;
}

.page-docs-error {
    color: var(--danger);
}

.agent-docs-notification {
    border-left-color: var(--accent);
}

.agent-docs-hint {
    font-size: 12px;
    color: var(--text-secondary);
    margin-top: 4px;
    font-style: italic;
}

.docs-generating {
    opacity: 0.85;
    border-left-color: var(--warning, #f0ad4e);
}

.docs-spinner {
    display: inline-block;
    width: 14px;
    height: 14px;
    border: 2px solid var(--text-secondary);
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: docs-spin 0.8s linear infinite;
    vertical-align: middle;
    margin-right: 6px;
}

@keyframes docs-spin {
    to { transform: rotate(360deg); }
}

/* ===========================
   Admin Layout
   =========================== */
.admin-container {
    display: flex;
    height: 100vh;
    height: 100dvh;
}

.admin-sidebar {
    width: var(--sidebar-width);
    min-width: var(--sidebar-width);
    background: var(--bg-secondary);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
}

.admin-nav {
    flex: 1;
    padding: 8px;
}

.admin-nav-item {
    display: block;
    padding: 10px 14px;
    border-radius: var(--radius);
    color: var(--text-secondary);
    text-decoration: none;
    font-size: 13px;
    transition: all var(--transition);
    margin-bottom: 2px;
}

.admin-nav-item:hover {
    background: var(--bg-hover);
    color: var(--text-primary);
}

.admin-nav-item.active {
    background: var(--accent-light);
    color: var(--accent);
}

.admin-main {
    flex: 1;
    overflow-y: auto;
    padding: 24px;
}

.admin-section h2 {
    font-size: 20px;
    margin-bottom: 20px;
}

.section-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
}

/* Stats Grid */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 16px;
    margin-bottom: 24px;
}

.stat-card {
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 20px;
    text-align: center;
}

.stat-value {
    font-size: 32px;
    font-weight: 700;
    color: var(--accent);
    margin-bottom: 4px;
}

.stat-label {
    font-size: 13px;
    color: var(--text-secondary);
}

/* Data Table */
.table-container {
    overflow-x: auto;
}

.data-table {
    width: 100%;
    border-collapse: collapse;
    background: var(--bg-secondary);
    border-radius: var(--radius-lg);
    overflow: hidden;
    border: 1px solid var(--border);
}

.data-table th,
.data-table td {
    padding: 10px 14px;
    text-align: left;
    font-size: 13px;
    border-bottom: 1px solid var(--border);
}

.data-table th {
    background: var(--bg-tertiary);
    font-weight: 600;
    color: var(--text-secondary);
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.data-table tr:hover {
    background: var(--bg-hover);
}

.data-table .actions {
    display: flex;
    gap: 4px;
}

/* Modal */
.modal {
    position: fixed;
    inset: 0;
    z-index: 1000;
    display: flex;
    align-items: center;
    justify-content: center;
}

.modal-overlay {
    position: absolute;
    inset: 0;
    background: rgba(0, 0, 0, 0.6);
}

.modal-content {
    position: relative;
    background: var(--bg-secondary);
    border-radius: var(--radius-lg);
    padding: 24px;
    width: 90%;
    max-width: 480px;
    box-shadow: var(--shadow);
    border: 1px solid var(--border);
}

.modal-sm { max-width: 360px; }

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
}

.modal-header h3 {
    font-size: 16px;
}

.modal-close {
    background: none;
    border: none;
    color: var(--text-muted);
    font-size: 24px;
    cursor: pointer;
    padding: 0;
    line-height: 1;
}

.modal-close:hover { color: var(--text-primary); }

.modal-actions {
    display: flex;
    justify-content: flex-end;
    gap: 8px;
    margin-top: 20px;
}

/* ===========================
   Setup Wizard
   =========================== */
.setup-steps {
    display: flex;
    gap: 0;
    margin-bottom: 24px;
    background: var(--bg-tertiary);
    border-radius: var(--radius);
    padding: 3px;
}

.setup-step {
    flex: 1;
    padding: 8px;
    text-align: center;
    font-size: 12px;
    font-weight: 500;
    color: var(--text-muted);
    border-radius: 6px;
    transition: all var(--transition);
}

.setup-step.active {
    background: var(--accent);
    color: #fff;
}

.setup-step.done {
    color: var(--success);
}

.setup-step span {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 20px;
    height: 20px;
    border-radius: 50%;
    background: var(--bg-hover);
    font-size: 11px;
    margin-right: 4px;
}

.setup-step.active span {
    background: rgba(255,255,255,0.2);
}

.setup-step.done span {
    background: rgba(46, 204, 113, 0.2);
}

.setup-panel h3 {
    font-size: 15px;
    margin-bottom: 16px;
    color: var(--text-primary);
}

.setup-nav {
    display: flex;
    justify-content: space-between;
    gap: 8px;
    margin-top: 8px;
}

/* ===========================
   Settings Panel (Admin)
   =========================== */
.settings-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(360px, 1fr));
    gap: 20px;
    margin-bottom: 20px;
}

.settings-card {
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 24px;
}

.settings-card h3 {
    font-size: 15px;
    margin-bottom: 16px;
    padding-bottom: 12px;
    border-bottom: 1px solid var(--border);
}

/* Toggle Switch */
.toggle-switch {
    position: relative;
    display: inline-block;
    width: 40px;
    height: 22px;
    flex-shrink: 0;
}
.toggle-switch input {
    opacity: 0;
    width: 0;
    height: 0;
}
.toggle-slider {
    position: absolute;
    cursor: pointer;
    inset: 0;
    background: var(--bg-tertiary, #555);
    border-radius: 22px;
    transition: background 0.2s;
}
.toggle-slider::before {
    content: "";
    position: absolute;
    width: 16px;
    height: 16px;
    left: 3px;
    bottom: 3px;
    background: #fff;
    border-radius: 50%;
    transition: transform 0.2s;
}
.toggle-switch input:checked + .toggle-slider {
    background: var(--accent);
}
.toggle-switch input:checked + .toggle-slider::before {
    transform: translateX(18px);
}

.settings-actions {
    display: flex;
    align-items: center;
    gap: 16px;
}

/* Active Models Panel */
.active-models-panel {
    border: 1px solid var(--border);
    border-radius: 8px;
    margin-top: 4px;
    overflow: hidden;
    background: var(--bg-primary);
}

.active-models-toolbar {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 10px;
    background: var(--bg-secondary);
    border-bottom: 1px solid var(--border);
    flex-wrap: wrap;
}

.model-filter-input {
    flex: 1;
    min-width: 120px;
    padding: 5px 10px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--bg-primary);
    color: var(--text-primary);
    font-size: 13px;
    outline: none;
    font-family: var(--font);
}

.model-filter-input:focus {
    border-color: var(--accent);
}

.active-models-actions {
    display: flex;
    align-items: center;
    gap: 6px;
}

.active-models-count {
    font-size: 12px;
    color: var(--text-muted);
    white-space: nowrap;
}

.active-models-list {
    max-height: 320px;
    overflow-y: auto;
    padding: 4px 0;
}

.active-models-empty {
    color: var(--text-secondary);
    padding: 16px;
    text-align: center;
    font-size: 13px;
}

.selected-models-hint {
    color: var(--text-secondary);
    font-size: 12px;
    padding: 8px 12px 4px;
}

.selected-models-tags {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    padding: 8px 12px 12px;
}

.selected-model-tag {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    background: var(--bg-tertiary, var(--bg-secondary));
    border: 1px solid var(--border);
    border-radius: 16px;
    padding: 4px 8px 4px 12px;
    font-size: 12px;
    color: var(--text-primary);
    font-family: 'SF Mono', 'Cascadia Code', 'Consolas', monospace;
}

.selected-model-remove {
    background: none;
    border: none;
    color: var(--text-secondary);
    cursor: pointer;
    font-size: 16px;
    line-height: 1;
    padding: 0 2px;
    border-radius: 50%;
}

.selected-model-remove:hover {
    color: var(--danger, #d32f2f);
    background: rgba(211, 47, 47, 0.1);
}

/* Vertical selected models list with max tokens */
.selected-models-list-vertical {
    display: flex;
    flex-direction: column;
    gap: 0;
}

.selected-model-row {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 12px;
    border-bottom: 1px solid var(--border);
    transition: background 0.15s ease;
}

.selected-model-row:last-child {
    border-bottom: none;
}

.selected-model-row:hover {
    background: var(--bg-secondary);
}

.selected-model-name {
    flex: 1;
    font-family: var(--font-mono, 'SF Mono', 'Consolas', monospace);
    font-size: 13px;
    color: var(--text-primary);
    font-weight: 500;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.selected-model-tokens {
    display: flex;
    align-items: center;
    gap: 6px;
    flex-shrink: 0;
}

.selected-model-token-input {
    width: 110px;
    padding: 5px 8px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--bg-primary);
    color: var(--text-primary);
    font-size: 13px;
    font-family: var(--font-mono, 'SF Mono', 'Consolas', monospace);
    text-align: right;
    outline: none;
}

.selected-model-token-input:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 2px rgba(52, 152, 219, 0.15);
}

.selected-model-token-input::placeholder {
    color: var(--text-muted);
    font-family: var(--font);
    font-size: 11px;
}

.selected-model-token-hint {
    font-size: 11px;
    color: var(--text-muted);
    white-space: nowrap;
}

.selected-model-remove-btn {
    padding: 2px 8px;
    font-size: 18px;
    line-height: 1;
    color: var(--text-secondary);
    flex-shrink: 0;
}

.selected-model-remove-btn:hover {
    color: var(--danger, #d32f2f);
    border-color: var(--danger, #d32f2f);
}

@media (max-width: 600px) {
    .selected-model-row {
        flex-wrap: wrap;
        gap: 6px;
    }
    .selected-model-name {
        width: 100%;
        flex: unset;
    }
    .selected-model-tokens {
        flex: 1;
    }
    .selected-model-token-input {
        flex: 1;
        width: auto;
    }
}

.model-group {
    border-bottom: 1px solid var(--border);
}

.model-group:last-child {
    border-bottom: none;
}

.model-group-header {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 8px 12px;
    cursor: pointer;
    font-weight: 600;
    font-size: 13px;
    color: var(--text-primary);
    user-select: none;
    transition: background var(--transition);
}

.model-group-header:hover {
    background: var(--bg-secondary);
}

.model-group-toggle {
    font-size: 10px;
    color: var(--text-muted);
    width: 14px;
    text-align: center;
}

.model-group-count {
    font-weight: 400;
    color: var(--text-muted);
    font-size: 12px;
}

.model-group-items {
    padding: 0 6px 6px 6px;
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
}

.model-item {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 4px 10px;
    border-radius: var(--radius);
    cursor: pointer;
    font-size: 12px;
    color: var(--text-secondary);
    background: var(--bg-secondary);
    border: 1px solid transparent;
    transition: all 0.15s ease;
    user-select: none;
}

.model-item:hover {
    border-color: var(--border);
    color: var(--text-primary);
}

.model-item-active {
    background: rgba(52, 152, 219, 0.12);
    border-color: var(--accent);
    color: var(--accent);
}

.model-item input[type="checkbox"] {
    width: 14px;
    height: 14px;
    accent-color: var(--accent);
    cursor: pointer;
    margin: 0;
}

.model-item-name {
    white-space: nowrap;
    font-family: var(--font-mono, 'SF Mono', 'Consolas', monospace);
}

.settings-hint {
    font-size: 12px;
    color: var(--text-muted);
}

.input-with-badge {
    position: relative;
    display: flex;
    align-items: center;
}

.input-with-badge input {
    flex: 1;
    padding-right: 110px;
}

.field-badge {
    position: absolute;
    right: 8px;
    font-size: 11px;
    padding: 2px 8px;
    border-radius: 4px;
    white-space: nowrap;
    pointer-events: none;
}

.field-badge.badge-active {
    background: rgba(46, 204, 113, 0.12);
    color: var(--success);
}

.field-badge.badge-inactive {
    background: rgba(243, 156, 18, 0.12);
    color: var(--warning);
}

/* ===========================
   Sidebar Backdrop (mobile)
   =========================== */
.sidebar-backdrop {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: 98;
}

.sidebar-backdrop.active {
    display: block;
}

/* ===========================
   Mobile Bottom Navigation
   =========================== */
.mobile-bottom-nav {
    display: none;
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    z-index: 101;
    background: var(--bg-secondary);
    border-top: 1px solid var(--border);
    padding: 2px 0;
    padding-bottom: env(safe-area-inset-bottom, 2px);
    justify-content: space-around;
    align-items: center;
}

.mobile-nav-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 1px;
    padding: 4px 10px;
    font-size: 16px;
    color: var(--text-muted);
    text-decoration: none;
    border: none;
    background: none;
    cursor: pointer;
    font-family: var(--font);
    transition: color var(--transition);
    -webkit-tap-highlight-color: transparent;
}

.mobile-nav-item span {
    font-size: 9px;
    font-weight: 500;
}

.mobile-nav-item.active {
    color: var(--accent);
}

.mobile-nav-item:hover {
    color: var(--text-primary);
}

@media (max-width: 768px) {
    .mobile-bottom-nav {
        display: flex;
    }

    /* Shrink the entire app height so bottom nav never overlaps content */
    .app-container,
    .project-app,
    .admin-container {
        height: calc(100vh - 42px);
        height: calc(100dvh - 42px);
    }

    /* No extra padding needed on containers since height is reduced */

    /* Sidebar footer needs space too when sidebar is open */
    .sidebar-footer {
        padding-bottom: 64px;
    }

    /* Task chat input at bottom */
    .task-chat-input {
        padding-bottom: 60px;
    }

    /* Auth page */
    .auth-body {
        padding-bottom: 20px;
    }

    /* Hide the sidebar toggle button since we have bottom nav menu button */
    .sidebar-toggle {
        display: none;
    }
}

/* ===========================
   Responsive
   =========================== */
@media (max-width: 768px) {
    /* Global mobile scale-down */
    body {
        font-size: 12px;
    }

    .btn {
        padding: 5px 10px;
        font-size: 11px;
        gap: 4px;
    }

    .btn-sm {
        padding: 3px 7px;
        font-size: 10px;
    }

    .form-group label {
        font-size: 11px;
        margin-bottom: 4px;
    }

    .form-group input,
    .form-group select,
    .form-group textarea {
        padding: 7px 9px;
        font-size: 13px;
    }

    .sidebar, .admin-sidebar, .project-sidebar {
        position: fixed;
        left: -100%;
        top: 0;
        bottom: 0;
        z-index: 102;
        transition: left 0.25s ease;
        width: 260px;
        min-width: 260px;
    }

    .sidebar.open, .admin-sidebar.open, .project-sidebar.open {
        left: 0;
    }

    .sidebar-toggle, .admin-sidebar-toggle, .project-sidebar-toggle {
        display: block;
    }

    /* Sidebar internals compact */
    .sidebar-header, .sidebar-footer {
        padding: 8px 12px;
    }

    .logo {
        font-size: 14px;
    }

    .conv-item {
        padding: 7px 10px;
        font-size: 11px;
    }

    .user-avatar {
        width: 24px;
        height: 24px;
        font-size: 10px;
    }

    .user-name {
        font-size: 11px;
    }

    .sidebar-explorer {
        padding: 6px;
        max-height: 30vh;
    }

    .explorer-header h3 {
        font-size: 10px;
    }

    .explorer-chat-title {
        font-size: 10px;
    }

    .explorer-file-name {
        font-size: 10px;
    }

    /* Chat header */
    .chat-header {
        padding: 6px 12px 6px 12px;
        min-height: 40px;
    }

    .chat-header h2 {
        font-size: 12px;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
        max-width: 140px;
    }

    .chat-actions {
        gap: 3px;
    }

    .theme-toggle {
        width: 28px;
        height: 28px;
        font-size: 13px;
    }

    /* Welcome */
    .welcome-message {
        padding: 16px 12px;
    }

    .welcome-icon {
        font-size: 32px;
        margin-bottom: 8px;
    }

    .welcome-message h2 {
        font-size: 16px;
        margin-bottom: 4px;
    }

    .welcome-message p {
        font-size: 11px;
        margin-bottom: 16px;
    }

    .welcome-suggestions {
        grid-template-columns: 1fr;
        max-width: 100%;
        gap: 5px;
    }

    .suggestion-btn {
        padding: 8px 10px;
        font-size: 10px;
    }

    /* Messages */
    .chat-messages {
        padding: 8px 6px;
        gap: 10px;
    }

    .message {
        gap: 6px;
    }

    .message-avatar {
        width: 24px;
        height: 24px;
        font-size: 10px;
    }

    .message-role {
        font-size: 10px;
        margin-bottom: 2px;
    }

    .message-body {
        font-size: 12px;
        line-height: 1.5;
    }

    .message-body p {
        margin-bottom: 8px;
    }

    .message-body ul, .message-body ol {
        padding-left: 16px;
        margin: 4px 0;
    }

    .message-body pre code {
        font-size: 11px;
        padding: 8px;
        line-height: 1.4;
    }

    .code-header {
        font-size: 9px;
        padding: 3px 6px;
    }

    .code-header-actions {
        gap: 2px;
    }

    .copy-btn, .save-to-page-btn {
        font-size: 9px;
        padding: 1px 5px;
    }

    /* Chat Input */
    .chat-input-container {
        padding: 6px 6px 8px;
    }

    .input-wrapper {
        padding: 4px 6px;
        border-radius: var(--radius);
    }

    .input-wrapper textarea {
        font-size: 16px; /* Prevent iOS zoom */
        line-height: 1.4;
    }

    .send-btn {
        width: 30px;
        height: 30px;
    }

    .consistency-check-btn {
        width: 30px;
        height: 30px;
        font-size: 14px;
    }

    .cancel-response-btn,
    .regenerate-btn {
        width: 30px;
        height: 30px;
        font-size: 13px;
    }

    .input-hint {
        font-size: 9px;
        margin-top: 4px;
    }

    /* Pages panel */
    .pages-panel {
        max-height: 35vh;
        border-radius: var(--radius);
        margin-bottom: 4px;
    }

    .pages-header {
        padding: 6px 8px;
        flex-wrap: wrap;
        gap: 4px;
    }

    .pages-header h3 {
        font-size: 11px;
    }

    .pages-actions {
        gap: 3px;
    }

    .pages-tabs {
        padding: 4px 6px;
        gap: 3px;
    }

    .page-tab {
        padding: 3px 7px;
        font-size: 10px;
        gap: 4px;
    }

    .page-editor-header {
        flex-direction: column;
        gap: 4px;
    }

    .page-filename-input {
        font-size: 12px;
        padding: 5px 8px;
    }

    .page-language-select {
        font-size: 11px;
        padding: 5px 8px;
        min-width: 90px;
    }

    .pages-editor {
        padding: 6px 8px;
    }

    .page-content-textarea {
        font-size: 11px;
        min-height: 80px;
        padding: 6px;
    }

    .page-editor-actions {
        flex-wrap: wrap;
        gap: 3px;
    }

    .pages-toggle-btn {
        font-size: 10px;
    }

    /* Sidebar footer */
    .sidebar-footer .user-actions {
        gap: 3px;
    }

    /* Stats */
    .stats-grid {
        grid-template-columns: 1fr 1fr;
        gap: 6px;
    }

    .stat-card {
        padding: 10px;
    }

    .stat-value {
        font-size: 20px;
    }

    .stat-label {
        font-size: 10px;
    }

    /* Settings */
    .settings-grid {
        grid-template-columns: 1fr;
        gap: 12px;
    }

    .settings-card {
        padding: 12px;
    }

    .settings-card h3 {
        font-size: 13px;
        margin-bottom: 10px;
        padding-bottom: 8px;
    }

    .settings-actions {
        flex-direction: column;
        align-items: flex-start;
    }

    .settings-hint {
        font-size: 10px;
    }

    /* Tables */
    .table-container {
        margin: 0 -6px;
    }

    .data-table th,
    .data-table td {
        padding: 5px 4px;
        font-size: 10px;
    }

    .data-table th {
        font-size: 9px;
    }

    .data-table .actions {
        flex-direction: column;
        gap: 2px;
    }

    /* Admin page */
    .admin-main {
        padding: 12px 8px;
    }

    .admin-main .admin-section h2 {
        font-size: 15px;
        margin-bottom: 12px;
    }

    .section-header {
        flex-direction: column;
        align-items: flex-start;
        gap: 6px;
        margin-bottom: 12px;
    }

    /* Modal */
    .modal-content {
        width: 95%;
        padding: 14px;
        max-height: 90vh;
        overflow-y: auto;
    }

    .modal-sm {
        max-width: 95%;
    }

    .modal-header {
        margin-bottom: 12px;
    }

    .modal-header h3 {
        font-size: 13px;
    }

    .modal-actions {
        margin-top: 14px;
        gap: 6px;
    }

    /* Truncated/Donation notices */
    .truncated-notice {
        flex-direction: column;
        padding: 6px 10px;
        font-size: 11px;
    }

    .donation-notice {
        padding: 10px 12px;
        font-size: 11px;
    }

    /* Agent notifications */
    .agent-file-notification {
        padding: 6px 10px;
        font-size: 11px;
    }

    /* Badge */
    .badge {
        font-size: 9px;
        padding: 1px 6px;
    }

    /* Alerts */
    .alert {
        padding: 7px 10px;
        font-size: 11px;
    }
}

/* ===========================
   Theme Toggle
   =========================== */
.theme-toggle {
    background: transparent;
    border: 1px solid var(--border);
    color: var(--text-secondary);
    width: 32px;
    height: 32px;
    border-radius: var(--radius);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 16px;
    transition: all var(--transition);
    flex-shrink: 0;
}

.theme-toggle:hover {
    background: var(--bg-hover);
    color: var(--text-primary);
    border-color: var(--border-light);
}

[data-theme="light"] .message-body strong {
    color: #1a1a2e;
}

[data-theme="light"] .message-body code {
    color: #b45309;
}

[data-theme="light"] .auth-body {
    background: linear-gradient(135deg, #e8e8f0 0%, #d0d0e8 100%);
}

/* ===========================
   Agent File Notifications
   =========================== */
.agent-file-badge {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    color: var(--success);
    font-weight: 600;
    font-size: 12px;
}

.agent-file-notification {
    max-width: 900px;
    width: 100%;
    margin: 0 auto;
    padding: 12px 16px;
    background: var(--accent-light);
    border: 1px solid var(--accent);
    border-radius: var(--radius);
    font-size: 13px;
}

.agent-notification-header {
    font-weight: 600;
    margin-bottom: 6px;
    color: var(--text-primary);
}

.agent-file-notification ul {
    list-style: none;
    padding: 0;
    margin: 0;
}

.agent-file-notification li {
    padding: 2px 0;
    color: var(--text-secondary);
    display: flex;
    align-items: center;
    gap: 6px;
    flex-wrap: wrap;
}

.file-update-badge {
    display: inline-block;
    font-size: 11px;
    padding: 1px 7px;
    border-radius: 8px;
    font-weight: 600;
    line-height: 1.4;
}

.badge-created {
    background: rgba(46, 204, 113, 0.15);
    color: #2ecc71;
}

.badge-edited {
    background: rgba(52, 152, 219, 0.15);
    color: #3498db;
}

.badge-updated {
    background: rgba(52, 152, 219, 0.15);
    color: #3498db;
}

.badge-failed {
    background: rgba(231, 76, 60, 0.15);
    color: #e74c3c;
}

.file-update-failed {
    color: #e74c3c !important;
}

.file-update-partial {
    color: var(--warning, #f39c12) !important;
}

.file-update-rejected {
    color: #e74c3c !important;
}

.badge-rejected {
    background: rgba(231, 76, 60, 0.15);
    color: #e74c3c;
}

/* ===========================
   Diff Review Modal
   =========================== */
.diff-review-modal-content {
    max-width: 95vw;
    width: 1200px;
    max-height: 90vh;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.diff-review-modal-content .modal-header {
    display: flex;
    align-items: center;
    gap: 12px;
    flex-shrink: 0;
}

.diff-review-subtitle {
    font-size: 13px;
    color: var(--text-secondary);
    font-weight: 400;
}

.diff-review-tabs {
    display: flex;
    gap: 4px;
    padding: 8px 0;
    overflow-x: auto;
    flex-shrink: 0;
    border-bottom: 1px solid var(--border);
}

.diff-tab {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 6px 12px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--bg-secondary);
    color: var(--text-primary);
    cursor: pointer;
    font-size: 12px;
    white-space: nowrap;
    transition: all 0.15s;
}

.diff-tab:hover {
    background: var(--bg-tertiary, var(--bg-secondary));
    border-color: var(--accent);
}

.diff-tab.active {
    background: var(--accent-light);
    border-color: var(--accent);
}

.diff-tab-status {
    font-size: 11px;
    line-height: 1;
}

.diff-tab-approved .diff-tab-status {
    color: #2ecc71;
}

.diff-tab-rejected .diff-tab-status {
    color: #e74c3c;
}

.diff-tab-name {
    font-weight: 500;
}

.diff-review-body {
    flex: 1;
    overflow: auto;
    padding: 12px 0;
    min-height: 200px;
}

.diff-file-header {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 8px;
    flex-wrap: wrap;
}

.diff-file-action {
    display: inline-block;
    font-size: 11px;
    padding: 2px 8px;
    border-radius: 8px;
    font-weight: 600;
}

.diff-file-lang {
    color: var(--text-secondary);
    font-size: 12px;
}

.diff-edit-stats {
    font-size: 12px;
    color: var(--text-secondary);
}

.diff-stats {
    font-size: 12px;
    color: var(--text-secondary);
    margin-bottom: 8px;
}

.diff-stats span {
    margin-right: 8px;
}

.diff-table-wrap {
    overflow: auto;
    border: 1px solid var(--border);
    border-radius: var(--radius);
}

.diff-review-table {
    width: 100%;
    border-collapse: collapse;
    font-family: 'Cascadia Code', 'Fira Code', 'JetBrains Mono', monospace;
    font-size: 12px;
    table-layout: fixed;
}

.diff-review-table thead th {
    position: sticky;
    top: 0;
    background: var(--bg-secondary);
    padding: 6px 8px;
    text-align: left;
    font-weight: 600;
    font-size: 11px;
    color: var(--text-secondary);
    border-bottom: 1px solid var(--border);
    z-index: 1;
}

.diff-review-table td {
    padding: 0 8px;
    vertical-align: top;
    border-bottom: 1px solid rgba(255,255,255,0.03);
}

.diff-review-table td pre {
    margin: 0;
    padding: 1px 0;
    white-space: pre-wrap;
    word-break: break-all;
    font-size: 12px;
    font-family: inherit;
    line-height: 1.5;
}

.diff-col-num {
    width: 40px;
    min-width: 40px;
    max-width: 40px;
    text-align: right;
    color: var(--text-secondary);
    font-size: 11px;
    opacity: 0.5;
    user-select: none;
    padding-right: 4px !important;
}

.diff-line-add {
    background: rgba(46, 204, 113, 0.08);
}

.diff-line-add td:nth-child(4) pre {
    color: #2ecc71;
}

.diff-line-remove {
    background: rgba(231, 76, 60, 0.08);
}

.diff-line-remove td:nth-child(2) pre {
    color: #e74c3c;
}

.diff-line-equal td pre {
    color: var(--text-secondary);
}

.diff-new-file-content {
    border: 1px solid var(--border);
    border-radius: var(--radius);
    overflow: auto;
    max-height: 60vh;
    background: var(--bg-secondary);
}

.diff-new-file-content pre {
    margin: 0;
    padding: 8px;
    font-size: 12px;
    font-family: 'Cascadia Code', 'Fira Code', 'JetBrains Mono', monospace;
    line-height: 1.6;
}

.diff-new-file-content code {
    display: block;
}

.diff-line-num {
    display: inline-block;
    width: 40px;
    text-align: right;
    padding-right: 12px;
    color: var(--text-secondary);
    opacity: 0.4;
    user-select: none;
    font-size: 11px;
}

.diff-review-actions {
    flex-shrink: 0;
    display: flex;
    gap: 8px;
    justify-content: flex-end;
    padding-top: 12px;
    border-top: 1px solid var(--border);
}

.diff-review-actions .btn-danger {
    margin-right: auto;
}

/* Light theme overrides for diff */
[data-theme="light"] .diff-line-add {
    background: rgba(46, 204, 113, 0.12);
}

[data-theme="light"] .diff-line-remove {
    background: rgba(231, 76, 60, 0.1);
}

[data-theme="light"] .diff-line-add td:nth-child(4) pre {
    color: #27ae60;
}

[data-theme="light"] .diff-line-remove td:nth-child(2) pre {
    color: #c0392b;
}

[data-theme="light"] .diff-line-equal td pre {
    color: var(--text-secondary);
}

@media (max-width: 768px) {
    .diff-review-modal-content {
        width: 100%;
        max-width: 100%;
        max-height: 100vh;
        border-radius: 0;
        padding: 12px;
    }
    .diff-review-tabs {
        flex-wrap: nowrap;
        gap: 4px;
    }
    .diff-review-actions {
        flex-wrap: wrap;
    }
    .diff-review-actions .btn {
        font-size: 12px;
        padding: 6px 10px;
    }
    .diff-review-table {
        font-size: 11px;
    }
    .diff-col-num {
        width: 30px;
        min-width: 30px;
        max-width: 30px;
    }
}

/* ===========================
   Code Review / Consistency Notification
   =========================== */
.consistency-notification {
    max-width: 900px;
    width: 100%;
    margin: 0 auto;
    padding: 14px 18px;
    border: 1px solid rgba(155, 89, 182, 0.25);
    border-radius: var(--radius, 8px);
    background: rgba(155, 89, 182, 0.04);
    font-size: 13px;
}

.consistency-notification .agent-notification-header {
    font-size: 14px;
    font-weight: 600;
    margin-bottom: 10px;
    padding-bottom: 8px;
    border-bottom: 1px solid rgba(155, 89, 182, 0.15);
    color: #b07cc8;
    display: flex;
    align-items: center;
    gap: 6px;
}

.consistency-notification ul {
    list-style: none;
    padding: 0;
    margin: 0;
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.consistency-notification li {
    padding: 5px 10px;
    border-radius: 5px;
    font-size: 12.5px;
    line-height: 1.5;
    transition: background 0.15s;
}

.consistency-notification li:hover {
    background: rgba(255, 255, 255, 0.03);
}

.consistency-notification li strong {
    font-weight: 600;
}

.consistency-ok {
    border-color: rgba(46, 204, 113, 0.3);
    background: rgba(46, 204, 113, 0.05);
}

.consistency-ok .agent-notification-header {
    color: #2ecc71;
    border-bottom-color: rgba(46, 204, 113, 0.15);
}

.consistency-warning {
    border-color: rgba(243, 156, 18, 0.3);
    background: rgba(243, 156, 18, 0.05);
}

.consistency-error {
    color: #e74c3c !important;
    background: rgba(231, 76, 60, 0.06);
    border-left: 3px solid rgba(231, 76, 60, 0.5);
}

.consistency-warn {
    color: var(--warning, #f39c12) !important;
    background: rgba(243, 156, 18, 0.05);
    border-left: 3px solid rgba(243, 156, 18, 0.35);
}

.badge-ok {
    background: rgba(46, 204, 113, 0.15);
    color: #2ecc71;
}

/* AI Consistency Check */
.ai-consistency {
    border-color: rgba(155, 89, 182, 0.25);
    background: rgba(155, 89, 182, 0.04);
}

.ai-consistency .agent-notification-header {
    color: #b07cc8;
    border-bottom-color: rgba(155, 89, 182, 0.15);
}

/* AI Consistency Busy Overlay */
.ai-consistency-spinner {
    border-top-color: #9b59b6 !important;
}

.ai-consistency-text {
    color: #9b59b6 !important;
}

.processing-bubble {
    animation: aiBusyFadeIn 0.3s ease;
}

.processing-body {
    display: flex;
    align-items: center;
    gap: 18px;
    padding: 20px 24px !important;
}

.processing-spinner {
    display: inline-block;
    width: 48px;
    height: 48px;
    border: 4px solid var(--border);
    border-top-color: #3498db;
    border-radius: 50%;
    animation: spin 0.7s linear infinite;
    flex-shrink: 0;
}

.processing-text {
    font-size: 16px;
    color: #3498db;
    font-weight: 500;
}

@keyframes aiBusyFadeIn {
    from { opacity: 0; transform: translateY(10px); }
    to { opacity: 1; transform: translateY(0); }
}

/* AI Auto-Fix */
.ai-fix-applied {
    border-color: rgba(39, 174, 96, 0.3);
    background: rgba(39, 174, 96, 0.04);
}

.ai-fix-applied .agent-notification-header {
    color: #27ae60;
    border-bottom-color: rgba(39, 174, 96, 0.15);
}

.ai-fix-label {
    color: #27ae60;
    font-style: italic;
    font-size: 11.5px;
    margin-left: 4px;
    opacity: 0.85;
}

.ai-fix-success {
    color: #27ae60 !important;
    font-weight: 500;
    background: rgba(39, 174, 96, 0.06);
    border-left: 3px solid rgba(39, 174, 96, 0.4);
}

/* AI Fix Diff View */
.ai-fix-diff-container {
    list-style: none;
    margin-top: 8px;
    padding: 0 !important;
    border-left: none !important;
    background: none !important;
}

.ai-fix-diff-toggle {
    background: rgba(155, 89, 182, 0.08);
    border: 1px solid rgba(155, 89, 182, 0.25);
    color: #b07cc8;
    padding: 5px 14px;
    border-radius: 6px;
    cursor: pointer;
    font-size: 12px;
    font-weight: 500;
    transition: all 0.15s;
    display: inline-flex;
    align-items: center;
    gap: 4px;
}

.ai-fix-diff-toggle:hover {
    background: rgba(155, 89, 182, 0.15);
    border-color: rgba(155, 89, 182, 0.4);
}

.ai-fix-diff-block {
    display: none;
    margin-top: 8px;
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 8px;
    overflow: hidden;
    max-height: 600px;
    overflow-y: auto;
    background: var(--bg-code, #1a1a2e);
}

.ai-fix-diff-block.open {
    display: block;
}

.sr-hunk {
    border-bottom: 1px solid rgba(255, 255, 255, 0.06);
}

.sr-hunk:last-child {
    border-bottom: none;
}

.sr-header {
    font-family: 'Fira Code', 'Consolas', 'Monaco', monospace;
    font-size: 10px;
    font-weight: 700;
    padding: 4px 14px;
    user-select: none;
    letter-spacing: 0.5px;
    text-transform: uppercase;
}

.sr-search-header {
    color: #ff6b6b;
    background: rgba(255, 107, 107, 0.1);
    border-bottom: 1px solid rgba(255, 107, 107, 0.1);
}

.sr-divider {
    color: rgba(255, 255, 255, 0.15);
    text-align: center;
    padding: 2px 14px;
    font-size: 10px;
    background: rgba(255, 255, 255, 0.02);
}

.sr-replace-header {
    color: #51cf66;
    background: rgba(81, 207, 102, 0.1);
    border-top: 1px solid rgba(81, 207, 102, 0.1);
}

.sr-code {
    font-family: 'Fira Code', 'Consolas', 'Monaco', monospace;
    font-size: 12px;
    line-height: 1.6;
    padding: 8px 16px;
    margin: 0;
    white-space: pre;
    overflow-x: auto;
    tab-size: 4;
}

.sr-search-code {
    background: rgba(255, 107, 107, 0.05);
    color: #ffa0a0;
    border-left: 3px solid rgba(255, 107, 107, 0.3);
}

.sr-replace-code {
    background: rgba(81, 207, 102, 0.05);
    color: #a0f0b0;
    border-left: 3px solid rgba(81, 207, 102, 0.3);
}

/* Empty diff code block — hide if empty */
.sr-code:empty {
    padding: 2px 16px;
    min-height: 0;
}

/* ===========================
   Truncated Response Notice
   =========================== */
.truncated-notice {
    max-width: 900px;
    width: 100%;
    margin: 0 auto;
    padding: 10px 16px;
    background: rgba(243, 156, 18, 0.1);
    border: 1px solid var(--warning);
    border-radius: var(--radius);
    font-size: 13px;
    color: var(--text-secondary);
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
}

.truncated-notice span {
    flex: 1;
}

.continue-btn {
    flex-shrink: 0;
}

.donation-notice {
    max-width: 900px;
    width: 100%;
    margin: 12px auto;
    padding: 16px 20px;
    background: rgba(46, 204, 113, 0.08);
    border: 1px solid rgba(46, 204, 113, 0.3);
    border-radius: var(--radius);
    font-size: 14px;
    color: var(--text-secondary);
    text-align: center;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 10px;
}

.donation-notice p {
    margin: 0;
}

.donate-btn {
    background: #0070ba;
    border-color: #0070ba;
    color: #fff;
}

.donate-btn:hover {
    background: #005ea6;
    border-color: #005ea6;
}

.donate-dismiss {
    font-size: 12px;
    opacity: 0.7;
}

/* ===========================
   Project Planner
   =========================== */

.project-app {
    display: flex;
    height: 100vh;
    height: 100dvh;
    overflow: hidden;
}

.project-sidebar {
    width: var(--sidebar-width);
    background: var(--bg-secondary);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    flex-shrink: 0;
}

.project-nav-actions {
    padding: 8px 16px;
}

.project-list {
    flex: 1;
    overflow-y: auto;
    padding: 8px;
}

.project-list-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 12px;
    border-radius: var(--radius);
    cursor: pointer;
    transition: background var(--transition);
    margin-bottom: 2px;
}

.project-list-item:hover {
    background: var(--bg-hover);
}

.project-list-item.active {
    background: var(--accent-light);
    border: 1px solid var(--accent);
}

.project-list-item .project-item-title {
    flex: 1;
    font-size: 13px;
    font-weight: 500;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.project-list-item .project-item-progress {
    font-size: 11px;
    color: var(--text-muted);
    white-space: nowrap;
}

/* Main */
.project-main {
    flex: 1;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    min-width: 0;
}

.project-empty {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 12px;
    color: var(--text-secondary);
    text-align: center;
    padding: 40px;
}

.project-empty .welcome-icon {
    font-size: 48px;
}

.project-empty h2 {
    font-size: 22px;
    color: var(--text-primary);
}

.project-view {
    display: flex;
    flex-direction: column;
    height: 100%;
    overflow: hidden;
}

.project-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 24px;
    border-bottom: 1px solid var(--border);
    background: var(--bg-secondary);
    flex-shrink: 0;
}

.project-header h2 {
    font-size: 18px;
    margin-bottom: 2px;
}

.project-desc {
    font-size: 12px;
    color: var(--text-muted);
}

.project-header-actions {
    display: flex;
    align-items: center;
    gap: 16px;
}

.project-progress {
    display: flex;
    align-items: center;
    gap: 8px;
}

.progress-bar {
    width: 120px;
    height: 8px;
    background: var(--bg-tertiary);
    border-radius: 4px;
    overflow: hidden;
}

.progress-fill {
    height: 100%;
    background: var(--success);
    border-radius: 4px;
    transition: width 0.4s ease;
}

.progress-text {
    font-size: 12px;
    font-weight: 600;
    color: var(--text-secondary);
    min-width: 32px;
}

/* Project Content (board + chat) */
.project-content {
    flex: 1;
    display: flex;
    overflow: hidden;
}

.project-board {
    flex: 1;
    overflow-y: auto;
    padding: 20px 24px;
    min-width: 0;
}

/* Phase Card */
.phase-card {
    margin-bottom: 20px;
    border-radius: var(--radius-lg);
    border: 1px solid var(--border);
    background: var(--bg-secondary);
    overflow: hidden;
}

.phase-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 16px;
    cursor: pointer;
    user-select: none;
    transition: background var(--transition);
}

.phase-header:hover {
    background: var(--bg-hover);
}

.phase-header-left {
    display: flex;
    align-items: center;
    gap: 10px;
}

.phase-icon {
    font-size: 18px;
}

.phase-name {
    font-size: 14px;
    font-weight: 600;
}

.phase-badge {
    font-size: 11px;
    padding: 2px 8px;
    border-radius: 10px;
    background: var(--bg-tertiary);
    color: var(--text-muted);
}

.phase-header .phase-chevron {
    transition: transform 0.2s;
    color: var(--text-muted);
}

.phase-header.collapsed .phase-chevron {
    transform: rotate(-90deg);
}

.phase-body {
    border-top: 1px solid var(--border);
}

.phase-body.collapsed {
    display: none;
}

/* Task Row */
.task-row {
    display: grid;
    grid-template-columns: 2fr 1fr 1fr 100px 1fr auto;
    gap: 8px;
    align-items: center;
    padding: 10px 16px;
    border-bottom: 1px solid var(--border);
    font-size: 13px;
    transition: background var(--transition);
    cursor: pointer;
}

.task-row:last-child {
    border-bottom: none;
}

.task-row:hover {
    background: var(--bg-hover);
}

.task-row.task-active {
    background: var(--accent-light);
    border-left: 3px solid var(--accent);
}

.task-name {
    font-weight: 500;
}

.task-name small {
    display: block;
    font-weight: 400;
    color: var(--text-muted);
    font-size: 11px;
}

.task-meta {
    color: var(--text-secondary);
    font-size: 12px;
}

.task-status {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 3px 10px;
    border-radius: 12px;
    font-size: 11px;
    font-weight: 600;
    white-space: nowrap;
}

.task-status.status-offen {
    background: rgba(243, 156, 18, 0.15);
    color: var(--warning);
}

.task-status.status-in-arbeit {
    background: rgba(108, 92, 231, 0.15);
    color: var(--accent);
}

.task-status.status-erledigt {
    background: rgba(46, 204, 113, 0.15);
    color: var(--success);
}

.task-deliverable {
    font-size: 12px;
    color: var(--text-secondary);
    max-width: 160px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.task-open-btn {
    background: none;
    border: 1px solid var(--border);
    color: var(--accent);
    padding: 4px 10px;
    border-radius: var(--radius);
    cursor: pointer;
    font-size: 12px;
    transition: all var(--transition);
    white-space: nowrap;
}

.task-open-btn:hover {
    background: var(--accent);
    color: #fff;
    border-color: var(--accent);
}

.task-result-indicator {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    display: inline-block;
    margin-left: 6px;
}

.task-result-indicator.has-result {
    background: var(--success);
}

.task-result-indicator.no-result {
    background: var(--text-muted);
    opacity: 0.3;
}

/* Task Chat Panel */
.task-chat-panel {
    width: 460px;
    flex-shrink: 0;
    border-left: 1px solid var(--border);
    background: var(--bg-secondary);
    display: flex;
    flex-direction: column;
    animation: slideInRight 0.25s ease;
}

/* ===========================
   XAML Preview Modal
   =========================== */
.xaml-preview-modal-content {
    max-width: 98vw;
    width: 98vw;
    max-height: 96vh;
    height: 96vh;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.xaml-preview-toolbar {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 16px;
    padding: 8px 0;
    margin-bottom: 12px;
    border-bottom: 1px solid var(--border);
}

.xaml-highlight-toggle,
.xaml-theme-toggle {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 12px;
    color: var(--text-secondary);
    cursor: pointer;
}

.xaml-highlight-toggle input,
.xaml-theme-toggle input {
    width: auto;
}

.xaml-preview-container {
    flex: 1;
    overflow: auto;
    display: flex;
    justify-content: center;
    align-items: stretch;
    padding: 16px;
    background: var(--bg-tertiary);
    border-radius: var(--radius);
    min-height: 0;
}

.xaml-preview-frame {
    background: #f0f0f0;
    border: 1px solid #ccc;
    border-radius: 4px;
    overflow: auto;
    font-family: 'Segoe UI', system-ui, sans-serif;
    font-size: 14px;
    color: #1a1a1a;
    position: relative;
    width: 100%;
    height: 100%;
}

.xaml-preview-frame.dark-theme {
    background: #1e1e1e;
    color: #e0e0e0;
    border-color: #444;
}

.xaml-preview-errors {
    margin-top: 8px;
    padding: 8px 12px;
    background: rgba(231, 76, 60, 0.12);
    color: var(--danger);
    border-radius: var(--radius);
    font-size: 12px;
    font-family: var(--font-mono);
    white-space: pre-wrap;
}

/* Element hover highlighting mode */
.xaml-highlight-mode [data-xaml-tag]:hover {
    outline: 2px dashed rgba(0, 120, 212, 0.6) !important;
    outline-offset: 1px;
}
.xaml-highlight-mode [data-xaml-tag]:hover::after {
    content: attr(data-xaml-tag);
    position: absolute;
    top: -18px;
    left: 0;
    background: #0078d4;
    color: #fff;
    font-size: 10px;
    padding: 1px 5px;
    border-radius: 2px;
    z-index: 999;
    pointer-events: none;
    white-space: nowrap;
    font-family: 'Segoe UI', system-ui, sans-serif;
}

/* XAML Window title bar */
.xaml-window {
    display: flex;
    flex-direction: column;
    width: 100%;
    height: 100%;
}

.xaml-window-titlebar {
    display: flex;
    align-items: center;
    background: #f3f3f3;
    border-bottom: 1px solid #ddd;
    padding: 0;
    height: 30px;
    flex-shrink: 0;
    font-size: 12px;
    user-select: none;
}

.dark-theme .xaml-window-titlebar {
    background: #2d2d2d;
    border-bottom-color: #444;
    color: #ccc;
}

.xaml-window-icon {
    padding: 0 8px;
    font-size: 10px;
    opacity: 0.6;
}

.xaml-window-title {
    flex: 1;
    text-align: center;
    font-size: 12px;
    font-weight: 400;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.xaml-window-btns {
    display: flex;
    height: 100%;
}

.xaml-win-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 46px;
    height: 100%;
    font-size: 10px;
    cursor: default;
    color: inherit;
}

.xaml-win-btn:hover {
    background: rgba(0, 0, 0, 0.06);
}

.dark-theme .xaml-win-btn:hover {
    background: rgba(255, 255, 255, 0.08);
}

.xaml-win-close:hover {
    background: #e81123 !important;
    color: #fff !important;
}

.xaml-window-content {
    flex: 1;
    overflow: auto;
    min-height: 0;
}

/* XAML rendered elements */
.xaml-el {
    box-sizing: border-box;
    position: relative;
}

.xaml-el[data-type="Window"],
.xaml-el[data-type="Page"],
.xaml-el[data-type="UserControl"] {
    width: 100%;
    height: 100%;
    padding: 0;
}

.xaml-el[data-type="Grid"] {
    display: grid;
    width: 100%;
    height: 100%;
}

.xaml-el[data-type="StackPanel"] {
    display: flex;
    width: 100%;
}

.xaml-el[data-type="StackPanel"][data-orientation="Horizontal"] {
    flex-direction: row;
}

.xaml-el[data-type="StackPanel"]:not([data-orientation="Horizontal"]) {
    flex-direction: column;
}

.xaml-el[data-type="WrapPanel"] {
    display: flex;
    flex-wrap: wrap;
    width: 100%;
}

.xaml-el[data-type="DockPanel"] {
    display: flex;
    flex-direction: column;
    width: 100%;
    height: 100%;
}

.xaml-el[data-type="UniformGrid"] {
    display: grid;
    width: 100%;
}

.xaml-el[data-type="Canvas"] {
    position: relative;
    width: 100%;
    height: 100%;
}

.xaml-el[data-type="ScrollViewer"] {
    overflow: auto;
    width: 100%;
    height: 100%;
}

.xaml-el[data-type="Viewbox"] {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 100%;
    height: 100%;
}

.xaml-el[data-type="Border"] {
    border: 1px solid #999;
    border-radius: 0;
}

.xaml-el[data-type="GroupBox"] {
    border: 1px solid #999;
    border-radius: 4px;
    padding: 12px 8px 8px;
    position: relative;
}

.xaml-el[data-type="GroupBox"]::before {
    content: attr(data-header);
    position: absolute;
    top: -9px;
    left: 10px;
    background: inherit;
    padding: 0 4px;
    font-size: 12px;
    color: inherit;
}

.xaml-el[data-type="TabControl"] {
    display: flex;
    flex-direction: column;
    width: 100%;
    border: 1px solid #ccc;
    border-radius: 4px;
}

.xaml-tabs-header {
    display: flex;
    background: #e8e8e8;
    border-bottom: 1px solid #ccc;
    border-radius: 4px 4px 0 0;
}

.dark-theme .xaml-tabs-header {
    background: #2d2d2d;
    border-color: #555;
}

.xaml-tab-btn {
    padding: 6px 14px;
    border: none;
    background: transparent;
    cursor: pointer;
    font-size: 12px;
    font-family: inherit;
    color: inherit;
    border-bottom: 2px solid transparent;
}

.xaml-tab-btn.active {
    border-bottom-color: #0078d4;
    font-weight: 600;
}

.xaml-tab-content {
    padding: 8px;
}

/* XAML Controls */
.xaml-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 5px 16px;
    background: #e1e1e1;
    border: 1px solid #adadad;
    border-radius: 2px;
    cursor: default;
    font-family: inherit;
    font-size: 13px;
    color: #1a1a1a;
    min-height: 24px;
}

.dark-theme .xaml-btn {
    background: #333;
    border-color: #555;
    color: #e0e0e0;
}

.xaml-textbox,
.xaml-passwordbox {
    padding: 4px 8px;
    background: #fff;
    border: 1px solid #aaa;
    border-radius: 2px;
    font-family: inherit;
    font-size: 13px;
    color: #1a1a1a;
    min-height: 24px;
}

.dark-theme .xaml-textbox,
.dark-theme .xaml-passwordbox {
    background: #1a1a1a;
    border-color: #555;
    color: #e0e0e0;
}

.xaml-textbox[data-multiline="true"] {
    min-height: 60px;
    resize: vertical;
}

.xaml-passwordbox::placeholder {
    letter-spacing: 4px;
}

.xaml-label,
.xaml-textblock {
    display: inline-block;
    font-size: 13px;
    padding: 2px 0;
}

.xaml-checkbox,
.xaml-radiobutton {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    font-size: 13px;
    cursor: default;
    padding: 2px 0;
}

.xaml-combobox {
    padding: 4px 8px;
    background: #fff;
    border: 1px solid #aaa;
    border-radius: 2px;
    font-family: inherit;
    font-size: 13px;
    color: #1a1a1a;
    min-height: 24px;
    min-width: 120px;
    cursor: default;
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg width='10' height='6' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath d='M0 0l5 6 5-6z' fill='%23666'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 8px center;
    padding-right: 24px;
}

.dark-theme .xaml-combobox {
    background-color: #1a1a1a;
    border-color: #555;
    color: #e0e0e0;
    background-image: url("data:image/svg+xml,%3Csvg width='10' height='6' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath d='M0 0l5 6 5-6z' fill='%23aaa'/%3E%3C/svg%3E");
}

.xaml-listbox,
.xaml-listview {
    background: #fff;
    border: 1px solid #aaa;
    border-radius: 2px;
    min-height: 60px;
    overflow-y: auto;
    font-size: 13px;
}

.dark-theme .xaml-listbox,
.dark-theme .xaml-listview {
    background: #1a1a1a;
    border-color: #555;
    color: #e0e0e0;
}

.xaml-listbox-item {
    padding: 4px 8px;
    cursor: default;
}

.xaml-listbox-item:hover {
    background: #cce4f7;
}

.dark-theme .xaml-listbox-item:hover {
    background: #264f78;
}

/* TreeView */
.xaml-treeview {
    background: #fff;
    border: 1px solid #aaa;
    border-radius: 2px;
    min-height: 60px;
    overflow-y: auto;
    font-size: 13px;
    padding: 2px 0;
}

.dark-theme .xaml-treeview {
    background: #1a1a1a;
    border-color: #555;
    color: #e0e0e0;
}

.xaml-treeview-header {
    padding: 2px 4px;
    cursor: default;
    display: flex;
    align-items: center;
    gap: 2px;
}

.xaml-treeview-header:hover {
    background: #cce4f7;
}

.dark-theme .xaml-treeview-header:hover {
    background: #264f78;
}

.xaml-tree-arrow {
    font-size: 9px;
    width: 14px;
    text-align: center;
    flex-shrink: 0;
}

.xaml-slider {
    width: 100%;
    height: 20px;
    accent-color: #0078d4;
    cursor: default;
}

.xaml-progressbar {
    width: 100%;
    height: 20px;
    background: #e0e0e0;
    border-radius: 2px;
    overflow: hidden;
    position: relative;
}

.dark-theme .xaml-progressbar {
    background: #333;
}

.xaml-progressbar-fill {
    height: 100%;
    background: #0078d4;
    transition: width 0.3s ease;
}

.xaml-progressbar-indeterminate {
    width: 40% !important;
    animation: xaml-progress-indeterminate 1.5s ease-in-out infinite;
}

@keyframes xaml-progress-indeterminate {
    0% { transform: translateX(-100%); }
    100% { transform: translateX(350%); }
}

.xaml-image {
    display: flex;
    align-items: center;
    justify-content: center;
    background: #e8e8e8;
    border: 1px dashed #bbb;
    color: #888;
    font-size: 11px;
    min-width: 40px;
    min-height: 40px;
}

.dark-theme .xaml-image {
    background: #2a2a2a;
    border-color: #555;
    color: #777;
}

.xaml-separator {
    border: none;
    border-top: 1px solid #ccc;
    margin: 4px 0;
}

.dark-theme .xaml-separator {
    border-top-color: #444;
}

.xaml-gridsplitter {
    border: none;
    background: #d0d0d0;
    margin: 0;
    min-width: 4px;
    min-height: 4px;
    cursor: col-resize;
}

.dark-theme .xaml-gridsplitter {
    background: #444;
}

.xaml-expander {
    border: 1px solid #ccc;
    border-radius: 2px;
    margin: 2px 0;
}

.dark-theme .xaml-expander {
    border-color: #444;
}

.xaml-expander-header {
    padding: 6px 10px;
    cursor: pointer;
    font-size: 13px;
    font-weight: 500;
    background: #f0f0f0;
    display: flex;
    align-items: center;
    gap: 6px;
}

.dark-theme .xaml-expander-header {
    background: #2a2a2a;
}

.xaml-expander-content {
    padding: 8px 10px;
    border-top: 1px solid #ccc;
}

.dark-theme .xaml-expander-content {
    border-top-color: #444;
}

.xaml-menu {
    display: flex;
    gap: 0;
    background: #f0f0f0;
    border-bottom: 1px solid #ccc;
    padding: 0;
}

.dark-theme .xaml-menu {
    background: #2d2d2d;
    border-bottom-color: #555;
}

.xaml-menu-item {
    padding: 4px 12px;
    font-size: 13px;
    cursor: default;
}

.xaml-menu-item:hover {
    background: #e0e0e0;
}

.dark-theme .xaml-menu-item:hover {
    background: #3a3a3a;
}

.xaml-toolbar {
    display: flex;
    align-items: center;
    gap: 2px;
    background: #f0f0f0;
    border-bottom: 1px solid #ccc;
    padding: 2px 4px;
}

.dark-theme .xaml-toolbar {
    background: #2d2d2d;
    border-bottom-color: #555;
}

.xaml-statusbar {
    display: flex;
    align-items: center;
    padding: 4px 8px;
    background: #eee;
    border-top: 1px solid #ccc;
    font-size: 12px;
    gap: 12px;
}

.dark-theme .xaml-statusbar {
    background: #252525;
    border-top-color: #444;
}

.xaml-statusbar-sep {
    color: #bbb;
    font-size: 10px;
}

.dark-theme .xaml-statusbar-sep {
    color: #555;
}

.xaml-datagrid {
    width: 100%;
    border-collapse: collapse;
    border: 1px solid #ccc;
    font-size: 12px;
}

.dark-theme .xaml-datagrid {
    border-color: #444;
}

.xaml-datagrid th {
    background: #e8e8e8;
    padding: 6px 10px;
    text-align: left;
    border-bottom: 1px solid #ccc;
    font-weight: 600;
}

.dark-theme .xaml-datagrid th {
    background: #2d2d2d;
    border-bottom-color: #444;
}

.xaml-datagrid td {
    padding: 5px 10px;
    border-bottom: 1px solid #eee;
}

.dark-theme .xaml-datagrid td {
    border-bottom-color: #333;
}

/* Shapes */
.xaml-ellipse {
    border-radius: 50%;
    min-width: 20px;
    min-height: 20px;
    box-sizing: border-box;
}

.xaml-rectangle {
    min-width: 20px;
    min-height: 20px;
    box-sizing: border-box;
}

.xaml-calendar {
    display: flex;
    align-items: center;
    justify-content: center;
    background: #fff;
    border: 1px solid #aaa;
    border-radius: 2px;
    min-width: 180px;
    min-height: 160px;
    font-size: 13px;
    color: #888;
}

.dark-theme .xaml-calendar {
    background: #1a1a1a;
    border-color: #555;
    color: #777;
}

@media (max-width: 768px) {
    #xamlPreviewModal {
        display: none !important;
    }
    #previewXamlBtn {
        display: none !important;
    }
}

@keyframes slideInRight {
    from { transform: translateX(30px); opacity: 0; }
    to { transform: translateX(0); opacity: 1; }
}

.task-chat-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    padding: 14px 16px;
    border-bottom: 1px solid var(--border);
    background: var(--bg-tertiary);
}

.task-chat-info h3 {
    font-size: 14px;
    margin-top: 2px;
}

.task-chat-phase {
    font-size: 11px;
    color: var(--accent);
    font-weight: 600;
}

.task-chat-meta {
    padding: 10px 16px;
    border-bottom: 1px solid var(--border);
    font-size: 12px;
    color: var(--text-secondary);
    display: flex;
    flex-wrap: wrap;
    gap: 6px 16px;
    background: var(--bg-primary);
}

.task-chat-meta .meta-item {
    display: flex;
    align-items: center;
    gap: 4px;
}

.task-chat-meta .meta-label {
    color: var(--text-muted);
}

.task-chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.task-chat-welcome {
    text-align: center;
    color: var(--text-muted);
    padding: 40px 20px;
    font-size: 13px;
}

.task-chat-msg {
    max-width: 95%;
    padding: 10px 14px;
    border-radius: var(--radius-lg);
    font-size: 13px;
    line-height: 1.5;
    word-wrap: break-word;
}

.task-chat-msg.user {
    align-self: flex-end;
    background: var(--accent);
    color: #fff;
    border-bottom-right-radius: 4px;
}

.task-chat-msg.assistant {
    align-self: flex-start;
    background: var(--bg-tertiary);
    color: var(--text-primary);
    border-bottom-left-radius: 4px;
}

.task-chat-msg.assistant h1,
.task-chat-msg.assistant h2,
.task-chat-msg.assistant h3 {
    font-size: 14px;
    margin: 8px 0 4px;
}

.task-chat-msg.assistant ul,
.task-chat-msg.assistant ol {
    margin: 4px 0;
    padding-left: 20px;
}

.task-chat-msg.assistant pre {
    font-size: 12px;
    background: var(--bg-primary);
    padding: 8px;
    border-radius: var(--radius);
    overflow-x: auto;
    margin: 6px 0;
}

.task-chat-msg.assistant code {
    font-family: var(--font-mono);
    font-size: 12px;
}

.task-chat-msg.loading {
    color: var(--text-muted);
    font-style: italic;
}

.task-chat-input {
    padding: 12px 16px;
    border-top: 1px solid var(--border);
    background: var(--bg-secondary);
}

.task-chat-suggestions {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin-bottom: 8px;
}

.task-suggestion-btn {
    background: var(--bg-tertiary);
    border: 1px solid var(--border);
    color: var(--text-secondary);
    padding: 4px 10px;
    border-radius: 14px;
    font-size: 11px;
    cursor: pointer;
    transition: all var(--transition);
}

.task-suggestion-btn:hover {
    background: var(--accent-light);
    color: var(--accent);
    border-color: var(--accent);
}

/* Template Options */
.template-options {
    display: flex;
    gap: 12px;
}

.template-btn {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 6px;
    padding: 16px;
    background: var(--bg-tertiary);
    border: 2px solid var(--border);
    border-radius: var(--radius-lg);
    cursor: pointer;
    transition: all var(--transition);
    color: var(--text-primary);
}

.template-btn:hover {
    border-color: var(--accent);
}

.template-btn.active {
    border-color: var(--accent);
    background: var(--accent-light);
}

.template-icon {
    font-size: 28px;
}

.template-name {
    font-size: 13px;
    font-weight: 600;
}

.template-desc {
    font-size: 11px;
    color: var(--text-muted);
}

/* Phase Colors */
.phase-1 .phase-header { border-left: 4px solid #e74c3c; }
.phase-2 .phase-header { border-left: 4px solid #e67e22; }
.phase-3 .phase-header { border-left: 4px solid #f1c40f; }
.phase-4 .phase-header { border-left: 4px solid #2ecc71; }
.phase-5 .phase-header { border-left: 4px solid #3498db; }
.phase-6 .phase-header { border-left: 4px solid #9b59b6; }
.phase-7 .phase-header { border-left: 4px solid #1abc9c; }

/* Responsive - Project */
@media (max-width: 900px) {
    .task-chat-panel {
        position: fixed;
        top: 0;
        right: 0;
        width: 100%;
        height: 100%;
        z-index: 100;
    }
    .task-row {
        grid-template-columns: 1fr 80px auto;
    }
    .task-row .task-meta,
    .task-row .task-deliverable {
        display: none;
    }
}

@media (max-width: 768px) {
    /* Project sidebar toggle */
    .project-sidebar-toggle {
        display: block;
    }

    /* Project header */
    .project-header {
        flex-direction: column;
        align-items: flex-start;
        gap: 6px;
        padding: 8px 8px 8px 8px;
    }

    .project-header h2 {
        font-size: 13px;
    }

    .project-desc {
        font-size: 10px;
    }

    .project-header-actions {
        width: 100%;
        justify-content: space-between;
    }

    .progress-bar {
        width: 60px;
        height: 6px;
    }

    .progress-text {
        font-size: 10px;
    }

    /* Project board */
    .project-board {
        padding: 8px 6px;
        padding-bottom: 48px;
    }

    .phase-header {
        padding: 8px 8px;
    }

    .phase-name {
        font-size: 11px;
    }

    .phase-icon {
        font-size: 14px;
    }

    .phase-badge {
        font-size: 9px;
        padding: 1px 6px;
    }

    .task-row {
        grid-template-columns: 1fr auto;
        padding: 7px 8px;
        gap: 4px;
        font-size: 11px;
    }

    .task-row .task-meta,
    .task-row .task-deliverable,
    .task-row .task-status {
        display: none;
    }

    .task-name {
        font-size: 11px;
    }

    .task-name small {
        font-size: 9px;
    }

    .task-open-btn {
        font-size: 10px;
        padding: 3px 6px;
    }

    /* Project content */
    .project-content {
        flex-direction: column;
    }

    /* Task chat panel */
    .task-chat-panel {
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        width: 100%;
        height: 100%;
        z-index: 100;
    }

    .task-chat-header {
        padding: 8px 10px;
    }

    .task-chat-info h3 {
        font-size: 12px;
    }

    .task-chat-phase {
        font-size: 9px;
    }

    .task-chat-meta {
        padding: 6px 10px;
        font-size: 10px;
        gap: 4px 10px;
    }

    .task-chat-messages {
        padding: 8px;
        gap: 8px;
    }

    .task-chat-msg {
        font-size: 11px;
        padding: 7px 10px;
    }

    .task-chat-input {
        padding: 6px 8px;
    }

    .task-chat-suggestions {
        gap: 3px;
        margin-bottom: 6px;
    }

    .task-suggestion-btn {
        font-size: 9px;
        padding: 2px 6px;
    }

    .task-chat-welcome {
        padding: 20px 12px;
        font-size: 11px;
    }

    /* Project empty state */
    .project-empty {
        padding: 20px 12px;
    }

    .project-empty .welcome-icon {
        font-size: 36px;
    }

    .project-empty h2 {
        font-size: 15px;
    }

    .project-empty p {
        font-size: 11px;
    }

    /* Template options (new project modal) */
    .template-options {
        flex-direction: column;
        gap: 8px;
    }

    .template-btn {
        padding: 10px;
    }

    .template-icon {
        font-size: 22px;
    }

    .template-name {
        font-size: 11px;
    }

    .template-desc {
        font-size: 9px;
    }

    /* Phase cards */
    .phase-card {
        margin-bottom: 8px;
    }

    /* Project list in sidebar */
    .project-list-item {
        padding: 7px 10px;
        gap: 6px;
    }

    .project-list-item .project-item-title {
        font-size: 11px;
    }

    .project-list-item .project-item-progress {
        font-size: 9px;
    }

    .project-nav-actions {
        padding: 6px 10px;
    }
}

/* Admin/Project sidebar toggle buttons */
.admin-sidebar-toggle,
.project-sidebar-toggle {
    display: none;
    position: fixed;
    top: 8px;
    left: 8px;
    z-index: 100;
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    color: var(--text-primary);
    font-size: 16px;
    padding: 4px 8px;
    border-radius: var(--radius);
    cursor: pointer;
}

/* Small phone additional tweaks */
@media (max-width: 480px) {
    body {
        font-size: 11px;
    }

    .btn {
        padding: 4px 8px;
        font-size: 10px;
    }

    .btn-sm {
        padding: 2px 5px;
        font-size: 9px;
    }

    .chat-header {
        padding: 4px 8px 4px 8px;
        min-height: 34px;
    }

    .chat-header h2 {
        max-width: 100px;
        font-size: 11px;
    }

    .welcome-message h2 {
        font-size: 14px;
    }

    .welcome-message p {
        font-size: 10px;
    }

    .welcome-icon {
        font-size: 28px;
    }

    .suggestion-btn {
        padding: 6px 8px;
        font-size: 9px;
    }

    .message-avatar {
        width: 20px;
        height: 20px;
        font-size: 9px;
    }

    .message-body {
        font-size: 11px;
    }

    .message-body pre code {
        font-size: 10px;
        padding: 6px;
    }

    .stats-grid {
        grid-template-columns: 1fr;
    }

    .stat-value {
        font-size: 18px;
    }

    .stat-label {
        font-size: 9px;
    }

    .auth-card {
        padding: 16px;
    }

    .auth-logo {
        font-size: 32px;
    }

    .auth-header h1 {
        font-size: 18px;
    }

    .auth-header p {
        font-size: 11px;
    }

    .page-editor-actions {
        display: grid;
        grid-template-columns: 1fr 1fr;
    }

    .page-content-textarea {
        font-size: 10px;
    }

    .mobile-nav-item {
        padding: 4px 8px;
        font-size: 15px;
    }

    .mobile-nav-item span {
        font-size: 8px;
    }

    .data-table th,
    .data-table td {
        padding: 4px 3px;
        font-size: 9px;
    }

    .send-btn {
        width: 28px;
        height: 28px;
    }

    .cancel-response-btn,
    .regenerate-btn,
    .consistency-check-btn {
        width: 28px;
        height: 28px;
    }

    .input-hint {
        font-size: 8px;
    }
}

/* ===========================
   WebFTP
   =========================== */

/* Standalone .input class (used outside .form-group) */
.input {
    padding: 8px 12px;
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    color: var(--text-primary);
    font-family: var(--font);
    font-size: 13px;
    transition: border-color var(--transition);
}
.input:focus {
    outline: none;
    border-color: var(--accent);
}
.input::placeholder {
    color: var(--text-muted);
}

/* FTP connection settings panel */
.webftp-settings summary {
    cursor: pointer;
    font-weight: 600;
    font-size: 14px;
    padding: 10px 0;
    color: var(--text-primary);
    user-select: none;
}
.webftp-settings[open] summary {
    margin-bottom: 14px;
}
.webftp-settings .webftp-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: 14px;
    margin-bottom: 16px;
}
.webftp-settings label {
    font-size: 12px;
    color: var(--text-secondary);
    font-weight: 500;
}
.webftp-settings label .input {
    display: block;
    width: 100%;
    margin-top: 5px;
}
.webftp-settings .webftp-check {
    display: flex;
    align-items: center;
    gap: 7px;
    margin-top: 24px;
    font-size: 13px;
    color: var(--text-secondary);
    cursor: pointer;
}
.webftp-settings .webftp-check input[type="checkbox"] {
    accent-color: var(--accent);
    width: 15px;
    height: 15px;
    cursor: pointer;
}
.webftp-actions {
    display: flex;
    gap: 8px;
}

/* Toolbar */
.webftp-toolbar {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
    margin-bottom: 14px;
    padding: 10px 14px;
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
}
.webftp-toolbar .input {
    flex: 1;
    min-width: 160px;
}
.webftp-path {
    margin-bottom: 10px;
    font-size: 12px;
    color: var(--text-muted);
}
.webftp-path strong {
    color: var(--text-secondary);
    font-family: var(--font-mono);
    font-size: 12px;
}

/* File table */
.webftp-table-wrap {
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    overflow: hidden;
}
.webftp-table {
    width: 100%;
    border-collapse: collapse;
}
.webftp-table th {
    padding: 10px 14px;
    text-align: left;
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--text-muted);
    background: var(--bg-tertiary);
    border-bottom: 1px solid var(--border);
}
.webftp-table td {
    padding: 8px 14px;
    font-size: 13px;
    border-bottom: 1px solid var(--border);
    vertical-align: middle;
}
.webftp-table tbody tr:last-child td {
    border-bottom: none;
}
.webftp-table tbody tr:hover {
    background: var(--bg-hover);
}
.webftp-table td:last-child {
    white-space: nowrap;
}

/* Folder / file name buttons */
.webftp-name-btn {
    background: none;
    border: none;
    color: var(--accent);
    cursor: pointer;
    font-family: var(--font);
    font-size: 13px;
    padding: 2px 0;
    transition: color var(--transition);
}
.webftp-name-btn:hover {
    color: var(--accent-hover);
    text-decoration: underline;
}

/* Muted placeholder rows */
.webftp-muted {
    color: var(--text-muted);
    text-align: center;
    font-style: italic;
    padding: 28px 14px !important;
}

/* Size & type columns subtle */
.webftp-table td:nth-child(2),
.webftp-table td:nth-child(3) {
    color: var(--text-muted);
    font-size: 12px;
}

/* Responsive */
@media (max-width: 768px) {
    .webftp-toolbar {
        padding: 8px 10px;
        gap: 6px;
    }
    .webftp-settings .webftp-grid {
        grid-template-columns: 1fr;
    }
    .webftp-table th,
    .webftp-table td {
        padding: 6px 8px;
        font-size: 12px;
    }
    .webftp-table th:nth-child(2),
    .webftp-table td:nth-child(2),
    .webftp-table th:nth-child(3),
    .webftp-table td:nth-child(3) {
        display: none;
    }
}

/* ===========================
   History / Diff Page
   =========================== */
.history-main {
    display: flex;
    flex-direction: column;
    gap: 14px;
}

.history-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 12px;
}

.history-header h2 {
    margin-bottom: 2px;
}

.history-header p {
    color: var(--text-secondary);
    font-size: 12px;
}

.history-workspace {
    display: grid;
    grid-template-columns: 320px 1fr;
    gap: 14px;
    min-height: 0;
    flex: 1;
}

.history-browser-panel,
.history-diff-panel {
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    overflow: hidden;
    min-height: 0;
}

.history-browser-panel {
    display: flex;
    flex-direction: column;
}

.history-diff-panel {
    display: flex;
    flex-direction: column;
}

.history-panel-header {
    padding: 10px 12px;
    border-bottom: 1px solid var(--border);
}

.history-panel-header h3 {
    font-size: 13px;
    margin-bottom: 8px;
}

.history-diff-top {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 10px;
}

.history-meta {
    color: var(--text-muted);
    font-size: 11px;
}

.history-stats {
    display: flex;
    gap: 6px;
    flex-wrap: wrap;
}

.history-stat {
    border: 1px solid var(--border);
    border-radius: 999px;
    padding: 2px 8px;
    font-size: 11px;
    color: var(--text-secondary);
}

.history-explorer {
    padding: 8px;
    overflow: auto;
    flex: 1;
}

.history-chat {
    background: var(--bg-primary);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    margin-bottom: 8px;
    padding: 6px;
}

.history-chat-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 8px;
    cursor: pointer;
    list-style: none;
}

.history-chat-header::-webkit-details-marker {
    display: none;
}

.history-chat-title {
    font-size: 12px;
    font-weight: 600;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.history-chat-meta {
    font-size: 10px;
    color: var(--text-muted);
}

.history-chat-files {
    margin-top: 6px;
}

.history-file-item {
    width: calc(100% - 2px);
    display: flex;
    align-items: center;
    justify-content: space-between;
    border: 1px solid var(--border);
    border-radius: 6px;
    background: var(--bg-secondary);
    color: var(--text-primary);
    padding: 6px 8px;
    margin-top: 3px;
    cursor: pointer;
    text-align: left;
}

.history-file-item:hover {
    background: var(--bg-hover);
}

.history-file-item.active {
    border-color: var(--accent);
    background: var(--accent-light);
}

.history-file-name {
    font-size: 12px;
    max-width: 72%;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.history-file-lang {
    font-size: 10px;
    color: var(--text-muted);
    text-transform: uppercase;
}

.history-compare-controls {
    padding: 10px 12px;
    border-bottom: 1px solid var(--border);
    display: grid;
    grid-template-columns: 1fr auto 1fr;
    gap: 10px;
    align-items: end;
}

.history-compare-field label {
    display: block;
    margin-bottom: 5px;
    color: var(--text-secondary);
    font-size: 11px;
}

.history-diff-wrap {
    flex: 1;
    overflow: auto;
    background: var(--bg-primary);
}

.history-diff-table {
    width: 100%;
    border-collapse: collapse;
    table-layout: fixed;
}

.history-diff-table th {
    position: sticky;
    top: 0;
    background: var(--bg-tertiary);
    color: var(--text-secondary);
    font-size: 11px;
    padding: 8px;
    text-align: left;
    border-bottom: 1px solid var(--border);
    z-index: 1;
}

.history-diff-table td {
    border-bottom: 1px solid var(--border);
    vertical-align: top;
}

.history-diff-table td pre {
    margin: 0;
    padding: 5px 8px;
    white-space: pre-wrap;
    word-break: break-word;
    font-family: var(--font-mono);
    font-size: 12px;
    line-height: 1.45;
}

.history-col-num {
    width: 52px;
    color: var(--text-muted);
    text-align: right;
    padding: 5px 8px;
    font-size: 11px;
    font-family: var(--font-mono);
}

.history-line-add td {
    background: rgba(46, 204, 113, 0.14);
}

.history-line-remove td {
    background: rgba(231, 76, 60, 0.14);
}

.history-line-equal td {
    background: transparent;
}

.history-empty {
    padding: 16px;
    color: var(--text-muted);
    font-size: 12px;
}

@media (max-width: 1100px) {
    .history-workspace {
        grid-template-columns: 280px 1fr;
    }
}

@media (max-width: 768px) {
    .history-workspace {
        grid-template-columns: 1fr;
    }

    .history-browser-panel {
        min-height: 200px;
        max-height: 38vh;
    }

    .history-compare-controls {
        grid-template-columns: 1fr;
        gap: 8px;
    }

    .history-compare-controls .btn {
        justify-self: start;
    }

    .history-col-num {
        width: 40px;
        font-size: 10px;
    }
}
