:root {
  --ai-chat-primary: #284b63;
  --ai-chat-accent: #4d8b57;
  --ai-chat-bg: rgba(255, 255, 255, .92);
  --ai-chat-line: rgba(23, 32, 51, .10);
  --ai-chat-muted: #697386;
  --ai-chat-shadow: 0 24px 70px rgba(23, 32, 51, .18);
}

.ai-chat {
  backdrop-filter: blur(18px);
  background: var(--ai-chat-bg);
  border: 1px solid var(--ai-chat-line);
  border-radius: 16px;
  bottom: 1.25rem;
  box-shadow: var(--ai-chat-shadow);
  display: flex;
  flex-direction: column;
  max-height: min(720px, 78vh);
  overflow: hidden;
  position: fixed;
  right: 1.25rem;
  width: min(420px, calc(100vw - 2rem));
  z-index: 1055;
}

.ai-chat.is-hidden,
.ai-chat__toggle.is-hidden {
  display: none;
}

.ai-chat__header {
  align-items: center;
  background: linear-gradient(135deg, #172033 0%, #284b63 58%, #4d8b57 100%);
  color: #fff;
  display: flex;
  justify-content: space-between;
  padding: .875rem 1rem;
}

.ai-chat__identity {
  align-items: center;
  display: flex;
  gap: .75rem;
  min-width: 0;
}

.ai-chat__identity small {
  color: rgba(255, 255, 255, .72);
  display: block;
  max-width: 260px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.ai-chat__mark {
  align-items: center;
  background: rgba(255, 255, 255, .14);
  border-radius: 10px;
  display: inline-flex;
  height: 2.25rem;
  justify-content: center;
  width: 2.25rem;
}

.ai-chat__actions {
  display: flex;
  gap: .375rem;
}

.ai-chat__btn,
.ai-chat__copy {
  appearance: none;
  border: 0;
  cursor: pointer;
}

.ai-chat__btn {
  background: transparent;
  border-radius: 8px;
  color: #fff;
  padding: .375rem;
}

.ai-chat__btn:hover {
  background: rgba(255, 255, 255, .12);
}

.ai-chat__messages {
  background: linear-gradient(180deg, rgba(248, 250, 252, .72), rgba(255, 255, 255, .82));
  display: flex;
  flex: 1;
  flex-direction: column;
  gap: .75rem;
  min-height: 320px;
  overflow: auto;
  padding: 1rem;
}

.ai-chat__empty {
  align-items: center;
  border: 1px dashed var(--ai-chat-line);
  border-radius: 14px;
  color: var(--ai-chat-muted);
  display: flex;
  flex: 1;
  flex-direction: column;
  justify-content: center;
  padding: 1.5rem;
  text-align: center;
}

.ai-chat__empty i {
  color: var(--ai-chat-primary);
  font-size: 2rem;
  margin-bottom: .5rem;
}

.ai-chat__empty strong {
  color: #172033;
  margin-bottom: .25rem;
}

.ai-chat__bubble {
  border-radius: 14px;
  box-shadow: 0 8px 22px rgba(23, 32, 51, .06);
  font-size: .925rem;
  line-height: 1.45;
  max-width: 88%;
  padding: .75rem .875rem;
  white-space: pre-wrap;
}

.ai-chat__bubble--user {
  align-self: flex-end;
  background: var(--ai-chat-primary);
  color: #fff;
}

.ai-chat__bubble--ai {
  align-self: flex-start;
  background: #fff;
  border: 1px solid var(--ai-chat-line);
  color: #172033;
}

.ai-chat__copy {
  background: transparent;
  color: var(--ai-chat-muted);
  display: block;
  font-size: .75rem;
  margin-top: .5rem;
  padding: 0;
}

.ai-chat__system {
  align-self: center;
  color: var(--ai-chat-muted);
  font-size: .8rem;
  padding: .25rem .5rem;
  text-align: center;
}

.ai-chat__typing {
  display: inline-flex;
  gap: .25rem;
}

.ai-chat__typing span {
  animation: ai-chat-blink 1.2s infinite ease-in-out;
  background: #9aa4b2;
  border-radius: 999px;
  height: .45rem;
  width: .45rem;
}

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

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

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

.ai-chat__footer {
  align-items: end;
  background: #fff;
  border-top: 1px solid var(--ai-chat-line);
  display: flex;
  gap: .625rem;
  padding: .875rem;
}

.ai-chat__input {
  border: 1px solid var(--ai-chat-line);
  border-radius: 12px;
  flex: 1;
  line-height: 1.35;
  max-height: 120px;
  min-height: 42px;
  outline: none;
  padding: .625rem .75rem;
  resize: none;
}

.ai-chat__input:focus {
  border-color: rgba(40, 75, 99, .55);
  box-shadow: 0 0 0 .2rem rgba(40, 75, 99, .08);
}

.ai-chat__send,
.ai-chat__toggle {
  align-items: center;
  background: var(--ai-chat-primary);
  border: 0;
  color: #fff;
  cursor: pointer;
  display: inline-flex;
  justify-content: center;
}

.ai-chat__send {
  border-radius: 12px;
  flex: 0 0 42px;
  height: 42px;
}

.ai-chat__toggle {
  border-radius: 999px;
  bottom: 1.25rem;
  box-shadow: var(--ai-chat-shadow);
  height: 54px;
  position: fixed;
  right: 1.25rem;
  width: 54px;
  z-index: 1054;
}

.ai-chat__toggle i {
  font-size: 1.45rem;
}

.ai-chat__pulse {
  background: var(--ai-chat-accent);
  border: 2px solid #fff;
  border-radius: 999px;
  height: .75rem;
  position: absolute;
  right: .35rem;
  top: .35rem;
  width: .75rem;
}

@media (max-width: 576px) {
  .ai-chat {
    bottom: .75rem;
    right: .75rem;
    width: calc(100vw - 1.5rem);
  }
}
