:root {
  --base: #1e1e2e;
  --mantle: #181825;
  --crust: #11111b;
  --surface0: #313244;
  --surface1: #45475a;
  --surface2: #585b70;
  --overlay0: #6c7086;
  --overlay1: #7f849c;
  --text: #cdd6f4;
  --subtext0: #a6adc8;
  --subtext1: #bac2de;
  --lavender: #b4befe;
  --blue: #89b4fa;
  --green: #a6e3a1;
  --yellow: #f9e2af;
  --red: #f38ba8;
  --peach: #fab387;
  --mauve: #cba6f7;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  height: 100%;
  background: var(--base);
  color: var(--text);
  font: 13px system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

body {
  display: flex;
  flex-direction: column;
}

header,
footer {
  padding: 10px 14px;
  background: var(--mantle);
  border-color: var(--surface0);
  border-style: solid;
}

header {
  border-width: 0 0 1px;
  display: flex;
  align-items: center;
  gap: 16px;
  flex-wrap: wrap;
}

footer {
  border-width: 1px 0 0;
  color: var(--subtext0);
  font-size: 12px;
}

h1 {
  margin: 0;
  font-size: 14px;
}

.subtitle {
  color: var(--overlay1);
  font-weight: 400;
}

.toolbar {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

button,
.file-button {
  padding: 5px 14px;
  font: inherit;
  cursor: pointer;
  background: var(--surface0);
  color: var(--text);
  border: 1px solid var(--surface1);
  border-radius: 6px;
  transition: background 0.1s;
}

button:hover:not(:disabled),
.file-button:hover {
  background: var(--surface1);
}

button:disabled {
  color: var(--overlay0);
  cursor: default;
}

.file-button input {
  display: none;
}

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

.tabs {
  display: flex;
  gap: 4px;
  padding: 8px 8px 0;
  background: var(--mantle);
  border-bottom: 1px solid var(--surface0);
  overflow-x: auto;
}

.tab {
  padding: 7px 14px;
  border: 1px solid var(--surface0);
  border-bottom: none;
  border-radius: 6px 6px 0 0;
  background: var(--mantle);
  color: var(--subtext0);
  cursor: pointer;
  white-space: nowrap;
  font: inherit;
}

.tab:hover {
  color: var(--text);
}

.tab.active {
  background: var(--base);
  color: var(--text);
  border-bottom: 1px solid var(--base);
  margin-bottom: -1px;
}

.tab .badge {
  margin-left: 6px;
  padding: 1px 6px;
  border-radius: 10px;
  background: var(--surface0);
  color: var(--overlay1);
  font-size: 10px;
}

.tab-content {
  flex: 1;
  min-height: 0;
  overflow: auto;
  padding: 12px;
}

.tab-panel {
  display: none;
  height: 100%;
}

.tab-panel.active {
  display: block;
}

.form-pane {
  padding: 8px;
  max-width: 700px;
}

.form-row {
  margin-bottom: 16px;
}

.form-row label {
  display: block;
  color: var(--subtext0);
  margin-bottom: 5px;
  font-size: 12px;
}

input[type="text"],
input[type="number"],
select {
  width: 100%;
  max-width: 420px;
  padding: 7px 10px;
  font: inherit;
  background: var(--mantle);
  color: var(--text);
  border: 1px solid var(--surface1);
  border-radius: 6px;
  outline: none;
}

input:focus,
select:focus {
  border-color: var(--mauve);
}

input:invalid {
  border-color: var(--red);
}

button.form-action {
  margin-top: 4px;
}

.section-title {
  font-weight: 600;
  margin: 20px 0 10px;
  padding-bottom: 4px;
  border-bottom: 1px solid var(--surface0);
}

.checkbox-stack {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.checkbox-row {
  display: flex;
  align-items: center;
  gap: 8px;
}

.checkbox-row input[type="checkbox"] {
  width: 16px;
  height: 16px;
  accent-color: var(--mauve);
  cursor: pointer;
}

.checkbox-row label {
  color: var(--text);
  cursor: pointer;
}

.checksum-line {
  display: flex;
  gap: 16px;
  flex-wrap: wrap;
  margin-bottom: 14px;
  padding: 8px 10px;
  border: 1px solid var(--surface0);
  border-radius: 6px;
  background: var(--mantle);
}

.checksum-line .ok {
  color: var(--green);
  font-weight: 600;
}

.checksum-line .bad {
  color: var(--red);
  font-weight: 600;
}

.panel-split {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  height: 100%;
  min-height: 300px;
}

@media (max-width: 700px) {
  .panel-split {
    grid-template-columns: 1fr;
    grid-template-rows: 1fr 1fr;
  }
}

.tree-pane,
.detail-pane,
.hex-pane {
  border: 1px solid var(--surface0);
  border-radius: 6px;
  overflow: auto;
}

.tree-pane {
  padding: 4px 0;
}

.tree,
.tree ul {
  list-style: none;
  margin: 0;
  padding: 0;
}

.tree ul {
  padding-left: 18px;
}

.tree-node {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 2px 8px;
  cursor: pointer;
  user-select: none;
}

.tree-node:hover {
  background: var(--surface0);
}

.tree-node.selected {
  background: var(--surface1);
}

.tree-toggle {
  width: 16px;
  text-align: center;
  color: var(--overlay1);
  cursor: pointer;
  font-size: 11px;
}

.tree-toggle.placeholder {
  visibility: hidden;
}

.node-icon {
  width: 16px;
  text-align: center;
  color: var(--overlay1);
  font-size: 11px;
}

.node-summary {
  color: var(--overlay1);
  font-size: 11px;
  margin-left: 6px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.node-kind {
  color: var(--mauve);
  font-size: 10px;
  margin-left: 6px;
  font-family: monospace;
}

.tree-more {
  padding: 2px 8px 2px 28px;
  color: var(--mauve);
  cursor: pointer;
  font-size: 11px;
}

.detail-pane {
  padding: 10px;
}

.detail-pane h4 {
  margin: 0 0 8px;
  font-size: 13px;
  color: var(--mauve);
}

.path-bar {
  font-family: monospace;
  font-size: 11px;
  color: var(--subtext0);
  word-break: break-all;
  margin-bottom: 10px;
  padding: 6px 8px;
  border: 1px solid var(--surface0);
  border-radius: 6px;
  background: var(--mantle);
}

.detail-body {
  white-space: pre-wrap;
  font-family: monospace;
  font-size: 11px;
  line-height: 1.5;
  max-height: 50vh;
  overflow: auto;
  border: 1px solid var(--surface0);
  border-radius: 6px;
  padding: 8px;
  background: var(--mantle);
}

.help-text {
  color: var(--subtext0);
  font-size: 11px;
  margin-top: 6px;
}

.error-text {
  color: var(--red);
  font-size: 11px;
  margin-top: 6px;
}

.hex-pane pre,
.schemas-pane pre {
  margin: 0;
  padding: 8px;
  font-family: monospace;
  font-size: 11px;
  line-height: 1.5;
  white-space: pre;
}

.drag-over {
  outline: 2px dashed var(--mauve);
  outline-offset: -4px;
}

.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
}

.modal-box {
  background: var(--mantle);
  border: 1px solid var(--surface0);
  border-radius: 8px;
  max-width: 90vw;
  max-height: 90vh;
  width: 800px;
  display: flex;
  flex-direction: column;
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 14px;
  border-bottom: 1px solid var(--surface0);
}

.modal-body {
  padding: 12px;
  overflow: auto;
  flex: 1;
}

.modal-close {
  background: none;
  border: none;
  color: var(--text);
  font-size: 20px;
  cursor: pointer;
}
