/* Chat assistant: the button bottom-right and its panel (public/chat.js). Uses the colours in styles.css. */
.chat-fab { position: fixed; right: 18px; bottom: 18px; z-index: 60; height: 52px; padding: 0 20px 0 16px; border: 0; border-radius: 26px; background: var(--green-dark); color: #fff; display: flex; align-items: center; gap: 9px; font: inherit; font-size: 16px; font-weight: 600; box-shadow: 0 4px 14px rgba(0,0,0,.2); cursor: pointer; }
.chat-fab:hover { background: var(--green-deep); }
.chat-fab:focus-visible { outline: 3px solid var(--sun); outline-offset: 2px; }
.chat-fab svg { width: 24px; height: 24px; flex: none; }
.chat-fab svg:nth-of-type(2) { display: none; }
.chat-fab[aria-expanded="true"] { width: 52px; padding: 0; justify-content: center; }
.chat-fab[aria-expanded="true"] span, .chat-fab[aria-expanded="true"] svg:nth-of-type(1) { display: none; }
.chat-fab[aria-expanded="true"] svg:nth-of-type(2) { display: block; }
.chat-fab[hidden], .chat-panel[hidden] { display: none; }

.chat-panel { position: fixed; right: 18px; bottom: 82px; z-index: 90; width: 400px; max-width: calc(100vw - 24px); height: 620px; max-height: calc(100vh - 100px); max-height: calc(100dvh - 100px); background: #fff; color: var(--ink); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: 0 10px 34px rgba(0,0,0,.2); display: flex; flex-direction: column; overflow: hidden; font-size: 15px; line-height: 1.5; animation: chat-open .16s ease-out; }
.chat-panel:focus { outline: none; }
@keyframes chat-open { from { opacity: 0; transform: translateY(8px); } }

.chat-avatar { flex: none; width: 28px; height: 28px; border-radius: 50%; background: #fff; overflow: hidden; display: block; }
.chat-avatar img { display: block; width: 100%; height: 100%; }

.chat-head { display: flex; align-items: center; gap: 6px; padding: 10px 10px 10px 14px; background: var(--green-deep); color: #fff; }
.chat-head .chat-avatar { width: 38px; height: 38px; margin-right: 6px; }
.chat-head h2 { flex: 1; min-width: 0; margin: 0; font-size: 17px; line-height: 1.25; font-weight: 600; color: #fff; }
.chat-head h2 span { display: block; font-size: 13px; font-weight: 400; color: rgba(255,255,255,.82); }
.chat-head a, .chat-head button { flex: none; width: 38px; height: 38px; display: grid; place-items: center; border-radius: 50%; color: #fff; background: rgba(255,255,255,.12); border: 0; cursor: pointer; }
.chat-head a:hover, .chat-head button:hover { background: rgba(255,255,255,.24); }
.chat-head a:focus-visible, .chat-head button:focus-visible { outline: 2px solid var(--sun-bright); outline-offset: 2px; }
.chat-head svg { width: 18px; height: 18px; }

.chat-log { position: relative; flex: 1; min-height: 0; overflow-y: auto; overscroll-behavior: contain; padding: 14px; display: flex; flex-direction: column; gap: 12px; background: var(--paper-warm); }
.chat-log > * { flex: none; animation: chat-in .18s ease-out; }
@keyframes chat-in { from { opacity: 0; transform: translateY(4px); } }

.chat-row { display: flex; align-items: flex-start; gap: 8px; }
.chat-msg { padding: 9px 12px; border-radius: var(--radius); white-space: normal; overflow-wrap: anywhere; }
.chat-msg p { margin: 0 0 .5em; }
.chat-msg p:last-child, .chat-msg ul:last-child { margin-bottom: 0; }
.chat-msg ul { margin: 0 0 .5em; padding-left: 1.2em; }
.chat-msg a { color: var(--green-dark); font-weight: 500; }
.chat-msg strong { font-weight: 600; }
.chat-bot { min-width: 0; background: #fff; border: 1px solid var(--line); }
.chat-user { align-self: flex-end; max-width: 85%; background: var(--green-dark); color: #fff; }
.chat-more { margin-top: 8px !important; padding-top: 7px; border-top: 1px solid var(--line); font-size: 14px; }
.chat-cut { margin-top: 8px !important; font-size: 14px; color: var(--error); }

.chat-typing { display: flex; align-items: center; gap: 9px; color: var(--ink-soft); font-size: 14px; }
.chat-dots { display: inline-flex; gap: 4px; }
.chat-dots i { width: 6px; height: 6px; border-radius: 50%; background: var(--green); animation: chat-dot 1.1s infinite ease-in-out; }
.chat-dots i:nth-child(2) { animation-delay: .16s; }
.chat-dots i:nth-child(3) { animation-delay: .32s; }
@keyframes chat-dot { 0%, 70%, 100% { opacity: .3; } 35% { opacity: 1; } }

/* Topics, and the questions and next steps after an answer. Set in from the left to line up with the bubbles. */
.chat-welcome, .chat-next { display: flex; flex-direction: column; gap: 10px; margin-left: 36px; }
.chat-topics { display: grid; grid-template-columns: repeat(4, 1fr); border: 1px solid var(--line); border-radius: var(--radius); background: #fff; overflow: hidden; }
.chat-topics button { min-height: 38px; padding: 4px 2px; border: 0; border-left: 1px solid var(--line); background: none; color: var(--ink-soft); font: inherit; font-size: 13.5px; font-weight: 500; cursor: pointer; }
.chat-topics button:first-child { border-left: 0; }
.chat-topics button:hover { color: var(--green-dark); }
.chat-topics button[aria-pressed="true"] { background: var(--green-deep); color: #fff; }
.chat-topics button:focus-visible { outline: 2px solid var(--green); outline-offset: -2px; }

.chat-questions { list-style: none; margin: 0; padding: 0; border: 1px solid var(--line); border-radius: var(--radius); background: #fff; }
.chat-questions li + li { border-top: 1px solid var(--line); }
.chat-questions button { width: 100%; min-height: 44px; padding: 8px 10px 8px 12px; display: flex; align-items: center; justify-content: space-between; gap: 10px; border: 0; background: none; color: var(--green-dark); font: inherit; font-size: 14.5px; line-height: 1.35; font-weight: 500; text-align: left; cursor: pointer; }
.chat-questions button:hover { background: var(--paper-warm); }
.chat-questions button:focus-visible { outline: 2px solid var(--green); outline-offset: -2px; }
.chat-questions svg { flex: none; width: 16px; height: 16px; }

.chat-actions, .chat-handoff { display: flex; flex-wrap: wrap; gap: 8px; }
.chat-actions a, .chat-handoff a, .chat-retry { display: inline-flex; align-items: center; justify-content: center; gap: 6px; min-height: 40px; padding: 7px 10px; border-radius: var(--radius); border: 1px solid var(--line); background: #fff; color: var(--ink); font: inherit; font-size: 13.5px; font-weight: 600; white-space: nowrap; text-decoration: none; cursor: pointer; }
.chat-actions a:hover, .chat-handoff a:hover, .chat-retry:hover { border-color: var(--green-dark); }
.chat-actions a.chat-survey { background: var(--sun-bright); border-color: var(--sun-bright); color: var(--green-night); }
.chat-actions a.chat-survey:hover { background: #FFC23A; border-color: #FFC23A; }
.chat-handoff a.chat-wa { background: #25D366; border-color: #25D366; color: #0B3D1F; }
.chat-handoff a.chat-wa:hover { background: #1FBE5A; border-color: #1FBE5A; }
.chat-handoff svg { width: 16px; height: 16px; }
.chat-retry { align-self: flex-start; background: var(--green-dark); border-color: var(--green-dark); color: #fff; }
.chat-retry:hover { background: var(--green-deep); }
.chat-new { align-self: flex-start; min-height: 32px; padding: 4px 0; border: 0; background: none; color: var(--ink-soft); font: inherit; font-size: 13.5px; text-decoration: underline; text-underline-offset: 2px; cursor: pointer; }
.chat-new:hover { color: var(--ink); }

/* The question box and send button read as one field. */
.chat-form { display: flex; align-items: flex-end; gap: 4px; margin: 10px 12px 8px; padding: 0 4px 0 0; border: 1px solid #B9B5A8; border-radius: var(--radius); background: #fff; }
.chat-form:focus-within { border-color: var(--green); box-shadow: 0 0 0 2px rgba(31,138,76,.2); }
.chat-form textarea, .chat-form textarea:focus { flex: 1; min-width: 0; resize: none; height: 44px; min-height: 0; margin: 0; width: auto; max-height: 120px; padding: 10px 12px; border: 0; border-radius: var(--radius); outline: 0; box-shadow: none; background: none; font: inherit; font-size: 16px; color: var(--ink); }
.chat-form button { flex: none; width: 36px; height: 36px; margin: 4px 0; border: 0; border-radius: var(--radius); background: var(--green-dark); color: #fff; display: grid; place-items: center; cursor: pointer; }
.chat-form button:hover { background: var(--green-deep); }
.chat-form button:disabled { background: var(--paper-warm); color: #8A8F88; cursor: default; }
.chat-form button:focus-visible { outline: 2px solid var(--green); outline-offset: 2px; }
.chat-form svg { width: 18px; height: 18px; }
.chat-count { margin: -4px 0 6px; padding: 0 12px; font-size: 12px; color: var(--ink-soft); text-align: right; }
.chat-note { margin: 0; padding: 0 12px 10px; font-size: 12px; line-height: 1.4; color: var(--ink-soft); background: #fff; }
.chat-note a { color: inherit; }
.chat-sr, .chat-form .visually-hidden { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

@media (max-width: 860px) {
  /* Sit just above the Call / WhatsApp / Get a quote bar. A round icon, so it covers less of the page. */
  .chat-fab { right: 14px; bottom: calc(68px + env(safe-area-inset-bottom)); width: 52px; padding: 0; justify-content: center; border-radius: 50%; }
  .chat-fab span { display: none; }
  /* Full screen on phones. */
  .chat-panel { inset: 0; width: auto; max-width: none; height: auto; max-height: none; border: 0; border-radius: 0; padding-bottom: env(safe-area-inset-bottom); }
  .chat-log { padding: 12px; }
  .chat-welcome, .chat-next { margin-left: 0; }
  body.chat-open { overflow: hidden; }
}
@media (prefers-reduced-motion: reduce) {
  .chat-panel, .chat-log > * { animation: none; }
  .chat-dots i { animation: none; opacity: .7; }
}
@media print {
  .chat-fab, .chat-panel { display: none !important; }
}
