/* JSON Toolkit - Dark-first design system */
:root {
  --bg: #0d1117;
  --bg2: #161b22;
  --bg3: #21262d;
  --bg4: #30363d;
  --text: #e6edf3;
  --text2: #8b949e;
  --text3: #6e7681;
  --accent: #58a6ff;
  --accent2: #388bfd;
  --success: #3fb950;
  --error: #f85149;
  --warning: #d29922;
  --border: #30363d;
  --radius: 6px;
  --gutter-bg: #161b22;
  --gutter-text: #484f58;
  --hl-string: #a5d6ff;
  --hl-number: #79c0ff;
  --hl-bool: #ff7b72;
  --hl-null: #ff7b72;
  --hl-key: #d2a8ff;
  --hl-brace: #8b949e;
  --diff-add-bg: rgba(63,185,80,.15);
  --diff-del-bg: rgba(248,81,73,.15);
  --diff-add-text: #3fb950;
  --diff-del-text: #f85149;
}
[data-theme="light"] {
  --bg: #ffffff; --bg2: #f6f8fa; --bg3: #e1e4e8; --bg4: #d0d7de;
  --text: #1f2328; --text2: #656d76; --text3: #8c959f;
  --accent: #0969da; --accent2: #0550ae; --success: #1a7f37; --error: #cf222e; --warning: #9a6700;
  --border: #d0d7de; --gutter-bg: #f6f8fa; --gutter-text: #8c959f;
  --hl-string: #0a3069; --hl-number: #0550ae; --hl-bool: #cf222e; --hl-null: #cf222e;
  --hl-key: #8250df; --hl-brace: #656d76;
  --diff-add-bg: rgba(26,127,55,.12); --diff-del-bg: rgba(207,34,46,.12);
  --diff-add-text: #1a7f37; --diff-del-text: #cf222e;
}
*, *::before, *::after { margin: 0; padding: 0; box-sizing: border-box; }
body { font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif; background: var(--bg); color: var(--text); min-height: 100vh; display: flex; flex-direction: column; }
a { color: var(--accent); text-decoration: none; }

/* Navbar */
.navbar { display: flex; align-items: center; height: 48px; padding: 0 12px; background: var(--bg2); border-bottom: 1px solid var(--border); position: sticky; top: 0; z-index: 100; gap: 6px; flex-shrink: 0; }
.nav-brand { display: flex; align-items: center; gap: 6px; flex-shrink: 0; }
.logo { font-size: 1.3rem; font-weight: 800; color: var(--accent); font-family: monospace; }
.brand-name { font-weight: 700; font-size: .9rem; white-space: nowrap; color: var(--text); text-decoration: none; }
.nav-links { display: flex; gap: 2px; overflow-x: auto; flex: 1; padding: 0 8px; scrollbar-width: none; }
.nav-links::-webkit-scrollbar { display: none; }
.nav-link { padding: 6px 10px; border-radius: var(--radius); color: var(--text2); text-decoration: none; font-size: .8rem; white-space: nowrap; transition: all .15s; }
.nav-link:hover { background: var(--bg3); color: var(--text); }
.nav-link.active { background: var(--bg3); color: var(--accent); font-weight: 600; }
.nav-actions { display: flex; align-items: center; gap: 4px; flex-shrink: 0; }
.btn-icon { background: none; border: 1px solid var(--border); color: var(--text2); padding: 4px 8px; border-radius: var(--radius); cursor: pointer; font-size: .8rem; transition: all .15s; }
.btn-icon:hover { background: var(--bg3); color: var(--text); }
.hamburger { display: none; }

/* Main layout */
.editor-layout { display: flex; flex-direction: column; flex: 1; min-height: 0; }

/* Toolbar */
.toolbar { padding: 8px 12px; display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap; gap: 8px; background: var(--bg2); border-bottom: 1px solid var(--border); flex-shrink: 0; }
.tool-title { font-size: .95rem; font-weight: 600; white-space: nowrap; }
.toolbar-actions { display: flex; gap: 6px; flex-wrap: wrap; align-items: center; }
.btn { padding: 5px 12px; border-radius: var(--radius); border: none; cursor: pointer; font-size: .8rem; font-weight: 500; background: var(--accent); color: #fff; transition: all .15s; white-space: nowrap; }
.btn:hover { background: var(--accent2); }
.btn:active { transform: scale(.97); }
.btn-secondary { background: var(--bg3); color: var(--text); }
.btn-secondary:hover { background: var(--bg4); }
.btn-danger { background: var(--error); }
select, .toolbar input[type="text"] { padding: 5px 8px; border-radius: var(--radius); border: 1px solid var(--border); background: var(--bg); color: var(--text); font-size: .8rem; }

/* Panels */
.panels { display: grid; grid-template-columns: 1fr 1fr; flex: 1; min-height: 0; overflow: hidden; }
.panel { display: flex; flex-direction: column; min-height: 0; border-right: 1px solid var(--border); overflow: hidden; }
.panel:last-child { border-right: none; }
.panel-header { padding: 4px 10px; font-size: .75rem; color: var(--text2); background: var(--bg2); border-bottom: 1px solid var(--border); display: flex; justify-content: space-between; align-items: center; flex-shrink: 0; }

/* Code editor with line numbers */
.editor-wrap { flex: 1; position: relative; overflow: hidden; display: flex; }
.editor-gutter { width: 48px; flex-shrink: 0; background: var(--gutter-bg); border-right: 1px solid var(--border); overflow: hidden; padding: 8px 0; font-family: 'SF Mono','Fira Code','Consolas','Monaco',monospace; font-size: .8rem; line-height: 1.6; color: var(--gutter-text); text-align: right; user-select: none; }
.editor-gutter div { padding: 0 8px 0 4px; }
.editor-container { flex: 1; position: relative; overflow: hidden; }
.editor-highlight { position: absolute; top: 0; left: 0; right: 0; bottom: 0; padding: 8px 10px; font-family: 'SF Mono','Fira Code','Consolas','Monaco',monospace; font-size: .8rem; line-height: 1.6; white-space: pre-wrap; word-wrap: break-word; overflow: auto; color: transparent; pointer-events: none; z-index: 1; }
.editor-textarea { position: absolute; top: 0; left: 0; width: 100%; height: 100%; padding: 8px 10px; font-family: 'SF Mono','Fira Code','Consolas','Monaco',monospace; font-size: .8rem; line-height: 1.6; white-space: pre-wrap; word-wrap: break-word; background: transparent; color: var(--text); border: none; outline: none; resize: none; overflow: auto; z-index: 2; -webkit-text-fill-color: transparent; caret-color: var(--text); }
.editor-textarea.no-highlight { -webkit-text-fill-color: var(--text); }
.editor-highlight .hl-key { color: var(--hl-key); }
.editor-highlight .hl-string { color: var(--hl-string); }
.editor-highlight .hl-number { color: var(--hl-number); }
.editor-highlight .hl-bool, .editor-highlight .hl-null { color: var(--hl-null); }
.editor-highlight .hl-brace { color: var(--hl-brace); }
.editor-highlight .hl-error-line { background: var(--diff-del-bg); display: inline-block; width: 100%; }

/* Simple textarea fallback */
.code-area { flex: 1; width: 100%; padding: 8px 10px; border: none; background: var(--bg); color: var(--text); font-family: 'SF Mono','Fira Code','Consolas','Monaco',monospace; font-size: .8rem; line-height: 1.6; resize: none; outline: none; overflow: auto; }
.code-area:read-only { color: var(--text2); }

/* Status bar */
.status-bar { padding: 4px 12px; font-size: .78rem; background: var(--bg2); border-top: 1px solid var(--border); min-height: 26px; display: flex; align-items: center; gap: 12px; flex-shrink: 0; }
.status-bar.success { color: var(--success); }
.status-bar.error { color: var(--error); }

/* Drag overlay */
.drag-overlay { display: none; position: absolute; inset: 0; background: rgba(88,166,255,.1); border: 2px dashed var(--accent); border-radius: var(--radius); z-index: 50; align-items: center; justify-content: center; font-size: 1rem; color: var(--accent); pointer-events: none; }
.drag-overlay.show { display: flex; }

/* Diff */
.diff-result { flex: 1; overflow: auto; min-height: 0; }
.diff-side-by-side { display: grid; grid-template-columns: 1fr 1fr; min-height: 100%; }
.diff-col { font-family: 'SF Mono','Fira Code','Consolas','Monaco',monospace; font-size: .8rem; line-height: 1.6; padding: 8px; overflow-x: auto; white-space: pre; }
.diff-col:first-child { border-right: 1px solid var(--border); }
.diff-line { min-height: 1.6em; }
.diff-line-add { background: var(--diff-add-bg); color: var(--diff-add-text); }
.diff-line-del { background: var(--diff-del-bg); color: var(--diff-del-text); }
.diff-line-info { color: var(--accent); font-weight: 600; padding: 4px 0; }
.diff-line-num { display: inline-block; width: 36px; color: var(--gutter-text); text-align: right; margin-right: 8px; user-select: none; }
.diff-stats { padding: 8px 12px; background: var(--bg2); border-bottom: 1px solid var(--border); font-size: .8rem; color: var(--text2); display: flex; gap: 16px; }
.diff-stats .added { color: var(--success); }
.diff-stats .removed { color: var(--error); }
.diff-stats .changed { color: var(--warning); }

/* Validation errors */
.error-list { max-height: 200px; overflow-y: auto; }
.error-item { padding: 6px 10px; font-size: .8rem; color: var(--error); font-family: monospace; cursor: pointer; border-bottom: 1px solid var(--border); transition: background .1s; }
.error-item:hover { background: var(--bg3); }
.valid-result { text-align: center; padding: 2rem; }
.valid-result .icon { font-size: 2rem; margin-bottom: 8px; }
.stats-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(120px, 1fr)); gap: 8px; margin-top: 12px; text-align: center; }
.stat-card { padding: 8px; background: var(--bg); border-radius: var(--radius); border: 1px solid var(--border); }
.stat-card .value { font-size: 1.1rem; font-weight: 700; color: var(--accent); }
.stat-card .label { font-size: .7rem; color: var(--text2); }

/* URL import bar */
.url-bar { display: flex; gap: 6px; padding: 6px 12px; background: var(--bg2); border-bottom: 1px solid var(--border); }
.url-bar input { flex: 1; padding: 5px 8px; border-radius: var(--radius); border: 1px solid var(--border); background: var(--bg); color: var(--text); font-size: .8rem; font-family: monospace; }

/* Modal */
.modal { display: none; position: fixed; inset: 0; background: rgba(0,0,0,.6); z-index: 200; align-items: center; justify-content: center; backdrop-filter: blur(2px); }
.modal.show { display: flex; }
.modal-content { background: var(--bg2); border: 1px solid var(--border); border-radius: 12px; width: 90%; max-width: 500px; max-height: 80vh; display: flex; flex-direction: column; }
.modal-header { padding: 12px 16px; display: flex; justify-content: space-between; align-items: center; border-bottom: 1px solid var(--border); }
.modal-header h2 { font-size: 1rem; }
.modal-body { padding: 16px; overflow-y: auto; flex: 1; }
.modal-footer { padding: 10px 16px; border-top: 1px solid var(--border); text-align: right; }
.modal-close { background: none; border: none; color: var(--text2); font-size: 1.1rem; cursor: pointer; padding: 4px; }
.modal-close:hover { color: var(--text); }
.history-item { padding: 10px; margin-bottom: 6px; background: var(--bg); border-radius: var(--radius); cursor: pointer; font-size: .78rem; font-family: monospace; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; border: 1px solid var(--border); }
.history-item:hover { border-color: var(--accent); }
.history-item .meta { font-size: .7rem; color: var(--text2); margin-bottom: 4px; font-family: sans-serif; }

/* SEO */
.seo-content { padding: 24px 16px; max-width: 800px; margin: 0 auto; color: var(--text2); font-size: .85rem; line-height: 1.7; }
.seo-content h2 { color: var(--text); margin-bottom: 8px; font-size: 1.2rem; }
.seo-content h3 { color: var(--text); margin: 12px 0 6px; }
.seo-content ul { padding-left: 1.5rem; }
.seo-content li { margin-bottom: 4px; }
.seo-content code { background: var(--bg3); padding: 2px 6px; border-radius: 3px; font-size: .8rem; }

/* Footer */
.footer { padding: 16px; text-align: center; color: var(--text3); font-size: .75rem; border-top: 1px solid var(--border); flex-shrink: 0; }
.footer-links { margin-top: 6px; display: flex; gap: 8px; justify-content: center; align-items: center; }
.footer-link-btn { background: none; border: none; color: var(--accent); cursor: pointer; font-size: inherit; font-family: inherit; padding: 0; }
.footer-link-btn:hover { text-decoration: underline; }

/* Responsive */
@media (max-width: 768px) {
  .nav-links { display: none; }
  .nav-links.open { display: flex; position: absolute; top: 48px; left: 0; right: 0; flex-direction: column; background: var(--bg2); border-bottom: 1px solid var(--border); padding: 8px; z-index: 99; gap: 2px; }
  .hamburger { display: block; }
  .panels, .diff-side-by-side { grid-template-columns: 1fr; }
  .panel { border-right: none; border-bottom: 1px solid var(--border); min-height: 35vh; }
  .toolbar { flex-direction: column; align-items: stretch; }
  .toolbar-actions { justify-content: flex-start; }
  .editor-gutter { width: 36px; }
}

/* Scrollbar */
::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-track { background: var(--bg); }
::-webkit-scrollbar-thumb { background: var(--bg4); border-radius: 4px; }
::-webkit-scrollbar-thumb:hover { background: var(--text3); }

/* Checkbox style */
.toggle-label { display: flex; align-items: center; gap: 4px; font-size: .8rem; color: var(--text2); cursor: pointer; white-space: nowrap; }
.toggle-label input { accent-color: var(--accent); }

/* Donate button */
.donate-btn { background: linear-gradient(135deg, rgba(249,115,22,.15), rgba(239,68,68,.15)) !important; color: #f97316 !important; border-color: rgba(249,115,22,.3) !important; }
