/* JSON editor: two documents side by side (A | actions | B), each with a head, a toolbar,
   the text / tree / table view and a status bar.

   Layout by screen width:
   - 1100px and up (laptops, Full HD): A and B side by side, filling the screen height; the
     column between them holds the actions and a handle to resize.
   - 760px to 1099px (tablets): the same, with a narrower action column.
   - below 760px (phones): one document at a time, chosen with the A / B tabs; the actions sit in
     a row above it. */

.je { display: flex; flex-direction: column; gap: 14px; min-width: 0; }

.je-icon { width: 18px; height: 18px; flex-shrink: 0; }

/* ---------- Workspace ---------- */

.je-workspace {
  --split-a: 50fr;
  --split-b: 50fr;
  display: grid;
  grid-template-columns: minmax(0, var(--split-a)) 92px minmax(0, var(--split-b));
  gap: 0;
  /* Fills the window once you scroll to it: on a 1080p screen both documents get about 900px. */
  height: clamp(520px, calc(100dvh - 40px), 1600px);
  min-width: 0;
}

.je-panel {
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
  overflow: hidden;
  background: var(--surface);
  border: var(--border);
  border-radius: 14px;
  box-shadow: var(--shadow-sm);
}

/* ---------- Head: badge, name, file actions ---------- */

.je-head {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px 8px;
  padding: 8px 10px;
  background: var(--ink);
  color: var(--on-ink);
}

.je-badge {
  display: inline-grid;
  place-items: center;
  flex-shrink: 0;
  width: 26px;
  height: 26px;
  font: 700 14px var(--font-mono);
  color: var(--ink);
  background: var(--cat-json);
  border-radius: 6px;
}

.je-name {
  flex: 1 1 120px;
  min-width: 80px;
  height: 34px;
  padding: 0 8px;
  font: 700 15px var(--font-display);
  color: var(--on-ink);
  background: transparent;
  border: 1.5px solid transparent;
  border-radius: 8px;
}
.je-name:hover { border-color: var(--ink-3); }
.je-name:focus { border-color: var(--accent); outline: none; background: var(--ink-2); }

.je-head-actions { display: flex; flex-wrap: wrap; align-items: center; gap: 4px; }

.je-btn {
  position: relative;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 34px;
  padding: 0 10px;
  font: 600 13px var(--font-body);
  color: var(--on-ink);
  background: transparent;
  border: 1.5px solid transparent;
  border-radius: 8px;
  cursor: pointer;
  list-style: none;
}
.je-btn::-webkit-details-marker { display: none; }
.je-btn:hover { background: var(--ink-2); }
.je-btn[aria-pressed="true"] { color: var(--ink); background: var(--accent); }
.je-btn .je-icon:last-child:not(:first-child) { width: 14px; height: 14px; }

/* Drop-down menus (Open, Copy) are <details>, so they work with the keyboard without script. */
.je-menu { position: relative; }
.je-menu[open] > .je-btn { background: var(--ink-2); }
.je-menu-list {
  position: absolute;
  top: calc(100% + 6px);
  right: 0;
  z-index: 20;
  display: flex;
  flex-direction: column;
  min-width: 260px;
  padding: 6px;
  color: var(--ink);
  background: var(--surface);
  border: var(--border);
  border-radius: 12px;
  box-shadow: var(--shadow);
}
.je-menu-item {
  display: block;
  padding: 10px 12px;
  font: 500 14px var(--font-body);
  color: var(--ink);
  text-align: left;
  background: none;
  border: 0;
  border-radius: 8px;
  cursor: pointer;
}
.je-menu-item:hover, .je-menu-item:focus-within { background: var(--surface-2); }
.je-file input:focus-visible + * { outline: 3px solid var(--accent); }

.je-url { display: flex; flex-direction: column; gap: 6px; padding: 10px 12px; border-top: 1.5px solid #E3E9F4; }
.je-url-label { font-size: 13px; font-weight: 700; }
.je-url-row { display: flex; gap: 6px; }
.je-url-input {
  flex: 1 1 auto;
  min-width: 0;
  height: 36px;
  padding: 0 8px;
  font: 13px var(--font-mono);
  border: 2px solid var(--ink);
  border-radius: 8px;
}
.je-url .je-btn { color: var(--ink); background: var(--cat-json); border-color: var(--ink); }
.je-url-note { font-size: 12px; color: var(--ink-3); }

/* ---------- Toolbar ---------- */

.je-toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 4px;
  padding: 6px 8px;
  background: var(--surface-2);
  border-bottom: 1.5px solid #D6DEEE;
}

.je-modes { display: flex; overflow: hidden; border: 2px solid var(--ink); border-radius: 9px; }
.je-mode {
  min-height: 32px;
  padding: 0 12px;
  font: 600 13px var(--font-display);
  color: var(--ink);
  background: var(--surface);
  border: 0;
  border-right: 2px solid var(--ink);
  cursor: pointer;
}
.je-mode:last-child { border-right: 0; }
.je-mode[aria-pressed="true"] { background: var(--accent); }

.je-sep { width: 1.5px; height: 22px; margin: 0 4px; background: #C9D3E6; }

.je-tool {
  position: relative;
  display: inline-grid;
  place-items: center;
  width: 34px;
  height: 34px;
  padding: 0;
  color: var(--ink);
  background: transparent;
  border: 1.5px solid transparent;
  border-radius: 8px;
  cursor: pointer;
}
.je-tool:hover { background: var(--surface); border-color: var(--ink); }
.je-tool[aria-pressed="true"] { background: var(--cat-json); border-color: var(--ink); }
.je-tool:disabled { color: #B4C0D6; background: none; border-color: transparent; cursor: default; }

.je-indent {
  height: 30px;
  padding: 0 4px;
  font: 500 12px var(--font-body);
  color: var(--ink);
  background: var(--surface);
  border: 1.5px solid #C9D3E6;
  border-radius: 7px;
}

/* Tools that only make sense in one view. */
.je-panel:not([data-mode="tree"]) [data-for-mode="tree"],
.je-panel[data-mode="tree"] [data-for-mode="text"],
.je-panel[data-mode="table"] [data-for-mode="text"],
.je-panel[data-mode="table"] .je-search { display: none; }

.je-search {
  display: flex;
  align-items: center;
  gap: 6px;
  flex: 1 1 140px;
  max-width: 260px;
  min-width: 120px;
  height: 32px;
  margin-left: auto;
  padding: 0 8px;
  background: var(--surface);
  border: 1.5px solid #C9D3E6;
  border-radius: 8px;
}
.je-search:focus-within { border-color: var(--ink); }
.je-search .je-icon { width: 15px; height: 15px; color: var(--ink-3); }
.je-search-input { flex: 1 1 auto; min-width: 0; height: 100%; padding: 0; font: 13px var(--font-body); background: none; border: 0; outline: none; }
.je-search-count { font: 500 12px var(--font-mono); color: var(--ink-3); white-space: nowrap; }

/* Hints on hover and keyboard focus, as on the format buttons elsewhere on the site. */
[data-hint] { position: relative; }
.je-tool[data-hint]::after,
.je-btn[data-hint]::after,
.je-move[data-hint]::after,
.je-compare[data-hint]::after {
  content: attr(data-hint);
  position: absolute;
  top: calc(100% + 6px);
  left: 50%;
  z-index: 30;
  width: max-content;
  max-width: 240px;
  padding: 6px 10px;
  font: 500 12px/1.4 var(--font-body);
  text-align: left;
  white-space: normal;
  color: var(--on-ink);
  background: var(--ink);
  border-radius: 8px;
  transform: translateX(-50%);
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
}
.je-tool[data-hint]:hover::after, .je-tool[data-hint]:focus-visible::after,
.je-btn[data-hint]:hover::after, .je-btn[data-hint]:focus-visible::after,
.je-move[data-hint]:hover::after, .je-move[data-hint]:focus-visible::after,
.je-compare[data-hint]:hover::after, .je-compare[data-hint]:focus-visible::after { opacity: 1; visibility: visible; }
.je-menu[open] > .je-btn::after { display: none; }

/* ---------- Body: the views ---------- */

.je-body { position: relative; flex: 1 1 auto; min-height: 0; display: flex; flex-direction: column; }
.je-body > .ce { flex: 1 1 auto; }

/* Before the script runs, the textarea is a plain, usable box. */
.je-text {
  flex: 1 1 auto;
  width: 100%;
  min-height: 0;
  padding: 10px 14px;
  font: 14px/22px var(--font-mono);
  border: 0;
  resize: none;
}

.je-view { flex: 1 1 auto; min-height: 0; display: flex; flex-direction: column; overflow: hidden; }

/* The shared tree fills the document instead of being a box of its own. */
.je-view .jt { flex: 1 1 auto; min-height: 0; gap: 0; }
.je-view .jt-pathbar { border: 0; border-bottom: 1.5px solid #D6DEEE; border-radius: 0; }
.je-view .jt-scroll { flex: 1 1 auto; max-height: none; border: 0; border-radius: 0; }

.je-drop {
  position: absolute;
  inset: 8px;
  z-index: 5;
  display: none;
  place-items: center;
  font: 700 18px var(--font-display);
  background: rgba(255, 212, 59, 0.85);
  border: 3px dashed var(--ink);
  border-radius: 12px;
}
.je-body.is-dropping .je-drop { display: grid; }

/* ---------- Status bar and notes ---------- */

.je-status {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 4px 12px;
  min-height: 34px;
  padding: 6px 10px;
  font-size: 13px;
  background: var(--surface-2);
  border-top: 1.5px solid #D6DEEE;
}
.je-status.is-valid { background: #EBFBEE; }
.je-status.is-invalid { background: #FFF0F0; }
.je-status-main { min-width: 0; overflow-wrap: anywhere; }
.je-status-side { display: flex; gap: 12px; font: 500 12px var(--font-mono); color: var(--ink-3); white-space: nowrap; }

.je-link {
  padding: 0;
  font: inherit;
  font-weight: 700;
  color: var(--hover);
  text-decoration: underline;
  text-underline-offset: 2px;
  background: none;
  border: 0;
  cursor: pointer;
}
.je-warn { color: #9C5700; }

.je-notes {
  max-height: 40%;
  overflow: auto;
  padding: 8px 12px;
  font-size: 13px;
  background: #E7F0FF;
  border-top: 1.5px solid #D6DEEE;
}
.je-notes.is-error { background: #FFE3E3; }
.je-notes.is-warn { background: #FFF3BF; }
.je-notes-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; }
.je-notes-close { padding: 0 4px; font-size: 14px; background: none; border: 0; cursor: pointer; }
.je-notes-list { margin: 6px 0 0; padding-left: 20px; }

/* ---------- The column between A and B ---------- */

.je-middle {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
  padding: 14px 6px;
  min-height: 0;
}
.je-middle-group { display: flex; flex-wrap: wrap; justify-content: center; gap: 6px; }
.je-middle-label { flex-basis: 100%; font-size: 11px; font-weight: 700; letter-spacing: 0.05em; text-align: center; text-transform: uppercase; color: var(--ink-3); }

.je-move {
  display: inline-grid;
  place-items: center;
  width: 36px;
  height: 34px;
  padding: 0;
  color: var(--ink);
  background: var(--surface);
  border: 2px solid var(--ink);
  border-radius: 8px;
  box-shadow: 2px 2px 0 var(--ink);
  cursor: pointer;
}
.je-move:hover { background: var(--cat-json); }
.je-move:active { transform: translate(2px, 2px); box-shadow: none; }

.je-compare {
  min-height: 34px;
  padding: 0 10px;
  font: 700 13px var(--font-display);
  color: var(--ink);
  background: var(--surface);
  border: 2px solid var(--ink);
  border-radius: 8px;
  box-shadow: 2px 2px 0 var(--ink);
  cursor: pointer;
}
.je-compare[aria-pressed="true"] { background: var(--accent); }
.je-compare[aria-pressed="true"]::before { content: "✓ "; }
.je-diff-count { flex-basis: 100%; font-size: 12px; font-weight: 600; text-align: center; color: var(--ink-2); }

/* The resize handle: the rest of the column, with a dotted line to grab. */
.je-grip {
  flex: 1 1 auto;
  width: 100%;
  min-height: 40px;
  cursor: col-resize;
  touch-action: none;
  background: radial-gradient(circle, var(--line-soft) 1.5px, transparent 2px) center / 6px 10px repeat-y;
  border-radius: 8px;
}
.je-grip:hover, .je-grip:focus-visible { background-color: rgba(255, 107, 44, 0.15); }

/* ---------- Below the workspace ---------- */

.je-below { display: flex; flex-wrap: wrap; gap: 8px 20px; align-items: center; }
.je-remember { display: flex; align-items: flex-start; gap: 8px; font-size: 13px; color: var(--ink-2); cursor: pointer; }
.je-remember input { width: 18px; height: 18px; margin: 0; flex-shrink: 0; accent-color: var(--ink); }

/* Tabs to switch documents: phones only. */
.je-tabs { display: none; }

/* ---------- Differences list ---------- */

.je-diff { display: flex; flex-direction: column; gap: 12px; padding-top: 16px; border-top: 2px dashed var(--line-soft); }
.je-diff-summary { margin: 0; font-size: 15px; }
.je-diff.is-identical .je-diff-summary { padding: 12px 16px; background: #D3F9D8; border: var(--border); border-radius: 12px; }
.je-filters .segmented-btn { min-height: 38px; padding: 0 14px; font-size: 14px; }

.je-changes {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(min(100%, 520px), 1fr));
  gap: 8px;
  margin: 0;
  padding: 0;
  list-style: none;
}
.je-changes:empty { display: none; }
.je-change {
  display: grid;
  grid-template-columns: 96px minmax(0, 1fr);
  gap: 2px 12px;
  align-items: baseline;
  padding: 8px 12px;
  background: var(--surface);
  border: var(--border);
  border-left-width: 8px;
  border-radius: 10px;
}
.je-change-kind { grid-row: span 2; font-size: 11px; font-weight: 700; letter-spacing: 0.04em; text-transform: uppercase; }
.je-change-path {
  justify-self: start;
  padding: 0;
  font: 700 14px var(--font-mono);
  color: var(--ink);
  text-align: left;
  overflow-wrap: anywhere;
  background: none;
  border: 0;
  cursor: pointer;
}
.je-change-path:hover { text-decoration: underline; }
.je-change-values { font: 13px/1.5 var(--font-mono); overflow-wrap: anywhere; }
.je-old, .je-new { padding: 1px 4px; border-radius: 4px; font: inherit; }
.je-old { background: #FFE3E3; text-decoration: line-through; text-decoration-color: rgba(180, 35, 24, 0.6); }
.je-new { background: #D3F9D8; }
.je-arrow { white-space: pre; color: var(--ink-3); }
.je-change-added { border-left-color: #2F9E44; }
.je-change-removed { border-left-color: #E03131; }
.je-change-changed { border-left-color: #F08C00; }
.je-change-type { border-left-color: #7048E8; }
.je-change-removed .je-old { text-decoration: none; }
.je-diff-actions { display: flex; flex-wrap: wrap; gap: 12px; }
.je-diff-actions:not(:has(> :not([hidden]))) { display: none; }

/* ---------- Transform dialog ---------- */

.je-dialog {
  width: min(760px, calc(100vw - 32px));
  max-height: calc(100dvh - 32px);
  padding: 0;
  color: var(--ink);
  background: var(--surface);
  border: var(--border);
  border-radius: 16px;
  box-shadow: var(--shadow-lg);
}
.je-dialog::backdrop { background: rgba(11, 31, 68, 0.45); }
.je-dialog-form { display: flex; flex-direction: column; gap: 14px; padding: 18px 20px; }
.je-dialog-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.je-dialog-title { margin: 0; font: 700 22px var(--font-display); }
.je-dialog-intro { margin: 0; font-size: 14px; color: var(--ink-2); }
.je-dialog-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px 16px; }
.je-field { display: flex; flex-direction: column; gap: 6px; min-width: 0; margin: 0; padding: 0; font-size: 13px; font-weight: 700; border: 0; }
.je-field legend { padding: 0; margin-bottom: 6px; }
.je-field-row { flex-direction: row; flex-wrap: wrap; }
.je-field-note { font-weight: 500; color: var(--ink-3); }
.je-field select,
.je-field input[type="text"] {
  flex: 0 0 auto;
  min-width: 0;
  height: 38px;
  padding: 0 8px;
  font: 500 14px var(--font-body);
  color: var(--ink);
  background: var(--surface);
  border: 2px solid var(--ink);
  border-radius: 8px;
}
.je-field-row select,
.je-field-row input[type="text"] { flex: 1 1 120px; }
.je-field input:disabled { background: var(--surface-2); border-color: #C9D3E6; }
.je-picks { display: flex; flex-wrap: wrap; gap: 6px 14px; max-height: 120px; overflow: auto; font: 500 13px var(--font-mono); }
.je-pick { display: inline-flex; align-items: center; gap: 4px; cursor: pointer; }
.je-query { padding: 8px 10px; font: 500 13px var(--font-mono); background: var(--surface-2); border-radius: 8px; overflow-wrap: anywhere; }
.je-preview {
  max-height: 220px;
  margin: 0;
  padding: 10px 12px;
  overflow: auto;
  font: 12.5px/1.5 var(--font-mono);
  background: var(--surface-2);
  border: 1.5px solid #D6DEEE;
  border-radius: 8px;
}
.je-dialog-actions { display: flex; justify-content: flex-end; gap: 10px; }

/* ---------- Full screen: one document over the whole window ---------- */

html.je-no-scroll { overflow: hidden; }
.je.is-fullscreen .je-workspace {
  position: fixed;
  inset: 0;
  z-index: 100;
  grid-template-columns: minmax(0, 1fr);
  height: auto;
  padding: 10px;
  background: var(--paper);
}
.je.is-fullscreen .je-middle,
.je-workspace[data-focus="a"] [data-panel="b"],
.je-workspace[data-focus="b"] [data-panel="a"] { display: none; }

/* ---------- Tablets ---------- */

@media (max-width: 1099px) {
  .je-workspace { grid-template-columns: minmax(0, var(--split-a)) 64px minmax(0, var(--split-b)); }
  .je-middle-label { font-size: 10px; letter-spacing: 0; }
  .je-compare { padding: 0 6px; font-size: 12px; }
  .je-hide-narrow { display: none; }
  .je-btn span { display: none; }
  .je-btn { padding: 0 8px; }
}

/* ---------- Phones: one document at a time ---------- */

@media (max-width: 759px) {
  .je-tabs { display: flex; gap: 6px; }
  .je-tab {
    flex: 1 1 0;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    min-width: 0;
    min-height: 44px;
    padding: 0 10px;
    font: 600 14px var(--font-display);
    color: var(--ink);
    background: var(--surface);
    border: var(--border);
    border-radius: 10px;
    cursor: pointer;
  }
  .je-tab span:last-child { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .je-tab[aria-selected="true"] { background: var(--accent); box-shadow: var(--shadow-sm); }

  .je-workspace {
    grid-template-columns: minmax(0, 1fr);
    grid-template-rows: auto minmax(0, 1fr);
    gap: 10px;
    height: clamp(460px, calc(100dvh - 90px), 1200px);
  }
  .je-workspace[data-show="a"] [data-panel="b"],
  .je-workspace[data-show="b"] [data-panel="a"] { display: none; }
  .je-middle { grid-row: 1; flex-direction: row; flex-wrap: wrap; justify-content: center; gap: 8px 14px; padding: 0; }
  .je-middle-group { flex-wrap: nowrap; align-items: center; }
  .je-middle-label { flex-basis: auto; }
  .je-diff-count { flex-basis: auto; }
  .je-grip { display: none; }
  .je-panel { grid-row: 2; }

  .je-move { width: 40px; height: 38px; }
  .je-tool { width: 40px; height: 40px; }
  .je-search { order: 10; flex-basis: 100%; max-width: none; margin-left: 0; }
  .je-dialog-grid { grid-template-columns: minmax(0, 1fr); }
  .je-change { grid-template-columns: minmax(0, 1fr); }
  .je-change-kind { grid-row: auto; }
  .je-menu-list { right: auto; left: 0; }
  /* Hints would cover what you tap on a touch screen. */
  .je-tool[data-hint]::after, .je-btn[data-hint]::after, .je-move[data-hint]::after, .je-compare[data-hint]::after { display: none; }
}

@media (prefers-reduced-motion: no-preference) {
  .je-tool[data-hint]::after, .je-btn[data-hint]::after, .je-move[data-hint]::after, .je-compare[data-hint]::after { transition: opacity 120ms ease 350ms; }
}

/* Menus and hints reach outside a document, so the panel does not clip; its first and last
   rows round their own corners instead. */
.je-panel { overflow: visible; }
.je-head { border-radius: 12px 12px 0 0; }
.je-panel > :last-child { border-radius: 0 0 12px 12px; }
.je-body { overflow: hidden; }

/* Phones: keep the chrome around the document to a minimum, so the JSON gets the height.
   Rows of buttons scroll sideways instead of wrapping onto more lines. */
@media (max-width: 759px) {
  .je-head .je-badge { display: none; }
  .je-name { flex: 1 1 60px; min-width: 60px; }
  .je-head-actions { flex-wrap: nowrap; }
  .je-btn { padding: 0 6px; }
  .je-toolbar { flex-wrap: nowrap; overflow-x: auto; scrollbar-width: none; }
  .je-toolbar > * { flex-shrink: 0; }
  .je-tool { width: 36px; height: 36px; }
  .je-sep { display: none; }
  .je-search { order: 0; flex: 0 0 170px; max-width: none; margin-left: 4px; }
  .je-view .jt-pathbar { flex-wrap: nowrap; overflow-x: auto; scrollbar-width: none; }
  .je-view .jt-pathbar > * { flex-shrink: 0; }
  .je-view .jt-actions { flex-wrap: nowrap; margin-left: 8px; }
  .je-view .jt-path { flex: 0 0 auto; }
  .je-view .jt-copy { min-height: 34px; box-shadow: none; }
  .jtab-hint { display: none; }
}
