/* Subconscious Alarm site chat ("Ask SA"). All chat styles live here. Loaded only when CHAT_ENABLED is "true".
   Colors come from the site palette (src/styles.css: paper, ink, muted, rule, wash, orange) and Figtree. Light by
   default, a warm dark set under prefers-color-scheme: dark. tests/chat-surface.test.js checks every text and
   control pair in both sets (WCAG AA: 4.5:1 for text, 3:1 for control edges and icons). Orange carries no text:
   it is the mark and the send button only. No colored side lines, no inset edges, no capitals labels. */
.ac{
  --ac-ease:cubic-bezier(.16,1,.3,1);
  --ac-gap:max(1rem,env(safe-area-inset-left,0px) + .75rem);
  /* Light set. */
  --ac-surface:#faf9f6;--ac-field:#f0eee6;--ac-ink:#282923;--ac-muted:#5e6056;--ac-line:#dcdacf;--ac-edge:#7c7e72;
  --ac-soft:#ecebe3;--ac-em-bg:#282923;--ac-em-ink:#faf9f6;--ac-you:#ebe9e0;--ac-accent:#ff330a;--ac-accent-ink:#282923;
  --ac-focus:#282923;--ac-trigger-bg:#282923;--ac-trigger-ink:#faf9f6;
  --ac-shadow:0 18px 50px rgba(40,41,35,.14),0 2px 8px rgba(40,41,35,.08);
  position:fixed;left:var(--ac-gap);bottom:calc(max(1rem,env(safe-area-inset-bottom,0px) + .75rem) + var(--ac-lift,0px));
  z-index:4400;font-family:"Figtree",-apple-system,BlinkMacSystemFont,"Segoe UI",sans-serif;color:var(--ac-ink);font-size:1rem;line-height:1.4;
  transition:bottom .3s var(--ac-ease);-webkit-tap-highlight-color:transparent
}
/* Dark set: deep warm ink, paper text, the same orange lifted a little for contrast. */
@media (prefers-color-scheme:dark){
  .ac{
    --ac-surface:#1c1d18;--ac-field:#26271f;--ac-ink:#faf9f6;--ac-muted:#b5b6aa;--ac-line:#3a3b33;--ac-edge:#8a8b80;
    --ac-soft:#2d2e27;--ac-em-bg:#faf9f6;--ac-em-ink:#1c1d18;--ac-you:#33342c;--ac-accent:#ff5a36;--ac-accent-ink:#1c1d18;
    --ac-focus:#faf9f6;--ac-trigger-bg:#1c1d18;--ac-trigger-ink:#faf9f6;
    --ac-shadow:0 18px 50px rgba(0,0,0,.4),0 2px 8px rgba(0,0,0,.25);
    color-scheme:dark
  }
}
.ac[hidden],.ac [hidden]{display:none!important}
.ac *,.ac *::before,.ac *::after{box-sizing:border-box}
.ac button,.ac textarea,.ac input{font:inherit}
.ac_icon,.ac_input{color:var(--ac-ink)}
.ac :focus-visible{outline:2px solid var(--ac-focus);outline-offset:2px}

/* The mark: the site's orange full stop. */
.ac_mark{display:inline-block;flex:none;width:.6rem;height:.6rem;border-radius:50%;background-color:var(--ac-accent)}

/* Shared surface: hairline and a soft shadow. Solid on purpose, so nothing behind shows through the fields. */
.ac_panel,.ac_composer{background-color:var(--ac-surface);border:1px solid var(--ac-line);box-shadow:var(--ac-shadow)}

/* Idle pill. */
.ac_trigger{display:inline-flex;align-items:center;gap:.6rem;min-height:2.75rem;max-width:calc(100vw - 2 * var(--ac-gap));padding:.6rem 1.1rem .6rem 1rem;
  border:1px solid var(--ac-trigger-bg);border-radius:999px;background-color:var(--ac-trigger-bg);color:var(--ac-trigger-ink);box-shadow:var(--ac-shadow);
  cursor:pointer;font-size:.95rem;font-weight:500;text-align:left;transition:transform .25s var(--ac-ease)}
.ac_trigger:hover{transform:translateY(-1px)}
.ac_trigger:focus-visible{outline-color:var(--ac-ink);outline-offset:3px}
.ac_invite{white-space:nowrap;overflow:hidden;text-overflow:ellipsis}
/* The pill stays hidden until the panel has faded out (chat.js keeps is-open through the close), then it is placed in its
   resting spot and fades in, so it never jumps. */
.ac.is-open .ac_trigger,.ac[data-state=closing] .ac_trigger{display:none}
.ac[data-state=settling] .ac_trigger{animation:ac-fade .3s ease both}

/* Focused: panel above, composer where the pill was. */
.ac_dialog:not([hidden]){display:flex;flex-direction:column;gap:.5rem;width:calc(100vw - 2 * var(--ac-gap));transform-origin:0 100%}
@media (min-width:640px){.ac_dialog:not([hidden]){width:24rem}}
.ac[data-state=opening] .ac_dialog{animation:ac-in .3s var(--ac-ease) both}
.ac[data-state=closing] .ac_dialog{animation:ac-out .3s ease both;pointer-events:none}
.ac_panel{display:flex;flex-direction:column;border-radius:22px;corner-shape:squircle;--squircle:1;overflow:hidden}
.ac_head{display:flex;align-items:center;gap:.5rem;padding:.6rem .6rem .25rem}
.ac .ac_title{color:var(--ac-ink);display:flex;align-items:center;gap:.5rem;flex:1;min-width:0;margin:0 0 0 .4rem;font-family:inherit;font-size:1rem;font-weight:700;letter-spacing:0;line-height:1.2}
.ac_back:not([hidden])+.ac_title{margin-left:0}
.ac_icon{display:inline-flex;align-items:center;justify-content:center;flex:none;width:2.75rem;height:2.75rem;padding:0;border:1px solid var(--ac-edge);border-radius:50%;background:transparent;cursor:pointer}
.ac_icon:hover{background-color:var(--ac-soft)}
.ac_icon svg,.ac_send svg{width:18px;height:18px;fill:none;stroke:currentColor;stroke-width:1.8;stroke-linecap:round;stroke-linejoin:round}


.ac_thread{max-height:min(60vh,calc(100dvh - var(--ac-top,8rem) - 11rem - var(--ac-lift,0px)));min-height:4.5rem;overflow-y:auto;overscroll-behavior:contain;padding:.5rem 1rem 1rem;scrollbar-width:thin}
.ac_thread:focus{outline:none}
.ac_greet{display:flex;flex-direction:column;margin:.25rem 0 .5rem;font-size:1.2rem;font-weight:700;line-height:1.25}
.ac_greet-2{font-weight:500;color:var(--ac-muted);font-size:1rem;margin-top:.15rem}
.ac_honest{margin:0 0 .9rem;font-size:.9rem;color:var(--ac-muted)}

.ac_chips{display:flex;flex-wrap:wrap;gap:.4rem}
.ac_chip{display:inline-flex;align-items:center;min-height:2.75rem;padding:.4rem .85rem;border:1px solid var(--ac-edge);border-radius:999px;background:transparent;
  font-size:.9rem;font-weight:500;line-height:1.2;text-align:left;text-decoration:none;color:var(--ac-ink);cursor:pointer}
.ac_chip:hover{background-color:var(--ac-soft)}
.ac .ac_chip--em{background-color:var(--ac-em-bg);border-color:var(--ac-em-bg);color:var(--ac-em-ink)}
.ac .ac_chip--em:hover{background-color:var(--ac-em-bg);opacity:.9}

.ac_group{margin-top:.9rem}
/* Who said it is for screen readers only: the bubbles' alignment shows it on screen. */
.ac_group--you .ac_items{align-items:flex-end}
.ac_items{display:flex;flex-direction:column;gap:.4rem}
.ac_msg{max-width:100%;font-size:.95rem;overflow-wrap:anywhere}
.ac_msg p{margin:0;line-height:1.5}
.ac_msg p+p,.ac_msg ul+p,.ac_msg p+ul{margin-top:.55rem}
.ac_msg ul{margin:.3rem 0 0;padding-left:1.1rem}
.ac_msg li+li{margin-top:0}
/* Standalone links (a link-only line, a near-link list item and form links) get a 44px
   tap target. Links inside a sentence stay inline. */
.ac .ac_linkline a,.ac .ac_msg li>a{display:inline-flex;align-items:center;min-height:2.75rem}
.ac .ac_msg a{font:inherit;font-weight:600;color:inherit;text-decoration:underline;text-underline-offset:.15em;text-decoration-thickness:1px}
.ac_msg--you{align-self:flex-end;max-width:85%;padding:.55rem .85rem;border-radius:18px;corner-shape:squircle;--squircle:1;background-color:var(--ac-you)}
.ac_msg--error p{color:var(--ac-ink)}
.ac_actions{display:flex;flex-wrap:wrap;gap:.4rem;margin-top:.55rem}
.ac_pending{display:inline-block;color:var(--ac-muted);animation:ac-wait 1.2s ease-in-out infinite}
.ac_after{display:flex;flex-direction:column;align-items:flex-start;gap:.6rem;margin-top:.75rem}

.ac_cta{display:inline-flex;align-items:center;min-height:2.75rem;padding:.6rem 1.25rem;border:1px solid var(--ac-em-bg);border-radius:999px;
  background-color:var(--ac-em-bg);color:var(--ac-em-ink);font-weight:600;text-decoration:none}
.ac_cta:hover{opacity:.9}
.ac_cta--small{min-height:2.75rem;padding:.4rem 1rem;font-size:.9rem}
.ac .ac_greet,.ac .ac_honest{font-family:inherit}


/* Talk to a person opens a chat-style thread in the panel (no intake form). The optional email field after the first
   message uses these. */
.ac_label{font-size:.9rem;font-weight:600;color:var(--ac-ink)}
.ac .ac_text{width:100%;min-height:2.75rem;margin:0;padding:.5rem .75rem;border:1px solid var(--ac-edge);border-radius:12px;background-color:var(--ac-field);color:var(--ac-ink);font:inherit;font-size:1rem;line-height:1.35;box-shadow:none}
.ac .ac_text:focus{border-color:var(--ac-ink)}
/* An invalid field gets a heavier full border and its message below, never a colored edge on one side. */
.ac .ac_text[aria-invalid=true]{border:2px solid var(--ac-ink);padding:calc(.5rem - 1px) calc(.75rem - 1px)}
.ac_err{margin:0;font-size:.9rem;font-weight:600;color:var(--ac-ink)}
.ac_hactions{display:flex;flex-wrap:wrap;align-items:center;gap:.5rem}

/* Live thread with the team: one quiet status line, replies from the team as plain bubbles, and the optional email field. */
.ac_status{margin:.9rem 0 0;font-size:.9rem;color:var(--ac-muted)}
.ac_status--end{color:var(--ac-ink)}
.ac_status+.ac_after{margin-top:.6rem}
.ac_follow{display:flex;flex-direction:column;gap:.3rem;margin:.9rem 0 0}
.ac_follow-line{margin:0 0 .2rem;font-size:.9rem;color:var(--ac-muted)}

/* With JS off: a plain link to Support in the same spot. */
.ac_nojs{position:fixed;left:max(1rem,env(safe-area-inset-left,0px) + .75rem);bottom:max(1rem,env(safe-area-inset-bottom,0px) + .75rem);z-index:4400;
  display:inline-flex;align-items:center;min-height:2.75rem;padding:.6rem 1.1rem;border:1px solid #282923;border-radius:999px;
  background-color:#282923;color:#faf9f6;font-family:"Figtree",-apple-system,BlinkMacSystemFont,"Segoe UI",sans-serif;font-size:.95rem;font-weight:500;text-decoration:none;box-shadow:0 18px 50px rgba(40,41,35,.14)}
@media (prefers-color-scheme:dark){.ac_nojs{border-color:#1c1d18;background-color:#1c1d18}}

/* Composer in the pill. */
.ac_composer{display:flex;align-items:flex-end;gap:.5rem;min-height:3.875rem;padding:.5rem .5rem .5rem 1rem;border-color:var(--ac-edge);border-radius:24px;corner-shape:squircle;--squircle:1}
.ac_composer>.ac_mark{align-self:center}
.ac .ac_input{flex:1;min-width:0;min-height:2.75rem;max-height:120px;margin:0;padding:.7rem 0;border:0;background:transparent;resize:none;font-size:1rem;line-height:1.35;outline:none;box-shadow:none}
.ac .ac_input:focus,.ac .ac_input:focus-visible{outline:none;box-shadow:none}
.ac_input::placeholder{color:var(--ac-muted);opacity:1}
.ac_composer:focus-within{border-color:var(--ac-ink);outline:1px solid var(--ac-ink)}
.ac .ac_send{display:inline-flex;align-items:center;justify-content:center;flex:none;width:2.75rem;height:2.75rem;padding:0;border:0;border-radius:50%;background-color:var(--ac-accent);color:var(--ac-accent-ink);cursor:pointer}
.ac_composer.is-busy .ac_send{opacity:.45;cursor:default}

/* The site's own element rules (src/styles.css: button, button:hover, button:focus-visible, links) must not reach the
   chat. These win on specificity: every chat button keeps its own colors on hover, pills stay round pills, and focus
   uses the chat's ring in both sets. */
.ac_trigger,.ac_chip,.ac_cta,.ac_icon,.ac_send{corner-shape:round}
.ac a:focus-visible,.ac button:focus-visible,.ac input:focus-visible,.ac textarea:focus-visible{outline:2px solid var(--ac-focus);outline-offset:2px}
.ac button.ac_trigger:focus-visible{outline-offset:3px}
.ac button.ac_trigger:hover{background-color:var(--ac-trigger-bg);border-color:var(--ac-trigger-bg)}
.ac button.ac_chip:hover{background-color:var(--ac-soft);border-color:var(--ac-edge)}
.ac button.ac_chip--em:hover{background-color:var(--ac-em-bg);border-color:var(--ac-em-bg)}
.ac button.ac_icon:hover{background-color:var(--ac-soft);border-color:var(--ac-edge)}
.ac button.ac_send:hover{background-color:var(--ac-accent)}

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

/* The mark pulses once, only on open. */
.ac[data-state=opening] .ac_title .ac_mark,.ac[data-state=opening] .ac_composer>.ac_mark{animation:ac-pulse .6s var(--ac-ease) both}

@keyframes ac-in{from{opacity:0;transform:translateY(8px) scale(.98)}to{opacity:1;transform:none}}
@keyframes ac-out{from{opacity:1;transform:none}to{opacity:0;transform:translateY(8px) scale(.98)}}
@keyframes ac-fade{from{opacity:0}to{opacity:1}}
@keyframes ac-pulse{0%{transform:scale(1)}45%{transform:scale(1.45)}100%{transform:scale(1)}}
@keyframes ac-wait{0%,100%{opacity:.35}50%{opacity:1}}

@media (prefers-reduced-motion:reduce){
  .ac,.ac *{animation:none!important;transition:none!important}
}
/* Short screens (landscape phones): the open dialog sits above everything while open. */
@media (max-height:520px){.ac.is-open{z-index:5100}}
@media (max-width:359px){.ac_trigger{font-size:.9rem;padding-right:.9rem}}
