/* lockin Learning Buddy widget — token-driven; inherits the site's design style
 * via CSS custom properties (--accent, --surface, --ink, …) with safe fallbacks. */

.buddy-fab {
  position: fixed;
  right: 20px;
  bottom: 20px;
  z-index: 9998;
  width: 60px;
  height: 60px;
  border: none;
  border-radius: 50%;
  background: var(--accent, #d97757);
  color: var(--on-accent, #fff);
  font-size: 28px;
  line-height: 1;
  cursor: pointer;
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.22);
  transition: transform 0.18s ease, box-shadow 0.18s ease;
}
.buddy-fab:hover { transform: scale(1.06); box-shadow: 0 8px 26px rgba(0, 0, 0, 0.28); }
.buddy-fab:focus-visible,
.buddy-iconbtn:focus-visible,
.buddy-chip:focus-visible,
.buddy-send:focus-visible,
.buddy-input:focus-visible {
  outline: 2px solid var(--accent, #d97757);
  outline-offset: 2px;
}
.buddy-fab-open { transform: scale(0.94); }

.buddy-panel {
  position: fixed;
  right: 20px;
  bottom: 92px;
  z-index: 9999;
  display: flex;
  flex-direction: column;
  width: min(380px, calc(100vw - 32px));
  height: min(560px, calc(100vh - 124px));
  background: var(--surface, #fff);
  color: var(--ink, #1a1a1a);
  border: 1px solid var(--border, rgba(0, 0, 0, 0.1));
  border-radius: var(--radius-lg, 20px);
  box-shadow: 0 16px 48px rgba(0, 0, 0, 0.2);
  overflow: hidden;
  font-family: var(--font-body, system-ui, sans-serif);
  transition: opacity 0.18s ease, transform 0.18s ease;
}
.buddy-hidden {
  opacity: 0;
  transform: translateY(12px) scale(0.98);
  pointer-events: none;
}

.buddy-header {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 12px 14px;
  border-bottom: 1px solid var(--border, rgba(0, 0, 0, 0.1));
  background: var(--surface-2, rgba(0, 0, 0, 0.03));
}
.buddy-title {
  flex: 1;
  font-family: var(--font-display, inherit);
  font-weight: 600;
  font-size: 15px;
}
.buddy-iconbtn {
  border: none;
  background: transparent;
  color: var(--muted, #777);
  font-size: 15px;
  width: 30px;
  height: 30px;
  border-radius: 50%;
  cursor: pointer;
}
.buddy-iconbtn:hover { background: var(--border, rgba(0, 0, 0, 0.08)); color: var(--ink, #1a1a1a); }

.buddy-msgs {
  flex: 1;
  overflow-y: auto;
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.buddy-msg { display: flex; }
.buddy-msg-user { justify-content: flex-end; }
.buddy-bubble {
  max-width: 85%;
  padding: 9px 13px;
  border-radius: var(--radius, 14px);
  font-size: 14px;
  line-height: 1.55;
  overflow-wrap: break-word;
}
.buddy-msg-user .buddy-bubble {
  background: var(--accent, #d97757);
  color: var(--on-accent, #fff);
  border-bottom-right-radius: 4px;
}
.buddy-msg-buddy .buddy-bubble {
  background: var(--surface-2, rgba(0, 0, 0, 0.05));
  border-bottom-left-radius: 4px;
}
.buddy-msg-system .buddy-bubble,
.buddy-msg-error .buddy-bubble {
  background: transparent;
  border: 1px dashed var(--border, rgba(0, 0, 0, 0.2));
  color: var(--muted, #777);
  font-size: 13px;
  max-width: 100%;
}
.buddy-msg-error .buddy-bubble { color: var(--err, #b0552f); border-color: var(--err, #b0552f); }

.buddy-bubble p { margin: 0 0 8px; }
.buddy-bubble p:last-child { margin-bottom: 0; }
.buddy-bubble ul { margin: 0 0 8px 18px; padding: 0; }
.buddy-bubble code {
  font-family: var(--font-mono, ui-monospace, monospace);
  font-size: 12.5px;
  background: rgba(127, 127, 127, 0.15);
  padding: 1px 5px;
  border-radius: 5px;
}
.buddy-bubble pre {
  background: rgba(127, 127, 127, 0.12);
  padding: 10px;
  border-radius: 10px;
  overflow-x: auto;
  margin: 0 0 8px;
}
.buddy-bubble pre code { background: none; padding: 0; }

.buddy-typing span {
  display: inline-block;
  width: 7px;
  height: 7px;
  margin-right: 4px;
  border-radius: 50%;
  background: var(--muted, #999);
  animation: buddy-bounce 1.2s infinite;
}
.buddy-typing span:nth-child(2) { animation-delay: 0.15s; }
.buddy-typing span:nth-child(3) { animation-delay: 0.3s; }
@keyframes buddy-bounce {
  0%, 60%, 100% { transform: translateY(0); opacity: 0.5; }
  30% { transform: translateY(-5px); opacity: 1; }
}

.buddy-starters {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  padding: 0 14px 10px;
}
.buddy-starters:empty { display: none; }
.buddy-chip {
  border: 1px solid var(--border, rgba(0, 0, 0, 0.15));
  background: var(--surface, #fff);
  color: var(--ink, #333);
  border-radius: 999px;
  padding: 6px 12px;
  font-size: 12.5px;
  cursor: pointer;
}
.buddy-chip:hover { border-color: var(--accent, #d97757); color: var(--accent, #d97757); }

.buddy-form {
  display: flex;
  gap: 8px;
  align-items: flex-end;
  padding: 10px 12px;
  border-top: 1px solid var(--border, rgba(0, 0, 0, 0.1));
  background: var(--surface, #fff);
}
.buddy-input {
  flex: 1;
  resize: none;
  max-height: 110px;
  border: 1px solid var(--border, rgba(0, 0, 0, 0.15));
  border-radius: var(--radius, 12px);
  background: var(--surface-2, rgba(0, 0, 0, 0.03));
  color: var(--ink, #1a1a1a);
  font: inherit;
  font-size: 14px;
  padding: 9px 12px;
}
.buddy-send {
  border: none;
  border-radius: 50%;
  width: 38px;
  height: 38px;
  background: var(--accent, #d97757);
  color: var(--on-accent, #fff);
  font-size: 15px;
  cursor: pointer;
  flex-shrink: 0;
}
.buddy-send:disabled { opacity: 0.5; cursor: default; }

@media (max-width: 520px) {
  .buddy-panel {
    right: 8px;
    left: 8px;
    bottom: 84px;
    width: auto;
    height: min(70vh, calc(100vh - 108px));
  }
}

@media (prefers-reduced-motion: reduce) {
  .buddy-fab, .buddy-panel { transition: none; }
  .buddy-typing span { animation: none; opacity: 0.7; }
}
