/* UltraCAD — 스타일 (다크 테마, CAD 리본 스타일) */
* { box-sizing: border-box; }
:root, html[data-theme="midnight"] {
  color-scheme: dark;
  --app-bg:#0e151d; --surface:#151f29; --surface-raised:#1c2935; --surface-inset:#0b1118;
  --surface-soft:#22313e; --border:#334656; --text:#e4edf4; --text-muted:#91a5b5;
  --accent:#4db6ff; --selection:#183f5c; --hover:#20384a; --canvas-bg:#0b1118;
  --overlay:rgba(5,10,15,.78); --success:#67d88a; --danger:#ef6670; --on-accent:#07131c;
}
html[data-theme="blueprint"] { --app-bg:#061c31; --surface:#0b2b48; --surface-raised:#103858; --surface-inset:#082744; --surface-soft:#164566; --border:#276184; --text:#e5f5ff; --text-muted:#99c5df; --accent:#6bd7ff; --selection:#15557b; --hover:#16486b; --canvas-bg:#082744; --overlay:rgba(3,20,36,.8); --success:#72dc96; --danger:#ff7580; --on-accent:#062138; }
html[data-theme="graphite"] { --app-bg:#191b1e; --surface:#24272b; --surface-raised:#2d3136; --surface-inset:#202225; --surface-soft:#353a40; --border:#4b5158; --text:#eef0f2; --text-muted:#adb3ba; --accent:#72b7ff; --selection:#374e66; --hover:#353f49; --canvas-bg:#202225; --overlay:rgba(13,14,16,.8); --success:#7bd48e; --danger:#ee6d77; --on-accent:#101820; }
html[data-theme="solar"] { --app-bg:#0e171e; --surface:#17242d; --surface-raised:#21313b; --surface-inset:#101a22; --surface-soft:#2b3c47; --border:#465863; --text:#fff3d2; --text-muted:#c6b98f; --accent:#ffbd55; --selection:#62471d; --hover:#463b28; --canvas-bg:#101a22; --overlay:rgba(12,15,16,.8); --success:#8bdc75; --danger:#ef6c72; --on-accent:#2d1a03; }
html[data-theme="light"] { color-scheme:light; --app-bg:#dfe7ec; --surface:#f7fafc; --surface-raised:#fff; --surface-inset:#e7eef3; --surface-soft:#edf3f6; --border:#aebdc7; --text:#1f303c; --text-muted:#5d7180; --accent:#087fca; --selection:#c9e7f8; --hover:#e0eff7; --canvas-bg:#e7eef3; --overlay:rgba(245,249,252,.82); --success:#29894c; --danger:#bd3743; --on-accent:#fff; }
html, body { margin: 0; padding: 0; height: 100%; overflow: hidden; }
#acad-body {
  display: flex; flex-direction: column; height: 100vh; height: 100dvh;
  font-family: "Segoe UI", "Malgun Gothic", sans-serif;
  background: var(--app-bg); color: var(--text);
}
#acad-header {
  height: 40px; flex: 0 0 auto; display: flex; align-items: center; gap: 12px;
  padding: 0 12px; background: var(--surface); border-bottom: 1px solid var(--border);
  font-size: 13px;
}
.acad-logo { font-weight: 600; color: var(--text); }
.acad-logo i { color: #c0392b; margin-right: 4px; }
#acad-file-name { color: var(--text-muted); }
.acad-header-right { margin-left: auto; display: flex; gap: 10px; }
.acad-link { color: var(--text-muted); text-decoration: none; }
.acad-link:hover { color: var(--accent); }

/* ── 리본 탭/컨텐츠 ── */
#acad-ribbon-tabs { flex: 0 0 auto; display: flex; background: var(--surface); border-bottom: 1px solid var(--border); padding: 0 6px; }
.acad-rtab { border: none; background: transparent; color: var(--text-muted); padding: 6px 16px; font-size: 12px; cursor: pointer; border-bottom: 2px solid transparent; }
.acad-rtab:hover { color: var(--text); }
.acad-rtab.active { color: var(--text); border-bottom-color: var(--accent); font-weight: 600; }

#acad-ribbon-content { flex: 0 0 auto; background: var(--surface-raised); border-bottom: 1px solid var(--border); min-height: 78px; overflow-x: auto; overflow-y: hidden; }
.acad-rpanel { display: none; gap: 4px; padding: 4px 6px; }
.acad-rpanel.active { display: flex; }
.acad-rgroup { display: flex; flex-direction: column; border-right: 1px solid var(--border); padding: 0 8px; flex: 0 0 auto; }
.acad-rgroup-items { display: flex; gap: 2px; align-items: center; flex: 1; flex-wrap: wrap; max-width: 420px; }
.acad-rgroup-label { text-align: center; font-size: 9px; color: var(--text-muted); padding: 2px 0 1px; }
.acad-ricon-btn {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  width: 46px; height: 46px; border: 1px solid transparent; border-radius: 4px;
  background: transparent; cursor: pointer; color: var(--text); font-size: 9px; padding: 2px;
}
.acad-ricon-btn:hover { background: var(--hover); border-color: var(--accent); }
.acad-ricon-btn svg { width: 20px; height: 20px; }
.acad-ricon-btn i.fas { font-size: 17px; line-height: 1; }
.acad-ricon-btn span { line-height: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 44px; }

/* 파일(F) 탭: 첨부 이미지처럼 파란 강조 */
.acad-rtab-file { background: #2f6fd6; color: #fff !important; border-radius: 4px 4px 0 0; margin-right: 4px; font-weight: 600; }
.acad-rtab-file:hover { background: #2860bf; color: #fff !important; }

/* big 버튼(파일/보기/출력의 큰 아이콘) */
.acad-ricon-btn.big { width: 64px; height: 60px; }
.acad-ricon-btn.big i.fas { font-size: 22px; }
.acad-ricon-btn.big span { max-width: 62px; font-size: 10px; }

/* 토글 활성 상태(노란 강조 — 첨부 이미지의 활성 도구 스타일) */
.acad-ricon-btn.active {
  background: rgba(255, 193, 7, 0.16);
  border-color: #ffb300;
  box-shadow: inset 0 0 0 1px rgba(255,179,0,.45);
}
.acad-ricon-btn.active i.fas, .acad-ricon-btn.active span { color: #ffb300; }
.acad-ricon-btn.disabled, .acad-ricon-btn:disabled { opacity: .4; cursor: not-allowed; }
.acad-ricon-btn.disabled:hover, .acad-ricon-btn:disabled:hover { background: transparent; border-color: transparent; }

/* 뷰어 그룹 여러 줄 아이콘: 이미지처럼 2행 배치 허용 */
.acad-rpanel[data-rpanel="viewer"] .acad-rgroup-items { max-width: 300px; }

/* 제공/TEST 파일 플로팅 버튼 */
#acad-test-fab {
  position: fixed; right: 16px; bottom: 64px; z-index: 40;
  display: flex; flex-direction: column; align-items: flex-end; gap: 7px;
}
#acad-test-fab button {
  background: #16a34a; color: #fff; border: none; border-radius: 20px;
  padding: 8px 14px; font-size: 12px; font-weight: 600; cursor: pointer;
  box-shadow: 0 3px 10px rgba(0,0,0,.35); display: inline-flex; align-items: center; gap: 6px;
}
#acad-test-fab #acad-cover-dwg { background: #2563eb; }
#acad-test-fab button:hover { background: #15803d; }
#acad-test-fab #acad-cover-dwg:hover { background: #1d4ed8; }

/* ── 작업영역: 좌패널 | 캔버스 | 우패널 ── */
#acad-workspace { flex: 1 1 auto; display: flex; min-height: 0; overflow: hidden; }
#acad-left-panel, #acad-right-panel {
  flex: 0 0 200px; background: var(--surface); border-right: 1px solid var(--border);
  display: flex; flex-direction: column; overflow-y: auto; font-size: 12px;
}
#acad-right-panel { border-right: none; border-left: 1px solid var(--border); }
.acad-ptabs { display: flex; border-bottom: 1px solid var(--border); flex: 0 0 auto; }
.acad-ptab { flex: 1; background: transparent; border: none; color: var(--text-muted); padding: 6px 4px; font-size: 11px; cursor: pointer; }
.acad-ptab.active { color: var(--accent); border-bottom: 2px solid var(--accent); }
.acad-empty { color: #666; padding: 10px; font-size: 11px; text-align: center; }
#acad-layer-list { list-style: none; margin: 0; padding: 4px; }
#acad-layer-list li { display: flex; align-items: center; gap: 6px; padding: 4px 6px; border-radius: 3px; }
#acad-layer-list li:hover { background: var(--hover); }
.acad-layer-swatch { width: 11px; height: 11px; border-radius: 2px; flex: 0 0 auto; border: 1px solid #444; }
#acad-prop-table { width: 100%; border-collapse: collapse; font-size: 11px; }
#acad-prop-table td { padding: 4px 6px; border-bottom: 1px solid #2a3038; word-break: break-all; }
#acad-prop-table td:first-child { color: var(--text-muted); width: 40%; }

.acad-battman { border-top: 1px solid #333b45; padding: 8px; margin-top: auto; }
.acad-battman-head { font-size: 11px; color: var(--text-muted); margin-bottom: 6px; }
.acad-battman select { width: 100%; margin-bottom: 6px; background: var(--surface-inset); color: var(--text); border: 1px solid var(--border); padding: 4px; font-size: 11px; }
#acad-battman-table { width: 100%; border-collapse: collapse; font-size: 10px; margin-bottom: 6px; }
#acad-battman-table td { padding: 2px; border-bottom: 1px solid #2a3038; }
#acad-battman-table input { width: 100%; background: var(--surface-inset); color: var(--text); border: 1px solid var(--border); font-size: 10px; padding: 2px 4px; }
.acad-btn-accent { width: 100%; background: var(--accent); color: var(--on-accent); border: none; padding: 6px; border-radius: 3px; cursor: pointer; font-size: 11px; font-weight: 600; }
.acad-btn-accent:hover { background: #6bb5ff; }

#acad-main { flex: 1 1 auto; position: relative; overflow: hidden; min-width: 0; }
#acad-canvas { position: absolute; inset: 0; width: 100%; height: 100%; display: block; cursor: crosshair; }
#acad-coord {
  position: absolute; right: 10px; bottom: 10px; padding: 3px 8px;
  background: var(--overlay); color: var(--text); border-radius: 3px; font-size: 12px; font-family: monospace;
  pointer-events: none;
}

#acad-cmdline {
  flex: 0 0 auto; background: var(--surface-inset); border-top: 1px solid var(--border);
  padding: 4px 8px 6px; font-family: "Consolas", monospace; font-size: 13px;
}
#acad-cmd-history {
  max-height: 70px; overflow-y: auto; color: var(--text-muted); white-space: pre-wrap;
  margin-bottom: 3px; line-height: 1.35;
}
.acad-cmd-row { display: flex; align-items: center; gap: 6px; }
.acad-cmd-prompt { color: var(--success); }
#acad-cmd-input, #acad-lisp-input {
  flex: 1; background: transparent; border: none; outline: none;
  color: var(--text); font-family: inherit; font-size: 13px;
}

/* ── 모달 (플롯 / LISP) ── */
.acad-modal { position: fixed; inset: 0; background: color-mix(in srgb, var(--app-bg) 72%, transparent); display: flex; align-items: center; justify-content: center; z-index: 50; }
.acad-modal.hidden { display: none; }
.acad-modal-box { background: var(--surface); border: 1px solid var(--border); border-radius: 6px; width: 360px; max-width: 92vw; box-shadow: 0 10px 40px rgba(0,0,0,.5); }
.acad-lisp-box { width: 520px; }
.acad-modal-head { display: flex; align-items: center; gap: 8px; padding: 10px 12px; border-bottom: 1px solid var(--border); font-size: 13px; color: var(--text); }
.acad-modal-head button { margin-left: auto; background: none; border: none; color: var(--text-muted); cursor: pointer; font-size: 14px; }
.acad-modal-body { padding: 12px; display: flex; flex-direction: column; gap: 10px; font-size: 12px; }
.acad-modal-body label { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.acad-modal-body select { background: var(--surface-inset); color: var(--text); border: 1px solid var(--border); padding: 4px 6px; }
.acad-modal-actions { display: flex; gap: 8px; }
.acad-modal-actions button { flex: 1; }
#acad-lisp-output { height: 220px; overflow-y: auto; background: var(--surface-inset); border: 1px solid var(--border); border-radius: 4px; padding: 6px 8px; font-family: "Consolas", monospace; font-size: 12px; white-space: pre-wrap; color: var(--text-muted); }

/* ── 반응형 배치: 좁은 화면에서 캔버스 우선 확보 ──
   ≥901px: 패널 200px 고정(기본) / 901~641px: 패널 150px 축소
   ≤640px: 좌/우 패널을 오버레이 드로어로 전환(헤더 토글 버튼으로 여닫음) */
.acad-panel-toggle { display: none; background: transparent; border: 1px solid var(--border); color: var(--text-muted); border-radius: 4px; width: 30px; height: 26px; cursor: pointer; font-size: 12px; }
.acad-panel-toggle:hover { color: var(--text); border-color: var(--accent); }

@media (max-width: 900px) {
  #acad-left-panel, #acad-right-panel { flex: 0 0 150px; }
}
@media (max-width: 640px) {
  .acad-panel-toggle { display: inline-flex; align-items: center; justify-content: center; }
  #acad-workspace { position: relative; }
  #acad-workspace.drawer-open::after { content: ''; position: absolute; inset: 0; z-index: 29; background: color-mix(in srgb, var(--app-bg) 70%, transparent); }
  #acad-left-panel, #acad-right-panel {
    position: absolute; top: 0; bottom: 0; z-index: 30; width: 210px; flex: none;
    transform: translateX(-100%); transition: transform .18s ease;
    box-shadow: 4px 0 18px rgba(0,0,0,.45);
  }
  #acad-left-panel { left: 0; }
  #acad-right-panel { right: 0; transform: translateX(100%); box-shadow: -4px 0 18px rgba(0,0,0,.45); }
  #acad-left-panel.open, #acad-right-panel.open { transform: translateX(0); }
  .acad-ricon-btn { width: 44px; height: 44px; }
  #acad-header { gap: 8px; padding: 0 8px; }
  #acad-file-name { display: none; }
  #acad-header { min-width: 0; }
  .acad-header-right { gap: 5px; }
}

@media (max-height: 620px) {
  #acad-ribbon-content { min-height: 58px; }
  .acad-ricon-btn { width: 42px; height: 40px; }
  .acad-rgroup-label { display: none; }
  #acad-cmd-history { max-height: 34px; }
  #acad-cmdline { padding-block: 3px; }
}

/* ═══════════════════════ TM S-Design 스타일 오버라이드 ═══════════════════════ */
/* 밝은 파란색 계열 리본(윈도우 애플리케이션 룩) */
body.tmsd {
  --tmsd-blue: #4a86c5;
  --tmsd-blue-d: #2f6aa8;
  --tmsd-ribbon-bg: #e8eef5;
  --tmsd-ribbon-bg2: #dce6f1;
  --tmsd-tab-bg: #cfdcea;
  --tmsd-group-border: #b8c8da;
  --tmsd-text: #1f2a36;
  --tmsd-text-muted: #55677a;
  background: #c3d2e2;
  color: var(--tmsd-text);
}
body.tmsd .tmsd-hidden { display: none !important; }

/* 타이틀바 */
#tmsd-titlebar {
  flex: 0 0 auto; height: 26px; display: flex; align-items: center; gap: 10px;
  padding: 0 10px; font-size: 12px; color: #eaf2fb;
  background: linear-gradient(#4a86c5, #356399);
  border-bottom: 1px solid #2b568a;
}
#tmsd-titlebar .tmsd-app { font-weight: 600; letter-spacing:.2px; }
#tmsd-titlebar .tmsd-app i { margin-right: 4px; }
#tmsd-titlebar .tmsd-ver { opacity:.85; font-weight: 400; font-size: 11px; }
#tmsd-titlebar .tmsd-title-center { position: absolute; left: 50%; transform: translateX(-50%); opacity:.9; }
#tmsd-titlebar .tmsd-title-right { margin-left: auto; display: flex; align-items: center; gap: 12px; font-size: 11px; opacity:.92; }
#tmsd-titlebar .tmsd-user { font-family: monospace; }
#tmsd-titlebar .tmsd-link { color:#eaf2fb; text-decoration:none; }
#tmsd-titlebar .tmsd-link:hover { color:#fff; }

/* 탭바: 밝은 파랑, 탭들이 촘촘히 */
body.tmsd #acad-ribbon-tabs {
  background: var(--tmsd-tab-bg); border-bottom: 1px solid var(--tmsd-blue-d);
  padding: 0 2px; flex-wrap: nowrap; overflow-x: auto; gap: 0;
}
body.tmsd .acad-rtab {
  color: var(--tmsd-text); padding: 4px 10px; font-size: 12px; border-bottom: 2px solid transparent;
  white-space: nowrap; border-radius: 0;
}
body.tmsd .acad-rtab:hover { background: #d8e4f0; color: var(--tmsd-blue-d); }
body.tmsd .acad-rtab.active {
  background: var(--tmsd-ribbon-bg); color: var(--tmsd-blue-d); font-weight: 700;
  border-bottom-color: var(--tmsd-blue); border-top: 2px solid var(--tmsd-blue);
}
body.tmsd .acad-rtab-file { background: var(--tmsd-blue); color:#fff; }

/* 리본 컨텐츠 */
body.tmsd #acad-ribbon-content {
  background: linear-gradient(var(--tmsd-ribbon-bg), var(--tmsd-ribbon-bg2));
  border-bottom: 1px solid var(--tmsd-blue-d); min-height: 96px;
}
body.tmsd .acad-rgroup { border-right: 1px solid var(--tmsd-group-border); padding: 2px 6px 0; }
body.tmsd .acad-rgroup-items { max-width: none; gap: 1px; align-content: flex-start; max-height: 74px; }
body.tmsd .acad-rgroup-label {
  color: var(--tmsd-text-muted); font-size: 10px; border-top: 1px solid var(--tmsd-group-border);
  margin-top: 2px; padding-top: 2px;
}

/* 아이콘 버튼(밝은 테마) */
body.tmsd .acad-ricon-btn { color: var(--tmsd-text); width: 42px; height: 44px; font-size: 9px; }
body.tmsd .acad-ricon-btn i.fas { color: var(--tmsd-blue-d); font-size: 16px; }
body.tmsd .acad-ricon-btn:hover { background: #d4e2f1; border-color: var(--tmsd-blue); }
body.tmsd .acad-ricon-btn span { max-width: 46px; white-space: normal; text-align: center; line-height: 1.05; }
body.tmsd .acad-ricon-btn.big { width: 58px; height: 66px; }
body.tmsd .acad-ricon-btn.big i.fas { font-size: 22px; }
body.tmsd .acad-ricon-btn.big span { max-width: 58px; }
body.tmsd .acad-ricon-btn.active {
  background: #fff2c9; border-color: #e0a92b; box-shadow: inset 0 0 0 1px #f0c657;
}
body.tmsd .acad-ricon-btn.active i.fas, body.tmsd .acad-ricon-btn.active span { color: #b6791a; }
body.tmsd .acad-ricon-btn.disabled, body.tmsd .acad-ricon-btn:disabled { opacity:.4; }

/* 세로 구분선 */
.acad-rsep { width: 1px; align-self: stretch; margin: 2px 4px; background: var(--tmsd-group-border, #b8c8da); }

/* 체크박스형 표시항목(Node Display) */
.acad-rcheck {
  display: flex; align-items: center; gap: 3px; font-size: 10px; color: var(--tmsd-text, #1f2a36);
  padding: 1px 4px; cursor: pointer; white-space: nowrap; border-radius: 3px;
}
.acad-rcheck:hover { background: #d4e2f1; }
.acad-rcheck input { width: 12px; height: 12px; margin: 0; accent-color: var(--tmsd-blue, #4a86c5); }
.acad-rcheck.on span { color: var(--tmsd-blue-d, #2f6aa8); font-weight: 600; }

/* 드롭다운(Deck 등) */
.acad-rdrop {
  height: 22px; align-self: center; font-size: 11px; border: 1px solid var(--tmsd-group-border, #b8c8da);
  border-radius: 3px; background: #fff; color: var(--tmsd-text, #1f2a36); padding: 0 4px; margin-left: 2px;
}

/* 밝은 캔버스/패널(TM S-Design 룩) */
body.tmsd #acad-workspace { background: #c3d2e2; }
body.tmsd #acad-left-panel, body.tmsd #acad-right-panel { background: #eef3f8; color: var(--tmsd-text); border-color: var(--tmsd-group-border); }
body.tmsd #acad-cmdline { background: #dfe8f1; color: var(--tmsd-text); border-top: 1px solid var(--tmsd-group-border); }
body.tmsd #acad-cmd-input { background:#fff; color: var(--tmsd-text); border:1px solid var(--tmsd-group-border); }
body.tmsd #acad-coord { color: var(--tmsd-text); background: rgba(255,255,255,.7); }
body.tmsd #tmsd-title-doc, body.tmsd #tmsd-verinfo { pointer-events:none; }

/* ══════════════════════════ 파일 로딩 오버레이 ══════════════════════════ */
#acad-loading-overlay {
  position: fixed; inset: 0; z-index: 9999; display: none;
  align-items: center; justify-content: center;
  background: rgba(20, 30, 45, 0.55); backdrop-filter: blur(2px);
}
.acad-loading-box {
  background: #fff; color: #1c2b3a; border-radius: 10px;
  padding: 28px 40px; min-width: 280px; text-align: center;
  box-shadow: 0 12px 40px rgba(0,0,0,.35);
  font-size: 14px; line-height: 1.55;
}
.acad-loading-spin {
  width: 42px; height: 42px; margin: 0 auto 16px;
  border: 4px solid #d4e2f0; border-top-color: #4a86c5;
  border-radius: 50%; animation: acad-spin 0.9s linear infinite;
}
@keyframes acad-spin { to { transform: rotate(360deg); } }
.acad-loading-msg { color: #2a3b4d; }
.acad-loading-msg b { color: #1a5fa0; }
.acad-loading-warn { color: #c0392b; font-weight: 600; }
