/* Floating AI counselor: launcher, teaser and chat panel. */
.chat-root {
  --chat-ink: #06202a;
  --chat-mint: #86e6d9;
  --chat-red: #ff6b7a; /* brighter than --red so it reads on the dark header */
  --chat-gap: 24px;
  --chat-shadow: 0 24px 64px #0b2a3029, 0 4px 14px #0b2a3014;
}

/* Launcher */
.chat-launcher { position: fixed; right: var(--chat-gap); bottom: var(--chat-gap); z-index: 70; display: inline-flex; align-items: center; gap: 9px; height: 56px; padding: 0 22px 0 19px; border-radius: 999px; color: #fff; background: linear-gradient(180deg, #0e7a86 0%, #0b6f7a 100%); box-shadow: inset 0 1px 0 #ffffff24, 0 10px 28px #0b6f7a4d, 0 2px 6px #0b2a3024; font-size: .9375rem; font-weight: 700; letter-spacing: -.02em; transition: transform .2s var(--ease), box-shadow .2s ease, background .2s ease; }
.chat-launcher:hover { transform: translateY(-2px); box-shadow: inset 0 1px 0 #ffffff24, 0 14px 32px #0b6f7a59, 0 2px 6px #0b2a3024; }
.chat-launcher:focus-visible { outline-offset: 4px; }
.chat-launcher.is-open { width: 56px; padding: 0; justify-content: center; color: var(--chat-ink); background: #fff; border: 1px solid var(--border); box-shadow: var(--chat-shadow); }

/* Teaser bubble */
.chat-teaser { position: fixed; right: var(--chat-gap); bottom: calc(var(--chat-gap) + 70px); z-index: 70; display: flex; align-items: flex-start; max-width: 280px; background: #fff; border: 1px solid var(--border); border-radius: 14px 14px 4px 14px; box-shadow: var(--chat-shadow); animation: chat-rise .4s var(--ease) both; }
.chat-teaser-body { display: flex; flex-direction: column; gap: 2px; padding: 14px 4px 14px 16px; text-align: left; line-height: 1.5; }
.chat-teaser-body b { font-size: .9375rem; }
.chat-teaser-body span { color: var(--muted); font-size: var(--fs-xs); }
.chat-teaser-close { display: grid; place-items: center; width: 32px; height: 32px; margin: 6px 6px 0 0; border-radius: 8px; color: var(--faint); }
.chat-teaser-close:hover { color: var(--text); background: var(--surface-2); }

/* Panel */
.chat-panel { position: fixed; right: var(--chat-gap); bottom: calc(var(--chat-gap) + 72px); z-index: 70; display: flex; flex-direction: column; width: 392px; height: min(660px, calc(100dvh - 136px)); overflow: hidden; background: #fff; border: 1px solid var(--border); border-radius: 18px; box-shadow: var(--chat-shadow); transform-origin: bottom right; animation: chat-pop .32s var(--ease) both; }
.chat-panel:focus { outline: none; }

.chat-head { display: flex; align-items: center; gap: 12px; padding: 16px 12px 16px 18px; color: #fff; background: radial-gradient(120% 140% at 0% 0%, #0d3a45 0%, var(--chat-ink) 60%); }
.chat-head-text { flex: 1; min-width: 0; }
.chat-head h2 { font-size: 1rem; line-height: 1.4; letter-spacing: -.03em; }
.chat-head p { display: flex; align-items: center; gap: 7px; color: #b9d3d8; font-size: var(--fs-2xs); line-height: 1.5; }
/* Status dot: red until the in-browser AI is connected (pulsing while connecting), then mint. */
.chat-live { width: 7px; height: 7px; border-radius: 50%; background: var(--chat-red); box-shadow: 0 0 0 3px #ff6b7a33; transition: background .4s ease, box-shadow .4s ease; }
.chat-live.is-connecting { animation: chat-pulse 1.2s ease-in-out infinite; }
.chat-live.is-on { background: var(--chat-mint); box-shadow: 0 0 0 3px #86e6d92e; }
.chat-model { font-variant-numeric: tabular-nums; }
.chat-model:not(.is-on) { color: #ffb3bb; }
.chat-icon-btn { display: grid; place-items: center; width: 38px; height: 38px; border-radius: 10px; color: #cfe3e6; transition: background .15s ease, color .15s ease; }
.chat-icon-btn:hover:not(:disabled) { color: #fff; background: #ffffff1a; }
.chat-icon-btn:disabled { opacity: .35; cursor: default; }
.chat-icon-btn:focus-visible { outline: 2px solid var(--chat-mint); outline-offset: 0; }

.chat-avatar { display: grid; place-items: center; flex-shrink: 0; width: 30px; height: 30px; border-radius: 50%; background: #fff; border: 1px solid var(--border); }
.chat-avatar .brand-svg { width: 62%; height: auto; transform: translateX(-4%); }
.chat-avatar.is-lg { width: 40px; height: 40px; border: 0; }
.chat-avatar.is-xl { width: 52px; height: 52px; }

/* Message log */
.chat-log { flex: 1; display: flex; flex-direction: column; gap: 14px; padding: 20px 16px 16px; overflow-y: auto; overscroll-behavior: contain; background: var(--bg-2); }
.chat-welcome { display: flex; flex-direction: column; align-items: center; gap: 8px; padding: 10px 12px 8px; text-align: center; }
.chat-welcome h3 { margin-top: 4px; font-size: 1.0625rem; }
.chat-welcome p { color: var(--muted); font-size: var(--fs-sm); line-height: 1.7; }

.chat-msg { display: flex; align-items: flex-start; gap: 8px; animation: chat-rise .28s var(--ease) both; }
.chat-msg.is-user { justify-content: flex-end; }
.chat-msg-body { display: flex; flex-direction: column; gap: 6px; min-width: 0; max-width: 84%; }
.chat-msg.is-user .chat-msg-body { align-items: flex-end; }
.chat-bubble { padding: 11px 14px; border-radius: 4px 16px 16px 16px; background: #fff; border: 1px solid var(--border); font-size: .9375rem; line-height: 1.65; white-space: pre-wrap; overflow-wrap: anywhere; }
.chat-msg.is-user .chat-bubble { color: #fff; border-color: transparent; border-radius: 16px 4px 16px 16px; background: linear-gradient(180deg, #0e7a86 0%, #0b6f7a 100%); }
.chat-meta { padding: 0 4px; color: var(--faint); font-size: .6875rem; line-height: 1.4; }
.chat-caret { display: inline-block; width: 2px; height: 1em; margin-left: 2px; vertical-align: -2px; background: var(--green); animation: chat-blink 1s steps(2) infinite; }

.chat-actions { display: flex; flex-wrap: wrap; gap: 6px; }
.chat-action { display: inline-flex; align-items: center; gap: 6px; padding: 7px 12px; border: 1px solid #0b6f7a40; border-radius: 999px; color: var(--green); background: #fff; font-size: var(--fs-xs); font-weight: 650; line-height: 1.4; transition: background .15s ease, border-color .15s ease; }
.chat-action:hover { background: var(--green-soft); border-color: var(--green); }

.chat-action.is-reply { color: var(--text); border-color: var(--border-hi); }
.chat-action.is-reply:hover { color: var(--green); }
.chat-action.is-picked { color: var(--green); background: var(--green-soft); border-color: var(--green); }
.chat-action.is-submit { color: #fff; background: var(--green); border-color: var(--green); }
.chat-action.is-submit:hover:not(:disabled) { background: #085c66; }
.chat-action.is-submit:disabled { color: var(--faint); background: var(--surface-2); border-color: var(--border); cursor: default; }

.chat-card { overflow: hidden; border: 1px solid #0b6f7a40; border-radius: 12px; background: #fff; font-size: var(--fs-xs); line-height: 1.55; }
.chat-card-head { display: flex; align-items: center; gap: 7px; padding: 9px 13px; color: var(--green); background: var(--green-soft); font-weight: 700; }
.chat-card dl { display: grid; gap: 6px; padding: 11px 13px 12px; }
.chat-card dl > div { display: grid; grid-template-columns: 92px minmax(0, 1fr); gap: 8px; }
.chat-card dt { color: var(--faint); }
.chat-card dd { color: var(--text); white-space: pre-wrap; overflow-wrap: anywhere; }
.chat-card dl:empty { display: none; }
.chat-card-site, .chat-card-memo { border-top: 1px dashed var(--border); }
.chat-card-site h4 { padding: 10px 13px 0; color: var(--text); font-size: var(--fs-xs); font-weight: 700; letter-spacing: -.02em; }
.chat-card-site dl { padding-top: 6px; }

.chat-typing { display: inline-flex; gap: 4px; padding: 15px 16px; }
.chat-typing i { width: 6px; height: 6px; border-radius: 50%; background: var(--faint); animation: chat-dot 1.2s ease-in-out infinite; }
.chat-typing i:nth-child(2) { animation-delay: .15s; }
.chat-typing i:nth-child(3) { animation-delay: .3s; }

.chat-chips { display: flex; flex-direction: column; align-items: flex-end; gap: 7px; margin-top: auto; padding-top: 6px; }
.chat-chip { padding: 9px 14px; border: 1px solid var(--border-hi); border-radius: 999px; background: #fff; color: var(--text); font-size: var(--fs-sm); font-weight: 550; line-height: 1.4; transition: background .15s ease, border-color .15s ease, color .15s ease; }
.chat-chip:hover { color: var(--green); background: var(--green-soft); border-color: var(--green); }

.chat-error { display: flex; align-items: center; gap: 8px; padding: 10px 12px; border: 1px solid #b5374533; border-radius: 10px; color: var(--red); background: var(--red-soft); font-size: var(--fs-xs); }
.chat-error span { flex: 1; }
.chat-error button { font-weight: 700; text-decoration: underline; text-underline-offset: 3px; }

/* Composer */
.chat-composer { padding: 12px 14px 10px; border-top: 1px solid var(--border); background: #fff; }
.chat-intake { display: flex; align-items: center; gap: 9px; margin-bottom: 9px; padding: 0 2px; font-size: var(--fs-2xs); line-height: 1.4; }
.chat-intake-label { flex-shrink: 0; color: var(--green); font-weight: 700; white-space: nowrap; }
.chat-intake-steps { display: inline-flex; flex-shrink: 0; gap: 3px; }
.chat-intake-steps i { width: 9px; height: 4px; border-radius: 2px; background: var(--border); }
.chat-intake-steps i.is-on { background: var(--green); }
.chat-intake-field { min-width: 0; overflow: hidden; color: var(--muted); text-overflow: ellipsis; white-space: nowrap; }
.chat-intake-cancel { flex-shrink: 0; margin-left: auto; white-space: nowrap; padding: 4px 6px; border-radius: 6px; color: var(--faint); font-weight: 600; }
.chat-intake-cancel:hover { color: var(--red); background: var(--red-soft); }
.chat-input-wrap { display: flex; align-items: flex-end; gap: 8px; padding: 6px 6px 6px 14px; border: 1px solid var(--border-hi); border-radius: 14px; background: #fff; transition: border-color .15s ease, box-shadow .15s ease; }
.chat-input-wrap:focus-within { border-color: var(--green); box-shadow: 0 0 0 3px #0b6f7a1f; }
.chat-input { flex: 1; min-width: 0; max-height: 120px; padding: 7px 0; border: 0; outline: 0; resize: none; color: var(--text); background: transparent; font-family: var(--font-sans); font-size: .9375rem; line-height: 1.5; }
.chat-input::placeholder { color: #6d7e86; }
.chat-send { display: grid; place-items: center; flex-shrink: 0; width: 38px; height: 38px; border-radius: 10px; color: #fff; background: var(--green); transition: background .15s ease, opacity .15s ease; }
.chat-send:hover:not(:disabled) { background: #085c66; }
.chat-send:disabled { opacity: .3; cursor: default; }
.chat-send.is-stop { background: var(--chat-ink); }
.chat-send svg { transform: translateX(-1px); }
.chat-send.is-stop svg { transform: none; fill: currentColor; }
.chat-disclaimer { margin-top: 8px; color: var(--faint); font-size: .6875rem; line-height: 1.5; text-align: center; }

@keyframes chat-pop { from { opacity: 0; transform: translateY(12px) scale(.97); } to { opacity: 1; transform: none; } }
@keyframes chat-rise { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }
@keyframes chat-dot { 0%, 60%, 100% { opacity: .35; transform: none; } 30% { opacity: 1; transform: translateY(-3px); } }
@keyframes chat-blink { to { opacity: 0; } }
@keyframes chat-pulse { 50% { opacity: .35; } }

@media (max-width: 640px) {
  .chat-root { --chat-gap: 16px; }
  .chat-launcher { height: 52px; padding: 0 18px 0 16px; }
  .chat-launcher.is-open { display: none; }
  .chat-teaser { bottom: calc(var(--chat-gap) + 64px); max-width: calc(100vw - 32px); }
  .chat-panel { inset: 0; width: auto; height: 100dvh; border: 0; border-radius: 0; animation-name: chat-sheet; }
  .chat-head { padding-top: max(14px, env(safe-area-inset-top)); }
  .chat-composer { padding-bottom: max(10px, env(safe-area-inset-bottom)); }
  .chat-input { font-size: 16px; } /* prevents iOS focus zoom */
  html.chat-open, html.chat-open body { overflow: hidden; }
}
@keyframes chat-sheet { from { opacity: 0; transform: translateY(24px); } to { opacity: 1; transform: none; } }

@media (prefers-reduced-motion: reduce) {
  .chat-panel, .chat-teaser, .chat-msg, .chat-live { animation: none; }
  .chat-launcher, .chat-launcher:hover { transform: none; }
  .chat-typing i, .chat-caret { animation-duration: 0s; }
}

@media print { .chat-root { display: none; } }

/* Server-rendered messages: the list is a plain wrapper inside the flex log. */
#chat-messages { display: contents; }
/* The intake bar waits until the reply that opened it has been typed out. */
.chat-root.is-busy #chat-intake { display: none !important; }
