* { box-sizing: border-box; font-family: system-ui, -apple-system, Segoe UI, Roboto, Arial; }
html, body { height: 100%; }
body { margin: 0; background: #0f1115; color: #e7eaf0; overflow: hidden; }

#app { display: flex; height: 100vh; width: 100vw; }

/* sidebar */
.sidebar { width: 320px; min-width: 260px; max-width: 360px; border-right: 1px solid #232834; display: flex; flex-direction: column; }
.me { padding: 12px; border-bottom: 1px solid #232834; font-weight: 600; }
.clients { overflow: auto; padding: 8px; -webkit-overflow-scrolling: touch; }
.client { padding: 10px; border-radius: 10px; cursor: pointer; }
.client:hover { background: #171a22; }
.client.active { background: #1c2030; }

/* chat */
.chat { flex: 1; min-width: 0; display: flex; flex-direction: column; height: 100vh; }
.chat-header {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 12px; border-bottom: 1px solid #232834; font-weight: 600;
  min-height: 48px;
}
.chat-header span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* back button (mobile) */
.back {
  display: none;
  border: 1px solid #2a3040; background: #0f1115; color: #e7eaf0;
  border-radius: 10px; padding: 6px 10px; cursor: pointer;
}

.messages {
  flex: 1; min-height: 0;
  overflow: auto; padding: 12px;
  display: flex; flex-direction: column; gap: 8px;
  -webkit-overflow-scrolling: touch;
}
.bubble { max-width: min(520px, 85%); padding: 10px 12px; border-radius: 14px; line-height: 1.25; white-space: pre-wrap; }
.in { background: #171a22; align-self: flex-start; }
.out { background: #2b3a67; align-self: flex-end; }
.meta { opacity: .6; font-size: 12px; margin-top: 4px; }

.media { max-width: 100%; border-radius: 10px; display: block; margin-top: 6px; }

/* composer */
.composer {
  display: flex; gap: 8px; padding: 10px 12px;
  border-top: 1px solid #232834;
  align-items: center;
}
.text {
  flex: 1; min-width: 0;
  padding: 10px 12px; border-radius: 10px; border: 1px solid #2a3040;
  background: #0f1115; color: #e7eaf0;
}
.file { width: 46px; max-width: 46px; color: transparent; }
.file::-webkit-file-upload-button { visibility: hidden; }
.file::before {
  content: "📎";
  display: inline-flex; align-items: center; justify-content: center;
  width: 46px; height: 40px;
  border-radius: 10px;
  border: 1px solid #2a3040;
  background: #0f1115;
  color: #e7eaf0;
  cursor: pointer;
}
.send {
  width: 96px;
  padding: 10px 12px; border-radius: 10px; border: 0;
  background: #3b82f6; color: white; cursor: pointer;
}
.send:disabled { opacity: .5; cursor: not-allowed; }

/* Mobile: sidebar becomes full screen list, chat becomes full screen view */
@media (max-width: 820px) {
  .sidebar { width: 100vw; max-width: none; min-width: 0; border-right: none; }
  .chat { width: 100vw; }
  .back { display: inline-flex; }

  /* by default show sidebar, hide chat */
  #app.mobile-show-chat .sidebar { display: none; }
  #app.mobile-show-chat .chat { display: flex; }
  #app:not(.mobile-show-chat) .chat { display: none; }

  .send { width: 84px; }
}

/* Admin page (оставил) */
.admin input { width: 420px; max-width: 95vw; padding: 10px 12px; border-radius: 10px; border: 1px solid #2a3040; background: #0f1115; color: #e7eaf0; margin: 6px 0; display: block;}
.admin button { padding: 10px 14px; border-radius: 10px; border: 0; background: #3b82f6; color: white; cursor: pointer; }
.admin pre { margin-top: 12px; background: #0b0d12; padding: 12px; border-radius: 10px; border: 1px solid #232834; }

/*стикеры*/
.sticker-lottie {
  width: 160px;
  height: 160px;
  margin-top: 6px;
}

.audio {
  width: 280px;
  max-width: 100%;
}

.video-note {
  width: 240px;
  height: 240px;
  border-radius: 9999px;
  overflow: hidden;
  object-fit: cover;
}

.attach-preview{
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  background: #0b0d12;
}
.attach-name{
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 13px;
  opacity: .9;
}
.attach-clear{
  width: 32px;
  height: 32px;
  border-radius: 10px;
  border: 1px solid #2a3040;
  background: #0f1115;
  color: #e7eaf0;
  cursor: pointer;
}
.bubble-text { white-space: pre-wrap; }

.album-grid{
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 4px;
  margin-top: 6px;
}
.album-item{
  width: 100%;
  aspect-ratio: 1 / 1;
  overflow: hidden;
  border-radius: 10px;
  background: #0b0d12;
  cursor: pointer;
}
.album-item img, .album-item video{
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}
.album-holder{
  width: 100%;
  height: 100%;
  display:flex;
  align-items:center;
  justify-content:center;
  opacity:.7;
  font-size:12px;
}

/* Viewer */
.viewer{
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.86);
  z-index: 9999;
  display:flex;
  align-items:center;
  justify-content:center;
}
.viewer-stage{
  max-width: 92vw;
  max-height: 92vh;
  display:flex;
  align-items:center;
  justify-content:center;
}
.viewer-media{
  max-width: 92vw;
  max-height: 92vh;
  border-radius: 14px;
  display:none;
}
.viewer-close{
  position: fixed;
  top: 12px;
  right: 12px;
  width: 44px;
  height: 44px;
  border-radius: 12px;
  border: 1px solid #2a3040;
  background: #0f1115;
  color:#e7eaf0;
  cursor:pointer;
}
.viewer-nav{
  position: fixed;
  top: 50%;
  transform: translateY(-50%);
  width: 44px;
  height: 44px;
  border-radius: 12px;
  border: 1px solid #2a3040;
  background: #0f1115;
  color:#e7eaf0;
  cursor:pointer;
  opacity: .9;
}
.viewer-prev{ left: 12px; }
.viewer-next{ right: 12px; }
.viewer-nav:disabled{ opacity:.35; cursor: default; }

.attach-list{
  display:flex;
  gap: 8px;
  flex-wrap: wrap;
  flex: 1;
  min-width: 0;
}

.attach-item{
  display:flex;
  align-items:center;
  gap: 8px;
  padding: 6px 10px;
  border: 1px solid #232834;
  background: #0f1115;
  border-radius: 12px;
  max-width: 100%;
}

.attach-item-name{
  max-width: 44vw;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 13px;
  opacity: .95;
}

.attach-item-remove{
  width: 28px;
  height: 28px;
  border-radius: 10px;
  border: 1px solid #2a3040;
  background: #0f1115;
  color: #e7eaf0;
  cursor: pointer;
}

.client{
  padding: 10px;
  border-radius: 10px;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.client-row{
  display: flex;
  align-items: center;
  gap: 8px;
}

.client-name{
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-weight: 600;
}

.client-time{
  opacity: .6;
  font-size: 12px;
  white-space: nowrap;
}

.client-preview{
  opacity: .75;
  font-size: 13px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
/* ===== Chat list (native-ish) ===== */

/* убираем внутренние отступы контейнера, чтобы разделители были на всю ширину */
#clients{
  padding: 0;
  -webkit-tap-highlight-color: transparent;
}

/* элемент списка */
#clients .client{
  padding: 12px 12px;
  border-radius: 0;
  background: transparent;
  transition: background .12s ease;
}

/* разделитель как в Telegram */
#clients .client:not(:last-child){
  border-bottom: 1px solid #232834; /* тот же цвет что у бордеров в макете */
}

/* hover / active — очень мягко */
#clients .client:hover{
  background: rgba(255,255,255,0.03);
}
#clients .client.active{
  background: rgba(255,255,255,0.06);
}

/* строки */
#clients .client-row{
  display:flex;
  align-items: baseline;
  gap: 8px;
}
#clients .client-name{
  flex:1;
  min-width:0;
  overflow:hidden;
  text-overflow:ellipsis;
  white-space:nowrap;
  font-weight:600;
}
#clients .client-time{
  margin-left:auto;
  font-size:12px;
  opacity:.55;
  white-space:nowrap;
}
#clients .client-preview{
  margin-top:2px;
  font-size:13px;
  opacity:.75;
  overflow:hidden;
  text-overflow:ellipsis;
  white-space:nowrap;
}
.client-right{
  display:flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 4px;
  margin-left: auto;
}

.client-badge{
  display:inline-flex;
  align-items:center;
  justify-content:center;
  min-width: 18px;
  height: 18px;
  padding: 0 6px;
  border-radius: 9999px;
  font-size: 12px;
  font-weight: 600;
  line-height: 18px;
  background: #3b82f6;
  color: #fff;
}
/* ===== Client search (Telegram-like) ===== */
.client-search{
  padding: 10px 12px;
  border-bottom: 1px solid #232834;
  position: relative;
}

.client-search-input{
  width: 100%;
  padding: 10px 40px 10px 12px; /* место под крестик справа */
  border-radius: 12px;
  border: 1px solid #2a3040;
  background: #0f1115;
  color: #e7eaf0;
  outline: none;
}

.client-search-input::placeholder{
  opacity: .65;
}

.client-search-clear{
  position: absolute;
  right: 18px;
  top: 50%;
  transform: translateY(-50%);
  width: 28px;
  height: 28px;
  border-radius: 10px;
  border: 1px solid #2a3040;
  background: #0f1115;
  color: #e7eaf0;
  cursor: pointer;
}

.client-empty{
  padding: 14px 12px;
  opacity: .65;
  font-size: 13px;
}
.back{
  position: relative;
}

.back-badge{
  position: absolute;
  top: -6px;
  right: -6px;
  min-width: 18px;
  height: 18px;
  padding: 0 6px;
  border-radius: 9999px;
  font-size: 12px;
  font-weight: 700;
  line-height: 18px;
  background: #3b82f6;
  color: #fff;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
/* ===== Upload progress (Telegram-like) ===== */
.bubble[data-uploading="1"]{
  position: relative;
}

.bubble .upload-title{
  font-size: 13px;
  opacity: .95;
  margin-bottom: 6px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.bubble .upload-progress{
  width: 100%;
  height: 4px;
  border-radius: 9999px;
  background: rgba(255,255,255,0.18);
  overflow: hidden;
  margin-top: 8px;
}

.bubble .upload-progress > .upload-bar{
  height: 100%;
  width: 0%;
  border-radius: 9999px;
  background: rgba(255,255,255,0.85);
  transition: width .08s linear;
}

.meta .meta-progress{
  margin-left: 6px;
  opacity: .85;
}
/* upload error line */
.bubble .upload-error{
  margin-top: 6px;
  font-size: 12px;
  color: #ff5a5a;
}
