:root {
  --bg: #071016;
  --bg2: #0b1820;
  --panel: rgba(13, 30, 39, 0.78);
  --panel2: rgba(16, 42, 52, 0.72);
  --line: rgba(118, 222, 229, 0.18);
  --text: #e7fbff;
  --muted: #8fb0bb;
  --cyan: #35d6e8;
  --teal: #2ae6b2;
  --amber: #ffc24d;
  --red: #ff6374;
  --green: #62ef9b;
  --blue: #6aa7ff;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: Inter, Arial, sans-serif;
  color: var(--text);
  background:
    radial-gradient(circle at 18% 10%, rgba(42, 230, 178, 0.16), transparent 28%),
    radial-gradient(circle at 78% 18%, rgba(53, 214, 232, 0.12), transparent 26%),
    linear-gradient(135deg, #05090d, var(--bg) 48%, #0c171b);
  overflow: hidden;
}

button {
  font: inherit;
  color: var(--text);
  background: linear-gradient(180deg, rgba(47, 216, 232, 0.22), rgba(42, 230, 178, 0.1));
  border: 1px solid rgba(53, 214, 232, 0.38);
  border-radius: 8px;
  height: 36px;
  padding: 0 14px;
  cursor: pointer;
  box-shadow: 0 0 22px rgba(53, 214, 232, 0.08);
}

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

.side-nav {
  padding: 18px 14px;
  border-right: 1px solid var(--line);
  background: linear-gradient(180deg, rgba(6, 18, 25, 0.96), rgba(7, 20, 27, 0.76));
  display: flex;
  flex-direction: column;
  gap: 18px;
}

.brand { display: flex; gap: 12px; align-items: center; min-height: 58px; }
.brand-mark {
  width: 48px;
  height: 48px;
  border: 1px solid rgba(42, 230, 178, 0.45);
  display: grid;
  place-items: center;
  border-radius: 10px;
  color: var(--teal);
  font-weight: 800;
  background: rgba(42, 230, 178, 0.08);
}
.brand strong { display: block; font-size: 15px; line-height: 1.2; }
.brand span, .nav-footer small { display: block; color: var(--muted); font-size: 11px; margin-top: 4px; }

#moduleNav { display: grid; gap: 8px; }
.nav-item {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  text-align: left;
  height: 43px;
  padding: 0 11px;
  border-color: rgba(143, 176, 187, 0.14);
  background: rgba(255,255,255,0.025);
}
.nav-item.active {
  border-color: rgba(42, 230, 178, 0.55);
  background: linear-gradient(90deg, rgba(42, 230, 178, 0.2), rgba(53, 214, 232, 0.08));
}
.nav-item b { font-size: 13px; font-weight: 700; }
.nav-item span { color: var(--muted); font-size: 11px; }

.nav-footer {
  margin-top: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  background: rgba(255, 255, 255, 0.03);
}
.nav-footer span { color: var(--muted); font-size: 12px; }
.nav-footer strong { display: block; margin-top: 4px; font-size: 20px; color: var(--cyan); }

.workspace {
  padding: 14px;
  display: grid;
  grid-template-rows: 64px 86px minmax(0, 1fr) 158px;
  gap: 10px;
  min-width: 0;
  height: 100vh;
  overflow: hidden;
}

.topbar, .kpi-card, .panel, .twin-stage {
  border: 1px solid var(--line);
  background: linear-gradient(180deg, var(--panel), rgba(8, 19, 25, 0.8));
  box-shadow: 0 14px 45px rgba(0, 0, 0, 0.24), inset 0 1px rgba(255, 255, 255, 0.04);
}

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0 14px;
  border-radius: 10px;
}
h1 { font-size: 20px; margin: 0; letter-spacing: 0; }
.topbar p { margin: 5px 0 0; color: var(--muted); font-size: 12px; }
.top-actions { display: flex; gap: 8px; }

.kpi-strip {
  display: grid;
  grid-template-columns: repeat(6, minmax(0, 1fr));
  gap: 10px;
}
.kpi-card {
  border-radius: 9px;
  padding: 10px 11px;
  position: relative;
  overflow: hidden;
}
.kpi-card::after {
  content: "";
  position: absolute;
  inset: auto 10px 8px 10px;
  height: 2px;
  background: linear-gradient(90deg, var(--cyan), transparent);
  opacity: .65;
}
.kpi-card label { color: var(--muted); font-size: 11px; text-transform: uppercase; }
.kpi-card strong { display: block; margin-top: 4px; font-size: 23px; }
.kpi-card span { color: var(--green); font-size: 11px; }
.kpi-card.warn span { color: var(--amber); }

.control-grid {
  min-height: 0;
  display: grid;
  grid-template-columns: 310px minmax(420px, 1fr) 300px;
  gap: 10px;
}
.control-grid > *, .bottom-grid > * { min-height: 0; }
.bottom-grid {
  display: grid;
  grid-template-columns: 1.1fr 1fr 1.1fr;
  gap: 10px;
  min-height: 0;
}

.panel, .twin-stage { border-radius: 10px; min-height: 0; }
.panel { padding: 10px; overflow: hidden; display: flex; flex-direction: column; }
.panel-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 10px;
}
.panel-head h2, .twin-toolbar h2 { font-size: 14px; margin: 0; }
.panel-head span {
  color: var(--teal);
  border: 1px solid rgba(42, 230, 178, 0.22);
  border-radius: 999px;
  padding: 3px 8px;
  font-size: 10px;
}

.module-content { display: grid; gap: 7px; overflow: auto; max-height: calc(100% - 30px); padding-right: 2px; }
.overview-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}
.mini-kpi {
  border: 1px solid rgba(53, 214, 232, .18);
  border-radius: 8px;
  padding: 10px;
  background: linear-gradient(180deg, rgba(53, 214, 232, .08), rgba(255,255,255,.02));
}
.mini-kpi span, .mini-kpi em { display: block; color: var(--muted); font-size: 10px; font-style: normal; }
.mini-kpi strong { display: block; margin: 4px 0; font-size: 22px; }
.dense-table {
  display: grid;
  gap: 6px;
}
.dense-table div {
  display: grid;
  grid-template-columns: 1.1fr .8fr .7fr .9fr;
  gap: 6px;
  padding: 8px;
  border-radius: 7px;
  border: 1px solid rgba(143,176,187,.12);
  background: rgba(255,255,255,.025);
}
.dense-table span { font-size: 10px; color: var(--muted); }
.dense-table span:first-child { color: var(--text); font-weight: 700; }

.timeline-view {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 7px;
  height: 136px;
  align-items: end;
}
.milestone {
  height: 100%;
  display: grid;
  grid-template-rows: 1fr auto auto;
  gap: 5px;
  min-width: 0;
}
.milestone i {
  display: block;
  align-self: end;
  border-radius: 6px 6px 2px 2px;
  background: linear-gradient(180deg, var(--cyan), rgba(42,230,178,.25));
}
.milestone strong, .milestone span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.milestone strong { font-size: 10px; }
.milestone span { color: var(--muted); font-size: 9px; }
.change-list, .risk-cards, .andon-list, .agenda-view, .owner-score, .link-list {
  display: grid;
  gap: 7px;
}
.change-list div, .risk-cards div, .andon-list div, .agenda-view div, .asset-row, .owner-score div, .link-list div {
  border: 1px solid rgba(143,176,187,.12);
  background: rgba(255,255,255,.025);
  border-radius: 7px;
  padding: 8px;
}
.change-list b, .risk-cards strong, .andon-list b, .agenda-view b, .asset-row strong, .owner-score strong, .link-list b {
  display: block;
  font-size: 11px;
}
.change-list span, .risk-cards span, .andon-list span, .agenda-view span, .asset-row em, .owner-score em, .link-list span {
  color: var(--muted);
  font-size: 10px;
  font-style: normal;
}
.change-list em, .risk-cards em, .andon-list em, .agenda-view em, .link-list em {
  float: right;
  color: var(--teal);
  font-size: 10px;
  font-style: normal;
}

.gantt-view {
  display: grid;
  gap: 9px;
  padding: 4px 0 2px;
}
.gantt-row {
  display: grid;
  grid-template-columns: 78px 1fr;
  gap: 8px;
  align-items: center;
}
.gantt-row strong, .gantt-row em { font-size: 10px; font-style: normal; color: var(--muted); }
.gantt-row span {
  position: relative;
  display: block;
  height: 18px;
  border: 1px solid rgba(143,176,187,.13);
  border-radius: 999px;
  background: repeating-linear-gradient(90deg, rgba(143,176,187,.08), rgba(143,176,187,.08) 1px, transparent 1px, transparent 18px);
}
.gantt-row i {
  position: absolute;
  top: 3px;
  bottom: 3px;
  border-radius: 999px;
  background: linear-gradient(90deg, var(--cyan), var(--amber));
}
.gantt-row em { grid-column: 2; margin-top: -5px; }

.topology {
  position: relative;
  height: 160px;
  border: 1px solid rgba(53,214,232,.16);
  border-radius: 8px;
  background:
    radial-gradient(circle at center, rgba(53,214,232,.18), transparent 36%),
    linear-gradient(45deg, transparent 49%, rgba(53,214,232,.13) 50%, transparent 51%);
}
.node {
  position: absolute;
  width: 54px;
  height: 28px;
  display: grid;
  place-items: center;
  border: 1px solid rgba(53,214,232,.42);
  border-radius: 7px;
  background: rgba(10, 31, 39, .88);
  font-size: 10px;
  font-weight: 800;
}
.node.mes { left: calc(50% - 27px); top: calc(50% - 14px); color: var(--teal); }
.node.n0 { left: 16px; top: 18px; }
.node.n1 { right: 18px; top: 18px; }
.node.n2 { left: 20px; bottom: 20px; }
.node.n3 { right: 18px; bottom: 20px; }
.node.n4 { left: calc(50% - 27px); top: 12px; }
.node.n5 { left: calc(50% - 27px); bottom: 12px; }
.link-list div { display: grid; grid-template-columns: 38px 1fr 42px; align-items: center; gap: 6px; }
.link-list i {
  grid-column: 1 / -1;
  height: 4px;
  border-radius: 999px;
  background: linear-gradient(90deg, var(--teal), var(--cyan));
}

.line-view {
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  gap: 7px;
  height: 150px;
  align-items: end;
}
.line-stage {
  display: grid;
  grid-template-rows: auto 1fr auto auto;
  height: 100%;
  gap: 5px;
  min-width: 0;
}
.line-stage strong, .line-stage span, .line-stage em {
  font-size: 9px;
  text-align: center;
  color: var(--muted);
  font-style: normal;
  overflow: hidden;
  text-overflow: ellipsis;
}
.line-stage i {
  align-self: end;
  border-radius: 7px 7px 2px 2px;
  background: linear-gradient(180deg, var(--teal), rgba(53,214,232,.2));
}

.radar-layout {
  display: grid;
  grid-template-columns: 145px 1fr;
  gap: 8px;
}
.radar-layout svg {
  width: 145px;
  height: 150px;
}
.radar-layout polygon {
  fill: rgba(53,214,232,.08);
  stroke: rgba(53,214,232,.28);
}
.radar-layout polyline {
  fill: rgba(42,230,178,.28);
  stroke: var(--teal);
  stroke-width: 2;
}
.radar-layout circle { fill: var(--amber); }
.asset-row {
  display: grid;
  grid-template-columns: 1fr 36px;
  gap: 4px;
  padding: 6px;
}
.asset-row strong, .asset-row span, .asset-row em { font-size: 9px; }
.asset-row span { color: var(--teal); text-align: right; }
.asset-row em { grid-column: 1 / -1; }

.spc-view svg {
  width: 100%;
  height: 118px;
  border: 1px solid rgba(53,214,232,.13);
  border-radius: 8px;
  background: rgba(255,255,255,.02);
}
.spc-view polyline {
  fill: none;
  stroke: var(--cyan);
  stroke-width: 2;
}
.spc-view .limit { stroke: rgba(255, 99, 116, .6); stroke-dasharray: 4 4; }
.spc-view .target { stroke: rgba(42,230,178,.55); }
.defect-bars {
  display: grid;
  gap: 6px;
  margin-top: 7px;
}
.defect-bars div {
  display: grid;
  grid-template-columns: 54px 1fr 28px;
  gap: 7px;
  align-items: center;
  font-size: 10px;
  color: var(--muted);
}
.defect-bars i {
  height: 7px;
  border-radius: 999px;
  background: linear-gradient(90deg, var(--amber), var(--red));
}
.trace-chain {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}
.trace-chain span {
  border: 1px solid rgba(42,230,178,.25);
  border-radius: 999px;
  padding: 4px 7px;
  color: var(--teal);
  font-size: 10px;
}

.agenda-view div {
  display: grid;
  grid-template-columns: 42px 1fr 42px;
  gap: 7px;
  align-items: center;
}
.owner-score div {
  display: grid;
  grid-template-columns: 82px 1fr 34px;
  gap: 7px;
  align-items: center;
}
.owner-score span {
  height: 6px;
  border-radius: 999px;
  background: rgba(143,176,187,.14);
  overflow: hidden;
}
.owner-score i {
  display: block;
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, var(--cyan), var(--teal));
}

.metric-row, .data-row, .task-row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 10px;
  align-items: center;
  border: 1px solid rgba(143, 176, 187, 0.12);
  background: rgba(255, 255, 255, 0.025);
  border-radius: 8px;
  padding: 7px 8px;
}
.metric-row strong, .data-row strong, .task-row strong { font-size: 12px; }
.metric-row span, .data-row span, .task-row span { color: var(--muted); font-size: 11px; }
.bar {
  grid-column: 1 / -1;
  height: 5px;
  border-radius: 999px;
  background: rgba(143, 176, 187, 0.13);
  overflow: hidden;
}
.bar i { display: block; height: 100%; border-radius: inherit; background: linear-gradient(90deg, var(--cyan), var(--teal)); }

.twin-stage {
  display: grid;
  grid-template-rows: 56px minmax(0, 1fr) 42px;
  overflow: hidden;
  position: relative;
}
.twin-toolbar, .twin-bottom {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0 14px;
  border-bottom: 1px solid var(--line);
  background: rgba(7, 16, 22, 0.42);
}
.twin-toolbar span { color: var(--muted); font-size: 11px; }
.legend { display: flex; gap: 12px; }
.legend span { display: flex; gap: 5px; align-items: center; }
.legend i { width: 8px; height: 8px; border-radius: 50%; display: inline-block; }
.ok { background: var(--green); }
.warn { background: var(--amber); }
.bad { background: var(--red); }
.factory-twin {
  min-height: 0;
  position: relative;
  background:
    linear-gradient(rgba(53, 214, 232, 0.05) 1px, transparent 1px),
    linear-gradient(90deg, rgba(53, 214, 232, 0.05) 1px, transparent 1px),
    radial-gradient(circle at center, rgba(38, 110, 125, 0.18), transparent 55%);
  background-size: 28px 28px, 28px 28px, cover;
}
.factory-twin canvas { display: block; width: 100%; height: 100%; }
.twin-bottom { border-top: 1px solid var(--line); border-bottom: 0; }
.event-ticker { color: var(--muted); font-size: 12px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.mini-map { display: flex; gap: 4px; align-items: end; height: 20px; }
.mini-map span { display: block; width: 22px; background: var(--cyan); opacity: .75; }
.mini-map span:nth-child(1) { height: 8px; }
.mini-map span:nth-child(2) { height: 14px; background: var(--teal); }
.mini-map span:nth-child(3) { height: 18px; background: var(--amber); }
.mini-map span:nth-child(4) { height: 11px; }
.mini-map span:nth-child(5) { height: 16px; background: var(--green); }

.right-stack { display: grid; grid-template-rows: 1fr 1fr; gap: 12px; min-height: 0; }
.insight-list, .interface-matrix, .action-list { display: grid; gap: 8px; overflow: auto; }
.insight {
  border-left: 3px solid var(--cyan);
  padding: 7px 8px;
  background: rgba(53, 214, 232, 0.055);
  border-radius: 6px;
}
.insight h3 { margin: 0 0 5px; font-size: 12px; }
.insight p { margin: 0; color: var(--muted); font-size: 11px; line-height: 1.45; }
.interface-row {
  display: grid;
  grid-template-columns: 64px 1fr 42px;
  gap: 8px;
  align-items: center;
  font-size: 11px;
}
.sparkline { height: 5px; border-radius: 999px; background: rgba(143,176,187,.14); overflow: hidden; }
.sparkline i { display: block; height: 100%; background: linear-gradient(90deg, var(--teal), var(--cyan)); }
.status { color: var(--green); text-align: right; }
.status.warn { color: var(--amber); }

.flow-chart { display: grid; grid-template-columns: repeat(6, 1fr); gap: 8px; height: 98px; align-items: end; }
.flow-step {
  display: grid;
  align-content: end;
  gap: 7px;
  height: 100%;
}
.flow-step i {
  display: block;
  border-radius: 7px 7px 3px 3px;
  background: linear-gradient(180deg, rgba(53, 214, 232, 0.85), rgba(42, 230, 178, 0.35));
  border: 1px solid rgba(53,214,232,.22);
}
.flow-step span { font-size: 10px; color: var(--muted); text-align: center; }

canvas#qualityChart { width: 100%; min-height: 0; }
.task-row { grid-template-columns: auto 1fr auto; padding: 8px; }
.task-row em {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--cyan);
  font-style: normal;
}
.task-row small { color: var(--muted); }

@media (max-width: 1200px) {
  body { overflow: auto; }
  .app-shell { min-width: 0; grid-template-columns: 1fr; height: auto; }
  .side-nav { display: none; }
  .workspace { grid-template-rows: auto; height: auto; overflow: visible; }
  .topbar { min-height: 0; align-items: flex-start; gap: 12px; }
  .control-grid, .bottom-grid, .kpi-strip { grid-template-columns: 1fr; }
  .twin-stage { min-height: 560px; }
}

@media (max-width: 640px) {
  .workspace { padding: 14px; }
  .topbar { flex-direction: column; padding: 14px; }
  h1 { font-size: 18px; line-height: 1.12; }
  .topbar p { font-size: 12px; line-height: 1.35; }
  .top-actions { width: 100%; display: grid; grid-template-columns: 1fr 1fr; }
  .top-actions button { height: 42px; padding: 0 8px; font-size: 12px; }
  .kpi-strip { gap: 10px; }
  .kpi-card strong { font-size: 24px; }
  .twin-stage { min-height: 520px; }
  .twin-toolbar { align-items: flex-start; flex-direction: column; gap: 6px; padding: 12px; }
  .legend { flex-wrap: wrap; }
}
