:root {
  --bg: #0e1621;
  --panel: #17212b;
  --panel-2: #1e2c3a;
  --line: #24333f;
  --text: #e6edf3;
  --muted: #7d8b99;
  --accent: #4a9eff;
  --bubble: #182533;
  --bubble-own: #2b5278;
  --radius: 12px;
  --sidebar-w: 320px;
}

* { box-sizing: border-box; }

html, body {
  height: 100%;
  margin: 0;
}

body {
  background: var(--bg);
  color: var(--text);
  font: 15px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

.app {
  display: flex;
  height: 100dvh;
  overflow: hidden;
}

/* --- боковая панель ------------------------------------------------------ */
.sidebar {
  width: var(--sidebar-w);
  flex: 0 0 var(--sidebar-w);
  background: var(--panel);
  border-right: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  overflow-y: auto;
  padding: 12px;
  gap: 14px;
}

.side-head { display: flex; align-items: center; justify-content: space-between; }
.brand { font-weight: 700; font-size: 18px; color: var(--text); text-decoration: none; }
.side-close { display: none; background: none; border: 0; color: var(--muted); font-size: 26px; cursor: pointer; }

.search-form { display: flex; flex-direction: column; gap: 8px; }
.search-form input[type="search"] {
  width: 100%; padding: 9px 11px; border-radius: 9px;
  border: 1px solid var(--line); background: var(--panel-2); color: var(--text);
}
.filters { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; font-size: 12px; color: var(--muted); }
.filters label { display: flex; flex-direction: column; gap: 2px; }
.filters input, .filters select, .filters button {
  padding: 6px 8px; border-radius: 7px; border: 1px solid var(--line);
  background: var(--panel-2); color: var(--text); font-size: 12px; width: 100%;
}
.filters button { grid-column: 1 / -1; cursor: pointer; background: var(--accent); color: #06131f; font-weight: 600; border: 0; padding: 8px; }
.filters .clear { grid-column: 1 / -1; text-align: center; color: var(--muted); font-size: 12px; }

.timeline { font-size: 12px; }
.tl-head, .tl-top { color: var(--muted); margin-bottom: 4px; }
.tl-months { display: flex; flex-direction: column; gap: 1px; max-height: 46vh; overflow-y: auto; }
.tl-months a {
  display: flex; align-items: center; gap: 6px; padding: 3px 4px;
  color: var(--text); text-decoration: none; border-radius: 5px;
}
.tl-months a:hover { background: var(--panel-2); }
.tl-month { width: 68px; flex: 0 0 68px; color: var(--muted); }
.tl-bar { height: 8px; border-radius: 4px; background: var(--accent); opacity: .55; width: var(--w, 0%); min-width: 2px; }
.tl-top { display: inline-block; margin-top: 8px; color: var(--accent); text-decoration: none; }

/* --- основная область ---------------------------------------------------- */
.main { flex: 1 1 auto; display: flex; flex-direction: column; min-width: 0; }

.topbar {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 16px; border-bottom: 1px solid var(--line); background: var(--panel);
}
.side-open { display: none; background: none; border: 0; color: var(--text); font-size: 20px; cursor: pointer; }
.title { flex: 1 1 auto; font-weight: 600; }
.title a { color: var(--text); text-decoration: none; }
.who { display: flex; align-items: center; gap: 10px; font-size: 13px; color: var(--muted); }
.who a { color: var(--accent); }
.logout { display: inline; }
.logout button { background: none; border: 0; color: var(--muted); cursor: pointer; font-size: 13px; }

.feed-wrap { flex: 1 1 auto; overflow-y: auto; padding: 14px 16px 40px; scroll-behavior: smooth; }
.feed { display: flex; flex-direction: column; gap: 10px; max-width: 860px; margin: 0 auto; }

.feed-nav { display: flex; gap: 10px; justify-content: center; padding: 8px 0 14px; }
.feed-nav.bottom { padding-top: 18px; }
.more {
  font-size: 13px; color: var(--accent); text-decoration: none;
  background: var(--panel); padding: 7px 14px; border-radius: 999px; border: 1px solid var(--line);
}
.more:hover { background: var(--panel-2); }

/* --- сообщения ----------------------------------------------------------- */
.msg {
  background: var(--bubble); border-radius: var(--radius);
  padding: 9px 13px; border: 1px solid transparent;
}
.msg.focus { border-color: var(--accent); }
.msg .head { display: flex; align-items: baseline; gap: 8px; margin-bottom: 3px; }
.msg .author { font-weight: 600; color: #8bb9e8; font-size: 14px; }
.msg .ts { color: var(--muted); font-size: 11px; text-decoration: none; }
.msg .edited { color: var(--muted); font-size: 11px; }
.msg .text { white-space: pre-wrap; overflow-wrap: anywhere; }
.msg .text a { color: var(--accent); }

.reply {
  display: block; font-size: 12px; color: var(--muted); text-decoration: none;
  border-left: 2px solid var(--accent); padding: 2px 0 2px 8px; margin-bottom: 5px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.forwarded { font-size: 12px; color: var(--muted); margin-bottom: 4px; font-style: italic; }

.msg.service { background: transparent; text-align: center; padding: 4px; }
.service-line {
  display: inline-flex; align-items: center; gap: 6px; font-size: 12px; color: var(--muted);
  background: var(--panel); padding: 5px 12px; border-radius: 999px;
}
.service-line b { color: #9fb3c6; font-weight: 600; }
.service-line .ts { margin-left: 6px; opacity: .8; }

/* --- медиа --------------------------------------------------------------- */
.media { margin: 7px 0 2px; }
.media img { max-width: 100%; height: auto; border-radius: 9px; display: block; }
.media.photo img { max-height: 460px; width: auto; }
.media.sticker .sticker-img { width: 160px; max-height: 160px; }
.media.video video { width: 100%; max-width: 640px; border-radius: 9px; background: #000; }
.media.video.has-preview .player { display: none; }
.media.video.playing .player { display: block; }
.media.video.playing .play { display: none; }
.media.video .play { display: block; position: relative; }
.media.video .play::after {
  content: "▶"; position: absolute; inset: 0; display: grid; place-items: center;
  font-size: 40px; color: #fff; text-shadow: 0 0 18px rgba(0,0,0,.85);
}
.media.voice, .media.audio { display: flex; align-items: center; gap: 8px; }
.media audio { max-width: 320px; height: 34px; }
.media.document a { color: var(--accent); }
.hint { color: var(--muted); font-size: 12px; }

/* --- опросы, контакты, реакции ------------------------------------------- */
.poll { background: var(--panel); border-radius: 10px; padding: 10px 12px; margin-top: 6px; }
.poll-q { font-weight: 600; margin-bottom: 7px; }
.poll-opts { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 4px; }
.poll-opt {
  position: relative; padding: 5px 9px; border-radius: 7px; background: var(--panel-2);
  font-size: 13px; overflow: hidden;
}
.poll-opt.chosen { outline: 1px solid var(--accent); }
.poll-bar { position: absolute; inset: 0 auto 0 0; background: rgba(74,158,255,.22); width: 0; }
.poll-opt > *:not(.poll-bar) { position: relative; }
.poll-n { float: right; color: var(--muted); }
.poll-meta { font-size: 12px; color: var(--muted); margin-top: 6px; }

.contact { background: var(--panel); border-radius: 10px; padding: 10px 12px; margin-top: 6px; }
.contact-name { font-weight: 600; }
.contact-phone a { color: var(--accent); }
.contact a { color: var(--accent); }

.reactions { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 6px; }
.reaction {
  font-size: 12px; background: var(--panel-2); border-radius: 999px;
  padding: 2px 9px; display: inline-flex; gap: 5px; align-items: center;
}
.reaction b { color: var(--muted); font-weight: 500; }

/* --- вход/инвайт --------------------------------------------------------- */
.auth-wrap { flex: 1 1 auto; display: grid; place-items: center; padding: 24px; overflow-y: auto; }
.auth-form {
  width: min(380px, 100%); background: var(--panel); border-radius: 14px;
  padding: 22px; display: flex; flex-direction: column; gap: 12px; border: 1px solid var(--line);
}
.auth-form h1 { font-size: 19px; margin: 0 0 4px; }
.auth-form label { display: flex; flex-direction: column; gap: 5px; font-size: 13px; color: var(--muted); }
.auth-form input {
  padding: 9px 11px; border-radius: 8px; border: 1px solid var(--line);
  background: var(--panel-2); color: var(--text); font-size: 14px;
}
.auth-form button {
  padding: 10px; border: 0; border-radius: 8px; background: var(--accent);
  color: #06131f; font-weight: 700; cursor: pointer; font-size: 14px;
}
.auth-form .error { color: #ff8a80; font-size: 13px; margin: 0; }
.auth-form .hint { font-size: 12px; color: var(--muted); margin: 0; }
.auth-form a { color: var(--accent); }

.search-summary { max-width: 860px; margin: 0 auto 12px; font-size: 13px; color: var(--muted); display: flex; justify-content: space-between; gap: 12px; }
.search-summary a { color: var(--accent); }
.empty { text-align: center; color: var(--muted); padding: 40px 0; }

/* --- мобильная версия ---------------------------------------------------- */
@media (max-width: 760px) {
  .sidebar {
    position: fixed; inset: 0 auto 0 0; z-index: 20;
    width: min(var(--sidebar-w), 86vw);
    flex-basis: auto;
    transform: translateX(-102%); transition: transform .2s ease;
    box-shadow: 0 0 40px rgba(0,0,0,.6);
    visibility: hidden;
  }
  .app.side-open .sidebar { transform: translateX(0); visibility: visible; }
  .side-close, .side-open { display: block; }
  .feed-wrap { padding: 10px 10px 40px; }
  .media.photo img { max-height: 320px; }
}
