:root {
  color-scheme: dark;
  --aims-navy: #101528;
  --aims-navy-deep: #090d1b;
  --aims-panel: rgba(12, 16, 31, .9);
  --aims-panel-soft: rgba(255, 255, 255, .08);
  --aims-purple: #5b4bd6;
  --aims-purple-hover: #7568e7;
  --aims-white: #ffffff;
  --aims-muted: #c8cedc;
  --aims-border: rgba(255, 255, 255, .2);
  --aims-info-bg: rgba(224, 241, 255, .94);
  --aims-info-ink: #1c3150;
  --ink: var(--aims-white);
  --muted: var(--aims-muted);
  --line: var(--aims-border);
  --surface: var(--aims-panel);
  --accent: var(--aims-purple);
  --accent-dark: var(--aims-purple-hover);
  --accent-soft: var(--aims-panel-soft);
  --shadow: 0 24px 70px rgba(0, 0, 0, .38);
}

* { box-sizing: border-box; }

[hidden] { display: none !important; }

body {
  min-height: 100vh;
  margin: 0;
  padding: 28px 16px;
  background:
    linear-gradient(135deg, rgba(9, 13, 27, .96), rgba(16, 21, 40, .9)),
    radial-gradient(ellipse at 12% 100%, rgba(82, 62, 44, .55), transparent 46%),
    radial-gradient(ellipse at 86% 92%, rgba(36, 67, 57, .38), transparent 42%),
    linear-gradient(155deg, #263b39, #101528 56%, #080c18);
  color: var(--ink);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

.chat-shell {
  width: min(760px, 100%);
  min-height: min(820px, calc(100vh - 56px));
  display: flex;
  flex-direction: column;
  margin: 0 auto;
  overflow: hidden;
  background: var(--surface);
  border: 1px solid var(--aims-border);
  border-radius: 14px;
  box-shadow: var(--shadow);
  backdrop-filter: blur(16px);
}

.chat-header {
  position: relative;
  display: flex;
  align-items: center;
  gap: 15px;
  padding: 28px 30px 22px;
  border-bottom: 1px solid var(--aims-border);
  background: linear-gradient(120deg, rgba(255, 255, 255, .1), rgba(255, 255, 255, .02));
}

.brand-mark {
  display: grid;
  width: 48px;
  height: 48px;
  flex: 0 0 48px;
  place-items: center;
  border: 1px solid rgba(255, 255, 255, .3);
  border-radius: 10px;
  background: linear-gradient(145deg, var(--aims-purple-hover), var(--aims-purple));
  color: white;
  font-size: 1.45rem;
  font-weight: 800;
  box-shadow: 0 8px 20px rgba(91, 75, 214, .28);
}

.eyebrow { margin: 0 0 2px; color: #b9b1ff; font-size: .72rem; font-weight: 800; letter-spacing: .14em; }
h1 { margin: 0; font-size: clamp(1.35rem, 3vw, 1.7rem); letter-spacing: -.025em; }
.subtitle { margin: 5px 0 0; color: var(--muted); font-size: .9rem; }

.panel-close {
  position: absolute;
  top: 18px;
  right: 18px;
  display: grid;
  width: 34px;
  height: 34px;
  padding: 0;
  place-items: center;
  border: 1px solid transparent;
  border-radius: 8px;
  background: transparent;
  color: var(--aims-muted);
  font-size: 1.4rem;
  line-height: 1;
}
.panel-close:hover { border-color: var(--aims-border); background: var(--aims-panel-soft); color: var(--aims-white); }
.panel-close:focus-visible,
.chat-launcher:focus-visible,
.video-action:focus-visible,
button:focus-visible,
a:focus-visible,
textarea:focus-visible { outline: 3px solid rgba(164, 153, 255, .9); outline-offset: 2px; }

.notice {
  margin: 0 30px 14px;
  padding: 10px 13px;
  border: 1px solid rgba(210, 232, 255, .65);
  border-radius: 7px;
  background: var(--aims-info-bg);
  color: var(--aims-info-ink);
  font-size: .8rem;
}

.notice span { margin-right: 5px; }

.chat-log {
  display: flex;
  flex: 1;
  flex-direction: column;
  gap: 16px;
  min-height: 300px;
  padding: 18px 30px 26px;
  overflow-y: auto;
  background: rgba(4, 7, 17, .28);
}

.message {
  max-width: 88%;
  padding: 13px 16px;
  border: 1px solid var(--aims-border);
  border-radius: 9px;
  line-height: 1.55;
  font-size: .94rem;
}

.message-content { overflow-wrap: anywhere; }
.message-content p { margin: 0 0 .8em; }
.message-content p:last-child { margin-bottom: 0; }
.message-content strong { color: #ffffff; font-weight: 750; }
.message-content ul,
.message-content ol { margin: .45em 0 .8em; padding-left: 1.45em; }
.message-content li + li { margin-top: .25em; }
.message-content h1,
.message-content h2,
.message-content h3 { margin: .15em 0 .55em; line-height: 1.25; overflow-wrap: anywhere; }
.message-content h1 { font-size: 1.2em; }
.message-content h2 { font-size: 1.1em; }
.message-content h3 { font-size: 1em; }
.message-content blockquote { margin: .65em 0; padding-left: .85em; border-left: 3px solid var(--aims-purple-hover); color: var(--muted); }
.message-content code { padding: .1em .3em; border-radius: 4px; background: rgba(164, 153, 255, .16); color: #f0edff; font-size: .9em; overflow-wrap: anywhere; }
.message-content pre { max-width: 100%; margin: .65em 0 0; padding: .7em; overflow-x: auto; border-radius: 6px; background: rgba(0, 0, 0, .3); color: #f0f3fa; white-space: pre-wrap; overflow-wrap: anywhere; }
.message-content pre code { padding: 0; background: transparent; }
.message-label { margin-bottom: 5px; color: #b9b1ff; font-size: .72rem; font-weight: 750; }
.message-user { align-self: flex-end; border-bottom-right-radius: 4px; border-color: rgba(164, 153, 255, .5); background: linear-gradient(145deg, #6657db, #4d3fba); color: white; }
.message-user .message-label { color: #eeeaff; }
.message-assistant { align-self: flex-start; border-bottom-left-radius: 4px; background: rgba(255, 255, 255, .075); }
.streaming-text { white-space: pre-wrap; }
.generation-status { display: inline-flex; align-items: center; gap: 8px; color: var(--muted); }
.generation-status .loading { gap: 4px; }
.generation-status .loading span { width: 5px; height: 5px; }
.interrupted-message { margin-top: 10px; color: #ffb4b4; font-size: .82rem; font-style: italic; }

.sources { margin-top: 10px; color: var(--muted); font-size: .76rem; }
.sources strong { display: block; margin-bottom: 3px; color: #e2ddff; }
.sources ul { margin: 0; padding-left: 18px; }

.related-videos {
  display: grid;
  gap: 9px;
  width: 100%;
  max-width: 100%;
  margin-top: 14px;
  padding-top: 12px;
  border-top: 1px solid var(--aims-border);
}
.related-videos-label {
  color: #c2bbff;
  font-size: .72rem;
  font-weight: 800;
  letter-spacing: .04em;
  text-transform: uppercase;
}
.related-video-card {
  min-width: 0;
  padding: 11px;
  border: 1px solid rgba(164, 153, 255, .38);
  border-radius: 12px;
  background: rgba(8, 11, 25, .45);
}
.related-video-title {
  margin: 0 0 9px;
  color: var(--ink);
  font-size: .9rem;
  line-height: 1.35;
  overflow-wrap: anywhere;
}
.related-video-player-region {
  width: 100%;
  max-width: 100%;
}
.related-video-player {
  display: block;
  width: 100%;
  max-width: 100%;
  height: min(360px, 45vh);
  max-height: 360px;
  border-radius: 9px;
  background: #060913;
  object-fit: contain;
}
.related-video-unavailable {
  margin: 7px 0 0;
  color: var(--muted);
  font-size: .76rem;
}
.related-video-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 9px;
}
.video-action {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 34px;
  padding: 7px 10px;
  border-radius: 8px;
  font-size: .76rem;
  font-weight: 750;
  text-decoration: none;
}
.video-action-primary { background: var(--aims-purple); color: white; }
.video-action-primary:hover { background: var(--accent-dark); }
.video-action-secondary { border: 1px solid var(--aims-border); background: transparent; color: #e2ddff; }
.video-action-secondary:hover { border-color: var(--aims-purple-hover); background: var(--aims-panel-soft); }

.loading { display: inline-flex; align-items: center; gap: 6px; color: var(--muted); }
.loading span { width: 6px; height: 6px; border-radius: 50%; background: #aaa0ff; animation: pulse 1s infinite ease-in-out; }
.loading span:nth-child(2) { animation-delay: .15s; }
.loading span:nth-child(3) { animation-delay: .3s; }
@keyframes pulse { 0%, 80%, 100% { opacity: .25; transform: translateY(0); } 40% { opacity: 1; transform: translateY(-3px); } }

.composer { margin: 0 30px 30px; padding: 10px; border: 1px solid var(--aims-border); border-radius: 9px; background: rgba(0, 0, 0, .2); }
textarea { display: block; width: 100%; resize: vertical; min-height: 48px; max-height: 160px; padding: 8px 10px; border: 0; outline: 0; background: transparent; color: var(--ink); font: inherit; line-height: 1.45; }
textarea::placeholder { color: #9da5b8; }
.composer-footer { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 4px 2px 0 10px; }
.helper-text { color: var(--muted); font-size: .72rem; }
button { border: 0; border-radius: 7px; padding: 10px 15px; background: var(--aims-purple); color: white; cursor: pointer; font: inherit; font-size: .84rem; font-weight: 750; }
button:hover { background: var(--accent-dark); }
button:disabled { cursor: wait; opacity: .55; }
.error-message { margin: -17px 30px 23px; color: #ffb4b4; font-size: .8rem; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0; }

.chat-launcher {
  position: fixed;
  right: 22px;
  bottom: 22px;
  z-index: 1100;
  display: grid;
  width: 60px;
  height: 60px;
  padding: 0;
  place-items: center;
  border: 1px solid rgba(255, 255, 255, .3);
  border-radius: 15px;
  background: rgba(14, 18, 37, .94);
  box-shadow: 0 12px 32px rgba(0, 0, 0, .38), 0 0 0 1px rgba(91, 75, 214, .28);
}
.launcher-mark { color: #f7f5ff; font-size: 1.35rem; font-weight: 850; }
.launcher-tooltip {
  position: absolute;
  right: 70px;
  white-space: nowrap;
  padding: 7px 9px;
  border: 1px solid var(--aims-border);
  border-radius: 6px;
  background: var(--aims-navy-deep);
  color: var(--aims-white);
  font-size: .75rem;
  opacity: 0;
  pointer-events: none;
  transform: translateX(4px);
  transition: opacity .18s ease, transform .18s ease;
}
.chat-launcher:hover .launcher-tooltip,
.chat-launcher:focus-visible .launcher-tooltip { opacity: 1; transform: translateX(0); }

.embed-mode {
  overflow: hidden;
  padding: 0;
  background: transparent;
}
.embed-mode .chat-shell {
  position: fixed;
  right: 20px;
  bottom: 8px;
  width: min(430px, calc(100vw - 40px));
  height: min(680px, calc(100vh - 16px));
  min-height: 0;
  margin: 0;
}
.embed-mode .chat-log { min-height: 0; }

@media (max-width: 560px) {
  body { padding: 0; }
  .chat-shell { min-height: 100vh; border: 0; border-radius: 0; box-shadow: none; }
  .chat-header { padding: 22px 18px 18px; }
  .notice { margin-inline: 18px; }
  .chat-log { padding-inline: 18px; }
  .composer { margin-inline: 18px; margin-bottom: 18px; }
  .helper-text { font-size: .68rem; }
}

@media (max-width: 520px) {
  .embed-mode .chat-shell {
    right: 8px;
    bottom: 8px;
    width: calc(100vw - 16px);
    height: calc(100vh - 16px);
    max-height: none;
  }
  .embed-mode .chat-header { padding-inline: 16px 54px; }
  .embed-mode .notice,
  .embed-mode .composer { margin-inline: 12px; }
  .embed-mode .chat-log { padding-inline: 12px; }
  .embed-mode .chat-launcher { right: 8px; bottom: 8px; }
  .related-video-player { height: min(45vh, 320px); max-height: 45vh; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    scroll-behavior: auto !important;
    transition-duration: .01ms !important;
    animation-duration: .01ms !important;
    animation-iteration-count: 1 !important;
  }
}
