/* ==========================================================================
   AI assistant: chat bubble and window (loaded only when the assistant is on)
   The site's language: square geometry, navy + green, tide lines and the shoreline curve.
   ========================================================================== */
.ccchat { --cc-w: 420px; --cc-h: 640px; position: fixed; bottom: 22px; z-index: 900; font-family: var(--font-sans); color: var(--ink); }
.ccchat.pos-right { right: 22px; }
.ccchat.pos-left { left: 22px; }
.ccchat [hidden] { display: none !important; }
.ccchat button { font: inherit; }

/* ---------- Launcher ---------- */
.ccchat-launcher { position: relative; display: grid; place-items: center; width: 62px; height: 62px; padding: 0; border: 0; border-bottom: 4px solid var(--accent);
    background: var(--tide-lines-light), linear-gradient(135deg, var(--primary-dark), var(--navy)); color: #fff; cursor: pointer;
    box-shadow: 0 18px 34px -14px rgba(6,16,34,.6); transition: transform .35s var(--ease-out), box-shadow .35s; }
.ccchat-launcher:hover { transform: translateY(-3px); box-shadow: 0 24px 40px -16px rgba(6,16,34,.7); }
.ccchat-launcher:focus-visible { outline: 3px solid var(--accent-glow); outline-offset: 3px; }
.ccchat-launcher .icon { width: 26px; height: 26px; }
.ccchat-launcher-icon, .ccchat-launcher-close { position: absolute; inset: 0; display: grid; place-items: center; transition: transform .4s var(--ease-out), opacity .25s; }
.ccchat-launcher-close { position: absolute; inset: 0; opacity: 0; transform: rotate(-90deg) scale(.6); }
.ccchat.is-open .ccchat-launcher-icon { opacity: 0; transform: rotate(90deg) scale(.6); }
.ccchat.is-open .ccchat-launcher-close { opacity: 1; transform: none; }
.ccchat-launcher-dot { position: absolute; top: 9px; right: 9px; width: 10px; height: 10px; background: #3ddc84; box-shadow: 0 0 0 2px var(--navy); transition: opacity .2s; }
.is-paused .ccchat-launcher-dot { background: #f2b33d; }
.ccchat.is-open .ccchat-launcher-dot { opacity: 0; }
/* A gentle ripple invites the first click */
.ccchat-launcher::before { content: ""; position: absolute; inset: 0; border: 2px solid var(--accent-glow); opacity: 0; animation: ccchatRipple 3.2s var(--ease-out) 2s 3; pointer-events: none; }
@keyframes ccchatRipple { 0% { opacity: .8; transform: scale(1); } 100% { opacity: 0; transform: scale(1.6); } }
.ccchat.is-open .ccchat-launcher::before { display: none; }
.ccchat-launcher-tip { position: absolute; bottom: 50%; right: calc(100% + 12px); transform: translate(6px, 50%); width: max-content; padding: 8px 12px; background: var(--navy); color: #fff;
    font-size: .82rem; font-weight: 600; opacity: 0; pointer-events: none; transition: opacity .2s, transform .3s var(--ease-out); }
.pos-left .ccchat-launcher-tip { right: auto; left: calc(100% + 12px); transform: translate(-6px, 50%); }
.ccchat-launcher:hover .ccchat-launcher-tip { opacity: 1; transform: translate(0, 50%); }
.ccchat.is-open .ccchat-launcher-tip, .ccchat.has-teaser .ccchat-launcher-tip { display: none; }

/* ---------- Teaser: a short greeting beside the bubble, once per visit ---------- */
.ccchat-teaser { position: absolute; bottom: 76px; right: 0; display: flex; align-items: flex-start; width: 290px; background: #fff;
    box-shadow: 0 22px 48px -20px rgba(6,16,34,.45), 0 0 0 1px rgba(6,16,34,.06); border-bottom: 3px solid var(--accent); animation: ccchatTeaser .5s var(--ease-out); }
.pos-left .ccchat-teaser { right: auto; left: 0; }
.ccchat-teaser::after { content: ""; position: absolute; bottom: -9px; right: 24px; width: 14px; height: 14px; background: #fff; transform: rotate(45deg); box-shadow: 3px 3px 0 0 var(--accent); }
.pos-left .ccchat-teaser::after { right: auto; left: 24px; }
.ccchat-teaser-body { display: flex; gap: 12px; flex: 1; padding: 14px 6px 14px 14px; border: 0; background: none; text-align: left; font-size: .84rem; line-height: 1.45; color: var(--text); cursor: pointer; }
.ccchat-teaser-body > span:last-child { min-width: 0; }
.ccchat-teaser-body strong { display: block; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; margin-bottom: 2px; font-family: var(--font-display); font-size: .86rem; color: var(--ink); }
.ccchat-teaser-avatar { display: grid; place-items: center; flex-shrink: 0; width: 40px; height: 40px; background: #fff; box-shadow: inset 0 0 0 1px var(--line); }
.ccchat-teaser-avatar img { width: 30px; height: 30px; }
.ccchat-teaser-close { display: grid; place-items: center; flex-shrink: 0; width: 30px; height: 30px; margin: 6px 6px 0 0; border: 0; background: none; color: var(--muted); cursor: pointer; }
.ccchat-teaser-close:hover { color: var(--ink); background: var(--mist); }
.ccchat-teaser-close .icon { width: 15px; height: 15px; }
@keyframes ccchatTeaser { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: none; } }

/* ---------- Window ---------- */
.ccchat-panel { position: absolute; bottom: 80px; right: 0; display: flex; flex-direction: column; width: min(var(--cc-w), calc(100vw - 32px)); height: min(var(--cc-h), calc(100vh - 124px));
    overflow: hidden; background: #fff; box-shadow: 0 34px 80px -26px rgba(6,16,34,.55), 0 0 0 1px rgba(6,16,34,.07);
    transform-origin: bottom right; animation: ccchatIn .4s var(--ease-out); transition: width .35s var(--ease-out), height .35s var(--ease-out); }
.pos-left .ccchat-panel { right: auto; left: 0; transform-origin: bottom left; }
.ccchat.is-wide { --cc-w: 620px; --cc-h: 820px; }
@keyframes ccchatIn { from { opacity: 0; transform: translateY(16px) scale(.96); } to { opacity: 1; transform: none; } }

/* Header */
.ccchat-head { position: relative; flex-shrink: 0; color: #fff; background: var(--tide-lines-light), radial-gradient(120% 90% at 100% 0, color-mix(in srgb, var(--accent) 38%, transparent), transparent 60%), linear-gradient(160deg, var(--primary-dark), var(--navy) 70%); }
.ccchat-bar { display: flex; align-items: center; gap: 12px; padding: 16px 10px 12px 16px; }
.ccchat-avatar { position: relative; display: grid; place-items: center; flex-shrink: 0; width: 44px; height: 44px; background: #fff; box-shadow: 0 8px 18px -8px rgba(0,0,0,.5); }
.ccchat-avatar img { width: 34px; height: 34px; }
.ccchat-avatar i { position: absolute; right: -3px; bottom: -3px; width: 12px; height: 12px; background: #3ddc84; border: 2px solid var(--navy); }
.is-paused .ccchat-avatar i { background: #f2b33d; }
.ccchat-titles { flex: 1; min-width: 0; }
.ccchat-titles h2 { margin: 0; font-family: var(--font-display); font-size: .96rem; font-weight: 700; line-height: 1.25; color: #fff; letter-spacing: -.01em; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.ccchat-titles p { margin: 3px 0 0; overflow: hidden; font-size: .78rem; color: rgba(255,255,255,.72); white-space: nowrap; text-overflow: ellipsis; }
.ccchat-status { color: #8ff0b8; font-weight: 600; }
.ccchat-status.ccchat-soon { display: inline-block; padding: 2px 8px; background: rgba(242,179,61,.18); color: #ffd27a; font-size: .72rem; letter-spacing: .06em; text-transform: uppercase; }
.ccchat-actions { display: flex; gap: 0; margin-right: -4px; }
.ccchat-icon-btn { display: grid; place-items: center; width: 34px; height: 34px; border: 0; background: transparent; color: rgba(255,255,255,.85); cursor: pointer; transition: background .2s, color .2s; }
.ccchat-icon-btn:hover { background: rgba(255,255,255,.14); color: #fff; }
.ccchat-icon-btn:focus-visible { outline: 2px solid var(--accent-glow); outline-offset: -2px; }
.ccchat-icon-btn .icon { width: 17px; height: 17px; }

/* The welcome: large on the first screen, folds away once the conversation starts */
.ccchat-hero { display: grid; grid-template-rows: 1fr; transition: grid-template-rows .45s var(--ease-out), opacity .3s; }
.ccchat-greeting { min-height: 0; overflow: hidden; margin: 0; padding: 6px 22px 22px; font-size: 1rem; font-weight: 500; line-height: 1.55; color: rgba(255,255,255,.9); }
.ccchat.has-chat .ccchat-hero { grid-template-rows: 0fr; opacity: 0; }
.ccchat.has-chat .ccchat-greeting { padding-top: 0; padding-bottom: 0; }
.ccchat-shore { display: block; width: 100%; height: 22px; margin-top: -8px; }
.ccchat-shore-line { fill: none; stroke: var(--accent-glow); stroke-width: 1.4px; vector-effect: non-scaling-stroke; opacity: .9; }
.ccchat-shore-fill { fill: #f4f8f9; }

/* Conversation */
.ccchat-log { flex: 1; overflow-y: auto; overscroll-behavior: contain; padding: 14px 16px 10px; background: linear-gradient(180deg, #f4f8f9, #fff 220px); scroll-behavior: smooth; }
.ccchat-log::-webkit-scrollbar { width: 6px; }
.ccchat-log::-webkit-scrollbar-thumb { background: var(--line-strong); }
.ccchat-label { margin: 2px 0 10px; font-size: .7rem; font-weight: 700; letter-spacing: .1em; text-transform: uppercase; color: var(--muted); }
.ccchat-suggestions { display: grid; gap: 8px; margin-bottom: 8px; }
.ccchat-chip { display: flex; align-items: center; justify-content: space-between; gap: 12px; width: 100%; padding: 12px 14px; border: 1px solid var(--line); border-left: 3px solid var(--accent);
    background: #fff; color: var(--ink); font-size: .88rem; font-weight: 600; line-height: 1.35; text-align: left; cursor: pointer;
    box-shadow: var(--shadow-sm); transition: transform .25s var(--ease-out), border-color .2s, box-shadow .25s; animation: ccchatUpIn .5s var(--ease-out) both; }
.ccchat-chip:nth-child(3) { animation-delay: .06s; }
.ccchat-chip:nth-child(4) { animation-delay: .12s; }
.ccchat-chip:nth-child(5) { animation-delay: .18s; }
.ccchat-chip .icon { flex-shrink: 0; width: 16px; height: 16px; color: var(--accent); transition: transform .25s var(--ease-out); }
.ccchat-chip:hover { transform: translateY(-1px); border-color: color-mix(in srgb, var(--accent) 40%, var(--line)); box-shadow: var(--shadow); }
.ccchat-chip:hover .icon { transform: translateX(3px); }
@keyframes ccchatUpIn { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }

.ccchat-msg { display: flex; gap: 10px; margin-bottom: 14px; animation: ccchatUpIn .35s var(--ease-out); }
.ccchat-msg.is-user { justify-content: flex-end; }
.ccchat-msg-avatar { display: grid; place-items: center; flex-shrink: 0; width: 30px; height: 30px; margin-top: 2px; background: #fff; box-shadow: inset 0 0 0 1px var(--line); }
.ccchat-msg-avatar img { width: 22px; height: 22px; }
.ccchat-msg-body { min-width: 0; max-width: calc(100% - 38px); }
.ccchat-bubble { padding: 11px 14px; font-size: .92rem; line-height: 1.6; color: var(--text); background: #fff; overflow-wrap: anywhere; }
.ccchat-msg.is-bot .ccchat-bubble { border: 1px solid var(--line); box-shadow: var(--shadow-sm); }
.ccchat-msg.is-user .ccchat-bubble { max-width: 85%; color: #fff; background: linear-gradient(135deg, var(--primary), var(--primary-dark)); box-shadow: 0 8px 18px -12px rgba(29,63,143,.8); }
.ccchat-msg.is-error .ccchat-bubble { border-color: #f3ddb0; background: #fffaf0; color: #6b3d00; }
.ccchat-bubble p { margin: 0 0 8px; }
.ccchat-bubble p:last-child, .ccchat-bubble ul:last-child { margin-bottom: 0; }
.ccchat-bubble ul { margin: 0 0 8px; padding-left: 0; list-style: none; }
.ccchat-bubble li { position: relative; margin-bottom: 4px; padding-left: 16px; }
.ccchat-bubble li::before { content: ""; position: absolute; left: 2px; top: .62em; width: 6px; height: 6px; background: var(--accent); }
.ccchat-bubble strong { color: var(--ink); }
.ccchat-bubble a { color: var(--primary); font-weight: 600; text-underline-offset: 2px; }

/* Sources: small numbered cards */
.ccchat-sources { display: grid; gap: 6px; margin-top: 8px; }
.ccchat-sources .ccchat-label { margin: 4px 0 0; font-size: .64rem; }
.ccchat-source { display: flex; align-items: center; gap: 10px; padding: 8px 10px; border: 1px solid var(--line); background: #fff; color: var(--ink); text-decoration: none; transition: border-color .2s, background .2s; }
.ccchat-source:hover { border-color: var(--accent); background: var(--accent-soft); }
.ccchat-source b { display: grid; place-items: center; flex-shrink: 0; width: 20px; height: 20px; background: var(--accent-soft); color: var(--accent-dark); font-size: .7rem; }
.ccchat-source span { min-width: 0; font-size: .8rem; font-weight: 600; line-height: 1.3; }
.ccchat-source small { display: block; overflow: hidden; color: var(--muted); font-weight: 500; font-size: .7rem; white-space: nowrap; text-overflow: ellipsis; }

.ccchat-tools { display: flex; gap: 4px; margin-top: 4px; }
.ccchat-tool { display: inline-flex; align-items: center; gap: 5px; padding: 4px 8px; border: 0; background: none; color: var(--muted); font-size: .74rem; font-weight: 600; cursor: pointer; transition: color .2s, background .2s; }
.ccchat-tool:hover { color: var(--ink); background: var(--mist); }
.ccchat-tool .icon { width: 13px; height: 13px; }
.ccchat-tool.is-done { color: var(--accent); }

/* Typing: three tide bars and a status line */
.ccchat-typing .ccchat-bubble { display: inline-flex; align-items: center; gap: 10px; color: var(--muted); font-size: .84rem; }
.ccchat-dots { display: inline-flex; align-items: flex-end; gap: 3px; height: 14px; }
.ccchat-dots i { width: 4px; height: 6px; background: var(--accent); animation: ccchatBar 1s var(--ease) infinite; }
.ccchat-dots i:nth-child(2) { animation-delay: .12s; }
.ccchat-dots i:nth-child(3) { animation-delay: .24s; }
@keyframes ccchatBar { 0%, 100% { height: 5px; opacity: .45; } 50% { height: 14px; opacity: 1; } }

/* Allowance used up */
.ccchat-limit { display: flex; gap: 12px; margin: 0 16px 10px; padding: 14px; background: #fff8eb; border: 1px solid #f3ddb0; font-size: .86rem; line-height: 1.5; color: #6b3d00; animation: ccchatUpIn .35s var(--ease-out); }
.ccchat-limit > .icon { flex-shrink: 0; width: 20px; height: 20px; margin-top: 2px; color: #c47f0a; }
.ccchat-limit p { margin: 0 0 10px; }
.ccchat-limit-actions { display: flex; flex-wrap: wrap; gap: 8px; }
.ccchat-limit-actions a { padding: 8px 14px; background: var(--accent); color: #fff; font-weight: 700; font-size: .82rem; text-decoration: none; transition: background .2s; }
.ccchat-limit-actions a:hover { background: var(--accent-dark); }
.ccchat-limit-actions a + a { background: #fff; color: var(--accent-dark); box-shadow: inset 0 0 0 1px var(--accent); }

/* Message box */
.ccchat-form { flex-shrink: 0; padding: 12px 14px 10px; border-top: 1px solid var(--line); background: #fff; }
.ccchat-field { display: flex; align-items: flex-end; gap: 6px; padding: 5px 5px 5px 0; border: 1px solid var(--line-strong); background: #fff; transition: border-color .2s, box-shadow .2s; }
.ccchat-field:focus-within { border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-soft); }
.ccchat-field textarea { flex: 1; min-height: 38px; max-height: 130px; padding: 9px 12px; border: 0; background: none; font: inherit; font-size: .92rem; line-height: 1.4; resize: none; color: var(--ink); outline: none; }
.ccchat-field textarea:disabled { cursor: not-allowed; }
.ccchat-send { display: grid; place-items: center; flex-shrink: 0; width: 38px; height: 38px; border: 0; background: var(--accent); color: #fff; cursor: pointer; transition: background .2s, opacity .2s, transform .2s; }
.ccchat-send:hover:not(:disabled) { background: var(--accent-dark); transform: translateY(-1px); }
.ccchat-send:disabled { background: var(--line-strong); cursor: not-allowed; }
.ccchat-send .icon { width: 17px; height: 17px; }
.ccchat-foot { display: flex; align-items: center; justify-content: space-between; gap: 10px; min-height: 0; }
.ccchat-foot:has(> :not([hidden])) { margin-top: 8px; }
.ccchat-quota { display: inline-flex; align-items: center; gap: 8px; font-size: .74rem; font-weight: 600; color: var(--muted); }
.ccchat-quota i { position: relative; display: block; width: 46px; height: 4px; background: var(--line); }
.ccchat-quota b { position: absolute; inset: 0 auto 0 0; background: var(--accent); transition: width .5s var(--ease-out); }
.ccchat-quota.is-low b { background: #e09a1b; }
.ccchat-quota.is-low { color: #8a4b00; }
.ccchat-count { margin-left: auto; font-size: .72rem; color: var(--muted); }
.ccchat-disclaimer { margin: 8px 0 0; font-size: .7rem; line-height: 1.4; color: var(--muted); }

/* ---------- Answers paused by the admin: header only, with the message ---------- */
.ccchat.is-paused .ccchat-panel { height: auto; }
.is-paused .ccchat-greeting { padding-bottom: 26px; font-size: 1.04rem; }
.is-paused .ccchat-shore-fill { fill: #fff; }
.is-paused .ccchat-head::after { content: ""; display: block; height: 10px; background: #fff; }

/* ---------- Larger window only makes sense on wide screens ---------- */
@media (max-width: 900px), (max-height: 700px) { .ccchat-expand { display: none; } }

/* ---------- Phones: a full-screen app view ---------- */
@media (max-width: 560px) {
    .ccchat { bottom: 16px; }
    .ccchat.pos-right { right: 16px; }
    .ccchat.pos-left { left: 16px; }
    .ccchat-launcher { width: 58px; height: 58px; }
    .ccchat-launcher-tip { display: none; }
    .ccchat-teaser { bottom: 72px; width: min(290px, calc(100vw - 32px)); }
    .ccchat-panel { position: fixed; inset: 0; width: auto; height: auto; height: 100dvh; animation: ccchatUp .35s var(--ease-out); }
    .ccchat.is-open .ccchat-launcher, .ccchat.is-open .ccchat-teaser { display: none; }
    .ccchat-bar { padding-top: max(14px, env(safe-area-inset-top)); }
    .ccchat-greeting { font-size: 1.05rem; }
    .ccchat-form { padding-bottom: max(10px, env(safe-area-inset-bottom)); }
    .ccchat-field textarea { font-size: 16px; }   /* no zoom on iOS */
    .ccchat-msg.is-user .ccchat-bubble { max-width: 88%; }
    .ccchat.is-paused .ccchat-panel { inset: auto 0 0; height: auto; }   /* a bottom sheet rather than a near-empty screen */
    .is-paused .ccchat-head::after { height: max(14px, env(safe-area-inset-bottom)); }
}
@keyframes ccchatUp { from { transform: translateY(28px); opacity: 0; } to { transform: none; opacity: 1; } }
html.ccchat-lock, html.ccchat-lock body { overflow: hidden; }

@media (prefers-reduced-motion: reduce) {
    .ccchat *, .ccchat *::before { animation: none !important; transition: none !important; }
}
