/* ========================================
   JSON Reader — Design System & Styles
   ======================================== */

/* ---------- CSS Custom Properties ---------- */
:root {
  /* Brand */
  --brand-hue: 280;
  --brand: hsl(var(--brand-hue) 65% 55%);
  --brand-light: hsl(var(--brand-hue) 70% 62%);
  --brand-dim: hsl(var(--brand-hue) 40% 44%);
  --brand-bg: hsl(var(--brand-hue) 70% 96%);

  /* Surfaces */
  --bg-primary: #ffffff;
  --bg-secondary: #f8f9fb;
  --bg-tertiary: #f1f3f6;
  --bg-elevated: #ffffff;
  --bg-inset: #eef0f4;

  /* Text */
  --text-primary: #1a1d26;
  --text-secondary: #5a6070;
  --text-tertiary: #8b92a5;
  --text-on-brand: #ffffff;

  /* Borders */
  --border-primary: #e2e5eb;
  --border-secondary: #eef0f4;
  --border-focus: var(--brand);

  /* Shadows */
  --shadow-sm: 0 1px 3px rgba(0,0,0,0.04), 0 1px 2px rgba(0,0,0,0.06);
  --shadow-md: 0 4px 12px rgba(0,0,0,0.06), 0 1px 4px rgba(0,0,0,0.04);
  --shadow-lg: 0 12px 40px rgba(0,0,0,0.08), 0 4px 12px rgba(0,0,0,0.04);
  --shadow-xl: 0 20px 60px rgba(0,0,0,0.1), 0 8px 20px rgba(0,0,0,0.06);

  /* JSON value type colors */
  --json-key: hsl(210 80% 40%);
  --json-string: hsl(150 55% 35%);
  --json-number: hsl(30 85% 45%);
  --json-boolean: hsl(280 60% 50%);
  --json-null: hsl(0 0% 55%);
  --json-bracket: hsl(210 15% 45%);
  --json-comma: hsl(0 0% 70%);
  --json-url: hsl(210 80% 45%);

  /* Misc */
  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 16px;
  --radius-xl: 20px;
  --toolbar-height: 52px;
  --tabs-height: 38px;
  --current-tabs-height: 0px;
  --toc-width: 280px;
  --outline-width: 260px;
  --transition-fast: 0.15s ease;
  --transition-normal: 0.25s ease;
  --transition-slow: 0.35s cubic-bezier(0.4, 0, 0.2, 1);

  /* Content */
  --font-sans: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  --font-mono: 'JetBrains Mono', 'Cascadia Code', 'Consolas', monospace;
  --content-font-family: var(--font-mono);
  --content-max-width: 1000px;
  --content-font-size: 14px;
  --json-indent: 2;
  --json-expand-depth: 2;

  /* Scrollbar */
  --scrollbar-width: 6px;
  --scrollbar-bg: transparent;
  --scrollbar-thumb: rgba(0,0,0,0.15);
  --scrollbar-thumb-hover: rgba(0,0,0,0.25);

  /* Highlight search */
  --search-highlight: hsl(48 100% 65%);
  --search-highlight-active: hsl(30 100% 55%);
}

/* ---------- Dark Theme ---------- */
[data-theme="dark"] {
  --brand: hsl(var(--brand-hue) 70% 65%);
  --brand-light: hsl(var(--brand-hue) 75% 72%);
  --brand-dim: hsl(var(--brand-hue) 50% 55%);
  --brand-bg: hsl(var(--brand-hue) 30% 14%);

  --bg-primary: #0f1117;
  --bg-secondary: #161820;
  --bg-tertiary: #1c1f2a;
  --bg-elevated: #1e2130;
  --bg-inset: #13151c;

  --text-primary: #e4e7ee;
  --text-secondary: #9ba1b2;
  --text-tertiary: #6a7086;
  --text-on-brand: #ffffff;

  --border-primary: #2a2e3d;
  --border-secondary: #22253100;
  --border-focus: var(--brand);

  --shadow-sm: 0 1px 3px rgba(0,0,0,0.2);
  --shadow-md: 0 4px 12px rgba(0,0,0,0.3);
  --shadow-lg: 0 12px 40px rgba(0,0,0,0.4);
  --shadow-xl: 0 20px 60px rgba(0,0,0,0.5);

  --json-key: hsl(210 70% 65%);
  --json-string: hsl(150 50% 60%);
  --json-number: hsl(30 80% 60%);
  --json-boolean: hsl(280 60% 70%);
  --json-null: hsl(0 0% 50%);
  --json-bracket: hsl(210 10% 60%);
  --json-comma: hsl(0 0% 40%);
  --json-url: hsl(210 70% 65%);

  --scrollbar-thumb: rgba(255,255,255,0.12);
  --scrollbar-thumb-hover: rgba(255,255,255,0.22);

  --search-highlight: hsl(48 80% 35%);
  --search-highlight-active: hsl(30 90% 45%);
}

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

html {
  font-size: 16px;
  scroll-behavior: smooth;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

body {
  font-family: var(--font-sans);
  background: var(--bg-primary);
  color: var(--text-primary);
  line-height: 1.6;
  min-height: 100vh;
  transition: background var(--transition-normal), color var(--transition-normal);
  overflow: hidden;
}

body.has-tabs {
  --current-tabs-height: var(--tabs-height);
}

/* Custom Scrollbar */
::-webkit-scrollbar { width: var(--scrollbar-width); height: var(--scrollbar-width); }
::-webkit-scrollbar-track { background: var(--scrollbar-bg); }
::-webkit-scrollbar-thumb { background: var(--scrollbar-thumb); border-radius: 10px; }
::-webkit-scrollbar-thumb:hover { background: var(--scrollbar-thumb-hover); }

::selection {
  background: hsl(var(--brand-hue) 60% 80%);
  color: var(--text-primary);
}
[data-theme="dark"] ::selection {
  background: hsl(var(--brand-hue) 50% 30%);
}

/* ---------- Reading Progress ---------- */
.reading-progress {
  position: fixed; top: 0; left: 0; right: 0; height: 3px; z-index: 1000;
  background: transparent; opacity: 0; transition: opacity var(--transition-normal);
}
.reading-progress.visible { opacity: 1; }
.reading-progress-bar {
  height: 100%; width: 0%;
  background: linear-gradient(90deg, var(--brand), var(--brand-light));
  border-radius: 0 2px 2px 0; transition: width 0.1s linear;
}

/* ---------- Toolbar ---------- */
.toolbar {
  position: fixed; top: 0; left: 0; right: 0; height: var(--toolbar-height);
  background: var(--bg-elevated); border-bottom: 1px solid var(--border-primary);
  display: flex; align-items: center; justify-content: space-between; padding: 0 16px;
  z-index: 900; backdrop-filter: blur(16px); -webkit-backdrop-filter: blur(16px);
  transition: background var(--transition-normal), border-color var(--transition-normal);
}
[data-theme="dark"] .toolbar { background: rgba(15, 17, 23, 0.85); }
[data-theme="light"] .toolbar { background: rgba(255, 255, 255, 0.85); }

.toolbar-left, .toolbar-right {
  display: flex; align-items: center; gap: 4px; flex-shrink: 0;
}
.toolbar-center {
  flex: 1; display: flex; justify-content: center; max-width: 480px; margin: 0 16px;
}
.toolbar-divider { width: 1px; height: 20px; background: var(--border-primary); margin: 0 8px; }

.toolbar-btn {
  display: flex; align-items: center; justify-content: center; width: 36px; height: 36px;
  border: none; background: transparent; color: var(--text-secondary);
  border-radius: var(--radius-sm); cursor: pointer; transition: all var(--transition-fast); flex-shrink: 0;
}
.toolbar-btn:hover { background: var(--bg-tertiary); color: var(--text-primary); }
.toolbar-btn.active { background: var(--brand-bg); color: var(--brand); }

.logo-btn { width: auto; gap: 8px; padding: 0 10px; font-weight: 600; }
.logo-text { font-size: 14px; letter-spacing: -0.3px; color: var(--text-primary); }
.file-name { font-size: 13px; color: var(--text-tertiary); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 150px; }
.doc-stats { font-size: 12px; color: var(--text-tertiary); white-space: nowrap; display: flex; align-items: center; gap: 12px; }
.doc-stats span { display: flex; align-items: center; gap: 4px; }

/* View Switcher */
.view-switcher {
  display: flex; align-items: center; background: var(--bg-tertiary);
  border: 1px solid var(--border-secondary); border-radius: var(--radius-sm); padding: 2px; gap: 2px;
}
.view-btn {
  display: flex; align-items: center; justify-content: center; width: 30px; height: 28px;
  border: none; background: transparent; color: var(--text-tertiary);
  border-radius: 4px; cursor: pointer; transition: all var(--transition-fast);
}
.view-btn:hover { color: var(--text-primary); }
.view-btn.active { background: var(--bg-elevated); color: var(--brand); box-shadow: var(--shadow-sm); }

/* Dropdown menu */
.toolbar-dropdown-container { position: relative; }
.toolbar-dropdown {
  position: absolute; top: calc(100% + 8px); right: 0; background: var(--bg-elevated);
  border: 1px solid var(--border-primary); border-radius: var(--radius-md); box-shadow: var(--shadow-md);
  padding: 6px; min-width: 150px; opacity: 0; visibility: hidden; transform: translateY(-8px);
  transition: all var(--transition-fast); z-index: 1000;
}
.toolbar-dropdown-container:hover .toolbar-dropdown,
.toolbar-dropdown.open { opacity: 1; visibility: visible; transform: translateY(0); }
.dropdown-item {
  padding: 8px 12px; font-size: 13px; color: var(--text-primary);
  border-radius: 4px; cursor: pointer; transition: background var(--transition-fast);
}
.dropdown-item:hover { background: var(--bg-tertiary); }

/* ---------- Tabs ---------- */
.tabs-container {
  position: fixed; top: var(--toolbar-height); left: 0; right: 0; height: var(--tabs-height);
  background: var(--bg-secondary); border-bottom: 1px solid var(--border-primary);
  display: flex; align-items: center; padding: 0 12px; gap: 6px; overflow-x: auto; z-index: 890;
}
.tabs-container::-webkit-scrollbar { height: 0; }
.tab {
  display: flex; align-items: center; height: 28px; padding: 0 10px;
  background: var(--bg-tertiary); border: 1px solid var(--border-secondary);
  border-radius: var(--radius-sm); color: var(--text-secondary); font-size: 13px;
  cursor: pointer; white-space: nowrap; transition: all var(--transition-fast); max-width: 180px; flex-shrink: 0;
}
.tab:hover { background: var(--bg-elevated); }
.tab.active { background: var(--bg-primary); color: var(--brand); border-color: var(--brand); font-weight: 500; }
.tab-title { overflow: hidden; text-overflow: ellipsis; margin-right: 6px; }
.tab-close {
  display: flex; align-items: center; justify-content: center; width: 16px; height: 16px;
  border-radius: 50%; color: var(--text-tertiary); margin-right: -4px;
}
.tab-close:hover { background: rgba(0,0,0,0.1); color: var(--text-primary); }
[data-theme="dark"] .tab-close:hover { background: rgba(255,255,255,0.1); }

/* ---------- Search ---------- */
.search-container {
  display: flex; align-items: center; background: var(--bg-tertiary);
  border: 1px solid var(--border-secondary); border-radius: var(--radius-md);
  padding: 0 12px; height: 36px; width: 100%; transition: all var(--transition-fast);
}
.search-container:focus-within {
  border-color: var(--brand); background: var(--bg-primary);
  box-shadow: 0 0 0 3px hsl(var(--brand-hue) 60% 50% / 0.12);
}
.search-icon { color: var(--text-tertiary); flex-shrink: 0; }
.search-input {
  flex: 1; border: none; background: transparent; color: var(--text-primary);
  font-size: 13.5px; font-family: inherit; padding: 0 8px; outline: none; min-width: 0;
}
.search-input::placeholder { color: var(--text-tertiary); }
.search-results-count { font-size: 11px; color: var(--text-tertiary); white-space: nowrap; padding: 0 6px; }
.search-nav-btn, .search-clear-btn {
  display: flex; align-items: center; justify-content: center; width: 24px; height: 24px;
  border: none; background: transparent; color: var(--text-tertiary); border-radius: 4px;
  cursor: pointer; transition: all var(--transition-fast);
}
.search-nav-btn:hover, .search-clear-btn:hover { background: var(--border-primary); color: var(--text-primary); }

/* ---------- Font Size Popover ---------- */
.popover {
  position: fixed; background: var(--bg-elevated); border: 1px solid var(--border-primary);
  border-radius: var(--radius-lg); padding: 20px; box-shadow: var(--shadow-lg); z-index: 950;
  opacity: 0; visibility: hidden; transform: translateY(-8px); transition: all var(--transition-normal); min-width: 260px;
}
.popover.visible { opacity: 1; visibility: visible; transform: translateY(0); }
.popover-title { font-size: 12px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.5px; color: var(--text-tertiary); margin-bottom: 12px; }
.popover-divider { height: 1px; background: var(--border-primary); margin: 16px 0; }
.font-size-slider-container { display: flex; align-items: center; gap: 12px; }
.font-size-label { font-size: 13px; color: var(--text-tertiary); width: 20px; text-align: center; flex-shrink: 0; }
.font-size-label-lg { font-size: 18px; }
.font-size-slider {
  flex: 1; -webkit-appearance: none; appearance: none; height: 4px; background: var(--bg-tertiary); border-radius: 2px; outline: none;
}
.font-size-slider::-webkit-slider-thumb {
  -webkit-appearance: none; width: 18px; height: 18px; background: var(--brand); border-radius: 50%;
  cursor: pointer; box-shadow: 0 1px 4px rgba(0,0,0,0.15); transition: transform var(--transition-fast);
}
.font-size-slider::-webkit-slider-thumb:hover { transform: scale(1.15); }
.font-size-value { text-align: center; font-size: 12px; color: var(--text-tertiary); margin-top: 6px; }

/* ---------- Main Layout ---------- */
.main-layout {
  display: flex; height: 100vh; padding-top: calc(var(--toolbar-height) + var(--current-tabs-height));
  transition: all var(--transition-normal);
}

/* ---------- History Sidebar ---------- */
.history-sidebar {
  position: fixed; top: calc(var(--toolbar-height) + var(--current-tabs-height)); left: 0; bottom: 0;
  width: 260px; background: var(--bg-secondary); border-right: 1px solid var(--border-primary);
  z-index: 850; transform: translateX(-100%); transition: transform var(--transition-slow);
  display: flex; flex-direction: column;
}
.history-sidebar.open { transform: translateX(0); }
.history-list { flex: 1; overflow-y: auto; padding: 12px; }
.history-item {
  display: flex; flex-direction: column; padding: 10px 12px; margin-bottom: 6px;
  border-radius: var(--radius-sm); background: var(--bg-elevated); border: 1px solid var(--border-primary);
  cursor: pointer; transition: all var(--transition-fast);
}
.history-item:hover { border-color: var(--brand); box-shadow: var(--shadow-sm); }
.history-item-title { font-size: 13px; font-weight: 500; color: var(--text-primary); margin-bottom: 4px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.history-item-meta { font-size: 11px; color: var(--text-tertiary); display: flex; justify-content: space-between; }
.history-item-delete { color: hsl(0 70% 55%); background: none; border: none; cursor: pointer; opacity: 0; transition: opacity 0.2s; font-size: 11px; }
.history-item:hover .history-item-delete { opacity: 1; }

/* ---------- TOC Sidebar ---------- */
.toc-sidebar {
  width: var(--toc-width); min-width: var(--toc-width); background: var(--bg-secondary);
  border-right: 1px solid var(--border-primary); display: flex; flex-direction: column; overflow: hidden;
  transform: translateX(-100%); margin-left: calc(-1 * var(--toc-width));
  transition: transform var(--transition-slow), margin var(--transition-slow);
}
.toc-sidebar.open { transform: translateX(0); margin-left: 0; }
.toc-header {
  display: flex; align-items: center; justify-content: space-between; padding: 16px 16px 12px;
  border-bottom: 1px solid var(--border-secondary); flex-shrink: 0;
}
.toc-header h3 { font-size: 13px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.5px; color: var(--text-tertiary); }
.toc-close-btn {
  display: flex; align-items: center; justify-content: center; width: 28px; height: 28px;
  border: none; background: transparent; color: var(--text-tertiary); border-radius: var(--radius-sm); cursor: pointer; transition: all var(--transition-fast);
}
.toc-close-btn:hover { background: var(--bg-tertiary); color: var(--text-primary); }

.toc-nav { flex: 1; overflow-y: auto; padding: 12px 8px; }
.toc-item {
  display: block; padding: 6px 12px; font-size: 13px; color: var(--text-secondary); text-decoration: none;
  border-radius: var(--radius-sm); cursor: pointer; transition: all var(--transition-fast); line-height: 1.5;
  border-left: 2px solid transparent; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  font-family: var(--font-mono);
}
.toc-item:hover { background: var(--bg-tertiary); color: var(--text-primary); }
.toc-item.active { background: var(--brand-bg); color: var(--brand); border-left-color: var(--brand); font-weight: 500; }
.toc-item[data-level="2"] { padding-left: 28px; }
.toc-item[data-level="3"] { padding-left: 44px; font-size: 12.5px; }
.toc-item[data-level="4"] { padding-left: 56px; font-size: 12px; }
.toc-item .toc-type-icon { font-size: 11px; opacity: 0.6; margin-right: 4px; }

/* ---------- Outline Sidebar ---------- */
.outline-sidebar {
  width: var(--outline-width); min-width: var(--outline-width); background: var(--bg-secondary);
  border-left: 1px solid var(--border-primary); display: flex; flex-direction: column; overflow: hidden;
  transform: translateX(100%); margin-right: calc(-1 * var(--outline-width));
  transition: transform var(--transition-slow), margin var(--transition-slow);
}
.outline-sidebar.open { transform: translateX(0); margin-right: 0; }
.outline-content { flex: 1; overflow-y: auto; padding: 12px 16px; font-size: 13px; color: var(--text-secondary); line-height: 1.7; }
.outline-section { margin-bottom: 16px; }
.outline-section-title { font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.5px; color: var(--text-tertiary); margin-bottom: 6px; }
.outline-stat { display: flex; justify-content: space-between; padding: 3px 0; }
.outline-stat-label { color: var(--text-tertiary); }
.outline-stat-value { font-weight: 500; color: var(--text-primary); font-variant-numeric: tabular-nums; }
.outline-type-bar { display: flex; gap: 4px; height: 6px; border-radius: 3px; overflow: hidden; margin-top: 6px; }
.outline-type-segment { height: 100%; transition: flex var(--transition-normal); }

/* ---------- Content Area ---------- */
.content-area { flex: 1; overflow-y: auto; overflow-x: hidden; scroll-behavior: smooth; position: relative; }

/* ---------- Welcome Screen ---------- */
.welcome-screen { display: flex; align-items: center; justify-content: center; min-height: calc(100vh - var(--toolbar-height)); padding: 40px 24px; }
.welcome-inner { text-align: center; max-width: 520px; animation: fadeInUp 0.6s ease; }
@keyframes fadeInUp { from { opacity: 0; transform: translateY(20px); } to { opacity: 1; transform: translateY(0); } }
.welcome-icon { color: var(--brand); margin-bottom: 20px; opacity: 0.8; }
.welcome-title { font-size: 36px; font-weight: 700; letter-spacing: -1px; background: linear-gradient(135deg, var(--brand), var(--brand-light)); -webkit-background-clip: text; -webkit-text-fill-color: transparent; background-clip: text; margin-bottom: 8px; }
.welcome-subtitle { font-size: 16px; color: var(--text-tertiary); margin-bottom: 36px; }
.welcome-drop-zone { border: 2px dashed var(--border-primary); border-radius: var(--radius-xl); padding: 40px 24px; margin-bottom: 28px; cursor: pointer; transition: all var(--transition-normal); }
.welcome-drop-zone:hover, .welcome-drop-zone.drag-over { border-color: var(--brand); background: var(--brand-bg); }
.welcome-drop-zone.drag-over { transform: scale(1.02); }
.drop-zone-content { display: flex; flex-direction: column; align-items: center; gap: 12px; color: var(--text-secondary); }
.drop-zone-content p { font-size: 15px; font-weight: 500; }
.drop-zone-hint { font-size: 13px; color: var(--text-tertiary); }
.welcome-actions { display: flex; gap: 12px; justify-content: center; margin-bottom: 36px; flex-wrap: wrap; }
.welcome-btn { display: flex; align-items: center; gap: 8px; padding: 10px 20px; border: 1px solid var(--border-primary); background: var(--bg-elevated); color: var(--text-primary); font-size: 14px; font-weight: 500; font-family: inherit; border-radius: var(--radius-md); cursor: pointer; transition: all var(--transition-fast); }
.welcome-btn:hover { border-color: var(--brand); box-shadow: var(--shadow-sm); transform: translateY(-1px); }
.welcome-btn.primary { background: var(--brand); border-color: var(--brand); color: var(--text-on-brand); }
.welcome-btn.primary:hover { background: var(--brand-light); border-color: var(--brand-light); box-shadow: var(--shadow-md); }
.welcome-shortcuts { padding-top: 8px; }
.welcome-shortcuts h4 { font-size: 12px; text-transform: uppercase; letter-spacing: 0.5px; color: var(--text-tertiary); margin-bottom: 14px; }
.shortcut-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.shortcut-item { display: flex; align-items: center; gap: 6px; font-size: 12px; color: var(--text-tertiary); justify-content: center; }
kbd { display: inline-flex; align-items: center; justify-content: center; min-width: 22px; height: 22px; padding: 0 5px; background: var(--bg-tertiary); border: 1px solid var(--border-primary); border-radius: 4px; font-size: 11px; font-family: inherit; font-weight: 500; color: var(--text-secondary); box-shadow: 0 1px 0 var(--border-primary); }

/* ---------- JSON Container ---------- */
.json-container {
  font-family: var(--content-font-family);
  max-width: var(--content-max-width);
  margin: 0 auto;
  padding: 0 0 120px;
  animation: fadeIn 0.35s ease;
}
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }

/* JSON Toolbar (breadcrumb + actions) */
.json-toolbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 40px; background: var(--bg-secondary);
  border-bottom: 1px solid var(--border-primary);
  margin-bottom: 8px; gap: 12px;
}
.json-breadcrumb {
  display: flex; align-items: center; gap: 4px; flex: 1;
  overflow-x: auto; white-space: nowrap; font-size: 12.5px; color: var(--text-tertiary);
}
.json-breadcrumb::-webkit-scrollbar { height: 0; }
.json-breadcrumb-item {
  cursor: pointer; padding: 2px 6px; border-radius: 4px; transition: all var(--transition-fast);
  font-family: var(--font-mono);
}
.json-breadcrumb-item:hover { background: var(--bg-tertiary); color: var(--text-primary); }
.json-breadcrumb-sep { color: var(--text-tertiary); opacity: 0.5; }
.json-toolbar-actions { display: flex; gap: 6px; flex-shrink: 0; }
.json-toolbar-btn {
  display: flex; align-items: center; gap: 5px; padding: 4px 10px; border: 1px solid var(--border-primary);
  background: var(--bg-elevated); color: var(--text-secondary); font-size: 12px; font-family: inherit;
  border-radius: var(--radius-sm); cursor: pointer; transition: all var(--transition-fast);
}
.json-toolbar-btn:hover { border-color: var(--brand); color: var(--brand); }

/* ---------- JSON Body ---------- */
.json-body {
  padding: 8px 40px;
  font-size: var(--content-font-size);
  line-height: 1.7;
}

/* ---------- Tree View ---------- */
.json-tree { font-family: var(--font-mono); }
.json-node { position: relative; }
.json-node-row {
  display: flex; align-items: flex-start; gap: 0; padding: 1px 4px; border-radius: 4px;
  transition: background var(--transition-fast); position: relative; min-height: 24px;
}
.json-node-row:hover { background: var(--bg-tertiary); }
.json-node-row:hover .json-node-actions { opacity: 1; }

.json-toggle {
  display: flex; align-items: center; justify-content: center; width: 16px; height: 22px; flex-shrink: 0;
  cursor: pointer; color: var(--text-tertiary); transition: transform var(--transition-fast); user-select: none;
}
.json-toggle.expanded { transform: rotate(90deg); }
.json-toggle.leaf { visibility: hidden; }

.json-key { color: var(--json-key); font-weight: 500; }
.json-key::after { content: ': '; color: var(--json-bracket); }
.json-colon { color: var(--json-bracket); margin-right: 4px; }

.json-value { display: inline; }
.json-value-string { color: var(--json-string); }
.json-value-number { color: var(--json-number); }
.json-value-boolean { color: var(--json-boolean); }
.json-value-null { color: var(--json-null); font-style: italic; }
.json-value-undefined { color: var(--json-null); font-style: italic; opacity: 0.7; }

.json-string-quote { color: var(--json-bracket); opacity: 0.6; }
.json-url { color: var(--json-url); text-decoration: underline; cursor: pointer; }
.json-url:hover { text-decoration: underline; }

.json-bracket { color: var(--json-bracket); }
.json-bracket-open, .json-bracket-close { font-weight: 500; }
.json-comma { color: var(--json-comma); }
.json-count { color: var(--text-tertiary); font-size: 0.85em; margin-left: 4px; font-style: italic; }

.json-preview {
  color: var(--text-tertiary); font-size: 0.85em; font-style: italic; margin-left: 8px;
  opacity: 0.7; max-width: 300px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}

/* Nested children with guide lines */
.json-children {
  margin-left: 16px; padding-left: 12px; border-left: 1px solid var(--border-secondary);
  overflow: hidden;
}
.json-children.collapsed { display: none; }

/* Node actions (copy value, copy path) */
.json-node-actions {
  display: flex; gap: 4px; margin-left: 8px; opacity: 0; transition: opacity var(--transition-fast);
  flex-shrink: 0; align-self: center;
}
.json-action-btn {
  display: flex; align-items: center; justify-content: center; width: 22px; height: 22px;
  border: none; background: transparent; color: var(--text-tertiary); border-radius: 4px;
  cursor: pointer; transition: all var(--transition-fast);
}
.json-action-btn:hover { background: var(--bg-elevated); color: var(--brand); }
.json-action-btn.copied { color: hsl(150 60% 45%); }

/* Search highlight in tree */
.json-node-row.search-match { background: hsl(48 100% 90%); }
[data-theme="dark"] .json-node-row.search-match { background: hsl(48 80% 20%); }
.json-node-row.search-active { background: hsl(30 100% 88%); box-shadow: inset 0 0 0 2px var(--search-highlight-active); }
[data-theme="dark"] .json-node-row.search-active { background: hsl(30 90% 25%); }
.search-mark { background: var(--search-highlight); color: inherit; padding: 1px 2px; border-radius: 2px; }
.search-mark.active { background: var(--search-highlight-active); }

/* ---------- Table View ---------- */
.json-table-wrapper { overflow-x: auto; padding: 8px 0; }
.json-table {
  width: 100%; border-collapse: collapse; font-size: 13px; font-family: var(--font-mono);
  border: 1px solid var(--border-primary); border-radius: var(--radius-md); overflow: hidden;
}
.json-table th {
  background: var(--bg-tertiary); font-weight: 600; text-align: left; padding: 10px 14px;
  border-bottom: 2px solid var(--border-primary); white-space: nowrap; position: sticky; top: 0; z-index: 1;
  cursor: pointer; user-select: none; transition: background var(--transition-fast);
}
.json-table th:hover { background: var(--bg-inset); }
.json-table th .th-sort-icon { opacity: 0.3; margin-left: 4px; font-size: 10px; }
.json-table th.sorted .th-sort-icon { opacity: 1; color: var(--brand); }
.json-table td { padding: 8px 14px; border-bottom: 1px solid var(--border-secondary); vertical-align: top; max-width: 400px; overflow: hidden; text-overflow: ellipsis; }
.json-table tbody tr:hover { background: var(--brand-bg); }
.json-table tbody tr:last-child td { border-bottom: none; }
.json-table .cell-string { color: var(--json-string); }
.json-table .cell-number { color: var(--json-number); }
.json-table .cell-boolean { color: var(--json-boolean); }
.json-table .cell-null { color: var(--json-null); font-style: italic; }
.json-table .cell-object, .json-table .cell-array { color: var(--json-bracket); }
.json-table .cell-expand { color: var(--brand); cursor: pointer; font-size: 11px; }
.json-table-empty { text-align: center; padding: 40px; color: var(--text-tertiary); font-family: var(--font-sans); }
.json-table-row-num { color: var(--text-tertiary); font-size: 11px; text-align: right; user-select: none; }

/* ---------- Raw View ---------- */
.json-raw-view {
  font-family: var(--font-mono); font-size: var(--content-font-size); line-height: 1.7;
  white-space: pre-wrap; word-break: break-all; padding: 8px 0;
}
.json-raw-view pre { margin: 0; padding: 0; background: transparent !important; }
.json-raw-view code { font-family: inherit !important; background: transparent !important; padding: 0 !important; }

/* ---------- JSON Error ---------- */
.json-error {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  padding: 60px 40px; text-align: center; gap: 16px;
}
.json-error-icon { color: hsl(0 70% 55%); }
.json-error-title { font-size: 20px; font-weight: 600; color: var(--text-primary); font-family: var(--font-sans); }
.json-error-msg { font-size: 14px; color: var(--text-secondary); font-family: var(--font-mono); background: var(--bg-tertiary); padding: 16px 20px; border-radius: var(--radius-md); max-width: 600px; word-break: break-all; }

/* ---------- Back to Top ---------- */
.back-to-top {
  position: fixed; bottom: 32px; right: 32px; width: 44px; height: 44px; border: none;
  background: var(--bg-elevated); color: var(--text-secondary); border-radius: 50%;
  box-shadow: var(--shadow-md); cursor: pointer; display: flex; align-items: center; justify-content: center;
  opacity: 0; visibility: hidden; transform: translateY(12px); transition: all var(--transition-normal); z-index: 800;
}
.back-to-top.visible { opacity: 1; visibility: visible; transform: translateY(0); }
.back-to-top:hover { background: var(--brand); color: var(--text-on-brand); box-shadow: var(--shadow-lg); transform: translateY(-2px); }

/* ---------- Modals ---------- */
.modal-overlay {
  position: fixed; inset: 0; background: rgba(0, 0, 0, 0.45); display: flex; align-items: center; justify-content: center;
  z-index: 1000; opacity: 0; visibility: hidden; transition: all var(--transition-normal); backdrop-filter: blur(4px);
}
.modal-overlay.visible { opacity: 1; visibility: visible; }
.modal {
  background: var(--bg-elevated); border: 1px solid var(--border-primary); border-radius: var(--radius-lg); box-shadow: var(--shadow-xl);
  width: 90%; max-width: 640px; max-height: 80vh; display: flex; flex-direction: column; transform: scale(0.95) translateY(10px); transition: transform var(--transition-normal);
}
.modal-overlay.visible .modal { transform: scale(1) translateY(0); }
.modal-header { display: flex; align-items: center; justify-content: space-between; padding: 20px 24px 16px; }
.modal-header h3 { font-size: 18px; font-weight: 600; }
.modal-close-btn {
  display: flex; align-items: center; justify-content: center; width: 32px; height: 32px; border: none; background: transparent;
  color: var(--text-tertiary); border-radius: var(--radius-sm); cursor: pointer; transition: all var(--transition-fast);
}
.modal-close-btn:hover { background: var(--bg-tertiary); color: var(--text-primary); }
.modal-body { flex: 1; padding: 0 24px; overflow: auto; }
.settings-section { margin-bottom: 20px; }
.settings-section h4 { font-size: 14px; font-weight: 600; margin-bottom: 8px; }
.settings-desc { font-size: 12px; color: var(--text-tertiary); margin-bottom: 12px; }
.paste-textarea {
  width: 100%; height: 320px; border: 1px solid var(--border-primary); border-radius: var(--radius-md); padding: 16px;
  font-family: var(--font-mono); font-size: 13.5px; line-height: 1.6; background: var(--bg-secondary); color: var(--text-primary);
  resize: vertical; outline: none; transition: border-color var(--transition-fast);
}
.paste-textarea:focus { border-color: var(--brand); }
.modal-footer { display: flex; justify-content: flex-end; gap: 10px; padding: 16px 24px 20px; }
.modal-btn {
  padding: 8px 20px; border: 1px solid var(--border-primary); background: var(--bg-elevated); color: var(--text-primary);
  font-size: 14px; font-weight: 500; font-family: inherit; border-radius: var(--radius-sm); cursor: pointer; transition: all var(--transition-fast);
}
.modal-btn:hover { background: var(--bg-tertiary); }
.modal-btn.primary { background: var(--brand); border-color: var(--brand); color: var(--text-on-brand); }
.modal-btn.primary:hover { background: var(--brand-light); }

/* ---------- Toast & Drag Overlay ---------- */
.toast-container { position: fixed; bottom: 28px; left: 50%; transform: translateX(-50%); z-index: 1100; display: flex; flex-direction: column-reverse; align-items: center; gap: 8px; }
.toast { padding: 10px 20px; background: var(--text-primary); color: var(--bg-primary); font-size: 13.5px; font-weight: 500; border-radius: var(--radius-md); box-shadow: var(--shadow-lg); animation: toastIn 0.35s ease, toastOut 0.35s ease 2.5s forwards; white-space: nowrap; }
@keyframes toastIn { from { opacity: 0; transform: translateY(12px) scale(0.95); } to { opacity: 1; transform: translateY(0) scale(1); } }
@keyframes toastOut { from { opacity: 1; transform: translateY(0) scale(1); } to { opacity: 0; transform: translateY(-8px) scale(0.95); } }

.drag-overlay { position: fixed; inset: 0; background: rgba(0, 0, 0, 0.4); backdrop-filter: blur(8px); display: flex; align-items: center; justify-content: center; z-index: 1200; opacity: 0; visibility: hidden; transition: all var(--transition-normal); }
.drag-overlay.visible { opacity: 1; visibility: visible; }
.drag-overlay-content { display: flex; flex-direction: column; align-items: center; gap: 16px; color: white; font-size: 20px; font-weight: 500; }

/* Theme Icons */
[data-theme="dark"] .theme-icon-light { display: none !important; }
[data-theme="dark"] .theme-icon-dark { display: block !important; }
[data-theme="light"] .theme-icon-light { display: block; }
[data-theme="light"] .theme-icon-dark { display: none; }
[data-theme="dark"] #hljs-theme-light { disabled: true; }
[data-theme="light"] #hljs-theme-dark { disabled: true; }

/* ---------- Print & Export Styles ---------- */
.export-hide { display: none !important; }

@media print {
  .toolbar, .toc-sidebar, .outline-sidebar, .reading-progress, .back-to-top, .history-sidebar,
  .json-toolbar, .json-node-actions { display: none !important; }
  .main-layout { padding-top: 0; }
  .json-container { max-width: 100%; padding: 0; }
  .json-body { padding: 0; font-size: 12pt; }
  .json-children { border-left-color: #ccc !important; }
}

@media (max-width: 768px) {
  .toolbar-center { display: none; }
  .doc-stats { display: none; }
  .logo-text { display: none; }
  .welcome-title { font-size: 28px; }
  .shortcut-grid { grid-template-columns: repeat(2, 1fr); }
  .json-body { padding: 8px 16px; }
  .json-toolbar { padding: 10px 16px; }
  .toc-sidebar, .outline-sidebar, .history-sidebar { position: fixed; top: calc(var(--toolbar-height) + var(--current-tabs-height)); bottom: 0; z-index: 850; box-shadow: var(--shadow-lg); }
  .toc-sidebar { left: 0; } .outline-sidebar { right: 0; }
  .view-switcher { gap: 0; }
  .view-btn { width: 28px; }
}
