*,
*::before,
*::after {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: system-ui, -apple-system, Segoe UI, Roboto, sans-serif;
  background: #1a1f26;
  color: #e8edf2;
  min-height: 100vh;
}

h1, h2, h3 {
  margin: 0 0 0.5rem;
  font-weight: 600;
}

.top-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 1rem;
  align-items: center;
  padding: 0.75rem 1rem;
  background: #252b34;
  border-bottom: 1px solid #3a4450;
}

.top-bar h1 {
  font-size: 1.1rem;
  margin: 0;
  flex: 0 0 auto;
}

.meta-fields,
.file-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  align-items: center;
}

.meta-fields label,
.file-actions label {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  font-size: 0.85rem;
}

input[type="text"],
input[type="number"],
select {
  background: #1a1f26;
  border: 1px solid #4a5568;
  color: inherit;
  border-radius: 4px;
  padding: 0.25rem 0.4rem;
}

button {
  background: #3a4450;
  border: 1px solid #4a5568;
  color: inherit;
  border-radius: 4px;
  padding: 0.35rem 0.65rem;
  cursor: pointer;
  font-size: 0.85rem;
}

button:hover {
  background: #4a5568;
}

button.primary {
  background: #2563eb;
  border-color: #1d4ed8;
}

.save-status {
  font-size: 0.8rem;
  color: #94a3b8;
  min-width: 5rem;
}

.save-status.dirty {
  color: #fbbf24;
}

button.primary:hover {
  background: #1d4ed8;
}

button.danger {
  background: #7f1d1d;
  border-color: #991b1b;
  margin-top: 0.5rem;
}

button.link {
  background: none;
  border: none;
  color: #93c5fd;
  padding: 0;
  text-decoration: underline;
}

.validation-banner {
  background: #7f1d1d;
  color: #fecaca;
  padding: 0.5rem 1rem;
  font-size: 0.9rem;
}

.validation-banner.hidden {
  display: none;
}

.mode-banner {
  background: #1e3a5f;
  color: #bfdbfe;
  padding: 0.5rem 1rem;
  font-size: 0.9rem;
  border-bottom: 1px solid #2563eb;
}

.mode-banner.hidden {
  display: none;
}

.link-group-row {
  display: flex;
  gap: 0.35rem;
  align-items: center;
  margin-bottom: 0.5rem;
  flex-wrap: wrap;
}

.link-group-row select {
  flex: 1;
  min-width: 120px;
}

.link-custom-field {
  margin-top: 0.25rem;
}

.small {
  font-size: 0.75rem;
}

.layout {
  display: grid;
  grid-template-columns: 220px 1fr 280px;
  gap: 0;
  min-height: calc(100vh - 56px);
}

.sidebar {
  padding: 0.75rem;
  background: #252b34;
  border-right: 1px solid #3a4450;
  overflow-y: auto;
}

.sidebar.right {
  border-right: none;
  border-left: 1px solid #3a4450;
}

.center {
  padding: 1rem;
  overflow: auto;
  display: flex;
  justify-content: center;
  align-items: flex-start;
}

.panel {
  margin-top: 1rem;
}

.panel h2 {
  font-size: 0.95rem;
}

.toolbar {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.tool-group {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}

.tool-group button.active {
  background: #2563eb;
  border-color: #1d4ed8;
}

.color-palette {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
}

.color-swatch {
  width: 28px;
  height: 28px;
  padding: 0;
  border: 2px solid transparent;
  border-radius: 4px;
}

.color-swatch.active {
  border-color: #fff;
  box-shadow: 0 0 0 2px #2563eb;
}

.grid-wrap {
  position: relative;
  display: inline-block;
  background: #111;
  border-radius: 6px;
  padding: 4px;
}

#grid-canvas {
  display: block;
  cursor: crosshair;
}

.grid-tooltip {
  position: absolute;
  pointer-events: none;
  background: rgba(0, 0, 0, 0.85);
  color: #fff;
  font-size: 11px;
  padding: 2px 6px;
  border-radius: 3px;
  display: none;
  z-index: 2;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  margin-bottom: 0.6rem;
  font-size: 0.85rem;
}

.field.checkbox {
  flex-direction: row;
  align-items: center;
}

.muted {
  color: #94a3b8;
  font-size: 0.85rem;
}

.muted.small {
  font-size: 0.75rem;
}

.subhead {
  font-weight: 600;
  margin: 0.75rem 0 0.35rem;
  font-size: 0.85rem;
}

.queue-list,
.layer-list {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  margin-bottom: 0.5rem;
}

.queue-row,
.layer-row {
  display: flex;
  gap: 0.25rem;
  align-items: center;
}

.intake-list,
.footprint-list {
  margin: 0.25rem 0 0.5rem;
  padding-left: 1.2rem;
  font-size: 0.85rem;
}

#validation-panel ul {
  margin: 0.25rem 0 0.75rem;
  padding-left: 1.2rem;
  font-size: 0.8rem;
}

.val-errors {
  color: #fca5a5;
  font-weight: 600;
}

.val-warnings {
  color: #fcd34d;
  font-weight: 600;
}

.ok {
  color: #86efac;
  font-size: 0.85rem;
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
}

.modal-backdrop.hidden {
  display: none;
}

.modal {
  background: #252b34;
  border: 1px solid #4a5568;
  border-radius: 8px;
  min-width: 320px;
  max-width: 90vw;
  max-height: 90vh;
  overflow: auto;
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.75rem 1rem;
  border-bottom: 1px solid #3a4450;
}

.modal-header h3 {
  margin: 0;
}

.modal-close {
  background: none;
  border: none;
  font-size: 1.5rem;
  line-height: 1;
  padding: 0 0.25rem;
}

.modal-body {
  padding: 1rem;
}

.modal-footer {
  padding: 0.75rem 1rem;
  border-top: 1px solid #3a4450;
  display: flex;
  justify-content: flex-end;
  gap: 0.5rem;
}

.fp-picker {
  display: grid;
  gap: 2px;
  justify-content: center;
  margin-top: 0.75rem;
}

.fp-cell {
  width: 28px;
  height: 28px;
  padding: 0;
  background: #3a4450;
  border: 1px solid #4a5568;
}

.fp-cell.on {
  background: #2563eb;
}

.fp-cell.anchor {
  outline: 2px solid #f59e0b;
}

@media (max-width: 900px) {
  .layout {
    grid-template-columns: 1fr;
  }
  .sidebar.right {
    border-left: none;
    border-top: 1px solid #3a4450;
  }
}
