/* ============================================================
   BENTO AI Buddy — Panel Styles
   Uses existing IDE CSS variables for theme consistency
   ============================================================ */

/* --- Panel Container --- */
.buddy-panel {
  position: fixed;
  right: 0;
  top: var(--header-height, 54px);
  height: calc(100vh - var(--header-height, 54px) - var(--statusbar-height, 26px));
  width: 520px;
  min-width: 360px;
  max-width: 800px;
  background: var(--bg-surface, #ffffff);
  border-left: 1px solid var(--border-color, #e5e7eb);
  box-shadow: var(--shadow-lg, -4px 0 20px rgba(0,0,0,0.15));
  z-index: 1000;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  transform: translateX(100%);
  transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  font-family: var(--font-sans, 'Inter', sans-serif);
}

.buddy-panel.visible {
  transform: translateX(0);
}

.buddy-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.3);
  z-index: 999;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s ease;
}

.buddy-overlay.visible {
  opacity: 1;
  pointer-events: auto;
}

/* --- Resize Handle --- */
.buddy-resize-handle {
  position: absolute;
  left: -3px;
  top: 0;
  bottom: 0;
  width: 6px;
  cursor: col-resize;
  z-index: 1001;
  background: transparent;
}

.buddy-resize-handle:hover,
.buddy-resize-handle:active {
  background: var(--tesa-primary, #7239ea);
  opacity: 0.4;
}

/* --- Header --- */
.buddy-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 14px;
  border-bottom: 1px solid var(--border-color, #e5e7eb);
  background: var(--bg-elevated, #ffffff);
  flex-shrink: 0;
}

.buddy-header-left {
  display: flex;
  align-items: center;
  gap: 10px;
}

.buddy-header-right {
  display: flex;
  align-items: center;
  gap: 6px;
}

.buddy-avatar {
  width: 32px;
  height: 32px;
  flex-shrink: 0;
}

.buddy-avatar-svg {
  display: block;
}

.buddy-title {
  font-size: 14px;
  font-weight: 700;
  color: var(--text-primary, #111827);
  display: block;
}

.buddy-subtitle {
  font-size: 11px;
  color: var(--text-secondary, #6b7280);
  display: block;
  margin-top: 1px;
}

.buddy-btn-icon {
  width: 28px;
  height: 28px;
  border: none;
  background: transparent;
  border-radius: var(--border-radius-sm, 6px);
  color: var(--text-secondary, #6b7280);
  font-size: 18px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.15s;
}

.buddy-btn-icon:hover {
  background: var(--bg-muted, #f1f3f5);
  color: var(--text-primary, #111827);
}

/* --- Pin Button --- */
.buddy-pin-btn.pinned {
  color: var(--tesa-primary, #7239ea);
  background: rgba(114, 57, 234, 0.1);
}

/* When pinned, overlay is invisible so user can interact with editor */
.buddy-overlay.buddy-overlay-hidden {
  opacity: 0 !important;
  pointer-events: none !important;
}

/* --- Language Switch (TH | EN) --- */
.buddy-lang-switch {
  display: flex;
  border: 1px solid var(--border-color, #e5e7eb);
  border-radius: 6px;
  overflow: hidden;
  flex-shrink: 0;
}

.buddy-lang-btn {
  padding: 2px 8px;
  border: none;
  background: transparent;
  color: var(--text-tertiary, #9ca3af);
  font-size: 11px;
  font-weight: 600;
  font-family: var(--font-sans, 'Inter', sans-serif);
  cursor: pointer;
  transition: all 0.15s;
  line-height: 1.4;
}

.buddy-lang-btn + .buddy-lang-btn {
  border-left: 1px solid var(--border-color, #e5e7eb);
}

.buddy-lang-btn:hover {
  background: var(--bg-muted, #f1f3f5);
  color: var(--text-primary, #111827);
}

.buddy-lang-btn.active {
  background: var(--tesa-primary, #7239ea);
  color: #fff;
}

/* --- Confidence Dot --- */
.buddy-confidence {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 2px 8px;
  border-radius: 12px;
  font-size: 11px;
  color: var(--text-secondary, #6b7280);
}

.buddy-confidence-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--text-tertiary, #9ca3af);
  transition: background-color 0.3s;
}

.buddy-confidence-dot[data-tier="high"]   { background: #4CAF50; }
.buddy-confidence-dot[data-tier="medium"] { background: #FF9800; }
.buddy-confidence-dot[data-tier="low"]    { background: #F44336; }

/* --- Info Bar (Board + Model badges) --- */
.buddy-info-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 14px;
  border-bottom: 1px solid var(--border-color, #e5e7eb);
  background: var(--bg-muted, #f1f3f5);
  flex-shrink: 0;
  flex-wrap: wrap;
}

.buddy-badge {
  display: inline-flex;
  align-items: center;
  padding: 4px 12px;
  border-radius: 16px;
  font-size: 12px;
  font-weight: 500;
  border: 1px solid var(--border-color, #e5e7eb);
  background: var(--bg-surface, #ffffff);
  color: var(--text-secondary, #6b7280);
}

.buddy-badge-board {
  background: rgba(114, 57, 234, 0.08);
  border-color: rgba(114, 57, 234, 0.2);
  color: var(--tesa-primary, #7239ea);
}

.buddy-badge-model {
  background: rgba(88, 166, 255, 0.08);
  border-color: rgba(88, 166, 255, 0.2);
  color: #58a6ff;
}

/* --- Quota Bar --- */
.buddy-quota-bar {
  height: 24px;
  padding: 0 14px;
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 11px;
  color: var(--text-tertiary, #9ca3af);
  border-bottom: 1px solid var(--border-color, #e5e7eb);
  background: var(--bg-elevated, #ffffff);
  flex-shrink: 0;
}

.quota-fill-track {
  flex: 1;
  height: 4px;
  background: var(--bg-muted, #f1f3f5);
  border-radius: 2px;
  overflow: hidden;
}

.quota-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--tesa-primary, #7239ea), #9b6ef3);
  border-radius: 2px;
  transition: width 0.3s;
  width: 0%;
}

/* --- Messages Area --- */
.buddy-messages {
  flex: 1;
  min-height: 0; /* CRITICAL: allows flex child to shrink below content height → enables scroll */
  overflow-y: auto;
  overflow-x: hidden;
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  min-width: 0;
}

.buddy-messages::-webkit-scrollbar {
  width: 6px;
}

.buddy-messages::-webkit-scrollbar-thumb {
  background: var(--border-color, #e5e7eb);
  border-radius: 3px;
}

/* --- Message Bubbles --- */
.buddy-message {
  display: flex;
  gap: 8px;
  max-width: 95%;
  min-width: 0;
  flex-shrink: 0; /* Prevent messages from shrinking — forces overflow → enables scroll */
  overflow: hidden;
  animation: buddyFadeIn 0.2s ease;
}

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

.buddy-message.user {
  align-self: flex-end;
  flex-direction: row-reverse;
}

.buddy-message.assistant {
  align-self: flex-start;
}

.buddy-message-bubble {
  padding: 10px 14px;
  border-radius: 12px;
  font-size: 13px;
  line-height: 1.5;
  word-break: break-word;
  overflow: hidden;
  min-width: 0;
  max-width: 100%;
}

.buddy-message.user .buddy-message-bubble {
  background: var(--tesa-primary, #7239ea);
  color: #fff;
  border-bottom-right-radius: 4px;
}

.buddy-message.assistant .buddy-message-bubble {
  background: var(--bg-muted, #f1f3f5);
  color: var(--text-primary, #111827);
  border-bottom-left-radius: 4px;
}

/* --- Code Blocks in Messages --- */
.buddy-message-bubble pre {
  background: var(--bg-code, #1e1e2d);
  color: var(--text-code, #d4d4d4);
  padding: 12px;
  border-radius: 8px;
  overflow-x: auto;
  font-family: var(--font-mono, 'JetBrains Mono', monospace);
  font-size: 12px;
  line-height: 1.5;
  margin: 8px 0;
  position: relative;
  max-width: 100%;
  box-sizing: border-box;
}

.buddy-message-bubble pre code {
  background: transparent;
  padding: 0;
  font-size: inherit;
  white-space: pre-wrap;
  word-break: break-all;
}

.buddy-message-bubble code {
  background: rgba(0,0,0,0.08);
  padding: 2px 5px;
  border-radius: 4px;
  font-family: var(--font-mono, 'JetBrains Mono', monospace);
  font-size: 12px;
}

.buddy-message.user .buddy-message-bubble code {
  background: rgba(255,255,255,0.2);
}

/* --- Python Syntax Highlighting (dark theme) --- */
.buddy-message-bubble pre .py-kw   { color: #c586c0; }  /* keywords: purple */
.buddy-message-bubble pre .py-bi   { color: #dcdcaa; }  /* builtins: yellow */
.buddy-message-bubble pre .py-str  { color: #ce9178; }  /* strings: orange */
.buddy-message-bubble pre .py-cmt  { color: #6a9955; font-style: italic; }  /* comments: green */
.buddy-message-bubble pre .py-num  { color: #b5cea8; }  /* numbers: light green */
.buddy-message-bubble pre .py-dec  { color: #dcdcaa; }  /* decorators: yellow */
.buddy-message-bubble pre .py-self { color: #9cdcfe; font-style: italic; }  /* self: light blue */

/* --- Feedback Buttons (Thumbs Up / Down) --- */
.buddy-feedback {
  display: flex;
  gap: 4px;
  margin-top: 4px;
  opacity: 0;
  transition: opacity 0.15s;
}

.buddy-message.assistant:hover .buddy-feedback,
.buddy-feedback:has(.selected-up),
.buddy-feedback:has(.selected-down) {
  opacity: 1;
}

.buddy-feedback-btn {
  width: 24px;
  height: 24px;
  border: none;
  border-radius: 6px;
  background: transparent;
  color: var(--text-tertiary, #9ca3af);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.15s;
}

.buddy-feedback-btn:hover {
  background: var(--bg-muted, #f1f3f5);
  color: var(--text-secondary, #6b7280);
}

.buddy-feedback-btn.selected-up {
  color: #22c55e;
  background: rgba(34, 197, 94, 0.1);
}

.buddy-feedback-btn.selected-down {
  color: #ef4444;
  background: rgba(239, 68, 68, 0.1);
}

/* --- Code Action Buttons --- */
.buddy-code-actions {
  display: flex;
  gap: 4px;
  margin-top: 6px;
  flex-wrap: wrap;
}

.buddy-code-action-btn {
  padding: 3px 10px;
  border: 1px solid var(--border-color, #e5e7eb);
  border-radius: 6px;
  background: var(--bg-surface, #fff);
  color: var(--text-secondary, #6b7280);
  font-size: 11px;
  cursor: pointer;
  transition: all 0.15s;
  font-family: var(--font-sans, 'Inter', sans-serif);
}

.buddy-code-action-btn:hover {
  background: var(--tesa-primary-subtle, #f5f0ff);
  color: var(--tesa-primary, #7239ea);
  border-color: var(--tesa-primary, #7239ea);
}

.buddy-code-action-btn.buddy-copied {
  background: #e8f5e9;
  color: #2e7d32;
  border-color: #66bb6a;
}

/* --- Typing Indicator --- */
.buddy-typing {
  display: flex;
  gap: 4px;
  padding: 10px 14px;
  align-items: center;
}

.buddy-typing-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--text-tertiary, #9ca3af);
  animation: buddyBounce 1.4s ease-in-out infinite;
}

.buddy-typing-dot:nth-child(2) { animation-delay: 0.16s; }
.buddy-typing-dot:nth-child(3) { animation-delay: 0.32s; }

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

/* --- Quick Actions Bar --- */
.buddy-quick-actions {
  display: flex;
  gap: 6px;
  padding: 8px 14px;
  border-top: 1px solid var(--border-color, #e5e7eb);
  background: var(--bg-elevated, #ffffff);
  flex-shrink: 0;
  flex-wrap: wrap;
}

.buddy-quick-btn {
  padding: 5px 12px;
  border: 1px solid var(--border-color, #e5e7eb);
  border-radius: 16px;
  background: transparent;
  color: var(--text-secondary, #6b7280);
  font-size: 12px;
  cursor: pointer;
  font-family: var(--font-sans, 'Inter', sans-serif);
  transition: all 0.15s;
  white-space: nowrap;
}

.buddy-quick-btn:hover {
  background: var(--tesa-primary-subtle, #f5f0ff);
  border-color: var(--tesa-primary, #7239ea);
  color: var(--tesa-primary, #7239ea);
}

/* --- Input Area --- */
.buddy-input-area {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  padding: 10px 14px;
  border-top: 1px solid var(--border-color, #e5e7eb);
  background: var(--bg-elevated, #ffffff);
  flex-shrink: 0;
}

.buddy-input-area textarea {
  flex: 1;
  border: 1px solid var(--border-color, #e5e7eb);
  border-radius: 10px;
  padding: 8px 12px;
  font-size: 13px;
  font-family: var(--font-sans, 'Inter', sans-serif);
  resize: none;
  outline: none;
  background: var(--bg-surface, #ffffff);
  color: var(--text-primary, #111827);
  min-height: 36px;
  max-height: 120px;
  line-height: 1.4;
  transition: border-color 0.15s;
}

.buddy-input-area textarea:focus {
  border-color: var(--tesa-primary, #7239ea);
  box-shadow: 0 0 0 3px rgba(114, 57, 234, 0.12);
}

.buddy-send-btn {
  width: 36px;
  height: 36px;
  border: none;
  border-radius: 10px;
  background: var(--tesa-primary, #7239ea);
  color: #fff;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: background 0.15s;
}

.buddy-send-btn:hover {
  background: var(--tesa-primary-hover, #5f2bc7);
}

.buddy-send-btn:disabled {
  background: var(--text-tertiary, #9ca3af);
  cursor: not-allowed;
}

/* --- Footer Bar --- */
.buddy-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 6px 14px;
  border-top: 1px solid var(--border-color, #e5e7eb);
  background: var(--bg-elevated, #ffffff);
  flex-shrink: 0;
}

.buddy-status {
  font-size: 11px;
  color: var(--green, #3fb950);
  font-weight: 500;
}

.buddy-footer-actions {
  display: flex;
  gap: 6px;
}

.buddy-footer-btn {
  padding: 4px 10px;
  border: 1px solid var(--border-color, #e5e7eb);
  border-radius: 6px;
  background: transparent;
  color: var(--text-secondary, #6b7280);
  font-size: 11px;
  cursor: pointer;
  font-family: var(--font-sans, 'Inter', sans-serif);
  transition: all 0.15s;
}

.buddy-footer-btn:hover {
  background: var(--tesa-primary-subtle, #f5f0ff);
  color: var(--tesa-primary, #7239ea);
  border-color: var(--tesa-primary, #7239ea);
}

/* --- Welcome Message --- */
.buddy-welcome {
  padding: 20px 10px;
  color: var(--text-secondary, #6b7280);
}

.buddy-welcome-card {
  background: var(--bg-muted, #f1f3f5);
  border-radius: 12px;
  padding: 24px;
  margin-bottom: 16px;
}

.buddy-welcome-card h3 {
  font-size: 16px;
  font-weight: 700;
  color: var(--text-primary, #111827);
  margin-bottom: 10px;
}

.buddy-welcome-card p {
  font-size: 13px;
  line-height: 1.6;
  margin: 4px 0;
  color: var(--text-secondary, #6b7280);
}

.buddy-suggestions {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.buddy-suggestion {
  padding: 10px 14px;
  border: 1px solid var(--border-color, #e5e7eb);
  border-radius: 10px;
  font-size: 13px;
  color: var(--text-secondary, #6b7280);
  cursor: pointer;
  text-align: left;
  background: transparent;
  font-family: var(--font-sans, 'Inter', sans-serif);
  transition: all 0.15s;
}

.buddy-suggestion:hover {
  background: var(--tesa-primary-subtle, #f5f0ff);
  border-color: var(--tesa-primary, #7239ea);
  color: var(--tesa-primary, #7239ea);
}

/* --- Avatar Expression States --- */
.buddy-avatar.buddy-thinking .buddy-eye { animation: buddyBlink 0.6s infinite; }
.buddy-avatar.buddy-happy .buddy-mouth { rx: 3; ry: 1; }
.buddy-avatar.buddy-error .buddy-eye-left { transform: rotate(-10deg); transform-origin: center; }
.buddy-avatar.buddy-error .buddy-eye-right { transform: rotate(10deg); transform-origin: center; }
.buddy-avatar.buddy-sleeping .buddy-eye { height: 1px; }
.buddy-avatar.buddy-celebrating { animation: buddyCelebrate 0.5s ease; }

@keyframes buddyBlink {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.2; }
}

@keyframes buddyCelebrate {
  0%, 100% { transform: translateY(0); }
  25% { transform: translateY(-4px); }
  75% { transform: translateY(-2px); }
}

/* --- Validation Card (displayed as separate message below) --- */
.buddy-validation-card {
  border-radius: 8px;
  padding: 10px 14px;
  font-size: 12px;
  line-height: 1.6;
}

.buddy-validation-card.warning {
  background: #fff8e1;
  border-left: 3px solid #ff9800;
  color: #5d4037;
}

.buddy-validation-card.error {
  background: #fce4ec;
  border-left: 3px solid #e53935;
  color: #b71c1c;
}

.buddy-validation-header {
  font-size: 12px;
  margin-bottom: 4px;
}

.buddy-validation-body {
  font-size: 12px;
}

.buddy-validation-body code {
  background: rgba(0,0,0,0.07);
  padding: 1px 4px;
  border-radius: 3px;
  font-family: 'Fira Code', 'Consolas', monospace;
  font-size: 11px;
}

/* Legacy inline validation (system messages) */
.buddy-validation.warning { background: #fff3e0; color: #e65100; display: inline-flex; padding: 2px 8px; border-radius: 10px; font-size: 11px; }

/* --- Quick Fix Banner --- */
.buddy-quickfix {
  background: #fff3e0;
  border: 1px solid #ffcc80;
  border-radius: 8px;
  padding: 8px 12px;
  margin: 4px 0;
  font-size: 12px;
  color: #e65100;
}

.buddy-quickfix code {
  background: rgba(0,0,0,0.06);
  padding: 1px 4px;
  border-radius: 3px;
}

/* --- Toolbar Button for Buddy --- */
.buddy-toolbar-btn {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 4px 10px;
  border: none;
  border-radius: var(--border-radius-sm, 6px);
  background: var(--tesa-primary, #7239ea);
  color: #fff;
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.15s;
  font-family: var(--font-sans, 'Inter', sans-serif);
}

.buddy-toolbar-btn:hover {
  background: var(--tesa-primary-hover, #5f2bc7);
}

.buddy-toolbar-btn svg {
  width: 16px;
  height: 16px;
}

/* --- Markdown Styles in Messages --- */
.buddy-message-bubble h1, .buddy-message-bubble h2, .buddy-message-bubble h3 {
  margin: 8px 0 4px;
  font-size: 14px;
  font-weight: 600;
}

.buddy-message-bubble ul, .buddy-message-bubble ol {
  margin: 4px 0;
  padding-left: 18px;
}

.buddy-message-bubble li {
  margin: 2px 0;
}

.buddy-message-bubble p {
  margin: 4px 0;
}

.buddy-message-bubble a {
  color: var(--tesa-primary, #7239ea);
  text-decoration: underline;
}

.buddy-message-bubble table {
  border-collapse: collapse;
  width: 100%;
  margin: 8px 0;
  font-size: 12px;
}

.buddy-message-bubble th, .buddy-message-bubble td {
  border: 1px solid var(--border-color, #e5e7eb);
  padding: 4px 8px;
  text-align: left;
}

.buddy-message-bubble th {
  background: var(--bg-muted, #f1f3f5);
  font-weight: 600;
}

/* ═══════════════ Conversation History Drawer ═══════════════ */
.buddy-history-drawer {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: var(--bg-main, #fff);
  z-index: 50;
  display: flex;
  flex-direction: column;
  transform: translateX(-100%);
  transition: transform 0.25s cubic-bezier(0.4, 0, 0.2, 1);
}

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

.buddy-history-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px;
  border-bottom: 1px solid var(--border-color, #e5e7eb);
  font-weight: 600;
  font-size: 15px;
}

.buddy-history-search {
  padding: 10px 16px;
  border-bottom: 1px solid var(--border-color, #e5e7eb);
}

.buddy-history-search-input {
  width: 100%;
  padding: 8px 12px;
  border: 1px solid var(--border-color, #e5e7eb);
  border-radius: 8px;
  font-size: 13px;
  font-family: inherit;
  background: var(--bg-muted, #f1f3f5);
  color: var(--text-primary, #111827);
  outline: none;
  transition: border-color 0.15s;
}

.buddy-history-search-input:focus {
  border-color: var(--tesa-primary, #7239ea);
  box-shadow: 0 0 0 2px var(--tesa-primary-subtle, #f5f0ff);
}

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

.buddy-history-empty {
  text-align: center;
  padding: 40px 20px;
  color: var(--text-secondary, #6b7280);
  font-size: 13px;
}

.buddy-history-item {
  display: flex;
  align-items: center;
  border-radius: 8px;
  cursor: pointer;
  transition: background 0.15s;
  margin-bottom: 2px;
}

.buddy-history-item-content {
  flex: 1;
  min-width: 0;
  padding: 12px 8px 12px 14px;
}

.buddy-history-item:hover {
  background: var(--bg-muted, #f1f3f5);
}

.buddy-history-item.active {
  background: var(--tesa-primary-subtle, #f5f0ff);
  border-left: 3px solid var(--tesa-primary, #7239ea);
}

.buddy-history-delete {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  border: none;
  border-radius: 6px;
  background: transparent;
  color: var(--text-secondary, #6b7280);
  cursor: pointer;
  opacity: 0;
  transition: opacity 0.15s, background 0.15s, color 0.15s;
  margin-right: 8px;
}

.buddy-history-item:hover .buddy-history-delete {
  opacity: 1;
}

.buddy-history-delete:hover {
  background: var(--danger-bg, #fef2f2);
  color: var(--danger, #ef4444);
}

.buddy-history-item-title {
  font-size: 13px;
  font-weight: 500;
  color: var(--text-primary, #111827);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin-bottom: 4px;
}

.buddy-history-item-meta {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 11px;
  color: var(--text-secondary, #6b7280);
}

.buddy-history-intent {
  background: var(--tesa-primary-subtle, #f5f0ff);
  color: var(--tesa-primary, #7239ea);
  padding: 1px 6px;
  border-radius: 8px;
  font-size: 10px;
  font-weight: 600;
  text-transform: uppercase;
}

/* ═══════════════ Auto-fix Confirm Dialog ═══════════════ */
.buddy-fix-confirm {
  background: var(--bg-main, #fff);
  border: 1px solid var(--tesa-primary, #7239ea);
  border-radius: 10px;
  margin: 8px 0;
  overflow: hidden;
  box-shadow: 0 4px 16px rgba(114, 57, 234, 0.15);
  max-width: 100%;
  box-sizing: border-box;
}

.buddy-fix-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 14px;
  background: var(--bg-muted, #f1f3f5);
  border-bottom: 1px solid var(--border-color, #e5e7eb);
}

.buddy-fix-title {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-primary, #111827);
}

.buddy-diff-preview {
  max-height: 200px;
  overflow-y: auto;
  font-family: 'Fira Code', 'Consolas', monospace;
  font-size: 11px;
  line-height: 1.6;
  border-bottom: 1px solid var(--border-color, #e5e7eb);
}

.buddy-diff-preview > div {
  padding: 1px 12px 1px 8px;
  white-space: pre-wrap;
  word-break: break-all;
}

.buddy-diff-prefix {
  display: inline-block;
  width: 14px;
  font-weight: 700;
  user-select: none;
}

.buddy-diff-added {
  background: #e6ffed;
  color: #22863a;
}

.buddy-diff-removed {
  background: #ffeef0;
  color: #cb2431;
  text-decoration: line-through;
  opacity: 0.7;
}

.buddy-diff-same {
  color: var(--text-secondary, #6b7280);
}

.buddy-fix-summary {
  padding: 8px 14px;
  font-size: 11px;
  color: var(--text-secondary, #6b7280);
  line-height: 1.5;
}

.buddy-fix-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  padding: 10px 14px;
  border-top: 1px solid var(--border-color, #e5e7eb);
}

.buddy-fix-cancel {
  padding: 6px 14px;
  border: 1px solid var(--border-color, #e5e7eb);
  border-radius: 6px;
  background: transparent;
  color: var(--text-secondary, #6b7280);
  font-size: 12px;
  cursor: pointer;
  font-family: inherit;
}

.buddy-fix-cancel:hover { background: var(--bg-muted, #f1f3f5); }

.buddy-fix-apply {
  padding: 6px 14px;
  border: none;
  border-radius: 6px;
  background: var(--tesa-primary, #7239ea);
  color: #fff;
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  font-family: inherit;
  transition: background 0.15s;
}

.buddy-fix-apply:hover { background: var(--tesa-primary-hover, #5f2bc7); }

.buddy-action-fix {
  background: var(--tesa-primary, #7239ea) !important;
  color: #fff !important;
  border-color: var(--tesa-primary, #7239ea) !important;
}

.buddy-action-fix:hover {
  background: var(--tesa-primary-hover, #5f2bc7) !important;
}

.buddy-action-applied {
  background: #4caf50 !important;
  border-color: #4caf50 !important;
  color: #fff !important;
  opacity: 0.7;
  cursor: default !important;
  pointer-events: none;
}

/* ═══════════════ Usage Stats Popup ═══════════════ */
.buddy-stats-popup {
  background: var(--bg-main, #fff);
  border: 1px solid var(--border-color, #e5e7eb);
  border-radius: 10px;
  margin: 8px 12px;
  overflow: hidden;
  box-shadow: 0 4px 16px rgba(0,0,0,0.1);
  animation: buddySlideDown 0.2s ease;
}

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

.buddy-stats-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 14px;
  background: var(--bg-muted, #f1f3f5);
  border-bottom: 1px solid var(--border-color, #e5e7eb);
  font-weight: 600;
  font-size: 13px;
}

.buddy-stats-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  padding: 14px;
}

.buddy-stat-item {
  text-align: center;
}

.buddy-stat-value {
  font-size: 20px;
  font-weight: 700;
  color: var(--text-primary, #111827);
}

.buddy-stat-label {
  font-size: 11px;
  color: var(--text-secondary, #6b7280);
  margin-top: 2px;
}

.buddy-stat-bar {
  height: 4px;
  background: var(--bg-muted, #f1f3f5);
  border-radius: 2px;
  margin-top: 6px;
  overflow: hidden;
}

.buddy-stat-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--tesa-primary, #7239ea), #9b6ef3);
  border-radius: 2px;
  transition: width 0.3s ease;
}

.buddy-stat-cap {
  font-size: 10px;
  color: var(--text-secondary, #6b7280);
  margin-top: 2px;
}

.buddy-stats-role {
  padding: 8px 14px;
  border-top: 1px solid var(--border-color, #e5e7eb);
  font-size: 11px;
  color: var(--text-secondary, #6b7280);
  text-align: center;
}

.buddy-stats-reset {
  padding: 6px 14px;
  font-size: 10px;
  color: var(--text-tertiary, #9ca3af);
  text-align: center;
  border-top: 1px solid var(--border-color, #e5e7eb);
}

.buddy-quota-bar {
  cursor: pointer;
}

/* --- Progressive Disclosure: Quota Fill Levels --- */
.quota-fill.quota-level-0 {
  background: linear-gradient(90deg, #22c55e, #4ade80);
}
.quota-fill.quota-level-1 {
  background: linear-gradient(90deg, var(--tesa-primary, #7239ea), #9b6ef3);
}
.quota-fill.quota-level-2 {
  background: linear-gradient(90deg, #f59e0b, #fbbf24);
}
.quota-fill.quota-level-3 {
  background: linear-gradient(90deg, #ef4444, #f87171);
}

/* --- Guest Sign-In CTA --- */
.buddy-guest-cta {
  padding: 4px 14px 6px;
  text-align: center;
  font-size: 11px;
  background: var(--bg-elevated, #ffffff);
}
.buddy-guest-cta a {
  color: var(--tesa-primary, #7239ea);
  text-decoration: none;
  font-weight: 600;
}
.buddy-guest-cta a:hover {
  text-decoration: underline;
}

/* ═══════════════ Knowledge Trace View ═══════════════ */
.buddy-knowledge-trace {
  margin-top: 8px;
  border-radius: 8px;
  overflow: hidden;
  border: 1px solid var(--border-color, #e5e7eb);
}

.buddy-trace-toggle {
  display: flex;
  align-items: center;
  gap: 6px;
  width: 100%;
  padding: 6px 10px;
  border: none;
  background: var(--bg-muted, #f1f3f5);
  color: var(--text-secondary, #6b7280);
  font-size: 11px;
  cursor: pointer;
  font-family: var(--font-sans, 'Inter', sans-serif);
  transition: background 0.15s;
  text-align: left;
}

.buddy-trace-toggle:hover {
  background: var(--bg-elevated, #e8e9eb);
}

.buddy-trace-toggle.open {
  border-bottom: 1px solid var(--border-color, #e5e7eb);
}

.buddy-trace-icon {
  font-size: 13px;
}

.buddy-trace-badge {
  display: inline-block;
  padding: 1px 6px;
  border-radius: 8px;
  font-size: 10px;
  font-weight: 600;
}

.buddy-trace-badge.fw {
  background: rgba(255, 152, 0, 0.12);
  color: #e65100;
}

.buddy-trace-badge.kb {
  background: rgba(114, 57, 234, 0.1);
  color: var(--tesa-primary, #7239ea);
}

.buddy-trace-details {
  max-height: 200px;
  overflow-y: auto;
  background: var(--bg-surface, #fff);
}

.buddy-trace-item {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px;
  font-size: 11px;
  border-bottom: 1px solid var(--border-color, #e5e7eb);
}

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

.buddy-trace-type {
  display: inline-block;
  min-width: 28px;
  padding: 1px 4px;
  border-radius: 4px;
  font-size: 9px;
  font-weight: 700;
  text-align: center;
  text-transform: uppercase;
  flex-shrink: 0;
}

.buddy-trace-type.firmware { background: #fff3e0; color: #e65100; }
.buddy-trace-type.example { background: #e8f5e9; color: #2e7d32; }
.buddy-trace-type.api_function { background: #e3f2fd; color: #1565c0; }
.buddy-trace-type.error_fix { background: #fbe9e7; color: #c62828; }
.buddy-trace-type.tutorial { background: #f3e5f5; color: #7b1fa2; }
.buddy-trace-type.board { background: #e0f2f1; color: #00695c; }
.buddy-trace-type.offline_qa { background: #eceff1; color: #455a64; }

.buddy-trace-title {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--text-primary, #111827);
}

.buddy-trace-score {
  flex-shrink: 0;
  font-weight: 600;
  padding: 1px 5px;
  border-radius: 6px;
  font-size: 10px;
}

.buddy-trace-score.high { background: #e8f5e9; color: #2e7d32; }
.buddy-trace-score.med  { background: #fff3e0; color: #e65100; }
.buddy-trace-score.low  { background: #fbe9e7; color: #c62828; }

.buddy-trace-path {
  flex-shrink: 0;
  color: var(--text-tertiary, #9ca3af);
  font-size: 10px;
  max-width: 120px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.buddy-trace-item.clickable {
  cursor: pointer;
}
.buddy-trace-item.clickable:hover {
  background: var(--bg-elevated, #f0f1f3);
}
.buddy-trace-item.clickable .buddy-trace-title {
  text-decoration: underline;
  text-decoration-color: transparent;
  transition: text-decoration-color 0.15s;
}
.buddy-trace-item.clickable:hover .buddy-trace-title {
  text-decoration-color: var(--tesa-primary, #7239ea);
  color: var(--tesa-primary, #7239ea);
}

/* ═══════════════ Related Examples ═══════════════ */
.buddy-related-examples {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
  margin-top: 10px;
  padding: 8px 10px;
  background: var(--bg-surface, #f9fafb);
  border-radius: 8px;
  border: 1px solid var(--border-color, #e5e7eb);
}

.buddy-related-label {
  font-size: 11px;
  font-weight: 600;
  color: var(--text-secondary, #6b7280);
  white-space: nowrap;
}

.buddy-example-chip {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 3px 10px;
  font-size: 11px;
  font-weight: 500;
  color: var(--tesa-primary, #7239ea);
  background: rgba(114, 57, 234, 0.08);
  border: 1px solid rgba(114, 57, 234, 0.2);
  border-radius: 12px;
  cursor: pointer;
  transition: all 0.15s;
  white-space: nowrap;
  max-width: 180px;
  overflow: hidden;
  text-overflow: ellipsis;
}

.buddy-example-chip:hover {
  background: rgba(114, 57, 234, 0.16);
  border-color: var(--tesa-primary, #7239ea);
  transform: translateY(-1px);
  box-shadow: 0 2px 4px rgba(114, 57, 234, 0.15);
}

.buddy-example-chip:active {
  transform: translateY(0);
  box-shadow: none;
}
