:root {
  --bg: #0e1621;
  --panel: #17212b;
  --panel-2: #1e2c3a;
  --accent: #2b5278;
  --accent-2: #3390ec;
  --text: #e9edf1;
  --muted: #7f91a4;
  --bubble-in: #182533;
  --bubble-out: #2b5278;
  --line: #101820;
  --danger: #ff6b6b;
}
* { box-sizing: border-box; }
/* атрибут hidden должен побеждать любые display-правила классов (.modal, .chat-pane и т.п.) */
[hidden] { display: none !important; }
html, body { height: 100%; margin: 0; }
body {
  font-family: -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg); color: var(--text);
}
.muted { color: var(--muted); }
.small { font-size: 12px; }

/* тонкие полупрозрачные скроллы как в телеграме */
* { scrollbar-width: thin; scrollbar-color: rgba(255,255,255,.16) transparent; } /* Firefox */
::-webkit-scrollbar { width: 7px; height: 7px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: rgba(255,255,255,.16); border-radius: 8px; }
::-webkit-scrollbar-thumb:hover { background: rgba(255,255,255,.30); }

/* ---------- login ---------- */
.login-body { display: grid; place-items: center; }
.login-card {
  width: 320px; background: var(--panel); padding: 28px 24px; border-radius: 14px;
  display: flex; flex-direction: column; gap: 12px; box-shadow: 0 10px 40px rgba(0,0,0,.4);
}
.login-card h1 { margin: 0; font-size: 22px; }
.login-card input {
  background: var(--panel-2); border: 1px solid #2a3b4d; color: var(--text);
  padding: 11px 12px; border-radius: 8px; font-size: 14px;
}
.login-card button, .primary-btn {
  background: var(--accent-2); color: #fff; border: 0; padding: 11px; border-radius: 8px;
  font-size: 15px; cursor: pointer;
}
.err { color: var(--danger); font-size: 13px; min-height: 16px; }

/* ---------- avatars ---------- */
.avatar {
  position: relative; display: inline-flex; align-items: center; justify-content: center;
  border-radius: 50%; flex: none;
  font-weight: 600; color: #fff; background: var(--accent); user-select: none;
}
.avatar img { width: 100%; height: 100%; object-fit: cover; border-radius: inherit; }
/* точка онлайн-статуса (не обрезается, т.к. у .avatar нет overflow:hidden) */
.presence-dot {
  position: absolute; right: -1px; bottom: -1px; width: 32%; height: 32%;
  min-width: 8px; min-height: 8px; max-width: 13px; max-height: 13px;
  border-radius: 50%; background: var(--muted); box-shadow: 0 0 0 2px var(--panel);
}
.presence-dot.online { background: #4caf50; }
.avatar.sm { width: 38px; height: 38px; font-size: 14px; }
.avatar.xs { width: 30px; height: 30px; font-size: 12px; }
.avatar.xxs { width: 18px; height: 18px; font-size: 9px; }
.avatar.md { width: 44px; height: 44px; font-size: 16px; }
.avatar.lg { width: 76px; height: 76px; font-size: 26px; }

/* ---------- layout ---------- */
.layout { display: grid; grid-template-columns: 320px 1fr; height: 100vh; }
.sidebar { background: var(--panel); border-right: 1px solid var(--line); display: flex; flex-direction: column; overflow: hidden; }
.sidebar-head {
  display: flex; justify-content: space-between; align-items: center; gap: 8px;
  padding: 12px 14px; border-bottom: 1px solid var(--line);
}
.me-card { display: flex; align-items: center; gap: 10px; cursor: pointer; padding: 4px; border-radius: 8px; flex: 1; min-width: 0; }
.me-card:hover { background: var(--panel-2); }
.me-text { min-width: 0; }
.me-name { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.head-actions { display: flex; gap: 2px; }
.icon-btn { background: transparent; border: 0; color: var(--muted); font-size: 18px; cursor: pointer; padding: 4px 6px; border-radius: 6px; }
.icon-btn:hover { background: var(--panel-2); color: var(--text); }
.new-event-btn {
  margin: 12px 16px; padding: 10px; background: var(--panel-2); color: var(--text);
  border: 1px dashed #35506b; border-radius: 8px; cursor: pointer; font-size: 14px;
}
.new-event-btn:hover { border-color: var(--accent-2); }
/* обе секции — одна сплошная лента с общим скроллом (без вложенных прокруток) */
.lists { flex: 1; min-height: 0; overflow-y: auto; }
.list-group { padding: 8px 0; }
.list-title { padding: 6px 16px; color: var(--muted); font-size: 11px; text-transform: uppercase; letter-spacing: .5px; }
.list-item { display: flex; align-items: center; gap: 10px; padding: 9px 16px; cursor: pointer; border-left: 3px solid transparent; }
.list-item:hover { background: var(--panel-2); }
.list-item.active { background: var(--panel-2); border-left-color: var(--accent-2); }
.li-body { min-width: 0; flex: 1; }
.li-title { font-size: 14px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#eventList .li-title, #archiveList .li-title { color: #ffcf6b; } /* названия мероприятий — жёлтым */
#archiveList .list-item { opacity: .65; } /* архив приглушён */

/* папка «Архив» + вкладка архива (как в телеграме) */
.archive-ava { background: var(--panel-2); font-size: 18px; }
.arch-badge { margin-left: auto; align-self: center; background: rgba(255,255,255,.12); color: var(--muted); font-size: 11px; min-width: 20px; height: 20px; border-radius: 10px; padding: 0 6px; display: inline-flex; align-items: center; justify-content: center; }
.archive-back { display: block; width: calc(100% - 24px); margin: 8px 12px; padding: 9px 12px; background: var(--panel-2); border: 1px solid #2a3b4d; border-radius: 8px; color: var(--text); cursor: pointer; text-align: left; font-size: 13px; }
.archive-back:hover { border-color: var(--accent-2); }
.li-sub { margin-top: 2px; }

/* ---------- chat ---------- */
.chat { display: flex; flex-direction: column; background:
  linear-gradient(180deg, #0e1621, #0b1119); min-width: 0; min-height: 0; overflow: hidden; }
.chat-empty { margin: auto; color: var(--muted); }
.chat-pane { display: flex; flex-direction: column; height: 100%; min-height: 0; overflow: hidden; }
.chat-head {
  display: flex; justify-content: space-between; align-items: center; gap: 10px;
  padding: 12px 20px; background: var(--panel); border-bottom: 1px solid var(--line);
}
.chat-head-info { cursor: pointer; min-width: 0; }
.chat-title { font-weight: 600; }
.chat-head-actions { display: flex; gap: 8px; flex: none; }
.ghost-btn { background: var(--panel-2); color: var(--text); border: 1px solid #2a3b4d; border-radius: 8px; padding: 8px 12px; cursor: pointer; font-size: 13px; }
.ghost-btn:hover { border-color: var(--accent-2); }
.primary-btn { padding: 8px 12px; font-size: 13px; }
.primary-btn:disabled { opacity: .5; cursor: default; }

.messages { flex: 1 1 auto; min-height: 0; overflow-y: auto; padding: 18px 20px; display: flex; flex-direction: column; gap: 6px; }
.msg { display: flex; gap: 8px; max-width: 72%; align-items: flex-end; }
.msg.mine { align-self: flex-end; flex-direction: row-reverse; }
.msg-avatar { align-self: flex-end; }
.msg.mine .msg-avatar { display: none; }
.bubble {
  position: relative; background: var(--bubble-in); padding: 7px 12px 5px; border-radius: 12px;
  min-width: 90px;
}
.msg.mine .bubble { background: var(--bubble-out); }
.sender { font-size: 12px; font-weight: 600; color: #6fb0f0; margin-bottom: 2px; cursor: pointer; }
.sender:hover { text-decoration: underline; }
.sender .role-tag { color: var(--muted); font-weight: 400; }
.text { font-size: 14px; line-height: 1.35; white-space: pre-wrap; word-break: break-word; }
.time { font-size: 10px; color: var(--muted); text-align: right; margin-top: 2px; }
.img-wrap { position: relative; }
.chat-img { max-width: 260px; max-height: 300px; border-radius: 8px; display: block; cursor: pointer; }

/* альбом из нескольких фото */
.album-grid { display: grid; gap: 3px; max-width: 264px; border-radius: 8px; overflow: hidden; }
.album-cell { position: relative; aspect-ratio: 1; }
.album-img { width: 100%; height: 100%; object-fit: cover; display: block; cursor: pointer; }
.cell-del {
  position: absolute; top: 4px; right: 4px; width: 22px; height: 22px; border-radius: 50%;
  background: rgba(0,0,0,.55); color: #fff; border: 0; cursor: pointer; font-size: 12px; line-height: 1;
  display: none; align-items: center; justify-content: center;
}
.album-cell:hover .cell-del { display: flex; }

/* пересланное / цитата */
.fwd-label { font-size: 11px; color: var(--muted); font-style: italic; margin-bottom: 3px; }
.quote {
  border-left: 3px solid var(--accent-2); background: rgba(255,255,255,.06);
  border-radius: 6px; padding: 3px 8px; margin-bottom: 4px; cursor: pointer; max-width: 260px;
}
.quote-name { font-size: 12px; font-weight: 600; color: #6fb0f0; }
.quote-text { font-size: 12px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* файл-вложение */
.file-att { display: flex; align-items: center; gap: 10px; padding: 6px 4px; text-decoration: none; color: var(--text); }
.file-icon { font-size: 26px; }
.file-meta { min-width: 0; }
.file-name { font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 200px; }
.file-size { font-size: 11px; color: var(--muted); }

/* реакции */
.reactions { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 4px; }
.react-chip { display: inline-flex; align-items: center; gap: 3px; background: rgba(255,255,255,.08); border-radius: 12px; padding: 2px 7px 2px 6px; font-size: 12px; cursor: pointer; }
.react-chip.own { background: var(--accent-2); }
.react-emoji { font-size: 13px; line-height: 1; }
.react-avs { display: inline-flex; }
.react-avs .avatar { margin-left: -5px; box-shadow: 0 0 0 2px var(--bubble-in); }
.react-avs .avatar:first-child { margin-left: 0; }
.msg.mine .react-avs .avatar { box-shadow: 0 0 0 2px var(--bubble-out); }
.react-more { font-size: 11px; color: var(--muted); }

/* меню действий над сообщением */
.msg-menu-btn {
  position: absolute; top: -10px; right: -6px; background: var(--panel); border: 1px solid var(--line);
  border-radius: 12px; font-size: 12px; padding: 1px 6px; cursor: pointer; opacity: 0; transition: opacity .15s; color: var(--text);
}
.msg.mine .msg-menu-btn { right: auto; left: -6px; }
.msg:hover .msg-menu-btn { opacity: 1; }
.ctx-menu {
  position: absolute; z-index: 40; background: var(--panel); border: 1px solid var(--line);
  border-radius: 10px; padding: 4px; min-width: 160px; box-shadow: 0 6px 22px rgba(0,0,0,.5);
}
.ctx-menu button { display: block; width: 100%; text-align: left; background: transparent; border: 0; color: var(--text); padding: 8px 10px; border-radius: 6px; cursor: pointer; font-size: 13px; }
.ctx-menu button:hover { background: var(--panel-2); }
.emoji-row { display: flex; gap: 2px; padding: 4px 6px 6px; border-bottom: 1px solid var(--line); margin-bottom: 4px; flex-wrap: nowrap; align-items: center; }
.emoji-more { display: inline-flex; align-items: center; gap: 2px; }
.emoji-opt { background: transparent; border: 0; font-size: 18px; cursor: pointer; padding: 2px 4px; border-radius: 8px; }
.emoji-opt:hover { background: var(--panel-2); }
.emoji-toggle { font-size: 14px; color: var(--muted); margin-left: 2px; }

/* строка ответа над композером */
.reply-bar { display: flex; align-items: center; gap: 10px; padding: 8px 16px; background: var(--panel); border-top: 1px solid var(--line); }
.reply-bar-body { flex: 1; border-left: 3px solid var(--accent-2); padding-left: 8px; min-width: 0; }
.reply-bar-title { font-size: 12px; color: #6fb0f0; }
.reply-bar-text { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* composer */
.composer { display: flex; align-items: center; gap: 8px; padding: 12px 16px; background: var(--panel); border-top: 1px solid var(--line); }
.attach-btn { cursor: pointer; font-size: 20px; color: var(--muted); }
.msg-input { flex: 1; background: var(--panel-2); border: 1px solid #2a3b4d; color: var(--text); padding: 10px 14px; border-radius: 20px; font-size: 14px; }
.send-btn { background: var(--accent-2); color: #fff; border: 0; width: 40px; height: 40px; border-radius: 50%; cursor: pointer; font-size: 16px; }

/* modal */
.modal { position: fixed; inset: 0; background: rgba(0,0,0,.5); display: grid; place-items: center; z-index: 20; }
.modal-card { width: 420px; max-height: 88vh; overflow-y: auto; background: var(--panel); border-radius: 14px; padding: 22px; display: flex; flex-direction: column; gap: 12px; }
.modal-card.wide { width: 560px; }
.modal-card h2 { margin: 0; font-size: 18px; }
.modal-card h3 { margin: 0; font-size: 15px; }
.modal-card label { display: flex; flex-direction: column; gap: 4px; font-size: 13px; color: var(--muted); }
.modal-card label.row-check { flex-direction: row; align-items: center; gap: 8px; }
.modal-card input[type="text"], .modal-card input[type="password"], .modal-card > label > input, .worker-form input { background: var(--panel-2); border: 1px solid #2a3b4d; color: var(--text); padding: 9px 11px; border-radius: 8px; font-size: 14px; }
.modal-head-row { display: flex; align-items: center; justify-content: space-between; }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 6px; }

.assign-block { border-top: 1px solid var(--line); padding-top: 10px; }
.assign-search { display: block; width: 100%; margin: 8px 0 4px; }
.assign-list { display: flex; flex-direction: column; gap: 6px; margin-top: 4px; max-height: 240px; overflow-y: auto; }
/* строка назначения: [чекбокс] [ФИО] [роль] [чекбокс админ] — строго в одну линию */
.assign-row { display: flex; flex-direction: row; align-items: center; gap: 8px; font-size: 14px; color: var(--text); }
.assign-check { flex: none; }
.assign-name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.assign-role { flex: none; width: 104px; background: var(--panel-2); border: 1px solid #2a3b4d; color: var(--text); padding: 6px 8px; border-radius: 6px; font-size: 12px; }
.admin-pick { flex: none; flex-direction: row; color: var(--muted); font-size: 12px; display: flex; align-items: center; gap: 4px; }

/* добавление участников в модалке «Участники» */
.add-member-block { border-top: 1px solid var(--line); padding-top: 10px; display: flex; flex-direction: column; gap: 8px; }
.add-member-block .msg-input { width: 100%; }
.add-member-block .members-list { max-height: 220px; }

/* профиль / выездники */
.avatar-edit { display: flex; align-items: center; gap: 14px; }
.workers-list { display: flex; flex-direction: column; gap: 4px; max-height: 300px; overflow-y: auto; }
.worker-row { display: flex; align-items: center; gap: 10px; padding: 8px; border-radius: 8px; cursor: pointer; }
.worker-row:hover { background: var(--panel-2); }
.worker-row .li-body { flex: 1; }
.worker-row .row-actions { display: flex; gap: 6px; }
.badge { font-size: 11px; background: var(--accent); padding: 1px 6px; border-radius: 8px; }
.worker-form { border-top: 1px solid var(--line); padding-top: 12px; display: flex; flex-direction: column; gap: 10px; }
.worker-stats { border-top: 1px solid var(--line); padding-top: 12px; display: flex; flex-direction: column; gap: 8px; }
.stat-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.stat-box { background: var(--panel-2); border-radius: 8px; padding: 10px; text-align: center; }
.stat-num { font-size: 20px; font-weight: 700; }
.stat-lbl { font-size: 11px; color: var(--muted); }
.stat-events { display: flex; flex-direction: column; gap: 4px; max-height: 160px; overflow-y: auto; }
.stat-event { font-size: 13px; padding: 5px 8px; background: var(--panel-2); border-radius: 6px; display: flex; justify-content: space-between; gap: 8px; }

/* участники / пересылка */
.members-list, .forward-list { display: flex; flex-direction: column; gap: 4px; max-height: 360px; overflow-y: auto; }
.member-row { display: flex; align-items: center; gap: 10px; padding: 8px; border-radius: 8px; }
.member-row .li-body { flex: 1; min-width: 0; }
.member-row .row-actions { display: flex; gap: 6px; align-items: center; }
.forward-row { display: flex; align-items: center; gap: 10px; padding: 9px; border-radius: 8px; cursor: pointer; }
.forward-row:hover { background: var(--panel-2); }

/* галерея отбора фото */
.gallery-tools { display: flex; gap: 6px; }
.gallery-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; max-height: 60vh; overflow-y: auto; }
.gallery-empty { color: var(--muted); text-align: center; padding: 30px; }
.gallery-cell { position: relative; aspect-ratio: 1; border-radius: 8px; overflow: hidden; cursor: pointer; border: 2px solid transparent; }
.gallery-cell img { width: 100%; height: 100%; object-fit: cover; display: block; }
.gallery-cell.sel { border-color: var(--accent-2); }
.gallery-check {
  position: absolute; top: 6px; left: 6px; width: 22px; height: 22px; border-radius: 5px;
  background: rgba(0,0,0,.5); border: 2px solid #fff; display: flex; align-items: center; justify-content: center;
  color: #fff; font-size: 15px; font-weight: 700;
}
.gallery-cell.sel .gallery-check { background: var(--accent-2); border-color: var(--accent-2); }

/* непрочитанные + статус мероприятия */
.unread-badge { margin-left: auto; align-self: center; background: var(--accent-2); color: #fff; font-size: 11px; min-width: 20px; height: 20px; border-radius: 10px; padding: 0 6px; display: inline-flex; align-items: center; justify-content: center; }
.status-chip { padding: 0 6px; border-radius: 8px; font-size: 11px; white-space: nowrap; }
.status-chip.ok { background: rgba(60,180,90,.25); color: #7fe0a0; }
.status-chip.warn { background: rgba(230,150,40,.25); color: #ffcf87; }
.status-chip.info { background: rgba(51,144,236,.25); color: #8fc2f5; }

/* разделитель "Новое" */
.new-divider { align-self: stretch; text-align: center; font-size: 11px; color: var(--accent-2); margin: 6px 0; position: relative; }
.new-divider::before, .new-divider::after { content: ''; position: absolute; top: 50%; width: 40%; height: 1px; background: rgba(51,144,236,.4); }
.new-divider::before { left: 0; }
.new-divider::after { right: 0; }

/* тосты */
.toasts { position: fixed; top: 16px; right: 16px; display: flex; flex-direction: column; gap: 8px; z-index: 80; }
.toast { background: var(--panel); border: 1px solid var(--accent-2); color: var(--text); padding: 10px 14px; border-radius: 10px; box-shadow: 0 6px 22px rgba(0,0,0,.5); max-width: 320px; font-size: 13px; transition: opacity .3s, transform .3s; }
.toast.hide { opacity: 0; transform: translateX(20px); }

/* даты в модалке */
.dt-row { display: flex; gap: 10px; }
.dt-row label { flex: 1; }
.dt-row input { color-scheme: dark; }

/* действия галереи (три назначения) */
.gallery-actions { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin-top: 6px; }
.gallery-dest { display: flex; gap: 8px; flex-wrap: wrap; margin-left: auto; }

/* лайтбокс */
.lightbox { position: fixed; inset: 0; background: rgba(0,0,0,.88); display: grid; place-items: center; z-index: 60; }
.lightbox-img { max-width: 92vw; max-height: 90vh; border-radius: 8px; }
.lightbox-close { position: absolute; top: 18px; right: 22px; background: transparent; border: 0; color: #fff; font-size: 30px; cursor: pointer; }

/* видео в сообщении */
.chat-video { max-width: 280px; max-height: 320px; border-radius: 8px; display: block; background: #000; }

/* поиск по чату */
.chat-search-bar { display: flex; align-items: center; gap: 8px; padding: 8px 16px; background: var(--panel); border-bottom: 1px solid var(--line); }
.chat-search-bar .msg-input { flex: 1; }
mark { background: #ffd35c; color: #1a1a1a; border-radius: 3px; padding: 0 1px; }
.msg.search-hide, .new-divider.search-hide { display: none; }

/* drag & drop файлов */
.chat-pane.dragover { position: relative; }
.chat-pane.dragover::after {
  content: 'Отпустите — отправлю файлы'; position: absolute; inset: 0; z-index: 30;
  display: flex; align-items: center; justify-content: center; pointer-events: none;
  background: rgba(51,144,236,.15); border: 3px dashed var(--accent-2); border-radius: 12px;
  color: var(--text); font-size: 16px;
}

/* просмотр профиля */
.vp-card { align-items: center; text-align: center; }
.vp-name { font-size: 18px; font-weight: 600; margin-top: 6px; }
.vp-row { display: flex; gap: 8px; align-items: baseline; }
.pres { color: var(--muted); }
.pres.online { color: #6fdd8b; }

/* ---------- мобилка ---------- */
.chat-back { display: none; } /* на десктопе скрыта */
@media (max-width: 768px) {
  /* одна колонка: показываем ЛИБО список, ЛИБО чат (как в телеграм-мобайл) */
  .layout { grid-template-columns: 1fr; height: 100dvh; }
  .sidebar { width: 100%; border-right: 0; }
  .chat { display: none; }
  #app.show-chat .sidebar { display: none; }
  #app.show-chat .chat { display: flex; }
  .chat-back { display: inline-flex; align-items: center; font-size: 22px; flex: none; }

  .sidebar-head { padding: 10px 12px; }
  .chat-head { padding: 8px 10px; gap: 6px; flex-wrap: nowrap; }
  .chat-head-info { flex: 1 1 auto; min-width: 0; }
  .chat-title, #chatSub { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .chat-head-actions { flex: none; gap: 4px; }
  .chat-head-actions .ghost-btn { padding: 7px 9px; font-size: 15px; line-height: 1; }
  .btn-label { display: none; } /* на мобилке кнопки-иконки без подписей */

  .messages { padding: 12px; }
  .msg { max-width: 88%; }
  .composer { padding: 10px 12px; }

  /* модалки во всю ширину */
  .modal-card, .modal-card.wide { width: 94vw; max-width: 94vw; padding: 16px; }
  .dt-row { flex-direction: column; }
  .assign-role { width: 84px; }

  /* галерея: действия столбиком, кнопки на всю ширину */
  .gallery-actions { flex-direction: column; align-items: stretch; }
  .gallery-dest { margin-left: 0; width: 100%; }
  .gallery-dest button { flex: 1; }

  /* тосты — узкой полосой сверху */
  .toasts { left: 8px; right: 8px; top: 8px; }
  .toast { max-width: none; }
}
