/* ── Shared chat shell ───────────────────────────────────────────────
   Common layout/behavior + visual styles for Gillbert's full-screen
   chat pages (Catch Chat, Ask Gillbert). Both pages look identical on
   purpose — everything lives here so they can't drift apart. ────── */

* {
  box-sizing: border-box;
}

html {
  height: 100%;
  background: linear-gradient(135deg, #4FACFE 0%, #00F2FE 100%);
  overflow: hidden;
  overscroll-behavior: none;
}

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: linear-gradient(135deg, #4FACFE 0%, #00F2FE 100%);
  height: 100dvh;
  max-height: var(--app-height, 100dvh);
  overflow: hidden;
  overscroll-behavior: none;
}

.chat-page {
  display: flex;
  flex-direction: column;
  height: 100%;
  min-height: 0;
  max-width: 600px;
  margin: 0 auto;
  width: 100%;
}

/* ── Header ──────────────────────────────────────────────────────── */

.chat-header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 16px;
  padding-top: max(14px, env(safe-area-inset-top));
  flex-shrink: 0;
}

.chat-header-back {
  color: white;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-width: 40px;
  height: 40px;
  padding: 0 10px;
  border-radius: 999px;
  border: 1px solid rgba(255, 255, 255, 0.55);
  background: rgba(255, 255, 255, 0.16);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
  flex-shrink: 0;
  margin-left: auto;
  order: 2;
  transition: background 0.2s, box-shadow 0.2s, transform 0.2s;
}

.chat-header-back:hover {
  background: rgba(255, 255, 255, 0.24);
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.16);
}

.chat-header-back:active {
  transform: scale(0.97);
}

.chat-header-back:focus-visible {
  outline: 2px solid white;
  outline-offset: 2px;
}

.chat-header-back-icon {
  font-size: 20px;
  line-height: 1;
}

.chat-header-back-label {
  display: none;
  font-size: 12px;
  font-weight: 700;
}

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

.chat-header-title {
  color: white;
  font-size: 19px;
  font-weight: 700;
  line-height: 1.2;
}

.chat-header-subtitle {
  color: rgba(255, 255, 255, 0.75);
  font-size: 12px;
  margin-top: 2px;
}

/* ── Messages area ───────────────────────────────────────────────── */

.chat-messages {
  flex: 1;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 8px 16px 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  -webkit-overflow-scrolling: touch;
}

/* ── Welcome ─────────────────────────────────────────────────────── */

.chat-welcome {
  text-align: center;
  padding: 32px 16px 16px;
  color: white;
  flex-shrink: 0;
}

.chat-welcome-icon {
  font-size: 52px;
  margin-bottom: 12px;
  display: block;
}

.chat-welcome p {
  margin: 0;
  font-size: 15px;
  line-height: 1.6;
  opacity: 0.9;
}

/* ── Message bubbles ─────────────────────────────────────────────── */

.message {
  display: flex;
  gap: 8px;
  max-width: 88%;
}

.message--gillbert {
  align-self: flex-start;
}

.message--user {
  align-self: flex-end;
  flex-direction: row-reverse;
}

.message-avatar {
  font-size: 18px;
  width: 30px;
  height: 30px;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  flex-shrink: 0;
  padding-bottom: 2px;
}

.message-bubble {
  padding: 10px 14px;
  border-radius: 18px;
  font-size: 15px;
  line-height: 1.5;
  word-break: break-word;
}

.message--gillbert .message-bubble {
  background: white;
  color: #1a1a2e;
  border-bottom-left-radius: 4px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

.message--user .message-bubble {
  background: rgba(255, 255, 255, 0.22);
  color: white;
  border-bottom-right-radius: 4px;
  border: 1.5px solid rgba(255, 255, 255, 0.4);
}

.message-bubble strong {
  font-weight: 700;
}

.message-bubble em {
  font-style: italic;
}

.chat-catch-link {
  color: #1f7ff0;
  font-weight: 700;
  text-decoration: underline;
  text-underline-offset: 2px;
}

.chat-catch-link:hover,
.chat-catch-link:focus-visible {
  color: #1469cf;
}

/* ── Thinking indicator ──────────────────────────────────────────── */

.message--thinking .message-bubble {
  padding: 14px 16px;
}

.thinking-dots {
  display: flex;
  gap: 5px;
  align-items: center;
}

.thinking-dots span {
  width: 8px;
  height: 8px;
  background: #4FACFE;
  border-radius: 50%;
  animation: thinking 1.2s ease-in-out infinite;
}

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

@keyframes thinking {
  0%, 100% { opacity: 0.3; transform: translateY(0); }
  50%       { opacity: 1;   transform: translateY(-5px); }
}

/* ── Error bubble ────────────────────────────────────────────────── */

.message--error .message-bubble {
  background: #fff0f0;
  color: #c0392b;
  border: 1px solid #ffcccc;
}

/* ── Input bar ───────────────────────────────────────────────────── */

.chat-input-bar {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  padding: 12px 16px;
  padding-bottom: max(12px, env(safe-area-inset-bottom));
  background: rgba(255, 255, 255, 0.15);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-top: 1px solid rgba(255, 255, 255, 0.2);
  flex-shrink: 0;
}

.chat-input {
  flex: 1;
  padding: 11px 16px;
  border: none;
  border-radius: 22px;
  font-size: 15px;
  font-family: inherit;
  background: white;
  color: #333;
  resize: none;
  outline: none;
  max-height: 120px;
  overflow-y: auto;
  line-height: 1.45;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

.chat-input::placeholder {
  color: #aaa;
}

.chat-send-btn {
  width: 44px;
  height: 44px;
  border: none;
  border-radius: 50%;
  background: linear-gradient(135deg, #2f93ff 0%, #1f7ff0 100%);
  color: #ffffff;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: transform 0.15s, box-shadow 0.15s;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.15);
}

.chat-send-icon {
  width: 18px;
  height: 18px;
  transform: translateX(1px);
}

.chat-send-btn:hover:not(:disabled) {
  transform: translateY(-1px);
  box-shadow: 0 5px 14px rgba(0, 0, 0, 0.2);
}

.chat-send-btn:active {
  transform: scale(0.90);
}

.chat-send-btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
  transform: none;
}

@media (min-width: 480px) {
  .chat-header-back {
    padding: 0 12px;
  }

  .chat-header-back-label {
    display: inline;
  }
}
