/* Workshop Chat — floating panel + FAB
   All values reference ui.css variables. No hardcoded colors or spacing.
   ---------------------------------------------------------------------- */

/* Panel width is set by JS via: panel.style.setProperty('--wc-panel-width', w + 'px') */
.wc-panel { --wc-panel-width: 440px; }

/* ═══════════════════════════════════════════════════════
   FAB
   ═══════════════════════════════════════════════════════ */

.wc-fab {
  position: fixed;
  bottom: 24px;
  right: 24px;
  width: 56px;
  height: 56px;
  border-radius: var(--border-radius-full);
  background-color: var(--primary);
  box-shadow: var(--shadow-lg);
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 30;
  transition:
    background-color var(--transition-fast),
    transform var(--transition-fast),
    box-shadow var(--transition-fast);
  color: var(--white);
  outline: none;
}

.wc-fab:hover {
  background-color: var(--primary-dark);
  transform: scale(1.05);
  box-shadow: var(--shadow-xl);
}

.wc-fab:active { transform: scale(0.97); }

.wc-fab:focus-visible {
  box-shadow: var(--shadow-lg), 0 0 0 3px var(--primary-pale);
}

.wc-fab svg {
  width: 22px;
  height: 22px;
  stroke: var(--white);
  fill: none;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
  pointer-events: none;
}

/* ═══════════════════════════════════════════════════════
   PANEL CONTAINER
   ═══════════════════════════════════════════════════════ */

.wc-panel {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 80px;                 /* floating panel — room at the bottom, not full height */
  width: var(--wc-panel-width);
  min-width: 320px;
  max-width: 800px;
  background-color: var(--white);
  border-left: var(--border-width-thin) solid var(--gray-200);
  border-bottom-left-radius: 14px;   /* flush top + right stay square; only the free corner rounds */
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.18);
  z-index: 30;
  display: flex;
  flex-direction: column;
  transform: translateX(100%);
  transition: transform var(--transition-base);
  overflow: hidden;
}

/* While the chat is open, hide the floating launcher so it can't overlap the
   full-width composer / Send button. The header X closes it. (:has() is
   supported in all current browsers; for older targets, toggle a class on the
   FAB from JS instead.) */
body:has(.wc-panel--open) .wc-fab {
  opacity: 0;
  pointer-events: none;
  transform: scale(0.8);
}

/* --- Responsive: tablet --- */
@media (max-width: 768px) {
  .wc-panel {
    width: min(var(--wc-panel-width), 90vw);
  }
}

/* --- Responsive: phone --- */
@media (max-width: 640px) {
  .wc-panel {
    width: 100vw;
    min-width: 0;       /* override the 320px floor so it can shrink below 320px */
    max-width: 100vw;
    border-left: none;  /* no seam when it's edge-to-edge */
    bottom: 0;          /* full-height on phones — no bottom gap on small screens */
    border-bottom-left-radius: 0;
  }
}

.wc-panel.wc-panel--open { transform: translateX(0); }

/* ── Resize handle ───────────────────────────────────────────────── */

.wc-resize-handle {
  position: absolute;
  left: 0;
  top: 0;
  width: 4px;
  height: 100%;
  cursor: col-resize;
  z-index: 1;
  transition: background-color var(--transition-fast);
}

.wc-resize-handle:hover,
.wc-resize-handle--dragging {
  background-color: var(--primary-light);
  opacity: 0.4;
}

/* ═══════════════════════════════════════════════════════
   PANEL HEADER
   ═══════════════════════════════════════════════════════ */

.wc-panel-header {
  height: 52px;
  min-height: 52px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 var(--space-4);
  /* Reserve room on the right so the Close (X) clears the app's floating
     account avatar (~48px from the edge) and stays visible + clickable.
     Bump to 64px if the avatar widget is larger on some screens. */
  padding-right: 56px;
  border-bottom: var(--border-width-thin) solid var(--gray-200);
  background-color: var(--white);
  flex-shrink: 0;
}

.wc-panel-header-title {
  font-size: var(--font-size-sm);
  font-weight: var(--font-weight-semibold);
  color: var(--gray-700);
  display: flex;
  align-items: center;
  gap: var(--space-2);
}

.wc-panel-header-title svg {
  width: 16px;
  height: 16px;
  stroke: var(--primary);
  fill: none;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.wc-panel-header-actions {
  display: flex;
  align-items: center;
  gap: var(--space-1);
}

.wc-icon-btn {
  width: 32px;
  height: 32px;
  border-radius: var(--border-radius-md);
  border: none;
  background: transparent;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--gray-500);
  transition: background-color var(--transition-fast), color var(--transition-fast);
  outline: none;
}

.wc-icon-btn:hover {
  background-color: var(--gray-100);
  color: var(--gray-700);
}

.wc-icon-btn:focus-visible {
  box-shadow: 0 0 0 2px var(--primary-light);
}

.wc-icon-btn svg {
  width: 16px;
  height: 16px;
  stroke: currentColor;
  fill: none;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
  pointer-events: none;
}

/* ═══════════════════════════════════════════════════════
   MESSAGES AREA
   ═══════════════════════════════════════════════════════ */

.wc-panel-messages {
  flex: 1;
  overflow-y: auto;
  padding: var(--space-4);
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
  scroll-behavior: smooth;
}

/* ── Individual message ──────────────────────────────────────────── */

.wc-message {
  display: flex;
  flex-direction: column;
  max-width: 85%;
}

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

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

.wc-message-error {
  align-self: flex-start;
  align-items: flex-start;
}

.wc-message-bubble {
  padding: var(--space-3) var(--space-4);
  border-radius: var(--border-radius-lg);
  font-size: var(--font-size-sm);
  line-height: var(--line-height-relaxed);
  white-space: pre-wrap;
  word-break: break-word;
}

.wc-message-user .wc-message-bubble {
  background-color: var(--primary-pale);
  color: var(--gray-700);
  border-bottom-right-radius: var(--border-radius-sm);
}

.wc-message-assistant .wc-message-bubble {
  background-color: var(--gray-100);
  color: var(--gray-700);
  border-bottom-left-radius: var(--border-radius-sm);
}

.wc-message-error .wc-message-bubble {
  background-color: var(--error-pale);
  color: var(--error);
  border: var(--border-width-thin) solid var(--error);
  border-bottom-left-radius: var(--border-radius-sm);
}

/* ── Streaming dots (shown while content is empty during stream) ─── */

.wc-streaming-dots {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: var(--space-1) 0;
}

.wc-streaming-dots span {
  width: 6px;
  height: 6px;
  border-radius: var(--border-radius-full);
  background-color: var(--gray-400);
  animation: wc-dot-pulse 1.2s ease-in-out infinite;
}

.wc-streaming-dots span:nth-child(2) { animation-delay: 0.2s; }
.wc-streaming-dots span:nth-child(3) { animation-delay: 0.4s; }

@keyframes wc-dot-pulse {
  0%, 80%, 100% { opacity: 0.3; transform: scale(0.85); }
  40%           { opacity: 1;   transform: scale(1); }
}

/* ═══════════════════════════════════════════════════════
   EMPTY STATE
   ═══════════════════════════════════════════════════════ */

.wc-empty-state {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: var(--space-8);
  text-align: center;
  gap: var(--space-4);
}

.wc-empty-state-icon {
  width: 40px;
  height: 40px;
  stroke: var(--primary-light);
  fill: none;
  stroke-width: 1.5;
  stroke-linecap: round;
  stroke-linejoin: round;
  opacity: 0.8;
}

.wc-empty-state-title {
  font-size: var(--font-size-sm);
  font-weight: var(--font-weight-semibold);
  color: var(--gray-600);
}

.wc-empty-state-hint {
  font-size: var(--font-size-xs);
  color: var(--gray-400);
  line-height: var(--line-height-relaxed);
}

.wc-example-chips {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
  width: 100%;
}

.wc-example-chip {
  padding: var(--space-2) var(--space-3);
  border-radius: var(--border-radius-md);
  border: var(--border-width-thin) solid var(--gray-200);
  background-color: var(--gray-50);
  color: var(--gray-600);
  font-size: var(--font-size-xs);
  text-align: left;
  cursor: pointer;
  transition:
    background-color var(--transition-fast),
    border-color var(--transition-fast),
    color var(--transition-fast);
}

.wc-example-chip:hover {
  background-color: var(--primary-pale);
  border-color: var(--primary-light);
  color: var(--primary-dark);
}

/* ── No-project placeholder ──────────────────────────────────────── */

.wc-no-project {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: var(--space-8);
  text-align: center;
}

.wc-no-project p {
  font-size: var(--font-size-sm);
  color: var(--gray-400);
  line-height: var(--line-height-relaxed);
}

/* ═══════════════════════════════════════════════════════
   INPUT BAR
   ═══════════════════════════════════════════════════════ */

.wc-panel-input {
  border-top: var(--border-width-thin) solid var(--gray-200);
  padding: var(--space-3) var(--space-4);
  display: flex;
  align-items: flex-end;
  gap: var(--space-2);
  flex-shrink: 0;
  background-color: var(--white);
}

.wc-textarea {
  flex: 1;
  resize: none;
  border: var(--border-width-thin) solid var(--gray-300);
  border-radius: var(--border-radius-md);
  padding: var(--space-2) var(--space-3);
  font-size: var(--font-size-sm);
  font-family: inherit;
  line-height: var(--line-height-normal);
  color: var(--gray-700);
  background-color: var(--white);
  min-height: 36px;
  max-height: 96px; /* ~4 rows */
  overflow-y: auto;
  outline: none;
  transition: border-color var(--transition-fast), box-shadow var(--transition-fast);
}

.wc-textarea::placeholder { color: var(--gray-400); }

.wc-textarea:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 2px rgba(139, 92, 246, 0.15);
}

.wc-send-btn {
  width: 36px;
  height: 36px;
  flex-shrink: 0;
  border-radius: var(--border-radius-md);
  border: none;
  background-color: var(--primary);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition:
    background-color var(--transition-fast),
    transform var(--transition-fast);
  outline: none;
}

.wc-send-btn:hover:not(:disabled) { background-color: var(--primary-dark); }
.wc-send-btn:active:not(:disabled) { transform: scale(0.95); }

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

.wc-send-btn svg {
  width: 16px;
  height: 16px;
  stroke: var(--white);
  fill: none;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
  pointer-events: none;
}

/* ═══════════════════════════════════════════════════════
   HISTORY DROPDOWN
   ═══════════════════════════════════════════════════════ */

.wc-history-dropdown {
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  max-height: 320px;
  border-bottom: var(--border-width-thin) solid var(--gray-200);
  background-color: var(--white);
}

.wc-history-dropdown[hidden] { display: none; }

/* ── Search row ──────────────────────────────────────────────────── */

.wc-history-search {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  padding: var(--space-2) var(--space-3);
  border-bottom: var(--border-width-thin) solid var(--gray-100);
  flex-shrink: 0;
}

.wc-history-search svg {
  width: 14px;
  height: 14px;
  flex-shrink: 0;
  stroke: var(--gray-400);
  fill: none;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.wc-history-search-input {
  flex: 1;
  border: none;
  outline: none;
  font-size: var(--font-size-sm);
  color: var(--gray-700);
  background: transparent;
}

.wc-history-search-input::placeholder { color: var(--gray-400); }

/* ── List ────────────────────────────────────────────────────────── */

.wc-history-list {
  overflow-y: auto;
  flex: 1;
}

/* ── Individual item ─────────────────────────────────────────────── */

.wc-history-item {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  padding: var(--space-2) var(--space-3);
  cursor: pointer;
  transition: background-color var(--transition-fast);
}

.wc-history-item:hover { background-color: var(--gray-50); }

.wc-history-item--active { background-color: var(--primary-pale); }
.wc-history-item--active:hover { background-color: var(--primary-pale); }

.wc-history-content {
  flex: 1;
  min-width: 0;
}

.wc-history-title {
  font-size: var(--font-size-sm);
  color: var(--gray-700);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.wc-history-item--active .wc-history-title { color: var(--primary-dark); }

.wc-history-time {
  font-size: var(--font-size-xs);
  color: var(--gray-400);
  margin-top: 2px;
}

/* ── Per-item action buttons (rename / delete) ───────────────────── */

.wc-history-actions {
  display: flex;
  gap: var(--space-1);
  flex-shrink: 0;
  opacity: 0;
  transition: opacity var(--transition-fast);
}

.wc-history-item:hover .wc-history-actions { opacity: 1; }

.wc-history-action {
  width: 24px;
  height: 24px;
  border: none;
  background: transparent;
  border-radius: var(--border-radius-sm);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--gray-400);
  transition:
    background-color var(--transition-fast),
    color var(--transition-fast);
  padding: 0;
  outline: none;
}

.wc-history-action:hover { background-color: var(--gray-200); color: var(--gray-700); }

.wc-history-action:focus-visible { box-shadow: 0 0 0 2px var(--primary-light); }

.wc-history-action svg {
  width: 12px;
  height: 12px;
  stroke: currentColor;
  fill: none;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
  pointer-events: none;
}

/* ── Empty state ─────────────────────────────────────────────────── */

.wc-history-empty {
  padding: var(--space-4) var(--space-3);
  font-size: var(--font-size-sm);
  color: var(--gray-400);
  text-align: center;
}
