/* ========== CSS Variables & Reset ========== */
:root {
  --bg-primary: #0d0d0d;
  --bg-secondary: #121212;
  --bg-surface: #1a1a1a;
  --bg-elevated: #242424;
  --text-primary: #f0f0f0;
  --text-secondary: #a0a0a0;
  --text-muted: #606060;
  --accent: #4d6bfe;
  --accent-hover: #3d5be0;
  --accent-muted: rgba(77, 107, 254, 0.15);
  --border: #2a2a2a;
  --border-light: #333;
  --danger: #e74c3c;
  --success: #2ecc71;
  --warning: #f39c12;
  --radius: 12px;
  --radius-sm: 8px;
  --radius-xs: 6px;
  --shadow: 0 4px 24px rgba(0, 0, 0, 0.4);
  --transition: 0.2s ease;
  --font-mono: 'JetBrains Mono', 'Fira Code', 'Cascadia Code', monospace;
}
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

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

body { display: flex; }

a { color: var(--accent); text-decoration: none; }

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

/* ========== Sidebar ========== */
#sidebar {
width: 260px;
min-width: 260px;
height: 100vh;
background: var(--bg-secondary);
border-right: 1px solid var(--border);
display: flex;
flex-direction: column;
z-index: 10;
transition: margin-left var(--transition);
}
#sidebar.collapsed { margin-left: -260px; }

.sidebar-header {
display: flex;
align-items: center;
justify-content: space-between;
padding: 16px;
border-bottom: 1px solid var(--border);
}
.sidebar-header h2 {
font-size: 18px;
font-weight: 600;
color: var(--accent);
}
.sidebar-header button {
width: 32px;
height: 32px;
border-radius: 50%;
font-size: 20px;
line-height: 1;
border: 1px solid var(--border);
background: transparent;
color: var(--text-primary);
cursor: pointer;
transition: all var(--transition);
}
.sidebar-header button:hover { background: var(--accent-muted); border-color: var(--accent); }

.sidebar-search { padding: 12px; }
.sidebar-search input {
width: 100%;
padding: 10px 14px;
background: var(--bg-surface);
border: 1px solid var(--border);
border-radius: var(--radius-sm);
color: var(--text-primary);
font-size: 13px;
}
.sidebar-search input::placeholder { color: var(--text-muted); }

.history-list {
flex: 1;
overflow-y: auto;
padding: 8px;
}
.history-item {
padding: 10px 12px;
border-radius: var(--radius-xs);
cursor: pointer;
transition: background var(--transition);
display: flex;
align-items: center;
gap: 8px;
font-size: 13px;
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
}
.history-item:hover { background: var(--bg-surface); }
.history-item.active { background: var(--accent-muted); color: var(--accent); }
.history-item .delete-chat {
margin-left: auto;
opacity: 0;
transition: opacity var(--transition);
color: var(--danger);
cursor: pointer;
background: none;
border: none;
font-size: 14px;
}
.history-item:hover .delete-chat { opacity: 1; }

.sidebar-footer { padding: 12px; border-top: 1px solid var(--border); }

/* ========== Main Chat Area ========== */
#main {
flex: 1;
display: flex;
flex-direction: column;
height: 100vh;
overflow: hidden;
}

/* ========== Header ========== */
#chatHeader {
display: flex;
align-items: center;
gap: 12px;
padding: 10px 16px;
border-bottom: 1px solid var(--border);
background: var(--bg-secondary);
min-height: 52px;
}
.header-center { flex: 1; display: flex; align-items: center; gap: 12px; }
#chatTitle { font-size: 15px; font-weight: 500; }
.header-actions { display: flex; align-items: center; gap: 8px; }

/* ========== Model Select ========== */
.v-select, select {
padding: 6px 10px;
background: var(--bg-surface);
border: 1px solid var(--border);
border-radius: var(--radius-xs);
color: var(--text-primary);
font-size: 13px;
cursor: pointer;
}
.v-select:focus, select:focus { outline: none; border-color: var(--accent); }

/* ========== Chat Container ========== */
.chat-container {
flex: 1;
overflow-y: auto;
padding: 20px;
display: flex;
flex-direction: column;
}
.welcome-screen {
flex: 1;
display: flex;
align-items: center;
justify-content: center;
}
.welcome-card {
text-align: center;
padding: 40px;
max-width: 500px;
}
.welcome-card h1 { font-size: 32px; margin-bottom: 12px; }
.welcome-card p { color: var(--text-secondary); margin-bottom: 8px; }
.welcome-suggestions {
display: flex;
flex-wrap: wrap;
gap: 8px;
margin-top: 20px;
justify-content: center;
}
.suggestion-chip {
font-size: 12px;
padding: 8px 14px;
cursor: pointer;
}

.messages-container {
display: flex;
flex-direction: column;
gap: 16px;
width: 100%;
max-width: 800px;
margin: 0 auto;
}

/* ========== Messages ========== */
.message {
display: flex;
gap: 12px;
animation: fadeIn 0.3s ease;
}
@keyframes fadeIn { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: translateY(0); } }

.message.user { flex-direction: row-reverse; }
.message-avatar {
width: 32px;
height: 32px;
border-radius: 50%;
flex-shrink: 0;
display: flex;
align-items: center;
justify-content: center;
font-size: 14px;
font-weight: 600;
}
.message.user .message-avatar { background: var(--accent); color: #fff; }
.message.assistant .message-avatar { background: var(--bg-elevated); color: var(--accent); }
.message-body {
max-width: 85%;
min-width: 0;
}
.message.user .message-body {
background: var(--accent);
color: #fff;
border-radius: var(--radius) var(--radius) 4px var(--radius);
padding: 10px 16px;
}
.message.assistant .message-body {
padding: 4px 0;
}
.message-content {
font-size: 14px;
line-height: 1.65;
word-wrap: break-word;
}
.message-content p { margin-bottom: 10px; }
.message-content p:last-child { margin-bottom: 0; }
.message-content h1, .message-content h2, .message-content h3 {
margin: 16px 0 8px;
font-weight: 600;
}
.message-content h1 { font-size: 20px; }
.message-content h2 { font-size: 17px; border-bottom: 1px solid var(--border); padding-bottom: 6px; }
.message-content h3 { font-size: 15px; }
.message-content ul, .message-content ol { padding-left: 20px; margin-bottom: 10px; }
.message-content li { margin-bottom: 4px; }
.message-content blockquote {
border-left: 3px solid var(--accent);
padding-left: 14px;
color: var(--text-secondary);
margin-bottom: 10px;
}
.message-content table {
border-collapse: collapse;
width: 100%;
margin-bottom: 10px;
}
.message-content th, .message-content td {
border: 1px solid var(--border);
padding: 8px 12px;
text-align: left;
}
.message-content th { background: var(--bg-surface); font-weight: 600; }
.message-content a { color: var(--accent); text-decoration: underline; }
.message-timestamp {
font-size: 11px;
color: var(--text-muted);
margin-top: 4px;
}
.message.user .message-timestamp { color: rgba(255,255,255,0.6); }

/* ========== Code Blocks ========== */
.message-content pre {
background: #1e1e2e;
border-radius: var(--radius-sm);
padding: 0;
margin-bottom: 10px;
overflow: hidden;
position: relative;
border: 1px solid var(--border);
}
.message-content pre .code-header {
display: flex;
align-items: center;
justify-content: space-between;
padding: 8px 14px;
background: #181825;
border-bottom: 1px solid var(--border);
font-size: 12px;
color: var(--text-secondary);
}
.message-content pre .code-lang { text-transform: uppercase; font-weight: 600; font-size: 11px; }
.message-content pre .code-actions { display: flex; gap: 6px; }
.message-content pre .code-copy,
.message-content pre .code-download {
background: transparent;
border: 1px solid var(--border);
color: var(--text-secondary);
padding: 3px 8px;
border-radius: 4px;
cursor: pointer;
font-size: 11px;
transition: all var(--transition);
}
.message-content pre .code-copy:hover,
.message-content pre .code-download:hover {
background: var(--accent-muted);
border-color: var(--accent);
color: var(--accent);
}
.message-content pre code {
display: block;
padding: 16px;
overflow-x: auto;
font-family: var(--font-mono);
font-size: 13px;
line-height: 1.55;
}

/* ========== Inline Code ========== */
.message-content :not(pre) > code {
background: var(--bg-surface);
padding: 2px 6px;
border-radius: 4px;
font-family: var(--font-mono);
font-size: 12px;
color: var(--accent);
}

/* ========== BDS Tool Cards ========== */
.tool-card {
margin: 12px 0;
border-radius: var(--radius);
border: 1px solid var(--border);
overflow: hidden;
background: var(--bg-surface);
}
.tool-card-header {
display: flex;
align-items: center;
gap: 8px;
padding: 10px 14px;
background: var(--bg-elevated);
border-bottom: 1px solid var(--border);
font-size: 13px;
font-weight: 600;
}
.tool-card-body { padding: 14px; }
.tool-card-body iframe {
width: 100%;
min-height: 300px;
border: none;
border-radius: var(--radius-sm);
background: #fff;
}

.file-card {
display: flex;
align-items: center;
gap: 10px;
padding: 10px 14px;
background: var(--bg-surface);
border: 1px solid var(--border);
border-radius: var(--radius-sm);
margin: 6px 0;
}
.file-card .file-icon { font-size: 20px; }
.file-card .file-info { flex: 1; }
.file-card .file-name { font-size: 13px; font-weight: 500; }
.file-card .file-size { font-size: 11px; color: var(--text-muted); }

.image-result {
margin: 8px 0;
display: inline-block;
}
.image-result img {
max-width: 400px;
max-height: 300px;
border-radius: var(--radius-sm);
border: 1px solid var(--border);
cursor: pointer;
transition: transform var(--transition);
}
.image-result img:hover { transform: scale(1.02); }

/* ========== Input Area ========== */
.input-area {
padding: 12px 20px 16px;
border-top: 1px solid var(--border);
background: var(--bg-secondary);
}
.input-wrapper {
display: flex;
align-items: flex-end;
gap: 8px;
max-width: 800px;
margin: 0 auto;
position: relative;
}
#chatInput {
flex: 1;
background: var(--bg-surface);
border: 1px solid var(--border);
border-radius: var(--radius);
padding: 10px 14px;
color: var(--text-primary);
font-size: 14px;
font-family: inherit;
resize: none;
max-height: 200px;
transition: border-color var(--transition);
}
#chatInput:focus { outline: none; border-color: var(--accent); }
#chatInput::placeholder { color: var(--text-muted); }
.upload-btn { font-size: 18px; padding: 8px 12px; }

.upload-menu {
position: absolute;
bottom: 100%;
left: 0;
background: var(--bg-elevated);
border: 1px solid var(--border);
border-radius: var(--radius-sm);
padding: 6px;
z-index: 100;
min-width: 180px;
box-shadow: var(--shadow);
}
.upload-menu button {
display: block;
width: 100%;
background: transparent;
border: none;
color: var(--text-primary);
padding: 8px 12px;
text-align: left;
cursor: pointer;
border-radius: var(--radius-xs);
font-size: 13px;
}
.upload-menu button:hover { background: var(--accent-muted); }

.attachments-bar {
max-width: 800px;
margin: 8px auto 0;
display: flex;
flex-wrap: wrap;
gap: 6px;
}
.attachment-tag {
display: flex;
align-items: center;
gap: 6px;
padding: 4px 10px;
background: var(--accent-muted);
border-radius: 20px;
font-size: 12px;
color: var(--accent);
}
.attachment-tag .remove-attachment {
background: none;
border: none;
color: var(--text-secondary);
cursor: pointer;
font-size: 14px;
}

/* ========== Buttons ========== */
.v-btn, .v-btn-outline {
padding: 8px 16px;
border-radius: var(--radius-sm);
font-size: 13px;
font-weight: 500;
cursor: pointer;
transition: all var(--transition);
display: inline-flex;
align-items: center;
gap: 6px;
}
.v-btn {
background: var(--accent);
border: none;
color: #fff;
}
.v-btn:hover { background: var(--accent-hover); }
.v-btn:disabled { opacity: 0.5; cursor: not-allowed; }
.v-btn-outline {
background: transparent;
border: 1px solid var(--border);
color: var(--text-primary);
}
.v-btn-outline:hover { border-color: var(--accent); color: var(--accent); background: var(--accent-muted); }

/* ========== v-card, v-glass, v-title, v-stat, v-label ========== */
.v-card {
background: var(--bg-surface);
border: 1px solid var(--border);
border-radius: var(--radius);
box-shadow: var(--shadow);
}
.v-glass {
background: rgba(26, 26, 26, 0.7);
backdrop-filter: blur(12px);
border: 1px solid var(--border);
border-radius: var(--radius);
}
.v-title {
font-size: 18px;
font-weight: 600;
color: var(--text-primary);
padding-bottom: 10px;
border-bottom: 1px solid var(--border);
margin-bottom: 14px;
}
.v-stat {
background: var(--accent-muted);
color: var(--accent);
padding: 3px 10px;
border-radius: 20px;
font-family: var(--font-mono);
font-size: 12px;
}
.v-label {
font-size: 12px;
font-weight: 500;
color: var(--text-secondary);
text-transform: uppercase;
letter-spacing: 0.5px;
margin-bottom: 6px;
}
.v-control-group { display: flex; flex-direction: column; gap: 10px; }
.v-row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.v-animate-float { animation: float 3s ease-in-out infinite; }
@keyframes float { 0%, 100% { transform: translateY(0); } 50% { transform: translateY(-5px); } }

/* ========== BDS Drawer ========== */
.drawer-overlay {
position: fixed;
inset: 0;
background: rgba(0,0,0,0.5);
z-index: 200;
}
.bds-drawer {
position: fixed;
top: 0;
right: -420px;
width: 400px;
max-width: 90vw;
height: 100vh;
background: var(--bg-secondary);
border-left: 1px solid var(--border);
z-index: 201;
transition: right var(--transition);
display: flex;
flex-direction: column;
box-shadow: var(--shadow);
}
.bds-drawer.open { right: 0; }
.drawer-header {
display: flex;
align-items: center;
justify-content: space-between;
padding: 16px;
border-bottom: 1px solid var(--border);
}
.drawer-body {
flex: 1;
overflow-y: auto;
padding: 16px;
}
.drawer-section {
margin-bottom: 24px;
padding-bottom: 20px;
border-bottom: 1px solid var(--border);
}
.drawer-section:last-child { border-bottom: none; margin-bottom: 0; }
.drawer-section textarea {
width: 100%;
background: var(--bg-surface);
border: 1px solid var(--border);
border-radius: var(--radius-sm);
color: var(--text-primary);
padding: 10px;
font-family: var(--font-mono);
font-size: 12px;
resize: vertical;
}
.drawer-section textarea:focus { outline: none; border-color: var(--accent); }

.memory-list, .skills-list, .characters-list { margin-bottom: 8px; }
.memory-item, .skill-item, .character-item {
display: flex;
align-items: center;
justify-content: space-between;
padding: 6px 10px;
background: var(--bg-surface);
border-radius: var(--radius-xs);
margin-bottom: 4px;
font-size: 13px;
}
.memory-item button, .skill-item button, .character-item button {
background: transparent;
border: none;
color: var(--text-muted);
cursor: pointer;
font-size: 14px;
}
.memory-item button:hover { color: var(--danger); }

/* ========== Modal ========== */
.modal-overlay {
position: fixed;
inset: 0;
background: rgba(0,0,0,0.6);
z-index: 300;
}
.modal {
position: fixed;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
z-index: 301;
padding: 24px;
min-width: 400px;
max-width: 90vw;
}
.modal input[type="text"] {
width: 100%;
padding: 10px 14px;
background: var(--bg-elevated);
border: 1px solid var(--border);
border-radius: var(--radius-sm);
color: var(--text-primary);
margin: 12px 0;
font-size: 13px;
}
.modal input[type="text"]:focus { outline: none; border-color: var(--accent); }

/* ========== Toast ========== */
.toast {
position: fixed;
bottom: 24px;
left: 50%;
transform: translateX(-50%);
background: var(--bg-elevated);
color: var(--text-primary);
padding: 10px 20px;
border-radius: var(--radius-sm);
border: 1px solid var(--border);
z-index: 500;
font-size: 13px;
box-shadow: var(--shadow);
animation: toastIn 0.3s ease;
}
@keyframes toastIn { from { opacity: 0; transform: translateX(-50%) translateY(10px); } to { opacity: 1; transform: translateX(-50%) translateY(0); } }

/* ========== Loading Dots ========== */
.typing-indicator {
display: flex;
gap: 4px;
padding: 8px 0;
}
.typing-dot {
width: 8px;
height: 8px;
border-radius: 50%;
background: var(--text-muted);
animation: typingBounce 1.4s infinite;
}
.typing-dot:nth-child(2) { animation-delay: 0.2s; }
.typing-dot:nth-child(3) { animation-delay: 0.4s; }
@keyframes typingBounce { 0%, 60%, 100% { transform: translateY(0); } 30% { transform: translateY(-8px); } }

/* ========== LONG_WORK Indicator ========== */
.long-work-indicator {
display: flex;
align-items: center;
gap: 10px;
padding: 14px;
background: var(--bg-surface);
border: 1px solid var(--border);
border-radius: var(--radius);
margin: 8px 0;
animation: pulse 2s infinite;
}
@keyframes pulse { 0%, 100% { opacity: 1; } 50% { opacity: 0.6; } }
.long-work-spinner {
width: 20px;
height: 20px;
border: 2px solid var(--border);
border-top-color: var(--accent);
border-radius: 50%;
animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ========== Checkbox & Radio Styling ========== */
input[type="checkbox"], input[type="radio"] {
accent-color: var(--accent);
margin-right: 6px;
}

/* ========== Image Viewer Modal ========== */
.image-viewer {
position: fixed;
inset: 0;
background: rgba(0,0,0,0.9);
z-index: 400;
display: flex;
align-items: center;
justify-content: center;
cursor: pointer;
}
.image-viewer img { max-width: 90vw; max-height: 90vh; border-radius: var(--radius); }

/* ========== Responsive ========== */
@media (max-width: 768px) {
#sidebar { position: fixed; left: 0; top: 0; height: 100vh; z-index: 50; }
#sidebar.collapsed { margin-left: -260px; }
.modal { min-width: auto; width: 95vw; }
}