:root {
  --bg: #0d1420; --panel: rgba(16, 26, 40, 0.92); --line: #2a3b55; --text: #e4ecf7; --muted: #8fa3bf;
  --accent: #4fa3ff; --ok: #3ddc84; --warn: #ffc65a; --bad: #ff6b6b;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text); font: 13px/1.45 'Segoe UI', 'Malgun Gothic', system-ui, sans-serif; overflow: hidden; }
#topbar { position: fixed; inset: 0 0 auto 0; height: 44px; display: flex; align-items: center; gap: 16px; padding: 0 14px; background: var(--panel); border-bottom: 1px solid var(--line); z-index: 10; }
#topbar .brand { font-size: 14px; white-space: nowrap; }
#topbar .brand b { color: var(--accent); }
#topbar .phase { margin-left: 8px; padding: 1px 8px; border: 1px solid var(--line); border-radius: 10px; color: var(--muted); font-size: 11px; }
#topbar .clock { font-variant-numeric: tabular-nums; font-size: 15px; margin-left: auto; }
#topbar .controls { display: flex; gap: 8px; align-items: center; }
button { background: #1b2a40; color: var(--text); border: 1px solid var(--line); border-radius: 6px; padding: 4px 10px; cursor: pointer; font: inherit; }
button:hover { border-color: var(--accent); }
.seg { display: flex; }
.seg button { border-radius: 0; margin-left: -1px; }
.seg button:first-child { border-radius: 6px 0 0 6px; }
.seg button:last-child { border-radius: 0 6px 6px 0; }
.seg button.on { background: var(--accent); color: #06121f; border-color: var(--accent); }
#viewport { position: fixed; inset: 44px 0 0 0; }
#viewport canvas { display: block; }
#status { position: fixed; right: 12px; bottom: 12px; width: 300px; padding: 10px 12px; background: var(--panel); border: 1px solid var(--line); border-radius: 8px; z-index: 10; }
#status h3 { margin: 0 0 6px; font-size: 13px; }
#status ul { list-style: none; margin: 0; padding: 0; }
#status li { padding: 2px 0; }
#status li.ok::before { content: '✓ '; color: var(--ok); }
#status li.bad::before { content: '✕ '; color: var(--bad); }
#status li.wait::before { content: '… '; color: var(--warn); }
#status .legend { margin: 8px 0 0; color: var(--muted); font-size: 11px; }
.cell-label { pointer-events: none; text-align: center; padding: 4px 8px; background: rgba(240, 245, 252, 0.94); color: #10233d; border-radius: 6px; box-shadow: 0 1px 4px rgba(0,0,0,0.35); white-space: nowrap; }
.cell-label b { color: #0b5cc2; margin-right: 6px; font-size: 13px; }
.cell-label small { display: block; color: #4a5d78; font-size: 10px; }
.cell-label.aux { background: rgba(255, 236, 196, 0.95); }
.cell-label.depot { background: rgba(214, 240, 228, 0.95); }
.lane-label { pointer-events: none; color: #cfe3ff; font-size: 10px; text-shadow: 0 1px 2px #000; white-space: nowrap; }
select { background: #1b2a40; color: var(--text); border: 1px solid var(--line); border-radius: 6px; padding: 4px 6px; font: inherit; max-width: 260px; }
.cell-label .step { color: #0b5cc2; font-weight: 600; }
.cell-label.alert { background: rgba(255, 214, 214, 0.97); }
.stop-sign { pointer-events: none; padding: 3px 10px; background: #c62828; color: #fff; font-weight: 700; border-radius: 4px; box-shadow: 0 0 0 2px #fff; }
#status { width: 380px; }
#detail { position: fixed; left: 12px; top: 56px; bottom: 12px; width: 340px; overflow: auto; padding: 10px 12px; background: var(--panel); border: 1px solid var(--line); border-radius: 8px; z-index: 11; font-size: 12px; }
#detail .cd-head { display: flex; align-items: center; gap: 8px; font-size: 14px; }
#detail .cd-head b { color: var(--accent); }
#detail .cd-head button { margin-left: auto; padding: 0 8px; }
#detail h4 { margin: 10px 0 4px; font-size: 12px; color: var(--muted); }
#detail ul, #detail ol { margin: 0; padding-left: 18px; }
#detail .muted { color: var(--muted); }
#detail .st { font-weight: 600; }
#detail .st-BUSY { color: var(--ok); } #detail .st-BLOCKED, #detail .st-STOPPED { color: var(--warn); } #detail .st-FAULT { color: var(--bad); }
#detail .steps li { padding: 1px 0; color: var(--muted); }
#detail .steps li span { color: var(--muted); font-size: 11px; }
#detail .steps li.done { color: #6f8aa8; text-decoration: line-through; }
#detail .steps li.now { color: var(--text); font-weight: 600; }
#detail table { width: 100%; border-collapse: collapse; }
#detail td, #detail th { border-bottom: 1px solid var(--line); padding: 2px 4px; text-align: left; }
.lane-label.big { font-size: 12px; background: rgba(10,20,35,0.6); padding: 1px 6px; border-radius: 4px; }

/* ── 운영 대시보드 (IMG-5) ── */
#dash { position: fixed; right: 12px; top: 56px; bottom: 12px; width: 470px; overflow: hidden; display: flex; flex-direction: column; background: var(--panel); border: 1px solid var(--line); border-radius: 8px; z-index: 11; font-size: 12px; }
#dash .db-top { display: flex; align-items: center; gap: 8px; padding: 8px 10px; border-bottom: 1px solid var(--line); font-size: 13px; }
#dash .db-mode { margin-left: auto; }
#dash .db-tabs { display: flex; flex-wrap: wrap; gap: 2px; padding: 6px 8px 0; }
#dash .db-tabs button { border-radius: 6px 6px 0 0; padding: 4px 8px; font-size: 12px; }
#dash .db-tabs button.on { background: var(--accent); color: #06121f; border-color: var(--accent); }
#dash .db-body { flex: 1; overflow: auto; padding: 8px 10px; border-top: 1px solid var(--line); }
#dash table { width: 100%; border-collapse: collapse; margin: 4px 0 8px; }
#dash th, #dash td { border-bottom: 1px solid var(--line); padding: 3px 4px; text-align: left; vertical-align: top; }
#dash th { color: var(--muted); font-weight: 500; }
#dash h4 { margin: 10px 0 4px; font-size: 12px; color: var(--muted); }
#dash .muted { color: var(--muted); }
#dash .bar { display: inline-block; width: 60px; height: 8px; background: #26354d; border-radius: 4px; overflow: hidden; vertical-align: middle; }
#dash .bar i { display: block; height: 100%; background: var(--ok); }
#dash .st-RUN { color: var(--ok); } #dash .st-WAIT { color: var(--muted); }
#dash tr.st-FAULT td, #dash tr.cmd-REJECTED td { color: var(--bad); }
#dash tr.st-STOPPED td, #dash tr.st-MAINT td { color: var(--warn); }
#dash .qc-ok { color: var(--ok); } #dash .qc-rework, #dash .qc-scrap { color: var(--bad); }
#dash .db-alarm { margin: 8px 10px 0; padding: 8px 10px; border-radius: 6px; background: rgba(198, 40, 40, 0.18); border: 1px solid #e05555; }
#dash .db-alarm.warn { background: rgba(255, 176, 32, 0.14); border-color: #d99a2b; }
#dash .al-title { font-weight: 700; margin-bottom: 3px; }
#dash .db-alarm .al-title { color: #ff8a8a; } #dash .db-alarm.warn .al-title { color: #ffc65a; }
#dash .al-btns { display: flex; gap: 8px; align-items: center; margin-top: 6px; }
#dash button.ok { background: #1f9d55; border-color: #1f9d55; color: #fff; }
#dash .badge { font-style: normal; background: #e05555; color: #fff; border-radius: 8px; padding: 0 5px; font-size: 10px; }
#dash .db-card { border: 1px solid var(--line); border-left: 4px solid var(--muted); border-radius: 6px; padding: 6px 8px; margin-bottom: 8px; }
#dash .db-card.alarm { border-left-color: #e05555; } #dash .db-card.warn { border-left-color: #d99a2b; } #dash .db-card.info { border-left-color: var(--accent); }
#dash .db-card .pst { float: right; font-weight: 500; color: var(--muted); }
#dash .db-card.ps-PENDING .pst { color: #ffc65a; } #dash .db-card.ps-EXECUTED .pst { color: var(--ok); } #dash .db-card.ps-REJECTED .pst, #dash .db-card.ps-FAILED .pst { color: var(--bad); }
#dash tr.rec td { color: #cfe3ff; }
#dash .db-console { padding: 6px; border: 1px solid var(--line); border-radius: 6px; display: flex; flex-wrap: wrap; gap: 4px; align-items: center; }
#dash .db-console button { padding: 2px 6px; font-size: 11px; }
#dash .db-note { margin: 0; padding: 6px 10px; border-top: 1px solid var(--line); color: var(--muted); font-size: 10px; }
#status { right: auto; left: 12px; width: 360px; }
#detail { bottom: 12px; }
.alarm-sign { pointer-events: none; padding: 3px 10px; background: #ff3030; color: #fff; font-weight: 700; border-radius: 4px; box-shadow: 0 0 10px #ff3030; }
body:has(#detail:not([hidden])) #status { display: none; }   /* 셀 상세가 열리면 운영 현황 패널은 숨김 (왼쪽 겹침 방지) */
#btnTrack.on { background: var(--accent); color: #06121f; border-color: var(--accent); }   /* P8 작업 추적 켜짐 */
#detail .bad { color: var(--bad); }   /* P9 AMR 정지 */
#dash .db-card.ps-EXPIRED { opacity: 0.6; }   /* P9 만료된 제안 */

/* ── 시연 모드 자막 패널 (자동 투어) — 왼쪽 운영 현황·오른쪽 대시보드 사이 아래 ── */
#tour { position: fixed; left: 384px; right: 494px; bottom: 16px; z-index: 12; padding: 10px 14px; background: rgba(8, 16, 28, 0.94); border: 1px solid var(--accent); border-radius: 8px; box-shadow: 0 4px 18px rgba(0,0,0,0.5); }
body:has(#detail:not([hidden])) #tour { left: 364px; }
#tour .tr-head { display: flex; gap: 10px; align-items: baseline; font-size: 12px; color: var(--muted); }
#tour .tr-scene { color: var(--accent); font-size: 13px; }
#tour .tr-wait { color: var(--warn); }
#tour .tr-text { margin: 6px 0 8px; font-size: 16px; line-height: 1.5; color: var(--text); }
#tour .tr-bar { height: 3px; background: #26354d; border-radius: 2px; overflow: hidden; }
#tour .tr-bar i { display: block; height: 100%; width: 0; background: var(--accent); transition: width 0.3s linear; }
#tour .tr-btns { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
#tour .tr-btns button { padding: 2px 8px; font-size: 12px; }
#btnTour.on { background: var(--accent); color: #06121f; border-color: var(--accent); }
@keyframes tour-pulse { 50% { box-shadow: 0 0 0 4px rgba(61, 220, 132, 0.6); } }
#dash.tour-hint .db-alarm button.ok { animation: tour-pulse 0.8s ease-in-out infinite; }
.cell-label.minor { background: rgba(255, 236, 190, 0.97); }   /* 순간 정지 (초코정) */
.cell-label.minor .step { color: #a35a00; }
#detail .steps li.minor, #detail .steps li.minor span { color: var(--warn); }

/* ── 대화 탭 (agent/chat.js) ── */
#dash .db-box { display: contents; }
#dash .db-note { order: 2; }
#dash .ch-bar { order: 1; display: flex; gap: 6px; padding: 6px 10px; border-top: 1px solid var(--line); }
#dash .ch-bar[hidden] { display: none; }
#dash .ch-bar input { flex: 1; min-width: 0; background: #0f1a2a; color: var(--text); border: 1px solid var(--line); border-radius: 6px; padding: 6px 8px; font: inherit; }
#dash .ch-bar input:focus { outline: none; border-color: var(--accent); }
#dash .ch-log { display: flex; flex-direction: column; gap: 8px; }
#dash .ch-msg { max-width: 88%; padding: 6px 9px; border-radius: 8px; background: #1b2a40; border: 1px solid var(--line); }
#dash .ch-me { align-self: flex-end; background: #1d4f91; border-color: #2f6fb5; }
#dash .ch-agent { border-left: 4px solid #e05555; }
#dash .ch-who { font-size: 10px; color: var(--muted); margin-bottom: 2px; }
#dash .ch-me .ch-who { color: #cfe3ff; }
#dash .ch-text { line-height: 1.5; }
#dash .ch-card { margin-top: 6px; padding: 6px; border: 1px dashed var(--accent); border-radius: 6px; }
#dash .ch-card div { display: flex; gap: 6px; margin-top: 4px; }
#dash .ch-chips { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 10px; }
#dash .ch-chips button { padding: 2px 8px; font-size: 11px; border-radius: 12px; }
/* ── 추이·리포트 (C-10·11) ── */
#dash .tr-bar { display: flex; flex-wrap: wrap; gap: 4px; margin-bottom: 4px; }
#dash .tr-bar button { padding: 2px 7px; font-size: 11px; }
#dash svg.trend { display: block; margin: 2px 0 6px; }
#dash .tr-tip { position: sticky; top: 0; z-index: 2; background: #0f1a2a; border: 1px solid var(--line); border-radius: 6px; padding: 4px 6px; font-size: 11px; color: var(--text); }
/* ── 품질현황 (P13 QDE) ── */
#dash .qd-btns { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 4px; }
#dash .qd-btns button { padding: 2px 7px; font-size: 11px; }
#dash .qd-btns button:disabled { opacity: 0.4; cursor: not-allowed; }
#dash .qk-HOLD { color: var(--warn); } #dash .qk-SCRAP { color: var(--bad); } #dash .qk-C08, #dash .qk-RETURN { color: #8fc7ff; }
#detail .qc-state { padding: 3px 6px; border-radius: 4px; background: #1b2a40; display: inline-block; }
#detail .qc-state.FIX { color: var(--ok); } #detail .qc-state.NOFIX { color: var(--warn); } #detail .qc-state.HOLD { color: var(--bad); }
.hold-sign { pointer-events: none; padding: 2px 8px; background: #b23b8f; color: #fff; font-weight: 700; border-radius: 4px; font-size: 11px; }
