:root {
  color-scheme: dark;
  --bg: #111315;
  --panel: #1a1d20;
  --panel-2: #22262a;
  --line: #343a40;
  --text: #edf0f2;
  --muted: #9ea7ad;
  --accent: #34c7a3;
  --accent-2: #f0b44c;
  --danger: #ff6b6b;
  --shadow: 0 14px 40px rgba(0, 0, 0, 0.34);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }

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

body {
  display: grid;
  grid-template-rows: auto 1fr auto;
}

.atlas-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  min-height: 58px;
  padding: 10px 14px;
  border-bottom: 1px solid var(--line);
  background: #16191c;
}

h1 {
  margin: 0;
  font-size: 16px;
  line-height: 1.1;
  font-weight: 700;
  letter-spacing: 0;
}

.title {
  display: grid;
  gap: 4px;
  min-width: 210px;
}

#status {
  min-height: 16px;
  color: var(--muted);
  font-size: 12px;
  line-height: 16px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 520px;
}

.toolbar {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
  flex-wrap: wrap;
}

button,
.file-button,
select,
input[type="text"],
input[type="number"] {
  height: 32px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--panel-2);
  color: var(--text);
  font: inherit;
  font-size: 13px;
  letter-spacing: 0;
}

button,
.file-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 0 10px;
  cursor: pointer;
  user-select: none;
}

button:hover,
.file-button:hover,
select:hover {
  border-color: #4c565f;
  background: #293037;
}

button.primary {
  border-color: #2d9c82;
  background: #16856d;
  color: white;
}

button.primary:hover { background: #1a957a; }

button.warning {
  border-color: #9c6a22;
  background: #7e561e;
}

input[type="file"] { display: none; }


.atlas-grid {
  min-height: 0;
  display: grid;
  grid-template-columns: 286px minmax(420px, 1fr) minmax(420px, 0.72fr);
  gap: 10px;
  padding: 10px;
}

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

.panel {
  display: flex;
  flex-direction: column;
}

.panel-head,
.stage-head,
.parts-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  min-height: 42px;
  padding: 8px 10px;
  border-bottom: 1px solid var(--line);
  background: #191d21;
}

.panel-head h2,
.stage-head h2,
.parts-head h2 {
  margin: 0;
  font-size: 13px;
  line-height: 1.2;
  font-weight: 700;
  letter-spacing: 0;
}

.panel-body {
  min-height: 0;
  overflow: auto;
  padding: 10px;
}

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

.field label,
.mini-label {
  color: var(--muted);
  font-size: 11px;
  line-height: 1.2;
  font-weight: 650;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.field-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  align-items: end;
}

.field-row.three {
  grid-template-columns: 1fr 1fr 1fr;
}

.check-row {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 28px;
  color: var(--text);
  font-size: 13px;
}

.check-row input { margin: 0; }

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

input[type="color"] {
  width: 100%;
  height: 32px;
  padding: 2px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--panel-2);
}

input[type="text"],
input[type="number"],
select {
  width: 100%;
  padding: 0 8px;
}

.value-line {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  color: var(--muted);
  font-size: 12px;
}

.stage {
  display: grid;
  grid-template-rows: auto 1fr;
}

.stage-tools {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.canvas-wrap {
  position: relative;
  min-height: 0;
  background:
    linear-gradient(45deg, #20252a 25%, transparent 25%),
    linear-gradient(-45deg, #20252a 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, #20252a 75%),
    linear-gradient(-45deg, transparent 75%, #20252a 75%),
    #15181b;
  background-position: 0 0, 0 8px, 8px -8px, -8px 0;
  background-size: 16px 16px;
}

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

#atlasCanvas {
  cursor: grab;
  touch-action: none;
}

#atlasCanvas.dragging { cursor: grabbing; }

.preview-wrap {
  height: clamp(440px, 55vh, 620px);
  border-bottom: 1px solid var(--line);
  background: #121518;
}

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

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

.parts {
  margin: 0 10px 10px;
  min-height: 178px;
  max-height: 240px;
  display: grid;
  grid-template-rows: auto 1fr;
}

.parts-table-wrap {
  min-height: 0;
  overflow: auto;
}

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

th,
td {
  border-bottom: 1px solid #2b3137;
  padding: 5px 6px;
  text-align: left;
  white-space: nowrap;
}

th {
  position: sticky;
  top: 0;
  z-index: 2;
  color: var(--muted);
  background: #191d21;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

tr {
  cursor: pointer;
}

tr.selected {
  background: rgba(52, 199, 163, 0.12);
  outline: 1px solid rgba(52, 199, 163, 0.45);
  outline-offset: -1px;
}

td input {
  width: 72px;
  height: 26px;
  border-radius: 4px;
  font-size: 12px;
}

td.small input { width: 58px; }

.role {
  color: var(--muted);
}

.drop-cover {
  position: absolute;
  inset: 18px;
  display: none;
  place-items: center;
  border: 1px dashed #5b6974;
  border-radius: 8px;
  background: rgba(12, 14, 16, 0.78);
  color: var(--text);
  font-size: 13px;
  pointer-events: none;
}

.drop-cover.visible { display: grid; }

@media (max-width: 1100px) {
  body { overflow: auto; }
  .atlas-grid {
    grid-template-columns: 1fr;
    overflow: visible;
  }
  .panel,
  .stage {
    min-height: 360px;
  }
  .parts {
    max-height: none;
  }
}
