/* ── Reset & Base ──────────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg: #0d0f15;
  --bg2: #161923;
  --bg3: #1f2330;
  --bg-hover: #262b3a;
  --border: #2a2e3f;
  --border2: #383d52;
  --text: #e7e9f2;
  --text2: #969ab0;
  --text3: #6a6f85;
  --accent: #10b981;
  --accent-hover: #0ea472;
  --accent2: #22d3ee;
  --danger: #f43f5e;
  --font: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  --mono: 'JetBrains Mono', 'Fira Code', ui-monospace, monospace;
  --radius: 10px;
  --radius-sm: 6px;
  --shadow: 0 4px 20px rgba(0,0,0,.35);
  --shadow-lg: 0 10px 40px rgba(0,0,0,.5);
  --ring: 0 0 0 3px rgba(16,185,129,.22);
}

html, body { height: 100%; }
body {
  background:
    radial-gradient(900px 500px at 85% -10%, rgba(34,211,238,.06), transparent 60%),
    radial-gradient(1000px 600px at 0% 0%, rgba(16,185,129,.06), transparent 55%),
    var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 14px;
  line-height: 1.5;
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
}
#app {
  display: flex;
  flex-direction: column;
  height: 100%;
}
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-thumb { background: var(--bg3); border-radius: 6px; border: 2px solid transparent; background-clip: padding-box; }
::-webkit-scrollbar-thumb:hover { background: var(--border2); background-clip: padding-box; }
a { color: var(--accent2); }

/* ── Topbar ────────────────────────────────────────────────────────────────── */
#topbar {
  display: flex; align-items: center; gap: 18px;
  padding: 0 18px;
  background: rgba(18,21,30,.85);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
  height: 56px;
  position: relative; z-index: 50;
}
.logo { font-size: 16px; font-weight: 700; white-space: nowrap; letter-spacing: -.01em; }
.tabs { display: flex; gap: 2px; }
.tab {
  background: none; border: none; color: var(--text2); cursor: pointer;
  padding: 7px 14px; border-radius: var(--radius-sm); font-size: 13px; font-weight: 500;
  transition: color .15s, background .15s;
}
.tab:hover:not(:disabled) { color: var(--text); background: var(--bg3); }
.tab.active { color: #fff; background: var(--accent); box-shadow: 0 2px 10px rgba(16,185,129,.35); }
.tab:disabled { opacity: .35; cursor: default; }

/* ── Search ────────────────────────────────────────────────────────────────── */
.search { position: relative; margin-left: auto; width: 300px; max-width: 38vw; }
.search-icon {
  position: absolute; left: 11px; top: 50%; transform: translateY(-50%);
  color: var(--text3); font-size: 16px; pointer-events: none;
}
#search-input {
  width: 100%; background: var(--bg3); border: 1px solid var(--border);
  color: var(--text); padding: 8px 34px; border-radius: 999px;
  font-size: 13px; font-family: var(--font); transition: border-color .15s, box-shadow .15s, background .15s;
}
#search-input::placeholder { color: var(--text3); }
#search-input:focus { outline: none; border-color: var(--accent); background: var(--bg2); box-shadow: var(--ring); }
.search-kbd {
  position: absolute; right: 10px; top: 50%; transform: translateY(-50%);
  font-family: var(--mono); font-size: 11px; color: var(--text3);
  background: var(--bg2); border: 1px solid var(--border); border-radius: 4px;
  padding: 1px 6px; pointer-events: none;
}
.search:focus-within .search-kbd { opacity: 0; }
.search-results {
  position: absolute; top: calc(100% + 8px); right: 0; width: 420px; max-width: 80vw;
  background: var(--bg2); border: 1px solid var(--border2); border-radius: var(--radius);
  box-shadow: var(--shadow-lg); max-height: 60vh; overflow-y: auto; padding: 6px;
}
.search-results.hidden { display: none; }
.search-empty { padding: 16px; color: var(--text3); font-size: 13px; text-align: center; }
.search-item {
  display: flex; align-items: center; gap: 10px; padding: 9px 10px;
  border-radius: var(--radius-sm); cursor: pointer;
}
.search-item:hover, .search-item.sel { background: var(--bg-hover); }
.search-item .dot { width: 8px; height: 8px; border-radius: 50%; flex-shrink: 0; }
.search-item .si-main { min-width: 0; flex: 1; }
.search-item .si-title { font-size: 13px; font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.search-item .si-path { font-family: var(--mono); font-size: 11px; color: var(--text3); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.search-item .si-label { font-size: 10px; color: var(--text2); text-transform: uppercase; letter-spacing: .04em; flex-shrink: 0; }

/* ── Status ────────────────────────────────────────────────────────────────── */
.status { display: flex; align-items: center; gap: 7px; font-size: 12px; color: var(--text2); white-space: nowrap; }
.status-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--text3); box-shadow: 0 0 0 0 rgba(0,0,0,0); }
.status.ok .status-dot { background: var(--accent); box-shadow: 0 0 8px rgba(16,185,129,.8); }
.status.err .status-dot { background: var(--danger); box-shadow: 0 0 8px rgba(244,63,94,.8); }

/* ── Main ──────────────────────────────────────────────────────────────────── */
main { flex: 1; overflow-y: auto; padding: 24px 28px; }
.tab-content { display: none; animation: fade .2s ease; }
.tab-content.active { display: block; }
@keyframes fade { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }

.section-head { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; margin-bottom: 18px; }
h2 { font-size: 20px; font-weight: 700; letter-spacing: -.02em; }
h3 { font-size: 15px; font-weight: 600; margin-bottom: 8px; }
.section-sub { font-size: 13px; color: var(--text2); }

/* ── Pipeline ──────────────────────────────────────────────────────────────── */
.pipeline-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: 14px;
}
.pipeline-card {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0;
  overflow: hidden;
  transition: border-color .15s, transform .15s, box-shadow .15s;
  position: relative;
}
.pipeline-card::before {
  content: ''; position: absolute; left: 0; top: 0; bottom: 0; width: 3px;
  background: var(--card-color, var(--accent)); opacity: .8;
}
.pipeline-card:hover { border-color: var(--border2); transform: translateY(-2px); box-shadow: var(--shadow); }
.pipeline-card-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 15px 16px; cursor: pointer; user-select: none;
}
.pipeline-card-header:hover .pipeline-card-label { color: var(--text); }
.pc-left { display: flex; flex-direction: column; gap: 3px; min-width: 0; }
.pipeline-card-label { font-size: 13px; font-weight: 600; transition: color .15s; }
.pipeline-card-latest { font-size: 11px; color: var(--text3); }
.pc-right { display: flex; align-items: center; gap: 10px; }
.pipeline-card-count { font-size: 26px; font-weight: 800; line-height: 1; letter-spacing: -.03em; }
.pc-chevron { color: var(--text3); font-size: 11px; transition: transform .2s; }
.pipeline-card.open .pc-chevron { transform: rotate(90deg); }
.pipeline-card.empty .pipeline-card-header { cursor: default; }
.pipeline-card.empty .pc-chevron { visibility: hidden; }
.pc-files { display: none; border-top: 1px solid var(--border); padding: 4px; max-height: 260px; overflow-y: auto; }
.pipeline-card.open .pc-files { display: block; }
.pc-file {
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  padding: 7px 10px; border-radius: var(--radius-sm); cursor: pointer; font-size: 12.5px;
}
.pc-file:hover { background: var(--bg-hover); }
.pc-file-name { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.pc-file-time { color: var(--text3); font-size: 11px; white-space: nowrap; flex-shrink: 0; }

/* ── Graph ──────────────────────────────────────────────────────────────────── */
#tab-graph { display: none; flex-direction: column; height: 100%; }
#tab-graph.active { display: flex; }
#graph-container {
  flex: 1;
  min-height: 400px;
  position: relative;
  background:
    radial-gradient(circle at 50% 40%, rgba(255,255,255,.02), transparent 70%),
    var(--bg2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}
#graph-svg { display: block; cursor: grab; }
#graph-svg:active { cursor: grabbing; }
.graph-node { stroke-width: 1.5; cursor: pointer; transition: stroke-width .15s, opacity .2s; }
.graph-link { transition: stroke-opacity .2s, stroke .2s; }
.graph-label { font-size: 10px; font-weight: 500; fill: var(--text2); pointer-events: none; user-select: none; transition: opacity .2s; }
.graph-hint {
  position: absolute; bottom: 12px; left: 14px; font-size: 11px; color: var(--text3);
  background: rgba(13,15,21,.7); padding: 4px 10px; border-radius: 999px; pointer-events: none;
}
.graph-legend { display: flex; gap: 16px; padding: 12px 2px; flex-wrap: wrap; }
.legend-item { display: flex; align-items: center; gap: 7px; font-size: 12px; color: var(--text2); cursor: default; }
.legend-dot { width: 10px; height: 10px; border-radius: 50%; display: inline-block; }
.tooltip {
  position: absolute; background: var(--bg3); border: 1px solid var(--border2);
  border-radius: var(--radius-sm); padding: 9px 12px; font-size: 12px;
  pointer-events: none; max-width: 300px; box-shadow: var(--shadow); z-index: 10;
}
.tooltip.hidden { display: none; }
.tooltip-title { font-weight: 600; margin-bottom: 4px; }
.tooltip-dir { color: var(--text3); font-size: 11px; font-family: var(--mono); }

/* ── Content ───────────────────────────────────────────────────────────────── */
.content-header {
  background: var(--bg2); border: 1px solid var(--border);
  border-radius: var(--radius) var(--radius) 0 0; padding: 14px 18px;
  position: sticky; top: -24px; z-index: 5;
}
.content-header-top { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.content-path { font-family: var(--mono); font-size: 12px; color: var(--text3); }
.content-meta { display: flex; gap: 8px; margin-top: 10px; flex-wrap: wrap; }
.content-meta:empty { display: none; }
.tag {
  display: inline-flex; align-items: center; background: var(--bg3); color: var(--accent2);
  padding: 3px 9px; border-radius: 999px; font-size: 11px; border: 1px solid var(--border);
}
.tag.rel { color: var(--accent); cursor: pointer; transition: background .15s; }
.tag.rel:hover { background: var(--bg-hover); }
.content-body {
  background: var(--bg2); border: 1px solid var(--border); border-top: none;
  border-radius: 0 0 var(--radius) var(--radius); padding: 28px 36px;
  line-height: 1.75; font-size: 14.5px; max-width: 860px;
}
.content-body h1 { font-size: 24px; font-weight: 700; margin: 20px 0 10px; letter-spacing: -.02em; }
.content-body h2 { font-size: 19px; font-weight: 600; margin: 18px 0 8px; }
.content-body h3 { font-size: 15px; font-weight: 600; margin: 14px 0 6px; }
.content-body p { margin: 10px 0; }
.content-body a { text-decoration: none; border-bottom: 1px solid rgba(34,211,238,.35); }
.content-body a:hover { border-bottom-color: var(--accent2); }
.content-body code { background: var(--bg3); padding: 2px 6px; border-radius: 4px; font-family: var(--mono); font-size: 12.5px; }
.content-body pre { background: #0b0d12; border: 1px solid var(--border); padding: 14px 16px; border-radius: var(--radius-sm); overflow-x: auto; margin: 14px 0; }
.content-body pre code { background: none; padding: 0; font-size: 12.5px; }
.content-body ul, .content-body ol { padding-left: 22px; margin: 10px 0; }
.content-body li { margin: 4px 0; }
.content-body blockquote { border-left: 3px solid var(--accent); padding: 2px 0 2px 14px; color: var(--text2); margin: 14px 0; }
.content-body hr { border: none; border-top: 1px solid var(--border); margin: 20px 0; }
.content-body table { border-collapse: collapse; margin: 14px 0; width: 100%; }
.content-body th, .content-body td { border: 1px solid var(--border); padding: 7px 11px; text-align: left; }
.content-body th { background: var(--bg3); }
.content-body.raw { white-space: pre-wrap; font-family: var(--mono); font-size: 13px; line-height: 1.6; }

/* ── Posts ─────────────────────────────────────────────────────────────────── */
.posts-summary { display: flex; gap: 12px; flex-wrap: wrap; margin-bottom: 18px; }
.posts-summary:empty { display: none; }
.summary-card {
  background: var(--bg2); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 12px 16px; min-width: 130px;
}
.summary-card .sc-label { font-size: 11px; color: var(--text2); text-transform: uppercase; letter-spacing: .05em; }
.summary-card .sc-value { font-size: 22px; font-weight: 700; margin-top: 4px; letter-spacing: -.02em; }
.summary-card .sc-sub { font-size: 11px; color: var(--text3); margin-top: 2px; }
.posts-list { display: flex; flex-direction: column; gap: 10px; margin-bottom: 24px; }
.post-card {
  background: var(--bg2); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 14px 16px; transition: border-color .15s;
}
.post-card:hover { border-color: var(--border2); }
.post-card-top { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; }
.post-card-title { font-weight: 600; }
.pc-badges { display: flex; align-items: center; gap: 8px; margin-top: 5px; }
.platform-badge { font-size: 10px; font-weight: 600; text-transform: uppercase; letter-spacing: .04em; padding: 2px 8px; border-radius: 999px; }
.platform-badge.linkedin { background: rgba(10,102,194,.18); color: #4f9cf9; }
.platform-badge.medium { background: rgba(255,255,255,.1); color: #e7e9f2; }
.platform-badge.x-twitter { background: rgba(255,255,255,.08); color: #cbd0e0; }
.platform-badge.other { background: var(--bg3); color: var(--text2); }
.post-card-url { font-size: 12px; color: var(--accent2); text-decoration: none; }
.post-card-url:hover { text-decoration: underline; }
.post-card-date { font-size: 11px; color: var(--text3); white-space: nowrap; }
.post-card-stats { display: flex; gap: 16px; margin-top: 10px; }
.post-stat { font-size: 12px; color: var(--text2); }
.post-stat strong { font-weight: 700; color: var(--text); }
.post-card-path { font-family: var(--mono); font-size: 11px; color: var(--text3); margin-top: 8px; }
.chart-wrap { background: var(--bg2); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; }
#engagement-chart { max-width: 100%; }

/* ── Activity ──────────────────────────────────────────────────────────────── */
.activity-list { display: flex; flex-direction: column; gap: 6px; }
.activity-item {
  display: flex; gap: 12px; align-items: center; padding: 9px 14px;
  background: var(--bg2); border: 1px solid var(--border); border-radius: var(--radius-sm); font-size: 13px;
}
.activity-time { color: var(--text3); font-size: 11px; white-space: nowrap; min-width: 150px; }
.activity-type { font-family: var(--mono); font-size: 11px; background: var(--bg3); padding: 2px 8px; border-radius: 999px; white-space: nowrap; color: var(--accent2); }

/* ── Empty / error states ───────────────────────────────────────────────────── */
.empty-state { padding: 40px 20px; text-align: center; color: var(--text3); font-size: 14px; }
.empty-state.err { color: var(--danger); }

/* ── Modal ─────────────────────────────────────────────────────────────────── */
.modal-overlay {
  position: fixed; inset: 0; z-index: 100; background: rgba(5,7,12,.7);
  backdrop-filter: blur(4px); display: flex; align-items: center; justify-content: center;
  animation: fade .15s ease;
}
.modal-overlay.hidden { display: none; }
.modal {
  background: var(--bg2); border: 1px solid var(--border2); border-radius: 14px;
  padding: 26px; min-width: 420px; max-width: 500px; box-shadow: var(--shadow-lg);
}
.modal h3 { margin-bottom: 18px; font-size: 17px; }
.modal label { display: block; margin-bottom: 14px; font-size: 12px; color: var(--text2); font-weight: 500; }
.modal input, .modal select {
  display: block; width: 100%; margin-top: 6px; background: var(--bg3);
  border: 1px solid var(--border); color: var(--text); padding: 9px 11px;
  border-radius: var(--radius-sm); font-size: 13px; font-family: var(--font); transition: border-color .15s, box-shadow .15s;
}
.modal input:focus, .modal select:focus { outline: none; border-color: var(--accent); box-shadow: var(--ring); }
.modal-actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 18px; }

/* ── Buttons ──────────────────────────────────────────────────────────────── */
.btn-sm {
  background: var(--bg3); border: 1px solid var(--border); color: var(--text);
  padding: 7px 14px; border-radius: var(--radius-sm); cursor: pointer; font-size: 12px;
  font-weight: 500; font-family: var(--font); transition: background .15s, border-color .15s;
}
.btn-sm:hover { background: var(--bg-hover); border-color: var(--border2); }
.btn-sm.active { background: var(--bg-hover); border-color: var(--accent); color: var(--accent); }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); }

/* ── Footer ────────────────────────────────────────────────────────────────── */
#app-footer {
  display: flex; align-items: center; gap: 20px;
  padding: 8px 20px;
  background: var(--bg2);
  border-top: 1px solid var(--border);
  font-size: 12px;
  color: var(--text2);
  height: 36px;
  flex-shrink: 0;
}
.footer-section { display: flex; align-items: center; gap: 6px; }
.footer-text { white-space: nowrap; }
.health-dot {
  width: 8px; height: 8px; border-radius: 50%;
  display: inline-block;
  background: #f59e0b;
}
.health-dot.ok { background: var(--accent); }
.health-dot.err { background: #ef4444; }
