/*
 * JSON Tools styles: two-pane full-height layout (input / output) in both themes.
 *
 * Colours, fonts and radii come from the same design tokens as the home page
 * (shadcn zinc scale + 0.625rem radius + indigo→purple brand gradient). Written out
 * locally per the self-containment rule — nothing outside this folder is referenced.
 */

:root {
  --bg: #ffffff;
  --panel: #ffffff;
  --panel-2: #f4f4f5;
  --border: #e4e4e7;
  --text: #09090b;
  --muted: #71717a;
  --accent: #18181b;        /* shadcn primary: the main button is near-black */
  --accent-text: #fafafa;
  --ring: #a1a1aa;
  --code-bg: #fafafa;
  --code-text: #09090b;
  --danger: #ef4444;
  --warn: #b45309;
  --ok: #15803d;
  --radius: 0.625rem;
  --brand-from: #6366f1;
  --brand-to: #a855f7;
  --shadow: 0 4px 12px rgba(0, 0, 0, 0.08);

  /* Syntax colours for values in the tree view */
  --tok-string: #0f766e;
  --tok-number: #b45309;
  --tok-boolean: #7c3aed;
  --tok-null: #71717a;
  --tok-key: #1d4ed8;

  --font-sans: system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto,
    'Helvetica Neue', 'PingFang SC', 'Microsoft YaHei', Arial, sans-serif;
  --font-mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

:root[data-theme='dark'] {
  --bg: #09090b;
  --panel: #09090b;
  --panel-2: #18181b;
  --border: #27272a;
  --text: #fafafa;
  --muted: #a1a1aa;
  --accent: #fafafa;
  --accent-text: #18181b;
  --ring: #d4d4d8;
  --code-bg: #09090b;
  --code-text: #fafafa;
  --danger: #f87171;
  --warn: #fbbf24;
  --ok: #4ade80;
  --shadow: 0 4px 12px rgba(0, 0, 0, 0.5);

  --tok-string: #5eead4;
  --tok-number: #fbbf24;
  --tok-boolean: #c4b5fd;
  --tok-null: #a1a1aa;
  --tok-key: #93c5fd;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

/* Author `display` rules beat the UA's [hidden]; make hiding win everywhere */
[hidden] { display: none !important; }

body {
  font-family: var(--font-sans);
  -webkit-font-smoothing: antialiased;
  background: var(--bg);
  color: var(--text);
  height: 100vh;
  height: 100dvh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  font-size: 14px;
}

/* ---------- topbar ---------- */

.topbar {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 8px 14px;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
}

.topbar__lead { display: flex; align-items: center; gap: 12px; min-width: 0; }
.topbar__title {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 15px;
  font-weight: 600;
  white-space: nowrap;
}
.btn, .segmented button { display: inline-flex; align-items: center; gap: 5px; }
.segmented button svg, .btn svg { flex-shrink: 0; }
.topbar__actions { display: flex; align-items: center; gap: 8px; }

/*
 * Back to home: every app pins it top-left (see the README). This app has its own
 * topbar, so it lives at the far left of that bar rather than as a fixed overlay —
 * visually the same corner.
 */
.back-home {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 7px 13px 7px 9px;
  border-radius: 999px;
  font-size: 13px;
  line-height: 1;
  text-decoration: none;
  color: var(--muted);
  background: var(--panel-2);
  border: 1px solid var(--border);
  transition: color 0.15s, background 0.15s, border-color 0.15s;
}
.back-home:hover { color: var(--text); border-color: var(--ring); }

.btn {
  font: inherit;
  font-size: 13px;
  padding: 6px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--panel-2);
  color: var(--text);
  cursor: pointer;
  white-space: nowrap;
  transition: background 0.15s, border-color 0.15s, opacity 0.15s;
}
.btn:hover { border-color: var(--ring); }
.btn--sm { padding: 3px 8px; font-size: 12px; }

.segmented {
  display: flex;
  gap: 2px;
  padding: 2px;
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}
.segmented button {
  font: inherit;
  font-size: 12px;
  padding: 4px 11px;
  border: none;
  border-radius: calc(var(--radius) - 2px);
  background: transparent;
  color: var(--muted);
  cursor: pointer;
}
.segmented button:hover { color: var(--text); }
.segmented button.is-active { background: var(--accent); color: var(--accent-text); }
.segmented--tabs { background: transparent; border-color: transparent; padding: 0; }
.segmented--tabs button { font-size: 12px; font-weight: 600; padding: 5px 12px; }

/* ---------- dropdown ---------- */

.menu { position: relative; }
.menu__list {
  position: absolute;
  right: 0;
  top: calc(100% + 6px);
  z-index: 50;
  min-width: 180px;
  padding: 5px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}
.menu__list button {
  display: block;
  width: 100%;
  text-align: left;
  font: inherit;
  font-size: 13px;
  padding: 7px 10px;
  border: none;
  border-radius: calc(var(--radius) - 2px);
  background: transparent;
  color: var(--text);
  cursor: pointer;
}
.menu__list button:hover { background: var(--panel-2); }
.menu__list button.is-danger { color: var(--danger); }
.menu__list hr { border: none; border-top: 1px solid var(--border); margin: 4px 2px; }

/* ---------- workspace ---------- */

.workspace {
  flex: 1 1 auto;
  display: grid;
  grid-template-columns: var(--split, 1fr) 6px 1fr;
  grid-template-rows: 1fr;
  min-height: 0;
}

.pane {
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
  background: var(--panel);
}

.pane__head {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 5px 10px;
  background: var(--panel-2);
  border-bottom: 1px solid var(--border);
  min-height: 34px;
}
.pane__head-right { display: flex; align-items: center; gap: 10px; }
.pane__label { font-size: 11px; letter-spacing: 0.08em; text-transform: uppercase; color: var(--muted); }

.pane__opt {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-size: 11px;
  color: var(--muted);
  white-space: nowrap;
}
.pane__opt select {
  font: inherit;
  font-size: 11px;
  padding: 2px 4px;
  border: 1px solid var(--border);
  border-radius: calc(var(--radius) - 4px);
  background: var(--panel);
  color: var(--text);
}
.pane__opt input[type='checkbox'] { accent-color: var(--brand-from); }

.splitter { background: var(--border); cursor: col-resize; }
.splitter:hover, .splitter:focus-visible { background: var(--ring); outline: none; }

/* ---------- input ---------- */

.editor {
  flex: 1 1 auto;
  width: 100%;
  padding: 12px;
  border: none;
  outline: none;
  resize: none;
  font-family: var(--font-mono);
  font-size: 13px;
  line-height: 1.6;
  background: var(--code-bg);
  color: var(--code-text);
  tab-size: 2;
  white-space: pre;
  overflow: auto;
}
.editor::placeholder { color: var(--muted); opacity: 0.75; }

.statusbar {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 4px 10px;
  font-size: 11px;
  color: var(--muted);
  background: var(--panel-2);
  border-top: 1px solid var(--border);
}
.statusbar__metrics { font-variant-numeric: tabular-nums; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
#status.is-ok { color: var(--ok); }
#status.is-error { color: var(--danger); }

/* ---------- output ---------- */

.output {
  flex: 1 1 auto;
  min-height: 0;
  overflow: auto;
  background: var(--code-bg);
}

.code {
  padding: 12px;
  font-family: var(--font-mono);
  font-size: 13px;
  line-height: 1.6;
  color: var(--code-text);
  white-space: pre;
  tab-size: 2;
}

.empty {
  padding: 28px 20px;
  font-size: 13px;
  color: var(--muted);
  text-align: center;
}

.error {
  margin: 14px;
  padding: 14px 16px;
  border-radius: var(--radius);
  border: 1px solid color-mix(in srgb, var(--danger) 40%, var(--border));
  background: color-mix(in srgb, var(--danger) 8%, transparent);
}
.error__title { font-size: 13px; font-weight: 600; color: var(--danger); margin-bottom: 6px; }
.error__msg { font-family: var(--font-mono); font-size: 12px; line-height: 1.6; word-break: break-word; }
.error__where { margin-top: 8px; font-size: 12px; color: var(--muted); font-variant-numeric: tabular-nums; }

/* ---------- tree ---------- */

.tree {
  padding: 12px 12px 24px;
  font-family: var(--font-mono);
  font-size: 13px;
  line-height: 1.75;
}
.node { display: flex; align-items: baseline; gap: 2px; white-space: pre; }
.kids { padding-left: 18px; border-left: 1px solid var(--border); margin-left: 7px; }

.twist {
  flex: 0 0 auto;
  width: 14px;
  height: 14px;
  padding: 0;
  margin-right: 3px;
  border: none;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  font: inherit;
  line-height: 1;
  align-self: center;
}
.twist::before { content: '▾'; display: inline-block; transition: transform 0.12s; font-size: 10px; }
.twist--leaf { cursor: default; }
.twist--leaf::before { content: ''; }
.node.is-closed > .twist::before { transform: rotate(-90deg); }

.k { color: var(--tok-key); }
.sep { color: var(--muted); }
.brace { color: var(--muted); }
.count { color: var(--muted); opacity: 0.7; font-size: 11px; }
.node.is-closed > .count { opacity: 1; }

.v--string { color: var(--tok-string); }
.v--number { color: var(--tok-number); }
.v--boolean { color: var(--tok-boolean); }
.v--null { color: var(--tok-null); font-style: italic; }

/* ---------- table ---------- */

.table-wrap { overflow-x: auto; }
.table {
  border-collapse: collapse;
  width: max-content;
  min-width: 100%;
  font-size: 13px;
}
.table th, .table td {
  padding: 6px 12px;
  border-bottom: 1px solid var(--border);
  border-right: 1px solid var(--border);
  text-align: left;
  vertical-align: top;
  max-width: 340px;
  overflow-wrap: anywhere;
}
.table th {
  position: sticky;
  top: 0;
  z-index: 1;
  background: var(--panel-2);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--muted);
  white-space: nowrap;
}
.table tbody tr:hover { background: color-mix(in srgb, var(--panel-2) 60%, transparent); }
.td--idx { color: var(--muted); font-variant-numeric: tabular-nums; text-align: right; width: 1%; }
.td--empty::after { content: '—'; color: var(--muted); opacity: 0.5; }
.table-foot { padding: 8px 12px 20px; font-size: 11px; color: var(--muted); }

/* ---------- toast ---------- */

.toast {
  position: fixed;
  bottom: 22px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 100;
  padding: 9px 18px;
  border-radius: 999px;
  background: var(--text);
  color: var(--bg);
  font-size: 13px;
  box-shadow: var(--shadow);
}

/* ---------- narrow screens ---------- */

@media (max-width: 860px) {
  .workspace { grid-template-columns: 1fr; grid-template-rows: var(--split, 1fr) 6px 1fr; }
  .splitter { cursor: row-resize; }
  .topbar { flex-wrap: wrap; }
  .topbar__actions { flex-wrap: wrap; }
}
