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

:root {
  --bg:        #0c0c12;
  --bg2:       #13131c;
  --bg3:       #1a1a26;
  --bg4:       #17172120;
  --hover:     #252535;
  --accent:    #7c6af7;
  --accent2:   #6457e8;
  --accent-glow: rgba(124,106,247,0.22);
  --text:      #e4e4f0;
  --text2:     #8888a8;
  --muted:     #55556a;
  --border:    #252535;
  --border2:   #303048;
  --green:     #3dd68c;
  --red:       #ff5572;
  --yellow:    #ffb340;
  --sidebar:   265px;
  --radius:    10px;
  --radius-lg: 14px;
  --radius-xl: 18px;
}

html, body {
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  font-size: 14px;
  line-height: 1.5;
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

.hidden { display: none !important; }

/* ── Scrollbars ── */
::-webkit-scrollbar { width: 4px; height: 4px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border2); border-radius: 4px; }
::-webkit-scrollbar-thumb:hover { background: var(--muted); }

/* ── Loading ── */
#loading-screen {
  position: fixed; inset: 0;
  background: var(--bg);
  display: flex; align-items: center; justify-content: center;
  z-index: 999;
}
.loading-content {
  text-align: center;
  display: flex; flex-direction: column; align-items: center; gap: 22px;
}
.loading-logo {
  font-size: 50px; font-weight: 800;
  background: linear-gradient(135deg, var(--accent) 0%, #a78bfa 50%, #60a5fa 100%);
  -webkit-background-clip: text; -webkit-text-fill-color: transparent;
  letter-spacing: -2px;
  filter: drop-shadow(0 0 32px var(--accent-glow));
}
.loading-text { color: var(--text2); font-size: 13px; font-weight: 500; letter-spacing: 0.02em; }
.spinner {
  width: 30px; height: 30px;
  border: 2px solid var(--border2);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.75s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ── Layout ── */
#main-ui { display: flex; height: 100vh; }

/* ── Sidebar ── */
#sidebar {
  width: var(--sidebar); min-width: var(--sidebar);
  background: var(--bg2);
  border-right: 1px solid var(--border);
  display: flex; flex-direction: column;
  overflow: hidden;
  transition: width 0.3s cubic-bezier(0.4,0,0.2,1),
              min-width 0.3s cubic-bezier(0.4,0,0.2,1),
              transform 0.3s cubic-bezier(0.4,0,0.2,1);
  z-index: 10;
}
#sidebar.collapsed {
  width: 0; min-width: 0; border-right: none;
}

/* Backdrop for mobile overlay */
#sidebar-backdrop {
  display: none;
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.55);
  z-index: 9;
  backdrop-filter: blur(2px);
}

.sidebar-header {
  padding: 15px 16px;
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center; justify-content: space-between;
  flex-shrink: 0;
}
.app-logo { display: flex; align-items: center; gap: 8px; font-weight: 800; font-size: 18px; letter-spacing: -0.5px; }
.logo-icon { font-size: 20px; }
.logo-text {
  background: linear-gradient(135deg, var(--accent), #a78bfa);
  -webkit-background-clip: text; -webkit-text-fill-color: transparent;
}
.network-badge {
  display: flex; align-items: center; gap: 5px;
  font-size: 11px; color: var(--text2); font-weight: 500;
  background: var(--bg3);
  padding: 4px 10px; border-radius: 20px;
  border: 1px solid var(--border);
}
.dot { width: 6px; height: 6px; border-radius: 50%; flex-shrink: 0; }
.dot.online {
  background: var(--green);
  box-shadow: 0 0 6px var(--green);
  animation: pulse-dot 2.5s ease infinite;
}
@keyframes pulse-dot { 0%, 100% { opacity: 1; } 50% { opacity: 0.6; } }

.sidebar-profile {
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center; gap: 10px;
  flex-shrink: 0;
  background: var(--bg3);
}
.avatar {
  border-radius: 50%;
  background: linear-gradient(135deg, var(--accent), #a78bfa);
  display: flex; align-items: center; justify-content: center;
  font-weight: 700; color: white;
  flex-shrink: 0; user-select: none;
  box-shadow: 0 2px 10px var(--accent-glow);
}
.avatar.lg { width: 38px; height: 38px; font-size: 15px; }
.avatar.sm { width: 28px; height: 28px; font-size: 11px; }
.avatar.xs { width: 22px; height: 22px; font-size: 9px; }
.profile-info { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.pseudo-name-row { display: flex; align-items: center; gap: 6px; min-width: 0; cursor: pointer; }
.pseudo-name-row:hover .pseudo-display { color: var(--accent); }
.pseudo-name-row:hover .btn-edit-pseudo { color: var(--accent); opacity: 1; }
.pseudo-display { font-weight: 600; font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; flex: 1; min-width: 0; transition: color 0.15s; }
.btn-edit-pseudo {
  background: none; border: none; color: var(--text2);
  cursor: pointer; font-size: 14px; padding: 2px 5px; border-radius: 4px;
  flex-shrink: 0; transition: all 0.15s; line-height: 1; opacity: 0.7;
}
.btn-edit-pseudo:hover { color: var(--accent); opacity: 1; background: rgba(124,106,247,0.12); }
.sidebar-profile.editing { flex-wrap: wrap; }
.sidebar-profile.editing .pseudo-edit {
  width: 100%; flex-basis: 100%;
}
.pseudo-edit { display: flex; gap: 6px; align-items: center; width: 100%; }
.pseudo-edit input {
  flex: 1; background: var(--bg); border: 1.5px solid var(--accent);
  border-radius: 8px; color: var(--text);
  padding: 7px 12px; font-size: 14px;
  outline: none; min-width: 0; font-family: inherit;
  box-shadow: 0 0 0 3px var(--accent-glow);
}
.pseudo-edit input:focus { border-color: var(--accent); }
.pseudo-edit button { background: none; border: none; cursor: pointer; padding: 4px 8px; border-radius: 6px; font-size: 13px; font-weight: 600; font-family: inherit; white-space: nowrap; }
#pseudo-save { color: var(--green); }
#pseudo-cancel { color: var(--red); }

.sidebar-sections { flex: 1; display: flex; flex-direction: column; overflow: hidden; }
.sidebar-section { overflow-y: auto; padding: 8px 0; }
.sidebar-section.channels-section { flex: 1; border-top: 1px solid var(--border); }

.section-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 6px 16px;
  font-size: 10px; font-weight: 700; letter-spacing: 0.12em;
  color: var(--muted); text-transform: uppercase;
}
.btn-icon {
  background: none; border: none; color: var(--muted);
  cursor: pointer; font-size: 16px;
  position: relative; display: inline-flex; align-items: center; gap: 6px;
  width: 22px; height: 22px;
  display: flex; align-items: center; justify-content: center;
  border-radius: 6px; transition: all 0.15s; line-height: 1;
}
.btn-icon:hover { color: var(--accent); background: var(--hover); }
.wall-badge {
  background: var(--red); color: #fff;
  font-size: 10px; font-weight: 700;
  min-width: 18px; height: 18px; padding: 0 4px;
  border-radius: 9px; display: inline-flex; align-items: center; justify-content: center;
  animation: badgePop 0.25s ease;
}
@keyframes badgePop { from { transform: scale(0); } to { transform: scale(1); } }

.user-item {
  display: flex; align-items: center; gap: 8px;
  padding: 5px 10px;
  cursor: pointer; border-radius: 8px;
  margin: 1px 8px;
  transition: background 0.12s;
}
.user-item:hover { background: var(--hover); }
.user-item.me { cursor: default; }
.user-item.me:hover { background: transparent; }
.user-name { font-size: 13px; color: var(--text2); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; flex: 1; }
.user-item.me .user-name { color: var(--text); font-weight: 500; }
.status-dot { width: 6px; height: 6px; border-radius: 50%; background: var(--green); flex-shrink: 0; box-shadow: 0 0 5px var(--green); }
.dm-unread {
  background: var(--accent); color: white;
  font-size: 10px; padding: 1px 6px;
  border-radius: 10px; font-weight: 700;
  min-width: 18px; text-align: center;
}

.channel-item {
  display: flex; flex-direction: column;
  margin: 1px 8px;
  cursor: pointer; border-radius: 8px;
  border: 1px solid transparent;
  transition: background 0.12s, border-color 0.12s;
}
.channel-item:hover > .channel-item-main { background: var(--hover); border-radius: 7px; }
.channel-item.active { border-color: rgba(124,106,247,0.3); }
.channel-item.active > .channel-item-main {
  background: linear-gradient(135deg, rgba(124,106,247,0.15), rgba(124,106,247,0.06));
  border-radius: 7px;
}
.channel-item.active .channel-name { color: var(--accent); font-weight: 600; }
.channel-item-main {
  display: flex; align-items: center; gap: 8px;
  padding: 6px 10px;
}
.channel-prefix { color: var(--muted); font-size: 15px; flex-shrink: 0; line-height: 1; }
.channel-name { font-size: 13px; color: var(--text2); flex: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.channel-lock { font-size: 11px; }

/* ── Main content ── */
#content { flex: 1; display: flex; flex-direction: column; overflow: hidden; background: var(--bg); min-width: 0; }

/* ── Tab bar ── */
#tab-bar {
  height: 48px; min-height: 48px;
  border-bottom: 1px solid var(--border);
  background: var(--bg2);
  display: flex; align-items: center;
  padding: 0 12px; overflow-x: auto; gap: 4px;
  flex-shrink: 0;
}
/* Hamburger toggle button */
#btn-sidebar-toggle {
  display: flex; flex-direction: column; justify-content: center; align-items: center;
  width: 34px; height: 34px; border-radius: 8px; flex-shrink: 0;
  background: transparent; border: none; cursor: pointer;
  gap: 4px; padding: 6px; margin-right: 4px;
  transition: background 0.15s;
}
#btn-sidebar-toggle:hover { background: var(--hover); }
.hamburger-icon,
.hamburger-icon::before,
.hamburger-icon::after {
  display: block; width: 18px; height: 2px;
  background: var(--text2); border-radius: 2px;
  transition: transform 0.25s, opacity 0.25s;
}
.hamburger-icon { position: relative; }
.hamburger-icon::before { content:''; position: absolute; top: -5px; left: 0; }
.hamburger-icon::after  { content:''; position: absolute; bottom: -5px; left: 0; }
/* Animate to × when open (sidebar not collapsed on mobile) */
#main-ui.sidebar-mobile-open .hamburger-icon { background: transparent; }
#main-ui.sidebar-mobile-open .hamburger-icon::before { transform: translateY(5px) rotate(45deg); background: var(--text); }
#main-ui.sidebar-mobile-open .hamburger-icon::after  { transform: translateY(-5px) rotate(-45deg); background: var(--text); }
#tab-bar::-webkit-scrollbar { height: 2px; }
#tab-bar::-webkit-scrollbar-thumb { background: var(--border); }
#tabs-container { display: flex; gap: 4px; align-items: center; }
.tab {
  display: flex; align-items: center; gap: 6px;
  padding: 6px 12px; border-radius: 8px;
  cursor: pointer; font-size: 13px; font-weight: 500;
  color: var(--text2); white-space: nowrap;
  transition: all 0.15s;
}
.tab:hover { background: var(--hover); color: var(--text); }
.tab.active {
  background: var(--bg3); color: var(--text);
  box-shadow: inset 0 0 0 1px var(--border2);
}
.tab-close { font-size: 14px; color: var(--muted); margin-left: 2px; opacity: 0; transition: opacity 0.1s; line-height: 1; }
.tab:hover .tab-close { opacity: 1; }
.tab-close:hover { color: var(--red); }

/* ── Content header ── */
#content-header { border-bottom: 1px solid var(--border); background: var(--bg2); flex-shrink: 0; }
.ch-wall { padding: 12px 20px; display: flex; align-items: center; justify-content: space-between; }
.ch-title { font-weight: 700; font-size: 15px; display: flex; align-items: center; gap: 8px; letter-spacing: -0.2px; }
.ch-sub { font-size: 12px; color: var(--text2); font-weight: 400; }
.ch-channel { padding: 12px 20px; display: flex; align-items: center; gap: 10px; }
.ch-channel-name { font-weight: 700; flex: 1; font-size: 15px; letter-spacing: -0.2px; }
.ch-members { font-size: 12px; color: var(--text2); }
.btn-leave {
  background: none; border: 1px solid var(--border);
  color: var(--text2); padding: 5px 13px;
  border-radius: 8px; font-size: 12px; font-weight: 500;
  cursor: pointer; transition: all 0.15s;
}
.btn-leave:hover { border-color: var(--red); color: var(--red); background: rgba(255,85,114,0.07); }
.btn-del-chan {
  background: none; border: 1px solid rgba(255,85,114,0.3);
  color: var(--red); padding: 5px 13px;
  border-radius: 8px; font-size: 12px; font-weight: 500;
  cursor: pointer; transition: all 0.15s; margin-left: 6px;
}
.btn-del-chan:hover { background: var(--red); color: white; border-color: var(--red); }
.ch-dm { padding: 12px 20px; display: flex; align-items: center; gap: 10px; }
.ch-dm-name { font-weight: 700; font-size: 15px; letter-spacing: -0.2px; }
.ch-dm-status { font-size: 12px; color: var(--green); font-weight: 500; }

/* ── Messages ── */
#messages-area {
  flex: 1; overflow-y: auto;
  padding: 20px;
  display: flex; flex-direction: column; gap: 8px;
}
.msgs-empty {
  flex: 1; display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  color: var(--muted); gap: 12px;
}
.msgs-empty-icon { font-size: 40px; opacity: 0.4; }
.msgs-empty-text { font-size: 14px; font-weight: 500; }

.msg-card {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 12px 14px;
  position: relative;
  transition: all 0.15s;
  animation: fadeUp 0.2s ease;
}
.msg-card:hover { border-color: var(--border2); background: var(--bg3); }
.msg-card.mine {
  border-color: rgba(124,106,247,0.28);
  background: rgba(124,106,247,0.05);
}
.msg-card.mine:hover {
  border-color: rgba(124,106,247,0.42);
  background: rgba(124,106,247,0.09);
}
@keyframes fadeUp { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: translateY(0); } }

.msg-header { display: flex; align-items: center; gap: 8px; margin-bottom: 6px; }
.msg-author { font-weight: 600; font-size: 13px; }
.msg-time { font-size: 11px; color: var(--muted); flex: 1; }
.msg-expiry {
  display: flex; align-items: center; gap: 3px;
  font-size: 11px; padding: 2px 9px;
  border-radius: 12px; font-weight: 600;
}
.msg-expiry.ok { color: var(--green); background: rgba(61,214,140,0.1); }
.msg-expiry.warn { color: var(--yellow); background: rgba(255,179,64,0.1); }
.msg-expiry.urgent { color: var(--red); background: rgba(255,85,114,0.1); animation: blink 1s ease infinite; }
@keyframes blink { 0%,100% { opacity: 1; } 50% { opacity: 0.5; } }

.msg-actions { display: flex; gap: 3px; opacity: 0; transition: opacity 0.15s; }
.msg-card:hover .msg-actions { opacity: 1; }
.msg-actions button {
  background: none; border: none; cursor: pointer;
  padding: 3px 8px; border-radius: 6px;
  font-size: 11px; color: var(--muted); font-weight: 500;
  transition: all 0.1s;
}
.msg-actions button:hover { background: var(--hover); color: var(--text); }
.msg-actions .btn-del:hover { color: var(--red); }
.msg-body { font-size: 14px; line-height: 1.65; word-break: break-word; }
.msg-img {
  max-width: 380px; max-height: 280px;
  border-radius: 10px; object-fit: cover;
  cursor: pointer; display: block; margin-top: 10px;
  transition: opacity 0.15s;
  box-shadow: 0 4px 18px rgba(0,0,0,0.3);
}
.msg-img:hover { opacity: 0.88; }
.msg-file {
  display: flex; align-items: center; gap: 10px;
  background: var(--bg3); border: 1px solid var(--border);
  border-radius: 10px; padding: 10px 14px;
  margin-top: 8px; max-width: 300px;
  transition: border-color 0.15s;
}
.msg-file:hover { border-color: var(--border2); }
.msg-file-icon { font-size: 22px; }
.msg-file-info { flex: 1; min-width: 0; }
.msg-file-name { font-size: 12px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.msg-file-size { font-size: 11px; color: var(--muted); margin-top: 1px; }

/* DM bubbles */
.dm-row { display: flex; gap: 10px; align-items: flex-end; animation: fadeUp 0.15s ease; margin-bottom: 6px; padding: 0 8px; }
.dm-row.sent { flex-direction: row-reverse; }
.dm-content { max-width: 72%; min-width: 60px; display: flex; flex-direction: column; }
.dm-row.sent .dm-content { align-items: flex-end; }
.dm-row.received .dm-content { align-items: flex-start; }
.dm-bubble {
  background: var(--bg3);
  border: 1px solid var(--border2);
  border-radius: 18px; padding: 10px 16px;
  font-size: 14px; line-height: 1.55;
  word-break: break-word; white-space: pre-wrap;
}
.dm-row.sent .dm-bubble {
  background: var(--accent); color: white;
  border-color: var(--accent);
  border-radius: 18px 18px 4px 18px;
  box-shadow: 0 3px 12px var(--accent-glow);
}
.dm-row.received .dm-bubble { border-radius: 18px 18px 18px 4px; }
.dm-ts { font-size: 10px; color: var(--muted); margin-top: 3px; padding: 0 4px; }
.dm-row.sent .dm-ts { text-align: right; }
.dm-img { max-width: 260px; max-height: 220px; border-radius: 12px; object-fit: cover; cursor: pointer; display: block; margin-top: 4px; }

/* Transfer progress */
.transfer-wrap { margin-top: 8px; }
.transfer-bar-bg { height: 3px; background: var(--hover); border-radius: 3px; overflow: hidden; }
.transfer-bar { height: 100%; background: var(--accent); border-radius: 3px; transition: width 0.2s; }
.transfer-label { font-size: 10px; color: var(--muted); margin-top: 3px; }

/* ── Composer ── */
#composer {
  border-top: 1px solid var(--border);
  background: var(--bg2);
  padding: 12px 16px;
  flex-shrink: 0;
}
.composer-toolbar { display: flex; align-items: center; margin-bottom: 10px; }
.expiry-label { font-size: 11px; color: var(--muted); margin-right: 10px; font-weight: 600; letter-spacing: 0.04em; text-transform: uppercase; }
.expiry-selector { display: flex; align-items: center; gap: 4px; }
.expiry-btn {
  background: var(--bg3); border: 1px solid var(--border);
  color: var(--text2); padding: 4px 12px;
  border-radius: 14px; font-size: 11px; font-weight: 600;
  cursor: pointer; transition: all 0.15s;
}
.expiry-btn:hover { border-color: var(--accent); color: var(--accent); }
.expiry-btn.active {
  background: rgba(124,106,247,0.14);
  border-color: var(--accent); color: var(--accent);
}
.composer-main {
  display: flex; align-items: flex-end; gap: 10px;
  background: var(--bg3);
  border: 1.5px solid var(--border);
  border-radius: var(--radius-xl);
  padding: 10px 10px 10px 14px;
  transition: border-color 0.2s, box-shadow 0.2s;
}
.composer-main:focus-within {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-glow);
}
.btn-attach {
  background: none; border: none; color: var(--muted);
  cursor: pointer; padding: 4px; border-radius: 6px;
  transition: color 0.15s; flex-shrink: 0;
  display: flex; align-items: center;
}
.btn-attach:hover { color: var(--accent); }
#message-input {
  flex: 1; background: none; border: none;
  color: var(--text); font-size: 14px;
  outline: none; resize: none;
  font-family: inherit; line-height: 1.5;
  max-height: 120px; overflow-y: auto;
}
#message-input::placeholder { color: var(--muted); }
.btn-send {
  background: var(--accent); border: none; color: white;
  width: 34px; height: 34px; border-radius: 10px;
  cursor: pointer; display: flex; align-items: center; justify-content: center;
  flex-shrink: 0; transition: all 0.15s;
  box-shadow: 0 2px 10px var(--accent-glow);
}
.btn-send:hover:not(:disabled) {
  background: var(--accent2);
  transform: scale(1.06);
  box-shadow: 0 4px 14px var(--accent-glow);
}
.btn-send:disabled {
  background: var(--hover); color: var(--muted);
  cursor: not-allowed; box-shadow: none;
}

#file-preview {
  margin-top: 10px; padding: 10px 12px;
  background: var(--bg3); border: 1px solid var(--border);
  border-radius: 12px;
  display: flex; align-items: center; gap: 10px;
}
#file-preview img { max-height: 56px; max-width: 72px; border-radius: 6px; object-fit: cover; }
.fp-info { flex: 1; min-width: 0; }
.fp-name { font-size: 12px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.fp-size { font-size: 11px; color: var(--muted); margin-top: 1px; }
.btn-rm-file { background: none; border: none; color: var(--muted); cursor: pointer; font-size: 17px; padding: 2px 4px; line-height: 1; transition: color 0.15s; }
.btn-rm-file:hover { color: var(--red); }

/* ── Modals ── */
#modal-overlay {
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.78);
  display: flex; align-items: center; justify-content: center;
  z-index: 100;
  backdrop-filter: blur(10px);
}
.modal {
  background: var(--bg2);
  border: 1px solid var(--border2);
  border-radius: 20px;
  padding: 24px 26px;
  width: 400px; max-width: 92vw;
  animation: modalIn 0.2s cubic-bezier(0.34, 1.56, 0.64, 1);
  box-shadow: 0 24px 64px rgba(0,0,0,0.55), 0 0 0 1px rgba(255,255,255,0.04);
}
@keyframes modalIn { from { opacity: 0; transform: scale(0.9) translateY(-12px); } to { opacity: 1; transform: scale(1) translateY(0); } }
.modal-title { font-size: 18px; font-weight: 700; margin-bottom: 18px; letter-spacing: -0.3px; }
.modal-body { display: flex; flex-direction: column; gap: 14px; }
.form-group { display: flex; flex-direction: column; gap: 6px; }
.form-label { font-size: 11px; font-weight: 700; color: var(--text2); text-transform: uppercase; letter-spacing: 0.08em; }
.form-input {
  background: var(--bg3);
  border: 1.5px solid var(--border);
  border-radius: 10px; color: var(--text);
  padding: 10px 13px; font-size: 14px;
  outline: none; transition: all 0.15s;
  font-family: inherit;
}
.form-input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-glow); }
.form-hint { font-size: 11px; color: var(--muted); }
.form-error { font-size: 12px; color: var(--red); font-weight: 500; }
.modal-actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 18px; }
.btn {
  padding: 9px 18px; border-radius: 10px;
  font-size: 13px; font-weight: 600;
  cursor: pointer; transition: all 0.15s;
  border: none; font-family: inherit;
  letter-spacing: 0.01em;
}
.btn-primary {
  background: var(--accent); color: white;
  box-shadow: 0 2px 10px var(--accent-glow);
}
.btn-primary:hover {
  background: var(--accent2);
  box-shadow: 0 4px 14px var(--accent-glow);
  transform: translateY(-1px);
}
.btn-secondary {
  background: var(--bg3); color: var(--text2);
  border: 1px solid var(--border2);
}
.btn-secondary:hover { border-color: var(--text2); color: var(--text); background: var(--hover); }
.btn-danger { background: var(--red); color: white; }
.btn-danger:hover { opacity: 0.85; transform: translateY(-1px); }

/* ── Toasts ── */
#toast-container {
  position: fixed; bottom: 20px; right: 20px;
  display: flex; flex-direction: column; gap: 8px;
  z-index: 999; pointer-events: none;
}
.toast {
  background: var(--bg2);
  border: 1px solid var(--border2);
  border-radius: 12px; padding: 12px 16px;
  font-size: 13px; font-weight: 500;
  display: flex; align-items: center; gap: 8px;
  max-width: 320px;
  animation: slideR 0.25s ease, fadeOut 0.3s ease 2.7s forwards;
  box-shadow: 0 8px 28px rgba(0,0,0,0.45), 0 0 0 1px rgba(255,255,255,0.04);
}
.toast.success { border-left: 3px solid var(--green); }
.toast.error { border-left: 3px solid var(--red); }
.toast.info { border-left: 3px solid var(--accent); }
@keyframes slideR { from { opacity: 0; transform: translateX(80px); } to { opacity: 1; transform: translateX(0); } }
@keyframes fadeOut { from { opacity: 1; } to { opacity: 0; } }

/* ── Lightbox ── */
#lightbox {
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.95);
  display: flex; align-items: center; justify-content: center;
  z-index: 200; cursor: zoom-out;
  backdrop-filter: blur(12px);
}
#lightbox img {
  max-width: 92vw; max-height: 92vh;
  border-radius: 12px; object-fit: contain;
  box-shadow: 0 24px 60px rgba(0,0,0,0.6);
}

/* ── Visibility toggle ── */
.btn-visibility {
  background: none; border: 1px solid var(--border);
  color: var(--text2); cursor: pointer;
  font-size: 11px; font-weight: 500; padding: 3px 10px;
  border-radius: 12px; margin-top: 3px;
  transition: all 0.15s;
}
.btn-visibility:hover { border-color: var(--accent); color: var(--accent); background: rgba(124,106,247,0.08); }
.btn-visibility.visibility-off { border-color: var(--muted); color: var(--muted); opacity: 0.65; }

/* ── Media in messages ── */
.msg-video {
  max-width: 400px; width: 100%;
  border-radius: 10px; display: block; margin-top: 8px;
  background: #000;
  box-shadow: 0 4px 18px rgba(0,0,0,0.3);
}
.msg-audio { width: 100%; max-width: 360px; display: block; margin-top: 8px; accent-color: var(--accent); }

/* ── CSV table ── */
.msg-csv-wrap { margin-top: 8px; }
.msg-csv-label { font-size: 12px; color: var(--text2); margin-bottom: 6px; display: flex; align-items: center; gap: 8px; font-weight: 500; }
.btn-dl-inline { color: var(--accent); text-decoration: none; font-size: 12px; font-weight: 600; }
.btn-dl-inline:hover { text-decoration: underline; }
.msg-csv-scroll { overflow-x: auto; max-height: 220px; border-radius: 8px; border: 1px solid var(--border); }
.msg-csv-table { border-collapse: collapse; font-size: 12px; min-width: 100%; }
.msg-csv-table th {
  background: var(--bg3); padding: 7px 12px;
  text-align: left; font-weight: 700;
  color: var(--text2); border-bottom: 1px solid var(--border);
  white-space: nowrap; position: sticky; top: 0;
}
.msg-csv-table td { padding: 6px 12px; border-bottom: 1px solid var(--border); color: var(--text); white-space: nowrap; }
.msg-csv-table tr:last-child td { border-bottom: none; }
.msg-csv-table tr:hover td { background: rgba(255,255,255,0.025); }

/* ── TXT preview ── */
.msg-txt-wrap { margin-top: 8px; }
.msg-txt {
  background: var(--bg3); border: 1px solid var(--border);
  border-radius: 8px; padding: 12px;
  font-size: 12px; line-height: 1.6; color: var(--text2);
  overflow-x: auto; max-height: 200px; overflow-y: auto;
  white-space: pre-wrap; word-break: break-word;
  font-family: 'JetBrains Mono', 'Fira Code', 'Courier New', monospace;
}

/* ── PDF / file download ── */
.btn-dl {
  color: var(--accent); text-decoration: none;
  font-size: 12px; font-weight: 600;
  padding: 4px 10px;
  border: 1px solid rgba(124,106,247,0.4);
  border-radius: 7px; white-space: nowrap;
  transition: all 0.15s;
}
.btn-dl:hover { background: var(--accent); color: white; border-color: var(--accent); }

/* ── Channel header extras ── */
.badge-readonly {
  font-size: 11px; font-weight: 600;
  background: rgba(255,179,64,0.12); color: var(--yellow);
  padding: 3px 10px; border-radius: 12px;
}
.ch-max { font-size: 12px; color: var(--muted); }
.btn-settings {
  background: none; border: 1px solid var(--border);
  color: var(--text2); padding: 5px 10px;
  border-radius: 8px; font-size: 14px;
  cursor: pointer; transition: all 0.15s;
}
.btn-settings:hover { border-color: var(--accent); color: var(--accent); background: rgba(124,106,247,0.08); }

/* ── Channel header with inline members ── */
.ch-channel { padding: 10px 20px 0; display: flex; flex-direction: column; gap: 0; }
.ch-channel-top { display: flex; align-items: center; gap: 8px; padding-bottom: 8px; flex-wrap: wrap; }
.ch-channel-name { font-weight: 700; font-size: 15px; letter-spacing: -0.2px; }
.ch-member-count { font-size: 12px; color: var(--muted); margin-right: auto; }
.ch-actions { display: flex; align-items: center; gap: 6px; }

/* ── Sidebar channel item — actions + members ── */
.channel-item-actions {
  display: flex; flex-wrap: wrap; gap: 4px;
  padding: 2px 10px 6px;
}
.ch-action-btn {
  background: var(--bg3); border: 1px solid var(--border);
  color: var(--text2); font-size: 11px; border-radius: 6px;
  padding: 3px 8px; cursor: pointer;
  transition: all 0.12s;
}
.ch-action-btn:hover { background: var(--hover); border-color: var(--border2); color: var(--text); }
.ch-action-btn.leave { border-color: rgba(255,85,114,0.3); color: var(--red); }
.ch-action-btn.leave:hover { background: rgba(255,85,114,0.12); border-color: var(--red); }
.ch-action-btn.delete { border-color: rgba(255,85,114,0.3); color: var(--red); }
.ch-action-btn.delete:hover { background: rgba(255,85,114,0.12); border-color: var(--red); }
.ch-action-btn.disabled { opacity: 0.45; cursor: not-allowed; }

.channel-item-members {
  display: flex; flex-direction: column; gap: 1px;
  padding: 4px 8px 8px;
  border-top: 1px solid rgba(124,106,247,0.12);
  margin: 0 4px;
}
.ch-sidebar-member {
  display: flex; align-items: center; gap: 7px;
  padding: 4px 6px; border-radius: 6px;
  cursor: pointer; font-size: 12px; color: var(--text2);
  transition: all 0.1s;
}
.ch-sidebar-member:hover { background: rgba(124,106,247,0.1); color: var(--accent); }
.ch-sidebar-member.me { cursor: default; color: var(--text); font-weight: 500; }
.ch-sidebar-member.me:hover { background: transparent; color: var(--text); }
.ch-sidebar-member-name { flex: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ch-sidebar-me { color: var(--muted); font-weight: 400; font-size: 10px; }

/* ── Simplified channel header ── */
.ch-channel-simple {
  display: flex; align-items: center; gap: 8px;
  padding: 12px 20px;
}
.ch-channel-simple .ch-channel-name { font-weight: 700; font-size: 15px; letter-spacing: -0.2px; }
}
.ch-member-chip {
  display: flex; align-items: center; gap: 5px;
  background: var(--bg3); border: 1px solid var(--border);
  border-radius: 20px; padding: 3px 10px 3px 3px;
  font-size: 12px; transition: border-color 0.12s;
  cursor: default;
}
.ch-member-chip:hover { border-color: var(--border2); }
.ch-member-chip.me { border-color: rgba(124,106,247,0.35); background: rgba(124,106,247,0.08); }
.ch-chip-name { color: var(--text2); white-space: nowrap; }
.ch-member-chip.me .ch-chip-name { color: var(--text); font-weight: 600; }
.ch-chip-me { color: var(--muted); font-weight: 400; font-size: 11px; }
.ch-chip-dot { width: 6px; height: 6px; border-radius: 50%; flex-shrink: 0; }
.ch-chip-dot.owner { background: var(--accent); box-shadow: 0 0 4px var(--accent-glow); }
.ch-chip-dot.admin { background: #a78bfa; }

/* ── Members panel — hidden, kept for DOM ── */
#members-panel { display: none !important; }

/* ── Channel settings modal ── */
.settings-section { background: var(--bg3); border-radius: 10px; padding: 14px 16px; border: 1px solid var(--border); }
.settings-title { font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.08em; color: var(--muted); margin-bottom: 10px; }
.members-list { display: flex; flex-direction: column; gap: 6px; max-height: 260px; overflow-y: auto; }
.member-row {
  display: flex; align-items: center; gap: 8px;
  padding: 8px 10px; border-radius: 8px;
  background: var(--bg4);
  border: 1px solid var(--border);
  transition: border-color 0.15s;
}
.member-row:hover { border-color: var(--border2); }
.member-name { flex: 1; font-size: 13px; font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.role-badge { font-size: 10px; padding: 2px 8px; border-radius: 8px; font-weight: 700; white-space: nowrap; letter-spacing: 0.04em; }
.role-badge.owner { background: rgba(124,106,247,0.15); color: var(--accent); }
.role-badge.admin { background: rgba(167,139,250,0.15); color: #a78bfa; }
.btn-kick {
  background: none; border: 1px solid rgba(255,85,114,0.3);
  color: var(--red); font-size: 11px; font-weight: 600;
  padding: 3px 10px; border-radius: 7px;
  cursor: pointer; transition: all 0.15s; white-space: nowrap;
}
.btn-kick:hover { background: var(--red); color: white; border-color: var(--red); }

/* ── Members panel ── */
#members-panel {
  width: 220px; min-width: 220px;
  background: var(--bg2);
  border-left: 1px solid var(--border);
  display: flex; flex-direction: column; gap: 12px;
  padding: 16px; overflow-y: auto;
}
.mp-title { font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.12em; color: var(--muted); }

/* ── Link preview ── */
.msg-link { color: var(--accent); text-decoration: none; word-break: break-all; }
.msg-link:hover { text-decoration: underline; }

.link-preview {
  display: flex; align-items: stretch;
  margin-top: 10px; max-width: 460px;
  border: 1px solid var(--border);
  border-left: 3px solid var(--accent);
  border-radius: 10px; overflow: hidden;
  text-decoration: none; color: inherit;
  transition: border-color 0.15s, background 0.15s;
  background: var(--bg3);
}
.link-preview:hover { border-color: var(--accent); background: var(--hover); }

.lp-img {
  width: 110px; min-height: 80px;
  object-fit: cover; flex-shrink: 0;
  border-right: 1px solid var(--border);
}
.lp-info {
  padding: 10px 12px;
  display: flex; flex-direction: column; gap: 3px;
  flex: 1; min-width: 0;
}
.lp-site { font-size: 10px; color: var(--accent); text-transform: uppercase; letter-spacing: 0.07em; font-weight: 700; }
.lp-title { font-size: 13px; font-weight: 600; color: var(--text); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.lp-desc { font-size: 12px; color: var(--text2); line-height: 1.4; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.lp-url { font-size: 11px; color: var(--muted); margin-top: 2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.link-preview-yt {
  display: block;
  border-left: 3px solid #ff0000;
  max-width: 480px; aspect-ratio: 16/9;
  padding: 0;
}
.link-preview-yt iframe { width: 100%; height: 100%; display: block; border: none; }

/* ── Share button states ── */
.btn-share { background: none; border: 1px solid var(--border); color: var(--text2); padding: 5px 10px; border-radius: 8px; font-size: 13px; cursor: pointer; transition: all 0.15s; }
.btn-share:hover { border-color: var(--accent); color: var(--accent); background: rgba(124,106,247,0.08); }
.btn-share-locked { opacity: 0.35; cursor: not-allowed !important; }
.btn-share-locked:hover { border-color: var(--border) !important; color: var(--text2) !important; background: none !important; }

/* ── Channel owner badge ── */
.channel-owner-badge {
  font-size: 11px;
  color: var(--yellow);
  opacity: 0.85;
  line-height: 1;
  flex-shrink: 0;
  filter: drop-shadow(0 0 3px rgba(255,179,64,0.4));
}
.chan-member-count {
  font-size: 10px; color: var(--muted);
  margin-left: auto; flex-shrink: 0;
  white-space: nowrap;
}

/* ── Clickable member chip ── */
.ch-member-chip.clickable { cursor: pointer; }
.ch-member-chip.clickable:hover {
  border-color: var(--accent);
  background: rgba(124,106,247,0.12);
  transform: translateY(-1px);
  box-shadow: 0 2px 8px var(--accent-glow);
}
.ch-member-chip.clickable:hover .ch-chip-name { color: var(--accent); }

/* ── Responsive Sidebar ── */
@media (max-width: 700px) {
  #sidebar {
    position: fixed; left: 0; top: 0; bottom: 0;
    transform: translateX(-100%);
    width: var(--sidebar) !important; min-width: var(--sidebar) !important;
    transition: transform 0.3s cubic-bezier(0.4,0,0.2,1);
    border-right: 1px solid var(--border) !important;
    z-index: 10;
  }
  #sidebar.collapsed { transform: translateX(-100%); }
  #main-ui.sidebar-mobile-open #sidebar { transform: translateX(0); }
  #main-ui.sidebar-mobile-open #sidebar-backdrop { display: block; }
  #content { width: 100%; }
}
