:root {
  --bg-base:    #050d1a;
  --bg-panel:   #080f1e;
  --bg-surface: #0c1526;
  --bg-raised:  #101e32;
  --bg-input:   #0a1322;
  --border:     #132040;
  --border-hi:  #1e3a60;
  --cyan:       #00d4ff;
  --cyan-dim:   #007a99;
  --green:      #00ff88;
  --red:        #ff3b3b;
  --amber:      #ffb800;
  --white:      #e8f0ff;
  --muted:      #3a5a7a;
  --subtle:     #1e3050;
  --font-ui:    'Inter', system-ui, sans-serif;
  --font-mono:  'JetBrains Mono', 'Courier New', monospace;
  --radius-sm:  4px;
  --radius:     8px;
  --radius-lg:  12px;
  --header-h:   56px;
  --panel-gap:  10px;
  --shadow-panel: 0 0 0 1px var(--border), 0 8px 32px rgba(0,0,0,0.5);
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html, body {
  height: 100%; overflow: hidden; background: var(--bg-base);
  color: var(--white); font-family: var(--font-ui); font-size: 13px;
}

body::after {
  content: " "; display: block; position: absolute;
  top: 0; left: 0; bottom: 0; right: 0;
  background: linear-gradient(rgba(18, 16, 16, 0) 50%, rgba(0, 0, 0, 0.1) 50%), 
              linear-gradient(90deg, rgba(255, 0, 0, 0.02), rgba(0, 255, 0, 0.01), rgba(0, 0, 255, 0.02));
  z-index: 100; background-size: 100% 4px, 3px 100%;
  pointer-events: none; opacity: 0.3;
}

button { cursor: pointer; border: none; background: none; font-family: inherit; }

.app-header {
  display: flex; align-items: center; justify-content: space-between;
  height: var(--header-h); padding: 0 16px;
  background: var(--bg-panel); border-bottom: 1px solid var(--border);
  position: relative; z-index: 10;
}
.header-brand { display: flex; align-items: center; gap: 10px; }
.brand-name { font-size: 18px; font-weight: 700; color: var(--white); }
.brand-accent { color: var(--cyan); }
.brand-tag {
  font-size: 9px; font-family: var(--font-mono); color: var(--muted);
  background: var(--bg-surface); border: 1px solid var(--border);
  padding: 2px 7px; border-radius: 3px; text-transform: uppercase;
}

.header-center { display: flex; align-items: center; gap: 10px; }
.scenario-label { font-size: 9px; font-family: var(--font-mono); color: var(--muted); letter-spacing: 1.5px; }
.scenario-select {
  background: var(--bg-surface); border: 1px solid var(--border-hi);
  color: var(--white); padding: 6px 10px; border-radius: var(--radius-sm);
  font-size: 12px; font-family: var(--font-mono); outline: none; cursor: pointer;
}

.header-right { display: flex; align-items: center; gap: 16px; }

.security-badge {
  background: rgba(0, 255, 136, 0.1);
  border: 1px solid var(--green);
  color: var(--green);
  padding: 4px 8px;
  border-radius: 4px;
  font-family: var(--font-mono);
  font-size: 9px;
  display: flex;
  align-items: center;
  gap: 5px;
}
.sec-icon { font-size: 10px; }

.hdr-stat { display: flex; align-items: center; gap: 7px; font-size: 11px; font-family: var(--font-mono); color: var(--muted); }
.status-beacon { width: 10px; height: 10px; border-radius: 50%; }
.status-beacon.fault { background: var(--red); box-shadow: 0 0 8px var(--red); animation: beacon-pulse 0.9s infinite; }
.status-beacon.ok { background: var(--green); box-shadow: 0 0 8px var(--green); }
@keyframes beacon-pulse { 0%,100% { opacity: 1; } 50% { opacity: 0.2; } }

.score-val { font-size: 20px; font-weight: 700; font-family: var(--font-mono); color: var(--cyan); }
.config-btn { font-size: 11px; font-family: var(--font-mono); color: var(--muted); border: 1px solid var(--border); padding: 5px 10px; border-radius: var(--radius-sm); background: var(--bg-surface); }

.app-layout {
  display: grid; grid-template-columns: 1fr 1fr 380px;
  gap: var(--panel-gap); padding: var(--panel-gap);
  height: calc(100vh - var(--header-h)); overflow: hidden;
}

.panel {
  background: var(--bg-panel); border: 1px solid var(--border);
  border-radius: var(--radius-lg); display: flex; flex-direction: column;
  overflow: hidden; box-shadow: var(--shadow-panel);
}
.panel-header { display: flex; align-items: center; justify-content: space-between; padding: 10px 14px; border-bottom: 1px solid var(--border); }
.panel-title { font-size: 12px; font-weight: 600; font-family: var(--font-mono); color: var(--white); text-transform: uppercase; }

.svg-wrapper { flex: 1; overflow: hidden; padding: 4px; }
#factory-svg { width: 100%; height: 100%; display: block; }
.sensor-strip { display: flex; border-top: 1px solid var(--border); }
.sr-item { flex: 1; display: flex; flex-direction: column; align-items: center; padding: 6px 4px; border-right: 1px solid var(--border); gap: 3px; }
.sr-lbl { font-size: 9px; font-family: var(--font-mono); color: var(--muted); }
.sr-val { font-size: 9px; font-family: var(--font-mono); font-weight: 600; padding: 1px 5px; border-radius: 3px; }
.sr-val.ok { color: var(--green); background: rgba(0,255,136,0.08); }
.sr-val.fault { color: var(--red); background: rgba(255,59,59,0.08); animation: chip-flash 0.9s infinite; }

.mid-tabs { display: flex; gap: 4px; }
.mid-tab { font-size: 10px; font-family: var(--font-mono); color: var(--muted); border: 1px solid var(--border); padding: 4px 10px; border-radius: 4px; background: var(--bg-surface); }
.mid-tab.active { border-color: var(--cyan-dim); color: var(--cyan); background: rgba(0, 212, 255, 0.08); }
.tab-content { display: none; flex: 1; flex-direction: column; overflow-y: auto; }
.tab-content.active { display: flex; }

.gpu-telemetry {
  background: var(--bg-surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 10px; margin-top: 10px;
  font-family: var(--font-mono); font-size: 10px;
  display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px;
}
.gpu-item { display: flex; justify-content: space-between; color: var(--muted); }
.gpu-item .val { color: var(--cyan); font-weight: bold; }

.scada-gauges { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; padding: 14px; }
.gauge-card { background: var(--bg-surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 10px 6px 8px; display: flex; flex-direction: column; align-items: center; gap: 6px; }
.gauge-svg { width: 100%; max-width: 90px; height: auto; }
.gauge-lbl { font-size: 8.5px; font-family: var(--font-mono); color: var(--muted); }

.process-flow { background: var(--bg-surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 10px 14px; margin: 0 14px; }
.pf-svg { width: 100%; height: auto; display: block; }

.io-table-wrap { flex: 1; margin: 14px; background: var(--bg-surface); border: 1px solid var(--border); border-radius: var(--radius); overflow-y: auto; }
.io-table { width: 100%; border-collapse: collapse; font-family: var(--font-mono); font-size: 10.5px; text-align: left; }
.io-table th { background: #091222; color: var(--muted); padding: 6px 10px; font-size: 9px; border-bottom: 1px solid var(--border); }
.io-table td { padding: 7px 10px; border-bottom: 1px solid var(--border); color: #c8d8e8; }
.io-ok { color: var(--green); }
.io-fault { color: var(--red); animation: txt-pulse 0.9s infinite; }

.scada-alarm-bar { background: rgba(255, 59, 59, 0.08); border: 1px solid rgba(255, 59, 59, 0.2); border-radius: var(--radius-sm); padding: 8px 12px; display: flex; align-items: center; gap: 8px; font-family: var(--font-mono); font-size: 10px; color: var(--red); margin: 0 14px 14px; animation: scada-alarm-flash 1.5s infinite; }

.plc-block { border-bottom: 1px solid var(--border); }
.plc-block-header { display: flex; align-items: center; justify-content: space-between; padding: 6px 14px; background: var(--bg-surface); border-bottom: 1px solid var(--border); }
.plc-code { font-family: var(--font-mono); font-size: 11px; line-height: 1.7; padding: 12px 14px; background: var(--bg-surface); color: #8fb8d8; white-space: pre; }

.terminal-container { flex: 1; display: flex; flex-direction: column; background: #030912; font-family: var(--font-mono); font-size: 11.5px; }
.terminal-output { flex: 1; overflow-y: auto; padding: 10px 14px; display: flex; flex-direction: column; gap: 2px; }
.tl { line-height: 1.5; white-space: pre-wrap; }
.tl.sys { color: #2a4a6a; }
.tl.fault { color: var(--red); }
.tl.ok { color: var(--green); }
.tl.warn { color: var(--amber); }
.tl.info { color: #5a8aaa; }
.tl.cmd { color: var(--cyan); }
.tl.sep { color: #162030; }
.terminal-input-row { display: flex; align-items: center; gap: 8px; padding: 8px 14px; border-top: 1px solid var(--border); background: #040c18; }
.t-prompt { color: var(--cyan); font-size: 11px; }
.t-input { flex: 1; background: none; border: none; color: var(--white); font-family: var(--font-mono); outline: none; }

.coach-panel { gap: 0; }
.coach-header { gap: 10px; }
.coach-avatar-wrap { position: relative; width: 38px; height: 38px; }
.coach-ring { position: absolute; inset: -3px; border-radius: 50%; border: 1.5px solid var(--cyan); animation: ring-spin 8s linear infinite; }
.coach-avatar-core { width: 38px; height: 38px; border-radius: 50%; background: linear-gradient(135deg, #0a2040, #0d3060); border: 1px solid var(--cyan-dim); display: flex; align-items: center; justify-content: center; font-size: 12px; font-weight: 700; color: var(--cyan); }
.coach-online { display: flex; align-items: center; gap: 5px; font-size: 9px; color: var(--muted); }
.online-dot { width: 7px; height: 7px; border-radius: 50%; background: var(--green); box-shadow: 0 0 6px var(--green); }
.online-dot.offline { background: var(--muted); box-shadow: none; }

.scenario-progress-block { padding: 8px 14px; border-bottom: 1px solid var(--border); }
.spb-top { display: flex; justify-content: space-between; font-size: 10px; color: var(--muted); margin-bottom: 6px; }
.spb-bar-wrap { height: 4px; background: var(--bg-raised); border-radius: 2px; overflow: hidden; }
.spb-bar { height: 100%; background: linear-gradient(90deg, var(--cyan), var(--green)); transition: width 0.6s ease; }

.chat-window { flex: 1; overflow-y: auto; padding: 12px 14px; display: flex; flex-direction: column; gap: 12px; }
.chat-msg { display: flex; flex-direction: column; gap: 4px; max-width: 90%; }
.chat-msg.ai { align-self: flex-start; }
.chat-msg.user { align-self: flex-end; }
.msg-body { padding: 10px 13px; border-radius: var(--radius); font-size: 12.5px; line-height: 1.6; }
.chat-msg.ai .msg-body { background: var(--bg-surface); border: 1px solid var(--border-hi); color: #c8d8e8; border-bottom-left-radius: 2px; }
.chat-msg.user .msg-body { background: rgba(0,212,255,0.08); border: 1px solid rgba(0,212,255,0.2); color: var(--white); border-bottom-right-radius: 2px; }
.msg-time { font-size: 9px; color: var(--muted); }

.chat-input-area { display: flex; gap: 8px; padding: 10px 14px; border-top: 1px solid var(--border); align-items: flex-end; }
.chat-textarea { flex: 1; background: var(--bg-input); border: 1px solid var(--border-hi); border-radius: var(--radius-sm); color: var(--white); font-size: 12px; padding: 8px 10px; resize: none; outline: none; }
.send-btn { width: 36px; height: 36px; border-radius: var(--radius-sm); background: var(--cyan); color: #050d1a; display: flex; align-items: center; justify-content: center; }

.quick-hints { display: flex; align-items: center; flex-wrap: wrap; gap: 5px; padding: 8px 14px; border-top: 1px solid var(--border); }
.qh-pill { font-size: 10px; color: var(--cyan-dim); border: 1px solid var(--border); padding: 3px 8px; border-radius: 20px; background: var(--bg-surface); }

.modal-overlay { display: none; position: fixed; inset: 0; background: rgba(2,6,15,0.88); z-index: 1000; align-items: center; justify-content: center; backdrop-filter: blur(6px); }
.modal-overlay.open { display: flex; }
.modal { background: var(--bg-panel); border: 1px solid var(--border-hi); border-radius: var(--radius-lg); padding: 28px 28px 24px; max-width: 420px; width: 90%; box-shadow: 0 24px 64px rgba(0,0,0,0.8), var(--shadow-glow-c); }
.api-input { width: 100%; background: var(--bg-input); border: 1px solid var(--border-hi); border-radius: var(--radius-sm); color: var(--white); font-family: var(--font-mono); font-size: 12px; padding: 10px 12px; outline: none; margin-bottom: 20px; }
.modal-presets { display: flex; gap: 8px; margin-top: 5px; margin-bottom: 20px; }
.preset-btn { flex: 1; font-size: 11px; font-family: var(--font-mono); color: var(--muted); border: 1px solid var(--border); padding: 6px; border-radius: var(--radius-sm); background: var(--bg-surface); text-align: center; }
.modal-actions { display: flex; gap: 10px; justify-content: flex-end; }
.btn-primary { background: var(--cyan); color: #050d1a; padding: 8px 18px; border-radius: var(--radius-sm); font-weight: 500; }
.btn-secondary { border: 1px solid var(--border); color: var(--muted); background: var(--bg-surface); padding: 8px 18px; border-radius: var(--radius-sm); }

@keyframes ring-spin { 0% { transform: rotate(0deg); } 100% { transform: rotate(360deg); } }
@keyframes chip-flash { 0%,100%{ opacity:1; } 50%{ opacity:0.4; } }
@keyframes txt-pulse { 0%, 100% { opacity: 1; } 50% { opacity: 0.5; } }
@keyframes scada-alarm-flash { 0%, 100% { border-color: rgba(255, 59, 59, 0.2); background: rgba(255, 59, 59, 0.06); } 50% { border-color: rgba(255, 59, 59, 0.4); background: rgba(255, 59, 59, 0.12); } }