/*
 * tokens.css is linked separately in the page <head>, not @imported here.
 * An @import forces the browser to download this file before it can even
 * discover the token file, serialising two render-blocking requests — and it
 * would also miss the ?v= cache fingerprint the linked assets get.
 */

/* ==========================================================================
   HEADER
   ========================================================================== */

.site-header {
  position: sticky;
  top: 0;
  z-index: var(--z-header);
  height: var(--header-h);
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(12px) saturate(180%);
  border-bottom: 1px solid var(--border);
}

.site-header .container {
  display: flex;
  align-items: center;
  gap: var(--s-4);
  height: 100%;
}

.brand {
  display: flex;
  align-items: center;
  gap: var(--s-3);
  font-family: var(--font-heading);
  font-weight: 800;
  font-size: var(--t-lg);
  letter-spacing: -0.03em;
  color: var(--text);
  text-decoration: none;
  margin-right: auto;
}

.brand-mark {
  display: grid;
  place-items: center;
  width: 36px;
  height: 36px;
  border-radius: 10px;
  background: var(--primary);
  color: var(--text-on-primary);
  flex-shrink: 0;
}

.brand-mark svg {
  width: 20px;
  height: 20px;
}

.site-nav {
  display: none;
  align-items: center;
  gap: var(--s-1);
}

.site-nav a {
  padding: var(--s-2) var(--s-3);
  border-radius: var(--r-sm);
  font-size: var(--t-sm);
  font-weight: 500;
  color: var(--text-muted);
  text-decoration: none;
  transition: color var(--d-fast) var(--ease-out), background-color var(--d-fast) var(--ease-out);
}

.site-nav a:hover {
  color: var(--text);
  background: var(--surface-2);
}

.header-actions {
  display: flex;
  align-items: center;
  gap: var(--s-2);
}

/* The phone CTA is the one thing that must survive to the smallest screen. */
.header-phone {
  display: none;
}

@media (min-width: 640px) {
  .header-phone {
    display: inline-flex;
  }
}

@media (min-width: 900px) {
  .site-nav {
    display: flex;
  }
}

.theme-toggle {
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  border-radius: var(--r-md);
  color: var(--text-muted);
  transition: background-color var(--d-fast) var(--ease-out), color var(--d-fast) var(--ease-out);
}

.theme-toggle:hover {
  background: var(--surface-2);
  color: var(--text);
}

.theme-toggle svg {
  width: 20px;
  height: 20px;
}

/* Show the sun in dark mode and the moon in light mode — never both. */
.theme-toggle .icon-sun {
  display: none;
}

:root[data-theme='dark'] .theme-toggle .icon-sun {
  display: block;
}

:root[data-theme='dark'] .theme-toggle .icon-moon {
  display: none;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme='light']) .theme-toggle .icon-sun {
    display: block;
  }
  :root:not([data-theme='light']) .theme-toggle .icon-moon {
    display: none;
  }
}

/* ==========================================================================
   SECTIONS
   ========================================================================== */

.section {
  padding-block: var(--s-16);
}

@media (min-width: 768px) {
  .section {
    padding-block: var(--s-24);
  }
}

.section-alt {
  background: var(--surface);
  border-block: 1px solid var(--border);
}

.section-head {
  max-width: 44rem;
  margin-bottom: var(--s-12);
}

.section-head.center {
  margin-inline: auto;
  text-align: center;
}

.eyebrow {
  display: inline-block;
  margin-bottom: var(--s-3);
  padding: var(--s-1) var(--s-3);
  border-radius: var(--r-full);
  background: var(--primary-soft);
  color: var(--primary-soft-text);
  font-size: var(--t-xs);
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.section-head h2 {
  font-size: var(--t-3xl);
  margin-bottom: var(--s-4);
}

.section-head p {
  font-size: var(--t-lg);
  color: var(--text-muted);
  /* 60–75 characters is the readable measure. */
  max-width: 65ch;
}

/* ==========================================================================
   HERO
   ========================================================================== */

.hero {
  position: relative;
  padding-block: var(--s-16) var(--s-20);
  overflow: hidden;
}

@media (min-width: 768px) {
  .hero {
    padding-block: var(--s-24);
  }
}

/* Decorative wash. aria-hidden in the markup; purely atmospheric. */
.hero::before {
  content: '';
  position: absolute;
  inset: -40% 0 auto -20%;
  width: 80%;
  aspect-ratio: 1;
  background: radial-gradient(circle, color-mix(in srgb, var(--primary) 16%, transparent), transparent 65%);
  pointer-events: none;
  z-index: -1;
}

.hero-grid {
  display: grid;
  gap: var(--s-12);
  align-items: center;
}

@media (min-width: 1024px) {
  .hero-grid {
    grid-template-columns: 1.05fr 0.95fr;
    gap: var(--s-16);
  }
}

/*
 * The hero pill carries a full sentence, unlike the short header pill. The
 * shared `.status` rule sets white-space: nowrap, and because a grid item's
 * min-width defaults to auto, that sentence's min-content width would force the
 * whole hero track wider than a phone screen and get clipped. Let it wrap.
 */
.hero .status {
  white-space: normal;
  align-items: flex-start;
  text-align: left;
  max-width: 100%;
}

.hero .status .status-dot {
  /* Keep the dot on the first line's optical centre once the text wraps. */
  margin-top: 0.45em;
}

.hero h1 {
  font-size: var(--t-4xl);
  margin-block: var(--s-5) var(--s-5);
}

.hero-lede {
  font-size: var(--t-lg);
  color: var(--text-muted);
  max-width: 55ch;
  margin-bottom: var(--s-8);
}

.hero-cta {
  display: flex;
  flex-wrap: wrap;
  gap: var(--s-3);
  margin-bottom: var(--s-6);
}

.hero-assurance {
  display: flex;
  flex-wrap: wrap;
  gap: var(--s-2) var(--s-5);
  font-size: var(--t-sm);
  color: var(--text-muted);
}

.hero-assurance li {
  display: flex;
  align-items: center;
  gap: var(--s-2);
}

.hero-assurance svg {
  width: 16px;
  height: 16px;
  color: var(--online);
}

/* --- Chat preview card ---------------------------------------------------- */

.hero-preview {
  background: var(--surface-raised);
  border: 1px solid var(--border);
  border-radius: var(--r-xl);
  box-shadow: var(--shadow-lg);
  overflow: hidden;
}

.preview-head {
  display: flex;
  align-items: center;
  gap: var(--s-3);
  padding: var(--s-4) var(--s-5);
  background: var(--surface-2);
  border-bottom: 1px solid var(--border);
}

.preview-head .avatar {
  width: 36px;
  height: 36px;
}

.preview-head strong {
  display: block;
  font-size: var(--t-sm);
  font-family: var(--font-heading);
}

.preview-head span {
  font-size: var(--t-xs);
  color: var(--text-muted);
}

.preview-body {
  display: flex;
  flex-direction: column;
  gap: var(--s-3);
  padding: var(--s-5);
}

.preview-body .bubble {
  max-width: 82%;
  padding: var(--s-3) var(--s-4);
  border-radius: var(--r-lg);
  font-size: var(--t-sm);
  line-height: 1.55;
  /* Entrance is staggered in the markup via inline animation-delay. */
  animation: bubble-in var(--d-slow) var(--ease-out) backwards;
}

.preview-body .bubble.bot {
  align-self: flex-start;
  background: var(--bubble-bot);
  color: var(--bubble-bot-text);
  border-bottom-left-radius: var(--r-sm);
}

.preview-body .bubble.visitor {
  align-self: flex-end;
  background: var(--bubble-out);
  color: var(--bubble-out-text);
  border-bottom-right-radius: var(--r-sm);
}

.preview-body .bubble.agent {
  align-self: flex-start;
  background: var(--bubble-in);
  color: var(--bubble-in-text);
  border-bottom-left-radius: var(--r-sm);
}

.preview-handoff {
  display: flex;
  align-items: center;
  gap: var(--s-2);
  align-self: center;
  padding: var(--s-1) var(--s-3);
  border-radius: var(--r-full);
  background: var(--online-soft);
  color: var(--online);
  font-size: var(--t-xs);
  font-weight: 600;
  animation: bubble-in var(--d-slow) var(--ease-out) backwards;
}

.preview-handoff svg {
  width: 14px;
  height: 14px;
}

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

/* ==========================================================================
   STATS
   ========================================================================== */

.stats {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: var(--s-1);
  background: var(--border);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  overflow: hidden;
}

@media (min-width: 768px) {
  .stats {
    grid-template-columns: repeat(4, 1fr);
  }
}

.stat {
  padding: var(--s-6) var(--s-5);
  background: var(--surface-raised);
  text-align: center;
}

.stat dt {
  font-family: var(--font-heading);
  font-size: var(--t-2xl);
  font-weight: 800;
  color: var(--primary);
  /* Stops the number jittering as values change width. */
  font-variant-numeric: tabular-nums;
}

.stat dd {
  margin: var(--s-1) 0 0;
  font-size: var(--t-sm);
  color: var(--text-muted);
}

/* ==========================================================================
   SERVICES
   ========================================================================== */

.grid-cards {
  display: grid;
  gap: var(--s-5);
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 260px), 1fr));
}

.service {
  transition: transform var(--d-base) var(--ease-out), box-shadow var(--d-base) var(--ease-out),
    border-color var(--d-base) var(--ease-out);
}

.service:hover {
  transform: translateY(-3px);
  box-shadow: var(--shadow-md);
  border-color: var(--border-strong);
}

.service-icon {
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  margin-bottom: var(--s-4);
  border-radius: var(--r-md);
  background: var(--primary-soft);
  color: var(--primary-soft-text);
}

.service-icon svg {
  width: 22px;
  height: 22px;
}

.service h3 {
  font-size: var(--t-lg);
  margin-bottom: var(--s-2);
}

.service p {
  font-size: var(--t-sm);
  color: var(--text-muted);
}

/* ==========================================================================
   HOW IT WORKS
   ========================================================================== */

.steps {
  display: grid;
  gap: var(--s-6);
  counter-reset: step;
}

@media (min-width: 768px) {
  .steps {
    grid-template-columns: repeat(3, 1fr);
    gap: var(--s-8);
  }
}

.step {
  position: relative;
  padding-top: var(--s-12);
}

.step::before {
  counter-increment: step;
  content: counter(step);
  position: absolute;
  top: 0;
  left: 0;
  display: grid;
  place-items: center;
  width: 40px;
  height: 40px;
  border-radius: var(--r-full);
  background: var(--primary);
  color: var(--text-on-primary);
  font-family: var(--font-heading);
  font-weight: 800;
  font-size: var(--t-base);
}

/* Connector line between steps, desktop only. */
@media (min-width: 768px) {
  .step:not(:last-child)::after {
    content: '';
    position: absolute;
    top: 20px;
    left: 52px;
    right: calc(var(--s-8) * -1 + 12px);
    height: 2px;
    background: linear-gradient(to right, var(--border-strong), transparent);
  }
}

.step h3 {
  font-size: var(--t-lg);
  margin-bottom: var(--s-2);
}

.step p {
  color: var(--text-muted);
  font-size: var(--t-sm);
}

.step .step-note {
  display: inline-flex;
  align-items: center;
  gap: var(--s-2);
  margin-top: var(--s-3);
  padding: var(--s-1) var(--s-3);
  border-radius: var(--r-full);
  background: var(--surface-2);
  font-size: var(--t-xs);
  font-weight: 600;
  color: var(--text-muted);
}

/* ==========================================================================
   CONTACT + HOURS
   ========================================================================== */

.contact-grid {
  display: grid;
  gap: var(--s-6);
}

@media (min-width: 900px) {
  .contact-grid {
    grid-template-columns: 1fr 1fr;
    gap: var(--s-8);
  }
}

.contact-list {
  display: grid;
  gap: var(--s-4);
}

.contact-item {
  display: flex;
  gap: var(--s-4);
  align-items: flex-start;
  padding: var(--s-4);
  border-radius: var(--r-md);
  text-decoration: none;
  color: inherit;
  transition: background-color var(--d-fast) var(--ease-out);
}

a.contact-item:hover {
  background: var(--surface-2);
}

.contact-item .ico {
  display: grid;
  place-items: center;
  width: 40px;
  height: 40px;
  border-radius: var(--r-md);
  background: var(--primary-soft);
  color: var(--primary-soft-text);
  flex-shrink: 0;
}

.contact-item .ico svg {
  width: 20px;
  height: 20px;
}

.contact-item .label {
  display: block;
  font-size: var(--t-xs);
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-subtle);
}

.contact-item .value {
  display: block;
  font-weight: 600;
  color: var(--text);
  overflow-wrap: anywhere;
}

.hours-card ul {
  display: grid;
  gap: var(--s-1);
}

.hours-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: var(--s-4);
  padding: var(--s-2) var(--s-3);
  border-radius: var(--r-sm);
  font-size: var(--t-sm);
  /* Aligned columns need fixed-width digits. */
  font-variant-numeric: tabular-nums;
}

.hours-row[data-today='true'] {
  background: var(--primary-soft);
  color: var(--primary-soft-text);
  font-weight: 700;
}

.hours-row .day {
  color: inherit;
}

.hours-row[data-closed='true'] .time {
  color: var(--text-subtle);
}

.hours-today-tag {
  margin-left: var(--s-2);
  font-size: var(--t-xs);
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

/* ==========================================================================
   FAQ
   ========================================================================== */

.faq {
  max-width: 48rem;
  margin-inline: auto;
  display: grid;
  gap: var(--s-3);
}

.faq details {
  background: var(--surface-raised);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  overflow: hidden;
  transition: border-color var(--d-fast) var(--ease-out);
}

.faq details[open] {
  border-color: var(--border-strong);
}

.faq summary {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--s-4);
  /* 44px min height for the tap target. */
  min-height: 44px;
  padding: var(--s-4) var(--s-5);
  font-weight: 600;
  cursor: pointer;
  list-style: none;
  transition: background-color var(--d-fast) var(--ease-out);
}

.faq summary::-webkit-details-marker {
  display: none;
}

.faq summary:hover {
  background: var(--surface-2);
}

.faq summary .chev {
  width: 18px;
  height: 18px;
  flex-shrink: 0;
  color: var(--text-muted);
  transition: transform var(--d-base) var(--ease-out);
}

.faq details[open] summary .chev {
  transform: rotate(180deg);
}

.faq .answer {
  padding: 0 var(--s-5) var(--s-5);
  color: var(--text-muted);
  font-size: var(--t-sm);
}

/* ==========================================================================
   CTA BAND
   ========================================================================== */

.cta-band {
  background: var(--primary);
  color: var(--text-on-primary);
  border-radius: var(--r-xl);
  padding: var(--s-12) var(--s-8);
  text-align: center;
}

.cta-band h2 {
  font-size: var(--t-3xl);
  margin-bottom: var(--s-3);
}

.cta-band p {
  max-width: 50ch;
  margin: 0 auto var(--s-8);
  opacity: 0.92;
}

.cta-band .btn-primary {
  background: var(--bg);
  color: var(--primary);
}

.cta-band .btn-primary:hover {
  background: var(--surface-2);
}

.cta-band .btn-secondary {
  background: transparent;
  color: var(--text-on-primary);
  border-color: color-mix(in srgb, var(--text-on-primary) 45%, transparent);
}

.cta-band .btn-secondary:hover {
  background: color-mix(in srgb, var(--text-on-primary) 12%, transparent);
  border-color: var(--text-on-primary);
}

.cta-actions {
  display: flex;
  flex-wrap: wrap;
  gap: var(--s-3);
  justify-content: center;
}

/* ==========================================================================
   FOOTER
   ========================================================================== */

.site-footer {
  background: var(--surface);
  border-top: 1px solid var(--border);
  padding-block: var(--s-12) var(--s-8);
  font-size: var(--t-sm);
}

.footer-grid {
  display: grid;
  gap: var(--s-8);
  margin-bottom: var(--s-8);
}

@media (min-width: 768px) {
  .footer-grid {
    grid-template-columns: 2fr 1fr 1fr;
  }
}

.footer-grid h3 {
  font-size: var(--t-sm);
  margin-bottom: var(--s-3);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-subtle);
}

.footer-grid a {
  color: var(--text-muted);
  text-decoration: none;
}

.footer-grid a:hover {
  color: var(--primary);
  text-decoration: underline;
}

.footer-grid li + li {
  margin-top: var(--s-2);
}

.footer-about p {
  color: var(--text-muted);
  max-width: 42ch;
  margin-top: var(--s-3);
}

.footer-bottom {
  padding-top: var(--s-6);
  border-top: 1px solid var(--border);
  display: flex;
  flex-wrap: wrap;
  gap: var(--s-3) var(--s-6);
  justify-content: space-between;
  color: var(--text-subtle);
  font-size: var(--t-xs);
}

.footer-disclaimer {
  max-width: 70ch;
  margin-top: var(--s-3);
  color: var(--text-subtle);
  font-size: var(--t-xs);
  line-height: 1.6;
}

/* ==========================================================================
   AVATAR — shared by widget, preview and console
   ========================================================================== */

.avatar {
  display: grid;
  place-items: center;
  width: 40px;
  height: 40px;
  border-radius: var(--r-full);
  background: var(--primary);
  color: var(--text-on-primary);
  font-family: var(--font-heading);
  font-weight: 700;
  font-size: var(--t-sm);
  flex-shrink: 0;
  /* Initials must never wrap or shrink the circle. */
  line-height: 1;
  text-transform: uppercase;
}

.avatar[data-kind='agent'] {
  background: var(--online);
  color: #fff;
}

.avatar[data-kind='visitor'] {
  background: var(--surface-2);
  color: var(--text-muted);
}

/* ==========================================================================
   CHAT WIDGET
   ========================================================================== */

.chat-launcher {
  position: fixed;
  right: max(var(--s-5), env(safe-area-inset-right));
  bottom: max(var(--s-5), env(safe-area-inset-bottom));
  z-index: var(--z-widget);

  display: inline-flex;
  align-items: center;
  gap: var(--s-3);
  min-height: 56px;
  padding: var(--s-3) var(--s-5) var(--s-3) var(--s-4);
  border-radius: var(--r-full);
  background: var(--primary);
  color: var(--text-on-primary);
  font-weight: 600;
  font-size: var(--t-sm);
  box-shadow: var(--shadow-widget);
  transition: transform var(--d-base) var(--ease-spring), box-shadow var(--d-base) var(--ease-out),
    opacity var(--d-base) var(--ease-out);
  touch-action: manipulation;
}

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

.chat-launcher:active {
  transform: scale(0.96);
}

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

.chat-launcher[data-open='true'] {
  opacity: 0;
  pointer-events: none;
  transform: scale(0.85);
}

/* Presence dot on the launcher, so status is readable before opening. */
.launcher-dot {
  position: absolute;
  top: 2px;
  right: 2px;
  width: 14px;
  height: 14px;
  border-radius: var(--r-full);
  border: 2px solid var(--primary);
  background: var(--offline);
}

.chat-launcher[data-state='online'] .launcher-dot {
  background: #34d399;
}

.chat-launcher[data-state='busy'] .launcher-dot {
  background: #fbbf24;
}

/* Unread badge when an agent replies while the panel is closed. */
.launcher-badge {
  position: absolute;
  top: -4px;
  left: -4px;
  min-width: 22px;
  height: 22px;
  padding-inline: 6px;
  display: grid;
  place-items: center;
  border-radius: var(--r-full);
  background: var(--danger);
  color: #fff;
  font-size: var(--t-xs);
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.chat-launcher .launcher-badge[hidden] {
  display: none;
}

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

.chat-panel {
  position: fixed;
  z-index: var(--z-widget-panel);
  display: flex;
  flex-direction: column;
  background: var(--bg);
  box-shadow: var(--shadow-widget);
  overflow: hidden;

  /* Mobile default: a full-height sheet. */
  inset: 0;
  border-radius: 0;

  transform-origin: bottom right;
  animation: panel-in var(--d-slow) var(--ease-spring);
}

.chat-panel[hidden] {
  display: none;
}

.chat-panel.closing {
  /* Exit is deliberately faster than entry — it feels more responsive. */
  animation: panel-out var(--d-base) var(--ease-in) forwards;
}

@media (min-width: 640px) {
  .chat-panel[data-mode='docked'] {
    inset: auto;
    right: max(var(--s-5), env(safe-area-inset-right));
    bottom: max(var(--s-5), env(safe-area-inset-bottom));
    width: 400px;
    /* Never taller than the viewport, never so short it feels cramped. */
    height: min(640px, calc(100dvh - var(--s-16)));
    border: 1px solid var(--border);
    border-radius: var(--r-xl);
  }
}

/* ==========================================================================
   FULL-SCREEN CHAT MODE
   Opened by the "Start a live chat" CTAs, and by the expand button in the
   panel header. The surface fills the viewport, but the conversation column
   is capped — chat lines running the full width of a 1920px monitor are
   unreadable, so the background goes full-bleed while the content stays in a
   comfortable measure.
   ========================================================================== */

.chat-panel[data-mode='full'] {
  --chat-measure: 820px;

  inset: 0;
  width: 100%;
  height: 100dvh;
  max-height: none;
  border: 0;
  border-radius: 0;
  transform-origin: center;
  animation: panel-full-in var(--d-slow) var(--ease-out);
}

@keyframes panel-full-in {
  from {
    opacity: 0;
    transform: scale(0.985);
  }
  to {
    opacity: 1;
    transform: none;
  }
}

/*
 * One rule centres every row: the background still spans edge to edge, while
 * the inner content is held to --chat-measure. Avoids adding wrapper elements
 * purely for layout.
 */
.chat-panel[data-mode='full'] .chat-head,
.chat-panel[data-mode='full'] .chat-notice,
.chat-panel[data-mode='full'] .chat-body,
.chat-panel[data-mode='full'] .chat-chips,
.chat-panel[data-mode='full'] .chat-composer,
.chat-panel[data-mode='full'] .chat-fallback,
.chat-panel[data-mode='full'] .chat-footnote {
  padding-inline: max(var(--s-5), calc((100% - var(--chat-measure)) / 2));
}

.chat-panel[data-mode='full'] .chat-error {
  margin-inline: max(var(--s-5), calc((100% - var(--chat-measure)) / 2));
}

@media (min-width: 640px) {
  .chat-panel[data-mode='full'] .chat-head {
    padding-block: var(--s-4);
  }

  .chat-panel[data-mode='full'] .chat-body {
    padding-block: var(--s-8);
    gap: var(--s-4);
  }

  /* More room to breathe than the narrow docked panel allows. */
  .chat-panel[data-mode='full'] .msg {
    max-width: min(72%, 32rem);
  }

  .chat-panel[data-mode='full'] .msg-bubble {
    font-size: var(--t-base);
    padding: var(--s-4) var(--s-5);
  }

  .chat-panel[data-mode='full'] .chat-composer {
    padding-block: var(--s-4);
  }

  .chat-panel[data-mode='full'] .chat-composer textarea {
    max-height: 180px;
  }

  .chat-panel[data-mode='full'] .chat-head .avatar {
    width: 44px;
    height: 44px;
  }

  .chat-panel[data-mode='full'] .chat-head-text strong {
    font-size: var(--t-lg);
  }
}

/* The expand control is meaningless on a phone, where the panel is already
   full screen. Hide it rather than offering a no-op.
   Scoped to .chat-head-actions to outrank that block's `button { display: grid }`,
   which is defined later in this file. */
@media (max-width: 639px) {
  .chat-head-actions [data-chat-expand] {
    display: none;
  }
}

@keyframes panel-in {
  from {
    opacity: 0;
    transform: translateY(16px) scale(0.96);
  }
  to {
    opacity: 1;
    transform: none;
  }
}

@keyframes panel-out {
  to {
    opacity: 0;
    transform: translateY(12px) scale(0.97);
  }
}

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

.chat-head {
  display: flex;
  align-items: center;
  gap: var(--s-3);
  padding: var(--s-4);
  padding-top: max(var(--s-4), env(safe-area-inset-top));
  background: var(--primary);
  color: var(--text-on-primary);
  flex-shrink: 0;
}

.chat-head .avatar {
  background: color-mix(in srgb, var(--text-on-primary) 20%, transparent);
  color: var(--text-on-primary);
}

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

.chat-head-text strong {
  display: block;
  font-family: var(--font-heading);
  font-size: var(--t-base);
  line-height: 1.3;
  /* Long agent names truncate rather than push the buttons off-screen. */
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.chat-head-status {
  display: flex;
  align-items: center;
  gap: var(--s-2);
  font-size: var(--t-xs);
  opacity: 0.9;
}

.chat-head-status .status-dot {
  background: currentColor;
}

.chat-head-actions {
  display: flex;
  gap: var(--s-1);
}

.chat-head-actions button {
  display: grid;
  place-items: center;
  width: 40px;
  height: 40px;
  border-radius: var(--r-md);
  color: var(--text-on-primary);
  opacity: 0.85;
  transition: background-color var(--d-fast) var(--ease-out), opacity var(--d-fast) var(--ease-out);
}

.chat-head-actions button:hover {
  background: color-mix(in srgb, var(--text-on-primary) 16%, transparent);
  opacity: 1;
}

.chat-head-actions svg {
  width: 20px;
  height: 20px;
}

/* --- Notice strip (busy / offline) ---------------------------------------- */

.chat-notice {
  display: flex;
  align-items: flex-start;
  gap: var(--s-3);
  padding: var(--s-3) var(--s-4);
  font-size: var(--t-xs);
  line-height: 1.5;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.chat-notice[hidden] {
  display: none;
}

.chat-notice svg {
  width: 16px;
  height: 16px;
  margin-top: 2px;
}

.chat-notice[data-state='busy'] {
  background: var(--busy-soft);
  color: var(--busy);
}

.chat-notice[data-state='offline'] {
  background: var(--offline-soft);
  color: var(--text-muted);
}

/* --- Message list --------------------------------------------------------- */

.chat-body {
  flex: 1;
  overflow-y: auto;
  overscroll-behavior: contain; /* stops the page scrolling behind the sheet */
  -webkit-overflow-scrolling: touch;
  padding: var(--s-5) var(--s-4);
  display: flex;
  flex-direction: column;
  gap: var(--s-3);
  background: var(--surface);
}

.msg {
  display: flex;
  flex-direction: column;
  max-width: 85%;
  animation: bubble-in var(--d-base) var(--ease-out);
}

.msg-bubble {
  padding: var(--s-3) var(--s-4);
  border-radius: var(--r-lg);
  font-size: var(--t-sm);
  line-height: 1.55;
  /* Long URLs must wrap instead of stretching the panel. */
  overflow-wrap: anywhere;
  white-space: pre-wrap;
}

.msg-meta {
  margin-top: var(--s-1);
  padding-inline: var(--s-1);
  font-size: 0.6875rem;
  color: var(--text-subtle);
  font-variant-numeric: tabular-nums;
}

.msg[data-sender='visitor'] {
  align-self: flex-end;
  align-items: flex-end;
}

.msg[data-sender='visitor'] .msg-bubble {
  background: var(--bubble-out);
  color: var(--bubble-out-text);
  border-bottom-right-radius: var(--r-sm);
}

.msg[data-sender='bot'] {
  align-self: flex-start;
}

.msg[data-sender='bot'] .msg-bubble {
  background: var(--bubble-bot);
  color: var(--bubble-bot-text);
  border-bottom-left-radius: var(--r-sm);
}

.msg[data-sender='agent'] {
  align-self: flex-start;
}

.msg[data-sender='agent'] .msg-bubble {
  background: var(--bubble-in);
  color: var(--bubble-in-text);
  border-bottom-left-radius: var(--r-sm);
  border: 1px solid var(--border);
}

/* System lines are centred and quiet — they are events, not speech. */
.msg[data-sender='system'] {
  align-self: center;
  max-width: 90%;
  align-items: center;
}

.msg[data-sender='system'] .msg-bubble {
  background: transparent;
  color: var(--text-subtle);
  font-size: var(--t-xs);
  text-align: center;
  padding: var(--s-1) var(--s-3);
}

.msg[data-sender='system'] .msg-meta {
  display: none;
}

/* --- Typing indicator ----------------------------------------------------- */

.typing {
  align-self: flex-start;
  display: flex;
  gap: 4px;
  padding: var(--s-4);
  background: var(--bubble-bot);
  border-radius: var(--r-lg);
  border-bottom-left-radius: var(--r-sm);
  width: fit-content;
}

.typing[hidden] {
  display: none;
}

.typing span {
  width: 7px;
  height: 7px;
  border-radius: var(--r-full);
  background: currentColor;
  color: var(--bubble-bot-text);
  opacity: 0.5;
  animation: typing-bounce 1.3s var(--ease-out) infinite;
}

.typing span:nth-child(2) {
  animation-delay: 0.15s;
}

.typing span:nth-child(3) {
  animation-delay: 0.3s;
}

@keyframes typing-bounce {
  0%,
  60%,
  100% {
    transform: translateY(0);
    opacity: 0.4;
  }
  30% {
    transform: translateY(-4px);
    opacity: 1;
  }
}

/* --- Quick reply chips ---------------------------------------------------- */

.chat-chips {
  display: flex;
  flex-wrap: wrap;
  gap: var(--s-2);
  padding: 0 var(--s-4) var(--s-3);
  background: var(--surface);
  flex-shrink: 0;
}

.chat-chips[hidden] {
  display: none;
}

.chip {
  min-height: 40px;
  padding: var(--s-2) var(--s-4);
  border-radius: var(--r-full);
  border: 1px solid var(--primary);
  background: var(--bg);
  color: var(--primary);
  font-size: var(--t-sm);
  font-weight: 600;
  transition: background-color var(--d-fast) var(--ease-out), transform var(--d-fast) var(--ease-out);
  touch-action: manipulation;
}

.chip:hover {
  background: var(--primary-soft);
}

.chip:active {
  transform: scale(0.96);
}

/* --- Composer ------------------------------------------------------------- */

.chat-composer {
  display: flex;
  align-items: flex-end;
  gap: var(--s-2);
  padding: var(--s-3) var(--s-4);
  padding-bottom: max(var(--s-3), env(safe-area-inset-bottom));
  background: var(--bg);
  border-top: 1px solid var(--border);
  flex-shrink: 0;
}

.chat-composer textarea {
  flex: 1;
  resize: none;
  max-height: 120px;
  min-height: 44px;
  padding: var(--s-3) var(--s-4);
  /* 16px prevents iOS from zooming the viewport on focus. */
  font-size: var(--t-base);
  line-height: 1.4;
  background: var(--surface-2);
  color: var(--text);
  border: 1px solid transparent;
  border-radius: var(--r-lg);
  transition: border-color var(--d-fast) var(--ease-out), background-color var(--d-fast) var(--ease-out);
}

.chat-composer textarea::placeholder {
  color: var(--text-subtle);
}

.chat-composer textarea:focus {
  outline: none;
  background: var(--bg);
  border-color: var(--primary);
}

.chat-send {
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  border-radius: var(--r-lg);
  background: var(--primary);
  color: var(--text-on-primary);
  flex-shrink: 0;
  transition: background-color var(--d-fast) var(--ease-out), transform var(--d-fast) var(--ease-out),
    opacity var(--d-fast) var(--ease-out);
}

.chat-send:hover:not(:disabled) {
  background: var(--primary-hover);
}

.chat-send:active:not(:disabled) {
  transform: scale(0.92);
}

.chat-send:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.chat-send svg {
  width: 20px;
  height: 20px;
}

.chat-footnote {
  padding: 0 var(--s-4) var(--s-3);
  background: var(--bg);
  font-size: 0.6875rem;
  color: var(--text-subtle);
  text-align: center;
  flex-shrink: 0;
}

.chat-footnote a {
  color: var(--text-muted);
}

/* --- Offline fallback actions --------------------------------------------- */

.chat-fallback {
  display: grid;
  gap: var(--s-2);
  padding: var(--s-3) var(--s-4);
  background: var(--surface-2);
  border-top: 1px solid var(--border);
  flex-shrink: 0;
}

.chat-fallback[hidden] {
  display: none;
}

.chat-fallback .btn {
  width: 100%;
}

/* --- Error toast inside the panel ----------------------------------------- */

.chat-error {
  margin: 0 var(--s-4) var(--s-2);
  padding: var(--s-2) var(--s-3);
  border-radius: var(--r-sm);
  background: var(--danger-soft);
  color: var(--danger);
  font-size: var(--t-xs);
  font-weight: 500;
}

.chat-error[hidden] {
  display: none;
}
