:root {
  --drawer-w: min(440px, 42vw);
  --bg: #10141a;
  --panel: #171c23;
  --line: #2a3340;
  --text: #e8eef6;
  --muted: #8b95a5;
  --accent: #4aa3f0;
  --accent-2: #2f7ec4;
  --ok: #3ecf8e;
  --err: #e36d76;
  --hover: #243044;
  --sel: #1d3654;
  --font: "Segoe UI", system-ui, sans-serif;
  --mono: ui-monospace, "SFMono-Regular", Menlo, Consolas, monospace;
}

* { box-sizing: border-box; }

[hidden] { display: none !important; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font: 13px/1.4 var(--font);
}

button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--accent); }

.login-wrap {
  min-height: 100%;
  display: grid;
  place-items: center;
  padding: 24px;
}

.login-card {
  width: min(400px, 100%);
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 22px;
}

.login-card h1 { margin: 0 0 6px; font-size: 22px; }
.eyebrow { margin: 0 0 4px; color: var(--accent); font-size: 11px; text-transform: uppercase; letter-spacing: 0.06em; }
.lead, .muted, .hint, .count { color: var(--muted); }
.lead { margin: 0 0 14px; }

.stack { display: grid; gap: 10px; }
.stack label { display: grid; gap: 4px; color: var(--muted); font-size: 12px; }

input, select, textarea {
  width: 100%;
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 7px 9px;
}
textarea { font-family: var(--mono); resize: vertical; }

.btn {
  border: 1px solid var(--line);
  background: #1e242d;
  border-radius: 6px;
  padding: 7px 11px;
  cursor: pointer;
  white-space: nowrap;
}
.btn:hover { border-color: var(--accent-2); }
.btn.primary { background: var(--accent-2); border-color: var(--accent-2); color: #fff; }
.btn.ghost { background: transparent; width: 100%; }
.btn:disabled { opacity: 0.4; cursor: default; }
a.btn { text-decoration: none; display: inline-block; color: inherit; }
.pult-bar { flex-wrap: wrap; }
.pult-bar input { width: auto; flex: 1 1 140px; }
.pult-bar input[type="number"] { flex: 0 0 88px; }
.pult-summary { border-collapse: collapse; margin: 8px 12px 24px; }
.pult-summary td { border-bottom: 1px solid var(--line); padding: 6px 12px; }
.pult-summary td:first-child { color: var(--muted); }

.error { color: var(--err); margin: 0; }
.more { margin-top: 14px; }
.more summary { cursor: pointer; color: var(--muted); font-size: 12px; }
.bookmarklet {
  display: inline-block;
  margin: 8px 0;
  padding: 6px 10px;
  border: 1px dashed var(--accent);
  border-radius: 6px;
  text-decoration: none;
}

.app {
  display: flex;
  height: 100%;
}

.sidebar {
  width: 188px;
  flex-shrink: 0;
  background: var(--panel);
  border-right: 1px solid var(--line);
  padding: 14px 10px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}
.brand strong { display: block; font-size: 15px; }
.sidebar nav { display: grid; gap: 2px; flex: 1; align-content: start; }
.sidebar nav button {
  text-align: left;
  background: transparent;
  border: 0;
  color: var(--muted);
  padding: 7px 10px;
  border-radius: 6px;
  cursor: pointer;
}
.sidebar nav button:hover,
.sidebar nav button.active { background: #1e242d; color: var(--text); }

.stage {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
}

.view {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
}

.toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
  padding: 10px 12px;
  flex-shrink: 0;
}
.toolbar.stacked { flex-direction: column; align-items: stretch; }
.toolbar .bar { display: flex; gap: 8px; align-items: center; }
.toolbar .bar > input,
.toolbar .bar > select { flex: 1; min-width: 0; }
.toolbar > input[type="search"] { flex: 1; min-width: 140px; }
#req-method, #preset-select { width: auto; flex: 0 0 auto; }
#preset-select { min-width: 170px; }

.seg {
  display: flex;
  border: 1px solid var(--line);
  border-radius: 6px;
  overflow: hidden;
  flex-shrink: 0;
}
.seg button {
  background: transparent;
  border: 0;
  color: var(--muted);
  padding: 6px 10px;
  cursor: pointer;
}
.seg button.active { background: var(--accent-2); color: #fff; }

.crumbs {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  align-items: center;
  margin: 0;
  min-width: 0;
  flex: 1;
  font-size: 12px;
  color: var(--muted);
}
.crumbs button {
  background: none;
  border: 0;
  color: var(--accent);
  cursor: pointer;
  padding: 0;
  font: inherit;
}
#org-crumbs {
  flex-wrap: nowrap;
  overflow: hidden;
}
#org-crumbs > span:last-child {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.count { font-size: 12px; white-space: nowrap; }

.table-host {
  flex: 1;
  min-height: 0;
  overflow: auto;
  border-top: 1px solid var(--line);
}

table {
  width: 100%;
  border-collapse: collapse;
  table-layout: fixed;
}
table.data {
  width: max-content;
}
th, td {
  text-align: left;
  padding: 6px 10px;
  border-bottom: 1px solid var(--line);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
thead {
  position: sticky;
  top: 0;
  z-index: 3;
  background: var(--panel);
}
th {
  color: var(--muted);
  font-weight: 600;
  position: relative;
  background: var(--panel);
}
.th-label {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
}
.col-resizer {
  position: absolute;
  right: 0;
  top: 0;
  bottom: 0;
  width: 7px;
  cursor: col-resize;
  z-index: 2;
}
.col-resizer:hover {
  background: var(--accent);
  opacity: 0.4;
}
body.col-resizing,
body.col-resizing * {
  cursor: col-resize !important;
  user-select: none !important;
}
tr.head-filters th {
  font-weight: 400;
  padding: 4px 8px 6px;
}
tr.head-filters input {
  padding: 4px 6px;
  font-size: 12px;
}
td.empty-row {
  color: var(--muted);
  text-align: center;
  padding: 20px 10px;
  white-space: normal;
}
tr.clickable { cursor: pointer; }
tr.clickable:hover { background: var(--hover); }
tr.selected { background: var(--sel); }
.id { font-family: var(--mono); font-size: 11px; color: var(--muted); }
.kind { color: var(--muted); font-size: 12px; }

.empty, .status {
  color: var(--muted);
  margin: 0;
  padding: 28px 16px;
}

.drawer {
  position: relative;
  flex: 0 0 var(--drawer-w);
  width: var(--drawer-w);
  min-width: 280px;
  align-self: stretch;
  background: var(--panel);
  border-left: 1px solid var(--line);
  z-index: 30;
  display: flex;
  flex-direction: column;
  min-height: 0;
}
.drawer-resizer {
  position: absolute;
  left: 0;
  top: 0;
  bottom: 0;
  width: 8px;
  margin-left: -4px;
  cursor: col-resize;
  z-index: 4;
  touch-action: none;
}
.drawer-resizer:hover,
body.drawer-resizing .drawer-resizer {
  background: var(--accent);
}
body.drawer-resizing {
  cursor: col-resize;
  user-select: none;
}
body.drawer-resizing iframe,
body.drawer-resizing img {
  pointer-events: none;
}
.drawer header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 10px 12px;
  border-bottom: 1px solid var(--line);
}
.drawer h2 {
  margin: 0;
  font-size: 14px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.icon-btn {
  background: transparent;
  border: 0;
  color: var(--muted);
  font-size: 20px;
  cursor: pointer;
  line-height: 1;
}
.drawer-tabs {
  margin: 8px 12px 0;
}
.drawer-tabs button { flex: 1; }

.drawer-info {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.fields {
  padding: 8px 12px;
  display: grid;
  grid-template-columns: 1fr;
  gap: 6px 16px;
  overflow: auto;
  flex: 0 1 auto;
}

.drawer-preview {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  background: #0c0f13;
}
.drawer-preview .status {
  padding: 16px 12px;
}
.drawer-preview iframe,
.drawer-preview img {
  flex: 1;
  width: 100%;
  min-height: 0;
  border: 0;
  background: #fff;
}
.drawer-preview img {
  object-fit: contain;
  background: #0c0f13;
}
.field {
  display: grid;
  grid-template-columns: 92px 1fr auto;
  gap: 6px;
  align-items: start;
  min-width: 0;
}
.lbl { color: var(--muted); font-size: 11px; }
.val {
  white-space: pre-wrap;
  word-break: break-word;
}
.chip {
  display: inline-flex;
  align-items: center;
  width: max-content;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 12px;
  line-height: 1.4;
  border: 1px solid var(--line);
  color: var(--muted);
}
.chip-ok {
  border-color: var(--ok);
  color: var(--ok);
  background: rgba(62, 207, 142, 0.12);
}
.copy {
  background: none;
  border: 0;
  color: var(--accent);
  cursor: pointer;
  font-size: 11px;
  padding: 0;
}
.drawer-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  padding: 10px 12px;
  border-top: 1px solid var(--line);
}
.jtree {
  flex: 1;
  min-height: 0;
  overflow: auto;
  padding: 8px 10px 16px;
  background: #0c0f13;
  border-top: 1px solid var(--line);
  font-family: var(--mono);
  font-size: 12px;
  line-height: 1.45;
}
.jnode { min-width: 0; }
.jhead {
  display: flex;
  align-items: flex-start;
  gap: 6px;
  padding: 1px 0;
  cursor: pointer;
  min-width: 0;
}
.jhead:hover { background: #18202a; }
.jtog {
  flex: 0 0 14px;
  width: 14px;
  background: none;
  border: 0;
  color: var(--muted);
  padding: 0;
  cursor: pointer;
  font-size: 11px;
  line-height: 1;
}
.jkey { color: #9cdcfe; flex-shrink: 0; }
.jkey::after { content: ':'; color: var(--muted); }
.jval {
  min-width: 0;
  flex: 1;
  white-space: pre-wrap;
  word-break: break-word;
}
.j-string { color: #ce9178; }
.j-number { color: #b5cea8; }
.j-boolean { color: #569cd6; }
.j-null { color: #808080; }
.j-muted { color: var(--muted); }
.jkids { margin-left: 14px; border-left: 1px solid #2a3340; padding-left: 8px; }
.jempty { color: var(--muted); padding: 2px 0; }

.toast {
  position: fixed;
  right: 16px;
  top: 16px;
  background: #1a222c;
  border: 1px solid var(--line);
  padding: 8px 12px;
  border-radius: 8px;
  z-index: 40;
}
.toast.ok { border-color: var(--ok); }
.toast.err { border-color: var(--err); }

.org-card {
  padding: 16px 18px 24px;
  max-width: 880px;
}
.org-card h2 {
  margin: 0 0 14px;
  font-size: 18px;
  font-weight: 650;
}
.org-card-fields {
  padding: 0;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  max-height: none;
}
.org-card-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 16px;
}

@media (max-width: 800px) {
  .app { flex-direction: column; }
  .sidebar { width: 100%; flex-direction: row; align-items: center; border-right: 0; border-bottom: 1px solid var(--line); }
  .sidebar nav { display: flex; flex: 1; }
  .btn.ghost { width: auto; }
  .drawer {
    position: fixed;
    top: 0;
    right: 0;
    bottom: 0;
    left: auto;
    width: min(100%, 420px);
    flex: none;
  }
}
