.doc-chat-toggle {
  position: fixed;
  right: 1.2rem;
  bottom: 1.2rem;
  z-index: 900;
  border: 1px solid var(--accent);
  border-radius: 999px;
  background: var(--accent);
  background-image: none;
  color: #fff;
  min-height: 3rem;
  padding: 0 1rem 0 0.55rem;
  font-weight: 800;
  cursor: pointer;
  box-shadow: var(--shadow-h);
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  transition: transform 0.16s ease, box-shadow 0.16s ease, background-color 0.16s ease;
}
.doc-chat-toggle:hover,
.doc-chat-toggle:focus,
.doc-chat-toggle:active {
  background: #000091 !important;
  background-color: #000091 !important;
  background-image: none !important;
  color: #fff !important;
  border-color: #000091 !important;
  transform: translateY(-1px);
}
.doc-chat-toggle-icon {
  display: inline-grid;
  place-items: center;
  width: 2rem;
  height: 2rem;
  border-radius: 999px;
  background: rgba(255,255,255,0.18);
  font-weight: 900;
}
.doc-chat {
  position: fixed;
  right: 1.2rem;
  bottom: 4.25rem;
  z-index: 900;
  width: min(760px, calc(100vw - 2.4rem));
  height: min(620px, calc(100vh - 6rem));
  display: grid;
  grid-template-rows: auto 1fr auto;
  background: var(--card-bg);
  border: 1px solid var(--card-border);
  border-radius: 8px;
  box-shadow: 0 24px 70px rgba(0, 0, 0, 0.22);
  overflow: hidden;
  resize: none;
  min-width: 340px;
  min-height: 410px;
  opacity: 0;
  pointer-events: none;
  transform: translateY(12px) scale(0.98);
  transform-origin: bottom right;
  transition: opacity 0.18s ease, transform 0.18s ease;
}
.doc-chat.is-resizing { user-select: none; }
.doc-chat-resize {
  position: absolute;
  z-index: 2;
  background: transparent;
}
.doc-chat-resize-left {
  top: 0;
  left: 0;
  width: 10px;
  height: 100%;
  cursor: ew-resize;
}
.doc-chat-resize-bottom {
  left: 0;
  bottom: 0;
  width: 100%;
  height: 10px;
  cursor: ns-resize;
}
.doc-chat-resize-corner {
  right: 0;
  bottom: 0;
  width: 18px;
  height: 18px;
  cursor: nwse-resize;
}
.doc-chat-resize-corner::after {
  content: "";
  position: absolute;
  right: 4px;
  bottom: 4px;
  width: 8px;
  height: 8px;
  border-right: 2px solid var(--muted);
  border-bottom: 2px solid var(--muted);
  opacity: 0.65;
}
.doc-chat.is-open {
  opacity: 1;
  pointer-events: auto;
  transform: translateY(0) scale(1);
}
.doc-chat.is-large {
  width: min(960px, calc(100vw - 2.4rem));
  height: min(780px, calc(100vh - 6rem));
}
.doc-chat-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 0.8rem;
  padding: 0.85rem 0.95rem;
  border-bottom: 1px solid var(--card-border);
  cursor: move;
  user-select: none;
  cursor: move;
}
.doc-chat-head h2 { margin: 0; font-size: 0.98rem; }
.doc-chat-head p { margin: 0.18rem 0 0; color: var(--muted); font-size: 0.72rem; line-height: 1.35; }
.doc-chat-tools { display: flex; gap: 0.35rem; flex: 0 0 auto; }
.doc-chat-tool,
.doc-chat-close {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 1.9rem;
  height: 1.9rem;
  border: 1px solid var(--card-border);
  border-radius: 6px;
  background: var(--bg);
  background-image: none;
  color: var(--text);
  cursor: pointer;
  font-weight: 800;
  transition: border-color 0.14s ease, transform 0.14s ease, background-color 0.14s ease;
}
.doc-chat-icon {
  width: 1rem;
  height: 1rem;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}
.doc-chat-tool:hover,
.doc-chat-tool:focus,
.doc-chat-tool:active,
.doc-chat-close:hover,
.doc-chat-close:focus,
.doc-chat-close:active {
  background: var(--bg) !important;
  background-color: var(--bg) !important;
  background-image: none !important;
  color: var(--text) !important;
  border-color: var(--accent) !important;
  transform: translateY(-1px);
}
.doc-chat-messages {
  padding: 0.85rem;
  overflow: auto;
  background: var(--bg);
}
.doc-msg {
  max-width: 92%;
  margin: 0 0 0.65rem;
  padding: 0.65rem 0.72rem;
  border: 1px solid var(--card-border);
  border-radius: 8px;
  color: var(--text);
  background: var(--card-bg);
  font-size: 0.78rem;
  line-height: 1.45;
  white-space: pre-wrap;
  animation: docChatMessageIn 0.18s ease both;
}
.doc-msg.user {
  margin-left: auto;
  background: #000091;
  color: #fff;
  border-color: #000091;
}
.doc-msg.system { color: var(--muted); }
.doc-msg.is-thinking {
  display: inline-flex;
  align-items: center;
  gap: 0.2rem;
}
.doc-msg.is-thinking::after {
  content: "";
  width: 1.5rem;
  text-align: left;
  animation: docChatThinking 1.1s steps(4, end) infinite;
}
.doc-msg p { margin: 0 0 0.45rem; }
.doc-msg p:last-child { margin-bottom: 0; }
.doc-msg ul { margin: 0.2rem 0 0; padding-left: 1.1rem; }
.doc-msg li + li { margin-top: 0.22rem; }
.doc-source-details {
  margin-top: 0.55rem;
  border-top: 1px solid var(--card-border);
  padding-top: 0.45rem;
}
.doc-source-details summary {
  cursor: pointer;
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 700;
}
.doc-sources { margin-top: 0.55rem; display: grid; gap: 0.35rem; }
.doc-source { color: var(--muted); font-size: 0.7rem; }
.doc-suggestions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
  margin-top: 0.55rem;
}
.doc-suggestion {
  border: 1px solid var(--card-border);
  border-radius: 6px;
  background: var(--bg);
  background-image: none;
  color: var(--text);
  padding: 0.28rem 0.45rem;
  font-size: 0.7rem;
  cursor: pointer;
  transition: border-color 0.14s ease, transform 0.14s ease, background-color 0.14s ease;
}
.doc-suggestion:hover,
.doc-suggestion:focus,
.doc-suggestion:active {
  background: var(--tag-bg) !important;
  background-color: var(--tag-bg) !important;
  background-image: none !important;
  color: var(--text) !important;
  border-color: var(--accent) !important;
  transform: translateY(-1px);
}
.doc-focus {
  display: none;
  margin: 0.55rem 0 0;
  color: var(--muted);
  font-size: 0.72rem;
}
.doc-focus.is-active { display: block; }
.doc-chat-form {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 0.45rem;
  padding: 0.75rem;
  border-top: 1px solid var(--card-border);
  background: var(--card-bg);
}
.doc-chat-form textarea {
  min-height: 2.5rem;
  max-height: 7rem;
  resize: vertical;
  border: 1px solid var(--card-border);
  border-radius: 7px;
  padding: 0.55rem 0.62rem;
  font: inherit;
  font-size: 0.78rem;
  color: var(--text);
  background: var(--bg);
}
.doc-chat-form button {
  border: 1px solid var(--accent);
  border-radius: 7px;
  background: var(--accent);
  background-image: none;
  color: #fff;
  min-width: 4.6rem;
  font-weight: 800;
  cursor: pointer;
  transition: transform 0.14s ease, background-color 0.14s ease, border-color 0.14s ease;
}
.doc-chat-form button:hover,
.doc-chat-form button:focus,
.doc-chat-form button:active {
  background: #000091 !important;
  background-color: #000091 !important;
  background-image: none !important;
  color: #fff !important;
  border-color: #000091 !important;
  transform: translateY(-1px);
}
.doc-chat-form button:disabled { opacity: 0.55; cursor: wait; }
.card-chat {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  position: absolute;
  right: 10px;
  bottom: 10px;
  min-width: 4.75rem;
  height: 1.75rem;
  border: 1px solid var(--card-border);
  border-radius: 999px;
  background: var(--card-bg);
  color: var(--accent);
  font-size: 0.68rem;
  font-weight: 800;
  line-height: 1;
  padding: 0 0.45rem;
  cursor: pointer;
  z-index: 3;
  box-shadow: var(--shadow);
  transition: transform 0.14s ease, border-color 0.14s ease, background-color 0.14s ease;
}
a.card .card-chat {
  display: none;
}
a.card:hover .card-chat,
a.card:focus-within .card-chat {
  display: inline-flex;
}
.card-chat:hover,
.card-chat:focus,
.card-chat:active {
  border-color: var(--accent) !important;
  background: var(--tag-bg) !important;
  background-color: var(--tag-bg) !important;
  background-image: none !important;
  color: var(--accent) !important;
  transform: translateY(-1px);
}
@keyframes docChatMessageIn {
  from { opacity: 0; transform: translateY(5px); }
  to { opacity: 1; transform: translateY(0); }
}
@keyframes docChatThinking {
  0% { content: ""; }
  25% { content: "."; }
  50% { content: ".."; }
  75%, 100% { content: "..."; }
}
@media (max-width: 1080px) {
  .doc-chat-toggle { right: 0.8rem; bottom: 0.8rem; }
  .doc-chat { right: 0.8rem; bottom: 3.8rem; width: min(760px, calc(100vw - 1.6rem)); min-width: 0; resize: none; }
}
@media (prefers-reduced-motion: reduce) {
  .doc-chat,
  .doc-chat-toggle,
  .doc-chat-tool,
  .doc-chat-close,
  .doc-suggestion,
  .doc-chat-form button,
  .card-chat {
    transition: none !important;
  }
  .doc-msg {
    animation: none !important;
  }
}
