:root{
  /* ChatGPT-style dark: #202123 main, #343541 prompt box */
  --bg:#202123;
  --fg:#ececec;
  --muted:#a6a7a8;
  --border:#3e3f4a;
  --border-light:rgba(255,255,255,0.08);
  --surface:#2d2e32;
  --input-bg:#343541;
  --inputH: 44px; /* default before JS runs */
}
*{box-sizing:border-box}
body{
  margin:0;background:var(--bg);color:var(--fg);
  font:14px/1.45 ui-sans-serif,system-ui,-apple-system,Segoe UI,Roboto,Helvetica,Arial;
}

html, body {
  height: 100%;
  overflow: hidden;
}
.wrap{
  height: 100svh;
  display:flex;
  justify-content:center;
  padding:14px 12px;
}

.chat{
  width:100%;
  max-width:720px;
  display:flex;
  flex-direction:column;
  gap:12px;

  height: auto;
}

.messages{
  flex:1;
  display:flex;
  flex-direction:column;
  gap:10px;
  padding:20px 0 0 0;
  min-height: 0;
  overflow:auto;
  scroll-behavior:smooth;

  /* IMPORTANT: remove the max-height hack; let flexbox do it */
  max-height: none;
  padding-bottom: calc(var(--composerH, 76px) + var(--kb, 0px) + env(safe-area-inset-bottom));
  scrollbar-width: none;
  -ms-overflow-style: none;
}
.messages::-webkit-scrollbar{ display:none; }

/* Composer pinned to bottom (ChatGPT-style: single rounded box, no top border) */
.composer{
  position: fixed;
  left: 50%;
  transform: translateX(-50%);
  width: calc(100% - 24px);
  max-width: 720px;

  bottom: calc(var(--kb, 0px) + env(safe-area-inset-bottom));
  background: transparent;
  z-index: 999;

  display: flex;
  flex-direction: column;
  gap: 8px;
  align-items: stretch;
  padding: 10px 0 calc(10px + env(safe-area-inset-bottom));
}



.composerBox{
  background: var(--input-bg);
  border-radius: 20px;
  padding: 10px 12px 10px 14px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  border: none;
  box-shadow: none;
}

#fileIndicators{
  display: flex;
  gap: 8px;
  align-items: center;
  flex-wrap: wrap;
  padding: 0 4px;
  margin-bottom: 6px;
}

.composerRow{
  display: flex;
  gap: 8px;
  align-items: flex-end;
  flex: 1;
  min-width: 0;
}

.composerActions{
  display: flex;
  justify-content: space-between;
  align-items: center;
  min-height: 36px;
  gap: 8px;
}

.composerLeftActions{
  display: flex;
  align-items: center;
  gap: 6px;
  flex-shrink: 0;
}

#searchModeBtn{
  display: inline-flex;
  align-items: center;
  gap: 5px;
  height: 32px;
  padding: 0 10px 0 8px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: transparent;
  color: var(--fg);
  font-size: 13px;
  font-weight: 500;
  flex-shrink: 0;
  opacity: 0.92;
}
#searchModeBtn:hover{ opacity: 1; }
#searchModeBtn svg{ flex-shrink: 0; opacity: 0.85; }
#searchModeBtn.searchModeOn{
  color: white;
  border-color: #4a9eff;
  background: rgba(128, 154, 240, 0.14);
  opacity: 1;
}
#searchModeBtn.searchModeOn svg{
  opacity: 1;
}

#input {
  height: var(--inputH);
  min-height: 44px;
  background: transparent;
  border: none;
  color: var(--fg);
  flex: 1;
  min-width: 0;
}
#input::placeholder { color: var(--muted); }

#send{
  width: 36px;
  height: 36px;
  min-width: 36px;
  min-height: 36px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  flex-shrink: 0;
  background: var(--fg);
  color: var(--bg);
  border: none;
  box-shadow: none;
}
#send:hover:not(:disabled) { background: var(--muted); }
#send:disabled { opacity: 0.4; }

#fileBtn{
  width: 36px;
  height: 36px;
  min-width: 36px;
  min-height: 36px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  flex-shrink: 0;
  background: transparent;
  border: none;
  color: var(--fg);
  opacity: 0.9;
}
#fileBtn:hover{ opacity: 1; }
#fileBtn:disabled{ opacity: 0.4; }

button:hover {
  cursor:pointer;
}

@media (max-width: 640px){
  .messages{
padding-top: 0;
  }
}



@media (max-width: 640px){
  textarea{
height: 48px;
padding: 12px 12px;
  }
  button#send{
width: 36px;
min-width: 36px;
  }
}




.fileChip {
  padding: 6px 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 13px;
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--surface);
}
.fileChipRemove {
  border: none;
  background: transparent;
  color: var(--fg);
  font-size: 18px;
  line-height: 1;
  cursor: pointer;
  padding: 0 2px;
  opacity: 0.9;
}
.fileChipRemove:hover { opacity: 1; }
.fileChipRemove:disabled { opacity: 0.4; cursor: not-allowed; }

.fileSpinner {
  width: 12px;
  height: 12px;
  border: 2px solid var(--border);
  border-top-color: var(--fg);
  border-radius: 50%;
  animation: spin .8s linear infinite;
  flex: 0 0 auto;
}

.fileChipText {
  font-weight: 600;
}

.fileChipSub {
  font-size: 12px;
  color: var(--muted);
  font-weight: 400;
}




.header{
  display:flex;
  justify-content:space-between;
  align-items:center;
  gap:10px;
  padding-bottom:10px;
  border-bottom:1px solid var(--border);
  position:sticky;
  top:0;
  background:var(--bg);
  z-index:5;
}
.title{font-weight:600;letter-spacing:.2px;display:flex;align-items:center;gap:8px;min-width:0}
.title span{white-space:nowrap;overflow:hidden;text-overflow:ellipsis}
.logo{width:28px;height:28px;object-fit:contain;border-radius:6px;flex:0 0 auto}
.status{color:var(--muted);font-size:12px}
#credits:not(:empty){
  padding:2px 8px;
  border:1px solid var(--border);
  border-radius:999px;
  background:var(--input-bg);
  line-height:1.4;
  white-space:nowrap;
}
.api-link{
  display:inline-flex;
  align-items:center;
  justify-content:center;
  gap:5px;
  height:20px;
  padding:0 10px;
  border:1px solid var(--border);
  border-radius:8px;
  background:var(--input-bg);
  color:var(--fg);
  font-size:12px;
  font-weight:600;
  text-decoration:none;
  line-height:1;
}
.api-link:hover{background:var(--surface)}
.api-link svg{width:11px;height:11px;display:block;flex-shrink:0}
#manageSubBtn{color:var(--fg)}
#manageSubBtn:hover{color:var(--muted);cursor:pointer}

.topLeftTools{
  position:sticky;
  top:44px;
  z-index:4;
  display:flex;
  align-items:center;
  justify-content:space-between;
  padding:8px 0 0;
  height:42px;
}
   .iconBtn{
  border:1px solid var(--border);
  background:var(--input-bg);
  color:var(--fg);
  border-radius:10px;
  cursor:pointer;
  display:flex;
  align-items:center;
  justify-content:center;
  gap:8px;
  height:34px;
  padding:0 10px;
  width:auto;
  flex-shrink:0;
}
.iconBtn:hover{background:var(--surface)}
.iconBtn:active{transform:translateY(1px)}
.iconBtn svg{width:18px;height:18px;display:block;flex-shrink:0}
.iconBtn .label{
  font-size:13px;
  color: var(--fg);
  font-weight: 600;
  line-height: 1;
  white-space: nowrap;
}




.msg{
  padding:12px 14px;
  border:1px solid var(--border);
  border-radius:12px;
  background: var(--surface);
  white-space:pre-wrap;
  word-break:break-word;
  display:flex;
  gap:10px;
  align-items:flex-start;
}
.msg.user{align-self:flex-end;max-width:85%; background: var(--input-bg); position:relative;}
.msg.assistant{align-self:flex-start;max-width:85%}
.turnScrollSpacer{
  width:1px;
  min-height:0;
  flex-shrink:0;
  pointer-events:none;
}

.msg { white-space: normal; }          /* default for HTML */
.msg.user { white-space: pre-wrap; }   /* preserve newlines for plain text user msgs */

.webSearchGlobe{
  display:flex;
  align-items:center;
  justify-content:center;
  width:28px;
  height:28px;
  border-radius:10px;
  border:1px solid var(--border);
  background:var(--surface);
  color:var(--muted);
  position:absolute;
  bottom:-15px;
  right:4px;
  box-shadow: 0 4px 14px rgba(0,0,0,.18);
}
.webSearchGlobe svg{ display:block; }
.userMsgBody{
  white-space:pre-wrap;
  word-break:break-word;
}

/* keep code blocks behaving correctly */
.msg.assistant pre { white-space: pre; }

/* NEW: empty-state center text */
.emptyState{
  flex:1;
  display:flex;
  align-items:center;
  justify-content:center;
  text-align:center;
  padding:26px 10px 10px;
  color:var(--fg);
}
.emptyStateInner{
  display:flex;
  flex-direction:column;
  gap:6px;
  margin-top:-10px;
}
.emptyTitle{
  font-weight:650;
  font-size:22px;
  letter-spacing:.2px;
}
.emptySub{
  color:var(--muted);
  font-size:13px;
}

/* Composer */


textarea{
  flex:1;
  resize:none;
  height:44px;
  max-height: 180px;
  overflow-y:auto;
  padding:10px 4px 10px 8px;
  border:none;
  border-radius:0;
  outline:none;
  font:inherit;
  color:var(--fg);
  background: transparent;
}

@media (max-width: 640px){
  textarea{
min-height:48px;   /* not height */
  }
}


.black-button{
  min-width:75px;
  border:1px solid var(--fg);
  background:var(--input-bg);
  color:var(--fg);
  border-radius:8px;
  cursor:pointer;
  font:inherit;
  padding: 6px 14px;
}
.black-button:hover:not(:disabled){ filter: brightness(1.1); }
.black-button:disabled{opacity:.4;cursor:not-allowed}

.tiny{
  margin-top:-6px;
  color:var(--muted);
  font-size:12px;
}
a{color:inherit}
/* Markdown styles for chat output (dark) */
.msg.assistant h1, .msg.assistant h2, .msg.assistant h3 { margin: 8px 0; }
.msg.assistant pre { background:#1e1e1e; padding:10px; border-radius:8px; overflow:auto; font-family: monospace; border:1px solid var(--border); }
.msg.assistant code { background:#2d2d2d; padding:2px 6px; border-radius:4px; font-family: monospace; }
.msg.assistant blockquote { border-left:3px solid var(--muted); padding-left:10px; color:var(--muted); margin:8px 0; }
.msg.assistant ul, .msg.assistant ol { margin:8px 0 8px 18px; }
.msg.assistant hr { border:none; border-top:1px solid var(--border); margin:10px 0; }

/* NEW: "thinking" spinner inside assistant bubble */
.thinkingRow{
  display:flex;
  align-items:center;
  gap:8px;
  color:var(--muted);
  font-size:13px;
}
.thinkingLabel{ display:inline-block; }
.thinkingLabel > span{ display:inline-block; white-space:pre; }
.spinner{
  width:14px;height:14px;
  border:2px solid var(--border);
  border-top-color:var(--fg);
  border-radius:50%;
  animation:spin .8s linear infinite;
  flex:0 0 auto;
  margin-top:2px;
}
@keyframes spin{to{transform:rotate(360deg)}}

.upgrade-btn-spinner {
  display: inline-block;
  width: 12px;
  height: 12px;
  border: 2px solid rgba(0,0,0,0.2);
  border-top-color: var(--bg);
  border-radius: 50%;
  animation: spin .7s linear infinite;
  vertical-align: middle;
  margin-right: 6px;
}

/* ---------- Upload Modal ---------- */
.uploadModal{
  display:none;
  position:fixed;inset:0;
  z-index:99999;
  background:rgba(0,0,0,0.7);
  align-items:center;
  justify-content:center;
}
.uploadModal.open{ display:flex; }
.uploadModalContent{
  background:var(--surface);
  border:1px solid var(--border);
  border-radius:14px;
  padding:28px 24px 24px;
  max-width:400px;
  width:calc(100% - 32px);
  position:relative;
  text-align:center;
}
.uploadModalClose{
  position:absolute;
  top:10px;right:14px;
  background:none;border:none;
  color:var(--muted);font-size:22px;
  cursor:pointer;line-height:1;
  padding:4px;
}
.uploadModalClose:hover{color:var(--fg)}
.uploadModalTitle{
  font-size:17px;
  font-weight:650;
  margin-bottom:6px;
  color:var(--fg);
}
.uploadModalSub{
  font-size:13px;
  color:var(--muted);
  margin-bottom:20px;
}
.uploadDropZone{
  border:2px dashed var(--border);
  border-radius:12px;
  padding:32px 20px;
  cursor:pointer;
  display:flex;
  flex-direction:column;
  align-items:center;
  gap:10px;
  transition:border-color .2s, background .2s;
}
.uploadDropZone:hover{
  border-color:rgba(255,255,255,0.25);
  background:rgba(255,255,255,0.03);
}
.uploadDropZone.dragover{
  border-color:#4a9eff;
  background:rgba(74,158,255,0.06);
}
.uploadDropLabel{
  font-size:14px;
  font-weight:600;
  color:var(--fg);
}
.uploadDropHint{
  font-size:12px;
  color:var(--muted);
}

/* ---------- Settings Page ---------- */
.settingsPage{
  display:none;
  position:fixed;inset:0;
  z-index:99998;
  background:var(--bg);
  overflow-y:auto;
  -webkit-overflow-scrolling:touch;
}
.settingsPage.open{ display:flex; flex-direction:column; }
.settingsPageInner{
  max-width:480px;
  width:100%;
  margin:0 auto;
  padding:24px 20px 48px;
}
.settingsHeader{
  display:flex;
  align-items:center;
  gap:12px;
  margin-bottom:32px;
}
.settingsBackBtn{
  background:none;border:none;
  color:var(--fg);cursor:pointer;
  padding:6px;border-radius:8px;
  display:flex;align-items:center;justify-content:center;
}
.settingsBackBtn:hover{background:var(--surface)}
.settingsTitle{
  font-size:20px;
  font-weight:700;
  color:var(--fg);
}
.settingsSection{
  margin-bottom:28px;
}
.settingsSectionTitle{
  font-size:12px;
  font-weight:600;
  text-transform:uppercase;
  letter-spacing:0.05em;
  color:var(--muted);
  margin-bottom:10px;
}
.settingsCard{
  background:var(--surface);
  border:1px solid var(--border);
  border-radius:12px;
  padding:16px 18px;
}
.settingsEmail{
  font-size:15px;
  color:var(--fg);
  word-break:break-all;
}
.settingsOptionGroup{
  display:flex;
  flex-direction:column;
  gap:0;
}
.settingsOption{
  display:flex;
  align-items:center;
  justify-content:space-between;
  padding:14px 18px;
  cursor:pointer;
  transition:background .15s;
  border:1px solid var(--border);
  background:var(--surface);
}
.settingsOption:first-child{
  border-radius:12px 12px 0 0;
}
.settingsOption:last-child{
  border-radius:0 0 12px 12px;
  border-top:none;
}
.settingsOption:hover{background:rgba(255,255,255,0.04)}
.settingsOption.active{
  background:rgba(255,255,255,0.06);
}
.settingsOptionLeft{
  display:flex;
  flex-direction:column;
  gap:2px;
}
.settingsOptionLabel{
  font-size:14px;
  font-weight:600;
  color:var(--fg);
}
.settingsOptionDesc{
  font-size:12px;
  color:var(--muted);
}
.settingsRadio{
  width:18px;height:18px;
  border-radius:50%;
  border:2px solid var(--muted);
  display:flex;align-items:center;justify-content:center;
  flex-shrink:0;
  transition:border-color .15s;
}
.settingsOption.active .settingsRadio{
  border-color:#4a9eff;
}
.settingsRadioDot{
  width:10px;height:10px;
  border-radius:50%;
  background:transparent;
  transition:background .15s;
}
.settingsOption.active .settingsRadioDot{
  background:#4a9eff;
}
.settingsManageBtn{
  width:100%;
  padding:14px;
  border-radius:12px;
  border:1px solid var(--border);
  background:var(--surface);
  color:var(--fg);
  font-size:15px;
  font-weight:600;
  cursor:pointer;
  transition:background .15s;
  display:flex;
  align-items:center;
  justify-content:center;
  gap:8px;
}
.settingsManageBtn:hover{background:rgba(255,255,255,0.06)}

/* ---------- Save Toggle ---------- */
.saveToggleWrap{
  display:flex;
  align-items:center;
  gap:6px;
}
.saveToggleLabel{
  font-size:11px;
  color:var(--muted);
  font-weight:600;
  white-space:nowrap;
  user-select:none;
  cursor:pointer;
}
.saveToggle{
  position:relative;
  width:36px;
  height:20px;
  flex-shrink:0;
  cursor:pointer;
}
.saveToggle input{
  opacity:0;
  width:0;
  height:0;
  position:absolute;
}
.saveToggleTrack{
  position:absolute;
  inset:0;
  background:var(--border);
  border-radius:10px;
  transition:background .2s ease;
}
.saveToggle input:checked + .saveToggleTrack{
  background:#4a9eff;
}
.saveToggleThumb{
  position:absolute;
  top:2px;
  left:2px;
  width:16px;
  height:16px;
  background:var(--fg);
  border-radius:50%;
  transition:transform .2s ease;
  pointer-events:none;
}
.saveToggle input:checked ~ .saveToggleThumb{
  transform:translateX(16px);
}

/* ---------- Sidebar ---------- */
.sidebar{
  position:fixed;
  top:0;left:0;
  width:280px;
  height:100%;
  background:#171717;
  border-right:1px solid var(--border);
  z-index:1000;
  display:flex;
  flex-direction:column;
  transform:translateX(-100%);
  transition:transform .25s cubic-bezier(.4,0,.2,1);
  overflow:hidden;
}
.sidebar.open{ transform:translateX(0); }

.sidebarBackdrop{
  position:fixed;inset:0;
  background:rgba(0,0,0,0.5);
  z-index:999;
  opacity:0;
  pointer-events:none;
  transition:opacity .25s ease;
}
.sidebarBackdrop.visible{
  opacity:1;
  pointer-events:auto;
}

.sidebarHeader{
  display:flex;
  align-items:center;
  justify-content:space-between;
  padding:14px 14px 8px;
  gap:8px;
}

.sidebarNewChatBtn{
  display:flex;align-items:center;gap:8px;
  background:var(--surface);
  border:1px solid var(--border);
  color:var(--fg);
  border-radius:10px;
  padding:8px 14px;
  font:inherit;font-size:13px;font-weight:600;
  cursor:pointer;
  flex:1;
}
.sidebarNewChatBtn:hover{ background:var(--input-bg); }

.sidebarCloseBtn{
  background:none;border:none;color:var(--fg);cursor:pointer;
  width:36px;height:36px;display:flex;align-items:center;justify-content:center;
  border-radius:8px;flex-shrink:0;
}
.sidebarCloseBtn:hover{ background:var(--surface); }

.sidebarLabel{
  padding:4px 18px 6px;
  font-size:11px;
  font-weight:600;
  text-transform:uppercase;
  letter-spacing:.5px;
  color:var(--muted);
}

.chatList{
  flex:1;overflow-y:auto;
  padding:0 8px 12px;
  display:flex;flex-direction:column;gap:2px;
}
.chatList::-webkit-scrollbar{ width:4px; }
.chatList::-webkit-scrollbar-thumb{ background:var(--border);border-radius:2px; }

.chatListEmpty{
  padding:20px 10px;
  text-align:center;
  color:var(--muted);
  font-size:13px;
}

.chatItem{
  display:flex;align-items:center;gap:6px;
  padding:10px 10px;
  border-radius:10px;
  cursor:pointer;
  font-size:13px;
  color:var(--fg);
  position:relative;
  min-height:40px;
}
.chatItem:hover{ background:var(--surface); }
.chatItem.active{ background:var(--surface); }

.chatItemTitle{
  flex:1;
  overflow:hidden;
  text-overflow:ellipsis;
  white-space:nowrap;
  line-height:1.3;
}
.chatItemTime{
  font-size:11px;
  color:var(--muted);
  white-space:nowrap;
  flex-shrink:0;
}

.chatItemActions{
  display:none;
  gap:2px;
  flex-shrink:0;
}
.chatItem:hover .chatItemActions{ display:flex; }
.chatItem:hover .chatItemTime{ display:none; }

.chatItemBtn{
  background:none;border:none;color:var(--muted);
  cursor:pointer;padding:2px;border-radius:4px;
  display:flex;align-items:center;justify-content:center;
  width:26px;height:26px;
}
.chatItemBtn:hover{ color:var(--fg);background:rgba(255,255,255,0.08); }

.chatItemRenameInput{
  flex:1;
  background:var(--input-bg);
  border:1px solid var(--border);
  color:var(--fg);
  font:inherit;font-size:13px;
  padding:4px 8px;
  border-radius:6px;
  outline:none;
}
.chatItemRenameInput:focus{ border-color:rgba(255,255,255,0.3); }

.sidebarToggleBtn{
  background:none;border:none;color:var(--fg);
  cursor:pointer;padding:0;
  width:28px;height:28px;
  display:flex;align-items:center;justify-content:center;
  border-radius:6px;flex-shrink:0;
}
.sidebarToggleBtn:hover{ background:var(--surface); }

@media (min-width:641px){
  .sidebarBackdrop{ display:none; }
}
@media (max-width:640px){
  .sidebar{ width:85vw;max-width:320px; }
  .wrap{ padding:14px 6px; }
  .headerActions{ gap:4px !important; }
}
