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

:root {
  --bg-primary:    #0d0d1a;
  --bg-secondary:  #12122a;
  --bg-card:       #1a1a35;
  --bg-card-hover: #22224a;
  --text-primary:  #e8e8f0;
  --text-muted:    #8888aa;
  --accent:        #534AB7;
  --border:        #2a2a4a;
  --sidebar-w:     320px;
  --header-h:      52px;
}

html, body {
  height: 100%;
  font-family: Inter, system-ui, -apple-system, sans-serif;
  background: var(--bg-primary);
  color: var(--text-primary);
  overflow: hidden;
}

/* ── Layout ──────────────────────────────────────────────────────────────── */
#app {
  display: grid;
  grid-template-rows: var(--header-h) 1fr;
  grid-template-columns: var(--sidebar-w) 1fr var(--sidebar-w);
  height: 100vh;
}

/* Header spans full width */
header {
  grid-column: 1 / -1;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 0 16px;
  background: var(--bg-secondary);
  border-bottom: 1px solid var(--border);
  z-index: 10;
}

header h1 {
  font-size: 1rem;
  font-weight: 600;
  color: var(--text-primary);
  white-space: nowrap;
}

header .subtitle {
  font-size: 0.75rem;
  color: var(--text-muted);
}

.header-spacer { flex: 1; }

/* Error banner */
#error-banner {
  position: fixed;
  top: var(--header-h);
  left: 50%;
  transform: translateX(-50%);
  background: #7a1a1a;
  color: #ffd0d0;
  padding: 8px 20px;
  border-radius: 0 0 8px 8px;
  font-size: 0.82rem;
  z-index: 200;
  max-width: 90vw;
  text-align: center;
}
#error-banner.hidden { display: none; }

/* ── Left sidebar ────────────────────────────────────────────────────────── */
#left-sidebar {
  background: var(--bg-secondary);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.sidebar-section {
  padding: 12px;
  border-bottom: 1px solid var(--border);
}

.sidebar-section h2 {
  font-size: 0.7rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-muted);
  margin-bottom: 8px;
}

/* Search */
#search-input {
  width: 100%;
  padding: 7px 10px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--bg-card);
  color: var(--text-primary);
  font-size: 0.85rem;
  outline: none;
}
#search-input:focus { border-color: var(--accent); }
#search-input::placeholder { color: var(--text-muted); }

/* Filter buttons */
#filter-buttons {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.filter-btn {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 10px;
  border: none;
  border-radius: 6px;
  background: var(--bg-card);
  color: var(--text-primary);
  font-size: 0.82rem;
  cursor: pointer;
  text-align: left;
  transition: background 0.15s;
}
.filter-btn::before {
  content: "";
  display: inline-block;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--cat-color, #888780);
  flex-shrink: 0;
}
.filter-btn:hover { background: var(--bg-card-hover); }
.filter-btn.active {
  background: var(--accent);
  color: #fff;
}
.filter-btn.active::before { background: rgba(255,255,255,0.7); }

/* Stats bar */
#stats-bar {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 0.8rem;
  color: var(--text-muted);
}
#stats-bar strong { color: var(--text-primary); }

/* Zoom controls */
.zoom-controls {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}
.zoom-controls button {
  flex: 1;
  padding: 6px 4px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--bg-card);
  color: var(--text-primary);
  font-size: 0.8rem;
  cursor: pointer;
  transition: background 0.15s;
}
.zoom-controls button:hover { background: var(--bg-card-hover); }

/* ── Graph canvas ────────────────────────────────────────────────────────── */
#cy-container {
  position: relative;
  background: var(--bg-primary);
  overflow: hidden;
}

#cy {
  width: 100%;
  height: 100%;
}

/* Tooltip */
#tooltip {
  position: absolute;
  background: rgba(26,26,53,0.95);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 5px 10px;
  font-size: 0.78rem;
  pointer-events: none;
  white-space: nowrap;
  z-index: 50;
  color: var(--text-primary);
}
#tooltip.hidden { display: none; }

/* ── Right sidebar ───────────────────────────────────────────────────────── */
#right-sidebar {
  background: var(--bg-secondary);
  border-left: 1px solid var(--border);
  overflow-y: auto;
  padding: 14px;
}

.placeholder {
  color: var(--text-muted);
  font-size: 0.83rem;
  margin-top: 20px;
  text-align: center;
}

.detail-title {
  font-size: 1rem;
  font-weight: 600;
  margin-bottom: 8px;
  line-height: 1.3;
}

.category-badge {
  display: inline-block;
  padding: 2px 10px;
  border-radius: 20px;
  font-size: 0.72rem;
  font-weight: 600;
  color: #fff;
  margin-bottom: 12px;
}

.detail-section {
  margin-top: 10px;
}

.detail-label {
  font-size: 0.68rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
  margin-bottom: 2px;
}

.detail-value {
  font-size: 0.83rem;
  color: var(--text-primary);
  line-height: 1.4;
}

.detail-grid {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 3px 12px;
  margin-top: 10px;
  font-size: 0.8rem;
}

.badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 12px;
  font-size: 0.72rem;
  font-weight: 600;
  color: #fff;
  margin-right: 6px;
}

.lock-row {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  margin-top: 10px;
  background: rgba(186,117,23,0.15);
  border: 1px solid #BA7517;
  border-radius: 6px;
  padding: 8px;
  font-size: 0.8rem;
}

.lock-icon { font-size: 1rem; flex-shrink: 0; }

.source-text {
  font-size: 0.78rem;
  color: var(--text-muted);
  font-style: italic;
  line-height: 1.5;
}

.mono { font-family: monospace; font-size: 0.78rem; }

/* ── Sidebar collapse ────────────────────────────────────────────────────── */
#app.sidebar-collapsed {
  grid-template-columns: 0 1fr var(--sidebar-w);
}

#app.sidebar-collapsed #left-sidebar {
  overflow: hidden;
  border: none;
}

/* ── Header buttons ──────────────────────────────────────────────────────── */
#btn-toggle-sidebar, #btn-lang {
  padding: 5px 10px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--bg-card);
  color: var(--text-primary);
  font-size: 0.85rem;
  cursor: pointer;
  white-space: nowrap;
  flex-shrink: 0;
}
#btn-toggle-sidebar:hover, #btn-lang:hover { background: var(--bg-card-hover); }

/* ── Refresh button ──────────────────────────────────────────────────────── */
#btn-refresh {
  padding: 5px 12px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--bg-card);
  color: var(--text-primary);
  font-size: 0.8rem;
  cursor: pointer;
  white-space: nowrap;
}
#btn-refresh:hover { background: var(--bg-card-hover); }
#btn-refresh:disabled { opacity: 0.5; cursor: default; }

/* ── Responsive ──────────────────────────────────────────────────────────── */
@media (max-width: 900px) {
  #app {
    grid-template-columns: 240px 1fr 0;
  }
  #right-sidebar { display: none; }
}

@media (max-width: 600px) {
  #app {
    grid-template-columns: 0 1fr 0;
    grid-template-rows: var(--header-h) 1fr;
  }
  #left-sidebar { display: none; }
}
