:root {
  color-scheme: light;
  --bg: #f4f6f8;
  --surface: #ffffff;
  --surface-2: #eef2f5;
  --line: #d4dbe3;
  --text: #1c2633;
  --muted: #617080;
  --accent: #176b87;
  --accent-strong: #0f5268;
  --success: #2f7d57;
  --danger: #a33a32;
  --warning: #a96c10;
  --focus: #c78b1b;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-width: 320px;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

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

button {
  min-height: 36px;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 0 12px;
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
}

button:hover,
button.active {
  border-color: var(--accent);
  color: var(--accent);
}

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

button.primary {
  border-color: var(--accent);
  background: var(--accent);
  color: white;
}

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

button.danger:hover {
  border-color: var(--danger);
  color: var(--danger);
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  min-height: 76px;
  padding: 14px 20px;
  border-bottom: 1px solid var(--line);
  background: var(--surface);
}

.brand h1 {
  margin: 0;
  font-size: 24px;
  line-height: 1.1;
}

.brand p {
  margin: 4px 0 0;
  color: var(--muted);
}

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

.workspace {
  display: grid;
  grid-template-columns: minmax(230px, 300px) minmax(460px, 1fr) minmax(320px, 390px);
  min-height: calc(100vh - 76px);
}

.sidebar,
.markdown-panel {
  min-width: 0;
  background: var(--surface);
}

.sidebar {
  border-right: 1px solid var(--line);
}

.markdown-panel {
  display: grid;
  grid-template-rows: auto auto auto auto minmax(260px, 1fr) auto;
  border-left: 1px solid var(--line);
}

.sidebar-header,
.panel-title,
.version-title,
.validation-title,
.change-title,
.list-tools,
.tabs {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  min-height: 50px;
  padding: 10px 12px;
  border-bottom: 1px solid var(--line);
}

.version-title,
.validation-title {
  min-height: 44px;
}

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

.change-panel {
  border-top: 1px solid var(--line);
}

.change-selectors {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
  padding: 10px 12px;
  border-bottom: 1px solid var(--line);
}

.change-toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  padding: 10px 12px;
  border-bottom: 1px solid var(--line);
}

.change-toolbar button {
  min-height: 30px;
  padding: 0 9px;
  font-size: 12px;
  font-weight: 700;
}

.change-toolbar button:not(.active) {
  color: var(--muted);
  background: var(--surface-2);
}

.change-options {
  display: grid;
  grid-template-columns: minmax(120px, 1fr) auto auto;
  align-items: end;
}

.change-options label {
  font-size: 12px;
}

.change-options select {
  min-height: 32px;
}

.change-summary {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 6px;
  padding: 10px 12px;
  border-bottom: 1px solid var(--line);
  color: var(--muted);
  font-size: 12px;
}

.change-list {
  display: grid;
  gap: 8px;
  max-height: 220px;
  overflow: auto;
  padding: 10px 12px;
  color: var(--muted);
  font-size: 12px;
}

.change-group {
  display: grid;
  gap: 8px;
}

.change-group h3 {
  margin: 0;
  color: var(--text);
  font-size: 12px;
  letter-spacing: 0;
}

.change-item {
  display: grid;
  gap: 4px;
  padding: 8px;
  border-left: 3px solid var(--accent);
  background: #fbfcfd;
  color: var(--text);
}

.change-item[data-change="add"] {
  border-left-color: var(--success);
}

.change-item[data-change="remove"] {
  border-left-color: var(--danger);
}

.change-item[data-change="rename"],
.change-item[data-change="move"] {
  border-left-color: var(--warning);
}

.change-item p {
  margin: 0;
}

.change-item span,
.change-item small {
  color: var(--muted);
  overflow-wrap: anywhere;
}

.change-summary span {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.validation-summary {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 6px;
  padding: 10px 12px;
  border-bottom: 1px solid var(--line);
  color: var(--muted);
  font-size: 12px;
}

.validation-summary span {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.validation-report {
  display: grid;
  gap: 8px;
  max-height: 240px;
  overflow: auto;
  padding: 10px 12px;
}

.validation-bucket[data-bucket="required"] {
  border-left: 3px solid var(--danger);
}

.validation-bucket[data-bucket="recommended"] {
  border-left: 3px solid var(--warning);
}

.validation-bucket[data-bucket="maturity"] {
  border-left: 3px solid var(--accent);
}

.validation-report details {
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--surface);
}

.validation-report summary {
  display: grid;
  gap: 2px;
  min-height: 46px;
  padding: 8px 10px;
  cursor: pointer;
}

.validation-report summary span,
.validation-report summary small {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.validation-report summary small,
.validation-empty {
  color: var(--muted);
  font-size: 12px;
}

.validation-items {
  display: grid;
  gap: 8px;
  padding: 0 10px 10px;
}

.validation-item {
  display: grid;
  gap: 4px;
  padding: 8px;
  border-left: 3px solid var(--warning);
  background: #fbfcfd;
  font-size: 12px;
}

.validation-item[data-severity="error"] {
  border-left-color: var(--danger);
}

.validation-item strong,
.validation-item span,
.validation-item small {
  overflow-wrap: anywhere;
}

.validation-item p {
  margin: 0;
  color: var(--text);
}

.validation-item small {
  color: var(--muted);
}

.validation-empty {
  margin: 0;
}

.tabs {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  min-height: 50px;
  padding: 10px 12px;
  border-bottom: 1px solid var(--line);
}

.sidebar-header span {
  min-width: 28px;
  min-height: 24px;
  border-radius: 999px;
  background: var(--surface-2);
  color: var(--muted);
  display: grid;
  place-items: center;
  font-size: 12px;
  font-weight: 700;
}

.list-tools input {
  min-height: 36px;
}

.process-list {
  display: grid;
  align-content: start;
  gap: 6px;
  max-height: calc(100vh - 176px);
  overflow: auto;
  padding: 12px;
}

.process-list button {
  display: grid;
  justify-items: start;
  gap: 2px;
  height: auto;
  min-height: 70px;
  padding: 9px 10px;
  text-align: left;
}

.process-list span,
.process-list small,
.process-list time {
  width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.process-list small,
.process-list time,
.empty-list {
  color: var(--muted);
  font-size: 12px;
}

.empty-list {
  padding: 14px 4px;
}

.editor {
  min-width: 0;
  overflow: auto;
  padding: 18px;
}

.identity {
  display: grid;
  grid-template-columns: minmax(260px, 1fr) 180px;
  gap: 12px;
  margin-bottom: 16px;
}

label {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 650;
}

input,
select,
textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--surface);
  color: var(--text);
}

input,
select {
  min-height: 40px;
  padding: 0 10px;
}

textarea {
  min-height: 104px;
  resize: vertical;
  padding: 10px;
  line-height: 1.45;
}

input.invalid,
select.invalid,
textarea.invalid {
  border-color: var(--danger);
}

input:focus,
select:focus,
textarea:focus,
button:focus {
  outline: 2px solid var(--focus);
  outline-offset: 1px;
}

.sections {
  display: grid;
  grid-template-columns: repeat(2, minmax(260px, 1fr));
  gap: 14px;
}

.sections details {
  display: grid;
  align-content: start;
  gap: 10px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
}

.sections summary {
  display: flex;
  align-items: center;
  min-height: 34px;
  color: var(--text);
  font-size: 15px;
  font-weight: 750;
  cursor: pointer;
}

.sections summary::marker {
  color: var(--accent);
}

.section-body {
  display: grid;
  gap: 10px;
  padding-top: 10px;
}

.section-body.identity {
  margin-bottom: 0;
}

.section-help {
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fbfcfd;
}

.section-help summary {
  min-height: 32px;
  padding: 6px 8px;
  color: var(--accent);
  font-size: 13px;
  font-weight: 700;
}

.section-help div {
  display: grid;
  gap: 4px;
  padding: 0 8px 8px;
}

.section-help p {
  margin: 0;
  color: var(--text);
  font-size: 13px;
}

.section-help small {
  color: var(--muted);
  font-size: 12px;
}

.field-tools {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  justify-content: flex-end;
  margin-bottom: -2px;
}

.field-tools button {
  min-height: 28px;
  padding: 0 8px;
  color: var(--muted);
  font-size: 12px;
}

.list-field {
  min-height: 122px;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 13px;
}

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

.version-title {
  min-height: 44px;
}

.version-list {
  display: grid;
  gap: 6px;
  max-height: 170px;
  overflow: auto;
  padding: 10px 12px;
  color: var(--muted);
  font-size: 12px;
}

.version-list button {
  display: grid;
  justify-items: start;
  gap: 2px;
  height: auto;
  min-height: 54px;
  padding: 8px 10px;
  text-align: left;
}

.version-list span,
.version-list small {
  width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.tabs {
  justify-content: flex-start;
}

.tabs button {
  min-width: 88px;
}

#markdown-input,
#markdown-preview {
  min-height: 320px;
  height: 100%;
  margin: 0;
  border: 0;
  border-radius: 0;
  border-bottom: 1px solid var(--line);
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 13px;
  line-height: 1.45;
}

#markdown-input {
  resize: none;
}

#markdown-preview {
  overflow: auto;
  padding: 12px;
  white-space: pre-wrap;
  background: #fbfcfd;
}

.message {
  min-height: 52px;
  padding: 12px;
  color: var(--muted);
  background: var(--surface-2);
  border-top: 1px solid var(--line);
}

.message[data-tone="success"] {
  color: var(--success);
}

.message[data-tone="error"] {
  color: var(--danger);
}

@media (max-width: 1180px) {
  .workspace {
    grid-template-columns: 260px 1fr;
  }

  .markdown-panel {
    grid-column: 1 / -1;
    min-height: 420px;
    border-top: 1px solid var(--line);
    border-left: 0;
  }
}

@media (max-width: 780px) {
  .topbar,
  .workspace,
  .identity,
  .sections {
    display: block;
  }

  .topbar > * + *,
  .identity > * + *,
  .sections > * + * {
    margin-top: 12px;
  }

  .sidebar,
  .editor,
  .markdown-panel {
    border-left: 0;
    border-right: 0;
  }

  .process-list {
    max-height: none;
  }

  .editor {
    padding: 12px;
  }

  .actions {
    justify-content: stretch;
  }

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