/* DG-1 示範量測機 ── 畫面樣式。純前端，無外部字型/資源。 */

:root {
  --bg: #0f1621;
  --panel: #182331;
  --panel-2: #1f2d3e;
  --line: #2b3b4f;
  --text: #e8eef6;
  --muted: #9fb0c4;
  --ok: #37c978;
  --ok-dim: #1d7d4c;
  --warn: #f3b705;
  --fault: #ff5a5a;
  --offline: #7a8aa0;
  --accent: #4aa8ff;
  --shadow: 0 8px 24px rgba(0, 0, 0, .35);
  color-scheme: dark;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, "Segoe UI", "PingFang TC", "Microsoft JhengHei", sans-serif;
  line-height: 1.5;
}

.wrap { max-width: 1100px; margin: 0 auto; padding: 16px; }

/* ── 頁首 ── */
header.top {
  display: flex; align-items: center; gap: 12px; flex-wrap: wrap;
  padding: 14px 0 18px;
}
header.top h1 { font-size: 20px; margin: 0; letter-spacing: .5px; }
header.top .sub { color: var(--muted); font-size: 13px; }
.spacer { flex: 1 1 auto; }
.sim-badge {
  font-size: 12px; font-weight: 600; color: #ffe08a;
  border: 1px solid #5a4a16; background: #2a2410;
  padding: 4px 10px; border-radius: 999px;
}
.btn {
  background: var(--panel-2); color: var(--text); border: 1px solid var(--line);
  border-radius: 8px; padding: 8px 12px; font-size: 13px; cursor: pointer;
}
.btn:hover { border-color: var(--accent); }
.btn.small { padding: 5px 10px; font-size: 12px; }

/* ── 結論橫幅 ── */
.conclusion {
  display: flex; align-items: center; gap: 14px;
  border-radius: 14px; padding: 16px 18px; margin-bottom: 16px;
  box-shadow: var(--shadow); border: 1px solid var(--line);
  transition: background .3s, border-color .3s;
}
.conclusion .dot { width: 16px; height: 16px; border-radius: 50%; flex: none; }
.conclusion .headline { font-size: 22px; font-weight: 700; }
.conclusion .reason { color: var(--muted); font-size: 14px; }
.conclusion.level-ready, .conclusion.level-measuring { background: #10251a; border-color: var(--ok-dim); }
.conclusion.level-ready .dot, .conclusion.level-measuring .dot { background: var(--ok); box-shadow: 0 0 12px var(--ok); }
.conclusion.level-wait { background: #2a2410; border-color: #5a4a16; }
.conclusion.level-wait .dot { background: var(--warn); box-shadow: 0 0 12px var(--warn); }
.conclusion.level-blocked { background: #2a1414; border-color: #6a2626; }
.conclusion.level-blocked .dot { background: var(--fault); box-shadow: 0 0 12px var(--fault); }
.conclusion.level-measuring .dot { animation: pulse 1.1s infinite; }
@keyframes pulse { 0%,100%{opacity:1} 50%{opacity:.35} }

/* ── 版面網格 ── */
.grid { display: grid; grid-template-columns: 1.4fr 1fr; gap: 16px; }
.col { display: flex; flex-direction: column; gap: 16px; }
.card {
  background: var(--panel); border: 1px solid var(--line);
  border-radius: 14px; padding: 14px; box-shadow: var(--shadow);
}
.card h2 { font-size: 14px; margin: 0 0 10px; color: var(--muted); font-weight: 600; letter-spacing: .4px; }

/* ── 機台圖 ── */
.machine-wrap { display: flex; flex-direction: column; gap: 10px; }
svg.machine { width: 100%; height: auto; display: block; }
svg.machine .part { cursor: pointer; transition: fill .3s, stroke .3s; }
svg.machine .part.sel { stroke: var(--accent); stroke-width: 2.5; }
.s-ok { fill: var(--ok); }
.s-warn { fill: var(--warn); }
.s-fault { fill: var(--fault); }
.s-offline { fill: var(--offline); }
.part-label { fill: var(--muted); font-size: 9px; pointer-events: none; }
.frame { fill: none; stroke: #3a4c63; stroke-width: 6; }
.belt { fill: #13202d; stroke: #2b3b4f; stroke-width: 2; }
.belt-mark { stroke: #223246; stroke-width: 2; }
.workpiece { fill: #3a5068; }
.laser { stroke: var(--accent); stroke-width: 1.5; opacity: .65; }

.detail {
  background: var(--panel-2); border: 1px solid var(--line); border-radius: 10px;
  padding: 10px 12px; font-size: 13px; min-height: 44px;
}
.detail .name { font-weight: 600; }
.detail .chip {
  display: inline-block; font-size: 11px; padding: 1px 8px; border-radius: 999px;
  margin-left: 6px; border: 1px solid var(--line);
}
.detail .muted { color: var(--muted); }
.legend { display: flex; gap: 14px; flex-wrap: wrap; font-size: 12px; color: var(--muted); }
.legend span { display: inline-flex; align-items: center; gap: 5px; }
.legend i { width: 10px; height: 10px; border-radius: 50%; display: inline-block; }

/* ── 流程鏈 ── */
.flow { display: flex; align-items: stretch; gap: 0; flex-wrap: wrap; }
.stage {
  flex: 1 1 0; min-width: 72px; text-align: center; position: relative;
  padding: 10px 6px; border-radius: 10px; border: 1px solid var(--line);
  background: var(--panel-2); font-size: 12px;
}
.stage .st-name { font-weight: 600; }
.stage.s-ok-b { border-color: var(--ok-dim); }
.stage.s-fault-b { border-color: #6a2626; background: #2a1414; }
.stage.s-idle-b { opacity: .45; }
.stage .mark { font-size: 16px; margin-top: 2px; }
.stage .start-here {
  position: absolute; top: -10px; left: 50%; transform: translateX(-50%);
  background: var(--fault); color: #fff; font-size: 10px; font-weight: 700;
  padding: 2px 7px; border-radius: 999px; white-space: nowrap;
}
.connector {
  flex: 0 0 26px; display: flex; align-items: center; justify-content: center;
  color: var(--muted); position: relative; overflow: hidden;
}
.connector.flowing::after {
  content: ""; position: absolute; width: 8px; height: 8px; border-radius: 50%;
  background: var(--accent); left: -8px; animation: dash 1.1s linear infinite;
}
@keyframes dash { to { left: 100%; } }
.connector.broken { color: var(--fault); font-weight: 700; }

/* ── 溫度卡片 ── */
.temps { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; }
.temp {
  background: var(--panel-2); border: 1px solid var(--line); border-radius: 10px; padding: 10px;
}
.temp.warn { border-color: #5a4a16; }
.temp .row { display: flex; align-items: baseline; justify-content: space-between; }
.temp .id { font-size: 12px; color: var(--muted); }
.temp .big { font-size: 26px; font-weight: 700; font-variant-numeric: tabular-nums; }
.temp.warn .big { color: var(--warn); }
.temp .tgt { font-size: 11px; color: var(--muted); }
.temp svg { width: 100%; height: 40px; display: block; margin-top: 6px; }
.spark { fill: none; stroke: var(--ok); stroke-width: 2; }
.temp.warn .spark { stroke: var(--warn); }
.band { fill: rgba(55, 201, 120, .12); }

/* ── 待處理清單 ── */
.pending-list { display: flex; flex-direction: column; gap: 8px; }
.pending-item {
  display: flex; align-items: center; gap: 10px;
  background: var(--panel-2); border: 1px solid var(--line); border-radius: 10px; padding: 10px;
}
.pending-item .what { flex: 1; font-size: 13px; }
.pending-item .what .comp { color: var(--muted); font-size: 12px; }
.pending-item .fix {
  background: var(--accent); color: #04223f; border: none; font-weight: 700;
  border-radius: 8px; padding: 7px 12px; font-size: 13px; cursor: pointer; white-space: nowrap;
}
.pending-item .fix:hover { filter: brightness(1.08); }
.pending-empty { color: var(--muted); font-size: 13px; padding: 6px 2px; }

/* ── 故障注入列 ── */
.faults { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.fault-btn { display: flex; align-items: center; gap: 6px; }
.fault-btn.active { border-color: var(--fault); color: #ffb0b0; background: #2a1414; }

footer.bottom {
  margin-top: 22px; padding-top: 14px; border-top: 1px solid var(--line);
  display: flex; gap: 10px; align-items: center; flex-wrap: wrap; color: var(--muted); font-size: 13px;
}
footer.bottom .tag { color: var(--text); font-weight: 600; }
footer.bottom a { color: var(--accent); text-decoration: none; }

/* ── 響應式：窄螢幕單欄 ── */
@media (max-width: 820px) {
  .grid { grid-template-columns: 1fr; }
  .conclusion .headline { font-size: 19px; }
}

/* 與站上其他 demo 一致的去識別化橫幅 */
.banner { background: var(--panel-2); color: var(--muted); font-size: 13px;
  padding: 8px 16px; text-align: center; border-bottom: 1px solid var(--line); }
.banner a { color: var(--accent); text-decoration: none; }
