/* rp-prep 작업 화면. 외부 글꼴·이미지 없이 시스템 글꼴만 쓴다. */
:root {
  --fg: #2b2b2b; --muted: #6b6b6b; --line: #d9d6cf; --bg: #f4f3ef; --card: #ffffff; --view: #eceae4;
  --accent: #3f3f3f; --accent-fg: #ffffff; --sel: #c27a2c; --sel-bg: #f6ead9;
  --ok: #2e7d32; --bad: #c62828; --warn: #a15c00; --focus: #c27a2c;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { height: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--fg);
  font: 13px/1.45 system-ui, -apple-system, "Segoe UI", "Malgun Gothic", "Apple SD Gothic Neo", "Noto Sans KR", sans-serif;
  display: grid; grid-template-rows: auto minmax(0, 1fr) auto;
}
button, input, select { font: inherit; color: inherit; }
button {
  border: 1px solid var(--line); background: var(--card); border-radius: 5px; padding: 4px 10px; cursor: pointer;
  white-space: nowrap;
}
button:hover:not(:disabled) { border-color: #a8a49c; }
button.primary { background: var(--accent); color: var(--accent-fg); border-color: var(--accent); }
button:disabled { opacity: .45; cursor: default; }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 1px; }
input[type=number], select { border: 1px solid var(--line); border-radius: 4px; padding: 3px 5px; background: #fff; }
input[type=number] { width: 78px; }
.muted { color: var(--muted); }
.grow { flex: 1; }
.sep { width: 1px; align-self: stretch; background: var(--line); margin: 0 4px; }

/* 머리 막대 */
.bar {
  display: flex; align-items: center; gap: 8px; padding: 7px 12px; background: var(--card);
  border-bottom: 1px solid var(--line); flex-wrap: wrap;
}
.brand { font-weight: 700; font-size: 15px; margin-right: 6px; letter-spacing: .2px; }
.brand .muted { font-weight: 400; font-size: 12px; }
.field { display: flex; align-items: center; gap: 5px; color: var(--muted); }
.field select { color: var(--fg); }

/* 세 칸 */
main { display: grid; grid-template-columns: 250px minmax(0, 1fr) 400px; min-height: 0; }
.panel { background: var(--card); overflow: auto; padding: 10px 12px; min-height: 0; }
#left { border-right: 1px solid var(--line); }
#right { border-left: 1px solid var(--line); padding-top: 0; }
h2 { font-size: 13px; margin: 6px 0 6px; font-weight: 650; }
h3 { font-size: 12.5px; margin: 14px 0 6px; font-weight: 650; color: #444; }
.row { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; margin: 6px 0; }
.line { display: flex; align-items: center; gap: 6px; margin: 5px 0; flex-wrap: wrap; }
.xyz { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; }
.xyz.two { grid-template-columns: repeat(2, 1fr); }
.xyz label { display: flex; align-items: center; gap: 4px; }
.xyz input { width: 100%; min-width: 0; }

/* 부품 목록 */
#parts { list-style: none; margin: 0; padding: 0; border: 1px solid var(--line); border-radius: 6px; max-height: 40vh;
  overflow: auto; }
#parts:empty { display: none; }
#parts li { padding: 6px 8px; border-bottom: 1px solid var(--line); cursor: pointer; }
#parts li:last-child { border-bottom: 0; }
#parts li:hover { background: #faf9f6; }
#parts li[aria-selected=true] { background: var(--sel-bg); box-shadow: inset 3px 0 0 var(--sel); }
#parts .name { font-weight: 600; overflow-wrap: anywhere; }
#parts .sub { color: var(--muted); font-size: 12px; }
.tag { display: inline-block; font-size: 11px; padding: 0 6px; border-radius: 999px; margin-left: 4px; font-weight: 600; }
.tag.bad { background: #fde7e7; color: var(--bad); }
#partinfo { display: grid; grid-template-columns: auto 1fr; gap: 2px 8px; margin: 8px 0 0; font-size: 12px; }
#partinfo dt { color: var(--muted); }
#partinfo dd { margin: 0; text-align: right; font-variant-numeric: tabular-nums; }
#dupCount { width: 54px; }
#log { margin: 0; padding-left: 20px; font-size: 12px; color: var(--muted); max-height: 28vh; overflow: auto; }
#log li { margin: 2px 0; overflow-wrap: anywhere; }
#log li.err { color: var(--bad); }
#log li.warn { color: var(--warn); }

/* 3D 보기 */
#center { display: flex; flex-direction: column; min-width: 0; min-height: 0; }
#view { position: relative; flex: 1; min-height: 240px; background: var(--view); overflow: hidden; }
#view canvas { display: block; touch-action: none; }
#dropzone {
  position: absolute; inset: 12px; border: 2px dashed var(--sel); border-radius: 10px; display: flex;
  align-items: center; justify-content: center; font-size: 18px; color: var(--sel); background: rgba(255, 255, 255, .6);
  pointer-events: none;
}
#viewbar {
  display: flex; align-items: center; gap: 6px; padding: 6px 10px; background: var(--card);
  border-top: 1px solid var(--line); flex-wrap: wrap;
}
#legend { display: flex; gap: 10px; flex-wrap: wrap; font-size: 12px; color: var(--muted); }
#legend label { display: flex; gap: 4px; align-items: center; cursor: pointer; }
.sw { display: inline-block; width: 11px; height: 11px; border-radius: 2px; }

/* 탭 */
#tabs {
  display: flex; flex-wrap: wrap; gap: 2px; position: sticky; top: 0; background: var(--card); padding: 8px 0 6px;
  border-bottom: 1px solid var(--line); z-index: 1;
}
#tabs button { border: 0; border-radius: 4px; padding: 4px 7px; background: transparent; color: var(--muted); }
#tabs button.on { background: var(--accent); color: var(--accent-fg); }
.tab { display: none; padding-top: 6px; }
.tab.on { display: block; }

/* 결과 */
.result:empty { display: none; }
.result.stale > :not(.stalenote) { opacity: .5; }
.rhead { margin: 2px 0 4px; overflow-wrap: anywhere; }
#viewbar button.on { background: var(--accent); color: var(--accent-fg); border-color: var(--accent); }
#view.measuring canvas { cursor: crosshair; }
#measureInfo { font-variant-numeric: tabular-nums; }
/* 3D 보기 위 글자: 측정값(선분 가운데), 끄는 동안 이동량, 조작 안내 */
.mlabel, .tip, .hint { position: absolute; pointer-events: none; font-variant-numeric: tabular-nums; }
.mlabel {
  transform: translate(-50%, -50%); background: rgba(255, 255, 255, .94); border: 1px solid #3f3f3f; border-radius: 5px;
  padding: 2px 8px; text-align: center; line-height: 1.3; white-space: nowrap; box-shadow: 0 1px 4px rgba(0, 0, 0, .15);
}
.mlabel b { display: block; font-size: 13px; }
.mlabel .mhead { display: flex; align-items: center; justify-content: center; gap: 5px; }
.mlabel .mhead b { display: inline; }
.mlabel i {
  font-style: normal; font-size: 10.5px; font-weight: 700; color: #fff; background: #3f3f3f; border-radius: 999px;
  min-width: 16px; height: 16px; line-height: 16px; padding: 0 4px;
}
.mlabel .mclose {
  pointer-events: auto; border: 0; background: transparent; color: var(--muted); padding: 0 2px; font-size: 14px;
  line-height: 1; cursor: pointer;
}
.mlabel .mclose:hover { color: var(--bad); }
.mlabel span { display: block; font-size: 11px; color: var(--muted); }
.tip {
  background: var(--accent); color: var(--accent-fg); border-radius: 4px; padding: 2px 7px; font-size: 12px;
  white-space: nowrap;
}
.hint { right: 10px; bottom: 8px; font-size: 11.5px; color: var(--muted); background: rgba(236, 234, 228, .8);
  padding: 1px 6px; border-radius: 4px; }
.result { margin-top: 12px; border-top: 1px solid var(--line); padding-top: 8px; }
.badge { display: inline-block; padding: 1px 9px; border-radius: 999px; font-size: 12px; font-weight: 600; color: #fff; }
.badge.ok { background: var(--ok); }
.badge.bad { background: var(--bad); }
table { border-collapse: collapse; width: 100%; font-size: 12px; margin-top: 6px; }
th, td { border-bottom: 1px solid var(--line); padding: 3px 5px; text-align: right; font-variant-numeric: tabular-nums; }
th:first-child, td:first-child { text-align: left; }
th { font-weight: 600; color: #444; white-space: nowrap; }
td.bad { color: var(--bad); font-weight: 600; }
ul.msgs { margin: 6px 0 0; padding-left: 18px; }
ul.msgs li { margin: 2px 0; }
li.warn, p.warn { color: var(--warn); }
.err { color: var(--bad); font-weight: 600; }
#slice2d { width: 100%; height: 300px; background: #fff; border: 1px solid var(--line); border-radius: 6px;
  margin-top: 6px; }
#layerSlider { width: 100%; }

/* 아래 알림 줄 */
#status {
  display: flex; align-items: center; gap: 8px; padding: 5px 12px; background: var(--card);
  border-top: 1px solid var(--line); min-height: 28px; font-size: 12.5px;
}
#status.err #msg { color: var(--bad); font-weight: 600; }
#status.warn #msg { color: var(--warn); }
#spinner {
  width: 13px; height: 13px; border: 2px solid var(--line); border-top-color: var(--sel); border-radius: 50%;
  animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
body[data-busy="1"] #view { cursor: progress; }

@media (max-width: 1100px) {
  main { grid-template-columns: 220px minmax(0, 1fr); }
  #right { grid-column: 1 / -1; border-left: 0; border-top: 1px solid var(--line); max-height: none; }
  body { grid-template-rows: auto auto auto; height: auto; }
  #center { min-height: 60vh; }
}
@media (max-width: 700px) {
  main { grid-template-columns: minmax(0, 1fr); }
  #left { border-right: 0; border-bottom: 1px solid var(--line); }
  #center { min-height: 55vh; }
}
