/* Chat page. Builds on site.css. */

body.chat { display: flex; flex-direction: column; height: 100vh; height: 100dvh; min-height: 0; overflow: hidden; }

.chat-header {
  flex: none; display: flex; align-items: center; justify-content: space-between; gap: 12px;
  height: 60px; padding: 0 16px;
  border-bottom: 1px solid var(--border);
  background: rgba(11, 11, 18, 0.8);
  backdrop-filter: blur(18px);
  -webkit-backdrop-filter: blur(18px);
}
.chat-header .brand img { height: 22px; }
.header-actions { display: flex; gap: 8px; }
.chip-btn {
  display: inline-flex; align-items: center; gap: 8px;
  height: 38px; padding: 0 14px;
  border: 1px solid var(--border-2); border-radius: 999px;
  background: var(--surface); color: var(--text-2);
  font-size: 14px; font-weight: 500; cursor: pointer;
  transition: background 0.2s, color 0.2s, border-color 0.2s;
}
.chip-btn:hover { background: var(--surface-2); color: var(--text); }
.chip-btn svg { width: 16px; height: 16px; }
.chip-btn.is-pro { border-color: rgba(52, 211, 153, 0.35); background: rgba(52, 211, 153, 0.08); color: var(--green); }
.chip-btn[hidden] { display: none; }

.chat-main { flex: 1; display: flex; flex-direction: column; min-height: 0; }
.chat-scroll { flex: 1; min-height: 0; overflow-y: auto; overscroll-behavior: contain; scrollbar-width: thin; scrollbar-color: var(--surface-2) transparent; }
.thread {
  display: flex; flex-direction: column; gap: 22px;
  width: min(760px, calc(100% - 32px)); min-height: 100%;
  margin: 0 auto; padding: 28px 0 20px;
}

/* ---------- Welcome ---------- */
.welcome { margin: auto 0; padding: 24px 0 8px; text-align: center; animation: rise 0.6s var(--ease); }
.welcome h1 { margin: 0 0 8px; font-size: clamp(26px, 4vw, 34px); letter-spacing: -0.03em; line-height: 1.2; }
.welcome > p { margin: 0 0 28px; color: var(--text-2); }
.suggestions { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; text-align: left; }
.suggestion {
  display: flex; align-items: center; gap: 12px;
  padding: 14px 16px; text-align: left;
  border: 1px solid var(--border); border-radius: var(--radius);
  background: var(--surface); color: var(--text);
  cursor: pointer; transition: background 0.2s, border-color 0.2s, transform 0.2s var(--ease);
}
.suggestion:hover { background: var(--surface-2); border-color: var(--border-2); transform: translateY(-1px); }
.suggestion svg { flex: none; width: 20px; height: 20px; color: var(--red); }
.suggestion strong { display: block; font-size: 14.5px; font-weight: 600; }
.suggestion small { display: block; color: var(--text-3); font-size: 13px; }

/* ---------- Messages ---------- */
.msg { animation: rise 0.3s var(--ease); }
@keyframes rise { from { opacity: 0; transform: translateY(6px); } }
.msg.user {
  align-self: flex-end; max-width: min(80%, 560px);
  padding: 11px 16px;
  border-radius: 20px 20px 6px 20px;
  background: linear-gradient(135deg, var(--red), var(--red-2));
  color: #fff; white-space: pre-wrap; overflow-wrap: anywhere;
  box-shadow: 0 6px 20px rgba(255, 59, 85, 0.18);
}
.msg.ai { align-self: stretch; }

.md { font-size: 15.5px; line-height: 1.7; overflow-wrap: anywhere; }
.md > :first-child { margin-top: 0; }
.md > :last-child { margin-bottom: 0; }
.md p { margin: 0 0 12px; }
.md h4 { margin: 18px 0 8px; font-size: 16.5px; letter-spacing: -0.01em; }
.md ul, .md ol { margin: 0 0 12px; padding-left: 22px; }
.md li { margin: 4px 0; }
.md li::marker { color: var(--text-3); }
.md strong { color: #fff; font-weight: 650; }
.md a { color: var(--red-text); text-decoration: underline; text-underline-offset: 2px; }
.md code { padding: 1px 6px; border: 1px solid var(--border); border-radius: 6px; background: var(--surface-2); font-family: var(--mono); font-size: 0.88em; }
.md pre { position: relative; margin: 0 0 12px; padding: 14px 16px; overflow-x: auto; border: 1px solid var(--border); border-radius: 12px; background: var(--sunken); }
.md pre code { padding: 0; border: 0; background: none; font-size: 13.5px; line-height: 1.6; white-space: pre; }
.md blockquote { margin: 0 0 12px; padding: 2px 14px; border-left: 3px solid var(--red-line); color: var(--text-2); }
.md hr { margin: 16px 0; border: 0; border-top: 1px solid var(--border); }
.table-wrap { margin: 0 0 12px; overflow-x: auto; border: 1px solid var(--border); border-radius: 12px; }
.md table { width: 100%; border-collapse: collapse; font-size: 14.5px; }
.md th, .md td { padding: 9px 12px; border-bottom: 1px solid var(--border); text-align: left; vertical-align: top; }
.md th { background: var(--surface); font-weight: 600; }
.md tr:last-child td { border-bottom: 0; }
.copy-code {
  position: absolute; top: 8px; right: 8px;
  padding: 3px 9px; border: 1px solid var(--border-2); border-radius: 7px;
  background: var(--panel); color: var(--text-3); font-size: 12px; cursor: pointer;
  opacity: 0; transition: opacity 0.2s, color 0.2s;
}
.md pre:hover .copy-code, .copy-code:focus-visible { opacity: 1; }
.copy-code:hover { color: var(--text); }

.msg-actions { display: flex; gap: 4px; margin-top: 6px; opacity: 0; transition: opacity 0.2s; }
.msg.ai:hover .msg-actions, .msg-actions:focus-within, .msg.ai:last-child .msg-actions { opacity: 1; }
.action {
  display: inline-flex; align-items: center; gap: 6px;
  height: 30px; padding: 0 10px; margin-left: -10px;
  border: 0; border-radius: 8px; background: none;
  color: var(--text-3); font-size: 13px; cursor: pointer;
}
.action:hover { background: var(--surface); color: var(--text); }
.action svg { width: 15px; height: 15px; }
@media (hover: none) {
  .msg-actions, .copy-code { opacity: 1; }
}

.typing { display: flex; gap: 6px; padding: 10px 2px; }
.typing span { width: 7px; height: 7px; border-radius: 50%; background: var(--red); animation: blink 1.2s infinite ease-in-out; }
.typing span:nth-child(2) { animation-delay: 0.16s; }
.typing span:nth-child(3) { animation-delay: 0.32s; }
@keyframes blink { 0%, 70%, 100% { opacity: 0.3; transform: scale(0.85); } 35% { opacity: 1; transform: scale(1.1); } }

/* ---------- Notices (blocked, limits, errors, support) ---------- */
.notice {
  display: flex; align-items: flex-start; gap: 14px;
  padding: 16px 18px;
  border: 1px solid var(--border-2); border-radius: var(--radius);
  background: var(--surface);
  font-size: 14.5px; animation: rise 0.3s var(--ease);
}
.notice > svg { flex: none; width: 20px; height: 20px; margin-top: 2px; color: var(--text-3); }
.notice-body { min-width: 0; }
.notice-title { display: block; margin-bottom: 2px; }
.notice-text { margin: 0; color: var(--text-2); }
.notice .md { margin-top: 4px; color: var(--text-2); font-size: 15px; }
.notice .md strong { color: var(--text); }
.notice-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 12px; }
.notice.warn { border-color: rgba(245, 181, 68, 0.35); background: rgba(245, 181, 68, 0.07); }
.notice.warn > svg { color: var(--amber); }
.notice.support { border-color: rgba(94, 234, 212, 0.3); background: rgba(94, 234, 212, 0.06); }
.notice.support > svg { color: var(--teal); }
.notice.limit { border-color: var(--red-line); background: var(--red-soft); }
.notice.limit > svg { color: var(--red); }

/* ---------- Composer ---------- */
.composer-wrap { flex: none; width: min(760px, calc(100% - 32px)); margin: 0 auto; padding: 6px 0 calc(12px + env(safe-area-inset-bottom)); }
.composer-meta { display: flex; justify-content: space-between; gap: 12px; min-height: 20px; margin: 0 8px 8px; color: var(--text-3); font-size: 13px; }
.composer-meta a { color: var(--red-text); font-weight: 600; text-decoration: none; }
.composer-meta a:hover { text-decoration: underline; }
.composer-meta strong { color: var(--text-2); font-weight: 600; }
#counter.over { color: #ff7b8b; }
.composer {
  display: flex; align-items: flex-end; gap: 6px;
  padding: 8px;
  border: 1px solid var(--border-2); border-radius: 26px;
  background: var(--panel);
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.35);
  transition: border-color 0.2s, box-shadow 0.2s;
}
.composer:focus-within { border-color: rgba(255, 59, 85, 0.3); box-shadow: 0 10px 40px rgba(0, 0, 0, 0.35), 0 0 0 4px rgba(255, 59, 85, 0.06); }
.composer textarea {
  flex: 1; max-height: 200px; padding: 8px 4px;
  border: 0; outline: 0; background: none; resize: none;
  font-size: 16px; line-height: 1.5;
}
.composer textarea::placeholder { color: var(--text-3); }
.composer textarea:disabled { cursor: not-allowed; }
.send-btn {
  flex: none; display: grid; place-items: center;
  width: 40px; height: 40px; border: 0; border-radius: 50%;
  background: linear-gradient(135deg, var(--red), var(--red-2)); color: #fff;
  cursor: pointer; transition: transform 0.15s var(--ease);
}
.send-btn svg { width: 18px; height: 18px; }
.send-btn:not(:disabled):hover { transform: scale(1.06); }
.send-btn:disabled { background: var(--surface-2); color: var(--text-3); cursor: default; }
.composer-hint { margin: 10px 0 0; color: var(--text-3); font-size: 12px; text-align: center; }

/* ---------- Images ---------- */
.attach-btn {
  flex: none; display: grid; place-items: center;
  width: 40px; height: 40px; border: 0; border-radius: 50%;
  background: none; color: var(--text-3); cursor: pointer;
  transition: background 0.2s, color 0.2s;
}
.attach-btn:hover { background: var(--surface-2); color: var(--text); }
.attach-btn svg { width: 20px; height: 20px; }

.attachment {
  display: flex; align-items: center; gap: 10px;
  width: fit-content; max-width: 100%; margin: 0 4px 8px; padding: 6px;
  border: 1px solid var(--border-2); border-radius: 14px; background: var(--panel);
  animation: rise 0.25s var(--ease);
}
.attachment[hidden] { display: none; }
.attachment img { width: 44px; height: 44px; border-radius: 9px; object-fit: cover; }
.attachment-name { max-width: 200px; overflow: hidden; color: var(--text-2); font-size: 13px; text-overflow: ellipsis; white-space: nowrap; }
.attachment-remove {
  display: grid; place-items: center; width: 28px; height: 28px; margin-right: 2px;
  border: 0; border-radius: 50%; background: var(--surface-2); color: var(--text-2); cursor: pointer;
}
.attachment-remove:hover { background: var(--red); color: #fff; }
.attachment-remove svg { width: 14px; height: 14px; }

/* A message with an image shows the picture on its own, with any text in a bubble beneath it. */
.msg.user.has-image { display: flex; flex-direction: column; align-items: flex-end; gap: 6px; padding: 0; background: none; box-shadow: none; }
.msg-image {
  display: block; max-width: 260px; max-height: 260px;
  border: 1px solid var(--border-2); border-radius: 16px; cursor: zoom-in;
}
.user-text {
  padding: 11px 16px; border-radius: 20px 20px 6px 20px;
  background: linear-gradient(135deg, var(--red), var(--red-2));
  box-shadow: 0 6px 20px rgba(255, 59, 85, 0.18);
}

.chat-main { position: relative; }
.drop-zone {
  position: absolute; inset: 12px; z-index: 20;
  display: grid; place-items: center;
  border: 2px dashed var(--red-line); border-radius: 20px;
  background: rgba(11, 11, 18, 0.9); color: var(--text); font-weight: 600;
  pointer-events: none;
}
.drop-zone[hidden] { display: none; }

.lightbox { max-width: 92vw; max-height: 90vh; padding: 0; border: 0; background: none; cursor: zoom-out; }
.lightbox::backdrop { background: rgba(0, 0, 0, 0.85); }
.lightbox img { display: block; max-width: 92vw; max-height: 88vh; border-radius: 14px; }

/* ---------- Web sources ---------- */
.sources { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; margin-top: 12px; }
.sources-label { margin-right: 2px; color: var(--text-3); font-size: 12.5px; }
.source {
  display: inline-block; max-width: 220px; height: 28px; padding: 0 11px;
  overflow: hidden; border: 1px solid var(--border-2); border-radius: 999px;
  background: var(--surface); color: var(--text-2);
  font-size: 12.5px; line-height: 26px; text-decoration: none; text-overflow: ellipsis; white-space: nowrap;
}
.source:hover { border-color: var(--red-line); color: var(--text); }

/* ---------- Pro dialog ---------- */
.dialog {
  width: min(400px, calc(100% - 32px)); padding: 0;
  border: 1px solid var(--border-2); border-radius: 24px;
  background: var(--panel); color: var(--text);
  box-shadow: var(--shadow);
}
.dialog[open] { animation: pop 0.3s var(--ease); }
@keyframes pop { from { opacity: 0; transform: translateY(12px) scale(0.98); } }
.dialog::backdrop { background: rgba(0, 0, 0, 0.6); backdrop-filter: blur(6px); -webkit-backdrop-filter: blur(6px); }
.dialog-body { padding: 32px 28px 28px; text-align: center; }
.dialog h2 { margin: 0 0 6px; font-size: 21px; letter-spacing: -0.015em; }
.dialog-body > p { margin: 0 0 20px; color: var(--text-2); font-size: 14.5px; }
.dialog-close {
  position: absolute; top: 12px; right: 12px;
  display: grid; place-items: center; width: 34px; height: 34px;
  border: 0; border-radius: 50%; background: none; color: var(--text-3); cursor: pointer;
}
.dialog-close:hover { background: var(--surface-2); color: var(--text); }
.dialog-close svg { width: 18px; height: 18px; }
.dialog-reason {
  display: inline-block; margin: 0 0 14px; padding: 5px 12px;
  border-radius: 999px; background: var(--red-soft); color: var(--red-text);
  font-size: 13px; font-weight: 600;
}
.dialog-reason[hidden] { display: none; }
.dialog-divider { display: flex; align-items: center; gap: 12px; margin: 6px 0 18px; color: var(--text-3); font-size: 13px; }
.dialog-divider::before, .dialog-divider::after { content: ""; flex: 1; border-top: 1px solid var(--border); }
.dialog-foot { margin: 12px 0 0; color: var(--text-3); font-size: 12.5px; }
.pro-badge {
  display: inline-block; margin-bottom: 14px; padding: 4px 10px;
  border-radius: 999px; background: rgba(52, 211, 153, 0.12);
  color: var(--green); font-size: 12px; font-weight: 700; letter-spacing: 0.08em;
}
.token-box {
  margin-bottom: 14px; padding: 18px;
  border: 1px dashed var(--border-2); border-radius: 16px;
  background: var(--sunken); color: var(--red-text);
  font-family: var(--mono); font-size: 28px; font-weight: 700; letter-spacing: 0.12em;
}
.dialog-links { display: flex; flex-wrap: wrap; justify-content: center; gap: 8px 18px; margin-top: 16px; font-size: 13.5px; }
.dialog-links a, .dialog-links button { padding: 0; border: 0; background: none; color: var(--text-2); text-decoration: none; cursor: pointer; }
.dialog-links a:hover, .dialog-links button:hover { color: var(--text); text-decoration: underline; }

@media (max-width: 560px) {
  .chat-header { padding: 0 12px; }
  .chip-btn { padding: 0 12px; }
  .chip-btn .label { display: none; }
  .thread, .composer-wrap { width: calc(100% - 28px); }
  .suggestions { grid-template-columns: 1fr; }
  .welcome { padding-top: 8px; }
  .msg.user { max-width: 88%; }
  .composer-hint { display: none; }
}
