*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --blue: #2AABEE;
  --blue-dark: #1a9ede;
  --bg: #000000;
  --sidebar-bg: #000000;
  --header-bg: #1c1c1e;
  --chat-bg: #000000;
  --bubble-out: #2B5278;
  --bubble-in: #1c1c1e;
  --text: #FFFFFF;
  --text-2: #8e8e93;
  --border: #2c2c2e;
  --hover: rgba(255,255,255,.06);
  --active-chat: #1c3a5e;
  --green: #30d158;
  --red: #ff453a;
  --input-bg: #1c1c1e;
  --modal-bg: #1c1c1e;
  --modal-input: #2c2c2e;
}

html {
  height: -webkit-fill-available;
}
html, body {
  height: 100%;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  font-size: 15px;
  color: var(--text);
  background: var(--bg);
  overscroll-behavior-x: none;
  overflow: hidden;
}

.hidden { display: none !important; }

/* ─── Login ─────────────────────────────────────── */
#login-screen {
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  align-items: center;
  justify-content: center;
  background-color: #1a1625;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='400' height='400'%3E%3Cg transform='translate(20,30)'%3E%3Cpath d='M2,14 L2,8 L8,4 L24,4 L28,8 L34,8 L34,14 Z' fill='none' stroke='rgba(140,100,220,0.2)' stroke-width='1.2' stroke-linejoin='round'/%3E%3Ccircle cx='9' cy='14' r='4' fill='none' stroke='rgba(140,100,220,0.2)' stroke-width='1.2'/%3E%3Ccircle cx='27' cy='14' r='4' fill='none' stroke='rgba(140,100,220,0.2)' stroke-width='1.2'/%3E%3Cpath d='M8,8 L10,5 L24,5 L26,8 Z' fill='none' stroke='rgba(140,100,220,0.14)' stroke-width='1'/%3E%3C/g%3E%3Cg transform='translate(248,22)'%3E%3Cpath d='M0,18 L0,9 L7,3 L16,3 L16,18 Z' fill='none' stroke='rgba(140,100,220,0.18)' stroke-width='1.2' stroke-linejoin='round'/%3E%3Cpath d='M16,18 L16,7 L46,7 L46,18 Z' fill='none' stroke='rgba(140,100,220,0.18)' stroke-width='1.2' stroke-linejoin='round'/%3E%3Ccircle cx='7' cy='18' r='4' fill='none' stroke='rgba(140,100,220,0.18)' stroke-width='1.2'/%3E%3Ccircle cx='24' cy='18' r='4' fill='none' stroke='rgba(140,100,220,0.18)' stroke-width='1.2'/%3E%3Ccircle cx='39' cy='18' r='4' fill='none' stroke='rgba(140,100,220,0.18)' stroke-width='1.2'/%3E%3Cpath d='M1,14 L7,4 L15,4 L15,14 Z' fill='none' stroke='rgba(140,100,220,0.11)' stroke-width='1'/%3E%3C/g%3E%3Cg transform='translate(15,158)'%3E%3Cpath d='M2,18 L2,4 L38,4 L38,18 Z' fill='none' stroke='rgba(140,100,220,0.18)' stroke-width='1.2' stroke-linejoin='round'/%3E%3Ccircle cx='9' cy='18' r='4' fill='none' stroke='rgba(140,100,220,0.18)' stroke-width='1.2'/%3E%3Ccircle cx='31' cy='18' r='4' fill='none' stroke='rgba(140,100,220,0.18)' stroke-width='1.2'/%3E%3Crect x='5' y='7' width='10' height='7' rx='1' fill='none' stroke='rgba(140,100,220,0.12)' stroke-width='1'/%3E%3Crect x='19' y='7' width='10' height='7' rx='1' fill='none' stroke='rgba(140,100,220,0.12)' stroke-width='1'/%3E%3C/g%3E%3Cg transform='translate(390,150) scale(-1,1)'%3E%3Cpath d='M2,14 L2,8 L8,4 L24,4 L28,8 L34,8 L34,14 Z' fill='none' stroke='rgba(140,100,220,0.18)' stroke-width='1.2' stroke-linejoin='round'/%3E%3Ccircle cx='9' cy='14' r='4' fill='none' stroke='rgba(140,100,220,0.18)' stroke-width='1.2'/%3E%3Ccircle cx='27' cy='14' r='4' fill='none' stroke='rgba(140,100,220,0.18)' stroke-width='1.2'/%3E%3Cpath d='M8,8 L10,5 L24,5 L26,8 Z' fill='none' stroke='rgba(140,100,220,0.12)' stroke-width='1'/%3E%3C/g%3E%3Cg transform='translate(40,298)'%3E%3Cpath d='M2,20 L2,4 L52,4 L52,20 Z' fill='none' stroke='rgba(140,100,220,0.15)' stroke-width='1.2' stroke-linejoin='round'/%3E%3Ccircle cx='11' cy='20' r='5' fill='none' stroke='rgba(140,100,220,0.15)' stroke-width='1.2'/%3E%3Ccircle cx='43' cy='20' r='5' fill='none' stroke='rgba(140,100,220,0.15)' stroke-width='1.2'/%3E%3Crect x='6' y='8' width='9' height='7' rx='1' fill='none' stroke='rgba(140,100,220,0.1)' stroke-width='1'/%3E%3Crect x='18' y='8' width='9' height='7' rx='1' fill='none' stroke='rgba(140,100,220,0.1)' stroke-width='1'/%3E%3Crect x='30' y='8' width='9' height='7' rx='1' fill='none' stroke='rgba(140,100,220,0.1)' stroke-width='1'/%3E%3Crect x='42' y='8' width='7' height='7' rx='1' fill='none' stroke='rgba(140,100,220,0.1)' stroke-width='1'/%3E%3C/g%3E%3Cg transform='translate(278,290)'%3E%3Cpath d='M0,16 L0,6 L8,2 L18,2 L18,16 Z' fill='none' stroke='rgba(140,100,220,0.18)' stroke-width='1.2' stroke-linejoin='round'/%3E%3Cpath d='M18,16 L18,8 L36,8 L36,16 Z' fill='none' stroke='rgba(140,100,220,0.18)' stroke-width='1.2' stroke-linejoin='round'/%3E%3Ccircle cx='6' cy='16' r='4' fill='none' stroke='rgba(140,100,220,0.18)' stroke-width='1.2'/%3E%3Ccircle cx='28' cy='16' r='4' fill='none' stroke='rgba(140,100,220,0.18)' stroke-width='1.2'/%3E%3Cpath d='M1,12 L8,3 L17,3 L17,12 Z' fill='none' stroke='rgba(140,100,220,0.11)' stroke-width='1'/%3E%3C/g%3E%3Cg transform='translate(158,108) scale(0.85)'%3E%3Cpath d='M2,14 L2,8 L8,4 L24,4 L28,8 L34,8 L34,14 Z' fill='none' stroke='rgba(140,100,220,0.14)' stroke-width='1.2' stroke-linejoin='round'/%3E%3Ccircle cx='9' cy='14' r='4' fill='none' stroke='rgba(140,100,220,0.14)' stroke-width='1.2'/%3E%3Ccircle cx='27' cy='14' r='4' fill='none' stroke='rgba(140,100,220,0.14)' stroke-width='1.2'/%3E%3C/g%3E%3Cg transform='translate(400,238) scale(-1,1)'%3E%3Cpath d='M0,18 L0,9 L7,3 L16,3 L16,18 Z' fill='none' stroke='rgba(140,100,220,0.14)' stroke-width='1.2' stroke-linejoin='round'/%3E%3Cpath d='M16,18 L16,7 L46,7 L46,18 Z' fill='none' stroke='rgba(140,100,220,0.14)' stroke-width='1.2' stroke-linejoin='round'/%3E%3Ccircle cx='7' cy='18' r='4' fill='none' stroke='rgba(140,100,220,0.14)' stroke-width='1.2'/%3E%3Ccircle cx='24' cy='18' r='4' fill='none' stroke='rgba(140,100,220,0.14)' stroke-width='1.2'/%3E%3Ccircle cx='39' cy='18' r='4' fill='none' stroke='rgba(140,100,220,0.14)' stroke-width='1.2'/%3E%3C/g%3E%3C/svg%3E");
  background-size: 400px 400px;
}
.login-wrap { text-align: center; }
.login-logo {
  font-size: 52px;
  font-weight: 700;
  color: var(--blue);
  letter-spacing: -1px;
  margin-bottom: 28px;
  text-shadow: 0 0 40px rgba(42,171,238,0.3);
}
.login-box {
  background: rgba(30, 24, 45, 0.85);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border: 1px solid rgba(140,100,220,0.15);
  border-radius: 18px;
  padding: 32px 36px;
  width: 320px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  box-shadow: 0 8px 40px rgba(0,0,0,0.5);
}
.login-box input {
  width: 100%;
  padding: 13px 16px;
  border: none;
  border-bottom: 2px solid rgba(140,100,220,0.25);
  background: transparent;
  color: var(--text);
  font-size: 15px;
  outline: none;
  transition: border-color .2s;
  border-radius: 0;
}
.login-box input:focus { border-bottom-color: var(--blue); }
.login-box input::placeholder { color: var(--text-2); }
.login-box button {
  margin-top: 8px;
  width: 100%;
  padding: 13px;
  background: var(--blue);
  color: #fff;
  border: none;
  border-radius: 10px;
  font-size: 16px;
  font-weight: 600;
  cursor: pointer;
  transition: background .2s, box-shadow .2s;
  box-shadow: 0 4px 16px rgba(42,171,238,0.3);
}
.login-box button:hover { background: var(--blue-dark); box-shadow: 0 4px 20px rgba(42,171,238,0.45); }
#login-error { color: var(--red); font-size: 13px; min-height: 18px; }

/* ─── App layout ────────────────────────────────── */
#app-screen { display: flex; height: 100vh; height: 100dvh; overflow: hidden; }

/* ─── Sidebar ───────────────────────────────────── */
#sidebar {
  width: 340px;
  min-width: 260px;
  display: flex;
  flex-direction: column;
  background: var(--sidebar-bg);
  border-right: 1px solid #1c1c1e;
  flex-shrink: 0;
}

#sidebar-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  min-height: 56px;
  border-bottom: 1px solid rgba(255,255,255,.06);
  background: #1c1c1e;
}
#sidebar-user-name { font-weight: 600; font-size: 16px; color: var(--text); }
#sidebar-actions { display: flex; flex-direction: row; align-items: center; gap: 4px; }

#search-wrap {
  padding: 8px 12px;
  background: #1c1c1e;
  border-bottom: 1px solid rgba(255,255,255,.04);
}
#search-input {
  width: 100%;
  padding: 9px 14px 9px 36px;
  border: none;
  border-radius: 10px;
  background: #2c2c2e;
  color: var(--text);
  font-size: 14px;
  outline: none;
}
#search-input::placeholder { color: var(--text-2); }
#search-wrap { position: relative; }
#search-wrap::before {
  content: '';
  position: absolute;
  left: 24px;
  top: 50%;
  transform: translateY(-50%);
  width: 14px;
  height: 14px;
  background: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Ccircle cx='11' cy='11' r='7' fill='none' stroke='%238e8e93' stroke-width='2'/%3E%3Cpath d='M16.5 16.5 L21 21' stroke='%238e8e93' stroke-width='2' stroke-linecap='round'/%3E%3C/svg%3E") center/contain no-repeat;
  pointer-events: none;
}

#chat-list { flex: 1; overflow-y: auto; }

.chat-item {
  display: flex;
  align-items: center;
  padding: 10px 16px 10px 12px;
  gap: 12px;
  cursor: pointer;
  transition: background .15s;
  border-bottom: 1px solid rgba(255,255,255,.04);
}
.chat-item:hover { background: var(--hover); }
.chat-item.active { background: var(--active-chat); }

.chat-avatar {
  width: 52px;
  height: 52px;
  border-radius: 50%;
  background: linear-gradient(135deg, #4A6A8A 0%, #2B4A6F 100%);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 19px;
  font-weight: 600;
  flex-shrink: 0;
  position: relative;
  letter-spacing: -0.5px;
}
.chat-avatar.group { background: linear-gradient(135deg, #5A6A9A 0%, #3A4A8F 100%); }
.online-dot {
  width: 12px;
  height: 12px;
  background: var(--green);
  border: 2px solid var(--sidebar-bg);
  border-radius: 50%;
  position: absolute;
  bottom: 1px;
  right: 1px;
}
.chat-item.active .online-dot { border-color: var(--active-chat); }

.chat-item-right { flex: 1; min-width: 0; }
.chat-item-top {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  margin-bottom: 3px;
}
.chat-name { font-weight: 600; font-size: 16px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; color: var(--text); }
.chat-time { font-size: 13px; color: var(--text-2); flex-shrink: 0; margin-left: 6px; }
.chat-item-bottom { display: flex; align-items: center; gap: 4px; }
.chat-preview {
  font-size: 14px;
  color: var(--text-2);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  flex: 1;
}
.unread-badge {
  background: var(--blue);
  color: #fff;
  border-radius: 12px;
  font-size: 12px;
  font-weight: 600;
  padding: 2px 8px;
  min-width: 22px;
  text-align: center;
  flex-shrink: 0;
}

/* ─── Main area ─────────────────────────────────── */
#main { flex: 1; display: flex; flex-direction: column; background: var(--chat-bg); min-width: 0; }

#no-chat {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
}
.no-chat-text { color: var(--text-2); font-size: 15px; }

#chat-view { flex: 1; display: flex; flex-direction: column; min-height: 0; }

#chat-header {
  background: #1c1c1e;
  border-bottom: 1px solid rgba(255,255,255,.06);
  padding: 10px 16px;
  min-height: 56px;
  display: flex;
  align-items: center;
}
#chat-header-name { font-weight: 600; font-size: 16px; color: var(--text); }
#chat-header-sub { font-size: 13px; color: var(--blue); margin-top: 1px; }
#chat-header-info { cursor: pointer; }
#chat-header-info:active { opacity: .7; }

.gi-member { display: flex; align-items: center; gap: 12px; padding: 10px 0; border-bottom: 1px solid rgba(255,255,255,.06); }
.gi-member .chat-avatar { width: 40px; height: 40px; font-size: 15px; }
.gi-member:last-child { border-bottom: none; }
.gi-member-info { flex: 1; min-width: 0; }
.gi-member-name { font-size: 15px; font-weight: 500; color: var(--text); }
.gi-member-sub { font-size: 13px; color: var(--text-2); margin-top: 1px; }
.gi-member-sub.online { color: var(--blue); }

#messages-wrap {
  flex: 1;
  overflow-y: auto;
  padding: 12px 16px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  background-color: #1a1625;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='400' height='400'%3E%3Cg transform='translate(20,30)'%3E%3Cpath d='M2,14 L2,8 L8,4 L24,4 L28,8 L34,8 L34,14 Z' fill='none' stroke='rgba(140,100,220,0.12)' stroke-width='1.2' stroke-linejoin='round'/%3E%3Ccircle cx='9' cy='14' r='4' fill='none' stroke='rgba(140,100,220,0.12)' stroke-width='1.2'/%3E%3Ccircle cx='27' cy='14' r='4' fill='none' stroke='rgba(140,100,220,0.12)' stroke-width='1.2'/%3E%3Cpath d='M8,8 L10,5 L24,5 L26,8 Z' fill='none' stroke='rgba(140,100,220,0.08)' stroke-width='1'/%3E%3C/g%3E%3Cg transform='translate(248,22)'%3E%3Cpath d='M0,18 L0,9 L7,3 L16,3 L16,18 Z' fill='none' stroke='rgba(140,100,220,0.11)' stroke-width='1.2' stroke-linejoin='round'/%3E%3Cpath d='M16,18 L16,7 L46,7 L46,18 Z' fill='none' stroke='rgba(140,100,220,0.11)' stroke-width='1.2' stroke-linejoin='round'/%3E%3Ccircle cx='7' cy='18' r='4' fill='none' stroke='rgba(140,100,220,0.11)' stroke-width='1.2'/%3E%3Ccircle cx='24' cy='18' r='4' fill='none' stroke='rgba(140,100,220,0.11)' stroke-width='1.2'/%3E%3Ccircle cx='39' cy='18' r='4' fill='none' stroke='rgba(140,100,220,0.11)' stroke-width='1.2'/%3E%3C/g%3E%3Cg transform='translate(15,158)'%3E%3Cpath d='M2,18 L2,4 L38,4 L38,18 Z' fill='none' stroke='rgba(140,100,220,0.11)' stroke-width='1.2' stroke-linejoin='round'/%3E%3Ccircle cx='9' cy='18' r='4' fill='none' stroke='rgba(140,100,220,0.11)' stroke-width='1.2'/%3E%3Ccircle cx='31' cy='18' r='4' fill='none' stroke='rgba(140,100,220,0.11)' stroke-width='1.2'/%3E%3Crect x='5' y='7' width='10' height='7' rx='1' fill='none' stroke='rgba(140,100,220,0.07)' stroke-width='1'/%3E%3Crect x='19' y='7' width='10' height='7' rx='1' fill='none' stroke='rgba(140,100,220,0.07)' stroke-width='1'/%3E%3C/g%3E%3Cg transform='translate(390,150) scale(-1,1)'%3E%3Cpath d='M2,14 L2,8 L8,4 L24,4 L28,8 L34,8 L34,14 Z' fill='none' stroke='rgba(140,100,220,0.11)' stroke-width='1.2' stroke-linejoin='round'/%3E%3Ccircle cx='9' cy='14' r='4' fill='none' stroke='rgba(140,100,220,0.11)' stroke-width='1.2'/%3E%3Ccircle cx='27' cy='14' r='4' fill='none' stroke='rgba(140,100,220,0.11)' stroke-width='1.2'/%3E%3C/g%3E%3Cg transform='translate(40,298)'%3E%3Cpath d='M2,20 L2,4 L52,4 L52,20 Z' fill='none' stroke='rgba(140,100,220,0.1)' stroke-width='1.2' stroke-linejoin='round'/%3E%3Ccircle cx='11' cy='20' r='5' fill='none' stroke='rgba(140,100,220,0.1)' stroke-width='1.2'/%3E%3Ccircle cx='43' cy='20' r='5' fill='none' stroke='rgba(140,100,220,0.1)' stroke-width='1.2'/%3E%3Crect x='6' y='8' width='9' height='7' rx='1' fill='none' stroke='rgba(140,100,220,0.07)' stroke-width='1'/%3E%3Crect x='18' y='8' width='9' height='7' rx='1' fill='none' stroke='rgba(140,100,220,0.07)' stroke-width='1'/%3E%3Crect x='30' y='8' width='9' height='7' rx='1' fill='none' stroke='rgba(140,100,220,0.07)' stroke-width='1'/%3E%3C/g%3E%3Cg transform='translate(278,290)'%3E%3Cpath d='M0,16 L0,6 L8,2 L18,2 L18,16 Z' fill='none' stroke='rgba(140,100,220,0.11)' stroke-width='1.2' stroke-linejoin='round'/%3E%3Cpath d='M18,16 L18,8 L36,8 L36,16 Z' fill='none' stroke='rgba(140,100,220,0.11)' stroke-width='1.2' stroke-linejoin='round'/%3E%3Ccircle cx='6' cy='16' r='4' fill='none' stroke='rgba(140,100,220,0.11)' stroke-width='1.2'/%3E%3Ccircle cx='28' cy='16' r='4' fill='none' stroke='rgba(140,100,220,0.11)' stroke-width='1.2'/%3E%3C/g%3E%3Cg transform='translate(158,108) scale(0.85)'%3E%3Cpath d='M2,14 L2,8 L8,4 L24,4 L28,8 L34,8 L34,14 Z' fill='none' stroke='rgba(140,100,220,0.09)' stroke-width='1.2' stroke-linejoin='round'/%3E%3Ccircle cx='9' cy='14' r='4' fill='none' stroke='rgba(140,100,220,0.09)' stroke-width='1.2'/%3E%3Ccircle cx='27' cy='14' r='4' fill='none' stroke='rgba(140,100,220,0.09)' stroke-width='1.2'/%3E%3C/g%3E%3Cg transform='translate(400,238) scale(-1,1)'%3E%3Cpath d='M0,18 L0,9 L7,3 L16,3 L16,18 Z' fill='none' stroke='rgba(140,100,220,0.09)' stroke-width='1.2' stroke-linejoin='round'/%3E%3Cpath d='M16,18 L16,7 L46,7 L46,18 Z' fill='none' stroke='rgba(140,100,220,0.09)' stroke-width='1.2' stroke-linejoin='round'/%3E%3Ccircle cx='7' cy='18' r='4' fill='none' stroke='rgba(140,100,220,0.09)' stroke-width='1.2'/%3E%3Ccircle cx='24' cy='18' r='4' fill='none' stroke='rgba(140,100,220,0.09)' stroke-width='1.2'/%3E%3Ccircle cx='39' cy='18' r='4' fill='none' stroke='rgba(140,100,220,0.09)' stroke-width='1.2'/%3E%3C/g%3E%3C/svg%3E");
  background-size: 400px 400px;
}

#messages-load-more { text-align: center; padding: 8px 0; }
#messages-load-more button {
  background: rgba(255,255,255,.08);
  border: none;
  border-radius: 16px;
  padding: 6px 18px;
  font-size: 13px;
  color: var(--text-2);
  cursor: pointer;
}
#messages-load-more button:hover { background: rgba(255,255,255,.12); }

/* ─── Message bubbles ───────────────────────────── */
.msg-row { display: flex; margin: 3px 0; }
.msg-row.out { justify-content: flex-end; }
.msg-row.in { justify-content: flex-start; }

.msg-bubble {
  max-width: 62%;
  padding: 8px 12px 6px;
  border-radius: 16px;
  position: relative;
  word-break: break-word;
}
.msg-row.out .msg-bubble {
  background: var(--bubble-out);
  border-bottom-right-radius: 4px;
}
.msg-row.in .msg-bubble {
  background: var(--bubble-in);
  border-bottom-left-radius: 4px;
}

.msg-sender {
  font-size: 13px;
  font-weight: 600;
  color: var(--blue);
  margin-bottom: 3px;
}
.msg-text { font-size: 16px; line-height: 1.45; color: var(--text); }

.msg-meta {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 4px;
  margin-top: 4px;
}
.msg-time { font-size: 11px; color: rgba(255,255,255,.5); white-space: nowrap; }
.msg-edited { font-size: 11px; color: rgba(255,255,255,.4); white-space: nowrap; }

.msg-status svg { width: 16px; height: 10px; display: block; }
.msg-status.sent  { color: rgba(255,255,255,.45); }
.msg-status.delivered { color: rgba(255,255,255,.65); }
.msg-status.read  { color: var(--blue); }
.msg-status.pending { color: rgba(255,255,255,.4); }
.msg-status.pending svg { width: 14px; height: 14px; }

/* ─── Reply preview inside bubble ──────────────── */
.reply-preview {
  border-left: 3px solid var(--blue);
  background: rgba(255,255,255,.07);
  border-radius: 6px;
  padding: 5px 8px;
  margin-bottom: 6px;
  max-width: 100%;
  overflow: hidden;
}
.reply-preview-name {
  font-size: 12px;
  font-weight: 600;
  color: var(--blue);
  margin-bottom: 2px;
}
.reply-preview-text {
  font-size: 12px;
  color: rgba(255,255,255,.7);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* ─── Reply bar above input ──────────────────── */
#edit-bar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 12px;
  background: var(--header-bg);
  border-top: 1px solid rgba(255,255,255,.06);
}
#edit-bar-label { font-size: 12px; font-weight: 600; color: var(--green); margin-bottom: 1px; }
#edit-bar-text { font-size: 12px; color: var(--text-2); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
#edit-bar .reply-bar-accent { background: var(--green); }

#reply-bar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 12px;
  background: var(--header-bg);
  border-top: 1px solid rgba(255,255,255,.06);
}
.reply-bar-accent {
  width: 3px;
  align-self: stretch;
  background: var(--blue);
  border-radius: 3px;
  flex-shrink: 0;
}
.reply-bar-body { flex: 1; min-width: 0; }
#reply-bar-name {
  font-size: 12px;
  font-weight: 600;
  color: var(--blue);
  margin-bottom: 1px;
}
#reply-bar-text {
  font-size: 12px;
  color: var(--text-2);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
#reply-bar-cancel svg { fill: currentColor; }

/* ─── Context menu ───────────────────────────── */
#ctx-menu {
  position: fixed;
  z-index: 1000;
  background: #2c2c2e;
  border-radius: 12px;
  overflow: hidden;
  box-shadow: 0 8px 30px rgba(0,0,0,.5);
  min-width: 160px;
}
#ctx-menu button {
  display: block;
  width: 100%;
  padding: 13px 18px;
  background: none;
  border: none;
  color: var(--text);
  font-size: 15px;
  text-align: left;
  cursor: pointer;
}
#ctx-menu button:not(:last-child) { border-bottom: 1px solid rgba(255,255,255,.06); }
#ctx-menu button:hover { background: rgba(255,255,255,.06); }
#ctx-delete { color: var(--red); }

/* ─── Image messages ────────────────────────────── */
.msg-image {
  max-width: 260px;
  max-height: 220px;
  border-radius: 10px;
  cursor: pointer;
  display: block;
  object-fit: cover;
  transition: opacity .15s;
}
.msg-image:hover { opacity: .88; }
.msg-bubble.image-bubble { padding: 4px 4px 6px; }
.image-bubble .msg-meta { padding: 0 4px; }

/* ─── Audio messages ────────────────────────────── */
.audio-player {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 200px;
}
.audio-play-btn {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  border: none;
  background: var(--blue);
  color: #fff;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: background .15s;
}
.audio-play-btn:hover { background: var(--blue-dark); }
.audio-play-btn svg { width: 18px; height: 18px; }
.audio-progress-wrap { flex: 1; display: flex; flex-direction: column; gap: 5px; }
.audio-waveform {
  height: 24px;
  display: flex;
  align-items: center;
  gap: 2px;
}
.waveform-bar {
  width: 3px;
  border-radius: 2px;
  background: rgba(255,255,255,.4);
  flex-shrink: 0;
}
.audio-progress {
  height: 2px;
  background: rgba(255,255,255,.2);
  border-radius: 2px;
  cursor: pointer;
}
.audio-progress-fill {
  height: 100%;
  background: var(--blue);
  border-radius: 2px;
  width: 0%;
  transition: width .1s;
}
.audio-duration { font-size: 12px; color: rgba(255,255,255,.5); }

/* ─── Input area ────────────────────────────────── */
#input-area {
  display: flex;
  align-items: flex-end;
  padding: 8px 10px 8px 0;
  padding-bottom: max(8px, env(safe-area-inset-bottom));
  background: var(--header-bg);
  border-top: 1px solid rgba(0,0,0,.3);
  gap: 6px;
}
#attach-btn { margin-right: -6px; }

#message-input {
  flex: 1;
  min-height: 40px;
  max-height: 140px;
  padding: 10px 14px;
  background: var(--input-bg);
  border-radius: 22px;
  outline: none;
  font-size: 16px;
  color: var(--text);
  overflow-y: auto;
  line-height: 1.4;
}
#message-input:empty::before {
  content: attr(data-placeholder);
  color: var(--text-2);
  pointer-events: none;
}

.icon-btn {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  border: none;
  background: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  color: var(--text-2);
  transition: background .15s, color .15s;
}
.icon-btn:hover { background: var(--hover); color: var(--blue); }
.icon-btn svg { width: 22px; height: 22px; fill: currentColor; }
.icon-btn.send { background: var(--blue); color: #fff; }
.icon-btn.send:hover { background: var(--blue-dark); }
#audio-btn { background: var(--blue); color: #fff; }
#audio-btn:hover { background: var(--blue-dark); color: #fff; }

#push-btn.push-active { color: var(--blue); }
#mute-btn { margin-left: auto; }
#mute-btn.muted { color: var(--text-2); }
#mute-btn:not(.muted) { color: var(--blue); }

#image-preview-wrap {
  padding: 8px 12px;
  background: var(--header-bg);
  border-top: 1px solid rgba(0,0,0,.3);
  display: flex;
  align-items: center;
  gap: 12px;
}
#image-preview { height: 80px; border-radius: 8px; object-fit: contain; }
#image-preview-cancel, #image-preview-send {
  padding: 7px 16px;
  border-radius: 16px;
  border: none;
  font-size: 13px;
  cursor: pointer;
  font-weight: 500;
}
#image-preview-cancel { background: rgba(255,255,255,.08); color: var(--text-2); }
#image-preview-send { background: var(--blue); color: #fff; }

#recording-indicator {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 16px;
  background: var(--header-bg);
  border-top: 1px solid rgba(0,0,0,.3);
}
.rec-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--red);
  animation: blink 1s infinite;
}
@keyframes blink { 0%,100% { opacity: 1; } 50% { opacity: .2; } }
#rec-timer { font-size: 14px; color: var(--text); flex: 1; }
#rec-cancel-btn, #rec-send-btn {
  padding: 7px 16px;
  border-radius: 16px;
  border: none;
  font-size: 13px;
  cursor: pointer;
  font-weight: 500;
}
#rec-cancel-btn { background: rgba(255,255,255,.08); color: var(--text-2); }
#rec-send-btn { background: var(--blue); color: #fff; }

/* ─── Lightbox ──────────────────────────────────── */
#lightbox { position: fixed; inset: 0; z-index: 1000; display: flex; align-items: center; justify-content: center; }
#lightbox-bg { position: absolute; inset: 0; background: rgba(0,0,0,.9); }
#lightbox-img { position: relative; max-width: 90vw; max-height: 90vh; border-radius: 4px; object-fit: contain; }
#lightbox-close {
  position: absolute;
  top: 20px;
  right: 24px;
  background: rgba(255,255,255,.12);
  border: none;
  color: #fff;
  font-size: 22px;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  cursor: pointer;
  z-index: 1;
  transition: background .15s;
}
#lightbox-close:hover { background: rgba(255,255,255,.22); }

/* ─── Modals ────────────────────────────────────── */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.6);
  z-index: 500;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}
.modal-box {
  background: var(--modal-bg);
  border-radius: 14px;
  width: 100%;
  max-width: 540px;
  max-height: 88vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.modal-box.small { max-width: 400px; }

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px 20px 14px;
  flex-shrink: 0;
}
.modal-title { font-size: 18px; font-weight: 700; color: var(--text); }
.modal-close {
  background: none;
  border: none;
  font-size: 20px;
  cursor: pointer;
  color: var(--text-2);
  width: 32px;
  height: 32px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background .15s;
}
.modal-close:hover { background: var(--hover); color: var(--text); }

.modal-tabs {
  display: flex;
  border-bottom: 1px solid rgba(255,255,255,.06);
  flex-shrink: 0;
}
.tab-btn {
  flex: 1;
  padding: 13px;
  border: none;
  background: none;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  color: var(--text-2);
  border-bottom: 2px solid transparent;
  transition: color .15s, border-color .15s;
}
.tab-btn.active { color: var(--blue); border-bottom-color: var(--blue); }

.tab-content { flex: 1; overflow-y: auto; padding: 12px 16px; }

/* ─── Admin lists ───────────────────────────────── */
.admin-item {
  display: flex;
  align-items: center;
  padding: 10px 8px;
  border-radius: 8px;
  gap: 10px;
  transition: background .15s;
}
.admin-item:hover { background: var(--hover); }
.admin-item-name { font-size: 15px; color: var(--text); }
.admin-item-sub { font-size: 12px; color: var(--text-2); margin-top: 2px; }
.inactive-label { font-size: 12px; color: var(--text-2); margin-left: 6px; }
.admin-actions { display: flex; gap: 6px; }
.admin-btn {
  padding: 6px 14px;
  border-radius: 16px;
  border: 1px solid rgba(255,255,255,.12);
  background: none;
  font-size: 13px;
  color: var(--text-2);
  cursor: pointer;
  transition: background .15s, color .15s;
}
.admin-btn:hover { background: var(--hover); color: var(--text); }
.admin-btn.danger { color: var(--red); border-color: rgba(229,57,53,.4); }
.admin-btn.danger:hover { background: rgba(229,57,53,.1); }

.add-btn {
  display: block;
  width: 100%;
  padding: 12px;
  margin-top: 10px;
  background: var(--blue);
  color: #fff;
  border: none;
  border-radius: 8px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: background .15s;
}
.add-btn:hover { background: var(--blue-dark); }

/* ─── Forms ─────────────────────────────────────── */

/* группируем поля в один блок с разделителями */
.modal-box.small .form-group { margin-bottom: 0; }

.form-fields-group {
  background: #2C2C2E;
  border-radius: 12px;
  overflow: hidden;
  margin-bottom: 16px;
}
.form-fields-group .form-group { margin-bottom: 0; }
.form-fields-group .form-group + .form-group {
  border-top: 1px solid rgba(255,255,255,.06);
}

.form-group input[type="text"],
.form-group input[type="password"],
.form-group select {
  width: 100%;
  padding: 14px 16px;
  background: #2C2C2E;
  border: none;
  border-radius: 12px;
  color: var(--text);
  font-size: 16px;
  outline: none;
  -webkit-appearance: none;
  appearance: none;
}
.form-fields-group .form-group input,
.form-fields-group .form-group select {
  border-radius: 0;
}
.form-fields-group .form-group:first-child input,
.form-fields-group .form-group:first-child select { border-radius: 12px 12px 0 0; }
.form-fields-group .form-group:last-child input,
.form-fields-group .form-group:last-child select { border-radius: 0 0 12px 12px; }
.form-fields-group .form-group:only-child input,
.form-fields-group .form-group:only-child select { border-radius: 12px; }

.form-group select {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath d='M1 1l5 5 5-5' stroke='%23708499' stroke-width='1.5' fill='none' stroke-linecap='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 16px center;
  padding-right: 40px;
  cursor: pointer;
}
.form-group input::placeholder { color: #636366; }
.form-group input:focus,
.form-group select:focus { background: #3A3A3C; }

/* checkbox row — отдельный блок */
.form-group.checkbox-group {
  background: #2C2C2E;
  border-radius: 12px;
  padding: 4px 16px;
  margin-bottom: 16px;
}
.form-group label.checkbox-label {
  display: flex;
  align-items: center;
  gap: 14px;
  cursor: pointer;
  font-size: 16px;
  color: var(--text);
  padding: 10px 0;
  user-select: none;
}
.form-group input[type="checkbox"] { display: none; }
.checkbox-box {
  width: 24px;
  height: 24px;
  border-radius: 50%;
  border: 2px solid #636366;
  background: transparent;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: background .15s, border-color .15s;
}
.form-group input[type="checkbox"]:checked + .checkbox-box {
  background: var(--blue);
  border-color: var(--blue);
}
.checkbox-box::after {
  content: '';
  width: 6px;
  height: 11px;
  border: 2px solid #fff;
  border-top: none;
  border-left: none;
  transform: rotate(45deg) translateY(-1px);
  opacity: 0;
  transition: opacity .1s;
}
.form-group input[type="checkbox"]:checked + .checkbox-box::after { opacity: 1; }

.form-error { color: var(--red); font-size: 13px; min-height: 16px; margin: 4px 0 10px; }
.form-actions { padding: 4px 0; }
.btn-primary {
  width: 100%;
  padding: 14px;
  background: var(--blue);
  color: #fff;
  border: none;
  border-radius: 12px;
  font-size: 16px;
  font-weight: 600;
  cursor: pointer;
  transition: background .15s;
}
.btn-primary:hover { background: var(--blue-dark); }

/* members list in group form */
.members-label { font-size: 13px; color: var(--text-2); margin-bottom: 8px; padding-left: 4px; }
.members-scroll { background: #2C2C2E; border-radius: 12px; overflow: hidden; max-height: 240px; overflow-y: auto; }
.member-item {
  border-top: 1px solid rgba(255,255,255,.05);
  padding: 0 16px;
}
.member-item:first-child { border-top: none; }
.member-item input[type="checkbox"] { display: none; }
.member-item label.checkbox-label {
  display: flex;
  align-items: center;
  gap: 14px;
  font-size: 15px;
  padding: 11px 0;
  cursor: pointer;
  color: var(--text);
  user-select: none;
}
.member-item input[type="checkbox"]:checked + .checkbox-box {
  background: var(--blue);
  border-color: var(--blue);
}
.member-item input[type="checkbox"]:checked + .checkbox-box::after { opacity: 1; }

/* ─── Admin btn icon ────────────────────────────── */
.icon-btn svg path { transition: fill .15s; }

/* ─── Date separators ───────────────────────────── */
.date-sep {
  text-align: center;
  font-size: 12px;
  color: var(--text-2);
  margin: 10px 0 6px;
}
.date-sep span {
  background: rgba(0,0,0,.35);
  padding: 4px 12px;
  border-radius: 10px;
}

/* ─── Toast ─────────────────────────────────────── */
#toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%) translateY(100px);
  background: #2B3A4A;
  color: #fff;
  padding: 11px 22px;
  border-radius: 20px;
  font-size: 14px;
  z-index: 2000;
  transition: transform .25s;
  pointer-events: none;
}
#toast.show { transform: translateX(-50%) translateY(0); }

/* ─── Scrollbar ─────────────────────────────────── */
::-webkit-scrollbar { width: 4px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: rgba(255,255,255,.1); border-radius: 2px; }
::-webkit-scrollbar-thumb:hover { background: rgba(255,255,255,.18); }

/* ─── Mobile layout ─────────────────────────────── */
@media (max-width: 768px) {
  #app-screen { position: relative; overflow: hidden; }

  #sidebar {
    position: absolute;
    inset: 0;
    width: 100%;
    z-index: 10;
    transform: translateX(0);
    transition: transform .28s cubic-bezier(.4,0,.2,1);
  }
  #sidebar.slide-out { transform: translateX(-100%); }

  #main {
    position: absolute;
    inset: 0;
    width: 100%;
    z-index: 9;
    transform: translateX(100%);
    transition: transform .28s cubic-bezier(.4,0,.2,1);
  }
  #main.slide-in { transform: translateX(0); }

  /* back arrow button in chat header */
  #back-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    margin-right: 6px;
    background: none;
    border: none;
    color: var(--blue);
    cursor: pointer;
    flex-shrink: 0;
    border-radius: 50%;
  }
  #back-btn svg { width: 22px; height: 22px; fill: currentColor; }

  #messages-wrap { padding: 8px 8px; }

  .msg-bubble { max-width: 80%; }

  /* wider modals on mobile */
  .modal-overlay { padding: 12px; align-items: flex-end; }
  .modal-box, .modal-box.small {
    max-width: 100%;
    max-height: 92vh;
    border-radius: 16px 16px 0 0;
  }
}

@media (min-width: 769px) {
  #back-btn { display: none; }
  #attach-btn { width: 32px; height: 41px; }
  #attach-btn svg { width: 18px; height: 18px; }
}

/* ─── Touch devices: remove sticky hovers, use :active ─ */
@media (hover: none) {
  * { -webkit-tap-highlight-color: transparent; }

  .chat-item:hover,
  .chat-item:focus            { background: transparent; }
  .chat-item.active:hover     { background: var(--active-chat); }
  .icon-btn:hover             { background: none; color: var(--text-2); }
  .icon-btn.send:hover        { background: var(--blue); color: #fff; }
  .admin-item:hover           { background: transparent; }
  .admin-btn:hover            { background: none; color: var(--text-2); }
  .admin-btn.danger:hover     { background: none; }
  .add-btn:hover              { background: var(--blue); }
  .btn-primary:hover          { background: var(--blue); box-shadow: none; }
  .login-box button:hover     { background: var(--blue); box-shadow: none; }
  .modal-close:hover          { background: none; color: var(--text-2); }
  .tab-btn:hover              { color: var(--text-2); }
  .msg-image:hover            { opacity: 1; }
  .audio-play-btn:hover       { background: var(--blue); }
  #audio-btn:hover            { background: var(--blue); color: #fff; }
  #messages-load-more button:hover { background: rgba(255,255,255,.08); }
  ::-webkit-scrollbar-thumb:hover  { background: rgba(255,255,255,.1); }

  /* active feedback instead */
  .chat-item:active           { background: var(--hover); }
  .icon-btn:active            { background: var(--hover) !important; }
  .icon-btn.send:active       { background: var(--blue-dark) !important; }
  #audio-btn:active           { background: var(--blue-dark) !important; }
  .admin-btn:active           { background: var(--hover); }
  .add-btn:active             { background: var(--blue-dark); }
  .btn-primary:active         { background: var(--blue-dark); }
  .login-box button:active    { background: var(--blue-dark); }
  .modal-close:active         { background: var(--hover); }
  .audio-play-btn:active      { background: var(--blue-dark); }
}

/* ─── Mobile: Telegram iOS dark colors ──────────────── */
@media (max-width: 768px) {
  :root {
    --bg:         #000000;
    --chat-bg:    #000000;
    --sidebar-bg: #000000;
    --header-bg:  #1c1c1e;
    --input-bg:   #1c1c1e;
    --modal-bg:   #1c1c1e;
    --modal-input:#2c2c2e;
    --bubble-in:  #1c1c1e;
    --hover:      rgba(255,255,255,.07);
  }
  #search-input { background: #2c2c2e; }
  .form-fields-group { background: #2c2c2e; }
  .form-group input[type="text"],
  .form-group input[type="password"],
  .form-group select { background: #2c2c2e; }
  .form-group.checkbox-group { background: #2c2c2e; }
  .members-scroll { background: #2c2c2e; }
}

/* ─── Upload progress overlay ───────────────────── */
.upload-overlay {
  position: absolute;
  inset: 0;
  border-radius: 10px;
  background: rgba(0,0,0,.45);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 6px;
}
.upload-spinner { width: 48px; height: 48px; }
.upload-arc { transition: stroke-dashoffset .2s; }
.upload-pct { font-size: 13px; color: #fff; font-weight: 600; }
.upload-error { font-size: 22px; color: #ff5555; }

/* pending audio */
.audio-pending {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 160px;
  padding: 6px 0;
  color: rgba(255,255,255,.6);
  font-size: 13px;
}
.audio-spinner {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  border: 3px solid rgba(255,255,255,.2);
  border-top-color: #fff;
  animation: spin .8s linear infinite;
  flex-shrink: 0;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* pending clock status */
.msg-status.pending svg { opacity: .6; }
