:root {
  --bg: #eef1f4;
  --surface: #ffffff;
  --surface-muted: #f7f8fa;
  --line: #d6dbe1;
  --line-strong: #aeb7c2;
  --text: #17202a;
  --muted: #647181;
  --blue: #2563eb;
  --green: #12805c;
  --amber: #b7791f;
  --red: #b42318;
  --red-bg: #fff1f0;
  --shadow: 0 8px 22px rgba(22, 29, 38, 0.08);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  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 {
  border: 1px solid transparent;
  cursor: pointer;
}

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

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

.topbar h1 {
  margin: 0;
  font-size: 20px;
  line-height: 1.2;
}

.topbar p {
  margin: 3px 0 0;
  color: var(--muted);
  font-size: 13px;
}

.topbar-actions,
.action-row,
.block-head,
.check-row,
.layout-meta,
.legend,
.tabs {
  display: flex;
  align-items: center;
  gap: 8px;
}

.workspace {
  display: grid;
  grid-template-columns: minmax(360px, 440px) 1fr;
  min-height: calc(100vh - 73px);
}

.input-panel {
  overflow: auto;
  max-height: calc(100vh - 73px);
  padding: 16px;
  border-right: 1px solid var(--line);
  background: #f9fafb;
}

.results-panel {
  overflow: auto;
  max-height: calc(100vh - 73px);
  padding: 18px;
}

.panel-block,
.layout-card,
.raw-section,
.empty-state,
.error-box {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.panel-block {
  margin-bottom: 14px;
  padding: 14px;
}

.block-head {
  justify-content: space-between;
  margin-bottom: 10px;
}

h2 {
  margin: 0;
  font-size: 15px;
  line-height: 1.3;
}

.rows {
  display: grid;
  gap: 10px;
}

.data-row {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--surface-muted);
}

.data-row .wide {
  grid-column: 1 / -1;
}

.data-row .row-actions {
  grid-column: 1 / -1;
  display: flex;
  justify-content: flex-end;
}

label {
  display: grid;
  gap: 4px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 600;
}

input,
select,
textarea {
  width: 100%;
  min-height: 34px;
  border: 1px solid var(--line-strong);
  border-radius: 6px;
  background: var(--surface);
  color: var(--text);
  padding: 7px 9px;
  outline: none;
}

input:focus,
select:focus,
textarea:focus {
  border-color: var(--blue);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.12);
}

input.field-invalid,
select.field-invalid,
textarea.field-invalid {
  border-color: #dc2626;
  background: #fff7f6;
  box-shadow: 0 0 0 3px rgba(220, 38, 38, 0.12);
}

.field-invalid-label {
  color: #b42318;
}

.field-error-message {
  color: #b42318;
  font-size: 11px;
  font-weight: 700;
  line-height: 1.25;
}

textarea {
  min-height: 190px;
  resize: vertical;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 12px;
  line-height: 1.45;
}

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

.check-row {
  flex-wrap: wrap;
  margin-top: 10px;
}

.check-row label {
  display: flex;
  align-items: center;
  gap: 6px;
  min-height: 28px;
  color: var(--text);
  font-weight: 500;
}

.check-row input {
  width: 16px;
  min-height: 16px;
}

.primary-button,
.secondary-button,
.small-button,
.danger-button,
.link-button {
  min-height: 34px;
  border-radius: 6px;
  padding: 7px 11px;
  font-weight: 700;
  text-decoration: none;
}

.primary-button {
  flex: 1;
  background: var(--blue);
  color: #fff;
}

.secondary-button,
.small-button,
.link-button {
  border-color: var(--line-strong);
  background: var(--surface);
  color: var(--text);
}

.danger-button {
  border-color: #f1b5ae;
  background: #fff;
  color: var(--red);
}

.link-button {
  display: inline-flex;
  align-items: center;
}

.small-button,
.danger-button {
  min-height: 30px;
  padding: 5px 9px;
  font-size: 12px;
}

.status {
  display: inline-flex;
  align-items: center;
  min-height: 28px;
  border-radius: 999px;
  padding: 4px 10px;
  font-size: 12px;
  font-weight: 800;
}

.status-ok {
  background: #e7f6ef;
  color: var(--green);
}

.status-error {
  background: var(--red-bg);
  color: var(--red);
}

.status-pending {
  background: #fff7e6;
  color: var(--amber);
}

.hidden {
  display: none !important;
}

.empty-state {
  padding: 36px;
  text-align: center;
}

.empty-state h2 {
  font-size: 18px;
}

.empty-state p {
  margin: 8px 0 0;
  color: var(--muted);
}

.error-box {
  margin-bottom: 14px;
  padding: 14px;
  border-color: #f1b5ae;
  background: var(--red-bg);
  color: var(--red);
  font-weight: 700;
}

.error-box ul {
  margin: 8px 0 0;
  padding-left: 18px;
}

.error-box li + li {
  margin-top: 4px;
}

.summary-grid {
  display: grid;
  grid-template-columns: repeat(5, minmax(120px, 1fr));
  gap: 10px;
  margin-bottom: 14px;
}

.metric {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  padding: 12px;
  box-shadow: var(--shadow);
}

.metric span {
  display: block;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.metric strong {
  display: block;
  margin-top: 5px;
  font-size: 20px;
}

.layouts {
  display: grid;
  gap: 16px;
}

.layout-card {
  padding: 14px;
}

.layout-head {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 10px;
}

.layout-head h2 {
  font-size: 16px;
}

.layout-meta {
  flex-wrap: wrap;
  justify-content: flex-end;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.drawing-wrap {
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #f5f7fa;
  padding: 10px;
}

.layout-svg {
  display: block;
  width: 100%;
  min-width: 560px;
  height: auto;
  max-height: 620px;
}

.layout-svg text {
  pointer-events: none;
  font-family: Inter, ui-sans-serif, system-ui, sans-serif;
}

.legend {
  flex-wrap: wrap;
  margin: 10px 0;
  color: var(--muted);
  font-size: 12px;
}

.legend-item {
  display: inline-flex;
  align-items: center;
  gap: 5px;
}

.swatch {
  width: 12px;
  height: 12px;
  border-radius: 3px;
  border: 1px solid rgba(23, 32, 42, 0.28);
}

.layout-details {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  margin-top: 10px;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 12px;
}

th,
td {
  padding: 7px 8px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  white-space: nowrap;
}

th {
  color: var(--muted);
  font-size: 11px;
}

.table-wrap {
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 6px;
}

.raw-section {
  margin-top: 16px;
  padding: 14px;
}

.raw-json {
  overflow: auto;
  max-height: 360px;
  margin: 0;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #111827;
  color: #f9fafb;
  font-size: 12px;
  line-height: 1.5;
}

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

  .input-panel,
  .results-panel {
    max-height: none;
  }

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

  .summary-grid {
    grid-template-columns: repeat(2, minmax(120px, 1fr));
  }

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

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

  .summary-grid,
  .data-row,
  .settings-grid {
    grid-template-columns: 1fr;
  }

  .layout-head {
    flex-direction: column;
  }

  .layout-meta {
    justify-content: flex-start;
  }
}
