:root{
  --bg:#0d0f12;
  --panel:#111419;
  --panel2:#171b22;
  --line:#252a33;
  --text:#f4f6f8;
  --muted:#8c95a5;
  --accent:#7b67ff;
  --bubble:#1a1f27;
  --mine:#2b2548;
  --danger:#ff7d7d;
}

*{
  box-sizing:border-box;
}

html,
body{
  margin:0;
  height:100%;
  font-family:Inter,ui-sans-serif,system-ui,-apple-system,Segoe UI,sans-serif;
  background:var(--bg);
  color:var(--text);
}

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

.hidden{
  display:none!important;
}


/* =========================
   APP
========================= */

.app{
  height:100dvh;
  display:grid;
  grid-template-columns:310px 1fr;
  background:var(--bg);
}

.side{
  background:var(--panel);
  border-right:1px solid var(--line);
  display:flex;
  flex-direction:column;
  min-width:0;
}

.side-head{
  height:68px;
  padding:0 16px;
  display:flex;
  align-items:center;
  justify-content:space-between;
}

.brand{
  display:flex;
  align-items:center;
  gap:10px;
}

.brand-mark{
  width:54px;
  height:54px;
  border-radius:18px;
  display:grid;
  place-items:center;
  background:linear-gradient(135deg,#7b67ff,#b55cff);
  box-shadow:0 10px 35px #7b67ff33;
  font-size:26px;
}

.brand-mark.small{
  width:34px;
  height:34px;
  border-radius:11px;
  font-size:16px;
}


/* =========================
   SIDEBAR BUTTONS
========================= */

.new-room{
  margin:8px 12px 6px;
  border:1px solid var(--line);
  background:var(--panel2);
  color:var(--text);
  border-radius:13px;
  padding:12px 14px;
  text-align:left;
  cursor:pointer;
}

.archive-toggle{
  margin:0 12px 12px;
  border:1px solid var(--line);
  background:transparent;
  color:var(--muted);
  border-radius:13px;
  padding:10px 14px;
  text-align:left;
  cursor:pointer;
}

.archive-toggle:hover{
  color:var(--text);
  background:var(--panel2);
}


/* =========================
   ROOMS
========================= */

.rooms{
  padding:0 8px;
  overflow:auto;
  flex:1;
}

.room-item{
  position:relative;
  display:flex;
  align-items:center;
  gap:4px;
  border-radius:14px;
  margin:2px 0;
}

.room-item:hover,
.room-item.active{
  background:var(--panel2);
}

.room-main{
  flex:1;
  min-width:0;
  border:0;
  background:transparent;
  color:inherit;
  border-radius:14px;
  padding:9px 4px 9px 9px;
  display:flex;
  gap:10px;
  align-items:center;
  cursor:pointer;
  text-align:left;
}

.room-menu{
  width:34px;
  height:34px;
  flex:0 0 34px;
  border:0;
  background:transparent;
  color:var(--muted);
  border-radius:10px;
  cursor:pointer;
  font-size:21px;
  display:grid;
  place-items:center;
  opacity:.65;
}

.room-item:hover .room-menu,
.room-item.active .room-menu{
  opacity:1;
}

.room-menu:hover{
  background:#ffffff10;
  color:var(--text);
}

.room-avatar{
  width:42px;
  height:42px;
  flex:0 0 42px;
  border-radius:14px;
  background:#292f3a;
  display:grid;
  place-items:center;
  font-weight:700;
}

.room-text{
  min-width:0;
  display:flex;
  flex-direction:column;
  gap:4px;
}

.room-text b,
.room-text small{
  white-space:nowrap;
  overflow:hidden;
  text-overflow:ellipsis;
}

.room-text small{
  color:var(--muted);
  font-size:12px;
}

.no-rooms{
  color:var(--muted);
  padding:20px;
  text-align:center;
}


/* =========================
   SIDEBAR BOTTOM
========================= */

.side-bottom{
  border-top:1px solid var(--line);
  padding:14px;
}

.usage>div:first-child{
  display:flex;
  justify-content:space-between;
  font-size:13px;
}

.meter{
  height:5px;
  background:#252a33;
  border-radius:99px;
  margin:10px 0 6px;
  overflow:hidden;
}

.meter i{
  display:block;
  height:100%;
  width:0;
  background:var(--accent);
}

.usage small{
  color:var(--muted);
}

.side-actions{
  display:flex;
  gap:8px;
  margin-top:12px;
}

.ghost,
.icon-btn{
  border:1px solid var(--line);
  background:transparent;
  color:var(--text);
  border-radius:10px;
  padding:8px 10px;
  cursor:pointer;
}

.side-actions .ghost{
  flex:1;
}


/* =========================
   CHAT
========================= */

.chat{
  min-width:0;
  display:grid;
  grid-template-rows:68px 1fr auto auto;
  height:100dvh;
}

.chat header{
  display:flex;
  align-items:center;
  gap:12px;
  padding:0 18px;
  border-bottom:1px solid var(--line);
  background:color-mix(in srgb,var(--bg) 90%,transparent);
  backdrop-filter:blur(16px);
}

.chat-title{
  min-width:0;
  display:flex;
  flex-direction:column;
  flex:1;
}

.chat-title b,
.chat-title small{
  overflow:hidden;
  text-overflow:ellipsis;
  white-space:nowrap;
}

.chat-title small{
  color:var(--muted);
  margin-top:3px;
}

.top-cost{
  font-size:12px;
  color:var(--muted);
}


/* =========================
   MESSAGES
========================= */

#messages{
  overflow:auto;
  padding:28px max(18px,calc((100vw - 310px - 900px)/2));
  scroll-behavior:smooth;
}

.row{
  display:flex;
  gap:12px;
  margin:16px auto;
  max-width:900px;
}

.row.mine{
  flex-direction:row-reverse;
}

.avatar,
.mini-avatar{
  display:grid;
  place-items:center;
  font-weight:700;
  color:white;
}

.avatar{
  width:36px;
  height:36px;
  border-radius:12px;
  flex:0 0 36px;
}

.mini-avatar{
  width:30px;
  height:30px;
  border-radius:10px;
}

.ai{
  background:linear-gradient(135deg,#785dff,#bc5eff);
}

.u0{background:#5073e8;}
.u1{background:#db5c8a;}
.u2{background:#2f9a78;}
.u3{background:#c77935;}
.u4{background:#8f62cc;}
.u5{background:#62717e;}

.bubble-wrap{
  max-width:min(78%,740px);
  min-width:0;
}

.mine .bubble-wrap{
  display:flex;
  flex-direction:column;
  align-items:flex-end;
}

.message-head{
  width:100%;
  display:flex;
  align-items:center;
  gap:8px;
  min-height:22px;
}

.mine .message-head{
  justify-content:flex-end;
}

.name{
  font-size:12px;
  color:var(--muted);
  margin:0 3px 5px;
}

.message-delete{
  width:24px;
  height:24px;
  border:0;
  background:transparent;
  color:var(--muted);
  border-radius:8px;
  cursor:pointer;
  display:grid;
  place-items:center;
  font-size:16px;
  line-height:1;
  opacity:.35;
  margin:-3px 0 2px;
}

.row:hover .message-delete{
  opacity:1;
}

.message-delete:hover{
  color:#fff;
  background:#ff5a5a33;
}

.bubble{
  background:var(--bubble);
  border:1px solid var(--line);
  padding:11px 14px;
  border-radius:17px;
  line-height:1.45;
  word-break:break-word;
}

.mine .bubble{
  background:var(--mine);
}

.ai-row .bubble{
  background:transparent;
  border-color:transparent;
  padding-left:0;
}

.time{
  font-size:10px;
  color:#687181;
  margin:4px 5px;
}


/* =========================
   ATTACHMENTS
========================= */

.files{
  display:flex;
  flex-wrap:wrap;
  gap:8px;
  margin-top:10px;
}

.attachment-wrap{
  position:relative;
  display:inline-flex;
  max-width:100%;
}

.attachment-wrap>a{
  max-width:100%;
}

.thumb{
  width:min(310px,100%);
  max-height:310px;
  object-fit:cover;
  border-radius:13px;
  border:1px solid var(--line);
  display:block;
}

.attachment-delete{
  position:absolute;
  top:6px;
  right:6px;
  width:28px;
  height:28px;
  border:1px solid #ffffff33;
  background:#090b0ecc;
  color:white;
  border-radius:50%;
  cursor:pointer;
  display:grid;
  place-items:center;
  line-height:1;
  font-size:18px;
  backdrop-filter:blur(8px);
  opacity:.8;
  z-index:2;
}

.attachment-delete:hover{
  background:#b92f39;
  opacity:1;
}

.file-card{
  display:flex;
  align-items:center;
  gap:8px;
  padding:9px 42px 9px 11px;
  border:1px solid var(--line);
  border-radius:12px;
  color:inherit;
  text-decoration:none;
  background:#11151b;
  min-width:180px;
  max-width:100%;
}

.file-card div{
  display:flex;
  flex-direction:column;
  min-width:0;
}

.file-card b{
  white-space:nowrap;
  overflow:hidden;
  text-overflow:ellipsis;
}

.file-card small{
  color:var(--muted);
}


/* =========================
   EMPTY / TYPING
========================= */

.empty{
  height:100%;
  display:grid;
  place-content:center;
  text-align:center;
  color:var(--muted);
  padding:20px;
}

.empty-logo{
  font-size:42px;
  color:#9a85ff;
}

.empty h2{
  color:var(--text);
  margin:12px 0 4px;
}

.typing{
  display:flex;
  gap:5px;
  max-width:900px;
  margin:10px auto;
  padding-left:48px;
}

.typing span{
  width:7px;
  height:7px;
  border-radius:50%;
  background:#8d96a4;
  animation:b 1s infinite alternate;
}

.typing span:nth-child(2){
  animation-delay:.15s;
}

.typing span:nth-child(3){
  animation-delay:.3s;
}

@keyframes b{
  to{
    transform:translateY(-5px);
    opacity:.4;
  }
}


/* =========================
   PENDING FILES
========================= */

.pending{
  display:flex;
  gap:8px;
  overflow:auto;
  padding:8px max(18px,calc((100vw - 310px - 900px)/2));
  border-top:1px solid var(--line);
}

.pending-item{
  display:flex;
  align-items:center;
  gap:7px;
  white-space:nowrap;
  background:var(--panel2);
  border:1px solid var(--line);
  padding:7px 9px;
  border-radius:10px;
}

.pending-item button{
  border:0;
  background:transparent;
  color:var(--muted);
  cursor:pointer;
  font-size:18px;
}


/* =========================
   FOOTER
========================= */

footer{
  border-top:1px solid var(--line);
  padding:12px max(18px,calc((100vw - 310px - 900px)/2)) max(12px,env(safe-area-inset-bottom));
  background:var(--bg);
}

.composer{
  display:flex;
  align-items:flex-end;
  gap:8px;
  background:var(--panel2);
  border:1px solid var(--line);
  border-radius:18px;
  padding:8px;
}

.composer textarea{
  flex:1;
  resize:none;
  border:0;
  outline:0;
  background:transparent;
  color:var(--text);
  padding:8px 4px;
  max-height:160px;
}

.composer textarea:disabled{
  opacity:.45;
}

.send-btn{
  width:38px;
  height:38px;
  border:0;
  border-radius:12px;
  background:var(--text);
  color:var(--bg);
  font-weight:800;
  cursor:pointer;
}

.composer-meta{
  display:flex;
  align-items:center;
  gap:12px;
  font-size:11px;
  color:var(--muted);
  padding:7px 5px 0;
}

.ai-button{
  margin-left:auto;
  border:1px solid #6f5ce777;
  background:#6f5ce722;
  color:#b9adff;
  border-radius:10px;
  padding:6px 10px;
  cursor:pointer;
}

.ai-provider{
  border:1px solid var(--line);
  background:var(--panel2);
  color:var(--text);
  border-radius:10px;
  padding:6px 9px;
  outline:none;
}

.ai-button:disabled,
.send-btn:disabled,
.ai-provider:disabled{
  opacity:.45;
  cursor:not-allowed;
}

.attach{
  width:38px;
  height:38px;
  display:grid;
  place-items:center;
  padding:0;
  font-size:22px;
}


/* =========================
   LOGIN
========================= */

.login-screen{
  position:fixed;
  inset:0;
  background:radial-gradient(circle at 50% 15%,#292044 0,#11131a 42%,#090b0e 100%);
  display:grid;
  place-items:center;
  padding:20px;
}

.login-card{
  width:min(460px,100%);
  background:#14171d;
  border:1px solid #292e38;
  border-radius:25px;
  padding:28px;
  box-shadow:0 30px 100px #0008;
  text-align:center;
}

.login-card .brand-mark{
  margin:0 auto;
}

.login-card h1{
  margin:16px 0 5px;
}

.login-card p{
  color:#9aa3b1;
}

.people{
  display:grid;
  grid-template-columns:repeat(2,1fr);
  gap:8px;
  margin:22px 0;
}

.person{
  display:flex;
  align-items:center;
  gap:9px;
  border:1px solid #2a2f39;
  background:#191d24;
  color:#eee;
  border-radius:13px;
  padding:10px;
  cursor:pointer;
}

.person.active{
  border-color:#806cff;
  box-shadow:0 0 0 2px #806cff22;
}

.login-card form{
  display:flex;
  flex-direction:column;
  gap:10px;
}

.login-card input,
.field input{
  width:100%;
  border:1px solid #303642;
  background:#0f1217;
  color:#fff;
  border-radius:12px;
  padding:12px 14px;
  outline:0;
}

.primary{
  border:0;
  background:#7965ff;
  color:white;
  border-radius:12px;
  padding:12px 16px;
  font-weight:700;
  cursor:pointer;
}

.error{
  min-height:20px;
  color:var(--danger);
  font-size:13px;
  margin-top:8px;
}


/* =========================
   MODAL
========================= */

.modal{
  position:fixed;
  inset:0;
  background:#0009;
  display:grid;
  place-items:center;
  padding:18px;
  z-index:30;
}

.modal-card{
  width:min(480px,100%);
  background:var(--panel);
  border:1px solid var(--line);
  border-radius:20px;
  padding:20px;
  box-shadow:0 30px 100px #000a;
}

.modal-head{
  display:flex;
  justify-content:space-between;
  align-items:center;
}

.modal-head h2{
  margin:0;
}

.field{
  display:flex;
  flex-direction:column;
  gap:8px;
  margin:18px 0;
  color:var(--muted);
}

.member-choices{
  display:grid;
  grid-template-columns:1fr 1fr;
  gap:8px;
}

.member-choice{
  display:flex;
  align-items:center;
  gap:9px;
  padding:9px;
  border:1px solid var(--line);
  border-radius:12px;
  background:var(--panel2);
  color:var(--text);
}

.member-choice input{
  accent-color:var(--accent);
}


/* =========================
   MOBILE
========================= */

.mobile-only{
  display:none;
}

.scrim{
  display:none;
}


/* =========================
   LIGHT THEME
========================= */

.light{
  --bg:#f5f6f8;
  --panel:#ffffff;
  --panel2:#f1f2f5;
  --line:#dcdfe5;
  --text:#16191f;
  --muted:#6d7480;
  --bubble:#fff;
  --mine:#ece8ff;
}

.light .file-card{
  background:#fff;
}

.light .login-screen{
  background:#eef0f5;
}

.light .login-card{
  background:#fff;
  color:#17191f;
}

.light .login-card input,
.light .field input{
  background:#f5f6f8;
  color:#17191f;
}

.light .person{
  background:#f3f4f7;
  color:#17191f;
}

.light .room-menu:hover{
  background:#0000000a;
}

.light .attachment-delete{
  background:#17191fcc;
}


/* =========================
   MOBILE
========================= */

@media(max-width:760px){

  .app{
    grid-template-columns:1fr;
  }

  .mobile-only{
    display:inline-grid;
    place-items:center;
  }

  .side{
    position:fixed;
    z-index:20;
    inset:0 auto 0 0;
    width:min(88vw,330px);
    transform:translateX(-105%);
    transition:.22s;
  }

  .side.open{
    transform:none;
  }

  .scrim.show{
    display:block;
    position:fixed;
    inset:0;
    background:#0008;
    z-index:19;
  }

  .chat header{
    padding:0 12px;
  }

  #messages,
  .pending,
  footer{
    padding-left:12px;
    padding-right:12px;
  }

  .bubble-wrap{
    max-width:84%;
  }

  .composer-meta{
    gap:7px;
    flex-wrap:wrap;
  }

  .composer-meta>span:first-child{
    width:100%;
  }

  .ai-button{
    margin-left:0;
  }

  .ai-provider{
    max-width:170px;
  }

  .top-cost{
    display:none;
  }

  .people{
    grid-template-columns:1fr 1fr;
  }

  .message-delete{
    opacity:.8;
  }

  .room-menu{
    opacity:1;
  }
}