/* AI-консультант — виджет чата */
.ai-chat {
  position: fixed;
  right: 20px;
  bottom: 20px;
  z-index: 97;
  font-family: var(--font-body);
}

.ai-chat__toggle {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  border: 1px solid var(--line, #e4dac6);
  border-radius: 999px;
  background: var(--sand-100, #f5efe2);
  color: var(--green-900, #123b2a);
  padding: 12px 18px;
  font: inherit;
  font-size: 0.92rem;
  font-weight: 700;
  cursor: pointer;
  box-shadow: 0 12px 30px rgba(18, 59, 42, 0.18);
  transition: transform 0.15s ease, box-shadow 0.15s ease;
}

.ai-chat__toggle:hover {
  transform: translateY(-2px);
  box-shadow: 0 16px 34px rgba(18, 59, 42, 0.3);
}

.ai-chat__toggle svg {
  width: 20px;
  height: 20px;
  flex: none;
}

.ai-chat__toggle-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--green-600, #2c825a);
  box-shadow: 0 0 0 3px rgba(44, 130, 90, 0.16);
}

.ai-chat__panel {
  position: absolute;
  right: 0;
  bottom: 0;
  width: min(380px, calc(100vw - 24px));
  height: min(560px, calc(100vh - 32px));
  display: flex;
  flex-direction: column;
  border: 1px solid var(--line, #ddd3c1);
  border-radius: 20px;
  background: var(--sand-50, #fbf8f1);
  box-shadow: 0 24px 60px rgba(18, 59, 42, 0.24);
  overflow: hidden;
}

.ai-chat__panel[hidden] {
  display: none;
}

.ai-chat__head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 16px;
  background: var(--sand-100, #f5efe2);
  color: var(--green-900, #123b2a);
  border-bottom: 1px solid var(--line, #e4dac6);
}

.ai-chat__head strong {
  display: block;
  font-family: var(--font-head, Georgia, serif);
  font-size: 1.05rem;
  font-weight: 600;
  line-height: 1.2;
}

.ai-chat__head span {
  display: block;
  margin-top: 3px;
  font-size: 0.76rem;
  opacity: 0.75;
}

.ai-chat__close {
  border: 0;
  background: transparent;
  color: inherit;
  font-size: 1.4rem;
  line-height: 1;
  padding: 2px 4px;
  cursor: pointer;
  opacity: 0.8;
}

.ai-chat__close:hover {
  opacity: 1;
}

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

.ai-chat.is-started .ai-chat__body {
  display: flex;
}

.ai-chat__consent {
  display: none;
  flex: 1;
  flex-direction: column;
  justify-content: center;
  gap: 12px;
  padding: 22px 18px;
  text-align: center;
}

.ai-chat:not(.is-started) .ai-chat__consent {
  display: flex;
}

.ai-chat__consent p {
  margin: 0;
  font-size: 0.86rem;
  line-height: 1.5;
  color: var(--ink, #24362b);
}

.ai-chat__consent a {
  color: var(--green-800, #1d5c43);
  text-decoration: underline;
}

.ai-chat__phone {
  font-size: 0.86rem;
  color: var(--green-900, #123b2a);
}

.ai-chat__messages {
  flex: 1;
  overflow-y: auto;
  padding: 16px 14px 6px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  scroll-behavior: smooth;
}

.ai-chat__msg {
  max-width: 88%;
  padding: 10px 13px;
  border-radius: 14px;
  font-size: 0.88rem;
  line-height: 1.45;
  white-space: pre-wrap;
  word-break: break-word;
}

.ai-chat__msg.is-assistant {
  align-self: flex-start;
  background: #fff;
  border: 1px solid var(--line, #e3d9c7);
  border-bottom-left-radius: 5px;
  color: var(--ink, #24362b);
}

.ai-chat__msg.is-user {
  align-self: flex-end;
  background: var(--green-800, #1d5c43);
  color: #fff;
  border-bottom-right-radius: 5px;
}

.ai-chat__msg.is-error {
  align-self: stretch;
  max-width: 100%;
  background: #fdf1e7;
  border: 1px solid #e8c9a8;
  color: #6d3b16;
  font-size: 0.82rem;
}

.ai-chat__chips {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
  padding: 6px 14px 10px;
}

.ai-chat__chips:empty {
  display: none;
}

.ai-chat__chip {
  border: 1px solid var(--green-700, #226b49);
  background: transparent;
  color: var(--green-800, #1d5c43);
  border-radius: 999px;
  padding: 7px 11px;
  font: inherit;
  font-size: 0.8rem;
  line-height: 1.2;
  cursor: pointer;
  transition: background 0.15s ease, color 0.15s ease;
}

.ai-chat__chip:hover {
  background: var(--green-700, #226b49);
  color: #fff;
}

.ai-chat__form {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  padding: 10px 12px;
  border-top: 1px solid var(--line, #e3d9c7);
  background: #fdfaf4;
}

.ai-chat__input {
  flex: 1;
  min-height: 40px;
  max-height: 110px;
  resize: none;
  border: 1px solid var(--line, #d8cdb9);
  border-radius: 12px;
  padding: 10px 12px;
  font: inherit;
  font-size: 0.88rem;
  line-height: 1.35;
  color: var(--ink, #24362b);
  background: #fff;
}

.ai-chat__input:focus {
  outline: 2px solid rgba(34, 107, 73, 0.25);
  outline-offset: 1px;
}

.ai-chat__send {
  flex: none;
  width: 42px;
  height: 42px;
  border: 0;
  border-radius: 12px;
  background: var(--green-900, #123b2a);
  color: #fff;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
}

.ai-chat__send svg {
  width: 19px;
  height: 19px;
}

.ai-chat__send:disabled,
.ai-chat__chip:disabled {
  opacity: 0.5;
  cursor: default;
}

.ai-chat__note {
  margin: 0;
  padding: 0 14px 10px;
  font-size: 0.7rem;
  line-height: 1.4;
  color: var(--muted, #6b7c72);
}

.ai-chat__note a {
  color: inherit;
  text-decoration: underline;
}

.ai-chat__typing {
  align-self: flex-start;
  display: inline-flex;
  gap: 4px;
  padding: 12px 14px;
  border-radius: 14px;
  background: #fff;
  border: 1px solid var(--line, #e3d9c7);
}

.ai-chat__typing i {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--green-700, #226b49);
  opacity: 0.5;
  animation: ai-chat-blink 1.2s infinite ease-in-out;
}

.ai-chat__typing i:nth-child(2) {
  animation-delay: 0.15s;
}

.ai-chat__typing i:nth-child(3) {
  animation-delay: 0.3s;
}

@keyframes ai-chat-blink {
  0%, 80%, 100% { opacity: 0.25; transform: translateY(0); }
  40% { opacity: 1; transform: translateY(-2px); }
}

@media (max-width: 860px) {
  .ai-chat {
    bottom: calc(100px + 14px + env(safe-area-inset-bottom, 0px));
  }
}

@media (max-width: 560px) {
  .ai-chat {
    right: 12px;
    bottom: calc(100px + 10px + env(safe-area-inset-bottom, 0px));
    left: 12px;
  }

  .ai-chat__toggle {
    margin-left: auto;
  }

  .ai-chat__panel {
    position: fixed;
    top: 8px;
    right: 8px;
    bottom: calc(100px + 8px + env(safe-area-inset-bottom, 0px));
    left: 8px;
    width: auto;
    height: auto;
    max-height: none;
  }
}

@media (prefers-reduced-motion: reduce) {
  .ai-chat__toggle,
  .ai-chat__chip,
  .ai-chat__typing i {
    transition: none;
    animation: none;
  }
}
