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

:root {
  --bg:          #0f172a;
  --surface:     #1e293b;
  --surface2:    #273449;
  --border:      #334155;
  --border2:     #475569;
  --text:        #f1f5f9;
  --text2:       #94a3b8;
  --text3:       #64748b;
  --accent:      #06b6d4;
  --accent2:     #0ea5e9;
  --accent-dim:  #0e7490;
  --sidebar-w:   240px;
  --detail-w:    300px;
  --topbar-h:    52px;
  --legend-h:    56px;
  --radius:      8px;
  --radius-sm:   4px;
  --shadow:      0 4px 24px rgba(0,0,0,.45);
  --font:        -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  --mono:        'JetBrains Mono', 'Fira Code', 'Cascadia Code', monospace;
}

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

/* ─── Layout shell ───────────────────────────────────────────────────────── */
#app {
  display: grid;
  grid-template-rows: var(--topbar-h) 1fr var(--legend-h);
  grid-template-columns: var(--sidebar-w) 1fr;
  grid-template-areas:
    "topbar topbar"
    "sidebar canvas"
    "legend  legend";
  height: 100vh;
}

/* ─── Top bar ────────────────────────────────────────────────────────────── */
#topbar {
  grid-area: topbar;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 0 16px;
  background: linear-gradient(90deg, #0d1b32 0%, #132035 100%);
  border-bottom: 1px solid var(--border);
  z-index: 10;
}

#topbar .logo {
  font-size: 15px;
  font-weight: 700;
  color: var(--accent);
  white-space: nowrap;
  letter-spacing: .02em;
  margin-right: 6px;
}
#topbar .logo span { color: var(--text2); font-weight: 400; }

#search-wrap {
  position: relative;
  flex: 1;
  max-width: 280px;
}
#search-wrap svg {
  position: absolute;
  left: 9px; top: 50%;
  transform: translateY(-50%);
  color: var(--text3);
  pointer-events: none;
}
#search {
  width: 100%;
  height: 32px;
  padding: 0 10px 0 32px;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 20px;
  color: var(--text);
  font-size: 12px;
  outline: none;
  transition: border-color .15s;
}
#search::placeholder { color: var(--text3); }
#search:focus { border-color: var(--accent); }

.tb-label {
  color: var(--text3);
  font-size: 11px;
  white-space: nowrap;
  margin-left: 8px;
}

#layout-select {
  height: 32px;
  padding: 0 8px;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-size: 12px;
  outline: none;
  cursor: pointer;
}
#layout-select:focus { border-color: var(--accent); }

.tb-btn {
  height: 32px;
  padding: 0 12px;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text2);
  font-size: 12px;
  cursor: pointer;
  display: flex; align-items: center; gap: 5px;
  transition: background .12s, color .12s, border-color .12s;
  white-space: nowrap;
}
.tb-btn:hover { background: var(--surface); color: var(--text); border-color: var(--border2); }
.tb-btn.active { color: var(--accent); border-color: var(--accent-dim); }

#stats-badge {
  margin-left: auto;
  font-size: 11px;
  color: var(--text3);
  white-space: nowrap;
  padding: 3px 10px;
  background: var(--surface);
  border-radius: 20px;
  border: 1px solid var(--border);
}
#stats-badge strong { color: var(--accent); }

/* ─── Sidebar ────────────────────────────────────────────────────────────── */
#sidebar {
  grid-area: sidebar;
  background: var(--surface);
  border-right: 1px solid var(--border);
  overflow-y: auto;
  padding: 8px 0 16px;
}
#sidebar::-webkit-scrollbar { width: 4px; }
#sidebar::-webkit-scrollbar-thumb { background: var(--border); border-radius: 2px; }

.cat-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 14px 6px;
  cursor: pointer;
  user-select: none;
  color: var(--text3);
  font-size: 10px;
  font-weight: 700;
  letter-spacing: .08em;
  text-transform: uppercase;
}
.cat-header:hover { color: var(--text2); }
.cat-arrow { font-size: 10px; transition: transform .15s; }
.cat-header.open .cat-arrow { transform: rotate(90deg); }

.cat-views { list-style: none; }
.cat-views.collapsed { display: none; }

.view-item {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  padding: 6px 14px 6px 20px;
  cursor: pointer;
  border-left: 2px solid transparent;
  transition: background .1s, border-color .1s;
}
.view-item:hover { background: var(--surface2); }
.view-item.active {
  background: rgba(6,182,212,.08);
  border-left-color: var(--accent);
}
.view-icon { font-size: 13px; flex-shrink: 0; margin-top: 1px; }
.view-text { flex: 1; min-width: 0; }
.view-title { font-size: 12px; font-weight: 500; color: var(--text); line-height: 1.35; }
.view-item.active .view-title { color: var(--accent); }
.view-meta { font-size: 10px; color: var(--text3); margin-top: 1px; }

/* ─── Graph canvas ───────────────────────────────────────────────────────── */
#canvas-wrap {
  grid-area: canvas;
  position: relative;
  background: var(--bg);
  overflow: hidden;
}

#cy {
  width: 100%;
  height: 100%;
  position: absolute;
  inset: 0;
}

/* Tooltip */
#tooltip {
  position: absolute;
  pointer-events: none;
  background: var(--surface);
  border: 1px solid var(--border2);
  border-radius: var(--radius-sm);
  padding: 5px 10px;
  font-size: 11.5px;
  color: var(--text);
  max-width: 260px;
  box-shadow: var(--shadow);
  z-index: 100;
  display: none;
  white-space: nowrap;
}
#tooltip.visible { display: block; }

/* Loading overlay */
#loading {
  position: absolute;
  inset: 0;
  background: rgba(15,23,42,.75);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 50;
  opacity: 0;
  pointer-events: none;
  transition: opacity .2s;
}
#loading.visible { opacity: 1; pointer-events: all; }
.spinner {
  width: 32px; height: 32px;
  border: 3px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin .7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ─── Detail panel ───────────────────────────────────────────────────────── */
#detail-panel {
  position: absolute;
  right: 0; top: 0; bottom: 0;
  width: var(--detail-w);
  background: var(--surface);
  border-left: 1px solid var(--border);
  transform: translateX(100%);
  transition: transform .22s cubic-bezier(.4,0,.2,1);
  overflow-y: auto;
  z-index: 20;
  display: flex;
  flex-direction: column;
}
#detail-panel.open { transform: translateX(0); }
#detail-panel::-webkit-scrollbar { width: 4px; }
#detail-panel::-webkit-scrollbar-thumb { background: var(--border); border-radius: 2px; }

#detail-header {
  padding: 12px 14px 10px;
  border-bottom: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 6px;
  position: sticky; top: 0;
  background: var(--surface);
  z-index: 1;
}
#detail-close {
  position: absolute; top: 10px; right: 10px;
  width: 24px; height: 24px;
  background: transparent;
  border: none; cursor: pointer;
  color: var(--text3); font-size: 16px;
  display: flex; align-items: center; justify-content: center;
  border-radius: var(--radius-sm);
  transition: background .1s, color .1s;
}
#detail-close:hover { background: var(--surface2); color: var(--text); }

#detail-node-name {
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
  padding-right: 28px;
  line-height: 1.4;
  word-break: break-word;
}
#detail-cat-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 10px;
  padding: 2px 8px;
  border-radius: 20px;
  font-weight: 600;
  letter-spacing: .04em;
  width: fit-content;
}
.dot { width: 8px; height: 8px; border-radius: 50%; flex-shrink: 0; }

#detail-body { padding: 12px 14px; flex: 1; display: flex; flex-direction: column; gap: 14px; }

.detail-section-title {
  font-size: 10px;
  font-weight: 700;
  letter-spacing: .07em;
  text-transform: uppercase;
  color: var(--text3);
  margin-bottom: 6px;
}

.conn-list { list-style: none; display: flex; flex-direction: column; gap: 3px; }
.conn-item {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 4px 6px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: background .1s;
  font-size: 11.5px;
}
.conn-item:hover { background: var(--surface2); }
.conn-arrow { color: var(--text3); font-size: 10px; flex-shrink: 0; }
.conn-name { flex: 1; color: var(--text2); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.conn-name:hover { color: var(--accent); }

.views-list { display: flex; flex-wrap: wrap; gap: 5px; }
.view-chip {
  padding: 3px 8px;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 20px;
  font-size: 10px;
  color: var(--text2);
  cursor: pointer;
  transition: background .1s, color .1s, border-color .1s;
}
.view-chip:hover { background: rgba(6,182,212,.12); color: var(--accent); border-color: var(--accent-dim); }

/* ─── Legend ─────────────────────────────────────────────────────────────── */
#legend {
  grid-area: legend;
  background: var(--surface);
  border-top: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 0;
  padding: 0 16px;
  overflow-x: auto;
  overflow-y: hidden;
}
#legend::-webkit-scrollbar { height: 3px; }
#legend::-webkit-scrollbar-thumb { background: var(--border); border-radius: 2px; }

.legend-title {
  font-size: 10px;
  font-weight: 700;
  letter-spacing: .07em;
  text-transform: uppercase;
  color: var(--text3);
  margin-right: 12px;
  white-space: nowrap;
  flex-shrink: 0;
}

.legend-sep {
  width: 1px; height: 24px;
  background: var(--border);
  margin: 0 12px;
  flex-shrink: 0;
}

.legend-items { display: flex; align-items: center; gap: 10px; flex-wrap: nowrap; }
.legend-item {
  display: flex; align-items: center; gap: 5px;
  font-size: 10.5px; color: var(--text2); white-space: nowrap;
  cursor: pointer; padding: 2px 4px; border-radius: 3px;
  transition: background .1s;
}
.legend-item:hover { background: var(--surface2); }
.legend-dot { width: 10px; height: 10px; border-radius: 50%; flex-shrink: 0; }

.legend-edge-items { display: flex; align-items: center; gap: 12px; }
.legend-edge-item { display: flex; align-items: center; gap: 6px; font-size: 10.5px; color: var(--text2); white-space: nowrap; }
.legend-line {
  width: 28px; height: 2px; border-radius: 1px; flex-shrink: 0;
}
.legend-line.flow        { background: #00e5ff; }
.legend-line.composition { background: #64748b; height: 3px; }
.legend-line.association { background: #38bdf8; }
.legend-line.access      { background: #f97316; }

/* ─── Scrollbar global ───────────────────────────────────────────────────── */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--border2); }

/* ─── No-data placeholder ────────────────────────────────────────────────── */
#empty-msg {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
  color: var(--text3);
  pointer-events: none;
  display: none;
}
#empty-msg .em-icon { font-size: 48px; opacity: .4; }
#empty-msg .em-text { font-size: 13px; }

/* ─── Search highlight pulse ─────────────────────────────────────────────── */
@keyframes highlight-pulse {
  0%   { box-shadow: 0 0 0 0 rgba(6,182,212,.6); }
  70%  { box-shadow: 0 0 0 8px rgba(6,182,212,0); }
  100% { box-shadow: 0 0 0 0 rgba(6,182,212,0); }
}
