/* Chat page: session list, conversation, tool cards, composer, floating tool dropdowns. */

.chat {
  position: relative;
  display: grid;
  grid-template-columns: 290px minmax(0, 1fr);
  height: 100%;
}

/* ----------------------------------------------------------- session list */

.chat-side {
  display: flex;
  flex-direction: column;
  min-height: 0;
  border-right: 1px solid var(--border);
  background: color-mix(in srgb, var(--surface) 55%, transparent);
}

.chat-side-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 18px 16px 12px;
}

.session-list {
  flex: 1;
  min-height: 0;
  overflow: auto;
  padding: 4px 10px 14px;
}

.session-row {
  position: relative;
  margin-bottom: 2px;
}

.session-item {
  display: flex;
  align-items: center;
  gap: 11px;
  padding: 10px 40px 10px 12px;
  border-radius: 12px;
  transition: background 0.15s;
  animation: fade-up 0.3s var(--ease) both;
}

.session-row:hover .session-item {
  background: var(--surface-3);
}

.session-row.active .session-item {
  background: color-mix(in srgb, var(--accent) 15%, transparent);
}

.session-text {
  min-width: 0;
  display: grid;
}

.session-title {
  display: flex;
  align-items: center;
  gap: 6px;
  overflow: hidden;
  font-weight: 600;
  font-size: 0.9rem;
  white-space: nowrap;
  text-overflow: ellipsis;
}

.session-sub {
  overflow: hidden;
  font-size: 0.76rem;
  color: var(--text-3);
  white-space: nowrap;
  text-overflow: ellipsis;
}

.session-del {
  position: absolute;
  top: 50%;
  right: 8px;
  transform: translateY(-50%);
  opacity: 0;
  transition: opacity 0.15s;
}

.session-row:hover .session-del,
.session-del:focus-visible {
  opacity: 1;
}

.side-empty {
  padding: 18px;
  text-align: center;
  font-size: 0.88rem;
  color: var(--text-3);
}

/* ------------------------------------------------------------- main column */

.chat-main {
  position: relative;
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
}

.chat-head {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 62px;
  padding: 12px 84px 12px 24px;
  border-bottom: 1px solid var(--border);
}

.chat-head-text {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 4px 12px;
  min-width: 0;
}

.chat-title {
  max-width: 100%;
  overflow: hidden;
  font-size: 1.05rem;
  white-space: nowrap;
  text-overflow: ellipsis;
}

.chat-status {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  font-size: 0.8rem;
  color: var(--text-2);
}

.chat-status .is-running {
  color: var(--accent);
  font-weight: 600;
}

.side-toggle {
  display: none;
}

/* Stacked, frameless tool dropdowns at the top right of the chat. */
.chat-tools {
  position: absolute;
  top: 8px;
  right: 14px;
  z-index: 40;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 2px;
}

.tool-dd {
  position: relative;
  display: flex;
  justify-content: flex-end;
}

.tool-trigger {
  display: flex;
  flex-direction: row-reverse;
  align-items: center;
  gap: 0;
  height: 38px;
  padding: 0 9px;
  border: 0;
  border-radius: 11px;
  background: transparent;
  color: var(--text-2);
  transition: background 0.2s, color 0.2s, gap 0.25s var(--ease);
}

.tool-trigger-label {
  max-width: 0;
  overflow: hidden;
  font-size: 0.84rem;
  font-weight: 600;
  white-space: nowrap;
  opacity: 0;
  transition: max-width 0.3s var(--ease), opacity 0.2s;
}

.tool-trigger:hover,
.tool-trigger:focus-visible,
.tool-trigger[aria-expanded="true"] {
  gap: 8px;
  background: color-mix(in srgb, var(--text) 8%, transparent);
  color: var(--text);
}

.tool-trigger:hover .tool-trigger-label,
.tool-trigger:focus-visible .tool-trigger-label,
.tool-trigger[aria-expanded="true"] .tool-trigger-label {
  max-width: 80px;
  opacity: 1;
}

.tool-trigger[aria-expanded="true"] {
  color: var(--accent);
}

.trigger-icon {
  position: relative;
  display: grid;
}

.trigger-dot {
  position: absolute;
  top: -3px;
  right: -3px;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  color: var(--accent);
  background: var(--accent);
  animation: pulse 1.6s infinite;
}

.drop-overlay {
  position: absolute;
  inset: 8px;
  z-index: 70;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
  border: 2px dashed var(--accent);
  border-radius: var(--radius-xl);
  background: color-mix(in srgb, var(--bg) 78%, var(--accent) 10%);
  backdrop-filter: blur(6px);
  font-weight: 650;
  color: var(--accent);
  animation: fade-in 0.15s ease;
  pointer-events: none;
}

/* ------------------------------------------------------------ conversation */

.conv {
  position: relative;
  flex: 1;
  min-height: 0;
}

.conv-scroll {
  height: 100%;
  overflow-y: auto;
  scroll-behavior: auto;
}

.conv-stream {
  display: flex;
  flex-direction: column;
  gap: 18px;
  max-width: 860px;
  margin: 0 auto;
  padding: 28px 24px 36px;
}

.conv-stream.instant *,
.conv-stream.instant {
  animation-duration: 0.001ms !important;
}

.scroll-down {
  position: absolute;
  left: 50%;
  bottom: 14px;
  z-index: 10;
  display: inline-flex;
  align-items: center;
  gap: 7px;
  height: 34px;
  padding: 0 14px;
  border: 1px solid var(--border-strong);
  border-radius: 99px;
  background: var(--glass);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  box-shadow: var(--shadow);
  font-size: 0.82rem;
  font-weight: 600;
  transform: translateX(-50%);
  animation: fade-up 0.25s var(--ease);
}

.scroll-down:hover {
  border-color: var(--accent);
}

/* empty state */
.conv-empty {
  position: absolute;
  inset: 0;
  z-index: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 24px;
  text-align: center;
  pointer-events: none;
  animation: fade-in 0.5s ease;
}

.conv-empty > * {
  pointer-events: auto;
}

.conv-empty-orb {
  display: grid;
  place-items: center;
  width: 68px;
  height: 68px;
  margin-bottom: 6px;
  border-radius: 22px;
  color: #fff;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  box-shadow: 0 14px 40px color-mix(in srgb, var(--accent) 45%, transparent);
  animation: float-orb 8s ease-in-out infinite;
}

.conv-empty h2 {
  font-size: 1.4rem;
  letter-spacing: -0.02em;
}

.conv-empty p {
  max-width: 440px;
}

.suggest-row {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 8px;
  max-width: 640px;
  margin-top: 16px;
}

.suggest {
  padding: 9px 14px;
  border: 1px solid var(--border-strong);
  border-radius: 99px;
  background: var(--surface);
  font-size: 0.85rem;
  color: var(--text-2);
  transition: border-color 0.2s, color 0.2s, transform 0.15s var(--ease), background 0.2s;
}

.suggest:hover {
  border-color: var(--accent);
  color: var(--text);
  background: color-mix(in srgb, var(--accent) 8%, var(--surface));
  transform: translateY(-1px);
}

/* messages */
.msg {
  display: flex;
  gap: 12px;
  animation: fade-up 0.35s var(--ease) both;
}

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

.bubble {
  max-width: min(640px, 86%);
  padding: 11px 16px;
  border-radius: 20px 20px 6px 20px;
  color: var(--accent-ink);
  background: linear-gradient(135deg, var(--accent), color-mix(in srgb, var(--accent) 60%, var(--accent-2)));
  box-shadow: 0 6px 20px color-mix(in srgb, var(--accent) 25%, transparent);
}

.bubble-text {
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.bubble-atts {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 8px;
}

.avatar {
  flex: none;
  display: grid;
  place-items: center;
  width: 30px;
  height: 30px;
  margin-top: 2px;
  border-radius: 10px;
  color: #fff;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
}

.msg-assistant .msg-body {
  flex: 1;
  min-width: 0;
  padding-top: 3px;
}

.msg-assistant.streaming .msg-body > :last-child::after {
  content: "";
  display: inline-block;
  width: 8px;
  height: 1.05em;
  margin-left: 3px;
  vertical-align: text-bottom;
  border-radius: 2px;
  background: var(--accent);
  animation: pulse-caret 1s steps(2) infinite;
}

@keyframes pulse-caret {
  50% { opacity: 0; }
}

/* markdown */
.md > :first-child { margin-top: 0; }
.md > :last-child { margin-bottom: 0; }
.md p { margin: 0 0 0.8em; overflow-wrap: anywhere; }
.md h1, .md h2, .md h3, .md h4 { margin: 1.2em 0 0.5em; line-height: 1.3; letter-spacing: -0.01em; }
.md h1 { font-size: 1.3rem; }
.md h2 { font-size: 1.15rem; }
.md h3 { font-size: 1.02rem; }
.md ul, .md ol { margin: 0 0 0.8em; padding-left: 1.4em; }
.md li { margin: 0.2em 0; }
.md a { color: var(--accent); text-decoration: underline; text-underline-offset: 2px; }
.md blockquote { margin: 0 0 0.8em; padding: 2px 14px; border-left: 3px solid var(--accent); color: var(--text-2); }
.md hr { border: 0; border-top: 1px solid var(--border-strong); margin: 1.2em 0; }
.md code { padding: 1px 6px; border-radius: 6px; background: var(--surface-3); font-family: var(--mono); font-size: 0.86em; }
.md table { display: block; max-width: 100%; margin: 0 0 0.9em; overflow-x: auto; border-collapse: collapse; font-size: 0.9rem; }
.md th, .md td { padding: 7px 12px; border: 1px solid var(--border-strong); text-align: left; }
.md th { background: var(--surface-2); }

.md pre {
  position: relative;
  margin: 0 0 0.9em;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--code-bg);
  overflow: hidden;
}

.md pre code {
  display: block;
  padding: 12px 14px;
  overflow-x: auto;
  background: transparent;
  font-size: 0.84rem;
  line-height: 1.55;
}

.code-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 5px 8px 5px 14px;
  border-bottom: 1px solid var(--border);
  background: var(--surface-2);
}

.code-lang {
  font-family: var(--mono);
  font-size: 0.74rem;
  color: var(--text-3);
}

.code-copy {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 26px;
  padding: 0 9px;
  border: 0;
  border-radius: 7px;
  background: transparent;
  font-size: 0.76rem;
  color: var(--text-2);
}

.code-copy:hover {
  background: var(--surface-3);
  color: var(--text);
}

/* thinking */
.think {
  margin-left: 42px;
  font-size: 0.88rem;
  color: var(--text-3);
  animation: fade-up 0.3s var(--ease) both;
}

.think summary {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 4px 4px;
  border-radius: 8px;
  cursor: pointer;
  list-style: none;
  user-select: none;
}

.think summary::-webkit-details-marker { display: none; }
.think summary:hover { color: var(--text-2); }

.think.live .think-label {
  background: linear-gradient(90deg, var(--text-3) 30%, var(--accent) 50%, var(--text-3) 70%);
  background-size: 200% 100%;
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
  animation: shimmer 1.8s linear infinite;
}

.think-text {
  margin: 4px 0 4px 6px;
  padding: 4px 0 4px 14px;
  border-left: 2px solid var(--border-strong);
  font-style: italic;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  max-height: 260px;
  overflow: auto;
}

.chev {
  transition: transform 0.2s var(--ease);
}

details[open] > summary > .chev {
  transform: rotate(90deg);
}

/* tool cards */
.tool {
  margin-left: 42px;
  border: 1px solid var(--border);
  border-radius: 13px;
  background: var(--surface);
  overflow: hidden;
  transition: border-color 0.25s, background 0.25s;
  animation: fade-up 0.3s var(--ease) both;
}

.tool.pending {
  border-color: color-mix(in srgb, var(--accent) 40%, var(--border));
}

.tool.error {
  border-color: color-mix(in srgb, var(--danger) 45%, var(--border));
}

.tool summary {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 42px;
  padding: 8px 12px;
  cursor: pointer;
  list-style: none;
  user-select: none;
}

.tool summary::-webkit-details-marker { display: none; }
.tool summary:hover { background: var(--surface-2); }

.tool-icon {
  display: grid;
  place-items: center;
  flex: none;
  width: 28px;
  height: 28px;
  border-radius: 9px;
  color: var(--accent);
  background: color-mix(in srgb, var(--accent) 13%, transparent);
}

.tool.error .tool-icon {
  color: var(--danger);
  background: color-mix(in srgb, var(--danger) 13%, transparent);
}

.tool-name {
  display: flex;
  align-items: center;
  gap: 8px;
  flex: none;
  font-weight: 650;
  font-size: 0.88rem;
}

.tool-server {
  padding: 0 7px;
  border-radius: 99px;
  font-size: 0.68rem;
  font-weight: 600;
  color: var(--text-3);
  background: var(--surface-3);
}

.tool-sum {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  font-family: var(--mono);
  font-size: 0.78rem;
  color: var(--text-2);
  white-space: nowrap;
  text-overflow: ellipsis;
}

.tool-status {
  display: grid;
  place-items: center;
  flex: none;
  width: 20px;
  color: var(--text-3);
}

.tool.done .tool-status { color: var(--ok); }
.tool.error .tool-status { color: var(--danger); }

.tool-body {
  display: grid;
  gap: 10px;
  padding: 4px 12px 12px;
  border-top: 1px solid var(--border);
}

.tool-section-title {
  margin: 8px 0 4px;
  font-size: 0.68rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-3);
}

.tool-pre {
  margin: 0;
  padding: 10px 12px;
  max-height: 280px;
  overflow: auto;
  border-radius: 10px;
  background: var(--code-bg);
  font-family: var(--mono);
  font-size: 0.78rem;
  line-height: 1.5;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

/* typing indicator, result, banners, notices */
.typing {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-left: 42px;
  font-size: 0.86rem;
  color: var(--text-3);
  animation: fade-in 0.3s ease;
}

.typing-dots {
  display: inline-flex;
  gap: 4px;
}

.typing-dots i {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--accent);
  animation: bounce-dot 1.2s infinite;
}

.typing-dots i:nth-child(2) { animation-delay: 0.15s; }
.typing-dots i:nth-child(3) { animation-delay: 0.3s; }

.result-line {
  margin-left: 42px;
  font-size: 0.76rem;
  color: var(--text-3);
}

.result-line.is-error {
  color: var(--danger);
}

.banner {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  margin-left: 42px;
  padding: 11px 14px;
  border-radius: 12px;
  font-size: 0.9rem;
  animation: fade-up 0.3s var(--ease) both;
}

.banner-error {
  color: var(--danger);
  background: color-mix(in srgb, var(--danger) 11%, transparent);
  border: 1px solid color-mix(in srgb, var(--danger) 35%, transparent);
}

.banner span {
  overflow-wrap: anywhere;
}

.notice-chip {
  align-self: center;
  display: inline-flex;
  align-items: center;
  gap: 7px;
  max-width: 100%;
  padding: 4px 12px;
  border-radius: 99px;
  font-size: 0.78rem;
  color: var(--text-2);
  background: var(--surface-3);
  animation: scale-in 0.3s var(--ease) both;
}

/* ---------------------------------------------------------------- composer */

.composer {
  position: relative;
  width: 100%;
  max-width: 884px;
  margin: 0 auto;
  padding: 0 24px 14px;
}

.composer-chips {
  display: none;
  flex-wrap: wrap;
  gap: 8px;
  padding: 0 6px 10px;
}

.composer-chips.has-items {
  display: flex;
}

.composer-bar {
  display: flex;
  align-items: flex-end;
  gap: 4px;
  padding: 8px;
  border: 1px solid var(--border-strong);
  border-radius: 28px;
  background: var(--surface);
  box-shadow: 0 8px 30px rgba(0, 0, 0, 0.18);
  transition: border-color 0.2s, box-shadow 0.25s;
}

.composer-bar:focus-within {
  border-color: var(--accent);
  box-shadow: 0 8px 34px rgba(0, 0, 0, 0.22), 0 0 0 3px color-mix(in srgb, var(--accent) 20%, transparent);
}

.composer.is-running .composer-bar {
  border-color: color-mix(in srgb, var(--accent) 45%, var(--border-strong));
}

.composer-input {
  flex: 1;
  min-width: 0;
  max-height: 220px;
  padding: 9px 8px;
  border: 0;
  outline: none;
  resize: none;
  background: transparent;
  line-height: 1.5;
}

.composer-input::placeholder {
  color: var(--text-3);
}

.composer-btn {
  display: grid;
  place-items: center;
  flex: none;
  width: 38px;
  height: 38px;
  border: 0;
  border-radius: 50%;
  background: transparent;
  color: var(--text-2);
  transition: background 0.2s, color 0.2s, transform 0.2s var(--ease);
}

.composer-btn:hover {
  background: var(--surface-3);
  color: var(--text);
}

.composer-btn[aria-expanded="true"] {
  color: var(--accent);
  background: color-mix(in srgb, var(--accent) 14%, transparent);
}

.composer-btn[aria-expanded="true"] .icon {
  transform: rotate(60deg);
  transition: transform 0.4s var(--ease);
}

.send-btn {
  display: grid;
  place-items: center;
  flex: none;
  width: 38px;
  height: 38px;
  border: 0;
  border-radius: 50%;
  color: var(--accent-ink);
  background: linear-gradient(135deg, var(--accent), color-mix(in srgb, var(--accent) 55%, var(--accent-2)));
  box-shadow: 0 4px 14px color-mix(in srgb, var(--accent) 38%, transparent);
  transition: transform 0.2s var(--ease-spring), opacity 0.2s, background 0.3s;
}

.send-btn:hover:not(:disabled) {
  transform: scale(1.08);
}

.send-btn:active:not(:disabled) {
  transform: scale(0.94);
}

.send-btn:disabled {
  opacity: 0.35;
  box-shadow: none;
}

.send-btn.is-stop {
  color: #fff;
  background: var(--danger);
  box-shadow: 0 4px 14px color-mix(in srgb, var(--danger) 40%, transparent);
  animation: pulse 1.8s infinite;
}

.composer-hint {
  padding: 8px 14px 0;
  text-align: center;
  font-size: 0.72rem;
  color: var(--text-3);
}

/* ---------------------------------------------------------------- responsive */

@media (max-width: 1000px) {
  .chat {
    grid-template-columns: minmax(0, 1fr);
  }

  .chat-side {
    position: absolute;
    top: 0;
    bottom: 0;
    left: 0;
    z-index: 90;
    width: min(320px, 86vw);
    background: var(--surface);
    box-shadow: var(--shadow);
    transform: translateX(-102%);
    transition: transform 0.3s var(--ease);
  }

  .chat.side-open .chat-side {
    transform: none;
  }

  .side-toggle {
    display: inline-grid;
    flex: none;
  }

  .chat-head {
    padding-left: 12px;
  }
}

@media (max-width: 600px) {
  .conv-stream {
    padding: 20px 14px 28px;
  }

  .composer {
    padding: 0 10px 10px;
  }

  .think,
  .tool,
  .typing,
  .result-line,
  .banner {
    margin-left: 0;
  }

  .tool-name .tool-server {
    display: none;
  }

  .composer-hint {
    display: none;
  }
}
