:root {
  --bg-deep: #0a0a0f;
  --bg-surface: #12121a;
  --bg-card: #1a1a28;
  --bg-elevated: #222236;
  --border: #2a2a44;
  --border-glow: #4a4a7a;
  --text-primary: #e8e8f0;
  --text-secondary: #8888aa;
  --text-muted: #555570;
  --accent-1: #6c5ce7;
  --accent-2: #00cec9;
  --accent-3: #fd79a8;
  --accent-4: #fdcb6e;
  --accent-5: #55efc4;
  --type-string: #55efc4;
  --type-number: #74b9ff;
  --type-boolean: #fd79a8;
  --type-null: #636e72;
  --type-object: #6c5ce7;
  --type-array: #fdcb6e;
  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 16px;
  --radius-xl: 24px;
  --shadow-glow: 0 0 30px rgba(108,92,231,0.15);
  --transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

* { margin: 0; padding: 0; box-sizing: border-box; }

body {
  font-family: 'Outfit', sans-serif;
  background: var(--bg-deep);
  color: var(--text-primary);
  overflow: hidden;
  height: 100vh;
  position: relative;
}

body::before {
  content: '';
  position: fixed;
  top: -50%; left: -50%;
  width: 200%; height: 200%;
  background: radial-gradient(ellipse at 30% 20%, rgba(108,92,231,0.08) 0%, transparent 50%),
              radial-gradient(ellipse at 70% 80%, rgba(0,206,201,0.06) 0%, transparent 50%),
              radial-gradient(ellipse at 50% 50%, rgba(253,121,168,0.04) 0%, transparent 60%);
  animation: nebula 30s ease-in-out infinite alternate;
  pointer-events: none; z-index: 0;
}

@keyframes nebula {
  0% { transform: translate(0,0) rotate(0deg); }
  100% { transform: translate(-3%,-3%) rotate(5deg); }
}

/* SCROLLBAR */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--border-glow); }

/* LAYOUT */
.app { display: flex; flex-direction: column; height: 100vh; position: relative; z-index: 1; }

/* HEADER */
.header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 24px;
  background: rgba(18,18,26,0.85);
  backdrop-filter: blur(20px);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.logo {
  display: flex; align-items: center; gap: 12px;
  font-weight: 800; font-size: 20px; letter-spacing: -0.5px;
}

.logo-icon {
  width: 36px; height: 36px;
  background: linear-gradient(135deg, var(--accent-1), var(--accent-2));
  border-radius: var(--radius-sm);
  display: flex; align-items: center; justify-content: center;
  font-size: 18px; font-weight: 900; color: white;
  box-shadow: 0 4px 15px rgba(108,92,231,0.4);
  animation: logoPulse 3s ease-in-out infinite;
}

@keyframes logoPulse {
  0%,100% { box-shadow: 0 4px 15px rgba(108,92,231,0.4); }
  50% { box-shadow: 0 4px 25px rgba(108,92,231,0.6); }
}

.logo span { background: linear-gradient(135deg, var(--accent-1), var(--accent-2)); -webkit-background-clip: text; -webkit-text-fill-color: transparent; }

.header-actions { display: flex; align-items: center; gap: 8px; }

/* BUTTONS */
.btn {
  font-family: 'Outfit', sans-serif;
  padding: 8px 16px; border: 1px solid var(--border);
  background: var(--bg-card); color: var(--text-primary);
  border-radius: var(--radius-sm); cursor: pointer;
  font-size: 13px; font-weight: 500;
  transition: var(--transition);
  display: flex; align-items: center; gap: 6px;
  white-space: nowrap;
}
.btn:hover { border-color: var(--accent-1); background: var(--bg-elevated); transform: translateY(-1px); }
.btn.active { background: var(--accent-1); border-color: var(--accent-1); color: white; box-shadow: 0 4px 15px rgba(108,92,231,0.4); }
.btn-accent { background: linear-gradient(135deg, var(--accent-1), #8b5cf6); border: none; color: white; }
.btn-accent:hover { box-shadow: 0 4px 20px rgba(108,92,231,0.5); transform: translateY(-1px); }
.btn-danger { border-color: #e74c3c44; }
.btn-danger:hover { background: #e74c3c22; border-color: #e74c3c; }

.btn-icon {
  width: 36px; height: 36px; padding: 0;
  display: flex; align-items: center; justify-content: center;
  border-radius: var(--radius-sm);
}

/* TOOLBAR */
.toolbar {
  display: flex; align-items: center; gap: 8px;
  padding: 10px 24px;
  background: rgba(18,18,26,0.6);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  flex-wrap: wrap;
}

.view-tabs { display: flex; gap: 4px; background: var(--bg-deep); border-radius: var(--radius-sm); padding: 3px; }
.view-tab {
  padding: 6px 14px; border: none; background: transparent;
  color: var(--text-secondary); cursor: pointer; font-family: 'Outfit'; font-size: 13px; font-weight: 500;
  border-radius: 4px; transition: var(--transition);
}
.view-tab:hover { color: var(--text-primary); }
.view-tab.active { background: var(--accent-1); color: white; }

.search-box {
  flex: 1; min-width: 200px; max-width: 400px;
  position: relative;
}
.search-box input {
  width: 100%; padding: 8px 12px 8px 36px;
  background: var(--bg-deep); border: 1px solid var(--border);
  color: var(--text-primary); border-radius: var(--radius-sm);
  font-family: 'JetBrains Mono'; font-size: 12px;
  transition: var(--transition); outline: none;
}
.search-box input:focus { border-color: var(--accent-1); box-shadow: 0 0 0 3px rgba(108,92,231,0.15); }
.search-box input::placeholder { color: var(--text-muted); }
.search-box .search-icon {
  position: absolute; left: 10px; top: 50%; transform: translateY(-50%);
  color: var(--text-muted); font-size: 14px; pointer-events: none;
}

.stats {
  display: flex; gap: 12px; margin-left: auto;
  font-size: 12px; color: var(--text-secondary); font-family: 'JetBrains Mono';
}
.stat-item { display: flex; align-items: center; gap: 4px; }
.stat-dot { width: 8px; height: 8px; border-radius: 50%; }

/* MAIN AREA */
.main { flex: 1; display: flex; overflow: hidden; position: relative; }

/* INPUT PANEL */
.input-panel {
  width: 420px; min-width: 320px;
  display: flex; flex-direction: column;
  border-right: 1px solid var(--border);
  background: rgba(18,18,26,0.5);
  transition: width 0.3s ease;
  flex-shrink: 0;
}
.input-panel.collapsed { width: 0; min-width: 0; overflow: hidden; border: none; }

.panel-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  font-size: 13px; font-weight: 600;
}
.panel-header .badge {
  font-size: 10px; padding: 2px 8px; background: var(--accent-1);
  color: white; border-radius: 10px; font-weight: 600;
}

.input-area {
  flex: 1; position: relative; overflow: hidden;
}

.code-editor {
  position: relative; width: 100%; height: 100%;
  overflow: auto;
}

.code-highlight {
  position: absolute; inset: 0;
  padding: 16px; margin: 0;
  font-family: 'JetBrains Mono'; font-size: 12px; line-height: 1.7;
  white-space: pre-wrap; word-wrap: break-word;
  pointer-events: none;
  tab-size: 2; overflow: hidden;
  z-index: 0;
}

#jsonInput {
  position: relative; z-index: 1;
  width: 100%; height: 100%;
  background: transparent; border: none;
  color: transparent;
  font-family: 'JetBrains Mono'; font-size: 12px; line-height: 1.7;
  padding: 16px; resize: none; outline: none;
  tab-size: 2;
  caret-color: var(--accent-2);
}
#jsonInput::placeholder { color: var(--text-muted); }
#jsonInput::selection { background: rgba(108,92,231,0.3); color: transparent; }

/* Syntax tokens */
.hl-key { color: #00cec9; }
.hl-string { color: #55efc4; }
.hl-number { color: #74b9ff; }
.hl-boolean { color: #fd79a8; }
.hl-null { color: #636e72; font-style: italic; }
.hl-brace { color: #a29bfe; }
.hl-bracket { color: #fdcb6e; }
.hl-colon { color: #888; }
.hl-comma { color: #555; }

/* CODE GEN MODAL */
.codegen-overlay {
  position: fixed; inset: 0; background: rgba(0,0,0,0.65);
  backdrop-filter: blur(10px);
  display: flex; align-items: center; justify-content: center;
  z-index: 1000; opacity: 0; pointer-events: none; transition: opacity 0.25s;
}
.codegen-overlay.visible { opacity: 1; pointer-events: all; }

.codegen-modal {
  background: var(--bg-card); border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  width: 720px; max-width: 95vw; max-height: 85vh;
  display: flex; flex-direction: column;
  box-shadow: 0 25px 60px rgba(0,0,0,0.5), var(--shadow-glow);
  transform: scale(0.95); transition: transform 0.25s;
  overflow: hidden;
}
.codegen-overlay.visible .codegen-modal { transform: scale(1); }

.codegen-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 18px 24px; border-bottom: 1px solid var(--border);
}
.codegen-header h3 { font-size: 17px; font-weight: 700; display: flex; align-items: center; gap: 8px; }

.codegen-langs {
  display: flex; gap: 4px; padding: 12px 24px;
  overflow-x: auto; border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.lang-tab {
  padding: 6px 14px; border: 1px solid var(--border);
  background: var(--bg-deep); color: var(--text-secondary);
  border-radius: var(--radius-sm); cursor: pointer;
  font-family: 'Outfit'; font-size: 12px; font-weight: 600;
  transition: var(--transition); white-space: nowrap;
  display: flex; align-items: center; gap: 5px;
}
.lang-tab:hover { border-color: var(--accent-1); color: var(--text-primary); }
.lang-tab.active { background: var(--accent-1); border-color: var(--accent-1); color: white; }

.codegen-body {
  flex: 1; overflow: auto; position: relative;
}

.codegen-output {
  margin: 0; padding: 20px 24px;
  font-family: 'JetBrains Mono'; font-size: 12px; line-height: 1.7;
  color: var(--text-primary); white-space: pre-wrap; word-wrap: break-word;
  background: transparent; min-height: 200px;
}
.codegen-output .ck-keyword { color: #c792ea; font-weight: 600; }
.codegen-output .ck-type { color: #ffcb6b; }
.codegen-output .ck-string { color: #c3e88d; }
.codegen-output .ck-number { color: #f78c6c; }
.codegen-output .ck-comment { color: #546e7a; font-style: italic; }
.codegen-output .ck-decorator { color: #82aaff; }
.codegen-output .ck-func { color: #82aaff; }
.codegen-output .ck-class { color: #ffcb6b; font-weight: 600; }
.codegen-output .ck-prop { color: #00cec9; }
.codegen-output .ck-punct { color: #89ddff; }
.codegen-output .ck-brace { color: #a29bfe; }
.codegen-output .ck-generic { color: #ff5370; }

.codegen-footer {
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 24px; border-top: 1px solid var(--border);
  font-size: 12px; color: var(--text-muted);
}
.codegen-footer .line-count { font-family: 'JetBrains Mono'; }

.input-actions {
  display: flex; gap: 6px; padding: 10px 16px;
  border-top: 1px solid var(--border);
}

/* RESIZE HANDLE */
.resize-handle {
  width: 4px; cursor: col-resize;
  background: transparent; transition: background 0.2s;
  flex-shrink: 0; position: relative;
}
.resize-handle:hover, .resize-handle.active { background: var(--accent-1); }

/* VISUALIZATION PANEL */
.viz-panel {
  flex: 1; display: flex; flex-direction: column;
  overflow: hidden; position: relative;
}

/* TREE VIEW */
.tree-container {
  flex: 1; overflow: auto; padding: 20px;
  display: none;
}
.tree-container.active { display: block; }

.tree-node {
  margin-left: 4px;
  animation: nodeIn 0.2s ease-out;
}
@keyframes nodeIn {
  from { opacity: 0; transform: translateX(-8px); }
  to { opacity: 1; transform: translateX(0); }
}

.tree-row {
  display: flex; align-items: center; gap: 4px;
  padding: 3px 8px; border-radius: 4px;
  cursor: pointer; transition: background 0.15s;
  font-size: 13px; line-height: 1.6;
  position: relative;
}
.tree-row:hover { background: rgba(108,92,231,0.08); }
.tree-row.highlight { background: rgba(108,92,231,0.15); outline: 1px solid var(--accent-1); }
.tree-row.search-match { background: rgba(253,203,110,0.12); outline: 1px dashed var(--accent-4); }

.tree-toggle {
  width: 18px; height: 18px;
  display: flex; align-items: center; justify-content: center;
  color: var(--text-muted); flex-shrink: 0;
  transition: transform 0.2s;
  font-size: 10px;
}
.tree-toggle.open { transform: rotate(90deg); }
.tree-toggle.leaf { visibility: hidden; }

.tree-key {
  color: var(--accent-2); font-family: 'JetBrains Mono';
  font-size: 12px; font-weight: 500;
}
.tree-colon { color: var(--text-muted); margin: 0 2px; }
.tree-value { font-family: 'JetBrains Mono'; font-size: 12px; }
.tree-value.string { color: var(--type-string); }
.tree-value.number { color: var(--type-number); }
.tree-value.boolean { color: var(--type-boolean); }
.tree-value.null { color: var(--type-null); font-style: italic; }

.tree-bracket {
  color: var(--text-muted); font-family: 'JetBrains Mono';
  font-size: 12px;
}
.tree-count {
  font-size: 10px; color: var(--text-muted);
  background: var(--bg-deep); padding: 1px 6px;
  border-radius: 8px; margin-left: 6px;
  font-family: 'JetBrains Mono';
}
.tree-type-badge {
  font-size: 9px; padding: 1px 5px; border-radius: 3px;
  font-weight: 600; margin-left: 4px; text-transform: uppercase;
  letter-spacing: 0.5px;
}
.tree-type-badge.object { background: rgba(108,92,231,0.15); color: var(--type-object); }
.tree-type-badge.array { background: rgba(253,203,110,0.15); color: var(--type-array); }

.tree-guide {
  position: absolute; left: 0; top: 0; bottom: 0;
  width: 1px; background: var(--border);
}

/* PATH BAR */
.path-bar {
  padding: 8px 16px;
  border-top: 1px solid var(--border);
  font-family: 'JetBrains Mono'; font-size: 11px;
  color: var(--text-secondary);
  display: flex; align-items: center; gap: 4px;
  overflow-x: auto; white-space: nowrap;
  background: rgba(10,10,15,0.5);
  min-height: 36px;
}
.path-segment {
  padding: 2px 6px; background: var(--bg-card); border-radius: 3px;
  cursor: pointer; transition: var(--transition);
}
.path-segment:hover { background: var(--accent-1); color: white; }
.path-sep { color: var(--text-muted); }

/* TABLE VIEW */
.table-container {
  flex: 1; overflow: auto; padding: 20px;
  display: none;
}
.table-container.active { display: block; }

.json-table {
  width: 100%; border-collapse: separate;
  border-spacing: 0; font-size: 13px;
}
.json-table th {
  position: sticky; top: 0; z-index: 2;
  background: var(--bg-card); color: var(--text-secondary);
  text-align: left; padding: 10px 14px;
  border-bottom: 2px solid var(--accent-1);
  font-weight: 600; font-size: 12px;
  text-transform: uppercase; letter-spacing: 0.5px;
}
.json-table td {
  padding: 8px 14px; border-bottom: 1px solid var(--border);
  font-family: 'JetBrains Mono'; font-size: 12px;
  max-width: 300px; overflow: hidden; text-overflow: ellipsis;
  white-space: nowrap; transition: background 0.15s;
}
.json-table tr:hover td { background: rgba(108,92,231,0.06); }
.json-table tr.search-match td { background: rgba(253,203,110,0.08); }

/* GRAPH VIEW */
.graph-container {
  flex: 1; position: relative; overflow: hidden;
  display: none;
}
.graph-container.active { display: block; }

#graphCanvas {
  width: 100%; height: 100%;
  cursor: grab;
}
#graphCanvas.grabbing { cursor: grabbing; }

.graph-controls {
  position: absolute; bottom: 20px; right: 20px;
  display: flex; flex-direction: column; gap: 6px;
  z-index: 10;
}

.graph-minimap {
  position: absolute; bottom: 20px; left: 20px;
  width: 180px; height: 120px;
  background: var(--bg-card); border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  overflow: hidden; z-index: 10;
  opacity: 0.8;
}

/* EDIT MODAL */
.modal-overlay {
  position: fixed; inset: 0; background: rgba(0,0,0,0.6);
  backdrop-filter: blur(8px);
  display: flex; align-items: center; justify-content: center;
  z-index: 1000; opacity: 0; pointer-events: none;
  transition: opacity 0.25s;
}
.modal-overlay.visible { opacity: 1; pointer-events: all; }

.modal {
  background: var(--bg-card); border: 1px solid var(--border);
  border-radius: var(--radius-lg); padding: 28px;
  width: 440px; max-width: 90vw;
  box-shadow: 0 25px 60px rgba(0,0,0,0.5), var(--shadow-glow);
  transform: scale(0.95); transition: transform 0.25s;
}
.modal-overlay.visible .modal { transform: scale(1); }

.modal h3 { font-size: 18px; font-weight: 700; margin-bottom: 6px; }
.modal .modal-path {
  font-family: 'JetBrains Mono'; font-size: 11px;
  color: var(--text-secondary); margin-bottom: 18px;
}

.modal label { display: block; font-size: 12px; font-weight: 600; color: var(--text-secondary); margin-bottom: 6px; }

.modal select, .modal input, .modal textarea {
  width: 100%; padding: 10px 12px;
  background: var(--bg-deep); border: 1px solid var(--border);
  color: var(--text-primary); border-radius: var(--radius-sm);
  font-family: 'JetBrains Mono'; font-size: 13px;
  outline: none; transition: var(--transition);
  margin-bottom: 14px;
}
.modal select:focus, .modal input:focus, .modal textarea:focus {
  border-color: var(--accent-1); box-shadow: 0 0 0 3px rgba(108,92,231,0.15);
}
.modal textarea { min-height: 80px; resize: vertical; }
.modal-actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 6px; }

/* TOAST */
.toast-container { position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%); z-index: 2000; display: flex; flex-direction: column; gap: 8px; }
.toast {
  padding: 12px 20px; background: var(--bg-card); border: 1px solid var(--border);
  border-radius: var(--radius-sm); font-size: 13px; box-shadow: 0 10px 30px rgba(0,0,0,0.4);
  animation: toastIn 0.3s ease-out;
  display: flex; align-items: center; gap: 8px;
}
.toast.success { border-color: var(--accent-5); }
.toast.error { border-color: #e74c3c; }
@keyframes toastIn {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: translateY(0); }
}

/* DROP ZONE */
.drop-zone {
  position: absolute; inset: 0; background: rgba(108,92,231,0.1);
  border: 2px dashed var(--accent-1); border-radius: var(--radius-lg);
  display: flex; align-items: center; justify-content: center;
  font-size: 18px; font-weight: 600; color: var(--accent-1);
  z-index: 100; opacity: 0; pointer-events: none; transition: opacity 0.2s;
}
.drop-zone.visible { opacity: 1; pointer-events: all; }

/* EMPTY STATE */
.empty-state {
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  height: 100%; text-align: center; padding: 40px;
  gap: 16px;
}
.empty-state .icon { font-size: 64px; opacity: 0.3; }
.empty-state h2 { font-size: 22px; font-weight: 700; color: var(--text-secondary); }
.empty-state p { font-size: 14px; color: var(--text-muted); max-width: 360px; line-height: 1.6; }

/* CONTEXT MENU */
.context-menu {
  position: fixed; background: var(--bg-card); border: 1px solid var(--border);
  border-radius: var(--radius-sm); padding: 6px; min-width: 180px;
  box-shadow: 0 10px 30px rgba(0,0,0,0.5); z-index: 500;
  display: none;
}
.context-menu.visible { display: block; }
.context-item {
  padding: 8px 12px; cursor: pointer; border-radius: 4px;
  font-size: 13px; display: flex; align-items: center; gap: 8px;
  transition: background 0.1s;
}
.context-item:hover { background: var(--bg-elevated); }
.context-item .shortcut { margin-left: auto; font-size: 11px; color: var(--text-muted); font-family: 'JetBrains Mono'; }

/* FLOW VIEW */
.flow-container {
  flex: 1; position: relative; overflow: hidden;
  display: none;
  background:
    radial-gradient(circle at 20% 30%, rgba(108,92,231,0.04) 0%, transparent 40%),
    radial-gradient(circle at 80% 70%, rgba(0,206,201,0.03) 0%, transparent 40%);
}
.flow-container.active { display: block; }

#flowCanvas {
  width: 100%; height: 100%;
  cursor: grab;
}
#flowCanvas.grabbing { cursor: grabbing; }

.flow-controls {
  position: absolute; bottom: 20px; right: 20px;
  display: flex; flex-direction: column; gap: 6px;
  z-index: 10;
}

.flow-legend {
  position: absolute; top: 16px; right: 16px;
  display: flex; gap: 10px; flex-wrap: wrap;
  z-index: 10; font-size: 11px;
  background: rgba(18,18,26,0.75);
  backdrop-filter: blur(10px);
  padding: 8px 14px; border-radius: var(--radius-sm);
  border: 1px solid var(--border);
}
.flow-legend-item { display: flex; align-items: center; gap: 5px; color: var(--text-secondary); }
.flow-legend-dot { width: 10px; height: 10px; border-radius: 3px; }

.flow-tooltip {
  position: fixed; z-index: 100;
  background: var(--bg-card); border: 1px solid var(--border-glow);
  border-radius: var(--radius-sm);
  padding: 10px 14px; pointer-events: none;
  font-size: 12px; max-width: 300px;
  box-shadow: 0 8px 30px rgba(0,0,0,0.5);
  opacity: 0; transition: opacity 0.15s;
  font-family: 'JetBrains Mono';
}
.flow-tooltip.visible { opacity: 1; }
.flow-tooltip .tt-path { color: var(--accent-2); margin-bottom: 4px; font-size: 10px; }
.flow-tooltip .tt-type { color: var(--text-muted); font-size: 10px; text-transform: uppercase; }

/* RESPONSIVE */
@media (max-width: 768px) {
  .input-panel { width: 100%; max-height: 200px; border-right: none; border-bottom: 1px solid var(--border); }
  .main { flex-direction: column; }
  .stats { display: none; }
  .resize-handle { display: none; }
}

/* ANIMATIONS */
.fade-in { animation: fadeIn 0.3s ease-out; }
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }