@import url('fonts/fonts.css');

  :root {
    --bg: #0c0e13;
    --surface: #14171f;
    --surface-hover: #1a1e28;
    --border: #252a36;
    --border-bright: #3a4155;
    --text: #e2e4ea;
    --text-dim: #7a8194;
    --text-muted: #4a5068;
    --accent: #6c8cff;
    --accent-dim: rgba(108, 140, 255, 0.12);
    --accent-glow: rgba(108, 140, 255, 0.25);
    --green: #4ade80;
    --green-dim: rgba(74, 222, 128, 0.12);
    --amber: #fbbf24;
    --amber-dim: rgba(251, 191, 36, 0.12);
    --rose: #fb7185;
    --rose-dim: rgba(251, 113, 133, 0.12);
    --purple: #a78bfa;
    --purple-dim: rgba(167, 139, 250, 0.12);
    --cyan: #22d3ee;
    --cyan-dim: rgba(34, 211, 238, 0.12);
    --node-w: 220;
    --node-h: 48;
    --radius: 10px;
    --field-row-border: rgba(255,255,255,0.03);
    --field-row-hover: rgba(255,255,255,0.02);
    --grid-opacity: 0.4;
    --canvas-glow: rgba(108,140,255,0.03);
    --loading-bg: rgba(12,14,19,0.85);
    --node-shadow: rgba(0,0,0,0.3);
    --node-shadow-expanded: rgba(0,0,0,0.5);
    --minimap-node: rgba(108,140,255,0.35);
    --minimap-edge: rgba(58,65,85,0.5);
    --minimap-viewport: rgba(108,140,255,0.6);
    --ref-hover: #8aaaff;
  }

  [data-theme="light"] {
    --bg: #f0f2f5;
    --surface: #ffffff;
    --surface-hover: #f5f6f8;
    --border: #dde0e7;
    --border-bright: #bfc4cf;
    --text: #1a1d26;
    --text-dim: #5c6378;
    --text-muted: #8f96a8;
    --accent: #4a6cf7;
    --accent-dim: rgba(74, 108, 247, 0.1);
    --accent-glow: rgba(74, 108, 247, 0.18);
    --green: #16a34a;
    --green-dim: rgba(22, 163, 74, 0.1);
    --amber: #d97706;
    --amber-dim: rgba(217, 119, 6, 0.1);
    --rose: #e11d48;
    --rose-dim: rgba(225, 29, 72, 0.1);
    --purple: #7c3aed;
    --purple-dim: rgba(124, 58, 237, 0.1);
    --cyan: #0891b2;
    --cyan-dim: rgba(8, 145, 178, 0.1);
    --field-row-border: rgba(0,0,0,0.04);
    --field-row-hover: rgba(0,0,0,0.02);
    --grid-opacity: 0.25;
    --canvas-glow: rgba(74,108,247,0.04);
    --loading-bg: rgba(240,242,245,0.85);
    --node-shadow: rgba(0,0,0,0.08);
    --node-shadow-expanded: rgba(0,0,0,0.14);
    --minimap-node: rgba(74,108,247,0.3);
    --minimap-edge: rgba(191,196,207,0.6);
    --minimap-viewport: rgba(74,108,247,0.5);
    --ref-hover: #3855d4;
  }

  * { margin: 0; padding: 0; box-sizing: border-box; }

  body {
    font-family: 'DM Sans', sans-serif;
    background: var(--bg);
    color: var(--text);
    height: 100vh;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    transition: background 0.35s ease, color 0.35s ease;
  }

  /* ─── HEADER ─── */
  header {
    display: flex;
    align-items: center;
    gap: 16px;
    padding: 16px 24px;
    border-bottom: 1px solid var(--border);
    background: var(--surface);
    z-index: 100;
    flex-shrink: 0;
  }
  header .logo {
    font-weight: 700;
    font-size: 17px;
    letter-spacing: -0.3px;
    display: flex;
    align-items: center;
    gap: 10px;
    white-space: nowrap;
  }
  header .logo svg { flex-shrink: 0; }
  header .divider {
    width: 1px;
    height: 24px;
    background: var(--border);
  }
  .file-actions {
    display: flex;
    gap: 8px;
    align-items: center;
    flex: 1;
    min-width: 0;
  }
  .file-chips {
    display: flex;
    gap: 6px;
    flex-wrap: wrap;
    flex: 1;
    min-width: 0;
  }
  .chip {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 5px 12px;
    background: var(--accent-dim);
    border: 1px solid rgba(108,140,255,0.2);
    border-radius: 20px;
    font-size: 12px;
    font-family: 'JetBrains Mono', monospace;
    font-weight: 500;
    color: var(--accent);
    white-space: nowrap;
    animation: chipIn 0.3s ease;
  }
  .chip .remove {
    cursor: pointer;
    opacity: 0.5;
    transition: opacity 0.15s;
    font-size: 14px;
    line-height: 1;
  }
  .chip .remove:hover { opacity: 1; }
  .chip-dot {
    width: 8px; height: 8px;
    border-radius: 50%;
    flex-shrink: 0;
  }
  @keyframes chipIn {
    from { opacity: 0; transform: scale(0.9); }
    to { opacity: 1; transform: scale(1); }
  }

  .btn {
    display: inline-flex;
    align-items: center;
    gap: 7px;
    padding: 8px 16px;
    border-radius: 8px;
    font-size: 13px;
    font-weight: 500;
    font-family: 'DM Sans', sans-serif;
    cursor: pointer;
    border: 1px solid var(--border);
    background: var(--surface);
    color: var(--text);
    transition: all 0.15s;
    white-space: nowrap;
  }
  .btn:hover { background: var(--surface-hover); border-color: var(--border-bright); }
  .btn-primary {
    background: var(--accent);
    border-color: var(--accent);
    color: #fff;
  }
  .btn-primary:hover { background: #5a7cf0; }
  .btn svg { width: 15px; height: 15px; }
  .stats {
    display: flex;
    gap: 16px;
    font-size: 12px;
    color: var(--text-dim);
    white-space: nowrap;
  }
  .stats span { display: flex; align-items: center; gap: 5px; }
  .stats .dot {
    width: 7px; height: 7px; border-radius: 50%;
  }

  /* ─── CANVAS AREA ─── */
  .canvas-wrap {
    flex: 1;
    position: relative;
    overflow: hidden;
    background:
      radial-gradient(circle at 50% 50%, var(--canvas-glow) 0%, transparent 70%),
      var(--bg);
  }
  .canvas-wrap::before {
    content: '';
    position: absolute;
    inset: 0;
    background-image:
      radial-gradient(circle, var(--border) 1px, transparent 1px);
    background-size: 32px 32px;
    opacity: var(--grid-opacity);
    pointer-events: none;
  }

  #canvas {
    position: absolute;
    top: 0; left: 0;
    transform-origin: 0 0;
  }

  /* ─── EDGES (SVG) ─── */
  #edges {
    position: absolute;
    top: 0; left: 0;
    pointer-events: none;
    overflow: visible;
  }
  #edges path {
    fill: none;
    stroke: var(--border-bright);
    stroke-width: 1.5;
    transition: stroke 0.2s;
  }
  #edges path.highlighted {
    stroke: var(--accent);
    stroke-width: 2;
    filter: drop-shadow(0 0 4px var(--accent-glow));
  }
  #edges path.dimmed {
    opacity: 0.15;
  }
  #edges .arrow {
    fill: var(--border-bright);
    transition: fill 0.2s;
  }
  #edges .arrow.highlighted {
    fill: var(--accent);
  }

  /* ─── NODES ─── */
  .node {
    position: absolute;
    width: calc(var(--node-w) * 1px);
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    cursor: pointer;
    transition: opacity 0.2s, border-color 0.2s, box-shadow 0.2s, width 0.3s ease;
    user-select: none;
    overflow: hidden;
    border-left: 3px solid var(--file-color, var(--border));
  }
  .node:hover {
    border-color: var(--border-bright);
    border-left-color: var(--file-color, var(--border-bright));
    box-shadow: 0 4px 24px var(--node-shadow);
  }
  .node.highlighted {
    border-color: var(--file-color, var(--accent));
    box-shadow: 0 0 0 2px var(--file-color-dim, var(--accent-dim)), 0 4px 24px var(--node-shadow);
  }
  .node.dimmed {
    opacity: 0.25;
    transition: opacity 0.2s, border-color 0.2s, box-shadow 0.2s, width 0.3s ease;
  }
  .node.expanded {
    width: 320px;
    z-index: 20;
    box-shadow: 0 8px 40px var(--node-shadow-expanded);
  }

  .node-header {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 12px 14px;
    min-height: calc(var(--node-h) * 1px);
  }
  .node-icon {
    width: 26px; height: 26px;
    border-radius: 6px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 11px;
    font-weight: 700;
    font-family: 'JetBrains Mono', monospace;
    flex-shrink: 0;
  }
  .node-icon.object { background: var(--accent-dim); color: var(--accent); }
  .node-icon.array  { background: var(--green-dim); color: var(--green); }
  .node-icon.enum   { background: var(--amber-dim); color: var(--amber); }
  .node-icon.string { background: var(--purple-dim); color: var(--purple); }
  .node-icon.other  { background: var(--cyan-dim); color: var(--cyan); }
  .node-icon.missing { background: var(--rose-dim); color: var(--rose); }

  /* Ghost nodes — unresolved $ref targets */
  .node.ghost {
    border-style: dashed;
    border-color: var(--rose);
    border-left-width: 3px;
    border-left-color: var(--rose);
    opacity: 0.7;
    background: var(--surface);
  }
  .node.ghost .node-name { color: var(--rose); }
  .node.ghost .node-badge { color: var(--rose); opacity: 0.6; }

  .stat-warn { color: var(--amber); }

  .node-name {
    font-size: 13px;
    font-weight: 600;
    letter-spacing: -0.2px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    flex: 1;
  }
  .node-badge {
    font-size: 10px;
    font-family: 'JetBrains Mono', monospace;
    color: var(--text-muted);
    flex-shrink: 0;
  }

  /* ─── EXPANDED FIELDS ─── */
  .node-fields {
    max-height: 0;
    overflow: hidden;
    transition: max-height 0.35s ease;
    border-top: 0px solid transparent;
  }
  .node.expanded .node-fields {
    max-height: 500px;
    border-top: 1px solid var(--border);
    overflow-y: auto;
  }
  .node-fields::-webkit-scrollbar { width: 4px; }
  .node-fields::-webkit-scrollbar-thumb { background: var(--border-bright); border-radius: 2px; }

  .field-row {
    display: flex;
    align-items: baseline;
    gap: 8px;
    padding: 7px 14px;
    font-size: 12px;
    border-bottom: 1px solid var(--field-row-border);
    transition: background 0.1s;
  }
  .field-row:hover { background: var(--field-row-hover); }
  .field-row:last-child { border-bottom: none; }
  .field-name {
    font-family: 'JetBrains Mono', monospace;
    font-weight: 500;
    color: var(--text);
    min-width: 0;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }
  .field-required {
    color: var(--rose);
    font-size: 9px;
    flex-shrink: 0;
  }
  .field-type {
    margin-left: auto;
    font-family: 'JetBrains Mono', monospace;
    font-size: 11px;
    color: var(--text-dim);
    white-space: nowrap;
    flex-shrink: 0;
  }
  .field-type.ref {
    color: var(--accent);
    cursor: pointer;
    text-decoration: underline;
    text-decoration-style: dotted;
    text-underline-offset: 2px;
  }
  .field-type.ref:hover { color: var(--ref-hover); }

  .field-section-label {
    padding: 8px 14px 4px;
    font-size: 10px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.8px;
    color: var(--text-muted);
  }

  /* ─── EMPTY STATE ─── */
  .empty-state {
    position: absolute;
    inset: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 16px;
    color: var(--text-dim);
    z-index: 10;
  }
  .empty-state svg { opacity: 0.3; }
  .empty-state p { font-size: 14px; max-width: 360px; text-align: center; line-height: 1.6; }
  .empty-state .hint {
    font-size: 12px;
    color: var(--text-muted);
    display: flex; align-items: center; gap: 6px;
  }
  .empty-state kbd {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 4px;
    padding: 2px 6px;
    font-family: 'JetBrains Mono', monospace;
    font-size: 11px;
  }

  .hidden { display: none !important; }

  /* ─── MINIMAP ─── */
  #minimap {
    position: absolute;
    bottom: 16px;
    right: 16px;
    width: 180px;
    height: 120px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 8px;
    overflow: hidden;
    z-index: 50;
    opacity: 0.85;
  }
  #minimap canvas { width: 100%; height: 100%; }

  /* ─── ZOOM CONTROLS ─── */
  .zoom-controls {
    position: absolute;
    bottom: 16px;
    left: 16px;
    display: flex;
    gap: 4px;
    z-index: 50;
  }
  .zoom-btn {
    width: 36px; height: 36px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 8px;
    color: var(--text-dim);
    cursor: pointer;
    font-size: 16px;
    transition: all 0.15s;
  }
  .zoom-btn:hover { background: var(--surface-hover); color: var(--text); }

  /* ─── TOOLTIP ─── */
  .tooltip {
    position: fixed;
    background: var(--surface);
    border: 1px solid var(--border-bright);
    border-radius: 8px;
    padding: 8px 12px;
    font-size: 12px;
    color: var(--text);
    pointer-events: none;
    z-index: 200;
    opacity: 0;
    transition: opacity 0.15s;
    max-width: 280px;
    box-shadow: 0 8px 30px rgba(0,0,0,0.4);
  }
  .tooltip.show { opacity: 1; }

  /* ─── LOADING ─── */
  .loading-overlay {
    position: absolute;
    inset: 0;
    background: var(--loading-bg);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 200;
    backdrop-filter: blur(4px);
  }
  .spinner {
    width: 32px; height: 32px;
    border: 3px solid var(--border);
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: spin 0.7s linear infinite;
  }
  @keyframes spin { to { transform: rotate(360deg); } }

  /* ─── SEARCH ─── */
  .search-box {
    position: relative;
  }
  .search-box input {
    padding: 7px 12px 7px 32px;
    width: 200px;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 8px;
    color: var(--text);
    font-family: 'DM Sans', sans-serif;
    font-size: 13px;
    outline: none;
    transition: border-color 0.15s, width 0.2s;
  }
  .search-box input:focus { border-color: var(--accent); width: 260px; }
  .search-box svg {
    position: absolute;
    left: 10px;
    top: 50%;
    transform: translateY(-50%);
    color: var(--text-muted);
    width: 14px; height: 14px;
  }

  /* ─── LEVEL FILTER PANEL ─── */
  .level-filter {
    position: absolute;
    bottom: 16px;
    left: 180px;
    z-index: 50;
    display: flex;
    flex-direction: column;
    gap: 4px;
  }
  .level-filter-toggle {
    width: 36px; height: 36px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 8px;
    color: var(--text-dim);
    cursor: pointer;
    font-size: 14px;
    transition: all 0.15s;
  }
  .level-filter-toggle:hover { background: var(--surface-hover); color: var(--text); }
  .level-filter-toggle.active { border-color: var(--accent); color: var(--accent); }

  .level-panel {
    position: absolute;
    bottom: 44px;
    left: 0;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 10px 0;
    min-width: 220px;
    box-shadow: 0 8px 32px var(--node-shadow-expanded);
    opacity: 0;
    transform: translateY(8px);
    pointer-events: none;
    transition: opacity 0.2s ease, transform 0.2s ease;
  }
  .level-panel.open {
    opacity: 1;
    transform: translateY(0);
    pointer-events: auto;
  }
  .level-panel-title {
    padding: 2px 14px 8px;
    font-size: 10px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.8px;
    color: var(--text-muted);
    border-bottom: 1px solid var(--border);
    margin-bottom: 4px;
  }
  .level-row {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 6px 14px;
    cursor: pointer;
    transition: background 0.1s;
    font-size: 13px;
    user-select: none;
  }
  .level-row:hover { background: var(--surface-hover); }
  .level-check {
    width: 18px; height: 18px;
    border-radius: 5px;
    border: 1.5px solid var(--border-bright);
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.15s;
    flex-shrink: 0;
  }
  .level-row.checked .level-check {
    background: var(--accent);
    border-color: var(--accent);
  }
  .level-check svg {
    width: 12px; height: 12px;
    stroke: #fff;
    stroke-width: 2.5;
    fill: none;
    opacity: 0;
    transition: opacity 0.15s;
  }
  .level-row.checked .level-check svg { opacity: 1; }
  .level-label {
    flex: 1;
    display: flex;
    align-items: center;
    gap: 8px;
    min-width: 0;
  }
  .level-label > span:nth-child(2) {
    flex: 1;
    min-width: 0;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    font-size: 12px;
    color: var(--text-dim);
  }
  .level-label .level-num {
    font-family: 'JetBrains Mono', monospace;
    font-weight: 600;
    font-size: 11px;
    width: 20px; height: 20px;
    border-radius: 5px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--accent-dim);
    color: var(--accent);
  }
  .level-label .level-count {
    margin-left: auto;
    font-size: 11px;
    font-family: 'JetBrains Mono', monospace;
    color: var(--text-muted);
  }
  .level-panel-actions {
    display: flex;
    gap: 6px;
    padding: 8px 14px 2px;
    border-top: 1px solid var(--border);
    margin-top: 4px;
  }
  .level-panel-actions button {
    flex: 1;
    padding: 5px 0;
    font-size: 11px;
    font-family: 'DM Sans', sans-serif;
    font-weight: 500;
    background: none;
    border: 1px solid var(--border);
    border-radius: 6px;
    color: var(--text-dim);
    cursor: pointer;
    transition: all 0.15s;
  }
  .level-panel-actions button:hover {
    background: var(--surface-hover);
    color: var(--text);
    border-color: var(--border-bright);
  }

  /* ─── THEME TOGGLE ─── */
  .theme-toggle {
    width: 38px; height: 38px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 8px;
    cursor: pointer;
    color: var(--text-dim);
    transition: all 0.25s ease;
    flex-shrink: 0;
    position: relative;
    overflow: hidden;
  }
  .theme-toggle:hover { background: var(--surface-hover); color: var(--text); border-color: var(--border-bright); }
  .theme-toggle svg {
    width: 17px; height: 17px;
    transition: transform 0.4s ease, opacity 0.25s ease;
    position: absolute;
  }
  .theme-toggle .icon-sun { opacity: 0; transform: rotate(-90deg) scale(0.5); }
  .theme-toggle .icon-moon { opacity: 1; transform: rotate(0) scale(1); }
  [data-theme="light"] .theme-toggle .icon-sun { opacity: 1; transform: rotate(0) scale(1); }
  [data-theme="light"] .theme-toggle .icon-moon { opacity: 0; transform: rotate(90deg) scale(0.5); }

  /* Smooth transitions for themed elements */
  header, .node, .btn, .chip, .zoom-btn, #minimap, .search-box input, .empty-state kbd, .tooltip {
    transition: background 0.35s ease, border-color 0.35s ease, color 0.35s ease, box-shadow 0.25s ease;
  }
  .canvas-wrap { transition: background 0.35s ease; }