:root {
  color-scheme: light;
  --bg: #f5f7f9;
  --panel: #ffffff;
  --text: #1f2933;
  --muted: #667085;
  --line: #d8dee6;
  --primary: #1769aa;
  --primary-dark: #10507f;
  --danger: #b42318;
  --control-height: 40px;
  --control-radius: 6px;
  --control-padding-x: 12px;
  --form-gap: 12px;
  --field-label-width: 176px;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

.hidden {
  display: none !important;
}

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

button {
  border: 1px solid var(--line);
  background: #fff;
  border-radius: var(--control-radius);
  min-height: var(--control-height);
  padding: 0 14px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  line-height: 1.2;
  white-space: nowrap;
}

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

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

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

#app {
  display: flex;
  min-height: 100vh;
}

.login-view {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: #eef3f7;
}

.login-card {
  width: min(420px, 100%);
  display: grid;
  gap: 16px;
  padding: 24px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: 0 12px 36px rgba(16, 24, 40, 0.1);
}

.login-title {
  font-size: 24px;
  font-weight: 750;
}

.login-subtitle {
  margin-top: 6px;
  color: var(--muted);
  font-size: 13px;
}

.form-error {
  min-height: 18px;
  color: var(--danger);
  font-size: 13px;
}

.sidebar {
  width: 248px;
  background: #17212b;
  color: #e6edf3;
  padding: 20px 16px;
  flex-shrink: 0;
}

.brand {
  padding: 6px 4px 20px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.12);
}

.brand-title {
  font-size: 18px;
  font-weight: 700;
}

.user-panel {
  display: grid;
  gap: 8px;
  padding: 14px 4px 0;
  color: #cfd8e3;
  font-size: 13px;
}

.user-panel strong {
  color: #fff;
}

.user-panel button {
  justify-content: flex-start;
  min-height: 34px;
  padding: 0 10px;
  border-color: rgba(255, 255, 255, 0.18);
  color: #e6edf3;
  background: rgba(255, 255, 255, 0.04);
}

.nav {
  display: grid;
  gap: 6px;
  margin-top: 18px;
}

.nav button {
  text-align: left;
  background: transparent;
  color: #d4dde6;
  border: 0;
  padding: 10px 12px;
}

.nav button.active {
  background: #263646;
  color: #fff;
}

.main {
  flex: 1;
  padding: 24px;
  overflow: auto;
  min-width: 0;
}

.toolbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 18px;
  margin-bottom: 18px;
}

.toolbar > div:first-child {
  min-width: 0;
}

.toolbar h1 {
  margin: 0;
  font-size: 28px;
}

.toolbar-actions {
  display: flex;
  flex: 0 0 auto;
  align-items: center;
  gap: var(--form-gap);
}

.toolbar-actions select {
  width: 300px;
}

.toolbar-actions button {
  min-width: 96px;
  white-space: nowrap;
}

.grid {
  display: grid;
  grid-template-columns: minmax(320px, 420px) minmax(0, 1fr);
  gap: 18px;
  align-items: start;
}

.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 16px;
  box-shadow: 0 1px 2px rgba(16, 24, 40, 0.04);
}

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

.panel-header h2 {
  margin: 0;
  font-size: 17px;
}

.entity-list {
  display: grid;
  gap: 8px;
}

.entity-card {
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 10px;
  cursor: pointer;
}

.entity-card:hover,
.entity-card.active {
  border-color: var(--primary);
  background: #f0f7fc;
}

.entity-title {
  font-weight: 650;
}

.entity-meta {
  margin-top: 6px;
  color: var(--muted);
  font-size: 12px;
}

.entity-summary {
  margin-top: 5px;
  color: #475467;
  font-size: 13px;
  line-height: 1.45;
}

.form {
  display: grid;
  gap: var(--form-gap);
}

.compact-form {
  margin-bottom: 14px;
}

label {
  display: grid;
  gap: 6px;
  color: #344054;
  font-size: 13px;
  font-weight: 600;
  line-height: 20px;
  min-width: 0;
}

input,
select,
textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: var(--control-radius);
  padding: 0 var(--control-padding-x);
  background: #fff;
  color: var(--text);
  min-width: 0;
}

input,
select {
  height: var(--control-height);
  line-height: var(--control-height);
}

textarea {
  resize: vertical;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 13px;
  line-height: 1.5;
  min-height: 96px;
  padding-top: 9px;
  padding-bottom: 9px;
}

input[type="checkbox"] {
  width: 16px;
  height: 16px;
  min-width: 16px;
  padding: 0;
  accent-color: var(--primary);
}

.form-row {
  display: grid;
  gap: var(--form-gap);
  align-items: start;
}

.form-row.two {
  grid-template-columns: 1fr 1fr;
}

.form-row.three {
  grid-template-columns: 1fr 1fr 1fr;
}

.form-row.two > label,
.form-row.three > label {
  min-height: 66px;
}

.form-row.two.form-row-module {
  grid-template-columns: 1fr 1fr;
}

.readonly-control {
  display: flex;
  align-items: center;
  height: var(--control-height);
  border: 1px solid var(--line);
  border-radius: var(--control-radius);
  background: #f8fafc;
  color: var(--text);
  font-weight: 600;
  padding: 0 var(--control-padding-x);
  min-width: 0;
}

.form-actions {
  display: flex;
  gap: var(--form-gap);
  align-items: center;
}

.form-actions button {
  min-width: 88px;
}

.save-status {
  color: var(--muted);
  font-size: 13px;
}

.metadata-box {
  border: 1px solid #d8e3ee;
  background: #fbfdff;
  border-radius: 8px;
  padding: 12px;
}

.metadata-box summary {
  cursor: pointer;
  color: #175cd3;
  font-weight: 650;
}

.typed-fields-wrap {
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: hidden;
}

.typed-fields-title {
  background: #f8fafc;
  border-bottom: 1px solid var(--line);
  padding: 10px var(--control-padding-x);
  font-weight: 650;
}

.typed-fields {
  display: grid;
}

.field-row {
  display: grid;
  grid-template-columns: var(--field-label-width) minmax(0, 1fr);
  border-bottom: 1px solid var(--line);
  min-height: 57px;
}

.field-row:last-child {
  border-bottom: 0;
}

.field-row-wide {
  grid-template-columns: var(--field-label-width) minmax(0, 1fr);
}

.field-row > label {
  display: flex;
  align-items: center;
  padding: 10px var(--control-padding-x);
  background: #fbfcfd;
  border-right: 1px solid var(--line);
  font-weight: 600;
  min-height: 56px;
}

.field-row > div {
  padding: 8px;
  min-width: 0;
}

.field-row input,
.field-row select,
.field-row textarea {
  border-color: #cfd6df;
}

.fact-table {
  display: grid;
  gap: 8px;
}

.fact-table-head,
.fact-table-row {
  display: grid;
  grid-template-columns: minmax(150px, 0.9fr) minmax(300px, 1.6fr) minmax(180px, 1fr) 88px;
  gap: 8px;
  align-items: center;
}

.fact-table-head {
  color: var(--muted);
  font-size: 12px;
  font-weight: 650;
  padding: 0 2px;
  min-height: 24px;
}

.fact-table-rows {
  display: grid;
  gap: 8px;
}

.fact-delete {
  color: var(--danger);
  border-color: #f3b4ae;
  padding: 0 10px;
  width: 88px;
}

.fact-add {
  justify-self: start;
  min-width: 96px;
}

.publish-panel {
  margin-top: 18px;
}

.publish-summary {
  display: grid;
  gap: 6px;
  margin-bottom: 12px;
  padding: 12px;
  border: 1px solid #cfe2f3;
  background: #f2f8fd;
  border-radius: 8px;
}

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

.advanced {
  margin-bottom: 12px;
}

.advanced summary {
  cursor: pointer;
  color: var(--primary);
  margin-bottom: 10px;
}

.publish-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.checkbox {
  display: flex;
  align-items: center;
  gap: 8px;
  padding-top: 24px;
  font-weight: 400;
  line-height: 1.4;
}

.publish-result {
  margin: 12px 0 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 14px;
  background: #fff;
}

.publish-result.empty {
  color: var(--muted);
}

.publish-result.success {
  border-color: #98d5b3;
  background: #f2fbf6;
}

.publish-result.failure {
  border-color: #f0b8b1;
  background: #fff5f4;
}

.publish-result.loading {
  border-color: #b7d7f0;
  background: #f3f9fe;
}

.publish-result.history {
  background: #fbfcfd;
}

.result-head {
  display: flex;
  align-items: flex-start;
  gap: 12px;
}

.status-icon,
.status-dot {
  width: 28px;
  height: 28px;
  border-radius: 999px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  font-weight: 800;
}

.status-icon.success {
  color: #05603a;
  background: #d1fadf;
}

.status-icon.failure {
  color: #b42318;
  background: #fee4e2;
}

.status-icon.info {
  color: #175cd3;
  background: #dbeafe;
}

.status-dot {
  background: #2e90fa;
  animation: pulse 1s infinite ease-in-out;
}

@keyframes pulse {
  0% { opacity: 0.35; transform: scale(0.88); }
  50% { opacity: 1; transform: scale(1); }
  100% { opacity: 0.35; transform: scale(0.88); }
}

.result-title {
  font-weight: 750;
  font-size: 16px;
}

.result-subtitle {
  margin-top: 4px;
  color: var(--muted);
}

.result-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
  margin-top: 14px;
}

.result-grid div {
  border: 1px solid rgba(16, 24, 40, 0.08);
  border-radius: 6px;
  background: rgba(255, 255, 255, 0.68);
  padding: 10px;
  min-width: 0;
}

.result-grid span {
  display: block;
  color: var(--muted);
  font-size: 12px;
}

.result-grid strong {
  display: block;
  margin-top: 5px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.result-details {
  margin-top: 12px;
}

.result-details summary {
  cursor: pointer;
  color: var(--primary);
}

.result-details pre {
  margin: 10px 0 0;
  padding: 12px;
  background: #0f1720;
  color: #d7e5f2;
  border-radius: 6px;
  max-height: 260px;
  overflow: auto;
}

.history-list {
  display: grid;
  gap: 8px;
  margin-top: 12px;
}

.history-item {
  display: grid;
  grid-template-columns: 1.1fr 1.6fr 1fr 0.8fr;
  gap: 10px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  padding: 9px 10px;
}

.history-item span {
  color: var(--muted);
}

.request-list {
  display: grid;
  gap: 10px;
  margin-top: 12px;
}

.request-card {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  padding: 12px;
}

.request-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
}

.status-badge {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  padding: 0 8px;
  border-radius: 999px;
  background: #eef4ff;
  color: #175cd3;
  font-size: 12px;
  white-space: nowrap;
}

.token-value {
  user-select: all;
  overflow-wrap: anywhere;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 12px;
}

.role-list {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 8px;
}

.role-pill {
  display: inline-flex;
  align-items: center;
  min-height: 22px;
  padding: 0 8px;
  border: 1px solid #d8e3ee;
  border-radius: 999px;
  color: #344054;
  background: #fbfdff;
  font-size: 12px;
}

.request-card {
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  padding: 12px;
}

.request-head {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: center;
}

.status-badge {
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 3px 9px;
  font-size: 12px;
  color: var(--muted);
  white-space: nowrap;
}

.request-details {
  margin-top: 10px;
}

.request-details summary {
  cursor: pointer;
  color: var(--primary);
  font-weight: 650;
}

.request-details pre {
  margin: 10px 0 0;
  padding: 12px;
  border-radius: 6px;
  background: #0f1720;
  color: #d7e5f2;
  max-height: 260px;
  overflow: auto;
}

.request-actions {
  margin-top: 12px;
}

@media (max-width: 980px) {
  #app {
    display: block;
  }
  .sidebar {
    width: auto;
  }
  .grid,
  .publish-grid {
    grid-template-columns: 1fr;
  }
  .toolbar-actions {
    width: 100%;
  }
  .toolbar-actions select {
    width: 100%;
  }
  .form-row.two,
  .form-row.three,
  .form-row.two.form-row-module {
    grid-template-columns: 1fr;
  }
  .field-row {
    grid-template-columns: 1fr;
  }
  .fact-table-head {
    display: none;
  }
  .fact-table-row {
    grid-template-columns: 1fr;
    border: 1px solid var(--line);
    border-radius: 6px;
    padding: 8px;
    background: #fbfcfd;
  }
  .field-row > label {
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }
  .result-grid,
  .history-item {
    grid-template-columns: 1fr;
  }
  .toolbar {
    display: grid;
  }
}
