:root {
  color-scheme: light;
  --bg: #eef2f0;
  --paper: #fbfcfa;
  --paper-2: #f3f6f4;
  --ink: #1c2528;
  --muted: #687176;
  --line: #d5ddd8;
  --strong-line: #aebbb4;
  --green: #3d6f66;
  --green-dark: #284f49;
  --gold: #bd8127;
  --red: #b64b3c;
  --blue: #315f7b;
  --shadow: 0 18px 45px rgba(33, 42, 43, 0.12);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-width: 320px;
  color: var(--ink);
  background:
    linear-gradient(180deg, rgba(61, 111, 102, 0.12), transparent 300px),
    var(--bg);
}

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

button {
  cursor: pointer;
}

button:disabled,
input:disabled,
select:disabled {
  cursor: not-allowed;
  opacity: 0.55;
}

.app-shell {
  width: min(1480px, calc(100vw - 32px));
  margin: 0 auto;
  padding: 24px 0 40px;
}

.app-header {
  display: flex;
  align-items: center;
  gap: 18px;
  min-height: 108px;
}

.brand-mark {
  display: grid;
  flex: 0 0 72px;
  width: 72px;
  height: 72px;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--paper);
  box-shadow: var(--shadow);
}

.brand-mark svg {
  width: 48px;
  height: 48px;
  fill: var(--green);
}

.brand-mark .ridge {
  fill: none;
  stroke: var(--paper);
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 3;
}

h1,
h2,
h3,
p {
  margin: 0;
}

h1 {
  font-size: clamp(1.75rem, 3vw, 3.2rem);
  line-height: 1.02;
  letter-spacing: 0;
}

h2 {
  font-size: 1rem;
}

h3 {
  font-size: 1.02rem;
}

.app-header p {
  max-width: 720px;
  margin-top: 8px;
  color: var(--muted);
}

.drop-zone {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  margin-bottom: 18px;
  padding: 22px;
  border: 1px dashed var(--strong-line);
  border-radius: 8px;
  background: rgba(255, 253, 248, 0.78);
}

.drop-zone.is-over {
  border-color: var(--green);
  background: #eef7f2;
}

.drop-copy {
  display: grid;
  gap: 6px;
}

.drop-copy p,
.tool-panel p,
.change-summary p,
.muted {
  color: var(--muted);
}

.eyebrow {
  color: var(--green-dark);
  font-size: 0.75rem;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.primary-button,
.secondary-button,
.icon-button,
.tab-button {
  min-height: 38px;
  border: 1px solid transparent;
  border-radius: 7px;
  font-weight: 750;
}

.primary-button,
.secondary-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 0 14px;
}

.primary-button {
  color: #fff;
  background: var(--green-dark);
}

.primary-button:hover:not(:disabled) {
  background: #1f403b;
}

.secondary-button {
  color: var(--ink);
  border-color: var(--line);
  background: var(--paper);
}

.secondary-button:hover:not(:disabled),
.icon-button:hover:not(:disabled),
.tab-button:hover {
  border-color: var(--strong-line);
  background: var(--paper-2);
}

.button-icon {
  display: inline-grid;
  width: 20px;
  height: 20px;
  place-items: center;
  border-radius: 999px;
  color: inherit;
}

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

.workspace.is-empty {
  opacity: 0.62;
}

.sidebar,
.editor-area,
.tool-panel,
.summary-card {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--paper);
  box-shadow: 0 10px 30px rgba(33, 42, 43, 0.08);
}

.sidebar {
  position: sticky;
  top: 14px;
  max-height: calc(100vh - 28px);
  overflow: auto;
}

.panel-section {
  padding: 16px;
  border-bottom: 1px solid var(--line);
}

.panel-section:last-child {
  border-bottom: 0;
}

.section-title,
.tool-header,
.toolbar,
.button-row,
.add-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.status-pill,
.chunk-badge,
.type-badge {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  padding: 0 8px;
  border-radius: 999px;
  color: var(--green-dark);
  background: #e7f1ed;
  font-size: 0.76rem;
  font-weight: 800;
  white-space: nowrap;
}

.status-pill.warn,
.chunk-badge.warn {
  color: #7a4b0b;
  background: #fff3d7;
}

.status-pill.dirty,
.chunk-badge.dirty {
  color: #fff;
  background: var(--gold);
}

.status-pill.error,
.chunk-badge.error {
  color: #fff;
  background: var(--red);
}

.stat-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  margin-top: 14px;
}

.stat-grid > div {
  min-width: 0;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: var(--paper-2);
}

.stat-label {
  display: block;
  margin-bottom: 5px;
  color: var(--muted);
  font-size: 0.75rem;
}

.stat-grid strong {
  display: block;
  overflow: hidden;
  font-size: 0.92rem;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.action-stack {
  display: grid;
  gap: 9px;
  margin-top: 12px;
}

.filter-box input,
.field-group input,
.form-grid input,
.vector-editor input,
.add-row input,
.add-row select,
.managed-state-input {
  width: 100%;
  min-height: 38px;
  border: 1px solid var(--line);
  border-radius: 7px;
  padding: 8px 10px;
  color: var(--ink);
  background: #fff;
}

.filter-box {
  margin-top: 12px;
}

.filter-box.compact {
  width: min(260px, 42vw);
  margin-top: 0;
}

.chunk-list {
  display: grid;
  gap: 7px;
  margin-top: 12px;
}

.chunk-button {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 8px;
  align-items: center;
  width: 100%;
  min-height: 44px;
  border: 1px solid var(--line);
  border-radius: 7px;
  padding: 8px 10px;
  color: var(--ink);
  background: #fff;
  text-align: left;
}

.chunk-button strong {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.chunk-button.is-active {
  border-color: var(--green);
  box-shadow: inset 3px 0 0 var(--green);
}

.icon-button {
  width: 38px;
  padding: 0;
  border-color: var(--line);
  background: #fff;
}

.editor-area {
  min-width: 0;
  overflow: hidden;
}

.tabs {
  display: flex;
  gap: 6px;
  padding: 10px;
  border-bottom: 1px solid var(--line);
  background: var(--paper-2);
}

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

.tab-button.is-active {
  color: #fff;
  background: var(--green-dark);
}

.tab-panel {
  display: none;
  padding: 18px;
}

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

.summary-grid,
.tool-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
  margin-bottom: 14px;
}

.summary-card,
.tool-panel {
  padding: 16px;
}

.detail-list {
  display: grid;
  gap: 10px;
  margin: 14px 0 0;
}

.detail-list div {
  display: grid;
  grid-template-columns: 140px minmax(0, 1fr);
  gap: 10px;
}

.detail-list dt {
  color: var(--muted);
}

.detail-list dd {
  min-width: 0;
  margin: 0;
  overflow-wrap: anywhere;
}

.validation-list {
  display: grid;
  gap: 8px;
  margin-top: 14px;
}

.validation-item {
  display: flex;
  gap: 8px;
  align-items: flex-start;
}

.validation-dot {
  flex: 0 0 10px;
  width: 10px;
  height: 10px;
  margin-top: 6px;
  border-radius: 999px;
  background: var(--green);
}

.validation-dot.warn {
  background: var(--gold);
}

.validation-dot.error {
  background: var(--red);
}

.tool-panel {
  margin-bottom: 14px;
}

.form-grid,
.vector-editor {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
  margin-top: 14px;
}

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

.vector-editor label,
.form-grid label,
.field-group label {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 750;
}

.vector-editor button {
  align-self: end;
}

.button-row {
  justify-content: flex-start;
  margin-top: 12px;
}

.add-row {
  justify-content: flex-start;
  margin: 14px 0;
}

.add-row input {
  max-width: 360px;
}

.add-row select {
  max-width: 180px;
}

.table-wrap {
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 7px;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.92rem;
}

th,
td {
  padding: 10px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  vertical-align: middle;
}

th {
  color: var(--muted);
  background: var(--paper-2);
  font-size: 0.78rem;
  text-transform: uppercase;
}

tbody tr:last-child td {
  border-bottom: 0;
}

.toolbar {
  align-items: end;
  margin-bottom: 14px;
}

.field-group.grow {
  flex: 1 1 auto;
}

.toggle {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 38px;
  color: var(--muted);
  font-weight: 750;
  white-space: nowrap;
}

.tree-editor {
  max-height: 70vh;
  overflow: auto;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

.tree-node {
  margin-left: 16px;
}

.tree-node.root {
  margin-left: 0;
}

.tree-row {
  display: grid;
  grid-template-columns: minmax(180px, 0.85fr) minmax(180px, 1fr) auto;
  gap: 8px;
  align-items: center;
  min-height: 36px;
  padding: 5px 0;
  border-bottom: 1px solid #eee8df;
}

.tree-key {
  min-width: 0;
  overflow: hidden;
  color: var(--blue);
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.86rem;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.tree-value {
  min-width: 0;
}

.tree-value input,
.tree-value textarea,
.json-string-editor textarea {
  width: 100%;
  min-height: 34px;
  border: 1px solid var(--line);
  border-radius: 7px;
  padding: 7px 9px;
  background: #fff;
}

.tree-value textarea,
.json-string-editor textarea {
  min-height: 84px;
  resize: vertical;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

.tree-type {
  color: var(--muted);
  font-size: 0.78rem;
}

.tree-details > summary {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 34px;
  cursor: pointer;
  border-bottom: 1px solid #eee8df;
}

.json-string-editor {
  margin: 8px 0 10px 18px;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: var(--paper-2);
}

#jsonEditor {
  width: 100%;
  min-height: 68vh;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 14px;
  color: #172024;
  background: #fff;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.9rem;
  line-height: 1.5;
  resize: vertical;
}

.changes-list {
  display: grid;
  gap: 10px;
  margin-top: 14px;
}

.change-item {
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: #fff;
}

.change-item strong {
  display: block;
  margin-bottom: 6px;
}

.change-path {
  color: var(--muted);
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.84rem;
  overflow-wrap: anywhere;
}

.toast {
  position: fixed;
  right: 18px;
  bottom: 18px;
  z-index: 10;
  max-width: min(420px, calc(100vw - 36px));
  padding: 12px 14px;
  border-radius: 8px;
  color: #fff;
  background: rgba(28, 37, 40, 0.95);
  box-shadow: var(--shadow);
  opacity: 0;
  transform: translateY(10px);
  transition: opacity 160ms ease, transform 160ms ease;
  pointer-events: none;
}

.toast.is-visible {
  opacity: 1;
  transform: translateY(0);
}

.danger-link {
  min-height: 34px;
  border: 0;
  color: var(--red);
  background: transparent;
  font-weight: 800;
}

.empty-state {
  padding: 28px;
  color: var(--muted);
  text-align: center;
}

@media (max-width: 980px) {
  .workspace,
  .summary-grid,
  .tool-grid {
    grid-template-columns: 1fr;
  }

  .sidebar {
    position: static;
    max-height: none;
  }
}

@media (max-width: 680px) {
  .app-shell {
    width: min(100vw - 20px, 1480px);
    padding-top: 14px;
  }

  .app-header,
  .drop-zone,
  .section-title,
  .tool-header,
  .toolbar,
  .add-row,
  .button-row {
    align-items: stretch;
    flex-direction: column;
  }

  .brand-mark {
    width: 58px;
    height: 58px;
    flex-basis: 58px;
  }

  .tabs {
    overflow-x: auto;
  }

  .form-grid,
  .vector-editor,
  .stat-grid {
    grid-template-columns: 1fr;
  }

  .detail-list div,
  .tree-row {
    grid-template-columns: 1fr;
  }

  .filter-box.compact,
  .add-row input,
  .add-row select {
    width: 100%;
    max-width: none;
  }
}
