* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: -apple-system, "Segoe UI", Roboto, sans-serif;
  background: #f6f7f9;
  color: #222;
}
header {
  background: #fff;
  padding: 10px 20px;
  border-bottom: 1px solid #e3e6ea;
}
header h1 { margin: 0; font-size: 18px; }
.badge {
  font-size: 11px; background: #d62728; color: #fff;
  padding: 2px 6px; border-radius: 4px; vertical-align: middle;
}

.layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 12px;
  padding: 12px;
  align-items: start;
}

.diagram-panel, .controls-panel {
  background: #fff;
  border: 1px solid #e3e6ea;
  border-radius: 8px;
  padding: 10px;
}

/* Диаграмма: адаптивная ширина и ограничение высоты */
#diagram {
  width: 100%;
  height: 100%;
  max-height: 80vh; /* Диаграмма занимает до 80% высоты экрана */
  object-fit: contain;
  display: block;
}

.top-fields {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 6px;
  margin-bottom: 10px;
}
.top-fields label {
  display: flex;
  flex-direction: column;
  font-size: 11px;
  color: #555;
}
.top-fields input {
  width: 100%;
  padding: 4px 5px;
  font-size: 12px;
  border: 1px solid #ccd2d8;
  border-radius: 4px;
  text-align: center;
}

/* Таблица: прокручивается, чтобы не ломать макет */
.table-wrap {
  max-height: 65vh; /* Было 55vh, теперь 65vh */
  overflow: auto;
  border: 1px solid #e3e6ea;
  border-radius: 6px;
}
table { width: 100%; border-collapse: collapse; font-size: 11px; }
thead th {
  position: sticky; top: 0; z-index: 1;
  background: #f1f3f6;
  padding: 5px 3px;
  border-bottom: 1px solid #e3e6ea;
  text-align: center;
  font-weight: 600;
  white-space: nowrap;
}
tbody td { padding: 2px; text-align: center; border-bottom: 1px solid #f0f2f5; }
tbody input, tbody select {
  width: 100%;
  padding: 3px 3px;
  border: 1px solid #e0e4e9;
  border-radius: 3px;
  font-size: 11px;
  text-align: center;
}
tbody input:disabled, tbody select:disabled {
  background-color: #f0f2f5;
  color: #a0a0a0;
  cursor: not-allowed;
}
tbody tr:nth-child(even) { background: #fafbfc; }

.buttons {
  display: flex; flex-wrap: wrap; gap: 6px; margin-top: 10px;
}
button, .file-btn {
  padding: 7px 12px;
  border: 1px solid #ccd2d8;
  background: #fff;
  border-radius: 6px;
  font-size: 12px;
  cursor: pointer;
}
button.primary { background: #d62728; color: #fff; border-color: #b71c1c; }
button:hover, .file-btn:hover { background: #eef1f4; }
button.primary:hover { background: #b71c1c; }

#messages { margin-top: 10px; }
#messages .msg {
  padding: 5px 9px;
  border-radius: 4px;
  margin-bottom: 5px;
  font-size: 12px;
}
.msg.err { background: #fdecea; color: #b71c1c; }
.msg.ok  { background: #e7f5ea; color: #1b5e20; }

@media (max-width: 1100px) {
  .layout { grid-template-columns: 1fr; }
  .table-wrap { max-height: none; }
  #diagram { max-height: none; }
}