:root {
  --bg: #f6f7f9;
  --panel: #ffffff;
  --panel-2: #fbfcfd;
  --border: #d9dee7;
  --border-soft: #e8ebf0;
  --text: #1f2328;
  --muted: #626b78;
  --muted-2: #8992a0;
  --accent: #1668dc;
  --accent-2: #0b57d0;
  --selected: #e7f0ff;
  --selected-text: #0b57d0;
  --hover: #eef2f7;
  --danger: #c62828;
  --danger-bg: #fde8e8;
  --ok: #188038;
  --string: #9b2c2c;
  --number: #0b57d0;
  --boolean: #b15c00;
  --null: #68717d;
  --key: #1f2328;
  --map-array: #177245;
  --font: "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --mono: "Cascadia Code", "Roboto Mono", Consolas, monospace;
  --col-1: minmax(210px, 1fr);
  --col-2: minmax(240px, 1fr);
  --col-3: minmax(320px, 1.5fr);
}

:root.dark {
  color-scheme: dark;
  --bg: #101317;
  --panel: #171b21;
  --panel-2: #1d222a;
  --border: #303744;
  --border-soft: #28303a;
  --text: #edf1f7;
  --muted: #a9b2c0;
  --muted-2: #768293;
  --accent: #8ab4f8;
  --accent-2: #aecbfa;
  --selected: #203a60;
  --selected-text: #d2e3fc;
  --hover: #222933;
  --danger: #ff8a80;
  --danger-bg: #3b2024;
  --ok: #81c995;
  --string: #f2a7a7;
  --number: #9fc4ff;
  --boolean: #ffca7a;
  --null: #a9b2c0;
  --key: #edf1f7;
  --map-array: #91d7a9;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  height: 100%;
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 13px;
  overflow: hidden;
}

button,
input,
textarea {
  font: inherit;
}

.topbar {
  height: 52px;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 0 14px;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
}

.home-button,
.icon-button,
.text-button {
  appearance: none;
  border: 0;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: inherit;
}

.home-button,
.icon-button {
  width: 34px;
  height: 34px;
  border-radius: 6px;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  flex: 0 0 auto;
}

.home-button:hover,
.icon-button:hover {
  background: var(--hover);
  color: var(--text);
}

.icon-button:disabled,
.text-button:disabled {
  opacity: 0.45;
  cursor: default;
}

.icon-button:disabled:hover,
.text-button:disabled:hover {
  background: transparent;
}

.icon-button.danger {
  color: var(--danger);
}

.icon-button.muted {
  cursor: default;
}

.text-button {
  gap: 7px;
  min-height: 32px;
  padding: 0 10px;
  border-radius: 6px;
  background: transparent;
  color: var(--accent);
  font-weight: 600;
  cursor: pointer;
}

.text-button:hover {
  background: var(--selected);
  color: var(--accent-2);
}

.text-button.primary {
  background: var(--accent);
  color: #fff;
}

.text-button.primary:hover {
  background: var(--accent-2);
  color: #fff;
}

.crumbs {
  display: flex;
  align-items: center;
  gap: 6px;
  min-width: 0;
  white-space: nowrap;
  color: var(--muted);
}

.crumbs a {
  color: var(--accent);
  text-decoration: none;
  cursor: pointer;
  max-width: 220px;
  overflow: hidden;
  text-overflow: ellipsis;
}

.crumbs a:hover {
  text-decoration: underline;
}

.crumbs .current {
  color: var(--text);
  font-weight: 600;
}

.sep {
  color: var(--muted-2);
}

.topbar-spacer {
  flex: 1;
}

.search-box {
  width: min(360px, 34vw);
  min-width: 190px;
  height: 34px;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 0 11px;
  border: 1px solid var(--border);
  border-radius: 7px;
  background: var(--panel-2);
  color: var(--muted);
}

.search-box:focus-within {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 18%, transparent);
}

.search-box input {
  width: 100%;
  min-width: 0;
  border: 0;
  outline: 0;
  background: transparent;
  color: var(--text);
}

.status {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--muted);
  font-size: 12px;
  white-space: nowrap;
}

.dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--ok);
}

.dot.off {
  background: var(--danger);
}

.console-grid {
  display: grid;
  grid-template-columns: var(--col-1) 6px var(--col-2) 6px var(--col-3);
  height: calc(100vh - 52px - 30px);
  min-height: 0;
}

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

.column-head {
  height: 50px;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 0 12px 0 16px;
  border-bottom: 1px solid var(--border-soft);
  flex: 0 0 auto;
}

.column-title {
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 9px;
  font-weight: 650;
}

.column-title span {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.column-title i {
  color: var(--muted);
}

.head-actions {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 2px;
}

.column-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  padding: 6px 12px 9px;
  border-bottom: 1px solid var(--border-soft);
  flex: 0 0 auto;
}

.column-body {
  flex: 1;
  min-height: 0;
  overflow: auto;
}

.resizer {
  cursor: col-resize;
  background: linear-gradient(to right, transparent 0 2px, var(--border) 2px 4px, transparent 4px 6px);
}

.resizer:hover,
.resizer.dragging {
  background: var(--accent);
}

.list-row {
  display: flex;
  align-items: center;
  gap: 9px;
  min-height: 40px;
  padding: 8px 14px;
  cursor: pointer;
  border-left: 3px solid transparent;
  user-select: none;
}

.list-row:hover {
  background: var(--hover);
}

.list-row.active {
  background: var(--selected);
  border-left-color: var(--accent);
  color: var(--selected-text);
  font-weight: 650;
}

.list-row .label {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-family: var(--mono);
  font-size: 12.5px;
}

.list-row .meta {
  color: var(--muted-2);
  font-size: 11px;
  max-width: 44%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.list-row .chev {
  color: var(--muted-2);
  flex: 0 0 auto;
}

.fields {
  padding: 4px 0 22px;
}

.field {
  display: grid;
  grid-template-columns: minmax(110px, 36%) 1fr auto;
  gap: 8px 12px;
  padding: 8px 16px;
  align-items: start;
  line-height: 1.45;
}

.field:hover {
  background: var(--hover);
}

.field.clickable {
  cursor: pointer;
}

.field.clickable:hover .field-key {
  color: var(--accent);
}

.field-key,
.field-value {
  font-family: var(--mono);
  font-size: 12.5px;
}

.field-key {
  color: var(--key);
  word-break: break-all;
}

.field-key::after {
  content: ":";
  color: var(--muted-2);
  margin-left: 1px;
}

.field-value {
  word-break: break-word;
  white-space: pre-wrap;
}

.field-value.string {
  color: var(--string);
}

.field-value.number {
  color: var(--number);
}

.field-value.boolean {
  color: var(--boolean);
}

.field-value.null {
  color: var(--null);
  font-style: italic;
}

.field-value.map,
.field-value.array {
  color: var(--map-array);
  font-style: italic;
}

.field-open {
  color: var(--muted-2);
}

.empty-state {
  padding: 34px 20px;
  color: var(--muted);
  text-align: center;
  line-height: 1.5;
}

.empty-state strong {
  display: block;
  color: var(--text);
  margin-bottom: 6px;
  font-weight: 650;
}

.error {
  display: none;
  margin: 12px;
  padding: 10px 12px;
  border: 1px solid color-mix(in srgb, var(--danger) 30%, transparent);
  background: var(--danger-bg);
  color: var(--danger);
  border-radius: 6px;
  font-size: 12px;
}

.error.show {
  display: block;
}

.footer {
  height: 30px;
  display: flex;
  align-items: center;
  gap: 18px;
  padding: 0 16px;
  background: var(--panel);
  border-top: 1px solid var(--border);
  color: var(--muted-2);
  font-size: 11px;
}

.context-menu[hidden] {
  display: none;
}

.context-menu {
  position: fixed;
  z-index: 30;
  min-width: 132px;
  padding: 5px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 7px;
  box-shadow: 0 16px 48px rgba(0, 0, 0, 0.22);
}

.context-menu button {
  width: 100%;
  min-height: 32px;
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 0 10px;
  border: 0;
  border-radius: 5px;
  background: transparent;
  color: var(--text);
  text-align: left;
  cursor: pointer;
}

.context-menu button:hover {
  background: var(--hover);
}

.context-menu button.danger {
  color: var(--danger);
}

.modal[hidden] {
  display: none;
}

.modal {
  position: fixed;
  inset: 0;
  z-index: 20;
}

.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.44);
}

.modal-panel {
  position: absolute;
  inset: 6vh 5vw;
  min-width: 0;
  min-height: 0;
  display: flex;
  flex-direction: column;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: 0 24px 80px rgba(0, 0, 0, 0.28);
}

.modal-head {
  min-height: 64px;
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 12px 14px 12px 18px;
  border-bottom: 1px solid var(--border);
}

.modal-head h1 {
  margin: 0;
  font-size: 16px;
  line-height: 1.3;
}

.modal-head p {
  margin: 3px 0 0;
  color: var(--muted);
  font-family: var(--mono);
  font-size: 12px;
}

.modal-actions {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 8px;
}

.json-viewer,
.json-editor {
  flex: 1;
  min-height: 0;
  margin: 0;
  padding: 16px 18px;
  border: 0;
  outline: 0;
  overflow: auto;
  background: var(--panel-2);
  color: var(--text);
  font-family: var(--mono);
  font-size: 12.5px;
  line-height: 1.55;
  resize: none;
  tab-size: 2;
}

.json-editor[hidden],
.json-viewer[hidden] {
  display: none;
}

.modal-foot {
  min-height: 34px;
  padding: 8px 18px;
  border-top: 1px solid var(--border);
  color: var(--muted);
  font-size: 12px;
}

.modal-foot.error-text {
  color: var(--danger);
}

@media (max-width: 860px) {
  body {
    overflow: auto;
  }

  .topbar {
    height: auto;
    min-height: 52px;
    flex-wrap: wrap;
    padding: 9px 10px;
  }

  .topbar-spacer {
    display: none;
  }

  .search-box {
    order: 2;
    width: 100%;
  }

  .console-grid {
    grid-template-columns: 1fr;
    height: auto;
  }

  .resizer {
    display: none;
  }

  .column {
    min-height: 260px;
    max-height: 44vh;
    border-bottom: 1px solid var(--border);
  }

  .column:last-child {
    max-height: none;
  }

  .modal-panel {
    inset: 2vh 2vw;
  }
}
