:root {
  color-scheme: light;
  --bg: #eef2f6;
  --surface: #ffffff;
  --surface-2: #f8fafc;
  --ink: #172033;
  --muted: #5f6f85;
  --line: #d7e0ea;
  --slate: #233447;
  --teal: #0f766e;
  --teal-soft: #dff3ef;
  --blue: #2563eb;
  --blue-soft: #e7efff;
  --amber: #d97706;
  --amber-soft: #fff3d7;
  --violet: #7c3aed;
  --violet-soft: #f1e8ff;
  --green: #059669;
  --green-soft: #dff7eb;
  --red: #dc2626;
  --red-soft: #fee2e2;
  --shadow: 0 12px 28px rgb(23 32 51 / 10%);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-width: 320px;
  background: var(--bg);
  color: var(--ink);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

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

button {
  cursor: pointer;
}

.app-shell {
  min-height: 100vh;
  display: grid;
  grid-template-columns: 260px minmax(0, 1fr);
}

.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  padding: 20px 16px;
  background: #1f3145;
  color: #f8fafc;
  display: flex;
  flex-direction: column;
  gap: 22px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 4px;
}

.brand-mark {
  width: 44px;
  height: 44px;
  border-radius: 8px;
  display: grid;
  place-items: center;
  background: linear-gradient(135deg, #f59e0b, #0f766e);
  font-weight: 800;
  color: #ffffff;
}

.brand h1 {
  margin: 0;
  font-size: 18px;
  line-height: 1.1;
}

.brand p {
  margin: 3px 0 0;
  color: #bed0df;
  font-size: 13px;
}

.nav-list {
  display: grid;
  gap: 6px;
}

.nav-button {
  min-height: 42px;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: #dbeafe;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  text-align: left;
}

.nav-button:hover,
.nav-button:focus-visible {
  background: rgb(255 255 255 / 8%);
  outline: none;
}

.nav-button.is-active {
  background: #ffffff;
  color: var(--ink);
}

.nav-icon {
  width: 24px;
  height: 24px;
  border-radius: 6px;
  display: grid;
  place-items: center;
  background: rgb(255 255 255 / 12%);
  font-size: 12px;
  font-weight: 800;
}

.nav-button.is-active .nav-icon {
  background: var(--amber-soft);
  color: #8a4b00;
}

.sidebar-footer {
  margin-top: auto;
  padding: 12px;
  border: 1px solid rgb(255 255 255 / 14%);
  border-radius: 8px;
  display: grid;
  gap: 4px;
  color: #bed0df;
  font-size: 12px;
}

.sidebar-footer strong {
  color: #ffffff;
  font-size: 13px;
}

.workspace {
  min-width: 0;
  padding: 20px;
}

.topbar {
  min-height: 74px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 18px;
  margin-bottom: 18px;
  padding: 16px 18px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.topbar h2,
.view-header h2 {
  margin: 0;
  font-size: 24px;
  line-height: 1.15;
}

.eyebrow {
  margin: 0 0 4px;
  color: var(--teal);
  font-size: 12px;
  font-weight: 800;
  text-transform: uppercase;
}

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

.fact-badges {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.status-badge {
  display: inline-flex;
  min-height: 28px;
  align-items: center;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 4px 10px;
  background: var(--surface-2);
  color: var(--ink);
  font-size: 12px;
  font-weight: 800;
  white-space: nowrap;
}

.status-badge.verified {
  border-color: #a7f3d0;
  background: var(--green-soft);
  color: #06634a;
}

.status-badge.observed {
  border-color: #bfdbfe;
  background: var(--blue-soft);
  color: #1947a3;
}

.status-badge.unknown {
  border-color: #fed7aa;
  background: var(--amber-soft);
  color: #8a4b00;
}

.icon-button,
.secondary-button,
.primary-button,
.text-button,
.segmented button {
  min-height: 38px;
  border-radius: 8px;
  border: 1px solid var(--line);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 8px 12px;
  background: #ffffff;
  color: var(--ink);
  font-weight: 750;
  text-decoration: none;
}

.icon-button {
  width: 40px;
  padding: 0;
}

.primary-button {
  background: var(--teal);
  border-color: var(--teal);
  color: #ffffff;
}

.secondary-button,
.segmented button {
  background: var(--surface-2);
}

.text-button {
  min-height: auto;
  padding: 0;
  border: 0;
  background: transparent;
  color: var(--teal);
}

.file-button input {
  display: none;
}

.view {
  display: none;
}

.view.is-active {
  display: block;
}

.view-header {
  display: flex;
  justify-content: space-between;
  align-items: end;
  gap: 16px;
  margin: 0 0 14px;
}

.production-header {
  align-items: center;
}

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

.tool-button {
  min-height: 36px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 7px 10px;
  background: #ffffff;
  color: var(--ink);
  font-weight: 800;
}

.tool-button:hover,
.tool-button:focus-visible {
  border-color: var(--teal);
  outline: none;
}

.tool-button.is-active {
  background: var(--teal);
  border-color: var(--teal);
  color: #ffffff;
}

.tool-button.danger {
  color: #991b1b;
}

.tool-button.danger:hover,
.tool-button.danger:focus-visible {
  border-color: var(--red);
}

.wiki-grid {
  align-items: stretch;
}

.lower-grid {
  margin-top: 14px;
}

.metric-grid {
  display: grid;
  grid-template-columns: repeat(5, minmax(130px, 1fr));
  gap: 12px;
  margin-bottom: 14px;
}

.metric {
  min-height: 96px;
  padding: 14px;
  border-radius: 8px;
  background: var(--surface);
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
}

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

.metric strong {
  display: block;
  margin-top: 10px;
  font-size: 28px;
}

.two-column,
.table-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(320px, 420px);
  gap: 14px;
  align-items: start;
}

.panel,
.map-panel,
.editor-panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.panel {
  padding: 16px;
}

.panel-heading {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  margin-bottom: 12px;
}

.panel h3,
.form-section h3 {
  margin: 0 0 12px;
  font-size: 16px;
}

.task-list,
.flow-summary,
.note-list,
.compact-list {
  display: grid;
  gap: 10px;
}

.compact-list p {
  margin: 0;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-2);
  line-height: 1.45;
}

.task-item,
.flow-item,
.note-item {
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-2);
}

.task-item strong,
.flow-item strong,
.note-item strong {
  display: block;
  margin-bottom: 4px;
}

.meta-row {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  align-items: center;
  color: var(--muted);
  font-size: 12px;
}

.pill {
  display: inline-flex;
  min-height: 22px;
  align-items: center;
  border-radius: 999px;
  padding: 2px 8px;
  background: var(--blue-soft);
  color: #1947a3;
  font-size: 12px;
  font-weight: 750;
}

.pill.status-active,
.pill.status-done {
  background: var(--green-soft);
  color: #06634a;
}

.pill.status-blocked,
.pill.priority-high {
  background: var(--red-soft);
  color: #991b1b;
}

.pill.status-unknown,
.pill.status-todo {
  background: var(--amber-soft);
  color: #8a4b00;
}

.pill.priority-medium {
  background: var(--amber-soft);
  color: #8a4b00;
}

.pill.priority-low {
  background: var(--green-soft);
  color: #06634a;
}

.map-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 340px;
  gap: 14px;
  align-items: stretch;
}

.flow-editor {
  display: grid;
  grid-template-columns: 220px minmax(520px, 1fr) 300px;
  gap: 14px;
  align-items: stretch;
}

.flow-palette,
.flow-stage,
.flow-inspector,
.inspector-card {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.flow-palette,
.flow-inspector {
  padding: 14px;
  display: grid;
  gap: 14px;
  align-content: start;
}

.palette-section {
  display: grid;
  gap: 10px;
}

.palette-section h3,
.inspector-card h3 {
  margin: 0;
  font-size: 15px;
}

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

.palette-node {
  min-height: 58px;
  border: 1px solid var(--line);
  border-radius: 8px;
  display: grid;
  grid-template-columns: 20px 1fr;
  gap: 2px 10px;
  align-items: center;
  padding: 9px;
  background: var(--surface-2);
  color: var(--ink);
  text-align: left;
}

.palette-node:hover,
.palette-node:focus-visible {
  border-color: var(--teal);
  outline: none;
}

.palette-swatch {
  width: 18px;
  height: 18px;
  border-radius: 6px;
  border: 2px solid #64748b;
  grid-row: span 2;
}

.palette-node strong {
  font-size: 13px;
}

.palette-node small {
  color: var(--muted);
  font-size: 11px;
}

.type-miner .palette-swatch {
  border-color: #ca8a04;
  background: #fef9c3;
}

.type-smelter .palette-swatch {
  border-color: #f97316;
  background: #fff7ed;
}

.type-constructor .palette-swatch {
  border-color: #2563eb;
  background: #eff6ff;
}

.type-assembler .palette-swatch {
  border-color: #059669;
  background: #ecfdf5;
}

.type-storage .palette-swatch {
  border-color: #64748b;
  background: #f1f5f9;
}

.type-power .palette-swatch {
  border-color: #dc2626;
  background: #fee2e2;
}

.type-note .palette-swatch {
  border-color: #7c3aed;
  background: #f1e8ff;
}

.flow-status {
  display: grid;
  gap: 8px;
}

.status-row {
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: 8px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 8px 10px;
  background: var(--surface-2);
}

.status-row strong {
  font-size: 18px;
}

.status-row span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
  text-transform: uppercase;
}

.flow-stage {
  position: relative;
  min-height: calc(100vh - 150px);
  overflow: hidden;
}

.canvas-hint {
  position: absolute;
  z-index: 2;
  top: 12px;
  left: 12px;
  right: 12px;
  min-height: 34px;
  border: 1px solid var(--line);
  border-radius: 8px;
  display: flex;
  align-items: center;
  padding: 7px 10px;
  background: rgb(255 255 255 / 92%);
  color: var(--muted);
  font-size: 13px;
  font-weight: 750;
  backdrop-filter: blur(6px);
}

.flow-stage #factoryMap {
  width: 100%;
  height: calc(100vh - 150px);
  min-height: 720px;
  display: block;
  background: #f8fafc;
  touch-action: none;
}

.flow-inspector {
  max-height: calc(100vh - 150px);
  overflow: auto;
}

.inspector-card {
  padding: 14px;
  box-shadow: none;
}

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

.connection-readout {
  margin: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px;
  background: var(--surface-2);
  color: var(--muted);
  font-weight: 750;
}

.edge-list {
  display: grid;
  gap: 8px;
  max-height: 280px;
  overflow: auto;
}

.edge-item {
  border: 1px solid var(--line);
  border-radius: 8px;
  display: grid;
  gap: 3px;
  padding: 8px 10px;
  background: var(--surface-2);
  color: var(--ink);
  text-align: left;
}

.edge-item span {
  color: var(--muted);
  font-size: 12px;
}

.edge-item.is-selected {
  border-color: var(--teal);
  box-shadow: 0 0 0 2px rgb(15 118 110 / 16%);
}

.data-actions {
  display: grid;
  gap: 8px;
}

.map-panel {
  min-height: 680px;
  overflow: hidden;
}

.wiki-map-panel {
  min-height: 620px;
}

#factoryMap {
  width: 100%;
  height: min(72vh, 760px);
  min-height: 620px;
  display: block;
  background: #f8fafc;
  touch-action: none;
}

.editor-panel {
  padding: 14px;
  display: grid;
  gap: 14px;
  align-content: start;
}

.form-section {
  padding-bottom: 14px;
  border-bottom: 1px solid var(--line);
}

.form-section:last-child {
  border-bottom: 0;
  padding-bottom: 0;
}

.stacked-form {
  display: grid;
  gap: 10px;
}

label {
  display: grid;
  gap: 5px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

input,
select,
textarea {
  width: 100%;
  min-height: 38px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 8px 10px;
  background: #ffffff;
  color: var(--ink);
}

textarea {
  resize: vertical;
}

.muted-box {
  border-radius: 8px;
  border: 1px dashed var(--line);
  background: var(--surface-2);
  color: var(--muted);
  padding: 12px;
}

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

table {
  width: 100%;
  min-width: 780px;
  border-collapse: collapse;
  background: #ffffff;
}

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

th {
  position: sticky;
  top: 0;
  background: var(--teal);
  color: #ffffff;
  font-size: 12px;
  text-transform: uppercase;
}

td {
  font-size: 14px;
}

.row-actions {
  display: flex;
  gap: 8px;
  justify-content: flex-end;
}

.mini-button {
  min-height: 30px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: #ffffff;
  color: var(--ink);
  padding: 4px 8px;
  font-weight: 750;
}

.json-box {
  min-height: 360px;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 12px;
  white-space: pre;
}

.toast {
  position: fixed;
  right: 20px;
  bottom: 20px;
  min-width: 220px;
  max-width: min(420px, calc(100vw - 40px));
  padding: 12px 14px;
  border-radius: 8px;
  background: #172033;
  color: #ffffff;
  box-shadow: var(--shadow);
  transform: translateY(120%);
  transition: transform 180ms ease;
  z-index: 50;
}

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

.map-bg {
  fill: #f8fafc;
}

.grid-line {
  stroke: #e2e8f0;
  stroke-width: 1;
}

.map-band {
  fill: #ffffff;
  stroke: #d8e2ed;
  stroke-width: 1.5;
  rx: 12;
}

.belt-line {
  fill: none;
  stroke-width: 4;
  stroke-linecap: round;
  marker-end: url(#arrow);
  cursor: pointer;
}

.belt-line.is-selected {
  stroke-width: 7;
  filter: drop-shadow(0 2px 3px rgb(15 23 42 / 22%));
}

.belt-label {
  font-size: 11px;
  fill: #344256;
  font-weight: 750;
  paint-order: stroke;
  stroke: #ffffff;
  stroke-width: 4px;
  stroke-linejoin: round;
}

.flow-node,
.node {
  cursor: grab;
}

.flow-node:active,
.node:active {
  cursor: grabbing;
}

.flow-node rect,
.node rect {
  stroke-width: 2;
  filter: drop-shadow(0 4px 4px rgb(23 32 51 / 13%));
}

.flow-node text,
.node text {
  pointer-events: none;
}

.node-title {
  fill: #101828;
  font-size: 13px;
  font-weight: 800;
}

.node-sub {
  fill: #475569;
  font-size: 10px;
  font-weight: 650;
}

.flow-node.is-selected rect,
.node.is-selected rect {
  stroke: #111827;
  stroke-width: 3;
}

.flow-node.is-connect-source rect {
  stroke: #7c3aed;
  stroke-width: 4;
}

.pending-dot {
  fill: #7c3aed;
  stroke: #ffffff;
  stroke-width: 3;
}

.type-smelter rect {
  fill: #fff7ed;
  stroke: #f97316;
}

.type-constructor rect {
  fill: #eff6ff;
  stroke: #2563eb;
}

.type-assembler rect {
  fill: #ecfdf5;
  stroke: #059669;
}

.type-storage rect {
  fill: #f1f5f9;
  stroke: #64748b;
}

.type-miner rect {
  fill: #fef9c3;
  stroke: #ca8a04;
}

.type-power rect {
  fill: #fee2e2;
  stroke: #dc2626;
}

.type-note rect {
  fill: #f1e8ff;
  stroke: #7c3aed;
}

.source-panel {
  padding: 0;
  overflow: hidden;
}

.source-list {
  display: grid;
}

.source-link {
  display: grid;
  gap: 4px;
  padding: 14px 16px;
  border-bottom: 1px solid var(--line);
  color: var(--ink);
  text-decoration: none;
}

.source-link:hover,
.source-link:focus-visible {
  background: var(--teal-soft);
  outline: none;
}

.source-link span {
  font-weight: 800;
}

.source-link strong {
  color: var(--muted);
  font-size: 12px;
  word-break: break-word;
}

a {
  color: var(--teal);
  font-weight: 750;
}

code {
  border-radius: 6px;
  background: var(--surface-2);
  padding: 2px 5px;
}

@media (max-width: 1100px) {
  .app-shell {
    grid-template-columns: 1fr;
  }

  .sidebar {
    position: static;
    height: auto;
  }

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

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

  .two-column,
  .table-layout,
  .map-layout,
  .flow-editor {
    grid-template-columns: 1fr;
  }

  .editor-panel,
  .flow-inspector {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .flow-stage,
  .flow-inspector {
    min-height: auto;
    max-height: none;
  }

  .flow-stage #factoryMap {
    height: 680px;
    min-height: 680px;
  }
}

@media (max-width: 680px) {
  .workspace {
    padding: 12px;
  }

  .topbar,
  .view-header {
    align-items: stretch;
    flex-direction: column;
  }

  .nav-list,
  .metric-grid,
  .editor-panel,
  .flow-inspector {
    grid-template-columns: 1fr;
  }

  .editor-toolbar {
    justify-content: stretch;
  }

  .tool-button {
    flex: 1 1 90px;
  }

  .map-panel {
    min-height: 520px;
  }

  #factoryMap {
    min-height: 500px;
  }
}
