/* JSONfmt — permanent dark "editor" theme + tool styling.
   Palette follows GitHub-dark conventions: dim navy surfaces, blue links,
   green = valid, red = errors. Declared in both modes so the palette is
   identical regardless of prefers-color-scheme and load order. */

:root {
  --bg: #0d1117;
  --surface: #161b22;
  --surface-2: #21262d;
  --text: #e6edf3;
  --text-dim: #9198a1;
  --border: #30363d;
  --jf-green: #3fb950;
  --jf-red: #f85149;
  --jf-red-soft: #ff7b72;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0d1117;
    --surface: #161b22;
    --surface-2: #21262d;
    --text: #e6edf3;
    --text-dim: #9198a1;
    --border: #30363d;
  }
}
html {
  color-scheme: dark; /* native controls (select/checkbox/scrollbars) go dark */
}

/* ---------- tool shell ---------- */
.jf {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  padding: 1rem;
  margin: 1.4rem 0 1.8rem;
  box-shadow: 0 8px 30px -18px rgba(0, 0, 0, 0.7);
}
/* On wide screens the editor breaks out of the narrow prose column —
   aligned to the column's left edge and capped to the viewport, so it
   can never overflow horizontally (prose sits left-of-center in .wrap). */
@media (min-width: 54rem) {
  .prose .jf {
    width: min(68rem, calc(100vw - 2.5rem));
  }
}

.jf-toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 0.45rem;
  align-items: center;
  padding-bottom: 0.8rem;
  border-bottom: 1px solid var(--border);
}
.jf-sp { flex: 1 1 auto; }

.jf-btn {
  font: inherit;
  font-size: 0.85rem;
  font-weight: 650;
  padding: 0.42rem 0.85rem;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s, filter 0.15s;
}
.jf-btn:hover {
  border-color: color-mix(in srgb, var(--primary) 60%, var(--border));
}
.jf-btn.primary {
  background: var(--jf-green);
  border-color: transparent;
  color: #04140a;
}
.jf-btn.primary:hover { filter: brightness(1.12); }
.jf-btn.ghost { background: transparent; color: var(--text-dim); }
.jf-btn.ghost:hover { color: var(--text); }

.jf select {
  font: inherit;
  font-size: 0.85rem;
  background: var(--surface-2);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.4rem 0.5rem;
}
.jf-check {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  font-size: 0.85rem;
  font-weight: 550;
  color: var(--text-dim);
  cursor: pointer;
  white-space: nowrap;
}
.jf-check input { accent-color: var(--jf-green); }

/* ---------- panes ---------- */
.jf-panes {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.9rem;
  margin-top: 0.9rem;
}
@media (max-width: 46rem) {
  .jf-panes { grid-template-columns: 1fr; }
}
.jf-pane { min-width: 0; }
.jf-panehead {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 0.6rem;
  font-size: 0.74rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: var(--text-dim);
  margin-bottom: 0.35rem;
}
.jf-panehead .jf-stat {
  font-family: var(--mono);
  font-weight: 500;
  text-transform: none;
  letter-spacing: 0;
  font-size: 0.78rem;
}
.jf textarea {
  display: block;
  width: 100%;
  min-height: 22rem;
  resize: vertical;
  font-family: var(--mono);
  font-size: 0.85rem;
  line-height: 1.55;
  color: var(--text);
  background: #0a0d12;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 0.8rem;
  tab-size: 2;
  transition: border-color 0.15s, box-shadow 0.15s;
}
.jf textarea:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--primary) 22%, transparent);
}
.jf textarea[readonly] { color: #c9d1d9; }

/* ---------- tabs (Text / Tree) ---------- */
.jf-tabs {
  display: inline-flex;
  gap: 0.15rem;
  background: var(--surface-2);
  border-radius: 7px;
  padding: 0.15rem;
}
.jf-tabs button {
  font: inherit;
  font-size: 0.74rem;
  font-weight: 700;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  border: none;
  border-radius: 5px;
  padding: 0.2rem 0.6rem;
  background: transparent;
  color: var(--text-dim);
  cursor: pointer;
}
.jf-tabs button.on {
  background: var(--bg);
  color: var(--text);
}

/* ---------- status + errors ---------- */
.jf-status {
  margin-top: 0.75rem;
  font-family: var(--mono);
  font-size: 0.82rem;
  color: var(--text-dim);
  min-height: 1.5em;
}
.jf-badge {
  display: inline-block;
  padding: 0.08em 0.6em;
  margin-right: 0.35em;
  border-radius: 999px;
  font-weight: 700;
  font-size: 0.76rem;
  font-family: var(--font);
}
.jf-badge.ok {
  background: rgba(63, 185, 80, 0.14);
  color: var(--jf-green);
  border: 1px solid rgba(63, 185, 80, 0.45);
}
.jf-badge.bad {
  background: rgba(248, 81, 73, 0.14);
  color: var(--jf-red-soft);
  border: 1px solid rgba(248, 81, 73, 0.45);
}

.jf-err {
  margin-top: 0.7rem;
  border: 1px solid rgba(248, 81, 73, 0.5);
  background: rgba(248, 81, 73, 0.08);
  border-radius: var(--radius-sm);
  padding: 0.7rem 0.9rem;
}
.jf-err-head { font-size: 0.92rem; color: var(--text); }
.jf-err-head strong { color: var(--jf-red-soft); font-weight: 650; }
.jf-err-loc { color: var(--text-dim); font-family: var(--mono); font-size: 0.82rem; }
.jf-err-snip {
  margin: 0.55rem 0 0;
  padding: 0.55rem 0.7rem;
  background: #0a0d12;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-family: var(--mono);
  font-size: 0.82rem;
  line-height: 1.5;
  overflow-x: auto;
  white-space: pre;
  color: var(--text);
}
.jf-err-snip .jf-err-caret { color: var(--jf-red-soft); font-weight: 700; }
.jf-err .jf-btn { margin-top: 0.55rem; }

/* ---------- tree view ---------- */
.jf-tree {
  min-height: 22rem;
  max-height: 34rem;
  overflow: auto;
  background: #0a0d12;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 0.7rem 0.8rem;
  font-family: var(--mono);
  font-size: 0.82rem;
  line-height: 1.6;
}
.jt-node { padding-left: 1.15rem; }
.jf-tree > .jt-node { padding-left: 0; }
.jt-node .jt-node {
  border-left: 1px solid var(--border);
}
.jt-kids[hidden], .jt-end[hidden] { display: none; }
.jt-row {
  display: flex;
  align-items: baseline;
  min-width: max-content;
}
.jt-tog {
  flex: none;
  width: 1.1rem;
  padding: 0;
  margin-left: -1.15rem;
  border: none;
  background: none;
  color: var(--text-dim);
  font: inherit;
  font-size: 0.75rem;
  cursor: pointer;
  text-align: left;
}
.jt-tog:hover { color: var(--text); }
.jt-togspace { flex: none; width: 0; margin-left: 0; }
.jt-key { color: #79c0ff; }
.jt-idx { color: #8b949e; }
.jt-str { color: #a5d6ff; }
.jt-num { color: #d2a8ff; }
.jt-lit { color: #ff7b72; }
.jt-null { color: #ff7b72; font-style: italic; }
.jt-p { color: var(--text-dim); }
.jt-meta {
  color: #8b949e;
  font-size: 0.76rem;
  background: var(--surface-2);
  border-radius: 999px;
  padding: 0 0.5em;
  margin: 0 0.35em;
}
.jt-end { color: var(--text-dim); padding-left: 0; }
.jt-more {
  font: inherit;
  font-size: 0.78rem;
  color: var(--primary);
  background: none;
  border: none;
  padding: 0.15rem 0;
  cursor: pointer;
}
.jt-more:hover { text-decoration: underline; }
.jt-empty { color: var(--text-dim); margin: 0.4rem; }

/* ---------- article code samples ---------- */
.prose pre {
  background: #0a0d12;
  border: 1px solid var(--border);
}
.prose code {
  background: var(--surface-2);
}
.prose pre code {
  background: none;
}
.prose table code { white-space: nowrap; }

@media (max-width: 480px) {
  .jf { padding: 0.8rem; }
  .jf textarea { min-height: 15rem; }
  .jf-tree { min-height: 15rem; max-height: 26rem; }
}
