.chat-widget {
  position: fixed;
  right: 1.25rem;
  bottom: 1.25rem;
  z-index: 30;
  font-family: var(--font-sans);
}

.chat-widget__launcher {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 1px solid rgba(0, 0, 0, 0.14);
  border-radius: var(--radius-pill);
  padding: 0.625rem 1.35rem;
  font-size: 0.875rem;
  font-weight: 600;
  background: var(--dirt-red);
  color: var(--accent-on);
  cursor: pointer;
  transition: background 0.15s ease;
  box-shadow: 0 4px 20px rgba(26, 24, 20, 0.12);
}

.chat-widget__launcher:hover {
  background: var(--dirt-red-hover);
}

.chat-widget__launcher:focus-visible {
  outline: 2px solid var(--dirt-red);
  outline-offset: 2px;
}

.chat-widget.is-open .chat-widget__launcher {
  display: none;
}

.chat-widget__panel {
  display: none;
  flex-direction: column;
  width: min(22rem, calc(100vw - 2rem));
  max-height: min(28rem, calc(100vh - 6rem));
  background: var(--card);
  border: 1px solid var(--card-border);
  border-radius: var(--radius-card);
  box-shadow: 0 8px 32px rgba(26, 24, 20, 0.14);
  overflow: hidden;
}

.chat-widget.is-open .chat-widget__panel {
  display: flex;
}

.chat-widget__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  padding: 0.875rem 1rem;
  border-bottom: 1px solid var(--card-border);
}

.chat-widget__title {
  margin: 0;
  font-size: 0.9375rem;
  font-weight: 700;
  color: var(--foreground);
}

.chat-widget__close {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 2rem;
  height: 2rem;
  border: 1px solid var(--card-border);
  border-radius: var(--radius-pill);
  background: transparent;
  color: var(--muted);
  font-size: 1.25rem;
  line-height: 1;
  cursor: pointer;
  transition: background 0.15s ease, color 0.15s ease;
}

.chat-widget__close:hover {
  background: var(--dirt-red);
  border-color: var(--dirt-red);
  color: var(--accent-on);
}

.chat-widget__close:focus-visible {
  outline: 2px solid var(--dirt-red);
  outline-offset: 2px;
}

.chat-widget__messages {
  flex: 1;
  overflow-y: auto;
  padding: 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  min-height: 10rem;
}

.chat-widget__message {
  max-width: 90%;
  padding: 0.625rem 0.875rem;
  border-radius: 1rem;
  font-size: 0.875rem;
  line-height: 1.5;
  word-wrap: break-word;
}

.chat-widget__message--user {
  align-self: flex-end;
  background: var(--dirt-red);
  color: var(--accent-on);
  border-bottom-right-radius: 0.25rem;
}

.chat-widget__message--assistant {
  align-self: flex-start;
  background: rgba(26, 24, 20, 0.06);
  color: var(--foreground);
  border-bottom-left-radius: 0.25rem;
}

.chat-widget__message--error {
  align-self: center;
  background: rgba(107, 68, 60, 0.1);
  color: var(--dirt-red);
  font-size: 0.8125rem;
  text-align: center;
}

.chat-widget__message--loading {
  align-self: flex-start;
  background: rgba(26, 24, 20, 0.06);
  color: var(--muted);
  font-style: italic;
}

.chat-widget__form {
  display: flex;
  gap: 0.5rem;
  padding: 0.75rem;
  border-top: 1px solid var(--card-border);
}

.chat-widget__input {
  flex: 1;
  min-width: 0;
  padding: 0.625rem 0.875rem;
  border: 1px solid var(--card-border);
  border-radius: var(--radius-pill);
  background: var(--background);
  color: var(--foreground);
  font-family: inherit;
  font-size: 0.875rem;
}

.chat-widget__input:focus {
  outline: 2px solid var(--dirt-red);
  outline-offset: 0;
  border-color: var(--dirt-red);
}

.chat-widget__input:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

.chat-widget__send {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 1px solid rgba(0, 0, 0, 0.14);
  border-radius: var(--radius-pill);
  padding: 0.625rem 1rem;
  font-size: 0.875rem;
  font-weight: 600;
  background: var(--dirt-red);
  color: var(--accent-on);
  cursor: pointer;
  transition: background 0.15s ease;
  white-space: nowrap;
}

.chat-widget__send:hover:not(:disabled) {
  background: var(--dirt-red-hover);
}

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

.chat-widget__send:focus-visible {
  outline: 2px solid var(--dirt-red);
  outline-offset: 2px;
}

@media (max-width: 480px) {
  .chat-widget {
    right: 1rem;
    bottom: 1rem;
  }
}
