/* ── Variables ─────────────────────────────────────────── */
:root {
  --bg:           #0d0f12;
  --bg-secondary: #13161b;
  --sidebar-bg:   #0b0d10;
  --surface:      #1a1e26;
  --surface-hover:#212633;
  --border:       rgba(255,255,255,0.07);
  --border-hover: rgba(255,255,255,0.14);
  --text:         #e8eaf0;
  --text-muted:   #6b7280;
  --text-faint:   #374151;
  --accent:       #3b82f6;
  --accent-dim:   rgba(59,130,246,0.15);
  --accent-glow:  rgba(59,130,246,0.25);
  --green:        #22c55e;
  --red:          #ef4444;
  --yellow:       #f59e0b;
  --cyan:         #06b6d4;
  --purple:       #a78bfa;
  --user-bubble:  #1e2a3d;
  --scrollbar:    rgba(255,255,255,0.08);
  --radius:       12px;
  --sidebar-w:    260px;
  font-size: 15px;
}

/* ── Light theme ────────────────────────────────────────── */
[data-theme="light"] {
  --bg:           #f7f8fa;
  --bg-secondary: #ffffff;
  --sidebar-bg:   #f0f1f5;
  --surface:      #ffffff;
  --surface-hover:#f3f4f8;
  --border:       rgba(0,0,0,0.08);
  --border-hover: rgba(0,0,0,0.15);
  --text:         #111827;
  --text-muted:   #6b7280;
  --text-faint:   #d1d5db;
  --accent:       #2563eb;
  --accent-dim:   rgba(37,99,235,0.1);
  --accent-glow:  rgba(37,99,235,0.2);
  --user-bubble:  #dbeafe;
  --scrollbar:    rgba(0,0,0,0.1);
}

/* ── OLED theme ─────────────────────────────────────────── */
[data-theme="oled"] {
  --bg:           #000000;
  --bg-secondary: #000000;
  --sidebar-bg:   #000000;
  --surface:      #0a0a0a;
  --surface-hover:#111111;
  --border:       rgba(255,255,255,0.06);
  --border-hover: rgba(255,255,255,0.12);
  --text:         #f0f0f0;
  --text-muted:   #555;
  --text-faint:   #222;
  --accent:       #3b82f6;
  --accent-dim:   rgba(59,130,246,0.12);
  --accent-glow:  rgba(59,130,246,0.2);
  --user-bubble:  #0d1520;
  --scrollbar:    rgba(255,255,255,0.06);
}

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

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

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

/* ── Layout ────────────────────────────────────────────── */
#app {
  display: flex;
  height: 100vh;
  height: 100dvh;
  overflow: hidden;
}

/* ── Sidebar ───────────────────────────────────────────── */
#sidebar {
  width: var(--sidebar-w);
  min-width: var(--sidebar-w);
  background: var(--sidebar-bg);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  transition: transform 0.25s ease, width 0.25s ease, min-width 0.25s ease;
  overflow: hidden;
  position: relative;
  z-index: 10;
}

#sidebar.collapsed {
  width: 0;
  min-width: 0;
  border-right: none;
}

.sidebar-header {
  padding: 16px 14px 12px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 10px;
}

.logo {
  display: flex;
  align-items: center;
  gap: 8px;
  flex: 1;
  text-decoration: none;
  color: var(--text);
}

.logo-icon {
  width: 32px; height: 32px;
  background: linear-gradient(135deg, var(--accent), var(--cyan));
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
  flex-shrink: 0;
}

.logo-text { font-size: 15px; font-weight: 700; letter-spacing: -0.3px; }
.logo-sub  { font-size: 10px; color: var(--text-muted); font-weight: 500; letter-spacing: 0.5px; text-transform: uppercase; }

.btn-new-chat {
  display: flex;
  align-items: center;
  gap: 8px;
  width: calc(100% - 28px);
  margin: 10px 14px 6px;
  padding: 9px 14px;
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: var(--radius);
  cursor: pointer;
  font-size: 13px;
  font-weight: 600;
  transition: background 0.15s, transform 0.1s;
}
.btn-new-chat:hover  { background: #2563eb; }
.btn-new-chat:active { transform: scale(0.98); }

/* ── Sidebar search ─────────────────────────────────────── */
.sidebar-search {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 4px 14px 2px;
  padding: 6px 10px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text-muted);
}

.sidebar-search svg { flex-shrink: 0; }

#conv-search {
  flex: 1;
  background: none;
  border: none;
  outline: none;
  font-size: 12px;
  font-family: inherit;
  color: var(--text);
}
#conv-search::placeholder { color: var(--text-muted); }

.sidebar-section {
  padding: 8px 10px 2px;
  font-size: 10px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.8px;
  color: var(--text-muted);
}

#conversation-list {
  flex: 1;
  overflow-y: auto;
  padding: 4px 8px 8px;
}

.conv-item {
  display: flex;
  align-items: center;
  padding: 8px 10px;
  border-radius: 8px;
  cursor: pointer;
  gap: 8px;
  transition: background 0.12s;
  position: relative;
}
.conv-item:hover    { background: var(--surface-hover); }
.conv-item.active   { background: var(--surface); }
.conv-item.active::before {
  content: '';
  position: absolute;
  left: 0; top: 6px; bottom: 6px;
  width: 2px;
  background: var(--accent);
  border-radius: 0 2px 2px 0;
}

.conv-icon  { color: var(--text-muted); flex-shrink: 0; opacity: 0.6; }
.conv-title {
  flex: 1;
  font-size: 13px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  color: var(--text);
}
.conv-item.active .conv-title { font-weight: 500; }

.conv-delete {
  opacity: 0;
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  padding: 2px;
  border-radius: 4px;
  display: flex;
  transition: opacity 0.12s, color 0.12s;
}
.conv-item:hover .conv-delete { opacity: 1; }
.conv-delete:hover             { color: var(--red); }

.sidebar-footer {
  padding: 10px 14px;
  border-top: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.sidebar-footer-user {
  display: flex;
  align-items: center;
  gap: 4px;
  margin-left: auto;
}

.footer-username {
  font-size: 11px;
  color: var(--text-muted);
  max-width: 90px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.btn-icon-sm {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 24px;
  height: 24px;
  background: none;
  border: 1px solid transparent;
  border-radius: 6px;
  color: var(--text-muted);
  cursor: pointer;
  transition: background 0.12s, color 0.12s, border-color 0.12s;
  padding: 0;
}
.btn-icon-sm:hover {
  background: var(--surface-hover);
  color: var(--text);
  border-color: var(--border);
}

/* ── Modal ────────────────────────────────────────────────── */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.6);
  backdrop-filter: blur(2px);
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
}

.modal-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.5rem;
  width: 100%;
  max-width: 420px;
  max-height: 80vh;
  overflow-y: auto;
  margin: 1rem;
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 1.25rem;
}

.modal-title {
  font-size: 0.95rem;
  font-weight: 600;
}

.modal-section-label {
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 0.6rem;
}

.create-user-form {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
  align-items: center;
}

.create-user-form input[type="text"],
.create-user-form input[type="password"],
#chpw-form input[type="password"] {
  flex: 1;
  min-width: 110px;
  background: rgba(255,255,255,0.04);
  border: 1px solid var(--border);
  border-radius: 7px;
  padding: 0.45rem 0.7rem;
  font-size: 0.82rem;
  color: var(--text);
  outline: none;
  font-family: inherit;
  transition: border-color 0.15s;
}
.create-user-form input:focus,
#chpw-form input:focus { border-color: var(--accent); }

.admin-check {
  display: flex;
  align-items: center;
  gap: 5px;
  font-size: 0.82rem;
  color: var(--text-muted);
  cursor: pointer;
  white-space: nowrap;
}

.btn-create-user {
  padding: 0.45rem 1rem;
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: 7px;
  font-size: 0.82rem;
  font-weight: 600;
  cursor: pointer;
  font-family: inherit;
  transition: background 0.12s;
  white-space: nowrap;
}
.btn-create-user:hover { background: #2563eb; }

.create-user-error {
  font-size: 0.8rem;
  color: var(--red);
  margin-top: 0.4rem;
  min-height: 1rem;
}

.user-list { display: flex; flex-direction: column; gap: 4px; }

.user-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 0.5rem 0.65rem;
  border-radius: 8px;
  background: rgba(255,255,255,0.03);
  border: 1px solid var(--border);
}

.user-row-name {
  font-size: 0.85rem;
  font-weight: 500;
  flex: 1;
}

.user-row-badge {
  font-size: 0.7rem;
  padding: 2px 7px;
  border-radius: 20px;
  background: rgba(59,130,246,0.15);
  color: var(--accent);
  font-weight: 600;
}

.user-row-badge.admin { background: rgba(167,139,250,0.15); color: var(--purple); }

.btn-delete-user {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 26px;
  height: 26px;
  background: none;
  border: 1px solid transparent;
  border-radius: 6px;
  color: var(--text-muted);
  cursor: pointer;
  transition: background 0.12s, color 0.12s, border-color 0.12s;
  padding: 0;
  flex-shrink: 0;
}
.btn-delete-user:hover {
  background: rgba(239,68,68,0.1);
  color: var(--red);
  border-color: rgba(239,68,68,0.3);
}

.status-dot {
  width: 8px; height: 8px;
  border-radius: 50%;
  background: var(--text-muted);
  flex-shrink: 0;
  transition: background 0.3s;
}
.status-dot.online { background: var(--green); box-shadow: 0 0 6px var(--green); }
.status-dot.error  { background: var(--red); }

.status-label {
  font-size: 12px;
  color: var(--text-muted);
  flex: 1;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

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

/* ── Topbar ────────────────────────────────────────────── */
#topbar {
  height: 52px;
  display: flex;
  align-items: center;
  padding: 0 12px;
  border-bottom: 1px solid var(--border);
  background: var(--bg-secondary);
  gap: 8px;
  flex-shrink: 0;
}

.btn-icon {
  background: none;
  border: 1px solid var(--border);
  color: var(--text-muted);
  cursor: pointer;
  padding: 6px;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.12s, color 0.12s, border-color 0.12s;
  flex-shrink: 0;
}
.btn-icon:hover {
  background: var(--surface);
  color: var(--text);
  border-color: var(--border-hover);
}

#conv-title-display {
  flex: 1;
  font-size: 14px;
  font-weight: 500;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  text-align: center;
}

/* ── Model picker ───────────────────────────────────────── */
.model-picker {
  position: relative;
  display: flex;
  align-items: center;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 0 8px 0 10px;
  gap: 2px;
  transition: border-color 0.12s;
  flex-shrink: 0;
}
.model-picker:focus-within { border-color: var(--accent); }

#model-select {
  background: none;
  border: none;
  outline: none;
  font-size: 11px;
  font-family: inherit;
  color: var(--text-muted);
  font-weight: 500;
  cursor: pointer;
  padding: 5px 0;
  max-width: 160px;
  appearance: none;
  -webkit-appearance: none;
}
#model-select option { background: var(--surface); color: var(--text); }

.model-picker-arrow { color: var(--text-muted); flex-shrink: 0; }

/* ── Export dropdown ────────────────────────────────────── */
.topbar-menu { position: relative; flex-shrink: 0; }

.topbar-dropdown {
  position: absolute;
  top: calc(100% + 6px);
  right: 0;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: 0 8px 24px rgba(0,0,0,0.3);
  min-width: 160px;
  overflow: hidden;
  display: none;
  z-index: 100;
}
.topbar-dropdown.open { display: block; }

.dropdown-item {
  display: block;
  width: 100%;
  padding: 9px 14px;
  background: none;
  border: none;
  color: var(--text);
  font-size: 13px;
  font-family: inherit;
  text-align: left;
  cursor: pointer;
  transition: background 0.1s;
}
.dropdown-item:hover { background: var(--surface-hover); }

/* ── Chat Area ─────────────────────────────────────────── */
#chat-area {
  flex: 1;
  overflow-y: auto;
  padding: 24px 0 8px;
  display: flex;
  flex-direction: column;
}

.welcome {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 40px 20px;
  text-align: center;
}

.welcome-icon {
  width: 64px; height: 64px;
  background: linear-gradient(135deg, var(--accent), var(--cyan));
  border-radius: 18px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 30px;
  margin-bottom: 20px;
  box-shadow: 0 8px 32px var(--accent-glow);
}

.welcome h2 {
  font-size: 24px;
  font-weight: 700;
  margin-bottom: 8px;
  background: linear-gradient(135deg, var(--text), var(--accent));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}

.welcome p {
  color: var(--text-muted);
  font-size: 14px;
  max-width: 380px;
  line-height: 1.6;
  margin-bottom: 28px;
}

.suggestions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  max-width: 480px;
  width: 100%;
}

.suggestion {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 14px;
  cursor: pointer;
  text-align: left;
  transition: background 0.12s, border-color 0.12s, transform 0.1s;
  color: var(--text);
}
.suggestion:hover {
  background: var(--surface-hover);
  border-color: var(--border-hover);
  transform: translateY(-1px);
}
.suggestion-icon { font-size: 18px; margin-bottom: 5px; display: block; }
.suggestion-text { font-size: 12px; color: var(--text-muted); line-height: 1.4; }

/* ── Messages ──────────────────────────────────────────── */
.message-row {
  padding: 6px 16px;
  max-width: 840px;
  width: 100%;
  margin: 0 auto;
  animation: fadeInUp 0.2s ease;
  position: relative;
}

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

.message-row.user {
  display: flex;
  justify-content: flex-end;
}

.user-msg-wrap {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  max-width: 72%;
  gap: 4px;
}

.msg-actions {
  display: flex;
  gap: 4px;
  opacity: 0;
  transition: opacity 0.15s;
}
.message-row.user:hover .msg-actions { opacity: 1; }

.msg-action-btn {
  display: flex;
  align-items: center;
  gap: 4px;
  background: none;
  border: 1px solid var(--border);
  color: var(--text-muted);
  font-size: 11px;
  font-family: inherit;
  padding: 3px 8px;
  border-radius: 6px;
  cursor: pointer;
  transition: background 0.12s, color 0.12s, border-color 0.12s;
}
.msg-action-btn:hover {
  background: var(--surface);
  color: var(--text);
  border-color: var(--border-hover);
}

/* ── Inline message edit ────────────────────────────────── */
.edit-area {
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.edit-textarea {
  width: 100%;
  min-width: 280px;
  background: var(--surface);
  border: 1px solid var(--accent);
  border-radius: var(--radius);
  color: var(--text);
  font-size: 14px;
  font-family: inherit;
  padding: 10px 12px;
  resize: none;
  outline: none;
  box-shadow: 0 0 0 3px var(--accent-dim);
  line-height: 1.5;
}

.edit-actions {
  display: flex;
  gap: 6px;
  justify-content: flex-end;
}

.btn-primary-sm {
  padding: 5px 12px;
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: 8px;
  font-size: 12px;
  font-family: inherit;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s;
}
.btn-primary-sm:hover { background: #2563eb; }

.btn-ghost-sm {
  padding: 5px 12px;
  background: none;
  color: var(--text-muted);
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 12px;
  font-family: inherit;
  cursor: pointer;
  transition: background 0.12s, color 0.12s;
}
.btn-ghost-sm:hover { background: var(--surface); color: var(--text); }

.message-bubble {
  padding: 11px 15px;
  border-radius: 16px;
  font-size: 14px;
  line-height: 1.65;
}

.message-row.user .message-bubble {
  background: var(--user-bubble);
  border: 1px solid rgba(59,130,246,0.2);
  border-bottom-right-radius: 4px;
  color: var(--text);
  max-width: 100%;
}

.message-row.assistant {
  display: flex;
  gap: 10px;
  align-items: flex-start;
}

.assistant-avatar {
  width: 28px; height: 28px;
  background: linear-gradient(135deg, var(--accent), var(--cyan));
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  flex-shrink: 0;
  margin-top: 4px;
}

.message-row.assistant .message-bubble {
  background: transparent;
  color: var(--text);
  max-width: calc(100% - 38px);
  padding: 4px 0;
}

/* ── Copy button on assistant messages ──────────────────── */
.msg-copy-btn {
  position: absolute;
  top: 6px;
  right: 16px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text-muted);
  cursor: pointer;
  padding: 4px 6px;
  display: flex;
  align-items: center;
  opacity: 0;
  transition: opacity 0.15s, color 0.12s, background 0.12s;
}
.message-row.assistant:hover .msg-copy-btn { opacity: 1; }
.msg-copy-btn:hover { background: var(--surface-hover); color: var(--text); }

/* ── Conversation metadata bar ──────────────────────────── */
.msg-meta-bar {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 0;
  padding: 5px 14px 5px 42px;   /* indent to align with message bubble */
  font-size: 11px;
  color: var(--text-muted);
  opacity: 0.75;
  line-height: 1.4;
  border-top: 1px solid var(--border);
  margin-top: 2px;
  margin-bottom: 8px;
  user-select: none;
}
.msg-meta-bar span {
  white-space: nowrap;
}
.meta-sep {
  margin: 0 6px;
  opacity: 0.4;
}
.meta-model {
  font-weight: 600;
  color: var(--accent);
  opacity: 1;
}
.msg-meta-bar:hover {
  opacity: 1;
}

/* ── Copy button on code blocks ─────────────────────────── */
.code-copy-btn {
  position: absolute;
  top: 8px;
  right: 8px;
  background: var(--surface-hover);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text-muted);
  font-size: 11px;
  font-family: inherit;
  font-weight: 500;
  padding: 3px 8px;
  cursor: pointer;
  opacity: 0;
  transition: opacity 0.15s, color 0.12s, background 0.12s;
}
.message-bubble pre:hover .code-copy-btn { opacity: 1; }
.code-copy-btn:hover { background: var(--surface); color: var(--text); }

/* ── Markdown in messages ──────────────────────────────── */
.message-bubble p { margin-bottom: 10px; }
.message-bubble p:last-child { margin-bottom: 0; }

.message-bubble h1, .message-bubble h2, .message-bubble h3 {
  margin: 16px 0 8px;
  font-weight: 600;
}
.message-bubble h1 { font-size: 18px; }
.message-bubble h2 { font-size: 16px; }
.message-bubble h3 { font-size: 14px; }

.message-bubble code {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 1px 5px;
  font-size: 12.5px;
  font-family: 'JetBrains Mono', 'Fira Code', monospace;
  color: var(--cyan);
}

.message-bubble pre {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 16px;
  overflow-x: auto;
  margin: 10px 0;
  position: relative;
}

.message-bubble pre code {
  background: none;
  border: none;
  padding: 0;
  color: inherit;
  font-size: 13px;
}

.message-bubble ul, .message-bubble ol { padding-left: 20px; margin-bottom: 10px; }
.message-bubble li { margin-bottom: 3px; }

.message-bubble table {
  border-collapse: collapse;
  width: 100%;
  margin: 10px 0;
  font-size: 13px;
}
.message-bubble th, .message-bubble td {
  border: 1px solid var(--border);
  padding: 6px 10px;
  text-align: left;
}
.message-bubble th { background: var(--surface); font-weight: 600; }

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

/* ── Tool Call Cards ───────────────────────────────────── */
.tool-card {
  max-width: 840px;
  width: 100%;
  margin: 4px auto;
  padding: 0 16px 0 54px;
}

.tool-card-inner {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  transition: border-color 0.2s;
}
.tool-card-inner.running { border-color: var(--accent); }
.tool-card-inner.done    { border-color: rgba(34,197,94,0.3); }
.tool-card-inner.error   { border-color: rgba(239,68,68,0.3); }

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

.tool-status-icon {
  width: 22px; height: 22px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 11px;
  flex-shrink: 0;
}
.tool-status-icon.running { background: var(--accent-dim); color: var(--accent); animation: spin 1.2s linear infinite; }
.tool-status-icon.done    { background: rgba(34,197,94,0.15); color: var(--green); }
.tool-status-icon.error   { background: rgba(239,68,68,0.15); color: var(--red); }

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

.tool-name         { font-size: 13px; font-weight: 600; font-family: 'JetBrains Mono', monospace; color: var(--accent); }
.tool-args-preview { font-size: 12px; color: var(--text-muted); flex: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tool-chevron      { color: var(--text-muted); transition: transform 0.2s; flex-shrink: 0; }
.tool-card-inner.expanded .tool-chevron { transform: rotate(90deg); }

.tool-body {
  display: none;
  border-top: 1px solid var(--border);
  padding: 12px 14px;
}
.tool-card-inner.expanded .tool-body { display: block; }

.tool-section-label {
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.8px;
  color: var(--text-muted);
  font-weight: 600;
  margin-bottom: 6px;
}

.tool-body pre {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 12px;
  font-size: 12px;
  font-family: 'JetBrains Mono', monospace;
  overflow-x: auto;
  white-space: pre-wrap;
  word-break: break-all;
  color: var(--text);
  max-height: 320px;
  overflow-y: auto;
  margin-bottom: 10px;
}

/* ── Cursor ────────────────────────────────────────────── */
.cursor {
  display: inline-block;
  width: 2px;
  height: 1em;
  background: var(--accent);
  border-radius: 1px;
  animation: blink 1s step-end infinite;
  vertical-align: text-bottom;
  margin-left: 1px;
}
@keyframes blink {
  0%, 100% { opacity: 1; }
  50%       { opacity: 0; }
}

/* ── Input Area ────────────────────────────────────────── */
#input-area {
  padding: 12px 16px 16px;
  /* Extra bottom padding for iOS home bar */
  padding-bottom: max(16px, env(safe-area-inset-bottom, 16px));
  background: var(--bg-secondary);
  border-top: 1px solid var(--border);
  flex-shrink: 0;
}

.input-wrapper {
  max-width: 840px;
  margin: 0 auto;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  display: flex;
  align-items: flex-end;
  padding: 8px 8px 8px 16px;
  gap: 8px;
  transition: border-color 0.2s, box-shadow 0.2s;
}
.input-wrapper:focus-within {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-dim);
}

#user-input {
  flex: 1;
  background: none;
  border: none;
  outline: none;
  color: var(--text);
  font-size: 14px;
  font-family: inherit;
  resize: none;
  min-height: 24px;
  max-height: 200px;
  overflow-y: auto;
  padding: 4px 0;
  line-height: 1.5;
}
#user-input::placeholder { color: var(--text-muted); }

.input-actions { display: flex; gap: 6px; align-items: flex-end; padding-bottom: 2px; }

#send-btn, #stop-btn {
  width: 36px; height: 36px;
  border: none;
  border-radius: 10px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s, transform 0.1s, opacity 0.2s;
}
#send-btn { background: var(--accent); color: white; }
#send-btn:hover  { background: #2563eb; }
#send-btn:active { transform: scale(0.95); }
#send-btn:disabled { opacity: 0.4; cursor: default; }

#stop-btn { background: rgba(239,68,68,0.15); color: var(--red); border: 1px solid rgba(239,68,68,0.3); }
#stop-btn:hover  { background: rgba(239,68,68,0.25); }
#stop-btn:active { transform: scale(0.95); }

#scroll-to-bottom {
  position: absolute;
  bottom: 140px;
  right: 24px;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text-muted);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 2px 8px rgba(0,0,0,0.3);
  transition: background 0.15s, color 0.15s, transform 0.15s;
  z-index: 10;
}
#scroll-to-bottom:hover { background: var(--accent); color: white; transform: translateY(2px); }

#lang-select {
  appearance: none;
  background: transparent;
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text-muted);
  font-size: 12px;
  font-family: inherit;
  padding: 4px 22px 4px 8px;
  cursor: pointer;
  outline: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='10' viewBox='0 0 24 24' fill='none' stroke='%23888' stroke-width='2.5'%3E%3Cpolyline points='6 9 12 15 18 9'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 6px center;
  transition: border-color 0.15s, color 0.15s;
}
#lang-select:hover  { border-color: var(--accent); color: var(--text); }
#lang-select:focus  { border-color: var(--accent); color: var(--text); }
#lang-select option { background: var(--bg); color: var(--text); }

.input-toggles {
  max-width: 840px;
  margin: 4px auto 0;
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}

.toggle-pill {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 3px 9px 3px 7px;
  border-radius: 20px;
  font-size: 11px;
  font-weight: 500;
  cursor: pointer;
  user-select: none;
  border: 1px solid var(--border);
  color: var(--text-muted);
  background: transparent;
  transition: background 0.15s, color 0.15s, border-color 0.15s;
}
.toggle-pill svg { opacity: 0.5; transition: opacity 0.15s; flex-shrink: 0; }
.toggle-pill:hover { border-color: var(--accent); color: var(--text); }
.toggle-pill:hover svg { opacity: 0.8; }

/* ── Suggest chips ─────────────────────────────────────────── */
.suggest-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 10px;
  padding-top: 10px;
  border-top: 1px solid var(--border);
}

.suggest-chip {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 5px 12px;
  border-radius: 20px;
  border: 1px solid var(--accent);
  background: var(--accent-dim);
  color: var(--accent);
  font-size: 12px;
  font-family: inherit;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
  white-space: nowrap;
}

.suggest-chip:hover {
  background: var(--accent);
  color: #fff;
}

.suggest-chip::before {
  content: '↳';
  opacity: 0.6;
  font-size: 11px;
}

.toggle-pill.active {
  background: var(--accent-dim);
  border-color: var(--accent);
  color: var(--accent);
}
.toggle-pill.active svg { opacity: 1; }

.input-hint {
  text-align: center;
  font-size: 11px;
  color: var(--text-muted);
  margin-top: 6px;
}

/* ── Error banner ──────────────────────────────────────── */
.error-banner {
  background: rgba(239,68,68,0.1);
  border: 1px solid rgba(239,68,68,0.3);
  border-radius: var(--radius);
  padding: 10px 14px;
  font-size: 13px;
  color: var(--red);
  max-width: 840px;
  margin: 8px auto;
  display: flex;
  align-items: center;
  gap: 8px;
}

/* ── Thinking dots ─────────────────────────────────────── */
.thinking-row {
  padding: 6px 16px;
  max-width: 840px;
  width: 100%;
  margin: 0 auto;
  display: flex;
  gap: 10px;
  align-items: flex-start;
}

.thinking-dots {
  display: flex;
  gap: 4px;
  padding: 12px 0;
}

.thinking-dots span {
  width: 6px; height: 6px;
  background: var(--text-muted);
  border-radius: 50%;
  animation: bounce 1.2s ease-in-out infinite;
}
.thinking-dots span:nth-child(2) { animation-delay: 0.15s; }
.thinking-dots span:nth-child(3) { animation-delay: 0.3s; }

@keyframes bounce {
  0%, 60%, 100% { transform: translateY(0); opacity: 0.4; }
  30%           { transform: translateY(-6px); opacity: 1; }
}

/* ── LLM thinking blocks (<think>…</think>) ─────────────── */
.thinking-block {
  margin: 0 0 12px 0;
  border: 1px solid var(--border);
  border-left: 3px solid rgba(167,139,250,0.4);
  border-radius: 6px;
  background: rgba(167,139,250,0.04);
  overflow: hidden;
}

.thinking-summary {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 10px;
  font-size: 11px;
  font-weight: 500;
  color: var(--text-muted);
  cursor: pointer;
  user-select: none;
  letter-spacing: 0.03em;
  text-transform: uppercase;
  list-style: none;
}
.thinking-summary::-webkit-details-marker { display: none; }
.thinking-summary::before { content: '▶'; font-size: 9px; transition: transform 0.15s ease; opacity: 0.5; }
details.thinking-block[open] .thinking-summary::before { transform: rotate(90deg); }

.thinking-content {
  padding: 8px 12px 10px;
  font-size: 12.5px;
  line-height: 1.6;
  color: var(--text-muted);
  opacity: 0.75;
  border-top: 1px solid var(--border);
}
.thinking-content p { margin: 0 0 6px; }
.thinking-content p:last-child { margin-bottom: 0; }
.thinking-content code { font-size: 11px; background: rgba(255,255,255,0.05); padding: 1px 4px; border-radius: 3px; }
.thinking-content a { color: var(--text-primary); text-decoration: underline; opacity: 0.8; }
.thinking-content a:hover { opacity: 1; }

/* ── Empty state ───────────────────────────────────────── */
.empty-sidebar {
  padding: 20px 14px;
  text-align: center;
  color: var(--text-muted);
  font-size: 12px;
}

/* ── highlight.js ──────────────────────────────────────── */
.hljs { background: transparent !important; padding: 0 !important; font-size: 13px; }

/* ── Responsive / Mobile ────────────────────────────────── */
/* Sidebar overlay (mobile backdrop) */
#sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.5);
  z-index: 190;
}
#sidebar-overlay.active { display: block; }

@media (max-width: 768px) {
  :root { --sidebar-w: 80vw; }

  /* Shrink pills row so it fits on a single line on small screens */
  .input-toggles {
    gap: 4px;
  }
  .toggle-pill {
    padding: 2px 7px 2px 6px;
    font-size: 10px;
  }

  #sidebar {
    position: fixed;
    top: 0; left: 0;
    height: 100%;
    z-index: 200;
    transform: translateX(-100%);
    width: var(--sidebar-w);
    min-width: var(--sidebar-w);
    box-shadow: 4px 0 24px rgba(0,0,0,0.4);
  }

  #sidebar.open {
    transform: translateX(0);
  }

  #sidebar.collapsed {
    transform: translateX(-100%);
    width: var(--sidebar-w);
    min-width: var(--sidebar-w);
    border-right: 1px solid var(--border);
  }

  #conv-title-display { font-size: 13px; }

  .model-picker { max-width: 100px; }
  #model-select { max-width: 80px; font-size: 10px; }

  .suggestions { grid-template-columns: 1fr; }

  .message-row { padding: 6px 10px; }
  .user-msg-wrap { max-width: 88%; }
  .message-row.assistant .message-bubble { max-width: calc(100% - 34px); }

  .tool-card { padding: 0 10px 0 44px; }

  #topbar { padding: 0 8px; gap: 6px; }

  .input-hint { display: none; }

  .msg-actions { opacity: 1; }
  .msg-copy-btn { opacity: 1; }
}

@media (max-width: 480px) {
  .welcome h2 { font-size: 20px; }
  .welcome p  { font-size: 13px; }
  #conv-title-display { display: none; }
  .model-picker { display: none; }
}
