/* =========================================================
   AXON AI — chat.css
   Chat area, messages, markdown, composer, attachments
   ========================================================= */

/* ================= CHAT AREA ================= */

.chat-area {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  overflow-x: hidden;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
  scroll-behavior: smooth;
}

.chat-inner {
  width: 100%;
  max-width: 780px;
  margin: 0 auto;
  padding: 18px 14px 26px;
}

/* ================= WELCOME ================= */

.welcome {
  min-height: calc(100dvh - 300px);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 22px 6px 10px;
  animation: fadeIn .35s ease both;
}

.welcome-logo {
  width: 92px;
  height: 92px;
  object-fit: contain;
  margin-bottom: 16px;
  filter: drop-shadow(0 10px 26px rgba(37, 133, 237, .3));
}

.welcome h1 {
  font-size: 22px;
  font-weight: 750;
  letter-spacing: -.2px;
  margin-bottom: 7px;
  background: linear-gradient(100deg, #2585ed, #8bd5ff);
  color: transparent;
  background-clip: text;
  -webkit-background-clip: text;
}

body.dark .welcome h1 {
  background: linear-gradient(100deg, #65baff, #b8e5ff);
  color: transparent;
  background-clip: text;
  -webkit-background-clip: text;
}

.welcome p {
  font-size: 14px;
  color: var(--muted);
  max-width: 340px;
  line-height: 1.55;
}

.suggestions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 9px;
  width: 100%;
  max-width: 460px;
  margin-top: 24px;
}

.suggestion {
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 12px 13px;
  border: 1px solid var(--border);
  border-radius: 13px;
  background: var(--surface);
  font-size: 13px;
  text-align: left;
  color: var(--text);
  transition: transform .16s, border-color .16s, background .16s;
}

.suggestion:hover { border-color: var(--border-strong); background: var(--hover); }
.suggestion:active { transform: scale(.98); }
.suggestion svg { width: 17px; height: 17px; color: var(--purple); }
.suggestion span { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ================= MESSAGES ================= */

.messages {
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.msg {
  display: flex;
  flex-direction: column;
  animation: fadeIn .22s ease both;
}

.msg.user { align-items: flex-end; }
.msg.ai { align-items: flex-start; }

.msg-head {
  display: flex;
  align-items: center;
  gap: 7px;
  margin-bottom: 6px;
  font-size: 11.5px;
  color: var(--muted);
  font-weight: 600;
}

.msg-head img {
  width: 22px;
  height: 22px;
  border-radius: 50%;
  object-fit: cover;
  background: var(--hover);
}

.msg-head .ai-mark {
  width: 22px;
  height: 22px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  background: linear-gradient(135deg, #2585ed, #8bd5ff);
  color: #fff;
}

.msg-head .ai-mark svg { width: 13px; height: 13px; stroke-width: 2.2; }

.msg-body {
  max-width: min(88%, 660px);
  font-size: var(--chat-font);
  line-height: var(--chat-line);
  overflow-wrap: anywhere;
}

.msg.user .msg-body {
  background: rgba(190, 220, 255, 0.42); /* very light blue glass */
  color: #000000; /* black text */
  border: 1px solid rgba(0,0,0,0.1);
  border-radius: 16px;
  padding: 12px 16px;
  white-space: pre-wrap;
  box-shadow: 0 2px 8px rgba(0,0,0,0.06);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
}

.msg.ai .msg-body { padding: 0 2px; }

.msg.status-msg .msg-body {
  color: var(--muted);
  font-style: italic;
}

/* streaming caret */
.caret {
  display: inline-block;
  width: 7px;
  height: 1.02em;
  margin-left: 2px;
  vertical-align: -2px;
  border-radius: 2px;
  background: linear-gradient(180deg, var(--purple), var(--pink));
  animation: caretPulse 1s steps(2, start) infinite;
}

@keyframes caretPulse {
  0%, 100% { opacity: 1; }
  50% { opacity: .15; }
}

/* thinking dots */
.thinking {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 4px 0;
}

.thinking i {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--purple);
  opacity: .35;
  animation: dotBounce 1.15s infinite ease-in-out;
}

.thinking i:nth-child(2) { animation-delay: .16s; background: #65baff; }
.thinking i:nth-child(3) { animation-delay: .32s; background: var(--pink); }

@keyframes dotBounce {
  0%, 60%, 100% { transform: translateY(0); opacity: .35; }
  30% { transform: translateY(-4px); opacity: 1; }
}

/* delivery status under user message */
.send-status {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  margin-top: 5px;
  font-size: 11.5px;
  color: var(--muted);
}

.send-status svg { width: 12px; height: 12px; }
.send-status.failed { color: var(--danger); }

/* error card inside assistant message */
.msg-error {
  display: flex;
  flex-direction: column;
  gap: 9px;
  padding: 12px 13px;
  border: 1px solid rgba(229, 72, 77, .35);
  background: rgba(229, 72, 77, .07);
  border-radius: 13px;
  font-size: 13.5px;
  line-height: 1.5;
}

.msg-error .err-title {
  display: flex;
  align-items: center;
  gap: 7px;
  font-weight: 700;
  color: var(--danger);
}

.msg-error .err-title svg { width: 16px; height: 16px; }
.msg-error .err-detail { color: var(--muted); font-size: 12.5px; overflow-wrap: anywhere; }
.msg-error .err-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.msg-error .btn { min-height: 36px; font-size: 13px; }

/* ================= MARKDOWN ================= */

.md > *:first-child { margin-top: 0; }
.md > *:last-child { margin-bottom: 0; }

.md p { margin: 0 0 .78em; }

.md h1, .md h2, .md h3, .md h4 {
  font-weight: 720;
  line-height: 1.35;
  margin: 1.05em 0 .5em;
  letter-spacing: -.1px;
}

.md h1 { font-size: 1.32em; }
.md h2 { font-size: 1.2em; }
.md h3 { font-size: 1.09em; }
.md h4 { font-size: 1em; }

.md ul, .md ol { margin: 0 0 .78em; padding-left: 1.35em; }
.md li { margin: .22em 0; }
.md li > ul, .md li > ol { margin: .22em 0; }

.md blockquote {
  margin: 0 0 .78em;
  padding: 2px 0 2px 12px;
  border-left: 3px solid var(--purple);
  color: var(--muted);
}

.md a { color: var(--purple-strong); text-decoration: underline; text-underline-offset: 2px; }

.md hr {
  border: 0;
  height: 1px;
  background: var(--border);
  margin: 1em 0;
}

.md strong { font-weight: 700; }
.md em { font-style: italic; }

.md code.inline {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: .88em;
  background: var(--hover);
  border: 1px solid var(--border);
  border-radius: 5px;
  padding: 1px 5px;
}

.md table {
  width: 100%;
  border-collapse: collapse;
  margin: 0 0 .8em;
  font-size: .92em;
  display: block;
  overflow-x: auto;
}

.md th, .md td {
  border: 1px solid var(--border);
  padding: 6px 9px;
  text-align: left;
  white-space: nowrap;
}

.md th { background: var(--hover); font-weight: 700; }

/* code block */
.code-block {
  position: relative;
  margin: 0 0 .85em;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: #16131f;
  overflow: hidden;
}

.code-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 6px 8px 6px 12px;
  background: rgba(255, 255, 255, .05);
  border-bottom: 1px solid rgba(255, 255, 255, .07);
}

.code-lang {
  font-size: 11px;
  letter-spacing: .6px;
  text-transform: uppercase;
  color: #a99ec6;
  font-weight: 700;
}

.code-copy {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 4px 8px;
  border-radius: 7px;
  font-size: 11.5px;
  font-weight: 650;
  color: #d8d2ea;
  background: rgba(255, 255, 255, .08);
}

.code-copy:hover { background: rgba(255, 255, 255, .16); }
.code-copy svg { width: 13px; height: 13px; }

.code-block pre {
  margin: 0;
  padding: 11px 12px;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

.code-block code {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 12.8px;
  line-height: 1.6;
  color: #e7e2f5;
  white-space: pre;
}

/* syntax colors */
.tok-key { color: #c79bff; }
.tok-str { color: #9fe6a0; }
.tok-num { color: #ffcf7a; }
.tok-com { color: #7d7590; font-style: italic; }
.tok-fn { color: #7fd3ff; }
.tok-tag { color: #ff9ecb; }

/* ================= MESSAGE ACTIONS ================= */

.msg-actions {
  display: flex;
  align-items: center;
  gap: 2px;
  margin-top: 7px;
  flex-wrap: wrap;
}

.msg-actions button {
  height: 30px;
  min-width: 30px;
  padding: 0 6px;
  border-radius: 8px;
  display: inline-flex;
  align-items: center;
  gap: 5px;
  color: var(--muted);
  font-size: 12px;
  transition: background .16s, color .16s, transform .16s;
}

.msg-actions button:hover { background: var(--hover); color: var(--text); }
.msg-actions button:active { transform: scale(.92); }
.msg-actions button svg { width: 15px; height: 15px; }
.msg-actions button.active { color: var(--purple-strong); background: rgba(118, 85, 232, .12); }
.msg-actions button.danger:hover { color: var(--danger); }

.msg-time {
  font-size: 11px;
  color: var(--muted);
  margin-left: 4px;
}

/* ================= ATTACHMENTS ================= */

.msg-images {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
  margin-bottom: 7px;
}

.msg-images img {
  width: 108px;
  height: 108px;
  object-fit: cover;
  border-radius: 11px;
  border: 1px solid var(--border);
  cursor: zoom-in;
  background: var(--hover);
  transition: transform .16s;
}

.msg-images img:active { transform: scale(.97); }

.msg.user .msg-images { justify-content: flex-end; }

/* composer previews */
.image-preview {
  padding: 0 0 8px;
}

.preview-images {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding: 2px;
  -webkit-overflow-scrolling: touch;
}

.preview-item {
  position: relative;
  flex-shrink: 0;
  width: 66px;
  height: 66px;
  border-radius: 11px;
  overflow: hidden;
  border: 1px solid var(--border-strong);
  background: var(--hover);
}

.preview-item img { width: 100%; height: 100%; object-fit: cover; }

.preview-item .remove {
  position: absolute;
  top: 2px;
  right: 2px;
  width: 21px;
  height: 21px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  background: rgba(18, 14, 28, .78);
  color: #fff;
}

.preview-item .remove svg { width: 12px; height: 12px; stroke-width: 2.4; }

/* ================= COMPOSER ================= */

.composer-wrap {
  width: 100%;
  max-width: 780px;
  margin: 0 auto;
  padding: 6px 12px calc(8px + var(--safe-bottom));
  background: var(--bg);
}

/* Reserve the composer space from the first layout pass. This prevents the
   chat area from jumping when the composer finishes initializing on mobile. */
.composer-wrap {
  flex: 0 0 auto;
  min-height: 76px;
  align-self: stretch;
  box-sizing: border-box;
}

.edit-banner {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 7px;
  padding: 8px 10px;
  border-radius: 10px;
  background: rgba(118, 85, 232, .1);
  border: 1px solid rgba(118, 85, 232, .25);
  font-size: 12.5px;
  color: var(--purple-strong);
}

.edit-banner svg { width: 15px; height: 15px; }
.edit-banner span { flex: 1; min-width: 0; }

.composer {
  display: flex;
  align-items: flex-end;
  gap: 4px;
  padding: 6px;
  border: 1px solid var(--border-strong);
  border-radius: 22px;
  background: var(--surface);
  box-shadow: 0 4px 18px rgba(30, 20, 60, .06);
  transition: border-color .18s, box-shadow .18s;
}

.composer:focus-within {
  border-color: rgba(140, 203, 255, .45);
  box-shadow: 0 4px 22px rgba(140, 203, 255, .20);
}

.message-input {
  flex: 1;
  min-width: 0;
  max-height: 168px;
  padding: 9px 4px;
  border: 0;
  outline: 0;
  resize: none;
  background: transparent;
  font-size: 15.5px;
  line-height: 1.5;
  overflow-y: auto;
}

.message-input::placeholder { color: var(--muted); }

.send-btn {
  width: 38px;
  height: 38px;
  flex-shrink: 0;
  border-radius: 50%;
  display: grid;
  place-items: center;
  background: linear-gradient(135deg, #55B6FF, #287DEB);
  color: #fff;
  box-shadow: 0 4px 14px rgba(85, 182, 255, .22);
  transition: transform .16s, opacity .16s, filter .16s;
}

.send-btn:active { transform: scale(.92); }
.send-btn:disabled { opacity: .45; }
.send-btn svg { width: 19px; height: 19px; stroke-width: 2.2; }

.stop-btn {
  background: var(--text);
  color: var(--bg);
}

.voice-btn { color: #389BE8; }
.voice-btn.active {
  background: rgba(85, 182, 255, .14);
  color: #389BE8;
}

.composer-hint {
  text-align: center;
  font-size: 10.5px;
  color: var(--muted);
  margin-top: 6px;
  letter-spacing: .1px;
}

/* scroll to bottom */
.scroll-bottom {
  position: absolute;
  right: 14px;
  bottom: calc(112px + var(--safe-bottom));
  width: 38px;
  height: 38px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  background: var(--surface);
  border: 1px solid var(--border-strong);
  box-shadow: var(--shadow);
  color: var(--text);
  z-index: 6;
  animation: fadeIn .2s ease both;
}

.scroll-bottom svg { width: 18px; height: 18px; }

/* ================= IMAGE VIEWER ================= */

.viewer {
  position: fixed;
  inset: 0;
  z-index: 150;
  background: rgba(8, 6, 14, .94);
  display: grid;
  place-items: center;
  padding: 16px;
  animation: fadeIn .18s ease both;
}

.viewer img {
  max-width: 100%;
  max-height: 88dvh;
  border-radius: 10px;
  object-fit: contain;
}

.viewer-close {
  position: absolute;
  top: calc(12px + var(--safe-top));
  right: 12px;
  color: #fff;
  background: rgba(255, 255, 255, .12);
}

/* ================= RESPONSIVE ================= */

@media (min-width: 900px) {
  .sidebar {
    position: relative;
    transform: none;
    inset: auto;
    flex-shrink: 0;
  }

  .sidebar-overlay,
  #closeSidebar,
  #menuBtn { display: none; }

  .topbar-title { max-width: 40vw; }
  .chat-inner { padding: 24px 22px 30px; }
  .composer-wrap { padding: 8px 22px calc(10px + var(--safe-bottom)); }
  .msg-body { max-width: min(84%, 680px); }
}

@media (max-width: 380px) {
  .suggestions { grid-template-columns: 1fr; }
  .msg-images img { width: 92px; height: 92px; }
}

/* sending status styling */
.send-status-wrapper {
  margin-top: 4px;
  font-size: 10px;
  color: var(--muted);
  display: flex;
  align-items: center;
  gap: 4px;
}

.send-status {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px 6px;
  border-radius: 10px;
  background: rgba(0,0,0,0.04);
  font-size: 10px;
  color: var(--muted);
}

.send-status.failed {
  background: rgba(255,0,0,0.08);
  color: var(--danger);
}


/* Five-line user message with corner expand link */
.user-text.is-collapsed {
  display: -webkit-box;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 5;
  line-clamp: 5;
  overflow: hidden;
}

.user-text-toggle {
  display: block;
  width: fit-content;
  margin: 6px 0 0 auto;
  padding: 0;
  border: 0;
  background: none;
  color: #2585ed;
  font: inherit;
  font-size: 0.88em;
  font-weight: 600;
  text-align: right;
  cursor: pointer;
}

/* User message contextual actions */
.msg-actions:has(.user-action-menu) {
  margin: 0;
}

.user-action-menu {
  display: none;
  position: fixed;
  z-index: 9999;
  align-items: center;
  gap: 5px;
  padding: 6px;
  border: 1px solid var(--border-strong);
  border-radius: 13px;
  background: var(--surface);
  box-shadow: 0 8px 28px rgba(0, 0, 0, .2);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
}

.user-action-menu.menu-open {
  display: flex;
}

.user-action-menu button {
  min-width: 38px;
  height: 36px;
  justify-content: center;
}


/* AXON generated image panel */
.generated-image-panel {
  width: 100%;
  max-width: min(100%, 720px);
  margin-top: 8px;
}

.generated-image {
  display: block;
  width: 100%;
  height: auto;
  max-height: 75vh;
  object-fit: contain;
  border-radius: 14px;
  cursor: zoom-in;
  background: var(--surface);
}

.generated-image-actions {
  display: flex;
  align-items: center;
  gap: 9px;
  margin-top: 10px;
}

.generated-image-actions button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 34px;
  min-width: 34px;
  height: 34px;
  padding: 0;
  border: 1px solid rgba(59, 130, 246, .2);
  border-radius: 10px;
  color: #2585ed;
  background: rgba(59, 130, 246, .11);
  transition: background .16s, transform .16s;
}

.generated-image-actions button:hover {
  color: #1670dc;
  background: rgba(59, 130, 246, .2);
}

.generated-image-actions button:active {
  transform: scale(.92);
}

.generated-image-actions button svg {
  width: 16px;
  height: 16px;
}

.generated-image-error {
  color: var(--danger);
  margin: 8px 0;
}
