:root {
  --bg: #f6f7f9;
  --panel: #ffffff;
  --text: #172033;
  --muted: #667085;
  --border: #d8dee8;
  --blue: #155eef;
  --blue-dark: #124bbd;
  --green-bg: #e8f6ee;
  --green-text: #17663a;
  --red-bg: #fff0f0;
  --red-text: #a12a2a;
  --yellow-bg: #fff7dc;
  --yellow-text: #735900;
  font-family: ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
}

body:not(.result-mode) {
  overflow: auto;
}

button,
textarea,
input {
  font: inherit;
}

.app {
  width: min(1440px, calc(100% - 32px));
  margin: 0 auto;
  min-height: 100vh;
  padding: 14px 0;
}

body:not(.result-mode) .app {
  display: grid;
  grid-template-rows: auto auto minmax(0, 1fr);
  gap: 10px;
  height: 100vh;
  min-height: 0;
  padding-bottom: 18px;
}

.header {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 0;
}

.eyebrow {
  margin: 0 0 2px;
  color: var(--blue);
  font-size: 11px;
  font-weight: 800;
  letter-spacing: .04em;
  text-transform: uppercase;
}

h1,
h2 {
  margin: 0;
  letter-spacing: 0;
}

h1 {
  font-size: clamp(22px, 2.2vw, 30px);
}

h2 {
  font-size: 17px;
}

.api-state {
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 5px 10px;
  background: var(--panel);
  color: var(--muted);
  font-size: 13px;
}

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

.panel,
.toolbar,
.stats div,
.result {
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--panel);
}

.panel-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  min-height: 36px;
  padding: 0 10px;
  border-bottom: 1px solid var(--border);
  font-weight: 800;
  font-size: 13px;
}

.panel-title input {
  max-width: 180px;
  font-size: 12px;
}

.file-info {
  margin: 0;
  padding: 5px 10px;
  border-bottom: 1px solid var(--border);
  color: var(--muted);
  font-size: 12px;
  line-height: 1.35;
}

textarea {
  display: block;
  width: 100%;
  min-height: 136px;
  resize: vertical;
  border: 0;
  outline: 0;
  padding: 10px;
  background: transparent;
  color: var(--text);
  line-height: 1.45;
  font-family: "SFMono-Regular", Consolas, "Liberation Mono", monospace;
  font-size: 13px;
}

.toolbar {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
  margin: 0;
  padding: 8px;
}

body:not(.result-mode) .inputs {
  min-height: 0;
}

body:not(.result-mode) .panel {
  display: flex;
  min-height: 0;
  flex-direction: column;
}

body:not(.result-mode) .panel textarea {
  flex: 1;
  min-height: 0;
}

body:not(.result-mode) .stats,
body:not(.result-mode) .result {
  display: none;
}

.result-toolbar {
  display: none;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
  margin-bottom: 10px;
  padding: 8px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--panel);
}

.segmented {
  display: inline-flex;
  overflow: hidden;
  border: 1px solid var(--border);
  border-radius: 8px;
}

button {
  min-height: 32px;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0 10px;
  background: #fff;
  color: var(--text);
  cursor: pointer;
  font-size: 13px;
}

.segmented button {
  border: 0;
  border-radius: 0;
}

.segmented button + button {
  border-left: 1px solid var(--border);
}

button:hover {
  border-color: #aab4c4;
}

button.active,
.primary {
  border-color: var(--blue);
  background: var(--blue);
  color: #fff;
}

.primary:hover {
  border-color: var(--blue-dark);
  background: var(--blue-dark);
}

.toolbar label {
  color: var(--muted);
  font-size: 13px;
}

.actions {
  display: flex;
  gap: 6px;
  margin-left: auto;
  flex-wrap: wrap;
}

.stats {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
  margin-bottom: 10px;
}

.stats div {
  padding: 8px 10px;
}

.stats strong {
  display: block;
  font-size: 18px;
}

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

.result-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 14px;
  border-bottom: 1px solid var(--border);
}

.result-mode .app {
  width: min(1600px, calc(100% - 24px));
  min-height: auto;
  padding-top: 10px;
}

.result-mode .header,
.result-mode .inputs,
.result-mode .toolbar,
.result-mode .stats,
.result-mode .result-head {
  display: none;
}

.result-mode .result-toolbar {
  display: flex;
  position: sticky;
  top: 0;
  z-index: 10;
}

.result-mode .result {
  min-height: calc(100vh - 74px);
}

.result-mode .output {
  min-height: calc(100vh - 86px);
  max-height: none;
}

.result-head p {
  margin: 0;
  color: var(--muted);
  font-size: 14px;
}

.output {
  min-height: 340px;
  max-height: 64vh;
  overflow: auto;
  font-family: "SFMono-Regular", Consolas, "Liberation Mono", monospace;
  font-size: 13px;
  line-height: 1.55;
}

.compare-editor-layout {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
  padding: 12px 14px;
  border-bottom: 1px solid var(--border);
}

.compare-source {
  min-width: 0;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #fff;
}

.compare-source label {
  display: block;
  padding: 8px 10px;
  border-bottom: 1px solid var(--border);
  color: var(--muted);
  font-family: ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-size: 12px;
  font-weight: 800;
}

.compare-editor {
  min-height: 180px;
}

.compare-diff {
  border-top: 1px solid #edf0f5;
}

.result-mode .compare-editor-layout {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.result-mode .compare-editor {
  min-height: 220px;
  max-height: 34vh;
}

.merge-notice {
  margin: 12px 14px 0;
  padding: 10px 12px;
  border: 1px solid #c7d7fe;
  border-radius: 8px;
  background: #eef4ff;
  color: #1d3f8f;
  font-family: ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-size: 13px;
}

.merge-notice code {
  border-radius: 4px;
  padding: 1px 4px;
  background: #fff;
  color: #172033;
}

.merge-meta {
  margin: 8px 14px 0;
  color: var(--muted);
  font-family: ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-size: 12px;
}

.merge-editor-layout {
  display: grid;
  grid-template-columns: minmax(320px, 42%) minmax(0, 1fr);
  gap: 12px;
  padding: 12px 14px 14px;
}

.merge-picker,
.merge-final {
  min-width: 0;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #fff;
}

.merge-picker {
  max-height: 340px;
  overflow: auto;
}

.merge-picker-head,
.merge-final label {
  display: block;
  padding: 8px 10px;
  border-bottom: 1px solid var(--border);
  color: var(--muted);
  font-family: ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-size: 12px;
  font-weight: 800;
}

.merge-line {
  display: grid;
  grid-template-columns: 24px 40px minmax(0, 1fr);
  gap: 6px;
  align-items: start;
  padding: 7px 10px;
  border-bottom: 1px solid #edf0f5;
  cursor: pointer;
}

.merge-line:hover {
  background: #f8fafc;
}

.merge-line-no {
  color: #8b96a8;
  text-align: right;
  user-select: none;
}

.merge-line-text {
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.merged-editor {
  min-height: 360px;
  resize: vertical;
}

.result-mode .merge-editor-layout {
  grid-template-columns: minmax(360px, 42%) minmax(0, 1fr);
  min-height: calc(100vh - 188px);
  padding: 10px 14px 14px;
}

.result-mode .merge-picker {
  max-height: none;
}

.result-mode .merge-picker,
.result-mode .merge-final {
  display: flex;
  min-height: 0;
  flex-direction: column;
}

.result-mode .merge-line {
  flex: 0 0 auto;
}

.result-mode .merged-editor {
  flex: 1;
  min-height: 0;
  resize: none;
}

.empty,
.error {
  padding: 24px 14px;
  color: var(--muted);
}

.error {
  color: var(--red-text);
}

.row {
  display: grid;
  grid-template-columns: 64px minmax(0, 1fr);
  border-bottom: 1px solid #edf0f5;
}

.line {
  padding: 6px 10px;
  background: #fafbfe;
  color: #8b96a8;
  text-align: right;
  user-select: none;
}

.text {
  min-width: 0;
  padding: 6px 12px;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.marker {
  display: inline-block;
  min-width: 22px;
  font-weight: 800;
}

.insert .text {
  background: var(--green-bg);
  color: var(--green-text);
}

.delete .text {
  background: var(--red-bg);
  color: var(--red-text);
}

.replace .text {
  background: var(--yellow-bg);
  color: var(--yellow-text);
}

@media (max-width: 900px) {
  .header,
  .result-head {
    align-items: flex-start;
    flex-direction: column;
  }

  .inputs,
  .stats {
    grid-template-columns: 1fr;
  }

  body:not(.result-mode) {
    overflow: auto;
  }

  body:not(.result-mode) .inputs {
    min-height: auto;
  }

  body:not(.result-mode) .panel textarea {
    min-height: 220px;
  }

  .actions {
    width: 100%;
    margin-left: 0;
  }

  .actions button {
    flex: 1 1 96px;
  }

  .result-toolbar {
    justify-content: stretch;
    flex-wrap: wrap;
  }

  .result-toolbar button {
    flex: 1 1 120px;
  }

  .merge-editor-layout {
    grid-template-columns: 1fr;
  }

  .compare-editor-layout,
  .result-mode .compare-editor-layout {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 560px) {
  .app {
    width: min(100% - 20px, 1440px);
    padding-top: 10px;
  }

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

  .segmented {
    width: 100%;
  }

  .segmented button {
    flex: 1;
  }

  .row {
    grid-template-columns: 46px minmax(0, 1fr);
  }
}
