:root {
  color-scheme: light;
  --bg: #f4f1ea;
  --panel: #ffffff;
  --text: #1f2937;
  --muted: #5b6472;
  --line: #d9d5cc;
  --accent: #176b87;
  --accent-strong: #0f4c5c;
  --accent-soft: #e8f3f6;
  --danger: #a33a3a;
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

html,
body {
  width: 100%;
  height: 100%;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: Arial, "Microsoft YaHei", sans-serif;
}

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

.app {
  height: 100vh;
  padding: 16px;
  overflow: hidden;
}

.workspace {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  gap: 12px;
  max-width: 1680px;
  height: calc(100vh - 32px);
  margin: 0 auto;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

h1 {
  margin: 0 0 4px;
  font-size: 24px;
  letter-spacing: 0;
}

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

.actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

.render-mode-control {
  display: grid;
  gap: 4px;
  color: var(--muted);
  font-size: 13px;
}

.render-mode-control select {
  height: 42px;
  min-width: 132px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #ffffff;
  color: var(--text);
}

button {
  min-width: 120px;
  height: 42px;
  border: 0;
  border-radius: 6px;
  color: #ffffff;
  background: var(--accent);
  cursor: pointer;
}

button.secondary {
  color: var(--accent-strong);
  background: var(--accent-soft);
}

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

button.secondary:hover {
  color: #ffffff;
}

button:disabled {
  cursor: wait;
  opacity: 0.65;
}

.visually-hidden {
  position: absolute !important;
  width: 1px !important;
  height: 1px !important;
  padding: 0 !important;
  margin: -1px !important;
  overflow: hidden !important;
  clip: rect(0, 0, 0, 0) !important;
  white-space: nowrap !important;
  border: 0 !important;
}

.editor-grid {
  display: grid;
  grid-template-columns: minmax(320px, 0.62fr) minmax(680px, 1.38fr);
  gap: 16px;
  min-height: 0;
  overflow: hidden;
}

.pane {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  min-width: 0;
  min-height: 0;
  overflow: hidden;
}

.pane-header {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  min-height: 30px;
}

.pane-header h2 {
  margin: 0;
  color: var(--text);
  font-size: 16px;
  letter-spacing: 0;
}

.pane-header span {
  color: var(--muted);
  font-size: 13px;
}

textarea {
  width: 100%;
  height: 100%;
  min-height: 0;
  resize: none;
  overflow: auto;
  padding: 18px;
  border: 1px solid var(--line);
  border-radius: 8px;
  outline: none;
  background: var(--panel);
  color: var(--text);
  line-height: 1.5;
  tab-size: 2;
}

iframe {
  width: 100%;
  height: 100%;
  min-height: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #ffffff;
}

textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(23, 107, 135, 0.14);
}

.status {
  min-height: 24px;
  color: var(--muted);
}

.status.error {
  color: var(--danger);
}

.drawer-backdrop {
  position: fixed;
  inset: 0;
  z-index: 20;
  background: rgba(15, 23, 42, 0.32);
}

.report-drawer {
  position: fixed;
  top: 0;
  right: 0;
  z-index: 30;
  display: grid;
  width: min(460px, calc(100vw - 24px));
  height: 100vh;
  border-left: 1px solid var(--line);
  background: var(--panel);
  box-shadow: -16px 0 40px rgba(15, 23, 42, 0.16);
  transform: translateX(104%);
  transition: transform 180ms ease;
}

.report-drawer.is-open {
  transform: translateX(0);
}

.report-form {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  min-height: 0;
}

.drawer-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  padding: 20px 20px 14px;
  border-bottom: 1px solid var(--line);
}

.drawer-header h2 {
  margin: 0 0 6px;
  font-size: 20px;
}

.drawer-header p {
  font-size: 13px;
  line-height: 1.45;
}

.icon-button {
  min-width: 36px;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  color: var(--accent-strong);
  background: var(--accent-soft);
  font-size: 24px;
  line-height: 1;
}

.drawer-fields {
  display: grid;
  align-content: start;
  gap: 14px;
  min-height: 0;
  padding: 18px 20px;
  overflow: auto;
}

.drawer-fields label {
  display: grid;
  gap: 7px;
}

.field-label {
  color: var(--text);
  font-size: 14px;
  font-weight: 600;
}

.workflow-version-row {
  display: grid;
  align-items: center;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 8px;
  transition:
    grid-template-columns 180ms ease,
    gap 180ms ease;
}

.workflow-version-row.is-random-mode {
  grid-template-columns: minmax(0, 0fr) 1fr;
  gap: 0;
}

.drawer-fields input,
.drawer-fields select,
.drawer-fields textarea {
  width: 100%;
  min-height: 40px;
  padding: 9px 10px;
  border: 1px solid var(--line);
  border-radius: 6px;
  outline: none;
  background: #ffffff;
  color: var(--text);
}

.workflow-version-row button {
  width: 100%;
  min-height: 40px;
  padding: 0 16px;
  transition:
    background-color 180ms ease,
    box-shadow 180ms ease,
    color 180ms ease,
    transform 180ms ease;
}

.workflow-version-row button:hover {
  transform: translateY(-1px);
  box-shadow: 0 8px 20px rgba(15, 76, 92, 0.16);
}

.workflow-version-row #reportWorkflowVersion {
  min-width: 0;
  transition:
    opacity 160ms ease,
    transform 160ms ease,
    visibility 0s linear,
    padding 160ms ease,
    border-color 160ms ease;
}

.workflow-version-row.is-random-mode #reportWorkflowVersion {
  visibility: hidden;
  opacity: 0;
  transform: translateX(-8px);
  pointer-events: none;
  padding-right: 0;
  padding-left: 0;
  border-color: transparent;
  transition:
    opacity 160ms ease,
    transform 160ms ease,
    visibility 0s linear 160ms,
    padding 160ms ease,
    border-color 160ms ease;
}

.drawer-fields textarea {
  min-height: 116px;
  resize: vertical;
}

.drawer-fields input:focus,
.drawer-fields select:focus,
.drawer-fields textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(23, 107, 135, 0.14);
}

.drawer-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  padding: 14px 20px 20px;
  border-top: 1px solid var(--line);
}

.drawer-actions button {
  width: 100%;
}

@media (min-height: 900px) {
  .workspace {
    gap: 14px;
  }

  .pane-header {
    min-height: 34px;
  }
}

@media (max-width: 720px) {
  .app {
    height: auto;
    min-height: 100vh;
    overflow: visible;
    padding: 12px;
  }

  .workspace {
    height: auto;
    min-height: calc(100vh - 24px);
  }

  .topbar {
    align-items: stretch;
    flex-direction: column;
  }

  .actions {
    flex-direction: column;
  }

  button {
    width: 100%;
  }

  .editor-grid {
    grid-template-columns: 1fr;
    min-height: auto;
    overflow: visible;
  }

  .pane {
    min-height: min(72vh, 620px);
    overflow: visible;
  }

  .pane:last-child {
    min-height: max(76vh, 680px);
  }
}
