/* CSS Reset and Base Styles */
* {
  box-sizing: border-box;
}

html {
  height: 100%;
  height: 100dvh;
  overflow: hidden;
}

body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  font-family:
    "SF Mono", Monaco, "Cascadia Code", "Roboto Mono", Consolas, "Courier New", monospace;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
  letter-spacing: -0.01em;
  color: var(--text-primary);
  background: var(--bg-secondary);
}

/* CSS Variables */
:root {
  --font-mono:
    "SF Mono", Monaco, "Cascadia Code", "Roboto Mono", Consolas, "Courier New", monospace;
  --primary: #2563eb;
  --primary-dark: #1d4ed8;
  --bg-base: #ffffff;
  --bg-secondary: #f9fafb;
  --bg-tertiary: #f3f4f6;
  --border: #e5e7eb;
  --text-primary: #111827;
  --text-secondary: #6b7280;
  --text-tertiary: #9ca3af;
  --success-bg: #f0fdf4;
  --success-border: #bbf7d0;
  --success-text: #166534;
  --error-bg: #fef2f2;
  --error-border: #fecaca;
  --error-text: #991b1b;
  --warning-bg: #fffbeb;
  --warning-border: #fcd34d;
  --warning-text: #92400e;
  --blue-bg: #eff6ff;
  --blue-border: #bfdbfe;
  --blue-text: #1e40af;
  --user-message-text: #2563eb;
  --link-color: #2563eb;
  --green-600: #16a34a;
  --green-700: #15803d;
  --gray-50: #f9fafb;
  --gray-100: #f3f4f6;
  --gray-200: #e5e7eb;
  --gray-300: #d1d5db;
  --gray-400: #9ca3af;
  --gray-500: #6b7280;
  --gray-600: #4b5563;
  --gray-700: #374151;
  --gray-800: #1f2937;
  --gray-900: #111827;
}

.dark {
  --bg-base: #1f2937;
  --bg-secondary: #111827;
  --bg-tertiary: #374151;
  --border: #374151;
  --text-primary: #f9fafb;
  --text-secondary: #9ca3af;
  --text-tertiary: #6b7280;
  --success-bg: rgba(34, 197, 94, 0.1);
  --success-border: rgba(34, 197, 94, 0.3);
  --success-text: #86efac;
  --error-bg: rgba(239, 68, 68, 0.1);
  --error-border: rgba(239, 68, 68, 0.3);
  --error-text: #fca5a5;
  --warning-bg: rgba(251, 191, 36, 0.15);
  --warning-border: #fbbf24;
  --warning-text: #fcd34d;
  --blue-bg: rgba(59, 130, 246, 0.1);
  --blue-border: rgba(59, 130, 246, 0.3);
  --blue-text: #93c5fd;
  --user-message-text: #60a5fa;
  --link-color: #60a5fa;
}

/* Layout */
.app-container {
  display: flex;
  height: 100vh; /* Fallback for older browsers */
  height: 100dvh; /* Dynamic viewport height - adjusts when mobile browser chrome appears/hides */
  background: var(--bg-secondary);
  position: relative;
  overflow: hidden;
}

.main-content {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.screen-height {
  height: 100vh; /* Fallback for older browsers */
  height: 100dvh;
}

.full-height {
  height: 100%;
}

/* Flexbox utilities */
.flex {
  display: flex;
}

.flex-col {
  flex-direction: column;
}

.flex-1 {
  flex: 1;
}

.items-center {
  align-items: center;
}

.justify-center {
  justify-content: center;
}

.justify-between {
  justify-content: space-between;
}

.space-x-2 > * + * {
  margin-left: 0.5rem;
}

.space-x-3 > * + * {
  margin-left: 0.75rem;
}

.space-y-2 > * + * {
  margin-top: 0.5rem;
}

.space-y-3 > * + * {
  margin-top: 0.75rem;
}

.space-y-4 > * + * {
  margin-top: 1rem;
}

/* Text */
.text-center {
  text-align: center;
}

.text-sm {
  font-size: 0.875rem;
  line-height: 1.5;
}

.text-xs {
  font-size: 0.75rem;
  line-height: 1.4;
}

.text-lg {
  font-size: 1.125rem;
  line-height: 1.6;
}

.font-medium {
  font-weight: 500;
}

.font-semibold {
  font-weight: 600;
}

.italic {
  font-style: italic;
}

.truncate {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.break-words {
  word-break: break-word;
}

.break-all {
  word-break: break-all;
}

.whitespace-pre-wrap {
  white-space: pre-wrap;
}

/* Colors */
.text-primary {
  color: var(--text-primary);
}

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

.text-tertiary {
  color: var(--text-tertiary);
}

.text-white {
  color: white;
}

.text-error {
  color: var(--error-text);
}

.text-success {
  color: var(--success-text);
}

.text-blue {
  color: var(--blue-text);
}

.bg-primary {
  background: var(--primary);
}

.bg-base {
  background: var(--bg-base);
}

.bg-secondary {
  background: var(--bg-secondary);
}

/* Buttons */
button {
  font-family: inherit;
  cursor: pointer;
  border: none;
  background: none;
  padding: 0;
  color: inherit;
}

.btn {
  padding: 0.5rem 0.75rem;
  border-radius: 0.25rem;
  transition: background-color 0.2s;
}

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

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

.btn-primary {
  padding: 0.5rem 1rem;
  background: var(--primary);
  color: white;
  border-radius: 0.25rem;
  font-weight: 500;
  transition: background-color 0.2s;
  letter-spacing: -0.01em;
}

.btn-primary:hover:not(:disabled) {
  background: var(--primary-dark);
}

.btn-primary:disabled {
  background: var(--gray-300);
  cursor: not-allowed;
}

.dark .btn-primary:disabled {
  background: var(--gray-600);
}

.btn-secondary {
  padding: 0.5rem 1rem;
  background: var(--bg-secondary);
  color: var(--text-primary);
  border: 1px solid var(--border);
  border-radius: 0.25rem;
  font-weight: 500;
  transition: background-color 0.2s;
  letter-spacing: -0.01em;
}

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

.btn-sm {
  padding: 0.375rem 0.75rem;
  font-size: 0.8125rem;
}

.btn-icon {
  padding: 0.5rem;
  border-radius: 0.375rem;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background-color 0.2s;
}

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

.btn-icon-sm {
  padding: 0.25rem;
  border-radius: 0.25rem;
  display: flex;
  align-items: center;
  justify-content: center;
  transition:
    background-color 0.2s,
    opacity 0.2s;
  opacity: 0.4;
  color: var(--text-secondary);
}

.btn-icon-sm:hover {
  background: var(--gray-200);
  opacity: 1;
}

.dark .btn-icon-sm:hover {
  background: var(--gray-600);
}

.conversation-item:hover .btn-icon-sm {
  opacity: 0.7;
}

.conversation-item.active .btn-icon-sm {
  color: rgba(255, 255, 255, 0.8);
  opacity: 0.7;
}

.conversation-item.active .btn-icon-sm:hover {
  background: rgba(255, 255, 255, 0.2);
  color: white;
  opacity: 1;
}

.btn-icon-sm.btn-danger:hover {
  background: var(--red-600);
  color: white;
  opacity: 1;
}

.btn-new {
  width: 2rem;
  height: 2rem;
  background: var(--text-primary);
  color: var(--bg-base);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background-color 0.2s;
}

.btn-new:hover {
  background: var(--text-secondary);
}

/* Header */
.header {
  flex: 0 0 auto;
  background: var(--bg-base);
  border-bottom: 1px solid var(--border);
  padding: 0.5rem 1rem;
  padding-top: calc(0.5rem + env(safe-area-inset-top, 0px));
  padding-left: max(1rem, env(safe-area-inset-left));
  padding-right: max(1rem, env(safe-area-inset-right));
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
}

.header-left {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  min-width: 0; /* Allow shrinking below content size */
  flex: 1 1 auto;
  overflow: hidden;
}

.header-title {
  font-size: 1rem;
  font-weight: 600;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  letter-spacing: -0.02em;
  min-width: 0; /* Allow shrinking */
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-shrink: 0; /* Never shrink the actions */
}

/* Drawer/Sidebar */
.drawer {
  position: fixed;
  inset: 0 auto 0 0;
  z-index: 50;
  width: 20rem;
  max-width: calc(100vw - 3rem); /* Ensure drawer doesn't fill entire screen on mobile */
  background: var(--bg-base);
  border-right: 1px solid var(--border);
  color: var(--text-primary);
  display: flex;
  flex-direction: column;
  height: 100%;
  height: 100dvh;
  transform: translateX(-100%);
  transition: transform 0.3s ease;
  padding-top: env(safe-area-inset-top);
  padding-left: env(safe-area-inset-left);
  padding-bottom: env(safe-area-inset-bottom);
}

.drawer.open {
  transform: translateX(0);
}

.drawer-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1rem;
}

.drawer-header-actions {
  display: flex;
  align-items: center;
  gap: 0.25rem;
}

.drawer-title {
  font-size: 1.125rem;
  font-weight: 600;
}

.drawer-body {
  flex: 1;
  overflow-y: auto;
  min-height: 0;
}

.drawer-section {
  padding: 1rem;
  border-bottom: 1px solid var(--border);
}

.drawer-footer {
  padding: 1rem;
}

/* Backdrop */
.backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  z-index: 40;
}

/* Group By */
.group-by-wrapper {
  position: relative;
}

.btn-icon.group-by-active {
  color: var(--primary);
}

.group-by-menu {
  position: absolute;
  top: 100%;
  right: 0;
  z-index: 50;
  margin-top: 0.25rem;
  min-width: 8rem;
  padding: 0.25rem;
  border-radius: 0.375rem;
  border: 1px solid var(--border);
  background: var(--bg-secondary);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
}

.group-by-menu-item {
  display: block;
  width: 100%;
  padding: 0.375rem 0.625rem;
  border: none;
  border-radius: 0.25rem;
  background: none;
  color: var(--text-primary);
  font-size: 0.8125rem;
  text-align: left;
  cursor: pointer;
}

.group-by-menu-item:hover {
  background: var(--bg-tertiary);
}

.group-by-menu-item.active {
  font-weight: 600;
  color: var(--primary);
}

/* Conversation Groups */
.conversation-group {
  margin-bottom: 0.25rem;
}

.conversation-group-header {
  display: flex;
  align-items: center;
  gap: 0.375rem;
  width: 100%;
  padding: 0.375rem 0.75rem;
  border: none;
  background: none;
  color: var(--text-secondary);
  font-size: 0.75rem;
  font-weight: 600;
  cursor: pointer;
  text-align: left;
  letter-spacing: 0.02em;
}

.conversation-group-header:hover {
  color: var(--text-primary);
}

.conversation-group-chevron {
  width: 0.75rem;
  height: 0.75rem;
  flex-shrink: 0;
  transition: transform 0.15s ease;
}

.conversation-group-label {
  font-family: var(--font-mono);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  min-width: 0;
}

.conversation-group-count {
  flex-shrink: 0;
  color: var(--text-tertiary);
  font-weight: 400;
}

/* Conversation List */
.conversation-list {
  padding: 0.5rem;
}

.conversation-item {
  width: 100%;
  text-align: left;
  padding: 0.75rem;
  border-radius: 0.5rem;
  margin-bottom: 0.25rem;
  transition: background-color 0.2s;
  display: flex;
  flex-direction: row;
  align-items: center;
  gap: 0.25rem;
}

.conversation-item:hover {
  background: var(--bg-tertiary);
}

.conversation-item.active {
  background: var(--primary);
  color: white;
}

.conversation-item .conversation-title {
  font-weight: 500;
  font-size: 0.875rem;
  word-break: break-all;
}

.conversation-item .conversation-meta {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.75rem;
  color: var(--text-tertiary);
  min-width: 0;
}

.conversation-item .conversation-date {
  flex-shrink: 0;
}

.conversation-item.active .conversation-meta {
  color: rgba(255, 255, 255, 0.8);
}

.conversation-item .conversation-cwd {
  font-family: var(--font-mono);
  font-size: 0.7rem;
  opacity: 0.8;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  text-align: left;
  min-width: 0;
}

/* Messages */
.messages-container {
  flex: 1 1 auto;
  overflow-y: auto;
  overflow-x: hidden;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
  padding: 1rem;
  padding-left: max(1rem, env(safe-area-inset-left));
  padding-right: max(1rem, env(safe-area-inset-right));
}

.messages-list {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.message {
  display: flex;
  flex-direction: column;
}

.message-content {
  padding: 1rem;
  border-radius: 0.5rem;
  overflow-wrap: break-word;
  word-wrap: break-word;
  min-width: 0;
}

.message-user .message-content {
  margin-left: auto;
  max-width: 80%;
  color: var(--user-message-text);
}

.message-agent .message-content,
.message-tool .message-content {
  margin-right: auto;
  max-width: 100%;
  color: var(--text-primary);
}

.thinking-indicator {
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
  color: var(--text-secondary);
  font-size: 0.875rem;
  margin: 0.25rem 0 0.75rem 0;
  padding-left: 0.5rem;
}

.thinking-dots {
  display: inline-flex;
  gap: 0.2rem;
  font-size: 1.25rem;
  letter-spacing: 0.15rem;
  color: var(--blue-text);
}

.thinking-dots span {
  animation: thinking-dot 1.2s infinite ease-in-out;
  opacity: 0.25;
}

.thinking-dots span:nth-child(2) {
  animation-delay: 0.2s;
}

.thinking-dots span:nth-child(3) {
  animation-delay: 0.4s;
}

@keyframes thinking-dot {
  0%,
  80%,
  100% {
    opacity: 0.25;
    transform: translateY(0);
  }
  40% {
    opacity: 1;
    transform: translateY(-0.2rem);
  }
}

.message-error .message-content {
  margin-right: auto;
  max-width: 100%;
  background: var(--error-bg);
  border: 2px solid var(--error-border);
  color: var(--error-text);
}

/* Tool Display */
.tool-use {
  background: var(--blue-bg);
  border: 1px solid var(--blue-border);
  border-radius: 0.5rem;
  padding: 0.75rem;
  margin: 0.5rem 0;
}

.tool-header {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-bottom: 0.5rem;
}

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

.tool-input {
  font-size: 0.875rem;
  font-family: monospace;
  background: var(--gray-100);
  border-radius: 0.25rem;
  padding: 0.5rem;
  overflow-wrap: break-word;
  word-break: break-all;
  white-space: pre-wrap;
}

.dark .tool-input {
  background: var(--gray-800);
}

.tool-result-details {
  border: 1px solid var(--border);
  border-radius: 0.5rem;
  margin: 0.5rem 0;
}

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

.tool-result-summary {
  cursor: pointer;
  padding: 0.5rem 0.75rem;
  border-radius: 0.5rem;
  transition: background-color 0.2s;
  background: var(--bg-tertiary);
}

.tool-result-summary:hover {
  background: var(--bg-secondary);
}

.tool-result-details.error .tool-result-summary {
  background: var(--error-bg);
  color: var(--error-text);
}

.tool-result-content {
  padding: 0.75rem;
  padding-top: 0;
}

.tool-result-section {
  background: var(--blue-bg);
  border: 1px solid var(--blue-border);
  border-radius: 0.25rem;
  padding: 0.5rem;
  margin-top: 0.75rem;
}

.tool-result-section.output {
  background: var(--success-bg);
  border-color: var(--success-border);
}

.tool-result-section.error.output {
  background: var(--error-bg);
  border-color: var(--error-border);
}

.tool-result-label {
  font-size: 0.75rem;
  font-weight: 500;
  margin-bottom: 0.25rem;
  color: var(--blue-text);
}

.tool-result-section.output .tool-result-label {
  color: var(--success-text);
}

.tool-result-section.error.output .tool-result-label {
  color: var(--error-text);
}

.tool-result-data {
  font-size: 0.875rem;
  font-family: monospace;
  overflow-wrap: break-word;
  word-break: break-all;
  white-space: pre-wrap;
}

.tool-result-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.tool-result-status {
  font-size: 0.75rem;
}

.tool-result-status.success {
  color: var(--success-text);
}

.tool-result-status.error {
  color: var(--error-text);
}

.tool-result-time {
  font-size: 0.75rem;
  color: var(--text-tertiary);
}

/* Tool running state */
.tool-running {
  background: var(--blue-bg);
  border: 1px solid var(--blue-border);
  border-radius: 0.5rem;
  padding: 0.75rem;
  margin: 0.5rem 0;
}

.tool-running-header {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-bottom: 0.5rem;
}

.tool-status-running {
  font-size: 0.875rem;
  color: var(--text-secondary);
  font-style: italic;
  animation: pulse 2s cubic-bezier(0.4, 0, 0.6, 1) infinite;
}

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

/* Tool Component (shared styles for all tools) */
.tool {
  background: var(--gray-100);
  border-radius: 0.5rem;
  margin: 0.5rem 0;
  width: 100%;
}

.dark .tool {
  background: var(--gray-800);
}

.tool-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.75rem 1rem;
  cursor: pointer;
  user-select: none;
}

.tool-header:hover {
  background: rgba(0, 0, 0, 0.02);
  border-radius: 0.5rem;
}

.dark .tool-header:hover {
  background: rgba(255, 255, 255, 0.02);
}

.tool-summary {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex: 1;
  min-width: 0;
}

.tool-emoji {
  font-size: 1rem;
  flex-shrink: 0;
}

.tool-emoji.running {
}

.tool-command {
  font-family: var(--font-mono);
  font-size: 0.875rem;
  color: var(--text-primary);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.tool-running {
  font-size: 0.75rem;
  color: var(--text-secondary);
  font-style: italic;
  flex-shrink: 0;
  animation: pulse 2s cubic-bezier(0.4, 0, 0.6, 1) infinite;
}

.tool-success {
  color: var(--success-text);
  font-size: 0.875rem;
  flex-shrink: 0;
}

.tool-error {
  color: var(--error-text);
  font-size: 0.875rem;
  flex-shrink: 0;
}

.tool-toggle {
  background: none;
  border: none;
  cursor: pointer;
  padding: 0.25rem;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-secondary);
  flex-shrink: 0;
}

.tool-toggle:hover {
  color: var(--text-primary);
}

.tool-details {
  padding: 0 1rem 0.75rem 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.tool-section {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.tool-label {
  font-size: 0.75rem;
  font-weight: 500;
  color: var(--text-secondary);
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.tool-time {
  font-size: 0.75rem;
  color: var(--text-tertiary);
  font-weight: normal;
}

.tool-code {
  font-family: var(--font-mono);
  font-size: 0.875rem;
  background: var(--bg-base);
  border: 1px solid var(--border);
  border-radius: 0.25rem;
  padding: 0.75rem;
  margin: 0;
  overflow-x: auto;
  white-space: pre-wrap;
  word-break: break-word;
  color: var(--text-primary);
}

.tool-code.error {
  background: var(--error-bg);
  border-color: var(--error-border);
  color: var(--error-text);
}

/* Bash Tool Component - uses shared tool styles */
.bash-tool {
  /* Alias for backwards compatibility */
  background: var(--gray-100);
  border-radius: 0.5rem;
  margin: 0.5rem 0;
  width: 100%;
}

.dark .bash-tool {
  background: var(--gray-800);
}

.bash-tool-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.75rem 1rem;
  cursor: pointer;
  user-select: none;
}

.bash-tool-header:hover {
  background: rgba(0, 0, 0, 0.02);
  border-radius: 0.5rem;
}

.dark .bash-tool-header:hover {
  background: rgba(255, 255, 255, 0.02);
}

.bash-tool-summary {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex: 1;
  min-width: 0;
}

.bash-tool-emoji {
  font-size: 1rem;
  flex-shrink: 0;
}

.bash-tool-emoji.running {
}

.bash-tool-command {
  font-family: var(--font-mono);
  font-size: 0.875rem;
  color: var(--text-primary);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  flex-shrink: 1;
  min-width: 0;
}

.bash-tool-cwd {
  font-family: var(--font-mono);
  font-size: 0.75rem;
  color: var(--text-tertiary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  flex-shrink: 0;
  max-width: 30%;
}

.bash-tool-running {
  font-size: 0.75rem;
  color: var(--text-secondary);
  font-style: italic;
  flex-shrink: 0;
  animation: pulse 2s cubic-bezier(0.4, 0, 0.6, 1) infinite;
}

.bash-tool-success {
  color: var(--success-text);
  font-size: 0.875rem;
  flex-shrink: 0;
}

.bash-tool-error {
  color: var(--error-text);
  font-size: 0.875rem;
  flex-shrink: 0;
}

.bash-tool-cancelled {
  color: var(--error-text);
  font-size: 0.875rem;
  flex-shrink: 0;
}

.bash-tool-toggle {
  background: none;
  border: none;
  cursor: pointer;
  padding: 0.25rem;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-secondary);
  flex-shrink: 0;
}

.bash-tool-toggle:hover {
  color: var(--text-primary);
}

.bash-tool-details {
  padding: 0 1rem 0.75rem 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.bash-tool-section {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.bash-tool-label {
  font-size: 0.75rem;
  font-weight: 500;
  color: var(--text-secondary);
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.bash-tool-time {
  font-size: 0.75rem;
  color: var(--text-tertiary);
  font-weight: normal;
}

.bash-tool-code {
  font-family: var(--font-mono);
  font-size: 0.875rem;
  background: var(--bg-base);
  border: 1px solid var(--border);
  border-radius: 0.25rem;
  padding: 0.75rem;
  margin: 0;
  overflow-x: auto;
  white-space: pre-wrap;
  word-break: break-word;
  color: var(--text-primary);
}

.bash-tool-code.error {
  background: var(--error-bg);
  border-color: var(--error-border);
  color: var(--error-text);
}

/* Patch Tool */
.patch-tool {
  background: var(--gray-100);
  border-radius: 0.5rem;
  margin: 0.5rem 0;
  width: 100%;
  /* Performance: isolate layout/paint for each patch tool */
  contain: layout style;
}

.dark .patch-tool {
  background: var(--gray-800);
}

.patch-tool-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.75rem 1rem;
  cursor: pointer;
  user-select: none;
}

.patch-tool-header:hover {
  background: rgba(0, 0, 0, 0.02);
  border-radius: 0.5rem;
}

.dark .patch-tool-header:hover {
  background: rgba(255, 255, 255, 0.02);
}

.patch-tool-summary {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex: 1;
  min-width: 0;
}

.patch-tool-emoji {
  font-size: 1rem;
  flex-shrink: 0;
}

.patch-tool-emoji.running {
}

.patch-tool-filename {
  font-family: var(--font-mono);
  font-size: 0.875rem;
  color: var(--text-primary);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-weight: 500;
}

.patch-tool-running {
  font-size: 0.75rem;
  color: var(--text-secondary);
  font-style: italic;
  flex-shrink: 0;
  animation: pulse 2s cubic-bezier(0.4, 0, 0.6, 1) infinite;
}

.patch-tool-success {
  color: var(--success-text);
  font-size: 0.875rem;
  flex-shrink: 0;
}

.patch-tool-error {
  color: var(--text-secondary);
  font-size: 0.875rem;
  flex-shrink: 0;
}

.patch-tool-header-controls {
  display: flex;
  align-items: center;
  gap: 0.25rem;
  flex-shrink: 0;
}

.patch-tool-toggle {
  background: none;
  border: none;
  cursor: pointer;
  padding: 0.25rem;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-secondary);
  flex-shrink: 0;
}

.patch-tool-toggle:hover {
  color: var(--text-primary);
}

.patch-tool-diff-mode-toggle {
  background: none;
  border: 1px solid var(--border);
  border-radius: 0.25rem;
  cursor: pointer;
  padding: 0.25rem;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-secondary);
  flex-shrink: 0;
  transition: all 0.15s ease;
}

.patch-tool-diff-mode-toggle:hover {
  color: var(--text-primary);
  background: var(--bg-secondary);
  border-color: var(--text-tertiary);
}

.patch-tool-details {
  padding: 0 1rem 0.75rem 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.patch-tool-section {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.patch-tool-label {
  font-size: 0.75rem;
  font-weight: 500;
  color: var(--text-secondary);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.patch-tool-time {
  font-size: 0.75rem;
  color: var(--text-tertiary);
  font-weight: normal;
}

.patch-tool-error-message {
  font-family: var(--font-mono);
  font-size: 0.875rem;
  background: var(--bg-tertiary);
  border: 1px solid var(--border);
  border-radius: 0.25rem;
  padding: 0.75rem;
  margin: 0;
  overflow-x: auto;
  white-space: pre-wrap;
  word-break: break-word;
  color: var(--text-secondary);
}

/* Patch Tool Simple Diff View */
.patch-tool-diff {
  font-family: var(--font-mono);
  font-size: 0.875rem;
  background: var(--bg-base);
  border: 1px solid var(--border);
  border-radius: 0.25rem;
  padding: 0.75rem;
  margin: 0;
  overflow-x: auto;
  line-height: 1.4;
}

.patch-diff-line {
  white-space: pre;
  display: block;
}

.patch-diff-addition {
  background: rgba(34, 197, 94, 0.1);
  color: #16a34a;
}

.dark .patch-diff-addition {
  background: rgba(34, 197, 94, 0.15);
  color: #86efac;
}

.patch-diff-deletion {
  background: rgba(239, 68, 68, 0.1);
  color: #dc2626;
}

.dark .patch-diff-deletion {
  background: rgba(239, 68, 68, 0.15);
  color: #fca5a5;
}

.patch-diff-hunk {
  color: var(--text-secondary);
  background: var(--bg-tertiary);
  font-weight: 500;
}

.patch-diff-header {
  color: var(--text-tertiary);
  font-style: italic;
}

/* Patch Tool Diffs Container */
.patch-tool-diffs-container {
  border-radius: 0.25rem;
  overflow: hidden;
  font-size: 0.8125rem;
  /* Performance: allow browser to skip rendering off-screen diffs */
  content-visibility: auto;
  contain-intrinsic-size: auto 200px;
}

/* Target the diffs-container custom element from @pierre/diffs */
.patch-tool-diffs-container diffs-container {
  display: block;
  contain: content;
}

/* Screenshot Tool */
.screenshot-tool {
  background: var(--gray-100);
  border-radius: 0.5rem;
  margin: 0.5rem 0;
  width: 100%;
}

.dark .screenshot-tool {
  background: var(--gray-800);
}

.screenshot-tool-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.75rem 1rem;
  cursor: pointer;
  user-select: none;
}

.screenshot-tool-header:hover {
  background: rgba(0, 0, 0, 0.02);
  border-radius: 0.5rem;
}

.dark .screenshot-tool-header:hover {
  background: rgba(255, 255, 255, 0.02);
}

.screenshot-tool-summary {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex: 1;
  min-width: 0;
}

.screenshot-tool-emoji {
  font-size: 1rem;
  flex-shrink: 0;
}

.screenshot-tool-emoji.running {
}

.screenshot-tool-filename {
  font-family: var(--font-mono);
  font-size: 0.875rem;
  color: var(--text-primary);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-weight: 500;
}

.screenshot-tool-running {
  font-size: 0.75rem;
  color: var(--text-secondary);
  font-style: italic;
  flex-shrink: 0;
  animation: pulse 2s cubic-bezier(0.4, 0, 0.6, 1) infinite;
}

.screenshot-tool-success {
  color: var(--success-text);
  font-size: 0.875rem;
  flex-shrink: 0;
}

.screenshot-tool-error {
  color: var(--error-text);
  font-size: 0.875rem;
  flex-shrink: 0;
}

.screenshot-tool-toggle {
  background: none;
  border: none;
  cursor: pointer;
  padding: 0.25rem;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-secondary);
  flex-shrink: 0;
}

.screenshot-tool-toggle:hover {
  color: var(--text-primary);
}

.screenshot-tool-details {
  padding: 0 1rem 0.75rem 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.screenshot-tool-section {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.screenshot-tool-label {
  font-size: 0.75rem;
  font-weight: 500;
  color: var(--text-secondary);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.screenshot-tool-time {
  font-size: 0.75rem;
  color: var(--text-tertiary);
  font-weight: normal;
}

.screenshot-tool-image-container {
  border: 1px solid var(--border);
  border-radius: 0.25rem;
  overflow: hidden;
  background: var(--bg-base);
  width: fit-content;
  max-width: 100%;
}

.screenshot-tool-image-container a {
  display: block;
}

.screenshot-tool-image-container img {
  display: block;
  border-radius: 0.25rem;
}

.screenshot-tool-error-message {
  font-family: var(--font-mono);
  font-size: 0.875rem;
  background: var(--error-bg);
  border: 1px solid var(--error-border);
  border-radius: 0.25rem;
  padding: 0.75rem;
  margin: 0;
  overflow-x: auto;
  white-space: pre-wrap;
  word-break: break-word;
  color: var(--error-text);
}

/* Output Iframe Tool */
.output-iframe-tool {
  background: var(--gray-100);
  border-radius: 0.5rem;
  margin: 0.5rem 0;
  width: 100%;
}

.dark .output-iframe-tool {
  background: var(--gray-800);
}

.output-iframe-tool-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.75rem 1rem;
  cursor: pointer;
  user-select: none;
}

.output-iframe-tool-header:hover {
  background: rgba(0, 0, 0, 0.02);
  border-radius: 0.5rem;
}

.dark .output-iframe-tool-header:hover {
  background: rgba(255, 255, 255, 0.02);
}

.output-iframe-tool-summary {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex: 1;
  min-width: 0;
}

.output-iframe-tool-emoji {
  font-size: 1rem;
  flex-shrink: 0;
}

.output-iframe-tool-emoji.running {
}

.output-iframe-tool-title {
  font-family: var(--font-mono);
  font-size: 0.875rem;
  color: var(--text-primary);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-weight: 500;
}

.output-iframe-tool-success {
  color: var(--success-text);
  font-weight: 600;
  margin-left: 0.5rem;
}

.output-iframe-tool-error {
  color: var(--error-text);
  font-weight: 600;
  margin-left: 0.5rem;
}

.output-iframe-tool-actions {
  display: flex;
  align-items: center;
  gap: 0.25rem;
  flex-shrink: 0;
}

.output-iframe-tool-open-btn,
.output-iframe-tool-download-btn {
  background: none;
  border: none;
  padding: 0.25rem;
  cursor: pointer;
  color: var(--text-secondary);
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 4px;
}

.output-iframe-tool-open-btn:hover,
.output-iframe-tool-download-btn:hover {
  color: var(--text-primary);
  background: var(--gray-200);
}

.dark .output-iframe-tool-open-btn:hover,
.dark .output-iframe-tool-download-btn:hover {
  background: var(--gray-700);
}

.output-iframe-tool-toggle {
  background: none;
  border: none;
  padding: 0.25rem;
  cursor: pointer;
  color: var(--text-secondary);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.output-iframe-tool-toggle:hover {
  color: var(--text-primary);
}

.output-iframe-tool-details {
  padding: 0 1rem 1rem 1rem;
}

.output-iframe-tool-section {
  margin-top: 0.5rem;
}

.output-iframe-tool-label {
  font-size: 0.75rem;
  font-weight: 500;
  color: var(--text-secondary);
  margin-bottom: 0.5rem;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.output-iframe-tool-time {
  font-family: var(--font-mono);
  font-size: 0.75rem;
  color: var(--text-tertiary);
}

.output-iframe-container {
  width: 100%;
  overflow: hidden;
  border-radius: 0.25rem;
}

.output-iframe-container iframe {
  display: block;
}

.output-iframe-tool-error-message {
  font-family: var(--font-mono);
  font-size: 0.875rem;
  background: var(--error-bg);
  border: 1px solid var(--error-border);
  border-radius: 0.25rem;
  padding: 0.75rem;
  margin: 0;
  overflow-x: auto;
  white-space: pre-wrap;
  word-break: break-word;
  color: var(--error-text);
}

/* Message Input */
.message-input-container {
  flex: 0 0 auto;
  background: var(--bg-base);
  border-top: 1px solid var(--border);
  padding: 1rem;
  padding-bottom: calc(1rem + env(safe-area-inset-bottom, 0px));
  padding-left: max(1rem, env(safe-area-inset-left));
  padding-right: max(1rem, env(safe-area-inset-right));
}

.message-input-form {
  display: flex;
  align-items: flex-end;
  gap: 0.5rem;
  max-width: 800px;
  margin: 0 auto;
}

.message-textarea {
  width: 100%;
  box-sizing: border-box;
  min-height: 46px;
  max-height: 200px;
  padding: 0.625rem 1rem;
  border: 1.5px solid var(--border);
  border-radius: 4px;
  resize: none;
  background: var(--bg-base);
  color: var(--text-primary);
  font-family: inherit;
  font-size: 16px; /* Must be 16px+ to prevent iOS zoom on focus */
  line-height: 1.5;
  transition:
    border-color 0.2s,
    box-shadow 0.2s;
}

.message-textarea:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.08);
}

.message-textarea:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.message-send-btn svg {
  transform: rotate(-90deg);
}

.message-textarea::placeholder {
  color: var(--text-tertiary);
}

.message-send-btn {
  flex-shrink: 0;
  width: 36px;
  height: 36px;
  margin-bottom: 0.25rem;
  padding: 0;
  background: var(--primary);
  color: white;
  border: none;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  transition:
    background-color 0.2s,
    transform 0.1s;
  cursor: pointer;
}

.message-send-btn:hover:not(:disabled) {
  background: var(--primary-dark);
  transform: scale(1.05);
}

.message-send-btn:active:not(:disabled) {
  transform: scale(0.95);
}

.message-send-btn:disabled {
  background: var(--gray-300);
  cursor: not-allowed;
  opacity: 0.6;
}

.dark .message-send-btn:disabled {
  background: var(--gray-600);
}

/* Action row under textarea */
.message-controls-row {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 0.25rem;
}

/* Attach file button */
.message-attach-btn {
  flex-shrink: 0;
  width: 36px;
  height: 36px;
  margin-bottom: 0.25rem;
  padding: 0;
  background: transparent;
  color: var(--text-secondary);
  border: none;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  transition:
    background-color 0.2s,
    color 0.2s,
    transform 0.1s;
  cursor: pointer;
}

.message-attach-btn:hover:not(:disabled) {
  background: var(--gray-100);
  color: var(--text-primary);
}

.dark .message-attach-btn:hover:not(:disabled) {
  background: var(--gray-700);
}

.message-attach-btn:active:not(:disabled) {
  transform: scale(0.95);
}

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

/* Voice input button */
.message-voice-btn {
  flex-shrink: 0;
  width: 36px;
  height: 36px;
  margin-bottom: 0.25rem;
  padding: 0;
  background: transparent;
  color: var(--text-secondary);
  border: none;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  transition:
    background-color 0.2s,
    color 0.2s,
    transform 0.1s;
  cursor: pointer;
}

.message-voice-btn:hover:not(:disabled):not(.listening) {
  background: var(--gray-100);
  color: var(--text-primary);
}

.dark .message-voice-btn:hover:not(:disabled):not(.listening) {
  background: var(--gray-700);
}

.message-voice-btn:active:not(:disabled):not(.listening) {
  transform: scale(0.95);
}

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

.message-voice-btn.listening,
.message-voice-btn.listening:hover {
  background: #dc2626;
  color: white;
  animation: pulse-voice 1.5s ease-in-out infinite;
}

.dark .message-voice-btn.listening,
.dark .message-voice-btn.listening:hover {
  background: #ef4444;
  color: white;
}

@keyframes pulse-voice {
  0%,
  100% {
    transform: scale(1);
  }
  50% {
    transform: scale(1.1);
  }
}

/* Drag and drop styles */
.message-input-container {
  position: relative;
}

.message-input-container.drag-over {
  border-color: var(--primary);
}

.message-input-container.shell-mode .message-input-form {
  border-color: var(--warning-border);
  background: var(--warning-bg);
}

.message-input-container.shell-mode .message-textarea {
  font-family: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
  background: transparent;
  padding-left: 36px;
  width: 100%;
}

.textarea-wrapper {
  position: relative;
  flex: 1;
  min-width: 0;
}

.message-input-container.shell-mode .message-textarea::placeholder {
  font-family: inherit;
}

.shell-mode-indicator {
  position: absolute;
  left: 12px;
  top: 14px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--warning-text);
  pointer-events: none;
  z-index: 1;
}

.drag-overlay {
  position: absolute;
  inset: 0;
  background: rgba(37, 99, 235, 0.1);
  border: 2px dashed var(--primary);
  border-radius: 4px;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 10;
  pointer-events: none;
}

.drag-overlay-content {
  background: var(--primary);
  color: white;
  padding: 0.5rem 1rem;
  border-radius: 4px;
  font-size: 0.875rem;
  font-weight: 500;
}

/* Modal */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  z-index: 50;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
}

.modal {
  background: var(--bg-base);
  border-radius: 0.5rem;
  box-shadow: 0 10px 25px rgba(0, 0, 0, 0.1);
  max-width: 28rem;
  width: 100%;
  max-height: 80vh;
  overflow: hidden;
}

.modal.modal-wide {
  max-width: 40rem;
}

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

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

.modal-title-right {
  margin-left: auto;
  margin-right: 1rem;
}

.modal-body {
  padding: 1rem;
  overflow-y: auto;
  max-height: calc(80vh - 60px);
}

/* Form Elements */
label {
  display: block;
  font-size: 0.875rem;
  font-weight: 500;
  margin-bottom: 0.5rem;
}

select {
  width: 100%;
  background: var(--bg-tertiary);
  border: 1px solid var(--border);
  border-radius: 0.375rem;
  padding: 0.5rem 0.75rem;
  font-family: inherit;
  font-size: 1rem;
  color: var(--text-primary);
}

select:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 2px rgba(37, 99, 235, 0.1);
}

select:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

/* Loading Spinner */
.spinner {
  width: 2rem;
  height: 2rem;
  border: 2px solid transparent;
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

.spinner-small {
  width: 1rem;
  height: 1rem;
  border-width: 2px;
  border-top-color: currentColor;
}

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

/* Loading/Error States */
.loading-container,
.error-container {
  height: 100vh; /* Fallback for older browsers */
  height: 100dvh;
  display: flex;
  align-items: center;
  justify-content: center;
}

.loading-content,
.error-content {
  text-align: center;
}

/* Unified Status Bar */
.status-bar {
  flex: 0 0 auto;
  background: var(--bg-base);
  border-top: 1px solid var(--border);
  padding: 0.5rem 1rem;
  padding-left: max(1rem, env(safe-area-inset-left));
  padding-right: max(1rem, env(safe-area-inset-right));
  min-height: 2.5rem;
  display: flex;
  align-items: center;
}

.status-bar-content {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  gap: 0.75rem;
}

.status-message {
  color: var(--text-secondary);
  font-size: 0.875rem;
  flex: 1;
  min-width: 0;
}

.status-message.status-ready {
  color: var(--text-tertiary);
}

.status-message.status-warning {
  color: var(--blue-text);
  font-weight: 500;
}

.status-message.status-error {
  color: var(--error-text);
  font-weight: 500;
}

.status-message.status-reconnecting {
  color: var(--blue-text);
  font-weight: 500;
}

.reconnecting-dots {
  display: inline-block;
  animation: reconnecting-pulse 1.5s ease-in-out infinite;
}

@keyframes reconnecting-pulse {
  0%,
  100% {
    opacity: 0.3;
  }
  50% {
    opacity: 1;
  }
}

.animated-working {
  display: inline;
}

.animated-working .bold-letter {
  font-weight: 700;
}

.status-button {
  padding: 0.375rem 0.875rem;
  border-radius: 0.375rem;
  font-size: 0.875rem;
  font-weight: 500;
  transition: all 0.2s;
  display: flex;
  align-items: center;
  gap: 0.375rem;
  white-space: nowrap;
  border: none;
  cursor: pointer;
}

.status-button svg {
  width: 0.875rem;
  height: 0.875rem;
}

.status-button-primary {
  background: var(--primary);
  color: white;
}

.status-button-primary:hover {
  background: var(--primary-dark);
}

.status-button-cancel {
  background: var(--error-bg);
  color: var(--error-text);
  border: 1px solid var(--error-border);
}

.status-button-cancel:hover:not(:disabled) {
  background: var(--error-text);
  color: white;
}

.status-button-cancel:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

.status-button-text {
  background: transparent;
  color: var(--text-secondary);
  padding: 0.25rem;
}

.status-button-text:hover {
  background: var(--bg-tertiary);
  color: var(--text-primary);
}

/* Legacy disconnect/error banner classes (kept for compatibility but unused) */
.disconnect-banner {
  background: var(--gray-100);
  border-top: 1px solid var(--border);
  padding: 0.5rem 1rem;
}

.dark .disconnect-banner {
  background: var(--gray-800);
}

.disconnect-banner-content {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.75rem;
}

.disconnect-message {
  color: var(--text-secondary);
  font-size: 0.875rem;
  margin: 0;
}

.btn-reconnect {
  padding: 0.25rem 0.75rem;
  background: var(--primary);
  color: white;
  border-radius: 0.375rem;
  font-size: 0.875rem;
  font-weight: 500;
  transition: background-color 0.2s;
}

.btn-reconnect:hover {
  background: var(--primary-dark);
}

.error-banner {
  background: var(--error-bg);
  border-top: 1px solid var(--error-border);
  padding: 0.75rem 1rem;
}

.error-banner-content {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.error-message {
  color: var(--error-text);
  font-size: 0.875rem;
}

/* Empty State */
.empty-state {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 100%;
  color: var(--text-secondary);
}

.empty-state-content {
  text-align: center;
}

/* Scrollbar */
.scrollable {
  scrollbar-width: thin;
  scrollbar-color: rgba(156, 163, 175, 0.5) transparent;
}

.scrollable::-webkit-scrollbar {
  width: 6px;
}

.scrollable::-webkit-scrollbar-track {
  background: transparent;
}

.scrollable::-webkit-scrollbar-thumb {
  background-color: rgba(156, 163, 175, 0.5);
  border-radius: 3px;
}

.scrollable::-webkit-scrollbar-thumb:hover {
  background-color: rgba(156, 163, 175, 0.8);
}

/* SVG Icons */
svg {
  width: 1.25rem;
  height: 1.25rem;
  display: block;
}

.icon-sm svg {
  width: 1rem;
  height: 1rem;
}

/* Utility Classes */
.relative {
  position: relative;
}

.overflow-auto {
  overflow: auto;
}

.overflow-hidden {
  overflow: hidden;
}

.rounded {
  border-radius: 0.25rem;
}

.rounded-lg {
  border-radius: 0.5rem;
}

.border {
  border: 1px solid var(--border);
}

.min-h-0 {
  min-height: 0;
}

/* Overflow Menu */
.overflow-menu {
  position: absolute;
  top: calc(100% + 0.5rem);
  right: 0;
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: 0.5rem;
  box-shadow:
    0 4px 6px -1px rgba(0, 0, 0, 0.1),
    0 2px 4px -1px rgba(0, 0, 0, 0.06);
  min-width: 10rem;
  z-index: 50;
}

.overflow-menu-item {
  display: flex;
  align-items: center;
  width: 100%;
  padding: 0.75rem 1rem;
  text-align: left;
  background: transparent;
  border: none;
  color: var(--text-primary);
  font-size: 0.875rem;
  cursor: pointer;
  transition: background-color 0.2s;
}

.overflow-menu-item:hover {
  background: var(--bg-hover);
}

.overflow-menu-item:first-child {
  border-top-left-radius: 0.5rem;
  border-top-right-radius: 0.5rem;
}

.overflow-menu-item:last-child {
  border-bottom-left-radius: 0.5rem;
  border-bottom-right-radius: 0.5rem;
}

.overflow-menu-divider {
  height: 1px;
  background: var(--border);
  margin: 0.5rem 0;
}

.theme-toggle-row {
  display: flex;
  gap: 0.25rem;
  padding: 0.5rem;
}

.theme-toggle-btn {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0.5rem;
  background: transparent;
  border: 1px solid var(--border);
  border-radius: 0.375rem;
  color: var(--text-secondary);
  cursor: pointer;
  transition: all 0.15s;
}

.theme-toggle-btn svg {
  width: 1.125rem;
  height: 1.125rem;
}

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

.theme-toggle-btn-selected {
  background: var(--primary);
  border-color: var(--primary);
  color: white;
}

.theme-toggle-btn-selected:hover {
  background: var(--primary-dark);
  border-color: var(--primary-dark);
  color: white;
}

/* Markdown mode toggle */
.md-toggle-row {
  padding: 0.5rem;
}

.md-toggle-label {
  font-size: 0.75rem;
  color: var(--text-secondary);
  margin-bottom: 0.375rem;
  font-weight: 500;
}

.md-toggle-buttons {
  display: flex;
  background: var(--bg-tertiary);
  border-radius: 0.375rem;
  padding: 2px;
  gap: 2px;
}

.md-toggle-btn {
  flex: 1;
  padding: 0.25rem 0.375rem;
  background: transparent;
  border: none;
  border-radius: 0.25rem;
  color: var(--text-secondary);
  cursor: pointer;
  font-size: 0.75rem;
  font-weight: 500;
  transition: all 0.15s;
}

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

.md-toggle-btn-selected {
  background: var(--primary);
  color: white;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.1);
}

.md-toggle-btn-selected:hover {
  background: var(--primary-dark);
  color: white;
}

/* Diff display styling */
.diff-display {
  font-family: var(--font-mono);
  font-size: 0.875rem;
  line-height: 1.5;
  background: var(--bg-base);
  padding: 1rem;
  border-radius: 0.25rem;
  overflow-x: auto;
  white-space: pre;
  color: var(--text-primary);
}

/* Responsive adjustments */
@media (min-width: 768px) {
  .drawer {
    position: static;
    transform: translateX(0) !important;
  }

  .drawer.collapsed {
    display: none;
  }

  .hide-on-desktop {
    display: none !important;
  }

  .show-on-desktop-only {
    display: flex !important;
  }

  .backdrop {
    display: none !important;
  }
}

/* Hide desktop-only elements on mobile */
@media (max-width: 767px) {
  .show-on-desktop-only {
    display: none !important;
  }
}

/* Scroll to bottom button */
.scroll-to-bottom-button {
  position: absolute;
  bottom: 1rem;
  left: 50%;
  transform: translateX(-50%);
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: 2rem;
  padding: 0.5rem 1rem;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  cursor: pointer;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
  transition: all 0.2s ease;
  color: var(--text-primary);
  font-size: 0.875rem;
  z-index: 10;
}

.scroll-to-bottom-button:hover {
  background: var(--bg-hover);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
}

.scroll-to-bottom-button:active {
  transform: translateX(-50%) scale(0.95);
}

/* Wrapper for messages area to position scroll-to-bottom button */
.messages-area-wrapper {
  position: relative;
  flex: 1 1 auto;
  min-height: 0; /* Important for flex children to shrink properly */
  overflow: hidden;
}

.messages-container {
  height: 100%;
}

/* Status bar configuration controls for empty conversations */
.status-bar-config {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  width: 100%;
}

.status-bar-new-conversation {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  flex-wrap: wrap;
  gap: 0.5rem;
}

/* On smaller screens, allow the fields to stack vertically */
@media (max-width: 600px) {
  .status-bar-new-conversation {
    flex-direction: column;
    align-items: stretch;
  }

  .status-field {
    width: 100%;
    max-width: none;
  }

  .status-field-label {
    width: 2.5rem;
    text-align: right;
  }
}

.status-bar-controls {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

/* Flexible containers for status fields that adapt to content */
.status-field {
  display: flex;
  align-items: center;
  gap: 0.25rem;
  min-width: 0; /* Allow flex items to shrink below content size */
}

.status-field-label {
  font-size: 0.7rem;
  color: var(--text-secondary);
  flex-shrink: 0;
}

.status-field-model {
  flex: 1 1 auto;
  min-width: 150px;
  max-width: 300px;
}

.status-field-cwd {
  flex: 1 1 auto;
  min-width: 180px;
  max-width: 400px;
}

/* Compact clickable chips for model and cwd */
.status-chip {
  padding: 0.25rem 0.5rem;
  border: 1px solid var(--border);
  border-radius: 0.25rem;
  background: var(--bg-tertiary);
  color: var(--text-primary);
  font-size: 0.75rem;
  font-family: var(--font-mono);
  cursor: pointer;
  transition: all 0.2s;
  white-space: normal; /* Allow text to wrap */
  word-break: break-word; /* Break long words if needed */
  overflow-wrap: break-word;
  width: 100%;
  text-align: left;
  box-sizing: border-box;
  line-height: 1.3; /* Better line height for multi-line text */
  min-height: 1.75rem; /* Minimum height to accommodate wrapped text */
}

.status-chip:hover:not(:disabled) {
  background: var(--bg-secondary);
  border-color: var(--blue-text);
}

.status-chip:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.status-chip-error {
  border-color: var(--red-text, #dc2626);
  background: rgba(220, 38, 38, 0.1);
}

.status-field-error {
  position: relative;
}

.status-input-error {
  border-color: var(--red-text, #dc2626);
}

.status-select {
  padding: 0.25rem 0.5rem;
  border: 1px solid var(--blue-text);
  border-radius: 0.25rem;
  background: var(--bg-base);
  color: var(--text-primary);
  font-size: 0.75rem;
  font-family: var(--font-mono);
  cursor: pointer;
  transition: border-color 0.2s;
  width: 100%;
  box-sizing: border-box;
}

.status-select:hover:not(:disabled) {
  border-color: var(--blue-text);
}

.status-select:focus {
  outline: none;
  border-color: var(--blue-text);
  box-shadow: 0 0 0 2px rgba(59, 130, 246, 0.15);
}

.status-select:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

/* Model Picker Custom Dropdown */
.model-picker {
  position: relative;
  display: inline-block;
  width: 100%;
}

.model-picker-trigger {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  padding: 0.25rem 0.5rem;
  border: 1px solid var(--border);
  border-radius: 0.25rem;
  background: var(--bg-tertiary);
  color: var(--text-primary);
  font-size: 0.75rem;
  font-family: var(--font-mono);
  cursor: pointer;
  transition: all 0.2s;
  width: 100%;
  text-align: left;
  box-sizing: border-box;
  min-height: 1.75rem;
}

.model-picker-trigger:hover:not(:disabled) {
  background: var(--bg-secondary);
  border-color: var(--blue-text);
}

.model-picker-trigger:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.model-picker-value {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.model-picker-chevron {
  flex-shrink: 0;
  transition: transform 0.2s;
  opacity: 0.6;
}

.model-picker-chevron.open {
  transform: rotate(180deg);
}

.model-picker-dropdown {
  position: absolute;
  top: 100%;
  left: 0;
  right: 0;
  margin-top: 2px;
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: 0.375rem;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
  z-index: 1000;
  max-height: 300px;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

.model-picker-dropdown.open-upward {
  top: auto;
  bottom: 100%;
  margin-top: 0;
  margin-bottom: 2px;
}

.model-picker-options {
  overflow-y: auto;
  max-height: 220px;
}

.model-picker-option {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  width: 100%;
  padding: 0.5rem 0.75rem;
  border: none;
  background: transparent;
  color: var(--text-primary);
  font-size: 0.8rem;
  font-family: var(--font-mono);
  cursor: pointer;
  text-align: left;
  transition: background 0.15s;
}

.model-picker-option:hover:not(:disabled) {
  background: var(--bg-tertiary);
}

.model-picker-option.selected {
  background: var(--bg-tertiary);
}

.model-picker-option.disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.model-picker-option-content {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 0.125rem;
  min-width: 0;
}

.model-picker-option-name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.model-picker-option-source {
  font-size: 0.65rem;
  color: var(--text-secondary);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.model-picker-option-badge {
  font-size: 0.65rem;
  color: var(--text-secondary);
  background: var(--bg-base);
  padding: 0.125rem 0.375rem;
  border-radius: 0.25rem;
}

.model-picker-option-check {
  flex-shrink: 0;
  color: var(--green-text);
}

.model-picker-divider {
  height: 1px;
  background: var(--border);
  margin: 0.25rem 0;
}

.model-picker-manage {
  color: var(--blue-text);
}

.model-picker-manage:hover {
  background: var(--bg-tertiary);
}

.model-picker-manage svg {
  flex-shrink: 0;
}

.status-input {
  padding: 0.25rem 0.5rem;
  border: 1px solid var(--blue-text);
  border-radius: 0.25rem;
  background: var(--bg-base);
  color: var(--text-primary);
  font-size: 0.75rem;
  font-family: var(--font-mono);
  transition: border-color 0.2s;
  width: 100%;
  box-sizing: border-box;
}

.status-input::placeholder {
  color: var(--text-secondary);
  opacity: 0.6;
}

.status-input:hover:not(:disabled) {
  border-color: var(--blue-text);
}

.status-input:focus {
  outline: none;
  border-color: var(--blue-text);
  box-shadow: 0 0 0 2px rgba(59, 130, 246, 0.15);
}

.status-input:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

/* Responsive adjustments for status bar controls */
@media (max-width: 768px) {
  .status-bar-config {
    flex-wrap: wrap;
    gap: 0.5rem;
  }

  .status-bar-controls {
    flex-wrap: wrap;
    gap: 0.5rem;
  }

  .status-field-model {
    min-width: 120px;
    max-width: none;
  }

  .status-field-cwd {
    min-width: 140px;
    max-width: none;
  }
}

/* Directory Picker Modal */
.directory-picker-modal {
  max-width: 32rem;
  height: 70vh;
  display: flex;
  flex-direction: column;
}

.directory-picker-body {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
  overflow: hidden;
}

.directory-picker-input-container {
  margin-bottom: 0.75rem;
}

.directory-picker-input {
  width: 100%;
  padding: 0.5rem 0.75rem;
  border: 1px solid var(--border);
  border-radius: 0.25rem;
  background: var(--bg-base);
  color: var(--text-primary);
  font-family: var(--font-mono);
  font-size: 0.875rem;
}

.directory-picker-input:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 2px rgba(37, 99, 235, 0.1);
}

.directory-picker-current {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.75rem;
  color: var(--text-secondary);
  font-family: var(--font-mono);
  margin-bottom: 0.5rem;
  padding: 0.25rem 0;
}

.directory-picker-current-path {
  flex-shrink: 0;
}

.directory-picker-current-git .directory-picker-current-path {
  color: var(--accent-color, #f97316);
}

.directory-picker-current-subject {
  flex: 1;
  min-width: 0;
  color: var(--text-tertiary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  text-align: right;
}

.directory-picker-filter {
  color: var(--primary);
  font-weight: 500;
}

.directory-picker-git-root-btn {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  width: 100%;
  padding: 0.375rem 0.75rem;
  margin-bottom: 0.5rem;
  background: var(--bg-secondary);
  border: 1px solid var(--border-color);
  border-radius: 0.375rem;
  color: var(--accent-color, #f97316);
  font-size: 0.8125rem;
  cursor: pointer;
  text-align: left;
}

.directory-picker-git-root-btn:hover {
  background: var(--bg-tertiary);
  border-color: var(--accent-color, #f97316);
}

.directory-picker-git-root-btn .directory-picker-icon {
  flex-shrink: 0;
}

.directory-picker-git-root-path {
  color: var(--text-tertiary);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  margin-left: auto;
}

.directory-picker-error {
  padding: 0.5rem 0.75rem;
  background: var(--error-bg);
  border: 1px solid var(--error-border);
  border-radius: 0.25rem;
  color: var(--error-text);
  font-size: 0.875rem;
  margin-bottom: 0.75rem;
}

.directory-picker-loading {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  flex: 1;
  color: var(--text-secondary);
  font-size: 0.875rem;
}

.directory-picker-list {
  flex: 1;
  overflow-y: auto;
  border: 1px solid var(--border);
  border-radius: 0.25rem;
  min-height: 0;
}

.directory-picker-entry {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  width: 100%;
  padding: 0.5rem 0.75rem;
  text-align: left;
  background: transparent;
  border: none;
  border-bottom: 1px solid var(--border);
  color: var(--text-primary);
  font-size: 0.875rem;
  font-family: var(--font-mono);
  cursor: pointer;
  transition: background-color 0.15s;
}

.directory-picker-entry:last-child {
  border-bottom: none;
}

.directory-picker-entry:hover {
  background: var(--bg-tertiary);
}

.directory-picker-entry-parent {
  color: var(--text-secondary);
  font-weight: 500;
}

.directory-picker-icon {
  width: 1rem;
  height: 1rem;
  flex-shrink: 0;
  color: var(--text-secondary);
}

.directory-picker-entry-name {
  flex-shrink: 0;
}

.directory-picker-entry-git .directory-picker-icon {
  color: var(--accent-color, #f97316);
}

.directory-picker-git-subject {
  flex: 1;
  min-width: 0;
  color: var(--text-tertiary);
  font-size: 0.75rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  text-align: right;
}

.directory-picker-empty {
  padding: 2rem;
  text-align: center;
  color: var(--text-tertiary);
  font-size: 0.875rem;
}

.directory-picker-footer {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 1rem;
  border-top: 1px solid var(--border);
}

.directory-picker-footer-spacer {
  flex: 1;
}

.directory-picker-new-btn {
  display: flex;
  align-items: center;
  gap: 0.375rem;
}

.directory-picker-new-icon {
  width: 1rem;
  height: 1rem;
}

/* Create directory form inside the list */
.directory-picker-create-form {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.5rem 0.75rem;
  background: var(--bg-tertiary);
  border-bottom: 1px solid var(--border);
}

.directory-picker-create-input {
  flex: 1;
  padding: 0.375rem 0.5rem;
  border: 1px solid var(--border);
  border-radius: 0.25rem;
  background: var(--bg-base);
  color: var(--text-primary);
  font-family: var(--font-mono);
  font-size: 0.875rem;
}

.directory-picker-create-input:focus {
  outline: none;
  border-color: var(--primary);
}

.directory-picker-create-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 1.75rem;
  height: 1.75rem;
  padding: 0;
  border: none;
  border-radius: 0.25rem;
  background: var(--primary);
  color: white;
  cursor: pointer;
  transition: background-color 0.15s;
}

.directory-picker-create-btn:hover:not(:disabled) {
  background: var(--primary-hover);
}

.directory-picker-create-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.directory-picker-create-btn svg {
  width: 1rem;
  height: 1rem;
}

.directory-picker-cancel-btn {
  background: var(--bg-secondary);
  color: var(--text-secondary);
}

.directory-picker-cancel-btn:hover:not(:disabled) {
  background: var(--bg-tertiary);
}

.directory-picker-create-error {
  padding: 0.375rem 0.75rem;
  background: var(--error-bg);
  color: var(--error-text);
  font-size: 0.75rem;
  border-bottom: 1px solid var(--error-border);
}

/* Screen reader only */
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

/* Context Usage Bar */
/* Status bar for active conversation */
.status-bar-active {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
}

.status-working-group {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.status-stop-button {
  display: flex;
  align-items: center;
  gap: 0.25rem;
  padding: 0.25rem 0.5rem;
  border: none;
  border-radius: 0.25rem;
  background: var(--error-bg);
  color: var(--error-text);
  cursor: pointer;
  transition: all 0.15s ease;
  font-size: 0.75rem;
  font-weight: 500;
}

.status-stop-button:hover:not(:disabled) {
  background: var(--error-text);
  color: white;
}

.status-stop-button:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.status-stop-button svg {
  width: 0.75rem;
  height: 0.75rem;
  flex-shrink: 0;
}

.status-stop-label {
  white-space: nowrap;
}

/* Hide stop label on small screens */
@media (max-width: 500px) {
  .status-stop-label {
    display: none;
  }
  .status-stop-button {
    padding: 0.25rem;
  }
}

.context-usage-bar-container {
  display: flex;
  align-items: center;
  gap: 4px;
}

.context-warning-icon {
  font-size: 14px;
  line-height: 1;
  cursor: help;
}

.context-usage-bar {
  width: 60px;
  height: 6px;
  background: var(--bg-tertiary);
  border-radius: 3px;
  overflow: hidden;
  cursor: pointer;
}

.context-usage-fill {
  height: 100%;
  border-radius: 3px;
  transition:
    width 0.3s ease,
    background-color 0.3s ease;
}

/* Mobile optimizations for tighter spacing */
@media (max-width: 767px) {
  .header {
    padding: 0.375rem 0.75rem;
    padding-top: calc(0.375rem + env(safe-area-inset-top, 0px));
  }

  .status-bar {
    padding: 0.375rem 0.75rem;
    min-height: 2rem;
  }

  .message-input-container {
    padding: 0.5rem 0.75rem;
    padding-bottom: calc(0.5rem + env(safe-area-inset-bottom, 0px));
  }

  .message-input-form {
    flex-direction: column;
    align-items: stretch;
    gap: 0.375rem;
  }

  .message-controls-row {
    width: 100%;
  }

  .message-attach-btn,
  .message-voice-btn,
  .message-send-btn {
    margin-bottom: 0;
  }
}

/* Print styles - looks like the chat window, just without chrome */
@media print {
  /* Reset page layout */
  html,
  body {
    height: auto !important;
    overflow: visible !important;
    background: white !important;
  }

  /* Hide interactive chrome but keep the header title */
  .status-bar,
  .message-input-container,
  .drawer,
  .backdrop,
  .scroll-to-bottom-button,
  .overflow-menu,
  .context-menu,
  .modal-overlay {
    display: none !important;
  }

  /* Hide header buttons but keep the title */
  .header-actions,
  .header .btn-icon {
    display: none !important;
  }

  /* Simplify header for print */
  .header {
    background: white !important;
    border-bottom: 1px solid #e5e7eb !important;
    padding: 0.75rem 1rem !important;
  }

  .header-title {
    font-size: 1rem !important;
  }

  /* Reset app container for print */
  .app-container {
    display: block !important;
    height: auto !important;
    background: white !important;
  }

  .main-content {
    display: block !important;
    height: auto !important;
  }

  /* Reset messages area to flow naturally */
  .messages-area-wrapper {
    height: auto !important;
    overflow: visible !important;
    position: static !important;
    background: white !important;
  }

  .messages-container {
    height: auto !important;
    overflow: visible !important;
    position: static !important;
    background: white !important;
  }

  .messages-list {
    background: white !important;
  }

  /* Hide empty state in print */
  .empty-state {
    display: none !important;
  }

  /* Keep message styling, just add page break hints */
  .message {
    page-break-inside: avoid;
  }

  /* Tool results */
  .tool-result-details {
    page-break-inside: avoid;
  }

  /* Code blocks */
  pre,
  code {
    page-break-inside: avoid;
  }

  /* Screenshots and images - ensure they fit */
  .screenshot-preview,
  .screenshot-image,
  .read-image-preview {
    max-width: 100% !important;
    height: auto !important;
    page-break-inside: avoid;
  }
}
/* Diff Viewer Overlay */
.diff-viewer-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.5);
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
  padding-top: max(1rem, env(safe-area-inset-top));
  padding-bottom: max(1rem, env(safe-area-inset-bottom));
}

.diff-viewer-container {
  background: var(--bg-base);
  border-radius: 0.5rem;
  width: calc(100% - 2rem);
  max-width: none;
  height: calc(100% - 2rem);
  max-height: none;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  box-shadow: 0 4px 24px rgba(0, 0, 0, 0.3);
}

.diff-viewer-header {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  padding: 0.5rem 0.75rem;
  background: var(--bg-secondary);
  border-bottom: 1px solid var(--border-color);
}

.diff-viewer-header-row {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  width: 100%;
}

.diff-viewer-selectors-row {
  display: flex;
  flex: 1;
  gap: 0.5rem;
  min-width: 0;
}

.diff-viewer-selectors-row .diff-viewer-select {
  flex: 1;
  min-width: 0;
  max-width: none;
}

.diff-viewer-file-selector-wrapper {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex: 1;
  min-width: 0;
}

.diff-viewer-file-selector-wrapper .diff-viewer-select {
  flex: 1;
  min-width: 0;
}

.diff-viewer-file-index {
  font-size: 0.75rem;
  color: var(--text-secondary);
  white-space: nowrap;
  flex-shrink: 0;
}

.diff-viewer-controls-row {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-shrink: 0;
}

.diff-viewer-header-mobile {
  flex-direction: row;
  align-items: center;
  gap: 0.5rem;
  padding: 0.375rem 0.5rem;
}

.diff-viewer-mobile-selectors {
  display: flex;
  flex: 1;
  gap: 0.375rem;
  min-width: 0;
}

.diff-viewer-mobile-selectors .diff-viewer-select {
  flex: 1;
  min-width: 0;
  font-size: 0.75rem;
  padding: 0.375rem;
}

.diff-viewer-mode-toggle {
  display: flex;
  border: 1px solid var(--border-color);
  border-radius: 0.25rem;
  overflow: hidden;
}

.diff-viewer-mode-btn {
  padding: 0.25rem 0.5rem;
  border: none;
  background: var(--bg-base);
  color: var(--text-secondary);
  cursor: pointer;
  font-size: 0.875rem;
}

.diff-viewer-mode-btn:first-child {
  border-right: 1px solid var(--border-color);
}

.diff-viewer-mode-btn.active {
  background: var(--blue-bg);
  color: var(--blue-text);
}

.diff-viewer-mode-btn:hover:not(.active) {
  background: var(--bg-tertiary);
}

.diff-viewer-nav-buttons {
  display: flex;
  gap: 0.125rem;
}

.diff-viewer-nav-btn {
  padding: 0.25rem 0.5rem;
  border: 1px solid var(--border-color);
  background: var(--bg-base);
  color: var(--text-primary);
  cursor: pointer;
  border-radius: 0.25rem;
  font-size: 0.875rem;
}

.diff-viewer-nav-btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.diff-viewer-nav-btn:hover:not(:disabled) {
  background: var(--bg-tertiary);
}

.diff-viewer-select {
  flex: 1;
  min-width: 120px;
  max-width: 300px;
  padding: 0.5rem;
  border: 1px solid var(--border-color);
  border-radius: 0.25rem;
  background: var(--bg-base);
  color: var(--text-primary);
  font-size: 0.875rem;
}

.diff-viewer-dir-btn {
  width: 2rem;
  height: 2rem;
  border: none;
  background: transparent;
  color: var(--text-secondary);
  cursor: pointer;
  border-radius: 0.25rem;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  padding: 0;
}

.diff-viewer-dir-btn:hover {
  background: var(--bg-tertiary);
  color: var(--text-primary);
}

.diff-viewer-close {
  width: 2rem;
  height: 2rem;
  border: none;
  background: transparent;
  color: var(--text-secondary);
  font-size: 1.5rem;
  cursor: pointer;
  border-radius: 0.25rem;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.diff-viewer-close:hover {
  background: var(--bg-tertiary);
  color: var(--text-primary);
}

.diff-viewer-error {
  padding: 0.5rem 1rem;
  background: var(--error-bg);
  color: var(--error-text);
  font-size: 0.875rem;
}

.diff-viewer-toast {
  position: fixed;
  bottom: 24px;
  right: 24px;
  padding: 12px 16px;
  border-radius: 8px;
  font-size: 14px;
  font-weight: 500;
  z-index: 9999;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
  animation: toast-fade-in 0.2s ease;
  color: #ffffff;
}

.diff-viewer-toast-saving {
  background: #1976d2;
}

.diff-viewer-toast-saved {
  background: #2e7d32;
}

.diff-viewer-toast-error {
  background: #d32f2f;
}

.diff-viewer-toast-hint {
  background: var(--bg-tertiary);
  color: var(--text-primary);
  border: 1px solid var(--border-color);
}

@keyframes toast-fade-in {
  from {
    opacity: 0;
    transform: translateY(10px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.diff-viewer-content {
  flex: 1;
  overflow: hidden;
  position: relative;
}

.diff-viewer-loading,
.diff-viewer-empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 100%;
  color: var(--text-secondary);
  gap: 0.5rem;
}

.diff-viewer-hint {
  font-size: 0.875rem;
  opacity: 0.7;
}

.diff-viewer-editor {
  height: 100%;
  width: 100%;
}

/* Diff viewer line hover highlighting (via decoration API) */
.diff-viewer-editor .monaco-editor .diff-viewer-line-hover {
  background-color: rgba(37, 99, 235, 0.08) !important;
}

.dark .diff-viewer-editor .monaco-editor .diff-viewer-line-hover {
  background-color: rgba(96, 165, 250, 0.12) !important;
}

/* Comment indicator glyph in margin for diff viewer */
.diff-viewer-editor .monaco-editor .diff-viewer-comment-glyph {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='14' height='14' viewBox='0 0 24 24' fill='none' stroke='%236b7280' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M21 15a2 2 0 0 1-2 2H7l-4 4V5a2 2 0 0 1 2-2h14a2 2 0 0 1 2 2z'%3E%3C/path%3E%3Cline x1='9' y1='10' x2='15' y2='10'%3E%3C/line%3E%3C/svg%3E");
  background-size: 14px 14px;
  background-repeat: no-repeat;
  background-position: center;
  opacity: 0.6;
  cursor: pointer;
}

.diff-viewer-editor .monaco-editor .diff-viewer-comment-glyph:hover {
  opacity: 1;
}

.dark .diff-viewer-editor .monaco-editor .diff-viewer-comment-glyph {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='14' height='14' viewBox='0 0 24 24' fill='none' stroke='%239ca3af' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M21 15a2 2 0 0 1-2 2H7l-4 4V5a2 2 0 0 1 2-2h14a2 2 0 0 1 2 2z'%3E%3C/path%3E%3Cline x1='9' y1='10' x2='15' y2='10'%3E%3C/line%3E%3C/svg%3E");
}

/* Make diff viewer Monaco lines clickable with pointer cursor */
.diff-viewer-editor .monaco-editor .view-lines {
  cursor: pointer;
}

.diff-viewer-comment-badge {
  position: absolute;
  bottom: 1rem;
  left: 1rem;
  padding: 0.5rem 1rem;
  background: var(--blue-bg);
  color: var(--blue-text);
  border-radius: 1rem;
  font-size: 0.875rem;
  font-weight: 500;
}

/* Comment dialog */
.diff-viewer-comment-dialog {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 90%;
  max-width: 500px;
  background: var(--bg-base);
  border: 1px solid var(--border-color);
  border-radius: 0.5rem;
  padding: 1rem;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
  z-index: 1001;
}

.diff-viewer-comment-dialog h4 {
  margin: 0 0 0.75rem 0;
  color: var(--text-primary);
}

.diff-viewer-selected-text {
  margin: 0 0 0.75rem 0;
  padding: 0.5rem;
  background: var(--bg-tertiary);
  border: 1px solid var(--border-color);
  border-radius: 0.25rem;
  font-size: 0.75rem;
  font-family: monospace;
  max-height: 150px;
  overflow: auto;
  white-space: pre;
}

.diff-viewer-comment-input {
  width: 100%;
  min-height: 100px;
  padding: 0.5rem;
  border: 1px solid var(--border-color);
  border-radius: 0.25rem;
  background: var(--bg-base);
  color: var(--text-primary);
  font-size: 0.875rem;
  resize: vertical;
}

.diff-viewer-comment-actions {
  display: flex;
  justify-content: flex-end;
  gap: 0.5rem;
  margin-top: 0.75rem;
}

.diff-viewer-btn {
  padding: 0.5rem 1rem;
  border: none;
  border-radius: 0.25rem;
  font-size: 0.875rem;
  cursor: pointer;
}

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

.diff-viewer-btn-primary {
  background: var(--blue-bg);
  color: var(--blue-text);
}

.diff-viewer-btn-primary:hover:not(:disabled) {
  filter: brightness(0.95);
}

.diff-viewer-btn-secondary {
  background: var(--bg-tertiary);
  color: var(--text-primary);
}

.diff-viewer-btn-secondary:hover:not(:disabled) {
  background: var(--bg-secondary);
}

/* Mobile floating nav buttons */
.diff-viewer-mobile-nav {
  position: absolute;
  bottom: 1.5rem;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  gap: 0.5rem;
  z-index: 100;
}

.diff-viewer-mobile-nav-btn {
  width: 3rem;
  height: 3rem;
  border: none;
  border-radius: 50%;
  background: var(--bg-base);
  color: var(--text-primary);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2);
}

.diff-viewer-mobile-nav-btn svg {
  width: 24px;
  height: 24px;
}

.diff-viewer-mobile-nav-btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.diff-viewer-mobile-nav-btn:active:not(:disabled) {
  background: var(--bg-tertiary);
  transform: scale(0.95);
}

.diff-viewer-mobile-mode-btn {
  font-size: 1.25rem;
}

.diff-viewer-mobile-mode-btn.active {
  background: var(--blue-bg);
  color: var(--blue-text);
}

/* Monaco comment glyph decoration */
/* Mobile optimizations for diff viewer */
@media (max-width: 767px) {
  .diff-viewer-overlay {
    padding: 0;
  }

  .diff-viewer-container {
    border-radius: 0;
    width: 100%;
    max-width: 100%;
    height: 100%;
    max-height: 100%;
  }

  .diff-viewer-close {
    width: 1.75rem;
    height: 1.75rem;
    font-size: 1.25rem;
    flex-shrink: 0;
  }

  /* Monaco editor mobile styles - hide gutters completely */
  .diff-viewer-editor .monaco-editor .margin {
    display: none !important;
    width: 0 !important;
  }

  .diff-viewer-editor .monaco-editor .margin-view-overlays {
    display: none !important;
    width: 0 !important;
  }

  .diff-viewer-editor .monaco-editor .editor-scrollable {
    left: 0 !important;
  }

  .diff-viewer-editor .monaco-editor .lines-content {
    margin-left: 0 !important;
  }

  /* Ensure diff editor uses full width */
  .diff-viewer-editor .monaco-diff-editor {
    width: 100% !important;
  }

  .diff-viewer-editor .monaco-diff-editor .editor.modified {
    width: 100% !important;
    left: 0 !important;
  }

  /* Comment dialog on top half of screen for mobile (keyboard space) */
  .diff-viewer-comment-dialog {
    top: 10%;
    transform: translate(-50%, 0);
    max-height: 40vh;
    overflow-y: auto;
  }

  .diff-viewer-comment-input {
    min-height: 60px;
  }
}

/* Injected text indicator (for diff comments) */
.injected-text-indicator {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.5rem 0.75rem;
  background: var(--blue-bg);
  border-bottom: 1px solid var(--border-color);
  gap: 0.5rem;
}

.injected-text-label {
  font-size: 0.875rem;
  color: var(--blue-text);
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.injected-text-insert-btn {
  padding: 0.375rem 0.75rem;
  background: var(--blue-text);
  color: white;
  border: none;
  border-radius: 0.25rem;
  font-size: 0.75rem;
  font-weight: 500;
  cursor: pointer;
  white-space: nowrap;
  flex-shrink: 0;
}

.injected-text-insert-btn:hover {
  filter: brightness(1.1);
}

/* Links in message text */
.text-link {
  color: var(--blue-text);
  text-decoration: underline;
  text-underline-offset: 2px;
  text-decoration-color: var(--blue-border);
}

.text-link:hover {
  text-decoration-color: var(--blue-text);
}

/* Command Palette */
.command-palette-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  z-index: 100;
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding-top: 15vh;
}

.command-palette {
  background: var(--bg-base);
  border: 1px solid var(--border-color);
  border-radius: 0.75rem;
  box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.25);
  width: 100%;
  max-width: 32rem;
  max-height: 60vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.command-palette-input-wrapper {
  display: flex;
  align-items: center;
  padding: 0.75rem 1rem;
  border-bottom: 1px solid var(--border-color);
  gap: 0.75rem;
}

.command-palette-search-icon {
  color: var(--text-secondary);
  flex-shrink: 0;
}

.command-palette-input {
  flex: 1;
  border: none;
  background: transparent;
  font-size: 1rem;
  color: var(--text-primary);
  outline: none;
}

.command-palette-input::placeholder {
  color: var(--text-secondary);
}

.command-palette-shortcut {
  flex-shrink: 0;
}

.command-palette-spinner {
  width: 16px;
  height: 16px;
  border: 2px solid var(--border-color);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.6s linear infinite;
  flex-shrink: 0;
}

.command-palette-list {
  flex: 1;
  overflow-y: auto;
  padding: 0.5rem;
}

.command-palette-empty {
  padding: 2rem 1rem;
  text-align: center;
  color: var(--text-secondary);
}

.command-palette-item {
  display: flex;
  align-items: center;
  padding: 0.625rem 0.75rem;
  border-radius: 0.5rem;
  cursor: pointer;
  gap: 0.75rem;
}

.command-palette-item:hover,
.command-palette-item.selected {
  background: var(--bg-secondary);
}

.command-palette-item-icon {
  flex-shrink: 0;
  color: var(--text-secondary);
  display: flex;
  align-items: center;
  justify-content: center;
}

.command-palette-item.selected .command-palette-item-icon {
  color: var(--primary);
}

.command-palette-item-content {
  flex: 1;
  min-width: 0;
}

.command-palette-item-title {
  font-size: 0.875rem;
  color: var(--text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.command-palette-item-subtitle {
  font-size: 0.75rem;
  color: var(--text-secondary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin-top: 0.125rem;
}

.command-palette-item-badge {
  flex-shrink: 0;
  font-size: 0.625rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  padding: 0.125rem 0.375rem;
  background: var(--bg-tertiary);
  border-radius: 0.25rem;
  color: var(--text-secondary);
}

.command-palette-item-shortcut {
  flex-shrink: 0;
  margin-left: auto;
}

.command-palette-item-shortcut kbd {
  font-size: 0.6875rem;
  font-family: inherit;
  padding: 0.125rem 0.375rem;
  background: var(--bg-tertiary);
  border: 1px solid var(--border-color);
  border-radius: 0.25rem;
  color: var(--text-secondary);
}

.command-palette-footer {
  display: flex;
  gap: 1rem;
  padding: 0.5rem 1rem;
  border-top: 1px solid var(--border-color);
  font-size: 0.75rem;
  color: var(--text-secondary);
}

.command-palette-footer span {
  display: flex;
  align-items: center;
  gap: 0.25rem;
}

@media (max-width: 640px) {
  .command-palette-overlay {
    padding: 1rem;
    padding-top: 5vh;
  }

  .command-palette {
    max-height: 80vh;
  }

  .command-palette-footer {
    display: none;
  }
}

/* Models Modal Styles */
.models-modal {
  padding: 0.5rem;
}

.models-loading {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  padding: 2rem;
  color: var(--text-secondary);
}

.models-error {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.75rem 1rem;
  background: var(--error-bg);
  border: 1px solid var(--error-border);
  border-radius: 0.375rem;
  color: var(--error-text);
  margin-bottom: 1rem;
}

.models-error-dismiss {
  background: none;
  border: none;
  font-size: 1.25rem;
  cursor: pointer;
  color: inherit;
  padding: 0;
  line-height: 1;
}

.models-info {
  padding: 0.75rem 1rem;
  background: var(--bg-tertiary);
  border-radius: 0.375rem;
  margin-bottom: 1rem;
}

.models-info p {
  margin: 0 0 0.5rem 0;
  color: var(--text-secondary);
}

.builtin-list {
  margin: 0;
  padding-left: 1.25rem;
  color: var(--text-primary);
}

.builtin-list li {
  margin: 0.25rem 0;
}

.models-list {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  margin-bottom: 1rem;
}

.model-card {
  padding: 0.75rem 1rem;
  background: var(--bg-base);
  border: 1px solid var(--border);
  border-radius: 0.375rem;
}

.model-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 0.5rem;
}

.model-info {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem;
}

.model-name {
  font-weight: 500;
  color: var(--text-primary);
}

.model-provider {
  font-size: 0.75rem;
  padding: 0.125rem 0.5rem;
  background: var(--bg-tertiary);
  border-radius: 0.25rem;
  color: var(--text-secondary);
}

.model-source {
  font-size: 0.75rem;
  padding: 0.125rem 0.5rem;
  background: var(--bg-tertiary);
  border-radius: 0.25rem;
  color: var(--text-secondary);
}

.model-card-builtin {
  opacity: 0.8;
  background: var(--bg-secondary);
}

.models-empty {
  padding: 2rem;
  text-align: center;
  color: var(--text-secondary);
}

.models-empty-hint {
  font-size: 0.875rem;
  margin-top: 0.5rem;
  color: var(--text-tertiary);
}

.model-badge {
  font-size: 0.625rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  padding: 0.125rem 0.375rem;
  background: var(--blue-bg);
  border: 1px solid var(--blue-border);
  border-radius: 0.25rem;
  color: var(--blue-text);
}

.model-actions {
  display: flex;
  gap: 0.25rem;
  flex-shrink: 0;
}

.model-details {
  margin-top: 0.5rem;
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}

.model-api-name {
  font-size: 0.75rem;
  font-family: var(--font-mono);
  color: var(--text-secondary);
}

.model-endpoint {
  font-size: 0.75rem;
  color: var(--text-tertiary);
  word-break: break-all;
}

.btn-icon {
  padding: 0.25rem;
  border-radius: 0.25rem;
  color: var(--text-secondary);
  background: transparent;
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}

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

/* Version Checker Styles */
.version-update-dot {
  position: absolute;
  top: 2px;
  right: 2px;
  width: 8px;
  height: 8px;
  background: #ef4444;
  border-radius: 50%;
  border: 2px solid var(--bg-base);
}

.version-menu-dot {
  width: 8px;
  height: 8px;
  background: #ef4444;
  border-radius: 50%;
  margin-left: auto;
  flex-shrink: 0;
}

.version-modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  padding: 1rem;
}

.version-modal {
  background: var(--bg-base);
  border-radius: 0.5rem;
  box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.25);
  max-width: 500px;
  width: 100%;
  max-height: 80vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.version-modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1rem 1.25rem;
  border-bottom: 1px solid var(--border-color);
}

.version-modal-header h2 {
  margin: 0;
  font-size: 1.125rem;
  font-weight: 600;
  color: var(--text-primary);
}

.version-modal-close {
  background: none;
  border: none;
  padding: 0.25rem;
  cursor: pointer;
  color: var(--text-secondary);
  border-radius: 0.25rem;
}

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

.version-modal-close svg {
  width: 1.25rem;
  height: 1.25rem;
}

.version-modal-content {
  padding: 1.25rem;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.version-info-row {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.875rem;
}

.version-label {
  color: var(--text-secondary);
}

.version-value {
  font-weight: 500;
  color: var(--text-primary);
  font-family: var(--font-mono);
}

.version-date {
  color: var(--text-tertiary);
  font-size: 0.75rem;
}

.version-error {
  padding: 0.75rem;
  background: var(--error-bg);
  border: 1px solid var(--error-border);
  border-radius: 0.375rem;
  font-size: 0.875rem;
  color: var(--error-text);
}

.version-success {
  padding: 0.75rem;
  background: var(--success-bg);
  border: 1px solid var(--success-border);
  border-radius: 0.375rem;
  font-size: 0.875rem;
  color: var(--success-text);
}

.version-changelog {
  border-top: 1px solid var(--border-color);
  padding-top: 1rem;
}

.version-changelog h3 {
  margin: 0 0 0.75rem 0;
  font-size: 0.875rem;
  font-weight: 600;
}

.changelog-link {
  color: var(--link-color);
  text-decoration: none;
}

.changelog-link:hover {
  text-decoration: underline;
}

.commit-list {
  margin: 0;
  padding: 0;
  list-style: none;
  max-height: 250px;
  overflow-y: auto;
  font-size: 0.8125rem;
}

.commit-item {
  display: flex;
  gap: 0.5rem;
  padding: 0.5rem 0;
  border-bottom: 1px solid var(--border-color);
  align-items: flex-start;
}

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

.commit-sha {
  font-family: var(--font-mono);
  color: var(--link-color);
  font-size: 0.75rem;
  flex-shrink: 0;
  text-decoration: none;
}

.commit-sha:hover {
  text-decoration: underline;
}

.commit-message {
  color: var(--text-primary);
  word-break: break-word;
  line-height: 1.4;
}

.version-loading,
.version-no-commits {
  color: var(--text-secondary);
  font-size: 0.875rem;
  padding: 0.5rem 0;
}

.version-auto-upgrade {
  padding: 1rem 0;
  border-top: 1px solid var(--border-color);
  margin-top: 1rem;
}

.version-checkbox-label {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  cursor: pointer;
  font-size: 0.875rem;
}

.version-checkbox-label input[type="checkbox"] {
  cursor: pointer;
  width: 1rem;
  height: 1rem;
}

.version-actions {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  border-top: 1px solid var(--border-color);
  padding-top: 1rem;
}

.version-btn {
  padding: 0.5rem 1rem;
  border-radius: 0.375rem;
  font-size: 0.875rem;
  font-weight: 500;
  cursor: pointer;
  transition: background-color 0.15s;
}

.version-btn:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

.version-btn-primary {
  background: var(--primary);
  color: white;
  border: none;
}

.version-btn-primary:hover:not(:disabled) {
  background: var(--primary-dark);
}

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

.add-model-btn {
  width: 100%;
}

/* Model Form */
.model-form h3 {
  margin: 0 0 0.75rem 0;
  font-size: 1rem;
  font-weight: 600;
}

.form-group {
  margin-bottom: 0.75rem;
}

.form-group label {
  display: block;
  font-size: 0.875rem;
  font-weight: 500;
  margin-bottom: 0.25rem;
  color: var(--text-primary);
}

.form-group label .optional {
  font-weight: 400;
  color: var(--text-secondary);
}

.form-input {
  width: 100%;
  padding: 0.5rem 0.75rem;
  background: var(--bg-base);
  border: 1px solid var(--border);
  border-radius: 0.375rem;
  color: var(--text-primary);
  font-family: inherit;
  font-size: 0.875rem;
}

.form-input:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 2px rgba(37, 99, 235, 0.2);
}

.form-checkbox {
  display: flex;
  align-items: center;
}

.form-checkbox label {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  cursor: pointer;
  margin: 0;
}

.form-checkbox input[type="checkbox"] {
  width: 1rem;
  height: 1rem;
  cursor: pointer;
}

.info-icon-wrapper {
  position: relative;
  display: inline-flex;
  align-items: center;
  margin-left: 0.25rem;
}

.info-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: var(--text-tertiary);
  cursor: pointer;
}

.info-icon:hover {
  color: var(--text-secondary);
}

.info-tooltip {
  position: absolute;
  top: 50%;
  left: 100%;
  transform: translateY(-50%);
  background: var(--bg-tertiary);
  border: 1px solid var(--border);
  border-radius: 0.375rem;
  padding: 0.5rem 0.75rem;
  font-size: 0.75rem;
  font-weight: 400;
  color: var(--text-primary);
  white-space: normal;
  width: 220px;
  margin-left: 0.375rem;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
  z-index: 100;
}

.info-tooltip::after {
  content: "";
  position: absolute;
  top: 50%;
  right: 100%;
  transform: translateY(-50%);
  border: 6px solid transparent;
  border-right-color: var(--border);
}

.provider-buttons {
  display: flex;
  gap: 0.5rem;
}

.provider-btn {
  flex: 1;
  padding: 0.5rem;
  background: var(--bg-base);
  border: 1px solid var(--border);
  border-radius: 0.375rem;
  color: var(--text-primary);
  font-size: 0.875rem;
  cursor: pointer;
  transition: all 0.15s;
}

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

.provider-btn.selected {
  background: var(--primary);
  border-color: var(--primary);
  color: white;
}

.endpoint-toggle {
  display: flex;
  gap: 0;
  margin-bottom: 0.5rem;
}

.toggle-btn {
  flex: 1;
  padding: 0.375rem 0.75rem;
  background: var(--bg-base);
  border: 1px solid var(--border);
  color: var(--text-secondary);
  font-size: 0.75rem;
  cursor: pointer;
  transition: all 0.15s;
}

.toggle-btn:first-child {
  border-radius: 0.375rem 0 0 0.375rem;
}

.toggle-btn:last-child {
  border-radius: 0 0.375rem 0.375rem 0;
  border-left: none;
}

.toggle-btn.selected {
  background: var(--bg-tertiary);
  color: var(--text-primary);
}

.endpoint-display {
  padding: 0.5rem 0.75rem;
  background: var(--bg-tertiary);
  border-radius: 0.375rem;
  font-size: 0.75rem;
  color: var(--text-secondary);
  word-break: break-all;
}

.model-presets {
  display: flex;
  flex-wrap: wrap;
  gap: 0.375rem;
  margin-bottom: 0.5rem;
}

.preset-btn {
  padding: 0.25rem 0.625rem;
  background: var(--bg-base);
  border: 1px solid var(--border);
  border-radius: 0.25rem;
  color: var(--text-secondary);
  font-size: 0.75rem;
  cursor: pointer;
  transition: all 0.15s;
}

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

.preset-btn.selected {
  background: var(--blue-bg);
  border-color: var(--blue-border);
  color: var(--blue-text);
}

.test-result {
  padding: 0.75rem 1rem;
  border-radius: 0.375rem;
  margin-bottom: 1rem;
  font-size: 0.875rem;
}

.test-result.success {
  background: var(--success-bg);
  border: 1px solid var(--success-border);
  color: var(--success-text);
}

.test-result.error {
  background: var(--error-bg);
  border: 1px solid var(--error-border);
  color: var(--error-text);
}

.form-actions {
  display: flex;
  gap: 0.5rem;
  justify-content: flex-end;
  margin-top: 1rem;
  padding-bottom: 0.5rem;
}

kbd {
  display: inline-block;
  padding: 0.125rem 0.375rem;
  font-size: 0.75rem;
  font-family: inherit;
  background: var(--bg-tertiary);
  border: 1px solid var(--border-color);
  border-radius: 0.25rem;
  color: var(--text-secondary);
}

/* System Prompt View */
.system-prompt-view {
  background: var(--gray-100);
  border-radius: 0.5rem;
  margin: 0.5rem 0;
  width: 100%;
  border: 1px dashed var(--border);
}

.dark .system-prompt-view {
  background: var(--gray-800);
}

.system-prompt-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.75rem 1rem;
  cursor: pointer;
  user-select: none;
}

.system-prompt-header:hover {
  background: rgba(0, 0, 0, 0.02);
  border-radius: 0.5rem;
}

.dark .system-prompt-header:hover {
  background: rgba(255, 255, 255, 0.02);
}

.system-prompt-summary {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex: 1;
  min-width: 0;
}

.system-prompt-icon {
  font-size: 1rem;
  flex-shrink: 0;
}

.system-prompt-label {
  font-family: var(--font-mono);
  font-size: 0.875rem;
  color: var(--text-primary);
  font-weight: 500;
}

.system-prompt-meta {
  font-size: 0.75rem;
  color: var(--text-secondary);
  flex-shrink: 0;
}

.system-prompt-content {
  padding: 0 1rem 1rem 1rem;
}

.system-prompt-text {
  font-family: var(--font-mono);
  font-size: 0.75rem;
  line-height: 1.5;
  color: var(--text-secondary);
  background: var(--bg-base);
  border: 1px solid var(--border);
  border-radius: 0.375rem;
  padding: 1rem;
  margin: 0;
  max-height: 400px;
  overflow: auto;
  white-space: pre-wrap;
  word-wrap: break-word;
}

.dark .system-prompt-text {
  background: var(--gray-900);
}

/* ===== Terminal Panel ===== */
.terminal-panel {
  display: flex;
  flex-direction: column;
  border-top: 1px solid var(--border);
  background: var(--bg-secondary);
  min-height: 80px;
  max-height: 800px;
  overflow: hidden;
}

.terminal-panel-resize-handle {
  height: 6px;
  cursor: ns-resize;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  background: var(--bg-secondary);
  border-bottom: 1px solid var(--border);
  user-select: none;
}

.terminal-panel-resize-handle:hover {
  background: var(--bg-tertiary);
}

.terminal-panel-resize-grip {
  width: 40px;
  height: 3px;
  background: var(--text-tertiary);
  border-radius: 2px;
}

.terminal-panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 8px;
  height: 34px;
  flex-shrink: 0;
  background: var(--bg-secondary);
  border-bottom: 1px solid var(--border);
  gap: 8px;
}

.terminal-panel-tabs {
  display: flex;
  align-items: center;
  gap: 2px;
  overflow-x: auto;
  flex: 1;
  min-width: 0;
  scrollbar-width: none;
}

.terminal-panel-tabs::-webkit-scrollbar {
  display: none;
}

.terminal-panel-tab {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 4px 8px;
  border-radius: 4px;
  cursor: pointer;
  font-size: 12px;
  font-family: Consolas, "Liberation Mono", Menlo, monospace;
  color: var(--text-secondary);
  white-space: nowrap;
  user-select: none;
  border: 1px solid transparent;
  transition:
    background-color 0.1s,
    color 0.1s;
}

.terminal-panel-tab:hover {
  background: var(--bg-tertiary);
  color: var(--text-primary);
}

.terminal-panel-tab-active {
  background: var(--bg-base);
  color: var(--text-primary);
  border-color: var(--border);
}

.terminal-panel-tab-indicator {
  font-size: 10px;
  line-height: 1;
}

.terminal-panel-tab-running {
  color: var(--success-text);
}

.terminal-panel-tab-success {
  color: var(--success-text);
}

.terminal-panel-tab-error {
  color: var(--error-text);
}

.terminal-panel-tab-label {
  max-width: 120px;
  overflow: hidden;
  text-overflow: ellipsis;
}

.terminal-panel-tab-close {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 16px;
  height: 16px;
  border: none;
  background: none;
  cursor: pointer;
  color: var(--text-tertiary);
  font-size: 14px;
  line-height: 1;
  border-radius: 3px;
  padding: 0;
}

.terminal-panel-tab-close:hover {
  background: var(--bg-tertiary);
  color: var(--error-text);
}

.terminal-panel-actions {
  display: flex;
  align-items: center;
  gap: 2px;
  background: var(--bg-base);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 2px;
  flex-shrink: 0;
}

.terminal-panel-actions-divider {
  width: 1px;
  height: 16px;
  background: var(--border);
  margin: 0 2px;
}

.terminal-panel-action-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 24px;
  height: 24px;
  border-radius: 4px;
  border: none;
  background: transparent;
  cursor: pointer;
  color: var(--text-secondary);
  transition:
    background-color 0.15s,
    color 0.15s;
}

.terminal-panel-action-btn:hover {
  background: var(--bg-tertiary);
}

.terminal-panel-action-btn-feedback {
  background: var(--success-bg);
  color: var(--success-text);
}

.terminal-panel-content {
  flex: 1;
  min-height: 0;
  overflow: hidden;
  position: relative;
}

.terminal-panel-content > div {
  position: absolute;
  inset: 0;
  padding: 8px 12px;
}

/* Highlight animation for navigated user messages */
@keyframes message-nav-highlight {
  0% {
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.3);
    background-color: rgba(37, 99, 235, 0.08);
  }
  100% {
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0);
    background-color: transparent;
  }
}

@keyframes message-nav-highlight-dark {
  0% {
    box-shadow: 0 0 0 3px rgba(96, 165, 250, 0.3);
    background-color: rgba(96, 165, 250, 0.08);
  }
  100% {
    box-shadow: 0 0 0 3px rgba(96, 165, 250, 0);
    background-color: transparent;
  }
}

.message-highlight {
  animation: message-nav-highlight 1.5s ease-out;
  border-radius: 8px;
}

.dark .message-highlight {
  animation: message-nav-highlight-dark 1.5s ease-out;
}

/* Markdown content rendering */
.markdown-content {
  line-height: 1.6;
}

.markdown-content p {
  margin: 0.5em 0;
}

.markdown-content p:first-child {
  margin-top: 0;
}

.markdown-content p:last-child {
  margin-bottom: 0;
}

.markdown-content h1,
.markdown-content h2,
.markdown-content h3,
.markdown-content h4,
.markdown-content h5,
.markdown-content h6 {
  margin: 1em 0 0.5em;
  font-weight: 600;
  line-height: 1.3;
}

.markdown-content h1:first-child,
.markdown-content h2:first-child,
.markdown-content h3:first-child {
  margin-top: 0;
}

.markdown-content h1 {
  font-size: 1.4em;
}
.markdown-content h2 {
  font-size: 1.2em;
}
.markdown-content h3 {
  font-size: 1.1em;
}

.markdown-content code {
  font-family: var(--font-mono);
  font-size: 0.875em;
  background: var(--bg-tertiary);
  padding: 0.15em 0.35em;
  border-radius: 4px;
}

.markdown-content pre {
  margin: 0.75em 0;
  padding: 0.75em 1em;
  background: var(--bg-tertiary);
  border-radius: 6px;
  overflow-x: auto;
}

.markdown-content pre code {
  background: none;
  padding: 0;
  font-size: 0.85em;
}

.markdown-content blockquote {
  margin: 0.75em 0;
  padding: 0.25em 1em;
  border-left: 3px solid var(--border);
  color: var(--text-secondary);
}

.markdown-content ul,
.markdown-content ol {
  margin: 0.5em 0;
  padding-left: 1.5em;
}

.markdown-content li {
  margin: 0.25em 0;
}

.markdown-content hr {
  margin: 1em 0;
  border: none;
  border-top: 1px solid var(--border);
}

.markdown-content table {
  border-collapse: collapse;
  margin: 0.75em 0;
  width: 100%;
}

.markdown-content th,
.markdown-content td {
  border: 1px solid var(--border);
  padding: 0.4em 0.75em;
  text-align: left;
}

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

.markdown-content a {
  color: var(--link-color);
  text-decoration: underline;
}

.markdown-content a:hover {
  text-decoration: none;
}

.markdown-content del {
  text-decoration: line-through;
  color: var(--text-secondary);
}
