:root{
  --bg:#0e1621;
  --panel:#17212b;
  --panel-2:#202b36;
  --panel-3:#243443;
  --text:#e8f0f8;
  --muted:#8fa3b6;
  --line:#263746;
  --brand:#2aabee;
  --brand-2:#229ed9;
  --danger:#ef4444;
  --ok:#22c55e;
  --bubble-in:#182533;
  --bubble-out:#2b5278;
  --shadow:0 18px 50px rgba(0,0,0,.34);
}
*{box-sizing:border-box}
html,body{height:100%;margin:0}
body{
  font:16px/1.45 system-ui,-apple-system,BlinkMacSystemFont,"Segoe UI",Roboto,Arial,sans-serif;
  background:var(--bg);
  color:var(--text);
}
a{color:#7dd3fc;text-decoration:none}
a:hover{text-decoration:underline}
button,input,textarea,select{font:inherit}
.hidden{display:none!important}
.mobile-only{display:none!important}

.input,textarea,select{
  width:100%;
  background:#111c27;
  border:1px solid var(--line);
  border-radius:13px;
  color:var(--text);
  padding:12px 14px;
  outline:none;
}
.input:focus,textarea:focus,select:focus{border-color:var(--brand);box-shadow:0 0 0 3px rgba(42,171,238,.12)}
.btn{
  border:0;
  border-radius:13px;
  padding:11px 15px;
  background:#263747;
  color:var(--text);
  cursor:pointer;
}
.btn-primary{background:var(--brand);color:#06111a;font-weight:700}
.danger-btn{background:#3b1f27;color:#fecaca;border:1px solid #7f1d1d}
.btn:hover{filter:brightness(1.08)}
.icon-btn,.link-btn{
  border:0;
  background:transparent;
  color:var(--muted);
  cursor:pointer;
  border-radius:12px;
  padding:9px 10px;
}
.icon-btn{font-size:20px;line-height:1;min-width:42px;min-height:42px}
.icon-btn:hover,.link-btn:hover{background:#223244;color:var(--text);text-decoration:none}
.field-error{display:block;color:#fca5a5;margin:-6px 0 8px}
.muted{color:var(--muted)}
.compact-note{margin:4px 0 0;font-size:14px}

.auth-page{display:grid;place-items:center;padding:22px}
.auth-card{width:min(450px,100%);background:var(--panel);border:1px solid var(--line);border-radius:22px;padding:26px;box-shadow:var(--shadow)}
.auth-card.wide{width:min(780px,100%)}
.auth-card h1{margin:0 0 14px}
.auth-card form{display:grid;gap:13px}
.check{display:flex;gap:8px;align-items:center}
.secret-box{display:grid;gap:6px;padding:12px;background:#111c27;border:1px solid var(--line);border-radius:14px;margin:8px 0}
.secret-box code{white-space:normal;word-break:break-all;color:#bfdbfe}

.flash-stack{position:fixed;right:16px;top:16px;z-index:80;display:grid;gap:8px}
.toast{padding:11px 13px;border-radius:14px;background:#1f2937;border:1px solid var(--line);box-shadow:var(--shadow);max-width:390px}
.toast-success{border-color:#166534}
.toast-danger{border-color:#7f1d1d}
.toast-warning{border-color:#92400e}
.toast-info{border-color:#075985}

.messenger{
  height:100vh;
  display:grid;
  grid-template-columns:390px 1fr;
  background:#0e1621;
}
.sidebar,.chat-pane{min-height:0}
.sidebar{
  border-right:1px solid #0b1118;
  background:var(--panel);
  display:flex;
  flex-direction:column;
}
.sidebar-head,.chat-head{
  min-height:70px;
  padding:12px 16px;
  border-bottom:1px solid var(--line);
  display:flex;
  align-items:center;
  justify-content:space-between;
  gap:12px;
  background:var(--panel);
}
.user-block{display:flex;align-items:center;gap:12px;min-width:0}
.avatar-letter,.chat-avatar{
  flex:0 0 auto;
  width:46px;
  height:46px;
  border-radius:50%;
  display:grid;
  place-items:center;
  background:linear-gradient(135deg,#2aabee,#60a5fa);
  color:white;
  font-weight:800;
}
.sidebar-head strong,.chat-head strong{display:block;font-size:17px;line-height:1.15}
.sidebar-head span,.chat-head span{color:var(--muted);font-size:13px}
.head-actions{display:flex;gap:4px;align-items:center}
.active-chat-title{min-width:0;flex:1}
.active-chat-title strong,.active-chat-title span{overflow:hidden;text-overflow:ellipsis;white-space:nowrap}

.search-line{padding:11px 12px;border-bottom:1px solid rgba(255,255,255,.03)}
.chat-list{overflow:auto;padding:7px 8px;display:grid;gap:2px}
.chat-item{
  border:0;
  width:100%;
  text-align:left;
  border-radius:14px;
  background:transparent;
  color:var(--text);
  padding:10px;
  cursor:pointer;
  display:grid;
  grid-template-columns:50px 1fr;
  gap:11px;
  align-items:center;
}
.chat-item:hover,.chat-item.active{background:#233242}
.chat-avatar{width:50px;height:50px}
.chat-item-content{min-width:0;display:grid;gap:3px}
.chat-item-top{display:flex;justify-content:space-between;gap:8px;min-width:0}
.chat-item-title{font-weight:700;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}
.chat-item-time{color:var(--muted);font-size:12px;flex:0 0 auto}
.chat-item-last{color:var(--muted);overflow:hidden;text-overflow:ellipsis;white-space:nowrap;font-size:14px}
.empty-list{padding:18px;color:var(--muted);text-align:center}

.sidebar-footer{
  border-top:1px solid var(--line);
  padding:10px 12px;
  display:flex;
  align-items:center;
  gap:10px;
}
.sidebar-footer form{margin-left:auto}
.settings-link{font-size:15px}

.chat-pane{
  display:grid;
  grid-template-rows:70px 1fr auto auto;
  background:
    radial-gradient(circle at 70% 10%,rgba(42,171,238,.08),transparent 34%),
    linear-gradient(135deg,#0e1621,#101b26);
}
.messages{
  overflow:auto;
  padding:20px 28px;
  display:flex;
  flex-direction:column;
  gap:8px;
  background-image:
    radial-gradient(rgba(255,255,255,.035) 1px, transparent 1px);
  background-size:22px 22px;
}
.empty-chat{
  margin:auto;
  display:grid;
  gap:4px;
  text-align:center;
  color:var(--muted);
  background:rgba(10,18,27,.65);
  border:1px solid rgba(255,255,255,.06);
  border-radius:18px;
  padding:20px 24px;
}
.empty-chat strong{color:var(--text)}

.msg{display:flex;max-width:min(70%,780px)}
.msg.out{margin-left:auto}
.bubble{
  border-radius:18px 18px 18px 6px;
  padding:9px 11px 6px;
  background:var(--bubble-in);
  box-shadow:0 3px 12px rgba(0,0,0,.16);
  word-break:break-word;
  font-size:16px;
}
.msg.out .bubble{background:var(--bubble-out);border-radius:18px 18px 6px 18px}
.msg-body{white-space:pre-wrap}
.msg-meta{
  display:flex;
  gap:8px;
  align-items:center;
  margin-top:5px;
  color:#c7d2df;
  font-size:12px;
  justify-content:flex-end;
}
.msg-author{font-weight:700;color:#9bd8ff;margin-bottom:3px}
.deleted{font-style:italic;color:var(--muted)}

.attachment{
  display:flex;
  align-items:center;
  gap:9px;
  margin-top:8px;
  padding:9px;
  border:1px solid rgba(255,255,255,.11);
  border-radius:13px;
  background:rgba(0,0,0,.14);
}
.thumb{
  max-width:260px;
  max-height:190px;
  border-radius:13px;
  display:block;
  cursor:pointer;
  object-fit:cover;
}
.typing{height:24px;padding:0 28px;color:var(--muted);font-size:14px;background:#0f1720}

.composer{
  border-top:1px solid var(--line);
  padding:11px 14px;
  display:grid;
  grid-template-columns:auto 1fr auto;
  gap:9px;
  align-items:end;
  background:#17212b;
}
.composer.drag-over{
  outline:2px dashed var(--brand);
  outline-offset:-7px;
  background:#1b2b39;
}
.composer textarea{
  resize:none;
  max-height:150px;
  min-height:46px;
  border-radius:16px;
  background:#111c27;
}
.send-btn{
  width:46px;
  height:46px;
  border:0;
  border-radius:50%;
  background:var(--brand);
  color:#06111a;
  cursor:pointer;
  font-weight:900;
}
.send-btn:hover{filter:brightness(1.08)}
.file-chips{
  padding:0 14px 12px 66px;
  display:flex;
  gap:7px;
  flex-wrap:wrap;
  background:#17212b;
}
.chip{
  display:inline-flex;
  align-items:center;
  gap:7px;
  padding:6px 9px;
  background:#223244;
  border:1px solid var(--line);
  border-radius:999px;
  color:#cbd5e1;
  font-size:13px;
}
.chip-remove{
  width:20px;
  height:20px;
  border:0;
  border-radius:50%;
  background:#33475b;
  color:white;
  cursor:pointer;
}
.chip-remove:hover{background:#7f1d1d}

.modal{
  position:fixed;
  inset:0;
  z-index:60;
  display:grid;
  place-items:center;
  background:rgba(0,0,0,.58);
  padding:18px;
}
.modal-card{
  width:min(540px,100%);
  background:var(--panel);
  border:1px solid var(--line);
  border-radius:20px;
  padding:16px;
  box-shadow:var(--shadow);
  display:grid;
  gap:12px;
}
.modal-card-wide{width:min(720px,100%)}
.modal-card header{display:flex;align-items:center;justify-content:space-between}
.modal-card h2{margin:0;font-size:21px}
.result-list{display:grid;gap:7px;max-height:55vh;overflow:auto}
.result-row{
  border:1px solid var(--line);
  background:#111c27;
  border-radius:14px;
  padding:11px;
  display:flex;
  justify-content:space-between;
  align-items:center;
  gap:10px;
}
.role{color:var(--muted);font-size:13px}
.member-add{display:grid;grid-template-columns:1fr auto;gap:8px}
.member-row{align-items:center}
.member-actions{display:flex;gap:7px;align-items:center;flex-wrap:wrap;justify-content:flex-end}
.role-select{width:145px;padding:8px 10px}

.settings-modal-card label{font-size:14px;color:var(--muted)}
.settings-tabs{display:flex;gap:7px;padding:3px;background:#111c27;border:1px solid var(--line);border-radius:14px}
.settings-tab{
  flex:1;
  border:0;
  background:transparent;
  color:var(--muted);
  padding:10px;
  border-radius:11px;
  cursor:pointer;
}
.settings-tab.active{background:#263747;color:var(--text);font-weight:700}
.settings-panel{display:none;gap:10px}
.settings-panel.active{display:grid}
.settings-state{padding:10px 12px;border-radius:13px;background:#111c27;border:1px solid var(--line)}
.twofa-box{display:grid;gap:10px}

.image-modal{background:rgba(0,0,0,.82)}
.modal-backdrop{position:absolute;inset:0;border:0;background:transparent}
.image-card{position:relative;max-width:min(96vw,1120px);max-height:92vh}
.image-card img{max-width:100%;max-height:92vh;border-radius:16px;box-shadow:var(--shadow)}
.image-close{position:absolute;right:8px;top:8px;background:rgba(0,0,0,.45);color:white}

@media (max-width:900px){
  .messenger{grid-template-columns:330px 1fr}
  .msg{max-width:78%}
}
@media (max-width:780px){
  body{font-size:15px}
  .messenger{grid-template-columns:1fr}
  .sidebar{display:flex}
  .chat-pane{display:none}
  .messenger.chat-open .sidebar{display:none}
  .messenger.chat-open .chat-pane{display:grid}
  .mobile-only{display:inline-grid!important}
  .msg{max-width:88%}
  .sidebar-head,.chat-head{min-height:62px}
  .messages{padding:13px}
  .composer{grid-template-columns:auto 1fr auto;padding:9px}
  .file-chips{padding-left:10px}
  .flash-stack{left:10px;right:10px}
  .toast{max-width:none}
  .member-add{grid-template-columns:1fr}
  .result-row{align-items:stretch;flex-direction:column}
  .member-actions{justify-content:stretch}
  .role-select{width:100%}
}

/* Messenger refinement: unread, presence, quotes, compact attachments */
.chat-pane{grid-template-rows:70px 1fr auto auto auto}
.chat-item.has-unread .chat-item-title{font-weight:800;color:#fff}
.chat-item.has-unread .chat-item-last{color:#dbeafe;font-weight:600}
.chat-group{background:rgba(42,171,238,.04)}
.chat-item.chat-group .chat-avatar{background:linear-gradient(135deg,#7c3aed,#2aabee)}
.chat-type-pill{
  display:inline-flex;
  align-items:center;
  padding:2px 6px;
  border-radius:999px;
  background:rgba(42,171,238,.18);
  color:#9bd8ff;
  border:1px solid rgba(42,171,238,.22);
  font-size:11px;
  font-weight:800;
  text-transform:uppercase;
  letter-spacing:.03em;
}
.chat-item-right{display:flex;align-items:center;gap:7px;flex:0 0 auto}
.unread-badge{
  min-width:22px;
  height:22px;
  padding:0 7px;
  display:inline-grid;
  place-items:center;
  border-radius:999px;
  background:var(--brand);
  color:#06111a;
  font-size:12px;
  font-weight:900;
}
.status-dot{
  display:inline-block;
  width:9px;
  height:9px;
  border-radius:50%;
  border:2px solid rgba(255,255,255,.28);
  background:#64748b;
}
.status-dot.online{background:#22c55e}
.status-dot.offline{background:#64748b}
.chat-avatar{position:relative}
.chat-avatar .status-dot{
  position:absolute;
  right:1px;
  bottom:1px;
  width:13px;
  height:13px;
  border:2px solid var(--panel);
}
.user-result-left strong{display:flex;align-items:center;gap:5px}
.compact-row{padding:9px 10px}
.selectable-row{width:100%;color:var(--text);cursor:pointer;text-align:left}
.selectable-row:hover{background:#182637}
.selected-users{display:flex;gap:7px;flex-wrap:wrap;min-height:0}
.compact-results{max-height:240px}

.attachment.image-attachment{
  display:grid;
  align-items:start;
  justify-items:start;
  gap:7px;
  width:max-content;
  max-width:100%;
}
.attachment.image-attachment .download-link{
  font-size:13px;
  padding-left:2px;
}
.attachment.file-attachment{
  display:flex;
  max-width:340px;
}
.file-icon{
  width:34px;
  height:34px;
  border-radius:10px;
  display:grid;
  place-items:center;
  background:#263747;
  color:#9bd8ff;
  flex:0 0 auto;
}
.file-attachment a{
  overflow:hidden;
  text-overflow:ellipsis;
  white-space:nowrap;
}
.reply-preview{
  display:flex;
  align-items:center;
  justify-content:space-between;
  gap:10px;
  padding:8px 14px 8px 66px;
  background:#17212b;
  border-top:1px solid rgba(255,255,255,.05);
}
.reply-preview > div{
  min-width:0;
  display:grid;
  gap:2px;
  border-left:3px solid var(--brand);
  padding-left:10px;
}
.reply-preview strong{font-size:13px;color:#9bd8ff}
.reply-preview span{font-size:14px;color:#cbd5e1;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}
.quoted-message{
  width:100%;
  border:0;
  border-left:3px solid #7dd3fc;
  background:rgba(0,0,0,.16);
  color:inherit;
  border-radius:9px;
  padding:6px 8px;
  margin-bottom:6px;
  display:grid;
  gap:2px;
  text-align:left;
  cursor:pointer;
}
.quoted-message strong{font-size:13px;color:#9bd8ff}
.quoted-message span{font-size:13px;color:#cbd5e1;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}
.msg-actions{
  display:flex;
  gap:8px;
  align-items:center;
  justify-content:flex-end;
  margin-top:5px;
}
.msg-action{
  border:0;
  background:transparent;
  color:#bfdbfe;
  cursor:pointer;
  font-size:12px;
  padding:2px 0;
  opacity:.78;
}
.msg-action:hover{opacity:1;text-decoration:underline}
.msg.highlight .bubble{outline:2px solid rgba(125,211,252,.65);outline-offset:2px}

@media (max-width:780px){
  .reply-preview{padding-left:10px}
  .attachment.file-attachment{max-width:280px}
}
