.gpt-chat {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  font-family: "Helvetica Neue", Arial, sans-serif;
  font-size: 0.95rem;
  color: #1f2933;
  min-height: 0;
  --btn-bg: var(--primary-500, #2563eb);
  --btn-ink: #ffffff;
  --ring: var(--primary-400, #60a5fa);
  --stt-btn-size: 36px;
  --stt-btn-radius: 8px;
}

.gpt-chat--floating .gpt-chat__messages {
  max-height: 280px;
}

.gpt-chat__messages {
  flex: 1 1 auto;
  min-height: 160px;
  max-height: 360px;
  overflow-y: auto;
  padding: 0.5rem;
  border: 1px solid #d0d7de;
  border-radius: 0.75rem;
  background: #f8fafc;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.gpt-chat--floating .gpt-chat__messages {
  min-height: 0;
}

.gpt-chat__bubble {
  position: relative;
  padding: 0.5rem 0.75rem;
  border-radius: 0.75rem;
  line-height: 1.4;
  background: #ffffff;
  color: inherit;
  box-shadow: 0 1px 2px rgba(15, 23, 42, 0.08);
  max-width: 100%;
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
}

.gpt-chat__bubble--assistant {
  align-self: flex-start;
  background: #ffffff;
}

.gpt-chat__bubble--user {
  align-self: flex-end;
  background: #2563eb;
  color: #ffffff;
}

.gpt-chat__bubble a {
  color: inherit;
  text-decoration: underline;
}

.gpt-chat__bubble code {
  font-family: "SFMono-Regular", Menlo, Consolas, monospace;
  font-size: 0.9em;
  background: rgba(15, 23, 42, 0.08);
  padding: 0.1rem 0.3rem;
  border-radius: 0.35rem;
}

.gpt-chat__bubble pre {
  margin: 0.25rem 0;
  padding: 0.5rem;
  overflow: auto;
  border-radius: 0.5rem;
  background: rgba(15, 23, 42, 0.08);
}

.gpt-chat__bubble-content {
  display: block;
}

.gpt-chat__bubble-content table {
  width: 100%;
  border-collapse: collapse;
  margin: 0.5rem 0;
  font-size: 0.95rem;
  background: rgba(255, 255, 255, 0.96);
  border-radius: 0.6rem;
  overflow: hidden;
}

.gpt-chat__bubble-content th,
.gpt-chat__bubble-content td {
  border: 1px solid rgba(148, 163, 184, 0.35);
  padding: 0.45rem 0.65rem;
  text-align: left;
  vertical-align: middle;
}

.gpt-chat__bubble-content th {
  background: rgba(59, 130, 246, 0.12);
  font-weight: 700;
}

.gpt-chat__bubble-content tbody tr:nth-child(even) {
  background: rgba(59, 130, 246, 0.05);
}

.gpt-chat__bubble-actions {
  display: flex;
  align-items: center;
  gap: 0.25rem;
  margin-top: 0.1rem;
}

.gpt-chat__copy {
  border: none;
  background: transparent;
  color: inherit;
  padding: 0.25rem;
  border-radius: 999px;
  cursor: pointer;
  transition: background-color 0.2s ease, color 0.2s ease, opacity 0.2s ease;
  opacity: 0.7;
}

.gpt-chat__copy:hover,
.gpt-chat__copy:focus {
  outline: none;
  background: rgba(37, 99, 235, 0.12);
  color: #1d4ed8;
  opacity: 1;
}

.gpt-chat__copy-icon {
  width: 1.05rem;
  height: 1.05rem;
  display: block;
  fill: currentColor;
}

.gpt-chat__copy--copied {
  color: #15803d;
  background: rgba(34, 197, 94, 0.18);
  opacity: 1;
}

.gpt-chat__status {
  min-height: 1.1rem;
  font-size: 0.85rem;
  color: #4b5563;
}

.gpt-chat__status--error {
  color: #dc2626;
}

.gpt-chat__form {
  margin: 0;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.gpt-chat__input-wrapper {
  display: flex;
  align-items: flex-end;
  flex-wrap: wrap;
  gap: 0.5rem;
  background: #ffffff;
  border: 1px solid #d0d7de;
  border-radius: 0.75rem;
  padding: 0.35rem;
}

.gpt-chat__input {
  width: 100%;
  flex: 1 1 auto;
  border: none;
  resize: none;
  min-height: 3.25rem;
  max-height: 6rem;
  padding: 0.5rem;
  font: inherit;
  line-height: 1.4;
  color: inherit;
  background: transparent;
}

.gpt-chat__input:focus {
  outline: none;
}

.gpt-chat__actions {
  display: flex;
  gap: 0.4rem;
  align-items: center;
  align-self: flex-end;
  flex-wrap: wrap;
}

.gpt-chat__actions .stt-trigger {
  display: flex;
  flex: 0 0 auto;
}

.gpt-chat__submit {
  width: var(--stt-btn-size, 36px);
  height: var(--stt-btn-size, 36px);
  border: 1px solid var(--ring, #cbd5e1);
  border-radius: var(--stt-btn-radius, 8px);
  background: var(--btn-bg, var(--primary));
  color: var(--btn-ink, #ffffff);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: background 0.2s ease, transform 0.15s ease, filter 0.15s ease;
  align-self: flex-end;
  padding: 0;
}

.gpt-chat__submit:disabled {
  cursor: wait;
  opacity: 0.6;
}

.gpt-chat__submit:hover,
.gpt-chat__submit:focus {
  background: var(--btn-bg, var(--primary));
  filter: brightness(0.97);
  transform: translateY(-1px);
}

.gpt-chat__submit-icon {
  width: 1.2rem;
  height: 1.2rem;
  fill: currentColor;
}

.gpt-chat__prompts {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.gpt-chat__prompts-select {
  position: relative;
}

.gpt-chat__prompt-select {
  width: 100%;
  padding: 0.5rem 0.75rem;
  border: 1px solid #d0d7de;
  border-radius: 0.75rem;
  font-size: 0.9rem;
  color: #1f2937;
  background-color: #ffffff;
  appearance: none;
  background-image: linear-gradient(45deg, transparent 50%, #64748b 50%),
    linear-gradient(135deg, #64748b 50%, transparent 50%),
    linear-gradient(to right, #ffffff, #ffffff);
  background-position: calc(100% - 1.3rem) calc(50% - 0.05rem),
    calc(100% - 0.9rem) calc(50% - 0.05rem),
    calc(100% - 2.5rem) 0.35rem;
  background-size: 0.5rem 0.5rem, 0.5rem 0.5rem, 1.6rem 70%;
  background-repeat: no-repeat;
  cursor: pointer;
  transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

.gpt-chat__prompt-select:focus {
  border-color: #2563eb;
  box-shadow: 0 0 0 2px rgba(37, 99, 235, 0.15);
  outline: none;
}

.gpt-chat--busy .gpt-chat__prompt-select {
  opacity: 0.6;
  cursor: wait;
}

.gpt-chat__tts-toggle-row {
  display: flex;
  justify-content: flex-end;
  margin: 0.35rem 0 0.2rem;
}

.gpt-chat__tts-toggle {
  border: none;
  background: none;
  color: #64748b;
  cursor: pointer;
  width: 2.25rem;
  height: 2.25rem;
  border-radius: 0.5rem;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 1.4rem;
  line-height: 1;
  transition: color 0.2s ease, background 0.2s ease;
}

.gpt-chat__tts-toggle:hover,
.gpt-chat__tts-toggle:focus {
  color: #1d4ed8;
  background: rgba(37, 99, 235, 0.08);
  outline: none;
}

.gpt-chat__tts-toggle--active {
  color: #1d4ed8;
  background: rgba(37, 99, 235, 0.12);
}

.gpt-chat__tts-toggle:disabled {
  opacity: 0.45;
  cursor: not-allowed;
  color: #94a3b8;
  background: transparent;
}

.gpt-chat__tts-toggle-icon {
  font-size: 1.1rem;
  line-height: 1;
}

.gpt-chat__visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  border: 0;
}

.course-gpt-popup__actions .gpt-chat__tts-toggle {
  width: 2.25rem;
  height: 2.25rem;
  border-radius: 0.5rem;
  font-size: 1.3rem;
}

:root {
  --course-gpt-dock-width: 380px;
  --course-gpt-flyout-height: 520px;
  --course-gpt-launcher-offset: calc(env(safe-area-inset-bottom, 0px) + 1.5rem);
  --course-gpt-launcher-gap: 0.75rem;
  --course-gpt-launcher-size: 3.25rem;
}

.course-gpt-launcher {
  position: fixed;
  right: 1.5rem;
  bottom: var(--course-gpt-launcher-offset);
  z-index: 1100;
  pointer-events: none;
}

.course-gpt-launcher__inner {
  position: relative;
  display: flex;
  flex-direction: row;
  justify-content: flex-end;
  align-items: flex-end;
  gap: var(--course-gpt-launcher-gap);
  pointer-events: auto;
}

.course-gpt-launcher__button {
  width: var(--course-gpt-launcher-size);
  height: var(--course-gpt-launcher-size);
  min-width: var(--course-gpt-launcher-size);
  flex-shrink: 0;
  border-radius: 50%;
  border: none;
  background: #2563eb;
  color: #ffffff;
  box-shadow: 0 10px 30px rgba(37, 99, 235, 0.35);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.2rem;
  opacity: 0.8;
  transition: transform 0.2s ease, background 0.2s ease, opacity 0.2s ease;
}

.course-gpt-launcher__button--page {
  background: #2563eb;
}

.course-gpt-launcher__button--label {
  width: auto;
  min-width: 3.2rem;
  padding: 0 0.85rem;
  background: #2563eb;
  font-weight: 700;
  cursor: default;
  opacity: 1;
}

.course-gpt-launcher__button:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

.course-gpt-launcher__button:hover,
.course-gpt-launcher__button:focus {
  transform: translateY(-1px);
  background: #1d4ed8;
  opacity: 1;
}

.course-gpt-popup {
  position: absolute;
  right: 0;
  bottom: calc(100% + var(--course-gpt-launcher-gap));
  width: 340px;
  max-width: 90vw;
  height: min(var(--course-gpt-flyout-height, 520px), calc(100vh - 3rem));
  max-height: min(var(--course-gpt-flyout-height, 520px), calc(100vh - 3rem));
  background: #ffffff;
  border-radius: 1rem;
  box-shadow: 0 20px 45px rgba(15, 23, 42, 0.15);
  border: 1px solid rgba(15, 23, 42, 0.05);
  padding: 1rem;
  display: none;
  pointer-events: auto;
  flex-direction: column;
  z-index: 4200;
}

.course-gpt-popup--open {
  display: flex;
}

.course-gpt-editor {
  position: fixed;
  left: 1.5rem;
  right: calc(1.5rem + var(--course-gpt-dock-width, 380px));
  bottom: calc(
    var(--course-gpt-launcher-offset) + var(--course-gpt-launcher-gap) + var(--course-gpt-launcher-size)
  );
  background: #ffffff;
  border-radius: 1rem;
  box-shadow: 0 20px 45px rgba(15, 23, 42, 0.12);
  border: 1px solid rgba(15, 23, 42, 0.05);
  padding: 1rem 1.25rem;
  height: min(var(--course-gpt-flyout-height, 520px), calc(100vh - 3rem));
  max-height: min(var(--course-gpt-flyout-height, 520px), calc(100vh - 3rem));
  display: none;
  flex-direction: column;
  gap: 0.75rem;
  pointer-events: auto;
  z-index: 1120;
}

.course-gpt-editor--open {
  display: flex;
}

.course-gpt-editor--expanded {
  top: 1rem;
  right: 1rem;
  bottom: 1rem;
  left: 1rem;
  width: auto;
  height: auto;
  max-height: none;
  z-index: 1140;
}

.course-gpt-editor__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
}

.course-gpt-editor__heading {
  flex: 1 1 auto;
}

.course-gpt-editor__title {
  font-size: 1rem;
  margin: 0;
  color: #0f172a;
  font-weight: 600;
}

.course-gpt-editor__meta {
  margin: 0.15rem 0 0;
  font-size: 0.8rem;
  color: #64748b;
  display: none;
}

.course-gpt-editor__actions {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.course-gpt-editor__close {
  border: none;
  background: none;
  font-size: 1.5rem;
  line-height: 1;
  color: #64748b;
  cursor: pointer;
  width: 2.25rem;
  height: 2.25rem;
  border-radius: 0.5rem;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: color 0.2s ease, background 0.2s ease;
}

.course-gpt-editor__resize {
  border: none;
  background: none;
  font-size: 1.15rem;
  line-height: 1;
  color: #64748b;
  cursor: pointer;
  width: 2.25rem;
  height: 2.25rem;
  border-radius: 0.5rem;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: color 0.2s ease, background 0.2s ease;
}

.course-gpt-editor__resize:hover,
.course-gpt-editor__resize:focus {
  color: #1d4ed8;
  background: rgba(37, 99, 235, 0.08);
}

.course-gpt-editor__close:hover,
.course-gpt-editor__close:focus {
  color: #0f172a;
  background: rgba(37, 99, 235, 0.08);
}

.course-gpt-editor__status {
  min-height: 1.1rem;
  font-size: 0.85rem;
  color: #4b5563;
}

.course-gpt-editor__status--error {
  color: #dc2626;
}

.course-gpt-editor__status--success {
  color: #16a34a;
}

.course-gpt-editor__body {
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  overflow: hidden;
}

.course-gpt-editor__textarea {
  flex: 1 1 auto;
  width: 100%;
  max-width: 100%;
  min-height: 0;
  height: 100%;
  max-height: 100%;
  border: 1px solid #d0d7de;
  border-radius: 0.75rem;
  padding: 0.75rem;
  font-family: "SFMono-Regular", Menlo, Consolas, monospace;
  font-size: 0.9rem;
  line-height: 1.5;
  color: #1f2937;
  resize: none;
  background: #f8fafc;
  box-sizing: border-box;
}

.course-gpt-editor__textarea:focus {
  outline: none;
  border-color: #2563eb;
  box-shadow: 0 0 0 2px rgba(37, 99, 235, 0.15);
}

.course-gpt-editor__footer {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 0.5rem;
}

.course-gpt-editor__icon-button {
  width: 2.5rem;
  height: 2.5rem;
  border: none;
  border-radius: 0.65rem;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #e2e8f0;
  color: #1f2933;
  cursor: pointer;
  transition: background 0.2s ease, color 0.2s ease, opacity 0.2s ease;
}

.course-gpt-editor__icon-button:hover,
.course-gpt-editor__icon-button:focus {
  background: #dbeafe;
}

.course-gpt-editor__icon-button--primary {
  background: #2563eb;
  color: #ffffff;
}

.course-gpt-editor__icon-button--primary:hover,
.course-gpt-editor__icon-button--primary:focus {
  background: #1d4ed8;
}

.course-gpt-editor__icon-button:disabled {
  opacity: 0.6;
  cursor: wait;
}

.course-gpt-editor__icon {
  width: 1.3rem;
  height: 1.3rem;
  fill: currentColor;
}

.course-gpt-editor--busy .course-gpt-editor__icon-button,
.course-gpt-editor--busy .course-gpt-editor__textarea {
  opacity: 0.6;
  cursor: wait;
}

.course-gpt-editor--busy .course-gpt-editor__textarea {
  pointer-events: none;
}

.course-gpt-editor--busy .course-gpt-editor__icon-button {
  pointer-events: none;
}

.course-gpt-popup__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  margin-bottom: 0.75rem;
}

.course-gpt-popup__actions {
  display: flex;
  align-items: center;
  gap: 0.35rem;
}

.course-gpt-popup__title {
  font-size: 1rem;
  margin: 0;
  color: #0f172a;
}

.course-gpt-popup__fullscreen,
.course-gpt-popup__close {
  border: none;
  background: none;
  font-size: 1.5rem;
  line-height: 1;
  color: #64748b;
  cursor: pointer;
  width: 2.25rem;
  height: 2.25rem;
  border-radius: 0.5rem;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: color 0.2s ease, background 0.2s ease;
}

.course-gpt-popup__fullscreen-icon {
  font-size: 1.1rem;
  line-height: 1;
}

.course-gpt-popup__fullscreen:hover,
.course-gpt-popup__fullscreen:focus {
  color: #1d4ed8;
  background: rgba(37, 99, 235, 0.08);
}

.course-gpt-popup__close:hover,
.course-gpt-popup__close:focus {
  color: #0f172a;
}

.course-gpt-popup__body {
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  flex-direction: column;
}

.course-gpt-popup__body > .gpt-chat {
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  flex-direction: column;
}

.course-gpt-popup__fullscreen--active {
  color: #1d4ed8;
  background: rgba(37, 99, 235, 0.12);
}

.course-gpt-popup--fullscreen {
  position: fixed;
  inset: 1.5rem;
  width: auto;
  max-width: none;
  height: auto;
  max-height: none;
  border-radius: 1rem;
  z-index: 4300;
  box-shadow: 0 30px 60px rgba(15, 23, 42, 0.35);
}

.course-gpt-popup--fullscreen .course-gpt-popup__body {
  flex: 1 1 auto;
  overflow: auto;
  max-height: none;
}

.course-gpt-popup--fullscreen .gpt-chat {
  height: 100%;
}

.course-gpt-popup--fullscreen .gpt-chat__messages {
  max-height: none;
  min-height: 0;
  flex: 1 1 auto;
}

.course-gpt-popup--fullscreen .gpt-chat__form {
  margin-top: 0.75rem;
}

@media (max-width: 640px) {
  :root {
    --course-gpt-flyout-height: min(70vh, 520px);
    --course-gpt-launcher-offset: calc(env(safe-area-inset-bottom, 0px) + 1rem);
  }

  .course-gpt-launcher {
    right: 1rem;
  }

  .course-gpt-launcher__inner {
    align-items: flex-end;
    flex-direction: column;
    gap: calc(var(--course-gpt-launcher-gap) * 0.85);
  }

  .course-gpt-launcher__button--page.course-gpt-launcher__button--prev,
  .course-gpt-launcher__button--page.course-gpt-launcher__button--next {
    font-size: 0;
  }

  .course-gpt-launcher__button--page.course-gpt-launcher__button--prev::after,
  .course-gpt-launcher__button--page.course-gpt-launcher__button--next::after {
    font-size: 1.1rem;
    line-height: 1;
  }

  .course-gpt-launcher__button--page.course-gpt-launcher__button--prev::after {
    content: "▲";
  }

  .course-gpt-launcher__button--page.course-gpt-launcher__button--next::after {
    content: "▼";
  }

  .course-gpt-launcher__button--label {
    width: 100%;
    min-width: var(--course-gpt-launcher-size);
    text-align: center;
  }

  .course-gpt-launcher__button--label {
    padding: 0;
    text-align: center;
  }

  .course-gpt-popup {
    position: fixed;
    right: 0.75rem;
    left: 0.75rem;
    width: auto;
    max-width: none;
    bottom: calc(var(--course-gpt-launcher-offset, 0px) + var(--course-gpt-launcher-size) + var(--course-gpt-launcher-gap));
    transform: none;
    overflow: hidden;
    display: none;
  }

  .course-gpt-popup__body {
    max-height: calc(var(--course-gpt-flyout-height, 520px) - 3rem);
    overflow-y: auto;
  }

  .course-gpt-popup--open {
    display: flex;
  }

  .course-gpt-popup--fullscreen {
    inset: 0;
    width: 100vw;
    height: 100vh;
    max-width: none;
    max-height: none;
    border-radius: 0;
  }

  .course-gpt-popup--fullscreen .course-gpt-popup__body {
    max-height: none;
  }

  .course-gpt-editor {
    left: 1rem;
    right: 1rem;
    top: auto;
    height: min(var(--course-gpt-flyout-height, 520px), calc(100vh - 2rem));
    max-height: none;
    padding: 1rem;
  }
}

body.course-gpt-fullscreen-open {
  overflow: hidden;
}

@media (max-width: 1024px) {
  .course-gpt-editor {
    left: 1rem;
    right: 1rem;
  }
}
