/* ─────────────────────────────────────────────────────────────────────────
   Design tokens — single source of truth for the app palette & radii.
   Values match the previous hardcoded literals, so this is visually lossless;
   adjust a token here to retune every element that references it.
   ───────────────────────────────────────────────────────────────────────── */
:root {
  /* Neutrals (slate) */
  --bg: #f8fafc;
  --surface: #ffffff;
  --surface-2: #f1f5f9;
  --border: #e2e8f0;
  --border-strong: #cbd5e1;
  --text: #0f172a;
  --text-strong: #1e293b;
  --text-body: #334155;
  --text-secondary: #475569;
  --text-muted: #64748b;
  --text-faint: #94a3b8;

  /* Primary (blue) */
  --primary: #2563eb;
  --primary-hover: #1d4ed8;
  --primary-light: #3b82f6;
  --primary-dark: #1e40af;
  --primary-bg: #dbeafe;
  --primary-bg-subtle: #eff6ff;
  --primary-border: #93c5fd;

  /* Danger (red) */
  --danger: #dc2626;
  --danger-light: #ef4444;
  --danger-dark: #991b1b;
  --danger-bg: #fee2e2;
  --danger-border: #fca5a5;

  /* Warning (amber) */
  --warning: #f59e0b;
  --warning-hover: #d97706;
  --warning-bg: #fef3c7;

  /* Success (green) */
  --success: #059669;
  --success-bg: #dcfce7;

  /* Radius */
  --radius-sm: 4px;
  --radius: 6px;
  --radius-lg: 8px;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: system-ui, -apple-system, Segoe UI, Roboto, Helvetica, Arial, "Apple Color Emoji", "Segoe UI Emoji";
  color: var(--text);
  background: var(--bg);
}

/* Consistent keyboard-focus ring across all interactive elements (accessibility
   + polish). :where() keeps specificity 0 so element-specific styles still win,
   and :focus-visible only shows during keyboard navigation, not mouse clicks. */
:where(button, a, input, select, textarea, [tabindex]):focus-visible {
  outline: 2px solid var(--primary);
  outline-offset: 2px;
}

/* Backprompter logo — masked so the single logo.svg renders in currentColor
   (adapts to light/dark contexts). Use <span class="brand-mark"></span>. */
.brand-mark {
  display: inline-block;
  width: 1.45em;
  height: 1.1em;
  background-color: currentColor;
  -webkit-mask: url(./logo.svg) center / contain no-repeat;
          mask: url(./logo.svg) center / contain no-repeat;
  vertical-align: -0.18em;
  flex-shrink: 0;
}

/* Loading Overlay */
.loading-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(255, 255, 255, 0.95);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  z-index: 9999;
  gap: 16px;
}

.loading-spinner {
  width: 48px;
  height: 48px;
  border: 4px solid var(--border);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

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

.loading-overlay p {
  margin: 0;
  font-size: 16px;
  color: var(--text-muted);
}

.app-header, .app-footer {
  background: var(--text);
  color: var(--surface);
  padding: 12px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.nav-docs-link {
  color: var(--text-faint);
  text-decoration: none;
  font-size: 13px;
  padding: 4px 10px;
  border-radius: 6px;
  border: 1px solid var(--text-body);
  transition: background 0.15s, color 0.15s;
}
.nav-docs-link:hover {
  background: var(--text-strong);
  color: var(--surface);
}
.app-header h1 { margin: 0; font-size: 18px; }
.header-left {
  display: flex;
  align-items: center;
  gap: 12px;
}
.sidebar-toggle {
  background: none;
  border: none;
  color: var(--surface);
  font-size: 18px;
  cursor: pointer;
  padding: 4px;
  border-radius: 4px;
}
.sidebar-toggle:hover {
  background: rgba(255, 255, 255, 0.1);
}
.app-footer { font-size: 12px; }

.config { display: flex; gap: 8px; align-items: center; }
.config input[type="url"] {
  width: 420px;
  max-width: 60vw;
  padding: 8px;
  border-radius: 6px;
  border: 1px solid var(--border-strong);
}
.config button { padding: 8px 10px; border-radius: 6px; border: none; cursor: pointer; }

.chat-container { display: flex; height: calc(100vh - 96px); overflow: hidden; }
.sidebar { width: 300px; flex-shrink: 0; background: var(--surface); border-right: 1px solid var(--border); padding: 12px; overflow-y: auto; }
.chat { flex: 1; }
.chat-container.sidebar-hidden .sidebar { position: absolute; left: -300px; }
.sidebar { background: var(--surface); border-right: 1px solid var(--border); padding: 12px; overflow-y: auto; }
.sidebar .field { display: grid; gap: 6px; margin-bottom: 12px; }
.sidebar .field.checkbox { grid-template-columns: auto 1fr; align-items: center; }
.sidebar textarea {
  width: 100%; min-height: 100px; resize: vertical; padding: 8px;
  border: 1px solid var(--border-strong); border-radius: 6px; font-family: inherit;
}
.sidebar select, .sidebar input[type="range"], .sidebar input[type="text"], .sidebar input[type="url"] {
  padding: 6px; border: 1px solid var(--border-strong); border-radius: 6px;
}

.profile-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 8px;
  margin-bottom: 8px;
}

.profile-actions button {
  padding: 8px 12px;
  border: none;
  border-radius: 6px;
  background: var(--primary);
  color: var(--surface);
  cursor: pointer;
  font-size: 12px;
  transition: background 0.2s;
}

.profile-actions button:hover:not(:disabled) {
  background: var(--primary-hover);
}

.profile-actions button:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

.tabs {
  display: flex;
  gap: 4px;
  margin-bottom: 8px;
  border-bottom: 2px solid var(--border);
}

.tab {
  padding: 8px 12px;
  background: transparent;
  border: none;
  border-bottom: 2px solid transparent;
  cursor: pointer;
  font-size: 13px;
  color: var(--text-muted);
  transition: all 0.2s;
}

.tab:hover {
  color: var(--primary);
}

.tab.active {
  color: var(--primary);
  border-bottom-color: var(--primary);
  font-weight: 500;
}

.tab-content {
  padding: 8px 0;
}

.prompt-info {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 8px;
  background: var(--bg);
  border-radius: 4px;
  font-size: 12px;
  color: var(--text-muted);
}

.prompt-info-actions {
  display: flex;
  gap: 6px;
}

.prompt-info button {
  padding: 4px 8px;
  font-size: 11px;
  border-radius: 4px;
  border: 1px solid var(--border-strong);
  background: var(--surface);
  color: var(--text-secondary);
  cursor: pointer;
}

.prompt-info button:hover {
  background: var(--surface-2);
}

.modal {
  display: none;
  position: fixed;
  z-index: 1000;
  left: 0;
  top: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.5);
  align-items: center;
  justify-content: center;
}

.modal.show {
  display: flex;
}

.modal-content {
  background: var(--surface);
  border-radius: 8px;
  width: 90%;
  max-width: 800px;
  max-height: 90vh;
  display: flex;
  flex-direction: column;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.15);
}

.modal-content.large {
  max-width: 1200px;
}

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

.modal-header h2 {
  margin: 0;
  font-size: 18px;
  color: var(--text);
}

.modal-close {
  background: none;
  border: none;
  font-size: 24px;
  color: var(--text-muted);
  cursor: pointer;
  padding: 0;
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 4px;
}

.modal-close:hover {
  background: var(--surface-2);
}

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

.modal-body textarea {
  width: 100%;
  font-family: 'Courier New', monospace;
  font-size: 13px;
  padding: 12px;
  border: 1px solid var(--border-strong);
  border-radius: 6px;
  resize: vertical;
}

.modal-footer {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  padding: 16px 20px;
  border-top: 1px solid var(--border);
}

.modal-footer-right {
  display: flex;
  gap: 8px;
}

.modal-footer button {
  padding: 8px 16px;
  border-radius: 6px;
  border: none;
  cursor: pointer;
  font-size: 14px;
}

.modal-footer button:not(.secondary) {
  background: var(--primary);
  color: var(--surface);
}

.modal-footer button:not(.secondary):not(:disabled):hover {
  background: var(--primary-hover);
}

.modal-footer button.secondary {
  background: var(--border);
  color: var(--text-secondary);
}

.modal-footer button.secondary:not(:disabled):hover {
  background: var(--border-strong);
}

.modal-footer button:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  background: #9ca3af !important;
  color: #6b7280 !important;
}

.modal-footer button.processing {
  background: var(--success) !important;
  color: var(--surface) !important;
  cursor: wait;
}

.chat { display: grid; grid-template-rows: 1fr auto; height: 100%; overflow: hidden; }
.messages { padding: 16px; overflow-y: auto; }
.composer { display: grid; grid-template-rows: auto 1fr auto; gap: 8px; padding: 12px; border-top: 1px solid var(--border); background: var(--surface); }
.composer-header { display: flex; justify-content: flex-end; align-items: center; }
.agent-selector { display: flex; align-items: center; gap: 6px; font-size: 12px; }
.agent-selector label { font-weight: 500; color: var(--text-muted); }
.agent-selector select { padding: 4px 8px; border: 1px solid var(--border-strong); border-radius: 4px; font-size: 12px; background: var(--surface); }
.composer textarea { width: 100%; padding: 10px; border: 1px solid var(--border-strong); border-radius: 8px; font-family: inherit; }
.prompt-file-list {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: -2px;
}
.prompt-file-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  background: var(--surface-2);
  border: 1px solid var(--border-strong);
  border-radius: 999px;
  padding: 4px 8px;
  color: var(--text-body);
}
.prompt-file-chip button {
  border: none;
  background: transparent;
  cursor: pointer;
  color: var(--text-secondary);
  font-size: 14px;
  line-height: 1;
  padding: 0;
}
.prompt-file-chip button:hover {
  color: var(--text);
}
.actions { display: flex; gap: 8px; align-items: center; }
.actions button { padding: 10px 14px; border-radius: 8px; border: none; cursor: pointer; }
.actions .secondary { background: var(--border); }
.actions button[type="submit"] { background: var(--primary); color: var(--surface); }
.actions button:disabled { opacity: 0.6; cursor: not-allowed; }

.actions .voice-btn {
  background: var(--text);
  color: var(--surface);
}

.actions .voice-btn:hover:not(:disabled) {
  background: #111827;
}

.voice-inline {
  padding: 0 12px 12px;
}

.voice-status {
  font-size: 13px;
  color: var(--text-secondary);
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 12px;
}

.voice-status.listening {
  border-color: #86efac;
}

.voice-status.speaking {
  border-color: var(--primary-border);
}

.voice-status.error {
  border-color: #fecaca;
}


.msg { display: flex; margin: 8px 0; }
.msg .bubble { padding: 10px 12px; border-radius: 12px; max-width: 80ch; white-space: pre-wrap; word-wrap: break-word; }
.msg.user { justify-content: flex-end; }
.msg.user .bubble { background: var(--primary-bg); }
.msg.assistant { justify-content: flex-start; }
.msg.assistant .bubble { background: var(--border); }
.msg.assistant .bubble p { margin: 0 0 8px 0; }
.msg.assistant .bubble p:last-child { margin-bottom: 0; }
.msg.assistant .bubble pre {
  background: var(--text);
  color: var(--border);
  padding: 10px;
  border-radius: 8px;
  overflow-x: auto;
  white-space: pre;
}
.msg.assistant .bubble code {
  font-family: Consolas, 'Courier New', monospace;
  font-size: 0.92em;
}
.msg.pending .bubble { opacity: 0.8; font-style: italic; }

/* Attachment styles */
.attachment {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  background: var(--surface-2);
  border: 1px solid var(--border-strong);
  border-radius: 6px;
  cursor: pointer;
  transition: all 0.2s ease;
  font-size: 14px;
  color: var(--text-secondary);
}

.attachment:hover {
  background: var(--border);
  border-color: var(--text-faint);
  transform: translateY(-1px);
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

.attachment-icon {
  font-size: 16px;
}

.attachment-text {
  font-weight: 500;
}

/* Portrait mode: sidebar overlays as a drawer */
.portrait .chat-container { position: relative; }
.portrait .sidebar { 
  position: absolute; 
  top: 0; 
  left: 0; 
  width: 300px; 
  height: 100%; 
  z-index: 10; 
  transform: translateX(-100%); 
  transition: transform 0.3s ease; 
  border-right: 1px solid var(--border);
}
.portrait .chat-container.sidebar-shown .sidebar { transform: translateX(0); }

/* Portrait composer layout */
.portrait .composer { display: flex; flex-direction: column; gap: 10px; }
.portrait .actions { justify-content: center; }

/* Portrait mode: stack profile-actions buttons vertically */
.portrait .profile-actions {
  flex-direction: column;
  width: 100%;
}
.portrait .profile-actions button {
  width: 100%;
}

/* Portrait mode: larger text for mobile readability */
.portrait {
  font-size: 16px;
}
.portrait input, .portrait textarea, .portrait select, .portrait button {
  font-size: 16px;
}
.portrait .sidebar textarea {
  font-size: 16px;
}
.portrait .composer textarea {
  font-size: 16px;
}
.portrait .agent-selector select {
  font-size: 14px;
}
.portrait .actions button {
  font-size: 16px;
  padding: 12px 16px;
}
.portrait .sidebar .field label {
  font-size: 16px;
}
.portrait .sidebar select, .portrait .sidebar input[type="range"] {
  font-size: 16px;
}

/* Landscape mode: both sidebar and chat visible with equal width */
.landscape .sidebar {
  width: 50% !important;
  position: relative !important;
  transform: none !important;
  border-right: 1px solid var(--border);
  flex: none !important;
}

.landscape .chat {
  width: 50% !important;
  flex: none !important;
}

/* App and Agent Management Styles */
.section {
  margin-bottom: 20px;
  padding: 12px;
  background: var(--bg);
  border-radius: 8px;
  border: 1px solid var(--border);
}

.section-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 12px;
}

.section-header h3 {
  margin: 0;
  font-size: 14px;
  font-weight: 600;
  color: var(--text);
}

.section-header-actions {
  display: flex;
  gap: 8px;
  align-items: center;
}

.create-btn {
  background: #10b981;
  color: var(--surface);
  border: none;
  border-radius: 50%;
  width: 24px;
  height: 24px;
  cursor: pointer;
  font-size: 16px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.2s;
}

.create-btn:hover:not(:disabled) {
  background: var(--success);
}

.create-btn:disabled {
  background: var(--border-strong);
  cursor: not-allowed;
}

.app-select, .agent-select, .mock-user-select {
  width: 100%;
  padding: 8px;
  border: 1px solid var(--border-strong);
  border-radius: 6px;
  background: var(--surface);
  font-size: 14px;
}

.app-info, .agent-info, .mock-user-info {
  margin-top: 12px;
  padding: 12px;
  background: var(--surface);
  border-radius: 6px;
  border: 1px solid var(--border);
}

.app-details, .agent-details, .mock-user-details {
  margin-bottom: 12px;
}

.app-details strong, .agent-details strong, .mock-user-details strong {
  display: block;
  font-size: 14px;
  color: var(--text);
  margin-bottom: 4px;
}

.app-details p, .agent-details p, .mock-user-details p {
  margin: 0;
  font-size: 12px;
  color: var(--text-muted);
  line-height: 1.4;
}

.app-actions, .agent-actions, .mock-user-actions {
  display: flex;
  gap: 8px;
}

.edit-btn, .delete-btn, .versions-btn {
  padding: 6px 12px;
  border: 1px solid var(--border-strong);
  border-radius: 4px;
  background: var(--surface);
  color: var(--text-secondary);
  cursor: pointer;
  font-size: 12px;
  transition: all 0.2s;
}

.edit-btn:hover {
  background: var(--surface-2);
  border-color: var(--text-faint);
}

.delete-btn:hover {
  background: #fef2f2;
  border-color: var(--danger-border);
  color: var(--danger);
}

.versions-btn:hover {
  background: #f0f9ff;
  border-color: #7dd3fc;
  color: #0369a1;
}

/* Modal form styles */
.form-field {
  margin-bottom: 16px;
}

.form-field label {
  display: block;
  margin-bottom: 6px;
  font-weight: 500;
  color: #374151;
  font-size: 14px;
}

.form-field.checkbox {
  display: flex;
  align-items: center;
  gap: 8px;
}

.form-field.checkbox label {
  margin-bottom: 0;
  font-weight: normal;
}

.form-field.checkbox input[type="checkbox"] {
  width: auto;
  margin: 0;
}

.form-field input[type="text"],
.form-field textarea {
  width: 100%;
  padding: 8px 12px;
  border: 1px solid #d1d5db;
  border-radius: 6px;
  font-family: inherit;
  font-size: 14px;
}

.form-field input[type="text"]:focus,
.form-field textarea:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
}

.form-field textarea {
  resize: vertical;
  min-height: 80px;
}

.inline-input-action {
  display: flex;
  gap: 8px;
  align-items: center;
}

.inline-input-action input[type="text"] {
  flex: 1;
}

.inline-input-action button {
  width: auto;
  padding: 8px 12px;
  flex-shrink: 0;
}

/* Versions modal layout */
.versions-container {
  display: flex;
  gap: 20px;
  height: 500px;
}

.version-details {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 15px;
}

.version-metadata {
  flex-shrink: 0;
}

.version-metadata h3 {
  margin: 0 0 10px 0;
  font-size: 16px;
  color: var(--text-strong);
}

.metadata-content {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 8px 10px;
  max-height: 120px;
  overflow-y: auto;
}

.metadata-item {
  margin-bottom: 4px;
  font-size: 13px;
  line-height: 1.35;
}

.metadata-item:last-child {
  margin-bottom: 0;
}

.metadata-item strong {
  color: var(--text-secondary);
  font-weight: 500;
}

.version-prompt {
  flex: 1;
  display: flex;
  flex-direction: column;
}

.version-prompt h3 {
  margin: 0 0 10px 0;
  font-size: 16px;
  color: var(--text-strong);
}

.prompt-content {
  flex: 1;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 12px;
  overflow-y: auto;
}

.prompt-content pre {
  margin: 0;
  white-space: pre-wrap;
  word-wrap: break-word;
  font-family: 'Monaco', 'Menlo', 'Ubuntu Mono', monospace;
  font-size: 13px;
  line-height: 1.4;
  color: #374151;
}

.versions-list {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.versions-list h3 {
  margin: 0;
  font-size: 16px;
  color: var(--text-strong);
}

.versions-list-content {
  flex: 1;
  overflow-y: auto;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--bg);
}

/* Versions list */
.version-item {
  padding: 12px;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  transition: background 0.2s;
}

.version-item:hover {
  background: var(--surface-2);
}

.version-item.selected {
  background: var(--primary-bg);
  border-left: 3px solid var(--primary-light);
}

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

.version-commit {
  font-weight: 500;
  color: var(--text);
  font-size: 14px;
  margin-bottom: 4px;
}

.version-timestamp {
  font-size: 12px;
  color: var(--text-muted);
  margin-bottom: 4px;
}

.version-committed-by {
  font-size: 12px;
  color: var(--text-muted);
  font-style: italic;
}

/* Version action buttons */
#loadSelectedVersionBtn {
  padding: 8px 16px;
  background: var(--primary-light);
  color: var(--surface);
  border: none;
  border-radius: 4px;
  font-size: 13px;
  cursor: pointer;
  transition: background 0.2s;
}

#loadSelectedVersionBtn:hover:not(:disabled) {
  background: var(--primary);
}

#promoteSelectedVersionBtn {
  padding: 8px 16px;
  background: #10b981;
  color: var(--surface);
  border: none;
  border-radius: 4px;
  font-size: 13px;
  cursor: pointer;
  transition: background 0.2s;
}

#promoteSelectedVersionBtn:hover:not(:disabled) {
  background: var(--success);
}

#deleteSelectedVersionBtn {
  padding: 8px 16px;
  background: var(--danger-light);
  color: var(--surface);
  border: none;
  border-radius: 4px;
  font-size: 13px;
  cursor: pointer;
  transition: background 0.2s;
}

#deleteSelectedVersionBtn:hover:not(:disabled) {
  background: var(--danger);
}

#loadSelectedVersionBtn:disabled,
#promoteSelectedVersionBtn:disabled,
#deleteSelectedVersionBtn:disabled {
  background: #9ca3af;
  cursor: not-allowed;
  opacity: 0.6;
}

/* Version selection states */
.version-item.selected {
  background: var(--primary-bg);
  border-left: 3px solid var(--primary-light);
}

.version-item.selected-primary {
  background: var(--primary-bg);
  border-left: 3px solid var(--primary-light);
}

.version-item.selected-secondary {
  background: var(--warning-bg);
  border-left: 3px solid var(--warning);
}

/* Diff styling */
.diff-container {
  width: 100%;
}

.diff-content {
  margin: 0;
  white-space: pre-wrap;
  word-wrap: break-word;
  font-family: 'Monaco', 'Menlo', 'Ubuntu Mono', monospace;
  font-size: 13px;
  line-height: 1.4;
  color: #374151;
}

.diff-insert {
  background-color: #d1fae5;
  color: #065f46;
}

.diff-delete {
  background-color: var(--danger-bg);
  color: var(--danger-dark);
  text-decoration: line-through;
}

.promote-version-btn {
  background: var(--warning);
  color: var(--surface);
  border: none;
  border-radius: 4px;
  font-size: 13px;
  cursor: pointer;
  transition: background 0.2s;
}

.promote-version-btn:hover {
  background: var(--warning-hover);
}

.delete-version-btn {
  flex: 1;
  padding: 8px;
  background: var(--danger-light);
  color: var(--surface);
  border: none;
  border-radius: 4px;
  font-size: 13px;
  cursor: pointer;
  transition: background 0.2s;
}

.delete-version-btn:hover {
  background: var(--danger);
}

.delete-version-btn:disabled {
  background: #9ca3af;
  cursor: not-allowed;
  opacity: 0.6;
}

.version-buttons {
  display: flex;
  flex-direction: row;
  gap: 8px;
  margin-top: 8px;
}

/* Builder section styles */
.section .field input[type="text"] {
  width: 100%;
  padding: 8px;
  margin-bottom: 8px;
  border: 1px solid var(--border-strong);
  border-radius: 4px;
}

.section .field button.primary {
  width: 100%;
  padding: 8px;
  background: var(--primary-light);
  color: var(--surface);
  border: none;
  border-radius: 4px;
  cursor: pointer;
}

.section .field button.primary:hover {
  background: var(--primary);
}

/* Routable status indicator */
.routable-status {
  font-size: 12px;
  font-weight: 500;
  padding: 2px 6px;
  border-radius: 3px;
  display: inline-block;
  margin-top: 4px;
}

.routable-status.routable {
  background: var(--success-bg);
  color: #166534;
}

.routable-status.not-routable {
  background: var(--warning-bg);
  color: #92400e;
}

/* Evaluations Styles */
.extra-large {
  max-width: 95vw;
  max-height: 90vh;
  width: 1400px;
}

.evaluations-controls {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 16px;
  padding: 12px;
  background: var(--bg);
  border-radius: 6px;
}

#evalCharCount {
  font-size: 14px;
  color: var(--text-muted);
  font-weight: 500;
}

.table-container {
  overflow: auto;
  max-height: calc(90vh - 250px);
  border: 1px solid var(--border);
  border-radius: 6px;
}

.evaluations-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
}

.evaluations-table thead {
  position: sticky;
  top: 0;
  background: var(--bg);
  z-index: 10;
}

.evaluations-table th {
  padding: 12px 8px;
  text-align: left;
  font-weight: 600;
  color: var(--text-secondary);
  border-bottom: 2px solid var(--border);
  white-space: nowrap;
}

.evaluations-table th.sortable {
  cursor: pointer;
  user-select: none;
}

.evaluations-table th.sortable:hover {
  background: var(--border);
}

.sort-indicator {
  display: inline-block;
  margin-left: 4px;
  color: var(--text-faint);
}

.sort-indicator.asc::after {
  content: '▲';
}

.sort-indicator.desc::after {
  content: '▼';
}

.filter-row th {
  padding: 8px;
  border-bottom: 1px solid var(--border);
}

.filter-input {
  width: 100%;
  padding: 6px 8px;
  border: 1px solid var(--border-strong);
  border-radius: 4px;
  font-size: 13px;
}

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

.evaluations-table tbody tr {
  border-bottom: 1px solid var(--border);
}

.evaluations-table tbody tr:hover {
  background: var(--bg);
}

.evaluations-table td {
  padding: 12px 8px;
  max-width: 250px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.evaluations-table td:first-child {
  text-align: center;
  width: 40px;
}

.evaluations-table input[type="checkbox"] {
  cursor: pointer;
}

.response-display {
  padding: 12px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  max-height: 200px;
  overflow-y: auto;
  font-size: 14px;
  line-height: 1.6;
  white-space: pre-wrap;
  word-wrap: break-word;
}

.word-count {
  display: block;
  text-align: right;
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 4px;
}

button.danger {
  background: var(--danger);
  color: var(--surface);
}

button.danger:hover {
  background: #b91c1c;
}

button.danger:disabled {
  background: var(--danger-border);
  cursor: not-allowed;
}

/* Artifact Side Pane */
.artifact-pane {
  position: fixed;
  left: -100%;
  top: 0;
  width: 500px;
  height: 100vh;
  background: var(--surface);
  border-right: 2px solid var(--border);
  box-shadow: 4px 0 16px rgba(0,0,0,0.1);
  transition: left 0.3s ease;
  z-index: 1000;
  display: flex;
  flex-direction: column;
}

.artifact-pane.open {
  left: 0;
}

.artifact-pane-header {
  padding: 16px 20px;
  background: var(--bg);
  border-bottom: 1px solid var(--border);
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.artifact-pane-header h3 {
  margin: 0;
  font-size: 18px;
  font-weight: 600;
  color: var(--text);
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.action-btn {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 4px;
  width: 28px;
  height: 28px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  font-size: 18px;
  line-height: 1;
  color: var(--text-muted);
  transition: all 0.2s;
}

.action-btn:hover {
  background: var(--surface-2);
  color: var(--text);
  border-color: var(--border-strong);
}

.close-pane-btn {
  background: none;
  border: none;
  font-size: 28px;
  cursor: pointer;
  color: var(--text-muted);
  padding: 0;
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 4px;
  transition: background-color 0.2s, color 0.2s;
}

.close-pane-btn:hover {
  background: var(--border);
  color: var(--text);
}

.artifact-pane-content {
  flex: 1;
  overflow: auto;
  padding: 20px;
}

.artifact-pane-content pre {
  margin: 0;
  font-family: 'Monaco', 'Menlo', 'Ubuntu Mono', 'Courier New', monospace;
  font-size: inherit;
  line-height: 1.6;
  color: var(--text);
  white-space: pre;
  overflow-x: auto;
}

.artifact-pane-content img {
  max-width: 100%;
  height: auto;
}

.artifact-pane-content table {
  width: 100%;
  border-collapse: collapse;
  margin: 16px 0;
}

.artifact-pane-content table th,
.artifact-pane-content table td {
  border: 1px solid var(--border);
  padding: 8px 12px;
  text-align: left;
}

.artifact-pane-content table th {
  background: var(--bg);
  font-weight: 600;
}

.mermaid-wrapper {
  overflow: auto;
  margin-bottom: 20px;
  width: 100%;
  max-height: 80vh;
  display: flex;
  justify-content: flex-start;
  align-items: flex-start;
}

.mermaid {
  display: block;
  width: 100%;
  overflow: visible;
  min-height: 100px; /* Prevent collapsing */
}

.mermaid svg {
  display: block;
  width: 100%;
  max-width: 100%;
  height: auto;
}

/* Responsive artifact pane */
@media (min-width: 1200px) and (orientation: landscape) {
  .artifact-pane {
    width: 50vw;
  }
}

@media (max-width: 768px) {
  .artifact-pane {
    width: 100%;
    left: -100%;
  }
}

/* Agent Suggestions */
.agent-suggestions {
  position: absolute;
  background: var(--surface);
  border: 1px solid #ddd;
  border-radius: 4px;
  box-shadow: 0 2px 8px rgba(0,0,0,0.1);
  max-height: 200px;
  overflow-y: auto;
  z-index: 1000;
  width: 100%;
}

.agent-suggestions div {
  padding: 8px 12px;
  cursor: pointer;
  border-bottom: 1px solid #eee;
}

.agent-suggestions div:hover,
.agent-suggestions div.selected {
  background: #f8f9fa;
}

.agent-suggestions div:last-child {
  border-bottom: none;
}

/* ===========================
   File Management Modal Styles
   =========================== */

.file-modal {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.6);
  z-index: 10000;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.file-modal-content {
  background: var(--surface);
  border-radius: 12px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
  max-width: 1200px;
  width: 100%;
  max-height: 90vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

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

.file-modal-header h2 {
  margin: 0;
  font-size: 20px;
  color: var(--text);
}

.file-modal-close {
  background: none;
  border: none;
  font-size: 32px;
  color: var(--text-muted);
  cursor: pointer;
  line-height: 1;
  padding: 0;
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 4px;
  transition: all 0.2s;
}

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

.file-upload-controls {
  padding: 20px 24px;
  border-bottom: 1px solid var(--border);
  display: flex;
  gap: 24px;
  align-items: flex-start;
  flex-wrap: wrap;
}

.file-upload-section, .url-upload-section {
  display: flex;
  gap: 12px;
  align-items: center;
  flex: 1;
  min-width: 250px;
}

.file-upload-btn {
  background: var(--primary);
  color: var(--surface);
  border: none;
  padding: 10px 20px;
  border-radius: 6px;
  cursor: pointer;
  font-size: 14px;
  font-weight: 500;
  transition: all 0.2s;
  white-space: nowrap;
}

.file-upload-btn:hover {
  background: var(--primary-hover);
}

.file-upload-btn:disabled {
  background: var(--text-faint);
  cursor: not-allowed;
}

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

.url-upload-section input[type="url"] {
  flex: 1;
  padding: 10px 12px;
  border: 1px solid var(--border-strong);
  border-radius: 6px;
  font-size: 14px;
}

.url-upload-section input[type="url"]:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
}

.file-main-content {
  display: flex;
  flex: 1;
  overflow: hidden;
  min-height: 0;
}

.file-list-panel {
  width: 350px;
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  background: var(--bg);
}

.file-list-panel h3 {
  margin: 0;
  padding: 16px 20px;
  font-size: 14px;
  font-weight: 600;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  border-bottom: 1px solid var(--border);
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.select-all-label {
  font-size: 12px;
  text-transform: none;
  letter-spacing: normal;
  font-weight: 500;
  color: var(--text-muted);
  display: flex;
  align-items: center;
  gap: 6px;
  cursor: pointer;
}

.select-all-label input[type="checkbox"] {
  cursor: pointer;
}

.file-list {
  flex: 1;
  overflow-y: auto;
  padding: 8px;
}

.file-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 6px;
  margin-bottom: 8px;
  cursor: pointer;
  transition: all 0.2s;
  position: relative;
}

.file-checkbox {
  flex-shrink: 0;
  width: 18px;
  height: 18px;
  cursor: pointer;
}

.file-item:hover {
  border-color: var(--border-strong);
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.05);
}

.file-item.selected {
  border-color: var(--primary);
  background: var(--primary-bg-subtle);
}

.file-icon {
  font-size: 24px;
  flex-shrink: 0;
}

.file-info {
  flex: 1;
  min-width: 0;
}

.file-name {
  font-size: 14px;
  font-weight: 500;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  display: flex;
  align-items: center;
  gap: 8px;
}

.kb-badge {
  font-size: 11px;
  padding: 2px 6px;
  background: var(--primary-bg);
  color: var(--primary-dark);
  border-radius: 3px;
  font-weight: 600;
  white-space: nowrap;
}

.file-meta {
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 2px;
}

.file-remove {
  background: none;
  border: none;
  color: var(--text-faint);
  font-size: 24px;
  cursor: pointer;
  width: 24px;
  height: 24px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 4px;
  flex-shrink: 0;
  transition: all 0.2s;
  line-height: 1;
  padding: 0;
}

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

.file-preview-panel {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.file-preview-panel h3 {
  margin: 0;
  padding: 16px 20px;
  font-size: 14px;
  font-weight: 600;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  border-bottom: 1px solid var(--border);
  background: var(--bg);
}

.file-preview {
  flex: 1;
  overflow-y: auto;
  padding: 20px;
}

.empty-state {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 100%;
  color: var(--text-faint);
  font-size: 14px;
  text-align: center;
  padding: 40px 20px;
}

.preview-content {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 16px;
  font-family: 'Consolas', 'Monaco', 'Courier New', monospace;
  font-size: 13px;
  line-height: 1.6;
  color: var(--text);
  overflow-x: auto;
  white-space: pre-wrap;
  word-break: break-word;
  margin: 0;
}

.url-preview {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.preview-label {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.url-link {
  color: var(--primary);
  text-decoration: none;
  font-size: 14px;
  word-break: break-all;
  padding: 8px 12px;
  background: var(--surface-2);
  border-radius: 4px;
  display: inline-block;
}

.url-link:hover {
  background: var(--border);
  text-decoration: underline;
}

.pdf-preview, .url-preview {
  text-align: center;
  padding: 40px 20px;
}

.pdf-preview p {
  margin: 8px 0;
  color: var(--text-secondary);
}

.preview-note {
  font-size: 13px;
  color: var(--text-faint);
  font-style: italic;
}

.file-modal-footer {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 16px 24px;
  border-top: 1px solid var(--border);
  background: var(--bg);
}

.file-modal-footer span {
  font-size: 14px;
  color: var(--text-muted);
  font-weight: 500;
}

.file-modal-footer button {
  padding: 8px 16px;
  margin-left: 10px;
  border-radius: 6px;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s ease;
  border: none;
  white-space: nowrap;
}

.file-modal-footer button:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.file-modal-footer #addToKBBtn {
  background: var(--primary);
  color: var(--surface);
}

.file-modal-footer #addToKBBtn:hover:not(:disabled) {
  background: var(--primary-hover);
}

.file-modal-footer #removeFromKBBtn {
  background: var(--text-muted);
  color: var(--surface);
}

.file-modal-footer #removeFromKBBtn:hover:not(:disabled) {
  background: var(--text-secondary);
}

.file-modal-footer #deleteFilesBtn {
  background: var(--danger-light);
  color: var(--surface);
}

.file-modal-footer #deleteFilesBtn:hover:not(:disabled) {
  background: var(--danger);
}

/* File item badges */
.kb-badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 4px;
  font-size: 11px;
  font-weight: 600;
  background: var(--primary-bg);
  color: var(--primary-dark);
  margin-right: 8px;
}

.appdata-badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 4px;
  font-size: 11px;
  font-weight: 600;
  background: #f3f4f6;
  color: #4b5563;
  margin-right: 8px;
}

/* Preview button in file list */
.preview-btn {
  padding: 6px 10px;
  border: 1px solid var(--border-strong);
  background: var(--surface);
  border-radius: 4px;
  cursor: pointer;
  font-size: 16px;
  transition: all 0.2s;
  opacity: 0;
  margin-left: auto;
}

.file-item:hover .preview-btn {
  opacity: 1;
}

.preview-btn:hover {
  background: var(--bg);
  border-color: var(--text-faint);
  transform: scale(1.1);
}

/* Loading and error states */
.loading-state, .error-state {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 200px;
  color: var(--text-muted);
  font-size: 14px;
}

.error-state {
  color: var(--danger-light);
}

.preview-placeholder {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 200px;
  color: var(--text-secondary);
  font-size: 14px;
  text-align: center;
}

.danger-btn:hover:not(:disabled) {
  background: var(--danger);
  border-color: var(--danger);
}

.secondary-btn {
  background: var(--surface-2);
  color: var(--text-secondary);
}

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

.primary-btn {
  background: var(--primary);
  color: var(--surface);
}

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

/* Responsive */
@media (max-width: 768px) {
  .file-main-content {
    flex-direction: column;
  }

  .file-list-panel {
    width: 100%;
    border-right: none;
    border-bottom: 1px solid var(--border);
    max-height: 40%;
  }

  .file-upload-controls {
    flex-direction: column;
    gap: 16px;
  }
  
  .file-upload-section, .url-upload-section {
    width: 100%;
    min-width: 100%;
  }
}

/* ============================================================
   API Reference Modal
   ============================================================ */

/* Scrollable content area */
.api-ref-content {
  overflow-y: auto;
  max-height: calc(80vh - 180px);
  padding-right: 4px;
}

.api-ref-layout {
  display: grid;
  grid-template-columns: 220px minmax(0, 1fr);
  gap: 20px;
}

.api-ref-main {
  min-width: 0;
}

.api-wiki-nav {
  position: sticky;
  top: 0;
  align-self: start;
  display: flex;
  flex-direction: column;
  gap: 6px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px;
}

.api-wiki-nav-title {
  font-size: 0.82em;
  font-weight: 700;
  color: var(--text-body);
  margin-bottom: 4px;
}

.api-wiki-nav a {
  display: block;
  text-decoration: none;
  color: var(--primary-hover);
  font-size: 0.84em;
  padding: 4px 6px;
  border-radius: 5px;
}

.api-wiki-nav a:hover {
  background: var(--primary-bg-subtle);
}

/* Intro block */
.api-ref-intro {
  padding: 10px 14px;
  background: var(--bg);
  border-radius: 6px;
  border: 1px solid var(--border);
  margin-bottom: 18px;
  font-size: 0.88em;
  line-height: 1.6;
}

.api-ref-intro code {
  background: var(--border);
  padding: 2px 5px;
  border-radius: 3px;
  font-size: 0.95em;
}

/* Section */
.api-section {
  margin-bottom: 28px;
}

.api-section-title {
  font-size: 1em;
  font-weight: 700;
  color: var(--text-strong);
  border-bottom: 2px solid var(--border);
  padding-bottom: 6px;
  margin-bottom: 4px;
  display: flex;
  align-items: center;
  gap: 8px;
}

.api-anchor-link {
  text-decoration: none;
  color: var(--primary-light);
  font-weight: 700;
  opacity: 0.4;
}

.api-section:hover .api-anchor-link,
.api-endpoint:hover .api-anchor-link {
  opacity: 1;
}

.api-section-desc {
  font-size: 0.85em;
  color: var(--text-muted);
  margin-bottom: 12px;
  margin-top: 0;
}

/* Endpoint entry */
.api-endpoint {
  margin-bottom: 16px;
}

.api-endpoint-header {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 4px;
  flex-wrap: wrap;
}

.api-endpoint-desc {
  font-size: 0.83em;
  color: var(--text-secondary);
  margin: 0 0 8px 0;
}

.api-path {
  font-size: 0.88em;
  font-family: monospace;
  background: var(--surface-2);
  padding: 2px 6px;
  border-radius: 4px;
  color: var(--text-strong);
}

/* HTTP method badges */
.api-method {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 4px;
  font-size: 0.75em;
  font-weight: 700;
  letter-spacing: 0.5px;
  text-transform: uppercase;
  min-width: 52px;
  text-align: center;
  color: var(--surface);
  flex-shrink: 0;
}

.api-method-post   { background: #16a34a; }
.api-method-get    { background: var(--primary); }
.api-method-put    { background: var(--warning-hover); }
.api-method-delete { background: var(--danger); }
.api-method-—      { background: #6b7280; }

/* Code block */
.api-code-block {
  position: relative;
  background: var(--text);
  border-radius: 6px;
  overflow: hidden;
}

.api-code-block pre {
  margin: 0;
  padding: 14px 14px 14px 14px;
  overflow-x: auto;
  font-size: 0.78em;
  line-height: 1.55;
  color: var(--border);
  font-family: 'Fira Code', 'Cascadia Code', 'Consolas', monospace;
  white-space: pre;
  tab-size: 2;
  max-height: 340px;
  overflow-y: auto;
}

.api-copy-btn {
  position: absolute;
  top: 8px;
  right: 8px;
  padding: 3px 10px;
  font-size: 0.75em;
  background: var(--text-body);
  color: var(--border-strong);
  border: 1px solid var(--text-secondary);
  border-radius: 4px;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
  z-index: 1;
}

.api-copy-btn:hover {
  background: var(--text-secondary);
  color: var(--surface-2);
}

.api-copy-btn.copied {
  background: #16a34a;
  color: var(--surface);
  border-color: #15803d;
}

.api-action-btn {
  padding: 6px 12px;
  font-size: 0.8em;
  background: var(--primary-hover);
  color: var(--surface);
  border: 1px solid var(--primary-dark);
  border-radius: 6px;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s;
}

.api-action-btn:hover:not(:disabled) {
  background: var(--primary-dark);
  border-color: #1e3a8a;
}

.api-action-btn:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

/* Agents table */
.api-agents-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.85em;
  margin-top: 4px;
}

.api-agents-table th,
.api-agents-table td {
  text-align: left;
  padding: 7px 10px;
  border-bottom: 1px solid var(--border);
}

.api-agents-table th {
  background: var(--surface-2);
  font-weight: 600;
  color: #374151;
}

.api-agents-table td code {
  background: var(--border);
  padding: 2px 5px;
  border-radius: 3px;
  font-size: 0.95em;
}

.api-agents-table tr:last-child td {
  border-bottom: none;
}

.api-ref-page-body {
  margin: 0;
  background: var(--bg);
}

.api-ref-page-wrap {
  max-width: 1200px;
  margin: 0 auto;
  padding: 24px;
}

.api-ref-page-header {
  margin-bottom: 16px;
}

.api-ref-page-header h1 {
  margin: 0;
  font-size: 1.5rem;
  color: var(--text);
}

.api-ref-page-header p {
  margin: 8px 0 0 0;
  color: var(--text-secondary);
  font-size: 0.95rem;
}

.api-ref-standalone-content {
  max-height: none;
  overflow: visible;
  padding-right: 0;
}

@media (max-width: 960px) {
  .api-ref-layout {
    grid-template-columns: 1fr;
  }

  .api-wiki-nav {
    position: static;
  }
}

/* ===== Billing ===== */
.billing-badge {
  background: #1e3a5f;
  color: var(--primary-border);
  border: 1px solid var(--primary-light);
  border-radius: 6px;
  padding: 4px 10px;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
  transition: background 0.15s;
}
.billing-badge:hover { background: var(--primary); color: var(--surface); }
.billing-badge.low-credits { border-color: var(--warning); color: #fbbf24; }

.modal-overlay {
  position: fixed;
  z-index: 2000;
  inset: 0;
  background: rgba(0,0,0,0.55);
  display: flex;
  align-items: center;
  justify-content: center;
}
.billing-modal {
  background: var(--surface);
  border-radius: 10px;
  width: 90%;
  max-width: 520px;
  box-shadow: 0 8px 32px rgba(0,0,0,0.2);
  overflow: hidden;
}
.billing-modal .modal-header {
  background: var(--text);
  color: var(--surface);
  padding: 14px 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.billing-modal .modal-header h2 { margin: 0; font-size: 16px; }
.billing-modal .modal-close {
  background: none; border: none; color: var(--text-faint); font-size: 18px;
  cursor: pointer; padding: 0 4px; line-height: 1;
}
.billing-modal .modal-close:hover { color: var(--surface); }
.billing-body { padding: 18px 20px; display: flex; flex-direction: column; gap: 16px; }
.billing-section { border: 1px solid var(--border); border-radius: 8px; padding: 14px; }
.billing-section h3 { margin: 0 0 10px; font-size: 13px; text-transform: uppercase; letter-spacing: .05em; color: var(--text-muted); }
.billing-tier-row { display: flex; align-items: center; justify-content: space-between; }
.billing-tier-name { font-size: 18px; font-weight: 700; color: var(--text); }
.billing-tier-badge { background: var(--primary-bg); color: var(--primary-dark); border-radius: 4px; padding: 2px 8px; font-size: 11px; font-weight: 600; }
.billing-tier-badge.pro { background: #fef9c3; color: #92400e; }
.billing-credits { font-size: 28px; font-weight: 800; color: var(--text); }
.billing-credits-sub { font-size: 12px; color: var(--text-muted); margin-top: 2px; }
.billing-usage-row { display: flex; justify-content: space-between; font-size: 13px; color: var(--text-body); padding: 3px 0; }
.billing-usage-bar { height: 6px; background: var(--border); border-radius: 3px; margin-top: 6px; overflow: hidden; }
.billing-usage-fill { height: 100%; background: var(--primary); border-radius: 3px; transition: width 0.3s; }
.billing-usage-fill.warning { background: var(--warning); }
.billing-usage-fill.danger { background: var(--danger-light); }
.billing-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.billing-actions button { flex: 1; min-width: 120px; padding: 8px 12px; border-radius: 6px; border: none; cursor: pointer; font-size: 13px; font-weight: 600; }
.billing-actions .btn-primary { background: var(--primary); color: var(--surface); }
.billing-actions .btn-primary:hover { background: var(--primary-hover); }
.billing-actions .btn-secondary { background: var(--surface-2); color: var(--text-body); border: 1px solid var(--border-strong); }
.billing-actions .btn-secondary:hover { background: var(--border); }
.billing-actions .btn-upgrade { background: var(--warning); color: var(--surface); }
.billing-actions .btn-upgrade:hover { background: var(--warning-hover); }
.billing-input-row { display: flex; gap: 8px; align-items: center; }
.billing-input-row input { flex: 1; padding: 7px 10px; border: 1px solid var(--border-strong); border-radius: 6px; font-size: 14px; }
.billing-msg { font-size: 13px; padding: 8px 12px; border-radius: 6px; }
.billing-msg.success { background: var(--success-bg); color: #166534; }
.billing-msg.error { background: var(--danger-bg); color: var(--danger-dark); }
