#aichat-root {
  --aichat-primary: #4f46e5;
  --aichat-header-bg: #4f46e5;
  --aichat-header-text: #ffffff;
  --aichat-bot-bg: #f3f4f6;
  --aichat-bot-text: #111827;
  --aichat-user-bg: #4f46e5;
  --aichat-user-text: #ffffff;
  --aichat-btn-bottom: 24px;
  --aichat-btn-side: 24px;
  --aichat-btn-size: 56px;
  --aichat-icon-size: 28px;
  --aichat-icon-color: ;
}

.aichat-floating-btn {
  position: fixed;
  bottom: var(--aichat-btn-bottom, 24px);
  right: var(--aichat-btn-side, 24px);
  z-index: 99998;
  width: var(--aichat-btn-size, 56px);
  height: var(--aichat-btn-size, 56px);
  border-radius: 50%;
  background: var(--aichat-primary);
  color: var(--aichat-icon-color, #fff);
  border: none;
  cursor: pointer;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.2);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: calc(var(--aichat-icon-size, 28px) * 0.85);
  transition: transform 0.25s ease, opacity 0.25s ease;
  opacity: 0;
  transform: scale(0.5);
  pointer-events: none;
}

.aichat-floating-btn.aichat-visible {
  opacity: 1;
  transform: scale(1);
  pointer-events: auto;
}

.aichat-floating-btn:hover {
  transform: scale(1.08);
}

.aichat-floating-btn svg {
  width: var(--aichat-icon-size, 28px);
  height: var(--aichat-icon-size, 28px);
  fill: currentColor;
}

.aichat-floating-btn.aichat-btn-left {
  left: var(--aichat-btn-side, 24px);
  right: auto;
}

.aichat-window {
  position: fixed;
  bottom: calc(var(--aichat-btn-bottom, 24px) + 72px);
  right: var(--aichat-btn-side, 24px);
  z-index: 99999;
  width: 380px;
  max-width: calc(100vw - 32px);
  height: 560px;
  max-height: calc(100vh - 160px);
  background: #fff;
  border-radius: 16px;
  box-shadow: 0 8px 40px rgba(0, 0, 0, 0.18);
  display: none;
  flex-direction: column;
  overflow: hidden;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen, Ubuntu, sans-serif;
  animation: aichat-slide-up 0.3s ease;
}

.aichat-window.aichat-open {
  display: flex;
}

.aichat-window.aichat-left {
  left: var(--aichat-btn-side, 24px);
  right: auto;
}

@keyframes aichat-slide-up {
  from {
    opacity: 0;
    transform: translateY(20px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.aichat-header {
  background: var(--aichat-header-bg);
  color: var(--aichat-header-text);
  padding: 16px 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-shrink: 0;
}

.aichat-header-title {
  font-size: 16px;
  font-weight: 600;
  line-height: 1.3;
}

.aichat-header-actions {
  display: flex;
  gap: 8px;
}

.aichat-header-btn {
  background: rgba(255, 255, 255, 0.2);
  border: none;
  color: inherit;
  width: 32px;
  height: 32px;
  border-radius: 8px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
  transition: background 0.15s;
}

.aichat-header-btn:hover {
  background: rgba(255, 255, 255, 0.35);
}

.aichat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  background: #fafafa;
}

.aichat-messages::-webkit-scrollbar {
  width: 5px;
}
.aichat-messages::-webkit-scrollbar-track {
  background: transparent;
}
.aichat-messages::-webkit-scrollbar-thumb {
  background: #d1d5db;
  border-radius: 10px;
}

.aichat-msg {
  max-width: 85%;
  padding: 10px 14px;
  border-radius: 14px;
  font-size: 14px;
  line-height: 1.5;
  word-wrap: break-word;
  animation: aichat-msg-in 0.2s ease;
}

@keyframes aichat-msg-in {
  from { opacity: 0; transform: translateY(8px); }
  to   { opacity: 1; transform: translateY(0); }
}

.aichat-msg-bot {
  align-self: flex-start;
  background: var(--aichat-bot-bg);
  color: var(--aichat-bot-text);
  border-bottom-left-radius: 4px;
}

.aichat-msg-user {
  align-self: flex-end;
  background: var(--aichat-user-bg);
  color: var(--aichat-user-text);
  border-bottom-right-radius: 4px;
}

.aichat-msg-label {
  font-size: 11px;
  font-weight: 600;
  margin-bottom: 4px;
  opacity: 0.7;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.aichat-typing {
  align-self: flex-start;
  background: var(--aichat-bot-bg);
  color: var(--aichat-bot-text);
  border-radius: 14px;
  border-bottom-left-radius: 4px;
  padding: 14px 18px;
  display: flex;
  gap: 5px;
}

.aichat-typing span {
  width: 8px;
  height: 8px;
  background: #9ca3af;
  border-radius: 50%;
  animation: aichat-bounce 1.2s infinite ease-in-out both;
}

.aichat-typing span:nth-child(1) { animation-delay: -0.32s; }
.aichat-typing span:nth-child(2) { animation-delay: -0.16s; }
.aichat-typing span:nth-child(3) { animation-delay: 0; }

@keyframes aichat-bounce {
  0%, 80%, 100% { transform: scale(0.6); opacity: 0.4; }
  40% { transform: scale(1); opacity: 1; }
}

.aichat-input-area {
  padding: 12px 16px;
  border-top: 1px solid #e5e7eb;
  display: flex;
  gap: 8px;
  flex-shrink: 0;
  background: #fff;
}

.aichat-input {
  flex: 1;
  border: 1px solid #d1d5db;
  border-radius: 10px;
  padding: 10px 14px;
  font-size: 14px;
  outline: none;
  font-family: inherit;
  transition: border-color 0.15s;
  resize: none;
  line-height: 1.4;
  max-height: 120px;
  overflow-y: auto;
  min-height: 40px;
  box-sizing: border-box;
}

.aichat-input:focus {
  border-color: var(--aichat-primary);
  box-shadow: 0 0 0 3px rgba(79, 70, 229, 0.1);
}

.aichat-send-btn {
  width: 40px;
  height: 40px;
  border-radius: 10px;
  background: var(--aichat-primary);
  color: #fff;
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: opcity 0.15s;
}

.aichat-send-btn:hover {
  opacity: 0.9;
}

.aichat-send-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.aichat-send-btn svg {
  width: 18px;
  height: 18px;
  fill: currentColor;
}

@media (max-width: 767px) and (min-width: 481px) {
  .aichat-window {
    width: calc(100vw - 64px);
    max-width: 420px;
    height: 60vh;
    max-height: 560px;
  }
}

@media (max-width: 480px) {
  .aichat-window {
    bottom: 0;
    right: 0;
    left: 0;
    width: 100%;
    max-width: 100%;
    height: 100%;
    max-height: 100%;
    border-radius: 0;
  }
  .aichat-header {
    padding-top: calc(16px + env(safe-area-inset-top, 0px));
  }
  .aichat-input-area {
    padding-bottom: calc(12px + env(safe-area-inset-bottom, 0px));
  }
  .aichat-floating-btn {
    bottom: calc(var(--aichat-btn-bottom, 24px) + env(safe-area-inset-bottom, 0px));
    right: var(--aichat-btn-side, 24px);
    width: var(--aichat-btn-size, 56px);
    height: var(--aichat-btn-size, 56px);
  }
  .aichat-floating-btn.aichat-btn-left {
    left: var(--aichat-btn-side, 24px);
    right: auto;
  }
  .aichat-floating-btn svg {
    width: var(--aichat-icon-size, 28px);
    height: var(--aichat-icon-size, 28px);
  }
}