* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: #e7ebf0;
  color: #222;
  display: flex;
  flex-direction: column;
}
.topbar {
  flex: 0 0 auto;
  z-index: 10;
  background: #517da2;
  color: #fff;
  padding: 10px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}
.topbar a { color: #fff; text-decoration: none; font-weight: 600; }
.topbar nav { display: flex; align-items: center; min-width: 0; }
.topbar nav span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.topbar .crumb { opacity: .6; margin: 0 6px; }
.menu-btn {
  display: none;
  background: none;
  border: none;
  color: #fff;
  font-size: 1.3rem;
  padding: 0 10px 0 0;
  cursor: pointer;
}
.backdrop { display: none; }
.topsearch input {
  border: none;
  border-radius: 16px;
  padding: 6px 14px;
  min-width: 220px;
  font-size: .9rem;
  background: rgba(255,255,255,.9);
}
main { flex: 1 1 auto; overflow-y: auto; max-width: 820px; margin: 0 auto; padding: 12px; width: 100%; }
main.full { max-width: none; margin: 0; padding: 0; overflow: hidden; }

/* списки чатов */
.cards { list-style: none; padding: 0; margin: 0; }
.card { background: #fff; border-radius: 10px; margin-bottom: 8px; }
.card-link { display: block; padding: 12px 16px; text-decoration: none; color: inherit; }
.card-link:hover { background: #f2f6fa; border-radius: 10px; }
.card-title { display: block; font-weight: 600; }
.card-sub { display: block; color: #6b7a8a; font-size: .85rem; margin-top: 2px; }

/* двухколоночный лейаут ленты */
.layout { display: flex; height: 100%; }
.sidebar {
  flex: 0 0 280px;
  overflow-y: auto;
  background: #fff;
  border-right: 1px solid #d5dde4;
}
.side-list { list-style: none; margin: 0; padding: 8px 0; }
.side-list a { display: block; text-decoration: none; color: inherit; padding: 8px 14px; }
.side-list a:hover { background: #f2f6fa; }
.side-archive a { font-weight: 600; }
.side-archive.active a { color: #3a6d99; }
.side-topic a {
  padding-left: 26px;
  font-size: .9rem;
  display: flex;
  justify-content: space-between;
  gap: 8px;
  align-items: baseline;
}
.side-topic-title { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.side-topic .count { color: #9aa7b3; font-size: .75rem; flex: 0 0 auto; }
.side-topic.current a { background: #517da2; color: #fff; }
.side-topic.current .count { color: rgba(255,255,255,.8); }
.content { flex: 1 1 auto; overflow-y: auto; padding: 12px; }

/* лента */
.feed { display: flex; flex-direction: column; gap: 6px; max-width: 780px; margin: 0 auto; overflow-anchor: auto; }
.load-more, .feed-start {
  text-align: center;
  color: #6b7a8a;
  font-size: .85rem;
  padding: 10px;
}
.service {
  text-align: center;
  color: #6b7a8a;
  font-size: .8rem;
  padding: 4px 10px;
}
.msg { display: flex; align-items: flex-end; gap: 8px; }
.msg:target .bubble { outline: 2px solid #f5a623; }
.avatar {
  flex: 0 0 36px;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  color: #fff;
  font-size: .8rem;
  font-weight: 600;
  display: flex;
  align-items: center;
  justify-content: center;
  user-select: none;
}
.bubble {
  background: #fff;
  border-radius: 12px 12px 12px 4px;
  padding: 6px 12px 8px;
  max-width: 75%;
  box-shadow: 0 1px 1px rgba(0,0,0,.08);
}
.meta { display: flex; gap: 10px; align-items: baseline; margin-bottom: 2px; }
.sender { font-weight: 600; font-size: .85rem; color: #3a6d99; }
.time { color: #9aa7b3; font-size: .75rem; }
.text { white-space: pre-wrap; word-wrap: break-word; font-size: .95rem; }
.media-img { max-width: 100%; max-height: 420px; border-radius: 8px; display: block; margin: 4px 0; }
.media-video { max-width: 100%; max-height: 420px; border-radius: 8px; display: block; margin: 4px 0; }
audio { display: block; margin: 4px 0; max-width: 100%; }
.doc { margin: 4px 0; font-size: .9rem; }
.doc a { color: #3a6d99; }
.size { color: #9aa7b3; font-size: .8rem; }

.avatar-img { object-fit: cover; background: #d5dde4; }
.msg.highlight .bubble { outline: 2px solid #f5a623; transition: outline .3s; }
.meta .pin { font-size: .75rem; }
.meta .tme { color: #9aa7b3; text-decoration: none; font-size: .8rem; }
.meta .tme:hover { color: #3a6d99; }
.meta .time em { font-style: normal; font-size: .7rem; }

/* цитата ответа */
.reply {
  display: block;
  border-left: 3px solid #517da2;
  background: #f2f6fa;
  border-radius: 4px;
  padding: 4px 8px;
  margin: 2px 0 4px;
  text-decoration: none;
  color: inherit;
  font-size: .85rem;
}
.reply:hover { background: #e7eff6; }
.reply-name { display: block; color: #3a6d99; font-weight: 600; }
.reply-excerpt {
  display: block;
  color: #55636f;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 480px;
}
.reply-missing { color: #9aa7b3; font-style: italic; }

/* альбомы */
.album { display: grid; gap: 2px; border-radius: 8px; overflow: hidden; margin: 4px 0; }
.album-2 { grid-template-columns: repeat(2, 1fr); }
.album-3 { grid-template-columns: repeat(3, 1fr); }
.album-4 { grid-template-columns: repeat(2, 1fr); }
.album a { display: block; line-height: 0; }
.album-img { width: 100%; height: 100%; max-height: 240px; object-fit: cover; display: block; }
.album .doc { line-height: 1.4; padding: 6px; }

/* превью ссылки */
.webpage {
  display: block;
  border-left: 3px solid #517da2;
  background: #f2f6fa;
  border-radius: 4px;
  padding: 6px 10px;
  margin: 4px 0;
  text-decoration: none;
  color: inherit;
  font-size: .85rem;
}
.webpage:hover { background: #e7eff6; }
.webpage-site { display: block; color: #3a6d99; font-weight: 600; }
.webpage-title { display: block; font-weight: 600; }
.webpage-desc { display: block; color: #55636f; }

/* реакции */
.reactions { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 4px; }
.reaction {
  background: #eaf1f7;
  border-radius: 12px;
  padding: 2px 8px;
  font-size: .8rem;
  color: #3a6d99;
}

/* форматирование текста */
.text a { color: #3a6d99; }
.text code {
  background: #f0f2f5;
  border-radius: 4px;
  padding: 1px 4px;
  font-size: .85em;
}
.text pre {
  background: #f0f2f5;
  border-radius: 6px;
  padding: 8px;
  overflow-x: auto;
  font-size: .85em;
  margin: 4px 0;
}
.text blockquote {
  border-left: 3px solid #c8d2db;
  margin: 4px 0;
  padding: 2px 8px;
  color: #55636f;
}
.text .mention { color: #3a6d99; }
.text .hashtag { color: #3a6d99; }
.text .spoiler {
  background: #d5dde4;
  color: transparent;
  border-radius: 3px;
  transition: color .15s, background .15s;
  cursor: pointer;
}
.text .spoiler:hover { background: transparent; color: inherit; }

/* лайтбокс */
.lb-overlay {
  position: fixed;
  inset: 0;
  z-index: 100;
  background: rgba(0,0,0,.85);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
  cursor: zoom-out;
}
.lb-overlay img {
  max-width: 95vw;
  max-height: 88vh;
  border-radius: 6px;
}
.lb-orig {
  color: #cfe3f5;
  font-size: .9rem;
}

/* поиск */
.searchform { display: flex; gap: 8px; margin-bottom: 16px; flex-wrap: wrap; }
.searchform input[type="search"] {
  flex: 1 1 260px;
  padding: 8px 12px;
  border: 1px solid #c8d2db;
  border-radius: 8px;
  font-size: .95rem;
}
.searchform select, .searchform button {
  padding: 8px 12px;
  border: 1px solid #c8d2db;
  border-radius: 8px;
  background: #fff;
  font-size: .9rem;
}
.searchform button { background: #517da2; color: #fff; border-color: #517da2; cursor: pointer; }
.notice { color: #6b7a8a; }
.notice code { background: #fff; padding: 2px 6px; border-radius: 4px; }
.results { list-style: none; padding: 0; margin: 0; }
.result { background: #fff; border-radius: 10px; margin-bottom: 8px; }
.result-link { display: block; padding: 10px 14px; text-decoration: none; color: inherit; }
.result-link:hover { background: #f2f6fa; border-radius: 10px; }
.result-meta { display: block; color: #6b7a8a; font-size: .8rem; margin-bottom: 4px; }
.result-snippet { display: block; font-size: .95rem; }
.result-snippet mark { background: #ffe28a; padding: 0 1px; border-radius: 2px; }

/* мобильная вёрстка: сайдбар — выдвижной ящик поверх контента */
@media (max-width: 768px) {
  .menu-btn { display: block; }
  .topsearch input { min-width: 0; width: 120px; }
  .sidebar {
    position: fixed;
    top: 0;
    bottom: 0;
    left: 0;
    width: min(82vw, 320px);
    z-index: 60;
    transform: translateX(-105%);
    transition: transform .2s ease;
    box-shadow: 2px 0 12px rgba(0,0,0,.25);
    border-right: none;
  }
  .layout.sidebar-open .sidebar { transform: translateX(0); }
  .layout.sidebar-open .backdrop {
    display: block;
    position: fixed;
    inset: 0;
    z-index: 50;
    background: rgba(0,0,0,.4);
  }
  .content { padding: 8px; }
  .bubble { max-width: 88%; }
  .avatar { flex-basis: 30px; width: 30px; height: 30px; font-size: .7rem; }
  .reply-excerpt { max-width: 62vw; }
  .media-img, .media-video { max-height: 320px; }
  .meta .tme { display: none; }
}
