* {
  box-sizing: border-box;
}

:root {
  --primary: #4F46E5;
  --primary-dark: #4338CA;
  --header-grad-start: #4F46E5;
  --header-grad-end: #6D5BF5;
  --text: #20212a;
  --muted: #737582;
  --border: #e8e8ef;
  --surface: #ffffff;
  --surface-soft: #f7f7fb;
  --shadow: 0 18px 55px rgba(29, 28, 54, 0.18);
  --online: #22C55E;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: #f4f4f8;
  color: var(--text);
}

.demo-page {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 40px;
}

.demo-content {
  max-width: 720px;
  text-align: center;
}

.eyebrow {
  display: inline-block;
  margin-bottom: 10px;
  color: var(--primary);
  font-weight: 700;
  letter-spacing: .08em;
  text-transform: uppercase;
  font-size: 13px;
}

.demo-content h1 {
  margin: 0 0 14px;
  font-size: clamp(30px, 5vw, 54px);
  line-height: 1.05;
}

.demo-content p {
  margin: 0 auto;
  max-width: 620px;
  color: var(--muted);
  line-height: 1.7;
}

.chat-toggle {
  position: fixed;
  right: 24px;
  bottom: 24px;
  width: 62px;
  height: 62px;
  border: 0;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--header-grad-start), var(--header-grad-end));
  color: white;
  box-shadow: 0 12px 30px rgba(79, 70, 229, .35);
  cursor: pointer;
  display: grid;
  place-items: center;
  z-index: 1000;
  transition: transform .2s ease, background .2s ease;
}

.chat-toggle:hover {
  transform: translateY(-2px);
}

.chat-bubble-icon {
  width: 34px;
  height: 30px;
  background: #fff;
  border-radius: 15px 15px 15px 4px;
  display: grid;
  place-items: center;
  padding: 4px;
}

.toggle-logo {
  width: 100%;
  height: 100%;
  object-fit: contain;
}

.chat-close {
  display: none;
  font-size: 31px;
  color: #fff;
}

.chat-toggle.open .chat-bubble-icon {
  display: none;
}

.chat-toggle.open .chat-close {
  display: block;
}

.chat-widget {
  position: fixed;
  right: 24px;
  bottom: 98px;
  width: min(390px, calc(100vw - 32px));
  height: min(690px, calc(100vh - 125px));
  min-height: 520px;
  background: var(--surface);
  border: 1px solid rgba(20, 20, 50, .06);
  border-radius: 22px;
  box-shadow: var(--shadow);
  overflow: hidden;
  display: grid;
  grid-template-rows: auto 1fr auto auto auto;
  z-index: 999;
  opacity: 0;
  transform: translateY(14px) scale(.98);
  pointer-events: none;
  transition: opacity .2s ease, transform .2s ease;
}

.chat-widget.open {
  opacity: 1;
  transform: translateY(0) scale(1);
  pointer-events: auto;
}

.chat-header {
  padding: 16px 18px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: linear-gradient(135deg, var(--header-grad-start), var(--header-grad-end));
  color: #fff;
}

.header-left {
  display: flex;
  align-items: center;
  gap: 12px;
}

.avatar {
  width: 40px;
  height: 40px;
  flex: 0 0 40px;
  border-radius: 50%;
  background: #fff;
  display: grid;
  place-items: center;
  overflow: hidden;
  padding: 5px;
}

.avatar img {
  width: 100%;
  height: 100%;
  object-fit: contain;
}

.header-text strong {
  display: block;
  font-size: 15px;
  line-height: 1.3;
}

.status {
  display: flex;
  align-items: center;
  gap: 5px;
  margin-top: 2px;
  color: rgba(255,255,255,.85);
  font-size: 11.5px;
}

.brand-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--online);
  box-shadow: 0 0 0 3px rgba(34,197,94,.25);
}

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

.icon-button {
  border: 0;
  background: transparent;
  color: rgba(255,255,255,.9);
  font-size: 18px;
  cursor: pointer;
  width: 30px;
  height: 30px;
  border-radius: 8px;
}

.icon-button:hover {
  background: rgba(255,255,255,.14);
}

.chat-subbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 9px 14px;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
}

.chat-subbar.hidden {
  display: none;
}

.subbar-link {
  border: 0;
  background: transparent;
  color: var(--primary);
  font: inherit;
  font-size: 12.5px;
  font-weight: 600;
  cursor: pointer;
  padding: 4px 2px;
}

.subbar-pill {
  border: 1px solid var(--border);
  background: var(--surface-soft);
  color: var(--muted);
  font: inherit;
  font-size: 11.5px;
  border-radius: 999px;
  padding: 5px 12px;
  cursor: pointer;
}

.subbar-pill:hover {
  border-color: #e2a4a4;
  color: #B02525;
}

.chat-messages {
  overflow-y: auto;
  padding: 18px 16px 10px;
  scroll-behavior: smooth;
}

.message {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  margin: 0 0 13px;
}

.message.bot {
  justify-content: flex-start;
}

.message.user {
  justify-content: flex-end;
}

.message-avatar {
  width: 26px;
  height: 26px;
  flex: 0 0 26px;
  border-radius: 50%;
  background: #fff;
  border: 1px solid var(--border);
  display: grid;
  place-items: center;
  overflow: hidden;
  padding: 3px;
}

.message-avatar img {
  width: 100%;
  height: 100%;
  object-fit: contain;
}

.message-body {
  display: flex;
  flex-direction: column;
  max-width: 82%;
}

.message.user .message-body {
  align-items: flex-end;
}

.bubble {
  padding: 11px 13px;
  border-radius: 15px;
  font-size: 14px;
  line-height: 1.5;
  white-space: pre-line;
}

.bubble.highlight {
  border-left: 3px solid var(--primary);
}

.bot .bubble {
  background: var(--surface-soft);
  border-bottom-left-radius: 5px;
}

.user .bubble {
  background: var(--primary);
  color: white;
  border-bottom-right-radius: 5px;
}

.msg-time {
  font-size: 10px;
  color: var(--muted);
  margin-top: 3px;
  padding: 0 3px;
}

.chat-actions.menu-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
}

.action-button.menu-card {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 8px;
  min-height: 68px;
  justify-content: center;
}

.menu-card .menu-icon {
  font-size: 18px;
}

.chat-actions {
  padding: 6px 14px 12px;
  display: grid;
  gap: 8px;
  max-height: 230px;
  overflow-y: auto;
}

.chat-input-area {
  order: 0;
}

.chat-actions {
  order: 1;
}

.chat-footer {
  order: 2;
}

.action-button {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid #dedeea;
  border-radius: 11px;
  background: white;
  color: var(--text);
  font: inherit;
  font-size: 13px;
  text-align: left;
  cursor: pointer;
  transition: border-color .15s ease, background .15s ease, transform .15s ease;
}

.action-button:hover {
  border-color: var(--primary);
  background: #faf9ff;
  transform: translateY(-1px);
}

.action-button.primary {
  border-color: var(--primary);
  background: var(--primary);
  color: white;
  text-align: center;
}

.action-button.primary:hover {
  background: var(--primary-dark);
}

.action-button.secondary {
  text-align: center;
  background: var(--surface-soft);
}

.chat-input-area {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 10px 14px 12px;
  border-top: 1px solid var(--border);
}

.input-instruction {
  color: var(--muted);
  font-size: 12px;
  line-height: 1.4;
}

.input-row {
  display: flex;
  gap: 8px;
}

.input-row input {
  flex: 1;
}

.input-row button {
  flex: 0 0 42px;
}

.input-field-group {
  display: grid;
  gap: 8px;
}

.chat-input-area.hidden {
  display: none;
}

.chat-input-area input {
  min-width: 0;
  border: 1px solid #dcdce7;
  border-radius: 11px;
  padding: 10px 12px;
  outline: none;
  font: inherit;
  font-size: 13px;
}

.chat-input-area input:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(91,75,219,.09);
}

.chat-input-area > .input-row button {
  width: 42px;
  border: 0;
  border-radius: 11px;
  background: var(--primary);
  color: white;
  cursor: pointer;
  font-size: 17px;
}

.chat-footer {
  padding: 9px 14px 12px;
  border-top: 1px solid var(--border);
  display: flex;
  justify-content: space-between;
  align-items: center;
  color: #999aa5;
  font-size: 10px;
}

.chat-footer strong {
  color: var(--muted);
}

.footer-link {
  border: 0;
  background: transparent;
  color: var(--primary);
  cursor: pointer;
  font: inherit;
  font-size: 11px;
  padding: 0;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

@media (max-width: 600px) {
  .demo-page {
    padding: 24px;
  }

  .chat-toggle {
    right: 16px;
    bottom: 16px;
  }

  .chat-widget {
    right: 8px;
    bottom: 88px;
    width: calc(100vw - 16px);
    height: calc(100vh - 105px);
    min-height: 480px;
    border-radius: 19px;
  }
}
