/* Monica-inspired UI — soft, spacious, utilitarian minimalism */

:root {
  /* Light theme (default) */
  --bg: #ffffff;
  --bg-secondary: #f7f7f8;
  --bg-tertiary: #ececec;
  --bg-input: #ffffff;
  --bg-hover: rgba(0, 0, 0, 0.04);
  --text: #1e293b;
  --text-secondary: #64748b;
  --text-dim: #94a3b8;
  --accent: #6366f1;
  --accent-hover: #4f46e5;
  --accent-light: rgba(99, 102, 241, 0.08);
  --accent-lighter: rgba(99, 102, 241, 0.04);
  --error: #ef4444;
  --error-bg: rgba(239, 68, 68, 0.08);
  --border: #e5e5e5;
  --border-light: #f1f5f9;
  --shadow: 0 1px 3px rgba(0, 0, 0, 0.06);
  --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.08);
  --radius: 14px;
  --radius-sm: 10px;
  --radius-xs: 6px;

  /* Layout */
  --header-h: 52px;
  --input-max-h: 120px;
}

[data-theme="dark"] {
  --bg: #1a1a1a;
  --bg-secondary: #222222;
  --bg-tertiary: #2a2a2a;
  --bg-input: #222222;
  --bg-hover: rgba(255, 255, 255, 0.06);
  --text: #e8e8e8;
  --text-secondary: #a0a0a0;
  --text-dim: #6a6a6a;
  --accent: #5b8def;
  --accent-hover: #4a7de0;
  --accent-light: rgba(91, 141, 239, 0.15);
  --accent-lighter: rgba(91, 141, 239, 0.07);
  --error: #ef4444;
  --error-bg: rgba(239, 68, 68, 0.12);
  --border: #2e2e2e;
  --border-light: #252525;
  --shadow: 0 1px 3px rgba(0, 0, 0, 0.3);
  --shadow-md: 0 4px 16px rgba(0, 0, 0, 0.4);
}

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

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

body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  font-size: 14px;
  line-height: 1.5;
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

/* ============ App Layout ============ */

.sidebar-app {
  display: flex;
  flex-direction: column;
  height: 100%;
}

.sidebar-body {
  display: flex;
  flex: 1;
  overflow: hidden;
}

/* ============ Header ============ */

.header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 16px;
  height: var(--header-h);
  background: var(--bg);
  flex-shrink: 0;
}

.header-left, .header-right {
  display: flex;
  align-items: center;
  gap: 4px;
}

.header-title {
  font-size: 15px;
  font-weight: 600;
  letter-spacing: -0.01em;
  color: var(--text);
}

.btn-icon {
  background: none;
  border: none;
  color: var(--text-secondary);
  width: 32px;
  height: 32px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-size: 16px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.15s ease;
}

.btn-icon:hover {
  background: var(--accent-light);
  color: var(--accent);
}

.btn-icon.active {
  background: var(--accent-light);
  color: var(--accent);
}

/* ============ Conversation List (Monica-style overlay) ============ */

.conv-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  z-index: 500;
  animation: fade-in 0.2s ease;
}

.conv-backdrop-closing {
  animation: fade-out 0.2s ease forwards;
}

@keyframes fade-in {
  from { opacity: 0; }
  to { opacity: 1; }
}

@keyframes fade-out {
  from { opacity: 1; }
  to { opacity: 0; }
}

.conversation-list {
  position: absolute;
  top: 0;
  left: 0;
  bottom: 0;
  width: 260px;
  background: var(--bg-secondary);
  display: flex;
  flex-direction: column;
  z-index: 501;
  border-radius: 0 var(--radius) var(--radius) 0;
  box-shadow: 4px 0 24px rgba(0, 0, 0, 0.2);
  animation: slide-in-left 0.25s cubic-bezier(0.16, 1, 0.3, 1);
}

.conversation-list-closing {
  animation: slide-out-left 0.2s cubic-bezier(0.7, 0, 0.84, 0) forwards;
}

@keyframes slide-in-left {
  from { transform: translateX(-100%); opacity: 0.5; }
  to { transform: translateX(0); opacity: 1; }
}

@keyframes slide-out-left {
  from { transform: translateX(0); opacity: 1; }
  to { transform: translateX(-100%); opacity: 0.5; }
}

/* ============ Settings Overlay (slide from right) ============ */

.settings-panel-overlay {
  position: absolute;
  inset: 0;
  z-index: 501;
  animation: slide-in-right 0.25s cubic-bezier(0.16, 1, 0.3, 1);
}

.settings-panel-closing {
  animation: slide-out-right 0.2s cubic-bezier(0.7, 0, 0.84, 0) forwards;
}

@keyframes slide-in-right {
  from { transform: translateX(100%); opacity: 0.5; }
  to { transform: translateX(0); opacity: 1; }
}

@keyframes slide-out-right {
  from { transform: translateX(0); opacity: 1; }
  to { transform: translateX(100%); opacity: 0.5; }
}

.conv-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 16px 14px 10px;
}

.conv-title {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-secondary);
}

.conv-items {
  overflow-y: auto;
  flex: 1;
  padding: 4px 8px;
}

.conv-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 12px;
  cursor: pointer;
  border-radius: var(--radius-sm);
  transition: background 0.15s ease;
  margin-bottom: 2px;
}

.conv-item:hover {
  background: var(--accent-lighter);
}

.conv-item.active {
  background: var(--accent-light);
  color: var(--accent);
}

.conv-item-main {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.conv-item-title {
  font-size: 13px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-weight: 500;
}

.conv-item-time {
  font-size: 11px;
  color: var(--text-dim);
  opacity: 0.7;
}

.conv-delete {
  background: none;
  border: none;
  color: var(--text-dim);
  cursor: pointer;
  font-size: 14px;
  padding: 2px 6px;
  border-radius: var(--radius-xs);
  opacity: 0;
  transition: all 0.15s ease;
  flex-shrink: 0;
}

.conv-item:hover .conv-delete {
  opacity: 1;
}

.conv-delete:hover {
  color: var(--error);
  background: var(--error-bg);
}

.conv-empty {
  padding: 20px 12px;
  text-align: center;
  color: var(--text-dim);
  font-size: 13px;
}

/* ============ Chat ============ */

.chat {
  display: flex;
  flex-direction: column;
  flex: 1;
  overflow: hidden;
  background: var(--bg);
}

.messages-wrapper {
  flex: 1;
  position: relative;
  overflow: hidden;
}

.messages {
  height: 100%;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  scroll-behavior: smooth;
}

.empty-state {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  color: var(--text-dim);
  text-align: center;
  padding: 48px 28px;
  gap: 14px;
}

.empty-state p:first-child {
  font-size: 16px;
  font-weight: 500;
  color: var(--text-secondary);
}

.empty-hint {
  font-size: 13px;
  color: var(--accent);
  background: var(--accent-lighter);
  padding: 10px 18px;
  border-radius: 20px;
}

/* ============ Messages ============ */

.msg {
  padding: 10px 14px;
  border-radius: var(--radius);
  max-width: 92%;
  word-break: break-word;
  line-height: 1.6;
  font-size: 14px;
}

.msg-user {
  background: var(--accent);
  color: #ffffff;
  align-self: flex-end;
  border-bottom-right-radius: 4px;
}

.msg-assistant {
  background: var(--bg-secondary);
  box-shadow: var(--shadow);
  align-self: flex-start;
  border-bottom-left-radius: 4px;
}

/* Markdown inside assistant messages */
.msg-assistant p {
  margin: 0;
}
.msg-assistant p + p {
  margin-top: 8px;
}

.msg-assistant h1,
.msg-assistant h2,
.msg-assistant h3,
.msg-assistant h4 {
  margin-top: 12px;
  margin-bottom: 4px;
  font-weight: 600;
  letter-spacing: -0.01em;
}
.msg-assistant h1 { font-size: 18px; }
.msg-assistant h2 { font-size: 16px; }
.msg-assistant h3 { font-size: 15px; }
.msg-assistant h4 { font-size: 14px; }
.msg-assistant h1:first-child,
.msg-assistant h2:first-child,
.msg-assistant h3:first-child {
  margin-top: 0;
}

.msg-assistant ul,
.msg-assistant ol {
  margin: 4px 0;
  padding-left: 20px;
}
.msg-assistant li {
  margin: 2px 0;
}
.msg-assistant li > p {
  margin: 0;
}

.msg-assistant blockquote {
  border-left: 3px solid var(--accent);
  margin: 8px 0;
  padding: 4px 12px;
  color: var(--text-secondary);
  background: var(--accent-lighter);
  border-radius: 0 var(--radius-xs) var(--radius-xs) 0;
}
.msg-assistant blockquote p {
  margin: 0;
}

.msg-assistant code {
  font-family: 'SF Mono', 'Fira Code', 'Consolas', monospace;
  font-size: 13px;
  background: var(--bg-tertiary);
  padding: 1px 5px;
  border-radius: 4px;
  color: var(--accent);
}

.msg-assistant pre {
  margin: 8px 0;
  padding: 12px;
  background: var(--bg);
  border-radius: var(--radius-sm);
  overflow-x: auto;
  font-size: 13px;
  line-height: 1.5;
}

.msg-assistant pre code {
  background: none;
  padding: 0;
  font-size: 13px;
  color: var(--text);
  border-radius: 0;
}

.msg-assistant hr {
  border: none;
  border-top: 1px solid var(--border);
  margin: 12px 0;
}

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

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

.msg-assistant img {
  max-width: 100%;
  border-radius: var(--radius-sm);
}

/* Inline error within assistant message */
.msg-error-inline {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 10px;
  margin-bottom: 8px;
  background: var(--error-bg);
  border: 1px solid var(--error);
  border-radius: var(--radius-xs);
  color: var(--error);
  font-size: 12px;
  font-weight: 500;
}

/* Inline typing indicator within assistant message */
.typing-indicator-inline {
  display: inline-flex;
  gap: 4px;
  align-items: center;
  padding: 4px 0;
  animation: pulse 1.5s ease-in-out infinite;
}

.typing-indicator-inline::before,
.typing-indicator-inline::after,
.typing-indicator-inline span {
  content: '';
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--text-dim);
  animation: dot-pulse 1.4s ease-in-out infinite;
}

.typing-indicator-inline::before { animation-delay: 0s; }
.typing-indicator-inline span { animation-delay: 0.2s; }
.typing-indicator-inline::after { animation-delay: 0.4s; }

/* ============ Tool Card (merged tool_use + tool_result) ============ */

.tool-card {
  align-self: flex-start;
  border-radius: var(--radius-sm);
  overflow: hidden;
  font-size: 12px;
  width: fit-content;
  max-width: 100%;
  background: var(--bg-secondary);
  box-shadow: var(--shadow);
  margin-top: 6px;
}

.tool-card + .tool-card {
  margin-top: 6px;
}

.tool-card-expanded {
  width: 100%;
  max-width: 500px;
}

.tool-card-running {
  border-color: var(--accent);
}

.tool-card-error {
  border-color: var(--error);
}

.tool-card-header {
  display: flex;
  align-items: center;
  gap: 6px;
  width: 100%;
  padding: 6px 10px;
  background: none;
  border: none;
  color: var(--text-secondary);
  cursor: pointer;
  font-family: inherit;
  font-size: 12px;
  text-align: left;
  transition: background 0.15s ease;
}

.tool-card-header:hover {
  background: var(--accent-lighter);
}

.tool-card-chevron {
  flex-shrink: 0;
  transition: transform 0.15s ease;
}

.tool-card-chevron-open {
  transform: rotate(90deg);
}

.tool-card-spinner {
  width: 10px;
  height: 10px;
  border: 1.5px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  flex-shrink: 0;
}

.tool-card-name {
  color: var(--text);
  font-weight: 500;
}

.tool-card-running-label {
  margin-left: auto;
  color: var(--text-dim);
  font-size: 11px;
}

.tool-card-body {
  border-top: 1px solid var(--border);
}

.tool-card-section {
  padding: 6px 10px;
}

.tool-card-section + .tool-card-section {
  border-top: 1px solid var(--border-light);
}

.tool-card-section-label {
  font-size: 10px;
  font-weight: 600;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 4px;
}

.tool-card-pre {
  font-family: 'SF Mono', 'Fira Code', monospace;
  font-size: 11px;
  color: var(--text-dim);
  white-space: pre-wrap;
  word-break: break-all;
  line-height: 1.4;
  max-height: 150px;
  overflow-y: auto;
  scrollbar-width: thin;
  scrollbar-color: var(--border) transparent;
}
.tool-card-pre::-webkit-scrollbar { width: 6px; }
.tool-card-pre::-webkit-scrollbar-track { background: transparent; }
.tool-card-pre::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }
.tool-card-pre::-webkit-scrollbar-thumb:hover { background: var(--text-dim); }

/* ============ Typing Indicator ============ */

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

.typing-indicator {
  color: var(--text-dim);
  padding: 8px 14px;
  animation: pulse 1.5s ease-in-out infinite;
  display: flex;
  gap: 4px;
  align-items: center;
}

.typing-indicator::before,
.typing-indicator::after,
.typing-indicator span {
  content: '';
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--text-dim);
  animation: dot-pulse 1.4s ease-in-out infinite;
}

.typing-indicator::before { animation-delay: 0s; }
.typing-indicator span { animation-delay: 0.2s; }
.typing-indicator::after { animation-delay: 0.4s; }

@keyframes pulse {
  0%, 100% { opacity: 0.5; }
  50% { opacity: 1; }
}

@keyframes dot-pulse {
  0%, 80%, 100% { transform: scale(0.6); opacity: 0.4; }
  40% { transform: scale(1); opacity: 1; }
}

/* ============ File Tabs Area ============ */

.file-tabs-area {
  background: var(--bg);
  flex-shrink: 0;
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  align-items: flex-start;
  padding: 6px 16px;
  position: relative;
  z-index: 300;
}

.file-tab-group {
  position: relative;
  flex-shrink: 0;
}

.file-tab-label {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 5px 10px;
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: 14px;
  color: var(--text-dim);
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.15s ease;
  font-family: inherit;
  white-space: nowrap;
}

.file-tab-label:hover {
  color: var(--text);
  border-color: var(--text-dim);
}

.file-tab-label.active {
  color: var(--accent);
  border-color: var(--accent);
  background: var(--accent-lighter);
}

.file-tab-count {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 16px;
  height: 16px;
  padding: 0 4px;
  border-radius: 8px;
  background: var(--accent);
  color: #ffffff;
  font-size: 10px;
  font-weight: 600;
}

.file-tab-chevron {
  transition: transform 0.15s ease;
}

.file-tab-chevron.open {
  transform: rotate(180deg);
}

.file-tab-panel {
  position: absolute;
  bottom: 100%;
  left: 0;
  min-width: 220px;
  max-width: 320px;
  max-height: 200px;
  overflow-y: auto;
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow-md);
  margin-bottom: 2px;
  z-index: 100;
}

.file-tab-empty {
  padding: 12px;
  color: var(--text-dim);
  font-size: 12px;
  text-align: center;
}

.file-tab-item {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 10px;
  cursor: pointer;
  font-size: 12px;
  color: var(--text);
  transition: background 0.1s ease;
}

.file-tab-item:hover {
  background: var(--accent-lighter);
}

.file-tab-name {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  min-width: 0;
}

.file-tab-desc {
  color: var(--text-dim);
  font-size: 11px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 100px;
}

/* ============ File Panel (bottom slide-up) ============ */

@keyframes slide-in-up {
  from { transform: translateY(100%); opacity: 0.5; }
  to { transform: translateY(0); opacity: 1; }
}

@keyframes slide-out-down {
  from { transform: translateY(0); opacity: 1; }
  to { transform: translateY(100%); opacity: 0.5; }
}

.file-modal-overlay {
  position: absolute;
  inset: 0;
  z-index: 200;
  background: rgba(0, 0, 0, 0.5);
  animation: fade-in 0.2s ease-out;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
}

.file-modal-overlay-closing {
  animation: fade-out 0.2s ease-in forwards;
}

.file-modal {
  background: var(--bg);
  border-top: 1px solid var(--border);
  height: 70vh;
  display: flex;
  flex-direction: column;
  animation: slide-in-up 0.25s cubic-bezier(0.16, 1, 0.3, 1);
}

.file-modal-closing {
  animation: slide-out-down 0.2s cubic-bezier(0.7, 0, 0.84, 0) forwards;
}

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

.file-modal-title {
  font-size: 14px;
  font-weight: 600;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  flex: 1;
  min-width: 0;
}

.file-modal-actions {
  display: flex;
  align-items: center;
  gap: 4px;
  flex-shrink: 0;
}

.btn-modal {
  background: none;
  border: none;
  color: var(--text-dim);
  cursor: pointer;
  padding: 4px;
  border-radius: var(--radius-xs);
  display: flex;
  align-items: center;
  justify-content: center;
}

.btn-modal:hover {
  color: var(--accent);
  background: var(--accent-light);
}

.file-modal-close {
  background: none;
  border: none;
  color: var(--text-dim);
  cursor: pointer;
  padding: 4px;
  border-radius: var(--radius-xs);
  display: flex;
  align-items: center;
  justify-content: center;
}

.file-modal-close:hover {
  color: var(--text);
  background: var(--bg-tertiary);
}

.file-modal-editor {
  flex: 1;
  padding: 12px 14px;
  background: var(--bg-secondary);
  color: var(--text);
  border: none;
  font-family: 'SF Mono', 'Fira Code', 'Consolas', monospace;
  font-size: 13px;
  line-height: 1.5;
  resize: none;
  outline: none;
  scrollbar-width: thin;
  scrollbar-color: var(--border) transparent;
}

.file-modal-editor::-webkit-scrollbar {
  width: 6px;
}

.file-modal-editor::-webkit-scrollbar-track {
  background: transparent;
}

.file-modal-editor::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 3px;
}

.file-modal-editor::-webkit-scrollbar-thumb:hover {
  background: var(--text-dim);
}

.file-modal-preview {
  flex: 1;
  padding: 12px 14px;
  background: var(--bg-secondary);
  color: var(--text);
  overflow-y: auto;
  font-size: 13px;
  line-height: 1.6;
  scrollbar-width: thin;
  scrollbar-color: var(--border) transparent;
}
.file-modal-preview::-webkit-scrollbar { width: 6px; }
.file-modal-preview::-webkit-scrollbar-track { background: transparent; }
.file-modal-preview::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }
.file-modal-preview::-webkit-scrollbar-thumb:hover { background: var(--text-dim); }
.file-modal-preview h1, .file-modal-preview h2, .file-modal-preview h3,
.file-modal-preview h4, .file-modal-preview h5, .file-modal-preview h6 {
  margin-top: 16px;
  margin-bottom: 8px;
  font-weight: 600;
  color: var(--text);
}
.file-modal-preview h1 { font-size: 1.4em; }
.file-modal-preview h2 { font-size: 1.25em; }
.file-modal-preview h3 { font-size: 1.1em; }
.file-modal-preview p { margin: 6px 0; }
.file-modal-preview ul, .file-modal-preview ol { padding-left: 20px; margin: 6px 0; }
.file-modal-preview li { margin: 2px 0; }
.file-modal-preview code {
  background: var(--bg-tertiary);
  padding: 2px 5px;
  border-radius: 3px;
  font-family: 'SF Mono', 'Fira Code', 'Consolas', monospace;
  font-size: 0.9em;
}
.file-modal-preview pre {
  background: var(--bg-tertiary);
  padding: 10px 12px;
  border-radius: 6px;
  overflow-x: auto;
  margin: 8px 0;
}
.file-modal-preview pre code {
  background: none;
  padding: 0;
  font-size: 0.9em;
}
.file-modal-preview blockquote {
  border-left: 3px solid var(--border);
  margin: 8px 0;
  padding: 4px 12px;
  color: var(--text-dim);
}
.file-modal-preview a {
  color: var(--accent);
  text-decoration: none;
}
.file-modal-preview a:hover {
  text-decoration: underline;
}
.file-modal-preview table {
  border-collapse: collapse;
  width: 100%;
  margin: 8px 0;
}
.file-modal-preview th, .file-modal-preview td {
  border: 1px solid var(--border);
  padding: 6px 10px;
  text-align: left;
}
.file-modal-preview th {
  background: var(--bg-tertiary);
  font-weight: 600;
}
.file-modal-preview hr {
  border: none;
  border-top: 1px solid var(--border);
  margin: 12px 0;
}
.file-modal-preview img {
  max-width: 100%;
  border-radius: 6px;
}

.btn-modal-toggle {
  color: var(--text-dim);
  transition: color 0.15s ease;
}
.btn-modal-toggle.active {
  color: var(--accent);
}

.file-modal-footer {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  padding: 10px 14px;
  border-top: 1px solid var(--border);
}

.btn-modal-save {
  background: var(--accent);
  color: #ffffff;
  border: none;
  border-radius: var(--radius-xs);
  padding: 6px 16px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  font-family: inherit;
  transition: background 0.15s ease;
}

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

.btn-modal-cancel {
  background: none;
  color: var(--text-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius-xs);
  padding: 6px 16px;
  font-size: 13px;
  cursor: pointer;
  font-family: inherit;
  transition: all 0.15s ease;
}

.btn-modal-cancel:hover {
  border-color: var(--text-dim);
  background: var(--bg-secondary);
}

/* ============ Input Bar ============ */

.input-bar {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  padding: 12px 16px 10px;
  background: var(--bg);
  flex-shrink: 0;
  position: relative;
  z-index: 400;
}

/* Turn stats bar (below input) */
.turn-stats-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 16px 8px;
  font-size: 11px;
  color: var(--text-dim);
  line-height: 1;
  flex-shrink: 0;
  font-variant-numeric: tabular-nums;
}

.turn-stat-elapsed {
  min-width: 5em;
  text-align: right;
}

.turn-stat-arrow-down {
  font-size: inherit;
  margin-right: 2px;
}

.turn-stats-left {
  display: flex;
  align-items: center;
  gap: 6px;
}

.turn-stats-right {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-left: auto;
}

.turn-stats-ad a {
  color: var(--text-secondary);
  text-decoration: none;
}

.turn-stats-ad a:hover {
  text-decoration: underline;
  color: var(--accent);
}

.ad-sponsor {
  color: var(--text-dim);
  opacity: 0.7;
}

.ad-row {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 5px;
  padding: 0 16px 6px;
  font-size: 12px;
  color: var(--text-secondary);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  flex-shrink: 0;
}

.ad-row .ad-label {
  display: inline-block;
  font-size: 10px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--accent);
  background: rgba(59, 130, 246, 0.15);
  padding: 1px 5px;
  border-radius: 3px;
  flex-shrink: 0;
}

.ad-row a {
  color: var(--text-secondary);
  text-decoration: none;
}

.ad-row a:hover {
  text-decoration: underline;
  color: var(--accent);
}

/* Ad celebration — golden pulse + confetti popper */
.ad-gold {
  animation: ad-gold-pulse 1.2s ease-out;
}

@keyframes ad-gold-pulse {
  0% { background: transparent; box-shadow: none; }
  15% { background: rgba(245, 158, 11, 0.12); box-shadow: 0 0 8px rgba(245, 158, 11, 0.3); }
  40% { background: rgba(245, 158, 11, 0.06); box-shadow: 0 0 4px rgba(245, 158, 11, 0.15); }
  100% { background: transparent; box-shadow: none; }
}

.ad-gold .ad-label {
  animation: ad-label-gold 1.2s ease-out;
}

@keyframes ad-label-gold {
  0% { color: var(--accent); background: rgba(59, 130, 246, 0.15); }
  15% { color: #b45309; background: rgba(245, 158, 11, 0.25); }
  100% { color: var(--accent); background: rgba(59, 130, 246, 0.15); }
}

.ad-gold a {
  animation: ad-text-gold 1.2s ease-out;
}

@keyframes ad-text-gold {
  0% { color: var(--text-secondary); }
  15% { color: #b45309; }
  100% { color: var(--text-secondary); }
}

/* Confetti particles */
.ad-confetti {
  position: fixed;
  width: 4px;
  height: 4px;
  border-radius: 50%;
  pointer-events: none;
  z-index: 9999;
  animation: ad-confetti-pop 700ms cubic-bezier(0.2, 0.8, 0.4, 1) forwards;
}

@keyframes ad-confetti-pop {
  0% { transform: translate(0, 0) scale(1); opacity: 1; }
  60% { opacity: 1; }
  100% { transform: translate(var(--tx), var(--ty)) scale(0.3); opacity: 0; }
}

.turn-stat-gap {
  width: 8px;
}

.turn-stat-warning {
  color: #f59e0b;
  animation: pulse-warning 1.5s ease-in-out infinite;
}

@keyframes pulse-warning {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.5; }
}

/* Context file chips */
.context-files {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  padding: 6px 16px 0;
}

.context-chip {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 3px 8px;
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: 12px;
  font-size: 12px;
  color: var(--text);
  max-width: 160px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.chip-remove {
  background: none;
  border: none;
  color: var(--text-dim);
  cursor: pointer;
  padding: 0 2px;
  font-size: 12px;
  line-height: 1;
}

.chip-remove:hover {
  color: var(--error);
}

/* Add button */
.btn-add {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  border-radius: var(--radius);
  border: 1.5px solid var(--border);
  background: var(--bg-secondary);
  color: var(--text-dim);
  cursor: pointer;
  flex-shrink: 0;
  transition: all 0.15s ease;
}

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

/* Add menu dropdown */
.add-menu-wrapper {
  position: relative;
  flex-shrink: 0;
}

.add-menu {
  position: absolute;
  bottom: 100%;
  left: 0;
  margin-bottom: 4px;
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
  padding: 4px;
  z-index: 100;
  min-width: 170px;
}

.add-menu-item {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  padding: 8px 12px;
  border: none;
  background: none;
  color: var(--text);
  font-size: 13px;
  cursor: pointer;
  border-radius: 4px;
  text-align: left;
}

.add-menu-item:hover {
  background: var(--bg-hover, rgba(255, 255, 255, 0.06));
}

.input {
  flex: 1;
  background: var(--bg-secondary);
  border: 1.5px solid var(--border);
  color: var(--text);
  border-radius: var(--radius);
  padding: 10px 14px;
  font-size: 14px;
  font-family: inherit;
  resize: none;
  outline: none;
  max-height: var(--input-max-h);
  min-height: auto;
  height: auto;
  line-height: 1.5;
  transition: border-color 0.15s ease;
  scrollbar-width: none;
  -ms-overflow-style: none;
}

.input::-webkit-scrollbar {
  display: none;
}

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

.input::placeholder {
  color: var(--text-dim);
}

.btn-send, .btn-stop {
  border: none;
  border-radius: var(--radius);
  padding: 0;
  width: 36px;
  height: 36px;
  cursor: pointer;
  font-size: 13px;
  font-weight: 600;
  font-family: inherit;
  transition: all 0.15s ease;
  white-space: nowrap;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}

.btn-send {
  background: var(--accent);
  color: #ffffff;
}

.btn-send:hover {
  background: var(--accent-hover);
  transform: translateY(-1px);
}

.btn-send:disabled {
  opacity: 0.4;
  cursor: not-allowed;
  transform: none;
}

.btn-stop {
  background: var(--error);
  color: #ffffff;
  font-size: 12px;
  padding: 10px 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  animation: btn-stop-breathe 2s ease-in-out infinite;
}

.btn-stop:hover {
  opacity: 0.9;
}

@keyframes btn-stop-breathe {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.5; }
}

/* ============ Settings ============ */

.settings {
  flex: 1;
  overflow-y: auto;
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 16px;
  background: var(--bg);
}

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

.settings-header h2 {
  font-size: 18px;
  font-weight: 600;
  letter-spacing: -0.01em;
}

.settings label {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 13px;
  font-weight: 500;
  color: var(--text-secondary);
}

.settings input,
.settings select,
.settings textarea {
  background: var(--bg-secondary);
  border: 1.5px solid var(--border);
  color: var(--text);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  font-size: 14px;
  font-family: inherit;
  outline: none;
  transition: border-color 0.15s ease;
}

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

.settings select {
  cursor: pointer;
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%2364748b' d='M6 8L1 3h10z'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
  padding-right: 32px;
}

.settings-actions {
  display: flex;
  gap: 8px;
  margin-top: 8px;
  padding-top: 16px;
  border-top: 1px solid var(--border);
  justify-content: flex-end;
}

.btn-save {
  background: var(--accent);
  color: #ffffff;
  border: none;
  border-radius: var(--radius-xs);
  padding: 6px 16px;
  cursor: pointer;
  font-size: 13px;
  font-weight: 600;
  font-family: inherit;
  transition: all 0.15s ease;
}

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

.btn-save:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.btn-cancel {
  background: none;
  color: var(--text-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius-xs);
  padding: 6px 16px;
  cursor: pointer;
  font-size: 13px;
  font-weight: 500;
  font-family: inherit;
  transition: all 0.15s ease;
}

.btn-cancel:hover {
  border-color: var(--text-dim);
  background: var(--bg-secondary);
}

/* ============ Theme Toggle ============ */

.theme-toggle {
  position: relative;
  width: 40px;
  height: 22px;
  background: var(--border);
  border-radius: 11px;
  cursor: pointer;
  border: none;
  padding: 0;
  transition: background 0.2s ease;
}

.theme-toggle::after {
  content: '';
  position: absolute;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: #ffffff;
  top: 3px;
  left: 3px;
  transition: transform 0.2s ease;
  box-shadow: 0 1px 2px rgba(0,0,0,0.15);
}

[data-theme="dark"] .theme-toggle {
  background: var(--accent);
}

[data-theme="dark"] .theme-toggle::after {
  transform: translateX(18px);
}

/* ============ Scrollbar ============ */

.messages::-webkit-scrollbar,
.conv-items::-webkit-scrollbar,
.settings::-webkit-scrollbar {
  width: 6px;
}

.messages::-webkit-scrollbar-track,
.conv-items::-webkit-scrollbar-track,
.settings::-webkit-scrollbar-track {
  background: transparent;
}

.messages::-webkit-scrollbar-thumb,
.conv-items::-webkit-scrollbar-thumb,
.settings::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 3px;
}

.messages::-webkit-scrollbar-thumb:hover,
.conv-items::-webkit-scrollbar-thumb:hover,
.settings::-webkit-scrollbar-thumb:hover {
  background: var(--text-dim);
}

/* ============ Selection ============ */

::selection {
  background: var(--accent-light);
  color: var(--accent);
}

/* User message: white text on blue bg needs different selection colors */
.msg-user::selection {
  background: rgba(255, 255, 255, 0.25);
  color: #ffffff;
}
