@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700&display=swap');

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

/* ===== DARK MODE (default) ===== */
:root {
  --bg: #1a1a1a;
  --sidebar-bg: #212121;
  --surface: #2a2a2a;
  --surface2: #303030;
  --border: #3a3a3a;
  --accent: #2563EB;
  --accent-hover: #1E40AF;
  --text: #ececec;
  --text-muted: #888;
  --text-dim: #aaa;
  --user-bubble: #2d3748;
  --danger: #ef4444;
  --success: #22c55e;
  --sidebar-width: 260px;
  --panel-width: 420px;
  --code-bg: #0d1117;
  --inline-code-bg: #252525;
}

/* ===== LIGHT MODE — Claude.ai-inspired beige palette ===== */
:root.light {
  --bg: #faf9f5;
  --sidebar-bg: #f0ede3;
  --surface: #e8e3d8;
  --surface2: #ddd8cc;
  --border: #ccc8be;
  --accent: #2563EB;
  --accent-hover: #1E40AF;
  --text: #1a1a18;
  --text-muted: #6b6860;
  --text-dim: #7a766c;
  --user-bubble: #e2ddd4;
  --danger: #dc2626;
  --success: #16a34a;
  --code-bg: #f0ede3;
  --inline-code-bg: #e4dfd4;
}

body { font-family: 'Inter', system-ui, sans-serif; background: var(--bg); color: var(--text); height: 100vh; overflow: hidden; display: flex; transition: background 0.2s, color 0.2s; }

/* Scrollbars */
::-webkit-scrollbar { width: 4px; height: 4px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 4px; }

/* Login */
#login-screen { display: flex; align-items: center; justify-content: center; width: 100vw; height: 100vh; background: var(--bg); flex-direction: column; gap: 24px; }
.login-card { background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 40px; width: 360px; display: flex; flex-direction: column; gap: 20px; }
.login-logo { font-size: 24px; font-weight: 700; color: var(--text); text-align: center; }
.login-logo span { color: var(--accent); }
.login-input { width: 100%; padding: 10px 14px; background: var(--bg); border: 1px solid var(--border); border-radius: 8px; color: var(--text); font-size: 14px; font-family: inherit; outline: none; transition: border-color 0.2s; }
.login-input:focus { border-color: var(--accent); }
.login-btn { width: 100%; padding: 11px; background: var(--accent); border: none; border-radius: 8px; color: white; font-size: 14px; font-weight: 600; cursor: pointer; font-family: inherit; transition: background 0.2s; }
.login-btn:hover { background: var(--accent-hover); }
.login-error { color: var(--danger); font-size: 13px; text-align: center; }

/* App layout */
#app { display: flex; width: 100vw; height: 100vh; overflow: hidden; }

/* Sidebar */
#sidebar { width: var(--sidebar-width); background: var(--sidebar-bg); border-right: 1px solid var(--border); display: flex; flex-direction: column; flex-shrink: 0; overflow: hidden; }
.sidebar-header { padding: 14px 12px; border-bottom: 1px solid var(--border); }
.logo { font-size: 16px; font-weight: 600; color: var(--text); display: flex; align-items: center; gap: 8px; }
.logo-icon { width: 26px; height: 26px; background: var(--accent); border-radius: 6px; display: flex; align-items: center; justify-content: center; font-size: 13px; }
.new-chat-btn { width: 100%; margin-top: 10px; padding: 8px 12px; background: var(--accent); border: none; border-radius: 8px; color: white; font-size: 13px; font-weight: 500; cursor: pointer; font-family: inherit; display: flex; align-items: center; gap: 6px; justify-content: center; transition: background 0.15s; }
.new-chat-btn:hover { background: var(--accent-hover); }
.sidebar-search { padding: 8px 10px; background: var(--bg); border: 1px solid var(--border); border-radius: 7px; color: var(--text); font-size: 12px; font-family: inherit; outline: none; width: 100%; margin-top: 8px; }
.sidebar-search:focus { border-color: var(--accent); }
.sidebar-nav { padding: 6px 8px; border-bottom: 1px solid var(--border); display: flex; gap: 4px; }
.nav-tab { flex: 1; padding: 6px; background: none; border: none; border-radius: 6px; color: var(--text-muted); font-size: 12px; font-weight: 500; cursor: pointer; font-family: inherit; transition: all 0.15s; text-align: center; }
.nav-tab.active { background: var(--surface); color: var(--text); }
.nav-tab:hover:not(.active) { color: var(--text-dim); }
.sidebar-content { flex: 1; overflow-y: auto; padding: 6px; }
.section-label { font-size: 10px; font-weight: 600; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.5px; padding: 8px 6px 4px; }
.chat-item, .project-item { display: flex; align-items: center; gap: 7px; padding: 7px 8px; border-radius: 7px; cursor: pointer; transition: background 0.12s; position: relative; }
.chat-item:hover, .project-item:hover { background: var(--surface); }
.chat-item.active { background: var(--surface2); }
.project-item.active { background: var(--surface2); }
.chat-item-title, .project-item-name { flex: 1; font-size: 12.5px; color: var(--text-dim); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chat-item.active .chat-item-title { color: var(--text); }
.project-item.active .project-item-name { color: var(--text); }
.chat-item-actions, .project-item-actions { display: none; gap: 1px; }
.chat-item:hover .chat-item-actions, .project-item:hover .project-item-actions { display: flex; }
.action-btn { padding: 2px 4px; background: none; border: none; color: var(--text-muted); cursor: pointer; border-radius: 4px; font-size: 11px; line-height: 1.4; }
.action-btn:hover { background: var(--border); color: var(--text); }

/* Main area — expands to fill all space not taken by open panels */
#main { flex: 1; display: flex; flex-direction: column; overflow: hidden; min-width: 0; transition: flex 0.25s ease; }
.main-header { padding: 10px 20px; border-bottom: 1px solid var(--border); display: flex; align-items: center; justify-content: space-between; min-height: 48px; gap: 8px; }
.skills-always-btn { margin-left: auto; flex-shrink: 0; }
.chat-title-display { font-size: 13px; font-weight: 600; color: var(--text); text-align: center; flex: 1; }
.header-actions { display: flex; gap: 6px; }
.header-btn { padding: 5px 11px; background: var(--surface); border: 1px solid var(--border); border-radius: 7px; color: var(--text-dim); font-size: 12px; font-weight: 500; cursor: pointer; font-family: inherit; transition: all 0.12s; }
.header-btn:hover { background: var(--surface2); color: var(--text); }

/* Messages */
#messages-area { flex: 1; overflow-y: auto; padding: 24px 20px 16px; display: flex; flex-direction: column; gap: 0; }

/* Centered content column — no hard max-width when panels are open */
.messages-inner { max-width: 820px; margin: 0 auto; width: 100%; display: flex; flex-direction: column; gap: 4px; }
#app.panel-open .messages-inner { max-width: 100%; padding: 0 8px; }

.empty-state { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 12px; color: var(--text-muted); }
.empty-state-icon { font-size: 40px; opacity: 0.3; }
.empty-state-text { font-size: 14px; }

/* Messages */
.message { display: flex; gap: 12px; max-width: 820px; margin: 0 auto; width: 100%; padding: 6px 0; }
#app.panel-open .message { max-width: 100%; }
.message.user { flex-direction: row-reverse; }

.message-avatar { width: 30px; height: 30px; border-radius: 7px; flex-shrink: 0; display: flex; align-items: center; justify-content: center; font-size: 13px; font-weight: 600; margin-top: 2px; }
.message.user .message-avatar { background: var(--accent); color: white; }
.message.assistant .message-avatar { background: var(--surface2); color: var(--text); }

.message-content { flex: 1; min-width: 0; }

/* User bubble */
.message.user .message-bubble {
  background: var(--user-bubble);
  border-radius: 18px;
  border-bottom-right-radius: 6px;
  padding: 10px 16px;
  font-size: 14px;
  line-height: 1.6;
  word-wrap: break-word;
  max-width: 75%;
  margin-left: auto;
  color: var(--text);
}

/* AI message — no bubble, flows naturally */
.message.assistant .message-bubble {
  background: transparent;
  padding: 4px 0;
  font-size: 14px;
  line-height: 1.7;
  word-wrap: break-word;
  color: var(--text);
}

.message-bubble.thinking { color: var(--text-muted); font-style: italic; padding: 8px 0; }
.message-bubble.streaming-bubble::after { content: '▋'; display: inline-block; animation: blink-cursor 0.7s step-end infinite; opacity: 0.7; }
@keyframes blink-cursor { 0%, 100% { opacity: 0.7; } 50% { opacity: 0; } }
.message-bubble.thinking-stale { color: var(--text-muted); font-style: italic; padding: 8px 0; display: flex; align-items: center; gap: 6px; }
.message-bubble p { margin-bottom: 10px; }
.message-bubble p:last-child { margin-bottom: 0; }
.message-bubble pre { background: var(--code-bg); border: 1px solid var(--border); border-radius: 10px; padding: 14px; overflow-x: auto; margin: 12px 0; font-size: 13px; position: relative; }
.message-bubble code { font-family: 'Fira Code', 'Cascadia Code', monospace; font-size: 13px; }
.message-bubble :not(pre) > code { background: var(--inline-code-bg); padding: 2px 6px; border-radius: 4px; font-size: 12px; border: 1px solid var(--border); }
.message-bubble h1, .message-bubble h2, .message-bubble h3 { margin: 16px 0 8px; color: var(--text); font-weight: 600; }
.message-bubble ul, .message-bubble ol { padding-left: 20px; margin: 8px 0; }
.message-bubble li { margin: 5px 0; }
.message-bubble blockquote { border-left: 3px solid var(--accent); padding-left: 14px; color: var(--text-dim); margin: 10px 0; }
.message-bubble table { width: 100%; border-collapse: collapse; margin: 12px 0; font-size: 13px; }
.message-bubble th, .message-bubble td { padding: 8px 12px; border: 1px solid var(--border); text-align: left; }
.message-bubble th { background: var(--surface2); }
.message-bubble a { color: var(--accent); text-decoration: none; }
.message-bubble a:hover { text-decoration: underline; }
.copy-code-btn { position: absolute; top: 8px; right: 8px; padding: 3px 8px; background: var(--surface); border: 1px solid var(--border); border-radius: 5px; color: var(--text-muted); font-size: 11px; cursor: pointer; font-family: inherit; }
.copy-code-btn:hover { color: var(--text); }
.artifact-link { display: inline-flex; align-items: center; gap: 6px; padding: 4px 10px; background: var(--accent); border-radius: 6px; color: white; font-size: 12px; font-weight: 500; cursor: pointer; margin-top: 8px; border: none; font-family: inherit; }
.artifact-link:hover { background: var(--accent-hover); }
.message-attachments { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 8px; }
.message-timestamp { font-size: 11px; color: var(--text-muted); margin-top: 4px; font-family: 'Fira Code', 'Cascadia Code', monospace; opacity: 0.6; }
.message.user .message-content { display: flex; flex-direction: column; align-items: flex-end; }
.attachment-chip { display: flex; align-items: center; gap: 4px; padding: 4px 8px; background: var(--surface); border: 1px solid var(--border); border-radius: 6px; font-size: 12px; color: var(--text-dim); }

/* Input area */
#input-area { padding: 12px 20px 16px; background: var(--bg); }
.input-wrap { max-width: 820px; margin: 0 auto; }
#app.panel-open .input-wrap { max-width: 100%; }
.input-attachments { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 8px; }
.input-attachment { display: flex; align-items: center; gap: 4px; padding: 4px 8px; background: var(--surface); border: 1px solid var(--border); border-radius: 6px; font-size: 12px; color: var(--text-dim); }
.input-attachment-remove { background: none; border: none; color: var(--text-muted); cursor: pointer; padding: 0 2px; font-size: 14px; line-height: 1; }
.input-row { display: flex; align-items: flex-end; gap: 8px; background: var(--surface); border: 1px solid var(--border); border-radius: 16px; padding: 10px 14px; transition: border-color 0.2s; box-shadow: 0 2px 8px rgba(0,0,0,0.3); }
.input-row:focus-within { border-color: var(--accent); }
#msg-input { flex: 1; background: none; border: none; color: var(--text); font-size: 14px; font-family: inherit; resize: none; outline: none; max-height: 150px; min-height: 20px; line-height: 1.5; }
#msg-input::placeholder { color: var(--text-muted); }
.input-btn { padding: 6px 8px; background: none; border: none; color: var(--text-muted); cursor: pointer; border-radius: 6px; font-size: 15px; transition: all 0.12s; flex-shrink: 0; }
.input-btn:hover { background: var(--surface2); color: var(--text); }
.input-btn.record.recording { color: var(--danger); animation: pulse 1s infinite; }
.send-btn { padding: 6px 14px; background: var(--accent); border: none; border-radius: 10px; color: white; font-size: 14px; cursor: pointer; font-family: inherit; font-weight: 500; transition: background 0.12s; flex-shrink: 0; }
.send-btn:hover { background: var(--accent-hover); }
.send-btn:disabled { opacity: 0.4; cursor: not-allowed; }

/* Artifact panel — participates in flex layout, pushes chat left */
#artifact-panel {
  width: 0;
  min-width: 0;
  background: var(--sidebar-bg);
  border-left: none;
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  overflow: hidden;
  transition: width 0.25s ease, min-width 0.25s ease, border-left 0.25s ease;
}
#artifact-panel.open {
  width: var(--panel-width);
  min-width: var(--panel-width);
  border-left: 1px solid var(--border);
}
.artifact-header { padding: 12px 16px; border-bottom: 1px solid var(--border); display: flex; align-items: center; justify-content: space-between; }
.artifact-title { font-size: 13px; font-weight: 600; color: var(--text); }
.artifact-close { background: none; border: none; color: var(--text-muted); cursor: pointer; font-size: 18px; padding: 2px 6px; border-radius: 4px; }
.artifact-close:hover { background: var(--border); color: var(--text); }
.artifact-tabs { display: flex; padding: 8px; gap: 4px; border-bottom: 1px solid var(--border); }
.artifact-tab { flex: 1; padding: 6px; background: none; border: none; border-radius: 6px; color: var(--text-muted); font-size: 11px; font-weight: 500; cursor: pointer; font-family: inherit; text-align: center; }
.artifact-tab.active { background: var(--surface); color: var(--text); }
.artifact-body { flex: 1; overflow: auto; padding: 12px; }
.artifact-body pre { background: var(--code-bg); border: 1px solid var(--border); border-radius: 8px; padding: 12px; font-size: 12px; overflow-x: auto; }
.artifact-actions { padding: 12px; border-top: 1px solid var(--border); display: flex; gap: 8px; }
.artifact-action-btn { flex: 1; padding: 8px; background: var(--surface); border: 1px solid var(--border); border-radius: 8px; color: var(--text); font-size: 12px; font-weight: 500; cursor: pointer; font-family: inherit; transition: all 0.15s; }
.artifact-action-btn:hover { background: var(--surface2); }
.artifact-action-btn.primary { background: var(--accent); border-color: var(--accent); color: white; }
.artifact-action-btn.primary:hover { background: var(--accent-hover); }

/* Modal */
.modal-overlay { position: fixed; inset: 0; background: rgba(0,0,0,0.65); display: flex; align-items: center; justify-content: center; z-index: 100; }
.modal { background: var(--surface); border: 1px solid var(--border); border-radius: 14px; padding: 24px; width: 420px; display: flex; flex-direction: column; gap: 16px; box-shadow: 0 8px 32px rgba(0,0,0,0.5); }
.modal h3 { font-size: 16px; font-weight: 600; }
.modal-input { width: 100%; padding: 9px 12px; background: var(--bg); border: 1px solid var(--border); border-radius: 8px; color: var(--text); font-size: 13px; font-family: inherit; outline: none; }
.modal-input:focus { border-color: var(--accent); }
.modal-textarea { min-height: 80px; resize: vertical; }
.modal-actions { display: flex; gap: 8px; justify-content: flex-end; }
.modal-btn { padding: 8px 16px; border: 1px solid var(--border); border-radius: 8px; font-size: 13px; font-weight: 500; cursor: pointer; font-family: inherit; transition: all 0.12s; }
.modal-btn.primary { background: var(--accent); border-color: var(--accent); color: white; }
.modal-btn.primary:hover { background: var(--accent-hover); }
.modal-btn.secondary { background: var(--surface2); color: var(--text); border-color: var(--border); }
.modal-btn.secondary:hover { background: var(--border); }

/* Share view */
.share-container { max-width: 700px; margin: 0 auto; padding: 40px 20px; }
.share-header { margin-bottom: 24px; }

/* Drag overlay */
.drag-overlay { position: absolute; inset: 0; background: rgba(37, 99, 235, 0.1); border: 2px dashed var(--accent); border-radius: 8px; display: flex; align-items: center; justify-content: center; z-index: 50; pointer-events: none; }

@keyframes pulse { 0%, 100% { opacity: 1; } 50% { opacity: 0.5; } }
@keyframes spin { to { transform: rotate(360deg); } }
.spinner { display: inline-block; width: 14px; height: 14px; border: 2px solid var(--border); border-top-color: var(--accent); border-radius: 50%; animation: spin 0.8s linear infinite; }

/* ========================
   Project Page
   ======================== */
.project-page {
  max-width: 760px;
  margin: 0 auto;
  width: 100%;
  padding: 32px 16px 48px;
  display: flex;
  flex-direction: column;
  gap: 32px;
}

.project-page-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
}

.project-page-title {
  font-size: 26px;
  font-weight: 700;
  color: var(--text);
  line-height: 1.2;
}

.project-page-header-actions {
  display: flex;
  gap: 8px;
  flex-shrink: 0;
  margin-top: 4px;
}

.project-page-section {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.project-section-title {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--border);
}

.project-instructions-text {
  font-size: 14px;
  color: var(--text-dim);
  line-height: 1.65;
  white-space: pre-wrap;
  background: var(--surface);
  padding: 14px 16px;
  border-radius: 10px;
  border: 1px solid var(--border);
}

/* Files drop zone */
.project-files-drop {
  border: 2px dashed var(--border);
  border-radius: 10px;
  padding: 24px;
  text-align: center;
  transition: border-color 0.15s, background 0.15s;
  cursor: default;
}

.project-files-drop.dragover {
  border-color: var(--accent);
  background: rgba(37, 99, 235, 0.06);
}

.project-files-drop-hint {
  font-size: 13px;
  color: var(--text-muted);
}

.project-files-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.project-file-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 9px;
  transition: background 0.12s;
}

.project-file-item:hover { background: var(--surface2); }

.project-file-icon { font-size: 15px; flex-shrink: 0; }
.project-file-name { flex: 1; font-size: 13px; color: var(--text); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.project-file-size { font-size: 12px; color: var(--text-muted); flex-shrink: 0; }

.project-files-empty {
  font-size: 13px;
  color: var(--text-muted);
  padding: 12px 0;
  text-align: center;
}

/* Project chats list */
.project-chats-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.project-chat-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 11px 14px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 9px;
  cursor: pointer;
  transition: background 0.12s;
}

.project-chat-item:hover { background: var(--surface2); }

.project-chat-title { flex: 1; font-size: 13px; color: var(--text); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.project-chat-date { font-size: 11px; color: var(--text-muted); flex-shrink: 0; }
.project-page-spinner { color: var(--text-muted); font-size: 14px; padding: 40px; text-align: center; }

/* ========================
   Skills Panel — participates in flex, pushes chat left
   ======================== */
#workflows-panel {
  width: 0;
  min-width: 0;
  background: var(--sidebar-bg);
  border-left: none;
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  overflow: hidden;
  transition: width 0.25s ease, min-width 0.25s ease, border-left 0.25s ease;
  position: relative;
}
#workflows-viewer {
  display: flex;
  flex-direction: column;
  flex: 1;
  overflow: hidden;
}
#workflows-panel.open {
  width: var(--panel-width);
  min-width: var(--panel-width);
  border-left: 1px solid var(--border);
}

#skills-panel {
  width: 0;
  min-width: 0;
  background: var(--sidebar-bg);
  border-left: none;
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  overflow: hidden;
  transition: width 0.25s ease, min-width 0.25s ease, border-left 0.25s ease;
  position: relative;
}
#skills-panel.open {
  width: var(--panel-width);
  min-width: var(--panel-width);
  border-left: 1px solid var(--border);
}

.skills-header {
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-shrink: 0;
}
.skills-title { font-size: 13px; font-weight: 600; color: var(--text); }

.skills-search-wrap { padding: 8px 10px; border-bottom: 1px solid var(--border); flex-shrink: 0; }
.skills-search {
  width: 100%;
  padding: 7px 10px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 7px;
  color: var(--text);
  font-size: 12px;
  font-family: inherit;
  outline: none;
}
.skills-search:focus { border-color: var(--accent); }

.skills-list { flex: 1; overflow-y: auto; padding: 6px; }

.skills-loading { padding: 20px; color: var(--text-muted); font-size: 13px; text-align: center; }

.skills-source-label {
  font-size: 10px;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  padding: 8px 6px 4px;
}

.skill-item {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 9px 10px;
  border-radius: 8px;
  cursor: pointer;
  transition: background 0.12s;
  border: 1px solid transparent;
}
.skill-item:hover { background: var(--surface); border-color: var(--border); }
.skill-item.active { background: var(--surface2); border-color: var(--accent); }

.skill-item-name {
  font-size: 13px;
  font-weight: 500;
  color: var(--text);
}
.skill-item-desc {
  font-size: 11px;
  color: var(--text-muted);
  line-height: 1.4;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.skill-item-badge {
  display: inline-block;
  font-size: 9px;
  font-weight: 600;
  padding: 1px 5px;
  border-radius: 3px;
  text-transform: uppercase;
  letter-spacing: 0.4px;
  margin-top: 2px;
  width: fit-content;
}
.skill-item-badge.workspace { background: rgba(37,99,235,0.2); color: #60a5fa; }
.skill-item-badge.system { background: rgba(34,197,94,0.15); color: #4ade80; }
.skill-item-footer { display: flex; align-items: center; justify-content: space-between; margin-top: 2px; }
.skill-move-btn {
  opacity: 0;
  background: none;
  border: none;
  cursor: pointer;
  font-size: 12px;
  padding: 1px 4px;
  color: var(--text-muted);
  border-radius: 4px;
  transition: opacity 0.15s, background 0.12s;
}
.skill-item:hover .skill-move-btn { opacity: 1; }
.skill-move-btn:hover { background: var(--surface2); color: var(--text); }
.skill-item.dragging { opacity: 0.45; }

/* Skills toolbar */
.skills-toolbar {
  padding: 6px 6px 4px;
  display: flex;
  align-items: center;
  gap: 6px;
}
.skills-add-folder-btn {
  font-size: 11px;
  font-weight: 600;
  padding: 4px 10px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text-dim);
  cursor: pointer;
  font-family: inherit;
  transition: background 0.12s, color 0.12s;
}
.skills-add-folder-btn:hover { background: var(--surface2); color: var(--text); }

/* Skills folder */
.skills-folder { margin-bottom: 2px; }
.skills-folder-header {
  display: flex;
  align-items: center;
  gap: 5px;
  padding: 7px 8px 7px 6px;
  border-radius: 8px;
  cursor: pointer;
  transition: background 0.12s;
  border: 2px solid transparent;
}
.skills-folder-header:hover { background: var(--surface); }
.skills-folder-header.drag-over { border-color: var(--accent); background: var(--surface2); }
.skills-folder-chevron { font-size: 10px; color: var(--text-muted); width: 12px; flex-shrink: 0; }
.skills-folder-icon { font-size: 14px; flex-shrink: 0; }
.skills-folder-name { flex: 1; font-size: 13px; font-weight: 600; color: var(--text); min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.skills-folder-count { font-size: 10px; color: var(--text-muted); background: var(--surface); border-radius: 10px; padding: 1px 6px; flex-shrink: 0; }
.skills-folder-actions { display: flex; gap: 2px; opacity: 0; transition: opacity 0.15s; }
.skills-folder-header:hover .skills-folder-actions { opacity: 1; }
.skills-folder-btn {
  background: none;
  border: none;
  cursor: pointer;
  font-size: 12px;
  padding: 2px 5px;
  color: var(--text-muted);
  border-radius: 4px;
  transition: background 0.12s, color 0.12s;
}
.skills-folder-btn:hover { background: var(--surface2); color: var(--text); }
.skills-folder-contents { padding-left: 20px; }
.skills-folder-empty {
  padding: 8px 10px;
  font-size: 11px;
  color: var(--text-muted);
  font-style: italic;
  border: 1px dashed var(--border);
  border-radius: 6px;
  margin: 3px 0;
  text-align: center;
}
.skill-remove-from-folder {
  background: none;
  border: none;
  cursor: pointer;
  font-size: 10px;
  padding: 1px 4px;
  color: var(--text-muted);
  border-radius: 4px;
  opacity: 0;
  transition: opacity 0.15s;
}
.skill-item:hover .skill-remove-from-folder { opacity: 1; }
.skill-remove-from-folder:hover { background: var(--surface2); color: var(--danger); }



/* Skill viewer */
#skills-viewer {
  position: absolute;
  inset: 0;
  background: var(--sidebar-bg);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.skills-viewer-header {
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 10px;
  flex-shrink: 0;
}
.skills-back-btn {
  padding: 5px 10px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 7px;
  color: var(--text-dim);
  font-size: 12px;
  cursor: pointer;
  font-family: inherit;
  flex-shrink: 0;
}
.skills-back-btn:hover { background: var(--surface2); color: var(--text); }
.skills-viewer-name {
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.skills-viewer-body {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  font-size: 13px;
  line-height: 1.7;
  color: var(--text);
}
.skills-viewer-body h1 { font-size: 17px; margin: 12px 0 8px; }
.skills-viewer-body h2 { font-size: 15px; margin: 12px 0 6px; }
.skills-viewer-body h3 { font-size: 13px; margin: 10px 0 5px; }
.skills-viewer-body p { margin-bottom: 8px; }
.skills-viewer-body ul, .skills-viewer-body ol { padding-left: 18px; margin: 6px 0; }
.skills-viewer-body li { margin: 4px 0; }
.skills-viewer-body pre { background: var(--code-bg); border: 1px solid var(--border); border-radius: 8px; padding: 12px; overflow-x: auto; margin: 10px 0; font-size: 12px; }
.skills-viewer-body code { font-family: 'Fira Code', 'Cascadia Code', monospace; font-size: 12px; }
.skills-viewer-body :not(pre) > code { background: var(--inline-code-bg); padding: 2px 5px; border-radius: 4px; font-size: 11px; border: 1px solid var(--border); word-break: break-all; overflow-wrap: anywhere; max-width: 100%; display: inline; white-space: pre-wrap; }
.skills-viewer-body blockquote { border-left: 3px solid var(--accent); padding-left: 12px; color: var(--text-dim); margin: 8px 0; }
.skills-viewer-body pre { max-width: 100%; white-space: pre-wrap; word-break: break-word; }
.skills-viewer-body table { width: 100%; border-collapse: collapse; font-size: 12px; margin: 10px 0; }
.skills-viewer-body th { background: var(--surface2); color: var(--text); font-weight: 600; text-align: left; padding: 7px 10px; border: 1px solid var(--border); font-size: 11px; }
.skills-viewer-body td { padding: 6px 10px; border: 1px solid var(--border); color: var(--text-dim); vertical-align: top; }
.skills-viewer-body tr:nth-child(even) td { background: var(--surface); }
.skills-viewer-body hr { border: none; border-top: 1px solid var(--border); margin: 12px 0; }
.skills-viewer-loading { color: var(--text-muted); padding: 20px; text-align: center; font-size: 13px; }

/* Light mode login card */
:root.light .login-card { box-shadow: 0 2px 16px rgba(0,0,0,0.08); }
:root.light .input-row { box-shadow: 0 2px 8px rgba(0,0,0,0.06); }
:root.light .modal { box-shadow: 0 8px 32px rgba(0,0,0,0.12); }
:root.light .completion-toast { box-shadow: 0 4px 16px rgba(0,0,0,0.12); }

/* Responsive */
@media (max-width: 768px) {
  #sidebar { position: fixed; left: -100%; z-index: 20; transition: left 0.25s; }
  #sidebar.open { left: 0; }
  #artifact-panel { position: fixed; right: 0; top: 0; bottom: 0; z-index: 20; width: 320px !important; min-width: 0 !important; border-left: 1px solid var(--border) !important; }
  #skills-panel.open { position: fixed; right: 0; top: 0; bottom: 0; z-index: 20; width: 320px !important; min-width: 0 !important; }
  #workflows-panel.open { position: fixed; right: 0; top: 0; bottom: 0; z-index: 20; width: 320px !important; min-width: 0 !important; }
  .project-page { padding: 20px 12px 40px; }
  .project-page-header { flex-direction: column; }
}

/* === Chat title: clickable project link === */
.header-project-link {
  color: var(--accent);
  cursor: pointer;
  font-weight: 600;
  transition: opacity 0.12s;
}
.header-project-link:hover { opacity: 0.75; text-decoration: underline; }
.header-title-sep { color: var(--text-muted); }

/* === Sidebar chats tab: project name as clickable prefix === */
.chat-item-project-name {
  color: var(--accent);
  cursor: pointer;
  font-size: 11px;
  font-weight: 600;
  white-space: nowrap;
}
.chat-item-project-name:hover { opacity: 0.75; text-decoration: underline; }
.chat-item-sep { color: var(--text-muted); font-size: 11px; }
.new-reply-badge {
  flex-shrink: 0;
  font-size: 9px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: #fff;
  background: var(--accent);
  border-radius: 4px;
  padding: 1px 5px;
  line-height: 16px;
  margin-left: 4px;
  animation: badge-pulse 1.5s ease-in-out infinite;
}
@keyframes badge-pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.6; }
}
.chat-item-title { flex: 1; font-size: 12.5px; color: var(--text-dim); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chat-item.active .chat-item-title { color: var(--text); }

/* === Sidebar projects tab: collapsible folders with child chats === */
.project-group { margin-bottom: 2px; }
.project-chevron {
  font-size: 9px;
  color: var(--text-muted);
  cursor: pointer;
  padding: 2px 4px;
  border-radius: 3px;
  flex-shrink: 0;
}
.project-chevron:hover { background: var(--surface2); color: var(--text); }
.project-item-name { cursor: pointer; flex: 1; }
.project-item-name:hover { color: var(--text); text-decoration: underline; }
.project-chat-indent {
  padding-left: 28px;
  margin-bottom: 4px;
}
.project-child-chat {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 5px 8px;
  border-radius: 6px;
  cursor: pointer;
  transition: background 0.12s;
}
.project-child-chat:hover { background: var(--surface); }
.project-child-chat.active { background: var(--surface2); }
.project-child-chat-title {
  font-size: 12px;
  color: var(--text-dim);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  flex: 1;
}
.project-child-chat.active .project-child-chat-title { color: var(--text); }
.project-no-chats { font-size: 11px; color: var(--text-muted); padding: 4px 8px; }

/* === Search: content results & spinner === */
.search-spinner {
  position: absolute;
  right: 10px;
  top: 50%;
  transform: translateY(-50%);
  width: 12px;
  height: 12px;
  border: 2px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  pointer-events: none;
}

.search-section-label {
  font-size: 10px;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  padding: 6px 6px 2px;
}

.search-snippet {
  font-size: 11px;
  color: var(--text-muted);
  margin-top: 2px;
  line-height: 1.4;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 100%;
}

mark.search-highlight {
  background: rgba(37,99,235,0.3);
  color: var(--text);
  border-radius: 2px;
  padding: 0 1px;
  font-style: normal;
}

/* === Thinking indicator: rotating messages === */
.thinking-label { font-style: italic; }

/* === Completion toast === */
.completion-toast {
  position: fixed;
  bottom: 24px;
  right: 24px;
  background: var(--surface2);
  color: var(--success);
  border: 1px solid var(--success);
  border-radius: 10px;
  padding: 10px 18px;
  font-size: 13px;
  font-weight: 500;
  box-shadow: 0 4px 16px rgba(0,0,0,0.4);
  z-index: 9999;
  opacity: 0;
  transform: translateY(12px);
  transition: opacity 0.25s ease, transform 0.25s ease;
  pointer-events: none;
}
.completion-toast.show {
  opacity: 1;
  transform: translateY(0);
}

/* ========================
   Message action buttons (Copy / Retry on user messages)
   ======================== */
.message-actions {
  display: none;
  gap: 4px;
  margin-top: 5px;
  justify-content: flex-end;
}
.message.user:hover .message-actions {
  display: flex;
}
.msg-action-btn {
  padding: 3px 9px;
  background: none;
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text-muted);
  font-size: 11px;
  cursor: pointer;
  font-family: inherit;
  transition: all 0.12s;
}
.msg-action-btn:hover {
  background: var(--surface2);
  color: var(--text);
}
.msg-action-btn.primary {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
  font-weight: 500;
}
.msg-action-btn.primary:hover {
  opacity: 0.88;
  background: var(--accent);
  color: #fff;
}

/* === Inline message edit (after stop) === */
.message.user.editing .message-bubble { display: none; }
.message.user.editing .message-actions { display: none !important; }
.msg-edit-container {
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 2px 0;
}
.msg-edit-textarea {
  width: 100%;
  min-height: 60px;
  max-height: 300px;
  background: var(--surface);
  border: 1.5px solid var(--accent);
  border-radius: 10px;
  color: var(--text);
  font-family: inherit;
  font-size: 14px;
  line-height: 1.5;
  padding: 10px 12px;
  resize: none;
  outline: none;
  box-sizing: border-box;
  transition: border-color 0.12s;
}
.msg-edit-textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px rgba(var(--accent-rgb,99,102,241),0.18);
}
.msg-edit-toolbar {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
}
.msg-edit-file-btn {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 3px 9px;
  background: none;
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text-muted);
  font-size: 11px;
  cursor: pointer;
  font-family: inherit;
  transition: all 0.12s;
  white-space: nowrap;
}
.msg-edit-file-btn:hover {
  background: var(--surface2);
  color: var(--text);
}
.msg-edit-new-atts {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
}
.msg-edit-existing-atts, .edit-existing-atts {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 5px;
}
.edit-att-chip {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 3px 8px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 11px;
  color: var(--text-dim);
  opacity: 0.7;
}
.edit-att-note {
  font-size: 10px;
  color: var(--text-muted);
  opacity: 0.7;
  font-style: italic;
}

/* ========================
   Stop generation button
   ======================== */
.stop-btn {
  align-items: center;
  gap: 5px;
  padding: 6px 12px;
  background: transparent;
  border: 1px solid var(--danger);
  border-radius: 10px;
  color: var(--danger);
  font-size: 13px;
  cursor: pointer;
  font-family: inherit;
  font-weight: 500;
  transition: all 0.12s;
  flex-shrink: 0;
  white-space: nowrap;
}
.stop-btn:hover {
  background: rgba(239,68,68,0.12);
}

/* ========================
   Message queue
   ======================== */
#message-queue {
  max-width: 820px;
  margin: 0 auto 10px;
}
#app.panel-open #message-queue {
  max-width: 100%;
}
.queue-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 6px 12px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px 8px 0 0;
  border-bottom: none;
}
.queue-title {
  font-size: 11px;
  font-weight: 600;
  color: var(--text-muted);
  letter-spacing: 0.3px;
}
.queue-clear-all {
  font-size: 11px;
  padding: 2px 8px;
  background: none;
  border: 1px solid var(--border);
  border-radius: 5px;
  color: var(--danger);
  cursor: pointer;
  font-family: inherit;
  transition: background 0.12s;
}
.queue-clear-all:hover {
  background: rgba(239,68,68,0.1);
}
.queue-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 7px 12px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-top: 1px solid var(--border);
}
.queue-item + .queue-item {
  border-top: 1px solid var(--border);
}
.queue-item:last-child {
  border-radius: 0 0 8px 8px;
}
.queue-idx {
  font-size: 11px;
  color: var(--text-muted);
  flex-shrink: 0;
  width: 16px;
  text-align: center;
  font-weight: 600;
}
.queue-item-text {
  flex: 1;
  font-size: 12px;
  color: var(--text-dim);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.queue-item-actions {
  display: flex;
  gap: 4px;
  flex-shrink: 0;
}
.queue-btn {
  padding: 2px 8px;
  background: none;
  border: 1px solid var(--border);
  border-radius: 5px;
  color: var(--text-muted);
  font-size: 11px;
  cursor: pointer;
  font-family: inherit;
  transition: all 0.12s;
}
.queue-btn:hover {
  background: var(--surface2);
  color: var(--text);
}
.queue-btn.danger {
  color: var(--danger);
}
.queue-btn.danger:hover {
  background: rgba(239,68,68,0.12);
}
