:root {
  --bg: #071018;
  --panel: #0d1823;
  --panel-2: #111f2d;
  --line: rgba(185, 205, 225, .14);
  --text: #eef6ff;
  --muted: #9fb0c4;
  --blue: #3b82f6;
  --cyan: #22d3ee;
  --green: #22c55e;
  --amber: #f59e0b;
  --red: #ef4444;
  --shadow: 0 22px 70px rgba(0, 0, 0, .34);
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; }
body {
  margin: 0;
  min-width: 320px;
  background:
    linear-gradient(115deg, rgba(34, 211, 238, .08), transparent 32%),
    linear-gradient(245deg, rgba(34, 197, 94, .06), transparent 34%),
    var(--bg);
  color: var(--text);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

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

.loginShell {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
}

.loginCard {
  width: min(980px, 100%);
  min-height: 580px;
  display: grid;
  grid-template-columns: 1.05fr .95fr;
  border: 1px solid var(--line);
  border-radius: 10px;
  overflow: hidden;
  background: rgba(13, 24, 35, .86);
  box-shadow: var(--shadow);
  animation: rise .55s ease both;
}

.loginVisual {
  position: relative;
  padding: 34px;
  background:
    linear-gradient(135deg, rgba(59, 130, 246, .24), transparent 46%),
    linear-gradient(180deg, #0f2232, #08121d);
  overflow: hidden;
}

.loginVisual::before {
  content: "";
  position: absolute;
  inset: 28px;
  border: 1px solid rgba(148, 163, 184, .18);
  border-radius: 10px;
  transform: perspective(900px) rotateX(62deg) rotateZ(-8deg);
  transform-origin: bottom;
  background:
    linear-gradient(rgba(34, 211, 238, .18) 1px, transparent 1px),
    linear-gradient(90deg, rgba(34, 211, 238, .15) 1px, transparent 1px);
  background-size: 36px 36px;
}

.loginVisual h1 {
  position: relative;
  margin: 0;
  font-size: clamp(34px, 5vw, 62px);
  line-height: 1;
  letter-spacing: 0;
}

.loginVisual p {
  position: relative;
  max-width: 440px;
  margin: 16px 0 0;
  color: #cbd5e1;
  line-height: 1.55;
}

.loginFlow {
  position: absolute;
  left: 34px;
  right: 34px;
  bottom: 34px;
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 10px;
}

.flowMini {
  border: 1px solid rgba(255,255,255,.13);
  background: rgba(0,0,0,.24);
  border-radius: 8px;
  padding: 12px;
  min-height: 96px;
  backdrop-filter: blur(10px);
}

.flowMini b { display: block; margin-bottom: 8px; }
.flowMini span { display: block; color: var(--muted); font-size: 12px; line-height: 1.35; }

.loginForm {
  padding: 34px;
  display: grid;
  align-content: center;
  gap: 14px;
}

.loginForm h2 { margin: 0; font-size: 25px; }
.loginForm p { margin: 0 0 8px; color: var(--muted); line-height: 1.45; }

.field { display: grid; gap: 7px; }
.field span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 850;
  text-transform: uppercase;
}

input, select, textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(5, 10, 18, .72);
  color: var(--text);
  padding: 11px 12px;
  outline: none;
}

textarea { min-height: 104px; resize: vertical; }
input[type="file"] {
  padding: 9px;
  color: var(--muted);
}
input:focus, select:focus, textarea:focus { border-color: rgba(34, 211, 238, .66); box-shadow: 0 0 0 3px rgba(34, 211, 238, .1); }

.primaryBtn, .ghostBtn, .dangerBtn {
  border: 1px solid var(--line);
  border-radius: 8px;
  min-height: 42px;
  padding: 10px 13px;
  color: var(--text);
  background: rgba(255,255,255,.07);
  font-weight: 850;
  transition: transform .14s ease, border-color .14s ease, background .14s ease;
}

.primaryBtn {
  border-color: rgba(59, 130, 246, .85);
  background: linear-gradient(135deg, #2563eb, #0891b2);
  box-shadow: 0 16px 38px rgba(37, 99, 235, .22);
}

.dangerBtn { color: #fecaca; border-color: rgba(239, 68, 68, .3); }
.primaryBtn:hover, .ghostBtn:hover, .dangerBtn:hover { transform: translateY(-1px); border-color: rgba(34, 211, 238, .68); }

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

.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  padding: 14px;
  border-right: 1px solid var(--line);
  background: rgba(5, 12, 20, .74);
  backdrop-filter: blur(14px);
  overflow: auto;
}

.brand {
  display: flex;
  align-items: center;
  gap: 11px;
  padding: 9px 8px 18px;
}

.brandMark {
  width: 40px;
  height: 40px;
  display: grid;
  place-items: center;
  border-radius: 9px;
  background: linear-gradient(135deg, var(--blue), var(--green));
  font-weight: 950;
}

.brand b, .brand span { display: block; }
.brand span { color: var(--muted); font-size: 12px; margin-top: 2px; }

.userBox {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  background: rgba(255,255,255,.055);
  margin-bottom: 12px;
}

.userBox b { display: block; overflow-wrap: anywhere; }
.userBox span { display: block; color: var(--muted); font-size: 12px; margin-top: 5px; }

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

.nav button {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  border: 1px solid transparent;
  border-radius: 8px;
  background: transparent;
  color: #dce8f6;
  padding: 10px;
  text-align: left;
  font-weight: 760;
}

.nav button i {
  width: 28px;
  height: 28px;
  display: grid;
  place-items: center;
  border-radius: 8px;
  background: rgba(255,255,255,.07);
  font-style: normal;
  font-size: 12px;
}

.nav button.active {
  border-color: rgba(34, 211, 238, .22);
  background: rgba(34, 211, 238, .1);
}

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

.topbar {
  min-height: 74px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: rgba(13, 24, 35, .78);
  padding: 14px 16px;
  box-shadow: 0 14px 46px rgba(0,0,0,.18);
  animation: rise .45s ease both;
}

.topbar h1 { margin: 0; font-size: 24px; letter-spacing: 0; }
.topbar p { margin: 3px 0 0; color: var(--muted); }
.topActions { display: flex; gap: 8px; flex-wrap: wrap; justify-content: flex-end; }

.gridKpis {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 10px;
  margin: 12px 0;
}

.kpi, .panel, .record, .insight {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(13, 24, 35, .74);
  box-shadow: 0 14px 42px rgba(0,0,0,.16);
}

.kpi {
  padding: 14px;
  animation: rise .45s ease both;
}

.kpi span { display: block; color: var(--muted); font-size: 12px; font-weight: 850; text-transform: uppercase; }
.kpi b { display: block; margin-top: 7px; font-size: 26px; }
.kpi small { display: block; color: var(--muted); margin-top: 5px; }

.contentGrid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 370px;
  gap: 12px;
  align-items: start;
}

.panel {
  padding: 14px;
  animation: rise .5s ease both;
}

.panelHead {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 12px;
  margin-bottom: 12px;
}

.panelHead h2 { margin: 0; font-size: 17px; }
.panelHead p { margin: 4px 0 0; color: var(--muted); line-height: 1.4; }

.records {
  display: grid;
  gap: 9px;
}

.record {
  padding: 12px;
  display: grid;
  gap: 8px;
  transition: transform .14s ease, border-color .14s ease, background .14s ease;
}

.record:hover {
  transform: translateY(-1px);
  border-color: rgba(34, 211, 238, .28);
  background: rgba(17, 31, 45, .88);
}

.recordTop {
  display: flex;
  justify-content: space-between;
  gap: 10px;
}

.record h3 {
  margin: 0;
  font-size: 15px;
  overflow-wrap: anywhere;
}

.record p {
  margin: 0;
  color: var(--muted);
  line-height: 1.45;
  white-space: pre-wrap;
}

.metaLine {
  display: flex;
  gap: 7px;
  flex-wrap: wrap;
}

.pill {
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 5px 8px;
  background: rgba(255,255,255,.05);
  color: #cbd5e1;
  font-size: 12px;
  font-weight: 760;
}

.pill.green { color: #bbf7d0; border-color: rgba(34,197,94,.28); background: rgba(34,197,94,.1); }
.pill.amber { color: #fde68a; border-color: rgba(245,158,11,.28); background: rgba(245,158,11,.1); }
.pill.blue { color: #bfdbfe; border-color: rgba(59,130,246,.32); background: rgba(59,130,246,.12); }

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

.formGrid .wide { grid-column: 1 / -1; }
.formActions { display: flex; gap: 8px; margin-top: 12px; flex-wrap: wrap; }

.insights {
  display: grid;
  gap: 10px;
  margin-top: 12px;
}

.insight {
  padding: 13px;
  display: grid;
  gap: 6px;
}

.insight b { font-size: 14px; }
.insight span { color: var(--muted); font-size: 13px; line-height: 1.4; }

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

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

.imageGrid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(92px, 1fr));
  gap: 8px;
}

.imageGrid a {
  display: block;
  aspect-ratio: 4 / 3;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255,255,255,.05);
}

.imageGrid img {
  width: 100%;
  height: 100%;
  display: block;
  object-fit: cover;
}

.fileList {
  display: grid;
  gap: 6px;
}

.fileList a {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 9px 10px;
  color: #dbeafe;
  text-decoration: none;
  background: rgba(255,255,255,.045);
  overflow-wrap: anywhere;
}

.fileList span {
  flex: 0 0 auto;
  color: var(--muted);
  font-size: 12px;
}

.steps {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}

.steps span {
  border: 1px solid rgba(34, 211, 238, .22);
  border-radius: 999px;
  padding: 6px 9px;
  color: #bfdbfe;
  background: rgba(34, 211, 238, .08);
  font-size: 12px;
  font-weight: 760;
}

.existingFiles {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 9px;
  background: rgba(255,255,255,.035);
}

.factoryMap {
  position: relative;
  min-height: 620px;
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: auto;
  background:
    rgba(5, 10, 18, .58);
  cursor: grab;
}

.factoryWorld {
  position: relative;
  width: 1200px;
  height: 760px;
  transform: translate(var(--pan-x), var(--pan-y)) scale(var(--zoom));
  transform-origin: 0 0;
  background:
    linear-gradient(rgba(148, 163, 184, .13) 1px, transparent 1px),
    linear-gradient(90deg, rgba(148, 163, 184, .13) 1px, transparent 1px),
    rgba(5, 10, 18, .42);
  background-size: var(--grid-size) var(--grid-size);
  background-position: 0 0;
  background-repeat: repeat;
}

.factoryWorld::before {
  content: "";
  position: absolute;
  inset: 0;
  background-image: var(--floor-bg);
  background-size: contain;
  background-position: center;
  background-repeat: no-repeat;
  opacity: .42;
  pointer-events: none;
}

.layoutToolbar {
  display: grid;
  grid-template-columns: auto repeat(3, minmax(96px, 130px)) minmax(180px, 1fr);
  gap: 8px;
  align-items: end;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px;
  margin-bottom: 10px;
  background: rgba(255,255,255,.04);
}

.layoutToolbar label {
  display: grid;
  gap: 5px;
}

.layoutToolbar label span {
  color: var(--muted);
  font-size: 11px;
  font-weight: 850;
  text-transform: uppercase;
}

.layoutToolbar input {
  min-height: 38px;
  padding: 8px 9px;
}

.toolGroup, .layerToggles, .drawTools, .selectionTools {
  display: flex;
  gap: 6px;
  align-items: center;
  flex-wrap: wrap;
}

.toolGroup span {
  min-width: 48px;
  text-align: center;
  color: #bfdbfe;
  font-weight: 850;
}

.layerToggles {
  grid-column: 1 / -1;
}

.drawTools {
  width: 100%;
  padding-bottom: 2px;
}

.drawTools button, .layerToggles button {
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 7px 10px;
  color: var(--muted);
  background: rgba(255,255,255,.04);
  font-weight: 850;
}

.selectionTools {
  width: 100%;
  padding-top: 2px;
}

.selectionTools span {
  color: #bfdbfe;
  font-size: 12px;
  font-weight: 850;
}

.selectionTools button {
  border: 1px solid rgba(34, 211, 238, .28);
  border-radius: 999px;
  padding: 7px 10px;
  color: #cffafe;
  background: rgba(34, 211, 238, .08);
  font-weight: 850;
}

.selectionTools button:disabled {
  cursor: not-allowed;
  color: rgba(148, 163, 184, .68);
  border-color: rgba(148, 163, 184, .18);
  background: rgba(148, 163, 184, .05);
}

.drawTools button.active {
  color: #bfdbfe;
  border-color: rgba(59,130,246,.48);
  background: rgba(59,130,246,.16);
}

.layerToggles button.active {
  color: #bbf7d0;
  border-color: rgba(34,197,94,.36);
  background: rgba(34,197,94,.12);
}

.stagingLane {
  display: grid;
  gap: 8px;
  border: 1px dashed rgba(34, 211, 238, .32);
  border-radius: 8px;
  padding: 10px;
  margin-bottom: 10px;
  background: rgba(34, 211, 238, .045);
}

.stagingLane > b { font-size: 13px; color: #bfdbfe; }
.stagingLane > span, .stagingLane .orderBadges > span { color: var(--muted); font-size: 13px; }

.station {
  position: absolute;
  display: grid;
  align-content: start;
  gap: 5px;
  min-width: 130px;
  min-height: 96px;
  border: 1px solid rgba(34, 211, 238, .32);
  border-radius: 8px;
  padding: 9px;
  background: rgba(13, 24, 35, .92);
  box-shadow: 0 14px 36px rgba(0,0,0,.24);
  overflow: auto;
  z-index: 3;
}

.station b { overflow-wrap: anywhere; }
.station span, .station small { color: var(--muted); font-size: 12px; line-height: 1.3; }

.orderBadges {
  display: grid;
  gap: 5px;
  margin-top: 5px;
}

.orderBadges button {
  border: 1px solid rgba(245,158,11,.28);
  border-radius: 7px;
  padding: 6px;
  color: #fde68a;
  background: rgba(245,158,11,.1);
  font-size: 11px;
  text-align: left;
  touch-action: none;
}

.orderBadges button:active {
  border-color: rgba(34, 211, 238, .5);
  background: rgba(34, 211, 238, .12);
}

.layoutObject {
  position: absolute;
  z-index: 1;
  display: grid;
  align-content: start;
  gap: 2px;
  border: 1px solid color-mix(in srgb, var(--item-color) 68%, white);
  border-radius: 6px;
  padding: 7px;
  color: #eef6ff;
  background: color-mix(in srgb, var(--item-color) 34%, transparent);
  box-shadow: inset 0 0 0 999px rgba(0,0,0,.14);
  overflow: hidden;
  user-select: none;
  touch-action: none;
}

.layoutObject b {
  font-size: 12px;
  line-height: 1.15;
  overflow-wrap: anywhere;
}

.layoutObject span {
  color: rgba(238,246,255,.78);
  font-size: 10px;
  text-transform: uppercase;
}

.layoutObject.caminho, .layoutObject.parede {
  border-radius: 3px;
  padding: 4px 6px;
}

.layoutObject.parede {
  background: rgba(15, 23, 42, .86);
  border-color: rgba(226, 232, 240, .32);
}

.layoutObject.locked {
  opacity: .82;
}

.layoutObject.selected {
  z-index: 6;
  outline: 2px solid #22d3ee;
  outline-offset: 2px;
  box-shadow: inset 0 0 0 999px rgba(0,0,0,.08), 0 0 0 4px rgba(34,211,238,.14);
}

.layoutObject.drawingPreview {
  z-index: 8;
  opacity: .78;
  pointer-events: none;
  border-style: dashed;
}

.layoutObject i {
  position: absolute;
  right: 0;
  bottom: 0;
  width: 18px;
  height: 18px;
  border-top: 1px solid rgba(255,255,255,.45);
  border-left: 1px solid rgba(255,255,255,.45);
  background: rgba(255,255,255,.16);
  cursor: nwse-resize;
}

.flowBox {
  display: grid;
  gap: 9px;
  border: 1px solid rgba(34, 211, 238, .22);
  border-radius: 8px;
  padding: 10px;
  margin: 10px 0;
  background: rgba(8, 47, 73, .16);
}

.flowSteps, .flowActions, .flowState, .flowLog {
  display: flex;
  gap: 7px;
  align-items: center;
  flex-wrap: wrap;
}

.flowSteps span {
  border: 1px solid rgba(148, 163, 184, .22);
  border-radius: 999px;
  padding: 6px 9px;
  color: var(--muted);
  background: rgba(255,255,255,.035);
  font-size: 12px;
  font-weight: 850;
}

.flowSteps span.done {
  color: #bbf7d0;
  border-color: rgba(34,197,94,.34);
  background: rgba(34,197,94,.1);
}

.flowSteps span.active {
  color: #bfdbfe;
  border-color: rgba(59,130,246,.5);
  background: rgba(59,130,246,.15);
}

.flowActions button {
  border: 1px solid rgba(34, 211, 238, .28);
  border-radius: 7px;
  padding: 7px 9px;
  color: #cffafe;
  background: rgba(34, 211, 238, .08);
  font-weight: 850;
}

.flowState span, .flowLog span {
  color: var(--muted);
  font-size: 12px;
}

.flowLog {
  display: grid;
  align-items: stretch;
}

.overloadedRecord {
  border-color: rgba(245, 158, 11, .42);
  background: rgba(120, 53, 15, .14);
}

.machineQueue {
  display: grid;
  gap: 6px;
  margin-top: 8px;
}

.machineQueue button {
  display: grid;
  gap: 3px;
  border: 1px solid rgba(148, 163, 184, .2);
  border-radius: 7px;
  padding: 8px;
  text-align: left;
  color: #dbeafe;
  background: rgba(15, 23, 42, .35);
}

.machineQueue button b {
  font-size: 12px;
}

.machineQueue button span {
  color: var(--muted);
  font-size: 11px;
}

table {
  width: 100%;
  border-collapse: collapse;
  min-width: 620px;
}

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

th { color: #bfdbfe; background: rgba(59,130,246,.08); }
td { color: #dbeafe; }

.alert {
  border: 1px solid rgba(239, 68, 68, .35);
  background: rgba(127, 29, 29, .2);
  color: #fecaca;
  border-radius: 8px;
  padding: 11px 12px;
  margin: 12px 0;
  font-weight: 760;
}

.okAlert {
  border-color: rgba(34,197,94,.35);
  background: rgba(20,83,45,.22);
  color: #bbf7d0;
}

.mobileMenu { display: none; }

@keyframes rise {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: translateY(0); }
}

@media (max-width: 1180px) {
  .appShell { grid-template-columns: 1fr; }
  .sidebar {
    display: none;
    position: fixed;
    inset: 0 auto 0 0;
    z-index: 20;
    width: min(86vw, 330px);
  }
  .sidebar.open { display: block; }
  .mobileMenu { display: inline-flex; }
  .contentGrid { grid-template-columns: 1fr; }
}

@media (max-width: 820px) {
  .loginCard { grid-template-columns: 1fr; }
  .loginVisual { min-height: 420px; }
  .loginFlow { grid-template-columns: 1fr 1fr; }
  .gridKpis { grid-template-columns: 1fr 1fr; }
  .formGrid { grid-template-columns: 1fr; }
  .layoutToolbar { grid-template-columns: 1fr; }
  .layerToggles { grid-column: auto; }
  .topbar { align-items: stretch; display: grid; }
  .topActions { justify-content: flex-start; }
}

@media (max-width: 520px) {
  .main, .loginShell { padding: 10px; }
  .gridKpis, .loginFlow { grid-template-columns: 1fr; }
  .loginForm, .loginVisual { padding: 20px; }
}
