
:root{
  --bg1:#f8e9f0;
  --bg2:#f1ecff;
  --card: rgba(255,255,255,0.62);
  --card2: rgba(255,255,255,0.78);
  --stroke: rgba(255,255,255,0.55);
  --text:#1a1a1a;
  --muted: rgba(0,0,0,0.55);
  --shadow: 0 12px 40px rgba(0,0,0,0.10);
  --radius: 18px;
  --radius2: 14px;
  --primary: #7b61ff;
  --danger: #ff4d6d;
  --mono: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace;
}

*{ box-sizing:border-box; }
html,body{ height:100%; margin:0; font-family: -apple-system,BlinkMacSystemFont,"Segoe UI",Roboto,Helvetica,Arial,"PingFang SC","Hiragino Sans GB","Microsoft YaHei",sans-serif; color:var(--text); font-size:14px; line-height:1.35; }
#bg{
  position:fixed; inset:0;
  background:
    radial-gradient(1200px 900px at 15% 10%, rgba(255,214,232,0.85), transparent 55%),
    radial-gradient(900px 700px at 80% 20%, rgba(230,214,255,0.78), transparent 55%),
    radial-gradient(900px 800px at 70% 85%, rgba(214,248,255,0.72), transparent 55%),
    linear-gradient(135deg,var(--bg1),var(--bg2));
  filter:saturate(1.05);
}

.app{
  position:relative;
  height:100%;
  display:flex;
  gap:16px;
  padding:16px;
}

.sidebar{
  width:300px;
  flex:0 0 300px;
  display:flex;
  flex-direction:column;
  gap:12px;
}

.main{
  flex:1;
  min-width:0;
  display:flex;
  flex-direction:column;
  border-radius: var(--radius);
  background: var(--card);
  border: 1px solid var(--stroke);
  backdrop-filter: blur(18px);
  box-shadow: var(--shadow);
  overflow:hidden;
}

.card{
  border-radius: var(--radius);
  background: var(--card);
  border: 1px solid var(--stroke);
  backdrop-filter: blur(18px);
  box-shadow: var(--shadow);
}

.userCard{
  display:flex;
  align-items:center;
  gap:12px;
  padding:12px;
  cursor:pointer;
}
.avatar{
  width:44px; height:44px; border-radius:14px;
  border:1px solid rgba(255,255,255,0.7);
  box-shadow: 0 6px 16px rgba(0,0,0,0.08);
}
.userMeta{ flex:1; min-width:0; }
.userName{ font-weight:700; letter-spacing:0.2px; white-space:nowrap; overflow:hidden; text-overflow:ellipsis; }
.userStatus{ font-size:12px; color:var(--muted); margin-top:2px; }

.section{
  padding:12px;
  border-radius: var(--radius);
  background: var(--card);
  border: 1px solid var(--stroke);
  backdrop-filter: blur(18px);
  box-shadow: var(--shadow);
}
.sectionTitle{
  font-weight:700;
  font-size:13px;
  color: rgba(0,0,0,0.72);
  margin-bottom:10px;
}

.row{ display:flex; gap:8px; align-items:center; }
.row + .row{ margin-top:8px; }
.wide{ width:100%; justify-content:center; }

.input{
  width:100%;
  padding:10px 12px;
  border-radius: 14px;
  border: 1px solid rgba(0,0,0,0.08);
  background: rgba(255,255,255,0.70);
  outline:none;
}
.input:focus{ border-color: rgba(123,97,255,0.45); box-shadow: 0 0 0 4px rgba(123,97,255,0.12); }

.textarea{
  width:100%;
  padding:10px 12px;
  border-radius: 14px;
  border: 1px solid rgba(0,0,0,0.08);
  background: rgba(255,255,255,0.70);
  outline:none;
  resize:none;
  line-height:1.35;
}
.textarea:focus{ border-color: rgba(123,97,255,0.45); box-shadow: 0 0 0 4px rgba(123,97,255,0.12); }

button{
  border:0; cursor:pointer;
  border-radius: 14px;
  padding:10px 12px;
  background: rgba(255,255,255,0.68);
  border: 1px solid rgba(0,0,0,0.08);
}
button:hover{ filter:brightness(0.98); }
button:active{ transform: translateY(1px); }

.primary{
  background: linear-gradient(135deg, rgba(123,97,255,0.95), rgba(255,122,200,0.80));
  color:white;
  border: 1px solid rgba(255,255,255,0.55);
  font-weight:700;
}
.ghost{ background: rgba(255,255,255,0.55); }
.danger{
  background: rgba(255,77,109,0.15);
  border: 1px solid rgba(255,77,109,0.28);
  color:#a10f29;
  font-weight:700;
}
.small{ padding:7px 10px; font-size:12px; }
.iconBtn{ width:44px; height:44px; display:flex; align-items:center; justify-content:center; padding:0; border-radius: 14px; }

.list{
  margin-top:10px;
  display:flex;
  flex-direction:column;
  gap:6px;
  max-height: 40vh;
  overflow:auto;
  padding-right:4px;
}
.listItem{
  display:flex;
  align-items:center;
  gap:10px;
  padding:10px 10px;
  border-radius: 14px;
  background: rgba(255,255,255,0.55);
  border: 1px solid rgba(0,0,0,0.06);
}
.listItem.active{ border-color: rgba(123,97,255,0.35); box-shadow: 0 0 0 4px rgba(123,97,255,0.10); }
.listItem .meta{ flex:1; min-width:0; }
.listItem .title{ font-weight:700; white-space:nowrap; overflow:hidden; text-overflow:ellipsis; }
.listItem .date{ font-size:12px; color:var(--muted); margin-top:2px; }
.listItem .actions{ display:flex; gap:6px; opacity:0; }
.listItem:hover .actions{ opacity:1; }
.actionBtn{ padding:6px 8px; font-size:12px; border-radius: 12px; }

.hint{ font-size:12px; color:var(--muted); margin-top:8px; line-height:1.35; }
.mono{ font-family: var(--mono); }

.pillBeta{
  display: inline-block;
  margin-left: 8px;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 12px;
  background: rgba(255,255,255,0.65);
  border: 1px solid rgba(0,0,0,0.06);
}

.helpWrap{
  max-height: 62vh;
  overflow: auto;
  padding-right: 4px;
}
.helpWrap details{ margin: 10px 0; }
.helpWrap summary{ cursor: pointer; font-weight: 700; }
.helpWrap ul{ margin: 8px 0 4px 18px; }
.helpWrap li{ margin: 6px 0; }
.helpWrap .helpGrid{ display: grid; grid-template-columns: 1fr; gap: 8px; }
.helpWrap .helpCard{
  background: rgba(255,255,255,0.65);
  border: 1px solid rgba(0,0,0,0.06);
  border-radius: 14px;
  padding: 10px 12px;
}
.helpWrap .helpTitle{ font-weight: 800; margin-bottom: 6px; }
.helpWrap .helpRow{ display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.helpWrap .helpRow .mono{ font-size: 12px; }

.memoryNote{
  margin: 8px 0 10px;
  padding: 10px 12px;
  border-radius: 14px;
  background: rgba(255,255,255,0.6);
  border: 1px solid rgba(0,0,0,0.06);
  line-height: 1.5;
}

.topbar{
  display:flex;
  align-items:center;
  justify-content:space-between;
  padding:12px 14px;
  border-bottom: 1px solid rgba(255,255,255,0.40);
}
.convTitle{ display:flex; align-items:center; gap:10px; min-width:0; }
.pill{
  width:34px; height:34px;
  display:flex; align-items:center; justify-content:center;
  border-radius: 14px;
  background: rgba(255,255,255,0.55);
  border: 1px solid rgba(0,0,0,0.06);
}
.titleBtn{
  background: transparent;
  border:0;
  padding:0;
  font-weight:800;
  font-size:16px;
  max-width: 380px;
  white-space:nowrap; overflow:hidden; text-overflow:ellipsis;
}
.sub{ font-size:12px; color:var(--muted); }
#appVersion{ margin-left:8px; }

.topActions{ display:flex; align-items:center; gap:10px; }
.toggle{ display:flex; align-items:center; gap:8px; font-size:12px; color:var(--muted); }
.toggle input{ transform: scale(1.15); }

.contextBar{
  display:flex;
  align-items:center;
  gap:8px;
  padding:10px 14px;
  border-bottom: 1px solid rgba(255,255,255,0.40);
}
.contextBar .label{ font-size:12px; color:var(--muted); }
.tags{ display:flex; gap:6px; flex-wrap:wrap; }
.tag{
  padding:6px 10px;
  border-radius: 999px;
  font-size:12px;
  background: rgba(255,255,255,0.60);
  border: 1px solid rgba(0,0,0,0.06);
}

.messages{
  flex:1;
  overflow:auto;
  padding:16px 14px;
  display:flex;
  flex-direction:column;
  gap:10px;
}
.msgRow{ display:flex; }
.msgStack{ display:flex; flex-direction:column; max-width:76%; }
.msgRow.user .msgStack{ align-items:flex-end; }
.msgRow.assistant .msgStack{ align-items:flex-start; }
.bubble{
  max-width: 100%;
  padding:12px 12px;
  border-radius: 16px;
  border: 1px solid rgba(0,0,0,0.06);
  background: rgba(255,255,255,0.70);
  position:relative;
}
.msgRow.user{ justify-content:flex-end; }
.msgRow.user .bubble{
  background: rgba(123,97,255,0.18);
  border-color: rgba(123,97,255,0.22);
}
.msgRow.assistant{ justify-content:flex-start; }
.msgOps{
  display:flex;
  gap:6px;
  margin-top:6px;
  opacity:0.9;
}
.msgOpBtn{
  padding:4px 6px;
  border-radius: 10px;
  font-size:12px;
}
.sysNote{
  margin-top:8px;
  font-size:12px;
  color: rgba(0,0,0,0.52);
}

.composer{
  padding:12px 14px;
  border-top: 1px solid rgba(255,255,255,0.40);
  background: rgba(255,255,255,0.20);
  backdrop-filter: blur(12px);
}
.composerTop{ display:flex; gap:10px; align-items:flex-end; }
.composerBottom{ display:flex; justify-content:space-between; align-items:center; margin-top:10px; gap:10px; }
.error{ margin-top:8px; font-size:12px; color:#b00020; min-height: 14px; }

.drawer{
  position:fixed;
  top:16px; bottom:16px; right:16px;
  width:min(1080px, calc(100% - 332px));
  border-radius: var(--radius);
  background: var(--card2);
  border: 1px solid var(--stroke);
  backdrop-filter: blur(20px);
  box-shadow: var(--shadow);
  display:none;
  overflow:hidden;
}
.drawer.show{ display:flex; flex-direction:column; }
.drawerHeader{
  display:flex;
  justify-content:space-between;
  align-items:center;
  padding:12px 14px;
  border-bottom: 1px solid rgba(0,0,0,0.06);
}
.drawerTitle{ font-weight:900; }
.drawerActions{ display:flex; gap:8px; }

.drawerBody{ flex:1; display:flex; flex-direction:column; }
.memoryToolbar{
  padding:12px 14px;
  display:flex;
  gap:10px;
  border-bottom: 1px solid rgba(0,0,0,0.06);
}
.memoryToolbar .input{ max-width: 360px; }
.memoryGrid{
  flex:1;
  display:grid;
  grid-template-columns: 1.6fr 1fr;
  gap:14px;
  padding:14px;
  min-height:0;
}
.memoryLeft{
  min-height:0;
  display:flex;
  flex-direction:column;
}
.memoryViewTabs{ display:flex; gap:8px; margin-bottom:10px; }
.tab{
  padding:8px 10px;
  border-radius: 999px;
  background: rgba(255,255,255,0.62);
}
.tab.active{ border-color: rgba(123,97,255,0.35); box-shadow: 0 0 0 4px rgba(123,97,255,0.10); }
.memoryCanvas{
  flex:1;
  border-radius: 16px;
  background: rgba(255,255,255,0.55);
  border: 1px solid rgba(0,0,0,0.06);
  min-height: 340px;
}
.memoryList{
  flex:1;
  overflow:auto;
  border-radius: 16px;
  background: rgba(255,255,255,0.55);
  border: 1px solid rgba(0,0,0,0.06);
  padding:10px;
}
.memItem{
  border-radius: 14px;
  padding:10px;
  border: 1px solid rgba(0,0,0,0.06);
  background: rgba(255,255,255,0.60);
  margin-bottom:8px;
}
.memItem .top{ display:flex; justify-content:space-between; gap:8px; }
.memItem .title{ font-weight:800; }
.memItem .meta{ font-size:12px; color:var(--muted); margin-top:4px; }

.memoryRight{
  border-radius: 16px;
  background: rgba(255,255,255,0.55);
  border: 1px solid rgba(0,0,0,0.06);
  padding:12px;
  overflow:auto;
  min-height:0;
}
.panelTitle{ font-weight:900; margin-bottom:10px; }
.panelBody{ display:flex; flex-direction:column; gap:12px; }
.fieldLabel{ font-size:12px; color:var(--muted); margin-bottom:6px; }
.fieldValue{ font-family: var(--mono); font-size:12px; }
.fieldRow{ display:grid; grid-template-columns: 1fr 1fr; gap:10px; }
.chips{ display:flex; gap:6px; flex-wrap:wrap; }
.chip{
  padding:6px 10px;
  border-radius: 999px;
  font-size:12px;
  background: rgba(255,255,255,0.60);
  border: 1px solid rgba(0,0,0,0.06);
}

.bulkBar{
  display:flex;
  justify-content:space-between;
  align-items:center;
  padding:10px 14px;
  border-top: 1px solid rgba(0,0,0,0.06);
  background: rgba(255,255,255,0.35);
}
.bulkActions{ display:flex; gap:8px; }

.modal{
  position:fixed;
  inset:0;
  display:flex;
  align-items:center;
  justify-content:center;
  background: rgba(0,0,0,0.25);
  backdrop-filter: blur(10px);
}

.modal[hidden]{ display:none !important; }
 .modalCard{
  width: min(520px, calc(100vw - 24px));
  max-height: calc(100vh - 24px);
  overflow: auto;
  -webkit-overflow-scrolling: touch;
  border-radius: var(--radius);
  background: rgba(255,255,255,0.80);
  border: 1px solid rgba(255,255,255,0.65);
  box-shadow: var(--shadow);
  padding:14px;
 }
.modalTitle{ font-weight:900; margin-bottom:10px; }

@media (max-width: 880px){
  .app{ padding:10px; gap:10px; }
  .sidebar{ width:260px; flex-basis:260px; }
  .drawer{ width: calc(100% - 20px); right:10px; left:10px; }
  .memoryGrid{ grid-template-columns: 1fr; }
}



/* --- UX fixes: message ops + mobile --- */
.msgOpBtn{
  background: transparent;
  border: 0;
  padding: 6px;
  border-radius: 10px;
  -webkit-tap-highlight-color: transparent;
}
.msgOpBtn:focus{ outline: none; }
.msgOpBtn:focus-visible{ outline: none; }

@media (max-width: 900px){
  .app{ flex-direction: column; height: auto; min-height: 100vh; }
  .sidebar{ width: auto; border-right: 0; border-bottom: 1px solid rgba(255,255,255,.25); }
  .main{ height: auto; }
  .messages{ min-height: 45vh; }
  .composer{ position: sticky; bottom: 0; background: rgba(250,250,255,.85); backdrop-filter: blur(10px); }
}
/* On touch devices, don't overlay ops on top of content */
@media (pointer: coarse){
  .msgOps{ opacity: 1; }
  .bubble{ padding-top: 14px; }
}

/* iOS Safari: prevent auto-zoom on focus (needs >=16px font-size) */
@supports (-webkit-touch-callout: none) {
  input, textarea, select{ font-size:16px !important; }
}

button, input, textarea, select { font: inherit; }


/* iOS zoom fix: prevent Safari auto-zoom on focus */
    @media (max-width: 520px){
      textarea#input, input, select, button { font-size: 16px; }
    }


.attachBar{
  display:flex;
  align-items:center;
  gap:10px;
  padding:8px 10px;
  margin:8px 0 0;
  border-radius: 12px;
  background: rgba(255,255,255,0.55);
  border: 1px solid rgba(255,255,255,0.55);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  font-size: 12px;
}
.attachName{ font-family: var(--mono); opacity: .85; overflow:hidden; text-overflow:ellipsis; white-space:nowrap; }
.ghost.small{ padding:4px 8px; border-radius: 10px; }

.betaTag{display:inline-block;margin-left:8px;padding:2px 8px;border-radius:999px;background:rgba(0,0,0,.06);font-size:12px;}
.pwRow{display:flex;gap:8px;align-items:center;}
.pwRow input{flex:1;}
.err{color:#b00020;margin-top:8px;min-height:18px;}
.helpBlock{margin:10px 0;padding:10px;border-radius:12px;background:rgba(0,0,0,.03);}
.helpTitle{font-weight:700;margin-bottom:6px;}
.helpList{margin:0;padding-left:18px;}
