:root{--bg:#0b1220;--card:#111a2e;--text:#e8eefc;--muted:#9fb0d0;--accent:#4da3ff;--danger:#ff4d6d;}
html[data-theme="light"]{--bg:#f4f6ff;--card:#ffffff;--text:#101a2f;--muted:#54627c;--accent:#2d7dff;--danger:#d72d4c;}
html[data-theme="light"] .card{background:rgba(255,255,255,.82);border:1px solid rgba(20,30,60,.10);box-shadow:0 12px 30px rgba(0,0,0,.12)}
html[data-theme="light"] .input{background:rgba(255,255,255,.92);border-color:rgba(20,30,60,.12)}
html[data-theme="light"] .btn{background:rgba(255,255,255,.72);border-color:rgba(20,30,60,.14)}
html[data-theme="light"] .item{background:rgba(255,255,255,.60);border-color:rgba(20,30,60,.10)}
html[data-theme="light"] .bubble{background:rgba(255,255,255,.74);border-color:rgba(20,30,60,.10)}
html[data-theme="light"] .me{background:rgba(45,125,255,.14);border-color:rgba(45,125,255,.22)}
html[data-theme="light"] dialog.modal::backdrop{background:rgba(0,0,0,.45)}
html[data-theme="light"] .modal-inner{background:rgba(255,255,255,.92);border:1px solid rgba(20,30,60,.14);box-shadow:0 18px 60px rgba(0,0,0,.18)}
html[data-theme="light"] hr{border-top:1px solid rgba(20,30,60,.10)}

*{box-sizing:border-box}
html{background:var(--bg)}
html,body{min-height:100%}
body{margin:0;font-family:system-ui,-apple-system,Segoe UI,Roboto,Ubuntu,'Helvetica Neue',Arial;background:var(--bg);color:var(--text);position:relative}
body::before{
  content:"";
  position:fixed;
  inset:0;
  z-index:-1;
  background:
    radial-gradient(1200px 700px at 10% 0%, rgba(77,163,255,.18), transparent 55%),
    radial-gradient(900px 600px at 90% 20%, rgba(255,77,109,.12), transparent 55%),
    linear-gradient(180deg, var(--bg), #070b14),
    repeating-linear-gradient(45deg, rgba(255,255,255,.02) 0 1px, transparent 1px 4px);
  background-repeat:no-repeat;
  background-size:cover;
  transform:translateZ(0);
  will-change:transform;
}
html[data-theme="light"] body::before{
  background:
    radial-gradient(1200px 700px at 10% 0%, rgba(45,125,255,.16), transparent 55%),
    radial-gradient(900px 600px at 90% 20%, rgba(215,45,76,.08), transparent 55%),
    linear-gradient(180deg, var(--bg), #e7ecff),
    repeating-linear-gradient(45deg, rgba(0,0,0,.02) 0 1px, transparent 1px 4px);
  background-repeat:no-repeat;
  background-size:cover;
}
a{color:var(--accent);text-decoration:none}
.container{max-width:1100px;margin:0 auto;padding:18px}
.topbar{display:flex;align-items:center;justify-content:space-between;margin-bottom:14px}
.brand{font-weight:800;letter-spacing:.4px}
.card{background:rgba(17,26,46,.85);border:1px solid rgba(255,255,255,.08);border-radius:16px;padding:16px;box-shadow:0 12px 30px rgba(0,0,0,.35)}
.grid{display:grid;grid-template-columns:320px 1fr;gap:14px}
@media(max-width:900px){.grid{grid-template-columns:1fr}}
.input{width:100%;padding:10px 12px;border-radius:12px;border:1px solid rgba(255,255,255,.12);background:#0e1730;color:var(--text);outline:none}
.btn{display:inline-flex;align-items:center;gap:8px;padding:10px 14px;border-radius:12px;border:1px solid rgba(255,255,255,.14);background:#142247;color:var(--text);cursor:pointer}
.btn.primary{background:linear-gradient(90deg,#2d7dff,#5ab0ff);border:none;color:#061022;font-weight:700}
.btn.danger{background:transparent;border-color:rgba(255,77,109,.45);color:var(--danger)}
.small{font-size:13px;color:var(--muted)}
.row{display:flex;gap:10px;align-items:center}
.avatar{width:38px;height:38px;border-radius:999px;background:#0e1730;border:1px solid rgba(255,255,255,.14);object-fit:cover}
.list{display:flex;flex-direction:column;gap:10px;margin-top:10px}
.item{display:flex;gap:10px;align-items:center;padding:10px;border-radius:14px;border:1px solid rgba(255,255,255,.08);background:rgba(14,23,48,.7)}
.item:hover{border-color:rgba(77,163,255,.35)}
.badge{margin-left:auto;background:rgba(77,163,255,.18);border:1px solid rgba(77,163,255,.35);padding:4px 8px;border-radius:999px;font-size:12px;color:#cfe6ff}
.chatbox{display:flex;flex-direction:column;height:70vh}
.messages{flex:1;overflow:auto;padding:10px;display:flex;flex-direction:column;gap:10px}
.bubble{max-width:75%;padding:10px 12px;border-radius:14px;border:1px solid rgba(255,255,255,.10);background:rgba(14,23,48,.85)}
.me{align-self:flex-end;background:rgba(77,163,255,.18);border-color:rgba(77,163,255,.3)}
.meta{font-size:12px;color:var(--muted);margin-top:4px}
.composer{display:flex;gap:10px;margin-top:10px}

/* Message rows with avatars */
.msg-row{display:flex;gap:8px;align-items:flex-end}
.msg-row.mine{justify-content:flex-end}
.msg-avatar{width:28px;height:28px}

/* Actions */
.bubble{position:relative}

/* Reply preview */
.reply-preview{border-right:3px solid rgba(77,163,255,.65);background:rgba(77,163,255,.10);padding:8px 10px;border-radius:12px;margin:6px 0 10px;cursor:pointer}
.reply-preview:hover{background:rgba(77,163,255,.14)}

/* Attachments */
.msg-attach{margin-top:8px}
.msg-media{display:block;max-width:260px;max-height:260px;border-radius:14px;border:1px solid rgba(255,255,255,.10);background:#0e1730;cursor:pointer}
.msg-file{display:flex;align-items:center;gap:10px;padding:10px 12px;border-radius:14px;border:1px solid rgba(255,255,255,.10);background:rgba(14,23,48,.65)}
.msg-file .icon{font-size:20px}
.msg-text{white-space:pre-wrap;line-height:1.55}

/* Context bar */
.context-bar{display:none;gap:10px;align-items:center;border-radius:14px;border:1px solid rgba(255,255,255,.10);background:rgba(14,23,48,.65);padding:10px 12px;margin-top:10px}
.context-bar.show{display:flex}

/* Highlight on jump */
.highlight{outline:2px solid rgba(77,163,255,.55);outline-offset:2px;border-radius:16px}

/* Modal */
dialog.modal{border:none;padding:0;background:transparent}
dialog.modal::backdrop{background:rgba(0,0,0,.65)}
.modal-inner{background:rgba(17,26,46,.95);border:1px solid rgba(255,255,255,.12);border-radius:16px;padding:14px;box-shadow:0 18px 60px rgba(0,0,0,.45);width:min(920px, 92vw)}
hr{border:none;border-top:1px solid rgba(255,255,255,.08);margin:12px 0}
.error{background:rgba(255,77,109,.14);border:1px solid rgba(255,77,109,.35);padding:10px;border-radius:12px}
.ok{background:rgba(0,255,160,.10);border:1px solid rgba(0,255,160,.25);padding:10px;border-radius:12px}

.truncate{overflow:hidden;text-overflow:ellipsis;white-space:nowrap}
.pill{margin-right:auto;background:rgba(255,255,255,.08);border:1px solid rgba(255,255,255,.12);padding:3px 8px;border-radius:999px;font-size:12px;color:var(--muted)}
textarea.input{resize:vertical;min-height:96px}
/* ---------- Mobile-first improvements ---------- */

.topbar{
  position:sticky;
  top:10px;
  z-index:50;
  padding:10px 12px;
  background:rgba(11,18,32,.55);
  backdrop-filter: blur(10px);
  border:1px solid rgba(255,255,255,.08);
  border-radius:16px;
}

.btn{min-height:44px}
.btn{touch-action:manipulation}

.icon-btn{
  display:inline-flex;
  align-items:center;
  justify-content:center;
  width:44px;
  height:44px;
  border-radius:14px;
  border:1px solid rgba(255,255,255,.14);
  background:rgba(20,34,71,.85);
  color:var(--text);
  cursor:pointer;
}

/* Visibility helpers */
.hamburger, .mobile-only{display:none !important;}
@media(max-width:760px){
  .hamburger, .mobile-only{display:inline-flex !important;}
}
.icon-btn.danger{border-color:rgba(255,77,109,.45);color:var(--danger);background:rgba(20,34,71,.55)}


/* Drawer */
.drawer-backdrop{
  display:none;
  position:fixed;
  inset:0;
  background:rgba(0,0,0,.55);
  z-index:60;
}
.drawer-backdrop.show{display:block}
.drawer{
  position:fixed;
  top:0;
  right:0;
  height:100vh;
  width:min(340px, 88vw);
  padding:14px;
  background:rgba(17,26,46,.98);
  border-left:1px solid rgba(255,255,255,.10);
  box-shadow:-18px 0 60px rgba(0,0,0,.45);
  z-index:70;
  transform:translateX(110%);
  transition:transform .18s ease;
}
.drawer.open{transform:translateX(0)}
.drawer-head{display:flex;align-items:center;justify-content:space-between;gap:10px}
.drawer-title{margin-top:12px;font-weight:900;opacity:.9}
.drawer-links{display:flex;flex-direction:column;gap:10px;margin-top:12px}
.drawer-link{
  display:flex;
  align-items:center;
  gap:10px;
  padding:12px 12px;
  border-radius:14px;
  border:1px solid rgba(255,255,255,.10);
  background:rgba(14,23,48,.70);
  color:var(--text);
}
.drawer-link:hover{border-color:rgba(77,163,255,.35)}
.drawer-link.danger{border-color:rgba(255,77,109,.35);color:var(--danger)}
.drawer-link .icon{width:26px;text-align:center}
.no-scroll{overflow:hidden}

/* Better chat height on mobile */
@media(max-width:760px){
  .container{padding:12px}
  .grid{grid-template-columns:1fr}
  .nav-links{display:none !important}
  .hamburger,.mobile-only{display:inline-flex}
  .topbar{top:8px}
  .card{padding:14px;border-radius:18px}
  .chatbox{height:calc(100dvh - 140px)}
  .messages{padding:8px}
  .bubble{max-width:86%}
  .msg-avatar{width:26px;height:26px}
  .pill{display:none}
  .composer{flex-wrap:wrap}
  .composer .input{flex:1 1 100%}
  #fileInput{flex:1 1 55%;max-width:none !important}
  #sendBtn{flex:1 1 40%}
}

/* Slightly smoother lists on phone */
@media(max-width:760px){
  .item{padding:12px}
  .avatar{width:42px;height:42px}
}

/* Reduce overflow in topbar rows */
.topbar .row{flex-wrap:wrap}


/* Toggle switch */
.switch{position:relative;display:inline-block;width:54px;height:30px}
.switch input{display:none}
.switch .slider{position:absolute;cursor:pointer;top:0;left:0;right:0;bottom:0;background:rgba(255,255,255,.10);border:1px solid rgba(255,255,255,.14);transition:.2s;border-radius:999px}
.switch .slider:before{position:absolute;content:"";height:24px;width:24px;left:3px;top:2px;background:rgba(255,255,255,.85);transition:.2s;border-radius:999px}
.switch input:checked + .slider{background:rgba(45,125,255,.25);border-color:rgba(45,125,255,.40)}
.switch input:checked + .slider:before{transform:translateX(24px)}
html[data-theme="light"] .switch .slider{background:rgba(20,30,60,.08);border-color:rgba(20,30,60,.14)}
html[data-theme="light"] .switch .slider:before{background:rgba(20,30,60,.18)}

/* Message context menu */
.ctx-menu{
  position:fixed;
  z-index:90;
  display:none;
  min-width:180px;
  max-width:min(260px, 92vw);
  padding:6px;
  border-radius:14px;
  border:1px solid rgba(255,255,255,.12);
  background:rgba(17,26,46,.98);
  box-shadow:0 18px 60px rgba(0,0,0,.55);
}
html[data-theme="light"] .ctx-menu{
  background:rgba(255,255,255,.96);
  border-color:rgba(20,30,60,.14);
  box-shadow:0 18px 60px rgba(0,0,0,.18);
}
.ctx-menu.show{display:block}
.ctx-menu button{
  width:100%;
  display:flex;
  align-items:center;
  justify-content:flex-start;
  gap:10px;
  padding:10px 12px;
  border:none;
  border-radius:12px;
  background:transparent;
  color:var(--text);
  cursor:pointer;
  font:inherit;
}
.ctx-menu button:hover{background:rgba(77,163,255,.14)}
.ctx-menu button.danger{color:var(--danger)}
.ctx-menu hr{
  border:none;
  border-top:1px solid rgba(255,255,255,.10);
  margin:6px 0;
}
html[data-theme="light"] .ctx-menu hr{border-top:1px solid rgba(20,30,60,.10)}
