/*
 * Marshall Auto Locksmiths: website chat assistant.
 * Uses the design tokens defined in /_astro/Layout.*.css (colours, fonts,
 * radii, shadows) so the widget matches the rest of the site.
 */

.chatbot [hidden] { display: none !important; }

.chatbot button { font-family: var(--font-heading); }

.chatbot :focus-visible {
  outline: 2px solid var(--color-primary);
  outline-offset: 2px;
}

/* ---------- Launcher ---------- */

.chatbot-launcher {
  position: fixed;
  right: 24px;
  bottom: calc(24px + var(--chatbot-lift, 0px));
  z-index: 1000002;
  width: 60px;
  height: 60px;
  border: 0;
  border-radius: 50%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  font-size: 1.45rem;
  cursor: pointer;
  background: linear-gradient(135deg, var(--color-primary), var(--color-navy-light));
  box-shadow: var(--shadow-lg);
  transition: transform .15s, box-shadow .15s, bottom .2s;
}

.chatbot-launcher:hover {
  transform: translateY(-2px);
  box-shadow: 0 20px 44px #16233a40;
}

.chatbot-launcher:focus-visible {
  outline: 3px solid var(--color-primary-light);
  outline-offset: 3px;
}

.chatbot-launcher .icon-close { display: none; }
.chatbot.is-open .chatbot-launcher .icon-open { display: none; }
.chatbot.is-open .chatbot-launcher .icon-close { display: inline-block; font-size: 1.15rem; }

.chatbot-badge {
  position: absolute;
  top: -3px;
  right: -3px;
  min-width: 22px;
  height: 22px;
  padding: 0 6px;
  border-radius: 11px;
  background: #fff;
  color: var(--color-navy);
  font-family: var(--font-heading);
  font-size: .75rem;
  font-weight: 800;
  line-height: 22px;
  box-shadow: var(--shadow-sm);
}

/* ---------- Teaser ---------- */

.chatbot-teaser {
  position: fixed;
  right: 24px;
  bottom: calc(98px + var(--chatbot-lift, 0px));
  z-index: 1000002;
  width: 270px;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-md);
  animation: chatbot-rise .25s ease-out;
}

.chatbot-teaser::after {
  content: "";
  position: absolute;
  right: 24px;
  bottom: -7px;
  width: 12px;
  height: 12px;
  background: var(--color-surface);
  border-right: 1px solid var(--color-border);
  border-bottom: 1px solid var(--color-border);
  transform: rotate(45deg);
}

.chatbot-teaser-body {
  display: block;
  width: 100%;
  padding: .9rem 2.4rem .9rem 1.1rem;
  border: 0;
  background: none;
  text-align: left;
  cursor: pointer;
  border-radius: var(--radius-md);
}

.chatbot-teaser-body strong {
  display: block;
  margin-bottom: .2rem;
  color: var(--color-navy);
  font-size: .95rem;
  font-weight: 700;
}

.chatbot-teaser-body span {
  display: block;
  color: var(--color-text-muted);
  font-family: var(--font-body);
  font-size: .88rem;
  line-height: 1.45;
}

.chatbot-teaser-close {
  position: absolute;
  top: .45rem;
  right: .45rem;
  width: 28px;
  height: 28px;
  border: 0;
  border-radius: 50%;
  background: none;
  color: var(--color-text-muted);
  cursor: pointer;
  font-size: .85rem;
}

.chatbot-teaser-close:hover { background: var(--color-bg); color: var(--color-navy); }

/* ---------- Panel ---------- */

.chatbot-panel {
  position: fixed;
  right: 24px;
  bottom: calc(98px + var(--chatbot-lift, 0px));
  z-index: 1000001;
  width: min(390px, calc(100vw - 48px));
  height: min(640px, calc(100vh - 122px - var(--chatbot-lift, 0px)));
  height: min(640px, calc(100dvh - 122px - var(--chatbot-lift, 0px)));
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background: var(--color-bg);
  color: var(--color-text);
  font-family: var(--font-body);
  line-height: 1.55;
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg), 0 0 0 1px #16233a14;
  transform-origin: bottom right;
  animation: chatbot-pop .2s ease-out;
}

.chatbot-panel.no-anim { animation: none; }

/* Header */

.chatbot-head {
  display: flex;
  align-items: center;
  gap: .8rem;
  padding: 1rem 1rem 1rem 1.15rem;
  background: linear-gradient(120deg, var(--color-navy), var(--color-navy-light));
  color: #fff;
}

.chatbot-head .icon-badge { box-shadow: 0 0 0 2px #ffffff26; }

.chatbot-head-text { flex: 1; min-width: 0; }

.chatbot-title {
  margin: 0;
  color: #fff;
  font-family: var(--font-heading);
  font-size: 1rem;
  font-weight: 700;
  line-height: 1.25;
}

.chatbot-title:focus { outline: none; }

.chatbot-status {
  display: flex;
  align-items: center;
  gap: .45rem;
  margin: .2rem 0 0;
  color: #ffffffbf;
  font-size: .8rem;
  line-height: 1.3;
}

.chatbot-status::before {
  content: "";
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #4ade80;
  box-shadow: 0 0 0 3px #4ade8033;
  flex-shrink: 0;
}

.chatbot-head-btn {
  width: 38px;
  height: 38px;
  flex-shrink: 0;
  border: 0;
  border-radius: 50%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: #ffffff14;
  color: #fff;
  font-size: .95rem;
  cursor: pointer;
  transition: background .2s;
}

.chatbot-head-btn:hover { background: var(--color-primary); color: #fff; }

.chatbot-head-btn:focus-visible { outline-color: #fff; }

/* Conversation */

.chatbot-body {
  position: relative;
  flex: 1;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 1.25rem 1rem .75rem;
}

.chatbot-log {
  display: flex;
  flex-direction: column;
  gap: .45rem;
}

.chatbot-row {
  display: flex;
  align-items: flex-start;
  gap: .5rem;
  animation: chatbot-rise .2s ease-out;
}

.chatbot-row.no-anim { animation: none; }

.chatbot-row.is-turn:not(:first-child) { margin-top: .6rem; }

.chatbot-row.is-user { justify-content: flex-end; }

.chatbot-avatar,
.chatbot-avatar-spacer {
  width: 28px;
  min-width: 28px;
  height: 28px;
}

.chatbot-avatar {
  border-radius: 50%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, var(--color-primary), var(--color-navy-light));
  color: #fff;
  font-size: .72rem;
}

.chatbot-bubble {
  max-width: 85%;
  padding: .7rem .95rem;
  border-radius: var(--radius-md);
  font-size: .95rem;
  overflow-wrap: anywhere;
}

.chatbot-bubble p { margin: 0; }

.is-bot .chatbot-bubble {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  box-shadow: 0 1px 2px #16233a0d;
}

.is-bot.is-turn .chatbot-bubble { border-top-left-radius: 4px; }

.is-user .chatbot-bubble {
  background: var(--color-primary);
  color: #fff;
  border-bottom-right-radius: 4px;
}

.chatbot-bubble strong {
  color: var(--color-navy);
  font-family: var(--font-heading);
  font-weight: 700;
}

.chatbot-bubble a {
  color: var(--color-primary-dark);
  font-family: var(--font-heading);
  font-weight: 700;
  white-space: nowrap;
}

.chatbot-bubble a:hover { text-decoration: underline; }

.chatbot-links {
  display: flex;
  flex-direction: column;
  gap: .35rem;
  margin-top: .65rem;
  padding-top: .65rem;
  border-top: 1px solid var(--color-border);
}

.chatbot-bubble .chatbot-links a {
  font-size: .86rem;
  white-space: normal;
}

.chatbot-links a i {
  margin-left: .35em;
  font-size: .8em;
  transition: transform .15s;
}

.chatbot-links a:hover { text-decoration: none; }
.chatbot-links a:hover i { transform: translateX(3px); }

/* Cards (call, contact details, callback summary) */

.chatbot-card {
  width: 85%;
  padding: 1rem;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-sm);
}

.chatbot-card .btn { font-size: .95rem; padding: .75em 1.2em; }

.chatbot-call-top {
  display: flex;
  align-items: center;
  gap: .75rem;
  margin-bottom: .85rem;
}

.chatbot-call-label,
.chatbot-contact-line small {
  display: block;
  color: var(--color-text-muted);
  font-family: var(--font-heading);
  font-size: .7rem;
  font-weight: 600;
  letter-spacing: .05em;
  text-transform: uppercase;
  line-height: 1.3;
}

.chatbot-call-number {
  display: block;
  color: var(--color-navy);
  font-family: var(--font-heading);
  font-size: 1.2rem;
  font-weight: 800;
  line-height: 1.25;
}

.chatbot-contact { display: flex; flex-direction: column; gap: .15rem; padding: .5rem; }

.chatbot-contact-line {
  display: flex;
  align-items: center;
  gap: .75rem;
  padding: .5rem;
  border-radius: var(--radius-sm);
  color: var(--color-navy);
  font-family: var(--font-heading);
  font-size: .92rem;
  font-weight: 700;
  overflow-wrap: anywhere;
  transition: background .15s;
}

.chatbot-contact-line:hover { background: var(--color-bg); }

.chatbot-contact-icon {
  width: 34px;
  min-width: 34px;
  height: 34px;
  border-radius: 50%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, var(--color-primary), var(--color-navy-light));
  color: #fff;
  font-size: .8rem;
}

.chatbot-card-title {
  margin: 0 0 .7rem;
  color: var(--color-navy);
  font-family: var(--font-heading);
  font-size: 1rem;
  font-weight: 700;
}

.chatbot-summary dl {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: .35rem 1rem;
  margin: 0 0 1rem;
  font-size: .88rem;
}

.chatbot-summary dt {
  color: var(--color-navy);
  font-family: var(--font-heading);
  font-weight: 700;
}

.chatbot-summary dd {
  margin: 0;
  overflow-wrap: anywhere;
}

.chatbot-summary.is-muted { opacity: .6; }
.chatbot-summary.is-muted dl { margin-bottom: 0; }

.chatbot-privacy {
  display: flex;
  align-items: flex-start;
  gap: .45rem;
  margin: .7rem 0 0;
  color: var(--color-text-muted);
  font-size: .78rem;
  line-height: 1.45;
}

.chatbot-privacy i { margin-top: .2em; }

.chatbot-sent {
  display: flex;
  align-items: center;
  gap: .5rem;
  margin: 0;
  padding-top: .75rem;
  border-top: 1px solid var(--color-border);
  color: var(--color-primary-dark);
  font-family: var(--font-heading);
  font-size: .9rem;
  font-weight: 700;
}

/* Typing indicator */

.chatbot-typing {
  display: flex;
  align-items: flex-start;
  gap: .5rem;
  margin-top: .45rem;
}

.chatbot-typing.is-turn { margin-top: 1.05rem; }
.chatbot-log:empty + .chatbot-typing { margin-top: 0; }

.chatbot-typing-dots {
  display: inline-flex;
  gap: 4px;
  padding: .9rem 1rem;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
}

.chatbot-typing.is-turn .chatbot-typing-dots { border-top-left-radius: 4px; }

.chatbot-typing-dots span {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--color-primary-light);
  animation: chatbot-blink 1.2s infinite ease-in-out;
}

.chatbot-typing-dots span:nth-child(2) { animation-delay: .15s; }
.chatbot-typing-dots span:nth-child(3) { animation-delay: .3s; }

/* Quick replies */

.chatbot-chips {
  display: flex;
  flex-wrap: wrap;
  gap: .5rem;
  padding: .85rem 0 .25rem 36px;
  animation: chatbot-rise .2s ease-out;
}

.chatbot-chip {
  display: inline-flex;
  align-items: center;
  gap: .5em;
  padding: .6em 1em;
  border: 1.5px solid var(--color-primary);
  border-radius: var(--radius-sm);
  background: var(--color-surface);
  color: var(--color-primary-dark);
  font-family: var(--font-heading);
  font-size: .86rem;
  font-weight: 700;
  line-height: 1.25;
  text-align: left;
  cursor: pointer;
  transition: background-color .15s, color .15s, border-color .15s, transform .15s;
}

.chatbot-chip:hover {
  background: var(--color-primary);
  color: #fff;
  transform: translateY(-1px);
}

.chatbot-chip.is-call {
  background: var(--color-primary);
  color: #fff;
  box-shadow: var(--shadow-sm);
}

.chatbot-chip.is-call:hover { background: var(--color-primary-dark); border-color: var(--color-primary-dark); }

.chatbot-chip.is-quiet {
  border-color: var(--color-border);
  color: var(--color-text-muted);
}

.chatbot-chip.is-quiet:hover {
  background: var(--color-surface);
  border-color: var(--color-navy);
  color: var(--color-navy);
}

/* The main menu shows as a list of option cards, echoing the service cards */

.chatbot-chips.is-menu {
  flex-direction: column;
  flex-wrap: nowrap;
  gap: .45rem;
}

.chatbot-chips.is-menu .chatbot-chip {
  gap: .75rem;
  padding: .55rem .85rem .55rem .55rem;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  color: var(--color-navy);
  font-size: .9rem;
  box-shadow: var(--shadow-sm);
}

.chatbot-chips.is-menu .chatbot-chip:hover {
  background: var(--color-surface);
  border-color: var(--color-primary);
  color: var(--color-navy);
  transform: translateX(2px);
}

.chatbot-chips.is-menu .chatbot-chip-label { flex: 1; }

.chatbot-chip-icon {
  width: 32px;
  min-width: 32px;
  height: 32px;
  border-radius: 50%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, var(--color-primary), var(--color-navy-light));
  color: #fff;
  font-size: .8rem;
}

.chatbot-chip-arrow {
  color: var(--color-primary);
  font-size: .75rem;
}

/* Composer */

.chatbot-compose {
  display: flex;
  gap: .5rem;
  padding: .75rem .75rem .5rem;
  background: var(--color-surface);
  border-top: 1px solid var(--color-border);
}

.chatbot-compose input {
  flex: 1;
  min-width: 0;
  padding: .7em .9em;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  background: #fff;
  color: var(--color-text);
  font-family: var(--font-body);
  font-size: 1rem;
}

.chatbot-compose input:focus {
  outline: 2px solid var(--color-primary);
  outline-offset: 1px;
}

.chatbot-send {
  width: 46px;
  min-width: 46px;
  border: 0;
  border-radius: var(--radius-sm);
  background: var(--color-primary);
  color: #fff;
  font-size: .95rem;
  cursor: pointer;
  transition: background .15s;
}

.chatbot-send:hover { background: var(--color-primary-dark); }

.chatbot-foot {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: .75rem;
  margin: 0;
  padding: .15rem .9rem .6rem;
  background: var(--color-surface);
  color: var(--color-text-muted);
  font-size: .78rem;
}

.chatbot-foot a {
  color: var(--color-primary-dark);
  font-family: var(--font-heading);
  font-weight: 700;
}

.chatbot-restart {
  padding: .2rem .3rem;
  border: 0;
  background: none;
  color: var(--color-text-muted);
  font-size: .78rem;
  font-weight: 600;
  cursor: pointer;
}

.chatbot-restart:hover { color: var(--color-navy); }

/* ---------- Animation ---------- */

@keyframes chatbot-pop {
  from { opacity: 0; transform: translateY(12px) scale(.97); }
  to { opacity: 1; transform: none; }
}

@keyframes chatbot-rise {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: none; }
}

@keyframes chatbot-blink {
  0%, 80%, 100% { opacity: .35; transform: translateY(0); }
  40% { opacity: 1; transform: translateY(-3px); }
}

/* ---------- Phones: full-screen panel ---------- */

@media (max-width: 560px) {
  .chatbot-launcher {
    right: 16px;
    bottom: calc(16px + var(--chatbot-lift, 0px));
    width: 56px;
    height: 56px;
    font-size: 1.35rem;
  }

  .chatbot.is-open .chatbot-launcher,
  .chatbot-teaser { display: none; }

  .chatbot-panel {
    top: 0;
    right: 0;
    bottom: auto;
    left: 0;
    width: 100%;
    height: 100%;
    border-radius: 0;
    box-shadow: none;
    animation-name: chatbot-rise;
  }

  .chatbot-card { width: 100%; }
  .chatbot-bubble { max-width: 88%; }
}

html.chatbot-locked,
html.chatbot-locked body { overflow: hidden; }

@media (prefers-reduced-motion: reduce) {
  .chatbot-panel,
  .chatbot-row,
  .chatbot-chips,
  .chatbot-teaser { animation: none; }

  .chatbot-typing-dots span { animation: none; opacity: .6; }
}

@media print {
  .chatbot { display: none !important; }
}
