/* ── TRC-6000 조작 트레이너 (3D 뷰어 통합 애드온 뷰) ──
   #trc-view 아래로 전부 스코프. HMI 팔레트 토큰 포함.
─────────────────────────────────────────────────── */
#trc-view {
  --hmi-bg: #C9CED6;
  --hmi-panel: #DDE1E7;
  --hmi-dark: #6F7887;
  --hmi-title: #1F4E8C;
  --hmi-btn: #E8EBEF;
  --hmi-btn-edge: #9AA2AE;
  --hmi-cyan: #009FD4;
  --hmi-magenta: #D6006E;
  --hmi-yellow: #E0B000;

  position: fixed;
  top: 74px; left: 0; right: 0; bottom: 0;
  z-index: 20;
  background: var(--ink);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
#trc-view[hidden] { display: none; }

/* 상단 툴바 (모드 전환 + 캡션) */
#trc-toolbar {
  display: flex; align-items: center; gap: 14px;
  padding: 10px 22px 4px;
  flex-shrink: 0;
}
#trc-toolbar .mode-btn {
  background: var(--panel); color: var(--paper);
  border: 1px solid var(--line); border-radius: 4px;
  font-size: 12.5px; padding: 7px 14px;
}
#trc-toolbar .mode-btn:hover { background: var(--panel-2); }
#trc-toolbar .mode-btn[aria-pressed="true"] { border-color: var(--yellow); color: var(--yellow); }
#trc-caption {
  margin-left: auto;
  font-size: 11px; color: var(--muted);
}
#trc-caption b { color: var(--paper); }

/* 레이아웃 */
#trc-layout {
  flex: 1; display: flex; gap: 18px;
  padding: 10px 22px 18px; min-height: 0;
}
#gp-wrap { flex: 1; display: flex; flex-direction: column; align-items: center; min-width: 0; }

/* GP 베젤 */
#gp-bezel {
  width: min(100%, calc((100vh - 260px) * 1.32));
  background: linear-gradient(180deg, #2E3540, #1C222B);
  border: 1px solid #0D1013;
  border-radius: 12px;
  padding: 10px 14px 14px;
  box-shadow: 0 16px 40px rgba(0,0,0,0.55), inset 0 1px 0 rgba(255,255,255,0.06);
}
#gp-head { display: flex; align-items: center; gap: 12px; padding: 4px 4px 8px; }
#trc-view .gp-logo {
  font-family: var(--mono); font-weight: 700; font-size: 13px;
  letter-spacing: 0.18em; color: #C8CFD8;
}
#trc-view .gp-model { font-size: 11px; color: #7C8794; flex: 1; }
#trc-view .gp-lamps { display: flex; gap: 8px; }
#trc-view .bezel-lamp {
  font-family: var(--mono); font-size: 9px; letter-spacing: 0.1em;
  color: #55606C; padding: 2px 7px;
  border: 1px solid #3A424C; border-radius: 3px;
}
#trc-view .bezel-lamp.on { color: #7CE8A2; border-color: #2E7A4B; text-shadow: 0 0 6px rgba(80,220,140,0.7); }

/* GP 스크린 */
#gp-screen {
  container-type: size;
  position: relative;
  aspect-ratio: 4 / 3;
  background: var(--hmi-bg);
  border: 3px solid #0A0D10;
  border-radius: 4px;
  overflow: hidden;
  color: #1B222C;
  display: flex; flex-direction: column;
}
#screen-body { flex: 1; display: flex; flex-direction: column; min-height: 0; }

/* HMI 공통 위젯 */
#trc-view .hmi-titlebar {
  background: linear-gradient(180deg, #2A62A8, var(--hmi-title));
  color: #F2F5F9;
  font-size: clamp(11px, 1.6cqw, 15px); font-weight: 700;
  padding: 0.5em 0.8em;
  display: flex; justify-content: space-between; align-items: center;
  flex-shrink: 0;
}
#trc-view .hmi-titlebar .jp { font-weight: 400; font-size: 0.78em; opacity: 0.75; }
#trc-view .hmi-body { flex: 1; padding: 1.2%; display: flex; flex-direction: column; gap: 1.2%; min-height: 0; overflow: hidden; }

#trc-view .hmi-btn {
  background: linear-gradient(180deg, #F2F4F7, var(--hmi-btn));
  border: 1px solid var(--hmi-btn-edge);
  border-bottom-width: 3px;
  border-radius: 3px;
  color: #212936;
  font-size: clamp(10px, 1.5cqw, 14px); font-weight: 600;
  padding: 0.55em 0.7em;
  text-align: center;
  user-select: none;
  position: relative;
}
#trc-view .hmi-btn:hover { background: #FAFBFC; }
#trc-view .hmi-btn:active, #trc-view .hmi-btn.pressing { transform: translateY(2px); border-bottom-width: 1px; }
#trc-view .hmi-btn:disabled { opacity: 0.45; cursor: not-allowed; }
#trc-view .hmi-btn small { display: block; font-weight: 400; font-size: 0.72em; color: #66707E; }
#trc-view .hmi-btn.lit { background: linear-gradient(180deg, #8FE2AE, #4CBF78); border-color: #2E7A4B; color: #0C2B18; }
#trc-view .hmi-btn.lit-cyan { background: linear-gradient(180deg, #9ADCF2, #46B4DC); border-color: #1D7AA0; }
#trc-view .hmi-btn.lit-sel { background: linear-gradient(180deg, #F7E08A, #E8C33C); border-color: #A88A18; }

#trc-view .hold-ring {
  position: absolute; inset: 0;
  background: linear-gradient(90deg, rgba(47,163,92,0.45) var(--p, 0%), transparent var(--p, 0%));
  pointer-events: none; border-radius: 2px;
}

#trc-view .hmi-lamp {
  display: inline-flex; align-items: center; gap: 0.45em;
  font-size: clamp(9px, 1.3cqw, 12.5px); font-weight: 600; color: #3A4450;
}
#trc-view .hmi-lamp .dot {
  width: 0.9em; height: 0.9em; border-radius: 50%;
  background: #A7AEB9; border: 1px solid #7E8794;
  box-shadow: inset 0 1px 2px rgba(0,0,0,0.25);
}
#trc-view .hmi-lamp.on { color: #14532D; }
#trc-view .hmi-lamp.on .dot { background: #35C46A; border-color: #1E7A42; box-shadow: 0 0 6px rgba(53,196,106,0.8); }

#trc-view .hmi-group {
  min-width: 0;
  background: var(--hmi-panel);
  border: 1px solid #A9B0BB;
  border-radius: 3px;
  padding: 1.5% 1.8%;
}
#trc-view .hmi-group-title {
  font-size: clamp(9px, 1.25cqw, 12px); font-weight: 700; color: #45505E;
  margin-bottom: 0.5em; letter-spacing: 0.04em;
}

#trc-view .hmi-num {
  font-family: var(--mono);
  background: #10151B; color: #6CE896;
  border: 1px solid #060809; border-radius: 2px;
  padding: 0.15em 0.4em;
  font-size: clamp(11px, 1.7cqw, 16px);
  text-align: right;
  font-variant-numeric: tabular-nums;
  min-width: 4.2em; display: inline-block;
}
#trc-view .hmi-num.warn { color: #FF7B5C; animation: trc-numblink 0.6s step-end infinite; }
@keyframes trc-numblink { 50% { color: #3A241E; } }
#trc-view .hmi-num.c { color: #52C8F0; }
#trc-view .hmi-num.m { color: #F077B4; }
#trc-view .hmi-num.y { color: #E8D44C; }
#trc-view .hmi-num.c.warn, #trc-view .hmi-num.m.warn, #trc-view .hmi-num.y.warn { color: #FF7B5C; }

#trc-view .ink-chip {
  display: inline-block; width: 1em; height: 1em; border-radius: 2px;
  border: 1px solid rgba(0,0,0,0.3); vertical-align: -0.12em;
}
#trc-view .ink-chip.c { background: var(--hmi-cyan); }
#trc-view .ink-chip.m { background: var(--hmi-magenta); }
#trc-view .ink-chip.y { background: var(--hmi-yellow); }
#trc-view .ink-chip.k { background: #23272E; }

/* 경보 스트립 */
#alarm-strip {
  flex-shrink: 0;
  background: #39414C; color: #C6CDD6;
  font-size: clamp(9px, 1.3cqw, 12px); font-weight: 600;
  padding: 0.4em 0.8em;
  display: flex; align-items: center; gap: 0.9em;
  border-top: 1px solid #262C34;
}
#alarm-strip.alarming {
  background: #B3261E; color: #FFF3F0; font-weight: 700;
  animation: trc-alarmpulse 1s step-end infinite;
}
@keyframes trc-alarmpulse { 50% { background: #8F1B15; } }
#trc-view .strip-unit {
  background: rgba(255,255,255,0.14); color: inherit;
  border: 1px solid rgba(255,255,255,0.25); border-radius: 2px;
  font-size: 0.95em; font-weight: 700; padding: 0.15em 0.7em;
}
#alarm-strip.alarming .strip-unit { background: #FFF; color: #8F1B15; }
#trc-view .strip-msg { flex: 1; }
#trc-view .strip-cams { display: flex; gap: 0.3em; }
#trc-view .cam-dot {
  width: 0.7em; height: 0.7em; border-radius: 50%;
  background: #59626E; border: 1px solid #47505B;
}
#trc-view .cam-dot.on { background: #6CE896; border-color: #2E7A4B; }
#trc-view .strip-buzz {
  background: none; color: inherit;
  border: 1px solid rgba(255,255,255,0.3); border-radius: 2px;
  font-size: 0.85em; padding: 0.15em 0.6em;
}
#trc-view .strip-buzz.on { border-color: #6CE896; color: #6CE896; }
#alarm-strip.alarming .strip-buzz.on { border-color: #FFF; color: #FFF; }
#trc-view .strip-clock { font-family: var(--mono); font-variant-numeric: tabular-nums; }

/* 모니터 마크 화상 */
#trc-view .mark-view {
  flex: 1; position: relative;
  background: #EFEDE4;
  border: 2px solid #10151B; border-radius: 2px;
  min-height: 0; overflow: hidden;
}
#trc-view .mark-view.search { background: #3A3F47; }
#trc-view .mark { position: absolute; width: 26px; height: 26px; transform: translate(-50%, -50%); }
#trc-view .mark::before, #trc-view .mark::after { content: ""; position: absolute; background: currentColor; opacity: 0.85; }
#trc-view .mark::before { left: 50%; top: 0; width: 3px; height: 100%; transform: translateX(-50%); }
#trc-view .mark::after { top: 50%; left: 0; height: 3px; width: 100%; transform: translateY(-50%); }
#trc-view .mark.k { color: #1A1D22; }
#trc-view .mark.c { color: var(--hmi-cyan); }
#trc-view .mark.m { color: var(--hmi-magenta); }
#trc-view .mark.y { color: var(--hmi-yellow); }
#trc-view .mark-label {
  position: absolute; left: 6px; bottom: 4px;
  font-size: clamp(9px, 1.2cqw, 11px); font-weight: 700; color: #66707E;
}
#trc-view .mark-view.search .mark-label { color: #E8B0A8; }

/* 로그 테이블 */
#trc-view .log-table {
  width: 100%; border-collapse: collapse;
  font-size: clamp(8px, 1.15cqw, 11px);
  font-variant-numeric: tabular-nums;
}
#trc-view .log-table th {
  text-align: left; color: #45505E; font-weight: 700;
  border-bottom: 1px solid #A9B0BB; padding: 0.25em 0.5em;
}
#trc-view .log-table td { padding: 0.28em 0.5em; border-bottom: 1px solid #C4CAD3; }
#trc-view .log-table tr.sel td { background: #F7E08A; }

/* 확인 대화상자 */
#trc-view .hmi-confirm {
  position: absolute; inset: 0;
  background: rgba(20, 25, 32, 0.45);
  display: flex; align-items: center; justify-content: center;
  z-index: 5;
}
#trc-view .hmi-confirm-box {
  background: var(--hmi-panel);
  border: 2px solid var(--hmi-dark); border-radius: 4px;
  padding: 4%; min-width: 50%;
  box-shadow: 0 10px 30px rgba(0,0,0,0.4);
}

#trc-view .grid { display: grid; gap: 1.2%; }

/* ── 우측 교육 패널 ── */
#coach {
  width: 330px; flex-shrink: 0;
  display: flex; flex-direction: column; gap: 14px;
  overflow-y: auto;
}
#coach::-webkit-scrollbar { width: 4px; }
#coach::-webkit-scrollbar-thumb { background: var(--line); }
#trc-view .coach-section {
  background: var(--panel);
  border: 1px solid var(--line); border-radius: 6px;
  padding: 14px 16px;
  flex-shrink: 0;
}
#trc-view .coach-title {
  font-size: 12px; font-weight: 700; letter-spacing: 0.12em;
  margin-bottom: 10px;
  display: flex; justify-content: space-between; align-items: baseline;
}
#trc-view .coach-sub { font-size: 10px; color: var(--muted); font-weight: 400; }

#scenario-list { display: flex; flex-direction: column; gap: 4px; margin-bottom: 10px; }
#trc-view .scn-btn {
  text-align: left; background: none; border: 1px solid var(--line);
  border-radius: 4px; color: var(--paper);
  font-size: 12.5px; padding: 8px 10px;
  display: flex; align-items: center; gap: 8px;
}
#trc-view .scn-btn:hover { background: var(--panel-2); }
#trc-view .scn-btn.active { border-color: var(--yellow); }
#trc-view .scn-btn.done { color: var(--muted); }
#trc-view .scn-btn .scn-check { margin-left: auto; font-size: 12px; color: var(--green); }

#step-list { display: flex; flex-direction: column; gap: 2px; }
#trc-view .step {
  font-size: 12px; color: var(--muted); line-height: 1.55;
  padding: 5px 8px 5px 26px; position: relative;
  border-radius: 3px;
}
#trc-view .step::before {
  content: ""; position: absolute; left: 8px; top: 10px;
  width: 9px; height: 9px; border-radius: 50%;
  border: 1.5px solid var(--muted);
}
#trc-view .step.current { color: var(--paper); background: var(--panel-2); }
#trc-view .step.current::before { border-color: var(--yellow); }
#trc-view .step.done { color: #5F8A6E; text-decoration: line-through; }
#trc-view .step.done::before { border-color: var(--green); background: var(--green); }

#coach-hint {
  margin-top: 10px; font-size: 12px; line-height: 1.6;
  color: var(--amber);
  border-top: 1px solid var(--line); padding-top: 10px;
}
#coach-hint:empty { display: none; }

#trc-view .event-btns { display: flex; flex-direction: column; gap: 6px; }
#trc-view .event-btn {
  background: var(--panel-2); border: 1px solid var(--line); border-radius: 4px;
  color: var(--paper); font-size: 12.5px; padding: 8px 10px; text-align: left;
}
#trc-view .event-btn:hover { border-color: var(--amber); }
#trc-view .event-note { font-size: 11px; color: var(--muted); margin-top: 8px; line-height: 1.5; }
#trc-view .event-note:empty { display: none; }

#machine-status { font-size: 12px; color: var(--muted); display: flex; flex-direction: column; gap: 5px; }
#trc-view .ms-row { display: flex; justify-content: space-between; }
#trc-view .ms-row b { color: var(--paper); font-weight: 600; }
#trc-view .ms-row .ok { color: var(--green); }
#trc-view .ms-row .bad { color: var(--red); }

/* 지면 미리보기 */
#trc-view .preview-controls { display: flex; gap: 8px; }
#trc-view .preview-controls button { flex: 1; }
#trc-view .preview-controls button:disabled { opacity: 0.45; cursor: not-allowed; }
#trc-view #btn-demo-start:not(:disabled) { border-color: var(--green); color: var(--green); }
#demo-note { margin-bottom: 10px; }

#paper-preview {
  width: 100%; display: block;
  border: 1px solid var(--line); border-radius: 3px;
  background: #F2EFE6;
  cursor: zoom-in;
}
#trc-view .preview-status { font-family: var(--mono); font-size: 11px; margin-top: 6px; }
#trc-view .preview-status.ok { color: var(--green); }
#trc-view .preview-status.warn { color: var(--amber); }
#trc-view .preview-status.bad { color: var(--red); }

#preview-modal {
  position: fixed; inset: 0; z-index: 50;
  background: rgba(10, 13, 16, 0.78);
  display: flex; align-items: center; justify-content: center;
  padding: 4vh 4vw;
}
#preview-modal.hidden { display: none; }
#trc-view .pm-box {
  background: var(--panel);
  border: 1px solid var(--line); border-radius: 8px;
  padding: 14px 16px 16px;
  max-width: min(92vw, 1160px);
  box-shadow: 0 24px 60px rgba(0,0,0,0.6);
}
#trc-view .pm-head { display: flex; align-items: center; gap: 16px; margin-bottom: 10px; }
#trc-view .pm-title { font-size: 14px; font-weight: 700; }
#trc-view .pm-sub { font-size: 11px; color: var(--muted); font-weight: 400; }
#trc-view .pm-head .preview-status { margin: 0 0 0 auto; }
#pm-close { background: none; border: 0; color: var(--muted); font-size: 22px; line-height: 1; padding: 0 2px; }
#pm-close:hover { color: var(--paper); }
#paper-preview-lg {
  display: block; width: 100%;
  max-height: 76vh; object-fit: contain;
  border: 1px solid var(--line); border-radius: 3px;
  background: #F2EFE6;
}

/* ── TRC 트러블 가이드 ── */
#trc-alarm-link {
  display: none;
  width: 100%; text-align: left;
  background: color-mix(in srgb, var(--red) 16%, transparent);
  border: 1px solid var(--red); border-radius: 4px;
  color: var(--paper); font-size: 12px; line-height: 1.5;
  padding: 8px 10px; margin-bottom: 8px;
}
#trc-alarm-link.show { display: block; }
#trc-alarm-link b { color: var(--red); }

#trc-guide-list { display: flex; flex-direction: column; gap: 4px; }
#trc-view .tg-item { border: 1px solid var(--line); border-radius: 4px; overflow: hidden; }
#trc-view .tg-item.hot { border-color: var(--red); }
#trc-view .tg-head {
  width: 100%; text-align: left;
  background: none; border: 0; color: var(--paper);
  font-size: 12.5px; font-weight: 600;
  padding: 8px 10px;
  display: flex; gap: 8px; align-items: baseline;
}
#trc-view .tg-head:hover { background: var(--panel-2); }
#trc-view .tg-head .tg-icon { color: var(--red); font-size: 11px; flex-shrink: 0; }
#trc-view .tg-item.hot .tg-head { background: color-mix(in srgb, var(--red) 12%, transparent); }
#trc-view .tg-body { display: none; padding: 2px 12px 10px; }
#trc-view .tg-item.open .tg-body { display: block; }
#trc-view .tg-label { font-size: 10.5px; font-weight: 700; letter-spacing: 0.08em; margin: 8px 0 3px; }
#trc-view .tg-label.cause { color: var(--magenta, #D6006E); }
#trc-view .tg-label.fix { color: var(--green); }
#trc-view .tg-line {
  font-size: 12px; color: color-mix(in srgb, var(--paper) 86%, transparent);
  line-height: 1.55; padding-left: 12px; position: relative;
}
#trc-view .tg-line::before {
  content: ""; position: absolute; left: 2px; top: 8px;
  width: 4px; height: 4px; border-radius: 50%;
  background: var(--muted);
}

@media (max-width: 1000px) {
  #trc-layout { flex-direction: column; overflow-y: auto; }
  #gp-wrap { flex: none; }
  #trc-toolbar { flex-wrap: wrap; }
  #trc-caption { flex-basis: 100%; margin-left: 0; }
  #coach { width: auto; }
}
@media (prefers-reduced-motion: reduce) {
  #alarm-strip.alarming, #trc-view .hmi-num.warn { animation: none; }
}
