/* ============================================================
   QT2045P 数控车床仿真系统 样式表
   复刻实体操作面板外观
   ============================================================ */

:root {
  --cabinet: #2b2f36;
  --cabinet-dark: #20242a;
  --cabinet-light: #3a3f47;
  --key-face: #4a505a;
  --key-face-light: #5b626d;
  --key-text: #e8eaed;
  --key-border: #16181c;
  --lcd-bg: #1a2b1a;
  --lcd-text: #58e058;
  --lcd-text-dim: #3fae3f;
  --lcd-accent: #a0ffa0;
  --accent: #f0b429;
  --red: #e03e2f;
  --green: #2fa832;
  --amber: #efa031;
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; }
body {
  font-family: "Microsoft YaHei", "PingFang SC", "Segoe UI", sans-serif;
  background: #14161a;
  color: #e8eaed;
  overflow: auto;
  user-select: none;
  -webkit-user-select: none;
}

#app {
  max-width: 1280px;
  margin: 0 auto;
  padding: 10px;
}

/* ---------- 顶部标题栏 ---------- */
#topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: linear-gradient(#3a3f47, #2b2f36);
  border: 1px solid #16181c;
  border-radius: 8px;
  padding: 8px 16px;
  box-shadow: inset 0 1px 0 rgba(255,255,255,.08);
}
.brand-cn { font-size: 20px; font-weight: bold; color: var(--accent); letter-spacing: 2px; }
.brand-model { margin-left: 14px; font-size: 14px; color: #cfd3d8; }
.sys-status { display: flex; align-items: center; gap: 8px; }
.sys-status label { font-size: 12px; color: #9aa0a8; }
.lamp {
  width: 14px; height: 14px; border-radius: 50%;
  background: #3a3f47; border: 1px solid #16181c;
  box-shadow: inset 0 1px 2px rgba(0,0,0,.6);
}
.lamp.on-green { background: var(--green); box-shadow: 0 0 10px var(--green); }
.lamp.on-red { background: var(--red); box-shadow: 0 0 12px var(--red); }
.lamp.on-amber { background: var(--amber); box-shadow: 0 0 10px var(--amber); }

/* ---------- 主体布局 ---------- */
#main {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
  margin-top: 12px;
}

/* ---------- LCD ---------- */
#left-panel {
  display: flex; flex-direction: column; gap: 10px;
}
.lcd {
  background: var(--lcd-bg);
  border: 6px solid #14171b;
  border-radius: 6px;
  padding: 12px;
  height: 360px;
  overflow: hidden;
  box-shadow: inset 0 0 18px rgba(0,0,0,.8), 0 0 0 2px #2b2f36;
}
.lcd-title {
  font-family: "Consolas", "Courier New", monospace;
  color: var(--lcd-accent);
  font-size: 14px;
  border-bottom: 1px solid #2f6b2f;
  padding-bottom: 6px;
  margin-bottom: 8px;
}
.lcd-body {
  font-family: "Consolas", "Courier New", monospace;
  color: var(--lcd-text);
  font-size: 14px;
  line-height: 1.55;
  white-space: pre-wrap;
  height: 100%;
  overflow-y: auto;
}
.lcd-body .dim { color: var(--lcd-text-dim); }
.lcd-body .hl { color: var(--lcd-accent); }
.lcd-body .cur { background: var(--lcd-text); color: #1a2b1a; }

/* 软键行 */
.softkeys { display: flex; gap: 6px; }
.softkey {
  flex: 1; height: 34px;
  background: linear-gradient(#3a3f47, #2b2f36);
  border: 1px solid #16181c;
  border-radius: 4px;
  color: #cfd3d8; font-size: 12px; cursor: pointer;
}
.softkey:active { background: #20242a; }
.softkey span { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; padding: 0 4px; }

.func-keys { display: flex; gap: 6px; }
.func-keys .key { flex: 1; }

/* 通用按键 */
.key {
  background: linear-gradient(#5b626d, #454b55);
  border: 1px solid var(--key-border);
  border-radius: 5px;
  color: var(--key-text);
  font-size: 14px;
  font-weight: bold;
  padding: 8px 6px;
  cursor: pointer;
  box-shadow: 0 2px 0 #17191d, inset 0 1px 0 rgba(255,255,255,.15);
  min-width: 40px;
}
.key:active { transform: translateY(1px); box-shadow: 0 1px 0 #17191d, inset 0 1px 2px rgba(0,0,0,.4); }
.key.func { background: linear-gradient(#4a5560, #38404a); font-size: 12px; }
.key.small { font-size: 12px; padding: 5px 8px; min-width: 34px; }

/* ---------- 图形区 ---------- */
#right-panel { display: flex; }
#graphics-box {
  flex: 1;
  background: #23272d;
  border: 1px solid #16181c;
  border-radius: 6px;
  padding: 8px;
  display: flex; flex-direction: column; gap: 6px;
}
.gfx-head {
  display: flex; justify-content: space-between; align-items: center;
  color: #9aa0a8; font-size: 12px;
}
.gfx-coord { font-family: "Consolas", monospace; color: var(--lcd-text); background: #14171b; padding: 2px 8px; border-radius: 3px; }
#gfx-machine, #gfx-toolpath {
  width: 100%; background: #101318; border: 1px solid #0a0c0f;
  border-radius: 4px; display: block;
}
.gfx-3d-box {
  position: relative; width: 100%; height: 300px;
  border: 1px solid #0a0c0f; border-radius: 4px; overflow: hidden; background: #101318;
}
.gfx-3d-box canvas {
  display: block; width: 100%; height: 100%; cursor: grab;
}
.gfx-3d-box canvas:active { cursor: grabbing; }
.gfx-3d-hint {
  position: absolute; left: 8px; bottom: 6px; font-size: 11px; color: #7f8894;
  pointer-events: none; font-family: Consolas, monospace;
}
.gfx-control { display: flex; align-items: center; gap: 8px; font-size: 12px; color: #9aa0a8; flex-wrap: wrap; }
.gfx-control input[type=number] {
  width: 60px; background: #14171b; color: var(--lcd-text);
  border: 1px solid #333; border-radius: 3px; padding: 3px 6px;
  font-family: "Consolas", monospace;
}
.btn {
  background: linear-gradient(#5b626d, #454b55);
  border: 1px solid var(--key-border); border-radius: 4px;
  color: #e8eaed; font-size: 12px; padding: 4px 10px; cursor: pointer;
}
.btn:active { transform: translateY(1px); }
.chk { color: #9aa0a8; font-size: 12px; display: inline-flex; align-items: center; gap: 4px; }

/* ---------- 操作台 ---------- */
#console {
  grid-column: 1 / -1;
  margin-top: 14px;
  background: linear-gradient(#2e333b, #262b31);
  border: 1px solid #16181c;
  border-radius: 8px;
  padding: 14px;
  display: grid;
  grid-template-columns: 140px 180px 200px 220px 340px 200px 150px;
  gap: 14px;
  align-items: start;
}
.unit {
  background: #23272d;
  border: 1px solid #17191d;
  border-radius: 6px;
  padding: 10px;
}
.unit-title {
  font-size: 11px; color: #9aa0a8; text-align: center;
  margin-bottom: 8px; letter-spacing: 1px;
}

/* 模式旋钮 */
.rotary {
  width: 90px; height: 90px; margin: 6px auto;
  background: radial-gradient(circle at 50% 40%, #3a3f47, #1c1f24);
  border: 3px solid #0f1114; border-radius: 50%;
  position: relative; cursor: pointer;
  box-shadow: 0 2px 6px rgba(0,0,0,.5), inset 0 1px 3px rgba(255,255,255,.08);
}
.rotary-knob {
  position: absolute; top: 8px; left: 8px; right: 8px; bottom: 8px;
  background: linear-gradient(#565d68, #363c45);
  border-radius: 50%;
  border: 2px solid #131518;
  box-shadow: inset 0 2px 3px rgba(255,255,255,.2);
}
.rotary-knob::after {
  content: ""; position: absolute; top: 24px; left: 50%;
  width: 5px; height: 22px; margin-left: -2.5px;
  background: var(--accent); border-radius: 2px;
  transform-origin: 2.5px 22px;
  transition: transform .15s ease;
}
.mode-label { text-align: center; font-size: 14px; color: var(--accent); font-weight: bold; }
.rotary-angles { display: none; }

/* 方向键 */
.jog-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; margin-bottom: 8px; }
.mini-row { display: flex; gap: 4px; flex-wrap: wrap; }
.mini-row .key { flex: 1; }

/* 倍率旋钮 */
.ov-row { display: grid; grid-template-columns: 34px 1fr 40px; align-items: center; gap: 6px; margin-bottom: 8px; font-size: 12px; color: #9aa0a8; }
.ov-row span { font-family: "Consolas", monospace; color: var(--lcd-text); }
input[type=range] { accent-color: var(--accent); }

/* 手轮 */
.hw-row { display: flex; gap: 4px; margin-bottom: 6px; }
.hw-row .key { flex: 1; }
.hw-row .key.active { background: linear-gradient(#e0a420, #b9861a); color: #1a1a1a; }
.hw-wheel-wrap { display: flex; flex-direction: column; align-items: center; gap: 8px; margin-top: 8px; }
.hw-wheel-disc {
  width: 96px; height: 96px; border-radius: 50%;
  background: radial-gradient(circle at 38% 32%, #4a505a, #23262c 70%);
  border: 3px solid #111318;
  box-shadow: 0 3px 8px rgba(0,0,0,.6), inset 0 2px 3px rgba(255,255,255,.12);
  position: relative; cursor: ns-resize; touch-action: none;
  user-select: none; -webkit-user-select: none;
}
.hw-wheel-knob {
  position: absolute; inset: 14px; border-radius: 50%;
  background: linear-gradient(#5b626d, #363c45);
  border: 2px solid #131518;
  box-shadow: inset 0 2px 3px rgba(255,255,255,.18);
  display: flex; align-items: center; justify-content: center;
}
.hw-mark {
  width: 4px; height: 26px; border-radius: 2px; background: var(--accent);
  position: relative; top: -12px;
}
.hw-dial {
  text-align: center; font-family: "Consolas", monospace;
  background: #14171b; border: 1px solid #333; border-radius: 4px;
  padding: 4px 8px; color: var(--lcd-text); font-size: 13px; min-width: 90px;
}
.hw-wheel-tip { font-size: 10px; color: #7f8894; text-align: center; line-height: 1.3; margin-top: 4px; }

/* 数字键盘 */
.keypad { display: grid; grid-template-columns: repeat(5, 1fr); gap: 5px; }
.keypad .key { padding: 7px 2px; font-size: 14px; }
.keypad .key-wide { grid-column: span 2; font-size: 12px; }

/* 编辑/控制 */
.edit-keys { display: grid; grid-template-columns: repeat(2, 1fr); gap: 5px; margin-bottom: 8px; }
.control-keys { display: grid; grid-template-columns: repeat(3, 1fr); gap: 5px; margin-bottom: 8px; }
.key.ctrl { height: 46px; font-size: 13px; }
.key.ctrl.reset { background: linear-gradient(#c4453a, #9c3128); }
.key.ctrl.start { background: linear-gradient(#3a9c3a, #2a7a2a); }
.key.ctrl.hold { background: linear-gradient(#d8952e, #b0761e); }
.switch-row { display: flex; gap: 10px; flex-wrap: wrap; }

/* 急停 */
.estop {
  width: 100%; height: 100px; border-radius: 50%;
  background: radial-gradient(circle at 40% 35%, #ef5a4a, #b02a1e);
  border: 3px solid #5c130c;
  color: #fff; cursor: pointer;
  box-shadow: 0 4px 8px rgba(0,0,0,.5), inset 0 2px 4px rgba(255,255,255,.3);
  margin-top: 10px;
}
.estop.active {
  background: radial-gradient(circle at 40% 35%, #a02318, #6d140b);
  transform: translateY(4px);
  box-shadow: inset 0 3px 6px rgba(0,0,0,.6);
}
.estop-cap { font-size: 13px; font-weight: bold; letter-spacing: 1px; }

/* ---------- 弹窗 ---------- */
.modal {
  position: fixed; inset: 0; background: rgba(0,0,0,.65);
  display: flex; align-items: center; justify-content: center;
  z-index: 100;
}
.modal.hidden { display: none; }
.modal-box {
  background: #23272d; border: 1px solid #16181c; border-radius: 8px;
  padding: 18px; min-width: 320px; max-width: 92vw;
  box-shadow: 0 10px 40px rgba(0,0,0,.6);
}
.modal-box.wide { width: 760px; }
.modal-title { font-size: 16px; color: var(--accent); margin-bottom: 12px; font-weight: bold; }
.alarm-box .modal-title { color: var(--red); }
.alarm-text { font-family: "Consolas", monospace; font-size: 15px; color: #ff8a7a; white-space: pre-wrap; margin-bottom: 14px; line-height: 1.6; }
.modal-btns { display: flex; gap: 10px; justify-content: flex-end; margin-top: 12px; }

/* 程序编辑器 */
.prog-toolbar { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 8px; align-items: center; }
.prog-toolbar input[type=text] {
  width: 90px; background: #14171b; color: var(--lcd-text); border: 1px solid #333;
  border-radius: 3px; padding: 4px 8px; font-family: "Consolas", monospace;
}
.prog-list { display: flex; gap: 5px; flex-wrap: wrap; margin-bottom: 8px; max-height: 60px; overflow-y: auto; }
.prog-list .pitem {
  background: #2f343b; border: 1px solid #16181c; border-radius: 3px;
  padding: 3px 8px; font-size: 11px; cursor: pointer; color: #cfd3d8;
  font-family: "Consolas", monospace;
}
.prog-list .pitem.active { background: var(--accent); color: #1a1a1a; }
.prog-editor {
  width: 100%; height: 280px; background: var(--lcd-bg); color: var(--lcd-text);
  border: 1px solid #0a0c0f; border-radius: 4px; padding: 10px;
  font-family: "Consolas", monospace; font-size: 14px; line-height: 1.5;
  resize: vertical; white-space: pre; overflow: auto;
}
.prog-status { font-size: 12px; color: #9aa0a8; margin-top: 6px; min-height: 16px; }

/* 刀补/参数表格 */
.offset-table { width: 100%; border-collapse: collapse; margin-bottom: 12px; }
.offset-table th, .offset-table td {
  border: 1px solid #16181c; padding: 5px; text-align: center; font-size: 12px;
  font-family: "Consolas", monospace; color: #cfd3d8;
}
.offset-table th { background: #2f343b; color: #9aa0a8; }
.offset-table input {
  width: 60px; background: #14171b; color: var(--lcd-text); border: 1px solid #333;
  border-radius: 3px; padding: 2px 4px; text-align: center; font-family: "Consolas", monospace;
}

/* Toast */
.toast {
  position: fixed; bottom: 30px; left: 50%; transform: translateX(-50%);
  background: rgba(20,23,27,.95); color: var(--lcd-text); border: 1px solid #333;
  border-radius: 6px; padding: 10px 20px; font-size: 14px; z-index: 200;
  font-family: "Consolas", monospace;
}
.toast.hidden { display: none; }

/* 响应式 */
@media (max-width: 1180px) {
  #console { grid-template-columns: repeat(4, 1fr); }
}
@media (max-width: 900px) {
  #main { grid-template-columns: 1fr; }
  #console { grid-template-columns: repeat(2, 1fr); }
}