.course-chat {
  --chat-left: max(1rem, env(safe-area-inset-left));
  --chat-right: max(1rem, env(safe-area-inset-right));
  --chat-bottom: max(1rem, env(safe-area-inset-bottom));
  position: fixed;
  z-index: 110;
  left: var(--chat-left);
  bottom: calc(var(--chat-bottom) + var(--chat-keyboard-offset, 0px));
  font-family: var(--font);
}

.course-chat [hidden] {
  display: none;
}

body:has(.mobile-menu.open) .course-chat {
  visibility: hidden;
}

.course-chat-launch {
  display: flex;
  align-items: center;
  gap: .55rem;
  min-height: 3rem;
  padding: .55rem .9rem;
  border: 1px solid rgba(255, 255, 255, .35);
  border-radius: 999px;
  background: linear-gradient(135deg, #67e8f9, #c4b5fd);
  box-shadow: var(--shadow-float), 0 6px 24px -12px var(--violet);
  color: #0f172a;
  font-weight: 800;
  font-size: .85rem;
}

.course-chat-launch:hover {
  background: linear-gradient(135deg, #a5f3fc, #ddd6fe);
}

.course-chat svg {
  width: 1.25rem;
  height: 1.25rem;
  flex: none;
}

.course-chat-panel {
  display: flex;
  flex-direction: column;
  width: min(23rem, calc(100vw - var(--chat-left) - var(--chat-right)));
  height: 33rem;
  max-height: calc(100vh - var(--chat-bottom) - max(.75rem, env(safe-area-inset-top)));
  max-height: calc(var(--chat-viewport-height, 100dvh) - var(--chat-bottom) - max(.75rem, env(safe-area-inset-top)));
  overflow: auto;
  overscroll-behavior: contain;
  background: var(--bg-card);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-float);
  color: var(--fg);
}

.course-chat-header {
  display: flex;
  flex: none;
  align-items: center;
  justify-content: space-between;
  gap: .5rem;
  padding: .5rem 1rem .5rem .55rem;
  background: linear-gradient(120deg, var(--radial1), var(--radial2));
  border-bottom: 1px solid var(--border);
}

.course-chat-header h2 {
  font-size: 1rem;
  font-weight: 800;
}

.course-chat-close {
  display: grid;
  place-items: center;
  flex: none;
  width: 2.75rem;
  height: 2.75rem;
  border-radius: .65rem;
  color: var(--fg-muted);
}

.course-chat-close:hover {
  background: var(--input-bg);
  color: var(--fg);
}

.course-chat-log {
  flex: 1;
  min-height: 3rem;
  padding: .85rem;
  overflow: auto;
  overscroll-behavior: contain;
  background: var(--bg-soft);
  scrollbar-width: thin;
}

.course-chat-log:focus-visible {
  outline-offset: -2px;
}

.course-chat-message {
  width: fit-content;
  max-width: 94%;
  padding: .55rem .75rem;
  border: 1px solid var(--border-strong);
  border-radius: .85rem;
  border-top-right-radius: .25rem;
  background: var(--bg-elev);
  font-size: .9rem;
  line-height: 1.7;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.course-chat-exchange .course-chat-message {
  margin-top: .6rem;
}

.course-chat-message-user {
  margin-right: auto;
  border-color: rgba(var(--nn-node2), .28);
  border-top-right-radius: .85rem;
  border-top-left-radius: .25rem;
  background: var(--radial2);
}

.course-chat-footer {
  flex: none;
  padding: .7rem .85rem .75rem;
  border-top: 1px solid var(--border);
}

.course-chat-status,
.course-chat-help {
  color: var(--fg-muted);
  font-size: .75rem;
}

.course-chat-status:not(:empty) {
  margin-bottom: .4rem;
}

.course-chat-form {
  display: flex;
  align-items: flex-end;
  gap: .45rem;
}

.course-chat-form textarea {
  flex: 1;
  min-width: 0;
  padding: .45rem .6rem;
  resize: none;
  border: 1px solid var(--border-strong);
  border-radius: .65rem;
  background: var(--input-bg);
  color: var(--fg);
  font: inherit;
  font-size: 1rem;
}

.course-chat-form textarea::placeholder {
  color: var(--fg-muted);
}

.course-chat-send {
  min-width: 3.3rem;
  min-height: 2.75rem;
  padding: .35rem .55rem;
  border-radius: .65rem;
  background: #67e8f9;
  color: #0f172a;
  font-size: .85rem;
  font-weight: 800;
}

.course-chat-send:hover:enabled {
  background: #a5f3fc;
}

.course-chat-send:disabled {
  opacity: .6;
  cursor: wait;
}

.course-chat-help {
  margin-top: .45rem;
}

.course-chat-help a {
  font-weight: 700;
  text-decoration: underline;
  text-underline-offset: .15em;
}
