:root{
  --bg:#0e1621;
  --panel:#17212b;
  --panel2:#202b36;
  --line:rgba(255,255,255,.08);
  --text:#e9edf0;
  --muted:#8ea2b5;
  --accent:#2ea6ff;
  --bubble-me:#2b5278;
  --bubble:#182533;
  --badge:#5d6c7c;
  --green:#0f9d8f
}

*{box-sizing:border-box}
html,body{height:100%}

body{
  margin:0;
  background:#0e1621;
  color:var(--text);
  font:14px/1.4 system-ui,sans-serif
}

.tg-app{
  height:100vh;
  display:grid;
  grid-template-columns:380px 1fr 300px
}

.tg-app.is-auth{grid-template-columns:1fr}

.auth-shell{display:grid;place-items:center}

.auth-card{
  width:min(420px,92vw);
  background:var(--panel);
  border:1px solid var(--line);
  border-radius:18px;
  padding:24px
}

.field{
  display:flex;
  flex-direction:column;
  gap:8px;
  margin-bottom:12px
}

.field input{
  height:42px;
  border-radius:12px;
  border:1px solid var(--line);
  background:#242f3d;
  color:var(--text);
  padding:0 14px
}

.btn{
  height:42px;
  border:none;
  border-radius:12px;
  padding:0 16px
}

.btn.primary{
  background:var(--accent);
  color:#fff
}

.btn.ghost{
  background:#273341;
  color:#fff
}

.btn.danger{
  background:#cc4455;
  color:#fff
}

.auth-actions,.info-actions{
  display:flex;
  gap:10px
}

.sidebar{
  background:#202b36;
  border-right:1px solid var(--line);
  display:flex;
  flex-direction:column
}

.top-search{
  display:flex;
  gap:10px;
  padding:12px
}

.top-search input{
  flex:1;
  height:36px;
  border-radius:18px;
  border:none;
  background:#323d49;
  color:#fff;
  padding:0 16px
}

.profile-btn,.icon-btn{
  width:36px;
  height:36px;
  border:none;
  border-radius:18px;
  background:#3b4652;
  color:#fff
}

.sidebar-menu{
  display:flex;
  gap:8px;
  padding:0 12px 10px
}

.menu-btn{
  flex:1;
  height:34px;
  border:none;
  border-radius:12px;
  background:#273341;
  color:#fff
}

.list-scroll{
  overflow:auto;
  padding-bottom:20px
}

.chat-row{
  display:flex;
  gap:12px;
  padding:12px 12px;
  cursor:pointer
}

.chat-row.active{background:#0f9d8f}
.chat-row:hover{background:rgba(255,255,255,.04)}

.avatar{
  width:54px;
  height:54px;
  border-radius:50%;
  display:grid;
  place-items:center;
  background:#4a7ed4;
  color:#fff;
  font-weight:700;
  flex:0 0 54px
}

.chat-main{
  min-width:0;
  flex:1
}

.chat-head,.chat-sub{
  display:flex;
  align-items:center;
  gap:10px
}

.chat-head strong{
  flex:1;
  white-space:nowrap;
  overflow:hidden;
  text-overflow:ellipsis
}

.chat-head span,.chat-sub{color:var(--muted)}

.last-line{
  flex:1;
  white-space:nowrap;
  overflow:hidden;
  text-overflow:ellipsis
}

.badge{
  min-width:22px;
  height:22px;
  padding:0 6px;
  border-radius:11px;
  background:var(--badge);
  display:grid;
  place-items:center;
  color:#fff;
  font-size:12px
}

.chat-pane{
  display:flex;
  flex-direction:column;
  background:#0f141a url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='160' height='160' viewBox='0 0 160 160'%3E%3Cg fill='none' stroke='%231d2a3a' stroke-width='1'%3E%3Ccircle cx='20' cy='20' r='10'/%3E%3Cpath d='M80 20l10 10-10 10-10-10z'/%3E%3Cpath d='M120 70h20v20h-20z'/%3E%3Cpath d='M30 110c8-12 20-12 28 0-8 12-20 12-28 0z'/%3E%3Cpath d='M90 110l15-8 0 16z'/%3E%3C/g%3E%3C/svg%3E")
}

.chat-header{
  height:72px;
  border-bottom:1px solid var(--line);
  display:flex;
  align-items:center;
  gap:12px;
  padding:0 16px;
  background:#202b36
}

.chat-header-meta{
  display:flex;
  flex-direction:column;
  gap:2px;
  flex:1
}

.messages-wrap{
  flex:1;
  overflow:auto;
  padding:16px
}

.msg-row{
  display:flex;
  margin-bottom:8px
}

.msg-row.me{justify-content:flex-end}

.msg-bubble{
  max-width:min(720px,82%);
  background:var(--bubble);
  padding:8px 12px;
  border-radius:16px;
  position:relative
}

.msg-bubble.me{background:var(--bubble-me)}

.msg-sender{
  font-size:12px;
  color:#8fd4ff;
  margin-bottom:4px
}

.msg-meta{
  font-size:12px;
  color:#9fb4c9;
  text-align:right;
  margin-top:4px
}

.date-divider{
  display:flex;
  justify-content:center;
  margin:12px 0
}

.date-divider span{
  background:#2a3440;
  border-radius:14px;
  padding:6px 12px;
  color:#d8e3ee
}

.composer{
  display:flex;
  align-items:flex-end;
  gap:10px;
  padding:12px;
  background:#202b36;
  border-top:1px solid var(--line)
}

.composer-input{
  flex:1;
  min-height:42px;
  max-height:180px;
  border:none;
  border-radius:20px;
  background:#2b3643;
  color:#fff;
  padding:11px 14px;
  resize:none
}

.send-btn{
  width:42px;
  height:42px;
  border:none;
  border-radius:21px;
  background:#2ea6ff;
  color:#fff
}

.info-pane{
  background:#17212b;
  border-left:1px solid var(--line);
  display:flex;
  flex-direction:column
}

.info-head{
  height:72px;
  display:flex;
  align-items:center;
  justify-content:space-between;
  padding:0 16px;
  border-bottom:1px solid var(--line)
}

.info-card{
  padding:14px 16px;
  border-bottom:1px solid var(--line)
}

.member-row{
  display:flex;
  justify-content:space-between;
  padding:6px 0
}

.muted{color:var(--muted)}

.section-title{
  font-weight:700;
  margin-bottom:8px
}

.empty-chat{
  flex:1;
  display:grid;
  place-items:center;
  color:var(--muted)
}

.empty-chat.center strong{
  background:#222d39;
  padding:8px 16px;
  border-radius:20px;
  color:#fff
}

.modal-backdrop{
  position:fixed;
  inset:0;
  background:rgba(0,0,0,.5);
  display:grid;
  place-items:center
}

.modal-card{
  width:min(480px,92vw);
  background:#17212b;
  border-radius:18px;
  padding:18px;
  border:1px solid var(--line)
}

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

.auth-error{
  color:#ff8b8b;
  margin:8px 0
}

.mobile-only{display:none}

@media (max-width:1100px){
  .tg-app{grid-template-columns:360px 1fr}
  .info-pane{display:none}
}

@media (max-width:820px){
  .tg-app{grid-template-columns:1fr}
  .sidebar.mobileHidden{display:none}
  .chat-pane{display:none}
  .chat-pane.mobileVisible{display:flex}
  .mobile-only{display:inline-grid}
}

.top-search{
  display:flex;
  gap:10px;
  padding:12px;
  align-items:center;
  position:relative;
  z-index:5;
}

.top-search input{
  flex:1;
  height:42px;
  border-radius:20px;
  border:1px solid rgba(255,255,255,.06);
  background:#2a3643;
  color:#fff;
  padding:0 16px;
  outline:none;
}

.top-search input::placeholder{
  color:#9eb0c2;
}

.profile-btn{
  width:40px;
  height:40px;
  min-width:40px;
  border:none;
  border-radius:50%;
  background:#415266;
  color:#fff;
  display:grid;
  place-items:center;
  font-weight:700;
}

/* =========================
   SEARCH PANEL
   ========================= */

.search-panel{
  margin:0 12px 12px;
  background:#1d2733;
  border:1px solid rgba(255,255,255,.08);
  border-radius:16px;
  overflow:hidden;
  box-shadow:0 12px 28px rgba(0,0,0,.22);
}

.search-panel-head{
  display:flex;
  align-items:center;
  justify-content:space-between;
  gap:10px;
  padding:10px 12px;
  border-bottom:1px solid rgba(255,255,255,.06);
}

.search-panel-head.compact{
  padding:8px 10px;
}

.search-panel-title{
  font-size:12px;
  letter-spacing:.02em;
}

.search-close-btn{
  width:28px;
  height:28px;
  border:none;
  border-radius:14px;
  background:#344252;
  color:#fff;
  cursor:pointer;
  display:grid;
  place-items:center;
  font-size:14px;
}

.search-state{
  padding:12px;
  font-size:13px;
}

.search-users-list{
  display:flex;
  flex-direction:column;
  gap:0;
  max-height:280px;
  overflow:auto;
}

.search-user-row{
  width:100%;
  display:flex;
  align-items:center;
  gap:12px;
  padding:10px 12px;
  border:none;
  border-bottom:1px solid rgba(255,255,255,.05);
  background:transparent;
  color:#fff;
  text-align:left;
  cursor:pointer;
}

.search-user-row:last-child{
  border-bottom:none;
}

.search-user-row:hover{
  background:#263242;
}

.search-user-row .avatar.small{
  width:40px;
  height:40px;
  min-width:40px;
  border-radius:50%;
  font-size:13px;
}

.search-user-meta{
  min-width:0;
  display:flex;
  flex-direction:column;
  gap:3px;
}

.search-user-meta strong{
  display:block;
  font-size:14px;
  font-weight:700;
  color:#fff;
  white-space:nowrap;
  overflow:hidden;
  text-overflow:ellipsis;
}

.search-user-meta span{
  display:block;
  font-size:12px;
  color:#9db0c3;
  white-space:nowrap;
  overflow:hidden;
  text-overflow:ellipsis;
}

/* =========================
   TABS
   ========================= */

.chat-tabs{
  display:flex;
  gap:6px;
  flex-wrap:wrap;
  padding:0 12px 12px;
}

.chat-tab{
  height:32px;
  border:none;
  border-radius:10px;
  padding:0 12px;
  background:#2a3643;
  color:#dbe6ef;
  cursor:pointer;
  display:inline-flex;
  align-items:center;
  gap:6px;
  font-size:13px;
}

.chat-tab:hover{
  background:#334254;
}

.chat-tab.active{
  background:#4d7bd6;
  color:#fff;
}

.mini-badge{
  min-width:18px;
  height:18px;
  padding:0 5px;
  border-radius:9px;
  background:rgba(255,255,255,.2);
  color:#fff;
  display:inline-grid;
  place-items:center;
  font-size:11px;
  font-weight:700;
}

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

.list-section-title{
  padding:10px 14px 6px;
  color:#92a7ba;
  font-size:12px;
  font-weight:700;
  text-transform:uppercase;
  letter-spacing:.04em;
}

.chat-row{
  display:flex;
  align-items:center;
  gap:12px;
  padding:10px 12px;
  cursor:pointer;
  border-bottom:1px solid rgba(255,255,255,.04);
}

.chat-row:hover{
  background:rgba(255,255,255,.04);
}

.chat-row.active{
  background:#35506d;
}

.chat-main{
  min-width:0;
  flex:1;
}

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

.chat-head strong{
  flex:1;
  min-width:0;
  white-space:nowrap;
  overflow:hidden;
  text-overflow:ellipsis;
  font-size:14px;
}

.chat-head span{
  font-size:12px;
  color:#9fb3c5;
  white-space:nowrap;
}

.chat-sub{
  display:flex;
  align-items:center;
  gap:8px;
  margin-top:3px;
}

.last-line{
  flex:1;
  min-width:0;
  white-space:nowrap;
  overflow:hidden;
  text-overflow:ellipsis;
  color:#9db0c3;
  font-size:13px;
}

.row-flags{
  display:flex;
  align-items:center;
  gap:8px;
  flex-shrink:0;
}

.row-icon-btn{
  width:24px;
  height:24px;
  border:none;
  border-radius:12px;
  background:transparent;
  color:#f2cb4d;
  cursor:pointer;
  display:grid;
  place-items:center;
  font-size:15px;
}

.row-icon-btn:hover{
  background:rgba(255,255,255,.08);
}

.fav-mark{
  color:#f2cb4d;
  font-size:14px;
}

.badge{
  min-width:22px;
  height:22px;
  padding:0 6px;
  border-radius:11px;
  background:#4d7bd6;
  display:grid;
  place-items:center;
  color:#fff;
  font-size:12px;
  font-weight:700;
}

.empty-list{
  padding:18px 14px;
  color:#9db0c3;
}

/* =========================
   MODAL + SELECT2
   ========================= */

.modal-card .field{
  margin-bottom:14px;
}

.modal-card .field select,
.modal-card .field input{
  width:100%;
}

.select2-container{
  width:100% !important;
}

.select2-container--default .select2-selection--multiple{
  min-height:42px;
  background:#243140 !important;
  border:1px solid rgba(255,255,255,.08) !important;
  border-radius:12px !important;
  padding:4px 6px !important;
}

.select2-container--default .select2-selection--multiple .select2-selection__choice{
  background:#4d7bd6 !important;
  border:none !important;
  color:#fff !important;
  border-radius:10px !important;
  padding:3px 8px !important;
  margin-top:4px !important;
}

.select2-container--default .select2-selection--multiple .select2-selection__choice__remove{
  color:#fff !important;
  margin-right:6px !important;
}

.select2-container--default .select2-search--inline .select2-search__field{
  color:#fff !important;
  margin-top:7px !important;
}

.select2-dropdown{
  background:#1f2a36 !important;
  border:1px solid rgba(255,255,255,.08) !important;
  color:#fff !important;
}

.select2-container--default .select2-results__option{
  color:#fff !important;
}

.select2-container--default .select2-results__option--highlighted[aria-selected]{
  background:#35506d !important;
  color:#fff !important;
}

.select2-search__field{
  background:transparent !important;
}

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

@media (max-width: 820px){
  .search-panel{
    margin:0 10px 10px;
  }

  .chat-tabs{
    overflow:auto;
    flex-wrap:nowrap;
    padding-bottom:10px;
  }

  .chat-tab{
    flex:0 0 auto;
  }
}