:root {
  --bg: #0f1115;
  --surface: #171a21;
  --surface-2: #1f232c;
  --border: #2a2f3a;
  --text: #e7eaf0;
  --text-dim: #9aa3b2;
  --accent: #4f8cff;
  --accent-soft: rgba(79, 140, 255, 0.14);
  --radius: 12px;
  --shadow: 0 4px 20px rgba(0, 0, 0, 0.35);
  --maxw: 1400px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  font-size: 15px;
  line-height: 1.5;
}

/* ---------- Top bar ---------- */
.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  gap: 24px;
  padding: 14px 24px;
  background: rgba(15, 17, 21, 0.9);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border);
}
.brand { display: flex; align-items: center; gap: 12px; min-width: 0; }
.brand-mark { font-size: 28px; }
.brand h1 { font-size: 17px; margin: 0; font-weight: 650; letter-spacing: -0.01em; }
.tagline { margin: 0; font-size: 12.5px; color: var(--text-dim); }

/* ---------- Mode tabs ---------- */
.mode-tabs { display: flex; gap: 4px; background: var(--surface-2); border: 1px solid var(--border); border-radius: 10px; padding: 3px; }
.mode-tabs button {
  border: 0; background: transparent; color: var(--text-dim); cursor: pointer;
  padding: 7px 14px; border-radius: 7px; font-size: 13.5px; font-weight: 550; transition: all 0.12s;
}
.mode-tabs button:hover { color: var(--text); }
.mode-tabs button.active { background: var(--accent); color: #fff; }

.search-wrap { position: relative; flex: 1; max-width: 480px; margin-left: auto; }
/* Hide search + sidebar while viewing analytics. */
body.mode-analytics .search-wrap { visibility: hidden; }
body.mode-analytics .sidebar { display: none; }
#search {
  width: 100%;
  padding: 11px 40px 11px 16px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 10px;
  color: var(--text);
  font-size: 14.5px;
  outline: none;
  transition: border-color 0.15s, box-shadow 0.15s;
}
#search:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.search-hint {
  position: absolute; right: 12px; top: 50%; transform: translateY(-50%);
  font-size: 12px; color: var(--text-dim);
  border: 1px solid var(--border); border-radius: 5px; padding: 1px 7px; background: var(--surface);
}

/* ---------- Layout ---------- */
.layout { display: flex; max-width: var(--maxw); margin: 0 auto; }
.sidebar {
  width: 250px;
  flex-shrink: 0;
  padding: 20px 16px;
  border-right: 1px solid var(--border);
  position: sticky;
  top: 61px;
  height: calc(100vh - 61px);
  overflow-y: auto;
}
.content { flex: 1; padding: 22px 28px 80px; min-width: 0; }

/* ---------- Category nav ---------- */
#category-nav { display: flex; flex-direction: column; gap: 2px; margin-bottom: 22px; }
.cat-btn {
  display: flex; align-items: center; gap: 10px;
  width: 100%; text-align: left;
  padding: 8px 10px; border: 0; border-radius: 8px;
  background: transparent; color: var(--text); cursor: pointer;
  font-size: 14px; transition: background 0.12s;
}
.cat-btn:hover { background: var(--surface-2); }
.cat-btn.active { background: var(--accent-soft); color: #cfe0ff; font-weight: 600; }
.cat-btn .cat-icon { font-size: 16px; width: 20px; text-align: center; }
.cat-btn .cat-count { margin-left: auto; font-size: 12px; color: var(--text-dim); }

/* ---------- Filters ---------- */
.filters h3 { font-size: 12px; text-transform: uppercase; letter-spacing: 0.06em; color: var(--text-dim); margin: 0 0 10px; }
.chip-row { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 18px; }
.chip {
  padding: 5px 11px; border-radius: 999px; border: 1px solid var(--border);
  background: var(--surface-2); color: var(--text-dim); cursor: pointer; font-size: 12.5px;
  transition: all 0.12s;
}
.chip:hover { color: var(--text); border-color: var(--text-dim); }
.chip.active { background: var(--accent); border-color: var(--accent); color: #fff; }
.toggle { display: flex; align-items: center; gap: 8px; font-size: 13px; color: var(--text-dim); cursor: pointer; }
.toggle input { accent-color: var(--accent); }
.sidebar-foot { margin-top: 24px; font-size: 11.5px; color: var(--text-dim); }

/* ---------- Content head ---------- */
.content-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; margin-bottom: 18px; flex-wrap: wrap; }
#view-title { margin: 0; font-size: 22px; letter-spacing: -0.01em; }
.view-blurb { margin: 4px 0 0; color: var(--text-dim); font-size: 13.5px; }
.content-controls { display: flex; align-items: center; gap: 12px; }
.result-count { font-size: 13px; color: var(--text-dim); white-space: nowrap; }
#sort {
  background: var(--surface-2); color: var(--text); border: 1px solid var(--border);
  border-radius: 8px; padding: 7px 10px; font-size: 13px; cursor: pointer;
}
.view-toggle { display: flex; border: 1px solid var(--border); border-radius: 8px; overflow: hidden; }
.view-toggle button { background: var(--surface-2); color: var(--text-dim); border: 0; padding: 7px 11px; cursor: pointer; font-size: 15px; }
.view-toggle button.active { background: var(--accent); color: #fff; }

/* ---------- Grid ---------- */
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 16px; }
.grid.list-mode { grid-template-columns: 1fr; gap: 8px; }

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  display: flex; flex-direction: column;
  text-decoration: none; color: inherit;
  transition: transform 0.12s, border-color 0.12s, box-shadow 0.12s;
}
.card:hover { transform: translateY(-3px); border-color: var(--accent); box-shadow: var(--shadow); }

.thumb {
  position: relative;
  aspect-ratio: 16 / 10;
  background: var(--surface-2);
  display: flex; align-items: center; justify-content: center;
  overflow: hidden;
}
.thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.thumb .thumb-fallback { font-size: 42px; opacity: 0.8; }
.type-badge {
  position: absolute; top: 8px; left: 8px;
  font-size: 10.5px; font-weight: 600; letter-spacing: 0.03em;
  padding: 3px 8px; border-radius: 6px; background: rgba(0,0,0,0.6); color: #fff;
  backdrop-filter: blur(4px);
}
.internal-badge {
  position: absolute; top: 8px; right: 8px;
  font-size: 10px; padding: 2px 7px; border-radius: 6px;
  background: rgba(255, 176, 32, 0.9); color: #1a1205; font-weight: 600;
}

.card-body { padding: 12px 13px 14px; display: flex; flex-direction: column; gap: 8px; flex: 1; }
.card-title { font-size: 14px; font-weight: 600; line-height: 1.35; }
.card-meta { font-size: 11.5px; color: var(--text-dim); display: flex; gap: 8px; flex-wrap: wrap; margin-top: auto; }
.card-meta .dot::before { content: "·"; margin-right: 8px; }
.tag-row { display: flex; flex-wrap: wrap; gap: 5px; }
.tag { font-size: 10.5px; color: var(--text-dim); background: var(--surface-2); border: 1px solid var(--border); padding: 1px 7px; border-radius: 999px; }

/* ---------- List mode ---------- */
.list-mode .card { flex-direction: row; align-items: center; }
.list-mode .thumb { width: 92px; aspect-ratio: 1 / 1; flex-shrink: 0; }
.list-mode .card-body { padding: 10px 14px; }
.list-mode .card-meta { margin-top: 4px; }

/* ---------- Empty ---------- */
.empty { text-align: center; padding: 80px 20px; color: var(--text-dim); }

/* ---------- Section headers in "All" view ---------- */
.section-head { grid-column: 1 / -1; margin: 18px 0 2px; padding-top: 6px; display: flex; align-items: baseline; gap: 10px; }
.section-head:first-child { margin-top: 0; }
.section-head h3 { margin: 0; font-size: 15px; }
.section-head .sec-icon { font-size: 16px; }
.section-head .sec-count { font-size: 12px; color: var(--text-dim); }

/* ---------- Analytics dashboard ---------- */
.metrics-source { margin: 0 0 26px; }
.metrics-source > h3 {
  display: flex; align-items: center; gap: 8px;
  font-size: 14px; margin: 0 0 12px; color: var(--text-dim);
  text-transform: uppercase; letter-spacing: 0.05em;
}
.metrics-source > h3 .src-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--accent); }

.stat-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; margin-bottom: 16px; }
.stat {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 14px 16px;
}
.stat .stat-label { font-size: 12px; color: var(--text-dim); margin-bottom: 6px; }
.stat .stat-value { font-size: 26px; font-weight: 650; letter-spacing: -0.02em; line-height: 1.1; }
.stat .stat-delta { font-size: 12px; margin-top: 4px; }
.stat .stat-delta.up { color: #4ade80; }
.stat .stat-delta.down { color: #f87171; }
.stat .stat-delta.flat { color: var(--text-dim); }

.panel-grid { display: grid; grid-template-columns: 1.4fr 1fr; gap: 16px; }
.panel {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 16px;
}
.panel h4 { margin: 0 0 14px; font-size: 13.5px; }

/* Sparkline / trend chart */
.chart svg { width: 100%; height: 120px; display: block; }
.chart .axis { font-size: 10px; fill: var(--text-dim); }

/* 12-month bar chart */
.month-bars { display: flex; align-items: flex-end; gap: 6px; height: 150px; padding-top: 4px; }
.month-bars .mb { flex: 1; display: flex; flex-direction: column; align-items: center; height: 100%; min-width: 0; }
.month-bars .mb-val { font-size: 10px; color: var(--text-dim); margin-bottom: 3px; white-space: nowrap; }
.month-bars .mb-track { flex: 1; width: 100%; display: flex; align-items: flex-end; }
.month-bars .mb-bar { width: 100%; min-height: 2px; border-radius: 3px 3px 0 0; transition: opacity 0.12s; }
.month-bars .mb:hover .mb-bar { opacity: 0.75; }
.month-bars .mb-label { font-size: 10.5px; color: var(--text-dim); margin-top: 6px; }

/* Mini tables */
.metric-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.metric-table td { padding: 7px 4px; border-bottom: 1px solid var(--border); }
.metric-table tr:last-child td { border-bottom: 0; }
.metric-table td.label { color: var(--text); max-width: 0; width: 99%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.metric-table td.val { color: var(--text-dim); text-align: right; white-space: nowrap; padding-left: 14px; }

/* Channel bars */
.bar-row { display: grid; grid-template-columns: 110px 1fr 52px; align-items: center; gap: 10px; margin-bottom: 9px; font-size: 12.5px; }
.bar-row .bar-label { color: var(--text-dim); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bar-track { background: var(--surface-2); border-radius: 6px; height: 9px; overflow: hidden; }
.bar-fill { height: 100%; background: var(--accent); border-radius: 6px; }
.bar-row .bar-val { text-align: right; color: var(--text-dim); }

/* Connect / empty states */
.connect-card {
  background: var(--surface); border: 1px dashed var(--border); border-radius: var(--radius);
  padding: 36px 28px; text-align: center; color: var(--text-dim); max-width: 640px;
}
.connect-card h3 { color: var(--text); margin: 0 0 8px; }
.connect-card code { background: var(--surface-2); padding: 1px 6px; border-radius: 5px; color: #cfe0ff; font-size: 12.5px; }
.connect-card .steps { text-align: left; display: inline-block; margin-top: 12px; line-height: 1.8; }
.source-error { font-size: 12.5px; color: #f8a; background: rgba(248,113,113,0.08); border: 1px solid rgba(248,113,113,0.25); border-radius: 8px; padding: 10px 12px; }
.source-pending { font-size: 13px; color: var(--text-dim); background: var(--surface); border: 1px dashed var(--border); border-radius: 8px; padding: 12px 14px; }
.source-pending strong { color: var(--text); font-weight: 600; }
.source-pending .pending-note { display: block; margin-top: 4px; font-size: 11.5px; opacity: 0.65; }
.connect-btn {
  display: inline-flex; align-items: center; gap: 8px;
  background: var(--accent); color: #fff; border: 0; border-radius: 8px;
  padding: 9px 16px; font-size: 13.5px; font-weight: 600; cursor: pointer; transition: filter 0.12s;
}
.connect-btn::before { content: "🔵"; font-size: 12px; }
.connect-btn:hover { filter: brightness(1.1); }

@media (max-width: 760px) { .panel-grid { grid-template-columns: 1fr; } }

/* ---------- Responsive ---------- */
@media (max-width: 860px) {
  .layout { flex-direction: column; }
  .sidebar { width: auto; position: static; height: auto; border-right: 0; border-bottom: 1px solid var(--border); }
  #category-nav { flex-direction: row; flex-wrap: wrap; }
  .cat-btn { width: auto; }
  .cat-btn .cat-count { display: none; }
  .search-wrap { max-width: none; }
  .brand .tagline { display: none; }
}
