/* Layout: a working tool — compact toolbar above a split view; the editor on the left, the tree on the right.
   On phones and tablets the two panes become an Editor | Tree switch. Colours, fonts and shapes come from Jive. */

:root {
  --bg: var(--surface);
  --panel: var(--surface-raised);
  --chip: var(--surface-sunken);
  --fg: var(--ink);
  --muted: var(--ink-muted);
  --accent: var(--brand);
  --seg-shadow: var(--shadow-sm), 0 0 0 1px var(--line);
  /* JSON value colours, readable on both themes */
  --j-key: var(--brand);
  --j-string: light-dark(#8a4b00, #f5b544);
  --j-number: light-dark(#0369a1, #7dd3fc);
  --j-bool: light-dark(#be123c, #fb8a97);
  --j-null: var(--ink-muted);
  --mono: var(--font-mono);
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { height: 100%; margin: 0; }
body { display: flex; flex-direction: column; background: var(--bg); color: var(--fg); font: 400 14px/1.45 var(--font-body); }
svg { width: 15px; height: 15px; fill: none; stroke: currentColor; stroke-width: 1.5; stroke-linecap: round; stroke-linejoin: round; flex: none; }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* ---------- top bar ---------- */
.topbar {
  display: flex; flex-wrap: wrap; align-items: center; gap: 10px 16px;
  padding-block: 10px;
  padding-left: max(16px, env(safe-area-inset-left, 0px));
  padding-right: max(16px, env(safe-area-inset-right, 0px));
  background: var(--panel); border-bottom: 1px solid var(--line);
}
.brand { display: inline-flex; align-items: center; gap: 8px; min-width: 0; white-space: nowrap; }
.brand-back { color: var(--muted); font: 500 14px/1 var(--font-body); text-decoration: none; padding: 6px 8px; margin-left: -8px; border-radius: var(--radius-sm); }
.brand-back:hover { color: var(--fg); background: var(--chip); }
.brand-sep { color: var(--line-strong); }
.brand-mark { font: 600 15px/1 var(--mono); letter-spacing: -.02em; }
.brand-mark span span { color: var(--accent); }

.toolbar { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; flex: 1; justify-content: center; }
.actions { display: flex; align-items: center; gap: 8px; }
.actions .jv-btn svg { width: 15px; height: 15px; }
.theme-btn { font-size: 0; gap: 0; width: 32px; padding: 0; }
.theme-btn .jv-themeflip__icon { font-size: 16px; line-height: 1; width: auto; }
.jv-menu__list { left: auto; right: 0; }

/* indent: segmented control built from radio buttons, Jive pill shape */
.seg { display: inline-flex; margin: 0; padding: 3px; border: 1px solid var(--line); border-radius: var(--radius-pill); background: var(--chip); }
.seg legend { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.seg input { position: absolute; opacity: 0; pointer-events: none; }
.seg label { display: inline-flex; align-items: center; height: 24px; padding: 0 10px; border-radius: var(--radius-pill); color: var(--muted); font-weight: 500; font-size: 13px; cursor: pointer; user-select: none; transition: color .15s, background-color .15s, box-shadow .15s; }
.seg label:hover { color: var(--fg); }
.seg input:checked + label { background: var(--panel); color: var(--fg); box-shadow: var(--seg-shadow); }
.seg input:focus-visible + label { outline: 2px solid var(--focus); outline-offset: 1px; }

/* Editor | Tree switch and phone-only menu items: hidden on bigger screens */
.viewtabs { display: none; }
.phone-only { display: none !important; }

/* ---------- workspace ---------- */
.workspace { flex: 1; display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); min-height: 0; }
.pane { display: flex; flex-direction: column; min-width: 0; min-height: 0; }
.pane-editor { background: var(--panel); border-right: 1px solid var(--line); }
.pane-tree { background: var(--bg); }
.pane-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; min-height: 42px; padding: 0 16px; border-bottom: 1px solid var(--line); font-size: 12px; }
.pane-title { font-weight: 600; letter-spacing: .01em; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pane-meta { color: var(--muted); font: 400 11.5px/1 var(--mono); font-variant-numeric: tabular-nums; white-space: nowrap; }

/* editor: line numbers + textarea, sharing one font and line height */
.editor { position: relative; flex: 1; display: flex; min-height: 0; font: 400 13px/22px var(--mono); }
.gutter {
  --digits: 1;
  margin: 0; padding: 14px 10px 40px 14px; min-width: calc(var(--digits) * 1ch + 26px);
  overflow: hidden; text-align: right; color: var(--muted); opacity: .6; user-select: none;
  font: inherit; border-right: 1px solid var(--line); background: var(--chip);
}
#input {
  flex: 1; min-width: 0; min-height: 0; margin: 0; padding: 14px 16px 40px; border: 0; resize: none; outline: none;
  background: transparent; color: var(--fg); font: inherit; tab-size: 2; white-space: pre; overflow: auto; caret-color: var(--accent);
}
#input::placeholder { color: var(--muted); }
#input::selection { background: color-mix(in oklab, var(--brand) 25%, transparent); }
.error-line { position: absolute; left: 0; right: 0; top: 14px; height: 22px; pointer-events: none; background: color-mix(in oklab, var(--danger) 14%, transparent); box-shadow: inset 3px 0 0 var(--danger); }

.status { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 10px; min-height: 46px; padding: 8px 16px; border-top: 1px solid var(--line); font-size: 13px; }
.status[data-tone="error"] { background: color-mix(in oklab, var(--danger) 7%, var(--panel)); }
.status-msg { color: var(--fg); }
.status-note { color: var(--muted); }
.status-warn { color: var(--warning); }

/* ---------- tree ---------- */
.tree-head { gap: 8px; }
.search { flex: 1; min-width: 120px; height: 30px; padding: 0 10px; border: 1px solid var(--line-strong); border-radius: var(--radius-md); background: var(--chip); color: var(--fg); font: 400 13px/1 var(--font-body); }
.search:focus { outline: none; border-color: var(--brand); box-shadow: var(--shadow-glow); }
.tree-buttons { display: inline-flex; gap: 2px; }
.tree { flex: 1; overflow: auto; padding: 10px 0 24px; font: 400 13px/24px var(--mono); }
.tree-empty { margin: 24px 16px; color: var(--muted); font-family: var(--font-body); }
.tl { --d: 0; display: flex; align-items: center; gap: 6px; padding: 0 16px 0 calc(10px + var(--d) * 18px); white-space: nowrap; cursor: default; }
.tl:hover { background: var(--chip); }
.tl[aria-selected="true"] { background: color-mix(in oklab, var(--brand) 13%, transparent); }
.tl:focus { outline: none; }
.tl:focus-visible { outline: 2px solid var(--focus); outline-offset: -2px; }
.tl.hit { box-shadow: inset 3px 0 0 var(--warning); }
.tt, .tt-space { flex: none; width: 16px; height: 16px; }
.tt { display: inline-grid; place-content: center; padding: 0; border: 0; border-radius: 4px; background: transparent; color: var(--muted); cursor: pointer; }
.tt::before { content: ""; width: 0; height: 0; border-left: 5px solid currentColor; border-top: 4px solid transparent; border-bottom: 4px solid transparent; transition: transform .15s ease; }
.tt[aria-expanded="true"]::before { transform: rotate(90deg); }
.tt:hover { color: var(--fg); background: var(--line); }
.k { color: var(--j-key); }
.k + .p { margin-left: -6px; }
.k.idx { color: var(--muted); }
.p { color: var(--muted); }
.ellipsis { margin-inline: -4px; }
.tt[aria-expanded="true"] ~ .ellipsis, .tt[aria-expanded="true"] ~ .close { display: none; }
.meta { color: var(--muted); font: 400 12px/1 var(--font-body); margin-left: 4px; }
.v { overflow: hidden; text-overflow: ellipsis; }
.v.string { color: var(--j-string); }
.v.number { color: var(--j-number); }
.v.boolean { color: var(--j-bool); }
.v.null { color: var(--j-null); font-style: italic; }
.tree mark { background: color-mix(in oklab, var(--warning) 32%, transparent); color: inherit; border-radius: 3px; }
.tmore { --d: 0; display: block; margin: 2px 0 6px calc(32px + var(--d) * 18px); padding: 2px 10px; border: 1px dashed var(--line-strong); border-radius: var(--radius-pill); background: transparent; color: var(--brand); font: 500 12px/20px var(--font-body); cursor: pointer; }
.tmore:hover { border-style: solid; }

.pathbar { display: flex; align-items: center; gap: 6px; min-height: 46px; padding: 6px 12px 6px 16px; border-top: 1px solid var(--line); background: var(--panel); }
.pathbar code { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font: 500 12.5px/1.4 var(--mono); color: var(--fg); }

/* ---------- footer ---------- */
.footer {
  display: flex; align-items: center; justify-content: center; gap: 7px;
  padding-block: 9px;
  padding-left: max(16px, env(safe-area-inset-left, 0px));
  padding-right: max(16px, env(safe-area-inset-right, 0px));
  background: var(--panel); border-top: 1px solid var(--line); color: var(--muted); font-size: 12px; text-align: center;
}
.footer svg { width: 13px; height: 13px; }

/* ---------- drop overlay ---------- */
.drop { position: fixed; inset: 0; z-index: 20; display: grid; place-items: center; background: color-mix(in srgb, var(--bg) 70%, transparent); backdrop-filter: blur(6px); pointer-events: none; }
.drop-card { padding: 28px 40px; border: 2px dashed var(--accent); border-radius: 14px; background: var(--panel); color: var(--fg); font-size: 16px; font-weight: 600; }

/* ---------- tablets: toolbar on its own row, editor and tree still side by side ---------- */
@media (max-width: 1000px) {
  .brand { flex: 1; }
  .toolbar { order: 3; flex-basis: 100%; justify-content: flex-start; }
  .tree-buttons .jv-btn { padding-inline: 8px; }
}

/* ---------- narrow screens: one pane at a time, Editor | Tree switch ---------- */
@media (max-width: 767px) {
  .viewtabs { order: 4; display: flex; gap: 2px; padding: 3px; border: 1px solid var(--line); border-radius: var(--radius-pill); background: var(--chip); }
  .viewtab { height: 28px; padding: 0 14px; border: 0; border-radius: var(--radius-pill); background: transparent; color: var(--muted); font: 500 13px/1 var(--font-body); cursor: pointer; }
  .viewtab[aria-selected="true"] { background: var(--panel); color: var(--fg); box-shadow: var(--seg-shadow); }
  .workspace { grid-template-columns: minmax(0, 1fr); }
  .workspace[data-view="editor"] .pane-tree, .workspace[data-view="tree"] .pane-editor { display: none; }
  .pane-editor { border-right: 0; }
}

/* ---------- phones ---------- */
@media (max-width: 640px) {
  .topbar { gap: 10px 8px; }
  .viewtabs { order: 1; }
  .theme-btn { order: 2; }
  .actions { display: none; }
  .phone-only { display: block !important; }
  /* Format · Minify · Repair · More in one row of equal buttons, indent below */
  .toolbar { order: 3; display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 6px; }
  .toolbar > .jv-btn, .toolbar .jv-menu, .toolbar .jv-menu > .jv-btn { width: 100%; }
  .toolbar .seg { order: 5; grid-column: 1 / -1; justify-self: start; }
  .footer { font-size: 11px; padding-block: 7px; }
  .tree-head { flex-wrap: wrap; padding-block: 8px; }
  .search { flex-basis: 100%; }
  .tree-buttons { margin-left: auto; }
  .gutter { padding-left: 8px; padding-right: 6px; }
  #input { padding-inline: 10px; }
}

@media (prefers-reduced-motion: reduce) { * { transition: none !important; } }

/* Smallest phones: drop the "Tools /" crumb so the name, Editor | Tree and theme fit one row */
@media (max-width: 360px) {
  .brand-back, .brand-sep { display: none; }
  .viewtab { padding: 0 12px; }
}
