:root {
  color-scheme: light;
  --background: #f5f7f6;
  --surface: #ffffff;
  --surface-muted: #eef2f1;
  --text: #17232a;
  --muted: #647278;
  --line: #d8e0de;
  --accent: #0f766e;
  --accent-dark: #115e59;
  --danger: #b42318;
  --ok: #15803d;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--background);
  color: var(--text);
  font-family: Arial, Helvetica, sans-serif;
}

.app-shell {
  width: min(1600px, calc(100% - 2cm));
  margin: 0 auto;
  padding: 32px 0;
}

.hero {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 24px;
  padding: 12px 0 28px;
}

.eyebrow {
  margin: 0 0 8px;
  color: var(--accent-dark);
  font-size: 13px;
  font-weight: 700;
  text-transform: uppercase;
}

h1 {
  margin: 0;
  font-size: 42px;
  line-height: 1.05;
  letter-spacing: 0;
}

.project-access {
  display: grid;
  grid-template-columns: minmax(360px, 1fr) auto;
  align-items: end;
  gap: 14px;
  max-width: 760px;
  margin-top: 18px;
}

.config-grid,
.query-panel,
.result-panel,
.tree-card {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: 0 12px 30px rgba(15, 35, 45, 0.06);
}

.tree-card {
  margin-bottom: 18px;
  overflow: hidden;
  --tree-height: 420px;
}

.tree-header {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  border-bottom: 1px solid var(--line);
  padding: 10px 14px;
}

.tree-header strong {
  display: block;
  font-size: 18px;
}

.tree-header span {
  display: block;
  margin-top: 2px;
  color: var(--muted);
  font-size: 13px;
}

.tree-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
}

.tree-actions button {
  min-height: 36px;
  padding: 8px 12px;
}

.tree-empty {
  color: var(--muted);
  min-height: 160px;
  padding: 12px 14px;
}

.tree-view {
  height: var(--tree-height);
  min-height: 260px;
  max-height: min(82vh, 960px);
  overflow: auto;
  padding: 8px 12px 12px;
}

.tree-columns {
  display: grid;
  grid-template-columns: minmax(280px, 2.2fr) minmax(90px, 0.7fr) minmax(220px, 1.8fr) minmax(90px, 0.7fr) minmax(170px, 1.2fr);
  gap: 8px;
  width: 100%;
  align-items: start;
}

.tree-columns-header {
  position: sticky;
  top: -8px;
  z-index: 2;
  margin: -8px -12px 8px;
  padding: 8px 12px 8px 30px;
  border-bottom: 1px solid var(--line);
  background: var(--surface);
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.02em;
  text-transform: uppercase;
}

.tree-column {
  min-width: 0;
  overflow-wrap: anywhere;
}

.tree-column-description {
  font-weight: 700;
}

.tree-column-composition-summary {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  width: 100%;
  flex-wrap: wrap;
}

.tree-composition-name {
  min-width: 0;
  flex: 1 1 220px;
}

.tree-kardex-link {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 32px;
  padding: 6px 12px;
  border: 1px solid var(--accent);
  border-radius: 999px;
  background: var(--accent);
  color: #fff;
  font-size: 12px;
  font-weight: 700;
  line-height: 1;
  text-decoration: none;
  white-space: nowrap;
}

.tree-kardex-link:hover {
  background: var(--accent-dark);
  border-color: var(--accent-dark);
}

.tree-view details {
  border-left: 1px solid var(--line);
  margin-left: 8px;
  padding: 3px 0 3px 10px;
}

.tree-view > details {
  border-left: 0;
  margin-left: 0;
  padding-left: 0;
}

.tree-view details.tree-focus-highlight {
  border-left-color: var(--accent);
  background: rgba(15, 118, 110, 0.08);
  border-radius: 6px;
}

.tree-view summary {
  cursor: pointer;
  display: flex;
  align-items: flex-start;
  gap: 6px;
  line-height: 1.35;
  list-style: none;
}

.tree-view summary::-webkit-details-marker {
  display: none;
}

.tree-view summary::before {
  content: "▸";
  flex: 0 0 12px;
  color: var(--muted);
  line-height: 1.35;
}

.tree-view details[open] > summary::before {
  content: "▾";
}

.tree-view ul {
  margin: 4px 0 6px;
  padding-left: 14px;
}

.tree-view li {
  color: var(--muted);
  line-height: 1.4;
}

.tree-splitter {
  height: 14px;
  border-top: 1px solid var(--line);
  background:
    linear-gradient(to bottom, rgba(15, 118, 110, 0.08), rgba(15, 118, 110, 0.02)),
    var(--surface-muted);
  cursor: row-resize;
  touch-action: none;
}

.tree-splitter::before {
  content: "";
  display: block;
  width: 56px;
  height: 4px;
  margin: 5px auto;
  border-radius: 999px;
  background: rgba(100, 114, 120, 0.45);
}

.tree-card.is-resizing {
  user-select: none;
}

.config-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 16px;
  padding: 18px;
}

.query-panel {
  margin-top: 18px;
  padding: 18px;
}

.toolbar {
  display: grid;
  grid-template-columns: minmax(220px, 1fr) 120px 120px auto;
  align-items: end;
  gap: 14px;
}

label {
  display: grid;
  gap: 7px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

input {
  width: 100%;
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  color: var(--text);
  font: inherit;
  padding: 10px 12px;
}

select {
  width: 100%;
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  color: var(--text);
  font: inherit;
  padding: 8px;
}

select option {
  padding: 7px 8px;
}

input[readonly] {
  background: var(--surface-muted);
}

button {
  min-height: 42px;
  border: 1px solid transparent;
  border-radius: 6px;
  background: var(--accent);
  color: #fff;
  cursor: pointer;
  font: inherit;
  font-weight: 700;
  padding: 10px 16px;
}

button:hover {
  background: var(--accent-dark);
}

button:disabled,
button:disabled:hover {
  background: #9aa6aa;
  cursor: not-allowed;
}

.quick-actions {
  display: flex;
  flex-wrap: nowrap;
  gap: 1mm;
  margin-top: 14px;
  overflow-x: auto;
}

.quick-actions button {
  min-height: 34px;
  border-color: var(--line);
  background: var(--surface-muted);
  color: var(--text);
  padding: 7px 11px;
}

.quick-actions button:hover {
  border-color: var(--accent);
}

.result-panel {
  margin-top: 18px;
  overflow: hidden;
}

.result-header {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  border-bottom: 1px solid var(--line);
  padding: 14px 18px;
}

.result-header span {
  min-width: 0;
  overflow: hidden;
  color: var(--muted);
  text-overflow: ellipsis;
  white-space: nowrap;
}

pre {
  min-height: 360px;
  max-height: 560px;
  margin: 0;
  overflow: auto;
  background: #101820;
  color: #eefbf8;
  font-size: 13px;
  line-height: 1.55;
  padding: 18px;
}

@media (max-width: 820px) {
  .tree-columns,
  .tree-columns-header {
    grid-template-columns: 1fr;
  }

  .tree-columns-header {
    padding-left: 12px;
  }

  .tree-columns-header .tree-column {
    display: none;
  }

  .tree-column {
    display: grid;
    gap: 2px;
  }

  .tree-column-composition-summary {
    align-items: flex-start;
    justify-content: flex-start;
  }

  .tree-column::before {
    content: attr(data-header);
    color: var(--muted);
    font-size: 11px;
    font-weight: 700;
    letter-spacing: 0.02em;
    text-transform: uppercase;
  }

  .hero,
  .result-header,
  .tree-header {
    align-items: stretch;
    flex-direction: column;
  }

  .tree-actions {
    justify-content: flex-start;
  }

  .config-grid,
  .toolbar,
  .project-access {
    grid-template-columns: 1fr;
  }
}
