/* Live chat widget — Slack via chat.php */

.chat-widget {
  position: fixed;
  right: max(20px, env(safe-area-inset-right, 0px));
  bottom: max(20px, env(safe-area-inset-bottom, 0px));
  z-index: 200;
  font-family: var(--font);
}

.chat-toggle {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 56px;
  height: 56px;
  border: none;
  border-radius: 50%;
  background: var(--gradient);
  color: #fff;
  cursor: pointer;
  box-shadow: 0 8px 28px rgba(37, 99, 235, 0.35);
  transition: transform 0.2s var(--ease), box-shadow 0.2s;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
  position: relative;
}

.chat-toggle__glyph {
  position: relative;
  width: 32px;
  height: 32px;
  display: block;
  flex-shrink: 0;
}

.chat-toggle__icon {
  position: absolute;
  transition: top 0.25s var(--ease), left 0.25s var(--ease), right 0.25s var(--ease),
    bottom 0.25s var(--ease), width 0.25s var(--ease), height 0.25s var(--ease),
    opacity 0.25s var(--ease), transform 0.25s var(--ease);
}

.chat-toggle__icon--chat {
  width: 24px;
  height: 24px;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
}

.chat-toggle__icon--mail {
  top: 1px;
  left: 1px;
  width: 11px;
  height: 11px;
  opacity: 0;
  transform: scale(0.45);
  pointer-events: none;
}

.chat-toggle--unread .chat-toggle__icon--chat {
  top: auto;
  left: auto;
  bottom: 1px;
  right: 1px;
  width: 18px;
  height: 18px;
  transform: none;
}

.chat-toggle--unread .chat-toggle__icon--mail {
  opacity: 1;
  transform: none;
}

.chat-toggle--unread {
  box-shadow: 0 8px 28px rgba(37, 99, 235, 0.35), 0 0 0 0 rgba(59, 130, 246, 0.45);
  animation: chat-toggle-pulse 2s ease-in-out infinite;
}

@keyframes chat-toggle-pulse {
  0%, 100% { box-shadow: 0 8px 28px rgba(37, 99, 235, 0.35), 0 0 0 0 rgba(59, 130, 246, 0.35); }
  50% { box-shadow: 0 12px 32px rgba(37, 99, 235, 0.5), 0 0 0 8px rgba(59, 130, 246, 0); }
}

.chat-toggle:hover {
  box-shadow: 0 12px 32px rgba(37, 99, 235, 0.45);
}

.chat-toggle--unread:hover {
  box-shadow: 0 12px 32px rgba(37, 99, 235, 0.5), 0 0 0 4px rgba(59, 130, 246, 0.2);
}

.chat-toggle:active {
  transform: scale(0.96);
}

@media (prefers-reduced-motion: reduce) {
  .chat-toggle--unread {
    animation: none;
  }

  .chat-toggle__icon {
    transition: none;
  }
}

.chat-panel {
  position: absolute;
  right: 0;
  bottom: calc(100% + 12px);
  width: min(360px, calc(100vw - 32px));
  max-height: min(520px, calc(100dvh - 120px));
  display: flex;
  flex-direction: column;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: 0 20px 60px rgba(15, 23, 42, 0.18);
  opacity: 0;
  visibility: hidden;
  transform: translateY(12px) scale(0.98);
  transition: opacity 0.25s var(--ease), transform 0.25s var(--ease), visibility 0.25s;
  pointer-events: none;
  overflow: hidden;
}

.chat-widget--open .chat-panel {
  opacity: 1;
  visibility: visible;
  transform: translateY(0) scale(1);
  pointer-events: auto;
}

.chat-widget--open .chat-toggle {
  opacity: 0;
  pointer-events: none;
  transform: scale(0.9);
}

.chat-panel__head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 16px 18px;
  border-bottom: 1px solid var(--border);
  background: linear-gradient(135deg, rgba(37, 99, 235, 0.08), transparent);
  flex-shrink: 0;
}

.chat-panel__title-wrap {
  min-width: 0;
  flex: 1;
}

.chat-panel__title {
  font-size: 0.9375rem;
  font-weight: 700;
  margin: 0;
  color: var(--text);
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px 8px;
  line-height: 1.35;
}

.chat-panel__title-prefix {
  font-weight: 700;
}

.logo--chat {
  display: inline-flex;
  align-items: center;
  font-size: 1rem;
  vertical-align: middle;
  flex-shrink: 0;
}

.logo--chat .logo__bracket {
  font-size: 1.125rem;
}

.logo--chat .logo__bracket:first-of-type {
  margin-right: 2px;
}

.logo--chat .logo__brand + .logo__bracket {
  margin-left: 2px;
}

.chat-panel__subtitle {
  font-size: 0.75rem;
  color: var(--text-muted);
  margin: 4px 0 0;
}

.chat-msg {
  display: flex;
  flex-direction: column;
  gap: 4px;
  max-width: 92%;
}

.chat-msg--user {
  align-self: flex-end;
  align-items: flex-end;
}

.chat-msg--bot {
  align-self: flex-start;
  align-items: flex-start;
}

.chat-msg__author {
  font-size: 0.6875rem;
  font-weight: 600;
  letter-spacing: 0.02em;
  color: var(--text-muted);
  padding: 0 4px;
}

.chat-msg--user .chat-msg__author {
  color: rgba(37, 99, 235, 0.85);
}

.chat-msg--bot .chat-msg__author {
  color: #64748b;
}

.chat-bubble {
  width: 100%;
  padding: 10px 12px;
  border-radius: 12px;
  font-size: 0.8125rem;
  line-height: 1.45;
  word-break: break-word;
}

.chat-bubble--bot {
  background: #f1f5f9;
  color: var(--text);
  border-bottom-left-radius: 4px;
}

.chat-bubble--hint {
  font-size: 0.75rem;
  color: var(--text-muted);
  background: #f8fafc;
  border: 1px dashed var(--border);
}

.chat-bubble--user {
  background: var(--gradient);
  color: #fff;
  border-bottom-right-radius: 4px;
}

.chat-panel__close {
  flex-shrink: 0;
  width: 44px;
  height: 44px;
  border: none;
  border-radius: 8px;
  background: transparent;
  color: var(--text-muted);
  font-size: 1.5rem;
  line-height: 1;
  cursor: pointer;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}

.chat-panel__close:hover {
  background: rgba(15, 23, 42, 0.05);
  color: var(--text);
}

.chat-panel__body {
  display: flex;
  flex-direction: column;
  min-height: 0;
  flex: 1;
  padding: 14px 16px 16px;
}

.chat-messages {
  flex: 1;
  min-height: 80px;
  max-height: 220px;
  overflow-y: auto;
  overflow-x: hidden;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-bottom: 12px;
  padding-right: 4px;
  touch-action: pan-y;
}

.chat-form {
  display: flex;
  flex-direction: column;
  gap: 8px;
  flex-shrink: 0;
}

.chat-form__row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.chat-form__row--full {
  grid-template-columns: 1fr;
}

.chat-form__input,
.chat-form__textarea {
  width: 100%;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: #fff;
  color: var(--text);
  font-family: inherit;
  font-size: 16px;
  transition: border-color 0.2s, box-shadow 0.2s;
}

.chat-form__textarea {
  min-height: 72px;
  resize: vertical;
}

.chat-form__input:focus,
.chat-form__textarea:focus {
  outline: none;
  border-color: rgba(37, 99, 235, 0.45);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
}

.chat-form__hp {
  position: absolute;
  left: -9999px;
  width: 1px;
  height: 1px;
  overflow: hidden;
}

.chat-form__status {
  min-height: 1rem;
  font-size: 0.75rem;
  margin: 0;
}

.chat-form__status--error {
  color: #dc2626;
}

.chat-form .btn {
  width: 100%;
  min-height: 48px;
}

.chat-widget__backdrop {
  display: none;
}

@media (max-width: 480px) {
  html.chat-open,
  body.chat-open {
    overflow: hidden;
    overscroll-behavior: none;
    height: 100%;
  }

  .chat-widget {
    right: max(12px, env(safe-area-inset-right, 0px));
    bottom: max(12px, env(safe-area-inset-bottom, 0px));
  }

  .chat-widget--open {
    inset: 0;
    right: 0;
    bottom: 0;
    left: 0;
    top: 0;
    pointer-events: none;
  }

  .chat-toggle {
    width: 52px;
    height: 52px;
    pointer-events: auto;
  }

  .chat-widget__backdrop {
    display: block;
    position: fixed;
    inset: 0;
    background: rgba(15, 23, 42, 0.45);
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
    transition: opacity 0.25s var(--ease), visibility 0.25s;
    border: none;
    padding: 0;
    margin: 0;
    cursor: default;
    z-index: 0;
  }

  .chat-widget--open .chat-widget__backdrop {
    opacity: 1;
    visibility: visible;
    pointer-events: auto;
  }

  .chat-widget--open .chat-panel {
    position: fixed;
    right: 0;
    left: 0;
    bottom: auto;
    width: auto;
    max-height: none;
    height: 88dvh;
    border-radius: 16px 16px 0 0;
    border-bottom: none;
    transform: translateY(100%);
    z-index: 1;
    pointer-events: auto;
    overflow: hidden;
    touch-action: pan-y;
  }

  .chat-widget--open.chat-widget--visible .chat-panel {
    transform: translateY(0);
  }

  .chat-panel__body {
    display: flex;
    flex-direction: column;
    flex: 1;
    min-height: 0;
    overflow: hidden;
    padding: 14px 0 0;
  }

  .chat-messages {
    flex: 1;
    min-height: 0;
    max-height: none;
    overflow-y: auto;
    overflow-x: hidden;
    -webkit-overflow-scrolling: touch;
    overscroll-behavior: contain;
    touch-action: pan-y;
    margin-bottom: 0;
    padding: 0 16px 10px;
  }

  .chat-form {
    flex-shrink: 0;
    position: relative;
    z-index: 1;
    margin: 0;
    padding: 10px 16px max(12px, env(safe-area-inset-bottom, 0px));
    background: var(--bg-elevated);
    border-top: 1px solid var(--border);
    box-shadow: 0 -6px 16px rgba(15, 23, 42, 0.06);
  }

  .chat-form__row {
    grid-template-columns: 1fr;
  }

  .chat-form__textarea {
    min-height: 56px;
    max-height: 96px;
    resize: none;
  }

  .chat-form .btn {
    position: static;
  }

  .chat-panel__title {
    font-size: 0.875rem;
    gap: 4px 6px;
  }

  .logo--chat {
    font-size: 0.9375rem;
  }

  .logo--chat .logo__bracket {
    font-size: 1rem;
  }
}
