/* jsonlv — styles */
:root {
  --font-ui: ui-sans-serif, -apple-system, "Segoe UI", Inter, Roboto, sans-serif;
  --font-mono: ui-monospace, "SF Mono", "JetBrains Mono", "Fira Code", Menlo, Consolas, monospace;

  --bg: #0a0c11;
  --bg2: #0e1117;
  --panel: #12151d;
  --panel2: #171b25;
  --panel3: #1d2230;
  --border: #232938;
  --border2: #2d3547;
  --text: #e8ebf2;
  --dim: #8a93a8;
  --dimmer: #5d6579;
  --accent: #7c6cff;
  --accent2: #22d3ee;
  --sel: rgba(124, 108, 255, 0.14);

  --lv-trace: #6b7280;
  --lv-debug: #38bdf8;
  --lv-info: #34d399;
  --lv-warn: #fbbf24;
  --lv-error: #f87171;
  --lv-fatal: #e879f9;
  --lv-raw: #5d6579;

  --json-k: #7dd3fc;
  --json-s: #86efac;
  --json-n: #fbbf24;
  --json-b: #f0abfc;
  --json-null: #94a3b8;

  --row-h: 28px;
  --shadow: 0 10px 40px rgba(0, 0, 0, 0.5);
}

html[data-theme="light"] {
  --bg: #f4f6fa;
  --bg2: #eef1f6;
  --panel: #ffffff;
  --panel2: #f6f8fb;
  --panel3: #eceff5;
  --border: #dde2ec;
  --border2: #c9d1e0;
  --text: #1a2030;
  --dim: #5a6478;
  --dimmer: #8a93a8;
  --sel: rgba(99, 82, 255, 0.10);

  --json-k: #0369a1;
  --json-s: #15803d;
  --json-n: #b45309;
  --json-b: #a21caf;
  --json-null: #64748b;

  --shadow: 0 10px 40px rgba(30, 40, 70, 0.15);
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: var(--font-ui);
  font-size: 13px;
  background: var(--bg);
  color: var(--text);
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
}

#app {
  display: grid;
  grid-template-rows: 46px 1fr 26px;
  height: 100vh;
}

/* ── top bar ─────────────────────────────────────────── */
.topbar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 0 12px;
  background: linear-gradient(180deg, var(--panel2), var(--panel));
  border-bottom: 1px solid var(--border);
}
.brand { display: flex; align-items: center; gap: 8px; user-select: none; }
.brand-logo { width: 22px; height: 22px; color: #fff; }
.brand-bg { fill: url(#brandGrad); }
.brand svg rect { fill: #7c6cff; }
.brand-name { font-weight: 600; letter-spacing: 0.2px; font-size: 13.5px; }
.brand-name b { color: var(--accent); font-weight: 800; }
.file-title {
  font-family: var(--font-mono);
  font-size: 11.5px;
  color: var(--dim);
  max-width: 34vw;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  padding: 3px 10px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--bg2);
}
.spacer { flex: 1; }

.searchwrap {
  display: flex;
  align-items: center;
  gap: 4px;
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0 6px 0 9px;
  width: 340px;
  transition: border-color 0.15s;
}
.searchwrap:focus-within { border-color: var(--accent); }
.searchwrap .ico { width: 14px; height: 14px; color: var(--dimmer); flex: none; }
#search {
  flex: 1;
  background: none;
  border: none;
  outline: none;
  color: var(--text);
  font-family: var(--font-mono);
  font-size: 12px;
  height: 30px;
}

.icon-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: transparent;
  border: 1px solid transparent;
  border-radius: 7px;
  color: var(--dim);
  font-family: var(--font-mono);
  font-size: 11px;
  font-weight: 600;
  height: 30px;
  padding: 0 8px;
  cursor: pointer;
  transition: all 0.15s;
}
.icon-btn:hover { color: var(--text); background: var(--panel3); }
.icon-btn.on { color: var(--accent); background: var(--sel); border-color: var(--accent); }
.icon-btn .ico { width: 15px; height: 15px; }

html[data-theme="dark"] .ico-sun { display: none; }
html[data-theme="light"] .ico-moon { display: none; }

.live-dot {
  width: 7px; height: 7px; border-radius: 50%;
  background: var(--dimmer);
  transition: all 0.2s;
}
.icon-btn.on .live-dot { background: #f43f5e; box-shadow: 0 0 8px #f43f5e; animation: pulse 1.6s infinite; }
@keyframes pulse { 50% { opacity: 0.5; } }

/* ── main layout ─────────────────────────────────────── */
.main {
  display: grid;
  grid-template-columns: 232px 1fr auto;
  min-height: 0;
}

/* ── sidebar ─────────────────────────────────────────── */
.side {
  background: var(--bg2);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  min-height: 0;
}
.side-sec { padding: 10px 10px 6px; }
.side-sec.grow { flex: 1; min-height: 0; display: flex; flex-direction: column; overflow: hidden; }
.side-h {
  font-size: 10.5px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.9px;
  color: var(--dimmer);
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 7px;
}
.count { color: var(--dim); font-weight: 500; }
.linkbtn {
  background: none; border: none; color: var(--accent);
  font-size: 10.5px; cursor: pointer; padding: 0; font-family: var(--font-ui);
}
.linkbtn:hover { text-decoration: underline; }

.files { display: flex; flex-direction: column; gap: 2px; max-height: 30vh; overflow-y: auto; }
.file-item {
  padding: 6px 9px;
  border-radius: 7px;
  cursor: pointer;
  border: 1px solid transparent;
  transition: background 0.12s;
}
.file-item:hover { background: var(--panel3); }
.file-item.active { background: var(--sel); border-color: rgba(124, 108, 255, 0.4); }
.file-item .f-name {
  font-family: var(--font-mono);
  font-size: 11px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  display: block;
}
.file-item .f-meta { font-size: 10px; color: var(--dimmer); margin-top: 2px; }

.facets { overflow-y: auto; flex: 1; padding-right: 2px; }
.facet { margin-bottom: 10px; }
.facet-h {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--dim);
  margin-bottom: 5px;
  display: flex;
  align-items: center;
  gap: 6px;
  cursor: pointer;
  user-select: none;
}
.facet-h .tw { transition: transform 0.15s; font-size: 8px; color: var(--dimmer); }
.facet.closed .tw { transform: rotate(-90deg); }
.facet.closed .chips { display: none; }
.chips { display: flex; flex-wrap: wrap; gap: 4px; }
.chip {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 2.5px 8px;
  border-radius: 20px;
  border: 1px solid var(--border);
  background: var(--panel);
  color: var(--dim);
  font-family: var(--font-mono);
  font-size: 10.5px;
  cursor: pointer;
  max-width: 100%;
  transition: all 0.12s;
}
.chip:hover { border-color: var(--border2); color: var(--text); }
.chip .cv { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 110px; }
.chip .n { color: var(--dimmer); font-size: 9.5px; }
.chip.on { background: var(--sel); border-color: var(--accent); color: var(--text); }
.chip.on .n { color: var(--accent); }

/* ── center: histogram + table ───────────────────────── */
.center { display: flex; flex-direction: column; min-width: 0; min-height: 0; }

.hist-wrap {
  position: relative;
  height: 54px;
  border-bottom: 1px solid var(--border);
  background: var(--bg2);
  padding: 6px 10px 4px;
  user-select: none;
}
#hist { width: 100%; height: 100%; display: block; cursor: crosshair; }
.hist-empty {
  position: absolute;
  right: 14px; top: 8px;
  font-size: 10px;
  color: var(--dimmer);
  pointer-events: none;
}
.range-chip {
  position: absolute;
  left: 50%; top: 8px;
  transform: translateX(-50%);
  display: inline-flex;
  align-items: center;
  gap: 8px;
  background: var(--panel3);
  border: 1px solid var(--accent);
  color: var(--text);
  font-family: var(--font-mono);
  font-size: 10.5px;
  padding: 3px 10px;
  border-radius: 20px;
  box-shadow: 0 4px 14px rgba(0,0,0,0.3);
  z-index: 4;
}
.range-chip button { background: none; border: none; color: var(--accent); cursor: pointer; font-size: 11px; padding: 0; }

.table-wrap {
  flex: 1;
  overflow: auto;
  position: relative;
  min-height: 0;
  overflow-anchor: none;
}
.table-wrap * { overflow-anchor: none; }
.table-wrap::-webkit-scrollbar { width: 11px; height: 11px; }
.table-wrap::-webkit-scrollbar-thumb { background: var(--border2); border-radius: 8px; border: 2px solid var(--bg); }
.table-wrap::-webkit-scrollbar-corner { background: transparent; }

.thead, .row {
  display: grid;
  grid-template-columns: var(--cols);
  align-items: center;
}
.thead {
  position: sticky;
  top: 0;
  z-index: 5;
  background: var(--panel2);
  border-bottom: 1px solid var(--border);
  height: 30px;
  font-size: 10.5px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.7px;
  color: var(--dimmer);
  min-width: 100%;
}
.thead > div { padding: 0 8px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; border-left: 1px solid var(--border); }
.thead > div:first-child { border-left: none; }
.thead > div.num { text-align: right; }
.thead > div[data-sortkey] { cursor: pointer; user-select: none; }
.thead > div[data-sortkey]:hover { color: var(--text); }
.thead div .sort-ind { margin-left: 4px; color: var(--accent); font-size: 9px; }

.vlist { position: relative; }
.spacer { width: 100%; }
.rowsbox { width: 100%; }

.row {
  height: var(--row-h);
  font-family: var(--font-mono);
  font-size: 11.5px;
  border-bottom: 1px solid color-mix(in srgb, var(--border) 45%, transparent);
  cursor: pointer;
  background: var(--bg);
  outline: none;
}
.row:hover { background: var(--bg2); }
.row.sel { background: var(--sel); box-shadow: inset 2px 0 0 var(--accent); }
.row .c { padding: 0 8px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; }
.row .c-line { color: var(--dimmer); font-size: 10.5px; text-align: right; user-select: none; }
.row .c-ts { color: var(--dim); font-variant-numeric: tabular-nums; }
.row .c-msg { color: var(--text); }
.row .c-col { color: var(--dim); }
.row .c-col.num { text-align: right; color: var(--dim); font-variant-numeric: tabular-nums; }
.row.bad .c-msg { color: var(--lv-warn); }

.badge {
  display: inline-block;
  font-size: 9.5px;
  font-weight: 700;
  letter-spacing: 0.6px;
  padding: 1.5px 7px;
  border-radius: 4px;
  text-transform: uppercase;
  font-family: var(--font-ui);
}
.lv-trace  { background: rgba(107,114,128,0.15); color: var(--lv-trace); }
.lv-debug  { background: rgba(56,189,248,0.13); color: var(--lv-debug); }
.lv-info   { background: rgba(52,211,153,0.13); color: var(--lv-info); }
.lv-warn   { background: rgba(251,191,36,0.13);  color: var(--lv-warn); }
.lv-error  { background: rgba(248,113,113,0.14); color: var(--lv-error); }
.lv-fatal  { background: rgba(232,121,249,0.14); color: var(--lv-fatal); }
.lv-raw    { background: rgba(93,101,121,0.15); color: var(--lv-raw); }
.lv-none   { color: var(--dimmer); font-size: 11px; font-family: var(--font-mono); }

.gap-chip {
  display: inline-block;
  font-size: 9.5px;
  color: var(--lv-warn);
  background: rgba(251,191,36,0.1);
  border-radius: 4px;
  padding: 0.5px 5px;
  margin-right: 7px;
  font-family: var(--font-mono);
  vertical-align: 1px;
}
mark.hl { background: rgba(251, 191, 36, 0.3); color: inherit; border-radius: 2px; padding: 0 1px; }
.row.sel mark.hl { background: rgba(251, 191, 36, 0.45); }

/* ── drawer ──────────────────────────────────────────── */
.drawer {
  width: 0;
  overflow: hidden;
  border-left: 1px solid transparent;
  background: var(--bg2);
  transition: width 0.18s ease, border-color 0.18s;
  display: flex;
  flex-direction: column;
  min-height: 0;
}
.drawer.open { width: 460px; border-left-color: var(--border); }
.d-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 9px 12px;
  border-bottom: 1px solid var(--border);
  gap: 8px;
}
.d-title { font-family: var(--font-mono); font-size: 12px; color: var(--dim); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.d-actions { display: flex; gap: 6px; flex: none; }
.btn {
  background: var(--panel3);
  border: 1px solid var(--border);
  color: var(--dim);
  font-size: 11px;
  font-family: var(--font-ui);
  font-weight: 600;
  border-radius: 7px;
  padding: 5px 10px;
  cursor: pointer;
  transition: all 0.15s;
}
.btn:hover { color: var(--text); border-color: var(--border2); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
a.btn { display: inline-flex; align-items: center; }
.btn.primary:hover { filter: brightness(1.1); }
.btn.icon-x { padding: 5px 9px; }
.d-tabs { display: flex; gap: 4px; padding: 8px 12px 0; border-bottom: 1px solid var(--border); }
.d-tab {
  background: none; border: none; cursor: pointer;
  color: var(--dimmer); font-size: 12px; font-weight: 600; font-family: var(--font-ui);
  padding: 5px 10px 8px; border-bottom: 2px solid transparent; margin-bottom: -1px;
}
.d-tab.on { color: var(--text); border-bottom-color: var(--accent); }
.d-body { flex: 1; overflow: auto; padding: 10px 14px; font-family: var(--font-mono); font-size: 11.5px; line-height: 1.75; }
.d-body::-webkit-scrollbar { width: 10px; }
.d-body::-webkit-scrollbar-thumb { background: var(--border2); border-radius: 8px; }
.d-raw { white-space: pre-wrap; word-break: break-all; color: var(--dim); }

/* json tree */
.t-branch { margin-left: 2px; }
.t-head { display: flex; align-items: baseline; gap: 5px; cursor: pointer; padding: 0 2px; border-radius: 4px; }
.t-head:hover { background: var(--panel3); }
.caret {
  display: inline-block;
  width: 12px; height: 12px;
  color: var(--dimmer);
  font-size: 9px;
  text-align: center;
  line-height: 12px;
  transition: transform 0.12s;
  flex: none;
  transform: translateY(1px);
}
.t-branch.closed .caret { transform: translateY(1px) rotate(-90deg); }
.t-branch.closed > .t-kids { display: none; }
.t-kids { margin-left: 19px; border-left: 1px solid var(--border); padding-left: 8px; }
.tk { color: var(--json-k); }
.ts { color: var(--json-s); word-break: break-all; }
.tn { color: var(--json-n); }
.tb { color: var(--json-b); }
.tnull { color: var(--json-null); font-style: italic; }
.tsum { color: var(--dimmer); font-size: 10.5px; }
.t-more { background: none; border: 1px dashed var(--border2); color: var(--dim); font-size: 10.5px; border-radius: 6px; padding: 2px 8px; cursor: pointer; margin: 2px 0 2px 27px; font-family: var(--font-mono); }
.t-more:hover { color: var(--text); }

/* ── statusbar ───────────────────────────────────────── */
.statusbar {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 0 12px;
  background: var(--panel2);
  border-top: 1px solid var(--border);
  font-size: 11px;
  color: var(--dim);
  font-family: var(--font-mono);
}
.st { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.st-mid { flex: 1; text-align: center; }
.st b { color: var(--text); font-weight: 600; }
.st .warn { color: var(--lv-warn); }

/* ── empty state / drop / loading ────────────────────── */
.empty {
  position: fixed; inset: 46px 0 26px 0;
  display: flex; align-items: center; justify-content: center;
  background: var(--bg);
  z-index: 30;
  transition: opacity 0.2s;
}
.empty.hidden { opacity: 0; pointer-events: none; }
.empty-card { text-align: center; max-width: 420px; padding: 20px; }
.empty-logo { width: 56px; height: 56px; color: #fff; margin-bottom: 14px; }
.empty-card h1 { font-size: 22px; font-weight: 700; margin: 0 0 8px; }
.empty-card h1 b { color: var(--accent); }
.empty-card p { color: var(--dim); margin: 0 0 18px; line-height: 1.5; }
.empty-hint { margin-top: 22px !important; color: var(--dimmer) !important; font-size: 11.5px; }
.empty-seo { margin-top: 10px !important; color: var(--dimmer) !important; font-size: 11px; }
.empty-hint code {
  background: var(--panel3);
  border: 1px solid var(--border);
  padding: 2px 8px;
  border-radius: 6px;
  font-size: 11px;
  color: var(--accent2);
}

.drop-cover {
  position: fixed; inset: 0;
  background: color-mix(in srgb, var(--accent) 12%, rgba(0,0,0,0.6));
  backdrop-filter: blur(3px);
  display: none;
  align-items: center; justify-content: center;
  z-index: 100;
  border: 3px dashed var(--accent);
}
.drop-cover.on { display: flex; }
.drop-inner {
  font-size: 24px; font-weight: 700; color: #fff;
  text-shadow: 0 2px 20px rgba(0,0,0,0.6);
  pointer-events: none;
}

.loadbar {
  position: fixed; top: 46px; left: 0; right: 0; height: 2.5px;
  background: rgba(124,108,255,0.15); z-index: 60;
}
.loadbar-fill { height: 100%; width: 0%; background: linear-gradient(90deg, var(--accent), var(--accent2)); transition: width 0.15s; box-shadow: 0 0 10px var(--accent); }

/* ── popover ─────────────────────────────────────────── */
/* ── open button ──────────────────────────────── */
.open-btn { height: 30px; gap: 6px; }
.open-btn .ico { width: 13px; height: 13px; }


/* raw view rows */
.row .c-raw {
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.row.bad .c-raw { color: var(--lv-warn); }

/* ── "run locally" dialog ────────────────────────────── */
.dialog-mask {
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.55);
  backdrop-filter: blur(2px);
  display: flex; align-items: center; justify-content: center;
  z-index: 200;
}
.dialog-mask[hidden] { display: none; }
.dialog {
  width: min(560px, 92vw);
  background: var(--panel2);
  border: 1px solid var(--border2);
  border-radius: 14px;
  box-shadow: var(--shadow);
  padding: 18px 20px 16px;
}
.dialog-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 4px; }
.dialog-h { font-size: 15px; font-weight: 700; }
.dialog-p { color: var(--dim); font-size: 12.5px; line-height: 1.55; margin: 4px 0 14px; }
.dialog-p b { color: var(--text); }
.dialog-p code, .cmd code { font-family: var(--font-mono); background: var(--panel3); padding: 1px 5px; border-radius: 4px; font-size: 11.5px; }
.dialog-note { color: var(--dimmer); font-size: 11px; margin: 14px 0 0; }
.cmd { margin-bottom: 10px; }
.cmd-label { font-size: 10px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.8px; color: var(--dimmer); margin-bottom: 5px; }
.cmd-line {
  display: flex; align-items: center; gap: 8px;
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 7px 7px 7px 12px;
  margin-bottom: 6px;
}
.cmd-line code { flex: 1; background: none; padding: 0; color: var(--accent2); white-space: pre; overflow-x: auto; }
.copy-btn { flex: none; padding: 4px 9px; font-size: 10.5px; }

/* about popup + byline */
.byline {
  font-size: 10.5px;
  color: var(--dimmer);
  text-decoration: none;
  margin-left: 2px;
  transition: color 0.15s;
}
.byline:hover { color: var(--accent2); text-decoration: underline; }
.about-dialog { width: min(480px, 92vw); }
.about-logo-row { display: flex; align-items: center; gap: 12px; margin: 6px 0 12px; }
.about-logo { width: 40px; height: 40px; color: #fff; flex: none; }
.about-name { font-size: 17px; font-weight: 700; }
.about-name b { color: var(--accent); }
.about-sub { font-size: 11.5px; color: var(--dim); margin-top: 2px; }
.about-cta {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  border: 1px solid var(--border);
  background: var(--bg2);
  border-radius: 10px;
  padding: 12px 14px;
  margin-top: 4px;
}
.about-brand { font-size: 13px; font-weight: 600; }
.about-brand a { color: var(--accent2); text-decoration: none; }
.about-brand a:hover { text-decoration: underline; }
.about-brand-sub { font-size: 11px; color: var(--dimmer); margin-top: 2px; }

.colsel { position: relative; }
.pop {
  position: absolute; right: 0; top: 36px;
  background: var(--panel2);
  border: 1px solid var(--border2);
  border-radius: 10px;
  box-shadow: var(--shadow);
  min-width: 180px;
  padding: 6px;
  z-index: 50;
}
.pop-item {
  display: flex; align-items: center; gap: 8px;
  padding: 6px 8px; border-radius: 6px; cursor: pointer;
  font-family: var(--font-mono); font-size: 11.5px; color: var(--dim);
}
.pop-item:hover { background: var(--panel3); color: var(--text); }
.pop-item input { accent-color: var(--accent); }
.lastsel { position: relative; }
.lastpop { min-width: 175px; }
.pop-title { font-size: 9.5px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.8px; color: var(--dimmer); padding: 7px 8px 3px; }
.pop-sep { height: 1px; background: var(--border); margin: 5px 4px; }
.lastpop .pop-item.on { color: var(--accent); }
.files.recents { max-height: 22vh; }
.file-item.unavail { opacity: 0.45; }
.file-item.unavail .f-name { cursor: default; }

/* scrollbars (global) */
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-thumb { background: var(--border2); border-radius: 8px; }
::-webkit-scrollbar-track { background: transparent; }

@media (max-width: 900px) {
  .main { grid-template-columns: 190px 1fr auto; }
  .searchwrap { width: 200px; }
  .file-title { display: none; }
}
