:root {
  --bg: #0b0f1a;
  --bg-elev: #121829;
  --bg-elev2: #1a2236;
  --border: #243049;
  --text: #e7ecf5;
  --muted: #8a96ad;
  --primary: #6366f1;
  --primary-2: #8b5cf6;
  --green: #34d399;
  --red: #f87171;
  --amber: #fbbf24;
  --cyan: #22d3ee;
  --shadow: 0 8px 30px rgba(0, 0, 0, 0.35);
  --radius: 14px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: "Inter", system-ui, -apple-system, "Segoe UI", sans-serif;
  -webkit-font-smoothing: antialiased;
}

.app {
  display: grid;
  grid-template-columns: 264px 1fr;
  min-height: 100vh;
}

/* Sidebar */
.sidebar {
  background: var(--bg-elev);
  border-right: 1px solid var(--border);
  padding: 22px 18px;
  display: flex;
  flex-direction: column;
  gap: 22px;
  position: sticky;
  top: 0;
  height: 100vh;
}

.brand { display: flex; align-items: center; gap: 12px; }
.brand-mark {
  width: 40px; height: 40px; border-radius: 11px;
  background: linear-gradient(135deg, var(--primary), var(--primary-2));
  display: grid; place-items: center; font-size: 18px; color: white;
  box-shadow: 0 6px 18px rgba(99, 102, 241, 0.4);
}
.brand-text { display: flex; flex-direction: column; line-height: 1.2; }
.brand-text strong { font-size: 16px; }
.brand-text span { font-size: 12px; color: var(--muted); }

.filters { display: flex; flex-direction: column; gap: 8px; }
.filter-label {
  font-size: 11px; text-transform: uppercase; letter-spacing: 0.06em;
  color: var(--muted); margin-top: 8px; font-weight: 600;
}
.filters select, .filters input, .modal input, .modal select {
  background: var(--bg-elev2);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 9px 11px;
  border-radius: 9px;
  font-size: 13px;
  font-family: inherit;
  outline: none;
  transition: border-color .15s, box-shadow .15s;
}
.filters select:focus, .filters input:focus,
.modal input:focus, .modal select:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.18);
}

.sidebar-actions { display: flex; flex-direction: column; gap: 10px; margin-top: auto; }
.io-row { display: flex; gap: 8px; }
.io-row .btn-ghost { flex: 1; }

.sidebar-foot { font-size: 11px; color: var(--muted); text-align: center; }

/* Buttons */
.btn-primary {
  background: linear-gradient(135deg, var(--primary), var(--primary-2));
  color: white; border: none; padding: 11px 14px; border-radius: 10px;
  font-weight: 600; font-size: 14px; cursor: pointer; font-family: inherit;
  transition: transform .12s, box-shadow .12s;
  box-shadow: 0 6px 18px rgba(99, 102, 241, 0.35);
}
.btn-primary:hover { transform: translateY(-1px); box-shadow: 0 9px 24px rgba(99,102,241,.45); }
.btn-ghost {
  background: var(--bg-elev2); color: var(--text);
  border: 1px solid var(--border); padding: 9px 12px; border-radius: 9px;
  font-size: 13px; cursor: pointer; font-family: inherit; font-weight: 500;
  transition: border-color .15s, background .15s;
}
.btn-ghost:hover { border-color: var(--primary); background: #20293f; }
.btn-ghost.sm { padding: 8px 10px; font-size: 12px; }
.btn-ghost.danger { color: var(--red); }
.btn-ghost.danger:hover { border-color: var(--red); }

/* Main */
.main { padding: 26px 30px 40px; max-width: 1400px; }
.topbar { display: flex; justify-content: space-between; align-items: flex-start; gap: 16px; margin-bottom: 22px; }
.topbar h1 { margin: 0; font-size: 24px; font-weight: 800; letter-spacing: -0.02em; }
.subtitle { margin: 4px 0 0; color: var(--muted); font-size: 14px; }
.topbar-meta { font-size: 13px; color: var(--muted); text-align: right; }

/* KPIs */
.kpis { display: grid; grid-template-columns: repeat(6, 1fr); gap: 14px; margin-bottom: 22px; }
.kpi {
  background: var(--bg-elev); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 16px; box-shadow: var(--shadow);
}
.kpi .kpi-label { font-size: 12px; color: var(--muted); font-weight: 600; }
.kpi .kpi-value { font-size: 22px; font-weight: 800; margin-top: 8px; letter-spacing: -0.02em; }
.kpi .kpi-sub { font-size: 11px; color: var(--muted); margin-top: 4px; }
.kpi-accent { height: 3px; width: 32px; border-radius: 3px; margin-bottom: 10px; }

/* Charts */
.charts { display: grid; grid-template-columns: 1.6fr 1fr; gap: 16px; margin-bottom: 22px; }
.card {
  background: var(--bg-elev); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 18px; box-shadow: var(--shadow);
}
.card-head { display: flex; justify-content: space-between; align-items: baseline; margin-bottom: 14px; gap: 12px; }
.card-head h3 { margin: 0; font-size: 15px; font-weight: 700; }
.hint { font-size: 12px; color: var(--muted); }
.chart-card canvas { max-height: 280px; }

/* Table */
.table-card { padding-bottom: 8px; }
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
thead th {
  text-align: left; color: var(--muted); font-weight: 600; font-size: 12px;
  padding: 10px 12px; border-bottom: 1px solid var(--border);
  cursor: pointer; user-select: none; white-space: nowrap;
}
thead th.num { text-align: right; }
thead th:hover { color: var(--text); }
tbody td { padding: 12px; border-bottom: 1px solid rgba(36,48,73,.5); vertical-align: middle; }
tbody td.num { text-align: right; font-variant-numeric: tabular-nums; }
tbody tr:hover { background: rgba(99,102,241,.06); }
.cell-title { display: flex; flex-direction: column; }
.cell-title a { color: var(--text); text-decoration: none; font-weight: 500; }
.cell-title a:hover { color: var(--primary); }
.cell-title small { color: var(--muted); font-size: 11px; margin-top: 2px; }

.pill {
  display: inline-block; padding: 3px 9px; border-radius: 999px;
  font-size: 11px; font-weight: 600; border: 1px solid var(--border);
}
.pill.YouTube { color: #ff6b6b; border-color: rgba(255,107,107,.4); background: rgba(255,107,107,.08); }
.pill.Instagram { color: #e879f9; border-color: rgba(232,121,249,.4); background: rgba(232,121,249,.08); }
.pill.TikTok { color: #22d3ee; border-color: rgba(34,211,238,.4); background: rgba(34,211,238,.08); }
.pill.X { color: #cbd5e1; border-color: rgba(203,213,225,.4); background: rgba(203,213,225,.08); }
.pill.Facebook { color: #60a5fa; border-color: rgba(96,165,250,.4); background: rgba(96,165,250,.08); }

.rate-good { color: var(--green); font-weight: 600; }
.rate-mid { color: var(--amber); font-weight: 600; }
.rate-low { color: var(--red); font-weight: 600; }

.row-actions { display: flex; gap: 6px; justify-content: flex-end; }
.icon-btn {
  background: transparent; border: 1px solid var(--border); color: var(--muted);
  width: 28px; height: 28px; border-radius: 7px; cursor: pointer; font-size: 13px;
  display: grid; place-items: center; transition: all .12s;
}
.icon-btn:hover { color: var(--text); border-color: var(--primary); }
.icon-btn.del:hover { color: var(--red); border-color: var(--red); }

.footnote { margin-top: 18px; font-size: 12px; color: var(--muted); }
.empty { text-align: center; padding: 40px; color: var(--muted); }

/* Modal */
.modal-backdrop {
  position: fixed; inset: 0; background: rgba(5,8,15,.7); backdrop-filter: blur(4px);
  display: grid; place-items: center; z-index: 50; padding: 20px;
}
/* `display: grid` above outranks the UA [hidden] rule, so toggling the
   `hidden` attribute alone won't hide the modal. This makes it actually hide. */
.modal-backdrop[hidden] { display: none; }
.modal {
  background: var(--bg-elev); border: 1px solid var(--border); border-radius: 16px;
  width: 100%; max-width: 560px; box-shadow: var(--shadow); overflow: hidden;
}
.modal-head { display: flex; justify-content: space-between; align-items: center; padding: 18px 20px; border-bottom: 1px solid var(--border); }
.modal-head h2 { margin: 0; font-size: 17px; }
.modal-body { padding: 20px; display: flex; flex-direction: column; gap: 14px; }
.modal label { display: flex; flex-direction: column; gap: 6px; font-size: 12px; color: var(--muted); font-weight: 600; min-width: 0; }
.modal input, .modal select { font-size: 13px; width: 100%; min-width: 0; }
.modal input.invalid { border-color: var(--red); box-shadow: 0 0 0 3px rgba(248,113,113,.18); }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.grid4 { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; }
.grid2 > *, .grid4 > * { min-width: 0; }
.modal-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 6px; }

@media (max-width: 1100px) {
  .kpis { grid-template-columns: repeat(3, 1fr); }
  .charts { grid-template-columns: 1fr; }
}
@media (max-width: 820px) {
  .app { grid-template-columns: 1fr; }
  .sidebar { position: relative; height: auto; }
  .kpis { grid-template-columns: repeat(2, 1fr); }
  .grid4 { grid-template-columns: 1fr 1fr; }
}
