:root {
  --bg: #f3f4f6;
  --panel: #ffffff;
  --line: #d1d5db;
  --text: #111827;
  --muted: #6b7280;
  --accent: #2563eb;
  --danger: #dc2626;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: Arial, Helvetica, sans-serif;
  background: var(--bg);
  color: var(--text);
}

.app {
  max-width: 1500px;
  margin: 0 auto;
  padding: 20px;
}

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 20px;
  margin-bottom: 18px;
}

.topbar h1,
.panel h2 {
  margin: 0 0 8px;
}

.topbar p,
.hint {
  margin: 0;
  color: var(--muted);
  line-height: 1.4;
}

.layout {
  display: grid;
  grid-template-columns: 560px 1fr;
  gap: 18px;
  align-items: start;
}

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

.criteria-list,
.objects-controls {
  display: grid;
  gap: 12px;
  margin-bottom: 10px;
}

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

.criterion-header,
.plot-header,
.topbar-actions,
.row-actions {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
}

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

label {
  display: grid;
  gap: 6px;
  font-size: 14px;
}

input[type="text"],
input[type="number"] {
  width: 100%;
  padding: 9px 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  font-size: 14px;
}

input[type="range"] {
  width: 100%;
}

button {
  border: none;
  background: var(--accent);
  color: white;
  padding: 10px 14px;
  border-radius: 10px;
  cursor: pointer;
  font-size: 14px;
}

button.secondary {
  background: #e5e7eb;
  color: #111827;
}

button.danger {
  background: var(--danger);
}

.table-wrap {
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 12px;
  margin-top: 10px;
}

table {
  width: 100%;
  border-collapse: collapse;
  min-width: 520px;
}

th,
td {
  border-bottom: 1px solid var(--line);
  padding: 8px;
  text-align: center;
}

th {
  position: sticky;
  top: 0;
  background: #f9fafb;
}

.matrix-name-input {
  min-width: 120px;
}

.matrix-value-input {
  width: 70px;
  text-align: center;
}

.plot-panel {
  min-height: 760px;
}

.plot-wrapper {
  margin-top: 14px;
  border: 1px solid var(--line);
  background: #fcfcfc;
  border-radius: 14px;
  overflow: hidden;
}

svg {
  display: block;
  width: 100%;
  height: 100%;
}

.object-row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 10px;
  align-items: end;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #fafafa;
}

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

  .plot-wrapper {
    width: 100% !important;
    height: auto !important;
    aspect-ratio: 1 / 1;
  }
}

.message {
  display: none;
  margin-bottom: 16px;
  padding: 12px 14px;
  border-radius: 12px;
  border: 1px solid transparent;
  font-size: 14px;
}

.message.is-visible {
  display: block;
}

.message.is-success {
  background: #ecfdf5;
  border-color: #86efac;
  color: #166534;
}

.message.is-error {
  background: #fef2f2;
  border-color: #fca5a5;
  color: #991b1b;
}

.checkbox-label {
  display: flex;
  align-items: center;
  gap: 8px;
  white-space: nowrap;
  margin-top: 20px;
}

.analysis-table {
  width: 100%;
  border-collapse: collapse;
  margin: 12px 0 24px;
  font-size: 14px;
}

.analysis-table th,
.analysis-table td {
  border: 1px solid #d9dde3;
  padding: 8px 10px;
  text-align: left;
  vertical-align: top;
}

.analysis-table th {
  background: #f3f4f6;
}

.analysis-cards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 12px;
  margin: 10px 0 24px;
}

.analysis-card {
  border: 1px solid #d9dde3;
  border-radius: 12px;
  padding: 12px 14px;
  background: #fafafa;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.analysis-card span {
  font-size: 18px;
  font-weight: 700;
}

.plot-options {
  display: grid;
  gap: 12px;
  min-width: 280px;
}

#autoArrangeBtn {
  white-space: nowrap;
}

.auto-layout-notice {
  margin-top: 12px;
  padding: 12px 14px;
  border-radius: 12px;
  border: 1px solid #cbd5e1;
  background: #f8fafc;
  color: #334155;
  display: grid;
  gap: 6px;
  font-size: 14px;
  line-height: 1.45;
}

.auto-layout-notice strong {
  display: block;
  color: #0f172a;
}

.auto-layout-notice.is-ok {
  background: #ecfdf5;
  border-color: #86efac;
  color: #166534;
}

.auto-layout-notice.is-warning {
  background: #fffbeb;
  border-color: #fcd34d;
  color: #92400e;
}