/* css/chat.css — Chat panel styles */

/* Toggle button */
.chat-toggle-btn {
  position: fixed;
  bottom: calc(var(--footer-height) + 1rem + env(safe-area-inset-bottom, 0px));
  inset-inline-end: 1.5rem;
  width: 52px;
  height: 52px;
  border-radius: 50%;
  background: var(--color-accent);
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.4rem;
  box-shadow: var(--shadow-lg), 0 0 0 0 var(--color-accent-shadow);
  z-index: 300;
  transition: transform var(--transition-fast), box-shadow var(--transition-fast);
}

.chat-toggle-btn:hover {
  transform: scale(1.08);
  box-shadow: var(--shadow-lg), 0 0 0 6px var(--color-accent-soft);
}

.chat-toggle-btn:focus-visible {
  outline: none;
  transform: scale(1.04);
  box-shadow: var(--shadow-lg), 0 0 0 4px var(--color-accent-soft);
}

.chat-toggle-btn:active {
  transform: scale(0.96);
}

.chat-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.chat-icon svg {
  width: 1.35rem;
  height: 1.35rem;
}

/* Panel */
.chat-panel {
  position: fixed;
  bottom: var(--footer-height);
  inset-inline-end: 0;
  width: clamp(20rem, 32vw, 23.75rem);
  height: calc(100dvh - var(--header-height) - var(--footer-height));
  background: var(--color-bg-elevated);
  border-inline-start: 1px solid var(--color-border);
  z-index: 250;
  display: flex;
  flex-direction: column;
  transform: translateX(100%);
  transition: transform var(--transition-normal);
}

.chat-panel[hidden] {
  display: none;
}

[dir="rtl"] .chat-panel {
  inset-inline-end: auto;
  inset-inline-start: 0;
  border-inline-start: none;
  border-inline-end: 1px solid var(--color-border);
  transform: translateX(-100%);
}

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

/* Chat header */
.chat-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.875rem 1rem;
  border-block-end: 1px solid var(--color-border);
  flex-shrink: 0;
}

.chat-title {
  font-weight: 700;
  font-size: 0.9375rem;
}

/* Messages area */
.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  scrollbar-width: thin;
  scrollbar-color: var(--color-border) transparent;
}

.chat-empty {
  text-align: center;
  color: var(--color-text-muted);
  font-size: 0.875rem;
  margin-block-start: 2rem;
  padding: 1rem;
}

/* Message bubbles */
.chat-bubble {
  max-width: 85%;
  padding: 0.6rem 0.875rem;
  border-radius: var(--radius-lg);
  font-size: 0.875rem;
  line-height: 1.55;
  word-break: break-word;
  animation: fadeIn var(--transition-fast) ease;
}

.chat-bubble.user,
.chat-bubble-user {
  background: var(--color-accent-aa);
  color: var(--color-on-accent);
  align-self: flex-end;
  border-end-end-radius: var(--radius-sm);
}

.chat-bubble.assistant,
.chat-bubble-assistant {
  background: var(--color-surface);
  color: var(--color-text);
  align-self: flex-start;
  border-end-start-radius: var(--radius-sm);
}

.chat-bubble.system,
.chat-bubble-system {
  background: var(--color-error-soft);
  border: 1px solid var(--color-error-text);
  color: var(--color-error-text);
  align-self: stretch;
  text-align: center;
}

.chat-bubble.system.info,
.chat-bubble-system.info {
  background: var(--color-info-soft);
  border-color: var(--color-info-text);
  color: var(--color-info-text);
}

.chat-timestamp {
  font-size: 0.65rem;
  color: var(--color-text-dim);
  margin-block-start: 0.25rem;
  text-align: end;
}

.chat-bubble.user .chat-timestamp,
.chat-bubble-user .chat-timestamp {
  color: var(--color-on-accent); /* white 5.56:1 on accent-aa */
}

.chat-bubble.assistant .chat-timestamp,
.chat-bubble-assistant .chat-timestamp {
  text-align: start;
  color: var(--color-text-muted);
}

/* Loading indicator */
.chat-loading {
  display: flex;
  gap: 4px;
  padding: 0.6rem 0.875rem;
  background: var(--color-surface);
  border-radius: var(--radius-lg) var(--radius-lg) var(--radius-lg) var(--radius-sm);
  align-self: flex-start;
  width: 52px;
}

.chat-loading-dot,
.chat-loading .dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--color-text-muted);
  animation: loadingPulse 1.8s ease-in-out infinite;
}

.chat-loading-dot:nth-child(1),
.chat-loading .dot:nth-child(1) { animation-delay: 0s; }
.chat-loading-dot:nth-child(2),
.chat-loading .dot:nth-child(2) { animation-delay: 0.2s; }
.chat-loading-dot:nth-child(3),
.chat-loading .dot:nth-child(3) { animation-delay: 0.4s; }

@keyframes loadingPulse {
  0%, 60%, 100% { transform: scale(0.8); opacity: 0.5; }
  30% { transform: scale(1.1); opacity: 1; }
}

@media (prefers-reduced-motion: reduce) {
  .chat-loading-dot,
  .chat-loading .dot {
    animation: none;
    opacity: 1;
  }
}

/* Input area */
.chat-input-area {
  display: flex;
  gap: 0.5rem;
  padding: 0.875rem;
  border-block-start: 1px solid var(--color-border);
  flex-shrink: 0;
}

.chat-input {
  flex: 1;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  color: var(--color-text);
  padding: 0.55rem 0.875rem;
  min-height: 44px;
  border-radius: var(--radius-md);
  font-family: var(--font-sans);
  font-size: 0.9rem;
  transition: border-color var(--transition-fast), box-shadow var(--transition-fast);
}

.chat-input:focus-visible {
  outline: none;
  border-color: var(--color-accent);
  box-shadow: 0 0 0 3px var(--color-accent-soft);
}

.chat-input:disabled {
  opacity: 0.6;
}

/* No-API-key state */
.chat-no-key {
  text-align: center;
  padding: 2rem 1rem;
}

.chat-no-key p {
  color: var(--color-text-muted);
  font-size: 0.875rem;
  margin-block-end: 1rem;
}

/* Responsive: full-width on mobile */
@media (max-width: 768px) {
  .chat-panel {
    width: 100%;
    height: calc(100dvh - var(--header-height) - var(--footer-height));
    top: var(--header-height);
  }
}

@media (prefers-reduced-motion: reduce) {
  .chat-toggle-btn {
    transition: none;
  }

  .chat-loading-dot,
  .chat-loading .dot,
  .chat-bubble {
    animation: none !important;
  }
}
