:root {
  --bg: #181818;
  --sidebar: #141414;
  --panel: #1e1e1e;
  --panel-hover: #2a2a2a;
  --input-bg: #252526;
  --text: #cccccc;
  --text-bright: #e8e8e8;
  --muted: #858585;
  --border: #2b2b2b;
  --border-light: #3c3c3c;
  --accent: #0078d4;
  --accent-hover: #1a86d9;
  --fairy-accent: #00e5c0;
  --success: #4ec9b0;
  --danger: #f48771;
  --warn: #cca700;
  --avatar-size: 28px;
  --header-h: 44px;
  --sidebar-w: 48px;
  --chat-font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
  --chat-font-size: 13px;
  --chat-bg: var(--panel);
  --user-bubble-bg: #264f78;
  --user-bubble-text: #ffffff;
  --assistant-bubble-bg: #2a2a2a;
  --assistant-bubble-text: #e8e8e8;
  --bubble-radius: 12px;
  --bubble-border: transparent;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
  font-size: 13px;
}

#app {
  display: flex;
  height: 100dvh;
  overflow: hidden;
}

.activity-bar {
  width: var(--sidebar-w);
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 8px 0;
  gap: 4px;
  background: var(--sidebar);
  border-right: 1px solid var(--border);
}

.activity-brand {
  width: 32px;
  height: 32px;
  border-radius: 8px;
  overflow: hidden;
  margin-bottom: 4px;
}

.activity-brand img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.activity-btn {
  width: 36px;
  height: 36px;
  border: none;
  border-radius: 8px;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.12s, color 0.12s;
}

.activity-btn:hover,
.activity-btn.active {
  background: var(--panel-hover);
  color: var(--text-bright);
}

.activity-spacer { flex: 1; }

.conn-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  margin-bottom: 8px;
  background: var(--muted);
}

.conn-dot.online { background: var(--success); box-shadow: 0 0 6px rgba(78, 201, 176, 0.5); }
.conn-dot.offline { background: #5a5a5a; }
.conn-dot.connecting { background: var(--warn); animation: pulse-dot 1.2s ease infinite; }

@keyframes pulse-dot {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.4; }
}

.main-panel {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
  background: var(--panel);
  position: relative;
}

.chat-header {
  height: var(--header-h);
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 16px;
  border-bottom: 1px solid var(--border);
}

.chat-header-left {
  display: flex;
  align-items: center;
  gap: 8px;
}

.chat-title {
  margin: 0;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-bright);
  cursor: pointer;
  border-radius: 4px;
  padding: 2px 4px;
  margin-left: -4px;
}

.chat-title:hover {
  background: var(--panel-hover);
}

.chat-title-input,
.conv-rename-input {
  width: 100%;
  min-width: 80px;
  font: inherit;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-bright);
  background: var(--input-bg, #2a2a2a);
  border: 1px solid var(--accent);
  border-radius: 4px;
  padding: 4px 8px;
  outline: none;
}

.chat-title-input {
  max-width: 240px;
}

.mode-badge {
  font-size: 11px;
  padding: 2px 8px;
  border-radius: 4px;
  background: rgba(0, 120, 212, 0.15);
  color: #6cb6ff;
  border: 1px solid rgba(0, 120, 212, 0.25);
}

.status {
  font-size: 11px;
  color: var(--muted);
  font-family: "Cascadia Code", "Consolas", monospace;
}

.status.online { color: var(--success); }
.status.connecting { color: var(--warn); }

.chat-body {
  flex: 1;
  position: relative;
  min-height: 0;
  display: flex;
}

.messages {
  flex: 1;
  overflow-y: auto;
  padding: 16px 20px 24px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  max-width: 820px;
  width: 100%;
  margin: 0 auto;
  background: var(--chat-bg);
  font-family: var(--chat-font-family);
  font-size: var(--chat-font-size);
}

.msg-row {
  display: flex;
  gap: 12px;
  padding: 10px 4px;
  max-width: 100%;
  border-radius: 6px;
}

.msg-row:hover { background: rgba(255, 255, 255, 0.02); }

.msg-row.user {
  justify-content: flex-end;
  width: 100%;
}

.msg-row.assistant {
  justify-content: flex-start;
  width: 100%;
}

.avatar {
  width: var(--avatar-size);
  height: var(--avatar-size);
  border-radius: 6px;
  flex-shrink: 0;
  object-fit: cover;
  margin-top: 2px;
}

.msg-row.assistant .avatar {
  border-radius: 50%;
  box-shadow: 0 0 0 1px rgba(0, 229, 192, 0.25);
}

.msg {
  flex: 1;
  min-width: 0;
  max-width: calc(100% - var(--avatar-size) - 12px);
  line-height: 1.6;
  white-space: pre-wrap;
  word-break: break-word;
  font-size: inherit;
  font-family: inherit;
  padding: 8px 12px;
  border-radius: var(--bubble-radius);
  border: 1px solid var(--bubble-border);
}

.msg-row.user .msg {
  flex: 0 1 auto;
  max-width: min(75%, calc(100% - var(--avatar-size) - 12px));
  text-align: left;
  background: var(--user-bubble-bg);
  color: var(--user-bubble-text);
}

.msg-row.user .msg-body {
  text-align: left;
  color: inherit;
}

.msg-row.assistant .msg {
  flex: 0 1 auto;
  max-width: min(85%, calc(100% - var(--avatar-size) - 12px));
  background: var(--assistant-bubble-bg);
  color: var(--assistant-bubble-text);
}

.msg-row.assistant .msg-body {
  color: inherit;
}

html[data-bubble-style="flat"] {
  --bubble-radius: 4px;
  --bubble-border: var(--border-light);
}

html[data-bubble-style="rounded"] {
  --bubble-radius: 12px;
  --bubble-border: transparent;
}

html[data-bubble-style="pill"] {
  --bubble-radius: 20px;
  --bubble-border: transparent;
}

.msg.system {
  align-self: center;
  max-width: 90%;
  padding: 8px 12px;
  margin: 4px 0;
  border-radius: 6px;
  font-size: 12px;
  text-align: center;
  border: 1px solid var(--border);
  background: var(--input-bg);
  color: var(--muted);
}

.msg.system.success { border-color: rgba(78, 201, 176, 0.4); color: var(--success); }
.msg.system.error { border-color: rgba(244, 135, 113, 0.4); color: var(--danger); }
.msg.system.warn { border-color: rgba(204, 167, 0, 0.4); color: var(--warn); }
.msg.system.info { border-color: rgba(0, 120, 212, 0.35); color: #6cb6ff; }

.msg.system .sys-action { margin-top: 8px; }

.msg.system .sys-action button {
  font-size: 12px;
  padding: 4px 10px;
  border-radius: 4px;
  border: 1px solid var(--border-light);
  background: var(--panel-hover);
  color: var(--text);
  cursor: pointer;
}

.msg-actions {
  margin-top: 8px;
  display: flex;
  gap: 6px;
  opacity: 0;
  transition: opacity 0.12s;
}

.msg-row:hover .msg-actions { opacity: 1; }

.msg-actions button {
  font-size: 11px;
  padding: 3px 8px;
  border-radius: 4px;
  border: 1px solid var(--border-light);
  background: transparent;
  color: var(--muted);
  cursor: pointer;
}

.msg-actions button:hover {
  background: var(--panel-hover);
  color: var(--text);
}

.typing-row .typing-panel {
  flex: 1;
  min-width: 0;
  display: grid;
  gap: 8px;
}

.typing-row .typing-bubble {
  font-size: 12px;
  color: var(--muted);
  font-family: "Cascadia Code", "Consolas", monospace;
  animation: thinking-pulse 1.4s ease-in-out infinite;
}

.thinking-steps-live,
.thinking-log-list {
  display: grid;
  gap: 8px;
}

.thinking-log {
  margin-bottom: 10px;
  padding: 8px 10px;
  border: 1px solid rgba(0, 229, 192, 0.18);
  border-radius: 6px;
  background: rgba(0, 229, 192, 0.04);
}

.thinking-log > summary {
  cursor: pointer;
  font-size: 12px;
  color: var(--fairy-accent);
  user-select: none;
}

.thinking-step {
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--input-bg);
  overflow: hidden;
}

.thinking-step-head {
  padding: 6px 10px;
  font-size: 11px;
  color: var(--muted);
  border-bottom: 1px solid var(--border);
  font-family: "Cascadia Code", "Consolas", monospace;
}

.thinking-step-body {
  margin: 0;
  padding: 8px 10px;
  font-size: 12px;
  line-height: 1.5;
  white-space: pre-wrap;
  word-break: break-word;
  color: var(--text);
  font-family: "Cascadia Code", "Consolas", monospace;
  max-height: 220px;
  overflow: auto;
}

.thinking-step-tool_call .thinking-step-head { color: #6cb6ff; }
.thinking-step-tool_result .thinking-step-head { color: var(--success); }
.thinking-step-reasoning .thinking-step-head { color: #c586c0; }

.typing-row .typing-bubble::before {
  content: "● ";
  color: var(--fairy-accent);
  animation: blink 1s step-end infinite;
}

@keyframes blink { 50% { opacity: 0; } }
@keyframes thinking-pulse {
  0%, 100% { opacity: 0.55; }
  50% { opacity: 1; }
}

.side-panel {
  width: min(300px, 78vw);
  flex-shrink: 0;
  height: 100%;
  display: flex;
  flex-direction: column;
  background: var(--sidebar);
  border-right: 1px solid var(--border);
  min-width: 0;
}

.side-panel.hidden { display: none; }

.side-view {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-height: 0;
}

.side-view.hidden { display: none; }

.side-panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 14px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.side-panel-header h2 {
  margin: 0;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-bright);
}

.conversation-list {
  list-style: none;
  margin: 0;
  padding: 8px;
  overflow-y: auto;
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.conv-row {
  display: flex;
  align-items: stretch;
  gap: 2px;
}

.conv-empty {
  color: var(--muted);
  font-size: 12px;
  padding: 16px 10px;
}

.conv-item {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 2px;
  border: none;
  border-radius: 8px;
  background: transparent;
  color: var(--text);
  padding: 8px 10px;
  cursor: pointer;
  text-align: left;
  font: inherit;
}

.conv-item:hover { background: var(--panel-hover); }

.conv-item.active {
  background: var(--panel-hover);
  box-shadow: inset 2px 0 0 var(--accent);
}

.conv-item-title {
  font-size: 13px;
  color: var(--text-bright);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 100%;
}

.conv-item-meta {
  font-size: 11px;
  color: var(--muted);
}

.conv-rename-btn {
  flex-shrink: 0;
  width: 28px;
  border: none;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  border-radius: 8px;
  font-size: 13px;
  line-height: 1;
}

.conv-rename-btn:hover {
  background: var(--panel-hover);
  color: var(--text-bright);
}

.conv-delete-btn {
  flex-shrink: 0;
  width: 28px;
  border: none;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  border-radius: 8px;
  font-size: 16px;
  line-height: 1;
}

.conv-delete-btn:hover {
  background: rgba(244, 135, 113, 0.16);
  color: var(--danger);
}

.settings-section-title {
  margin: 12px 0 2px;
  font-size: 11px;
  font-weight: 600;
  color: var(--fairy-accent);
  letter-spacing: 0.04em;
}

.settings-inline-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-top: 8px;
}

.field-hint {
  float: right;
  color: var(--muted);
  font-size: 11px;
}

.settings-panel-body select,
.settings-panel-body input[type="color"],
.settings-panel-body input[type="file"] {
  width: 100%;
  padding: 8px 10px;
  border-radius: 4px;
  border: 1px solid var(--border-light);
  background: var(--input-bg);
  color: var(--text);
  font: inherit;
}

.settings-panel-body input[type="color"] {
  height: 36px;
  padding: 4px;
  cursor: pointer;
}

.settings-panel-body input[type="file"] {
  padding: 6px 8px;
  font-size: 12px;
}

.settings-panel-body select:focus,
.settings-panel-body input[type="color"]:focus {
  outline: 1px solid var(--accent);
  border-color: var(--accent);
}

.settings-panel-footer {
  padding: 12px 16px;
  border-top: 1px solid var(--border);
  display: grid;
  gap: 8px;
}

.settings-panel-body {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  display: grid;
  gap: 10px;
  align-content: start;
}

.settings-panel-body label {
  font-size: 11px;
  color: var(--muted);
  margin-top: 4px;
}

.settings-panel-body input {
  width: 100%;
  padding: 8px 10px;
  border-radius: 4px;
  border: 1px solid var(--border-light);
  background: var(--input-bg);
  color: var(--text);
  font: inherit;
}

.settings-panel-body input:focus {
  outline: 1px solid var(--accent);
  border-color: var(--accent);
}

.settings-panel-footer .btn-secondary,
.settings-panel-footer .btn-primary {
  width: 100%;
}

.icon-btn-sm {
  border: none;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  padding: 4px 8px;
  border-radius: 4px;
}

.icon-btn-sm:hover {
  background: var(--panel-hover);
  color: var(--text);
}

.btn-primary, .btn-secondary {
  padding: 8px 14px;
  border-radius: 4px;
  cursor: pointer;
  font-size: 13px;
  font-weight: 500;
  border: none;
}

.btn-primary {
  background: var(--accent);
  color: #fff;
  width: 100%;
}

.btn-primary:hover { background: var(--accent-hover); }

.btn-secondary {
  background: var(--input-bg);
  color: var(--text);
  border: 1px solid var(--border-light);
}

.btn-secondary:hover { background: var(--panel-hover); }

.confirm-bar {
  position: absolute;
  inset: 0;
  z-index: 20;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  padding: 24px;
  background: rgba(0, 0, 0, 0.5);
}

.confirm-bar.hidden { display: none; }

.confirm-inner {
  width: min(480px, 100%);
  background: var(--sidebar);
  border: 1px solid var(--border-light);
  border-radius: 8px;
  padding: 16px;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.5);
}

.confirm-label {
  font-size: 11px;
  font-weight: 600;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.confirm-bar p {
  margin: 12px 0 16px;
  font-size: 12px;
  line-height: 1.5;
  max-height: 120px;
  overflow-y: auto;
  font-family: "Cascadia Code", "Consolas", monospace;
  background: var(--input-bg);
  padding: 10px;
  border-radius: 4px;
  border: 1px solid var(--border);
}

.confirm-actions {
  display: flex;
  gap: 8px;
  justify-content: flex-end;
}

.confirm-actions .btn-primary,
.confirm-actions .btn-secondary { width: auto; min-width: 88px; }

.confirm-actions button:disabled { opacity: 0.5; cursor: not-allowed; }

.composer {
  flex-shrink: 0;
  padding: 12px 16px 10px;
  border-top: 1px solid var(--border);
  background: var(--panel);
}

.composer.hidden { display: none; }

.composer-inner {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  max-width: 820px;
  margin: 0 auto;
  padding: 8px 10px;
  border-radius: 8px;
  border: 1px solid var(--border-light);
  background: var(--input-bg);
}

.composer-inner:focus-within { border-color: var(--accent); }

.composer-tool {
  flex-shrink: 0;
  border: none;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  padding: 4px;
  font-size: 16px;
}

.composer-tool:hover { color: var(--text); }
.composer-tool:disabled { opacity: 0.35; cursor: not-allowed; }

#input {
  flex: 1;
  resize: none;
  min-height: 24px;
  max-height: min(40vh, 360px);
  overflow-y: auto;
  padding: 2px 0;
  border: none;
  background: transparent;
  color: var(--text-bright);
  font: inherit;
  line-height: 1.5;
  field-sizing: content;
}

#input:focus { outline: none; }
#input::placeholder { color: var(--muted); }

.send-btn {
  flex-shrink: 0;
  width: 28px;
  height: 28px;
  border: none;
  border-radius: 6px;
  background: var(--accent);
  color: #fff;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}

.send-btn:hover { background: var(--accent-hover); }

.stop-btn {
  flex-shrink: 0;
  height: 28px;
  padding: 0 10px;
  border: none;
  border-radius: 6px;
  background: var(--danger);
  color: #1a1a1a;
  cursor: pointer;
  font: inherit;
  font-size: 12px;
  font-weight: 600;
}

.stop-btn:hover { filter: brightness(1.08); }
.stop-btn.hidden { display: none; }
.send-btn.hidden { display: none; }

.attach-preview {
  max-width: 820px;
  margin: 8px auto 0;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.attach-preview.hidden { display: none; }

.attach-thumb {
  position: relative;
  width: 64px;
  height: 64px;
  border-radius: 8px;
  overflow: hidden;
  border: 1px solid var(--border-light);
}

.attach-thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.attach-thumb button {
  position: absolute;
  top: 2px;
  right: 2px;
  width: 18px;
  height: 18px;
  border: none;
  border-radius: 50%;
  background: rgba(0, 0, 0, 0.65);
  color: #fff;
  font-size: 12px;
  line-height: 18px;
  cursor: pointer;
}

.msg-media {
  display: block;
  max-width: min(420px, 100%);
  max-height: 320px;
  margin: 8px 0;
  border-radius: 8px;
  border: 1px solid var(--border-light);
}

.msg-media-missing {
  display: block;
  margin: 8px 0;
  padding: 8px 12px;
  border-radius: 8px;
  border: 1px dashed var(--border-light);
  color: var(--muted);
  font-size: 13px;
}

.composer-hint {
  max-width: 820px;
  margin: 6px auto 0;
  font-size: 11px;
  color: var(--muted);
  text-align: center;
  opacity: 0.7;
}

.file-browser-toolbar {
  display: flex;
  gap: 8px;
  padding: 8px 10px 0;
  flex-shrink: 0;
}

.file-browser-toolbar .btn-secondary {
  flex: 1;
  width: auto;
  padding: 6px 8px;
  font-size: 12px;
}

.file-browser-toolbar .btn-secondary:disabled {
  opacity: 0.45;
  cursor: default;
}

.file-path-label {
  margin: 6px 12px 0;
  font-size: 11px;
  color: var(--muted);
  word-break: break-all;
  flex-shrink: 0;
}

.file-list {
  list-style: none;
  margin: 0;
  padding: 8px;
  overflow-y: auto;
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.file-item {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 8px;
  border: none;
  border-radius: 8px;
  background: transparent;
  color: var(--text);
  padding: 8px 10px;
  cursor: pointer;
  text-align: left;
  font: inherit;
}

.file-item:hover,
.file-item.active {
  background: var(--panel-hover);
}

.file-item-kind {
  flex-shrink: 0;
  color: var(--muted);
  font-size: 12px;
  width: 1.2em;
}

.file-item-name {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--text-bright);
}

.file-editor {
  position: absolute;
  inset: 0;
  z-index: 6;
  display: flex;
  flex-direction: column;
  background: var(--panel);
}

.file-editor.hidden {
  display: none;
}

.file-editor-header {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  border-bottom: 1px solid var(--border);
  min-height: var(--header-h);
}

.file-editor-header .btn-primary,
.file-editor-header .btn-secondary {
  width: auto;
  flex-shrink: 0;
  padding: 6px 12px;
}

.file-editor-path {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 12px;
  color: var(--text-bright);
}

.file-editor-status {
  flex-shrink: 0;
  font-size: 11px;
  color: var(--muted);
}

.file-editor-status.dirty { color: var(--warn); }
.file-editor-status.ok { color: var(--success); }
.file-editor-status.err { color: var(--danger); }

.file-editor textarea {
  flex: 1;
  min-height: 0;
  width: 100%;
  border: none;
  resize: none;
  padding: 16px 18px 24px;
  background: var(--chat-bg);
  color: var(--text-bright);
  font-family: "Cascadia Code", "Consolas", "Courier New", monospace;
  font-size: 14px;
  line-height: 1.6;
  outline: none;
}
