/* Browse-mode floating tools and AI chat modal */
#browse-stack{
  position:fixed;
  right:28px;
  bottom:28px;
  z-index:300;
  display:flex;
  flex-direction:column;
  align-items:flex-end;
  gap:8px;
}

body[data-mode="ask"] #browse-stack{display:none!important}

body.chat-open #browse-stack{
  right:28px;
  bottom:28px;
  width:380px;
  transform:none;
  align-items:flex-end;
}

.bs-buttons{display:flex;flex-direction:column;align-items:flex-end;gap:8px}
body.chat-open .bs-buttons{display:none}

.bs-btn{
  display:inline-flex;
  align-items:center;
  gap:6px;
  border-radius:20px;
  cursor:pointer;
  font-family:var(--font-sans);
  font-weight:500;
  white-space:nowrap;
  transition:all .2s;
  border:none;
  letter-spacing:-.01em;
  font-size:13px;
  padding:9px 20px;
  background:var(--gradient-accent);
  color:white;
  box-shadow:0 4px 16px rgba(30,58,110,.28);
}

.bs-btn:hover{box-shadow:0 6px 22px rgba(30,58,110,.40);transform:translateY(-1px)}
#chat-pill-btn.active{opacity:.85;box-shadow:0 2px 8px rgba(30,58,110,.20)}

.chat-modal,
.chat-body,
.chat-container,
.modal-content{
  overflow:hidden;
}

.chat-modal{
  width:380px;
  height:min(560px,calc(100dvh - 96px));
  display:none;
  flex-direction:column;
  border-radius:16px;
  background:var(--surface);
  border:1px solid rgba(226,221,214,.9);
  box-shadow:0 24px 80px rgba(28,27,25,.18);
  animation:cbSlide .25s ease;
}

.chat-modal.open{display:flex}

.cb-panel{display:none}
.cb-panel.open{display:flex}

@keyframes cbSlide{from{opacity:0;transform:translateY(12px)}to{opacity:1;transform:translateY(0)}}

.chat-header{
  flex-shrink:0;
  background:var(--gradient-accent);
  padding:16px 20px;
  display:flex;
  align-items:center;
  gap:12px;
}

.cb-head-icon{
  width:36px;
  height:36px;
  border-radius:50%;
  background:rgba(255,255,255,.16);
  display:flex;
  align-items:center;
  justify-content:center;
  flex-shrink:0;
}

.cb-head-icon svg{width:18px;height:18px;fill:white}
.cb-head-text{flex:1;min-width:0}
.cb-head-title{font-family:var(--font-serif);font-size:17px;font-weight:500;color:white;line-height:1.2}
.cb-head-sub{font-size:11px;color:rgba(255,255,255,.68);margin-top:2px;font-weight:300}

.cb-head-close{
  width:28px;
  height:28px;
  border:none;
  border-radius:50%;
  background:rgba(255,255,255,.14);
  color:white;
  cursor:pointer;
  display:flex;
  align-items:center;
  justify-content:center;
  font-size:14px;
  line-height:1;
  transition:background .2s,transform .2s;
  flex-shrink:0;
}

.cb-head-close:hover{background:rgba(255,255,255,.24);transform:scale(1.03)}

.chat-messages-wrapper{
  flex:1;
  min-height:0;
  overflow:hidden;
  display:flex;
  flex-direction:column;
  background:linear-gradient(180deg,var(--surface) 0%,var(--bg) 100%);
}

.chat-messages{
  flex:1;
  min-height:0;
  overflow-y:auto;
  overflow-x:hidden;
  overscroll-behavior:contain;
  padding:16px;
  scroll-behavior:smooth;
  display:flex;
  flex-direction:column;
  gap:12px;
}

.chat-messages::-webkit-scrollbar{width:8px}
.chat-messages::-webkit-scrollbar-track{background:transparent}
.chat-messages::-webkit-scrollbar-thumb{background:rgba(120,120,140,.28);border-radius:999px}
.chat-messages::-webkit-scrollbar-thumb:hover{background:rgba(120,120,140,.38)}

.cb-msg{
  display:flex;
  flex-direction:column;
  gap:8px;
  max-width:88%;
}

.cb-msg.bot{align-self:flex-start}
.cb-msg.user{align-self:flex-end}
.cb-msg.assistant-message{max-width:88%}

.cb-bubble{
  padding:10px 14px;
  border-radius:12px;
  font-size:13px;
  line-height:1.65;
}

.cb-msg.bot .cb-bubble{
  background:var(--bg-warm);
  border:1px solid var(--border);
  color:var(--text-primary);
  border-radius:4px 12px 12px 12px;
}

.cb-msg.assistant-message .cb-bubble{
  padding:12px 15px;
  font-size:13px;
  line-height:1.65;
}

.cb-msg.user .cb-bubble{
  background:var(--gradient-accent);
  color:white;
  border-radius:12px 4px 12px 12px;
}

.cb-msg-time{font-size:10px;color:var(--text-muted);padding:0 4px}
.cb-msg.user .cb-msg-time{text-align:right}

.cb-typing{
  align-self:flex-start;
  background:var(--bg-warm);
  border:1px solid var(--border);
  padding:12px 16px;
  border-radius:4px 12px 12px 12px;
  display:none;
}

.cb-typing.vis{display:flex;align-items:center;gap:4px}
.cb-dot{width:5px;height:5px;border-radius:50%;background:var(--text-muted);animation:cbDot 1.2s infinite ease-in-out}
.cb-dot:nth-child(2){animation-delay:.2s}
.cb-dot:nth-child(3){animation-delay:.4s}
@keyframes cbDot{0%,80%,100%{transform:scale(.6);opacity:.4}40%{transform:scale(1);opacity:1}}

.chat-suggestions{
  display:flex;
  flex-wrap:wrap;
  gap:6px;
  margin-top:6px;
  padding:0;
  flex-shrink:0;
  max-width:100%;
}

.cb-sugg{
  font-size:11px;
  padding:6px 12px;
  border:1px solid rgba(226,221,214,.95);
  border-radius:999px;
  background:rgba(255,255,255,.82);
  color:var(--text-secondary);
  cursor:pointer;
  transition:all .2s;
  font-family:var(--font-sans);
  line-height:1.3;
  text-align:left;
  box-shadow:0 4px 14px rgba(28,27,25,.04);
}

.cb-sugg:hover{
  border-color:var(--accent-light);
  color:var(--accent-mid);
  background:var(--gradient-subtle);
  transform:translateY(-1px);
}

.chat-input-area{
  flex-shrink:0;
  position:relative;
  background:white;
  padding:12px 16px 10px;
  border-top:1px solid rgba(0,0,0,.06);
}

.chat-input-row{
  display:flex;
  align-items:flex-end;
  gap:8px;
}

.cb-input{
  flex:1;
  min-width:0;
  max-height:80px;
  min-height:34px;
  padding:9px 20px 9px 13px;
  border:1px solid rgba(226,221,214,.95);
  border-radius:24px;
  background-clip:padding-box;
  background:var(--surface);
  color:var(--text-primary);
  outline:none;
  resize:none;
  overflow-y:auto;
  overflow-x:hidden;
  overscroll-behavior:contain;
  font-family:var(--font-sans);
  font-size:13px;
  line-height:1.4;
  transition:border-color .2s,box-shadow .2s;
  scrollbar-width:thin;
  scrollbar-color:rgba(120,120,140,.28) transparent;
}

.cb-input::-webkit-scrollbar{width:8px}
.cb-input::-webkit-scrollbar-track{background:transparent;margin:14px 6px}
.cb-input::-webkit-scrollbar-thumb{
  background:rgba(120,120,140,.28);
  border:3px solid var(--surface);
  border-radius:999px;
}
.cb-input::-webkit-scrollbar-thumb:hover{background:rgba(120,120,140,.38)}

.cb-input:focus{
  border-color:var(--accent-light);
  box-shadow:0 0 0 3px rgba(74,124,196,.12);
}

.cb-send{
  width:34px;
  height:34px;
  border-radius:50%;
  background:var(--gradient-accent);
  border:none;
  cursor:pointer;
  display:flex;
  align-items:center;
  justify-content:center;
  flex-shrink:0;
  transition:transform .2s,box-shadow .2s,opacity .2s;
  box-shadow:0 8px 20px rgba(30,58,110,.24);
}

.cb-send:hover{transform:translateY(-1px) scale(1.03);box-shadow:0 12px 28px rgba(30,58,110,.30)}
.cb-send:disabled{opacity:.4;cursor:not-allowed;transform:none;box-shadow:none}
.cb-send svg{width:14px;height:14px;fill:white;margin-left:1px}

.chat-input-area .mic-btn{
  width:34px;
  height:34px;
}

.cb-powered{
  font-size:10px;
  color:var(--text-muted);
  text-align:center;
  padding-top:6px;
  letter-spacing:.01em;
}

.mp.vis~#browse-stack,.mp.vis+#browse-stack{bottom:88px}
body.chat-open .mp.vis~#browse-stack,
body.chat-open .mp.vis+#browse-stack{bottom:88px}

@media(max-width:820px){
  body.chat-open #browse-stack{
    left:12px;
    right:12px;
    bottom:10px;
    width:auto;
    transform:none;
    align-items:stretch;
  }

  .chat-modal{
    width:100%;
    height:calc(100dvh - 20px);
    max-height:calc(100dvh - 20px);
    border-radius:22px;
  }

  .chat-header{padding:18px 20px;gap:14px}
  .cb-head-icon{width:44px;height:44px}
  .cb-head-title{font-size:25px}
  .cb-head-sub{font-size:14px}
  .cb-head-close{width:42px;height:42px;font-size:23px}
  .chat-messages{padding:22px 20px 24px;gap:12px}
  .cb-msg,.cb-msg.assistant-message{max-width:100%}
  .cb-msg.assistant-message .cb-bubble{padding:20px 22px;font-size:16px;line-height:1.6}
  .chat-suggestions{max-width:100%;gap:8px;margin-top:10px}
  .cb-sugg{font-size:12px;padding:7px 11px}
  .chat-input-area{padding:12px 14px 10px}
  .chat-input-row{gap:10px}
  .cb-input{font-size:14px;min-height:44px;max-height:96px}
  .cb-send,.chat-input-area .mic-btn{width:44px;height:44px}
  .cb-powered{font-size:10px;padding-top:7px}
}
