/* ============================================================
   ServerBorn AI chat widget — terminal-window aesthetic
   ============================================================ */

.sb-chat-root { position: fixed; right: calc(22px + env(safe-area-inset-right, 0px)); bottom: calc(22px + env(safe-area-inset-bottom, 0px)); z-index: 2147483600; font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif; max-width: 100%; }
.sb-chat-root *, .sb-chat-root *::before, .sb-chat-root *::after { box-sizing: border-box; }
.sb-mono { font-family: 'JetBrains Mono', ui-monospace, Consolas, monospace; }

/* ---------- Launcher (round chat-bubble button) ---------- */
.sb-launcher {
  width: 58px; height: 58px; border-radius: 50%; border: 0; cursor: pointer;
  background: linear-gradient(135deg, #2ed573, #00d4ff);
  display: grid; place-items: center;
  color: #1d2a44;
  box-shadow: 0 16px 36px rgba(46,213,115,.35), 0 0 0 1px rgba(46,213,115,.45), inset 0 1px 0 rgba(255,255,255,.30), 0 0 40px rgba(46,213,115,.10);
  transition: transform .18s ease, box-shadow .18s ease;
  position: relative;
}
.sb-launcher:hover { transform: translateY(-2px) scale(1.05); box-shadow: 0 22px 48px rgba(46,213,115,.50), 0 0 0 1px rgba(46,213,115,.65), inset 0 1px 0 rgba(255,255,255,.30), 0 0 60px rgba(46,213,115,.18); }
.sb-launcher svg { width: 26px; height: 26px; position: relative; z-index: 2; }
/* Halo rings pulsing outward from the launcher */
.sb-launcher::before, .sb-launcher::after {
  content: ""; position: absolute; inset: 0; border-radius: 50%;
  border: 2px solid rgba(46,213,115,.55);
  pointer-events: none;
  animation: sb-halo 2.4s ease-out infinite;
}
.sb-launcher::after { animation-delay: 1.2s; }
@keyframes sb-halo {
  0%   { opacity: .85; transform: scale(1); }
  80%, 100% { opacity: 0; transform: scale(1.65); }
}
.sb-chat-root.is-open .sb-launcher { display: none; }

/* ---------- Panel (terminal window) ---------- */
.sb-panel {
  position: fixed; right: calc(22px + env(safe-area-inset-right, 0px)); bottom: calc(22px + env(safe-area-inset-bottom, 0px));
  width: 400px; height: min(640px, calc(100dvh - 44px));
  max-width: calc(100dvw - 28px);
  display: none; flex-direction: column;
  background: linear-gradient(180deg, #0c1622 0%, #07101a 100%);
  border: 1px solid rgba(46,213,115,.28);
  border-radius: 16px; overflow: hidden;
  box-shadow: 0 32px 72px rgba(0,0,0,.55), 0 0 0 1px rgba(46,213,115,.12), 0 0 60px rgba(46,213,115,.10);
  isolation: isolate;
  transition: width .22s ease, height .22s ease;
}
.sb-chat-root.is-open .sb-panel { display: flex; animation: sb-rise .22s cubic-bezier(.16,.84,.44,1); }
.sb-chat-root.is-expanded .sb-panel { width: min(560px, calc(100dvw - 28px)); height: min(760px, calc(100dvh - 44px)); }
@keyframes sb-rise { from { opacity: 0; transform: translateY(12px) scale(.98); } to { opacity: 1; transform: none; } }

/* Subtle scanlines + animated glow border */
.sb-panel::before {
  content: ""; position: absolute; inset: 0; pointer-events: none; z-index: 1;
  background: repeating-linear-gradient(180deg, rgba(255,255,255,.015) 0 1px, transparent 1px 4px);
  mix-blend-mode: overlay;
}
.sb-panel::after {
  content: ""; position: absolute; top: 0; left: 24px; right: 24px; height: 1px; pointer-events: none; z-index: 2;
  background: linear-gradient(90deg, transparent, rgba(46,213,115,.6), rgba(0,212,255,.5), transparent);
  opacity: .9;
}

/* ---------- Terminal title bar header ---------- */
.sb-head {
  display: flex; align-items: center; gap: 12px;
  padding: 12px 14px;
  background: rgba(4,8,13,.85);
  border-bottom: 1px solid rgba(255,255,255,.05);
  font-family: 'JetBrains Mono', ui-monospace, monospace;
  font-size: 11.5px; color: #aab7cc;
  position: relative; z-index: 3;
}
.sb-dots { display: inline-flex; gap: 6px; flex-shrink: 0; }
.sb-dots span { width: 10px; height: 10px; border-radius: 50%; display: inline-block; }
.sb-dots .r { background: #f43f5e; }
.sb-dots .y { background: #f59e0b; }
.sb-dots .g { background: #2ed573; box-shadow: 0 0 6px rgba(46,213,115,.6); }
.sb-head .sb-ttl { flex: 1; min-width: 0; text-align: center; color: #e8edf3; letter-spacing: .02em; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sb-head .sb-ttl .pr { color: #2ed573; margin-right: 6px; }
.sb-head .sb-ttl .sep { color: #4d586a; margin: 0 6px; }
.sb-head .sb-ttl .live { color: #2ed573; display: inline-flex; align-items: center; gap: 5px; font-size: 10px; letter-spacing: .14em; text-transform: uppercase; }
.sb-head .sb-ttl .live::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: #2ed573; box-shadow: 0 0 6px #2ed573; animation: sb-pulse 1.8s ease-in-out infinite; }
.sb-head-actions { display: inline-flex; gap: 2px; flex-shrink: 0; }
.sb-head-actions button { width: 30px; height: 30px; background: transparent; border: 0; border-radius: 7px; color: #6b7785; cursor: pointer; display: grid; place-items: center; transition: color .15s ease, background .15s ease; }
.sb-head-actions button:hover { color: #f3f7fb; background: rgba(255,255,255,.06); }
.sb-head-actions button svg { width: 14px; height: 14px; }

/* ---------- Status line below header ---------- */
.sb-status {
  padding: 8px 16px;
  background: rgba(7,16,26,.65);
  border-bottom: 1px solid rgba(255,255,255,.04);
  font-family: 'JetBrains Mono', ui-monospace, monospace;
  font-size: 10px; letter-spacing: .12em; color: #4d586a; text-transform: uppercase;
  display: flex; gap: 18px; align-items: center; flex-wrap: wrap;
  position: relative; z-index: 3;
}
.sb-status b { color: #2ed573; font-weight: 600; letter-spacing: .12em; }
.sb-status .sep { color: #2a3441; }

/* ---------- Pre-chat (welcome screen) ---------- */
.sb-prechat { padding: 24px 20px 18px; flex: 1; display: flex; flex-direction: column; justify-content: center; overflow-y: auto; gap: 18px; position: relative; z-index: 2; }
.sb-prechat-hero { text-align: center; }
.sb-prechat-hero .sb-avatar-lg {
  width: 72px; height: 72px; margin: 0 auto 16px; border-radius: 20px;
  background: linear-gradient(180deg, rgba(46,213,115,.06), rgba(0,212,255,.03)), #07101a;
  border: 1px solid rgba(46,213,115,.35);
  display: grid; place-items: center;
  box-shadow: 0 0 36px rgba(46,213,115,.25), inset 0 1px 0 rgba(255,255,255,.04);
  position: relative;
}
.sb-prechat-hero .sb-avatar-lg::after { content: ""; position: absolute; inset: -10px; border-radius: 26px; border: 1px solid rgba(46,213,115,.30); animation: sb-ring 2.4s ease-in-out infinite; pointer-events: none; }
@keyframes sb-ring { 0%,100% { opacity: .55; transform: scale(1); } 50% { opacity: 0; transform: scale(1.18); } }
.sb-prechat-hero .sb-avatar-lg svg { width: 42px; height: 42px; }
.sb-prechat-hero h3 { margin: 0 0 8px; font-size: 18px; font-weight: 700; color: #f3f7fb; letter-spacing: -.01em; }
.sb-prechat-hero p { margin: 0; font-size: 13px; color: #aab7cc; line-height: 1.55; max-width: 300px; margin-inline: auto; }

/* ---------- Suggestion chips — mirror the hero badge bar ---------- */
.sb-suggest { display: flex; flex-wrap: wrap; gap: 6px; justify-content: center; }
.sb-suggest .b {
  padding: 6px 12px;
  background: rgba(7,16,26,.7);
  border: 1px solid rgba(255,255,255,.13);
  border-radius: 999px;
  -webkit-backdrop-filter: blur(10px); backdrop-filter: blur(10px);
  color: #aab7cc;
  white-space: nowrap;
  display: inline-flex; align-items: center; gap: 6px;
  line-height: 1;
  font-family: 'JetBrains Mono', ui-monospace, monospace;
  font-size: 10.5px; letter-spacing: .14em; text-transform: uppercase; font-weight: 600;
  cursor: pointer;
  transition: transform .15s ease, border-color .15s ease, color .15s ease, box-shadow .15s ease;
}
.sb-suggest .b:hover { transform: translateY(-1px); }
.sb-suggest .b.acc { color: #2ed573; border-color: rgba(46,213,115,.32); background: rgba(46,213,115,.07); }
.sb-suggest .b.cy  { color: #00d4ff; border-color: rgba(0,212,255,.32);  background: rgba(0,212,255,.06); }
.sb-suggest .b.am  { color: #f59e0b; border-color: rgba(245,158,11,.32); background: rgba(245,158,11,.06); }
.sb-suggest .b.vi  { color: #9b6bff; border-color: rgba(155,107,255,.34);background: rgba(155,107,255,.07); }
.sb-suggest .b.acc:hover { box-shadow: 0 6px 18px rgba(46,213,115,.18); border-color: rgba(46,213,115,.55); }
.sb-suggest .b.cy:hover  { box-shadow: 0 6px 18px rgba(0,212,255,.18);  border-color: rgba(0,212,255,.55); }
.sb-suggest .b.am:hover  { box-shadow: 0 6px 18px rgba(245,158,11,.20); border-color: rgba(245,158,11,.55); }
.sb-suggest .b.vi:hover  { box-shadow: 0 6px 18px rgba(155,107,255,.20); border-color: rgba(155,107,255,.55); }

/* ---------- Prechat form ---------- */
.sb-prechat-form { display: flex; flex-direction: column; gap: 10px; }
.sb-prechat-form .sb-input-wrap { display: flex; align-items: flex-start; gap: 8px; background: #0e1a23; border: 1px solid rgba(255,255,255,.10); border-radius: 12px; padding: 10px 12px; transition: border-color .15s ease, box-shadow .15s ease; }
.sb-prechat-form .sb-input-wrap:focus-within { border-color: rgba(46,213,115,.55); box-shadow: 0 0 0 3px rgba(46,213,115,.10); }
.sb-prechat-form .sb-input-wrap .sb-pr-mono { font-family: 'JetBrains Mono', ui-monospace, monospace; color: #2ed573; font-size: 13px; padding-top: 2px; flex-shrink: 0; user-select: none; }
.sb-prechat-form textarea {
  flex: 1; min-width: 0; resize: none; min-height: 22px; max-height: 110px;
  background: transparent; border: 0; outline: 0;
  color: #f3f7fb; font-family: inherit; font-size: 14px; line-height: 1.5;
}
.sb-prechat-form textarea::placeholder { color: #4d586a; }
.sb-prechat-form .sb-start {
  width: 100%; padding: 11px; border: 0; border-radius: 12px; cursor: pointer;
  background: linear-gradient(135deg, #2ed573, #00d4ff); color: #1d2a44;
  font-family: inherit; font-size: 13.5px; font-weight: 700; letter-spacing: .02em;
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  box-shadow: 0 8px 22px rgba(46,213,115,.28);
  transition: filter .15s ease, transform .15s ease;
}
.sb-prechat-form .sb-start:hover { filter: brightness(1.08); transform: translateY(-1px); }
.sb-prechat-form .sb-start svg { width: 14px; height: 14px; }
.sb-prechat-link { text-align: center; font-size: 11.5px; color: #6b7785; }
.sb-prechat-link a { color: #aab7cc; text-decoration: none; border-bottom: 1px dashed rgba(255,255,255,.20); }
.sb-prechat-link a:hover { color: #2ed573; border-color: #2ed573; }

/* ---------- Messages area ---------- */
.sb-messages { flex: 1; overflow-y: auto; padding: 14px 12px; display: none; flex-direction: column; gap: 14px; scrollbar-width: thin; scrollbar-color: #1f2a36 transparent; position: relative; z-index: 2; }
.sb-messages::-webkit-scrollbar { width: 8px; }
.sb-messages::-webkit-scrollbar-thumb { background: #1f2a36; border-radius: 4px; }
.sb-chat-root.is-chatting .sb-prechat { display: none; }
.sb-chat-root.is-chatting .sb-messages { display: flex; }
.sb-chat-root.is-chatting .sb-input-bar { display: flex; }
.sb-chat-root.is-chatting .sb-foot { display: block; }

.sb-bubble { display: flex; gap: 9px; max-width: 92%; }
.sb-bubble.sb-ai { align-self: flex-start; }
.sb-bubble.sb-user { align-self: flex-end; flex-direction: row-reverse; }
.sb-bubble .sb-avatar-sm { width: 28px; height: 28px; border-radius: 8px; flex-shrink: 0; display: grid; place-items: center; }
.sb-bubble.sb-ai .sb-avatar-sm { background: #07101a; border: 1px solid rgba(46,213,115,.35); box-shadow: 0 0 10px rgba(46,213,115,.18); }
.sb-bubble.sb-user .sb-avatar-sm { background: rgba(0,212,255,.10); border: 1px solid rgba(0,212,255,.35); color: #00d4ff; }
.sb-bubble .sb-avatar-sm svg { width: 18px; height: 18px; }
.sb-bubble .sb-stack { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.sb-bubble.sb-user .sb-stack { align-items: flex-end; }
.sb-bubble .sb-pre { font-family: 'JetBrains Mono', ui-monospace, monospace; font-size: 10px; letter-spacing: .16em; text-transform: uppercase; color: #6b7785; padding: 0 6px; }
.sb-bubble.sb-ai .sb-pre { color: #2ed573; }
.sb-bubble.sb-user .sb-pre { color: #00d4ff; }
.sb-bubble .sb-body { padding: 11px 14px; border-radius: 12px; font-size: 14px; line-height: 1.6; color: #dfe4eb; word-wrap: break-word; }
.sb-bubble.sb-ai .sb-body { background: #0e1a23; border: 1px solid rgba(46,213,115,.20); border-left: 3px solid #2ed573; border-top-left-radius: 4px; }
.sb-bubble.sb-user .sb-body { background: linear-gradient(135deg, rgba(0,212,255,.18), rgba(0,212,255,.08)); border: 1px solid rgba(0,212,255,.30); border-right: 3px solid #00d4ff; border-top-right-radius: 4px; color: #f3f7fb; }
.sb-bubble.sb-error .sb-body { background: rgba(244,63,94,.10); border-color: rgba(244,63,94,.35); border-left-color: #f43f5e; color: #ffd9df; }

/* Inline markdown */
.sb-bubble .sb-body strong { font-weight: 700; color: #ffffff; }
.sb-bubble .sb-body a { color: #2ed573; text-decoration: none; border-bottom: 1px dashed rgba(46,213,115,.5); padding-bottom: 1px; transition: color .15s ease, border-color .15s ease; }
.sb-bubble .sb-body a:hover { color: #00d4ff; border-bottom-color: #00d4ff; }
.sb-bubble .sb-body code { background: rgba(46,213,115,.10); padding: 1px 6px; border-radius: 4px; font-family: 'JetBrains Mono', ui-monospace, monospace; font-size: .9em; color: #2ed573; }

/* Block-level: paragraphs and bullet lists */
.sb-bubble .sb-body .sb-p { margin: 0 0 8px; }
.sb-bubble .sb-body .sb-p:last-child { margin-bottom: 0; }
.sb-bubble .sb-body .sb-ul { margin: 4px 0 8px; padding: 0; list-style: none; }
.sb-bubble .sb-body .sb-ul:last-child { margin-bottom: 0; }
.sb-bubble .sb-body .sb-ul li { padding-left: 18px; position: relative; margin-bottom: 5px; color: #dfe4eb; }
.sb-bubble .sb-body .sb-ul li:last-child { margin-bottom: 0; }
.sb-bubble .sb-body .sb-ul li::before { content: "›"; position: absolute; left: 4px; top: -1px; color: #2ed573; font-family: 'JetBrains Mono', ui-monospace, monospace; font-weight: 700; font-size: 16px; }
.sb-bubble .sb-body .sb-ul li strong { color: #ffffff; }

/* ---------- Typing indicator ---------- */
.sb-typing { display: none; gap: 9px; max-width: 88%; align-self: flex-start; padding: 0 12px; margin-bottom: 4px; }
.sb-typing.sb-on { display: flex; }
.sb-typing .sb-avatar-sm { width: 28px; height: 28px; border-radius: 8px; background: #07101a; border: 1px solid rgba(46,213,115,.35); box-shadow: 0 0 10px rgba(46,213,115,.18); display: grid; place-items: center; flex-shrink: 0; }
.sb-typing .sb-avatar-sm svg { width: 18px; height: 18px; }
.sb-typing .sb-dots { padding: 14px 16px; background: #0e1a23; border: 1px solid rgba(46,213,115,.20); border-left: 3px solid #2ed573; border-radius: 12px; border-top-left-radius: 4px; display: inline-flex; gap: 5px; align-items: center; }
.sb-typing .sb-dots i { width: 6px; height: 6px; border-radius: 50%; background: #2ed573; opacity: .25; animation: sb-bounce 1.2s ease-in-out infinite; box-shadow: 0 0 6px rgba(46,213,115,.5); }
.sb-typing .sb-dots i:nth-child(2) { animation-delay: .15s; }
.sb-typing .sb-dots i:nth-child(3) { animation-delay: .30s; }
@keyframes sb-bounce { 0%,100% { opacity: .25; transform: translateY(0); } 50% { opacity: 1; transform: translateY(-3px); } }

/* ---------- Input bar (mono $ prefix) ---------- */
.sb-input-bar { display: none; align-items: center; gap: 8px; padding: 10px 12px 12px; border-top: 1px solid rgba(255,255,255,.06); background: rgba(4,8,13,.85); position: relative; z-index: 3; }
.sb-input-bar .sb-input-wrap { flex: 1; display: flex; align-items: center; gap: 8px; background: #0e1a23; border: 1px solid rgba(255,255,255,.10); border-radius: 12px; padding: 6px 12px; transition: border-color .15s ease, box-shadow .15s ease; }
.sb-input-bar .sb-input-wrap:focus-within { border-color: rgba(46,213,115,.55); box-shadow: 0 0 0 3px rgba(46,213,115,.10); }
.sb-input-bar .sb-pr-mono { font-family: 'JetBrains Mono', ui-monospace, monospace; color: #2ed573; font-size: 13px; flex-shrink: 0; user-select: none; }
.sb-input-bar input { flex: 1; min-width: 0; background: transparent; border: 0; outline: 0; color: #f3f7fb; font-family: inherit; font-size: 14px; padding: 6px 0; }
.sb-input-bar input::placeholder { color: #4d586a; }
.sb-input-bar button.sb-send { width: 38px; height: 38px; border: 0; border-radius: 10px; cursor: pointer; background: linear-gradient(135deg, #2ed573, #00d4ff); color: #1d2a44; display: grid; place-items: center; box-shadow: 0 4px 14px rgba(46,213,115,.30); transition: filter .15s ease, transform .15s ease; flex-shrink: 0; }
.sb-input-bar button.sb-send:hover { filter: brightness(1.08); transform: translateY(-1px); }
.sb-input-bar button.sb-send:disabled { filter: grayscale(.4) brightness(.65); cursor: not-allowed; transform: none; }
.sb-input-bar button.sb-send svg { width: 15px; height: 15px; }

/* ---------- Footer ---------- */
.sb-foot { display: none; padding: 7px 14px 11px; font-family: 'JetBrains Mono', ui-monospace, monospace; font-size: 10px; letter-spacing: .08em; color: #4d586a; text-align: center; background: rgba(4,8,13,.92); border-top: 1px solid rgba(255,255,255,.04); position: relative; z-index: 3; }
.sb-foot a { color: #6b7785; text-decoration: none; }
.sb-foot a:hover { color: #2ed573; }

/* ---------- Narrower panel ---------- */
@media (max-width: 480px), (max-width: 420px) {
  .sb-head .sb-ttl .sep, .sb-head .sb-ttl .live { display: none; }
  .sb-status { font-size: 9.5px; gap: 10px; padding: 7px 12px; }
}

/* ---------- Mobile (no horizontal push, true fullscreen panel) ---------- */
@media (max-width: 540px) {
  .sb-chat-root { right: calc(14px + env(safe-area-inset-right, 0px)); bottom: calc(14px + env(safe-area-inset-bottom, 0px)); }
  .sb-launcher { width: 54px; height: 54px; }
  .sb-launcher svg { width: 23px; height: 23px; }
  .sb-panel, .sb-chat-root.is-expanded .sb-panel { position: fixed !important; left: 8px !important; right: 8px !important; top: auto !important; bottom: calc(10px + env(safe-area-inset-bottom, 0px)) !important; width: auto !important; height: min(680px, calc(100dvh - 20px - env(safe-area-inset-bottom, 0px))) !important; max-width: none !important; max-height: none !important; border-radius: 16px; }
  .sb-head { padding: 10px 12px; gap: 10px; }
  .sb-head .sb-ttl { font-size: 11px; }
  .sb-head .sb-ttl .sep, .sb-head .sb-ttl .live { display: none; }
  .sb-head-actions button { width: 28px; height: 28px; }
  .sb-status { font-size: 9.5px; gap: 10px; padding: 7px 12px; flex-wrap: wrap; }
  .sb-prechat { padding: 18px 16px 14px; }
  .sb-bubble { max-width: 94%; }
  .sb-foot { font-size: 9px; letter-spacing: .06em; }
}

@media (prefers-reduced-motion: reduce) {
  .sb-launcher .sb-pulse, .sb-head .sb-ttl .live::before, .sb-prechat-hero .sb-avatar-lg::after, .sb-typing .sb-dots i, .sb-panel { animation: none !important; }
}

/* Prevent iOS auto-zoom on input focus (font-size must be >= 16px).
   Without this, focusing the chat input rescales the page and overflows. */
@media (max-width: 540px) {
  .sb-prechat-form textarea,
  .sb-input-bar input {
    font-size: 16px !important;
  }
}

/* ============================================================ *
 *  Pre-chat textarea size + centering fix.                     *
 *                                                              *
 *  Bug: the textarea was growing to ~170px tall because         *
 *  `align-items: flex-start` on the wrap pinned the cursor to   *
 *  the top of an oversized box. The wrap's natural height +     *
 *  the textarea's max-height: 110px combined with the wrap      *
 *  padding (10px × 2 = 20px) yielded a 130px+ block, and        *
 *  flex-start put the placeholder at the very top.              *
 *                                                              *
 *  Fix: lock the textarea to a comfortable 2-line height (44px) *
 *  + center it vertically in the wrap. Matches the active-chat  *
 *  input's visual density.                                      *
 * ============================================================ */
.sb-prechat-form .sb-input-wrap {
  align-items: center !important;
  padding: 8px 12px !important;
  min-height: 56px;
}
.sb-prechat-form textarea {
  min-height: 40px !important;
  height: 40px !important;
  max-height: 80px !important;
  line-height: 1.4 !important;
  padding: 0 !important;
}
