:root {
  --bg: #fff6f6;
  --panel: rgba(255, 255, 255, 0.9);
  --panel-strong: rgba(255, 252, 252, 0.98);
  --line: rgba(184, 19, 29, 0.12);
  --text: #2f1215;
  --muted: #7d4c50;
  --accent: #b8131d;
  --accent-strong: #8f0f17;
  --heat: #d4684f;
  --danger: #8f0f17;
  --shadow: 0 24px 80px rgba(184, 19, 29, 0.14);
  --radius: 24px;
}

* {
  box-sizing: border-box;
}

html, body {
  margin: 0;
  min-height: 100%;
  background:
    radial-gradient(circle at top left, rgba(255, 192, 194, 0.44), transparent 34%),
    radial-gradient(circle at 85% 10%, rgba(184, 19, 29, 0.16), transparent 28%),
    linear-gradient(160deg, #fff9f9 0%, #fff0f2 100%);
  color: var(--text);
  font-family: "Space Grotesk", "Helvetica Neue", sans-serif;
}

body {
  position: relative;
}

.ambient {
  position: fixed;
  inset: auto;
  border-radius: 999px;
  filter: blur(48px);
  opacity: 0.5;
  pointer-events: none;
}

.ambient-a {
  width: 18rem;
  height: 18rem;
  left: -4rem;
  top: 22rem;
  background: rgba(184, 19, 29, 0.18);
}

.ambient-b {
  width: 24rem;
  height: 24rem;
  right: -8rem;
  top: 6rem;
  background: rgba(255, 212, 214, 0.42);
}

.shell {
  position: relative;
  z-index: 1;
  width: min(1480px, calc(100vw - 32px));
  margin: 24px auto 40px;
  display: grid;
  gap: 18px;
}

.card {
  background: var(--panel);
  backdrop-filter: blur(14px);
  border: 1px solid rgba(184, 19, 29, 0.1);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.hero {
  padding: 28px 30px;
  display: grid;
  gap: 18px;
  grid-template-columns: minmax(0, 1.6fr) minmax(300px, 0.9fr);
  align-items: end;
  overflow: hidden;
}

.hero::after {
  content: "";
  position: absolute;
  width: 18rem;
  height: 18rem;
  right: -5rem;
  top: -7rem;
  border-radius: 50%;
  background: radial-gradient(circle, rgba(184, 19, 29, 0.18), rgba(184, 19, 29, 0) 62%);
}

.eyebrow {
  margin: 0 0 10px;
  font-family: "IBM Plex Mono", monospace;
  text-transform: uppercase;
  letter-spacing: 0.14em;
  font-size: 0.72rem;
  color: var(--accent);
}

h1, h2 {
  margin: 0;
}

h1 {
  font-size: clamp(2.4rem, 5vw, 4.2rem);
  line-height: 0.96;
  letter-spacing: -0.04em;
}

h2 {
  font-size: 1.1rem;
  letter-spacing: -0.03em;
}

.hero-copy,
.section-head p,
.muted-text,
.document-meta,
.jobs-meta,
.query-subline {
  margin: 0;
  color: var(--muted);
}

.hero-status {
  display: grid;
  gap: 14px;
}

.status-cluster {
  padding: 14px 16px;
  border-radius: 18px;
  background: linear-gradient(180deg, rgba(184, 19, 29, 0.94), rgba(124, 12, 20, 0.96));
  color: #fff8f8;
  border: 1px solid rgba(255, 216, 222, 0.14);
}

.status-label {
  display: block;
  font-family: "IBM Plex Mono", monospace;
  font-size: 0.72rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  opacity: 0.72;
  margin-bottom: 6px;
}

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

.workspace {
  display: grid;
  gap: 18px;
  grid-template-columns: 340px minmax(0, 1fr);
}

.sidebar,
.jobs-section,
.form-card,
.stack-card {
  padding: 22px;
}

.main-panel {
  min-width: 0;
}

.document-layout {
  display: grid;
  gap: 18px;
  grid-template-columns: minmax(0, 1.15fr) minmax(360px, 0.85fr);
  align-items: start;
}

.section-head {
  display: grid;
  gap: 4px;
  margin-bottom: 18px;
}

.section-head.inline {
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: start;
}

.stack-form,
.stack-card {
  display: grid;
  gap: 14px;
}

.grid {
  display: grid;
  gap: 12px;
}

.grid.two-up {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

label {
  display: grid;
  gap: 7px;
  color: var(--muted);
  font-size: 0.92rem;
}

.field-hint {
  margin: -4px 0 2px;
  color: var(--muted);
  font-size: 0.82rem;
}

input,
select,
textarea,
button {
  font: inherit;
}

input,
select,
textarea {
  width: 100%;
  border: 1px solid rgba(184, 19, 29, 0.14);
  border-radius: 16px;
  background: var(--panel-strong);
  color: var(--text);
  padding: 13px 15px;
  outline: none;
  transition: border-color 120ms ease, transform 120ms ease, box-shadow 120ms ease;
}

input:focus,
select:focus,
textarea:focus {
  border-color: rgba(184, 19, 29, 0.45);
  box-shadow: 0 0 0 4px rgba(184, 19, 29, 0.12);
}

textarea {
  resize: vertical;
}

button {
  cursor: pointer;
  border: 0;
  border-radius: 999px;
  padding: 12px 18px;
  transition: transform 120ms ease, opacity 120ms ease, box-shadow 120ms ease;
}

button:hover {
  transform: translateY(-1px);
}

button:disabled {
  opacity: 0.55;
  cursor: not-allowed;
  transform: none;
}

.primary-btn {
  background: linear-gradient(135deg, #d11a25 0%, #8f0f17 100%);
  color: #fffafa;
  box-shadow: 0 12px 28px rgba(184, 19, 29, 0.28);
}

.secondary-btn,
.ghost-btn,
.danger-btn {
  background: rgba(255, 252, 252, 0.96);
  color: var(--text);
  border: 1px solid rgba(184, 19, 29, 0.12);
}

.danger-btn {
  color: var(--danger);
}

.ghost-btn {
  padding-inline: 14px;
}

.details-panel {
  border: 1px solid var(--line);
  border-radius: 18px;
  padding: 14px;
  background: rgba(255, 247, 248, 0.72);
}

.details-panel summary {
  cursor: pointer;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 14px;
}

.jobs-list,
.documents-list,
.structure-tree {
  display: grid;
  gap: 12px;
}

.documents-list {
  position: relative;
  overflow: visible;
  isolation: isolate;
}

.structure-card,
.inspector-card {
  padding: 22px;
  overflow: hidden;
}

.structure-card {
  min-height: 74vh;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  position: sticky;
  top: 18px;
}

.structure-head {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 16px;
  align-items: start;
  margin-bottom: 18px;
}

.structure-doc {
  min-width: 0;
  display: grid;
  gap: 6px;
}

.panel-kicker {
  margin: 0;
  font-family: "IBM Plex Mono", monospace;
  font-size: 0.72rem;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--accent);
}

.structure-actions {
  display: grid;
  gap: 10px;
  justify-items: end;
}

.structure-tree {
  min-height: 0;
  max-height: calc(74vh - 64px);
  overflow: auto;
  padding-right: 4px;
}

.inspector-card {
  min-height: 74vh;
  display: grid;
  grid-template-rows: auto auto minmax(0, 1fr);
  position: sticky;
  top: 18px;
}

.inspector-tabs {
  display: inline-flex;
  gap: 8px;
  padding: 6px;
  margin-bottom: 14px;
  background: rgba(255, 243, 245, 0.95);
  border: 1px solid rgba(184, 19, 29, 0.08);
  border-radius: 999px;
}

.tab-btn {
  background: transparent;
  color: var(--muted);
  border: 0;
  padding: 10px 14px;
}

.tab-btn.active {
  background: rgba(184, 19, 29, 0.12);
  color: var(--accent-strong);
  box-shadow: inset 0 0 0 1px rgba(184, 19, 29, 0.14);
}

.inspector-pane {
  display: none;
  min-height: 0;
  height: 100%;
}

.inspector-pane.active {
  display: grid;
  gap: 14px;
  grid-template-rows: auto auto minmax(0, 1fr);
  overflow: hidden;
}

.pane-head {
  display: grid;
  gap: 4px;
}

.pane-head h3 {
  margin: 0;
  font-size: 1rem;
}

.pane-head p {
  margin: 0;
  color: var(--muted);
}

.compact-form {
  align-content: start;
}

.inspector-output {
  min-height: 0;
  max-height: none;
  height: 100%;
  overflow: auto;
}

.inspector-output.empty-state {
  display: grid;
  place-items: center;
}

.job-card,
.doc-card,
.tree-node {
  border: 1px solid rgba(184, 19, 29, 0.08);
  border-radius: 18px;
  background: rgba(255, 252, 252, 0.96);
}

.job-card,
.doc-card {
  padding: 16px;
}

.doc-card {
  position: relative;
  z-index: 0;
  cursor: pointer;
  overflow: visible;
  transition: transform 140ms ease, border-color 140ms ease, box-shadow 140ms ease;
}

.doc-card:hover,
.doc-card:focus-within {
  z-index: 24;
  transform: translateX(2px);
  border-color: rgba(184, 19, 29, 0.28);
}

.doc-card.active {
  border-color: rgba(184, 19, 29, 0.5);
  box-shadow: 0 12px 26px rgba(184, 19, 29, 0.12);
}

.doc-title,
.jobs-title {
  display: flex;
  justify-content: space-between;
  gap: 14px;
  align-items: flex-start;
  flex-wrap: wrap;
  margin-bottom: 8px;
  min-width: 0;
}

.doc-card .doc-title {
  margin-bottom: 0;
}

.doc-hover-card {
  position: absolute;
  left: 14px;
  right: 14px;
  top: calc(100% + 8px);
  z-index: 18;
  padding: 14px;
  border-radius: 16px;
  background: rgba(255, 252, 252, 0.98);
  border: 1px solid rgba(184, 19, 29, 0.14);
  box-shadow: 0 18px 40px rgba(184, 19, 29, 0.16);
  opacity: 0;
  pointer-events: none;
  transform: translateY(6px);
  transition: opacity 140ms ease, transform 140ms ease;
}

.doc-card:hover .doc-hover-card,
.doc-card:focus-within .doc-hover-card {
  opacity: 1;
  transform: translateY(0);
}

.doc-hover-head {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: flex-start;
  flex-wrap: wrap;
  margin-bottom: 8px;
}

.tag,
.job-status {
  font-family: "IBM Plex Mono", monospace;
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  padding: 5px 8px;
  border-radius: 999px;
  background: rgba(184, 19, 29, 0.1);
  color: var(--accent-strong);
  flex: 0 0 auto;
}

.job-status.running {
  background: rgba(185, 93, 40, 0.12);
  color: var(--heat);
}

.job-status.failed {
  background: rgba(141, 44, 44, 0.12);
  color: var(--danger);
}

.document-meta,
.jobs-meta {
  font-family: "IBM Plex Mono", monospace;
  font-size: 0.75rem;
  line-height: 1.6;
}

.toggle {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-size: 0.88rem;
}

.toggle input {
  width: auto;
}

.tree-node {
  padding: 16px;
}

.tree-head {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: flex-start;
  flex-wrap: wrap;
  min-width: 0;
}

.tree-meta {
  font-family: "IBM Plex Mono", monospace;
  color: var(--muted);
  font-size: 0.74rem;
}

.tree-summary {
  margin-top: 8px;
  color: var(--muted);
  font-size: 0.9rem;
}

.tree-children {
  margin-top: 12px;
  padding-left: 18px;
  border-left: 1px dashed rgba(184, 19, 29, 0.22);
  display: grid;
  gap: 10px;
}

.code-panel {
  margin: 0;
  min-height: 0;
  height: 100%;
  overflow: auto;
  border-radius: 18px;
  padding: 18px;
  background: linear-gradient(180deg, #5f0d14 0%, #41070d 100%);
  color: #fff5f6;
  font-family: "IBM Plex Mono", monospace;
  font-size: 0.8rem;
  line-height: 1.6;
  white-space: pre-wrap;
  word-break: break-word;
  overflow-wrap: anywhere;
}

.query-output {
  display: grid;
  gap: 12px;
  align-content: start;
  overflow: auto;
}

.answer-card {
  border-radius: 18px;
  padding: 18px;
  background: rgba(255, 252, 252, 0.98);
  border: 1px solid rgba(184, 19, 29, 0.08);
}

.answer-topline {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 10px;
  font-family: "IBM Plex Mono", monospace;
  font-size: 0.74rem;
  color: var(--muted);
  align-items: flex-start;
  flex-wrap: wrap;
  min-width: 0;
}

.answer-body {
  line-height: 1.65;
  max-height: 14rem;
  overflow: auto;
  padding-right: 6px;
  overflow-wrap: anywhere;
}

.answer-list {
  margin: 0;
  padding-left: 18px;
  color: var(--muted);
  overflow-wrap: anywhere;
}

.context-details {
  border-top: 1px solid rgba(184, 19, 29, 0.08);
  padding-top: 12px;
}

.context-details summary {
  cursor: pointer;
  color: var(--accent-strong);
  font-weight: 600;
}

.compact-field {
  margin-bottom: 14px;
}

.empty-state {
  padding: 22px;
  border-radius: 18px;
  background: rgba(255, 248, 249, 0.92);
  border: 1px dashed rgba(184, 19, 29, 0.16);
  color: var(--muted);
  text-align: center;
  overflow-wrap: anywhere;
}

.toast-host {
  position: fixed;
  right: 20px;
  bottom: 20px;
  z-index: 40;
  display: grid;
  gap: 10px;
}

.toast {
  min-width: 260px;
  max-width: 360px;
  padding: 14px 16px;
  border-radius: 18px;
  color: #fff8f8;
  background: rgba(95, 13, 20, 0.96);
  box-shadow: 0 20px 40px rgba(0, 0, 0, 0.18);
}

.toast.error {
  background: rgba(143, 15, 23, 0.98);
}

.context-menu {
  position: fixed;
  z-index: 80;
  min-width: 168px;
  padding: 8px;
  border-radius: 16px;
  background: rgba(255, 252, 252, 0.98);
  border: 1px solid rgba(184, 19, 29, 0.14);
  box-shadow: 0 18px 40px rgba(184, 19, 29, 0.16);
  backdrop-filter: blur(10px);
}

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

.context-menu-item {
  width: 100%;
  display: block;
  padding: 10px 12px;
  border-radius: 12px;
  background: transparent;
  border: 0;
  text-align: left;
  color: var(--text);
}

.context-menu-item:hover {
  background: rgba(184, 19, 29, 0.08);
  transform: none;
}

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

.hero-copy,
.section-head p,
.muted-text,
.document-meta,
.jobs-meta,
.status-cluster strong,
.doc-title strong,
.tree-head strong,
.tree-meta,
.answer-topline span,
.pane-head p,
#docTitle,
#docMeta {
  overflow-wrap: anywhere;
}

.doc-title strong,
.tree-head strong {
  min-width: 0;
}

.document-meta,
.jobs-meta,
.tree-summary {
  overflow-wrap: anywhere;
}

@media (max-width: 1100px) {
  .hero,
  .top-grid,
  .workspace,
  .document-layout {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 720px) {
  .shell {
    width: min(100vw - 16px, 100%);
    margin: 8px auto 18px;
  }

  .card,
  .sidebar,
  .jobs-section,
  .form-card,
  .structure-card,
  .inspector-card {
    padding: 16px;
  }

  .grid.two-up {
    grid-template-columns: 1fr;
  }

  .hero-status {
    grid-template-columns: 1fr;
  }

  .structure-head {
    grid-template-columns: 1fr;
  }

  .structure-actions {
    justify-items: stretch;
  }

  .structure-card,
  .inspector-card {
    min-height: auto;
    position: static;
  }

  .doc-hover-card {
    left: 8px;
    right: 8px;
  }

  .structure-tree {
    max-height: 60vh;
  }

  .inspector-pane.active {
    grid-template-rows: auto auto minmax(240px, 1fr);
  }
}
