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

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

:root {
  --bg-primary: #111113;
  --bg-secondary: #1a1a1e;
  --bg-card: #212126;
  --bg-input: #212126;
  --bg-sidebar: #0e0e10;
  --border: #2e2e33;
  --border-hover: #45454d;
  --text-primary: #ededef;
  --text-secondary: #9a9aa0;
  --text-dim: #62626a;
  --accent: #3b82f6;
  --accent-bright: #60a5fa;
  --accent-glow: rgba(59, 130, 246, 0.12);
  --cyan: #22d3ee;
  --orange: #f59e0b;
  --green: #34d399;
  --red: #f87171;
  --user-bg: linear-gradient(135deg, #2563eb 0%, #1d4ed8 100%);
  --bot-bg: #212126;
  --radius: 16px;
  --radius-sm: 10px;
  --radius-xs: 6px;
  --sidebar-width: 260px;
}

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

/* ── App Layout ── */
.app {
  display: flex;
  height: 100vh;
  height: 100dvh;
  width: 100%;
}

/* ── Sidebar (icon rail + expandable panel) ── */
.sidebar {
  display: flex;
  flex-direction: row;
  background: var(--bg-sidebar);
  border-right: 1px solid var(--border);
  overflow: hidden;
  height: 100%;
}

/* Icon Rail — always visible */
.sidebar-rail {
  width: 48px;
  min-width: 48px;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 10px 0;
  border-right: 1px solid var(--border);
  flex-shrink: 0;
}
.rail-top {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 8px;
  width: 100%;
}
.rail-nav {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  flex: 1;
}
.rail-bottom {
  margin-top: auto;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding-top: 8px;
}
.rail-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  border: none;
  border-radius: 8px;
  background: transparent;
  color: var(--text-dim);
  cursor: pointer;
  flex-shrink: 0;
  transition: background 0.15s, color 0.15s;
}
.rail-btn:hover {
  background: rgba(255, 255, 255, 0.06);
  color: var(--text-primary);
}
.rail-btn.active {
  color: var(--text-primary);
  background: rgba(255, 255, 255, 0.08);
}
.rail-avatar {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: linear-gradient(135deg, #2563eb, #1d4ed8);
  display: flex;
  align-items: center;
  justify-content: center;
  color: white;
}

/* Expandable Panel */
.sidebar-panel {
  width: 0;
  min-width: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  transition: width 0.2s ease, min-width 0.2s ease;
  position: relative;
}
.sidebar.expanded .sidebar-panel {
  width: 240px;
  min-width: 240px;
}

/* Mobile hamburger — hidden on desktop, visible on mobile */
#sidebar-toggle-mobile { display: none; }

/* Also keep the mobile sidebar-icon-btn in header */
.sidebar-icon-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  border: none;
  border-radius: 8px;
  background: transparent;
  color: var(--text-secondary);
  cursor: pointer;
  flex-shrink: 0;
  transition: background 0.15s, color 0.15s;
}
.sidebar-icon-btn:hover {
  background: var(--accent-glow);
  color: var(--accent-bright);
}

.sidebar-search {
  padding: 8px 10px;
  flex-shrink: 0;
}
.sidebar-search-input {
  width: 100%;
  padding: 7px 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg-primary);
  color: var(--text-primary);
  font-size: 13px;
  font-family: inherit;
  outline: none;
  transition: border-color 0.2s;
}
.sidebar-search-input::placeholder { color: var(--text-dim); }
.sidebar-search-input:focus { border-color: var(--accent); }

.session-list {
  overflow-y: auto;
  padding: 4px 0;
}
.session-list::-webkit-scrollbar { width: 4px; }
.session-list::-webkit-scrollbar-track { background: transparent; }
.session-list::-webkit-scrollbar-thumb { background: var(--border); border-radius: 2px; }

.session-group-label {
  padding: 12px 14px 4px;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.6px;
  color: var(--text-secondary);
}

.session-item {
  display: flex;
  align-items: center;
  padding: 8px 14px;
  cursor: pointer;
  transition: background 0.1s;
  position: relative;
  gap: 4px;
}
.session-item:hover { background: rgba(167, 139, 250, 0.08); }
.session-item.active {
  background: var(--accent-glow);
  border-left: 2px solid var(--accent);
  padding-left: 12px;
}
.session-title {
  font-size: 13px;
  color: var(--text-primary);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  flex: 1;
}
.session-item.active .session-title { color: var(--text-primary); }

.session-delete {
  display: none;
  border: none;
  background: transparent;
  color: var(--text-dim);
  font-size: 16px;
  cursor: pointer;
  padding: 0 4px;
  line-height: 1;
  flex-shrink: 0;
}
.session-item:hover .session-delete { display: block; }
.session-delete:hover { color: var(--red); }

.session-rename-input {
  flex: 1;
  min-width: 0;
  padding: 2px 6px;
  border: 1px solid var(--accent);
  border-radius: 4px;
  background: var(--bg-primary);
  color: var(--text-primary);
  font-size: 13px;
  font-family: inherit;
  outline: none;
}

.session-empty {
  padding: 24px 14px;
  text-align: center;
  font-size: 13px;
  color: var(--text-dim);
}

/* ── Tab Content Panels ── */
.sidebar-tab-content {
  display: none;
  flex-direction: column;
  flex: 1;
  overflow: hidden;
  min-height: 0;
}
.sidebar-tab-content.active {
  display: flex;
}
.sidebar-tab-content > .session-list,
.sidebar-tab-content > .project-list,
.sidebar-tab-content > .artifact-list,
.sidebar-tab-content > .code-list {
  flex: 1;
  overflow-y: auto;
}
.sidebar-tab-content > .project-list::-webkit-scrollbar,
.sidebar-tab-content > .artifact-list::-webkit-scrollbar,
.sidebar-tab-content > .code-list::-webkit-scrollbar {
  width: 4px;
}
.sidebar-tab-content > .project-list::-webkit-scrollbar-track,
.sidebar-tab-content > .artifact-list::-webkit-scrollbar-track,
.sidebar-tab-content > .code-list::-webkit-scrollbar-track {
  background: transparent;
}
.sidebar-tab-content > .project-list::-webkit-scrollbar-thumb,
.sidebar-tab-content > .artifact-list::-webkit-scrollbar-thumb,
.sidebar-tab-content > .code-list::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 2px;
}

/* ── Tab Panel Header ── */
.tab-panel-header {
  padding: 8px 14px;
  flex-shrink: 0;
}
.tab-panel-action {
  display: flex;
  align-items: center;
  gap: 6px;
  width: 100%;
  padding: 7px 10px;
  border: 1px dashed var(--border);
  border-radius: 6px;
  background: transparent;
  color: var(--text-dim);
  font-family: inherit;
  font-size: 12px;
  cursor: pointer;
  transition: border-color 0.15s, color 0.15s, background 0.15s;
}
.tab-panel-action:hover {
  border-color: var(--accent);
  color: var(--accent-bright);
  background: var(--accent-glow);
}

/* ── Project Items ── */
.project-item {
  padding: 0;
}
.project-header {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 14px;
  cursor: pointer;
  transition: background 0.1s;
}
.project-header:hover {
  background: rgba(167, 139, 250, 0.08);
}
.project-chevron {
  flex-shrink: 0;
  transition: transform 0.15s;
  color: var(--text-dim);
}
.project-item.expanded .project-chevron {
  transform: rotate(90deg);
}
.project-icon {
  flex-shrink: 0;
  color: var(--text-dim);
}
.project-name {
  flex: 1;
  font-size: 13px;
  color: var(--text-primary);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.project-count {
  font-size: 10px;
  color: var(--text-dim);
  background: rgba(255, 255, 255, 0.04);
  padding: 1px 6px;
  border-radius: 8px;
  flex-shrink: 0;
}
.project-delete {
  display: none;
  border: none;
  background: transparent;
  color: var(--text-dim);
  font-size: 16px;
  cursor: pointer;
  padding: 0 4px;
  line-height: 1;
  flex-shrink: 0;
}
.project-header:hover .project-delete {
  display: block;
}
.project-delete:hover {
  color: var(--red);
}
.project-sessions {
  display: none;
  padding-left: 12px;
}
.project-item.expanded .project-sessions {
  display: block;
}
.project-rename-input {
  flex: 1;
  min-width: 0;
  padding: 2px 6px;
  border: 1px solid var(--accent);
  border-radius: 4px;
  background: var(--bg-primary);
  color: var(--text-primary);
  font-size: 13px;
  font-family: inherit;
  outline: none;
}

/* ── Artifact Items ── */
.artifact-item {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 8px 14px;
  cursor: pointer;
  transition: background 0.1s;
}
.artifact-item:hover {
  background: rgba(167, 139, 250, 0.08);
}
.artifact-type-icon {
  flex-shrink: 0;
  width: 28px;
  height: 28px;
  border-radius: 6px;
  display: flex;
  align-items: center;
  justify-content: center;
  margin-top: 1px;
}
.artifact-type-icon.type-code {
  background: rgba(59, 130, 246, 0.12);
  color: var(--accent-bright);
}
.artifact-type-icon.type-table {
  background: rgba(52, 211, 153, 0.12);
  color: var(--green);
}
.artifact-type-icon.type-image {
  background: rgba(245, 158, 11, 0.12);
  color: var(--orange);
}
.artifact-info {
  flex: 1;
  min-width: 0;
}
.artifact-preview {
  font-size: 12px;
  color: var(--text-primary);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  line-height: 1.4;
}
.artifact-source {
  font-size: 11px;
  color: var(--text-dim);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  margin-top: 2px;
}

/* ── Code List Items ── */
.code-item {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 8px 14px;
  cursor: pointer;
  transition: background 0.1s;
}
.code-item:hover {
  background: rgba(167, 139, 250, 0.08);
}
.code-lang-badge {
  flex-shrink: 0;
  padding: 2px 6px;
  border-radius: 4px;
  font-size: 10px;
  font-weight: 600;
  font-family: 'SF Mono', 'Fira Code', monospace;
  text-transform: lowercase;
  background: rgba(59, 130, 246, 0.12);
  color: var(--accent-bright);
  margin-top: 2px;
}
.code-item-info {
  flex: 1;
  min-width: 0;
}
.code-item-preview {
  font-size: 12px;
  font-family: 'SF Mono', 'Fira Code', monospace;
  color: var(--text-primary);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  line-height: 1.4;
}
.code-item-source {
  font-size: 11px;
  color: var(--text-dim);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  margin-top: 2px;
}
.code-item-copy {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 24px;
  height: 24px;
  border: none;
  border-radius: 4px;
  background: transparent;
  color: var(--text-dim);
  cursor: pointer;
  opacity: 0;
  transition: opacity 0.15s, color 0.15s, background 0.15s;
  margin-top: 1px;
}
.code-item:hover .code-item-copy {
  opacity: 1;
}
.code-item-copy:hover {
  color: var(--text-primary);
  background: rgba(255, 255, 255, 0.08);
}
.code-item-copy.copied {
  color: var(--green);
}

/* ── Sidebar Profile Bar ── */
.sidebar-profile {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  border-top: 1px solid var(--border);
  cursor: pointer;
  flex-shrink: 0;
  transition: background 0.15s;
  position: relative;
}
.sidebar-profile:hover {
  background: rgba(255, 255, 255, 0.04);
}
.sidebar-profile-avatar {
  width: 30px;
  height: 30px;
  border-radius: 50%;
  background: linear-gradient(135deg, #2563eb, #1d4ed8);
  display: flex;
  align-items: center;
  justify-content: center;
  color: white;
  flex-shrink: 0;
}
.sidebar-profile-name {
  flex: 1;
  font-size: 13px;
  font-weight: 500;
  color: var(--text-primary);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.sidebar-profile-chevron {
  flex-shrink: 0;
  color: var(--text-dim);
  transition: transform 0.15s;
}
.sidebar-profile:hover .sidebar-profile-chevron {
  color: var(--text-secondary);
}

/* ── Profile Popover ── */
.profile-popover {
  display: none;
  position: absolute;
  bottom: 52px;
  left: 10px;
  right: 10px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  box-shadow: 0 -8px 32px rgba(0, 0, 0, 0.4);
  z-index: 20;
  overflow: hidden;
}
.profile-popover.visible {
  display: block;
}
.popover-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  cursor: pointer;
  transition: background 0.1s;
  font-size: 13px;
  color: var(--text-primary);
}
.popover-item:hover {
  background: rgba(255, 255, 255, 0.04);
}
.popover-item svg {
  flex-shrink: 0;
  color: var(--text-secondary);
}
.popover-divider {
  height: 1px;
  background: var(--border);
  margin: 2px 0;
}
.popover-select {
  margin-left: auto;
  padding: 3px 6px;
  border: 1px solid var(--border);
  border-radius: 4px;
  background: var(--bg-primary);
  color: var(--text-secondary);
  font-size: 11px;
  font-family: inherit;
  cursor: pointer;
  outline: none;
}
.popover-select:focus {
  border-color: var(--accent);
}
.popover-version {
  margin-left: auto;
  font-size: 11px;
  color: var(--text-dim);
}

/* ── Settings Panel ── */
.settings-panel {
  position: absolute;
  inset: 0;
  background: var(--bg-sidebar);
  display: flex;
  flex-direction: column;
  z-index: 25;
  transform: translateX(100%);
  transition: transform 0.2s ease;
}
.settings-panel.visible {
  transform: translateX(0);
}
.settings-header {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 14px 14px 10px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.settings-back {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  border: none;
  border-radius: 6px;
  background: transparent;
  color: var(--text-secondary);
  cursor: pointer;
  flex-shrink: 0;
  transition: background 0.15s, color 0.15s;
}
.settings-back:hover {
  background: var(--accent-glow);
  color: var(--accent-bright);
}
.settings-title {
  font-size: 14px;
  font-weight: 600;
  color: var(--text-primary);
}
.settings-restart-banner {
  display: none;
  align-items: center;
  gap: 6px;
  padding: 8px 14px;
  background: rgba(245, 158, 11, 0.12);
  border-bottom: 1px solid rgba(245, 158, 11, 0.2);
  font-size: 11px;
  color: #f59e0b;
}
.settings-restart-banner.visible {
  display: flex;
}
.settings-body {
  flex: 1;
  overflow-y: auto;
  padding: 8px 0;
}
.settings-body::-webkit-scrollbar { width: 4px; }
.settings-body::-webkit-scrollbar-track { background: transparent; }
.settings-body::-webkit-scrollbar-thumb { background: var(--border); border-radius: 2px; }
.settings-category {
  padding: 4px 0;
}
.settings-category-label {
  padding: 10px 14px 6px;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.6px;
  color: var(--text-secondary);
}
.settings-field {
  padding: 6px 14px 10px;
}
.settings-field-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 2px;
}
.settings-field-label {
  font-size: 12px;
  font-weight: 500;
  color: var(--text-primary);
}
.settings-required {
  color: #ef4444;
  margin-left: 2px;
}
.settings-field-status {
  font-size: 10px;
  font-weight: 500;
  padding: 1px 6px;
  border-radius: 4px;
}
.settings-field-status.set {
  color: #34d399;
  background: rgba(52, 211, 153, 0.1);
}
.settings-field-status.unset {
  color: var(--text-dim);
  background: rgba(255, 255, 255, 0.04);
}
.settings-env-name {
  display: flex;
  align-items: center;
  gap: 8px;
  font-family: 'SF Mono', 'Fira Code', monospace;
  font-size: 10px;
  color: var(--text-dim);
  margin-bottom: 4px;
}
.settings-help-link {
  font-family: 'Inter', system-ui, sans-serif;
  color: var(--accent-bright, #818cf8);
  text-decoration: none;
  font-size: 10px;
}
.settings-help-link:hover {
  text-decoration: underline;
}
.settings-input {
  width: 100%;
  padding: 6px 10px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--bg-primary);
  color: var(--text-primary);
  font-size: 12px;
  font-family: 'SF Mono', 'Fira Code', monospace;
  outline: none;
  transition: border-color 0.2s;
  box-sizing: border-box;
}
.settings-input::placeholder {
  color: var(--text-dim);
  font-family: 'Inter', system-ui, sans-serif;
}
.settings-input:focus {
  border-color: var(--accent, #6366f1);
}
.settings-footer {
  padding: 10px 14px;
  border-top: 1px solid var(--border);
  flex-shrink: 0;
}
.settings-save-btn {
  width: 100%;
  padding: 8px 16px;
  border: none;
  border-radius: 8px;
  background: var(--accent, #6366f1);
  color: #fff;
  font-size: 13px;
  font-weight: 500;
  font-family: inherit;
  cursor: pointer;
  transition: background 0.15s, opacity 0.15s;
}
.settings-save-btn:hover:not(:disabled) {
  background: var(--accent-bright, #818cf8);
}
.settings-save-btn:disabled {
  opacity: 0.4;
  cursor: default;
}
.settings-loading {
  padding: 24px 14px;
  text-align: center;
  font-size: 13px;
  color: var(--text-dim);
}
.settings-error {
  padding: 24px 14px;
  text-align: center;
  font-size: 13px;
  color: #ef4444;
}

/* ── Context Menu (move to project) ── */
.context-menu {
  position: fixed;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-xs);
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.4);
  z-index: 50;
  min-width: 160px;
  overflow: hidden;
}
.context-menu-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 14px;
  cursor: pointer;
  font-size: 12px;
  color: var(--text-primary);
  transition: background 0.1s;
}
.context-menu-item:hover {
  background: var(--accent-glow);
}
.context-menu-item svg {
  flex-shrink: 0;
  color: var(--text-secondary);
}
.context-menu-sub {
  padding-left: 28px;
}
.context-menu-divider {
  height: 1px;
  background: var(--border);
  margin: 2px 0;
}

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

/* ── Chat Header ── */
.chat-header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 20px;
  background: var(--bg-secondary);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.chat-header-title {
  flex: 1;
  font-size: 15px;
  font-weight: 600;
  color: var(--text-primary);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.status-dot {
  width: 8px; height: 8px;
  border-radius: 50%;
  background: var(--text-dim);
  transition: background 0.3s;
  flex-shrink: 0;
}
.status-dot.connected { background: var(--green); box-shadow: 0 0 8px rgba(52, 211, 153, 0.5); }
.status-dot.error { background: var(--red); }

/* ── Reconnect Banner ── */
.reconnect-banner {
  display: none;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 8px 16px;
  background: rgba(245, 158, 11, 0.95);
  color: #1a1a1a;
  font-size: 13px;
  font-weight: 600;
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  z-index: 100;
}
.reconnect-banner.visible { display: flex; }
.reconnect-spinner {
  width: 14px; height: 14px;
  border: 2px solid rgba(251, 191, 36, 0.3);
  border-top-color: #fbbf24;
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ══════════════════════════════════════════
   WELCOME MODE — Claude-style centered layout
   ══════════════════════════════════════════ */
.main.welcome-mode .chat-header {
  background: transparent;
  border-bottom: none;
}
.main.welcome-mode .chat-header-title {
  display: none;
}
.main.welcome-mode {
  justify-content: center;
}
.main.welcome-mode #messages {
  flex: 0;
  overflow: visible;
  padding: 0 24px 24px;
}
.main.welcome-mode .scroll-bottom,
.main.welcome-mode .typing {
  display: none !important;
}
.main.welcome-mode .input-area {
  background: transparent;
  border-top: none;
  padding-top: 0;
}
.main.welcome-mode .input-hint {
  justify-content: center;
}

/* ── Welcome Greeting ── */
.welcome {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 0;
  text-align: center;
}
.welcome-logo {
  width: 56px;
  height: 56px;
  border-radius: 14px;
  object-fit: contain;
  margin-bottom: 4px;
}
.welcome-greeting {
  font-size: 32px;
  font-weight: 700;
  color: var(--text-primary);
  letter-spacing: -0.8px;
  line-height: 1.2;
}
.welcome-sub {
  font-size: 14px;
  color: var(--text-dim);
  font-weight: 400;
}

/* ── Market Pulse (live stats on welcome) ── */
.welcome-pulse {
  display: flex;
  align-items: center;
  gap: 20px;
  margin-top: 4px;
  font-size: 12px;
  color: var(--text-dim);
  min-height: 20px;
}
.welcome-pulse-item {
  display: flex;
  align-items: center;
  gap: 6px;
  white-space: nowrap;
}
.welcome-pulse-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  flex-shrink: 0;
}
.welcome-pulse-dot.live {
  background: var(--green);
  box-shadow: 0 0 6px rgba(52, 211, 153, 0.5);
  animation: pulse-glow 2s ease-in-out infinite;
}
.welcome-pulse-dot.warn {
  background: var(--orange);
}
.welcome-pulse-value {
  font-weight: 600;
  color: var(--text-secondary);
  font-variant-numeric: tabular-nums;
}
.welcome-pulse-value.up { color: var(--green); }
.welcome-pulse-value.down { color: var(--red); }
@keyframes pulse-glow {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.4; }
}

/* ── Welcome Cards (below input) ── */
.welcome-cards {
  display: none;
  grid-template-columns: repeat(2, 1fr);
  gap: 10px;
  margin-top: 12px;
  max-width: 560px;
  margin-left: auto;
  margin-right: auto;
}
.main.welcome-mode .welcome-cards {
  display: grid;
}
.welcome-card {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  padding: 14px 16px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg-secondary);
  color: var(--text-secondary);
  font-family: inherit;
  font-size: 13px;
  cursor: pointer;
  text-align: left;
  transition: border-color 0.2s, background 0.2s, transform 0.15s, box-shadow 0.2s;
}
.welcome-card:hover {
  border-color: var(--border-hover);
  background: var(--bg-card);
  transform: translateY(-1px);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
}
.welcome-card-icon {
  width: 20px;
  height: 20px;
  flex-shrink: 0;
  margin-top: 1px;
  stroke: var(--accent);
  opacity: 0.8;
}
.welcome-card:hover .welcome-card-icon {
  opacity: 1;
}
.welcome-card-text {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}
.welcome-card-title {
  font-size: 13px;
  font-weight: 500;
  color: var(--text-primary);
  line-height: 1.3;
}
.welcome-card-sub {
  font-size: 12px;
  color: var(--text-dim);
  line-height: 1.3;
}

/* ── Messages ── */
#messages {
  flex: 1;
  overflow-y: auto;
  padding: 20px 24px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
#messages > * {
  max-width: 720px;
  width: 100%;
  margin-left: auto;
  margin-right: auto;
}
#messages::-webkit-scrollbar { width: 5px; }
#messages::-webkit-scrollbar-track { background: transparent; }
#messages::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }
#messages::-webkit-scrollbar-thumb:hover { background: var(--border-hover); }

.msg-row { display: flex; align-items: flex-end; gap: 10px; animation: fadeUp 0.25s ease-out; }
.msg-row.user-row { flex-direction: row-reverse; }
@keyframes fadeUp {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

.msg-avatar {
  width: 30px; height: 30px;
  border-radius: 50%;
  flex-shrink: 0;
  display: flex; align-items: center; justify-content: center;
  font-size: 14px;
  margin-bottom: 2px;
}
.bot-avatar {
  background: linear-gradient(135deg, #1e3a8a, #2563eb);
  color: #f59e0b;
}
.user-avatar {
  background: linear-gradient(135deg, #0891b2, #06b6d4);
  color: #0c0a1a;
  font-weight: 600;
}

.msg-bubble {
  max-width: 75%;
  padding: 12px 16px;
  line-height: 1.6;
  font-size: 14px;
  word-wrap: break-word;
  overflow-wrap: break-word;
}
.msg-bubble.user-bubble {
  background: var(--user-bg);
  color: #f5f3ff;
  border-radius: var(--radius) var(--radius) var(--radius-xs) var(--radius);
  white-space: pre-wrap;
}
.msg-content {
  flex: 1;
  min-width: 0;
}
.avatar-img {
  width: 100%;
  height: 100%;
  border-radius: 50%;
  object-fit: cover;
}
.msg-bubble.bot-bubble {
  background: var(--bg-card);
  color: var(--text-primary);
  border: 1px solid var(--border);
  border-radius: var(--radius) var(--radius) var(--radius) var(--radius-xs);
  max-width: 100%;
}
.msg-bubble.bot-bubble pre,
.msg-bubble.bot-bubble code {
  font-family: 'SF Mono', 'Fira Code', 'Cascadia Code', Consolas, monospace;
  font-size: 12.5px;
}
.msg-bubble.bot-bubble pre {
  background: rgba(0,0,0,0.3);
  padding: 10px 12px;
  border-radius: var(--radius-xs);
  margin: 8px 0;
  overflow-x: auto;
  border: 1px solid rgba(255,255,255,0.05);
  white-space: pre;
}
.msg-bubble.bot-bubble code {
  background: rgba(167, 139, 250, 0.12);
  padding: 2px 6px;
  border-radius: 4px;
  color: var(--accent-bright);
}
.msg-bubble.bot-bubble pre code {
  background: transparent;
  padding: 0;
  border-radius: 0;
  color: inherit;
}
.msg-bubble.bot-bubble a { color: var(--cyan); text-decoration: none; }
.msg-bubble.bot-bubble a:hover { text-decoration: underline; }
.msg-bubble.bot-bubble img {
  max-width: 100%;
  max-height: 70vh;
  object-fit: contain;
  border-radius: var(--radius-sm);
  margin-top: 8px;
}
.table-wrap {
  overflow-x: auto;
  margin: 8px 0;
}
.msg-bubble.bot-bubble table {
  border-collapse: collapse;
  font-size: 13px;
  width: 100%;
}
.msg-bubble.bot-bubble th,
.msg-bubble.bot-bubble td {
  border: 1px solid var(--border);
  padding: 4px 8px;
  text-align: left;
}
.msg-bubble.bot-bubble th {
  background: rgba(167, 139, 250, 0.1);
  font-weight: 600;
}
.msg-bubble.bot-bubble strong { color: var(--accent-bright); }
.msg-bubble.bot-bubble em { color: var(--text-secondary); font-style: italic; }
.msg-bubble.bot-bubble h1,
.msg-bubble.bot-bubble h2,
.msg-bubble.bot-bubble h3,
.msg-bubble.bot-bubble h4 {
  color: var(--text-primary);
  margin: 12px 0 6px;
  line-height: 1.3;
}
.msg-bubble.bot-bubble h1 { font-size: 18px; font-weight: 700; }
.msg-bubble.bot-bubble h2 { font-size: 16px; font-weight: 700; }
.msg-bubble.bot-bubble h3 { font-size: 15px; font-weight: 600; }
.msg-bubble.bot-bubble h4 { font-size: 14px; font-weight: 600; color: var(--text-secondary); }
.msg-bubble.bot-bubble h1:first-child,
.msg-bubble.bot-bubble h2:first-child,
.msg-bubble.bot-bubble h3:first-child,
.msg-bubble.bot-bubble h4:first-child { margin-top: 0; }
.msg-bubble.bot-bubble ul,
.msg-bubble.bot-bubble ol {
  margin: 6px 0;
  padding-left: 20px;
}
.msg-bubble.bot-bubble li {
  margin: 3px 0;
  line-height: 1.5;
}
.msg-bubble.bot-bubble blockquote {
  border-left: 3px solid var(--accent);
  padding: 4px 12px;
  margin: 8px 0;
  color: var(--text-secondary);
  background: rgba(167, 139, 250, 0.06);
  border-radius: 0 var(--radius-xs) var(--radius-xs) 0;
}
.msg-bubble.bot-bubble hr {
  border: none;
  border-top: 1px solid var(--border);
  margin: 12px 0;
}

/* ── Code Block with Header ── */
.code-block {
  margin: 8px 0;
  border-radius: var(--radius-xs);
  border: 1px solid rgba(255,255,255,0.05);
  overflow: hidden;
}
.msg-bubble.bot-bubble .code-block pre {
  margin: 0;
  border: none;
  border-radius: 0;
}
.code-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 6px 12px;
  background: rgba(0,0,0,0.4);
  border-bottom: 1px solid rgba(255,255,255,0.05);
  font-size: 12px;
}
.code-lang {
  color: var(--text-dim);
  font-size: 11px;
  text-transform: lowercase;
}
.code-copy {
  display: flex;
  align-items: center;
  gap: 4px;
  border: none;
  background: transparent;
  color: var(--text-dim);
  font-size: 11px;
  font-family: inherit;
  cursor: pointer;
  padding: 2px 6px;
  border-radius: 4px;
  transition: color 0.15s, background 0.15s;
}
.code-copy:hover {
  color: var(--text-primary);
  background: rgba(255,255,255,0.08);
}
.code-copy.copied { color: var(--green); }
.code-copy svg { flex-shrink: 0; }

/* ── Message Actions ── */
.msg-actions {
  display: flex;
  align-items: center;
  gap: 2px;
  padding: 4px 0 0;
  opacity: 0;
  transition: opacity 0.15s;
}
.msg-row:hover .msg-actions { opacity: 1; }
.msg-copy {
  display: flex;
  align-items: center;
  gap: 4px;
  border: none;
  border-radius: 6px;
  background: transparent;
  color: var(--text-dim);
  cursor: pointer;
  padding: 4px 8px;
  font-size: 12px;
  font-family: inherit;
  transition: color 0.15s, background 0.15s;
}
.msg-copy svg { flex-shrink: 0; }
.msg-copy:hover { color: var(--text-primary); background: rgba(255,255,255,0.08); }
.msg-copy.copied { color: var(--green); }

/* ── Edit Button ── */
.user-row .msg-actions { justify-content: flex-end; }
.msg-edit {
  display: flex;
  align-items: center;
  justify-content: center;
  border: none;
  border-radius: 6px;
  background: transparent;
  color: var(--text-dim);
  cursor: pointer;
  padding: 4px 6px;
  transition: color 0.15s, background 0.15s;
}
.msg-edit:hover { color: var(--text-primary); background: rgba(255,255,255,0.08); }
.msg-edit svg { flex-shrink: 0; }

/* ── Timestamps ── */
.msg-time {
  font-size: 11px;
  color: var(--text-dim);
  opacity: 0;
  transition: opacity 0.15s;
  padding: 2px 0 0;
}
.msg-row:hover .msg-time { opacity: 1; }
.user-row .msg-time { text-align: right; }

/* ── Stop Button ── */
#send-btn.stop-mode svg { display: none; }
#send-btn.stop-mode::before {
  content: '';
  width: 14px; height: 14px;
  background: var(--text-primary);
  border-radius: 2px;
}

/* ── Attach Button ── */
.attach-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  flex-shrink: 0;
  border: none;
  border-radius: 8px;
  background: transparent;
  color: var(--text-dim);
  cursor: pointer;
  transition: color 0.15s, background 0.15s;
}
.attach-btn:hover { color: var(--text-primary); background: rgba(255,255,255,0.08); }
.attach-btn.has-file { color: var(--accent); }
.file-preview {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 12px;
  margin: 0 0 6px 0;
  background: var(--bg-card);
  border: 1px solid var(--accent);
  border-radius: 10px;
  font-size: 13px;
  color: var(--text-primary);
  max-width: 720px;
  width: fit-content;
  margin-left: auto;
  margin-right: auto;
}
.file-preview-icon { font-size: 16px; flex-shrink: 0; }
.file-preview-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; }
.file-preview-remove {
  background: none;
  border: none;
  color: var(--text-dim);
  font-size: 18px;
  cursor: pointer;
  padding: 0 2px;
  line-height: 1;
  flex-shrink: 0;
}
.file-preview-remove:hover { color: var(--text-primary); }
.attach-btn svg { flex-shrink: 0; }

/* ── Mic Button ── */
.mic-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  flex-shrink: 0;
  border: none;
  border-radius: 8px;
  background: transparent;
  color: var(--text-dim);
  cursor: pointer;
  transition: color 0.15s, background 0.15s;
}
.mic-btn:hover { color: var(--text-primary); background: rgba(255,255,255,0.08); }
.mic-btn.listening {
  color: var(--red);
  animation: mic-pulse 1.5s ease-in-out infinite;
}
.mic-btn.unsupported { display: none; }
@keyframes mic-pulse {
  0%, 100% { background: rgba(248, 113, 113, 0.1); }
  50% { background: rgba(248, 113, 113, 0.25); }
}

/* ── Scroll to Bottom ── */
.scroll-bottom {
  display: none;
  position: absolute;
  bottom: 90px;
  left: 50%;
  transform: translateX(-50%);
  width: 36px;
  height: 36px;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: var(--bg-card);
  color: var(--text-secondary);
  cursor: pointer;
  align-items: center;
  justify-content: center;
  z-index: 5;
  box-shadow: 0 4px 12px rgba(0,0,0,0.3);
  transition: background 0.15s, border-color 0.15s, color 0.15s;
}
.scroll-bottom.visible { display: flex; }
.scroll-bottom:hover {
  background: var(--accent-glow);
  border-color: var(--accent);
  color: var(--accent-bright);
}

/* ── Skeleton Loading ── */
.session-loading {
  padding: 16px 14px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.skeleton-line {
  height: 12px;
  background: linear-gradient(90deg, var(--bg-card) 25%, rgba(167, 139, 250, 0.08) 50%, var(--bg-card) 75%);
  background-size: 200% 100%;
  animation: shimmer 1.5s infinite;
  border-radius: 6px;
}
.skeleton-line.short { width: 60%; }
@keyframes shimmer {
  0% { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}

.msg-system {
  text-align: center;
  font-size: 12px;
  color: var(--text-dim);
  padding: 8px 16px;
  animation: fadeUp 0.25s ease-out;
}
.msg-system .pill {
  display: inline-block;
  padding: 4px 14px;
  background: var(--accent-glow);
  border: 1px solid rgba(167, 139, 250, 0.15);
  border-radius: 20px;
  color: var(--text-secondary);
}

/* ── Typing indicator ── */
.typing {
  display: none;
  align-items: flex-end;
  gap: 10px;
  padding: 0 24px 6px;
  max-width: 720px;
  width: 100%;
  margin-left: auto;
  margin-right: auto;
}
.typing.visible { display: flex; }
.typing-indicator {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 16px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius) var(--radius) var(--radius) var(--radius-xs);
  font-size: 13px;
  color: var(--text-dim);
}
.typing-spinner {
  width: 16px;
  height: 16px;
  border: 2px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: typing-spin 0.8s linear infinite;
}
@keyframes typing-spin {
  to { transform: rotate(360deg); }
}
.typing-label {
  font-weight: 500;
  color: var(--text-secondary);
}
.typing-elapsed {
  color: var(--text-dim);
  font-size: 12px;
  font-variant-numeric: tabular-nums;
}

/* ── Input Area ── */
.input-area {
  padding: 16px 24px 20px;
  background: var(--bg-secondary);
  border-top: 1px solid var(--border);
  flex-shrink: 0;
  position: relative;
}
.input-area > * {
  max-width: 720px;
  margin-left: auto;
  margin-right: auto;
}
.input-wrap {
  display: flex;
  align-items: flex-end;
  gap: 10px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 4px 4px 4px 18px;
  transition: border-color 0.2s, box-shadow 0.2s;
}
.input-wrap:focus-within {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-glow);
}
#input {
  flex: 1;
  border: none;
  background: transparent;
  color: var(--text-primary);
  font-size: 14px;
  font-family: inherit;
  outline: none;
  padding: 10px 0;
  resize: none;
  overflow-y: auto;
  max-height: 200px;
  line-height: 1.5;
}
#input::placeholder { color: var(--text-dim); }
#send-btn {
  width: 40px; height: 40px;
  border: none;
  border-radius: 12px;
  background: linear-gradient(135deg, #2563eb 0%, #1d4ed8 100%);
  color: white;
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
  transition: transform 0.1s, box-shadow 0.2s, opacity 0.2s;
  opacity: 0.5;
}
#send-btn.active { opacity: 1; }
#send-btn:hover { transform: translateY(-1px); box-shadow: 0 4px 16px rgba(124, 58, 237, 0.4); }
#send-btn:active { transform: scale(0.95); }
#send-btn svg { width: 18px; height: 18px; }

.input-hint {
  display: flex;
  justify-content: center;
  margin-top: 8px;
  font-size: 11px;
  color: var(--text-dim);
  padding: 0 4px;
}
.input-hint kbd {
  background: rgba(255,255,255,0.06);
  padding: 1px 6px;
  border-radius: 4px;
  font-family: inherit;
  font-size: 11px;
}

/* ── Command Palette ── */
.cmd-palette {
  display: none;
  position: absolute;
  bottom: 100%;
  left: 0; right: 0;
  max-height: 380px;
  overflow-y: auto;
  background: var(--bg-primary);
  border: 1px solid var(--border);
  border-bottom: none;
  border-radius: var(--radius) var(--radius) 0 0;
  z-index: 100;
  box-shadow: 0 -12px 48px rgba(0,0,0,0.5);
  scrollbar-width: thin;
  scrollbar-color: var(--border) transparent;
}
.cmd-palette::-webkit-scrollbar { width: 6px; }
.cmd-palette::-webkit-scrollbar-track { background: transparent; }
.cmd-palette::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }
.cmd-palette.visible { display: block; }
.cmd-palette-header {
  padding: 12px 16px;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.8px;
  color: var(--text-dim);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  background: var(--bg-primary);
  display: flex;
  align-items: center;
  justify-content: space-between;
  z-index: 1;
  backdrop-filter: blur(8px);
}
.cmd-palette-hint {
  font-size: 10px;
  color: var(--text-dim);
  font-weight: 400;
  letter-spacing: 0;
  text-transform: none;
}
.cmd-palette-hint kbd {
  background: rgba(255,255,255,0.06);
  padding: 1px 5px;
  border-radius: 3px;
  font-family: inherit;
  font-size: 10px;
  margin: 0 1px;
}
.cmd-back {
  padding: 8px 16px;
  font-size: 11px;
  color: var(--text-dim);
  cursor: pointer;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 6px;
}
.cmd-back:hover { color: var(--accent); }

/* Super-category section header */
.cmd-super-header {
  padding: 14px 16px 6px;
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.8px;
  color: var(--text-secondary);
  border-top: 1px solid var(--border);
}
.cmd-super-header:first-child {
  border-top: none;
}

.cmd-category { border-bottom: 1px solid rgba(45,39,85,0.3); }
.cmd-category:last-child { border-bottom: none; }
.cmd-category-label {
  padding: 8px 16px 4px 24px;
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.8px;
  color: var(--text-dim);
  display: flex;
  align-items: center;
  gap: 6px;
}
.cmd-category-icon { font-size: 12px; opacity: 0.7; }
.cmd-category-count {
  margin-left: auto;
  font-size: 9px;
  font-weight: 500;
  color: var(--text-dim);
  background: rgba(255,255,255,0.04);
  padding: 1px 6px;
  border-radius: 8px;
}
.cmd-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 7px 16px 7px 28px;
  cursor: pointer;
  transition: background 0.1s;
}
.cmd-item:hover, .cmd-item.active { background: var(--accent-glow); }
.cmd-item.active { border-left: 2px solid var(--accent); padding-left: 26px; }
.cmd-item-name {
  font-family: 'SF Mono', 'Fira Code', 'Cascadia Code', monospace;
  font-size: 13px;
  font-weight: 600;
  color: var(--accent-bright);
  min-width: 140px;
  flex-shrink: 0;
}
.cmd-item-desc {
  font-size: 12px;
  color: var(--text-secondary);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  flex: 1;
}

/* ── Touch devices ── */
@media (hover: none) {
  .msg-actions { opacity: 1; }
}

/* ── Sidebar Backdrop (mobile only) ── */
.sidebar-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.5);
  z-index: 9;
}

/* ── Mobile ── */
@media (max-width: 768px) {
  .sidebar {
    position: fixed;
    left: 0; top: 0; bottom: 0;
    z-index: 10;
    transform: translateX(-100%);
    transition: transform 0.2s;
  }
  .sidebar.expanded {
    transform: translateX(0);
  }
  .sidebar.expanded .sidebar-panel {
    width: 200px;
    min-width: 200px;
  }
  #sidebar-toggle-mobile { display: flex; }

  .chat-header { padding: 10px 16px; }
  #messages { padding: 16px; }
  .input-area { padding: 12px 16px 16px; }
  .msg-bubble { max-width: 85%; }
  .msg-avatar { width: 26px; height: 26px; font-size: 12px; }
  .welcome-greeting { font-size: 24px; }
  .welcome-cards { grid-template-columns: 1fr; max-width: 300px; }
  .input-hint { display: none; }
  .input-area { padding-bottom: calc(16px + env(safe-area-inset-bottom, 0px)); }
  .sidebar-backdrop.visible { display: block; }
}

/* ── Focus Visible ── */
:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}
button:focus:not(:focus-visible),
input:focus:not(:focus-visible),
textarea:focus:not(:focus-visible) {
  outline: none;
}
