:root {
  --bg: #f4f6f8;
  --surface: #ffffff;
  --surface-2: #f8fafb;
  --line: #d9e0e7;
  --line-strong: #b8c4cf;
  --text: #1f2933;
  --muted: #667788;
  --blue: #1367d8;
  --blue-strong: #0d55b3;
  --green-bg: #dff6e9;
  --green-line: #93d7ad;
  --red-bg: #ffe4e1;
  --red-line: #f2a3a0;
  --yellow-bg: #fff5d6;
  --yellow-line: #e2c665;
  --shadow: 0 14px 34px rgba(31, 41, 51, 0.09);
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
    "PingFang SC", "Microsoft YaHei", sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background:
    linear-gradient(90deg, rgba(19, 103, 216, 0.05), transparent 32%),
    linear-gradient(180deg, #f7f9fb 0%, var(--bg) 100%);
  color: var(--text);
}

button,
select,
textarea {
  font: inherit;
}

button {
  cursor: pointer;
}

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

.app-shell {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 320px;
  gap: 18px;
  width: min(1480px, calc(100vw - 32px));
  margin: 16px auto;
  min-height: calc(100vh - 32px);
}

.workspace,
.history-panel {
  background: rgba(255, 255, 255, 0.94);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.workspace {
  display: flex;
  flex-direction: column;
  min-width: 0;
  overflow: hidden;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 18px 20px;
  border-bottom: 1px solid var(--line);
}

.brand {
  display: flex;
  align-items: center;
  gap: 14px;
  min-width: 0;
}

.brand-mark {
  display: grid;
  place-items: center;
  width: 48px;
  height: 48px;
  border-radius: 8px;
  background: #101820;
  color: #73e2a7;
  font-weight: 800;
  letter-spacing: 0;
  border: 1px solid #2a3540;
}

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

h1 {
  font-size: 22px;
  line-height: 1.2;
}

h2 {
  font-size: 17px;
}

h3 {
  font-size: 13px;
  color: var(--muted);
  font-weight: 700;
}

.topbar p,
.result-header p {
  margin-top: 4px;
  color: var(--muted);
  font-size: 13px;
}

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

.beta-controls {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--muted);
  font-size: 12px;
}

.mode-tabs {
  display: flex;
  gap: 6px;
  padding: 12px 20px 0;
}

.mode-tab,
.ghost-button,
.primary-button,
.text-button {
  border: 1px solid var(--line);
  border-radius: 6px;
  min-height: 36px;
  padding: 0 13px;
  background: var(--surface);
  color: var(--text);
}

.mode-tab {
  min-width: 74px;
  font-weight: 700;
}

.mode-tab.active {
  border-color: var(--blue);
  background: #e8f1ff;
  color: var(--blue);
}

.primary-button {
  border-color: var(--blue);
  background: var(--blue);
  color: #ffffff;
  font-weight: 800;
  min-width: 124px;
}

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

.ghost-button:hover,
.mode-tab:hover {
  border-color: var(--line-strong);
}

.text-button {
  border: 0;
  padding: 0;
  min-height: auto;
  background: transparent;
  color: var(--blue);
}

.safety-banner {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 14px 20px 0;
  padding: 10px 12px;
  border: 1px solid var(--yellow-line);
  border-radius: 8px;
  background: var(--yellow-bg);
  color: #5f4a05;
  font-size: 13px;
  line-height: 1.5;
}

.safety-banner strong {
  flex: 0 0 auto;
  color: #6d5100;
}

.control-strip {
  display: flex;
  align-items: end;
  gap: 12px;
  padding: 14px 20px;
  border-bottom: 1px solid var(--line);
  flex-wrap: wrap;
}

.control-strip label {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

select {
  min-width: 150px;
  height: 36px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--surface);
  color: var(--text);
  padding: 0 10px;
}

.hidden {
  display: none !important;
}

.input-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 0.76fr);
  gap: 14px;
  padding: 16px 20px;
}

.editor-block {
  display: grid;
  gap: 8px;
  min-width: 0;
}

.editor-block span,
.schema-details summary {
  color: var(--muted);
  font-size: 13px;
  font-weight: 800;
}

textarea {
  width: 100%;
  min-height: 210px;
  resize: vertical;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  background: #fbfcfd;
  color: var(--text);
  line-height: 1.55;
  font-family:
    "SFMono-Regular", Consolas, "Liberation Mono", Menlo, monospace;
  font-size: 13px;
  outline: none;
}

textarea:focus {
  border-color: var(--blue);
  box-shadow: 0 0 0 3px rgba(19, 103, 216, 0.13);
}

.schema-details {
  margin: 0 20px 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-2);
}

.schema-details summary {
  padding: 10px 12px;
  cursor: pointer;
}

.schema-details textarea {
  min-height: 110px;
  border: 0;
  border-top: 1px solid var(--line);
  border-radius: 0 0 8px 8px;
}

.result-panel {
  margin: 0 20px 20px;
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: hidden;
  background: var(--surface);
}

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

.diff-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  border-bottom: 1px solid var(--line);
}

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

.code-card {
  min-width: 0;
  background: #fbfcfd;
}

.code-card + .code-card {
  border-left: 1px solid var(--line);
}

.diff-grid.stacked .code-card + .code-card {
  border-left: 0;
  border-top: 1px solid var(--line);
}

.code-card h3 {
  padding: 10px 12px;
  border-bottom: 1px solid var(--line);
}

pre {
  margin: 0;
  min-height: 230px;
  max-height: 420px;
  overflow: auto;
  padding: 12px;
  font-family:
    "SFMono-Regular", Consolas, "Liberation Mono", Menlo, monospace;
  font-size: 13px;
  line-height: 1.65;
  white-space: pre-wrap;
  word-break: break-word;
}

.line {
  display: block;
  min-height: 21px;
  padding: 0 4px;
  border-left: 3px solid transparent;
}

.line.added {
  background: var(--green-bg);
  border-left-color: var(--green-line);
}

.line.removed {
  background: var(--red-bg);
  border-left-color: var(--red-line);
}

.line.changed {
  background: var(--yellow-bg);
  border-left-color: var(--yellow-line);
}

.placeholder {
  color: #9aa8b5;
}

.insight-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

.insight-grid article {
  padding: 14px;
  min-width: 0;
}

.insight-grid article + article {
  border-left: 1px solid var(--line);
}

.feedback-panel {
  display: grid;
  grid-template-columns: minmax(160px, 0.5fr) minmax(0, 1fr) auto;
  align-items: center;
  gap: 12px;
  padding: 14px;
  border-top: 1px solid var(--line);
  background: var(--surface-2);
}

.feedback-panel p {
  margin-top: 4px;
  color: var(--muted);
  font-size: 13px;
}

.feedback-panel textarea {
  min-height: 52px;
  resize: vertical;
}

.feedback-actions {
  display: flex;
  gap: 8px;
  justify-content: flex-end;
  flex-wrap: wrap;
}

ul {
  margin: 10px 0 0;
  padding-left: 18px;
  color: var(--text);
  line-height: 1.55;
}

li + li {
  margin-top: 6px;
}

.risk-card li {
  color: #8a3d14;
}

.history-panel {
  display: flex;
  flex-direction: column;
  min-height: 0;
  overflow: hidden;
}

.history-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px;
  border-bottom: 1px solid var(--line);
}

.history-list {
  display: grid;
  align-content: start;
  gap: 10px;
  padding: 12px;
  overflow: auto;
}

.history-item {
  display: grid;
  gap: 7px;
  text-align: left;
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-2);
  padding: 10px;
}

.history-item strong {
  font-size: 13px;
}

.history-item span {
  color: var(--muted);
  font-size: 12px;
}

.history-item code {
  color: var(--text);
  font-size: 12px;
  font-family:
    "SFMono-Regular", Consolas, "Liberation Mono", Menlo, monospace;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.empty-history {
  color: var(--muted);
  font-size: 13px;
  padding: 8px;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: 20px;
  transform: translateX(-50%) translateY(18px);
  opacity: 0;
  pointer-events: none;
  min-width: 180px;
  max-width: min(520px, calc(100vw - 32px));
  background: #101820;
  color: #ffffff;
  border-radius: 8px;
  padding: 10px 14px;
  text-align: center;
  transition:
    opacity 0.2s ease,
    transform 0.2s ease;
  z-index: 10;
}

.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

@media (max-width: 1100px) {
  .app-shell {
    grid-template-columns: 1fr;
  }

  .history-panel {
    min-height: 260px;
  }
}

@media (max-width: 780px) {
  .app-shell {
    width: calc(100vw - 16px);
    margin: 8px auto;
  }

  .topbar,
  .result-header,
  .safety-banner {
    align-items: stretch;
    flex-direction: column;
  }

  .input-grid,
  .diff-grid,
  .insight-grid,
  .feedback-panel {
    grid-template-columns: 1fr;
  }

  .top-actions,
  .beta-controls,
  .feedback-actions {
    justify-content: stretch;
    width: 100%;
  }

  .feedback-actions button {
    flex: 1;
  }

  .code-card + .code-card,
  .insight-grid article + article {
    border-left: 0;
    border-top: 1px solid var(--line);
  }

  .control-strip label,
  select,
  .primary-button {
    width: 100%;
  }
}
