/* First-party ATP chat. Brand tokens come from brand.css. */
.atp-chat {
  position: fixed;
  z-index: 80;
  right: max(16px, env(safe-area-inset-right, 0px));
  bottom: max(16px, env(safe-area-inset-bottom, 0px));
  display: flex;
  width: min(384px, calc(100vw - 32px - env(safe-area-inset-left, 0px) - env(safe-area-inset-right, 0px)));
  flex-direction: column;
  align-items: flex-end;
  gap: 12px;
  pointer-events: none;
}
.atp-chat-panel,
.atp-chat-launcher { pointer-events: auto; }

.atp-chat-launcher {
  display: inline-flex;
  min-height: 52px;
  align-items: center;
  gap: 10px;
  padding: 8px 16px 8px 8px;
  border: 1px solid rgba(176, 138, 62, .55);
  border-radius: 999px;
  color: var(--paper);
  background: var(--navy-950);
  box-shadow: 0 16px 36px rgba(7, 20, 30, .28);
  cursor: pointer;
  font-weight: 700;
  letter-spacing: .01em;
}
.atp-chat-launcher-mark {
  display: grid;
  width: 36px;
  height: 36px;
  place-items: center;
  border-radius: 50%;
  background: var(--brass);
  color: var(--navy-950);
}
.atp-chat-launcher-mark svg { width: 18px; height: 18px; }
.atp-chat-launcher:hover { background: var(--navy-800); }
.atp-chat-launcher[aria-expanded="true"] {
  background: var(--navy-800);
  border-color: var(--brass);
}

.atp-chat-panel {
  display: flex;
  width: 100%;
  max-height: min(680px, calc(100dvh - 108px - env(safe-area-inset-top, 0px) - env(safe-area-inset-bottom, 0px)));
  flex-direction: column;
  overflow: hidden;
  border: 1px solid rgba(176, 138, 62, .45);
  border-radius: 18px;
  background: var(--cream);
  box-shadow: var(--shadow-lg);
  color: var(--ink);
}
.atp-chat-panel[hidden] { display: none !important; }

.atp-chat-head {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 10px 10px 12px;
  color: var(--paper);
  background:
    linear-gradient(180deg, rgba(176, 138, 62, .18), transparent 42%),
    var(--navy-950);
}
.atp-chat-mark {
  width: 54px;
  height: 32px;
  flex: none;
  padding: 4px 6px;
  border-radius: 6px;
  background: var(--cream);
  object-fit: contain;
}
.atp-chat-head-copy { min-width: 0; }
.atp-chat-kicker {
  margin: 0;
  color: var(--brass-soft);
  font-size: .68rem;
  font-weight: 700;
  letter-spacing: .14em;
  text-transform: uppercase;
}
.atp-chat-head h2 {
  margin: 2px 0 0;
  color: var(--paper);
  font-family: var(--font-serif);
  font-size: 1.25rem;
  font-weight: 500;
  line-height: 1.15;
}
.atp-chat-role {
  margin: 2px 0 0;
  color: var(--brass-soft);
  font-size: .78rem;
  font-weight: 600;
  letter-spacing: .01em;
}
.atp-chat-role[hidden] { display: none !important; }
.atp-chat-close {
  display: grid;
  width: 42px;
  height: 42px;
  flex: none;
  margin-left: auto;
  place-items: center;
  border: 1px solid rgba(243, 238, 228, .24);
  border-radius: 10px;
  color: var(--paper);
  background: transparent;
  cursor: pointer;
}
.atp-chat-close svg { width: 18px; height: 18px; }
.atp-chat-close:hover { border-color: var(--brass); }

.atp-chat-hours {
  margin: 0;
  padding: 8px 12px;
  border-bottom: 1px solid var(--line);
  color: var(--navy-900);
  background: var(--brass-soft);
  font-size: .84rem;
  line-height: 1.45;
}
.atp-chat-hours[data-quiet="true"] { background: #f3e6c8; }

.atp-chat-scroll {
  min-height: 0;
  flex: 1;
  overflow-y: auto;
}
.atp-chat-thread {
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 10px 12px;
  background:
    linear-gradient(180deg, rgba(176, 138, 62, .08), transparent 28px),
    var(--paper);
}
.atp-chat-bubble {
  max-width: 92%;
  margin: 0;
  padding: 10px 12px;
  border-radius: 14px;
  font-size: .94rem;
  line-height: 1.45;
}
.atp-chat-bubble-atp {
  align-self: flex-start;
  border: 1px solid var(--line);
  border-left: 3px solid var(--brass);
  background: var(--white);
  color: var(--ink);
}
.atp-chat-bubble a { color: var(--navy-800); font-weight: 700; text-decoration: underline; }
.atp-chat-bubble-user {
  align-self: flex-end;
  background: var(--navy-900);
  color: var(--paper);
}
.atp-chat-bubble { white-space: pre-wrap; }
.atp-chat-who {
  display: block;
  margin-bottom: 2px;
  font-size: .68rem;
  font-weight: 700;
  letter-spacing: .08em;
  text-transform: uppercase;
  opacity: .72;
}
.atp-chat-bubble strong { font-weight: 700; }
.atp-chat-ref {
  display: block;
  margin-top: 6px;
  color: var(--muted);
  font-size: .78rem;
}

.atp-chat-form {
  position: relative;
  display: grid;
  gap: 8px;
  padding: 10px 12px 12px;
  border-top: 1px solid var(--line);
  background: var(--cream);
}
.atp-chat-form .honeypot {
  position: absolute;
  left: 0;
  top: 0;
  width: 1px;
  height: 1px;
  margin: 0;
  padding: 0;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
  border: 0;
  opacity: 0;
  pointer-events: none;
}
.atp-chat-form .honeypot input {
  min-height: 0;
  height: 1px;
  padding: 0;
  border: 0;
}
.atp-chat-row { display: grid; gap: 8px; }
.atp-chat-label {
  display: grid;
  gap: 4px;
  color: var(--navy-800);
  font-size: .78rem;
  font-weight: 700;
}
.atp-chat-optional { color: var(--muted); font-weight: 600; }
.atp-chat-grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.atp-chat-form input:not([type="checkbox"]):not([type="radio"]),
.atp-chat-form textarea {
  width: 100%;
  min-height: 42px;
  padding: 8px 10px;
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  color: var(--ink);
  background: var(--white);
  outline: none;
}
.atp-chat-form textarea {
  min-height: 60px;
  resize: vertical;
}
.atp-chat-form input:focus,
.atp-chat-form textarea:focus {
  border-color: var(--brass);
  box-shadow: 0 0 0 3px var(--brass-glow);
}
.atp-chat-starters {
  display: grid;
  gap: 8px;
  margin: 0;
  padding: 0;
  border: 0;
}
.atp-chat-starters[hidden] { display: none !important; }
.atp-chat-starters legend {
  margin: 0 0 2px;
  color: var(--navy-800);
  font-size: .78rem;
  font-weight: 700;
}
.atp-chat-starter { position: relative; display: block; }
.atp-chat-starter input {
  position: absolute;
  inset: 0;
  margin: 0;
  opacity: 0;
  cursor: pointer;
}
.atp-chat-starter span {
  display: grid;
  gap: 1px;
  min-height: 44px;
  padding: 8px 12px;
  border: 1px solid var(--line-strong);
  border-radius: 10px;
  background: var(--white);
}
.atp-chat-starter strong {
  color: var(--navy-950);
  font-size: .92rem;
  line-height: 1.25;
}
.atp-chat-starter small {
  color: var(--muted);
  font-size: .76rem;
  font-weight: 600;
  line-height: 1.3;
}
.atp-chat-starter input:checked + span {
  border-color: var(--brass-deep);
  background: var(--brass-soft);
  box-shadow: inset 3px 0 0 var(--brass-deep);
}
.atp-chat-starter input:checked + span strong { color: var(--navy-950); }
.atp-chat-starter:hover span { border-color: var(--brass); }
.atp-chat-starter:has(input:focus-visible) span {
  outline: 2px solid var(--brass);
  outline-offset: 2px;
}
.atp-chat-details { display: grid; gap: 8px; }
.atp-chat-composer { display: grid; gap: 8px; }
.atp-chat-compose-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 8px;
  align-items: end;
}
.atp-chat-compose-row textarea { min-height: 52px; }
.atp-chat-compose-row .atp-chat-send { min-height: 52px; padding: 0 14px; }
.atp-chat-change {
  justify-self: start;
  margin: 0;
  padding: 0;
  border: 0;
  background: none;
  color: var(--navy-800);
  cursor: pointer;
  font-size: .78rem;
  font-weight: 700;
  text-decoration: underline;
}
.atp-chat-contact-note {
  margin: 0;
  color: var(--ink-soft);
  font-size: .82rem;
  font-weight: 600;
  line-height: 1.4;
}
.atp-chat-form[hidden],
.atp-chat-details[hidden],
.atp-chat-bubble[hidden],
.atp-chat-composer[hidden],
.atp-chat-change[hidden] { display: none !important; }
.atp-chat-consent {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  color: var(--ink-soft);
  font-size: .82rem;
  font-weight: 600;
  line-height: 1.4;
}
.atp-chat-consent input { width: 18px; height: 18px; margin-top: 2px; accent-color: var(--brass-deep); flex: none; }
.atp-chat-send {
  display: inline-flex;
  min-height: 46px;
  align-items: center;
  justify-content: center;
  gap: 8px;
  border: 0;
  border-radius: 8px;
  color: var(--navy-950);
  background: var(--brass);
  cursor: pointer;
  font-weight: 700;
}
.atp-chat-send:hover { background: #c49a49; }
.atp-chat-send:disabled { cursor: wait; opacity: .7; }
.atp-chat-status {
  margin: 0;
  color: var(--navy-800);
  font-size: .84rem;
}
.atp-chat-status:empty { display: none; }
.atp-chat-status.error { color: var(--red); }
.atp-chat-status a { color: var(--navy-900); text-decoration: underline; }
.atp-chat-mail { display: none; }

.atp-chat:has(#atpChatPanel:not([hidden])) .atp-chat-launcher { display: none; }
.atp-chat:has(#atpChatPanel:not([hidden])) {
  bottom: max(12px, env(safe-area-inset-bottom, 0px));
}
.atp-chat:has(#atpChatPanel:not([hidden])) .atp-chat-panel {
  max-height: calc(100dvh - 28px - env(safe-area-inset-top, 0px) - env(safe-area-inset-bottom, 0px));
}
.atp-chat-panel > .atp-chat-form {
  max-height: min(460px, 62%);
  overflow-y: auto;
}

@media (max-width: 860px) {
  body:has(.calc-trigger-mobile) .atp-chat {
    bottom: calc(78px + env(safe-area-inset-bottom, 0px));
  }
  body:has(.calc-trigger-mobile) .atp-chat-panel {
    max-height: min(640px, calc(100dvh - 176px - env(safe-area-inset-bottom, 0px)));
  }
  body:has(.atp-chat) .footer { padding-bottom: 108px; }
}
@media (max-width: 860px) {
  body:has(.calc-trigger-mobile):has(.atp-chat) .footer { padding-bottom: 168px; }
  .atp-chat-panel { max-height: calc(100dvh - 92px - env(safe-area-inset-bottom, 0px)); }
  .atp-chat:has(#atpChatPanel:not([hidden])) .atp-chat-launcher { display: none; }
  .atp-chat:has(#atpChatPanel:not([hidden])) { bottom: max(12px, env(safe-area-inset-bottom, 0px)); }
  body:has(.calc-trigger-mobile) .atp-chat:has(#atpChatPanel:not([hidden])) {
    bottom: calc(72px + env(safe-area-inset-bottom, 0px));
  }
  body:has(.calc-trigger-mobile) .atp-chat:has(#atpChatPanel:not([hidden])) .atp-chat-panel {
    max-height: calc(100dvh - 148px - env(safe-area-inset-bottom, 0px));
  }
  .atp-chat-form textarea { min-height: 56px; }
  .atp-chat-compose-row { grid-template-columns: 1fr; }
  .atp-chat-compose-row .atp-chat-send { width: 100%; }
}

body.menu-open .atp-chat { display: none; }

@media (prefers-reduced-motion: reduce) {
  .atp-chat-panel,
  .atp-chat-launcher { transition: none; }
}
@media print {
  .atp-chat { display: none !important; }
}
@media (forced-colors: active) {
  .atp-chat-launcher,
  .atp-chat-panel,
  .atp-chat-close,
  .atp-chat-send { border: 1px solid ButtonText; }
}
