:root {
  color-scheme: light;
  --bg: #ffffff;
  --surface: #ffffff;
  --surface-muted: #f7f7f5;
  --surface-hover: #f1f1ef;
  --border: #e6e4df;
  --border-strong: #d6d3cc;
  --text: #2f3437;
  --muted: #787774;
  --accent: #2f3437;
  --accent-dark: #17191a;
  --danger: #a33a3a;
  --warning-bg: #fff8df;
  --warning-border: #e4c760;
  --shadow: 0 18px 48px rgba(15, 23, 42, 0.18);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-size: 13px;
  line-height: 1.45;
}

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

a {
  color: inherit;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  padding: 14px 28px;
  background: rgba(255, 255, 255, 0.96);
  border-bottom: 1px solid var(--border);
  backdrop-filter: blur(10px);
}

.topbar h1 {
  font-size: 20px;
  font-weight: 650;
}

.topbar p,
.muted {
  color: var(--muted);
}

.top-actions,
.inline-actions,
.form-actions {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 32px;
  padding: 6px 12px;
  border: 1px solid var(--accent);
  border-radius: 5px;
  background: var(--accent);
  color: white;
  font: inherit;
  font-weight: 560;
  text-decoration: none;
  cursor: pointer;
}

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

.button.secondary {
  background: transparent;
  color: var(--text);
  border-color: var(--border);
}

.button.secondary:hover {
  background: var(--surface-hover);
}

.button.small {
  min-height: 31px;
  padding: 5px 10px;
  font-size: 13px;
}

.layout {
  display: grid;
  gap: 18px;
  padding: 18px 28px 48px;
}

.category-section,
.editor-section {
  background: var(--surface);
  border: 0;
  border-radius: 0;
  box-shadow: none;
}

.category-section {
  overflow: hidden;
  border-bottom: 1px solid var(--border);
}

.section-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 10px 0;
  border-bottom: 1px solid var(--border);
}

.section-heading.compact {
  padding: 0 0 16px;
  border-bottom: 0;
}

.section-heading h2,
.editor-section h2 {
  font-size: 16px;
  font-weight: 650;
}

.table-wrap {
  overflow-x: auto;
}

.case-table {
  width: max-content;
  min-width: 100%;
  border-collapse: collapse;
  table-layout: fixed;
}

.case-table th,
.case-table td {
  padding: 7px 10px;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
  text-align: left;
}

.case-table th {
  background: var(--surface);
  color: var(--muted);
  font-size: 12px;
  font-weight: 580;
  white-space: nowrap;
}

.case-table th:nth-child(1),
.case-table td:nth-child(1) {
  width: 58px;
}

.case-table th:nth-child(2),
.case-table td:nth-child(2),
.case-table th:nth-child(3),
.case-table td:nth-child(3) {
  width: 200px;
}

.case-table th:nth-child(5),
.case-table td:nth-child(5) {
  width: 92px;
}

.case-table th:nth-child(6),
.case-table td:nth-child(6) {
  width: 110px;
}

.case-table th:nth-child(7),
.case-table td:nth-child(7),
.case-table th:nth-child(8),
.case-table td:nth-child(8),
.case-table th:nth-child(9),
.case-table td:nth-child(9),
.case-table th:nth-child(10),
.case-table td:nth-child(10) {
  width: 76px;
}

.case-row {
  cursor: pointer;
}

.case-row:hover {
  background: var(--surface-hover);
}

.main-text,
.prompt-cell {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.case-id {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-weight: 720;
}

.chips-cell {
  display: flex;
  gap: 4px;
  flex-wrap: wrap;
}

.chip {
  display: inline-flex;
  align-items: center;
  min-height: 20px;
  padding: 1px 6px;
  border-radius: 4px;
  background: var(--surface-muted);
  color: var(--muted);
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 11px;
}

.badge {
  display: inline-flex;
  align-items: center;
  min-height: 22px;
  padding: 1px 7px;
  border-radius: 4px;
  font-size: 12px;
  font-weight: 580;
  background: var(--surface-muted);
  color: #344050;
}

.priority {
  background: #eef3f2;
  color: #32645f;
}

.status-draft {
  background: #f1f1ef;
}

.status-generated {
  background: #e9eff7;
  color: #2d5f8b;
}

.status-confirmed {
  background: #e8f1ec;
  color: #2f6b4f;
}

.status-pending {
  background: #f7eee3;
  color: #8a5a24;
}

.detail-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.1fr) minmax(320px, 0.9fr);
  gap: 24px;
}

.detail-grid h3,
.turn-editor-heading h3 {
  font-size: 14px;
  font-weight: 700;
  margin-bottom: 10px;
}

.turn-block {
  padding: 12px 0;
  border-top: 1px solid var(--border);
}

.turn-block:first-of-type {
  border-top: 0;
}

.turn-label {
  margin-bottom: 5px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.agent-output {
  color: var(--text);
}

.meta-list {
  display: grid;
  gap: 10px;
  margin: 0 0 16px;
}

.meta-list dt {
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.meta-list dd {
  margin: 0;
}

.schema-list {
  display: grid;
  gap: 6px;
}

pre {
  max-width: 100%;
  overflow: auto;
  margin: 0;
  padding: 10px;
  border: 0;
  border-radius: 5px;
  background: var(--surface-muted);
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 12px;
  line-height: 1.45;
}

.empty-state {
  padding: 15px 0 22px;
  color: var(--muted);
}

.form-layout {
  max-width: 1120px;
  margin: 0 auto;
  padding: 24px 28px 48px;
}

.context-form-layout {
  max-width: 1180px;
}

.alert {
  margin-bottom: 16px;
  padding: 12px 14px;
  border: 1px solid var(--warning-border);
  border-radius: 6px;
  background: var(--warning-bg);
  color: #5f4100;
}

form {
  display: grid;
  gap: 18px;
}

.form-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 14px;
  padding: 18px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.compact-form-grid {
  grid-template-columns: 150px minmax(280px, 1fr) 150px;
  padding: 0 0 18px;
  border: 0;
  border-bottom: 1px solid var(--border);
  border-radius: 0;
  box-shadow: none;
}

.editor-section {
  display: grid;
  gap: 16px;
  padding: 18px;
}

.context-editor {
  gap: 20px;
  padding: 0;
}

.context-block {
  display: grid;
  gap: 10px;
  padding: 10px 0 18px;
  border-bottom: 1px solid var(--border);
}

.context-block-heading,
.context-row-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.context-block-heading h2 {
  font-size: 15px;
  font-weight: 650;
}

.context-field-grid,
.context-row-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(170px, 1fr));
  gap: 10px;
}

.context-row-grid.two-plus {
  grid-template-columns: minmax(120px, 0.5fr) minmax(260px, 1fr);
}

.context-list {
  display: grid;
  gap: 0;
}

.context-row {
  display: grid;
  gap: 10px;
  padding: 10px 0;
  border-top: 1px solid var(--border);
}

.context-row:first-child {
  border-top: 0;
}

.compact-list {
  gap: 8px;
}

.compact-list .context-row {
  border-top: 0;
}

.note-row {
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: start;
  padding: 0;
}

.row-kicker {
  color: var(--muted);
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 11px;
  font-weight: 650;
}

.json-preview {
  padding: 0 0 8px;
}

.json-preview summary {
  width: fit-content;
  margin-bottom: 10px;
  color: var(--muted);
  font-weight: 650;
  cursor: pointer;
}

.json-error {
  color: var(--danger);
  font-size: 12px;
}

label {
  display: grid;
  gap: 6px;
}

label span {
  color: #344050;
  font-size: 12px;
  font-weight: 720;
}

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

input,
select {
  min-height: 38px;
  padding: 7px 10px;
}

textarea {
  resize: vertical;
  padding: 10px;
}

input:focus,
select:focus,
textarea:focus {
  outline: 2px solid rgba(33, 104, 105, 0.18);
  border-color: var(--accent);
}

select:disabled,
input:disabled {
  background: var(--surface-muted);
  color: var(--muted);
}

.turn-editor {
  display: grid;
  gap: 12px;
  padding: 14px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #fbfcfd;
}

.turn-editor + .turn-editor {
  margin-top: 12px;
}

.turn-editor-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.checkbox-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 8px;
}

.checkbox-row {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  padding: 7px 8px;
  border-radius: 5px;
  background: var(--surface-muted);
}

.checkbox-row input {
  width: auto;
  min-height: auto;
  margin-top: 3px;
}

.checkbox-row span {
  display: grid;
  gap: 2px;
}

.checkbox-row strong {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 12px;
}

.checkbox-row small {
  color: var(--muted);
}

.text-link {
  border: 0;
  background: transparent;
  color: var(--accent);
  font: inherit;
  font-weight: 650;
  text-decoration: none;
  cursor: pointer;
}

.text-link:hover {
  text-decoration: underline;
}

.text-link.danger {
  color: var(--danger);
}

.form-actions {
  justify-content: flex-end;
  padding: 0 0 8px;
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: grid;
  place-items: center;
  padding: 28px;
  background: rgba(15, 15, 15, 0.28);
}

.modal-backdrop[hidden] {
  display: none;
}

.modal-shell {
  position: relative;
  width: min(980px, 100%);
  max-height: min(82vh, 860px);
  overflow: auto;
  padding: 22px 24px;
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.modal-close {
  position: absolute;
  top: 12px;
  right: 12px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  border: 0;
  border-radius: 4px;
  background: transparent;
  color: var(--muted);
  font: inherit;
  font-size: 20px;
  cursor: pointer;
}

.modal-close:hover {
  background: var(--surface-hover);
  color: var(--text);
}

.modal-body {
  display: grid;
  gap: 18px;
}

.modal-heading {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 18px;
  padding-right: 28px;
}

.modal-kicker {
  margin-bottom: 5px;
  color: var(--muted);
  font-size: 12px;
}

.modal-heading h2 {
  max-width: 680px;
  font-size: 20px;
  font-weight: 650;
  line-height: 1.35;
}

.modal-badges,
.modal-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.modal-actions {
  justify-content: flex-end;
  padding-top: 4px;
}

.neutral {
  color: var(--muted);
}

@media (max-width: 880px) {
  .topbar,
  .section-heading {
    align-items: flex-start;
    flex-direction: column;
  }

  .detail-grid,
  .form-grid {
    grid-template-columns: 1fr;
  }

  .modal-heading {
    flex-direction: column;
  }

  .modal-shell {
    max-height: 88vh;
    padding: 20px;
  }
}
