.chat {
  position: fixed;
  right: clamp(12px, 2vw, 24px);
  bottom: clamp(12px, 2vw, 24px);
  width: min(340px, calc(100vw - 24px));
  max-height: min(70vh, 520px);
  display: flex;
  flex-direction: column;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: rgba(23, 27, 36, .96);
  backdrop-filter: blur(12px);
  box-shadow: 0 18px 50px rgba(0, 0, 0, .5);
  z-index: 30;
  font-size: 14px;
}

.chat[hidden] { display: none; }
.chat.is-collapsed .chat__body { display: none; }

.chat__header {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 12px;
  border-bottom: 1px solid var(--line);
}

.chat__title { flex: 1; font-weight: 700; font-size: 14px; }

.chat__status {
  font-size: 11px;
  color: var(--muted);
  white-space: nowrap;
}

.chat__status[data-state="online"] { color: var(--ok); }
.chat__status[data-state="error"] { color: var(--off); }
.chat__status[data-state="connecting"] { color: var(--warn); }

.chat__toggle {
  width: 26px;
  height: 26px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: var(--surface-2);
  color: var(--text);
  font-size: 16px;
  line-height: 1;
  cursor: pointer;
}

.chat__body { display: flex; flex-direction: column; min-height: 0; }

.chat__messages {
  flex: 1;
  min-height: 140px;
  overflow-y: auto;
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.chat__empty {
  margin: auto;
  color: var(--muted);
  font-size: 12px;
  text-align: center;
}

.chat__msg {
  font-size: 13px;
  overflow-wrap: anywhere;
  line-height: 1.4;
}

.chat__msg strong { color: var(--accent); }

.chat__msg--system {
  color: var(--muted);
  font-size: 11px;
  font-style: italic;
  text-align: center;
}

.chat__msg--error { color: var(--off); font-size: 12px; }

.chat__auth,
.chat__form {
  display: flex;
  flex-direction: column;
  gap: 7px;
  padding: 10px;
  border-top: 1px solid var(--line);
}

.chat__auth[hidden],
.chat__form[hidden],
.chat__row[hidden] { display: none; }

.chat__row { display: flex; gap: 6px; }

.chat__auth input,
.chat__form input {
  min-width: 0;
  padding: 9px 11px;
  border: 1px solid var(--line);
  border-radius: 9px;
  background: var(--surface-2);
  color: var(--text);
  font: inherit;
  font-size: 13px;
}

.chat__form .chat__name { font-size: 11px; padding: 6px 10px; }

.chat__auth input:focus-visible,
.chat__form input:focus-visible,
.chat__toggle:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.chat__auth .btn,
.chat__form .btn { padding: 9px 12px; font-size: 13px; }

.chat__form .btn:disabled { opacity: .5; cursor: not-allowed; }

@media (max-width: 600px) {
  .chat { right: 8px; bottom: 8px; width: calc(100vw - 16px); max-height: 55vh; }
}
