:root {
  --bg: #2b2d31; --panel: #1e1f22; --panel2: #26282c; --line: #111214; --line2: #3a3d42;
  --text: #e6e6e6; --muted: #9a9ea6; --accent: #58a6ff; --accent2: #1f6feb; --danger: #e5534b; --warn: #f0b429;
  --radius: 6px; font-size: 13px;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { height: 100%; margin: 0; }
body { font-family: "Segoe UI", "Malgun Gothic", "Apple SD Gothic Neo", system-ui, sans-serif; font-size: 13px; color: var(--text); background: var(--bg); overflow: hidden; }
button, input, select, textarea { font: inherit; color: inherit; }
button { background: var(--panel2); border: 1px solid var(--line2); border-radius: var(--radius); padding: 4px 9px; cursor: pointer; line-height: 1.3; }
button:hover:not(:disabled) { background: #33363b; border-color: #4a4e55; }
button:active:not(:disabled) { background: #3b3e44; }
button:disabled { opacity: 0.45; cursor: default; }
button.primary { background: var(--accent2); border-color: var(--accent2); color: #fff; }
button.primary:hover:not(:disabled) { background: #2a7cf5; }
button.danger { background: #5a2320; border-color: #7a2f2b; }
button.link { background: none; border: none; padding: 0; color: var(--accent); text-decoration: underline; cursor: pointer; }
button.on { background: #2f4f7a; border-color: var(--accent2); color: #fff; }
input[type=number], input[type=text], input[type=password], select, textarea { background: #141517; border: 1px solid var(--line2); border-radius: var(--radius); padding: 4px 6px; color: var(--text); }
input[type=number] { width: 64px; }
input[type=range] { flex: 1; min-width: 60px; accent-color: var(--accent); }
input:focus, select:focus, textarea:focus { outline: 1px solid var(--accent); }
kbd { background: #111; border: 1px solid #444; border-bottom-width: 2px; border-radius: 3px; padding: 0 4px; font-size: 11px; font-family: inherit; }
.muted { color: var(--muted); }
.small { font-size: 11px; }
.val { min-width: 40px; text-align: right; font-variant-numeric: tabular-nums; color: var(--muted); }
.sep { width: 1px; height: 22px; background: var(--line2); margin: 0 4px; }

#app { display: flex; flex-direction: column; height: 100vh; }

/* ---- 상단 바 ---- */
#topbar { height: 44px; display: flex; align-items: center; gap: 8px; padding: 0 10px; background: var(--panel); border-bottom: 1px solid var(--line); flex-shrink: 0; }
#topbar .brand { display: flex; align-items: center; gap: 8px; font-weight: 600; min-width: 130px; }
#topbar .brand img { height: 26px; max-width: 120px; object-fit: contain; }
#topbar .menu { display: flex; align-items: center; gap: 4px; flex-wrap: nowrap; overflow: hidden; }
#topbar .right { margin-left: auto; display: flex; align-items: center; gap: 8px; }
.doc-name { background: none; border: 1px dashed transparent; max-width: 220px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.doc-name:hover { border-color: var(--line2); }
.save-status { font-size: 11px; color: var(--muted); min-width: 70px; text-align: right; }
.save-status.saving { color: var(--warn); }
.save-status.error { color: var(--danger); }
#userBox { display: flex; align-items: center; gap: 6px; }
#userBox .user-name { color: var(--accent); font-weight: 600; }

/* ---- 본문 ---- */
#main { flex: 1; display: flex; min-height: 0; }
#toolbar { width: 46px; display: flex; flex-direction: column; align-items: center; gap: 3px; padding: 6px 0; background: var(--panel); border-right: 1px solid var(--line); flex-shrink: 0; overflow-y: auto; }
#toolbar button { width: 36px; height: 34px; padding: 0; display: flex; align-items: center; justify-content: center; font-size: 15px; }
#toolbar button svg { width: 20px; height: 20px; }
#toolbar button.on { background: #2f4f7a; border-color: var(--accent2); }
#toolbar .tool-sep { width: 28px; height: 1px; background: var(--line2); margin: 4px 0; }

#workspace { flex: 1; position: relative; min-width: 0; background: var(--bg); overflow: hidden; }
#view { position: absolute; inset: 0; display: block; touch-action: none; }
.empty-state { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; pointer-events: none; }
.empty-card { background: rgba(30,31,34,0.9); border: 1px dashed #555; border-radius: 12px; padding: 28px 36px; text-align: center; pointer-events: auto; max-width: 520px; }
.empty-card p { margin: 6px 0; }
.empty-icon { font-size: 40px; margin-bottom: 6px; }
#dropOverlay { position: absolute; inset: 0; background: rgba(31,111,235,0.18); border: 3px dashed var(--accent); display: flex; align-items: center; justify-content: center; z-index: 20; pointer-events: none; }
#dropOverlay .drop-msg { background: var(--accent2); color: #fff; padding: 12px 22px; border-radius: 8px; font-size: 16px; font-weight: 600; }

.popover { position: absolute; z-index: 30; background: var(--panel); border: 1px solid var(--line2); border-radius: 8px; padding: 10px; box-shadow: 0 8px 30px rgba(0,0,0,0.5); display: flex; flex-direction: column; gap: 6px; min-width: 260px; }
.popover .pop-title { font-weight: 600; margin-bottom: 2px; }
.popover button { text-align: left; display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 7px 10px; }
.popover .pop-hint { font-size: 11px; color: var(--muted); }

/* ---- 사이드바 ---- */
#sidebar { width: 310px; overflow-y: auto; background: var(--panel); border-left: 1px solid var(--line); flex-shrink: 0; }
.panel { border-bottom: 1px solid var(--line); padding: 8px 10px 10px; }
.panel-head { display: flex; align-items: center; justify-content: space-between; font-weight: 600; margin-bottom: 6px; }
.panel-tools { display: flex; gap: 2px; }
.panel-tools button { padding: 2px 6px; font-size: 12px; }
.row { display: flex; align-items: center; gap: 6px; margin: 5px 0; }
.row > label { min-width: 58px; color: var(--muted); }
.row.btns { justify-content: flex-start; gap: 6px; flex-wrap: wrap; }
label.chk { display: flex; align-items: center; gap: 4px; color: var(--muted); }
.grid4 { display: grid; grid-template-columns: 1fr 1fr; gap: 4px 8px; }
.grid4 label { display: flex; align-items: center; gap: 4px; color: var(--muted); }
.grid4 input { width: 100%; }

.layer-list { max-height: 260px; overflow-y: auto; border: 1px solid var(--line2); border-radius: var(--radius); background: #17181a; }
.layer-row { display: flex; align-items: center; gap: 6px; padding: 4px 6px; border-bottom: 1px solid #222; cursor: pointer; user-select: none; }
.layer-row:last-child { border-bottom: none; }
.layer-row:hover { background: #22242a; }
.layer-row.selected { background: #243a5a; }
.layer-row.active { box-shadow: inset 3px 0 0 var(--accent); }
.layer-row.hidden-layer { opacity: 0.5; }
.layer-row .thumb { width: 40px; height: 30px; background: repeating-conic-gradient(#666 0 25%, #999 0 50%) 0 0 / 8px 8px; border: 1px solid #333; flex-shrink: 0; display: flex; align-items: center; justify-content: center; overflow: hidden; }
.layer-row .thumb canvas { max-width: 100%; max-height: 100%; }
.layer-row .lname { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.layer-row .lname input { width: 100%; padding: 1px 4px; }
.layer-row .ico { background: none; border: none; padding: 2px 4px; font-size: 13px; opacity: 0.8; }
.layer-row .ico.off { opacity: 0.3; }
.layer-row .badge { font-size: 10px; background: #5a4a1e; color: #f0c060; border-radius: 3px; padding: 0 4px; }
.layer-empty { padding: 12px; color: var(--muted); text-align: center; }

.tint-group { display: flex; gap: 4px; }
.tint { width: 26px; height: 24px; padding: 0; border-radius: 4px; background: var(--c, var(--panel2)); border: 2px solid var(--line2); }
.tint.on { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent); }

.split-list { display: flex; flex-direction: column; gap: 3px; margin: 4px 0; max-height: 130px; overflow-y: auto; }
.split-row { display: flex; align-items: center; gap: 6px; font-size: 12px; }
.split-row .axis { width: 28px; color: var(--muted); }
.split-row input { width: 70px; }
.split-row button { padding: 1px 6px; }

.anchor-grid { display: grid; grid-template-columns: repeat(3, 14px); gap: 2px; margin-left: 6px; }
.anchor-grid button { width: 14px; height: 14px; padding: 0; border-radius: 2px; }
.anchor-grid button.on { background: var(--accent); border-color: var(--accent); }

.history-list { max-height: 200px; overflow-y: auto; border: 1px solid var(--line2); border-radius: var(--radius); background: #17181a; font-size: 12px; }
.history-row { padding: 3px 8px; cursor: pointer; border-bottom: 1px solid #222; display: flex; justify-content: space-between; }
.history-row:hover { background: #22242a; }
.history-row.current { background: #243a5a; }
.history-row.future { opacity: 0.45; }
.history-row .t { color: var(--muted); font-size: 10px; }

/* ---- 상태 바 ---- */
#statusbar { height: 26px; display: flex; align-items: center; gap: 14px; padding: 0 10px; background: var(--panel); border-top: 1px solid var(--line); font-size: 12px; color: var(--muted); flex-shrink: 0; overflow: hidden; white-space: nowrap; }
#statusbar select { padding: 1px 4px; font-size: 12px; }
#statusbar .st.hint { margin-left: auto; overflow: hidden; text-overflow: ellipsis; }

/* ---- 컨텍스트 메뉴 ---- */
.ctxmenu { position: fixed; z-index: 1000; background: var(--panel); border: 1px solid var(--line2); border-radius: 8px; padding: 4px; box-shadow: 0 8px 30px rgba(0,0,0,0.55); min-width: 210px; }
.ctxmenu .mi { display: flex; justify-content: space-between; gap: 16px; padding: 5px 10px; border-radius: 4px; cursor: pointer; }
.ctxmenu .mi:hover { background: #2f4f7a; }
.ctxmenu .mi.disabled { opacity: 0.4; pointer-events: none; }
.ctxmenu .mi .sc { color: var(--muted); font-size: 11px; }
.ctxmenu .msep { height: 1px; background: var(--line2); margin: 4px 6px; }

/* ---- 모달 ---- */
.modal-backdrop { position: fixed; inset: 0; background: rgba(0,0,0,0.55); z-index: 500; display: flex; align-items: center; justify-content: center; }
.modal { background: var(--panel); border: 1px solid var(--line2); border-radius: 10px; min-width: 360px; max-width: min(760px, 94vw); max-height: 90vh; display: flex; flex-direction: column; box-shadow: 0 12px 40px rgba(0,0,0,0.6); }
.modal-head { display: flex; align-items: center; justify-content: space-between; padding: 12px 16px; border-bottom: 1px solid var(--line); font-weight: 600; font-size: 14px; }
.modal-head button { background: none; border: none; font-size: 16px; }
.modal-body { padding: 14px 16px; overflow-y: auto; }
.modal-foot { display: flex; justify-content: flex-end; gap: 8px; padding: 10px 16px; border-top: 1px solid var(--line); }
.modal .row > label { min-width: 90px; }
.modal input[type=text], .modal input[type=password], .modal textarea, .modal select { width: 100%; }
.modal textarea { min-height: 80px; resize: vertical; }
.form-msg { color: var(--danger); min-height: 18px; font-size: 12px; }
.tabs { display: flex; gap: 4px; margin-bottom: 10px; }
.tabs button { flex: 1; }
.preview-box { background: repeating-conic-gradient(#666 0 25%, #999 0 50%) 0 0 / 12px 12px; border: 1px solid var(--line2); border-radius: var(--radius); display: flex; align-items: center; justify-content: center; min-height: 120px; max-height: 260px; overflow: hidden; }
.preview-box img, .preview-box canvas { max-width: 100%; max-height: 260px; object-fit: contain; }
.proj-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 10px; }
.proj-card { border: 1px solid var(--line2); border-radius: 8px; overflow: hidden; background: var(--panel2); cursor: pointer; display: flex; flex-direction: column; }
.proj-card:hover { border-color: var(--accent); }
.proj-card.current { outline: 2px solid var(--accent); }
.proj-card .pthumb { height: 110px; background: repeating-conic-gradient(#666 0 25%, #999 0 50%) 0 0 / 10px 10px; display: flex; align-items: center; justify-content: center; overflow: hidden; }
.proj-card .pthumb img { max-width: 100%; max-height: 100%; object-fit: contain; }
.proj-card .pinfo { padding: 6px 8px; font-size: 12px; }
.proj-card .pname { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.proj-card .pacts { display: flex; gap: 4px; padding: 0 8px 8px; }
.proj-card .pacts button { padding: 2px 6px; font-size: 11px; }
.help-table { width: 100%; border-collapse: collapse; font-size: 12px; }
.help-table td { padding: 3px 6px; border-bottom: 1px solid #222; vertical-align: top; }
.help-table td:first-child { white-space: nowrap; color: var(--muted); }

/* ---- 토스트 ---- */
#toasts { position: fixed; left: 50%; bottom: 40px; transform: translateX(-50%); display: flex; flex-direction: column; gap: 6px; z-index: 2000; pointer-events: none; }
.toast { background: #333842; color: #fff; padding: 8px 14px; border-radius: 6px; box-shadow: 0 4px 16px rgba(0,0,0,0.4); opacity: 0; transform: translateY(8px); transition: all 0.25s; font-size: 13px; max-width: 520px; }
.toast.show { opacity: 1; transform: none; }
.toast.error { background: #7a2f2b; }
.toast.success { background: #1f6b3a; }
.toast.warn { background: #6b5514; }

@media (max-width: 900px) {
  #sidebar { width: 250px; }
  #topbar .menu button { padding: 4px 6px; }
}
