/* ─── CSS Custom Properties (Theming) ────────────────────────────────────── */

:root {
  --font-sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --font-mono: "SF Mono", "Fira Code", "Fira Mono", "Roboto Mono", Menlo, monospace;
  --radius: 8px;
  --radius-lg: 12px;
  --transition: 150ms ease;
  --sidebar-width: 320px;
  --topbar-height: 52px;
}

[data-theme="dark"] {
  --bg-primary: #0a0a0a;
  --bg-secondary: #141414;
  --bg-tertiary: #1e1e1e;
  --bg-hover: #252525;
  --bg-active: #2a2a2a;
  --bg-user-msg: #1a3a5c;
  --bg-assistant-msg: #1e1e1e;
  --bg-input: #1a1a1a;
  --border: #2a2a2a;
  --border-focus: #4a9eff;
  --text-primary: #e8e8e8;
  --text-secondary: #999;
  --text-muted: #666;
  --accent: #4a9eff;
  --accent-hover: #3a8eef;
  --accent-bg: #1a3050;
  --danger: #ef4444;
  --danger-bg: #3c1111;
  --success: #22c55e;
  --warning: #f59e0b;
  --code-bg: #161616;
  --scrollbar-track: #1a1a1a;
  --scrollbar-thumb: #333;
  --shadow: 0 1px 3px rgba(0,0,0,0.4);
  --shadow-lg: 0 4px 12px rgba(0,0,0,0.5);
}

[data-theme="light"] {
  --bg-primary: #ffffff;
  --bg-secondary: #f7f7f8;
  --bg-tertiary: #ececee;
  --bg-hover: #e8e8ea;
  --bg-active: #ddd;
  --bg-user-msg: #e8f0fe;
  --bg-assistant-msg: #f7f7f8;
  --bg-input: #ffffff;
  --border: #e0e0e0;
  --border-focus: #2563eb;
  --text-primary: #1a1a1a;
  --text-secondary: #555;
  --text-muted: #999;
  --accent: #2563eb;
  --accent-hover: #1d4ed8;
  --accent-bg: #e8f0fe;
  --danger: #dc2626;
  --danger-bg: #fef2f2;
  --success: #16a34a;
  --warning: #d97706;
  --code-bg: #f3f4f6;
  --scrollbar-track: #f0f0f0;
  --scrollbar-thumb: #ccc;
  --shadow: 0 1px 3px rgba(0,0,0,0.1);
  --shadow-lg: 0 4px 12px rgba(0,0,0,0.15);
}

/* ─── Reset ──────────────────────────────────────────────────────────────── */

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

html, body {
  height: 100%;
  overflow: hidden;
}

body {
  font-family: var(--font-sans);
  font-size: 14px;
  line-height: 1.6;
  color: var(--text-primary);
  background: var(--bg-primary);
  display: flex;
}

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

/* ─── Scrollbar ──────────────────────────────────────────────────────────── */

::-webkit-scrollbar {
  width: 6px;
}
::-webkit-scrollbar-track {
  background: var(--scrollbar-track);
}
::-webkit-scrollbar-thumb {
  background: var(--scrollbar-thumb);
  border-radius: 3px;
}

/* ─── Sidebar ────────────────────────────────────────────────────────────── */

.sidebar {
  width: var(--sidebar-width);
  height: 100vh;
  background: var(--bg-secondary);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  overflow: hidden;
  transition: transform var(--transition), width var(--transition);
  z-index: 100;
}

.sidebar.collapsed {
  width: 0;
  transform: translateX(calc(var(--sidebar-width) * -1));
  border-right: none;
}

.sidebar-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.logo {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 16px;
  font-weight: 700;
  color: var(--text-primary);
  white-space: nowrap;
}

.sidebar-content {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 12px 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  min-height: 0;
}

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

.footer-links {
  margin-top: 8px;
  font-size: 12px;
  text-align: center;
  color: var(--text-muted);
}

.sep {
  margin: 0 4px;
}

/* ─── Hints ──────────────────────────────────────────────────────────────── */

.hint {
  font-size: 11px;
  color: var(--text-muted);
  line-height: 1.4;
}

/* ─── Form Controls ──────────────────────────────────────────────────────── */

select, input[type="text"], input[type="password"], input[type="number"], textarea {
  width: 100%;
  padding: 8px 10px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text-primary);
  font-family: var(--font-sans);
  font-size: 13px;
  transition: border-color var(--transition);
  outline: none;
}

select:focus, input:focus, textarea:focus {
  border-color: var(--border-focus);
}

textarea {
  resize: vertical;
  min-height: 60px;
}

select {
  cursor: pointer;
}

.input-with-action {
  display: flex;
  gap: 4px;
}

.input-with-action input {
  flex: 1;
}

.range-with-value {
  display: flex;
  align-items: center;
  gap: 8px;
}

.range-with-value input[type="range"] {
  flex: 1;
  padding: 0;
  border: none;
  background: transparent;
  accent-color: var(--accent);
}

.range-with-value span {
  font-size: 12px;
  font-family: var(--font-mono);
  color: var(--text-secondary);
  min-width: 28px;
  text-align: right;
}

/* Toggle switch */
.toggle {
  position: relative;
  display: inline-block;
  width: 40px;
  height: 22px;
  cursor: pointer;
}

.toggle input {
  opacity: 0;
  width: 0;
  height: 0;
  position: absolute;
}

.toggle-slider {
  position: absolute;
  inset: 0;
  background: var(--bg-hover);
  border-radius: 22px;
  transition: background var(--transition);
}

.toggle-slider::before {
  content: "";
  position: absolute;
  height: 16px;
  width: 16px;
  left: 3px;
  bottom: 3px;
  background: var(--text-primary);
  border-radius: 50%;
  transition: transform var(--transition);
}

.toggle input:checked + .toggle-slider {
  background: var(--accent);
}

.toggle input:checked + .toggle-slider::before {
  transform: translateX(18px);
  background: #fff;
}

/* ─── Buttons ────────────────────────────────────────────────────────────── */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 8px 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: all var(--transition);
  background: var(--bg-tertiary);
  color: var(--text-primary);
  white-space: nowrap;
}

.btn:hover {
  background: var(--bg-hover);
}

.btn-primary {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}

.btn-primary:hover {
  background: var(--accent-hover);
  border-color: var(--accent-hover);
}

.btn-ghost {
  background: transparent;
  border-color: transparent;
}

.btn-ghost:hover {
  background: var(--bg-hover);
}

.full-width {
  width: 100%;
}

.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  border: none;
  border-radius: var(--radius);
  background: transparent;
  color: var(--text-secondary);
  cursor: pointer;
  transition: all var(--transition);
  flex-shrink: 0;
}

.icon-btn:hover {
  background: var(--bg-hover);
  color: var(--text-primary);
}

/* ─── Main Content ───────────────────────────────────────────────────────── */

.main {
  flex: 1;
  display: flex;
  flex-direction: column;
  height: 100vh;
  overflow: hidden;
  min-width: 0;
  position: relative;
}

/* ─── Top Bar ────────────────────────────────────────────────────────────── */

.topbar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  height: var(--topbar-height);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 4px;
}

.badge {
  display: inline-block;
  padding: 2px 8px;
  font-size: 11px;
  font-weight: 600;
  border-radius: 4px;
  background: var(--accent-bg);
  color: var(--accent);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  white-space: nowrap;
}

.muted {
  color: var(--text-muted);
  font-size: 12px;
}

/* ─── Messages Area ──────────────────────────────────────────────────────── */

.messages {
  flex: 1;
  overflow-y: auto;
  padding: 20px;
  scroll-behavior: smooth;
}

.welcome {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  height: 100%;
  gap: 12px;
  color: var(--text-secondary);
}

.welcome-icon {
  color: var(--accent);
  opacity: 0.6;
}

.welcome h2 {
  font-size: 22px;
  font-weight: 700;
  color: var(--text-primary);
}

.welcome p {
  max-width: 400px;
  line-height: 1.5;
}

/* Message bubbles */
.message {
  display: flex;
  gap: 12px;
  max-width: 820px;
  margin: 0 auto 16px;
  padding: 16px;
  border-radius: var(--radius-lg);
  animation: fadeIn 200ms ease;
}

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(4px); }
  to { opacity: 1; transform: translateY(0); }
}

.message.user {
  background: var(--bg-user-msg);
}

.message.assistant {
  background: var(--bg-assistant-msg);
}

.message.error {
  background: var(--danger-bg);
  border: 1px solid var(--danger);
}

.message-avatar {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 13px;
  font-weight: 700;
  flex-shrink: 0;
  color: #fff;
}

.message.user .message-avatar {
  background: var(--accent);
}

.message.assistant .message-avatar {
  background: #6b21a8;
}

.message.error .message-avatar {
  background: var(--danger);
}

.message-body {
  flex: 1;
  min-width: 0;
  overflow-x: auto;
}

.message-body p {
  margin-bottom: 8px;
}

.message-body p:last-child {
  margin-bottom: 0;
}

.message-body ul, .message-body ol {
  margin: 8px 0;
  padding-left: 20px;
}

.message-body li {
  margin-bottom: 4px;
}

.message-body blockquote {
  border-left: 3px solid var(--border);
  padding-left: 12px;
  margin: 8px 0;
  color: var(--text-secondary);
}

.message-body h1, .message-body h2, .message-body h3 {
  margin: 12px 0 6px;
  line-height: 1.3;
}

.message-body h1 { font-size: 18px; }
.message-body h2 { font-size: 16px; }
.message-body h3 { font-size: 14px; }

/* Inline code */
.message-body code {
  font-family: var(--font-mono);
  font-size: 12px;
  background: var(--code-bg);
  padding: 2px 5px;
  border-radius: 4px;
}

/* Code blocks */
.message-body pre {
  position: relative;
  margin: 10px 0;
  border-radius: var(--radius);
  overflow: hidden;
}

.message-body pre code {
  display: block;
  padding: 14px 16px;
  overflow-x: auto;
  font-size: 12px;
  line-height: 1.5;
  background: var(--code-bg);
  border-radius: var(--radius);
}

.code-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 6px 12px;
  background: var(--bg-tertiary);
  font-size: 11px;
  color: var(--text-muted);
  font-family: var(--font-mono);
}

.copy-btn {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px 8px;
  border: none;
  border-radius: 4px;
  background: transparent;
  color: var(--text-muted);
  font-size: 11px;
  cursor: pointer;
  transition: all var(--transition);
}

.copy-btn:hover {
  background: var(--bg-hover);
  color: var(--text-primary);
}

/* Tables */
.message-body table {
  width: 100%;
  border-collapse: collapse;
  margin: 10px 0;
  font-size: 13px;
}

.message-body th, .message-body td {
  padding: 6px 10px;
  border: 1px solid var(--border);
  text-align: left;
}

.message-body th {
  background: var(--bg-tertiary);
  font-weight: 600;
}

/* Cursor blink for streaming */
.streaming-cursor::after {
  content: "";
  display: inline-block;
  width: 7px;
  height: 15px;
  background: var(--accent);
  margin-left: 2px;
  vertical-align: text-bottom;
  animation: blink 0.8s infinite;
}

@keyframes blink {
  0%, 50% { opacity: 1; }
  51%, 100% { opacity: 0; }
}

/* Typing indicator */
.typing-indicator {
  display: inline-flex;
  gap: 4px;
  padding: 4px 0;
}

.typing-indicator span {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--text-muted);
  animation: typing 1.4s infinite;
}

.typing-indicator span:nth-child(2) { animation-delay: 0.2s; }
.typing-indicator span:nth-child(3) { animation-delay: 0.4s; }

@keyframes typing {
  0%, 60%, 100% { opacity: 0.3; transform: translateY(0); }
  30% { opacity: 1; transform: translateY(-4px); }
}

/* Message metadata */
.message-meta {
  display: flex;
  gap: 12px;
  margin-top: 8px;
  font-size: 11px;
  color: var(--text-muted);
}

/* ─── Input Area ─────────────────────────────────────────────────────────── */

.input-area {
  padding: 12px 20px 16px;
  border-top: 1px solid var(--border);
  flex-shrink: 0;
}

.input-container {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  max-width: 820px;
  margin: 0 auto;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 8px 12px;
  transition: border-color var(--transition);
}

.input-container:focus-within {
  border-color: var(--border-focus);
}

.input-container textarea {
  flex: 1;
  border: none;
  background: transparent;
  padding: 4px 0;
  max-height: 200px;
  resize: none;
  font-size: 14px;
  line-height: 1.5;
}

.input-container textarea:focus {
  border: none;
  outline: none;
}

.send-btn {
  width: 36px;
  height: 36px;
  border: none;
  border-radius: var(--radius);
  background: var(--accent);
  color: #fff;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background var(--transition);
  flex-shrink: 0;
}

.send-btn:hover {
  background: var(--accent-hover);
}

.send-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.stop-btn {
  background: var(--danger);
}

.stop-btn:hover {
  background: #dc2626;
}

/* Upload button */
.upload-btn {
  width: 36px;
  height: 36px;
  border: none;
  border-radius: var(--radius);
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all var(--transition);
  flex-shrink: 0;
}

.upload-btn:hover {
  background: var(--bg-hover);
  color: var(--text-primary);
}

.upload-btn.has-attachments {
  color: var(--accent);
}

/* Attachment preview strip */
.attachment-preview {
  max-width: 820px;
  margin: 0 auto 6px;
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  padding: 0 4px;
}

.attachment-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 8px 4px 4px;
  background: var(--bg-tertiary);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 12px;
  color: var(--text-secondary);
  max-width: 200px;
  animation: fadeIn 150ms ease;
}

.attachment-pill-thumb {
  width: 32px;
  height: 32px;
  border-radius: 4px;
  object-fit: cover;
  flex-shrink: 0;
}

.attachment-pill-icon {
  width: 32px;
  height: 32px;
  border-radius: 4px;
  background: var(--bg-hover);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  color: var(--text-muted);
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
}

.attachment-pill-name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  min-width: 0;
}

.attachment-pill-remove {
  width: 18px;
  height: 18px;
  border: none;
  border-radius: 50%;
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: all var(--transition);
  padding: 0;
}

.attachment-pill-remove:hover {
  background: var(--danger-bg);
  color: var(--danger);
}

/* Inline image/file display in user messages */
.message-attachments {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 8px;
}

.message-attachment-img {
  max-width: 300px;
  max-height: 300px;
  border-radius: var(--radius);
  cursor: pointer;
  transition: opacity var(--transition);
}

.message-attachment-img:hover {
  opacity: 0.85;
}

.message-attachment-file {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 10px;
  background: var(--bg-tertiary);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 12px;
  color: var(--text-secondary);
}

.message-attachment-file-icon {
  color: var(--text-muted);
}

/* Drag-and-drop indicator */
.input-area.drag-over {
  background: color-mix(in srgb, var(--accent) 8%, var(--bg-primary));
  border-color: var(--accent);
}

.input-area.drag-over .input-container {
  border-color: var(--accent);
  border-style: dashed;
}

.input-footer {
  max-width: 820px;
  margin: 4px auto 0;
  display: flex;
  justify-content: flex-end;
}

/* ─── Topbar — Model / Provider Select ───────────────────────────────────── */

.topbar-model-select {
  display: flex;
  align-items: center;
  gap: 0;
  flex: 1;
  min-width: 0;
}

.topbar-provider-wrap {
  display: flex;
  align-items: center;
  gap: 2px;
  flex-shrink: 0;
}

.topbar-provider-select {
  padding: 5px 8px;
  background: var(--bg-tertiary);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text-primary);
  font-family: var(--font-sans);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  outline: none;
  transition: border-color var(--transition);
  max-width: 160px;
}

.topbar-provider-select:focus {
  border-color: var(--border-focus);
}

.topbar-add-provider {
  width: 28px;
  height: 28px;
}

.topbar-separator {
  color: var(--text-muted);
  font-size: 16px;
  margin: 0 6px;
  user-select: none;
  flex-shrink: 0;
}

.topbar-model-combobox {
  flex: 1;
  min-width: 0;
  max-width: 320px;
}

.topbar-model-combobox input {
  height: 32px;
  padding: 4px 10px;
  font-size: 13px;
}

/* ─── Topbar — Key Status ────────────────────────────────────────────────── */

.topbar-key-btn {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  border: none;
  border-radius: var(--radius);
  background: transparent;
  color: var(--text-secondary);
  cursor: pointer;
  transition: all var(--transition);
  flex-shrink: 0;
}

.topbar-key-btn:hover {
  background: var(--bg-hover);
  color: var(--text-primary);
}

.key-status-dot {
  position: absolute;
  top: 4px;
  right: 4px;
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--danger);
  border: 1.5px solid var(--bg-primary);
}

.key-status-dot.has-key {
  background: var(--success);
}

/* ─── Settings Modal ─────────────────────────────────────────────────────── */

.settings-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  z-index: 300;
  display: flex;
  align-items: center;
  justify-content: center;
  animation: fadeInOverlay 150ms ease;
}

.settings-modal {
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  width: 90%;
  max-width: 520px;
  max-height: 80vh;
  display: flex;
  flex-direction: column;
  box-shadow: var(--shadow-lg);
  animation: slideUp 150ms ease;
  overflow: hidden;
}

.settings-modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px 12px;
  flex-shrink: 0;
}

.settings-modal-header h2 {
  font-size: 16px;
  font-weight: 700;
  color: var(--text-primary);
}

.settings-modal-tabs {
  display: flex;
  gap: 0;
  padding: 0 20px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.settings-tab {
  padding: 8px 14px;
  border: none;
  background: transparent;
  color: var(--text-muted);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  border-bottom: 2px solid transparent;
  transition: all var(--transition);
  font-family: var(--font-sans);
}

.settings-tab:hover {
  color: var(--text-secondary);
}

.settings-tab.active {
  color: var(--accent);
  border-bottom-color: var(--accent);
}

.settings-modal-body {
  flex: 1;
  overflow-y: auto;
  padding: 20px;
}

.settings-tab-pane {
  display: none;
  flex-direction: column;
  gap: 16px;
}

.settings-tab-pane.active {
  display: flex;
}

.setting-field {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.setting-field > label {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.settings-param-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
}

@media (max-width: 480px) {
  .settings-param-grid {
    grid-template-columns: 1fr;
  }
}

/* ─── Model Combobox ────────────────────────────────────────────────────── */

.model-combobox {
  position: relative;
}

.model-combobox input {
  width: 100%;
  padding: 8px 10px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text-primary);
  font-family: var(--font-mono);
  font-size: 12px;
  outline: none;
  transition: border-color var(--transition);
}

.model-combobox input:focus {
  border-color: var(--border-focus);
}

.model-combobox input::placeholder {
  font-family: var(--font-sans);
  color: var(--text-muted);
}

/* Modality tabs */
.modality-tabs {
  display: none;
  gap: 2px;
  padding: 6px 4px 0;
  background: var(--bg-secondary);
  border-left: 1px solid var(--border);
  border-right: 1px solid var(--border);
  border-radius: 0;
}

.model-combobox.open .modality-tabs {
  display: flex;
}

.mod-tab {
  flex: 1;
  padding: 4px 0;
  border: none;
  background: transparent;
  color: var(--text-muted);
  font-size: 11px;
  font-weight: 600;
  cursor: pointer;
  border-radius: 4px;
  transition: all var(--transition);
}

.mod-tab:hover {
  color: var(--text-secondary);
  background: var(--bg-hover);
}

.mod-tab.active {
  color: var(--accent);
  background: var(--accent-bg);
}

/* Results list */
.model-results {
  display: none;
  position: absolute;
  top: 100%;
  left: 0;
  right: 0;
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-top: none;
  border-radius: 0 0 var(--radius) var(--radius);
  box-shadow: var(--shadow-lg);
  z-index: 150;
  max-height: 280px;
  overflow-y: auto;
}

.model-combobox.open .model-results {
  display: block;
}

.model-combobox.open input {
  border-radius: var(--radius) var(--radius) 0 0;
}

/* Model row */
.model-row {
  display: flex;
  align-items: center;
  padding: 5px 10px;
  cursor: pointer;
  gap: 6px;
  transition: background 60ms ease;
  min-height: 32px;
}

.model-row:hover,
.model-row.hl {
  background: var(--bg-hover);
}

.model-row.sel {
  background: var(--accent-bg);
}

.model-row-name {
  flex: 1;
  font-size: 13px;
  color: var(--text-primary);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  min-width: 0;
}

.model-row-right {
  display: flex;
  align-items: center;
  gap: 4px;
  flex-shrink: 0;
}

.mtag {
  display: inline-block;
  padding: 0 4px;
  border-radius: 3px;
  font-size: 9px;
  font-weight: 600;
  line-height: 16px;
  text-transform: uppercase;
  letter-spacing: 0.3px;
}

.mtag-default {
  background: color-mix(in srgb, var(--accent) 15%, transparent);
  color: var(--accent);
}

.mtag-ctx {
  background: var(--bg-tertiary);
  color: var(--text-muted);
  font-family: var(--font-mono);
  font-weight: 500;
}

.mtag-cap {
  color: var(--text-muted);
  background: var(--bg-tertiary);
}

.mtag-cap.c-flagship { color: var(--accent); background: color-mix(in srgb, var(--accent) 12%, transparent); }
.mtag-cap.c-fast { color: var(--success); background: color-mix(in srgb, var(--success) 12%, transparent); }
.mtag-cap.c-reasoning { color: #a78bfa; background: color-mix(in srgb, #a78bfa 12%, transparent); }
.mtag-cap.c-code { color: var(--warning); background: color-mix(in srgb, var(--warning) 12%, transparent); }
.mtag-cap.c-vision { color: #ec4899; background: color-mix(in srgb, #ec4899 12%, transparent); }
.mtag-cap.c-search { color: #06b6d4; background: color-mix(in srgb, #06b6d4 12%, transparent); }
.mtag-cap.c-image { color: #f472b6; background: color-mix(in srgb, #f472b6 12%, transparent); }
.mtag-cap.c-audio { color: #34d399; background: color-mix(in srgb, #34d399 12%, transparent); }
.mtag-cap.c-tts { color: #60a5fa; background: color-mix(in srgb, #60a5fa 12%, transparent); }
.mtag-cap.c-embedding { color: #fbbf24; background: color-mix(in srgb, #fbbf24 12%, transparent); }

.model-row-id {
  font-size: 10px;
  font-family: var(--font-mono);
  color: var(--text-muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 140px;
}

.model-results-empty {
  padding: 16px 10px;
  text-align: center;
  color: var(--text-muted);
  font-size: 12px;
}

.model-use-custom {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 10px;
  cursor: pointer;
  font-size: 12px;
  color: var(--accent);
  border-top: 1px solid var(--border);
  transition: background var(--transition);
}

.model-use-custom:hover {
  background: var(--bg-hover);
}

.model-use-custom code {
  font-family: var(--font-mono);
  font-weight: 600;
  font-size: 12px;
  background: none;
  padding: 0;
}

/* ─── Endpoint Configuration ────────────────────────────────────────────── */

.endpoint-default {
  font-size: 11px;
  font-family: var(--font-mono);
  color: var(--text-muted);
  padding: 4px 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.mono-input {
  font-family: var(--font-mono);
  font-size: 12px;
}

/* ─── Custom Provider Dialog ────────────────────────────────────────────── */

.custom-provider-dialog {
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 20px;
  max-width: 420px;
  width: 90%;
  box-shadow: var(--shadow-lg);
  animation: slideUp 150ms ease;
}

.custom-provider-dialog h3 {
  font-size: 15px;
  font-weight: 600;
  color: var(--text-primary);
  margin-bottom: 14px;
}

.custom-provider-form {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.custom-provider-form .form-row {
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.custom-provider-form label {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-secondary);
}

.custom-provider-form .form-actions {
  display: flex;
  gap: 8px;
  justify-content: flex-end;
  margin-top: 6px;
}

.custom-provider-form .btn-danger {
  background: var(--danger);
  color: #fff;
  border-color: var(--danger);
  margin-right: auto;
}

.custom-provider-form .btn-danger:hover {
  opacity: 0.9;
}

/* ─── Chat History Section ───────────────────────────────────────────────── */

.chat-history-section {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-height: 0;
}

.chat-history-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 4px 0;
  margin-bottom: 6px;
}

.chat-history-label {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.chat-count {
  font-size: 11px;
  color: var(--text-muted);
  font-variant-numeric: tabular-nums;
}

.chat-search-wrap {
  position: relative;
  margin-bottom: 6px;
}

.chat-search-icon {
  position: absolute;
  left: 8px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-muted);
  pointer-events: none;
}

.chat-search-wrap input {
  width: 100%;
  padding: 6px 8px 6px 28px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text-primary);
  font-family: var(--font-sans);
  font-size: 12px;
  outline: none;
  transition: border-color var(--transition);
}

.chat-search-wrap input:focus {
  border-color: var(--border-focus);
}

.chat-search-wrap input::placeholder {
  color: var(--text-muted);
}

/* ─── Chat List ──────────────────────────────────────────────────────────── */

.chat-list {
  display: flex;
  flex-direction: column;
  gap: 2px;
  flex: 1;
  overflow-y: auto;
  min-height: 0;
}

.chat-list-empty {
  padding: 16px 8px;
  text-align: center;
  font-size: 12px;
  color: var(--text-muted);
}

.chat-list-item {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 7px 8px;
  border-radius: var(--radius);
  cursor: pointer;
  font-size: 13px;
  color: var(--text-secondary);
  transition: background var(--transition);
  flex-shrink: 0;
}

.chat-list-item:hover {
  background: var(--bg-hover);
}

.chat-list-item.active {
  background: var(--bg-active);
  color: var(--text-primary);
}

.chat-list-item .chat-icon {
  flex-shrink: 0;
  color: var(--text-muted);
}

.chat-list-item.active .chat-icon {
  color: var(--accent);
}

.chat-list-item .chat-title {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.chat-list-item .chat-title-input {
  flex: 1;
  min-width: 0;
  padding: 1px 4px;
  border: 1px solid var(--border-focus);
  border-radius: 3px;
  background: var(--bg-input);
  color: var(--text-primary);
  font-family: var(--font-sans);
  font-size: 13px;
  outline: none;
}

.chat-list-item .chat-actions {
  display: flex;
  gap: 2px;
  opacity: 0;
  transition: opacity var(--transition);
  flex-shrink: 0;
}

.chat-list-item:hover .chat-actions {
  opacity: 1;
}

.chat-list-item .chat-actions .icon-btn {
  width: 24px;
  height: 24px;
}

/* ─── Delete Confirm Dialog ──────────────────────────────────────────────── */

.confirm-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  z-index: 200;
  display: flex;
  align-items: center;
  justify-content: center;
  animation: fadeInOverlay 150ms ease;
}

@keyframes fadeInOverlay {
  from { opacity: 0; }
  to { opacity: 1; }
}

.confirm-dialog {
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 20px;
  max-width: 340px;
  width: 90%;
  box-shadow: var(--shadow-lg);
  animation: slideUp 150ms ease;
}

@keyframes slideUp {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

.confirm-dialog h3 {
  font-size: 15px;
  font-weight: 600;
  color: var(--text-primary);
  margin-bottom: 8px;
}

.confirm-dialog p {
  font-size: 13px;
  color: var(--text-secondary);
  margin-bottom: 16px;
  line-height: 1.5;
}

.confirm-dialog .confirm-actions {
  display: flex;
  gap: 8px;
  justify-content: flex-end;
}

.confirm-dialog .btn-danger {
  background: var(--danger);
  color: #fff;
  border-color: var(--danger);
}

.confirm-dialog .btn-danger:hover {
  opacity: 0.9;
}

/* ─── Responsive ─────────────────────────────────────────────────────────── */

@media (max-width: 768px) {
  .sidebar {
    position: fixed;
    left: 0;
    top: 0;
    bottom: 0;
    box-shadow: var(--shadow-lg);
  }

  .sidebar.collapsed {
    transform: translateX(-100%);
    width: var(--sidebar-width);
  }

  .message {
    padding: 12px;
  }

  .messages {
    padding: 12px;
  }

  .topbar-model-select {
    flex-wrap: nowrap;
  }

  .topbar-provider-select {
    max-width: 100px;
    font-size: 12px;
  }

  .topbar-model-combobox {
    max-width: 160px;
  }

  .topbar-model-combobox input {
    font-size: 12px;
  }

  .topbar-separator {
    margin: 0 3px;
  }
}

@media (max-width: 480px) {
  :root {
    --sidebar-width: 280px;
  }

  .message {
    gap: 8px;
  }

  .message-avatar {
    width: 24px;
    height: 24px;
    font-size: 11px;
  }

  .topbar-provider-select {
    max-width: 80px;
    font-size: 11px;
    padding: 4px 6px;
  }

  .topbar-model-combobox {
    max-width: 120px;
  }

  .settings-modal {
    width: 95%;
    max-height: 90vh;
  }
}

/* ─── Overlay for mobile sidebar ─────────────────────────────────────────── */

.sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.5);
  z-index: 99;
}

.sidebar-overlay.visible {
  display: block;
}

/* ─── Print ──────────────────────────────────────────────────────────────── */

@media print {
  .sidebar, .topbar, .input-area {
    display: none !important;
  }

  .main {
    height: auto;
    overflow: visible;
  }

  .messages {
    overflow: visible;
    height: auto;
  }
}

/* ─── Token Stats — Per-Message Badges ──────────────────────────────────── */

.token-summary {
  display: inline-flex;
  flex-wrap: wrap;
  gap: 4px;
  align-items: center;
}

.token-pill {
  display: inline-flex;
  align-items: center;
  padding: 1px 7px;
  border-radius: 10px;
  font-size: 11px;
  font-variant-numeric: tabular-nums;
  background: var(--bg-tertiary);
  color: var(--text-muted);
  white-space: nowrap;
}

.token-pill.token-cache {
  color: var(--success);
  background: color-mix(in srgb, var(--success) 12%, transparent);
}

.token-pill.token-reasoning {
  color: var(--warning);
  background: color-mix(in srgb, var(--warning) 12%, transparent);
}

.token-details-toggle {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 18px;
  height: 18px;
  border: none;
  border-radius: 50%;
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
  transition: all var(--transition);
  flex-shrink: 0;
}

.token-details-toggle:hover {
  background: var(--bg-hover);
  color: var(--text-primary);
}

.message-meta.expanded .token-details-toggle svg {
  transform: rotate(180deg);
}

.token-details {
  display: none;
  margin-top: 6px;
}

.message-meta.expanded .token-details {
  display: block;
  animation: fadeIn 200ms ease;
}

.token-details-grid {
  display: grid;
  grid-template-columns: auto auto;
  gap: 3px 16px;
  font-size: 11px;
  padding: 8px 10px;
  background: var(--bg-tertiary);
  border-radius: var(--radius);
  width: fit-content;
}

.td-label {
  color: var(--text-muted);
}

.td-value {
  font-variant-numeric: tabular-nums;
  color: var(--text-secondary);
  text-align: right;
}

.td-cache {
  color: var(--success);
}

.td-cache-write {
  color: color-mix(in srgb, var(--success) 70%, var(--warning));
}

.td-reasoning {
  color: var(--warning);
}

.td-pct {
  font-size: 10px;
  opacity: 0.7;
}

/* Cache hit bar (inline in message details) */
.cache-bar {
  display: inline-block;
  width: 60px;
  height: 5px;
  background: var(--bg-hover);
  border-radius: 3px;
  overflow: hidden;
  vertical-align: middle;
  margin-right: 4px;
}

.cache-bar-fill {
  display: block;
  height: 100%;
  background: var(--success);
  border-radius: 3px;
  transition: width 0.4s ease;
}

/* ─── Token Stats — Topbar Stats Button ─────────────────────────────────── */

.topbar-stats-btn {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 4px 10px;
  border: 1px solid var(--border);
  border-radius: 16px;
  background: transparent;
  color: var(--text-muted);
  font-size: 12px;
  font-variant-numeric: tabular-nums;
  cursor: pointer;
  transition: all var(--transition);
  white-space: nowrap;
  height: 28px;
}

.topbar-stats-btn:hover {
  background: var(--bg-hover);
  color: var(--text-primary);
  border-color: var(--text-muted);
}

.topbar-stats-btn.has-stats {
  color: var(--text-secondary);
}

.topbar-token-count:empty {
  display: none;
}

/* ─── Token Stats — Stats Popover ───────────────────────────────────────── */

.stats-popover {
  position: absolute;
  right: 16px;
  top: calc(var(--topbar-height) + 4px);
  width: 320px;
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  flex-direction: column;
  z-index: 50;
  animation: slideDown 200ms ease;
  overflow: hidden;
}

@keyframes slideDown {
  from { opacity: 0; transform: translateY(-8px); }
  to { opacity: 1; transform: translateY(0); }
}

.stats-popover-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
}

.stats-popover-title {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.stats-popover-body {
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  max-height: 400px;
  overflow-y: auto;
}

/* Hero total */
.stats-hero {
  text-align: center;
  padding: 4px 0 8px;
}

.stats-hero-value {
  font-size: 28px;
  font-weight: 700;
  color: var(--text-primary);
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.5px;
}

.stats-hero-label {
  font-size: 11px;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-top: 2px;
}

/* Distribution bar */
.stats-distribution {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.stats-dist-bar {
  display: flex;
  height: 8px;
  border-radius: 4px;
  overflow: hidden;
  background: var(--bg-tertiary);
}

.stats-dist-segment {
  height: 100%;
  min-width: 2px;
  transition: width 0.4s ease;
}

.dist-input {
  background: var(--accent);
}

.dist-output {
  background: #8b5cf6;
}

.stats-dist-legend {
  display: flex;
  justify-content: center;
  gap: 16px;
  font-size: 11px;
  color: var(--text-secondary);
  font-variant-numeric: tabular-nums;
}

.stats-legend-item {
  display: inline-flex;
  align-items: center;
  gap: 5px;
}

.legend-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
}

.dist-input-dot {
  background: var(--accent);
}

.dist-output-dot {
  background: #8b5cf6;
}

/* Stats grid */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
}

.stats-cell {
  text-align: center;
  padding: 8px 4px;
  background: var(--bg-tertiary);
  border-radius: var(--radius);
}

.stats-cell-value {
  font-size: 16px;
  font-weight: 700;
  color: var(--text-primary);
  font-variant-numeric: tabular-nums;
}

.stats-cell-label {
  font-size: 10px;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.3px;
  margin-top: 2px;
}

.stats-reasoning {
  color: var(--warning);
}

/* Cache section */
.stats-cache-section {
  border-top: 1px solid var(--border);
  padding-top: 12px;
}

.stats-section-title {
  font-size: 11px;
  font-weight: 600;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 10px;
}

.stats-cache-ring-row {
  display: flex;
  align-items: center;
  gap: 16px;
}

.stats-cache-ring {
  flex-shrink: 0;
}

.stats-cache-details {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.stats-cache-row {
  display: flex;
  justify-content: space-between;
  font-size: 12px;
}

.stats-cache-label {
  color: var(--text-muted);
}

.stats-cache-val {
  color: var(--text-secondary);
  font-variant-numeric: tabular-nums;
  font-weight: 500;
}

.stats-cache-saved .stats-cache-val {
  color: var(--success);
}

/* ─── Responsive adjustments for stats ──────────────────────────────────── */

@media (max-width: 480px) {
  .stats-popover {
    right: 8px;
    width: calc(100vw - 16px);
    max-width: 320px;
  }

  .stats-grid {
    grid-template-columns: repeat(2, 1fr);
  }
}

/* ─── MCP — Topbar Indicator ────────────────────────────────────────────── */

.topbar-mcp-btn {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 4px 10px;
  border: 1px solid var(--border);
  border-radius: 16px;
  background: transparent;
  color: var(--text-muted);
  font-size: 12px;
  font-variant-numeric: tabular-nums;
  cursor: pointer;
  transition: all var(--transition);
  white-space: nowrap;
  height: 28px;
}

.topbar-mcp-btn:hover {
  background: var(--bg-hover);
  color: var(--text-primary);
  border-color: var(--text-muted);
}

.topbar-mcp-btn.has-connected {
  color: var(--text-secondary);
}

.topbar-mcp-btn.has-tools {
  color: var(--success);
  border-color: color-mix(in srgb, var(--success) 40%, transparent);
}

.mcp-tool-badge:empty {
  display: none;
}

.mcp-tool-badge {
  font-weight: 600;
  font-size: 11px;
}

/* ─── MCP — Settings Tab ───────────────────────────────────────────────── */

.mcp-add-section {
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding-bottom: 16px;
  border-bottom: 1px solid var(--border);
}

.mcp-servers-section {
  padding-top: 12px;
}

.mcp-server-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-top: 6px;
}

.mcp-servers-empty {
  padding: 16px 0;
  text-align: center;
  font-size: 12px;
  color: var(--text-muted);
}

.mcp-server-item {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  padding: 8px 10px;
  background: var(--bg-tertiary);
  border-radius: var(--radius);
  border-left: 3px solid var(--text-muted);
}

.mcp-server-item.mcp-status-ok {
  border-left-color: var(--success);
}

.mcp-server-item.mcp-status-err {
  border-left-color: var(--danger);
}

.mcp-server-item.mcp-status-pending {
  border-left-color: var(--warning);
}

.mcp-server-info {
  display: flex;
  align-items: center;
  gap: 8px;
  flex: 1;
  min-width: 0;
}

.mcp-server-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
}

.mcp-dot-connected { background: var(--success); }
.mcp-dot-error { background: var(--danger); }
.mcp-dot-connecting { background: var(--warning); animation: blink 1s infinite; }

.mcp-server-name {
  font-size: 13px;
  font-weight: 500;
  color: var(--text-primary);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  min-width: 0;
}

.mcp-server-tools {
  font-size: 11px;
  color: var(--text-muted);
  white-space: nowrap;
}

.mcp-server-actions {
  display: flex;
  gap: 2px;
  flex-shrink: 0;
}

.mcp-server-actions .icon-btn {
  width: 24px;
  height: 24px;
}

.mcp-server-error {
  width: 100%;
  font-size: 11px;
  color: var(--danger);
  padding: 4px 0 0 16px;
  line-height: 1.4;
  word-break: break-word;
}

/* ─── MCP — Tool List ──────────────────────────────────────────────────── */

.mcp-tools-section {
  padding-top: 12px;
  border-top: 1px solid var(--border);
  margin-top: 12px;
}

.mcp-tool-list {
  display: flex;
  flex-direction: column;
  gap: 4px;
  margin-top: 6px;
  max-height: 200px;
  overflow-y: auto;
}

.mcp-tool-item {
  padding: 6px 10px;
  background: var(--bg-tertiary);
  border-radius: var(--radius);
}

.mcp-tool-name {
  font-family: var(--font-mono);
  font-size: 12px;
  font-weight: 600;
  color: var(--accent);
}

.mcp-tool-desc {
  font-size: 11px;
  color: var(--text-secondary);
  margin-top: 2px;
  line-height: 1.4;
}

.mcp-tool-server {
  font-size: 10px;
  color: var(--text-muted);
  margin-top: 2px;
}

/* ─── Tool Execution Block (Unified Tool Call + Result) ────────────────── */

.tool-exec-block {
  margin: 8px 48px 8px 56px;
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  overflow: hidden;
  background: var(--bg-secondary);
}

.tool-exec-header {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 14px;
  cursor: pointer;
  user-select: none;
  transition: background var(--transition);
}

.tool-exec-header:hover {
  background: var(--bg-hover);
}

.tool-exec-icon {
  color: var(--accent);
  display: flex;
  align-items: center;
  flex-shrink: 0;
}

.tool-exec-title {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-primary);
}

.tool-exec-badge {
  font-size: 11px;
  font-weight: 600;
  padding: 2px 8px;
  border-radius: 10px;
  display: inline-flex;
  align-items: center;
  gap: 4px;
  margin-left: auto;
}

.tool-exec-badge.success {
  background: color-mix(in srgb, var(--success) 15%, transparent);
  color: var(--success);
}

.tool-exec-badge.error {
  background: color-mix(in srgb, var(--danger) 15%, transparent);
  color: var(--danger);
}

.tool-exec-badge.executing {
  background: color-mix(in srgb, var(--accent) 15%, transparent);
  color: var(--accent);
}

.tool-exec-badge.pending {
  background: color-mix(in srgb, var(--warning) 15%, transparent);
  color: var(--warning);
}

.tool-exec-spinner {
  display: inline-flex;
  animation: tool-spin 1s linear infinite;
}

@keyframes tool-spin {
  from { transform: rotate(0deg); }
  to { transform: rotate(360deg); }
}

.tool-exec-chevron {
  color: var(--text-muted);
  display: flex;
  align-items: center;
  transition: transform var(--transition);
  flex-shrink: 0;
}

.tool-exec-block.collapsed .tool-exec-chevron {
  transform: rotate(-90deg);
}

.tool-exec-block.collapsed .tool-exec-items {
  display: none;
}

.tool-exec-block.collapsed .tool-exec-approval {
  display: none;
}

/* ─── Tool Approval Buttons ────────────────────────────────────────────── */

.tool-exec-approval {
  display: flex;
  gap: 8px;
  padding: 8px 14px 12px;
  border-bottom: 1px solid var(--border);
}

.tool-approve-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.tool-reject-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

/* ─── Tool Execution Items ─────────────────────────────────────────────── */

.tool-exec-items {
  border-top: 1px solid var(--border);
}

.tool-exec-item {
  border-bottom: 1px solid color-mix(in srgb, var(--border) 50%, transparent);
}

.tool-exec-item:last-child {
  border-bottom: none;
}

.tool-exec-item-header {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 14px;
  cursor: pointer;
  user-select: none;
  transition: background var(--transition);
}

.tool-exec-item-header:hover {
  background: var(--bg-hover);
}

/* Status indicators */
.tool-exec-status {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  flex-shrink: 0;
}

.tool-exec-status.done {
  background: color-mix(in srgb, var(--success) 18%, transparent);
  color: var(--success);
}

.tool-exec-status.error {
  background: color-mix(in srgb, var(--danger) 18%, transparent);
  color: var(--danger);
}

.tool-exec-status.executing {
  background: color-mix(in srgb, var(--accent) 18%, transparent);
  color: var(--accent);
  animation: tool-spin 1s linear infinite;
}

.tool-exec-status.pending {
  background: color-mix(in srgb, var(--warning) 15%, transparent);
  color: var(--warning);
}

.tool-exec-status.queued {
  background: var(--bg-tertiary);
}

.tool-exec-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--text-muted);
}

.tool-exec-name {
  font-family: var(--font-mono);
  font-size: 12px;
  font-weight: 600;
  color: var(--text-primary);
}

.tool-exec-summary {
  font-size: 11px;
  color: var(--text-muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  min-width: 0;
  flex: 1;
}

.tool-exec-item-chevron {
  color: var(--text-muted);
  display: flex;
  align-items: center;
  transition: transform var(--transition);
  flex-shrink: 0;
}

.tool-exec-item.expanded .tool-exec-item-chevron {
  transform: rotate(180deg);
}

/* Expandable detail body */
.tool-exec-item-body {
  display: none;
  padding: 0 14px 10px;
}

.tool-exec-item.expanded .tool-exec-item-body {
  display: block;
}

.tool-exec-section {
  margin-top: 8px;
}

.tool-exec-section-label {
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
  margin-bottom: 4px;
}

.tool-exec-args {
  margin: 0;
  border-radius: var(--radius);
}

.tool-exec-args code {
  display: block;
  padding: 8px 10px;
  font-size: 11px;
  line-height: 1.4;
  background: var(--code-bg);
  border-radius: var(--radius);
  overflow-x: auto;
  max-height: 200px;
  overflow-y: auto;
}

.tool-exec-result-content {
  font-size: 12px;
  color: var(--text-secondary);
  line-height: 1.5;
  padding: 8px 10px;
  background: var(--code-bg);
  border-radius: var(--radius);
  max-height: 150px;
  overflow-y: hidden;
  position: relative;
}

.tool-exec-result-content.truncatable {
  cursor: pointer;
}

.tool-exec-result-content.truncatable.expanded {
  max-height: none;
}

.tool-exec-result-content.is-error {
  border-left: 3px solid var(--danger);
}

.tool-exec-result-content p {
  margin-bottom: 4px;
}

.tool-exec-result-content p:last-child {
  margin-bottom: 0;
}

.tool-exec-result-fade {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  height: 40px;
  background: linear-gradient(transparent, var(--code-bg));
  pointer-events: none;
}

.tool-exec-result-content.expanded .tool-exec-result-fade {
  display: none;
}

/* ─── MCP Dropdown (Quick Access Popover) ──────────────────────────────── */

#mcp-dropdown {
  position: absolute;
  top: calc(var(--topbar-height) + 4px);
  right: 100px;
  width: 320px;
  max-height: 420px;
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  z-index: 100;
  overflow-y: auto;
  display: none;
}

.mcp-dropdown-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
}

.mcp-dropdown-title {
  font-size: 13px;
  font-weight: 700;
  color: var(--text-primary);
}

.mcp-dropdown-empty {
  padding: 20px 14px;
  text-align: center;
  color: var(--text-muted);
  font-size: 13px;
}

.mcp-dropdown-empty p {
  margin-bottom: 10px;
}

.mcp-dropdown-servers {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
}

.mcp-dropdown-server-pill {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-size: 11px;
  padding: 3px 8px;
  border-radius: 10px;
  background: var(--bg-tertiary);
  color: var(--text-secondary);
}

.mcp-dropdown-server-pill .mcp-server-dot {
  width: 6px;
  height: 6px;
}

.mcp-dropdown-tools {
  padding: 6px 0;
  max-height: 280px;
  overflow-y: auto;
}

.mcp-dropdown-tool {
  padding: 6px 14px;
  transition: background var(--transition);
}

.mcp-dropdown-tool:hover {
  background: var(--bg-hover);
}

.mcp-dropdown-tool-name {
  font-family: var(--font-mono);
  font-size: 12px;
  font-weight: 600;
  color: var(--accent);
  display: block;
}

.mcp-dropdown-tool-desc {
  font-size: 11px;
  color: var(--text-muted);
  line-height: 1.3;
  display: block;
  margin-top: 1px;
}

.btn-sm {
  padding: 4px 10px;
  font-size: 12px;
}

/* ─── Responsive: Tool blocks on mobile ────────────────────────────────── */

@media (max-width: 768px) {
  .tool-exec-block {
    margin: 6px 8px;
  }
  #mcp-dropdown {
    right: 8px;
    width: calc(100vw - 16px);
  }
}
