:root {
  --bg: #08111f;
  --bg-2: #0d1729;
  --panel: rgba(17, 29, 52, 0.86);
  --panel-solid: #111d34;
  --line: rgba(148, 163, 184, 0.18);
  --line-strong: rgba(148, 163, 184, 0.35);
  --text: #e5edf8;
  --muted: #8fa2bd;
  --muted-2: #65758d;
  --blue: #38bdf8;
  --blue-2: #2563eb;
  --green: #22c55e;
  --amber: #f59e0b;
  --red: #ef4444;
  --purple: #a78bfa;
  --shadow: 0 24px 70px rgba(0, 0, 0, 0.36);
  --radius: 18px;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }

html, body {
  width: 100%;
  min-height: 100%;
  margin: 0;
  background:
    radial-gradient(circle at 22% 12%, rgba(37, 99, 235, 0.20), transparent 32%),
    radial-gradient(circle at 84% 4%, rgba(34, 197, 94, 0.10), transparent 24%),
    linear-gradient(135deg, #050914 0%, var(--bg) 55%, #0b1020 100%);
  color: var(--text);
}

button, input, select { font: inherit; }
button { cursor: pointer; }

.app-shell {
  display: grid;
  grid-template-columns: 292px 1fr;
  min-height: 100vh;
}

.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  padding: 22px 18px;
  border-right: 1px solid var(--line);
  background: rgba(7, 15, 29, 0.82);
  backdrop-filter: blur(16px);
  overflow-y: auto;
}

.brand {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 10px 8px 24px;
}

.brand-mark {
  width: 48px;
  height: 48px;
  display: grid;
  place-items: center;
  border: 1px solid rgba(56, 189, 248, 0.45);
  border-radius: 15px;
  background: linear-gradient(135deg, rgba(37, 99, 235, 0.28), rgba(56, 189, 248, 0.10));
  color: #e0f2fe;
  font-weight: 900;
  letter-spacing: 0.04em;
  box-shadow: inset 0 0 30px rgba(56, 189, 248, 0.10), 0 18px 45px rgba(37, 99, 235, 0.18);
}

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

.brand p {
  margin: 6px 0 0;
  color: var(--muted);
  font-size: 12px;
}

.nav {
  display: grid;
  gap: 8px;
}

.nav-item {
  border: 1px solid transparent;
  border-radius: 14px;
  padding: 13px 14px;
  background: transparent;
  color: #aebed3;
  text-align: left;
  transition: 0.18s ease;
}

.nav-item:hover {
  background: rgba(148, 163, 184, 0.08);
  color: #ffffff;
}

.nav-item.active {
  border-color: rgba(56, 189, 248, 0.35);
  background: linear-gradient(135deg, rgba(56, 189, 248, 0.18), rgba(37, 99, 235, 0.12));
  color: #ffffff;
  box-shadow: inset 0 0 22px rgba(56, 189, 248, 0.05);
}

.side-panel {
  margin-top: 22px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: rgba(15, 23, 42, 0.66);
  padding: 16px;
}

.mini-heading {
  color: var(--muted);
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  margin-bottom: 12px;
}

.status-line {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 0;
  border-top: 1px solid rgba(148, 163, 184, 0.10);
  color: var(--muted);
  font-size: 13px;
}

.status-line:first-of-type { border-top: 0; }
.status-line strong { color: #eaf2ff; font-size: 12px; }
.status-line .ok { color: var(--green); }

.main {
  padding: 24px;
  min-width: 0;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 18px;
  margin: -24px -24px 22px;
  padding: 22px 24px;
  background: rgba(8, 17, 31, 0.72);
  backdrop-filter: blur(20px);
  border-bottom: 1px solid var(--line);
}

.eyebrow {
  margin: 0 0 4px;
  color: var(--blue);
  font-size: 12px;
  letter-spacing: 0.10em;
  text-transform: uppercase;
}

.topbar h2 {
  margin: 0;
  font-size: 26px;
  line-height: 1.1;
}

.topbar-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 10px;
  flex-wrap: wrap;
}

.pill {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 9px 12px;
  border: 1px solid var(--line);
  border-radius: 999px;
  color: #cbd5e1;
  background: rgba(15, 23, 42, 0.72);
  font-size: 13px;
}

.dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--green);
  box-shadow: 0 0 14px var(--green);
}

.btn, .chip {
  border: 1px solid var(--line-strong);
  border-radius: 12px;
  background: rgba(15, 23, 42, 0.78);
  color: #e2e8f0;
  padding: 10px 14px;
  transition: 0.18s ease;
}

.btn:hover, .chip:hover { transform: translateY(-1px); border-color: rgba(56, 189, 248, 0.50); }
.btn.primary { background: linear-gradient(135deg, var(--blue-2), #0ea5e9); border-color: rgba(125, 211, 252, 0.55); color: white; }
.btn.ghost { background: transparent; }
.btn.danger { background: rgba(239, 68, 68, 0.13); border-color: rgba(239, 68, 68, 0.42); color: #fecaca; }
.btn.full { width: 100%; margin-top: 14px; }
.chip { padding: 8px 10px; font-size: 12px; color: #bfdbfe; }

.view { display: none; }
.view.active { display: block; }

.grid { display: grid; gap: 16px; }
.kpi-grid { grid-template-columns: repeat(4, minmax(0, 1fr)); margin-bottom: 16px; }
.dashboard-grid { grid-template-columns: repeat(4, minmax(0, 1fr)); margin-bottom: 16px; }

.card {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel);
  box-shadow: var(--shadow);
  padding: 18px;
  min-width: 0;
}

.kpi-card, .metric-card {
  min-height: 128px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
}

.kpi-card span, .metric-card span {
  color: var(--muted);
  font-size: 13px;
}

.kpi-card strong, .metric-card strong {
  font-size: 32px;
  letter-spacing: -0.03em;
}

.kpi-card small, .metric-card p {
  color: var(--muted);
  margin: 0;
  font-size: 13px;
}

.bar {
  height: 8px;
  background: rgba(148, 163, 184, 0.14);
  border-radius: 999px;
  overflow: hidden;
}

.bar i {
  display: block;
  width: 0%;
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, var(--blue), var(--green));
  transition: width 0.2s ease;
}

.simulation-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 360px;
  gap: 16px;
}

.canvas-card { padding: 0; overflow: hidden; }
.canvas-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 18px;
  border-bottom: 1px solid var(--line);
}

.canvas-toolbar h3, .section-title h3 {
  margin: 0;
  font-size: 17px;
}

.canvas-toolbar p {
  margin: 6px 0 0;
  color: var(--muted);
  font-size: 13px;
}

.button-row { display: flex; gap: 8px; flex-wrap: wrap; justify-content: flex-end; }
.canvas-wrap { position: relative; min-height: 560px; background: radial-gradient(circle at center, rgba(30, 64, 175, 0.16), rgba(2, 6, 23, 0.40)); }
#simCanvas { display: block; width: 100%; height: 560px; }
.canvas-hud {
  position: absolute;
  left: 18px;
  right: 18px;
  bottom: 16px;
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  pointer-events: none;
}
.canvas-hud span {
  padding: 9px 12px;
  border-radius: 999px;
  border: 1px solid rgba(56, 189, 248, 0.30);
  background: rgba(2, 6, 23, 0.72);
  color: #dbeafe;
  font-size: 12px;
}

.panel-stack { display: grid; gap: 16px; align-content: start; }
.section-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 14px;
}
.tag {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 5px 9px;
  border-radius: 999px;
  border: 1px solid var(--line);
  color: #cbd5e1;
  font-size: 11px;
  white-space: nowrap;
}
.tag.blue { color: #bae6fd; border-color: rgba(56, 189, 248, 0.35); background: rgba(56, 189, 248, 0.08); }
.tag.green { color: #bbf7d0; border-color: rgba(34, 197, 94, 0.35); background: rgba(34, 197, 94, 0.08); }
.tag.amber { color: #fde68a; border-color: rgba(245, 158, 11, 0.35); background: rgba(245, 158, 11, 0.08); }

.control-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.target-list { display: grid; gap: 10px; }
.target-item {
  display: grid;
  grid-template-columns: 42px 1fr auto;
  gap: 10px;
  align-items: center;
  padding: 10px;
  border: 1px solid rgba(148, 163, 184, 0.14);
  border-radius: 14px;
  background: rgba(15, 23, 42, 0.44);
}
.target-badge {
  width: 42px;
  height: 42px;
  display: grid;
  place-items: center;
  border-radius: 12px;
  background: rgba(56, 189, 248, 0.12);
  color: #7dd3fc;
  font-weight: 800;
}
.target-item strong { display: block; margin-bottom: 2px; }
.target-item small { color: var(--muted); }
.target-status { font-size: 12px; color: var(--green); }
.target-status.pending { color: var(--muted); }
.target-status.scanning { color: var(--blue); }

.range-row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px 12px;
  align-items: center;
  color: var(--muted);
  font-size: 13px;
  margin-top: 14px;
}
.range-row output { color: #e2e8f0; font-weight: 700; }
.range-row input { grid-column: 1 / -1; width: 100%; accent-color: var(--blue); }

.two-col {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
  margin-bottom: 16px;
}
.two-col.wide-left { grid-template-columns: minmax(0, 1.55fr) minmax(320px, 0.75fr); }

.factory-map {
  position: relative;
  height: 340px;
  border: 1px solid rgba(148, 163, 184, 0.16);
  border-radius: 18px;
  overflow: hidden;
  background:
    linear-gradient(90deg, rgba(148, 163, 184, 0.07) 1px, transparent 1px),
    linear-gradient(rgba(148, 163, 184, 0.07) 1px, transparent 1px),
    rgba(2, 6, 23, 0.30);
  background-size: 38px 38px;
}
.map-line { position: absolute; left: 4%; right: 4%; top: 48%; height: 32px; border: 1px dashed rgba(148, 163, 184, 0.32); border-radius: 999px; }
.map-zone { position: absolute; display: grid; place-items: center; border-radius: 14px; font-size: 12px; color: #dbeafe; }
.scan-zone { left: 42%; top: 28%; width: 22%; height: 42%; border: 1px solid rgba(56, 189, 248, 0.38); background: rgba(56, 189, 248, 0.09); }
.dock-zone { left: 6%; bottom: 10%; width: 18%; height: 24%; border: 1px solid rgba(34, 197, 94, 0.38); background: rgba(34, 197, 94, 0.09); }
.map-robot, .map-frame { position: absolute; border-radius: 10px; display: grid; place-items: center; font-size: 11px; font-weight: 800; transition: 0.25s linear; }
.map-robot { left: 12%; top: 64%; width: 80px; height: 44px; background: linear-gradient(135deg, #0284c7, #38bdf8); color: #00111f; }
.map-frame { left: 48%; top: 46%; width: 116px; height: 40px; border: 2px solid #94a3b8; color: #e2e8f0; background: rgba(148, 163, 184, 0.12); }
.legend-row { display: flex; gap: 14px; flex-wrap: wrap; margin-top: 12px; color: var(--muted); font-size: 12px; }
.legend { display: inline-block; width: 10px; height: 10px; border-radius: 50%; margin-right: 6px; }
.legend.robot { background: var(--blue); }
.legend.frame { background: #cbd5e1; }
.legend.safe { background: var(--green); }

.table-wrap { overflow: auto; border-radius: 14px; border: 1px solid rgba(148, 163, 184, 0.14); }
table { width: 100%; border-collapse: collapse; min-width: 620px; }
th, td { padding: 13px 14px; text-align: left; border-bottom: 1px solid rgba(148, 163, 184, 0.10); font-size: 13px; }
th { color: #93c5fd; font-weight: 700; background: rgba(15, 23, 42, 0.72); }
td { color: #d9e4f3; }
tr:last-child td { border-bottom: 0; }
.status-pill { display: inline-flex; padding: 5px 8px; border-radius: 999px; font-size: 11px; border: 1px solid var(--line); }
.status-pill.ok { color: #bbf7d0; background: rgba(34, 197, 94, 0.09); border-color: rgba(34, 197, 94, 0.3); }
.status-pill.warn { color: #fde68a; background: rgba(245, 158, 11, 0.09); border-color: rgba(245, 158, 11, 0.3); }
.status-pill.blue { color: #bae6fd; background: rgba(56, 189, 248, 0.09); border-color: rgba(56, 189, 248, 0.3); }
.status-pill.fail { color: #fecaca; background: rgba(239, 68, 68, 0.09); border-color: rgba(239, 68, 68, 0.3); }

#trendCanvas, #pointCloudCanvas { width: 100%; max-width: 100%; border-radius: 14px; background: rgba(2, 6, 23, 0.28); }
.health-list { display: grid; gap: 10px; }
.health-item { display: flex; align-items: center; justify-content: space-between; padding: 12px; border-radius: 14px; background: rgba(15, 23, 42, 0.46); border: 1px solid rgba(148, 163, 184, 0.12); }
.health-item span { color: var(--muted); }
.health-item strong { color: var(--green); }

.point-cloud-card p { color: var(--muted); font-size: 13px; line-height: 1.5; }
.inspection-grid, .design-grid, .rules-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 14px;
}
.design-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.inspection-grid > div, .design-grid article, .rules-grid > div {
  padding: 16px;
  border: 1px solid rgba(148, 163, 184, 0.14);
  border-radius: 16px;
  background: rgba(15, 23, 42, 0.46);
}
.inspection-grid strong, .rules-grid strong { color: #bfdbfe; }
.inspection-grid p, .design-grid p, .rules-grid p { color: var(--muted); line-height: 1.5; margin-bottom: 0; }
.design-grid h4 { margin: 0 0 8px; color: #e0f2fe; }

.timeline { display: grid; gap: 12px; }
.timeline-step {
  display: grid;
  grid-template-columns: 46px 1fr auto;
  align-items: center;
  gap: 12px;
  padding: 14px;
  border: 1px solid rgba(148, 163, 184, 0.14);
  border-radius: 16px;
  background: rgba(15, 23, 42, 0.46);
}
.timeline-step.active { border-color: rgba(56, 189, 248, 0.45); background: rgba(56, 189, 248, 0.08); }
.step-index { width: 38px; height: 38px; display: grid; place-items: center; border-radius: 12px; background: rgba(56, 189, 248, 0.12); color: #7dd3fc; font-weight: 800; }
.timeline-step h4 { margin: 0 0 3px; }
.timeline-step p { margin: 0; color: var(--muted); font-size: 13px; }

.form-grid {
  display: grid;
  gap: 14px;
}
.form-grid.two { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.form-grid label {
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: center;
  gap: 8px;
  color: var(--muted);
  font-size: 13px;
}
.form-grid input, .form-grid select {
  grid-column: 1 / -1;
  width: 100%;
  border: 1px solid rgba(148, 163, 184, 0.26);
  border-radius: 12px;
  background: rgba(2, 6, 23, 0.35);
  color: #e5edf8;
  padding: 10px 12px;
  outline: none;
}
.form-grid input:focus, .form-grid select:focus { border-color: rgba(56, 189, 248, 0.58); }
.form-grid label span { color: var(--muted-2); font-size: 12px; }

.code-block {
  white-space: pre-wrap;
  overflow: auto;
  margin: 0;
  padding: 16px;
  border-radius: 14px;
  border: 1px solid rgba(56, 189, 248, 0.20);
  background: rgba(2, 6, 23, 0.44);
  color: #bfdbfe;
  line-height: 1.7;
}

.settings-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 340px;
  gap: 16px;
}
.settings-tabs {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-bottom: 16px;
}
.settings-tab {
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 9px 12px;
  color: #cbd5e1;
  background: rgba(15, 23, 42, 0.55);
}
.settings-tab.active { color: white; border-color: rgba(56, 189, 248, 0.45); background: rgba(56, 189, 248, 0.12); }
.setting-pane { display: none; }
.setting-pane.active { display: block; }
.muted { color: var(--muted); line-height: 1.5; }
.version-card { display: grid; gap: 6px; padding: 14px; border: 1px solid rgba(56, 189, 248, 0.22); border-radius: 14px; background: rgba(56, 189, 248, 0.07); }
.version-card span { color: #bae6fd; }
.nice-list { margin: 0; padding-left: 18px; color: var(--muted); line-height: 1.9; }
.nice-list strong { color: #e2e8f0; }

.wireframe {
  position: relative;
  height: 360px;
  border-radius: 16px;
  border: 1px solid rgba(148, 163, 184, 0.16);
  background: rgba(2, 6, 23, 0.28);
  overflow: hidden;
}
.wireframe > div { position: absolute; border-radius: 12px; background: rgba(148, 163, 184, 0.16); border: 1px solid rgba(148, 163, 184, 0.13); }
.wf-header { left: 18px; right: 18px; top: 18px; height: 46px; }
.operator-wireframe .wf-status { left: 18px; top: 84px; width: 38%; height: 72px; background: rgba(34, 197, 94, 0.12); }
.operator-wireframe .wf-main { left: 18px; right: 140px; top: 174px; bottom: 92px; background: rgba(56, 189, 248, 0.08); }
.operator-wireframe .wf-side { right: 18px; top: 84px; width: 104px; bottom: 92px; }
.operator-wireframe .wf-button { bottom: 18px; width: 27%; height: 54px; }
.operator-wireframe .wf-button.big { left: 18px; background: rgba(56, 189, 248, 0.18); }
.operator-wireframe .wf-button:not(.big):not(.danger) { left: 36%; }
.operator-wireframe .wf-button.danger { right: 18px; background: rgba(239, 68, 68, 0.15); }
.dashboard-wireframe .wf-kpi { top: 84px; height: 68px; width: 28%; }
.dashboard-wireframe .wf-kpi:nth-of-type(2) { left: 18px; }
.dashboard-wireframe .wf-kpi:nth-of-type(3) { left: 36%; }
.dashboard-wireframe .wf-kpi:nth-of-type(4) { right: 18px; }
.dashboard-wireframe .wf-chart { left: 18px; right: 38%; top: 172px; bottom: 18px; background: rgba(56, 189, 248, 0.08); }
.dashboard-wireframe .wf-table { right: 18px; width: 33%; top: 172px; bottom: 18px; }

.log-list { display: grid; gap: 10px; max-height: 420px; overflow: auto; padding-right: 4px; }
.log-item { padding: 12px; border: 1px solid rgba(148, 163, 184, 0.12); border-radius: 14px; background: rgba(15, 23, 42, 0.44); }
.log-item strong { display: block; margin-bottom: 4px; }
.log-item span { color: var(--muted); font-size: 12px; }

.toast {
  position: fixed;
  right: 22px;
  bottom: 22px;
  z-index: 50;
  max-width: 360px;
  padding: 13px 15px;
  border-radius: 14px;
  border: 1px solid rgba(56, 189, 248, 0.32);
  background: rgba(2, 6, 23, 0.86);
  box-shadow: var(--shadow);
  color: #dbeafe;
  transform: translateY(20px);
  opacity: 0;
  pointer-events: none;
  transition: 0.24s ease;
}
.toast.show { opacity: 1; transform: translateY(0); }

@media (max-width: 1240px) {
  .app-shell { grid-template-columns: 1fr; }
  .sidebar { position: relative; height: auto; }
  .nav { grid-template-columns: repeat(4, minmax(0, 1fr)); }
  .simulation-layout, .settings-layout, .two-col, .two-col.wide-left { grid-template-columns: 1fr; }
  .kpi-grid, .dashboard-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (max-width: 760px) {
  .main { padding: 14px; }
  .topbar { margin: -14px -14px 16px; padding: 16px 14px; align-items: flex-start; flex-direction: column; }
  .nav { grid-template-columns: 1fr 1fr; }
  .kpi-grid, .dashboard-grid, .inspection-grid, .design-grid, .rules-grid, .form-grid.two { grid-template-columns: 1fr; }
  .canvas-toolbar { flex-direction: column; align-items: stretch; }
  #simCanvas { height: 480px; }
  .canvas-wrap { min-height: 480px; }
}
