:root { --chat-width: min(410px, calc(100vw - 26px)); }

.chat-launch, .chat-panel {
  --chat-shadow: 0 6px 24px rgb(var(--shadow-rgb) / .12), 0 1px 4px rgb(var(--shadow-rgb) / .08);
}
.chat-launch {
  position: fixed;
  right: 22px;
  bottom: max(20px, env(safe-area-inset-bottom));
  z-index: 5;
  display: flex;
  min-height: 48px;
  align-items: center;
  gap: 9px;
  padding: 0 17px 0 13px;
  border: 1px solid transparent;
  border-radius: 19px 19px 5px 19px;
  background: var(--accent);
  box-shadow: var(--chat-shadow);
  color: var(--surface);
  font-weight: 700;
  transition: translate 160ms ease, background 160ms ease, box-shadow 160ms ease;
}
.chat-launch:hover { translate: 0 -2px; background: var(--accent-dark); }
.chat-launch:active { translate: 0 1px; }
.chat-launch.chat-unread { box-shadow: 0 0 0 4px var(--tint), var(--chat-shadow); }
.chat-panel {
  position: fixed;
  z-index: 6;
  right: 13px;
  bottom: 13px;
  display: flex;
  width: var(--chat-width);
  height: min(680px, calc(100dvh - 26px));
  flex-direction: column;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: var(--surface-radius) var(--surface-radius) 10px var(--surface-radius);
  background: var(--surface);
  box-shadow: var(--chat-shadow);
  color: var(--ink);
  transform-origin: right bottom;
}
.chat-panel[data-entering] { animation: mine-panel-in 250ms cubic-bezier(.16, 1, .3, 1) both; }
.chat-panel[data-closing] { pointer-events: none; animation: mine-panel-out 150ms ease-in both; }
.chat-panel:has(.chat-start:not([hidden])) {
  background-image:
    radial-gradient(ellipse 100% 42% at 36% 94%, rgb(var(--sky-rgb) / .72), transparent),
    radial-gradient(ellipse 76% 39% at 87% 88%, rgb(var(--sky-soft-rgb) / .74), transparent),
    linear-gradient(180deg, #fafafb, #fff 47%, #eef7ff);
}
.chat-header {
  position: relative;
  z-index: 4;
  display: flex;
  flex: none;
  align-items: center;
  gap: 9px;
  padding: 12px 13px 11px;
  border-bottom: 1px solid var(--line);
  background: var(--surface);
}
.chat-panel:has(.chat-start:not([hidden])) .chat-header { border-bottom-color: transparent; background: transparent; }
.chat-mark {
  display: grid;
  width: 43px;
  height: 43px;
  flex: none;
  place-items: center;
  border-radius: 15px 15px 5px 15px;
  background: var(--control);
  color: var(--ink);
  font-size: 1.28rem;
}
.chat-name { flex: 1; min-width: 0; }
.chat-name h2 { font-size: 1.12rem; line-height: 1.15; }
.chat-select { position: relative; min-width: 0; }
.chat-select select {
  display: block;
  width: 100%;
  min-height: 32px;
  padding: 4px 23px 4px 9px;
  appearance: none;
  overflow: hidden;
  border: 1px solid transparent;
  border-radius: 10px;
  background: var(--subtle);
  color: var(--ink);
  font-size: .87rem;
  text-overflow: ellipsis;
}
.chat-select > .icon {
  position: absolute;
  top: 50%;
  right: 5px;
  width: 16px;
  height: 16px;
  transform: translateY(-50%);
  color: var(--muted);
  pointer-events: none;
}
.chat-select select:not(:disabled):hover { background: var(--control); }
.chat-model-picker { width: clamp(96px, 29%, 116px); flex: none; }
.chat-model-picker:has(.chat-model-trigger:not([hidden])) > .icon { display: none; }
.chat-model-trigger {
  display: flex;
  width: 100%;
  min-height: 32px;
  align-items: center;
  justify-content: space-between;
  gap: 4px;
  padding: 4px 6px;
  border: 1px solid transparent;
  border-radius: 10px;
  background: transparent;
  color: var(--ink);
  font-size: .87rem;
  text-align: left;
}
.chat-model-trigger span { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chat-model-trigger .icon { width: 15px; height: 15px; flex: none; color: var(--muted); }
.chat-model-trigger:not(:disabled):hover { background: var(--control); }
.chat-model-trigger[aria-expanded="true"] { background: var(--tint); }
.chat-model-trigger[aria-expanded="true"] .icon { rotate: 180deg; }
.chat-model-trigger:disabled { color: var(--muted); opacity: .75; }
.chat-model-menu {
  position: absolute;
  z-index: 2;
  right: 3px;
  bottom: calc(100% + 8px);
  width: min(322px, calc(100% - 6px));
  max-height: min(420px, max(98px, calc(100dvh - 210px)));
  overflow: auto;
  padding: 6px;
  overscroll-behavior: contain;
  scrollbar-width: thin;
  scrollbar-color: var(--scroll-thumb) transparent;
  border: 1px solid var(--line);
  border-radius: 17px;
  background: var(--surface);
  box-shadow: var(--chat-shadow);
  animation: mine-content-in 150ms ease-out both;
}
.chat-model-choice {
  display: flex;
  width: 100%;
  min-height: 58px;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 8px 11px;
  border: 1px solid transparent;
  border-radius: 11px;
  background: transparent;
  color: var(--ink);
  text-align: left;
}
.chat-model-choice + .chat-model-choice { margin-top: 2px; }
.chat-model-choice:hover { background: var(--subtle); }
.chat-model-choice:focus-visible { outline-offset: -2px; }
.chat-model-choice[aria-selected="true"] { border-color: #d2e5ff; background: var(--tint); }
.chat-model-choice-text { display: grid; min-width: 0; gap: 3px; overflow-wrap: anywhere; }
.chat-model-choice-name { font-size: .95rem; font-weight: 620; line-height: 1.3; }
.chat-model-choice small { color: var(--muted); font-size: .81rem; line-height: 1.35; }
.chat-model-check { visibility: hidden; flex: none; color: var(--accent-dark); }
.chat-model-choice[aria-selected="true"] .chat-model-check { visibility: visible; }
.chat-icon, .chat-answer-action {
  display: grid;
  flex: none;
  place-items: center;
  border: 0;
  background: transparent;
  color: var(--muted);
  transition: background 150ms ease, scale 150ms ease;
}
.chat-icon { width: 39px; height: 40px; border-radius: 12px; font-size: 1.16rem; }
#chat-options { border-radius: 50%; }
.chat-icon:hover, .chat-answer-action:hover { background: var(--subtle); color: var(--ink); }
.chat-icon[aria-expanded="true"] { background: var(--tint); color: var(--accent-dark); }
.chat-icon:active, .chat-answer-action:active { scale: .93; }

.chat-config, .chat-log {
  overflow: auto;
  overscroll-behavior: contain;
  scrollbar-width: thin;
  scrollbar-color: var(--scroll-thumb) transparent;
}
.chat-config-dismiss { position: absolute; z-index: 2; inset: 0; border: 0; background: transparent; cursor: default; }
.chat-config-layer { position: relative; z-index: 3; height: 0; flex: none; }
.chat-config {
  position: absolute;
  inset: 2px 11px auto;
  max-height: min(475px, calc(100dvh - 125px));
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 19px;
  background: var(--surface);
  box-shadow: var(--chat-shadow);
}
.chat-config:not([hidden]) { animation: mine-content-in 180ms ease-out both; }
.chat-config-heading { display: flex; justify-content: space-between; align-items: center; gap: 8px; margin-bottom: 10px; }
.chat-config-back {
  display: flex; align-items: center; gap: 3px; min-height: 34px; padding: 3px 8px;
  border: 0; border-radius: 8px; background: var(--subtle); color: var(--ink); font-size: .85rem;
}
.chat-config-back:hover { background: var(--control); }
.chat-config-back .icon { rotate: 90deg; }
.chat-config label { display: block; margin-bottom: 4px; font-size: .88rem; font-weight: 650; }
.chat-config h3 { margin: 0; font-size: .98rem; }
.chat-config form { margin: 0 0 8px; padding: 13px; border: 1px solid var(--line); border-radius: 14px; background: var(--surface); }
.chat-config input[type="password"], .chat-config textarea {
  width: 100%;
  min-height: 42px;
  padding: 8px 10px;
  border: 1px solid var(--control-border);
  border-radius: 9px;
  background: var(--surface);
  color: var(--ink);
  font-size: .94rem;
  line-height: 1.45;
}
.chat-config textarea { resize: vertical; }
#chat-key-config { margin-bottom: 12px; }
.chat-hint { margin: 5px 0; color: var(--muted); font-size: .83rem; line-height: 1.4; }
.chat-hint:empty { display: none; }
.chat-hint a { color: var(--accent-dark); }
.chat-memory-fields { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin: 9px 0; }
.chat-memory-actions { display: flex; flex-wrap: wrap; gap: 7px; margin-top: 7px; }

.chat-log {
  position: relative;
  display: flex;
  flex: 1;
  min-height: 0;
  flex-direction: column;
  gap: 15px;
  padding: 12px 14px 11px;
}
.chat-log:focus-visible { outline-offset: -3px; }
.chat-start { display: flex; flex: 1 0 auto; min-width: 0; flex-direction: column; }
.chat-welcome { display: grid; flex: 1 0 auto; min-height: 150px; align-content: center; justify-items: center; padding: 12px 9px 18px; text-align: center; }
.chat-start-mark { width: 42px; height: 42px; margin-bottom: 12px; border-radius: 15px 15px 6px 15px; background: var(--subtle); font-size: 1.2rem; }
.chat-welcome h3 { max-width: 23ch; margin: 0; font-size: 1.63rem; font-weight: 650; line-height: 1.23; overflow-wrap: anywhere; }
.chat-welcome p { max-width: 31ch; margin: 7px 0 0; color: #465462; font-size: .94rem; line-height: 1.45; }
.chat-chips { display: flex; flex-direction: column; align-items: flex-start; gap: 7px; }
.chat-chips button {
  display: flex;
  min-height: 40px;
  max-width: 100%;
  align-items: center;
  gap: 9px;
  padding: 8px 13px;
  border: 1px solid rgb(255 255 255 / .92);
  border-radius: 999px;
  background: rgb(255 255 255 / .92);
  box-shadow: 0 1px 3px rgb(var(--shadow-rgb) / .07);
  color: var(--ink);
  font-size: .9rem;
  line-height: 1.25;
  text-align: left;
  transition: background 150ms ease, border-color 150ms ease, translate 150ms ease;
}
.chat-chips button .icon { flex: none; color: var(--muted); }
.chat-chips button:hover { translate: 0 -1px; border-color: var(--control-border); background: var(--surface); }
.chat-chips button:active { translate: 0 1px; }
.chat-message, .chat-typing { flex: 0 0 auto; min-width: 0; animation: mine-content-in 200ms cubic-bezier(.2, .75, .35, 1) both; }
.chat-message { max-width: 100%; font-size: 1rem; line-height: 1.57; overflow-wrap: anywhere; }
.chat-message.user {
  align-self: flex-end;
  max-width: 87%;
  padding: 9px 13px;
  border-radius: 16px 16px 5px 16px;
  background: var(--accent);
  color: var(--surface);
}
.chat-message.user p { margin: 0; white-space: pre-wrap; }
.chat-typing { display: flex; align-items: flex-start; gap: 8px; }
.chat-message-mark { width: 29px; height: 29px; margin-top: 3px; border-radius: 10px 10px 4px 10px; font-size: .92rem; }
.chat-answer {
  padding: 2px 5px 4px;
  line-height: 1.65;
}
.chat-message-content > :first-child { margin-top: 0; }
.chat-message-content > :last-child { margin-bottom: 0; }
.chat-message-content p { margin: 0 0 .9em; white-space: pre-wrap; }
.chat-message-content h4 { margin: 1em 0 .4em; font-size: 1.08em; font-weight: 670; line-height: 1.4; }
.chat-message-content ul, .chat-message-content ol { margin: 0 0 .85em; padding-left: 1.42em; }
.chat-message-content li { padding-left: .1em; white-space: pre-wrap; }
.chat-message-content li + li { margin-top: .25em; }
.chat-message-content pre { max-width: 100%; margin: 0 0 .85em; padding: 9px; overflow: auto; border-radius: 9px; background: var(--subtle); }
.chat-message-content code { border-radius: 4px; background: var(--subtle); font-size: .88em; }
.chat-message-content a { color: var(--accent-dark); text-decoration: underline; text-underline-offset: 2px; }
.chat-followups { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; margin-top: 15px; }
.chat-message.assistant:not(:last-child) .chat-followups { display: none; }
.chat-followups button {
  min-height: 59px;
  padding: 9px 11px;
  overflow-wrap: anywhere;
  border: 1px solid var(--line);
  border-radius: 13px;
  background: var(--subtle);
  color: var(--ink);
  font-size: .88rem;
  line-height: 1.35;
  text-align: left;
}
.chat-followups button:hover { background: var(--tint); color: var(--accent-dark); }
.chat-answer-meta {
  display: flex;
  min-height: 31px;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-top: 8px;
}
.chat-answer-actions { display: flex; align-items: center; gap: 4px; }
.chat-answer-model { color: var(--muted); font-size: .76rem; line-height: 1.3; }
.chat-answer-model:empty { display: none; }
.chat-answer-action { width: 36px; height: 36px; border-radius: 8px; font-size: .93rem; }
.chat-copy[data-copied] { background: var(--tint); color: var(--accent-dark); }
.chat-typing-bubble {
  display: flex;
  min-height: 35px;
  align-items: center;
  gap: 9px;
  padding: 6px 11px;
  border: 1px solid var(--line);
  border-radius: 5px 14px 14px;
  background: var(--subtle);
  color: var(--muted);
  font-size: .85rem;
}
.chat-dots { display: flex; flex: none; align-items: center; gap: 3px; }
.chat-dots i { width: 5px; height: 5px; border-radius: 50%; background: var(--muted); animation: mine-dot 980ms ease-in-out infinite; }
.chat-dots i:nth-child(2) { animation-delay: 100ms; }
.chat-dots i:nth-child(3) { animation-delay: 200ms; }
.chat-message[data-streaming] .chat-message-content > :last-child::after {
  display: inline-block; width: 6px; height: 6px; margin-left: 4px;
  border-radius: 50%; background: var(--accent); content: "";
  animation: mine-dot 980ms ease-in-out infinite;
}
.chat-compose {
  position: relative;
  flex: none;
  margin: 0 10px 10px;
  padding: 4px;
  border: 1px solid var(--line);
  border-radius: 24px;
  background: var(--surface);
  box-shadow: 0 2px 8px rgb(var(--shadow-rgb) / .07);
}
.chat-compose > .chat-hint { margin: 3px 10px 5px; }
.chat-context-menu { flex: none; }
.chat-context-trigger { color: var(--ink); cursor: pointer; list-style: none; }
.chat-context-trigger::-webkit-details-marker { display: none; }
.chat-context-trigger[data-linked], .chat-context-menu[open] > .chat-context-trigger { background: var(--tint); color: var(--accent-dark); }
.chat-context-card {
  position: absolute;
  z-index: 2;
  left: 3px;
  bottom: calc(100% + 8px);
  width: min(278px, calc(100% - 6px));
  padding: 11px 12px;
  border: 1px solid var(--line);
  border-radius: 17px;
  background: var(--surface);
  box-shadow: var(--chat-shadow);
}
.chat-context-card label { display: block; margin-bottom: 6px; font-size: .89rem; font-weight: 650; }
.chat-privacy { margin-top: 7px; }
.chat-privacy > summary {
  display: flex; align-items: center; gap: 6px; min-height: 32px; padding: 3px 4px;
  border-radius: 7px; color: var(--muted); font-size: .85rem; list-style: none; cursor: pointer;
}
.chat-privacy > summary:hover, .chat-privacy[open] > summary { background: var(--subtle); color: var(--ink); }
.chat-privacy > summary::-webkit-details-marker { display: none; }
.chat-privacy .cloud-note { margin: 4px; }
.chat-input-row {
  display: flex;
  min-height: 49px;
  align-items: center;
  gap: 3px;
  padding: 2px 4px;
  border: 1px solid transparent;
  border-radius: 20px;
  background: var(--surface);
  transition: border-color 150ms ease, box-shadow 150ms ease;
}
.chat-input-row:has(textarea:focus-visible) { border-color: var(--focus); box-shadow: 0 0 0 2px var(--tint); }
.chat-input-row textarea {
  width: 100%;
  min-width: 0;
  min-height: 41px;
  max-height: 108px;
  flex: 1;
  margin: 0;
  padding: 9px 4px 8px;
  border: 0;
  border-radius: 11px;
  background: transparent;
  color: var(--ink);
  font-size: 1rem;
  line-height: 1.45;
  resize: none;
  field-sizing: content;
}
.chat-input-row textarea:focus-visible { outline: none; }
.chat-mic { width: 36px; height: 41px; color: var(--ink); }
.chat-mic[aria-pressed="true"], .chat-read[aria-pressed="true"] { background: var(--tint); color: var(--accent-dark); }
.chat-send {
  display: flex;
  min-height: 41px;
  flex: none;
  align-items: center;
  justify-content: center;
  gap: 5px;
  padding: 0 10px;
  border: 1px solid transparent;
  border-radius: 11px;
  background: var(--accent);
  color: var(--surface);
  font-size: .89rem;
  font-weight: 700;
  transition: background 150ms ease, scale 150ms ease;
}
.chat-send:hover { background: var(--accent-dark); }
.chat-send:active { scale: .94; }
#chat-question:placeholder-shown ~ .chat-send:not([data-stop]) { display: none; }
.chat-send .chat-stop-square { display: none; }
.chat-send[data-stop] { background: var(--control); color: var(--ink); }
.chat-send[data-stop]:hover { background: var(--control-hover); }
.chat-send[data-stop] .chat-send-plane { display: none; }
.chat-send[data-stop] .chat-stop-square { display: block; }
.chat-status-error { color: var(--danger); }
.chat-panel[data-waiting] #chat-status {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}

@keyframes mine-panel-in { from { opacity: 0; transform: translateY(11px) scale(.975); } to { opacity: 1; transform: none; } }
@keyframes mine-panel-out { to { opacity: 0; transform: translateY(9px) scale(.983); } }
@keyframes mine-content-in { from { opacity: 0; transform: translateY(5px); } to { opacity: 1; transform: none; } }
@keyframes mine-dot { 0%, 60%, 100% { opacity: .5; translate: 0 0; } 30% { opacity: 1; translate: 0 -3px; } }

@media (min-width: 1180px) {
  .chat-is-open :is(main.shell, .topbar-inner) { width: calc(100% - var(--chat-width) - 55px); margin-left: 22px; }
}
@media (max-width: 525px) {
  body { padding-bottom: 48px; }
  .chat-launch { right: 13px; bottom: max(13px, env(safe-area-inset-bottom)); }
  .chat-panel { right: 8px; bottom: max(8px, env(safe-area-inset-bottom)); width: calc(100% - 16px); height: min(660px, calc(100dvh - 18px)); }
}
@media (max-width: 380px) {
  .chat-header { gap: 5px; padding-inline: 9px; }
  .chat-icon { width: 36px; }
  .chat-log { padding-inline: 9px; }
  .chat-send { min-width: 36px; padding-inline: 7px; }
  #chat-send-label { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); }
}
@media (prefers-reduced-motion: reduce) {
  .chat-launch, .chat-panel, .chat-panel *, .chat-panel *::after { animation: none !important; transition: none !important; }
  .chat-launch:hover, .chat-chips button:hover, .chat-icon:active, .chat-answer-action:active, .chat-send:active { translate: none; scale: none; }
}
