:root {
  --bg: #f3f5f7;
  --panel: #ffffff;
  --text: #17202a;
  --muted: #64707d;
  --line: #d8dee6;
  --accent: #0b6bcb;
  --accent-dark: #0757a6;
  --danger: #b42318;
  --soft: #eef5fc;
  --ok: #117a37;
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
  font-family: Arial, Helvetica, sans-serif;
  line-height: 1.45;
}

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

h1 {
  font-size: 28px;
  line-height: 1.15;
}

h2 {
  font-size: 20px;
}

h3 {
  font-size: 15px;
  margin-bottom: 10px;
}

h4 {
  font-size: 16px;
}

h5 {
  margin: 16px 0 8px;
  font-size: 14px;
}

.login-screen {
  display: grid;
  min-height: 100vh;
  place-items: center;
  padding: 20px;
}

.login-card {
  display: grid;
  width: min(420px, 100%);
  gap: 14px;
  padding: 24px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
}

.app-shell {
  width: min(1500px, calc(100vw - 32px));
  margin: 0 auto;
  padding: 24px 0 40px;
}

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

.nav-tabs,
.result-tabs,
.top-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
}

.nav-tabs {
  margin-top: 14px;
}

.top-actions {
  justify-content: flex-end;
}

.user-pill,
.status {
  min-height: 38px;
  padding: 8px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  color: var(--muted);
}

.status {
  min-width: 130px;
  text-align: center;
}

.status.busy {
  color: var(--accent);
  border-color: #9cc9f3;
  background: var(--soft);
}

.status.error {
  color: var(--danger);
  border-color: #f1b3ad;
  background: #fff3f1;
}

.view {
  display: none;
}

.view.active {
  display: block;
}

.workspace {
  display: grid;
  grid-template-columns: minmax(440px, 0.7fr) minmax(680px, 1.3fr);
  gap: 16px;
  align-items: start;
}

.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 18px;
}

.section-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 16px;
}

.group {
  padding: 14px 0;
  border-top: 1px solid var(--line);
}

.group:first-of-type {
  border-top: 0;
  padding-top: 0;
}

.grid,
.load-grid {
  display: grid;
  gap: 10px;
}

.grid.three {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

.grid.two {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.load-grid {
  grid-template-columns: repeat(4, minmax(0, 1fr));
}

.load-item {
  display: grid;
  gap: 8px;
}

label {
  display: grid;
  gap: 5px;
  color: #334151;
  font-size: 13px;
  font-weight: 600;
}

.check-row {
  display: flex;
  align-items: center;
  gap: 8px;
}

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

input,
select {
  width: 100%;
  min-height: 38px;
  border: 1px solid #c7d0da;
  border-radius: 6px;
  padding: 8px 10px;
  background: #fff;
  color: var(--text);
  font: inherit;
}

.title-input {
  width: min(360px, 100%);
  margin-top: 10px;
}

input:focus,
select:focus {
  outline: 2px solid #a8d0f5;
  border-color: var(--accent);
}

.actions,
.row-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.actions {
  padding-top: 16px;
  border-top: 1px solid var(--line);
}

button {
  min-height: 40px;
  border: 1px solid var(--accent);
  border-radius: 6px;
  padding: 9px 14px;
  background: var(--accent);
  color: #fff;
  font: inherit;
  font-weight: 700;
  cursor: pointer;
}

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

button.secondary,
button.ghost,
.nav-tab,
.result-tab {
  background: #fff;
  color: var(--accent);
}

button.secondary:hover,
button.ghost:hover,
.nav-tab:hover,
.result-tab:hover {
  background: var(--soft);
}

.nav-tab.active,
.result-tab.active {
  background: var(--accent);
  color: #fff;
}

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

button.danger {
  border-color: #d92d20;
  background: #d92d20;
  color: #fff;
}

button.danger:hover {
  background: #b42318;
}

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

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

.metrics {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 10px;
  margin-bottom: 18px;
}

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

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

.metric strong {
  display: block;
  margin-top: 4px;
  font-size: 18px;
}

.result-block {
  padding-top: 18px;
  margin-top: 18px;
  border-top: 1px solid var(--line);
}

.selected-grid,
.scheme-grid,
.variant-results {
  display: grid;
  gap: 12px;
}

.selected-grid {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.scheme-grid {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

.variant-card,
.calc-variant,
.scheme-card {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfcfe;
  padding: 12px;
}

.scheme-card.accepted {
  border-color: #9cc9f3;
  background: #f7fbff;
}

.variant-card-head,
.calc-variant-head,
.scheme-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
}

.variant-card-head,
.scheme-head {
  margin-bottom: 10px;
}

.variant-card-head span,
.scheme-head span,
.calc-meta {
  color: var(--muted);
  font-size: 13px;
}

.variant-lines,
.ldp-lines {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 8px;
}

.ldp-lines {
  display: grid;
}

.badge {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  padding: 3px 8px;
  border-radius: 999px;
  background: var(--soft);
  color: #174f83;
  font-size: 12px;
  font-weight: 700;
}

.scheme-svg {
  display: block;
  width: 100%;
  min-height: 150px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

.scheme-svg line {
  stroke: #61758a;
  stroke-width: 2;
}

.scheme-svg .duplicate-line {
  stroke-width: 2.2;
}

.scheme-svg rect {
  fill: #0b6bcb;
}

.scheme-svg circle {
  fill: #ffffff;
  stroke: #117a37;
  stroke-width: 2;
}

.scheme-svg text {
  fill: #17202a;
  font-size: 11px;
  font-weight: 700;
  text-anchor: middle;
}

.scheme-svg .node-power {
  fill: #64707d;
  font-size: 9px;
  font-weight: 400;
}

.result-tabs {
  margin-bottom: 12px;
}

.calc-variant {
  display: none;
  padding: 16px;
}

.calc-variant.active {
  display: block;
}

.calc-meta {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 6px;
}

.calc-meta span {
  min-height: 26px;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 3px 9px;
  background: #fff;
}

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

table {
  width: 100%;
  border-collapse: collapse;
  min-width: 620px;
  font-size: 13px;
}

th,
td {
  padding: 9px 10px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  vertical-align: top;
}

th {
  background: #f6f8fb;
  color: #334151;
  font-weight: 700;
}

tr:last-child td {
  border-bottom: 0;
}

.admin-layout {
  display: grid;
  grid-template-columns: minmax(280px, 360px) 1fr;
  gap: 18px;
}

.user-form {
  display: grid;
  gap: 12px;
  margin-top: 14px;
}

.error-box {
  overflow: auto;
  max-height: 280px;
  margin-top: 18px;
  padding: 12px;
  border: 1px solid #f1b3ad;
  border-radius: 8px;
  background: #fff3f1;
  color: var(--danger);
  white-space: pre-wrap;
}

.error-box.compact {
  margin-top: 0;
  white-space: normal;
}

@media (max-width: 1200px) {
  .workspace,
  .admin-layout {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 860px) {
  .topbar,
  .section-head {
    align-items: stretch;
    flex-direction: column;
  }

  .top-actions {
    justify-content: flex-start;
  }

  .grid.three,
  .grid.two,
  .load-grid,
  .metrics,
  .selected-grid,
  .scheme-grid {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 760px) {
  .app-shell {
    width: min(100vw - 20px, 720px);
    padding-top: 14px;
  }
}
