:root {
  --bg: #f6f7f9;
  --surface: #ffffff;
  --ink: #111827;
  --muted: #6b7280;
  --line: #e5e7eb;
  --brand: #111827;
  --brand-soft: #f3f4f6;
  --ok: #059669;
  --ok-soft: #d1fae5;
  --danger: #dc2626;
  --danger-soft: #fee2e2;
  --x: #000000;
  --ig: #e1306c;
  --fb: #1877f2;
  --radius: 16px;
  --shadow: 0 1px 2px rgba(0,0,0,.04), 0 8px 24px rgba(0,0,0,.04);
  --font: "DM Sans", "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: var(--font);
  color: var(--ink);
  background: var(--bg);
  min-height: 100vh;
}
a { color: inherit; text-decoration: none; }
button, input, select { font: inherit; }

.app-shell { display: grid; grid-template-columns: 240px 1fr; min-height: 100vh; }
.sidebar {
  background: #fff;
  border-right: 1px solid var(--line);
  padding: 24px 16px;
  display: flex;
  flex-direction: column;
  gap: 24px;
  position: sticky;
  top: 0;
  height: 100vh;
}
.brand { font-weight: 700; font-size: 1.15rem; padding: 0 10px; }
.brand span { display: block; color: var(--muted); font-size: .8rem; font-weight: 500; margin-top: 4px; }
.nav { display: flex; flex-direction: column; gap: 4px; }
.nav a {
  display: flex; align-items: center; gap: 10px;
  padding: 11px 12px; border-radius: 12px; color: #374151; font-weight: 600;
}
.nav a:hover, .nav a.active { background: var(--brand-soft); color: var(--ink); }
.nav-ico { width: 18px; height: 18px; opacity: .8; }
.sidebar-footer { margin-top: auto; padding: 0 8px; color: var(--muted); font-size: .9rem; }

.main { padding: 28px; max-width: 1180px; }
.topbar { display: flex; justify-content: space-between; align-items: flex-start; gap: 16px; margin-bottom: 22px; }
.topbar h1 { margin: 0; font-size: 1.75rem; font-weight: 700; letter-spacing: -.02em; }
.topbar p { margin: 6px 0 0; color: var(--muted); }

.card, .panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}
.card { padding: 18px; }
.panel { padding: 20px; }

.card-grid { display: grid; grid-template-columns: repeat(3, minmax(0,1fr)); gap: 14px; }
.stats-grid { display: grid; grid-template-columns: repeat(5, minmax(0,1fr)); gap: 12px; margin-bottom: 18px; }
.stat-card { padding: 16px; }
.stat-card .label { color: var(--muted); font-size: .82rem; font-weight: 600; }
.stat-card .value { font-size: 1.55rem; font-weight: 700; margin-top: 6px; letter-spacing: -.02em; }
.stat-card .delta { margin-top: 6px; font-size: .85rem; font-weight: 600; }
.delta.up { color: var(--ok); }
.delta.down { color: var(--danger); }
.delta.flat { color: var(--muted); }

.account-tile {
  display: flex; flex-direction: column; gap: 14px;
  transition: transform .15s ease, box-shadow .15s ease;
  cursor: pointer;
}
.account-tile:hover { transform: translateY(-2px); box-shadow: 0 10px 28px rgba(0,0,0,.08); }
.account-tile-head { display: flex; align-items: center; gap: 12px; }
.platform-icon {
  width: 44px; height: 44px; border-radius: 12px;
  display: grid; place-items: center; color: #fff; flex-shrink: 0;
}
.platform-icon svg { width: 22px; height: 22px; fill: currentColor; }
.platform-icon.x { background: var(--x); }
.platform-icon.instagram { background: linear-gradient(135deg, #f58529, #dd2a7b 50%, #8134af); }
.platform-icon.facebook { background: var(--fb); }
.platform-icon.sm { width: 34px; height: 34px; border-radius: 10px; }
.platform-icon.sm svg { width: 16px; height: 16px; }

.account-title { font-weight: 700; }
.account-sub { color: var(--muted); font-size: .9rem; margin-top: 2px; }
.mini-metrics { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.mini-metric { background: #f9fafb; border-radius: 12px; padding: 10px; }
.mini-metric .k { color: var(--muted); font-size: .72rem; font-weight: 600; }
.mini-metric .v { font-weight: 700; margin-top: 2px; }

.badge {
  display: inline-flex; align-items: center; padding: 4px 10px;
  border-radius: 999px; font-size: .75rem; font-weight: 700;
}
.badge.ok { background: var(--ok-soft); color: var(--ok); }
.badge.err { background: var(--danger-soft); color: var(--danger); }
.badge.muted { background: var(--brand-soft); color: var(--muted); }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  border: 0; border-radius: 12px; padding: 10px 14px; cursor: pointer; font-weight: 700;
}
.btn-primary { background: var(--brand); color: #fff; }
.btn-primary:hover { opacity: .92; }
.btn-secondary { background: var(--brand-soft); color: var(--ink); }
.btn-danger { background: var(--danger-soft); color: var(--danger); }
.btn-platform { color: #fff; }
.btn-platform.x { background: #000; }
.btn-platform.instagram { background: #e1306c; }
.btn-platform.facebook { background: #1877f2; }
.btn-sm { padding: 8px 12px; font-size: .88rem; }
.actions { display: flex; flex-wrap: wrap; gap: 8px; }

.flash { padding: 12px 14px; border-radius: 12px; margin-bottom: 16px; font-weight: 600; }
.flash.success { background: var(--ok-soft); color: var(--ok); }
.flash.error { background: var(--danger-soft); color: var(--danger); }

.tabs { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 16px; }
.tab {
  padding: 8px 12px; border-radius: 999px; background: #fff;
  border: 1px solid var(--line); font-weight: 700; color: var(--muted);
}
.tab.active { background: var(--brand); color: #fff; border-color: var(--brand); }

.filter-bar {
  display: flex; flex-wrap: wrap; gap: 10px; align-items: end;
  margin-bottom: 18px; padding: 14px; background: #fff;
  border: 1px solid var(--line); border-radius: var(--radius);
}
.filter-bar .field { margin: 0; }
.filter-bar label { display: block; font-size: .8rem; color: var(--muted); font-weight: 700; margin-bottom: 6px; }
.filter-bar input, .filter-bar select {
  border: 1px solid var(--line); border-radius: 10px; padding: 9px 11px; background: #fff; min-width: 140px;
}

.chart-wrap { height: 220px; margin-top: 8px; }
.chart-empty { color: var(--muted); padding: 24px 0; }

.table { width: 100%; border-collapse: collapse; }
.table th, .table td { text-align: left; padding: 12px 10px; border-bottom: 1px solid var(--line); vertical-align: middle; }
.table th { color: var(--muted); font-size: .8rem; font-weight: 700; }

.user-card { display: flex; flex-direction: column; gap: 14px; }
.user-card-head { display: flex; align-items: center; gap: 12px; }
.avatar, .avatar-img {
  width: 44px; height: 44px; border-radius: 50%; background: #111827; color: #fff;
  display: grid; place-items: center; font-weight: 700; object-fit: cover;
  flex-shrink: 0; border: 1px solid var(--line);
}
.avatar-sm { width: 34px; height: 34px; font-size: .85rem; }
.avatar-md { width: 44px; height: 44px; }
.avatar-lg { width: 64px; height: 64px; font-size: 1.3rem; }
.avatar-fallback { background: #111827; color: #fff; }
.avatar-stack { position: relative; display: inline-flex; align-items: center; }
.avatar-stack .platform-badge {
  position: absolute; right: -4px; bottom: -4px;
  width: 18px; height: 18px; border-radius: 6px;
  display: grid; place-items: center; border: 2px solid #fff;
}
.avatar-stack .platform-badge.x { background: #000; }
.avatar-stack .platform-badge.instagram { background: #e1306c; }
.avatar-stack .platform-badge.facebook { background: #1877f2; }
.avatar-stack .platform-badge svg { width: 10px; height: 10px; fill: #fff; }
.social-row { display: flex; flex-wrap: wrap; gap: 8px; }

.auth-wrap { min-height: 100vh; display: grid; place-items: center; padding: 24px; background: var(--bg); }
.auth-card {
  width: min(420px, 100%); background: #fff; border: 1px solid var(--line);
  border-radius: 20px; box-shadow: var(--shadow); padding: 28px;
}
.auth-card h1 { margin: 0 0 8px; font-size: 1.7rem; }
.auth-card p { color: var(--muted); margin: 0 0 22px; }
.field { margin-bottom: 14px; }
.field label { display: block; margin-bottom: 6px; font-weight: 700; font-size: .9rem; }
.field input {
  width: 100%; border: 1px solid var(--line); border-radius: 12px; padding: 12px 14px; background: #fff;
}
.error-text { color: var(--danger); font-size: .88rem; margin-top: 6px; }
.auth-links { margin-top: 16px; color: var(--muted); font-size: .92rem; }
.auth-links a { color: var(--ink); font-weight: 700; text-decoration: underline; }

.connect-grid { display: grid; grid-template-columns: repeat(3, minmax(0,1fr)); gap: 14px; margin-bottom: 20px; }
.connect-card { display: flex; flex-direction: column; gap: 12px; }
.connect-card p { margin: 0; color: var(--muted); font-size: .9rem; }

.section-title { font-size: 1.05rem; font-weight: 700; margin: 0 0 12px; }
.muted { color: var(--muted); }
.split-2 { display: grid; grid-template-columns: 1.2fr .8fr; gap: 14px; }
.search { display: flex; gap: 8px; margin-bottom: 16px; }
.search input { flex: 1; border: 1px solid var(--line); border-radius: 12px; padding: 10px 12px; }

.profile-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
}
.profile-grid .label { color: var(--muted); font-size: .8rem; font-weight: 700; margin-bottom: 4px; }
.profile-value { font-size: .98rem; line-height: 1.45; word-break: break-word; }
.posts-list { display: flex; flex-direction: column; gap: 12px; }
.post-item {
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 14px;
  background: #fafafa;
}
.post-content { white-space: pre-wrap; line-height: 1.45; margin-bottom: 10px; }
.post-meta {
  display: flex; flex-wrap: wrap; gap: 10px;
  color: var(--muted); font-size: .85rem; font-weight: 600;
}
.post-meta a { color: var(--ink); text-decoration: underline; }

@media (max-width: 980px) {
  .app-shell { grid-template-columns: 1fr; }
  .sidebar { position: relative; height: auto; border-right: 0; border-bottom: 1px solid var(--line); }
  .card-grid, .connect-grid, .stats-grid, .split-2 { grid-template-columns: 1fr; }
  .topbar { flex-direction: column; }
}
