:root {
  color-scheme: light;
  --bg: #eef2f5;
  --panel: #ffffff;
  --soft: #f7f9fb;
  --line: #cbd5df;
  --text: #17202a;
  --muted: #61717f;
  --accent: #1e7b74;
  --accent-dark: #145b56;
  --bad: #b91c1c;
  --warn: #c16921;
  --shadow: 0 18px 42px rgba(26, 39, 52, 0.12);
  font-family: Arial, Helvetica, sans-serif;
}

* { box-sizing: border-box; }

html,
body {
  height: 100%;
  margin: 0;
  background: var(--bg);
  color: var(--text);
  overflow: hidden;
}

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

button {
  height: 36px;
  border: 1px solid var(--accent-dark);
  border-radius: 8px;
  background: var(--accent);
  color: #fff;
  font-weight: 700;
  cursor: pointer;
}

button.secondary {
  border-color: var(--line);
  background: #fff;
  color: var(--text);
}

button.icon-btn {
  width: 34px;
  height: 32px;
  padding: 0;
}

button.danger {
  border-color: #e7b7bd;
  background: #fff4f5;
  color: #9f2630;
}

button:disabled {
  opacity: 0.45;
  cursor: default;
}

.topbar {
  min-height: 72px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 12px 18px;
  background: #17232c;
  color: #fff;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
}

.brand-mark {
  width: 42px;
  height: 42px;
  display: grid;
  place-items: center;
  border-radius: 8px;
  background: #f2d17c;
  color: #17232c;
  font-weight: 800;
  font-size: 24px;
}

.brand h1 {
  margin: 0;
  line-height: 1;
  font-size: 22px;
  letter-spacing: 0;
}

.brand p {
  margin: 4px 0 0;
  color: rgba(255, 255, 255, 0.72);
  font-size: 13px;
}

.top-status {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  align-items: center;
  gap: 10px;
  font-size: 13px;
  color: rgba(255, 255, 255, 0.72);
}

.top-status b {
  color: #fff;
}

.pill {
  border-radius: 999px;
  padding: 7px 10px;
  color: #fff;
  background: var(--warn);
  font-weight: 800;
}

.workspace {
  height: calc(100vh - 72px);
  min-height: 0;
  display: grid;
  grid-template-columns: 390px minmax(0, 1fr);
  gap: 14px;
  padding: 14px;
}

.controls {
  min-height: 0;
  overflow: auto;
  padding-right: 2px;
}

.group {
  padding: 13px;
  margin-bottom: 12px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: 0 8px 24px rgba(26, 39, 52, 0.06);
}

.group h2 {
  margin: 0 0 11px;
  font-size: 15px;
  letter-spacing: 0;
}

.single-field {
  display: grid;
  gap: 6px;
  margin-bottom: 10px;
}

.single-field span,
.mini-label,
.field label {
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.single-field input,
.section-fields input,
.section-fields select,
.field input[type="number"],
textarea {
  width: 100%;
  border: 1px solid #aeb9c5;
  border-radius: 7px;
  background: #fff;
  color: var(--text);
  outline: none;
}

.single-field input,
.section-fields input,
.section-fields select,
.field input[type="number"] {
  height: 34px;
  padding: 4px 8px;
}

textarea {
  min-height: 94px;
  padding: 9px;
  resize: vertical;
  line-height: 1.35;
}

input:focus,
select:focus,
textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(30, 123, 116, 0.12);
}

input[type="range"] {
  width: 100%;
  accent-color: var(--accent);
}

.field {
  display: grid;
  grid-template-columns: 78px minmax(0, 1fr) 82px;
  align-items: center;
  gap: 8px;
  margin: 9px 0;
}

.check-row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 8px 0 10px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.button-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-top: 8px;
}

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

.profile-section {
  padding: 9px;
  border: 1px solid #dde5ed;
  border-radius: 8px;
  background: var(--soft);
}

.profile-section-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 8px;
  font-size: 13px;
  font-weight: 800;
}

.profile-section-actions {
  display: flex;
  gap: 4px;
}

.section-fields {
  display: grid;
  gap: 8px;
}

.section-fields label {
  display: grid;
  gap: 4px;
}

.range-pair {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 90px;
  gap: 7px;
  align-items: center;
}

.stats {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.metric {
  padding: 9px;
  border: 1px solid #dde5ed;
  border-radius: 8px;
  background: var(--soft);
}

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

.metric b {
  display: block;
  margin-top: 4px;
  font-size: 17px;
}

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

.list {
  max-height: 260px;
  overflow: auto;
  padding: 9px;
  border: 1px solid #dde5ed;
  border-radius: 8px;
  background: var(--soft);
  font-size: 13px;
  line-height: 1.45;
}

.viewer {
  min-width: 0;
  min-height: 0;
  display: grid;
  grid-template-rows: minmax(0, 1fr) auto;
  gap: 10px;
}

.canvas-wrap {
  min-height: 0;
  min-width: 0;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: hidden;
  box-shadow: var(--shadow);
}

#drawing {
  display: block;
  width: 100%;
  height: 100%;
  max-width: 100%;
  max-height: 100%;
}

.legend {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 14px;
  align-items: center;
  min-height: 36px;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  color: var(--muted);
  font-size: 13px;
}

.sw {
  display: inline-block;
  width: 16px;
  height: 10px;
  margin-right: 5px;
  border: 1px solid #111827;
  vertical-align: -1px;
}

.fill-blue { background: #bae6fd; }
.fill-orange { background: #fed7aa; }
.fill-green { background: #bbf7d0; }
.fill-ns { background: #d7c7ff; }

.toast {
  position: fixed;
  right: 18px;
  bottom: 18px;
  max-width: min(360px, calc(100vw - 36px));
  padding: 12px 14px;
  border-radius: 8px;
  background: #17232c;
  color: #fff;
  box-shadow: var(--shadow);
  opacity: 0;
  transform: translateY(12px);
  pointer-events: none;
  transition: opacity 160ms ease, transform 160ms ease;
  font-size: 14px;
}

.toast.is-visible {
  opacity: 1;
  transform: translateY(0);
}

@media (max-width: 980px) {
  html,
  body {
    height: auto;
    overflow: auto;
  }

  .topbar {
    align-items: flex-start;
    flex-direction: column;
  }

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

  .workspace {
    height: auto;
    min-height: calc(100vh - 72px);
    grid-template-columns: 1fr;
  }

  .viewer {
    height: min(82vh, 760px);
  }
}

@media (max-width: 560px) {
  .workspace {
    padding: 10px;
  }

  .field {
    grid-template-columns: 1fr;
    gap: 5px;
  }

  .range-pair,
  .button-row,
  .stats {
    grid-template-columns: 1fr;
  }
}
