* { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg-base: #0a0a1a;
  --glass-bg: rgba(255,255,255,0.08);
  --glass-bg-strong: rgba(255,255,255,0.14);
  --glass-border: rgba(255,255,255,0.18);
  --glass-shadow: 0 8px 32px rgba(0,0,0,0.3);
  --glass-blur: 28px;
  --text-primary: #ffffff;
  --text-secondary: rgba(255,255,255,0.75);
  --text-muted: rgba(255,255,255,0.45);
  --accent: #5865f2;
  --accent-hover: #4752c4;
  --bubble-out: rgba(88,101,242,0.75);
  --bubble-in: rgba(255,255,255,0.12);
  --online: #57f287;
  --danger: #ed4245;
  --radius: 20px;
}

[data-theme="light"] {
  --bg-base: #eef1ff;
  --glass-bg: rgba(255,255,255,0.55);
  --glass-bg-strong: rgba(255,255,255,0.75);
  --glass-border: rgba(255,255,255,0.85);
  --glass-shadow: 0 8px 32px rgba(80,80,150,0.12);
  --text-primary: #171a2b;
  --text-secondary: rgba(20,20,50,0.7);
  --text-muted: rgba(20,20,50,0.45);
  --bubble-out: rgba(88,101,242,0.9);
  --bubble-in: rgba(255,255,255,0.85);
}

html, body {
  height: 100%;
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Display", "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
  color: var(--text-primary);
  overflow: hidden;
  background: var(--bg-base);
}

body::before {
  content: "";
  position: fixed; inset: -20%;
  background:
    radial-gradient(circle at 20% 30%, #5865f2 0%, transparent 35%),
    radial-gradient(circle at 80% 70%, #eb459e 0%, transparent 35%),
    radial-gradient(circle at 50% 50%, #57f287 0%, transparent 40%),
    radial-gradient(circle at 75% 15%, #f093fb 0%, transparent 35%),
    radial-gradient(circle at 15% 80%, #4facfe 0%, transparent 35%);
  filter: blur(60px);
  opacity: 0.55;
  z-index: -2;
  animation: bgShift 24s ease-in-out infinite;
}
[data-theme="light"] body::before { opacity: 0.35; }

@keyframes bgShift {
  0%,100% { transform: translate(0,0) scale(1); }
  33% { transform: translate(3%, -2%) scale(1.05); }
  66% { transform: translate(-2%, 3%) scale(0.98); }
}

/* Частицы на страницах авторизации */
#particles {
  position: fixed;
  inset: 0;
  z-index: -1;
  pointer-events: none;
  display: block;
}

.glass {
  background: var(--glass-bg);
  backdrop-filter: blur(var(--glass-blur)) saturate(180%);
  -webkit-backdrop-filter: blur(var(--glass-blur)) saturate(180%);
  border: 1px solid var(--glass-border);
  border-radius: var(--radius);
  box-shadow: var(--glass-shadow);
}

/* Авторизация */
.auth-page {
  height: 100vh;
  display: grid;
  place-items: center;
  padding: 20px;
  position: relative;
  z-index: 1;
}
.auth-card {
  width: min(420px, 100%);
  padding: 40px 32px;
  position: relative;
  z-index: 2;
}
.auth-card h1 { font-size: 26px; margin-bottom: 8px; text-align: center; }
.auth-card .sub { text-align: center; color: var(--text-secondary); font-size: 14px; margin-bottom: 28px; }
.field { margin-bottom: 14px; }
.field label {
  display: block; font-size: 12px; color: var(--text-secondary);
  margin-bottom: 6px; padding-left: 4px;
}
input[type="text"], input[type="password"], input[type="email"] {
  width: 100%; padding: 13px 16px;
  background: var(--glass-bg); border: 1px solid var(--glass-border);
  border-radius: 14px; color: var(--text-primary);
  font-size: 15px; outline: none; transition: 0.2s;
  backdrop-filter: blur(10px);
}
input:focus { border-color: var(--accent); background: var(--glass-bg-strong); }
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  padding: 13px 20px; border-radius: 14px;
  font-size: 15px; font-weight: 500; cursor: pointer;
  transition: 0.2s; color: var(--text-primary);
  background: var(--glass-bg); border: 1px solid var(--glass-border);
}
.btn:hover { background: var(--glass-bg-strong); transform: translateY(-1px); }
.btn:active { transform: translateY(0); }
.btn-primary {
  background: linear-gradient(135deg, #5865f2, #7b5cf0);
  border: none; color: white;
  box-shadow: 0 8px 24px rgba(88,101,242,0.4);
}
.btn-primary:hover { background: linear-gradient(135deg, #4752c4, #6a4de0); }
.btn-full { width: 100%; }
.btn-danger { background: rgba(237,66,69,0.2); border-color: rgba(237,66,69,0.5); color: #ffb3b5; }
.btn-danger:hover { background: rgba(237,66,69,0.35); }
.auth-switch { text-align: center; margin-top: 18px; color: var(--text-secondary); font-size: 14px; }
.auth-switch a { color: var(--accent); text-decoration: none; font-weight: 500; }
.error-box {
  background: rgba(237,66,69,0.15);
  border: 1px solid rgba(237,66,69,0.4);
  color: #ffb3b5;
  padding: 10px 14px; border-radius: 12px; font-size: 13px;
  margin-bottom: 14px; display: none;
}

/* Layout */
.app {
  display: grid; grid-template-columns: 340px 1fr;
  height: 100vh; padding: 14px; gap: 14px;
  position: relative; z-index: 1;
}

.sidebar { display: flex; flex-direction: column; overflow: hidden; }

.sidebar-header {
  padding: 16px; display: flex; align-items: center; gap: 12px;
  border-bottom: 1px solid var(--glass-border);
}
.me {
  display: flex; align-items: center; gap: 12px; flex: 1;
  cursor: pointer; padding: 6px; border-radius: 14px; transition: 0.2s;
}
.me:hover { background: var(--glass-bg); }
.avatar {
  width: 42px; height: 42px; border-radius: 50%;
  display: grid; place-items: center;
  font-weight: 600; font-size: 17px; color: white;
  flex-shrink: 0; position: relative;
}
.avatar.lg { width: 120px; height: 120px; font-size: 46px; }
.avatar.xl { width: 140px; height: 140px; font-size: 54px; }
.avatar .dot {
  position: absolute; bottom: 2px; right: 2px;
  width: 14px; height: 14px; border-radius: 50%;
  background: var(--online);
  border: 3px solid rgba(10,10,26,0.9);
  display: none;
}
.avatar.online .dot { display: block; }
[data-theme="light"] .avatar .dot { border-color: white; }

.me-name { font-weight: 600; font-size: 15px; }
.me-username { font-size: 12px; color: var(--text-muted); }

.icon-btn {
  background: transparent; border: none;
  color: var(--text-secondary); width: 38px; height: 38px;
  border-radius: 12px; cursor: pointer;
  display: grid; place-items: center; font-size: 18px; transition: 0.2s;
}
.icon-btn:hover { background: var(--glass-bg); color: var(--text-primary); }

.chat-list { flex: 1; overflow-y: auto; padding: 10px; }
.chat-list::-webkit-scrollbar { width: 6px; }
.chat-list::-webkit-scrollbar-thumb { background: var(--glass-border); border-radius: 3px; }

.chat-item {
  display: flex; align-items: center; gap: 12px;
  padding: 12px; border-radius: 16px; cursor: pointer;
  transition: 0.15s; margin-bottom: 4px;
}
.chat-item:hover { background: var(--glass-bg); }
.chat-item.active { background: var(--glass-bg-strong); }
.chat-item .info { flex: 1; min-width: 0; }
.chat-item .name {
  font-weight: 500; font-size: 14px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.chat-item .preview {
  font-size: 12px; color: var(--text-muted);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  margin-top: 2px;
}
.chat-item .badge {
  background: var(--accent); color: white;
  font-size: 11px; min-width: 20px; height: 20px;
  padding: 0 6px; border-radius: 10px;
  display: grid; place-items: center; font-weight: 600;
}

.new-chat-btn {
  margin: 12px; padding: 12px; border-radius: 14px;
  background: var(--glass-bg-strong);
  border: 1px solid var(--glass-border);
  color: var(--text-primary); cursor: pointer;
  font-size: 14px; font-weight: 500; transition: 0.2s;
  display: flex; align-items: center; justify-content: center; gap: 8px;
}
.new-chat-btn:hover { background: var(--accent); border-color: var(--accent); }

/* Область чата */
.chat-view { display: flex; flex-direction: column; overflow: hidden; }
.chat-header {
  padding: 14px 20px;
  border-bottom: 1px solid var(--glass-border);
  display: flex; align-items: center; gap: 14px; min-height: 72px;
}
.chat-header .info { flex: 1; cursor: pointer; }
.chat-header .name { font-weight: 600; font-size: 16px; }
.chat-header .status { font-size: 13px; color: var(--text-muted); margin-top: 2px; }
.chat-header .status.online { color: var(--online); }

.messages {
  flex: 1; overflow-y: auto; padding: 20px;
  display: flex; flex-direction: column; gap: 6px;
}
.messages::-webkit-scrollbar { width: 8px; }
.messages::-webkit-scrollbar-thumb { background: var(--glass-border); border-radius: 4px; }

.msg {
  max-width: 62%;
  padding: 10px 14px;
  border-radius: 18px;
  font-size: 14.5px;
  line-height: 1.4;
  word-wrap: break-word;
  position: relative;
}
.msg.out {
  align-self: flex-end;
  background: var(--bubble-out);
  border-bottom-right-radius: 6px;
  color: white;
}
.msg.in {
  align-self: flex-start;
  background: var(--bubble-in);
  border-bottom-left-radius: 6px;
  border: 1px solid var(--glass-border);
}
.msg .meta {
  font-size: 10.5px;
  margin-top: 4px;
  opacity: 0.75;
  text-align: right;
}

/* Заблокированная панель */
.blocked-bar {
  padding: 12px 20px;
  border-top: 1px solid var(--glass-border);
  color: var(--text-secondary);
  font-size: 14px;
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}
.blocked-bar .btn { padding: 8px 14px; font-size: 13px; }

.input-area {
  padding: 14px 18px;
  border-top: 1px solid var(--glass-border);
  display: flex; gap: 10px; align-items: center;
}
.input-area input {
  flex: 1;
  background: var(--glass-bg);
  border: 1px solid var(--glass-border);
  border-radius: 22px;
  padding: 12px 18px;
  color: var(--text-primary);
  font-size: 14.5px;
  outline: none;
}
.input-area input:focus { border-color: var(--accent); }
.input-area .attach-btn { font-size: 20px; flex-shrink: 0; }
.send-btn {
  width: 44px; height: 44px; border-radius: 50%;
  border: none; background: linear-gradient(135deg, #5865f2, #7b5cf0);
  color: white; cursor: pointer; font-size: 18px;
  display: grid; place-items: center; transition: 0.2s;
  box-shadow: 0 4px 14px rgba(88,101,242,0.4);
}
.send-btn:hover { transform: scale(1.05); }
.send-btn:disabled { opacity: 0.4; cursor: not-allowed; }

.empty-state {
  flex: 1; display: grid; place-items: center;
  color: var(--text-muted); font-size: 15px;
  text-align: center; padding: 20px;
}

/* Модалки */
.modal-backdrop {
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.4);
  backdrop-filter: blur(8px);
  display: none; place-items: center; z-index: 100;
}
.modal-backdrop.show { display: grid; }
.modal {
  width: min(400px, 90%);
  padding: 26px;
  animation: modalIn 0.25s ease;
}
@keyframes modalIn {
  from { opacity: 0; transform: scale(0.96); }
  to { opacity: 1; transform: scale(1); }
}
.modal h2 { font-size: 19px; margin-bottom: 8px; }
.modal p { color: var(--text-secondary); font-size: 13px; margin-bottom: 18px; }
.modal-actions { display: flex; gap: 10px; margin-top: 16px; }

/* Настройки */
.settings-group { margin-bottom: 18px; }
.settings-label {
  font-size: 12px; color: var(--text-muted);
  margin-bottom: 8px; padding-left: 4px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}
.theme-picker { display: flex; gap: 10px; }
.theme-option {
  flex: 1;
  background: var(--glass-bg);
  border: 2px solid var(--glass-border);
  border-radius: 14px;
  padding: 10px;
  cursor: pointer;
  color: var(--text-primary);
  font-size: 13px;
  font-weight: 500;
  transition: 0.2s;
}
.theme-option:hover { background: var(--glass-bg-strong); }
.theme-option.active {
  border-color: var(--accent);
  background: var(--glass-bg-strong);
}
.theme-preview {
  height: 60px;
  border-radius: 10px;
  margin-bottom: 8px;
  border: 1px solid rgba(0,0,0,0.1);
}
.theme-preview.dark {
  background: linear-gradient(135deg, #0a0a1a 0%, #1a1a3a 100%);
}
.theme-preview.light {
  background: linear-gradient(135deg, #eef1ff 0%, #ffffff 100%);
}

/* Профиль */
.profile-page {
  min-height: 100vh;
  display: grid; place-items: center;
  padding: 20px;
  position: relative; z-index: 1;
}
.profile-card { width: min(480px, 100%); padding: 22px; }
.profile-topbar { display: flex; align-items: center; margin-bottom: 10px; }
.profile-hero { text-align: center; padding: 20px 0 24px; }
.profile-hero .avatar { margin: 0 auto 18px; }
.profile-hero h2 { font-size: 22px; margin-bottom: 6px; }
.profile-status {
  font-size: 13px;
  color: var(--text-muted);
  display: inline-flex;
  align-items: center;
  gap: 6px;
}
.profile-status.online { color: var(--online); }
.profile-status .dot {
  width: 8px; height: 8px; border-radius: 50%;
  background: var(--online); display: inline-block;
}
.profile-actions {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 10px;
  margin-bottom: 24px;
}
.action-tile {
  background: var(--glass-bg);
  border: 1px solid var(--glass-border);
  border-radius: 16px;
  padding: 14px 6px;
  display: flex; flex-direction: column; align-items: center; gap: 6px;
  cursor: pointer; transition: 0.2s;
  color: var(--text-primary); font-size: 12px;
}
.action-tile:hover { background: var(--glass-bg-strong); transform: translateY(-2px); }
.action-tile .ic { font-size: 20px; }
.action-tile:disabled { opacity: 0.5; cursor: not-allowed; }

.info-row {
  display: flex; justify-content: space-between;
  align-items: center; gap: 12px;
  padding: 14px 4px;
  border-bottom: 1px solid var(--glass-border);
}
.info-row:last-child { border-bottom: none; }
.info-row .label { font-size: 12px; color: var(--text-muted); margin-bottom: 3px; }
.info-row .value { font-size: 15px; color: var(--text-primary); text-decoration: none; }
.info-row a.value { color: var(--accent); }
.info-row a.value:hover { text-decoration: underline; }
.info-row .copy-btn {
  background: transparent; border: none;
  color: var(--text-muted); cursor: pointer;
  padding: 6px; border-radius: 8px; font-size: 14px;
}
.info-row .copy-btn:hover { background: var(--glass-bg); color: var(--text-primary); }

/* Админка */
.admin-page {
  padding: 30px;
  max-width: 1100px;
  margin: 0 auto;
  height: 100vh;
  overflow-y: auto;
  position: relative; z-index: 1;
}
.admin-page h1 { margin-bottom: 20px; }
.admin-table {
  width: 100%;
  border-collapse: collapse;
  overflow: hidden;
  border-radius: 16px;
}
.admin-table th, .admin-table td {
  padding: 12px 14px;
  text-align: left;
  font-size: 14px;
  border-bottom: 1px solid var(--glass-border);
}
.admin-table th {
  font-size: 12px;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}
.admin-table tr:last-child td { border-bottom: none; }

/* Вложения */
.msg-attach { margin: 4px 0; }
.msg-attach img,
.msg-attach video {
  display: block;
  max-width: 320px; max-height: 400px;
  width: auto; height: auto;
  border-radius: 12px; cursor: pointer;
  background: rgba(0,0,0,0.2);
}
.msg-attach video { cursor: default; }

.msg-file {
  display: flex; align-items: center; gap: 12px;
  padding: 10px 12px;
  border-radius: 12px;
  background: rgba(0,0,0,0.18);
  text-decoration: none; color: inherit;
  transition: 0.2s; min-width: 180px;
}
[data-theme="light"] .msg-file { background: rgba(0,0,0,0.06); }
.msg-file:hover { background: rgba(0,0,0,0.28); }
[data-theme="light"] .msg-file:hover { background: rgba(0,0,0,0.1); }
.msg-file .file-ic {
  width: 40px; height: 40px; border-radius: 10px;
  display: grid; place-items: center;
  background: rgba(255,255,255,0.14);
  font-size: 20px; flex-shrink: 0;
}
.msg-file .file-info { min-width: 0; }
.msg-file .file-name {
  font-size: 13.5px; font-weight: 500;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  max-width: 220px;
}
.msg-file .file-size { font-size: 11.5px; opacity: 0.7; margin-top: 2px; }
.msg-text + .msg-attach { margin-top: 6px; }

.messages.drag-over {
  outline: 2px dashed var(--accent);
  outline-offset: -10px;
  border-radius: 12px;
}

/* Верификация и бан */
.verified {
  display: inline-flex; align-items: center; justify-content: center;
  width: 16px; height: 16px;
  background: #1d9bf0; color: #fff;
  border-radius: 50%;
  font-size: 11px; font-weight: 700;
  margin-left: 4px;
  vertical-align: middle;
  box-shadow: 0 1px 4px rgba(29,155,240,0.5);
  line-height: 1;
}
.profile-status.banned { color: #7ecbff; font-weight: 500; }
.avatar.banned {
  filter: grayscale(1) brightness(0.7);
  opacity: 0.7;
}

@media (max-width: 780px) {
  .app { grid-template-columns: 1fr; padding: 8px; gap: 8px; }
  .sidebar { display: none; }
  .sidebar.mobile-show { display: flex; }
}
/* Картинка внутри круглого аватара */
.avatar { overflow: hidden; }
.avatar img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
  border-radius: 50%;
}
/* Внутри аватара с online-точкой — точка сверху */
.avatar.online img { filter: brightness(1); }
/* Загрузка аватара в профиле */
.avatar-edit {
  position: relative;
  width: 140px;
  height: 140px;
  margin: 0 auto 18px;
}
.avatar-edit .avatar { margin: 0; }
.avatar-edit-overlay {
  position: absolute;
  inset: 0;
  border-radius: 50%;
  background: rgba(0,0,0,0.55);
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  opacity: 0;
  transition: 0.2s;
  text-align: center;
  padding: 8px;
}
.avatar-edit:hover .avatar-edit-overlay { opacity: 1; }
.avatar-edit-actions {
  display: flex;
  gap: 8px;
  justify-content: center;
  margin-top: 10px;
}
.avatar-edit-actions .btn { padding: 8px 14px; font-size: 13px; }