:root {
  --primary: #0071bc;
  --green: #86bc25;
  --green-hover: #6ea61c;
  --deep-blue: #003a70;
  --text: #4d4d4f;
  --muted: #666666;
  --line: #e6e7e8;
  --bot: #eaf4fb;
  --success-bg: #e8f3d7;
  --teal: #00b2a9;
  --white: #ffffff;
  --shadow: 0 8px 30px rgba(0, 0, 0, 0.12);
  --radius: 16px;
  --font-scale: 1;
  --site-scale: 1;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Arial, sans-serif;
}

* {
  box-sizing: border-box;
}

html,
body {
  width: 100%;
  height: 100%;
  margin: 0;
}

body {
  color: var(--text);
  background: var(--deep-blue);
  overflow: hidden;
  font-size: calc(16px * var(--font-scale));
}

button,
textarea,
a {
  font: inherit;
}

button {
  cursor: pointer;
}

button:focus-visible,
textarea:focus-visible,
a:focus-visible {
  outline: 3px solid var(--green);
  outline-offset: 3px;
}

.site-shell {
  position: fixed;
  inset: 0;
  overflow: hidden;
  background: linear-gradient(135deg, var(--primary), var(--deep-blue));
}

.site-frame {
  position: absolute;
  top: 0;
  left: 0;
  width: calc(100% / var(--site-scale));
  height: calc(100% / var(--site-scale));
  border: 0;
  background: var(--white);
  transform: scale(var(--site-scale));
  transform-origin: top left;
  transition: filter 0.2s ease, transform 0.2s ease, width 0.2s ease, height 0.2s ease;
}

.frame-fallback {
  position: fixed;
  left: 18px;
  bottom: 18px;
  z-index: 2;
  display: grid;
  gap: 4px;
  max-width: min(330px, calc(100vw - 36px));
  padding: 12px 14px;
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.94);
  color: var(--text);
  box-shadow: var(--shadow);
  font-size: 0.86rem;
}

.frame-fallback a {
  color: var(--primary);
  font-weight: 800;
}

.chat-toggle,
.accessibility-toggle {
  position: fixed;
  right: 22px;
  z-index: 20;
  display: grid;
  place-items: center;
  border: 0;
  box-shadow: var(--shadow);
}

.chat-toggle {
  bottom: 22px;
  width: 64px;
  height: 64px;
  border-radius: 50%;
  background: var(--primary);
  color: var(--white);
  animation: heartbeat 2.3s ease-in-out infinite;
}

.chat-toggle::after {
  content: "";
  position: absolute;
  inset: -8px;
  border: 2px solid rgba(0, 113, 188, 0.28);
  border-radius: inherit;
  animation: chat-ring 2.3s ease-out infinite;
  pointer-events: none;
}

.accessibility-toggle {
  bottom: 96px;
  width: 48px;
  height: 48px;
  border-radius: 14px;
  background: var(--white);
  color: var(--deep-blue);
  font-weight: 900;
}

.chat-toggle svg,
.icon-button svg,
.send-button svg {
  width: 24px;
  height: 24px;
  fill: currentColor;
}

.chat-window {
  position: fixed;
  right: 22px;
  bottom: 22px;
  z-index: 30;
  display: grid;
  grid-template-rows: auto auto 1fr auto auto auto;
  width: min(410px, calc(100vw - 28px));
  height: min(680px, calc(100vh - 28px));
  overflow: hidden;
  border-radius: var(--radius);
  background: var(--white);
  box-shadow: 0 18px 60px rgba(0, 0, 0, 0.28);
  opacity: 0;
  transform: translateY(18px) scale(0.96);
  transform-origin: right bottom;
  transition: opacity 0.22s ease, transform 0.22s ease;
}

.chat-window.is-open {
  opacity: 1;
  transform: translateY(0) scale(1);
}

.chat-window.is-closing {
  opacity: 0;
  transform: translateY(18px) scale(0.96);
}

.chat-header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 16px;
  background: var(--primary);
  color: var(--white);
}

.assistant-mark {
  display: block;
  width: 42px;
  height: 42px;
  flex: 0 0 auto;
  border: 2px solid rgba(255, 255, 255, 0.88);
  border-radius: 50%;
  background: var(--green);
  object-fit: cover;
  box-shadow: 0 4px 12px rgba(0, 58, 112, 0.22);
}

.chat-header h1,
.chat-header p {
  margin: 0;
}

.chat-header h1 {
  font-size: 1.04rem;
}

.chat-header p {
  font-size: 0.84rem;
  opacity: 0.94;
}

.chat-header button,
.panel-heading button {
  margin-left: auto;
  border: 0;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.18);
  color: currentColor;
  width: 34px;
  height: 34px;
  font-weight: 800;
}

.reader-controls {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 10px;
  border-bottom: 1px solid rgba(0, 113, 188, 0.14);
  background: #f0f8fd;
  color: var(--deep-blue);
  animation: reader-in 0.18s ease both;
}

.reader-pulse {
  width: 10px;
  height: 10px;
  flex: 0 0 auto;
  border-radius: 50%;
  background: var(--green);
  box-shadow: 0 0 0 0 rgba(134, 188, 37, 0.42);
  animation: reader-pulse 1.2s ease-in-out infinite;
}

.reader-controls > span {
  min-width: 0;
  flex: 1 1 auto;
  font-size: 0.84rem;
  font-weight: 800;
}

.reader-controls button {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  flex: 0 0 auto;
  border: 1px solid rgba(0, 113, 188, 0.16);
  border-radius: 999px;
  background: var(--white);
  color: var(--deep-blue);
  padding: 6px 9px;
  font-size: 0.78rem;
  font-weight: 800;
}

.reader-controls svg {
  width: 14px;
  height: 14px;
  fill: currentColor;
}

.chat-messages {
  display: flex;
  flex-direction: column;
  gap: 10px;
  overflow-y: auto;
  padding: 16px;
  background: linear-gradient(180deg, #ffffff 0%, #f7fbfe 100%);
}

.message {
  position: relative;
  max-width: 86%;
  padding: 10px 12px;
  border-radius: 14px;
  line-height: 1.38;
  font-size: 0.94rem;
  white-space: pre-wrap;
  animation: message-in 0.2s ease both;
}

.message.is-reading {
  outline: 2px solid rgba(134, 188, 37, 0.78);
  box-shadow: 0 0 0 5px rgba(134, 188, 37, 0.13);
}

.message-body {
  white-space: pre-wrap;
}

.message.bot {
  align-self: flex-start;
  margin-left: 42px;
  border-bottom-left-radius: 4px;
  background: var(--bot);
  color: var(--text);
}

.message.user {
  align-self: flex-end;
  border-bottom-right-radius: 4px;
  background: var(--primary);
  color: var(--white);
}

.message.system {
  align-self: center;
  max-width: 92%;
  background: var(--success-bg);
  color: var(--deep-blue);
  font-size: 0.86rem;
}

.message.thinking {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  margin-left: 42px;
  padding: 9px 12px;
}

.bot-avatar {
  position: absolute;
  left: -42px;
  top: 0;
  width: 34px;
  height: 34px;
  border: 2px solid var(--white);
  border-radius: 50%;
  background: var(--white);
  box-shadow: 0 4px 14px rgba(0, 58, 112, 0.18);
  object-fit: cover;
}

.message.thinking i {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--primary);
  opacity: 0.35;
  animation: thinking-dot 1s ease-in-out infinite;
}

.message.thinking i:nth-child(3) {
  animation-delay: 0.14s;
}

.message.thinking i:nth-child(4) {
  animation-delay: 0.28s;
}

.message a {
  color: inherit;
  font-weight: 800;
}

.message-links {
  display: grid;
  gap: 6px;
  margin-top: 10px;
  white-space: normal;
}

.message-links-hint {
  color: inherit;
  font-size: 0.82rem;
  opacity: 0.82;
}

.message-links a {
  display: inline-flex;
  width: fit-content;
  max-width: 100%;
  padding: 6px 9px;
  border-radius: 999px;
  background: rgba(0, 113, 188, 0.1);
  color: var(--deep-blue);
  text-decoration: none;
}

.message-actions {
  display: flex;
  gap: 7px;
  margin-top: 9px;
}

.message-action {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  min-height: 28px;
  border: 0;
  border-radius: 999px;
  padding: 5px 8px;
  background: rgba(255, 255, 255, 0.74);
  color: var(--deep-blue);
  font-size: 0.74rem;
  font-weight: 800;
  transition: background 0.18s ease, transform 0.18s ease;
}

.message.user .message-action {
  background: rgba(255, 255, 255, 0.18);
  color: var(--white);
}

.message-action:hover {
  transform: translateY(-1px);
}

.message-action.is-done {
  background: var(--success-bg);
  color: var(--deep-blue);
}

.message-action svg {
  width: 14px;
  height: 14px;
  fill: currentColor;
}

.message-time {
  display: block;
  margin-top: 7px;
  text-align: right;
  font-size: 0.68rem;
  font-weight: 700;
  line-height: 1;
  opacity: 0.66;
  white-space: nowrap;
}

.message.bot .message-time {
  color: var(--muted);
}

.message.user .message-time {
  color: rgba(255, 255, 255, 0.9);
}

.quick-actions {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding: 10px 12px;
  border-top: 1px solid var(--line);
      height: 60px;
}

.quick-actions button,
.accessibility-panel button {
  flex: 0 0 auto;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--white);
  color: var(--deep-blue);
  padding: 8px 11px;
  font-size: 0.84rem;
  font-weight: 750;
  transition: opacity 0.2s ease, transform 0.2s ease;
}

.chat-composer {
  display: grid;
  grid-template-columns: auto auto 1fr auto;
  gap: 8px;
  align-items: end;
  padding: 10px 12px;
  border-top: 1px solid var(--line);
  background: var(--white);
  transition: opacity 0.2s ease;
}

.chat-composer.is-busy {
  opacity: 0.68;
}

.icon-button,
.send-button {
  display: grid;
  place-items: center;
  width: 40px;
  height: 40px;
  border: 0;
  border-radius: 50%;
  transition: opacity 0.2s ease, transform 0.2s ease, background 0.2s ease;
}

.icon-button {
  background: var(--bot);
  color: var(--primary);
}

.icon-button.is-recording {
  background: #fff8cc;
  color: #d9534f;
  animation: mic-recording 0.9s ease-in-out infinite;
}

.send-button {
  background: var(--green);
  color: var(--white);
}

.send-button:hover {
  background: var(--green-hover);
}

button:disabled,
textarea:disabled {
  cursor: not-allowed;
  opacity: 0.58;
}

textarea {
  width: 100%;
  max-height: 110px;
  min-height: 40px;
  resize: none;
  border: 1px solid var(--line);
  border-radius: 20px;
  padding: 10px 12px;
  color: var(--text);
  background: var(--white);
}

.composer-note {
  min-height: 20px;
  margin: 0;
  padding: 0 16px 12px;
  color: var(--muted);
  font-size: 0.78rem;
}

.voice-overlay {
  position: fixed;
  inset: 0;
  z-index: 40;
  display: grid;
  place-items: center;
  padding: 24px;
  background: rgba(0, 58, 112, 0.26);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease;
}

.voice-overlay.is-listening,
.voice-overlay.is-done {
  opacity: 1;
}

.voice-card {
  display: grid;
  justify-items: center;
  gap: 10px;
  width: min(300px, calc(100vw - 48px));
  padding: 24px;
  border-radius: 18px;
  background: rgba(255, 255, 255, 0.96);
  color: var(--deep-blue);
  text-align: center;
  box-shadow: var(--shadow);
  transform: translateY(8px) scale(0.96);
  transition: transform 0.22s ease;
}

.voice-overlay.is-listening .voice-card,
.voice-overlay.is-done .voice-card {
  transform: translateY(0) scale(1);
}

.voice-card p {
  margin: 0;
  color: var(--muted);
  font-size: 0.88rem;
}

.voice-orb {
  position: relative;
  display: grid;
  grid-template-columns: repeat(3, 10px);
  align-items: center;
  justify-content: center;
  gap: 7px;
  width: 82px;
  height: 82px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--primary), var(--teal));
  color: var(--white);
}

.voice-orb::before,
.voice-orb::after {
  content: "";
  position: absolute;
  inset: -8px;
  border: 2px solid rgba(0, 178, 169, 0.24);
  border-radius: inherit;
  animation: voice-ring 1.3s ease-out infinite;
}

.voice-orb::after {
  animation-delay: 0.38s;
}

.voice-orb span {
  display: block;
  width: 8px;
  height: 24px;
  border-radius: 999px;
  background: var(--white);
  animation: voice-bar 0.8s ease-in-out infinite;
}

.voice-orb span:nth-child(2) {
  animation-delay: 0.12s;
}

.voice-orb span:nth-child(3) {
  animation-delay: 0.24s;
}

.voice-overlay.is-done .voice-orb {
  background: linear-gradient(135deg, var(--green), var(--teal));
}

.voice-overlay.is-done .voice-orb span {
  height: 8px;
  animation: done-pop 0.45s ease both;
}

.accessibility-panel {
  position: fixed;
  right: 82px;
  bottom: 96px;
  z-index: 25;
  display: grid;
  gap: 8px;
  width: 230px;
  padding: 12px;
  border-radius: 14px;
  background: var(--white);
  box-shadow: var(--shadow);
}

.accessibility-note {
  margin: 2px 2px 0;
  color: var(--muted);
  font-size: 0.74rem;
  line-height: 1.3;
}

.panel-heading {
  display: flex;
  align-items: center;
  color: var(--deep-blue);
}

.is-high-contrast {
  --primary: #000000;
  --deep-blue: #000000;
  --text: #000000;
  --bot: #ffffff;
  --line: #000000;
}

.is-high-contrast .chat-window,
.is-high-contrast .accessibility-panel,
.is-high-contrast .frame-fallback {
  border: 2px solid #000000;
}

.is-high-contrast .site-frame {
  filter: contrast(1.28) saturate(1.15);
}

.highlight-links a {
  background: #ffd700;
  color: #000000 !important;
}

.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;
}

[hidden] {
  display: none !important;
}

@keyframes heartbeat {
  0%,
  45%,
  100% {
    transform: scale(1);
  }
  12% {
    transform: scale(1.08);
  }
  24% {
    transform: scale(0.98);
  }
}

@keyframes chat-ring {
  0% {
    opacity: 0.7;
    transform: scale(0.84);
  }
  70%,
  100% {
    opacity: 0;
    transform: scale(1.28);
  }
}

@keyframes message-in {
  from {
    opacity: 0;
    transform: translateY(7px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes thinking-dot {
  0%,
  80%,
  100% {
    opacity: 0.3;
    transform: translateY(0);
  }
  40% {
    opacity: 1;
    transform: translateY(-3px);
  }
}

@keyframes mic-recording {
  0%,
  100% {
    transform: scale(1);
  }
  50% {
    transform: scale(1.08);
  }
}

@keyframes voice-ring {
  from {
    opacity: 0.65;
    transform: scale(0.82);
  }
  to {
    opacity: 0;
    transform: scale(1.38);
  }
}

@keyframes voice-bar {
  0%,
  100% {
    height: 16px;
  }
  50% {
    height: 34px;
  }
}

@keyframes done-pop {
  from {
    transform: scale(0.8);
  }
  to {
    transform: scale(1);
  }
}

@keyframes reader-in {
  from {
    opacity: 0;
    transform: translateY(-5px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes reader-pulse {
  0%,
  100% {
    box-shadow: 0 0 0 0 rgba(134, 188, 37, 0.42);
    transform: scale(1);
  }
  50% {
    box-shadow: 0 0 0 7px rgba(134, 188, 37, 0);
    transform: scale(0.94);
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.001ms !important;
    animation-iteration-count: 1 !important;
    scroll-behavior: auto !important;
    transition-duration: 0.001ms !important;
  }
}

@media (max-width: 640px) {
  .chat-window {
    right: 0;
    bottom: 0;
    width: 100vw;
    height: 100vh;
    height: 100dvh;
    max-height: 100dvh;
    border-radius: 0;
    grid-template-rows: auto auto minmax(0, 1fr) auto auto auto;
  }

  .chat-toggle {
    right: 16px;
    bottom: max(16px, env(safe-area-inset-bottom));
    width: 58px;
    height: 58px;
  }

  .accessibility-toggle {
    right: 16px;
    bottom: calc(max(16px, env(safe-area-inset-bottom)) + 72px);
  }

  .accessibility-panel {
    right: 16px;
    bottom: calc(max(16px, env(safe-area-inset-bottom)) + 128px);
    width: min(260px, calc(100vw - 32px));
  }

  .chat-header {
    padding: 12px 14px;
    padding-top: max(12px, env(safe-area-inset-top));
  }

  .assistant-mark {
    width: 38px;
    height: 38px;
  }

  .chat-header h1 {
    font-size: 1rem;
  }

  .chat-header p {
    font-size: 0.8rem;
  }

  .chat-messages {
    min-height: 0;
    padding: 12px 10px;
  }

  .message {
    max-width: 90%;
    padding: 9px 11px;
    font-size: 0.9rem;
  }

  .message.bot,
  .message.thinking {
    margin-left: 34px;
  }

  .bot-avatar {
    left: -34px;
    width: 28px;
    height: 28px;
  }

  .message-actions {
    flex-wrap: wrap;
  }

  .message-action {
    min-height: 30px;
  }

  .quick-actions {
    height: auto;
    padding: 9px 10px;
    gap: 7px;
    scroll-padding-inline: 10px;
    -webkit-overflow-scrolling: touch;
  }

  .quick-actions button {
    max-width: 78vw;
    padding: 8px 10px;
    white-space: nowrap;
  }

  .chat-composer {
    grid-template-columns: 40px 40px minmax(0, 1fr) 40px;
    gap: 7px;
    padding: 9px 10px;
  }

  textarea {
    min-width: 0;
    max-height: 96px;
    font-size: 16px;
  }

  .composer-note {
    padding: 0 12px max(10px, env(safe-area-inset-bottom));
  }

  .reader-controls {
    padding-inline: 12px;
  }

  .reader-controls button span {
    display: none;
  }

  .frame-fallback {
    display: none;
  }
}
