:root {
  --bg: #0f1117;
  --bg-card: #1a1d27;
  --bg-hover: #252836;
  --border: #2d3142;
  --text: #e8eaed;
  --muted: #8b92a5;
  --accent: #5181b8;
  --accent-hover: #5b88bd;
  --green: #4bb34b;
  --orange: #ffa000;
  --red: #e64646;
  --radius: 12px;
  --shadow: 0 4px 24px rgba(0,0,0,.35);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

body {
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  line-height: 1.5;
}

a { color: var(--accent); text-decoration: none; }
code {
  background: var(--bg-hover);
  padding: 2px 6px;
  border-radius: 4px;
  font-size: 0.85em;
}

.muted { color: var(--muted); font-size: 0.875rem; }
.empty { color: var(--muted); padding: 1rem 0; font-style: italic; text-align: center; }

/* Scroll panels */
.scroll-panel {
  overflow-y: auto;
  overflow-x: hidden;
  scrollbar-width: thin;
  scrollbar-color: var(--border) transparent;
}
.scroll-panel::-webkit-scrollbar { width: 6px; }
.scroll-panel::-webkit-scrollbar-track { background: transparent; }
.scroll-panel::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 3px;
}
.scroll-panel::-webkit-scrollbar-thumb:hover { background: var(--muted); }
.scroll-panel-sm { max-height: 220px; }

/* Login */
.login-page {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  background: radial-gradient(ellipse at top, #1a2744 0%, var(--bg) 60%);
}
.login-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 2.5rem;
  width: 100%;
  max-width: 400px;
  box-shadow: var(--shadow);
  text-align: center;
}
.login-logo {
  width: 56px; height: 56px;
  background: var(--accent);
  border-radius: 14px;
  display: flex; align-items: center; justify-content: center;
  font-weight: 700; font-size: 1.25rem;
  margin: 0 auto 1rem;
}
.login-card h1 { font-size: 1.5rem; margin-bottom: 0.25rem; }
.subtitle { color: var(--muted); margin-bottom: 1.5rem; }
.login-card label { display: block; text-align: left; margin-bottom: 0.5rem; font-size: 0.875rem; }
.login-card input {
  width: 100%;
  padding: 0.75rem 1rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg);
  color: var(--text);
  font-size: 1rem;
  margin-bottom: 1rem;
}
.login-card input:focus { outline: none; border-color: var(--accent); }

/* Buttons */
.btn {
  display: inline-flex; align-items: center; justify-content: center;
  padding: 0.6rem 1.2rem;
  border-radius: 8px;
  border: none;
  font-size: 0.9rem;
  font-weight: 500;
  cursor: pointer;
  transition: background .15s;
}
.btn-primary { background: var(--accent); color: #fff; width: 100%; }
.btn-primary:hover { background: var(--accent-hover); }
.btn-secondary { background: var(--bg-hover); color: var(--text); border: 1px solid var(--border); }
.btn-secondary:hover { background: var(--border); }
.btn-ghost { background: transparent; color: var(--muted); text-decoration: none; }
.btn-ghost:hover { color: var(--text); }

/* Topbar */
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 1rem 1.5rem;
  background: var(--bg-card);
  border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 100;
}
.topbar-left { display: flex; align-items: center; gap: 1rem; }
.logo-badge {
  width: 40px; height: 40px;
  background: var(--accent);
  border-radius: 10px;
  display: flex; align-items: center; justify-content: center;
  font-weight: 700;
}
.topbar h1 { font-size: 1.15rem; }
.topbar-sub { font-size: 0.8rem; color: var(--muted); }
.topbar-actions { display: flex; gap: 0.5rem; align-items: center; }

.container { max-width: 1680px; margin: 0 auto; padding: 1.25rem 1.5rem 2rem; }

/* Stats */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  gap: 0.75rem;
  margin-bottom: 1.25rem;
}
@media (max-width: 1100px) {
  .stats-grid { grid-template-columns: repeat(3, 1fr); }
}
@media (max-width: 600px) {
  .stats-grid { grid-template-columns: repeat(2, 1fr); }
}
.stat-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.85rem 1rem;
  display: flex; flex-direction: column; gap: 0.15rem;
}
.stat-label { font-size: 0.7rem; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
.stat-value { font-size: 1.35rem; font-weight: 700; color: var(--accent); }

/* Main layout: sidebar | messages | logs */
.layout-grid {
  display: grid;
  grid-template-columns: 240px minmax(0, 1fr) 400px;
  gap: 1rem;
  margin-bottom: 1rem;
  align-items: start;
}
@media (max-width: 1200px) {
  .layout-grid { grid-template-columns: 1fr; }
}

.column { display: flex; flex-direction: column; gap: 1rem; min-width: 0; }

/* Cards */
.card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem 1.15rem;
}
.card h2 {
  font-size: 0.95rem;
  font-weight: 600;
}
.card-header-row {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 0.85rem;
  padding-bottom: 0.65rem;
  border-bottom: 1px solid var(--border);
}
.card-header-row h2 { margin: 0; border: none; padding: 0; }

/* Group sidebar */
.group-header { display: flex; gap: 0.75rem; margin-bottom: 0.75rem; align-items: center; }
.group-name { font-size: 1rem; font-weight: 600; }
.group-status { color: var(--accent); font-size: 0.85rem; margin-top: 0.15rem; }
.info-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 0.4rem; font-size: 0.8rem; }
.info-grid .label { display: block; color: var(--muted); font-size: 0.7rem; }

/* Avatars */
.avatar-lg { width: 56px; height: 56px; border-radius: 50%; object-fit: cover; flex-shrink: 0; }
.avatar-md { width: 44px; height: 44px; border-radius: 50%; object-fit: cover; }
.avatar-sm { width: 36px; height: 36px; border-radius: 50%; object-fit: cover; flex-shrink: 0; }
.avatar-placeholder {
  width: 36px; height: 36px; border-radius: 50%;
  background: var(--accent);
  display: flex; align-items: center; justify-content: center;
  font-weight: 600; font-size: 0.9rem; flex-shrink: 0;
}
.avatar-placeholder.md { width: 44px; height: 44px; }

/* Messages */
.messages-card {
  display: flex;
  flex-direction: column;
  height: calc(100vh - 220px);
  min-height: 480px;
  max-height: 780px;
}
.messages-feed {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
  padding-right: 4px;
}

.message-item {
  display: flex; gap: 0.75rem;
  padding: 0.75rem;
  border-radius: 10px;
  background: var(--bg);
  border: 1px solid var(--border);
  flex-shrink: 0;
}
.message-item.event-new { border-left: 3px solid var(--green); }
.message-item.event-reply { border-left: 3px solid var(--accent); }
.message-item.event-edit { border-left: 3px solid var(--orange); }

.msg-header { display: flex; flex-wrap: wrap; align-items: center; gap: 0.4rem; margin-bottom: 0.2rem; }
.user-name { font-weight: 600; font-size: 0.9rem; }
.username { color: var(--accent); font-size: 0.8rem; }
.msg-time { margin-left: auto; font-size: 0.72rem; color: var(--muted); white-space: nowrap; }
.msg-meta { margin-bottom: 0.25rem; font-size: 0.75rem; }
.msg-text {
  white-space: pre-wrap;
  word-break: break-word;
  font-size: 0.9rem;
  line-height: 1.45;
}

/* Badges */
.badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 0.68rem;
  font-weight: 600;
  background: var(--bg-hover);
  color: var(--muted);
}
.badge-new { background: rgba(75,179,75,.2); color: var(--green); }
.badge-reply { background: rgba(81,129,184,.2); color: var(--accent); }
.badge-edit { background: rgba(255,160,0,.2); color: var(--orange); }
.badge-ok { background: rgba(75,179,75,.15); color: var(--green); }
.badge-muted { background: rgba(139,146,165,.15); color: var(--muted); }
.event-badge { text-transform: uppercase; letter-spacing: .03em; }

/* Connections */
.connections-list { display: flex; flex-direction: column; gap: 0.6rem; }
.connection-item { display: flex; gap: 0.6rem; align-items: flex-start; }
.connection-body { flex: 1; min-width: 0; }
.track-badge { font-size: 0.8rem; margin-top: 0.2rem; color: var(--green); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* Logs — fixed right column */
.logs-card {
  display: flex;
  flex-direction: column;
  height: calc(100vh - 220px);
  min-height: 480px;
  max-height: 780px;
}
.logs-feed {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  padding-right: 4px;
}
.log-entry {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.5rem 0.65rem;
  flex-shrink: 0;
}
.log-entry.log-info { border-left: 3px solid var(--accent); }
.log-entry.log-warning { border-left: 3px solid var(--orange); }
.log-entry.log-error { border-left: 3px solid var(--red); }
.log-entry-head {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-bottom: 0.25rem;
}
.log-time {
  font-family: "Consolas", monospace;
  font-size: 0.72rem;
  color: var(--muted);
}
.log-level {
  font-size: 0.68rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .04em;
  padding: 1px 6px;
  border-radius: 4px;
  background: var(--bg-hover);
}
.log-info .log-level { color: var(--accent); }
.log-warning .log-level { color: var(--orange); }
.log-error .log-level { color: var(--red); }
.log-msg {
  font-family: "Consolas", "Cascadia Code", monospace;
  font-size: 0.72rem;
  line-height: 1.45;
  overflow-wrap: anywhere;
  word-break: break-word;
  color: var(--text);
}

/* Dialogs — full width grid */
.dialogs-card { margin-bottom: 1rem; }
.dialogs-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
  gap: 0.6rem;
  margin-bottom: 1rem;
}
.dialog-item {
  display: flex;
  gap: 0.75rem;
  padding: 0.75rem;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 10px;
  transition: border-color .15s, background .15s, box-shadow .15s;
  cursor: pointer;
  user-select: none;
}
.dialog-item:hover {
  border-color: var(--accent);
  background: var(--bg-hover);
}
.dialog-item-active {
  border-color: var(--accent);
  background: rgba(81, 129, 184, 0.12);
  box-shadow: 0 0 0 1px var(--accent);
}
.dialogs-hint {
  font-size: 0.8rem;
  margin-bottom: 0.75rem;
}

/* Dialog viewer / chat thread */
.dialog-viewer {
  margin-bottom: 1.25rem;
  border: 1px solid var(--accent);
  border-radius: var(--radius);
  background: var(--bg);
  overflow: hidden;
}
.dialog-viewer-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.85rem 1rem;
  background: var(--bg-hover);
  border-bottom: 1px solid var(--border);
}
.dialog-viewer-user {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}
.chat-thread {
  max-height: 520px;
  min-height: 200px;
  padding: 1rem;
  display: flex;
  flex-direction: column;
}
.chat-meta {
  font-size: 0.78rem;
  margin-bottom: 0.75rem;
  flex-shrink: 0;
}
.chat-messages {
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
}
.chat-bubble {
  display: flex;
  gap: 0.5rem;
  max-width: 85%;
}
.chat-bubble.chat-in {
  align-self: flex-start;
}
.chat-bubble.chat-out {
  align-self: flex-end;
  flex-direction: row-reverse;
}
.chat-bubble-avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  flex-shrink: 0;
  margin-top: 0.25rem;
}
.chat-bubble-body {
  padding: 0.55rem 0.75rem;
  border-radius: 12px;
  font-size: 0.88rem;
  line-height: 1.45;
}
.chat-in .chat-bubble-body {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-bottom-left-radius: 4px;
}
.chat-out .chat-bubble-body {
  background: rgba(81, 129, 184, 0.25);
  border: 1px solid rgba(81, 129, 184, 0.4);
  border-bottom-right-radius: 4px;
}
.chat-bubble-head {
  display: flex;
  align-items: baseline;
  gap: 0.5rem;
  margin-bottom: 0.2rem;
}
.chat-author {
  font-size: 0.72rem;
  font-weight: 600;
  color: var(--accent);
}
.chat-out .chat-author { color: var(--green); }
.chat-time {
  font-size: 0.68rem;
  color: var(--muted);
}
.chat-text {
  white-space: pre-wrap;
  word-break: break-word;
}
.dialog-avatar { position: relative; flex-shrink: 0; }
.dialog-unread {
  position: absolute;
  top: -4px; right: -4px;
  min-width: 18px; height: 18px;
  background: var(--orange);
  color: #000;
  font-size: 0.65rem;
  font-weight: 700;
  border-radius: 999px;
  display: flex; align-items: center; justify-content: center;
  padding: 0 4px;
}
.dialog-body { flex: 1; min-width: 0; }
.dialog-top {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 0.5rem;
  margin-bottom: 0.25rem;
}
.dialog-peer {
  font-size: 0.7rem;
  color: var(--muted);
  white-space: nowrap;
  flex-shrink: 0;
}
.dialog-msg {
  font-size: 0.85rem;
  color: var(--muted);
  line-height: 1.4;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

/* Pagination */
.pagination {
  display: flex;
  align-items: center;
  justify-content: center;
  flex-wrap: wrap;
  gap: 0.35rem;
  padding-top: 0.5rem;
  border-top: 1px solid var(--border);
}
.page-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 36px;
  height: 36px;
  padding: 0 0.5rem;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  font-size: 0.85rem;
  font-weight: 500;
  text-decoration: none;
  transition: background .15s, border-color .15s;
}
a.page-btn:hover {
  background: var(--bg-hover);
  border-color: var(--accent);
  text-decoration: none;
}
.page-btn.active {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
  cursor: default;
}
.page-btn.disabled {
  opacity: 0.35;
  cursor: not-allowed;
}
.page-ellipsis {
  color: var(--muted);
  padding: 0 0.25rem;
  user-select: none;
}
.pagination-info {
  text-align: center;
  margin-top: 0.5rem;
  font-size: 0.8rem;
}

/* Wall */
.wall-card .wall-post {
  padding: 0.6rem 0;
  border-bottom: 1px solid var(--border);
  font-size: 0.82rem;
}
.wall-post:last-child { border: none; }

/* VK Explorer */
.vk-explorer { margin-top: 0; }
.explorer-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 0.5rem;
  margin-top: 0.75rem;
}
.explorer-item {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
}
.explorer-item summary {
  padding: 0.65rem 0.85rem;
  cursor: pointer;
  display: flex; align-items: center; gap: 0.5rem;
  font-size: 0.82rem;
  list-style: none;
}
.explorer-item summary::-webkit-details-marker { display: none; }
.explorer-key { font-weight: 600; color: var(--accent); }
.explorer-body { padding: 0 0.85rem 0.85rem; }
.explorer-body pre {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 0.65rem;
  overflow: auto;
  font-size: 0.68rem;
  max-height: 260px;
  white-space: pre-wrap;
  word-break: break-word;
}

.alert { padding: 0.6rem 0.85rem; border-radius: 8px; margin-bottom: 0.5rem; font-size: 0.8rem; }
.alert-muted { background: rgba(139,146,165,.1); color: var(--muted); border: 1px solid var(--border); }
.alert-error { background: rgba(230,70,70,.15); color: var(--red); border: 1px solid rgba(230,70,70,.3); }
