/* Виджет HR: стили изолированы от общих диалогов сайта. */
.chat-launcher {
  position: fixed;
  right: 24px;
  bottom: calc(24px + env(safe-area-inset-bottom));
  z-index: 30;
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 58px;
  padding: 14px 22px;
  border: 1px solid #ead59c;
  border-radius: 999px;
  background: var(--gold);
  color: #191b15;
  box-shadow: 0 8px 30px #0005;
  font-weight: 700;
  transition:
    transform 0.2s,
    background 0.2s;
}
.chat-launcher:hover {
  background: #e7d59f;
  transform: translateY(-2px);
}
.chat-launcher svg,
.chat-button-icon {
  width: 24px;
  height: 24px;
  flex-shrink: 0;
}
body.menu-open .chat-launcher,
body.chat-open .chat-launcher {
  visibility: hidden;
}
body.chat-open {
  overflow: hidden;
}
body {
  padding-bottom: 88px;
}
#hr-chat-dialog {
  position: fixed;
  inset: auto 24px 24px auto;
  width: 410px;
  max-width: calc(100vw - 32px);
  height: min(640px, calc(100dvh - 48px));
  max-height: calc(100dvh - 48px);
  margin: 0;
  padding: 0;
  overflow: hidden;
  border: 1px solid #72633f;
  border-radius: 20px;
  background: var(--bg);
  color: var(--text);
  box-shadow: 0 24px 90px #0008;
}
#hr-chat-dialog[open] {
  display: flex;
  flex-direction: column;
}
#hr-chat-dialog::backdrop {
  background: #0005;
  backdrop-filter: blur(3px);
}
.chat-header {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-shrink: 0;
  padding: 20px;
  border-bottom: 1px solid var(--line);
  background: var(--panel);
}
.chat-avatar {
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  flex-shrink: 0;
  border: 1px solid #d4bd8050;
  border-radius: 14px;
  color: var(--gold);
  font-size: 15px;
  font-weight: bold;
}
#hr-chat-title {
  font-size: 19px;
  line-height: 1.3;
  letter-spacing: 0;
  margin: 0;
}
#hr-chat-dialog .chat-subtitle {
  font-size: 12px;
  margin: 3px 0 0;
  color: var(--muted);
}
.chat-close {
  display: grid;
  place-items: center;
  flex-shrink: 0;
  margin-left: auto;
  width: 44px;
  height: 44px;
  padding: 0;
  background: transparent;
  border: 1px solid var(--line);
  border-radius: 10px;
  color: var(--text);
  font-size: 26px;
}
.chat-conversation {
  position: relative;
  min-height: 0;
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.chat-empty {
  margin: auto;
  padding: 28px;
  text-align: center;
  color: var(--muted);
}
.chat-empty svg {
  width: 38px;
  height: 38px;
  color: var(--gold);
  margin-bottom: 12px;
}
.chat-empty strong {
  display: block;
  color: var(--text);
  font-size: 19px;
  font-weight: 500;
}
#hr-chat-dialog .chat-empty p {
  font-size: 14px;
  line-height: 1.6;
  margin: 10px 0 0;
}
.chat-messages {
  list-style: none;
  padding: 18px;
  margin: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  min-height: 0;
  scrollbar-width: thin;
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.chat-messages:empty {
  padding: 0;
}
.chat-message {
  max-width: 90%;
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: 14px 14px 14px 4px;
  background: var(--panel);
  align-self: flex-start;
  overflow-wrap: anywhere;
  flex-shrink: 0;
}
.chat-message--visitor {
  align-self: flex-end;
  background: #d4bd8017;
  border-color: #d4bd8045;
  border-radius: 14px 14px 4px 14px;
}
.chat-message-author {
  display: block;
  color: var(--gold);
  font-size: 12px;
}
#hr-chat-dialog .chat-message p {
  color: var(--text);
  font-size: 15px;
  line-height: 1.5;
  white-space: pre-wrap;
  margin: 5px 0 8px;
}
.chat-message-meta {
  font-size: 11px;
  color: var(--muted);
}
.chat-feedback {
  padding: 10px 18px;
  border-top: 1px solid var(--line);
  flex-shrink: 0;
}
#hr-chat-dialog #chat-status {
  font-size: 13px;
  line-height: 1.4;
  margin: 0;
  color: var(--muted);
}
#hr-chat-dialog #chat-status.is-error {
  color: #f0b1a4;
}
.chat-feedback button {
  background: none;
  border: 0;
  color: var(--gold);
  padding: 8px 0;
  min-height: 44px;
  text-decoration: underline;
  font-size: 14px;
}
.chat-form {
  padding: 12px 18px calc(14px + env(safe-area-inset-bottom));
  border-top: 1px solid var(--line);
  flex-shrink: 0;
  background: var(--panel);
}
.chat-form label {
  display: block;
  font-size: 13px;
  color: var(--muted);
  margin-bottom: 6px;
}
#chat-input {
  min-height: 64px;
  max-height: 120px;
  height: 72px;
  resize: none;
  margin: 0;
  font-size: 16px;
  line-height: 1.4;
  padding: 10px 12px;
}
.chat-form-bottom {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-top: 10px;
}
#chat-count {
  font-size: 12px;
  color: var(--muted);
}
.chat-send {
  min-height: 44px;
  padding: 9px 16px;
  font-size: 14px;
}
.chat-send:disabled {
  opacity: 0.45;
  transform: none;
}
@media (max-width: 640px) {
  .chat-launcher {
    right: 16px;
    bottom: calc(16px + env(safe-area-inset-bottom));
    min-height: 54px;
    padding: 12px 18px;
  }
  #hr-chat-dialog {
    inset: var(--chat-view-top, 0px) 0 auto;
    width: 100%;
    max-width: 100%;
    height: var(--chat-view-height, 100dvh);
    max-height: var(--chat-view-height, 100dvh);
    border: 0;
    border-radius: 0;
  }
  .chat-header {
    padding: calc(10px + env(safe-area-inset-top)) 14px 10px;
  }
  .chat-form {
    padding-left: 14px;
    padding-right: 14px;
  }
  .chat-feedback {
    padding: 8px 14px;
  }
  .chat-empty {
    padding: 20px;
  }
}
@media (max-height: 500px) {
  .chat-header {
    padding: 6px 12px;
  }
  .chat-avatar {
    display: none;
  }
  .chat-form {
    padding-top: 8px;
  }
  .chat-form label {
    display: none;
  }
  #chat-input {
    height: 48px;
    min-height: 48px;
  }
  .chat-form-bottom {
    margin-top: 6px;
  }
  .chat-feedback {
    padding-top: 5px;
    padding-bottom: 5px;
  }
  .chat-empty {
    padding: 12px;
  }
  .chat-empty svg {
    display: none;
  }
}
/* Ник и восстановление доступа. */
.chat-onboarding {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: 24px 20px;
  overscroll-behavior: contain;
}
.chat-onboarding h3 {
  font-size: 23px;
  margin: 0 0 12px;
}
#hr-chat-dialog .chat-onboarding p {
  font-size: 14px;
  margin: 0 0 24px;
}
.chat-onboarding form {
  display: grid;
  gap: 12px;
}
.chat-onboarding label {
  font-size: 14px;
  color: var(--muted);
}
.chat-onboarding input {
  margin: 0;
  font-size: 16px;
  min-width: 0;
}
.chat-onboarding details {
  border-top: 1px solid var(--line);
  margin-top: 26px;
  padding-top: 18px;
}
.chat-onboarding summary {
  color: var(--gold);
  font-size: 14px;
  padding: 8px 0;
}
.chat-onboarding details form {
  margin-top: 16px;
}
#chat-return {
  margin-top: 20px;
  min-height: 44px;
}
.chat-tools {
  display: flex;
  gap: 12px;
  padding: 5px 14px;
  border-bottom: 1px solid var(--line);
  flex-shrink: 0;
  justify-content: space-between;
}
.chat-tools button {
  background: none;
  border: 0;
  color: var(--gold);
  font-size: 12px;
  min-height: 38px;
  padding: 4px;
}
.chat-key-panel {
  padding: 12px 18px;
  border-bottom: 1px solid #d4bd8045;
  background: #d4bd800a;
  flex-shrink: 0;
  max-height: 190px;
  overflow: auto;
}
.chat-key-panel summary {
  color: var(--gold);
  font-size: 14px;
  padding: 4px 0;
}
#hr-chat-dialog .chat-key-panel p {
  font-size: 12px;
  line-height: 1.4;
  margin: 8px 0;
  color: var(--muted);
}
.chat-key-row {
  display: flex;
  gap: 8px;
  align-items: center;
}
#chat-key {
  margin: 0;
  min-width: 0;
  flex: 1;
  font-family: monospace;
  font-size: 13px;
  padding: 10px;
}
#chat-copy-key {
  width: 44px;
  height: 44px;
  flex-shrink: 0;
  border: 1px solid #d4bd8045;
  border-radius: 8px;
  background: transparent;
  color: var(--gold);
  display: grid;
  place-items: center;
}
#chat-copy-key svg {
  width: 22px;
  height: 22px;
}
.chat-message--system {
  border-style: dashed;
  background: transparent;
}
@media (max-height: 600px) {
  .chat-key-panel {
    max-height: 135px;
  }
  .chat-onboarding {
    padding: 16px;
  }
}
