:root {
  --tg-bg: #0e1621;
  --tg-bg-pattern: #0a1220;
  --tg-sidebar-bg: #17212b;
  --tg-header-bg: #17212b;
  --tg-msg-out: #2b5278;
  --tg-msg-in: #182533;
  --tg-text: #f5f5f5;
  --tg-text-secondary: #708499;
  --tg-accent: #6ab2f2;
  --tg-green: #4dcd5e;
  --tg-input-bg: #242f3d;
  --tg-border: rgba(255,255,255,0.06);
  --tg-hover: #202b36;
  --tg-danger: #e53935;
  --tg-reply-bar: #3a7ec0;
}
* { margin: 0; padding: 0; box-sizing: border-box; }
html, body { height: 100%; overflow: hidden; }
body {
  font-family: 'Segoe UI', system-ui, -apple-system, BlinkMacSystemFont, Roboto, Ubuntu, sans-serif;
  background: var(--tg-bg);
  color: var(--tg-text);
  font-size: 14px;
}
.hidden { display: none !important; }

/* ===== LOGIN ===== */
.login-wrap {
  display: flex; align-items: center; justify-content: center;
  height: 100vh; background: var(--tg-bg);
}
.login-card {
  background: var(--tg-sidebar-bg); border-radius: 12px;
  padding: 40px 36px; width: 360px; max-width: 92vw; text-align: center;
}
.login-logo {
  width: 120px; height: 120px; border-radius: 50%; margin: 0 auto 20px;
  background: linear-gradient(135deg, #6ab2f2 0%, #3d93d4 100%);
  display: flex; align-items: center; justify-content: center;
  font-size: 48px; color: #fff;
}
.login-card h1 { font-size: 22px; margin-bottom: 6px; font-weight: 500; }
.login-card .sub { color: var(--tg-text-secondary); font-size: 14px; margin-bottom: 24px; }
.login-card .error { color: var(--tg-danger); font-size: 13px; min-height: 20px; margin-bottom: 8px; }
.tg-input {
  width: 100%; padding: 14px 16px; border: none; border-bottom: 2px solid var(--tg-input-bg);
  background: transparent; color: var(--tg-text); font-size: 16px; outline: none;
  margin-bottom: 4px; transition: border-color .25s;
}
.tg-input:focus { border-bottom-color: var(--tg-accent); }
.tg-input::placeholder { color: var(--tg-text-secondary); }
.tg-btn {
  width: 100%; padding: 14px; border: none; border-radius: 8px; margin-top: 20px;
  background: var(--tg-accent); color: #fff; font-size: 16px; font-weight: 500;
  cursor: pointer; transition: background .2s;
}
.tg-btn:hover { background: #5aa0e0; }
.login-switch { margin-top: 16px; color: var(--tg-accent); font-size: 13px; cursor: pointer; }
.login-switch:hover { text-decoration: underline; }

/* ===== APP LAYOUT ===== */
.app-layout { display: flex; height: 100vh; }

/* Left sidebar (chat list style) */
.left-col {
  width: 260px; background: var(--tg-sidebar-bg); display: flex;
  flex-direction: column; border-right: 1px solid var(--tg-border); flex-shrink: 0;
}
.left-header {
  height: 56px; padding: 0 16px; display: flex; align-items: center;
  gap: 12px; flex-shrink: 0;
}
.hamburger {
  background: none; border: none; color: var(--tg-text-secondary); cursor: pointer;
  width: 36px; height: 36px; border-radius: 50%; display: flex; align-items: center;
  justify-content: center; transition: background .15s;
}
.hamburger:hover { background: var(--tg-hover); }
.hamburger svg { width: 22px; height: 22px; }
.left-search {
  flex: 1; padding: 8px 12px; border: none; border-radius: 20px;
  background: var(--tg-input-bg); color: var(--tg-text); font-size: 14px; outline: none;
}
.left-search::placeholder { color: var(--tg-text-secondary); }
.left-nav { flex: 1; overflow-y: auto; }
.nav-item {
  display: flex; align-items: center; gap: 12px; padding: 10px 16px;
  cursor: pointer; transition: background .1s; border-radius: 0;
}
.nav-item:hover { background: var(--tg-hover); }
.nav-item.active { background: var(--tg-accent); }
.nav-item.active .nav-name { color: #fff; }
.nav-item.active .nav-sub { color: rgba(255,255,255,.7); }
.nav-item.active .nav-ava { opacity: .9; }
.nav-ava {
  width: 46px; height: 46px; border-radius: 50%; flex-shrink: 0;
  display: flex; align-items: center; justify-content: center;
  font-size: 18px; font-weight: 600; color: #fff;
}
.nav-info { flex: 1; min-width: 0; }
.nav-name { font-size: 15px; font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.nav-sub { font-size: 13px; color: var(--tg-text-secondary); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.left-footer {
  padding: 12px 16px; border-top: 1px solid var(--tg-border);
  display: flex; align-items: center; gap: 10px; flex-shrink: 0;
}
.left-footer .user-ava {
  width: 32px; height: 32px; border-radius: 50%; font-size: 13px;
  display: flex; align-items: center; justify-content: center; color: #fff; font-weight: 600;
}
.left-footer .user-name { flex: 1; font-size: 13px; color: var(--tg-text-secondary); }
.logout-btn {
  background: none; border: none; color: var(--tg-text-secondary); cursor: pointer;
  padding: 6px; border-radius: 50%; display: flex; transition: color .15s;
}
.logout-btn:hover { color: var(--tg-danger); }
.logout-btn svg { width: 18px; height: 18px; }

/* ===== RIGHT (Chat area) ===== */
.right-col { flex: 1; display: flex; flex-direction: column; min-width: 0; background: var(--tg-bg); overflow: hidden; }
#chatPanel, #adminPanel { display: flex; flex-direction: column; flex: 1; min-height: 0; overflow: hidden; }
#chatPanel.hidden, #adminPanel.hidden { display: none; }

/* Chat header */
.chat-hdr {
  height: 56px; background: var(--tg-header-bg); display: flex; align-items: center;
  padding: 0 16px; gap: 12px; border-bottom: 1px solid var(--tg-border); flex-shrink: 0;
}
.chat-hdr-ava {
  width: 40px; height: 40px; border-radius: 50%;
  background: linear-gradient(135deg, #6ab2f2 0%, #3d93d4 100%);
  display: flex; align-items: center; justify-content: center;
  font-size: 16px; font-weight: 700; color: #fff; flex-shrink: 0;
}
.chat-hdr-info { flex: 1; }
.chat-hdr-info h3 { font-size: 15px; font-weight: 600; }
.chat-hdr-info .online { font-size: 12px; color: var(--tg-text-secondary); }
.chat-hdr-actions { display: flex; gap: 4px; }
.hdr-btn {
  width: 36px; height: 36px; border: none; background: none; border-radius: 50%;
  color: var(--tg-text-secondary); cursor: pointer; display: flex; align-items: center;
  justify-content: center; transition: background .15s;
}
.hdr-btn:hover { background: var(--tg-hover); }
.hdr-btn svg { width: 20px; height: 20px; }

/* Messages area */
.messages-wrap {
  flex: 1; overflow-y: auto; display: flex; flex-direction: column;
  min-height: 0; position: relative;
  background: var(--tg-bg-pattern);
  background-image: url("data:image/svg+xml,%3Csvg width='60' height='60' viewBox='0 0 60 60' xmlns='http://www.w3.org/2000/svg'%3E%3Cg fill='none' fill-rule='evenodd'%3E%3Cg fill='%23ffffff' fill-opacity='0.015'%3E%3Cpath d='M36 34v-4h-2v4h-4v2h4v4h2v-4h4v-2h-4zm0-30V0h-2v4h-4v2h4v4h2V6h4V4h-4zM6 34v-4H4v4H0v2h4v4h2v-4h4v-2H6zM6 4V0H4v4H0v2h4v4h2V6h4V4H6z'/%3E%3C/g%3E%3C/g%3E%3C/svg%3E");
}
.messages-inner {
  max-width: 728px; width: 100%; margin: 0 auto; padding: 8px 16px 8px;
  display: flex; flex-direction: column; gap: 2px; min-height: 100%;
  justify-content: flex-end;
}
.scroll-down-btn {
  position: sticky; bottom: 12px; align-self: flex-end; margin-right: 16px;
  width: 40px; height: 40px; border: none; border-radius: 50%;
  background: var(--tg-header-bg); color: var(--tg-text-secondary);
  box-shadow: 0 2px 8px rgba(0,0,0,.4);
  cursor: pointer; display: flex; align-items: center; justify-content: center;
  opacity: 0; pointer-events: none; transition: opacity .2s, transform .2s;
  transform: translateY(8px); z-index: 5;
}
.scroll-down-btn.visible {
  opacity: 1; pointer-events: auto; transform: translateY(0);
}
.scroll-down-btn:hover { background: var(--tg-hover); color: var(--tg-accent); }

.date-sep {
  text-align: center; padding: 8px 0;
}
.date-sep span {
  background: rgba(0,0,0,.35); color: #fff; font-size: 13px;
  padding: 4px 12px; border-radius: 16px; font-weight: 500;
}

/* Message bubble */
.msg {
  max-width: 480px; position: relative; padding: 6px 10px 4px; border-radius: 12px;
  word-wrap: break-word; overflow-wrap: break-word; line-height: 1.35;
  animation: msgIn .18s ease-out;
}
@keyframes msgIn { from { opacity:0; transform:translateY(6px); } to { opacity:1; transform:none; } }
.msg.out {
  background: var(--tg-msg-out); align-self: flex-end;
  border-bottom-right-radius: 4px; margin-left: 60px;
}
.msg.in {
  background: var(--tg-msg-in); align-self: flex-start;
  border-bottom-left-radius: 4px; margin-right: 60px;
}
.msg-name {
  font-size: 13px; font-weight: 600; margin-bottom: 2px; cursor: default;
  display: flex; align-items: center; gap: 6px;
}
.msg-name .badge {
  font-size: 10px; background: var(--tg-accent); color: #fff;
  padding: 1px 6px; border-radius: 4px; font-weight: 600;
}
.msg-photo {
  max-width: 100%; border-radius: 8px; margin: 4px 0 2px; display: block; cursor: pointer;
}

/* Album grid */
.album {
  display: grid; gap: 2px; border-radius: 8px; overflow: hidden;
  margin: 4px 0 2px; cursor: pointer;
}
.album img {
  width: 100%; height: 100%; object-fit: cover; display: block;
  transition: opacity .15s;
}
.album img:hover { opacity: .88; }
.album-item { position: relative; overflow: hidden; min-height: 0; }
.album-more {
  position: absolute; inset: 0; background: rgba(0,0,0,.55);
  display: flex; align-items: center; justify-content: center;
  color: #fff; font-size: 24px; font-weight: 600;
}
.album-2 { grid-template-columns: 1fr 1fr; }
.album-2 .album-item { height: 180px; }
.album-3 { grid-template-columns: 1fr 1fr; grid-template-rows: 1fr 1fr; }
.album-3 .album-item:first-child { grid-row: 1 / 3; height: 240px; }
.album-3 .album-item:nth-child(2),
.album-3 .album-item:nth-child(3) { height: 119px; }
.album-4 { grid-template-columns: 1fr 1fr; grid-template-rows: 1fr 1fr; }
.album-4 .album-item { height: 140px; }



.msg-body { font-size: 14px; white-space: pre-wrap; }
.msg-meta {
  display: flex; justify-content: flex-end; align-items: center; gap: 4px;
  margin-top: 2px;
}
.msg-time { font-size: 11px; color: rgba(255,255,255,.4); }
.msg-actions {
  position: absolute; top: 4px; right: 4px; display: flex; gap: 2px;
  opacity: 0; transition: opacity .15s;
}
.msg:hover .msg-actions { opacity: 1; }
.msg-act-btn {
  width: 26px; height: 26px; border: none; background: rgba(0,0,0,.35);
  border-radius: 50%; color: #fff; cursor: pointer; display: flex;
  align-items: center; justify-content: center; font-size: 12px;
  transition: background .15s;
}
.msg-act-btn:hover { background: var(--tg-danger); }

/* Comments */
.msg-comments-bar {
  margin-top: 4px; padding-top: 4px; border-top: 1px solid rgba(255,255,255,.06);
}
.comments-toggle {
  font-size: 12px; color: var(--tg-accent); cursor: pointer; display: flex;
  align-items: center; gap: 4px;
}
.comments-toggle:hover { text-decoration: underline; }
.comments-toggle svg { width: 14px; height: 14px; }
.comments-list { margin-top: 4px; }
.cmt {
  display: flex; align-items: baseline; gap: 4px; font-size: 13px;
  padding: 2px 0; line-height: 1.35;
}
.cmt-author { font-weight: 600; flex-shrink: 0; }
.cmt-text { flex: 1; }
.cmt-del {
  font-size: 10px; color: var(--tg-danger); cursor: pointer; opacity: .5;
  flex-shrink: 0; padding: 0 2px;
}
.cmt-del:hover { opacity: 1; }
.cmt-form {
  display: flex; gap: 4px; margin-top: 4px;
}
.cmt-form input {
  flex: 1; padding: 6px 10px; border: none; border-radius: 16px;
  background: rgba(255,255,255,.06); color: var(--tg-text); font-size: 13px; outline: none;
}
.cmt-form button {
  width: 28px; height: 28px; border: none; border-radius: 50%;
  background: var(--tg-accent); color: #fff; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
}
.cmt-form button svg { width: 14px; height: 14px; }

/* Input area */
.compose {
  background: var(--tg-header-bg); padding: 8px 8px 8px 4px;
  display: flex; align-items: flex-end; gap: 6px; border-top: 1px solid var(--tg-border);
  flex-shrink: 0;
}
.compose-btn {
  width: 40px; height: 40px; border: none; background: none; border-radius: 50%;
  color: var(--tg-text-secondary); cursor: pointer; display: flex;
  align-items: center; justify-content: center; flex-shrink: 0; transition: color .15s;
}
.compose-btn:hover { color: var(--tg-accent); }
.compose-btn svg { width: 22px; height: 22px; }
.compose-text {
  flex: 1; padding: 10px 14px; border: none; border-radius: 20px;
  background: var(--tg-input-bg); color: var(--tg-text); font-size: 14px;
  font-family: inherit; resize: none; outline: none; max-height: 140px;
  min-height: 40px; line-height: 1.4;
}
.compose-text::placeholder { color: var(--tg-text-secondary); }
.send-btn {
  width: 40px; height: 40px; border: none; border-radius: 50%;
  background: var(--tg-accent); color: #fff; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0; transition: transform .12s, background .15s;
}
.send-btn:active { transform: scale(.92); }
.send-btn svg { width: 20px; height: 20px; }

/* Image preview bar */
.preview-bar {
  display: none; padding: 8px 16px; background: var(--tg-header-bg);
  border-top: 1px solid var(--tg-border); align-items: center; gap: 8px;
  flex-shrink: 0;
}
.preview-bar.active { display: flex; }
.pv-list { display: flex; gap: 6px; flex: 1; overflow-x: auto; }
.pv-thumb { position: relative; flex-shrink: 0; }
.pv-thumb img { height: 56px; width: 56px; object-fit: cover; border-radius: 8px; display: block; }
.pv-thumb-del {
  position: absolute; top: -4px; right: -4px; width: 18px; height: 18px;
  border: none; border-radius: 50%; background: var(--tg-danger); color: #fff;
  cursor: pointer; font-size: 11px; display: flex; align-items: center; justify-content: center;
  line-height: 1;
}
.pv-count { color: var(--tg-text-secondary); font-size: 12px; flex-shrink: 0; }
.preview-bar .pv-close {
  width: 24px; height: 24px; border: none; border-radius: 50%;
  background: var(--tg-danger); color: #fff; cursor: pointer;
  display: flex; align-items: center; justify-content: center; font-size: 13px;
  flex-shrink: 0;
}

/* Readonly bar (for non-admin users) */
.readonly-bar {
  background: var(--tg-header-bg); padding: 12px 20px;
  display: flex; align-items: center; gap: 10px;
  border-top: 1px solid var(--tg-border); flex-shrink: 0;
  color: var(--tg-text-secondary); font-size: 13px;
}
.readonly-bar.hidden { display: none; }

/* Lightbox / Slider */
.lightbox {
  display: none; position: fixed; inset: 0;
  z-index: 999; align-items: center; justify-content: center;
}
.lightbox.open { display: flex; }
.lb-bg {
  position: absolute; inset: 0; background: rgba(0,0,0,.92); cursor: zoom-out;
}
.lightbox img {
  max-width: 85vw; max-height: 88vh; border-radius: 6px;
  position: relative; z-index: 2; user-select: none;
}
.lb-close {
  position: absolute; top: 16px; right: 20px; z-index: 3;
  width: 40px; height: 40px; border: none; border-radius: 50%;
  background: rgba(255,255,255,.12); color: #fff; font-size: 20px;
  cursor: pointer; display: flex; align-items: center; justify-content: center;
  transition: background .15s;
}
.lb-close:hover { background: rgba(255,255,255,.25); }
.lb-counter {
  position: absolute; top: 20px; left: 50%; transform: translateX(-50%);
  z-index: 3; color: #fff; font-size: 14px; font-weight: 500;
  background: rgba(0,0,0,.5); padding: 4px 14px; border-radius: 16px;
}
.lb-arrow {
  position: absolute; top: 50%; transform: translateY(-50%); z-index: 3;
  width: 48px; height: 48px; border: none; border-radius: 50%;
  background: rgba(255,255,255,.1); color: #fff; font-size: 22px;
  cursor: pointer; display: flex; align-items: center; justify-content: center;
  transition: background .15s;
}
.lb-arrow:hover { background: rgba(255,255,255,.25); }
.lb-prev { left: 16px; }
.lb-next { right: 16px; }

/* Admin panel */
.admin-wrap { flex: 1; overflow-y: auto; padding: 24px; }
.admin-wrap h2 { font-size: 18px; font-weight: 500; margin-bottom: 16px; }
.admin-tbl { width: 100%; border-collapse: collapse; }
.admin-tbl th { text-align: left; padding: 8px 12px; color: var(--tg-text-secondary); font-size: 12px; text-transform: uppercase; font-weight: 600; border-bottom: 1px solid var(--tg-border); }
.admin-tbl td { padding: 10px 12px; border-bottom: 1px solid var(--tg-border); }
.admin-tbl tr:hover { background: var(--tg-hover); }
.kick-btn { padding: 4px 14px; border: 1px solid var(--tg-danger); border-radius: 6px; background: transparent; color: var(--tg-danger); cursor: pointer; font-size: 12px; transition: all .15s; }
.kick-btn:hover { background: var(--tg-danger); color: #fff; }

/* Empty state */
.empty-state {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  flex: 1; color: var(--tg-text-secondary); font-size: 15px; gap: 8px;
}

/* Responsive */
@media (max-width: 720px) {
  .left-col { width: 0; overflow: hidden; border: none; }
  .left-col.mobile-open { width: 260px; position: fixed; z-index: 100; height: 100vh; }
  .msg { max-width: 85%; }
}
