/* ОБЛАКО · Мессенджер — светлая тема, стиль Telegram Desktop */
* { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --accent: #3390ec;
  --accent-light: #e3f2fd;
  --bg: #fff;
  --bg-gray: #f4f4f5;
  --border: #e5e5e6;
  --text: #1c1c1e;
  --muted: #8b8b8f;
}

html, body { height: 100%; }

body {
  font: 14px/1.4 -apple-system, "Segoe UI", Roboto, sans-serif;
  color: var(--text);
  background: var(--bg-gray);
  overflow: hidden;
}

button { font: inherit; color: inherit; background: none; border: 0; cursor: pointer; }
input, textarea { font: inherit; color: inherit; }
[hidden] { display: none !important; }

/* ---------- общие ---------- */
.btn {
  padding: 8px 16px;
  border-radius: 8px;
  background: var(--accent);
  color: #fff;
}
.btn:hover { filter: brightness(1.05); }
.btn.danger { background: #fff; color: #e53935; border: 1px solid #f0c9c8; }
.btn.danger:hover { background: #fdf1f1; }

.icon-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 38px;
  height: 38px;
  border-radius: 50%;
  color: var(--muted);
  flex: none;
}
.icon-btn:hover { background: var(--bg-gray); color: var(--accent); }

.inline-edit {
  width: 100%;
  min-width: 40px;
  border: 1px solid var(--accent);
  border-radius: 6px;
  padding: 1px 5px;
  font-size: inherit;
  font-weight: inherit;
  background: #fff;
  outline: none;
}

.list-empty { padding: 24px 16px; text-align: center; color: var(--muted); }

.avatar {
  border-radius: 50%;
  object-fit: cover;
  flex: none;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  font-weight: 600;
  user-select: none;
}
.av48 { width: 48px; height: 48px; font-size: 17px; }
.av40 { width: 40px; height: 40px; font-size: 15px; }

.ch-icon { display: inline-block; vertical-align: middle; flex: none; }

/* ---------- тост ---------- */
#toast {
  position: fixed;
  top: 14px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 300;
  background: #323232;
  color: #fff;
  padding: 9px 18px;
  border-radius: 10px;
  box-shadow: 0 4px 16px rgba(0, 0, 0, .25);
  max-width: 70vw;
}

/* ---------- логин ---------- */
#login {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg-gray);
  z-index: 200;
}
.login-card {
  background: #fff;
  border-radius: 16px;
  box-shadow: 0 6px 32px rgba(0, 0, 0, .08);
  padding: 36px 32px;
  width: 340px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.login-card h1 { font-size: 19px; text-align: center; margin-bottom: 10px; }
.login-card input {
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px 14px;
  outline: none;
}
.login-card input:focus { border-color: var(--accent); }
.login-error { color: #e53935; font-size: 13px; text-align: center; }

/* ---------- раскладка ---------- */
#app { display: flex; height: 100vh; min-width: 1024px; }

/* ---------- рельса папок ---------- */
#rail {
  width: 76px;
  flex: none;
  background: #fff;
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  align-items: stretch;
  padding: 8px 0;
  overflow-y: auto;
  overflow-x: hidden;
}
.rail-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  padding: 9px 2px;
  color: var(--muted);
  border-radius: 10px;
  margin: 1px 6px;
}
.rail-item:hover { background: var(--bg-gray); }
.rail-item.active { color: var(--accent); background: var(--accent-light); }
.rail-ico { position: relative; display: flex; }
.rail-name {
  font-size: 11px;
  max-width: 64px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  text-align: center;
}
.rail-badge {
  position: absolute;
  top: -5px;
  right: -9px;
  min-width: 17px;
  height: 17px;
  padding: 0 4px;
  border-radius: 9px;
  background: var(--accent);
  color: #fff;
  font-size: 10.5px;
  font-weight: 600;
  display: flex;
  align-items: center;
  justify-content: center;
}
.rail-sep { border-top: 1px solid var(--border); margin: 6px 14px; }
.rail-spacer { flex: 1; }

/* ---------- панель диалогов ---------- */
#panel {
  width: 340px;
  flex: none;
  background: #fff;
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  min-width: 0;
}
.search-wrap { padding: 10px 12px; }
#search {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: 18px;
  padding: 8px 16px;
  background: var(--bg-gray);
  outline: none;
}
#search:focus { border-color: var(--accent); background: #fff; }

#merge-banner {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 0 12px 8px;
  padding: 8px 12px;
  background: var(--accent-light);
  color: var(--accent);
  border-radius: 10px;
  font-size: 13px;
}
#merge-banner span { flex: 1; }
#merge-banner button { color: var(--accent); font-size: 15px; padding: 2px 6px; }

#add-row { padding: 0 12px 8px; display: flex; gap: 6px; align-items: center; }
#add-row #add-open {
  flex: 1;
  text-align: left;
  color: var(--accent);
  padding: 8px 12px;
  border: 1px dashed var(--accent);
  border-radius: 10px;
}
#add-row #add-open:hover { background: var(--accent-light); }
#add-row #add-input {
  flex: 1;
  border: 1px solid var(--accent);
  border-radius: 10px;
  padding: 8px 12px;
  outline: none;
}
#add-row #add-cancel { color: var(--muted); padding: 6px; }

#dialog-list { flex: 1; overflow-y: auto; padding-bottom: 8px; }

.list-section {
  padding: 8px 16px 4px;
  font-size: 12.5px;
  font-weight: 600;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: .3px;
}

.dialog {
  display: flex;
  gap: 11px;
  align-items: center;
  padding: 8px 12px;
  cursor: pointer;
  user-select: none;
}
.dialog:hover { background: var(--bg-gray); }
.dialog.active { background: var(--accent-light); }
.d-body { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 3px; }
.d-top { display: flex; align-items: baseline; gap: 6px; }
.d-name {
  flex: 1;
  min-width: 0;
  font-weight: 600;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.d-meta { display: flex; align-items: center; gap: 3px; flex: none; }
.d-pin { font-size: 11px; }
.d-time { font-size: 12px; color: var(--muted); }
.d-bottom { display: flex; align-items: center; gap: 6px; }
.d-last {
  flex: 1;
  min-width: 0;
  color: var(--muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  display: flex;
  align-items: center;
  gap: 4px;
}
.d-mini { display: inline-flex; gap: 2px; flex: none; }
.d-badge {
  flex: none;
  min-width: 20px;
  height: 20px;
  padding: 0 6px;
  border-radius: 10px;
  background: var(--accent);
  color: #fff;
  font-size: 12px;
  font-weight: 600;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* ---------- окно переписки ---------- */
#chat {
  flex: 1;
  min-width: 0;
  position: relative;
  display: flex;
  flex-direction: column;
  background: var(--bg-gray);
}
#chat-empty {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--muted);
}
#chat-view { flex: 1; display: flex; flex-direction: column; min-height: 0; }

#chat-header {
  display: flex;
  align-items: center;
  gap: 11px;
  padding: 8px 16px;
  background: #fff;
  border-bottom: 1px solid var(--border);
  flex: none;
  min-height: 56px;
}
.h-info { min-width: 0; flex: 1; }
.h-name {
  font-weight: 600;
  font-size: 15px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  cursor: default;
}
.h-sub {
  display: flex;
  align-items: center;
  gap: 5px;
  color: var(--muted);
  font-size: 12.5px;
  margin-top: 1px;
}

#messages {
  flex: 1;
  overflow-y: auto;
  padding: 14px 24px 10px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  scroll-behavior: auto;
}

.day-sep { display: flex; justify-content: center; margin: 10px 0 6px; }
.day-sep span {
  background: rgba(0, 0, 0, .28);
  color: #fff;
  font-size: 12.5px;
  padding: 3px 12px;
  border-radius: 12px;
}

.msg-row { display: flex; align-items: flex-end; gap: 6px; }
.msg-row.out { justify-content: flex-end; }
.msg-ch { flex: none; margin-bottom: 3px; }

.bubble {
  max-width: 60%;
  background: #fff;
  border-radius: 12px;
  padding: 7px 11px 6px;
  box-shadow: 0 1px 1px rgba(0, 0, 0, .06);
  word-wrap: break-word;
  overflow-wrap: break-word;
  position: relative;
}
.msg-row.out .bubble { background: var(--accent-light); }

.msg-agent { font-size: 12px; font-weight: 600; color: var(--accent); margin-bottom: 2px; }
.msg-text { white-space: pre-wrap; }

.msg-time {
  float: right;
  margin: 8px -3px -2px 8px;
  font-size: 11px;
  color: var(--muted);
}

.msg-note {
  align-self: center;
  background: #fff8dc;
  border: 1px solid #f0e6b8;
  border-radius: 10px;
  padding: 6px 12px;
  max-width: 60%;
  color: #7a6c34;
  font-size: 13px;
}

/* цитата (reply): вертикальная синяя полоска + 1 строка серого текста */
.quote {
  border-left: 3px solid var(--accent);
  background: rgba(51, 144, 236, .07);
  border-radius: 4px;
  padding: 3px 8px;
  margin-bottom: 5px;
  min-width: 0;
}
.q-who { font-size: 12.5px; font-weight: 600; color: var(--accent); }
.q-text {
  font-size: 13px;
  color: var(--muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 380px;
}

/* вложения */
.msg-img {
  display: block;
  max-width: 320px;
  max-height: 320px;
  border-radius: 8px;
  cursor: pointer;
  margin: 2px 0;
}
.msg-video { display: block; max-width: 320px; border-radius: 8px; margin: 2px 0; }
.msg-audio { display: block; max-width: 280px; margin: 2px 0; }

.file-plaque {
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 6px 4px;
  text-decoration: none;
  color: inherit;
  border-radius: 8px;
}
.file-plaque:hover { background: rgba(0, 0, 0, .04); }
.file-ico { font-size: 26px; flex: none; }
.file-meta { min-width: 0; display: flex; flex-direction: column; }
.file-name {
  font-weight: 500;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 260px;
}
.file-size { font-size: 12px; color: var(--muted); }

/* кнопка «вниз» */
#scroll-down {
  position: absolute;
  right: 18px;
  bottom: 76px;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  background: #fff;
  color: var(--muted);
  box-shadow: 0 2px 10px rgba(0, 0, 0, .18);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 5;
}
#scroll-down:hover { color: var(--accent); }
#scroll-down-badge {
  position: absolute;
  top: -6px;
  left: 50%;
  transform: translateX(-50%);
  min-width: 19px;
  height: 19px;
  padding: 0 5px;
  border-radius: 10px;
  background: var(--accent);
  color: #fff;
  font-size: 11.5px;
  font-weight: 600;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* drag&drop оверлей */
#drop-overlay {
  position: absolute;
  inset: 0;
  z-index: 20;
  background: rgba(51, 144, 236, .12);
  display: flex;
  align-items: center;
  justify-content: center;
  pointer-events: none;
  padding: 20px;
}
.drop-inner {
  border: 2px dashed var(--accent);
  border-radius: 16px;
  background: rgba(255, 255, 255, .92);
  color: var(--accent);
  font-size: 17px;
  font-weight: 600;
  padding: 40px 60px;
}

/* ---------- композер ---------- */
#composer {
  flex: none;
  background: #fff;
  border-top: 1px solid var(--border);
  padding: 8px 12px;
  position: relative;
}
.composer-row { display: flex; align-items: flex-end; gap: 4px; }

#input {
  flex: 1;
  resize: none;
  border: 0;
  outline: none;
  padding: 9px 8px;
  max-height: 160px;
  background: transparent;
  line-height: 1.35;
}

.icon-btn.send { color: var(--accent); }

#reply-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 4px 8px 6px;
}
#reply-bar .quote { flex: 1; margin-bottom: 0; }
#reply-bar .reply-cancel { width: 30px; height: 30px; font-size: 14px; }

#attach-bar {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  padding: 4px 8px 8px;
}
.attach-item {
  display: flex;
  align-items: center;
  gap: 7px;
  background: var(--bg-gray);
  border-radius: 10px;
  padding: 5px 8px;
  max-width: 240px;
}
.attach-item img {
  width: 38px;
  height: 38px;
  object-fit: cover;
  border-radius: 6px;
  flex: none;
}
.attach-item .file-ico { font-size: 22px; }
.attach-name {
  font-size: 12.5px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  min-width: 0;
}
.attach-remove { color: var(--muted); padding: 3px 5px; flex: none; }
.attach-remove:hover { color: #e53935; }

/* поповеры композера */
.popover {
  position: absolute;
  bottom: calc(100% + 6px);
  background: #fff;
  border-radius: 14px;
  box-shadow: 0 4px 24px rgba(0, 0, 0, .16);
  z-index: 30;
  overflow: hidden;
}
#channel-popover { left: 50px; padding: 8px; min-width: 240px; }
.chp-title { font-size: 13px; color: var(--muted); padding: 4px 8px 8px; }
.chp-item {
  display: flex;
  align-items: center;
  gap: 9px;
  width: 100%;
  padding: 8px 10px;
  border-radius: 8px;
  text-align: left;
}
.chp-item:hover { background: var(--bg-gray); }
.chp-item > span:first-of-type { font-weight: 500; }
.chp-num { margin-left: auto; color: var(--muted); font-size: 12.5px; }

#emoji-popover { right: 12px; }
.emoji-panel {
  width: 344px;
  max-height: 320px;
  overflow-y: auto;
  padding: 8px 10px 12px;
}
.emoji-cat {
  font-size: 12.5px;
  font-weight: 600;
  color: var(--muted);
  padding: 8px 4px 4px;
}
.emoji-grid { display: grid; grid-template-columns: repeat(8, 1fr); }
.emoji-btn {
  font-size: 22px;
  padding: 4px;
  border-radius: 8px;
  line-height: 1.2;
}
.emoji-btn:hover { background: var(--bg-gray); }

/* ---------- контекст-меню ---------- */
#ctx-menu {
  position: fixed;
  z-index: 400;
  background: #fff;
  border-radius: 12px;
  box-shadow: 0 4px 24px rgba(0, 0, 0, .18);
  padding: 5px;
  min-width: 180px;
}
.menu-item {
  display: block;
  width: 100%;
  text-align: left;
  padding: 8px 14px;
  border-radius: 8px;
}
.menu-item:hover { background: var(--bg-gray); }
.menu-item.danger { color: #e53935; }

/* ---------- лайтбокс ---------- */
#lightbox {
  position: fixed;
  inset: 0;
  z-index: 500;
  background: rgba(0, 0, 0, .82);
  display: flex;
  align-items: center;
  justify-content: center;
}
.lb-img {
  max-width: 92vw;
  max-height: 92vh;
  border-radius: 6px;
  box-shadow: 0 8px 40px rgba(0, 0, 0, .5);
}
.lb-close {
  position: absolute;
  top: 16px;
  right: 20px;
  color: #fff;
  font-size: 22px;
  padding: 8px 12px;
  opacity: .8;
}
.lb-close:hover { opacity: 1; }
.lb-nav {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  color: #fff;
  font-size: 46px;
  padding: 16px 20px;
  opacity: .7;
  user-select: none;
}
.lb-nav:hover { opacity: 1; }
.lb-prev { left: 8px; }
.lb-next { right: 8px; }

/* ---------- модалка настроек ---------- */
.modal {
  position: fixed;
  inset: 0;
  z-index: 250;
  background: rgba(0, 0, 0, .4);
  display: flex;
  align-items: center;
  justify-content: center;
}
.modal-card {
  background: #fff;
  border-radius: 16px;
  width: 420px;
  max-height: 88vh;
  overflow-y: auto;
  padding: 20px 24px 24px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}
.modal-head { display: flex; align-items: center; justify-content: space-between; }
.modal-head h2 { font-size: 17px; }
.modal-close { font-size: 16px; }

.set-block { display: flex; flex-direction: column; gap: 8px; }
.set-label {
  font-size: 12.5px;
  font-weight: 600;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: .3px;
}
.set-profile { display: flex; align-items: center; gap: 11px; }
.set-name { font-weight: 600; }
.set-login { color: var(--muted); font-size: 13px; }
.set-block input[type="password"] {
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 9px 13px;
  outline: none;
}
.set-block input[type="password"]:focus { border-color: var(--accent); }
.set-toggle { display: flex; align-items: center; gap: 9px; cursor: pointer; }
.set-toggle input { width: 17px; height: 17px; accent-color: var(--accent); }
.set-ch { display: flex; align-items: center; gap: 9px; padding: 4px 0; }
.set-ch-name { font-weight: 500; }
.set-num { color: var(--muted); font-size: 13px; }
.set-status { margin-left: auto; color: #2e9e46; font-size: 12.5px; }
.set-status::before { content: "● "; font-size: 10px; }

/* ---------- скроллбары ---------- */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-thumb { background: rgba(0, 0, 0, .18); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: rgba(0, 0, 0, .3); }

/* ---------- модалка «Загрузить историю» ---------- */
.imp-ch, .imp-period {
  display: flex; align-items: center; gap: 9px;
  padding: 5px 0; cursor: pointer; font-size: 14px;
}
.imp-ch input, .imp-period input[type=radio] {
  width: 16px; height: 16px; accent-color: var(--accent);
}
.imp-period input[type=date] {
  border: 1px solid var(--border, #e3e3e6); border-radius: 8px;
  padding: 4px 8px; font: inherit; margin-left: 4px;
}
.imp-note { font-size: 12.5px; color: var(--muted, #8a8a8e); margin: 10px 0 14px; line-height: 1.45; }
