.chat-root {
  position: fixed;
  right: 1rem;
  bottom: 1rem;
  z-index: 40;
  display: flex;
  flex-direction: column-reverse;
  align-items: flex-end;
  gap: 0.7rem;
  font-family: var(--sans, "Segoe UI", "Helvetica Neue", system-ui, sans-serif);
}

.chat-launcher {
  appearance: none;
  border: 1px solid var(--cyan, #01dbff);
  background: rgba(2, 14, 50, 0.92);
  color: var(--cyan, #01dbff);
  border-radius: 999px;
  padding: 0.7rem 1.05rem;
  font: inherit;
  font-size: 0.92rem;
  font-weight: 650;
  letter-spacing: 0.02em;
  cursor: pointer;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.28);
}
.chat-launcher:hover,
.chat-launcher:focus-visible {
  color: var(--ink, #f4f7ff);
  border-color: var(--ink, #f4f7ff);
  outline: none;
}

.chat-panel {
  width: min(22rem, calc(100vw - 2rem));
  max-height: min(70vh, 34rem);
  display: flex;
  flex-direction: column;
  background: rgba(7, 21, 63, 0.96);
  border: 1px solid rgba(183, 195, 224, 0.18);
  border-radius: 16px;
  overflow: hidden;
  box-shadow: 0 18px 40px rgba(0, 0, 0, 0.35);
}
/* Keep HTML hidden effective: display:flex above would otherwise override it. */
.chat-panel[hidden] {
  display: none !important;
}

.chat-panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  padding: 0.85rem 1rem 0.55rem;
  border-bottom: 1px solid rgba(183, 195, 224, 0.14);
}
.chat-panel-head h2 {
  margin: 0;
  font-size: 1rem;
  letter-spacing: -0.02em;
}
.chat-close {
  appearance: none;
  border: 0;
  background: transparent;
  color: var(--muted, #b7c3e0);
  font-size: 1.4rem;
  line-height: 1;
  cursor: pointer;
  padding: 0.1rem 0.35rem;
}
.chat-close:hover,
.chat-close:focus-visible {
  color: var(--ink, #f4f7ff);
  outline: none;
}

.chat-disclaimer {
  margin: 0;
  padding: 0.55rem 1rem 0.2rem;
  color: var(--muted, #b7c3e0);
  font-size: 0.78rem;
  line-height: 1.4;
}

.chat-log {
  flex: 1 1 auto;
  overflow-y: auto;
  padding: 0.7rem 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.55rem;
  min-height: 12rem;
}

.chat-bubble {
  max-width: 92%;
  padding: 0.55rem 0.7rem;
  border-radius: 12px;
  font-size: 0.92rem;
  line-height: 1.45;
  white-space: normal;
  word-break: break-word;
}
.chat-user {
  align-self: flex-end;
  background: rgba(1, 219, 255, 0.14);
  border: 1px solid rgba(1, 219, 255, 0.28);
  color: var(--ink, #f4f7ff);
}
.chat-assistant {
  align-self: flex-start;
  background: rgba(2, 14, 50, 0.72);
  border: 1px solid rgba(183, 195, 224, 0.16);
  color: var(--ink, #f4f7ff);
}
.chat-status {
  color: var(--muted, #b7c3e0);
  font-size: 0.86rem;
}

.chat-form {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 0.55rem;
  padding: 0.75rem 1rem 1rem;
  border-top: 1px solid rgba(183, 195, 224, 0.14);
}
.chat-form textarea {
  resize: none;
  width: 100%;
  min-height: 2.8rem;
  max-height: 7rem;
  padding: 0.55rem 0.65rem;
  border-radius: 10px;
  border: 1px solid rgba(183, 195, 224, 0.22);
  background: rgba(2, 14, 50, 0.7);
  color: var(--ink, #f4f7ff);
  font: inherit;
  font-size: 0.92rem;
}
.chat-form textarea:focus {
  outline: 1px solid var(--cyan, #01dbff);
  border-color: var(--cyan, #01dbff);
}
.chat-send {
  align-self: end;
  cursor: pointer;
}
.chat-send:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

@media (max-width: 680px) {
  .chat-root {
    right: 0.7rem;
    bottom: 0.7rem;
  }
  .chat-panel {
    width: min(100vw - 1.4rem, 22rem);
    max-height: min(72vh, 30rem);
  }
}

@media (prefers-reduced-motion: reduce) {
  .chat-launcher,
  .chat-panel {
    transition: none;
  }
}
