:root {
  --bg: #f3f5f9;
  --panel: #ffffff;
  --border: #e3e7ef;
  --text: #1b2230;
  --muted: #7a8396;
  --accent: #2f6fed;
  --accent-hover: #2459c9;
  --accent-soft: #e8efff;
  --mine: #2f6fed;
  --mine-text: #ffffff;
  --theirs: #ffffff;
  --danger: #d6455d;
  --online: #2fb36b;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #12151c;
    --panel: #1a1f29;
    --border: #2a303d;
    --text: #e6e9f0;
    --muted: #8a93a6;
    --accent: #4d84f5;
    --accent-hover: #6a99f7;
    --accent-soft: #23304a;
    --mine: #3b6fe0;
    --theirs: #232a37;
  }
}
* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body { font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; background: var(--bg); color: var(--text); }
button, input, textarea { font: inherit; color: inherit; }
.hidden { display: none !important; }
.muted { color: var(--muted); font-size: 13px; }

/* Бренд */
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 24px; }
.brand.small { font-size: 18px; }
.logo { display: inline-grid; place-items: center; width: 36px; height: 36px; border-radius: 10px; background: var(--accent); color: #fff; font-weight: 800; }
.brand.small .logo { width: 30px; height: 30px; border-radius: 8px; font-size: 15px; }
.logo.big { width: 72px; height: 72px; font-size: 36px; border-radius: 20px; opacity: .9; }

/* Кнопки */
.btn { border: 1px solid var(--border); background: var(--panel); padding: 9px 16px; border-radius: 10px; cursor: pointer; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600; }
.btn.primary:hover { background: var(--accent-hover); }
.btn.danger { color: var(--danger); }
.icon-btn { border: 0; background: transparent; width: 36px; height: 36px; border-radius: 10px; cursor: pointer; font-size: 18px; color: var(--muted); }
.icon-btn:hover { background: var(--accent-soft); color: var(--accent); }

/* Авторизация */
.auth { min-height: 100%; display: grid; place-items: center; padding: 16px; }
.auth-card { width: 100%; max-width: 380px; background: var(--panel); border: 1px solid var(--border); border-radius: 18px; padding: 28px; box-shadow: 0 10px 40px rgba(0,0,0,.06); }
.tagline { color: var(--muted); margin: 6px 0 20px; }
.tabs { display: flex; background: var(--bg); border-radius: 10px; padding: 4px; margin-bottom: 18px; }
.tab { flex: 1; border: 0; background: transparent; padding: 8px; border-radius: 8px; cursor: pointer; color: var(--muted); }
.tab.active { background: var(--panel); color: var(--text); font-weight: 600; box-shadow: 0 1px 3px rgba(0,0,0,.08); }
.form { display: flex; flex-direction: column; gap: 12px; }
.form label { display: flex; flex-direction: column; gap: 5px; font-size: 13px; color: var(--muted); }
input, textarea { background: var(--bg); border: 1px solid var(--border); border-radius: 10px; padding: 10px 12px; outline: none; }
input:focus, textarea:focus { border-color: var(--accent); }
.form .btn { margin-top: 6px; padding: 11px; }
.error { color: var(--danger); min-height: 20px; margin-top: 12px; font-size: 14px; }

/* Раскладка */
.app { display: flex; height: 100%; }
.sidebar { width: 320px; flex-shrink: 0; background: var(--panel); border-right: 1px solid var(--border); display: flex; flex-direction: column; }
.side-head { display: flex; justify-content: space-between; align-items: center; padding: 14px 14px 10px; }
.side-tabs { display: flex; gap: 4px; padding: 0 14px; }
.side-tab { flex: 1; border: 0; background: transparent; padding: 8px; border-bottom: 2px solid transparent; cursor: pointer; color: var(--muted); }
.side-tab.active { color: var(--accent); border-color: var(--accent); font-weight: 600; }
.search { margin: 10px 14px; }
.list { list-style: none; margin: 0; padding: 0 6px; overflow-y: auto; flex: 1; }
.item { display: flex; gap: 10px; align-items: center; padding: 9px 10px; border-radius: 12px; cursor: pointer; }
.item:hover { background: var(--bg); }
.item.active { background: var(--accent-soft); }
.item-main { flex: 1; min-width: 0; }
.item-top { display: flex; justify-content: space-between; gap: 6px; }
.item-title { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.item-sub { color: var(--muted); font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.time { color: var(--muted); font-size: 12px; flex-shrink: 0; }
.badge { background: var(--accent); color: #fff; font-size: 12px; font-weight: 700; min-width: 20px; height: 20px; padding: 0 6px; border-radius: 10px; display: inline-grid; place-items: center; }

.avatar { position: relative; flex-shrink: 0; width: 40px; height: 40px; border-radius: 50%; display: grid; place-items: center; color: #fff; font-weight: 700; font-size: 15px; background-size: cover !important; background-position: center !important; }
.clickable { cursor: pointer; }
.avatar.group { border-radius: 12px; }
.avatar.online::after { content: ""; position: absolute; right: 0; bottom: 0; width: 11px; height: 11px; border-radius: 50%; background: var(--online); border: 2px solid var(--panel); }

.me { display: flex; align-items: center; gap: 10px; padding: 12px 14px; border-top: 1px solid var(--border); }
.me-profile { flex: 1; min-width: 0; display: flex; align-items: center; gap: 10px; cursor: pointer; border-radius: 12px; padding: 4px; margin: -4px; }
.me-profile:hover { background: var(--bg); }
.me-info { flex: 1; min-width: 0; }
#me-name { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* Чат */
.chat { flex: 1; min-width: 0; display: flex; }
.empty { flex: 1; display: grid; place-content: center; justify-items: center; color: var(--muted); gap: 6px; }
.chat-view { flex: 1; display: flex; flex-direction: column; min-width: 0; }
.chat-head { display: flex; align-items: center; gap: 10px; padding: 10px 16px; background: var(--panel); border-bottom: 1px solid var(--border); }
.chat-title-wrap { flex: 1; min-width: 0; }
.chat-title { font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.back { display: none; }
.messages { flex: 1; overflow-y: auto; padding: 16px; display: flex; flex-direction: column; gap: 4px; }
.day { align-self: center; color: var(--muted); font-size: 12px; background: var(--panel); border: 1px solid var(--border); border-radius: 20px; padding: 2px 10px; margin: 10px 0; }
.sys { align-self: center; color: var(--muted); font-size: 13px; margin: 4px 0; text-align: center; }
.msg { display: flex; gap: 8px; align-items: flex-end; max-width: 75%; }
.msg.mine { align-self: flex-end; flex-direction: row-reverse; }
.msg .avatar { width: 32px; height: 32px; font-size: 13px; }
.msg .avatar.spacer { visibility: hidden; }
.bubble { background: var(--theirs); border: 1px solid var(--border); padding: 7px 12px; border-radius: 16px 16px 16px 4px; white-space: pre-wrap; word-wrap: break-word; overflow-wrap: anywhere; }
.msg.mine .bubble { background: var(--mine); color: var(--mine-text); border-color: var(--mine); border-radius: 16px 16px 4px 16px; }
.author { font-size: 12px; font-weight: 700; color: var(--accent); margin-bottom: 2px; }
.stamp { font-size: 11px; opacity: .6; margin-left: 8px; float: right; margin-top: 6px; }
.composer { display: flex; gap: 10px; padding: 12px 16px; background: var(--panel); border-top: 1px solid var(--border); align-items: flex-end; }
.composer textarea { flex: 1; resize: none; max-height: 160px; }

/* Модалка */
.modal { position: fixed; inset: 0; background: rgba(10,14,22,.45); display: grid; place-items: center; padding: 16px; z-index: 10; }
.modal-card { width: 100%; max-width: 420px; max-height: 85vh; display: flex; flex-direction: column; background: var(--panel); border-radius: 16px; padding: 20px; border: 1px solid var(--border); }
.modal-card h3 { margin: 0 0 14px; }
#modal-body { overflow-y: auto; display: flex; flex-direction: column; gap: 10px; }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 16px; }
.check { display: flex; align-items: center; gap: 10px; padding: 6px; border-radius: 10px; cursor: pointer; }
.check:hover { background: var(--bg); }
.check input { width: 18px; height: 18px; }
.check .avatar { width: 32px; height: 32px; font-size: 13px; }

/* Поиск людей */
.people-search-wrap { position: relative; margin: 2px 14px 8px; }
.people-search { width: 100%; margin: 0; padding-right: 36px; }
.people-search-wrap .clear { position: absolute; right: 2px; top: 50%; transform: translateY(-50%); width: 32px; height: 32px; font-size: 14px; }
.sidebar.searching .side-tabs, .sidebar.searching #search, .sidebar.searching #chats-list, .sidebar.searching #channels-list { display: none !important; }
#people-results .btn.small { flex-shrink: 0; }
.list .section { padding: 10px 10px 4px; font-size: 12px; font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
.at-input { display: flex; align-items: center; background: var(--bg); border: 1px solid var(--border); border-radius: 10px; padding-left: 12px; }
.at-input:focus-within { border-color: var(--accent); }
.at-input .at { color: var(--muted); }
.at-input input { flex: 1; border: 0; background: transparent; padding-left: 2px; min-width: 0; }
.chat-username { color: var(--accent); font-weight: 600; }

/* Аватар канала в настройках */
.chat-avatar-edit { display: flex; align-items: center; gap: 12px; }
.chat-avatar-edit .avatar { width: 64px; height: 64px; font-size: 24px; }

/* Группы и каналы */
.kind { margin-right: 5px; font-size: 13px; }
.choice { display: flex; align-items: center; gap: 12px; width: 100%; text-align: left; padding: 12px; border: 1px solid var(--border); border-radius: 12px; background: var(--panel); cursor: pointer; }
.choice:hover { border-color: var(--accent); background: var(--accent-soft); }
.choice-icon { font-size: 26px; width: 44px; height: 44px; display: grid; place-items: center; border-radius: 12px; background: var(--bg); flex-shrink: 0; }
.choice .item-sub { white-space: normal; }
.msg.post { max-width: min(640px, 92%); }
.msg.post .bubble { border-radius: 14px; }
.channel-bar { display: flex; justify-content: center; align-items: center; padding: 12px 16px; background: var(--panel); border-top: 1px solid var(--border); min-height: 62px; }
.btn.wide { width: min(360px, 100%); }
.role { margin-left: 6px; font-size: 11px; font-weight: 600; color: var(--accent); background: var(--accent-soft); padding: 1px 7px; border-radius: 10px; vertical-align: middle; }
.chat-desc { white-space: pre-wrap; }
.danger-actions { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 4px; }
.field textarea { resize: vertical; }
.profile-about { white-space: pre-wrap; }
#modal-body .check .btn.small { flex-shrink: 0; }

/* Боты */
.avatar.bot-avatar { font-size: 22px; background: linear-gradient(135deg, #2f6fed, #7c4dff) !important; }
.msg .avatar.bot-avatar { font-size: 17px; }
.profile-avatar .avatar.bot-avatar { font-size: 52px; }
.typing { color: var(--accent) !important; font-style: italic; }
.profile-status.bot { color: var(--accent); }

/* Вложения */
.bubble .msg-text { white-space: pre-wrap; }
.bubble.has-image, .bubble.has-video { padding: 4px; }
.bubble.has-image .msg-text, .bubble.has-video .msg-text, .bubble.has-image .author, .bubble.has-video .author { padding: 4px 8px 0; }
.bubble.has-image .stamp, .bubble.has-video .stamp { margin-right: 6px; }
.att-img { display: block; max-width: min(320px, 100%); max-height: 360px; border-radius: 12px; cursor: zoom-in; background: var(--bg); }
.att-video { display: block; width: min(360px, 70vw); max-height: 400px; border-radius: 12px; background: #000; }
.att-preview { display: block; max-width: 100%; max-height: 50vh; border-radius: 12px; margin: 0 auto; background: #000; }
.voice { display: flex; align-items: center; gap: 10px; min-width: 210px; padding: 2px 0; }
.voice-btn { width: 36px; height: 36px; border-radius: 50%; border: 0; background: var(--accent); color: #fff; cursor: pointer; font-size: 13px; flex-shrink: 0; }
.msg.mine .voice-btn { background: #fff; color: var(--mine); }
.voice-bar { flex: 1; height: 4px; border-radius: 2px; background: color-mix(in srgb, currentColor 25%, transparent); cursor: pointer; position: relative; }
.voice-fill { position: absolute; inset: 0 auto 0 0; width: 0; border-radius: 2px; background: currentColor; }
.voice-time { font-size: 12px; opacity: .8; min-width: 32px; }
.sys-wrap { align-self: center; display: flex; align-items: center; gap: 6px; }
.sys-wrap:hover .react-btn { opacity: 1; }
.del-btn { font-size: 13px; }
.del-btn:hover { color: var(--danger) !important; border-color: var(--danger) !important; }
.lightbox { position: fixed; inset: 0; z-index: 30; background: rgba(0,0,0,.9); display: grid; place-items: center; cursor: zoom-out; }
.lightbox img { max-width: 96vw; max-height: 96vh; object-fit: contain; }

/* Строка ввода, запись, загрузка */
.composer { align-items: center; }
.composer .icon-btn { flex-shrink: 0; }
.recorder { gap: 12px; }
.rec-dot { width: 12px; height: 12px; border-radius: 50%; background: var(--danger); animation: pulse 1s infinite; flex-shrink: 0; }
@keyframes pulse { 50% { opacity: .3; } }
#rec-time { font-variant-numeric: tabular-nums; font-weight: 600; }
.rec-hint { flex: 1; }
.upload-bar { padding: 8px 16px; background: var(--panel); border-top: 1px solid var(--border); font-size: 13px; color: var(--muted); }
.progress { height: 4px; background: var(--bg); border-radius: 2px; margin-top: 6px; overflow: hidden; }
#upload-progress { height: 100%; width: 0; background: var(--accent); transition: width .2s; }
@media (max-width: 720px) {
  #send-btn { padding: 9px 12px; }
  .rec-hint { display: none; }
  .att-video { width: 70vw; }
}

/* Галочка верификации */
.verified { display: inline-flex; width: 16px; height: 16px; margin-left: 4px; vertical-align: -3px; color: #1d9bf0; flex-shrink: 0; }
.verified svg { width: 100%; height: 100%; }
.profile-name .verified { width: 20px; height: 20px; vertical-align: -3px; }
.msg.mine .author .verified, .msg.post .author .verified { color: #1d9bf0; }

/* Реакции */
.bubble-wrap { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.bubble-line { display: flex; align-items: center; gap: 6px; min-width: 0; }
.msg.mine .bubble-wrap { align-items: flex-end; }
.msg.mine .bubble-line { flex-direction: row-reverse; }
.react-btn { flex-shrink: 0; width: 28px; height: 28px; border-radius: 50%; border: 1px solid var(--border); background: var(--panel); color: var(--muted); cursor: pointer; font-size: 15px; line-height: 1; opacity: 0; transition: opacity .15s; }
.msg:hover .react-btn, .react-btn:focus-visible { opacity: 1; }
.react-btn:hover { color: var(--accent); border-color: var(--accent); }
@media (hover: none) { .react-btn { opacity: .7; } }
.reactions { display: flex; flex-wrap: wrap; gap: 4px; }
.reaction { display: inline-flex; align-items: center; gap: 4px; padding: 2px 8px; border-radius: 14px; border: 1px solid var(--border); background: var(--panel); cursor: pointer; font-size: 13px; }
.reaction:hover:not(:disabled) { border-color: var(--accent); }
.reaction.mine { background: var(--accent-soft); border-color: var(--accent); color: var(--accent); font-weight: 600; }
.reaction:disabled { cursor: default; }
.r-emoji { font-size: 15px; }
.reaction-picker { position: fixed; z-index: 20; display: flex; gap: 2px; padding: 5px; background: var(--panel); border: 1px solid var(--border); border-radius: 24px; box-shadow: 0 8px 24px rgba(0,0,0,.18); }
.reaction-picker button { border: 0; background: transparent; font-size: 22px; width: 38px; height: 38px; border-radius: 50%; cursor: pointer; transition: transform .1s; }
.reaction-picker button:hover { background: var(--bg); transform: scale(1.2); }

/* Админ-панель */
.admin-panel { margin-top: 6px; padding: 10px 12px; border: 1px dashed var(--border); border-radius: 12px; display: flex; flex-direction: column; gap: 8px; }
.admin-title { font-size: 12px; font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
.admin-btn { display: inline-flex; align-items: center; gap: 4px; }
.admin-btn .verified { margin-left: 0; }

/* Профиль */
.modal-card.profile { padding: 0; overflow: hidden; }
.modal-card.profile #modal-body { gap: 0; }
.modal-card.profile .modal-actions { padding: 0 20px 20px; }
.profile-banner { position: relative; flex-shrink: 0; aspect-ratio: 3 / 1; width: 100%; }
.banner-actions { position: absolute; right: 10px; bottom: 10px; display: flex; gap: 6px; }
.chip { border: 0; border-radius: 20px; padding: 5px 12px; background: rgba(0,0,0,.55); color: #fff; font-size: 13px; cursor: pointer; }
.chip:hover { background: rgba(0,0,0,.75); }
.profile-avatar { margin: -48px 0 0 20px; position: relative; width: max-content; }
.profile-avatar .avatar { width: 96px; height: 96px; font-size: 34px; border: 4px solid var(--panel); }
.profile-info { padding: 10px 20px 0; display: flex; flex-direction: column; gap: 8px; }
.profile-name { font-size: 20px; font-weight: 700; }
.profile-status { font-size: 13px; color: var(--muted); }
.profile-status.on { color: var(--online); }
.avatar-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.btn.small { padding: 6px 12px; font-size: 13px; }
.field { display: flex; flex-direction: column; gap: 5px; font-size: 13px; color: var(--muted); }

/* Мобильная версия */
@media (max-width: 720px) {
  .sidebar { width: 100%; border-right: 0; }
  .app.in-chat .sidebar { display: none; }
  .app:not(.in-chat) .chat { display: none; }
  .back { display: inline-block; }
  .msg { max-width: 88%; }
}
