/* /json – the toolkit's tabs, input, output and tree, layered on style.css.
   Output is coloured the way jq prints it: blue keys, green strings, grey null. */
body.json {
  --j-border: var(--border); --j-muted: var(--muted); --j-accent: var(--fg); --j-bg: var(--bg); --j-soft: var(--soft); --j-err: var(--err);
  --j-key: #1d4ed8; --j-str: #15803d; --j-null: var(--muted); --j-pick: #e4e4e7;
  --j-mono: var(--mono);
}
body.json.dark-mode {
  --j-key: #93c5fd; --j-str: #86efac; --j-pick: #27272a;
}
body.json footer { position: static; padding: 40px 0 20px; }
.json-intro { max-width: 70ch; }

/* tabs: radio buttons, so the browser handles focus and arrow keys */
.json-mode { position: absolute; opacity: 0; width: 1px; height: 1px; margin: 0; pointer-events: none; }
.json-tabs { display: flex; flex-wrap: wrap; gap: 12px; margin: 14px 0 18px; font-size: 1.05rem; letter-spacing: 0.05ch; }
.json-tabs .json-sep { color: var(--j-muted); }
.json-tabs label { cursor: pointer; color: var(--j-muted); }
.json-tabs label:hover { color: var(--j-accent); }
#json-m-format:checked ~ .json-tabs [for="json-m-format"],
#json-m-tree:checked ~ .json-tabs [for="json-m-tree"],
#json-m-decode:checked ~ .json-tabs [for="json-m-decode"],
#json-m-encode:checked ~ .json-tabs [for="json-m-encode"] { color: var(--j-accent); font-weight: 700; }
#json-m-format:checked ~ .json-tabs [for="json-m-format"]::before,
#json-m-tree:checked ~ .json-tabs [for="json-m-tree"]::before,
#json-m-decode:checked ~ .json-tabs [for="json-m-decode"]::before,
#json-m-encode:checked ~ .json-tabs [for="json-m-encode"]::before { content: "> "; }
#json-m-format:focus-visible ~ .json-tabs [for="json-m-format"],
#json-m-tree:focus-visible ~ .json-tabs [for="json-m-tree"],
#json-m-decode:focus-visible ~ .json-tabs [for="json-m-decode"],
#json-m-encode:focus-visible ~ .json-tabs [for="json-m-encode"] { outline: 2px solid var(--j-accent); outline-offset: 2px; border-radius: 2px; }

/* each tab's options and output */
.json-opts, .json-pane { display: none; }
#json-m-format:checked ~ .json-options .json-opts-format,
#json-m-format:checked ~ .json-options .json-opts-parse,
#json-m-tree:checked ~ .json-options .json-opts-parse,
#json-m-decode:checked ~ .json-options .json-opts-decode,
#json-m-encode:checked ~ .json-options .json-opts-encode { display: contents; }
#json-m-format:checked ~ .json-wrap .json-pane-format,
#json-m-tree:checked ~ .json-wrap .json-pane-tree,
#json-m-decode:checked ~ .json-wrap .json-pane-decode,
#json-m-encode:checked ~ .json-wrap .json-pane-encode { display: block; }

.json-wrap { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 8px 40px; align-items: start; max-width: 1500px; padding-right: 2vw; }
.json-in, .json-out { min-width: 0; }

/* a title like the site's headings, with its buttons on the right */
.json-bar { display: flex; align-items: center; flex-wrap: wrap; gap: 6px 12px; min-height: 30px; margin: 0 0 8px; }
.json-title { font-weight: 700; font-size: 1.05rem; }
.json-title::after { content: " \\"; }
.json-pane.busy > .json-bar .json-title::after { content: " \\ working…"; font-weight: 400; color: var(--j-muted); }
.json-size { color: var(--j-muted); font-size: 0.8rem; letter-spacing: 0.03ch; }
.json-actions { display: flex; flex-wrap: wrap; gap: 6px; margin-left: auto; }
.json-actions button {
  font: inherit; font-size: 0.8rem; letter-spacing: 0.05ch; color: inherit; background: transparent;
  border: 1px solid var(--j-border); border-radius: 6px; padding: 3px 10px; cursor: pointer; transition: border-color 0.15s, background 0.15s, color 0.15s;
}
.json-actions button:hover:not(:disabled), .json-actions button:focus-visible { border-color: var(--j-accent); }
.json-actions button[aria-pressed="true"] { border-color: var(--j-accent); }
.json-actions button:active:not(:disabled) { background: var(--j-accent); color: var(--j-bg); }
.json-actions button:disabled { opacity: 0.4; cursor: default; }
.json-file { display: none; }

/* fields, as on /qr */
.json-form textarea, .json-form input[type="text"], .json-form select {
  display: block; width: 100%; box-sizing: border-box; padding: 7px 10px; font: inherit; font-size: 0.95rem;
  color: inherit; background: transparent; border: 1px solid var(--j-border); border-radius: 6px;
}
/* a solid fill: Firefox paints the open list with the select's own background */
.json-form select { height: 38px; background-color: var(--j-bg); }
.json-form option { color: var(--j-accent); background-color: var(--j-bg); }
.json-form textarea { font-family: var(--j-mono); font-size: 0.85rem; line-height: 1.5; tab-size: 4; resize: vertical; }
.json-form :focus-visible { outline: 2px solid var(--j-accent); outline-offset: 1px; }
#json-input { height: 52vh; min-height: 18rem; white-space: pre; overflow-wrap: normal; overflow: auto; }
#json-input.drop { border-style: dashed; border-color: var(--j-accent); }
/* tokens and base64 are one long line: wrap them */
#json-m-decode:checked ~ .json-wrap #json-input,
#json-m-encode:checked ~ .json-wrap #json-input { white-space: pre-wrap; overflow-wrap: anywhere; }
.json-count { min-height: 1.2em; margin: 4px 0 10px; font-size: 0.8rem; color: var(--j-muted); text-align: right; letter-spacing: 0.03ch; }
.json-count.over { color: var(--j-err); }

/* the options: one row that wraps, between the tabs and the input */
.json-options { display: flex; flex-wrap: wrap; align-items: center; gap: 10px 24px; max-width: 1500px; margin: 0 0 18px; padding-right: 2vw; }
.json-group { display: contents; }
.json-field { display: inline-flex; align-items: center; gap: 8px; margin: 0; }
.json-field > span { font-size: 0.8rem; color: var(--j-muted); letter-spacing: 0.05ch; white-space: nowrap; }
.json-form .json-field select { width: auto; min-width: 11rem; }
.json-check { display: inline-flex; align-items: baseline; flex-wrap: wrap; gap: 4px 8px; font-size: 0.9rem; cursor: pointer; }
.json-check input { margin: 0; accent-color: var(--j-accent); }
.json-check small, .json-field small { color: var(--j-muted); font-size: 0.78rem; }
.json-jwt-fields { display: grid; flex-basis: 100%; grid-template-columns: minmax(0, 3fr) minmax(0, 2fr); gap: 10px 16px; max-width: 64rem; }
.json-jwt-fields .json-field { display: block; }
.json-jwt-fields .json-field > span { display: block; margin-bottom: 4px; white-space: normal; }
.json-jwt-fields .json-field > span small { display: block; }

/* what jqo found */
.json-status { min-height: 1.5em; margin: 0 0 8px; font-size: 0.85rem; line-height: 1.5; color: var(--j-muted); overflow-wrap: anywhere; }
.json-line { margin: 0 0 4px; }
.json-line strong { color: var(--j-accent); }
.json-line.err, .json-line.err strong, .json-bad { color: var(--j-err); }
.json-snippet { margin: 4px 0; padding: 6px 10px; overflow-x: auto; font: 0.8rem/1.45 var(--j-mono); color: var(--j-accent); background: var(--j-soft); border-radius: 6px; }
.json-caret { color: var(--j-err); font-weight: 700; }
.json-notes { margin: 4px 0; padding: 0; list-style: none; }
.json-notes li { margin: 2px 0; }
.json-notes.warn li::before { content: "! "; color: var(--j-err); font-weight: 700; }
.json-notes.fix li::before { content: "- "; }
.json-link { font: inherit; color: var(--j-accent); background: none; border: 0; padding: 0; cursor: pointer; text-decoration: underline; text-underline-offset: 2px; }
.json-link:hover { color: var(--j-muted); }

/* output */
.json-code {
  margin: 0; padding: 10px 12px; min-height: 18rem; max-height: 70vh; box-sizing: border-box; overflow: auto;
  font: 0.85rem/1.5 var(--j-mono); tab-size: 4; white-space: pre;
  border: 1px solid var(--j-border); border-radius: 6px; transition: opacity 0.15s;
}
.json-code.wrap { white-space: pre-wrap; overflow-wrap: anywhere; }
.json-code.json-small { min-height: 0; max-height: 40vh; }
.json-code .k { color: var(--j-key); }
.json-code .s { color: var(--j-str); }
.json-code .z { color: var(--j-null); }
.json-cut { color: var(--j-muted); font-style: italic; }
.json-pane.stale .json-code, .json-pane.stale .json-tree, .json-pane.stale .json-jwt { opacity: 0.35; }

/* jwt */
.json-block { margin: 0 0 16px; }
.json-block .json-title { font-size: 0.95rem; }
.json-times { border-collapse: collapse; font-size: 0.85rem; }
.json-times th { padding: 2px 16px 2px 0; text-align: left; font: 700 0.85rem var(--j-mono); color: var(--j-key); }
.json-times td { padding: 2px 16px 2px 0; }
.json-times .json-when { color: var(--j-muted); }

/* tree */
.json-path { display: flex; align-items: center; flex-wrap: wrap; gap: 6px 10px; margin: 0 0 8px; }
.json-pointer { padding: 2px 8px; font: 0.8rem var(--j-mono); background: var(--j-soft); border-radius: 4px; overflow-wrap: anywhere; }
.json-path .json-actions { margin-left: 0; }
.json-tree {
  min-height: 18rem; max-height: 70vh; box-sizing: border-box; overflow: auto; padding: 8px 6px;
  font: 0.85rem/1.65 var(--j-mono); border: 1px solid var(--j-border); border-radius: 6px; transition: opacity 0.15s;
}
.json-tree:empty { border-style: dashed; }
.json-tree ul { margin: 0; padding: 0 0 0 1.4em; list-style: none; }
.json-tree > ul { padding-left: 0; }
.json-node { display: flex; align-items: baseline; white-space: nowrap; }
.json-toggle { flex: none; width: 1.4em; padding: 0; font: inherit; color: var(--j-muted); background: none; border: 0; text-align: center; }
button.json-toggle { cursor: pointer; }
button.json-toggle::before { content: "▸"; }
button.json-toggle[aria-expanded="true"]::before { content: "▾"; }
button.json-toggle:hover { color: var(--j-accent); }
.json-label { padding: 0 4px; font: inherit; color: inherit; text-align: left; white-space: nowrap; background: none; border: 0; border-radius: 4px; cursor: pointer; }
.json-label:hover { background: var(--j-soft); }
li.picked > .json-node .json-label { background: var(--j-pick); }
.json-tree .k { color: var(--j-key); }
.json-tree .s { color: var(--j-str); }
.json-tree .z { color: var(--j-null); }
.json-tree .i, .json-tree .p { color: var(--j-muted); }
.json-meta { margin-left: 8px; font-size: 0.75rem; color: var(--j-muted); }
.json-more { padding-left: 1.4em; }

@media (max-width: 900px) {
  .json-wrap { grid-template-columns: minmax(0, 1fr); padding-right: 1vw; }
  .json-options { padding-right: 1vw; }
  .json-jwt-fields { grid-template-columns: minmax(0, 1fr); }
  #json-input { height: 40vh; }
  .json-code, .json-tree { min-height: 10rem; max-height: 60vh; }
}
@media (max-width: 600px) {
  .json-wrap, .json-options { padding: 0 8px; }
  .json-tabs { justify-content: center; }
  .json-actions { margin-left: 0; }
}
