:root {
  --hb-bg: #ffffff;
  --hb-surface: #f8fafc;
  --hb-surface-elevated: #ffffff;
  --hb-surface-hover: #f1f5f9;
  --hb-text: #1f2937;
  --hb-text-muted: #64748b;
  --hb-primary: #2563eb;
  --hb-primary-hover: #1d4ed8;
  --hb-primary-soft: #dbeafe;
  --hb-accent-2: #f97316;
  --hb-secondary: #7c3aed;
  --hb-success: #22c55e;
  --hb-warning: #f59e0b;
  --hb-danger: #ef4444;
  --hb-border: #e2e8f0;
  --hb-shadow: rgba(0,0,0,0.10);
  --hb-bot-bg: #f1f5f9;
  --hb-bot-text: #1f2937;
  --hb-user-bg: #2563eb;
  --hb-user-text: #ffffff;
  --hb-input-bg: #ffffff;
  --hb-header-gradient-start: #2563eb;
  --hb-header-gradient-end: #1d4ed8;
  --hb-launcher-bottom: 20px;
  --hb-window-bottom: calc(var(--hb-launcher-bottom) + 74px);
  --hb-font-size: 14px;
}

[data-hb-theme="dark"] {
  --hb-bg: #0f172a;
  --hb-surface: #1e293b;
  --hb-surface-elevated: #334155;
  --hb-surface-hover: #475569;
  --hb-text: #f8fafc;
  --hb-text-muted: #94a3b8;
  --hb-primary: #3b82f6;
  --hb-primary-hover: #2563eb;
  --hb-primary-soft: rgba(59,130,246,0.15);
  --hb-accent-2: #fb923c;
  --hb-secondary: #a78bfa;
  --hb-success: #4ade80;
  --hb-warning: #fbbf24;
  --hb-danger: #f87171;
  --hb-border: #334155;
  --hb-shadow: rgba(0,0,0,0.35);
  --hb-bot-bg: #334155;
  --hb-bot-text: #f8fafc;
  --hb-user-bg: #3b82f6;
  --hb-user-text: #ffffff;
  --hb-input-bg: #1e293b;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-hb-theme="light"]) {
    --hb-bg: #0f172a;
    --hb-surface: #1e293b;
    --hb-surface-elevated: #334155;
    --hb-surface-hover: #475569;
    --hb-text: #f8fafc;
    --hb-text-muted: #94a3b8;
    --hb-primary: #3b82f6;
    --hb-primary-hover: #2563eb;
    --hb-primary-soft: rgba(59,130,246,0.15);
    --hb-accent-2: #fb923c;
    --hb-secondary: #a78bfa;
    --hb-success: #4ade80;
    --hb-warning: #fbbf24;
    --hb-danger: #f87171;
    --hb-border: #334155;
    --hb-shadow: rgba(0,0,0,0.35);
    --hb-bot-bg: #334155;
    --hb-bot-text: #f8fafc;
    --hb-user-bg: #3b82f6;
    --hb-user-text: #ffffff;
    --hb-input-bg: #1e293b;
  }
}

#hal-bot-root,
#hal-bot-root .hal-bot-window,
#hal-bot-root .hal-bot-messages,
#hal-bot-root .hal-bot-msg,
#hal-bot-root .hal-bot-typing,
#hal-bot-root .hal-bot-input-area,
#hal-bot-root .hal-bot-input,
#hal-bot-root .hal-bot-modal-content {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  font-size: var(--hb-font-size);
  color: var(--hb-text);
  line-height: 1.5;
}

#hal-bot-root * {
  box-sizing: border-box;
}

.hal-bot-launcher,
.hal-bot-window {
  position: fixed;
  z-index: 2147483000;
}

.hal-bot-launcher {
  bottom: var(--hb-launcher-bottom);
  width: 56px;
  height: 56px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--hb-header-gradient-start), var(--hb-header-gradient-end));
  color: #fff;
  border: none;
  cursor: pointer;
  box-shadow: 0 4px 16px var(--hb-shadow);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform 180ms ease-out, box-shadow 180ms ease-out;
}

.hal-bot-launcher svg {
  width: 26px;
  height: 26px;
}

.hal-bot-launcher:hover {
  transform: scale(1.06);
  box-shadow: 0 6px 22px var(--hb-shadow);
}

.hal-bot-launcher:focus-visible {
  outline: 3px solid var(--hb-primary-soft);
  outline-offset: 2px;
}

.hal-bot-launcher.hal-bot-pulse::after {
  content: '';
  position: absolute;
  inset: -4px;
  border-radius: 50%;
  border: 2px solid var(--hb-primary);
  opacity: 0;
  animation: hb-pulse 2.5s ease-out infinite;
}

@keyframes hb-pulse {
  0% { transform: scale(0.95); opacity: 0.6; }
  100% { transform: scale(1.35); opacity: 0; }
}

.hal-bot-right.hal-bot-launcher {
  right: 20px;
}

.hal-bot-left.hal-bot-launcher {
  left: 20px;
}

.hal-bot-window {
  bottom: var(--hb-window-bottom);
  width: 380px;
  max-width: calc(100vw - 40px);
  height: 520px;
  max-height: calc(100vh - 120px);
  background: var(--hb-bg);
  color: var(--hb-text);
  border: 1px solid var(--hb-border);
  border-radius: 18px;
  box-shadow: 0 12px 48px var(--hb-shadow);
  display: none;
  flex-direction: column;
  overflow: hidden;
  transition: opacity 220ms ease-out, transform 220ms ease-out;
  opacity: 0;
  transform: translateY(12px) scale(0.98);
}

.hal-bot-window.hb-open {
  opacity: 1;
  transform: translateY(0) scale(1);
}

.hal-bot-right.hal-bot-window {
  right: 16px;
}

.hal-bot-left.hal-bot-window {
  left: 16px;
}

.hal-bot-header {
  background: linear-gradient(135deg, var(--hb-header-gradient-start), var(--hb-header-gradient-end));
  color: #fff;
  padding: 10px 14px;
  display: flex;
  align-items: center;
  gap: 10px;
  flex-shrink: 0;
}

.hal-bot-avatar {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  background: rgba(255,255,255,0.18);
  backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.hal-bot-avatar svg {
  width: 20px;
  height: 20px;
  stroke: #fff;
  fill: none;
}

.hal-bot-header-info {
  flex: 1;
  min-width: 0;
}

.hal-bot-header-title {
  font-weight: 600;
  font-size: 15px;
  line-height: 1.25;
  display: block;
}

.hal-bot-header-subtitle {
  font-size: 12px;
  line-height: 1.3;
  opacity: 0.88;
  display: block;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.hal-bot-close {
  background: rgba(255,255,255,0.12);
  border: none;
  color: #fff;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  font-size: 18px;
  line-height: 1;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 150ms ease-out;
}

.hal-bot-close:hover {
  background: rgba(255,255,255,0.25);
}

.hal-bot-messages {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  scroll-behavior: smooth;
}

.hal-bot-msg {
  max-width: 82%;
  padding: 10px 14px;
  border-radius: 16px;
  font-size: var(--hb-font-size);
  line-height: 1.5;
  word-wrap: break-word;
  overflow-wrap: break-word;
  animation: hb-msg-in 240ms ease-out;
}

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

.hal-bot-msg a {
  color: inherit;
  text-decoration: underline;
  word-break: break-all;
}

.hal-bot-msg.user {
  align-self: flex-end;
  background: var(--hb-user-bg);
  color: var(--hb-user-text);
  border-bottom-right-radius: 5px;
  box-shadow: 0 2px 8px rgba(0,0,0,0.10);
}

.hal-bot-msg.bot {
  align-self: flex-start;
  background: var(--hb-bot-bg);
  color: var(--hb-bot-text);
  border-bottom-left-radius: 5px;
  border: 1px solid var(--hb-border);
}

.hal-bot-typing {
  align-self: flex-start;
  display: none;
  align-items: center;
  gap: 8px;
  background: var(--hb-bot-bg);
  color: var(--hb-text-muted);
  border: 1px solid var(--hb-border);
  padding: 10px 14px;
  border-radius: 16px;
  margin: 0 16px 8px;
  font-size: 13px;
}

.hal-bot-typing.active {
  display: flex;
}

.hal-bot-typing-icon {
  width: 16px;
  height: 16px;
  flex-shrink: 0;
  color: var(--hb-text-muted);
}

.hal-bot-typing-dots {
  display: flex;
  gap: 4px;
  align-items: center;
}

.hal-bot-typing-dots span {
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: currentColor;
  opacity: 0.55;
  animation: hb-bounce 1.2s infinite ease-in-out;
}

.hal-bot-typing-dots span:nth-child(2) { animation-delay: 0.15s; }
.hal-bot-typing-dots span:nth-child(3) { animation-delay: 0.3s; }

@keyframes hb-bounce {
  0%, 80%, 100% { transform: translateY(0); }
  40% { transform: translateY(-5px); }
}

.hal-bot-input-area {
  border-top: 1px solid var(--hb-border);
  padding: 12px;
  display: flex;
  gap: 8px;
  flex-shrink: 0;
  background: var(--hb-surface);
}

.hal-bot-input {
  flex: 1;
  border: 1px solid var(--hb-border);
  border-radius: 12px;
  padding: 10px 12px;
  font-size: var(--hb-font-size);
  line-height: 1.45;
  color: var(--hb-text);
  background: var(--hb-input-bg);
  outline: none;
  resize: none;
  min-height: 42px;
  max-height: 96px;
  overflow-y: auto;
  font-family: inherit;
  transition: border-color 150ms ease-out, box-shadow 150ms ease-out;
}

.hal-bot-input::placeholder {
  color: var(--hb-text-muted);
  opacity: 0.8;
}

.hal-bot-input:focus {
  border-color: var(--hb-primary);
  box-shadow: 0 0 0 3px var(--hb-primary-soft);
}

.hal-bot-send {
  width: 42px;
  height: 42px;
  border-radius: 12px;
  background: var(--hb-primary);
  color: #fff;
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: background 150ms ease-out, transform 150ms ease-out;
}

.hal-bot-send svg {
  width: 18px;
  height: 18px;
  fill: currentColor;
}

.hal-bot-send:hover {
  background: var(--hb-primary-hover);
}

.hal-bot-send:disabled {
  opacity: 0.55;
  cursor: not-allowed;
  transform: none;
}

.hal-bot-send:disabled:hover {
  background: var(--hb-primary);
}

.hal-bot-error {
  background: rgba(239,68,68,0.10);
  color: var(--hb-danger);
  border: 1px solid rgba(239,68,68,0.25);
  padding: 10px 14px;
  border-radius: 12px;
  font-size: 13px;
  margin: 0 16px 12px;
}

/* Modal overlay for comparison */
.hal-bot-modal {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  z-index: 2147483001;
  display: flex;
  align-items: center;
  justify-content: center;
}

.hal-bot-modal-backdrop {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0,0,0,0.45);
  backdrop-filter: blur(2px);
}

.hal-bot-modal-content {
  position: relative;
  background: var(--hb-surface-elevated);
  border: 1px solid var(--hb-border);
  border-radius: 16px;
  box-shadow: 0 24px 64px var(--hb-shadow);
  width: 92%;
  max-width: 680px;
  max-height: 85vh;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  color: var(--hb-text);
}

.hal-bot-modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 14px 18px;
  border-bottom: 1px solid var(--hb-border);
  position: sticky;
  top: 0;
  background: var(--hb-surface-elevated);
  z-index: 1;
}

.hal-bot-modal-title {
  font-weight: 600;
  font-size: 15px;
}

.hal-bot-modal-close {
  background: none;
  border: none;
  font-size: 22px;
  cursor: pointer;
  color: var(--hb-text-muted);
  line-height: 1;
  width: 30px;
  height: 30px;
  border-radius: 50%;
  transition: background 150ms ease-out, color 150ms ease-out;
}

.hal-bot-modal-close:hover {
  background: var(--hb-surface-hover);
  color: var(--hb-text);
}

.hal-bot-modal-body {
  padding: 16px 18px;
}

.hal-bot-compare-table table {
  width: 100%;
  border-collapse: collapse;
  font-size: var(--hb-font-size);
}

.hal-bot-compare-table th,
.hal-bot-compare-table td {
  border: 1px solid var(--hb-border);
  padding: 10px 12px;
  text-align: left;
}

.hal-bot-compare-table th {
  background: var(--hb-surface);
  font-weight: 600;
}

.hal-bot-compare-table tr:nth-child(even) td {
  background: var(--hb-surface);
}

.hal-bot-compare-footer {
  margin-top: 14px;
  padding-top: 12px;
  border-top: 1px solid var(--hb-border);
}

.hal-bot-compare-footer p {
  margin: 0 0 10px;
  font-size: 13px;
  color: var(--hb-text-muted);
}

.hal-bot-inquiry-btn {
  display: inline-block;
  background: var(--hb-primary);
  color: #fff;
  text-decoration: none;
  padding: 8px 14px;
  border-radius: 8px;
  font-size: 13px;
  margin-right: 8px;
  margin-bottom: 6px;
  transition: background 150ms ease-out;
}

.hal-bot-inquiry-btn:hover {
  background: var(--hb-primary-hover);
}

@media (max-width: 420px) {
  .hal-bot-launcher {
    width: 50px;
    height: 50px;
  }

  .hal-bot-launcher svg {
    width: 22px;
    height: 22px;
  }

  .hal-bot-right.hal-bot-launcher,
  .hal-bot-right.hal-bot-window {
    right: 12px;
  }

  .hal-bot-left.hal-bot-launcher,
  .hal-bot-left.hal-bot-window {
    left: 12px;
  }

  .hal-bot-window {
    width: calc(100vw - 24px);
    height: calc(100vh - 100px);
    max-width: calc(100vw - 24px);
    border-radius: 16px;
  }

  .hal-bot-messages {
    padding: 12px;
  }

  .hal-bot-msg {
    max-width: 88%;
  }

  .hal-bot-modal-content {
    width: 96%;
    max-height: 90vh;
    border-radius: 14px;
  }

  .hal-bot-compare-table th,
  .hal-bot-compare-table td {
    padding: 8px;
    font-size: 13px;
  }
}

/* Reduced motion support */
@media (prefers-reduced-motion: reduce) {
  .hal-bot-window,
  .hal-bot-launcher,
  .hal-bot-msg,
  .hal-bot-typing-dots span,
  .hal-bot-launcher.hal-bot-pulse::after {
    animation: none !important;
    transition: none !important;
  }
  .hal-bot-window {
    opacity: 1;
    transform: none;
  }
}
