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

:root {
  --bg:          #07070f;
  --bg2:         #0e0e1a;
  --bg3:         #14142a;
  --surface:     rgba(20,20,42,0.85);
  --border:      rgba(120,100,255,0.18);
  --accent:      #7c3aed;
  --accent2:     #a78bfa;
  --text:        #e2e8f0;
  --text-dim:    #94a3b8;
  --text-muted:  #475569;
  --node-normal: #3b82f6;
  --node-home:   #fbbf24;
  --node-orphan: #ef4444;
  --node-hub:    #a78bfa;
  --node-high:   #10b981;
  --edge:        rgba(148,130,255,0.55);
  --radius:      12px;
  --panel-w:     320px;
  --font:        'Inter', system-ui, sans-serif;
}

html, body {
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 14px;
  overflow: hidden;
}

/* ── Layout ───────────────────────────────────────────────────────────────── */
.layout {
  display: grid;
  grid-template-columns: var(--panel-w) 1fr;
  grid-template-rows: 100vh;
  height: 100vh;
}

/* ── Sidebar ──────────────────────────────────────────────────────────────── */
.sidebar {
  grid-column: 1;
  background: var(--bg2);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.sidebar-header {
  padding: 20px 20px 16px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.logo {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 16px;
}

.logo-icon {
  width: 32px;
  height: 32px;
  background: linear-gradient(135deg, var(--accent), #4f46e5);
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
  flex-shrink: 0;
  box-shadow: 0 0 16px rgba(124,58,237,0.4);
}

.logo-text {
  font-size: 15px;
  font-weight: 700;
  letter-spacing: -0.3px;
  color: var(--text);
}
.logo-sub {
  font-size: 10px;
  color: var(--text-muted);
  letter-spacing: 0.5px;
  text-transform: uppercase;
}

/* URL form */
.url-form { display: flex; flex-direction: column; gap: 8px; }

.url-input-wrap {
  display: flex;
  gap: 6px;
}

.url-input {
  flex: 1;
  background: var(--bg3);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 9px 12px;
  color: var(--text);
  font-size: 13px;
  outline: none;
  transition: border-color 0.2s;
}
.url-input:focus { border-color: var(--accent); }
.url-input::placeholder { color: var(--text-muted); }

.btn-crawl {
  background: linear-gradient(135deg, var(--accent), #4f46e5);
  color: #fff;
  border: none;
  border-radius: 8px;
  padding: 9px 16px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: opacity 0.2s, transform 0.1s;
  white-space: nowrap;
}
.btn-crawl:hover  { opacity: 0.9; }
.btn-crawl:active { transform: scale(0.97); }
.btn-crawl:disabled { opacity: 0.5; cursor: not-allowed; }

/* Settings toggle */
.settings-toggle {
  background: none;
  border: none;
  color: var(--text-dim);
  font-size: 12px;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 2px 0;
  transition: color 0.2s;
}
.settings-toggle:hover { color: var(--text); }
.settings-toggle .arrow { transition: transform 0.2s; font-size: 10px; }
.settings-toggle.open .arrow { transform: rotate(90deg); }

.settings-panel {
  display: none;
  flex-direction: column;
  gap: 8px;
  margin-top: 8px;
  padding: 12px;
  background: var(--bg3);
  border-radius: 8px;
  border: 1px solid var(--border);
}
.settings-panel.visible { display: flex; }

.setting-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}
.setting-row label { color: var(--text-dim); font-size: 12px; }
.setting-row input[type=range] {
  width: 100px;
  accent-color: var(--accent);
}
.setting-val {
  color: var(--accent2);
  font-size: 12px;
  min-width: 28px;
  text-align: right;
}

/* ── Sidebar scrollable body ──────────────────────────────────────────────── */
.sidebar-body {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 16px;
  scrollbar-width: thin;
  scrollbar-color: var(--border) transparent;
}

/* Stats grid */
.stats-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.stat-card {
  background: var(--bg3);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 12px;
}
.stat-card .val {
  font-size: 22px;
  font-weight: 700;
  color: var(--accent2);
  line-height: 1;
}
.stat-card .lbl {
  font-size: 11px;
  color: var(--text-muted);
  margin-top: 3px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

/* Issues */
.section-title {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: var(--text-muted);
  margin-bottom: 6px;
}

.issue-card {
  background: var(--bg3);
  border-radius: 8px;
  padding: 10px 12px;
  border-left: 3px solid transparent;
  font-size: 12px;
  line-height: 1.5;
}
.issue-card.error   { border-left-color: #ef4444; }
.issue-card.warning { border-left-color: #f59e0b; }
.issue-card.info    { border-left-color: #3b82f6; }

.issue-msg { color: var(--text-dim); }

/* Top pages list */
.top-list { display: flex; flex-direction: column; gap: 4px; }

.top-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 8px;
  border-radius: 6px;
  cursor: pointer;
  transition: background 0.15s;
}
.top-item:hover { background: var(--bg3); }
.top-item .rank {
  font-size: 11px;
  color: var(--text-muted);
  min-width: 18px;
}
.top-item .name {
  flex: 1;
  font-size: 12px;
  color: var(--text-dim);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.top-item .pr-bar {
  width: 48px;
  height: 4px;
  background: var(--bg3);
  border-radius: 2px;
  overflow: hidden;
}
.top-item .pr-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--accent), var(--accent2));
  border-radius: 2px;
}

/* Legend */
.legend { display: flex; flex-wrap: wrap; gap: 8px; }
.legend-item {
  display: flex;
  align-items: center;
  gap: 5px;
  font-size: 11px;
  color: var(--text-dim);
}
.legend-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  flex-shrink: 0;
}

/* Filter chips */
.filter-chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip {
  padding: 4px 10px;
  border-radius: 20px;
  border: 1px solid var(--border);
  background: var(--bg3);
  color: var(--text-dim);
  font-size: 11px;
  cursor: pointer;
  transition: all 0.15s;
  user-select: none;
}
.chip:hover  { border-color: var(--accent); color: var(--text); }
.chip.active { background: var(--accent); border-color: var(--accent); color: #fff; }

/* ── Graph area ───────────────────────────────────────────────────────────── */
.graph-wrap {
  position: relative;
  overflow: hidden;
  background: var(--bg);
  background-image:
    radial-gradient(ellipse at 20% 20%, rgba(124,58,237,0.06) 0%, transparent 60%),
    radial-gradient(ellipse at 80% 80%, rgba(59,130,246,0.05) 0%, transparent 60%);
}

#graph {
  width: 100%;
  height: 100%;
  cursor: grab;
}
#graph:active { cursor: grabbing; }

/* Graph controls */
.graph-controls {
  position: absolute;
  bottom: 20px;
  right: 20px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.ctrl-btn {
  width: 36px;
  height: 36px;
  background: var(--surface);
  backdrop-filter: blur(12px);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text-dim);
  font-size: 16px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.15s;
}
.ctrl-btn:hover { color: var(--text); border-color: var(--accent); }

/* Crawl info badge */
.crawl-info {
  position: absolute;
  top: 16px;
  left: 16px;
  background: var(--surface);
  backdrop-filter: blur(12px);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 12px;
  font-size: 11px;
  color: var(--text-dim);
  display: none;
}
.crawl-info.visible { display: block; }
.crawl-info strong { color: var(--accent2); }

/* Search box */
.graph-search {
  position: absolute;
  top: 16px;
  right: 16px;
  display: none;
}
.graph-search.visible { display: block; }
.graph-search input {
  background: var(--surface);
  backdrop-filter: blur(12px);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 12px;
  color: var(--text);
  font-size: 13px;
  outline: none;
  width: 220px;
  transition: border-color 0.2s;
}
.graph-search input:focus { border-color: var(--accent); }
.graph-search input::placeholder { color: var(--text-muted); }

/* ── Node detail panel ────────────────────────────────────────────────────── */
.detail-panel {
  position: absolute;
  top: 16px;
  right: 16px;
  width: 280px;
  background: var(--surface);
  backdrop-filter: blur(16px);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  display: none;
  flex-direction: column;
  gap: 12px;
  z-index: 10;
  box-shadow: 0 8px 32px rgba(0,0,0,0.4);
}
.detail-panel.visible { display: flex; }

.detail-close {
  position: absolute;
  top: 10px;
  right: 10px;
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 16px;
  line-height: 1;
  transition: color 0.15s;
}
.detail-close:hover { color: var(--text); }

.detail-title {
  font-size: 14px;
  font-weight: 600;
  color: var(--text);
  padding-right: 20px;
  word-break: break-word;
}
.detail-url {
  font-size: 11px;
  color: var(--text-muted);
  word-break: break-all;
}
.detail-url a { color: var(--accent2); text-decoration: none; }
.detail-url a:hover { text-decoration: underline; }

.detail-tags { display: flex; flex-wrap: wrap; gap: 4px; }
.tag {
  padding: 2px 8px;
  border-radius: 20px;
  font-size: 10px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}
.tag.orphan  { background: rgba(239,68,68,0.2);  color: #f87171; }
.tag.sink    { background: rgba(245,158,11,0.2); color: #fbbf24; }
.tag.home    { background: rgba(251,191,36,0.2); color: #fcd34d; }
.tag.hub     { background: rgba(167,139,250,0.2);color: #c4b5fd; }
.tag.high-pr { background: rgba(16,185,129,0.2); color: #34d399; }

.detail-metrics {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}
.metric {
  background: var(--bg3);
  border-radius: 8px;
  padding: 8px 10px;
}
.metric .mv {
  font-size: 18px;
  font-weight: 700;
  color: var(--accent2);
  line-height: 1;
}
.metric .ml {
  font-size: 10px;
  color: var(--text-muted);
  margin-top: 2px;
  text-transform: uppercase;
}

.detail-pr-bar {
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.detail-pr-bar .label { font-size: 11px; color: var(--text-dim); }
.pr-track {
  height: 6px;
  background: var(--bg3);
  border-radius: 3px;
  overflow: hidden;
}
.pr-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--accent), var(--accent2));
  border-radius: 3px;
  transition: width 0.4s ease;
}

.detail-open-btn {
  display: block;
  text-align: center;
  padding: 8px;
  background: var(--bg3);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--accent2);
  font-size: 12px;
  text-decoration: none;
  transition: all 0.15s;
}
.detail-open-btn:hover {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

/* ── Loading overlay ──────────────────────────────────────────────────────── */
.loading-overlay {
  position: absolute;
  inset: 0;
  background: rgba(7,7,15,0.88);
  backdrop-filter: blur(4px);
  display: none;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
  z-index: 20;
}
.loading-overlay.visible { display: flex; }

.spinner {
  width: 48px;
  height: 48px;
  border: 3px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.loading-text { color: var(--text-dim); font-size: 14px; }
.loading-sub  { color: var(--text-muted); font-size: 12px; }

/* ── Empty state ──────────────────────────────────────────────────────────── */
.empty-state {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  pointer-events: none;
  transition: opacity 0.3s;
}
.empty-state.hidden { opacity: 0; }
.empty-icon { font-size: 64px; opacity: 0.15; }
.empty-title { font-size: 18px; font-weight: 600; color: var(--text-dim); opacity: 0.5; }
.empty-desc  { font-size: 13px; color: var(--text-muted); opacity: 0.4; }

/* ── SVG graph elements ───────────────────────────────────────────────────── */
.link {
  stroke: var(--edge);
  stroke-width: 1;
  fill: none;
}
.link.highlighted { stroke: rgba(167,139,250,0.6); stroke-width: 2; }

.node circle {
  stroke: rgba(0,0,0,0.3);
  stroke-width: 1.5;
  cursor: pointer;
  transition: filter 0.2s;
}
.node circle:hover { filter: brightness(1.3); }
.node.selected circle { stroke: #fff; stroke-width: 2.5; }

.node text {
  fill: rgba(226,232,240,0.75);
  font-size: 10px;
  pointer-events: none;
  user-select: none;
}

.tooltip {
  position: absolute;
  background: var(--surface);
  backdrop-filter: blur(8px);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 12px;
  font-size: 12px;
  color: var(--text);
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.15s;
  max-width: 240px;
  z-index: 30;
  word-break: break-word;
}
.tooltip.visible { opacity: 1; }

/* ── Saved analyses ───────────────────────────────────────────────────────── */
.saved-del:hover { color: #f87171 !important; }

/* ── Scrollbar ────────────────────────────────────────────────────────────── */
::-webkit-scrollbar { width: 4px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 2px; }

/* ── Responsive ───────────────────────────────────────────────────────────── */
@media (max-width: 900px) {
  .layout { grid-template-columns: 260px 1fr; }
  :root { --panel-w: 260px; }
}
