/* ========================================
   C3SE Copilot — standalone chat interface
   ======================================== */

:root {
  --cc-accent: hsla(var(--fg-primary-hue), 51%, 46%, 1);
  --cc-text: #242633;
  --cc-muted: #777b8a;
  --cc-border: #e5e7ee;
  --cc-surface: #ffffff;
  --cc-surface-soft: #f7f8fc;
  --cc-user-message: hsla(var(--fg-primary-hue), 51%, 46%, 20%);
  --cc-shadow: 0 12px 48px rgb(26 30 55 / 18%);
  --cc-radius: 18px;
}

[data-md-color-scheme="slate"] {
  --cc-accent: hsla(var(--fg-primary-hue), 51%, 46%, 1);
  --cc-text: #ffffff;
  --cc-muted: #e5e7ee;
  --cc-border: #777b8a;
  --cc-surface: #242633;
  --cc-surface-soft: #2e303f;
  --cc-user-message: hsla(var(--fg-primary-hue), 51%, 46%, 50%);
  --cc-shadow: 0 12px 48px rgb(26 30 55 / 18%);
  --cc-radius: 18px;
}

/* Floating launcher */

.cc-launcher {
  position: fixed;
  right: 24px;
  bottom: 24px;
  z-index: 10000;

  display: grid;
  place-items: center;

  width: 58px;
  height: 58px;
  padding: 0;

  color: #fff;
  background: #0000;
  border: 0;
  border-radius: 50%;

  cursor: pointer;
  transition:
    transform 160ms ease,
    background 160ms ease,
    box-shadow 160ms ease;
}

.cc-launcher:hover {
  background: #0000;
  transform: translateY(-2px);
}

.cc-launcher:focus-visible,
.cc-chat button:focus-visible,
.cc-chat input:focus-visible {
  outline: 3px solid hsla(var(--fg-primary-hue), 51%, 46%, 30%);;
  outline-offset: 3px;
}

.cc-launcher svg {
  width: 25px;
  height: 25px;
}

/* Chat window */

.cc-chat {
  position: fixed;
  right: 24px;
  bottom: 96px;
  z-index: 10000;

  display: flex;
  flex-direction: column;

  width: 380px;
  height: min(560px, calc(100dvh - 130px));
  max-width: calc(100vw - 32px);

  overflow: hidden;
  color: var(--cc-text);
  background: var(--cc-surface);
  border: 1px solid var(--cc-border);
  border-radius: var(--cc-radius);
  box-shadow: var(--cc-shadow);

  font-family: Inter, ui-sans-serif, system-ui, sans-serif;
  font-size: 14px;
  line-height: 1.5;

  transform-origin: bottom right;
  animation: cc-appear 180ms ease-out;
}

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

@keyframes cc-appear {
  from {
    opacity: 0;
    transform: translateY(8px) scale(.98);
  }

  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

/* Header */

.cc-header {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-shrink: 0;

  padding: 16px;
  background: var(--cc-surface);
  border-bottom: 1px solid var(--cc-border);
}

.cc-avatar {
  display: grid;
  place-items: center;
  flex-shrink: 0;

  width: 40px;
  height: 40px;
  color: #fff;
  border-radius: 12px;
}

.cc-avatar svg {
  width: 21px;
  height: 21px;
}

.cc-heading {
  flex: 1;
  min-width: 0;
}

.cc-heading strong {
  display: block;
  font-size: 15px;
  font-weight: 650;
  line-height: 1.4;
}

.cc-heading span {
  display: block;
  margin-top: 2px;
  color: var(--cc-muted);
  font-size: 12px;
}

.cc-icon-button {
  display: grid;
  place-items: center;
  flex-shrink: 0;

  width: 34px;
  height: 34px;
  padding: 0;

  color: var(--cc-muted);
  background: transparent;
  border: 0;
  border-radius: 9px;
  cursor: pointer;
}

.cc-icon-button:hover {
  color: var(--cc-text);
  background: var(--cc-surface-soft);
}

.cc-icon-button svg {
  width: 19px;
  height: 19px;
}

/* Conversation area */

.cc-messages {
  display: flex;
  flex: 1;
  flex-direction: column;
  align-items: stretch;
  gap: 16px;

  min-height: 0;
  overflow-y: auto;
  padding: 20px 16px;

  background: var(--cc-surface-soft);
  overscroll-behavior: contain;
}

.cc-welcome {
  margin: 4px 0 8px;
  color: var(--cc-muted);
  font-size: 13px;
}

.cc-message {
  max-width: 90%;
  padding: 11px 13px;
  border-radius: 14px;
  overflow-wrap: anywhere;
}

.cc-message--assistant {
  align-self: flex-start;
  color: var(--cc-text);
  background: var(--cc-surface);
  border: 1px solid var(--cc-border);
  border-top-left-radius: 5px;
}

.cc-message--user {
  align-self: flex-end;
  color: var(--cc-text);
  background: var(--cc-user-message);
  border: 1px solid transparent;
  border-top-right-radius: 5px;
}

.cc-message p {
  margin: 0 0 8px;
}

.cc-message p:last-child {
  margin-bottom: 0;
}

.cc-message a {
  color: var(--cc-accent);
  text-decoration: underline;
}

/* Suggested prompts */

.cc-suggestions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: auto;
}

.cc-suggestion {
  padding: 8px 11px;
  color: var(--cc-text);
  background: var(--cc-surface);
  border: 1px solid var(--cc-border);
  border-radius: 999px;
  font: inherit;
  font-size: 12px;
  cursor: pointer;
}

.cc-suggestion:hover {
  border-color: var(--cc-accent);
  color: var(--cc-accent);
}

/* Composer */

.cc-composer {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  flex-shrink: 0;

  margin: 12px;
  padding: 8px;

  background: var(--cc-surface);
  border: 1px solid var(--cc-border);
  border-radius: 14px;

  transition: border-color 150ms ease,
              box-shadow 150ms ease;
}

.cc-composer:focus-within {
  border-color: var(--cc-accent);
  box-shadow: 0 0 0 3px rgb(101 88 245 / 10%);
}

.cc-composer input {
  flex: 1;
  width: 0;
  min-width: 0;
  min-height: 38px;
  padding: 9px 7px;

  color: var(--cc-text);
  background: transparent;
  border: 0;
  outline: none;
  box-shadow: none;

  font: inherit;
  font-size: 13px;
}

.cc-composer input::placeholder {
  color: #9699a7;
}

.cc-send {
  display: grid;
  place-items: center;
  flex-shrink: 0;

  width: 38px;
  height: 38px;
  padding: 0;

  color: #fff;
  background: var(--cc-accent);
  border: 0;
  border-radius: 10px;
  cursor: pointer;
}

.cc-send:disabled {
  opacity: .45;
  cursor: not-allowed;
}

.cc-send svg {
  width: 18px;
  height: 18px;
}

/* Small screens */

@media (max-width: 480px) {
  .cc-launcher {
    right: 16px;
    top: 48px;
    width: 54px;
    height: 54px;
  }

  .cc-chat {
    right: 8px;
    top: 112px;
    width: calc(100vw - 16px);
    max-width: none;
    height: min(600px, calc(100dvh - 100px));
    border-radius: 16px;
  }
}

/* Reduced motion */

@media (prefers-reduced-motion: reduce) {
  .cc-chat {
    animation: none;
  }

  .cc-launcher,
  .cc-composer {
    transition: none;
  }
}

/* Markdown Output */

.cc-message--assistant {
  line-height: 1.6;
  overflow-wrap: anywhere;
}

.cc-message--assistant > :first-child {
  margin-top: 0;
}

.cc-message--assistant > :last-child {
  margin-bottom: 0;
}

.cc-message--assistant pre {
  overflow-x: auto;
  padding: 0.85rem;
  border-radius: 0.5rem;
  background: var(--md-code-bg-color, #f3f4f6);
}

.cc-message--assistant code {
  font-family: var(--md-code-font, monospace);
  font-size: 0.9em;
}

.cc-message--assistant :not(pre) > code {
  padding: 0.12rem 0.3rem;
  border-radius: 0.25rem;
  background: var(--md-code-bg-color, #f3f4f6);
}

.cc-message--assistant table {
  display: block;
  max-width: 100%;
  overflow-x: auto;
  border-collapse: collapse;
}

.cc-message--assistant th,
.cc-message--assistant td {
  padding: 0.4rem 0.65rem;
  border: 1px solid var(--md-typeset-table-color, #ddd);
  text-align: left;
}

.cc-message--assistant img {
  max-width: 100%;
  height: auto;
}

