:root {
  --chat-widget-shadow: 0 12px 36px rgba(0, 0, 0, 0.22);
  --chat-widget-border: color-mix(in srgb, var(--sidebar-border) 85%, transparent);
  --chat-widget-muted: color-mix(in srgb, var(--text-color) 64%, transparent);
  --chat-widget-bg-soft: color-mix(in srgb, var(--bg-color) 92%, #ffffff 8%);
}

#scie-chat-root {
  position: fixed;
  right: 1rem;
  bottom: 1rem;
  z-index: 1300;
  font-family: var(--font-family);
}

.scie-chat-toggle {
  width: 56px;
  height: 56px;
  border-radius: 999px;
  border: 1px solid var(--chat-widget-border);
  background: linear-gradient(135deg, #1f4f8f 0%, #2a6fc4 100%);
  color: #ffffff;
  box-shadow: var(--chat-widget-shadow);
  font-size: 1.05rem;
  font-weight: 600;
  cursor: pointer;
}

.scie-chat-panel {
  width: min(390px, calc(100vw - 1.5rem));
  height: min(620px, calc(100vh - 5rem));
  display: none;
  flex-direction: column;
  border: 1px solid var(--chat-widget-border);
  border-radius: 14px;
  background-color: var(--bg-color);
  color: var(--text-color);
  box-shadow: var(--chat-widget-shadow);
  overflow: hidden;
}

.scie-chat-panel.is-open {
  display: flex;
}

.scie-chat-header {
  border-bottom: 1px solid var(--chat-widget-border);
  padding: 0.8rem 0.95rem;
  background-color: var(--chat-widget-bg-soft);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.8rem;
}

.scie-chat-title {
  margin: 0;
  font-size: 0.95rem;
  line-height: 1.3;
}

.scie-chat-subtitle {
  margin: 0.1rem 0 0;
  color: var(--chat-widget-muted);
  font-size: 0.74rem;
}

.scie-chat-close {
  border: 1px solid var(--chat-widget-border);
  background: transparent;
  color: var(--text-color);
  width: 30px;
  height: 30px;
  border-radius: 999px;
  cursor: pointer;
}

.scie-chat-status {
  padding: 0.35rem 0.95rem;
  font-size: 0.74rem;
  color: var(--chat-widget-muted);
  border-bottom: 1px solid var(--chat-widget-border);
}

.scie-chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 0.75rem;
  background-color: var(--bg-color);
}

.scie-chat-msg {
  display: flex;
  margin: 0 0 0.7rem;
}

.scie-chat-msg.assistant {
  justify-content: flex-start;
}

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

.scie-chat-bubble {
  max-width: 90%;
  border-radius: 10px;
  padding: 0.62rem 0.7rem;
  border: 1px solid var(--chat-widget-border);
  font-size: 0.88rem;
  line-height: 1.45;
  white-space: pre-wrap;
}

.scie-chat-msg.assistant .scie-chat-bubble {
  background-color: var(--chat-widget-bg-soft);
}

.scie-chat-msg.user .scie-chat-bubble {
  background-color: color-mix(in srgb, #2a6fc4 17%, var(--bg-color));
}

.scie-chat-sources {
  margin: 0.5rem 0 0;
  padding: 0;
  list-style: none;
}

.scie-chat-sources li {
  margin: 0.2rem 0 0;
}

.scie-chat-sources a {
  font-size: 0.76rem;
  color: var(--link-color);
  text-decoration: none;
}

.scie-chat-sources a:hover {
  color: var(--link-hover);
  text-decoration: underline;
}

.scie-chat-input-wrap {
  border-top: 1px solid var(--chat-widget-border);
  padding: 0.75rem;
  background-color: var(--chat-widget-bg-soft);
}

.scie-chat-input {
  width: 100%;
  min-height: 66px;
  max-height: 136px;
  resize: vertical;
  border: 1px solid var(--chat-widget-border);
  border-radius: 8px;
  background-color: var(--bg-color);
  color: var(--text-color);
  padding: 0.5rem 0.58rem;
  font-family: inherit;
  font-size: 0.85rem;
  line-height: 1.35;
}

.scie-chat-actions {
  display: flex;
  justify-content: space-between;
  gap: 0.55rem;
  margin-top: 0.5rem;
  align-items: center;
}

.scie-chat-note {
  margin: 0;
  color: var(--chat-widget-muted);
  font-size: 0.71rem;
}

.scie-chat-send {
  border: 1px solid var(--chat-widget-border);
  border-radius: 8px;
  padding: 0.42rem 0.75rem;
  background-color: #1f4f8f;
  color: #fff;
  cursor: pointer;
  font-size: 0.82rem;
  font-weight: 600;
}

.scie-chat-send[disabled] {
  opacity: 0.65;
  cursor: not-allowed;
}

@media (max-width: 767px) {
  #scie-chat-root {
    right: 0.7rem;
    bottom: 0.75rem;
  }

  .scie-chat-panel {
    width: calc(100vw - 1.4rem);
    height: min(75vh, 640px);
  }
}
