*,*::before,*::after{box-sizing:border-box;margin:0;padding:0;}
*{-webkit-user-select:none;-moz-user-select:none;user-select:none;-webkit-tap-highlight-color:transparent;}
.bubble,#user-input,textarea,.bubble *{-webkit-user-select:text;-moz-user-select:text;user-select:text;}
.bubble pre,.bubble code,.bubble .code-header{-webkit-user-select:text;-moz-user-select:text;user-select:text;}
input:focus, textarea:focus, select:focus, button:focus{outline:none!important;box-shadow:none!important;}

:root{
  --bg:#111111;
  --sidebar-bg:rgba(20,20,20,0.45);
  --surface:#232323;
  --surface2:#2a2a2a;
  --border:#333333;
  --text:#ececec;
  --muted:#888888;
  --subtle:#232323;
  --accent:#555555;
  --accent2:#aaaaaa;
  --accent-glow:rgba(150,150,150,0.12);
  --accent-hover:#444444;
  --danger:#f85149;
  --user-bubble:#2a2a2a;
  --user-text:#ffffff;
  --ai-bubble:#1c1c1c;
  --ai-border:#333333;
  --sidebar-w:260px;
  --sidebar-icon-w:56px;
}

html,body{height:100%;font-family:'Inter',-apple-system,sans-serif;font-size:14px;background:var(--bg);color:var(--text);overflow:hidden;}

@keyframes gradientShift {
  0%   { background-position: 0% 50%; }
  50%  { background-position: 100% 50%; }
  100% { background-position: 0% 50%; }
}

/* ══════════════════════════════════════
   LAYOUT
══════════════════════════════════════ */
#app{display:flex;height:100vh;height:100dvh;position:relative;}

/* ══════════════════════════════════════
   SIDEBAR
══════════════════════════════════════ */
#sidebar{
  width:var(--sidebar-w);
  background:var(--sidebar-bg);
  backdrop-filter:blur(18px) saturate(1.4);
  -webkit-backdrop-filter:blur(18px) saturate(1.4);
  border-right:none;
  display:flex;flex-direction:column;
  transition:width .32s cubic-bezier(.4,0,.2,1);
  overflow:hidden;position:relative;z-index:20;flex-shrink:0;
  will-change:width;
}
#sidebar.collapsed{width:var(--sidebar-icon-w);}
/* subtle separator using box-shadow instead of border so it doesn't add width */
#sidebar::after{
  content:'';position:absolute;top:0;right:0;bottom:0;width:1px;
  background:var(--border);opacity:.5;pointer-events:none;
}

/* top */
.sb-top{
  display:flex;align-items:center;justify-content:space-between;
  padding:12px 10px 10px;border-bottom:1px solid rgba(255,255,255,.06);flex-shrink:0;
  min-height:52px;transition:justify-content 0s .16s,padding .32s cubic-bezier(.4,0,.2,1);
}
#sidebar.collapsed .sb-top{justify-content:center;padding:12px 0 10px;}
.sb-logo{
  font-size:15px;font-weight:600;color:#ffffff;
  white-space:nowrap;overflow:hidden;opacity:1;
  transition:opacity .22s cubic-bezier(.4,0,.2,1),max-width .32s cubic-bezier(.4,0,.2,1);max-width:180px;
}
#sidebar.collapsed .sb-logo{opacity:0;max-width:0;}
.sb-toggle{
  width:32px;height:32px;border:none;background:none;color:var(--muted);
  border-radius:7px;cursor:pointer;display:flex;align-items:center;justify-content:center;
  transition:background .2s,color .2s,transform .32s cubic-bezier(.4,0,.2,1);flex-shrink:0;
}
.sb-toggle:hover{background:var(--surface2);color:var(--text);}
#sidebar.collapsed .sb-toggle{transform:rotate(180deg);}

/* actions */
.sb-actions{padding:8px 8px 4px;flex-shrink:0;display:flex;}
#sidebar.collapsed .sb-actions{padding:8px 0 4px;justify-content:center;}
.new-chat-btn{
  flex:1;height:36px;
  background:#252525;border:none;
  border-radius:20px;color:var(--text);font-size:13px;font-weight:500;cursor:pointer;
  display:flex;align-items:center;justify-content:flex-start;gap:8px;
  padding:0 14px;
  transition:background .18s;
  white-space:nowrap;overflow:hidden;
}
.new-chat-btn:hover{background:#2e2e2e;}
.new-chat-btn svg{flex-shrink:0;width:14px;height:14px;}
.new-chat-btn span{transition:opacity .18s cubic-bezier(.4,0,.2,1),max-width .32s cubic-bezier(.4,0,.2,1);max-width:200px;overflow:hidden;}
#sidebar.collapsed .new-chat-btn{
  flex:none;
  width:32px;
  height:32px;
  padding:0;
  display:flex;
  justify-content:center;
  align-items:center;
  border-radius:8px;
  gap:0;
}
#sidebar.collapsed .new-chat-btn span{display:none!important;}

.sb-search-collapsed-btn{display:none;}
.sb-search{padding:6px 10px;flex-shrink:0;overflow:hidden;transition:max-height .32s cubic-bezier(.4,0,.2,1),opacity .22s cubic-bezier(.4,0,.2,1),padding .32s;}
.sb-search input{
  width:100%;padding:9px 14px;
  background:#252525;border:none;
  border-radius:20px;color:var(--text);font-size:13px;outline:none;
  transition:background .2s;
}
.sb-search input:focus{background:#2e2e2e;}
.sb-search input::placeholder{color:var(--muted);}
#sidebar.collapsed .sb-search{
  padding:6px 0;
  display:flex;
  justify-content:center;
  align-items:center;
}
#sidebar.collapsed .sb-search input{display:none;}
#sidebar.collapsed .sb-search-collapsed-btn{
  display:flex;
  justify-content:center;
  align-items:center;
  width:32px;
  height:32px;
  background:#252525;
  border:none;
  border-radius:8px;
  color:var(--muted);
  cursor:pointer;
  transition:background .2s,color .2s;
}
#sidebar.collapsed .sb-search-collapsed-btn:hover{
  background:#2e2e2e;
  color:var(--text);
}

/* conv list */
.conv-list{flex:1;overflow-y:auto;overflow-x:hidden;padding:4px 6px;scrollbar-width:thin;scrollbar-color:var(--border) transparent;}
.conv-list::-webkit-scrollbar{width:3px;}
.conv-list::-webkit-scrollbar-thumb{background:var(--border);border-radius:2px;}
#sidebar.collapsed .conv-list{padding:4px 2px;}

.conv-group-label{
  font-size:10px;color:var(--muted);padding:8px 8px 3px;font-weight:500;
  text-transform:uppercase;letter-spacing:.06em;white-space:nowrap;overflow:hidden;
  transition:opacity .18s cubic-bezier(.4,0,.2,1),height .32s,padding .32s;
}
#sidebar.collapsed .conv-group-label{opacity:0;height:0;padding:0;}

.conv-item{
  display:flex;align-items:center;justify-content:space-between;
  padding:8px 10px;border-radius:8px;cursor:pointer;
  transition:background .18s ease;
  position:relative;margin-bottom:1px;min-height:36px;overflow:hidden;
}
.conv-item:hover{background:var(--surface);}
.conv-item.active{background:var(--surface2);}
.conv-title{
  font-size:13px;color:var(--text);white-space:nowrap;overflow:hidden;text-overflow:ellipsis;
  flex:1;transition:opacity .18s cubic-bezier(.4,0,.2,1),width .32s;
}
#sidebar.collapsed .conv-title{opacity:0;width:0;}
#sidebar.collapsed .conv-item{justify-content:center;padding:8px;}
.conv-item .conv-icon{display:none;flex-shrink:0;color:var(--muted);}
#sidebar.collapsed .conv-item .conv-icon{display:flex;}

.conv-menu-btn{
  width:22px;height:22px;border:none;background:none;color:var(--muted);
  border-radius:4px;cursor:pointer;visibility:hidden;align-items:center;justify-content:center;
  flex-shrink:0;font-size:14px;transition:background .1s;display:flex;
}
.conv-item:hover .conv-menu-btn,.conv-item.active .conv-menu-btn{visibility:visible;}
.conv-menu-btn:hover{background:var(--surface2);color:var(--text);}
#sidebar.collapsed .conv-menu-btn{display:none!important;}

/* sidebar footer */
.sb-footer{
  border-top:1px solid var(--border);
  padding:12px 10px 14px;
  display:flex;
  flex-direction:column;
  gap:5px;
  align-items:center;
  flex-shrink:0;
  box-sizing:border-box;
}
#sidebar.collapsed .sb-footer{
  padding:12px 0 16px;
  justify-content:center;
  flex-direction:column;
  align-items:center;
  gap:5px;
}
.sb-footer-btn{
  width:100%;padding:9px 10px;background:none;border:none;
  border-radius:9px;color:var(--text);font-size:13px;font-weight:500;cursor:pointer;
  display:flex;align-items:center;gap:9px;transition:background .15s;
  white-space:nowrap;overflow:hidden;
}
.sb-footer-btn:hover{background:var(--surface);}
.sb-footer-btn svg{flex-shrink:0;color:var(--accent2);}
.sb-footer-btn span{transition:opacity .18s cubic-bezier(.4,0,.2,1),max-width .32s cubic-bezier(.4,0,.2,1);max-width:200px;overflow:hidden;}
#sidebar.collapsed .sb-footer-btn{
  flex:none;
  width:32px;
  height:32px;
  padding:0;
  display:flex;
  justify-content:center;
  align-items:center;
  border-radius:8px;
  background:#252525;
  color:var(--text);
  margin:0 auto;
}
#sidebar.collapsed .sb-footer-btn span{display:none;}
.profile-row{
  width:100%;padding:8px 10px;background:none;border:none;border-radius:9px;color:var(--text);
  display:flex;align-items:center;gap:9px;cursor:pointer;transition:background .18s;
  white-space:nowrap;overflow:hidden;
}
.profile-row:hover{background:var(--surface);}
#sidebar.collapsed .profile-row{
  flex:none;
  width:32px;
  height:32px;
  padding:0;
  display:flex;
  justify-content:center;
  align-items:center;
  border-radius:8px;
  background:#252525;
  margin:0 auto;
  gap:0;
}
#sidebar.collapsed .profile-info{display:none!important;}
#sidebar.collapsed .signout-btn{display:none!important;}
.avatar{
  width:28px;height:28px;border-radius:50%;background:var(--accent);
  display:flex;align-items:center;justify-content:center;font-size:11px;font-weight:600;
  color:#fff;flex-shrink:0;
}
.profile-info{flex:1;overflow:hidden;transition:opacity .18s cubic-bezier(.4,0,.2,1),max-width .32s cubic-bezier(.4,0,.2,1);max-width:160px;text-align:left;}
#sidebar.collapsed .profile-info{opacity:0;max-width:0;}
.profile-name{font-size:13px;font-weight:500;white-space:nowrap;overflow:hidden;text-overflow:ellipsis;}
.profile-email{font-size:11px;color:var(--muted);white-space:nowrap;overflow:hidden;text-overflow:ellipsis;}
.signout-btn{
  border:none;background:none;color:var(--muted);cursor:pointer;padding:4px;
  border-radius:4px;flex-shrink:0;transition:color .15s;display:flex;
}
.signout-btn:hover{color:var(--danger);}
#sidebar.collapsed .signout-btn{display:none;}

/* ══════════════════════════════════════
   MAIN
══════════════════════════════════════ */
#main{
  flex:1;display:flex;flex-direction:column;overflow:hidden;min-width:0;position:relative;
  background: linear-gradient(135deg, #0d0d1a, #111111, #0a1a1a, #111111, #1a0d1a);
  background-size: 400% 400%;
  animation: gradientShift 20s ease infinite;
}

/* Ghost mode button */
#ghost-mode-btn{
  position:absolute;top:12px;right:14px;z-index:50;
  display:flex;align-items:center;gap:7px;
  background:#252525;border:1px solid #383838;
  border-radius:20px;padding:6px 13px 6px 10px;
  font-family:inherit;font-size:12px;font-weight:500;color:var(--muted);
  cursor:pointer;transition:background .2s, border-color .2s, color .2s, box-shadow .2s;white-space:nowrap;
}
#ghost-mode-btn:hover{background:#2e2e2e;color:var(--text);border-color:#4a4a4a;}
#ghost-mode-btn.active{
  background:rgba(88,166,255,.08);
  border-color:rgba(88,166,255,.35);
  color:#58a6ff;
  box-shadow:0 0 0 3px rgba(88,166,255,.07);
}
#ghost-mode-btn svg{flex-shrink:0;transition:transform .3s cubic-bezier(.34,1.56,.64,1);}
#ghost-mode-btn.active svg{transform:scale(1.15);}

/* Ghost mode banner */
#ghost-banner{
  overflow:hidden;max-height:0;opacity:0;
  display:flex;align-items:center;justify-content:center;gap:7px;
  background:rgba(88,166,255,.07);
  border-bottom:1px solid rgba(88,166,255,.15);
  font-size:12px;color:rgba(88,166,255,.8);flex-shrink:0;
  transition:max-height .35s cubic-bezier(.4,0,.2,1), opacity .25s ease, padding .35s cubic-bezier(.4,0,.2,1);
  padding:0 14px;
}
#ghost-banner.show{max-height:40px;opacity:1;padding:7px 14px;}

@keyframes ghostFloat{
  0%,100%{transform:translateY(0);}
  50%{transform:translateY(-7px);}
}

/* no topbar — just the chat window directly */
#chat-window{
  flex:1;overflow-y:auto;padding:20px 16px 12px;
  display:flex;flex-direction:column;gap:6px;scroll-behavior:smooth;
}
#chat-window::-webkit-scrollbar{width:4px;}
#chat-window::-webkit-scrollbar-thumb{background:var(--border);border-radius:4px;}

/* welcome */
.welcome{
  margin:auto;text-align:center;max-width:380px;padding:20px 0 14px;
  animation:fadeUp .4s cubic-bezier(.25,.46,.45,.94);
}
@keyframes fadeUp{from{opacity:0;transform:translateY(12px);}to{opacity:1;transform:none;}}
.welcome h2{font-size:17px;font-weight:600;color:var(--text);margin-bottom:14px;}
.typewriter-wrap{font-size:22px;font-weight:600;color:var(--text);line-height:1.4;min-height:32px;letter-spacing:-.3px;}
.typewriter-text{display:inline;}
.typewriter-caret{
  display:inline-block;width:2px;height:1em;background:var(--muted);
  border-radius:1px;margin-left:1px;vertical-align:text-bottom;
  animation:caretBlink .7s step-end infinite;
}
@keyframes caretBlink{0%,100%{opacity:1;}50%{opacity:0;}}

/* messages */
.message{display:flex;max-width:100%;animation:msgIn .28s cubic-bezier(.25,.46,.45,.94);}
@keyframes msgIn{from{opacity:0;transform:translateY(7px);}to{opacity:1;transform:none;}}
.message.user{justify-content:flex-end;}
.message.ai{justify-content:flex-start;}
.bubble{
  max-width:72%;padding:10px 14px;font-size:14px;line-height:1.55;
  white-space:pre-wrap;word-break:break-word;
}
.message.user .bubble{
  background:var(--user-bubble);color:#ffffff;
  border-radius:18px 18px 4px 18px;
  box-shadow:none;
}
.message.ai .bubble{
  background:var(--ai-bubble);color:var(--text);
  border-radius:18px 18px 18px 4px;border:1px solid var(--ai-border);
}
.bubble img{display:block;max-width:100%;border-radius:10px;margin-bottom:6px;}
.bubble code{font-family:'Courier New',monospace;background:rgba(31,111,235,.1);padding:2px 6px;border-radius:4px;color:var(--accent2);}
.bubble p{margin:0 0 12px;line-height:1.6;}.bubble p:last-child{margin-bottom:0;}
.bubble blockquote{margin:12px 0;padding:12px 16px;border-left:3px solid var(--accent);background:rgba(31,111,235,.06);}
.bubble strong{font-weight:600;}
.bubble em{font-style:italic;}
.bubble a{color:var(--accent2);text-decoration:none;cursor:pointer;}
.bubble a:hover{text-decoration:underline;}
.bubble h1,.bubble h2,.bubble h3,.bubble h4,.bubble h5,.bubble h6{margin-top:4px;margin-bottom:4px;color:var(--text);}
.bubble h1{font-size:19px;}.bubble h2{font-size:17px;}.bubble h3{font-size:15px;}
.bubble h4{font-size:14px;}.bubble h5{font-size:13px;}.bubble h6{font-size:12px;color:var(--muted);}
.bubble ul,.bubble ol{margin:4px 0 4px 20px;padding:0;}
.bubble ul ul,.bubble ol ol,.bubble ul ol,.bubble ol ul{margin:2px 0 2px 16px;}
.bubble li{margin-bottom:2px;}
.bubble table{width:100%;border-collapse:collapse;margin:12px 0;}
.bubble th{padding:10px 12px;text-align:left;background:var(--surface2);border-bottom:1px solid var(--border);font-weight:500;font-size:13px;}
.bubble hr{border:none;border-top:1px solid var(--border);margin:16px 0;}
.bubble td{padding:10px 12px;border-bottom:1px solid var(--border);font-size:13px;}
.bubble tr:last-child td{border-bottom:none;}
/* code header */
.bubble .code-header{
  display:flex;align-items:center;gap:6px;font-size:11px;font-weight:500;color:var(--muted);
  background:var(--surface2);border:1px solid var(--border);
  border-bottom:none;border-radius:8px 8px 0 0;padding:6px 10px;
  font-family:inherit;letter-spacing:.03em;
}
.bubble .code-header img{display:inline-block;flex-shrink:0;width:14px;height:14px;vertical-align:middle;}
.bubble .code-header span{vertical-align:middle;}
.bubble pre{margin:0 0 12px;padding:0;overflow-x:auto;border-radius:0 0 12px 12px;border:1px solid var(--border);}
.bubble pre code.hljs{border-radius:0 0 12px 12px;padding:12px;font-size:13px;}
.bubble pre:hover{opacity:.93;}
.bubble pre:last-child{margin-bottom:0;}

/* typing */
.typing-dots{display:flex;gap:4px;align-items:center;padding:2px 0;}
.typing-dots span{width:5px;height:5px;background:var(--muted);border-radius:50%;animation:dot 1.2s infinite;}
.typing-dots span:nth-child(2){animation-delay:.2s;}
.typing-dots span:nth-child(3){animation-delay:.4s;}
@keyframes dot{0%,60%,100%{opacity:.3;}30%{opacity:1;}}
.bubble.streaming::after{
  content:'';display:inline-block;width:2px;height:1em;
  background:var(--accent2);border-radius:1px;margin-left:2px;
  vertical-align:text-bottom;animation:blink .7s step-end infinite;
}
@keyframes blink{0%,100%{opacity:1;}50%{opacity:0;}}

/* ══════════════════════════════════════
   INPUT AREA
══════════════════════════════════════ */
#input-area{padding:6px 12px 6px;padding-bottom:max(8px,env(safe-area-inset-bottom));background:transparent;position:relative;flex-shrink:0;}
#footer{padding:2px 14px 4px;padding-bottom:max(8px,env(safe-area-inset-bottom));text-align:center;font-size:11px;color:var(--muted);background:transparent;flex-shrink:0;position:sticky;bottom:0;z-index:1;}

#file-previews{display:none;flex-wrap:wrap;gap:6px;padding:4px 4px 2px;}
#file-previews.has-files{display:flex;}
.file-chip{
  display:flex;align-items:center;gap:5px;
  background:var(--surface);border:1px solid var(--border);
  border-radius:8px;padding:4px 8px;
  font-size:11px;color:var(--muted);max-width:160px;
}
.file-chip span{overflow:hidden;text-overflow:ellipsis;white-space:nowrap;}
.file-chip-remove{
  background:none;border:none;cursor:pointer;color:var(--muted);
  font-size:13px;padding:0;line-height:1;flex-shrink:0;transition:color .15s;
}
.file-chip-remove:hover{color:var(--text);}
.attachment-tag{
  display:flex;align-items:center;gap:5px;
  margin-top:6px;font-size:11px;opacity:.6;color:var(--muted);
}
.attachment-tag svg{flex-shrink:0;opacity:.85;}
.attachment-tag span{overflow:hidden;text-overflow:ellipsis;white-space:nowrap;}

/* model selector at top left */
.model-section-wrap {
  position: absolute;
  top: 12px;
  left: 14px;
  z-index: 50;
}
#model-btn {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 7px;
  background: #252525;
  border: 1px solid #383838;
  border-radius: 20px;
  padding: 6px 12px;
  font-family: inherit;
  font-size: 12px;
  font-weight: 500;
  color: var(--muted);
  cursor: pointer;
  transition: background .2s, border-color .2s, color .2s;
  white-space: nowrap;
}
#model-btn:hover {
  background: #2e2e2e;
  color: var(--text);
  border-color: #4a4a4a;
}
#model-btn .chevron {
  color: var(--muted);
  transition: transform .3s cubic-bezier(.34,1.56,.64,1);
  flex-shrink: 0;
}
#model-btn.open .chevron {
  transform: rotate(180deg);
}
#model-menu {
  position: fixed;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  box-shadow: 0 8px 24px rgba(0,0,0,.4);
  z-index: 99999;
  opacity: 0;
  transform: translateY(-6px) scaleY(.95);
  transform-origin: top center;
  pointer-events: none;
  transition: opacity .18s, transform .2s cubic-bezier(.34,1.3,.64,1);
  overflow: hidden;
  min-width: 220px;
}
#model-menu.open {
  opacity: 1;
  transform: none;
  pointer-events: all;
}
#model-menu-inner {
  overflow-y: auto;
  max-height: 240px;
  overscroll-behavior: contain;
  scrollbar-width: thin;
  scrollbar-color: transparent transparent;
}
#model-menu-inner::-webkit-scrollbar {
  width: 6px;
}
#model-menu-inner::-webkit-scrollbar-track {
  background: transparent;
}
#model-menu-inner::-webkit-scrollbar-thumb {
  background: transparent;
  border-radius: 3px;
}
#model-menu-inner:hover::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.08);
}
.model-opt {
  display: flex;
  align-items: center;
  padding: 10px 12px;
  font-size: 13px;
  color: var(--text);
  cursor: pointer;
  border-bottom: 1px solid var(--border);
  gap: 10px;
  min-height: 40px;
  touch-action: manipulation;
  transition: background .12s;
}
.model-opt:last-child {
  border-bottom: none;
}
.model-opt:hover, .model-opt:active {
  background: var(--surface2);
}
.model-opt > span:first-child {
  flex: 1;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.model-opt .check {
  width: 14px;
  height: 14px;
  flex-shrink: 0;
  color: var(--accent2);
  opacity: 0;
  transition: opacity .2s;
  margin-left: auto;
}
.model-opt.selected .check {
  opacity: 1;
}
.model-opt .tag {
  font-size: 9px;
  background: var(--surface2);
  border: 1px solid var(--border);
  color: var(--muted);
  padding: 2px 5px;
  border-radius: 4px;
  flex-shrink: 0;
  white-space: nowrap;
}
.model-opt.vision-model .tag {
  color: var(--accent2);
  border-color: rgba(56,139,253,.25);
  background: rgba(56,139,253,.08);
}

/* plus-popup styles */
@keyframes popupFadeIn {
  from {
    opacity: 0;
    transform: translateY(8px) scale(0.96);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}
.plus-popup {
  position: absolute;
  bottom: calc(100% + 12px);
  left: 0;
  width: 240px;
  background: rgba(30, 30, 30, 0.9);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 14px;
  box-shadow: 0 12px 36px rgba(0, 0, 0, 0.5), 0 0 0 1px rgba(255, 255, 255, 0.03);
  padding: 6px;
  z-index: 1000;
  display: none;
  flex-direction: column;
  transform-origin: bottom left;
}
.plus-popup.open {
  display: flex;
  animation: popupFadeIn 0.2s cubic-bezier(0.34, 1.56, 0.64, 1) forwards;
}
.popup-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border-radius: 8px;
  color: #ececec;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
  user-select: none;
  position: relative;
}
.popup-item:hover {
  background: rgba(255, 255, 255, 0.08);
}
.popup-item.active {
  color: #3b82f6; /* Vibrant blue */
}
.popup-item.active:hover {
  background: rgba(59, 130, 246, 0.08);
}
.popup-icon {
  flex-shrink: 0;
  color: #888888;
  transition: color 0.15s;
}
.popup-item:hover .popup-icon {
  color: #ffffff;
}
.popup-item.active .popup-icon {
  color: #3b82f6;
}
.popup-item .check-icon {
  margin-left: auto;
  color: #3b82f6;
  display: none;
  flex-shrink: 0;
}
.popup-item.active .check-icon {
  display: block;
}
.popup-separator {
  height: 1px;
  background: rgba(255, 255, 255, 0.08);
  margin: 6px 4px;
}

/* Locked Deep Research style */
.popup-item.locked {
  opacity: 0.6;
  cursor: not-allowed;
}
.popup-item.locked:hover {
  background: transparent;
}
.popup-item.locked .popup-icon {
  color: #666;
}
.popup-item.locked .lock-icon {
  margin-left: auto;
  color: #666;
  display: block;
  flex-shrink: 0;
}
.popup-item .lock-icon {
  display: none;
}

.spin{width:10px;height:10px;border:2px solid var(--border);border-top-color:var(--accent);border-radius:50%;animation:spin .7s linear infinite;}
@keyframes spin{to{transform:rotate(360deg);}}

.bar{
  display:flex;align-items:center;gap:8px;
  background:#252525;border:1px solid #383838;
  border-radius:24px;padding:8px 8px 8px 6px;
  transition:border-radius .3s cubic-bezier(.34,1.56,.64,1),border-color .2s;
}
.bar:focus-within{border-color:#383838;}
.char-count{display:flex;align-items:center;color:var(--muted);font-size:12px;white-space:nowrap;min-width:60px;}
.char-count.overlimit{color:var(--danger);}
#plus-btn{
  width:32px;height:32px;flex-shrink:0;
  background:#3a3a3a;border:1px solid #4a4a4a;
  border-radius:50%;cursor:pointer;
  position:relative;
  transition:background .2s,transform .3s cubic-bezier(.34,1.56,.64,1);
  touch-action:manipulation;padding:0;box-sizing:border-box;
}
#plus-btn .plus-h,#plus-btn .plus-v{
  display:block;position:absolute;background:#ececec;border-radius:2px;
}
#plus-btn .plus-h{width:12px;height:2px;top:14px;left:9px;transition:transform .3s cubic-bezier(.34,1.56,.64,1);}
#plus-btn .plus-v{width:2px;height:12px;top:9px;left:14px;transition:transform .3s cubic-bezier(.34,1.56,.64,1);}
#plus-btn:hover{background:#484848;}
#plus-btn.active .plus-h{transform:rotate(45deg) translate(0,0);}
#plus-btn.active .plus-v{transform:rotate(45deg) translate(0,0);}
#user-input{
  flex:1;background:transparent;border:none;outline:none;
  font-family:inherit;font-size:16px;color:var(--text);
  resize:none;max-height:120px;min-height:20px;
  line-height:1.5;padding:6px 4px;touch-action:manipulation;
}
#user-input::placeholder{color:var(--muted);}
#send-btn{
  width:32px;height:32px;flex-shrink:0;
  background:#1f6feb;color:#fff;
  border:none;border-radius:50%;cursor:pointer;
  display:flex;align-items:center;justify-content:center;
  transition:all .2s cubic-bezier(.25,.46,.45,.94);
  touch-action:manipulation;
}
#send-btn svg{display:block;width:13px;height:13px;pointer-events:none;}
#send-btn:hover{transform:scale(1.08) translateY(-2px);box-shadow:0 4px 12px rgba(31,111,235,.45);}
#send-btn:active{transform:scale(.95);}
#send-btn:disabled{opacity:.3;cursor:not-allowed;transform:none;box-shadow:none;}

.file-chip.animate-in{animation:fileIn .25s ease-out forwards;}
@keyframes fileIn{from{opacity:0;transform:translateY(8px) scale(.95);}to{opacity:1;transform:none;}}

.image-modal{position:fixed;inset:0;display:flex;align-items:center;justify-content:center;z-index:9999;padding:24px;opacity:0;pointer-events:none;transition:opacity .22s ease;}
.image-modal.active{opacity:1;pointer-events:auto;}
.image-modal-backdrop{position:absolute;inset:0;background:rgba(0,0,0,.75);backdrop-filter:blur(4px);opacity:0;transition:opacity .22s ease;}
.image-modal.active .image-modal-backdrop{opacity:1;}
.image-modal-content{position:relative;max-width:min(95vw,720px);max-height:min(95vh,720px);border-radius:18px;overflow:hidden;box-shadow:0 28px 80px rgba(0,0,0,.35);background:rgba(0,0,0,.9);transform:scale(.94);opacity:0;transition:transform .22s ease,opacity .22s ease;}
.image-modal.active .image-modal-content{transform:scale(1);opacity:1;}
.image-modal-content img{display:block;width:100%;height:auto;max-height:80vh;object-fit:contain;}
.image-modal-caption{padding:12px 14px 14px;font-size:13px;color:#fff;background:rgba(0,0,0,.45);}

/* ══════════════════════════════════════
   CONTEXT MENU
══════════════════════════════════════ */
.ctx-menu{
  position:fixed;background:var(--surface2);border:1px solid var(--border);
  border-radius:9px;padding:4px;z-index:500;min-width:140px;
  box-shadow:0 8px 24px rgba(0,0,0,.5);
  opacity:0;transform:scale(.96);pointer-events:none;
  transition:opacity .18s ease,transform .18s ease;
}
.ctx-menu.open{
  opacity:1;transform:scale(1);pointer-events:auto;
}
@keyframes popIn{from{opacity:0;transform:scale(.95);}to{opacity:1;transform:scale(1);}}
@keyframes fadeIn{from{opacity:0;}to{opacity:1;}}
@keyframes slideUp{from{opacity:0;transform:translateY(16px) scale(.97);}to{opacity:1;transform:none;}}
.ctx-item{
  display:flex;align-items:center;gap:8px;padding:8px 10px;border-radius:6px;
  font-size:13px;cursor:pointer;transition:background .1s;color:var(--text);
  border:none;background:none;width:100%;
}
.ctx-item:hover{background:var(--surface);}
.ctx-item.danger{color:var(--danger);}
.ctx-item.danger:hover{background:rgba(248,81,73,.1);}

/* ══════════════════════════════════════
   AUTH MODAL
══════════════════════════════════════ */
#auth-screen{
  position:fixed;inset:0;display:none;align-items:center;justify-content:center;
  z-index:1000;padding:20px;padding-bottom:max(20px,env(safe-area-inset-bottom));
}
#auth-screen.visible{display:flex;}
.auth-backdrop{
  position:absolute;inset:0;background:rgba(0,0,0,0);backdrop-filter:blur(0px);
  transition:background .3s ease,backdrop-filter .3s ease;
}
#auth-screen.visible .auth-backdrop{background:rgba(0,0,0,.82);backdrop-filter:blur(12px);}
.auth-box{
  position:relative;z-index:1;width:100%;max-width:320px;
  padding:32px 28px 28px;
  background:#1e1e1e;border-radius:24px;
  box-shadow:0 32px 80px rgba(0,0,0,.85),0 0 0 1px rgba(255,255,255,.07);
  opacity:0;transform:translateY(32px) scale(.95);
  transition:opacity .4s cubic-bezier(.22,1,.36,1),transform .4s cubic-bezier(.22,1,.36,1);
}
#auth-screen.visible .auth-box{opacity:1;transform:none;}
.auth-close{
  position:absolute;top:16px;right:16px;
  width:28px;height:28px;border-radius:50%;
  border:none;background:rgba(255,255,255,.08);color:#888;
  cursor:pointer;font-size:16px;line-height:28px;text-align:center;
  transition:background .15s,color .15s;display:flex;align-items:center;justify-content:center;
}
.auth-close:hover{background:rgba(255,255,255,.14);color:#fff;}
.auth-logo{font-size:13px;font-weight:600;color:#888;letter-spacing:.06em;text-transform:uppercase;margin-bottom:20px;}
.auth-box h2{font-size:22px;font-weight:700;color:#fff;letter-spacing:-.4px;margin-bottom:6px;line-height:1.2;}
.auth-box .auth-sub{color:#666;font-size:13px;margin-bottom:28px;line-height:1.5;}
/* step indicator */
.auth-steps{display:flex;gap:6px;margin-bottom:24px;}
.auth-step-dot{width:6px;height:6px;border-radius:50%;background:#333;transition:background .3s,width .3s;flex-shrink:0;}
.auth-step-dot.active{background:#1f6feb;width:18px;border-radius:3px;}
/* fields */
.auth-field{margin-bottom:14px;}
.auth-field input{
  width:100%;padding:14px 16px;
  background:#2a2a2a;border:1.5px solid transparent;
  border-radius:12px;color:#fff;font-size:15px;outline:none;
  font-family:inherit;
  transition:border-color .2s,background .2s;
  -webkit-user-select:text;user-select:text;
}
.auth-field input:focus{background:#2e2e2e;}
.auth-field input::placeholder{color:#555;}
.auth-btn{
  width:100%;padding:14px;background:#1f6feb;border:none;border-radius:12px;
  color:#fff;font-size:15px;font-weight:600;cursor:pointer;margin-top:4px;
  transition:background .2s,transform .15s,box-shadow .2s;
  font-family:inherit;
}
.auth-btn:hover{background:#1a60d6;box-shadow:0 6px 20px rgba(31,111,235,.4);}
.auth-btn:active{transform:scale(.98);}
.auth-btn:disabled{opacity:.45;cursor:not-allowed;transform:none;box-shadow:none;}
.auth-divider{display:flex;align-items:center;gap:12px;margin:18px 0;color:#444;font-size:12px;}
.auth-divider::before,.auth-divider::after{content:'';flex:1;height:1px;background:#2a2a2a;}
.auth-switch{text-align:center;font-size:13px;color:#555;margin-top:16px;}
.auth-switch button{background:none;border:none;color:#888;cursor:pointer;font-size:13px;font-family:inherit;transition:color .15s;padding:0;}
.auth-switch button:hover{color:#fff;}
.auth-error{color:#f85149;font-size:12px;margin-top:10px;text-align:center;min-height:16px;}
.auth-success{color:#3fb950;font-size:13px;margin-top:10px;text-align:center;line-height:1.5;}

/* ══════════════════════════════════════
   MODAL (rename/delete)
══════════════════════════════════════ */
.modal-bg{
  position:fixed;inset:0;z-index:9600;
  display:none;align-items:center;justify-content:center;
  padding:20px;
}
.modal-bg.open{display:flex;}
.modal-bg .modal-backdrop{
  position:absolute;inset:0;background:rgba(0,0,0,0);backdrop-filter:blur(0px);
  transition:background .3s ease,backdrop-filter .3s ease;
}
.modal-bg.open.visible .modal-backdrop{background:rgba(0,0,0,.75);backdrop-filter:blur(8px);}
.modal{
  position:relative;z-index:1;
  background:#1e1e1e;border-radius:16px;padding:28px 24px 24px;
  width:100%;max-width:300px;
  box-shadow:0 24px 60px rgba(0,0,0,.7),0 0 0 1px rgba(255,255,255,.06);
  opacity:0;transform:translateY(20px) scale(.96);
  transition:opacity .35s cubic-bezier(.22,1,.36,1),transform .35s cubic-bezier(.22,1,.36,1);
}
.modal-bg.open.visible .modal{opacity:1;transform:none;}
.modal h3{font-size:16px;font-weight:600;margin-bottom:6px;text-align:center;}
.modal p.modal-sub{font-size:13px;color:var(--muted);text-align:center;margin-bottom:20px;}
.modal input{
  width:100%;padding:12px 14px;background:#2a2a2a;border:1.5px solid transparent;
  border-radius:10px;color:var(--text);font-size:14px;outline:none;margin-bottom:16px;
  font-family:inherit;transition:border-color .2s;
}
.modal input:focus{border-color:transparent;}
.modal-actions{display:flex;gap:10px;justify-content:center;}
.modal-btn{
  flex:1;padding:11px;border-radius:10px;border:none;
  font-size:14px;font-weight:500;cursor:pointer;transition:all .15s;font-family:inherit;
}
.modal-btn.cancel{background:#2a2a2a;color:var(--text);}
.modal-btn.cancel:hover{background:#333;}
.modal-btn.primary{background:#1f6feb;color:#fff;}
.modal-btn.primary:hover{background:#1a60d6;}
.modal-btn.danger{background:#f85149;color:#fff;}
.modal-btn.danger:hover{background:#e03d35;}

/* mobile overlay — sits behind the sidebar sliver */
#overlay{position:fixed;inset:0;background:rgba(0,0,0,.55);z-index:15;display:none;animation:fadeIn .2s ease;}
#overlay.show{display:block;}

@media(max-width:640px){
  #sidebar{position:absolute;top:0;left:0;height:100%;height:100dvh;z-index:200;}
  #sidebar.collapsed{width:var(--sidebar-icon-w);}
  #main{margin-left:var(--sidebar-icon-w);transition:margin-left .32s cubic-bezier(.4,0,.2,1);}
  #sidebar:not(.collapsed) ~ #main{margin-left:0;}
  .auth-box{margin:0 16px;max-width:calc(100% - 32px);}
  #auth-screen{align-items:flex-end;padding-bottom:max(24px,env(safe-area-inset-bottom));}
}

/* tooltip on collapsed icons */
#sidebar.collapsed .conv-item{position:relative;}
#sidebar.collapsed .guest-conv-msg{opacity:0;pointer-events:none;}

/* ── Welcome state: typewriter + input centered vertically ── */
#main.has-welcome {
  justify-content: center;
}
#main.has-welcome #chat-window {
  flex: 0 0 auto;
  display: flex;
  flex-direction: column;
  align-items: center;
  overflow: visible;
  padding: 0 16px;
}
#main.has-welcome .welcome {
  margin: 0 0 20px;
  text-align: center;
}
#main.has-welcome #input-area {
  max-width: 680px;
  width: 100%;
  margin: 0 auto;
  padding: 0 12px 8px;
  flex-shrink: 0;
}
#main:not(.has-welcome) #input-area {
  margin-top: auto;
}
/* ── Collapsed sidebar: hide chat list, search input, sign-in text ── */
#sidebar.collapsed .conv-list { visibility: hidden; opacity: 0; pointer-events: none; }
#sidebar.collapsed .sb-search {
  padding: 6px 0;
  display: flex;
  justify-content: center;
  align-items: center;
  visibility: visible;
  opacity: 1;
}

/* ══════════════════════════════════════
   SETTINGS
══════════════════════════════════════ */
.settings-anchor{
  position:relative;width:100%;
}
.settings-popup{
  position:fixed;
  background:#1e1e1e;border:1px solid var(--border);border-radius:12px;
  padding:4px;z-index:300;min-width:220px;
  box-shadow:0 8px 28px rgba(0,0,0,.55);
  opacity:0;transform:translateY(6px) scale(.98);
  pointer-events:none;
  transition:opacity .18s ease,transform .18s ease;
  left:14px;max-width:calc(100vw - 80px);overflow-y:auto;max-height:60vh;
}
.settings-popup.open{
  opacity:1;transform:none;pointer-events:auto;
}
.settings-profile-header{
  display:flex;align-items:center;gap:10px;
  padding:10px 10px 8px;pointer-events:none;cursor:default;
}
.settings-profile-header .avatar{
  position:relative;display:flex;align-items:center;justify-content:center;
}
.settings-profile-header .avatar img{display:block;width:28px;height:28px;border-radius:50%;object-fit:cover;}
.settings-guest-icon{
  width:15px;height:15px;color:var(--muted);flex-shrink:0;
}
.settings-profile-info{flex:1;overflow:hidden;min-width:0;}
.settings-profile-name{font-size:13px;font-weight:500;color:var(--text);white-space:nowrap;overflow:hidden;text-overflow:ellipsis;}
.settings-profile-email{font-size:11px;color:var(--muted);white-space:nowrap;overflow:hidden;text-overflow:ellipsis;}
.settings-sep{height:1px;background:var(--border);margin:4px 6px;}
.settings-trigger.active{background:var(--surface);}
.settings-detail-screen{
  position:fixed;inset:0;z-index:8500;display:none;align-items:center;justify-content:center;padding:20px;
}
.settings-detail-screen.open{display:flex;}
.settings-detail-backdrop{
  position:absolute;inset:0;background:rgba(0,0,0,0);backdrop-filter:blur(0px);
  transition:background .3s ease,backdrop-filter .3s ease;
}
.settings-detail-screen.open.visible .settings-detail-backdrop{background:rgba(0,0,0,.75);backdrop-filter:blur(10px);}
.settings-detail-box{
  position:relative;z-index:1;width:100%;max-width:400px;
  background:#1e1e1e;border-radius:20px;padding:24px;
  box-shadow:0 32px 80px rgba(0,0,0,.85),0 0 0 1px rgba(255,255,255,.07);
  opacity:0;transform:translateY(24px) scale(.96);
  transition:opacity .35s cubic-bezier(.22,1,.36,1),transform .35s cubic-bezier(.22,1,.36,1);
  max-height:min(90vh,560px);overflow-y:auto;
}
.settings-detail-screen.open.visible .settings-detail-box{opacity:1;transform:none;}
.settings-detail-close{
  position:absolute;top:14px;right:14px;
  width:28px;height:28px;border-radius:50%;
  border:none;background:rgba(255,255,255,.08);color:#888;
  cursor:pointer;font-size:16px;display:flex;align-items:center;justify-content:center;
  transition:background .15s,color .15s;
}
.settings-detail-close:hover{background:rgba(255,255,255,.14);color:#fff;}
.settings-title{font-size:18px;font-weight:700;color:#fff;margin-bottom:16px;letter-spacing:-.3px;}
.settings-sub{font-size:12px;color:#666;margin-bottom:14px;line-height:1.5;}
.settings-item{
  width:100%;display:flex;align-items:center;gap:10px;
  padding:12px 10px;background:none;border:none;border-radius:10px;
  color:var(--text);font-size:14px;font-weight:500;cursor:pointer;
  transition:background .15s;text-align:left;font-family:inherit;
}
.settings-item:hover{background:var(--surface);}
.settings-item.danger{color:var(--danger);}
.settings-item.danger:hover{background:rgba(248,81,73,.1);}
.settings-item svg:first-child{flex-shrink:0;color:var(--accent2);}
.settings-chevron{margin-left:auto;flex-shrink:0;color:var(--muted);opacity:.6;}
.settings-back{
  background:none;border:none;color:var(--muted);font-size:13px;
  cursor:pointer;padding:0 0 12px;font-family:inherit;transition:color .15s;
}
.settings-back:hover{color:var(--text);}
.settings-textarea{
  width:100%;background:#2a2a2a;border:1px solid #333;border-radius:10px;
  padding:12px;font-size:13px;color:#fff;font-family:inherit;
  resize:none;min-height:120px;max-height:200px;outline:none;line-height:1.5;
  overflow-y:auto;
  -webkit-user-select:text;user-select:text;
}
.settings-textarea:focus{border-color:#444;}
.settings-textarea::placeholder{color:#555;}
.settings-word-count{font-size:11px;color:var(--muted);margin-top:6px;text-align:right;}
.settings-word-count.overlimit{color:var(--danger);}
.settings-save-btn{
  width:100%;margin-top:14px;padding:11px;background:#1f6feb;border:none;
  border-radius:10px;color:#fff;font-size:14px;font-weight:600;cursor:pointer;
  font-family:inherit;transition:background .15s;
}
.settings-save-btn:hover{background:#1a60d6;}
.settings-status{font-size:12px;margin-top:10px;min-height:16px;color:var(--muted);}

.katex-display{overflow-x:auto;overflow-y:hidden;padding:4px 0;}.katex{font-size:1.05em;}