
.chat-widget {
  position: fixed;
  bottom: 24px;
  right: 24px;
  z-index: 99998;
  font-family: var(--font-sans, 'Inter', system-ui, -apple-system, sans-serif);
}

.chat-widget__btn {
  width: 60px;
  height: 60px;
  border-radius: 50%;
  border: none;
  background: var(--accent, #1468a3);
  color: #fff;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 12px 32px rgba(20, 104, 163, 0.45), 0 2px 8px rgba(0, 0, 0, 0.12);
  transition: transform 0.25s var(--ease-out, ease), background 0.25s var(--ease-out, ease);
  position: relative;
  animation: chat-pulse 2.4s var(--ease-out, ease) infinite;
}
.chat-widget__btn:hover {
  background: var(--accent-2, #19496c);
  transform: scale(1.06);
}
.chat-widget__btn:focus-visible {
  outline: 3px solid rgba(20, 104, 163, 0.35);
  outline-offset: 4px;
}
@keyframes chat-pulse {
  0%, 100% { box-shadow: 0 12px 32px rgba(20, 104, 163, 0.45), 0 2px 8px rgba(0, 0, 0, 0.12), 0 0 0 0 rgba(20, 104, 163, 0.5); }
  50%      { box-shadow: 0 12px 32px rgba(20, 104, 163, 0.45), 0 2px 8px rgba(0, 0, 0, 0.12), 0 0 0 14px rgba(20, 104, 163, 0); }
}

.chat-widget__icon { width: 26px; height: 26px; transition: transform 0.3s var(--ease-out, ease); }
.chat-widget__icon-close { display: none; }
.chat-widget__btn.is-open .chat-widget__icon-chat  { display: none; }
.chat-widget__btn.is-open .chat-widget__icon-close { display: block; transform: rotate(90deg); }
.chat-widget__btn.is-open { animation: none; }

.chat-widget__panel {
  position: absolute;
  bottom: 76px;
  right: 0;
  width: min(380px, calc(100vw - 32px));
  height: 560px;
  max-height: calc(100vh - 110px);
  background: #ffffff;
  border: 1px solid var(--border-soft, rgba(0, 0, 0, 0.08));
  border-radius: 18px;
  box-shadow: 0 24px 64px rgba(10, 10, 10, 0.22), 0 4px 12px rgba(10, 10, 10, 0.08);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  transform-origin: bottom right;
  animation: chat-pop 0.28s var(--ease-out, cubic-bezier(0.34, 1.56, 0.64, 1));
}
.chat-widget__panel[hidden] { display: none; }
@keyframes chat-pop {
  from { opacity: 0; transform: translateY(12px) scale(0.94); }
  to   { opacity: 1; transform: translateY(0)    scale(1); }
}

.chat-widget__header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 16px 18px;
  background: linear-gradient(135deg, var(--accent, #1468a3) 0%, var(--accent-2, #19496c) 100%);
  color: #fff;
}
.chat-widget__avatar {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.15);
  border: 1px solid rgba(255, 255, 255, 0.3);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  overflow: hidden;
}
.chat-widget__avatar svg { width: 22px; height: 22px; }
.chat-widget__avatar img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  border-radius: 50%;
}
.chat-widget__title {
  margin: 0;
  font-size: 0.95rem;
  font-weight: 600;
  line-height: 1.2;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}
.chat-widget__dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #4ade80;
  box-shadow: 0 0 0 3px rgba(74, 222, 128, 0.25);
  display: inline-block;
  flex-shrink: 0;
  animation: chat-dot-pulse 2.2s ease-in-out infinite;
}
@keyframes chat-dot-pulse {
  0%, 100% { box-shadow: 0 0 0 3px rgba(74, 222, 128, 0.25); }
  50%      { box-shadow: 0 0 0 5px rgba(74, 222, 128, 0.45); }
}
.chat-widget__status { margin: 2px 0 0; font-size: 0.78rem; opacity: 0.85; }
.chat-widget__close {
  margin-left: auto;
  background: transparent;
  border: none;
  color: #fff;
  font-size: 1.5rem;
  line-height: 1;
  cursor: pointer;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0.85;
  transition: background 0.2s ease;
}
.chat-widget__close:hover { background: rgba(255, 255, 255, 0.15); opacity: 1; }

.chat-widget__messages {
  flex: 1;
  overflow-y: auto;
  padding: 18px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  background: var(--paper-2, #f5f7f9);
  scrollbar-width: thin;
}
.chat-widget__messages::-webkit-scrollbar { width: 6px; }
.chat-widget__messages::-webkit-scrollbar-thumb { background: rgba(20, 104, 163, 0.2); border-radius: 3px; }

.chat-widget__msg {
  max-width: 82%;
  flex: 0 0 auto;
  padding: 10px 14px;
  border-radius: 16px;
  font-size: 0.92rem;
  line-height: 1.45;
  word-wrap: break-word;
  overflow-wrap: anywhere;
  word-break: break-word;
  animation: chat-msg-in 0.25s var(--ease-out, ease);
}
@keyframes chat-msg-in {
  from { opacity: 0; transform: translateY(6px); }
  to   { opacity: 1; transform: translateY(0); }
}
.chat-widget__msg--user {
  align-self: flex-end;
  background: var(--accent, #1468a3);
  color: #fff;
  border-bottom-right-radius: 4px;
}
.chat-widget__msg--bot {
  align-self: flex-start;
  background: #fff;
  color: var(--ink-100, #1a1a1a);
  border: 1px solid var(--border-soft, rgba(0, 0, 0, 0.08));
  border-bottom-left-radius: 4px;
}
.chat-widget__msg--bot a {
  color: var(--accent, #1468a3);
  text-decoration: underline;
  overflow-wrap: anywhere;
  word-break: break-all;
}

.chat-widget__msg--bot p { margin: 0 0 8px; }
.chat-widget__msg--bot p:last-child { margin-bottom: 0; }
.chat-widget__msg--bot strong { font-weight: 700; color: var(--ink-100, #1a1a1a); }
.chat-widget__msg--bot em { font-style: italic; }
.chat-widget__msg--bot code {
  font-family: var(--font-mono, ui-monospace, monospace);
  font-size: 0.86em;
  background: rgba(20, 104, 163, 0.08);
  border-radius: 4px;
  padding: 1px 5px;
}
.chat-widget__msg--bot h3,
.chat-widget__msg--bot h4,
.chat-widget__msg--bot h5,
.chat-widget__msg--bot h6 {
  font-family: var(--font-display, inherit);
  font-size: 0.95rem;
  font-weight: 700;
  line-height: 1.3;
  margin: 0 0 6px;
  color: var(--ink-100, #1a1a1a);
}
.chat-widget__msg--bot ul,
.chat-widget__msg--bot ol {
  margin: 4px 0 10px;
  padding-left: 20px;
  display: grid;
  gap: 6px;
}
.chat-widget__msg--bot ul:last-child,
.chat-widget__msg--bot ol:last-child { margin-bottom: 0; }
.chat-widget__msg--bot ul { list-style: disc; }
.chat-widget__msg--bot ol { list-style: decimal; }
.chat-widget__msg--bot li { margin: 0; padding-left: 2px; }
.chat-widget__msg--bot li::marker { color: var(--accent, #1468a3); font-weight: 700; }
.chat-widget__msg--bot li > p { margin: 0; }
.chat-widget__msg--bot li > ul,
.chat-widget__msg--bot li > ol { margin-top: 6px; }

.chat-widget__typing {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 14px 16px;
}
.chat-widget__typing span {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--accent, #1468a3);
  opacity: 0.4;
  animation: chat-typing 1.2s infinite;
}
.chat-widget__typing span:nth-child(2) { animation-delay: 0.15s; }
.chat-widget__typing span:nth-child(3) { animation-delay: 0.3s; }
@keyframes chat-typing {
  0%, 60%, 100% { opacity: 0.4; transform: translateY(0); }
  30%           { opacity: 1;   transform: translateY(-4px); }
}

.chat-widget__retry {
  opacity: 0.7;
  font-style: italic;
  font-size: 0.85rem;
}

.chat-widget__suggest {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  padding: 0 18px 12px;
  background: var(--paper-2, #f5f7f9);
}
.chat-widget__suggest button {
  background: #fff;
  border: 1px solid var(--border-soft, rgba(0, 0, 0, 0.08));
  color: var(--accent, #1468a3);
  font-size: 0.82rem;
  padding: 6px 12px;
  border-radius: 999px;
  cursor: pointer;
  transition: all 0.2s ease;
}
.chat-widget__suggest button:hover {
  background: var(--accent, #1468a3);
  color: #fff;
  border-color: var(--accent, #1468a3);
}

.chat-widget__form {
  display: flex;
  gap: 6px;
  padding: 12px 14px;
  border-top: 1px solid var(--border-soft, rgba(0, 0, 0, 0.08));
  background: #fff;
  align-items: center;
}
.chat-widget__input {
  flex: 1;
  border: 1px solid var(--border-soft, rgba(0, 0, 0, 0.08));
  border-radius: 999px;
  padding: 10px 16px;
  font-size: 0.92rem;
  font-family: inherit;
  outline: none;
  background: var(--paper-2, #f5f7f9);
  transition: border-color 0.2s ease, background 0.2s ease;
}
.chat-widget__input:focus {
  border-color: var(--accent, #1468a3);
  background: #fff;
}
.chat-widget__mic,
.chat-widget__send {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  border: none;
  background: var(--paper-2, #f5f7f9);
  color: var(--accent, #1468a3);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: background 0.2s ease, transform 0.2s ease, color 0.2s ease;
}
.chat-widget__mic:hover,
.chat-widget__send:hover {
  background: var(--accent, #1468a3);
  color: #fff;
  transform: scale(1.06);
}
.chat-widget__send {
  background: var(--accent, #1468a3);
  color: #fff;
}
.chat-widget__send:hover { background: var(--accent-2, #19496c); }
.chat-widget__send:disabled,
.chat-widget__mic:disabled {
  background: #cbd5e1;
  color: #fff;
  cursor: not-allowed;
  transform: none;
}
.chat-widget__mic svg,
.chat-widget__send svg { width: 18px; height: 18px; }

.chat-widget__mic.is-listening {
  background: #5998c5;
  color: #fff;
  animation: chat-mic-pulse 1.2s ease-in-out infinite;
}
@keyframes chat-mic-pulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(239, 68, 68, 0.5); }
  50%      { box-shadow: 0 0 0 12px rgba(239, 68, 68, 0); }
}


.chat-widget__powered {
  text-align: center;
  font-size: 0.75rem;
  color: var(--text-faint, #94a3b8);
  padding: 10px 0 10px;
  background: #fff;
  border-top: 1px solid var(--border-soft, rgba(0, 0, 0, 0.05));
}
.chat-widget__powered strong { color: var(--bk-accent, #1986c6); font-weight: 700; }

@media (max-width: 480px) {
  .chat-widget { bottom: 16px; right: 16px; left: auto; }
  .chat-widget__btn { width: 54px; height: 54px; }
  .chat-widget__panel {
    position: fixed;
    bottom: 80px;
    right: 0;
    left: 0;
    width: auto;
    height: calc(100vh - 110px);
    max-height: none;
    border-radius: 16px;
  }
}

@media (prefers-reduced-motion: reduce) {
  .chat-widget__btn { animation: none; }
  .chat-widget__panel { animation: none; }
  .chat-widget__msg { animation: none; }
}