/* Results page coaching chat — locked dark palette (OS light/dark independent) */

.iw-chat,
.results-chat-trigger {
  --iw-chat-bg: #000000;
  --iw-chat-bg-elevated: #1e1e1e;
  --iw-chat-text: #ffffff;
  --iw-chat-text-muted: rgba(255, 255, 255, 0.75);
  --iw-chat-text-soft: rgba(255, 255, 255, 0.45);
  --iw-chat-border: rgba(255, 255, 255, 0.2);
  --iw-chat-divider: rgba(255, 255, 255, 0.12);
  --iw-chat-surface: rgba(255, 255, 255, 0.1);
  --iw-chat-surface-hover: rgba(255, 255, 255, 0.15);
  --iw-chat-input-bg: #121212;
  --iw-chat-accent: #e7bd8d;
  --iw-chat-btn-bg: #f5f5f5;
  --iw-chat-btn-text: #1a1a1a;
  --iw-chat-font: "Akzidenz Grotesk Pro Ext", Arial, sans-serif;
  --iw-chat-radius-panel: 12px;
  --iw-chat-radius-bubble: 8px;
  --iw-chat-space-sm: 12px;
  --iw-chat-space-md: 16px;
  --iw-chat-space-lg: 20px;

  color-scheme: dark;
  color: var(--iw-chat-text);
  font-family: var(--iw-chat-font);
}

.results-chat-trigger {
  position: fixed;
  z-index: 9998;
  right: max(16px, env(safe-area-inset-right, 0px));
  bottom: max(20px, env(safe-area-inset-bottom, 0px));
  display: inline-flex;
  align-items: center;
  gap: 10px;
  margin: 0;
  padding: 12px 18px;
  border: 1px solid var(--iw-chat-border);
  border-radius: 999px;
  background-color: rgba(0, 0, 0, 0.88);
  box-shadow: 0 8px 28px rgba(0, 0, 0, 0.45);
  font-size: 0.875rem;
  line-height: 1.3;
  cursor: pointer;
  transition: background-color 0.2s, border-color 0.2s, transform 0.2s;
  text-align: left;
  width: auto;
  max-width: min(320px, calc(100vw - 32px));
  white-space: nowrap;
  -webkit-appearance: none;
  appearance: none;
}

.results-chat-trigger:hover {
  transform: translateY(-1px);
}

.results-chat-trigger:hover {
  background-color: var(--iw-chat-surface-hover);
  border-color: rgba(255, 255, 255, 0.3);
}

.results-chat-trigger__icon {
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  width: 28px;
  height: 28px;
}

.results-chat-trigger__icon svg {
  width: 28px;
  height: 28px;
  color: var(--iw-chat-text);
}

.results-chat-trigger__label {
  flex: 1 1 auto;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
}

.results-chat-trigger:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.results-chat-backdrop {
  position: fixed;
  inset: 0;
  z-index: 10000;
  background-color: rgba(0, 0, 0, 0.65);
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.25s ease, visibility 0.25s ease;
}

.results-chat-backdrop.is-open {
  opacity: 1;
  visibility: visible;
}

@media (min-width: 992px) {
  .results-chat-backdrop {
    display: none;
  }
}

.results-chat-panel {
  position: fixed;
  z-index: 10001;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background-color: var(--iw-chat-bg);
  border: 1px solid var(--iw-chat-border);
  border-radius: var(--iw-chat-radius-panel);
  box-shadow: 0 20px 48px rgba(0, 0, 0, 0.55);
}

/* desktop: bottom-right panel above FAB */
@media (min-width: 992px) {
  .results-chat-panel {
    right: max(16px, env(safe-area-inset-right, 0px));
    bottom: calc(72px + env(safe-area-inset-bottom, 0px));
    left: auto;
    width: 400px;
    min-width: 320px;
    max-width: min(400px, calc(100vw - 32px));
    max-height: min(640px, calc(100vh - 120px));
    transform: translateY(12px);
    opacity: 0;
    visibility: hidden;
    transition: transform 0.25s ease, opacity 0.25s ease, visibility 0.25s ease;
  }

  .results-chat-panel.is-open {
    transform: translateY(0);
    opacity: 1;
    visibility: visible;
  }
}

/* mobile: full viewport sheet */
@media (max-width: 991px) {
  .results-chat-panel {
    inset: 0;
    width: 100%;
    max-height: 100dvh;
    border-radius: 0;
    transform: translateY(100%);
    transition: transform 0.3s ease;
    padding-bottom: env(safe-area-inset-bottom, 0);
  }

  .results-chat-panel.is-open {
    transform: translateY(0);
  }
}

.results-chat-panel__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--iw-chat-space-sm);
  flex-shrink: 0;
  padding: var(--iw-chat-space-lg) var(--iw-chat-space-lg) var(--iw-chat-space-md);
  background-color: var(--iw-chat-bg);
  border-bottom: 1px solid var(--iw-chat-divider);
}

.results-chat-panel__title {
  margin: 0;
  font-size: 0.9375rem;
  font-weight: 400;
  letter-spacing: 0.01em;
  line-height: 1.3;
  color: var(--iw-chat-text);
}

@media (min-width: 992px) {
  .results-chat-panel__title {
    flex-shrink: 0;
    white-space: nowrap;
  }
}

.results-chat-panel__close {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  margin: 0;
  padding: 0;
  border: none;
  border-radius: 0;
  background: transparent;
  color: var(--iw-chat-text);
  font-size: 1.5rem;
  line-height: 1;
  cursor: pointer;
  opacity: 0.85;
  -webkit-appearance: none;
  appearance: none;
  transition: opacity 0.2s;
}

.results-chat-panel__close:hover {
  opacity: 1;
  background: transparent;
}

.results-chat-panel__close span {
  display: block;
  margin-top: -2px;
}

.results-chat-messages {
  flex: 1;
  overflow-y: auto;
  min-height: 0;
  padding: var(--iw-chat-space-md) var(--iw-chat-space-lg);
  display: flex;
  flex-direction: column;
  gap: 10px;
  background-color: var(--iw-chat-bg);
}

.results-chat-message {
  max-width: 88%;
  padding: 12px 14px;
  border: none;
  border-radius: var(--iw-chat-radius-bubble);
  font-size: 0.8125rem;
  font-weight: 300;
  line-height: 1.45;
  white-space: pre-wrap;
  word-break: break-word;
  color: var(--iw-chat-text);
}

.results-chat-message--formatted {
  white-space: normal;
}

.results-chat-message--formatted p {
  margin: 0 0 0.65em;
}

.results-chat-message--formatted p:last-child {
  margin-bottom: 0;
}

.results-chat-message--formatted strong {
  font-weight: 500;
  color: var(--iw-chat-text);
}

.results-chat-message--formatted em {
  font-style: italic;
  color: var(--iw-chat-text-muted);
}

.results-chat-message--formatted .results-chat-mark {
  padding: 0 0.2em;
  border-radius: 2px;
  background-color: rgba(231, 189, 141, 0.22);
  color: var(--iw-chat-accent);
  font-weight: 400;
}

.results-chat-message--formatted .results-chat-code {
  padding: 0.1em 0.35em;
  border-radius: 3px;
  background-color: rgba(255, 255, 255, 0.08);
  font-family: ui-monospace, Menlo, Monaco, Consolas, monospace;
  font-size: 0.9em;
}

.results-chat-message--formatted .results-chat-heading {
  margin: 0.85em 0 0.4em;
  font-size: 0.875rem;
  font-weight: 400;
  letter-spacing: 0.02em;
  color: var(--iw-chat-accent);
}

.results-chat-message--formatted .results-chat-heading:first-child {
  margin-top: 0;
}

.results-chat-message--formatted .results-chat-list {
  margin: 0.35em 0 0.65em;
  padding-left: 1.2em;
}

.results-chat-message--formatted .results-chat-list li {
  margin-bottom: 0.35em;
}

.results-chat-message--formatted .results-chat-list li:last-child {
  margin-bottom: 0;
}

.results-chat-message--formatted a {
  color: var(--iw-chat-accent);
  text-decoration: underline;
  text-underline-offset: 2px;
}

.results-chat-message--formatted a:hover {
  color: #f0d4b0;
}

.results-chat-message--user {
  align-self: flex-end;
  background-color: var(--iw-chat-bg-elevated);
}

.results-chat-message--assistant {
  align-self: flex-start;
  background-color: var(--iw-chat-bg-elevated);
}

.results-chat-message--typing {
  align-self: flex-start;
  width: fit-content;
  min-height: auto;
  padding: 14px 16px;
}

.results-chat-typing {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  height: 10px;
}

.results-chat-typing span {
  display: block;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background-color: var(--iw-chat-text-muted);
  animation: results-chat-typing-bounce 1.1s ease-in-out infinite;
}

.results-chat-typing span:nth-child(2) {
  animation-delay: 0.15s;
}

.results-chat-typing span:nth-child(3) {
  animation-delay: 0.3s;
}

@keyframes results-chat-typing-bounce {
  0%,
  55%,
  100% {
    transform: translateY(0);
    opacity: 0.45;
  }

  28% {
    transform: translateY(-5px);
    opacity: 1;
  }
}

.results-chat-empty {
  color: var(--iw-chat-text-muted);
  font-size: 0.8125rem;
  font-weight: 300;
  line-height: 1.5;
  margin: 0;
  padding: var(--iw-chat-space-sm) 0;
}

.results-chat-footer {
  flex-shrink: 0;
  padding: var(--iw-chat-space-md) var(--iw-chat-space-lg) var(--iw-chat-space-lg);
  background-color: var(--iw-chat-bg);
  border-top: 1px solid var(--iw-chat-divider);
}

.results-chat-form {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 10px;
  margin: 0;
}

.results-chat-input {
  display: block;
  box-sizing: border-box;
  width: 100%;
  min-height: 5.5rem;
  max-height: 9rem;
  margin: 0;
  padding: 14px;
  border: 1px solid var(--iw-chat-border);
  border-radius: 4px;
  background-color: var(--iw-chat-input-bg);
  color: var(--iw-chat-text);
  -webkit-text-fill-color: var(--iw-chat-text);
  caret-color: var(--iw-chat-text);
  font-family: inherit;
  font-size: 0.8125rem;
  font-weight: 300;
  resize: none;
  line-height: 1.45;
  overflow-y: auto;
  field-sizing: content;
  -webkit-appearance: none;
  appearance: none;
  box-shadow: none;
}

.results-chat-input::placeholder {
  color: var(--iw-chat-text-soft);
  opacity: 1;
}

.results-chat-input:focus {
  outline: none;
  border-color: rgba(255, 255, 255, 0.35);
  background-color: var(--iw-chat-input-bg);
}

.results-chat-input:-webkit-autofill,
.results-chat-input:-webkit-autofill:hover,
.results-chat-input:-webkit-autofill:focus {
  -webkit-box-shadow: 0 0 0 1000px var(--iw-chat-input-bg) inset;
  -webkit-text-fill-color: var(--iw-chat-text);
  caret-color: var(--iw-chat-text);
  transition: background-color 9999s ease-out 0s;
}

.results-chat-send {
  display: flex;
  align-items: center;
  justify-content: space-between;
  box-sizing: border-box;
  width: 100%;
  min-height: 48px;
  margin: 0;
  padding: 14px 16px;
  border: none;
  border-radius: 4px;
  background-color: var(--iw-chat-btn-bg);
  color: var(--iw-chat-btn-text);
  font-family: inherit;
  font-size: 0.875rem;
  font-weight: 400;
  line-height: 1;
  cursor: pointer;
  transition: opacity 0.2s, background-color 0.2s;
  -webkit-appearance: none;
  appearance: none;
}

.results-chat-send__icon {
  display: flex;
  flex-shrink: 0;
  align-items: center;
  justify-content: center;
  color: var(--iw-chat-btn-text);
  opacity: 0.9;
}

.results-chat-send__chevrons {
  display: block;
  width: 22px;
  height: 22px;
}

.results-chat-send:hover:not(:disabled) {
  opacity: 0.92;
  background-color: #ebebeb;
}

.results-chat-send:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.results-chat-input-hint {
  margin: 2px 0 0;
  font-size: 0.6875rem;
  font-weight: 300;
  line-height: 1.35;
  text-align: center;
  color: var(--iw-chat-text-soft);
}

.results-chat-error {
  padding: 0 0 var(--iw-chat-space-sm);
  color: var(--iw-chat-accent);
  font-size: 0.8125rem;
  line-height: 1.4;
  margin: 0;
}

.results-chat-error.hide {
  display: none;
}

/* OS high-contrast / forced-colors: keep readable without inverting the dark UI */
@media (forced-colors: active) {
  .iw-chat,
  .results-chat-trigger {
    forced-color-adjust: none;
  }

  .results-chat-trigger,
  .results-chat-panel,
  .results-chat-input,
  .results-chat-send,
  .results-chat-panel__close {
    border: 1px solid CanvasText;
  }

  .results-chat-send {
    background-color: ButtonFace;
    color: ButtonText;
  }
}
