/*
 * Support Assistant: use the full viewport below header/tabs (Material’s .md-grid
 * caps width at 61rem — we lift that only when #chat-app is present).
 */
html:has(#chat-app) {
  height: 100dvh;
  overflow: hidden;
}

body:has(#chat-app) {
  height: 100dvh;
  max-height: 100dvh;
  margin: 0;
  overflow: hidden;
  overscroll-behavior: none;
  display: flex;
  flex-direction: column;
}

body:has(#chat-app) .md-header {
  flex-shrink: 0;
}

body:has(#chat-app) .md-container {
  flex: 1 1 0;
  min-height: 0;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

body:has(#chat-app) nav.md-tabs {
  flex-shrink: 0;
}

body:has(#chat-app) .md-main {
  flex: 1 1 0;
  min-height: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

body:has(#chat-app) .md-main__inner {
  flex: 1 1 0;
  min-height: 0;
  max-height: 100%;
  margin-top: 0;
  overflow: hidden;
}

body:has(#chat-app) .md-main__inner.md-grid {
  max-width: none;
  width: 100%;
  margin-left: 0;
  margin-right: 0;
}

body:has(#chat-app) .md-content {
  flex: 1 1 0;
  min-width: 0;
  min-height: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

body:has(#chat-app) article.md-content__inner.md-typeset {
  position: relative;
  flex: 1 1 0;
  min-height: 0;
  display: flex;
  flex-direction: column;
  margin: 0;
  padding: 0;
  overflow: hidden;
}

body:has(#chat-app) .md-content__inner:before {
  display: none;
}

.chat-a11y-title {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

/* Support Assistant chat — scoped to #chat-app (TESSA colors via Material tokens) */
#chat-app {
  --chat-max: 100%;
  --chat-radius: 1rem;
  --chat-radius-pill: 1.25rem;
  --chat-hairline: color-mix(in srgb, var(--md-default-fg-color, #1a1a2e) 8%, transparent);
  --chat-user-bg: color-mix(in srgb, var(--md-primary-fg-color, #0d0d79) 9%, var(--md-default-bg-color, #fff));
  display: flex;
  flex-direction: column;
  box-sizing: border-box;
  width: 60%;
  max-width: 100%;
  min-width: 0;
  margin-left: auto;
  margin-right: auto;
  flex: 1 1 auto;
  min-height: 0;
  height: auto;
  max-height: none;
  padding-left: env(safe-area-inset-left, 0);
  padding-right: env(safe-area-inset-right, 0);
}

@media (max-width: 640px) {
  body:has(#chat-app) #chat-app {
    width: 100%;
  }
}

body:has(#chat-app) #chat-app .chat-shell {
  border-radius: 0;
  border: none;
  box-shadow: none;
}

#chat-app .chat-shell {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-height: 0;
  min-width: 0;
  background: var(--md-default-bg-color, #fff);
  overflow: hidden;
}

#chat-app .chat-header {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem 1.25rem;
  padding: 0.875rem clamp(1rem, 4vw, 1.5rem);
  border-bottom: 1px solid var(--chat-hairline);
  background: var(--md-default-bg-color, #fff);
}

#chat-app .chat-title {
  margin: 0;
  font-size: 0.9375rem;
  font-weight: 400;
  letter-spacing: -0.015em;
  color: var(--md-default-fg-color, #1a1a2e);
  line-height: 1.3;
}

#chat-app .chat-subtitle {
  margin: 0.2rem 0 0;
  font-size: 0.8125rem;
  line-height: 1.4;
  font-weight: 400;
  color: var(--md-default-fg-color--light, #5c5c6e);
  max-width: 36rem;
}

#chat-app .chat-new {
  font: inherit;
  font-size: 0.8125rem;
  font-weight: 600;
  padding: 0.45rem 1rem;
  color: var(--md-primary-fg-color, #0d0d79);
  background: color-mix(in srgb, var(--md-primary-fg-color, #0d0d79) 9%, var(--md-default-bg-color, #fff));
  border: 1px solid color-mix(in srgb, var(--md-primary-fg-color, #0d0d79) 32%, var(--chat-hairline));
  border-radius: 999px;
  cursor: pointer;
  white-space: nowrap;
  transition: color 0.12s ease, background 0.12s ease, border-color 0.12s ease, box-shadow 0.12s ease;
}

#chat-app .chat-new:hover:not(:disabled) {
  background: color-mix(in srgb, var(--md-primary-fg-color, #0d0d79) 15%, var(--md-default-bg-color, #fff));
  border-color: color-mix(in srgb, var(--md-primary-fg-color, #0d0d79) 48%, var(--chat-hairline));
  box-shadow: 0 1px 2px color-mix(in srgb, var(--md-primary-fg-color, #0d0d79) 12%, transparent);
}

#chat-app .chat-new:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

#chat-app .chat-messages {
  flex: 1 1 0;
  min-height: 0;
  min-width: 0;
  overflow-y: auto;
  overflow-x: hidden;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1.5rem;
  padding: 1.25rem clamp(1rem, 4vw, 1.5rem) 1.5rem;
  scroll-behavior: smooth;
}

#chat-app .chat-msg {
  flex-shrink: 0;
  min-width: 0;
  border-radius: 0;
  border: none;
  white-space: pre-wrap;
  word-break: break-word;
  overflow-wrap: anywhere;
  overflow-x: auto;
  overflow-y: visible;
  animation: chat-msg-in 0.22s ease-out both;
}

#chat-app .chat-msg.assistant,
#chat-app .chat-msg.error {
  width: 100%;
  max-width: var(--chat-max);
}

@keyframes chat-msg-in {
  from {
    opacity: 0;
    transform: translateY(4px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

#chat-app .chat-msg.user {
  align-self: flex-end;
  width: fit-content;
  max-width: min(92%, var(--chat-max));
  padding: 0.65rem 1rem;
  background: var(--chat-user-bg);
  border-radius: var(--chat-radius);
  color: var(--md-default-fg-color, #1a1a2e);
  font-size: 0.9375rem;
  line-height: 1.55;
  box-shadow: none;
}

#chat-app .chat-msg.assistant {
  align-self: stretch;
  display: flex;
  gap: 0.75rem;
  align-items: flex-start;
  padding: 0;
  background: transparent;
}

#chat-app .chat-msg.assistant .chat-avatar {
  flex-shrink: 0;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.6875rem;
  font-weight: 700;
  letter-spacing: 0.02em;
  color: var(--md-primary-bg-color, #fff);
  background: var(--md-primary-fg-color, #0d0d79);
  box-shadow: none;
}

#chat-app .chat-msg.assistant .chat-msg-column {
  flex: 1;
  min-width: 0;
  padding: 0.1rem 0 0;
  background: transparent;
  border: none;
  border-radius: 0;
  box-shadow: none;
}

#chat-app .chat-msg.assistant.streaming .chat-msg-column {
  border-left: 2px solid color-mix(in srgb, var(--md-accent-fg-color, #ed6000) 55%, transparent);
  padding-left: 0.65rem;
  margin-left: -0.65rem;
}

#chat-app .chat-msg.assistant .chat-body {
  font-size: 0.9375rem;
  line-height: 1.6;
  color: var(--md-default-fg-color, #1a1a2e);
}

/* Thinking / loader */
#chat-app .chat-thinking {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  color: var(--md-default-fg-color--light, #5c5c6e);
  font-size: 0.875rem;
  font-weight: 400;
}

#chat-app .chat-thinking-spinner {
  width: 16px;
  height: 16px;
  border-radius: 50%;
  border: 2px solid var(--chat-hairline);
  border-top-color: var(--md-accent-fg-color, #ed6000);
  animation: chat-spin 0.65s linear infinite;
}

@keyframes chat-spin {
  to {
    transform: rotate(360deg);
  }
}

#chat-app .chat-thinking-text {
  animation: chat-thinking-pulse 1.2s ease-in-out infinite;
}

@keyframes chat-thinking-pulse {
  0%,
  100% {
    opacity: 0.5;
  }
  50% {
    opacity: 1;
  }
}

#chat-app .chat-msg.error {
  align-self: center;
  max-width: var(--chat-max);
  padding: 0.75rem 1rem;
  background: color-mix(in srgb, #c62828 6%, var(--md-default-bg-color, #fff));
  border: 1px solid color-mix(in srgb, #c62828 20%, var(--chat-hairline));
  color: #7f1d1d;
  font-size: 0.875rem;
  line-height: 1.45;
  border-radius: var(--chat-radius);
}

#chat-app .chat-composer {
  padding: 0.75rem clamp(1rem, 4vw, 1.5rem) 0.25rem;
  background: var(--md-default-bg-color, #fff);
  border-top: 1px solid var(--chat-hairline);
}

#chat-app .chat-composer-box {
  display: flex;
  align-items: flex-end;
  gap: 0.5rem;
  max-width: var(--chat-max);
  margin: 0 auto;
  padding: 0.5rem 0.5rem 0.5rem 1rem;
  background: var(--md-default-bg-color, #fff);
  border: 1px solid var(--chat-hairline);
  border-radius: var(--chat-radius-pill);
  box-shadow: 0 1px 2px color-mix(in srgb, var(--md-default-fg-color, #1a1a2e) 4%, transparent);
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

#chat-app .chat-composer-box:focus-within {
  border-color: color-mix(in srgb, var(--md-primary-fg-color, #0d0d79) 35%, var(--chat-hairline));
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--md-primary-fg-color, #0d0d79) 12%, transparent);
}

#chat-app .chat-composer textarea {
  flex: 1;
  min-width: 0;
  min-height: 2.5rem;
  max-height: 200px;
  resize: none;
  padding: 0.5rem 0;
  font: inherit;
  font-size: 0.9375rem;
  line-height: 1.5;
  color: var(--md-default-fg-color, #1a1a2e);
  background: transparent;
  border: none;
  border-radius: 0;
  outline: none;
}

#chat-app .chat-composer textarea::placeholder {
  color: var(--md-default-fg-color--light, #6b6b7a);
  opacity: 0.85;
}

#chat-app .chat-composer textarea:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

#chat-app .chat-send {
  flex-shrink: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 2.25rem;
  height: 2.25rem;
  padding: 0;
  font: inherit;
  color: var(--md-primary-bg-color, #fff);
  background: var(--md-primary-fg-color, #0d0d79);
  border: none;
  border-radius: 50%;
  cursor: pointer;
  transition: background 0.12s ease, transform 0.12s ease, opacity 0.12s ease;
}

#chat-app .chat-send-label {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

#chat-app .chat-send-icon {
  display: flex;
  align-items: center;
  justify-content: center;
}

#chat-app .chat-send:hover:not(:disabled) {
  background: color-mix(in srgb, var(--md-accent-fg-color, #ed6000) 28%, var(--md-primary-fg-color, #0d0d79));
}

#chat-app .chat-send:active:not(:disabled) {
  transform: scale(0.96);
}

#chat-app .chat-send:disabled {
  opacity: 0.4;
  cursor: not-allowed;
  transform: none;
}

#chat-app .chat-status {
  font-size: 0.6875rem;
  color: var(--md-default-fg-color--light, #6b6b7a);
  min-height: 1.15rem;
  padding: 0.35rem clamp(1rem, 4vw, 1.5rem) 0.85rem;
  text-align: center;
  background: var(--md-default-bg-color, #fff);
}

#chat-app .chat-status.live {
  color: var(--md-default-fg-color--light, #6b6b7a);
}

#chat-app.chat-loading .chat-status.live:empty::before {
  content: "";
  display: inline-block;
  width: 5px;
  height: 5px;
  border-radius: 50%;
  margin-right: 6px;
  vertical-align: middle;
  background: var(--md-accent-fg-color, #ed6000);
  animation: chat-status-blink 1s ease-in-out infinite;
}

@keyframes chat-status-blink {
  0%,
  100% {
    opacity: 0.35;
  }
  50% {
    opacity: 1;
  }
}

@media (max-width: 600px) {
  #chat-app .chat-messages {
    gap: 1.25rem;
    padding-top: 1rem;
  }
}
