:root {
  --bg: #0d0d1a;
  --surface: #1a1a2e;
  --border: #2a2a3e;
  --text: #e8e8f0;
  --muted: #a0a0b0;
  --accent: #6366f1;
  --accent-hover: #4f52d4;
  --tg: #2aabee;
  --vk: #4680c2;
  --up: #10b981;
  --down: #ef4444;
  --radius: 12px;
  --font: 'Inter', system-ui, sans-serif;
}

*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  display: flex;
  min-height: 100vh;
}

.sidebar {
  width: 220px;
  min-height: 100vh;
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  padding: 24px 16px;
  gap: 8px;
  position: sticky;
  top: 0;
}

.logo {
  font-size: 18px;
  font-weight: 700;
  color: var(--accent);
  padding: 0 8px 16px;
  border-bottom: 1px solid var(--border);
}

.sidebar nav ul {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.sidebar nav a {
  display: block;
  padding: 10px 12px;
  border-radius: 8px;
  color: var(--muted);
  text-decoration: none;
  font-size: 14px;
  transition: background .15s, color .15s;
}

.sidebar nav a:hover,
.sidebar nav a.active {
  background: rgba(99, 102, 241, .15);
  color: var(--text);
}

.sidebar-footer {
  margin-top: auto;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.btn-refresh,
.btn-primary {
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: 8px;
  padding: 10px 16px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: background .15s, transform .1s;
  width: 100%;
}

.btn-refresh:hover,
.btn-primary:hover {
  background: var(--accent-hover);
}

.btn-refresh:active,
.btn-primary:active {
  transform: scale(.97);
}

.btn-danger {
  background: var(--down);
  color: #fff;
  border: none;
  border-radius: 6px;
  padding: 6px 12px;
  font-size: 13px;
  cursor: pointer;
}

.btn-danger:hover {
  opacity: 0.85;
}

.last-sync-label {
  font-size: 11px;
  color: var(--muted);
  text-align: center;
}

.content {
  flex: 1;
  padding: 32px 28px;
  overflow-y: auto;
}

.page-title {
  font-size: 24px;
  font-weight: 700;
  margin-bottom: 24px;
}

.cards {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 16px;
  margin-bottom: 24px;
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  transition: transform .2s, box-shadow .2s;
}

.card:hover {
  transform: translateY(-2px);
  box-shadow: 0 8px 24px rgba(0, 0, 0, .4);
}

.card-label {
  font-size: 12px;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: .05em;
  display: block;
  margin-bottom: 8px;
}

.metric-value {
  font-size: 32px;
  font-weight: 700;
  line-height: 1;
  display: block;
}

.metric-delta {
  font-size: 13px;
  margin-top: 6px;
  display: block;
}

.metric-delta.up {
  color: var(--up);
}

.metric-delta.down {
  color: var(--down);
}

.charts-row {
  display: grid;
  grid-template-columns: 1fr 340px;
  gap: 16px;
  margin-bottom: 24px;
}

.chart-box,
.compare-box,
.best-post-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
}

.chart-box h2,
.compare-box h2,
.best-post-card h2,
.posts-section h2 {
  font-size: 16px;
  font-weight: 600;
  margin-bottom: 16px;
}

.period-tabs {
  display: flex;
  gap: 8px;
  margin-top: 12px;
}

.period-tabs button {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--muted);
  border-radius: 6px;
  padding: 4px 12px;
  font-size: 13px;
  cursor: pointer;
  transition: all .15s;
}

.period-tabs button.active,
.period-tabs button:hover {
  border-color: var(--accent);
  color: var(--accent);
}

.compare-box {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.compare-platform {
  flex: 1;
  padding: 16px;
  border-radius: 8px;
  border: 1px solid var(--border);
}

.compare-platform.tg {
  border-left: 3px solid var(--tg);
}

.compare-platform.vk {
  border-left: 3px solid var(--vk);
}

.compare-platform h3 {
  font-size: 14px;
  font-weight: 600;
  margin-bottom: 10px;
}

.compare-row {
  display: flex;
  justify-content: space-between;
  font-size: 13px;
  color: var(--muted);
  padding: 3px 0;
}

.compare-row span:last-child {
  color: var(--text);
  font-weight: 500;
}

.best-post-card {
  margin-bottom: 24px;
}

.best-post-content {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.best-post-text {
  font-size: 14px;
  color: var(--muted);
  line-height: 1.5;
  max-height: 80px;
  overflow: hidden;
}

.best-post-meta {
  display: flex;
  gap: 16px;
  flex-wrap: wrap;
}

.best-post-meta span {
  font-size: 13px;
  color: var(--muted);
}

.best-post-meta strong {
  color: var(--text);
}

.best-post-link {
  font-size: 13px;
  color: var(--accent);
  text-decoration: none;
}

.best-post-link:hover {
  text-decoration: underline;
}

.posts-section {
  margin-bottom: 24px;
}

#recent-posts-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

#recent-posts-table th {
  text-align: left;
  padding: 10px 12px;
  color: var(--muted);
  font-weight: 500;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  user-select: none;
}

#recent-posts-table th:hover {
  color: var(--text);
}

#recent-posts-table td {
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  vertical-align: top;
  max-width: 300px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

#recent-posts-table tr:hover td {
  background: rgba(255, 255, 255, .03);
}

.platform-badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 4px;
  font-size: 11px;
  font-weight: 600;
}

.platform-badge.tg {
  background: rgba(42, 171, 238, .15);
  color: var(--tg);
}

.platform-badge.vk {
  background: rgba(70, 128, 194, .15);
  color: var(--vk);
}

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  display: inline-block;
  margin-right: 6px;
}

.status-dot.ok {
  background: var(--up);
}

.status-dot.err {
  background: var(--down);
}

.status-dot.pending {
  background: var(--muted);
}

#sources-list {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.source-item {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 14px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.source-info {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.source-title {
  font-size: 14px;
  font-weight: 600;
}

.source-meta {
  font-size: 12px;
  color: var(--muted);
}

.add-source-section {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  margin-bottom: 16px;
}

.add-source-section h2 {
  font-size: 15px;
  font-weight: 600;
  margin-bottom: 14px;
}

.add-source-section form {
  display: flex;
  gap: 10px;
}

input[type=text] {
  flex: 1;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 14px;
  color: var(--text);
  font-size: 14px;
  outline: none;
  transition: border-color .15s;
}

input[type=text]:focus {
  border-color: var(--accent);
}

.settings-section {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  margin-bottom: 16px;
}

.settings-section h2 {
  font-size: 15px;
  font-weight: 600;
  margin-bottom: 14px;
}

.settings-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
}

.settings-table td {
  padding: 8px 0;
  border-bottom: 1px solid var(--border);
}

.settings-table td:first-child {
  color: var(--muted);
  width: 200px;
}

#toast-container {
  position: fixed;
  bottom: 24px;
  right: 24px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  z-index: 9999;
}

.toast {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 12px 18px;
  font-size: 14px;
  min-width: 240px;
  animation: slideIn .2s ease;
}

.toast.success {
  border-left: 3px solid var(--up);
}

.toast.error {
  border-left: 3px solid var(--down);
}

.toast.info {
  border-left: 3px solid var(--accent);
}

@keyframes slideIn {
  from {
    opacity: 0;
    transform: translateX(20px);
  }
  to {
    opacity: 1;
    transform: translateX(0);
  }
}

.spinner {
  display: inline-block;
  width: 16px;
  height: 16px;
  border: 2px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin .6s linear infinite;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

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

.empty-state h3 {
  font-size: 18px;
  margin-bottom: 8px;
  color: var(--text);
}

@media (max-width: 1280px) {
  .cards {
    grid-template-columns: repeat(2, 1fr);
  }

  .charts-row {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 768px) {
  body {
    flex-direction: column;
  }

  .sidebar {
    width: 100%;
    min-height: auto;
    position: static;
    flex-direction: row;
    flex-wrap: wrap;
    padding: 12px;
  }

  .cards {
    grid-template-columns: repeat(2, 1fr);
  }

  .content {
    padding: 16px;
  }
}