/* AI Chat Widget — T166 */
.lid-chat-widget {
  position: fixed;
  right: 1.5rem;
  bottom: 1.5rem;
  z-index: 9999;
  font-family: inherit;
}

[dir="rtl"] .lid-chat-widget {
  right: auto;
  left: 1.5rem;
}

.lid-chat-trigger {
  position: relative;
  z-index: 3;
  width: 56px;
  height: 56px;
  border-radius: 50%;
  background: var(--primary, #3b82f6);
  color: #fff;
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
  transition: transform 200ms, box-shadow 200ms;
}

@media (hover: hover) {
  .lid-chat-trigger:not(.lid-chat-trigger--open):hover {
    transform: scale(1.06);
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.2);
  }
}

.lid-chat-trigger--open {
  transform: rotate(90deg);
}

.lid-chat-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.52);
  opacity: 0;
  pointer-events: none;
  transition: opacity 200ms;
  z-index: 1;
}

.lid-chat-backdrop.is-open {
  opacity: 1;
  pointer-events: auto;
}

.lid-chat-panel {
  position: absolute;
  right: 0;
  bottom: 72px;
  width: min(380px, calc(100vw - 2rem));
  max-height: 560px;
  background: #fff;
  border-radius: 16px;
  box-shadow: 0 18px 50px rgba(15, 23, 42, 0.18);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  opacity: 0;
  transform: translateY(16px) scale(0.98);
  pointer-events: none;
  visibility: hidden;
  transition: opacity 200ms, transform 200ms, visibility 0s linear 200ms;
  z-index: 2;
}

.lid-chat-panel.is-open {
  opacity: 1;
  transform: translateY(0) scale(1);
  pointer-events: auto;
  visibility: visible;
  transition: opacity 200ms, transform 200ms;
}

[dir="rtl"] .lid-chat-panel {
  right: auto;
  left: 0;
}

.lid-chat-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  padding: 0.75rem 1rem;
  background: var(--primary, #3b82f6);
  color: #fff;
}

.lid-chat-header__info strong {
  display: block;
  font-size: 0.95rem;
}

.lid-chat-header__status {
  font-size: 0.75rem;
  opacity: 0.85;
}

.lid-chat-header__actions {
  display: flex;
  align-items: center;
  gap: 0.4rem;
}

.lid-chat-reset,
.lid-chat-close {
  min-width: 44px;
  min-height: 44px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: transparent;
  border: none;
  color: #fff;
  cursor: pointer;
}

.lid-chat-reset {
  font-size: 0.75rem;
  font-weight: 600;
  padding: 0.35rem 0.55rem;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.16);
}

.lid-chat-close {
  font-size: 1.5rem;
  line-height: 1;
  padding: 0;
}

.lid-chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  min-height: 250px;
  max-height: 350px;
  background: #fff;
}

.lid-chat-bubble {
  max-width: 85%;
  padding: 0.65rem 1rem;
  border-radius: 16px;
  font-size: 0.9rem;
  line-height: 1.5;
  word-break: break-word;
}

.lid-chat-bubble p {
  margin: 0;
}

.lid-chat-model-badge {
  font-size: 0.65rem;
  color: #999;
  display: block;
  margin-top: 2px;
}

.lid-chat-bubble--user {
  align-self: flex-end;
  background: var(--primary, #3b82f6);
  color: #fff;
  border-bottom-right-radius: 4px;
}

[dir="rtl"] .lid-chat-bubble--user {
  border-bottom-right-radius: 16px;
  border-bottom-left-radius: 4px;
}

.lid-chat-bubble--assistant {
  align-self: flex-start;
  background: #f1f5f9;
  color: #1f2937;
  border-bottom-left-radius: 4px;
}

[dir="rtl"] .lid-chat-bubble--assistant {
  border-bottom-left-radius: 16px;
  border-bottom-right-radius: 4px;
}

.lid-chat-link {
  color: var(--primary, #3b82f6);
  text-decoration: underline;
}

.lid-chat-bubble--user .lid-chat-link {
  color: #fff;
}

.lid-chat-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  padding: 0.25rem 0;
}

.lid-chat-chip {
  background: #e3f2fd;
  color: #1565c0;
  border: 1px solid #90caf9;
  border-radius: 16px;
  padding: 0.3rem 0.75rem;
  font-size: 0.8rem;
  cursor: pointer;
  transition: background 200ms;
}

@media (hover: hover) {
  .lid-chat-chip:hover {
    background: #bbdefb;
  }
}

.lid-chat-input-wrap {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.65rem;
  border-top: 1px solid #e2e8f0;
  background: #fff;
}

.lid-chat-input {
  flex: 1;
  min-height: 44px;
  border: 1px solid #cbd5e1;
  border-radius: 20px;
  padding: 0.6rem 1rem;
  font-size: 0.9rem;
  outline: 2px solid transparent;
  outline-offset: 2px;
  font-family: inherit;
}

.lid-chat-input:focus,
.lid-chat-input:focus-visible {
  border-color: #1a73e8;
  outline-color: #1a73e8;
  box-shadow: 0 0 0 4px rgba(26, 115, 232, 0.18);
}

.lid-chat-send {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  border: none;
  background: var(--primary, #3b82f6);
  color: #fff;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform 200ms, background 200ms;
}

@media (hover: hover) {
  .lid-chat-send:hover {
    background: #2563eb;
    transform: translateY(-1px);
  }
}

.lid-chat-typing .lid-chat-dots span {
  display: inline-block;
  animation: lid-chat-dot-blink 1.4s infinite;
  font-size: 1.5rem;
  line-height: 1;
}

.lid-chat-dots span:nth-child(2) { animation-delay: 0.2s; }
.lid-chat-dots span:nth-child(3) { animation-delay: 0.4s; }

@keyframes lid-chat-dot-blink {
  0%, 80%, 100% { opacity: 0.2; }
  40% { opacity: 1; }
}

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

  [dir="rtl"] .lid-chat-widget {
    left: 1rem;
  }

  .lid-chat-panel {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    width: 100%;
    max-height: 100vh;
    border-radius: 0;
    transform: translateY(24px);
  }

  [dir="rtl"] .lid-chat-panel {
    left: 0;
    right: 0;
  }

  .lid-chat-panel.is-open {
    transform: translateY(0);
  }

  .lid-chat-backdrop {
    display: block;
  }

  .lid-chat-messages {
    max-height: none;
  }
}

@media (min-width: 640px) {
  .lid-chat-panel {
    width: 380px;
    max-height: 560px;
  }

  .lid-chat-backdrop {
    display: none;
  }
}

@media (prefers-reduced-motion: reduce) {
  .lid-chat-panel,
  .lid-chat-trigger,
  .lid-chat-backdrop,
  .lid-chat-send,
  .lid-chat-chip {
    transition: none !important;
  }

  .lid-chat-typing .lid-chat-dots span {
    animation: none !important;
  }
}
