* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

:root {
  color-scheme: light;
  --bg: #f4f6f8;
  --surface: #ffffff;
  --surface-strong: #eef2f5;
  --border: #cbd5df;
  --border-strong: #9aa9b7;
  --text: #17212b;
  --muted: #627386;
  --accent: #1b6f63;
  --accent-strong: #12564d;
  --blue: #244c9a;
  --red-bg: #fff0f0;
  --red-border: #e18888;
  --red-text: #8c1d1d;
  --green-bg: #ecf8f2;
  --green-border: #75b995;
  --green-text: #155b35;
  --yellow-bg: #fff7df;
  --yellow-border: #dbb85c;
  --mono: "SFMono-Regular", Consolas, "Liberation Mono", monospace;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

body {
  min-width: 320px;
  margin: 0;
  background: var(--bg);
  color: var(--text);
}

button,
textarea,
input {
  font: inherit;
}

button {
  cursor: pointer;
}

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

.app-shell {
  width: min(1520px, 100%);
  margin: 0 auto;
  padding: 20px;
}

.app-header,
.compare-head,
.panel-head,
.field-head,
.dialog-head,
.dialog-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.app-header {
  min-height: 72px;
  padding-bottom: 18px;
  border-bottom: 1px solid var(--border);
}

.title-block {
  min-width: 0;
}

.title-block h1,
.dialog-head h2,
.compare-head h2 {
  margin: 0;
  letter-spacing: 0;
}

.title-block h1 {
  font-size: clamp(28px, 4vw, 46px);
  line-height: 1.05;
}

.service-chip,
.panel-status,
.field-status {
  display: inline-flex;
  align-items: center;
  width: fit-content;
  min-height: 24px;
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 3px 9px;
  background: var(--surface-strong);
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  line-height: 1.2;
}

.main-layout {
  display: grid;
  gap: 18px;
  padding-top: 18px;
}

.editor-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.5fr) minmax(320px, 0.8fr);
  gap: 16px;
}

.field-block,
.panel {
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
}

.field-block {
  display: grid;
  grid-template-rows: auto minmax(260px, 34vh) auto;
  min-width: 0;
  overflow: hidden;
}

.prompt-block {
  grid-template-rows: auto minmax(180px, 34vh) auto;
}

.field-head,
.panel-head {
  min-height: 48px;
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
}

.field-head label,
.panel-head h3 {
  margin: 0;
  font-size: 15px;
  font-weight: 800;
}

.panel-head-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
}

.response-duration {
  border-color: var(--green-border);
  background: var(--green-bg);
  color: var(--green-text);
}

.field-block textarea {
  width: 100%;
  height: 100%;
  min-width: 0;
  resize: vertical;
  border: 0;
  border-radius: 0;
  padding: 12px;
  background: #fbfcfd;
  color: var(--text);
  line-height: 1.45;
  outline: none;
}

#jrxml-input {
  font-family: var(--mono);
  font-size: 13px;
  white-space: pre;
  overflow: auto;
}

#prompt-input {
  font-size: 14px;
}

.field-block textarea:focus {
  box-shadow: inset 0 0 0 2px rgba(27, 111, 99, 0.25);
}

.field-status {
  margin: 8px 12px 10px;
}

.button-group,
.header-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
}

.button {
  min-height: 36px;
  border: 1px solid transparent;
  border-radius: 8px;
  padding: 0 13px;
  color: var(--text);
  background: var(--surface);
  font-weight: 800;
  line-height: 1;
  white-space: nowrap;
}

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

.button.primary:hover {
  background: var(--accent-strong);
}

.button.secondary {
  border-color: var(--border-strong);
  background: #fff;
}

.button.secondary:hover,
.button.ghost:hover {
  border-color: var(--accent);
  color: var(--accent-strong);
}

.button.ghost {
  min-height: 32px;
  border-color: var(--border);
  background: transparent;
  color: var(--muted);
  font-size: 13px;
}

.file-picker {
  display: inline-flex;
  align-items: center;
}

#jrxml-file {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
  pointer-events: none;
}

.compare-head {
  padding-top: 4px;
}

.compare-head h2 {
  font-size: 18px;
}

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

.panel {
  display: grid;
  grid-template-rows: auto minmax(420px, calc(100vh - 520px));
  min-width: 0;
  overflow: hidden;
}

.panel-body {
  min-width: 0;
  min-height: 420px;
  overflow: auto;
  background:
    linear-gradient(45deg, #f6f8fa 25%, transparent 25%),
    linear-gradient(-45deg, #f6f8fa 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, #f6f8fa 75%),
    linear-gradient(-45deg, transparent 75%, #f6f8fa 75%);
  background-color: #fff;
  background-position: 0 0, 0 10px, 10px -10px, -10px 0;
  background-size: 20px 20px;
}

.image-stage {
  display: grid;
  min-height: 100%;
  place-items: center;
  padding: 16px;
}

.preview-figure {
  display: grid;
  gap: 12px;
  justify-items: center;
  max-width: 100%;
  margin: 0;
}

.preview-image {
  display: block;
  max-width: 100%;
  max-height: 78vh;
  object-fit: contain;
  border: 1px solid var(--border);
  background: #fff;
  box-shadow: 0 8px 24px rgba(23, 33, 43, 0.12);
}

.state-message {
  display: grid;
  align-content: start;
  gap: 10px;
  min-height: 100%;
  padding: 16px;
  background: rgba(255, 255, 255, 0.92);
}

.state-message h4 {
  margin: 0;
  font-size: 15px;
}

.state-message p,
.state-message pre {
  margin: 0;
}

.state-message pre {
  max-width: 100%;
  overflow: auto;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 12px;
  background: #f8fafb;
  color: var(--text);
  font-family: var(--mono);
  font-size: 12px;
  line-height: 1.45;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.state-message.error {
  background: var(--red-bg);
  color: var(--red-text);
}

.state-message.error pre {
  border-color: var(--red-border);
  background: #fff8f8;
  color: var(--red-text);
}

.state-message.text {
  background: #f8fbff;
}

.data-message {
  min-width: min-content;
}

.data-view {
  max-width: 100%;
  overflow: auto;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #fff;
}

.data-table {
  width: 100%;
  min-width: 520px;
  border-collapse: collapse;
  font-size: 13px;
  line-height: 1.4;
}

.data-table th,
.data-table td {
  max-width: 360px;
  padding: 9px 10px;
  border-bottom: 1px solid var(--border);
  text-align: left;
  vertical-align: top;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.data-table th {
  position: sticky;
  top: 0;
  z-index: 1;
  background: var(--surface-strong);
  color: var(--text);
  font-weight: 800;
}

.data-table tr:last-child td {
  border-bottom: 0;
}

.data-table tbody tr:nth-child(even) {
  background: #f8fafb;
}

.data-empty,
.data-scalar,
.data-list {
  margin: 0;
  padding: 12px;
}

.data-list {
  display: grid;
  gap: 8px;
  padding-left: 36px;
}

.data-empty {
  color: var(--muted);
  font-weight: 700;
}

.result-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.meta-chip {
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 4px 9px;
  background: #fff;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.loading {
  display: grid;
  min-height: 100%;
  place-items: center;
  padding: 20px;
  background: rgba(255, 255, 255, 0.86);
  color: var(--muted);
  font-weight: 800;
}

.loading::before {
  width: 30px;
  height: 30px;
  border: 3px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  content: "";
  animation: spin 0.8s linear infinite;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

dialog {
  width: min(1280px, 96vw);
  max-width: none;
  max-height: 92vh;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0;
  color: var(--text);
  background: var(--surface);
  box-shadow: 0 24px 80px rgba(23, 33, 43, 0.28);
}

dialog::backdrop {
  background: rgba(23, 33, 43, 0.5);
}

.dialog-shell {
  display: grid;
  grid-template-rows: auto auto auto minmax(0, 1fr);
  max-height: 92vh;
}

.dialog-head,
.dialog-actions,
.diff-labels {
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
}

.dialog-head h2 {
  font-size: 20px;
}

.icon-button {
  display: grid;
  width: 36px;
  height: 36px;
  place-items: center;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #fff;
  color: var(--text);
  font-size: 26px;
  line-height: 1;
}

.diff-labels {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 12px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.diff-view {
  min-height: 360px;
  overflow: auto;
  background: #101820;
  color: #dbe5ef;
  font-family: var(--mono);
  font-size: 12px;
  line-height: 1.45;
}

.diff-row {
  display: grid;
  grid-template-columns: 56px minmax(0, 1fr) 56px minmax(0, 1fr);
  min-width: 840px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.05);
}

.diff-cell {
  min-width: 0;
  padding: 3px 8px;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.diff-line-no {
  color: #7e8b98;
  text-align: right;
  user-select: none;
  background: rgba(255, 255, 255, 0.04);
}

.diff-same {
  color: #dbe5ef;
}

.diff-added {
  background: rgba(38, 118, 72, 0.42);
  color: #d9ffe6;
}

.diff-removed {
  background: rgba(152, 49, 49, 0.44);
  color: #ffe0e0;
}

.diff-changed {
  background: rgba(181, 136, 38, 0.35);
  color: #fff5d6;
}

.diff-empty {
  background: rgba(255, 255, 255, 0.02);
}

@media (max-width: 980px) {
  .app-shell {
    padding: 14px;
  }

  .app-header,
  .compare-head {
    align-items: stretch;
    flex-direction: column;
  }

  .header-actions,
  .compare-head .button-group {
    justify-content: flex-start;
  }

  .editor-grid,
  .panels {
    grid-template-columns: 1fr;
  }

  .panel {
    grid-template-rows: auto minmax(360px, 56vh);
  }

  .field-block,
  .prompt-block {
    grid-template-rows: auto minmax(220px, 36vh) auto;
  }
}

@media (max-width: 560px) {
  .field-head,
  .panel-head,
  .dialog-head,
  .dialog-actions {
    align-items: flex-start;
    flex-direction: column;
  }

  .button,
  .button-group,
  .header-actions,
  .panel-head-actions {
    width: 100%;
  }

  .button {
    justify-content: center;
  }

  .panel-head-actions {
    justify-content: flex-start;
  }

  .diff-labels {
    grid-template-columns: 1fr;
  }
}
