/* === Chat Widget === */

/* Collapsed bar */
.prince-chat-bar {
  position: fixed;
  bottom: 1.25rem;
  right: 1.25rem;
  display: flex;
  align-items: center;
  gap: 0.6rem;
  background: var(--brown-dark);
  color: var(--cream);
  padding: 0.6rem 1rem;
  border-radius: 100px;
  cursor: pointer;
  z-index: 300;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.15);
  transition: transform 0.2s, box-shadow 0.2s;
  font-family: var(--font-sans);
  font-size: 0.8rem;
  font-weight: 500;
  user-select: none;
}

.prince-chat-bar:hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 24px rgba(0, 0, 0, 0.2);
}

.prince-chat-bar.hidden {
  display: none;
}

.prince-chat-avatar-small {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  object-fit: cover;
  border: 2px solid rgba(255, 255, 255, 0.2);
}

.prince-chat-status {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #5cb85c;
  flex-shrink: 0;
  animation: pulse-online 2s ease-in-out infinite;
}

.prince-chat-status.offline {
  background: #999;
  animation: none;
}

@keyframes pulse-online {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.5; }
}

/* Chat window */
.prince-chat-window {
  position: fixed;
  bottom: 1.25rem;
  right: 1.25rem;
  width: 380px;
  height: 520px;
  background: var(--cream);
  border-radius: 16px;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.15);
  z-index: 301;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  opacity: 0;
  transform: translateY(20px) scale(0.95);
  pointer-events: none;
  transition: opacity 0.3s cubic-bezier(0.4, 0, 0.2, 1),
              transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.prince-chat-window.open {
  opacity: 1;
  transform: translateY(0) scale(1);
  pointer-events: auto;
}

/* Header */
.prince-chat-header {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.75rem 1rem;
  background: var(--cream-dark);
  border-bottom: 1px solid var(--sand);
  flex-shrink: 0;
}

.prince-chat-avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  object-fit: cover;
}

.prince-chat-header-info {
  flex: 1;
}

.prince-chat-name {
  font-family: var(--font-display);
  font-size: 1rem;
  font-weight: 600;
  color: var(--brown-dark);
  line-height: 1.2;
}

.prince-chat-subtitle {
  font-family: var(--font-sans);
  font-size: 0.65rem;
  color: var(--brown-light);
}

.prince-chat-new,
.prince-chat-close {
  background: none;
  border: none;
  font-size: 1.3rem;
  color: var(--brown-light);
  cursor: pointer;
  padding: 0.25rem;
  line-height: 1;
  transition: color 0.15s;
}

.prince-chat-new:hover,
.prince-chat-close:hover {
  color: var(--brown-dark);
}

/* Messages area */
.prince-chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

/* Greeting */
.prince-chat-greeting {
  text-align: center;
  padding: 1rem 0.5rem;
}

.prince-chat-greeting img {
  width: 64px;
  height: 64px;
  border-radius: 50%;
  margin-bottom: 0.75rem;
}

.prince-chat-greeting p {
  font-family: var(--font-display);
  font-size: 0.95rem;
  font-style: italic;
  color: var(--brown);
  line-height: 1.5;
}

/* Conversation starters */
.prince-chat-starters {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
  padding: 0 0.5rem;
}

.prince-chat-starter {
  background: var(--cream-dark);
  border: 1px solid var(--sand);
  border-radius: 12px;
  padding: 0.5rem 0.75rem;
  font-family: var(--font-body);
  font-size: 0.8rem;
  color: var(--brown);
  cursor: pointer;
  text-align: left;
  transition: background 0.15s, border-color 0.15s;
}

.prince-chat-starter:hover {
  background: var(--gold-light);
  border-color: var(--gold);
}

/* Message bubbles */
.prince-chat-msg {
  max-width: 85%;
  padding: 0.6rem 0.85rem;
  border-radius: 12px;
  font-family: var(--font-body);
  font-size: 0.85rem;
  line-height: 1.6;
  word-wrap: break-word;
}

.prince-chat-msg.prince {
  align-self: flex-start;
  background: var(--cream-dark);
  color: var(--brown-dark);
  border-left: 2px solid var(--gold);
  border-bottom-left-radius: 4px;
}

.prince-chat-msg.user {
  align-self: flex-end;
  background: var(--gold-light);
  color: var(--brown-dark);
  border-bottom-right-radius: 4px;
}

/* Paragraphs inside prince bubbles */
.prince-chat-msg.prince p {
  margin: 0;
}

.prince-chat-msg.prince p + p {
  margin-top: 0.5rem;
}

/* Action notes (stage directions between bubbles) */
.prince-chat-action {
  align-self: flex-start;
  font-family: var(--font-display);
  font-size: 0.8rem;
  font-style: italic;
  color: var(--brown-light);
  padding: 0.25rem 0.5rem;
  text-align: center;
  width: 100%;
}

/* Typing indicator */
.prince-chat-typing {
  align-self: flex-start;
  padding: 0.6rem 0.85rem;
  font-family: var(--font-display);
  font-style: italic;
  font-size: 0.8rem;
  color: var(--brown-light);
}

.prince-chat-typing::after {
  content: '...';
  animation: typing-dots 1.2s infinite;
}

@keyframes typing-dots {
  0%, 20% { content: '.'; }
  40% { content: '..'; }
  60%, 100% { content: '...'; }
}

/* Input area */
.prince-chat-input-area {
  display: flex;
  align-items: flex-end;
  gap: 0.5rem;
  padding: 0.75rem;
  border-top: 1px solid var(--sand);
  background: var(--cream);
  flex-shrink: 0;
}

.prince-chat-textarea {
  flex: 1;
  border: 1px solid var(--sand);
  border-radius: 12px;
  padding: 0.5rem 0.75rem;
  font-family: var(--font-body);
  font-size: 0.85rem;
  color: var(--brown-dark);
  background: var(--cream);
  resize: none;
  outline: none;
  max-height: 100px;
  line-height: 1.5;
  transition: border-color 0.15s;
}

.prince-chat-textarea:focus {
  border-color: var(--gold);
}

.prince-chat-textarea::placeholder {
  color: var(--brown-light);
  opacity: 0.6;
}

.prince-chat-send {
  background: var(--brown-dark);
  color: #fff;
  border: none;
  border-radius: 50%;
  width: 34px;
  height: 34px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: background 0.15s;
  font-size: 0.9rem;
}

.prince-chat-send:hover {
  background: var(--brown);
}

.prince-chat-send:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.prince-chat-char-count {
  font-family: var(--font-sans);
  font-size: 0.6rem;
  color: var(--brown-light);
  text-align: right;
  padding: 0 0.75rem;
  margin-top: -0.25rem;
}

.prince-chat-char-count.warn {
  color: var(--rose);
}

/* Offline message */
.prince-chat-offline {
  text-align: center;
  padding: 2rem 1.5rem;
  font-family: var(--font-display);
  font-size: 0.95rem;
  font-style: italic;
  color: var(--brown);
  line-height: 1.5;
}

/* === Mobile === */
@media (max-width: 900px) {
  .prince-chat-bar {
    bottom: 0.75rem;
    right: 0.75rem;
  }

  .prince-chat-window {
    inset: 0;
    width: 100%;
    height: 100%;
    border-radius: 0;
    bottom: 0;
    right: 0;
    padding-top: env(safe-area-inset-top, 0);
    padding-bottom: env(safe-area-inset-bottom, 0);
  }
}
