:root {
  --navy: #0d1638;
  --ink: #14182b;
  --muted: #5a6178;
  --line: #dde2ee;
  --bg: #f4f6fb;
  --accent: #2a9d8f;
  --amber: #ffb703;
  --danger: #b42318;
  --r: 12px;
  font: 15px/1.5 system-ui, -apple-system, 'Segoe UI', sans-serif;
  color: var(--ink);
  background: var(--bg);
}
* { box-sizing: border-box; }
body { margin: 0; }
h1, h2, h3 { line-height: 1.2; }
.muted { color: var(--muted); }
[hidden] { display: none !important; }
:focus-visible { outline: 3px solid var(--amber); outline-offset: 2px; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 40px; padding: 0 14px; border-radius: 10px; border: 1px solid transparent;
  font: 600 14px/1 inherit; font-family: inherit; color: inherit; background: rgba(255, 255, 255, 0.12);
  text-decoration: none; cursor: pointer; white-space: nowrap;
}
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn--primary { background: var(--navy); color: #fff; }
.btn--accent { background: var(--accent); color: #fff; }
.btn--ghost { background: #fff; border-color: var(--line); color: var(--ink); }
.btn--ghost:hover { background: #eef1f8; }

/* login */
.login { min-height: 100vh; display: grid; place-items: center; padding: 16px; background: var(--navy); }
.login__card { width: min(400px, 100%); background: #fff; border-radius: 18px; padding: 32px; box-shadow: 0 30px 80px rgba(0, 0, 0, 0.35); }
.login__card h1 { margin: 0 0 4px; font-size: 24px; }
.login__card form { display: grid; gap: 8px; margin-top: 24px; }
.login__card label { font-weight: 600; }
.login__card .btn { margin-top: 8px; }
input[type='text'], input[type='password'], input[type='number'], input[type='search'], textarea {
  width: 100%; font: inherit; color: var(--ink); background: #fff;
  border: 1.5px solid #c5cbdb; border-radius: 10px; padding: 9px 11px; min-height: 42px;
}
textarea { resize: vertical; line-height: 1.5; min-height: 80px; overflow: hidden; }
input:disabled, textarea:disabled { background: #f0f2f7; color: var(--muted); }
.error { color: var(--danger); margin: 0; }

/* app shell */
.top {
  position: sticky; top: 0; z-index: 5; display: flex; align-items: center; gap: 8px; flex-wrap: wrap;
  padding: 10px 16px; background: var(--navy); color: #fff;
}
.top__brand { margin-right: auto; font-size: 16px; }
.top__brand span { color: var(--amber); }
.status { font-size: 13px; opacity: 0.9; margin-right: 8px; }
.status--err { color: #ffb4a8; opacity: 1; }
.layout { display: grid; grid-template-columns: 260px 1fr; min-height: calc(100vh - 60px); }
.files { border-right: 1px solid var(--line); background: #fff; padding: 16px 12px; position: sticky; top: 60px; align-self: start; max-height: calc(100vh - 60px); overflow: auto; }
.files h2 { font-size: 12px; text-transform: uppercase; letter-spacing: 0.08em; color: var(--muted); margin: 16px 8px 6px; }
.files h2:first-child { margin-top: 0; }
.files ul { list-style: none; margin: 0; padding: 0; }
.files a { display: block; padding: 8px 10px; border-radius: 8px; color: var(--ink); text-decoration: none; }
.files a:hover { background: var(--bg); }
.files a[aria-current] { background: var(--navy); color: #fff; }
.main { padding: 24px clamp(16px, 3vw, 40px) 80px; max-width: 980px; width: 100%; }
.empty { background: #fff; border: 1px solid var(--line); border-radius: var(--r); padding: 28px; }
.empty h1 { margin-top: 0; }

.toolbar { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-bottom: 16px; position: sticky; top: 60px; z-index: 4; background: var(--bg); padding: 10px 0; }
.toolbar h1 { font-size: 22px; margin: 0 auto 0 0; }
.toolbar input[type='search'] { width: min(280px, 100%); }

.alert { background: #fff4f2; border: 1px solid #f3c2bb; color: var(--danger); border-radius: var(--r); padding: 12px 16px; margin-bottom: 16px; }
.alert ul { margin: 6px 0 0; padding-left: 18px; }

.form { display: grid; gap: 14px; }
.root, .obj { display: grid; gap: 14px; }
.group { border: 1px solid var(--line); border-radius: var(--r); background: #fff; padding: 14px 16px 16px; margin: 0; display: grid; gap: 14px; }
.group legend { font-weight: 700; padding: 0 6px; }
.group--locked { background: #f7f8fb; }
.group .group { background: #fbfcfe; }
.field { display: grid; gap: 4px; }
.field label { font-weight: 600; font-size: 14px; display: flex; justify-content: space-between; gap: 8px; }
.field--check { display: flex; align-items: center; gap: 8px; }
.field--check input { width: 20px; height: 20px; }
.field--error input, .field--error textarea { border-color: var(--danger); background: #fff8f7; }
.counter { font-weight: 400; color: var(--muted); font-size: 12px; }
.hint { margin: 0; font-size: 12px; color: var(--muted); }

.array { display: grid; gap: 8px; }
.array h3 { font-size: 15px; margin: 4px 0 0; }
.item { background: #fff; border: 1px solid var(--line); border-radius: var(--r); }
details.item > summary { display: flex; align-items: center; gap: 8px; padding: 8px 10px 8px 14px; cursor: pointer; list-style: none; font-weight: 600; min-height: 48px; }
details.item > summary::-webkit-details-marker { display: none; }
details.item > summary::before { content: '▸'; color: var(--muted); transition: transform 0.15s; }
details.item[open] > summary::before { transform: rotate(90deg); }
details.item > summary > span { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
details.item > .obj, details.item > .group { padding: 4px 14px 16px; border: 0; }
.item--leaf { display: flex; gap: 8px; align-items: end; padding: 8px 10px; }
.item--leaf .field { flex: 1; }
.item__ctl { display: flex; gap: 4px; }
.icon { width: 36px; height: 36px; border-radius: 8px; border: 1px solid var(--line); background: #fff; cursor: pointer; font-size: 15px; color: var(--ink); }
.icon:hover:not(:disabled) { background: #eef1f8; }
.icon:disabled { opacity: 0.35; cursor: default; }
.icon--danger:hover:not(:disabled) { background: #fff0ee; color: var(--danger); }
.add { justify-self: start; }

dialog { border: 0; border-radius: 16px; padding: 0; width: min(620px, calc(100vw - 24px)); box-shadow: 0 30px 80px rgba(13, 22, 56, 0.4); }
dialog::backdrop { background: rgba(13, 22, 56, 0.45); }
.dlg__head { display: flex; align-items: center; gap: 12px; padding: 16px 20px; border-bottom: 1px solid var(--line); }
.dlg__head h2 { margin: 0; font-size: 18px; flex: 1; }
#dlg-body { padding: 16px 20px 20px; max-height: 70vh; overflow: auto; }
.list { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px; }
.list li { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 8px 10px; border: 1px solid var(--line); border-radius: 10px; }
.badge { background: var(--accent); color: #fff; border-radius: 99px; padding: 4px 10px; font-size: 12px; }
.log { white-space: pre-wrap; font: 12px/1.45 ui-monospace, Menlo, monospace; background: #0f1430; color: #e8ebf6; padding: 12px; border-radius: 10px; max-height: 50vh; overflow: auto; }

@media (max-width: 760px) {
  .layout { grid-template-columns: 1fr; }
  .files { position: static; max-height: none; border-right: 0; border-bottom: 1px solid var(--line); }
  .toolbar { top: 0; position: static; }
  .top { position: static; }
}
@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation: none !important; }
}
