/* CaseLab landing: the live chat (js/chat.js). Same tokens as the page: blue = AI, amber = a person. */

.chat-launch {
  position: fixed;
  right: max(20px, env(safe-area-inset-right));
  bottom: max(20px, env(safe-area-inset-bottom));
  z-index: 95;
  display: inline-flex;
  align-items: center;
  gap: 10px;
  height: 52px;
  padding: 0 22px 0 18px;
  border: 0;
  border-radius: 999px;
  background: linear-gradient(180deg, #5cb9ff, #1f8ef5);
  color: #021120;
  font: 600 15px/1 var(--font);
  letter-spacing: -.005em;
  cursor: pointer;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, .45), 0 14px 44px -12px rgba(46, 158, 255, .9);
  transition: transform .3s var(--ease), box-shadow .3s var(--ease), opacity .3s var(--ease);
}
.chat-launch svg { width: 22px; height: 22px; flex: none; }
.chat-launch:hover { transform: translateY(-2px); box-shadow: inset 0 1px 0 rgba(255, 255, 255, .5), 0 22px 60px -14px rgba(46, 158, 255, 1); }
.chat-launch:focus-visible { outline: 2px solid var(--blue-hi); outline-offset: 3px; }
.chat-launch__n {
  position: absolute;
  top: -4px;
  right: -4px;
  display: none;
  min-width: 20px;
  height: 20px;
  padding: 0 6px;
  border-radius: 999px;
  background: var(--amber);
  color: #1d1203;
  font: 700 11.5px/20px var(--font);
  text-align: center;
  box-shadow: 0 0 0 3px var(--bg);
}
.chat-launch.has-unread .chat-launch__n { display: block; }
.chat-open .chat-launch { opacity: 0; pointer-events: none; transform: translateY(8px); }
.review:not([hidden]) ~ .chat-launch { bottom: max(76px, calc(env(safe-area-inset-bottom) + 60px)); }

.chat {
  position: fixed;
  right: max(20px, env(safe-area-inset-right));
  bottom: max(20px, env(safe-area-inset-bottom));
  z-index: 96;
  display: flex;
  flex-direction: column;
  width: 392px;
  height: min(640px, calc(100svh - 40px));
  border-radius: 22px;
  background: rgba(9, 13, 21, .96);
  box-shadow: inset 0 0 0 1px var(--line-2), 0 40px 120px -30px rgba(0, 0, 0, .9), 0 30px 90px -50px rgba(46, 158, 255, .55);
  -webkit-backdrop-filter: blur(18px);
  backdrop-filter: blur(18px);
  color: var(--text);
  font: 400 15px/1.5 var(--font);
  overflow: hidden;
  animation: chatIn .35s var(--ease);
}
.chat[hidden] { display: none; }
@keyframes chatIn { from { opacity: 0; transform: translateY(14px) scale(.98); } }

.chat__h {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 16px 14px 14px 18px;
  border-bottom: 1px solid var(--line);
  background: linear-gradient(180deg, rgba(46, 158, 255, .07), transparent);
}
.chat__mark { width: 34px; height: 34px; flex: none; }
.chat__who { display: grid; gap: 2px; min-width: 0; flex: 1; }
.chat__who strong { font-weight: 600; font-size: 15.5px; letter-spacing: -.01em; }
.chat__status { display: flex; align-items: center; gap: 7px; min-width: 0; padding-left: 1px; font: 500 11.5px/1.3 var(--mono); letter-spacing: .04em; color: var(--muted); }
.chat__status span { min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chat__status i { width: 7px; height: 7px; flex: none; border-radius: 50%; background: var(--blue); box-shadow: 0 0 10px var(--blue); }
.chat__status.is-human i { background: var(--amber); box-shadow: 0 0 10px var(--amber); }
.chat__x {
  display: grid;
  place-items: center;
  width: 38px;
  height: 38px;
  flex: none;
  border: 0;
  border-radius: 12px;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  transition: background .2s, color .2s;
}
.chat__x svg { width: 18px; height: 18px; }
.chat__x:hover { background: rgba(255, 255, 255, .06); color: var(--text); }
.chat__x:focus-visible, .chat__q:focus-visible, .chat__send:focus-visible, .chat__retry:focus-visible { outline: 2px solid var(--blue-hi); outline-offset: 2px; }

.chat__log {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 18px 16px 10px;
  overflow-y: auto;
  overscroll-behavior: contain;
  scrollbar-width: thin;
  scrollbar-color: var(--line-2) transparent;
}

.chat__row { display: flex; flex-direction: column; max-width: 86%; }
.chat__row--ours { align-self: flex-start; align-items: flex-start; }
.chat__row--mine { align-self: flex-end; align-items: flex-end; }
.chat__by { margin: 6px 0 4px 4px; font: 500 10.5px/1 var(--mono); letter-spacing: .1em; text-transform: uppercase; color: var(--blue-hi); }
.chat__by--operator { color: var(--amber); }
.chat__b {
  padding: 10px 14px;
  border-radius: 18px 18px 18px 6px;
  background: var(--panel-2);
  box-shadow: inset 0 0 0 1px var(--line);
  overflow-wrap: anywhere;
}
.chat__row--ours[data-kind="operator"] .chat__b { box-shadow: inset 0 0 0 1px rgba(255, 180, 84, .22); }
.chat__row--mine .chat__b {
  border-radius: 18px 18px 6px 18px;
  background: linear-gradient(180deg, #4aaeff, #1f8ef5);
  color: #021120;
  box-shadow: none;
}
.chat__row--mine.is-sending .chat__b { opacity: .7; }
.chat__row--mine.is-failed .chat__b { background: #283246; color: var(--text); }
.chat__t p { margin: 0; }
.chat__t p + p, .chat__t p + ul, .chat__t p + ol, .chat__t ul + p, .chat__t ol + p { margin-top: 8px; }
.chat__t ul, .chat__t ol { margin: 4px 0 0; padding-left: 20px; }
.chat__t li + li { margin-top: 2px; }
.chat__t a { color: var(--blue-hi); text-underline-offset: 2px; }
.chat__row--mine .chat__t a { color: #021120; }
.chat__t code { padding: 1px 5px; border-radius: 6px; background: rgba(255, 255, 255, .07); font: 13px/1.4 var(--mono); }
.chat__state { margin: 4px 6px 0; font-size: 12px; color: var(--dim); }
.chat__row--mine.is-failed .chat__state { color: var(--red); }
.chat__retry { margin-left: 2px; padding: 0; border: 0; background: none; color: var(--blue-hi); font: inherit; font-weight: 600; cursor: pointer; text-decoration: underline; text-underline-offset: 2px; }

.chat__sys { align-self: center; max-width: 92%; margin: 6px 0; padding: 6px 12px; border-radius: 999px; background: rgba(255, 255, 255, .035); font-size: 12.5px; line-height: 1.4; color: var(--muted); text-align: center; }
.chat__sys--human { color: var(--amber); background: rgba(255, 180, 84, .07); }
.chat__sys--warn { color: var(--red); }

.chat__typing .chat__b { display: flex; gap: 5px; padding: 14px 16px; }
.chat__typing i { width: 7px; height: 7px; border-radius: 50%; background: var(--muted); animation: chatDot 1.2s infinite ease-in-out; }
.chat__typing i:nth-child(2) { animation-delay: .15s; }
.chat__typing i:nth-child(3) { animation-delay: .3s; }
@keyframes chatDot { 0%, 60%, 100% { opacity: .3; transform: none; } 30% { opacity: 1; transform: translateY(-3px); } }

.chat__qs { display: flex; flex-wrap: wrap; gap: 8px; padding: 0 16px 10px; }
.chat__qs:empty { display: none; }
.chat__q {
  padding: 8px 13px;
  border: 0;
  border-radius: 999px;
  background: rgba(46, 158, 255, .08);
  box-shadow: inset 0 0 0 1px rgba(46, 158, 255, .3);
  color: var(--blue-hi);
  font: 500 13.5px/1.2 var(--font);
  cursor: pointer;
  transition: background .2s, box-shadow .2s;
}
.chat__q:hover { background: rgba(46, 158, 255, .16); box-shadow: inset 0 0 0 1px rgba(46, 158, 255, .55); }

.chat__form {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  margin: 0 12px;
  padding: 6px 6px 6px 16px;
  border-radius: 18px;
  background: var(--panel);
  box-shadow: inset 0 0 0 1px var(--line-2);
  transition: box-shadow .2s;
}
.chat__form:focus-within { box-shadow: inset 0 0 0 1px rgba(46, 158, 255, .55), 0 0 0 4px rgba(46, 158, 255, .1); }
.chat__form textarea {
  flex: 1;
  min-height: 40px;
  max-height: 132px;
  padding: 9px 0;
  border: 0;
  background: transparent;
  color: var(--text);
  font: 400 15px/1.45 var(--font);
  resize: none;
  outline: none;
}
.chat__form textarea::placeholder { color: var(--dim); }
.chat__send {
  display: grid;
  place-items: center;
  width: 40px;
  height: 40px;
  flex: none;
  border: 0;
  border-radius: 13px;
  background: linear-gradient(180deg, #5cb9ff, #1f8ef5);
  color: #021120;
  cursor: pointer;
  transition: transform .2s var(--ease), opacity .2s;
}
.chat__send svg { width: 18px; height: 18px; }
.chat__send:hover { transform: translateY(-1px); }

.chat__note { margin: 8px 16px 12px; font-size: 11.5px; line-height: 1.45; color: var(--dim); }
.chat__note a { color: var(--muted); text-underline-offset: 2px; white-space: nowrap; }
.chat__note a:hover { color: var(--text); }

@media (max-width: 820px) {
  .chat-launch { width: 56px; height: 56px; padding: 0; justify-content: center; }
  .chat-launch__l { display: none; }
}

/* A phone: the chat takes the screen. */
@media (max-width: 560px) {
  .chat {
    inset: 0;
    width: auto;
    height: 100%;
    height: 100dvh;
    border-radius: 0;
    padding: env(safe-area-inset-top) env(safe-area-inset-right) 0 env(safe-area-inset-left);
  }
  .chat__note { margin-bottom: max(12px, env(safe-area-inset-bottom)); }
  .chat__form textarea { font-size: 16px; } /* no zoom on focus in iOS Safari */
  html.chat-open, html.chat-open body { overflow: hidden; }
}

@media (prefers-reduced-motion: reduce) {
  .chat, .chat-launch, .chat__typing i { animation: none; transition: none; }
}
