/* ── Lens Companion ─────────────────────────────────────────────────── */

/* Floating bubble */
.companion-bubble {
  position: fixed;
  bottom: 24px;
  right: 24px;
  z-index: 1000;
  width: 52px;
  height: 52px;
  border-radius: 50%;
  background: #3b82f6;
  border: none;
  color: #fff;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.25);
  transition: background 0.15s, transform 0.15s;
}

.companion-bubble:hover {
  background: #2563eb;
  transform: scale(1.05);
}

.companion-bubble--hidden {
  display: none;
}

/* Panel */
.companion-panel {
  display: none;
  position: fixed;
  bottom: 24px;
  right: 24px;
  z-index: 1000;
  width: 380px;
  height: 60vh;
  min-height: 320px;
  max-height: 640px;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.companion-panel--open {
  display: flex;
}

/* Hide panel when closed (override the flex from above) */
.companion-panel:not(.companion-panel--open) {
  display: none;
}

.companion-panel--sidebar-open {
  width: 560px;
}

/* Header */
.companion-panel__header {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 12px 16px;
  flex-shrink: 0;
}

.companion-panel__history-toggle {
  background: none;
  border: none;
  color: rgba(255, 255, 255, 0.75);
  font-size: 1rem;
  cursor: pointer;
  line-height: 1;
  padding: 0 2px;
}

.companion-panel__history-toggle:hover {
  color: #fff;
}

/* Body: sidebar + main chat column */
.companion-panel__body {
  display: flex;
  flex: 1;
  min-height: 0;
}

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

/* Sidebar (collapsed by default) */
.companion-sidebar {
  width: 0;
  overflow: hidden;
  flex-shrink: 0;
  border-right: 1px solid #e2e8f0;
  display: flex;
  flex-direction: column;
  transition: width 0.15s;
}

.companion-sidebar--open {
  width: 180px;
}

.companion-new-chat-btn {
  margin: 10px;
  background: #fff;
  border: 1px solid #e2e8f0;
  border-radius: 8px;
  color: #334155;
  font-size: 0.78rem;
  padding: 8px 10px;
  cursor: pointer;
  font-family: inherit;
  white-space: nowrap;
}

.companion-new-chat-btn:hover {
  border-color: var(--color-companion);
}

.companion-history-list {
  flex: 1;
  overflow-y: auto;
  padding: 0 6px 10px;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.companion-history-empty {
  color: #475569;
  font-size: 0.72rem;
  text-align: center;
  padding: 12px 6px;
}

.companion-history-item-row {
  display: flex;
  align-items: center;
  gap: 2px;
  border-radius: 6px;
}

.companion-history-item-row:hover {
  background: #f8fafc;
}

.companion-history-item--active {
  background: #f5f3ff;
  border: 1px solid #ede9fe;
}

.companion-history-item {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 2px;
  flex: 1;
  min-width: 0;
  background: none;
  border: none;
  border-radius: 6px;
  padding: 6px 8px;
  cursor: pointer;
  font-family: inherit;
  text-align: left;
}

.companion-history-item__title {
  color: #1e293b;
  font-size: 0.75rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 100%;
}

.companion-history-item__time {
  color: #64748b;
  font-size: 0.65rem;
}

/* Inline rename */
.companion-history-rename-form {
  flex: 1;
  min-width: 0;
  padding: 6px 8px;
}

.companion-history-rename-input {
  width: 100%;
  background: #fff;
  border: 1px solid var(--color-companion);
  border-radius: 4px;
  color: #1e293b;
  font-size: 0.75rem;
  font-family: inherit;
  padding: 3px 6px;
}

.companion-history-rename-input:focus {
  outline: none;
}

/* Three-dot menu */
.companion-history-menu {
  position: relative;
  flex-shrink: 0;
}

.companion-history-menu__trigger {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 22px;
  height: 22px;
  color: #64748b;
  font-size: 0.85rem;
  cursor: pointer;
  border-radius: 4px;
  opacity: 0;
  list-style: none;
}

.companion-history-menu__trigger::-webkit-details-marker {
  display: none;
}

.companion-history-item-row:hover .companion-history-menu__trigger,
.companion-history-menu[open] .companion-history-menu__trigger {
  opacity: 1;
}

.companion-history-menu__trigger:hover {
  color: #1e293b;
  background: #f1f5f9;
}

.companion-history-menu__dropdown {
  position: absolute;
  top: 100%;
  right: 0;
  z-index: 10;
  margin-top: 2px;
  min-width: 110px;
  background: #fff;
  border: 1px solid #e2e8f0;
  border-radius: 8px;
  box-shadow: 0 8px 20px rgba(0, 0, 0, 0.12);
  overflow: hidden;
}

.companion-history-menu__item {
  display: block;
  width: 100%;
  background: none;
  border: none;
  color: #334155;
  font-size: 0.75rem;
  font-family: inherit;
  text-align: left;
  padding: 7px 10px;
  cursor: pointer;
}

.companion-history-menu__item:hover {
  background: #f1f5f9;
}

.companion-history-menu__item--danger {
  color: #f87171;
}

.companion-panel__title {
  font-size: 0.85rem;
  font-weight: 600;
  color: #fff;
}

.companion-scope-chip {
  font-size: 0.72rem;
  font-weight: 400;
  background: rgba(255, 255, 255, 0.15);
  color: rgba(255, 255, 255, 0.9);
  border: 1px solid rgba(255, 255, 255, 0.25);
  border-radius: 20px;
  padding: 2px 10px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 160px;
}

.companion-panel__close {
  margin-left: auto;
  background: none;
  border: none;
  color: rgba(255, 255, 255, 0.75);
  font-size: 1.2rem;
  cursor: pointer;
  line-height: 1;
  padding: 0 2px;
}

.companion-panel__close:hover {
  color: #fff;
}

/* Thread */
.companion-panel__thread {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.companion-empty {
  color: #475569;
  font-size: 0.85rem;
  text-align: center;
  margin-top: 32px;
}

/* Messages */
.companion-message {
  display: flex;
  flex-direction: column;
}

.companion-message--user {
  align-items: flex-end;
}

.companion-message--agent {
  align-items: flex-start;
}

.companion-message__bubble {
  max-width: 88%;
  font-size: 0.83rem;
  line-height: 1.5;
}

.companion-message__bubble p {
  margin: 0 0 6px;
}

.companion-message__bubble p:last-child {
  margin-bottom: 0;
}

/* Scope marker */
.companion-scope-marker {
  text-align: center;
  color: #475569;
  font-size: 0.72rem;
  display: flex;
  align-items: center;
  gap: 8px;
}

.companion-scope-marker::before,
.companion-scope-marker::after {
  content: "";
  flex: 1;
  height: 1px;
  background: #334155;
}

/* Input row */
.companion-panel__input-row {
  display: flex;
  gap: 8px;
  padding: 12px 16px;
  background: #fff;
  border-top: 1px solid #e2e8f0;
  flex-shrink: 0;
}

.companion-panel__input-row textarea {
  flex: 1;
  background: #fff;
  border: 1px solid #e2e8f0;
  border-radius: 8px;
  color: #1e293b;
  font-size: 0.83rem;
  padding: 8px 10px;
  resize: none;
  font-family: inherit;
  line-height: 1.4;
}

.companion-panel__input-row textarea:focus {
  outline: none;
  border-color: var(--color-companion);
}

.companion-panel__input-row textarea::placeholder {
  color: #94a3b8;
}

.companion-panel__input-row input[type="submit"] {
  border: none;
  border-radius: 8px;
  font-size: 0.83rem;
  padding: 0 14px;
  cursor: pointer;
  font-family: inherit;
  white-space: nowrap;
  align-self: flex-end;
}

.companion-panel__input-row input[type="submit"]:disabled,
.companion-panel__input-row textarea:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

/* ── Pinned insights — pin control overlays the top-right corner of an
   agent message bubble ─────────────────────────────────────────────── */
.companion-message--agent {
  position: relative;
}

.pin-control {
  position: absolute;
  top: -6px;
  right: 0;
  z-index: 1;
}

.pin-btn {
  background: #fff;
  border: 1px solid #e2e8f0;
  border-radius: 50%;
  width: 22px;
  height: 22px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.72rem;
  line-height: 1;
  cursor: pointer;
  padding: 0;
  /* Faintly visible at rest rather than opacity: 0 — fully invisible until
     hover made the pin action impossible to discover in practice. */
  opacity: 0.45;
  transition: opacity 0.15s, border-color 0.15s;
}

.companion-message--agent:hover .pin-btn,
.pin-btn--pinned {
  opacity: 1;
}

.pin-btn--pinned {
  border-color: var(--color-companion);
  color: var(--color-companion);
}

.pin-note {
  margin-top: 2px;
}

.pin-note-input {
  font-size: 0.7rem;
  border: 1px solid #e2e8f0;
  border-radius: 6px;
  padding: 3px 6px;
  width: 140px;
  font-family: inherit;
}

.pin-note-input:focus {
  outline: none;
  border-color: var(--color-companion);
}
