/*
 * cubeBUILDER 화면에 맞춘 밝은 테마.
 * 색과 형태는 실제 INSTANCE EDITOR / Node Tree 를 보고 잡았다 — 같은 화면을 쓰던
 * 사람이 옮겨 왔을 때 다시 배우지 않아도 되게 하는 것이 목적이다.
 */
:root {
    --brand: #6b4ee6;
    --brand-dark: #5a3fd0;
    --bg-soft: #f7f6fb;
    --line: #e3e2ec;
    --line-soft: #eeedf4;
    --text: #2c2c38;
    --muted: #8b8a99;
    --req: #e0466b;
    --bad: #d93a5c;
    --good: #1f9e6e;

    /* 노드 트리 — 실제 화면의 두 색 */
    --target-bg: #fbe9f0;
    --target-line: #f2cddc;
    --cond-bg: #ddeef8;
    --cond-line: #c8dff0;

    --font: -apple-system, BlinkMacSystemFont, "Apple SD Gothic Neo", "Malgun Gothic", sans-serif;
    --mono: "SFMono-Regular", Menlo, Consolas, monospace;
}

* { box-sizing: border-box; }

body {
    margin: 0;
    display: flex;
    flex-direction: column;
    height: 100vh;
    overflow: hidden;
    background: #fff;
    color: var(--text);
    font-family: var(--font);
    font-size: 13px;
}

/* ---------------------------------------------------------------- 공통 */

input, select, textarea, button {
    font-family: inherit;
    font-size: 12.5px;
    color: var(--text);
    background: #fff;
    border: 1px solid var(--line);
    border-radius: 3px;
    padding: 4px 8px;
}
input:focus, select:focus, textarea:focus {
    outline: none;
    border-color: var(--brand);
    box-shadow: 0 0 0 2px rgba(107, 78, 230, .12);
}
input::placeholder, textarea::placeholder { color: #b6b5c2; }
textarea { width: 100%; resize: vertical; line-height: 1.5; }

.btn { cursor: pointer; }
.btn:hover { border-color: var(--brand); color: var(--brand); }
.btn:disabled { opacity: .45; cursor: default; }
.btn-primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn-primary:hover { background: var(--brand-dark); border-color: var(--brand-dark); color: #fff; }
.btn-primary:disabled:hover { background: var(--brand); }

.row { display: flex; align-items: center; gap: 8px; }
.hidden { display: none !important; }
.status { font-size: 12px; color: var(--muted); }
.status.bad { color: var(--bad); }
.status.good { color: var(--good); }
.hint {
    margin-left: 3px; padding: 0 4px; border-radius: 3px;
    background: var(--line-soft); color: var(--muted); font-size: 10px;
}

/* ---------------------------------------------------------------- 상단바 */

.topbar {
    display: flex; align-items: center; gap: 14px;
    padding: 0 16px; height: 42px;
    border-bottom: 1px solid var(--line);
}
.brand { font-size: 15px; color: var(--brand); letter-spacing: -.2px; }
.brand b { font-weight: 800; }
.brand i {
    margin-left: 6px; padding: 1px 5px; border-radius: 3px;
    background: var(--brand); color: #fff; font-size: 10px; font-style: normal;
    vertical-align: 2px; letter-spacing: .5px;
}
.crumb { color: var(--muted); font-size: 12px; }
.spacer { margin-left: auto; }

.pill { padding: 2px 9px; border-radius: 999px; font-size: 11px; }
.pill-on  { background: #e7f6f0; color: var(--good); }
.pill-off { background: #f0eff5; color: var(--muted); }

.icon-btn {
    display: flex; align-items: center; justify-content: center;
    width: 27px; height: 23px; padding: 0; color: var(--muted); cursor: pointer;
}
.icon-btn:hover, .icon-btn.is-on { color: var(--brand); border-color: var(--brand); }
.icon-btn.is-on { background: rgba(107, 78, 230, .08); }
.icon-btn svg { fill: none; stroke: currentColor; stroke-width: 1.3; stroke-linejoin: round; }

/* ---------------------------------------------------------------- 워크플로우 */

/*
 * 상단바에서 내려오는 시트. 단계를 순서대로 늘어놓고 각 단계의 지금 상태를 함께 적는다.
 * 화면 위에 덮되 상단바는 가리지 않는다 — 여는 버튼이 거기 있다.
 */
.flow-back { position: fixed; inset: 42px 0 0; z-index: 30; background: rgba(30, 28, 50, .28); }
.flow-sheet {
    position: fixed; top: 42px; left: 0; right: 0; z-index: 31;
    max-height: calc(100vh - 42px); overflow: auto;
    background: #fff; border-bottom: 1px solid var(--line);
    box-shadow: 0 12px 28px rgba(30, 28, 50, .16);
}
.flow-head { display: flex; align-items: center; gap: 10px; padding: 12px 16px 0; }
.flow-head h2 { margin: 0; font-size: 13px; font-weight: 700; }
.flow-sub { color: var(--muted); font-size: 12px; }
.flow-body { display: flex; flex-direction: column; gap: 10px; padding: 10px 16px 16px; }
.flow-h { font-size: 11px; font-weight: 600; color: var(--muted); margin-top: 2px; }

.flow-chain { display: flex; align-items: stretch; flex-wrap: wrap; gap: 6px; }
.flow-arrow { display: flex; align-items: center; color: #c3c2d1; font-size: 13px; }

.flow-step {
    flex: 1 1 200px; min-width: 190px;
    display: flex; flex-direction: column; gap: 3px;
    padding: 9px 11px 10px; text-align: left; cursor: pointer;
    border: 1px solid var(--line); border-radius: 4px; background: #fff;
}
.flow-step:hover { border-color: var(--brand); }
.flow-top { display: flex; align-items: center; gap: 6px; }
.flow-n {
    flex: none; width: 18px; height: 18px; border-radius: 50%;
    display: inline-flex; align-items: center; justify-content: center;
    background: var(--line-soft); color: var(--muted); font-size: 10.5px; font-weight: 700;
}
/* 갈래는 순서가 없으므로 번호 대신 표시만 단다. 작은 글자에서 뭉개지지 않게 조금 키운다. */
.flow-n.branch { font-size: 12px; font-weight: 400; }
.flow-t { font-size: 12.5px; font-weight: 600; }
.flow-d { font-size: 11.5px; line-height: 1.5; }
.flow-w { font-family: var(--mono); font-size: 10.5px; color: var(--muted); }
.flow-s { margin-top: 3px; font-size: 11px; color: var(--muted); }

.flow-step.is-done .flow-n { background: #e7f6f0; color: var(--good); }
.flow-step.is-done .flow-s { color: var(--good); }
.flow-step.is-bad { background: #fdf2f4; border-color: #f2ccd6; }
.flow-step.is-bad .flow-n { background: #fbe1e7; color: var(--bad); }
.flow-step.is-bad .flow-s { color: var(--bad); }
.flow-step.is-skip { border-style: dashed; }
.flow-step.is-skip .flow-d, .flow-step.is-skip .flow-t { color: var(--muted); }
/* 지금 할 일 — 걸려 있는 곳이 눈에 먼저 들어와야 한다. */
.flow-step.is-now { border-color: var(--brand); box-shadow: 0 0 0 2px rgba(107, 78, 230, .12); }
.flow-step.is-now .flow-n { background: var(--brand); color: #fff; }

.flow-note {
    padding: 8px 11px; font-size: 11.5px; line-height: 1.65; color: var(--muted);
    background: var(--bg-soft); border: 1px solid var(--line); border-radius: 3px;
}

/* ---------------------------------------------------------------- 폼 영역 */

.editor-head {
    background: var(--bg-soft);
    border-bottom: 1px solid var(--line);
    padding: 10px 16px 12px;
}
.section-title {
    margin: 0 0 8px;
    font-size: 12px; font-weight: 700; letter-spacing: .4px;
}
.form {
    display: grid;
    grid-template-columns: 96px minmax(0, 1fr);
    gap: 6px 12px;
    align-items: center;
}
/* 라벨은 오른쪽 정렬 — 실제 화면과 같다. */
.form-label { text-align: right; font-size: 12.5px; }
.form-label.req::before { content: '* '; color: var(--req); }
.form-field { display: flex; align-items: center; gap: 6px; min-width: 0; }
.form-field > input[type="text"] { flex: 1; min-width: 0; }
.form-field > select { min-width: 150px; }
#check-open { max-width: 220px; }

.items { display: flex; flex-wrap: wrap; gap: 5px; }
.chip {
    font-family: var(--mono); font-size: 11.5px;
    background: #fff; border: 1px solid var(--line);
    border-radius: 3px; padding: 2px 7px;
}
.chip .visit { color: var(--muted); }

/* ---------------------------------------------------------------- 본문 */

.layout {
    display: grid;
    grid-template-columns: minmax(300px, 360px) minmax(0, 1fr);
    gap: 1px;
    background: var(--line);
    flex: 1;
    min-height: 0;
}
@media (max-width: 1100px) {
    .layout { grid-template-columns: 260px minmax(0, 1fr); }
}

.pane {
    background: #fff;
    padding: 10px 14px 12px;
    overflow: auto;
    display: flex; flex-direction: column; gap: 8px;
    min-width: 0;
}
.pane-title {
    margin: 0; font-size: 11px; font-weight: 700;
    letter-spacing: .5px; text-transform: uppercase; color: var(--muted);
}
.pane-title .sub { text-transform: none; font-weight: 400; }
.pane h4 { margin: 6px 0 2px; font-size: 11px; color: var(--muted); font-weight: 600; }

#editor {
    flex: 1; min-height: 200px;
    border: 1px solid var(--line); border-radius: 3px; overflow: hidden;
}

.problems {
    background: #fdf2f4; border: 1px solid #f2ccd6; border-radius: 3px;
    padding: 6px 10px; color: var(--bad); font-size: 12px; line-height: 1.65;
    max-height: 120px; overflow: auto;
}

.result { background: var(--bg-soft); border: 1px solid var(--line); border-radius: 3px; padding: 8px 10px; }
.result p { margin: 0 0 6px; line-height: 1.6; }

.examples { margin-top: auto; }
.example {
    display: block; width: 100%; text-align: left; margin-bottom: 4px;
    color: var(--muted); font-size: 11.5px; line-height: 1.4; cursor: pointer;
}
.example:hover { color: var(--brand); border-color: var(--brand); }

/*
 * 자연어 칸은 눌리지 않는다.
 *
 * .pane 이 세로 flex 라 내용이 pane 높이를 넘으면 flex 가 이 칸부터 줄인다 — 프롬프트를
 * 펼치거나 창이 낮으면 한 줄도 안 남는 10px 까지 찌그러졌다. 넘치는 것은 pane 이
 * 스크롤로 감당하면 된다. min-height 는 손으로 끌어 줄일 때의 바닥이기도 하다.
 */
#nl { flex: none; min-height: 66px; }

.prompt-box { display: flex; flex-direction: column; gap: 5px; flex: none; }
.prompt-box textarea {
    font-family: var(--mono); font-size: 11px; line-height: 1.5;
    height: 260px; white-space: pre; overflow-wrap: normal; overflow-x: auto;
}

/* ---------------------------------------------------------------- 하단 도크 */

.dock {
    position: relative;
    border-top: 1px solid var(--line);
    background: #fff;
    display: flex; flex-direction: column;
    height: var(--dock-height, 42vh);
    min-height: 34px;
}
.dock.collapsed { height: auto; }

.dock-resize {
    position: absolute; top: -3px; left: 0; right: 0; height: 7px;
    cursor: ns-resize; z-index: 5;
}
.dock-resize:hover, .dock-resize.dragging { background: var(--brand); opacity: .35; }
body.resizing { cursor: ns-resize; user-select: none; }
body.resizing .monaco-editor { pointer-events: none; }

.dock-bar {
    display: flex; align-items: center; gap: 10px;
    padding: 0 14px; height: 34px;
    border-bottom: 1px solid var(--line);
    background: var(--bg-soft);
}
.dock-bar .btn { padding: 2px 8px; font-size: 11px; }
.dock-bar #dvs-toggle { margin-left: auto; }
.dock-tools { display: flex; align-items: center; gap: 9px; }
.check { display: flex; align-items: center; gap: 5px; font-size: 11.5px; color: var(--muted); cursor: pointer; }
.check input { accent-color: var(--brand); margin: 0; }

.tabs { display: flex; align-self: stretch; }
.tab {
    padding: 0 14px; border: none; border-bottom: 2px solid transparent;
    background: none; color: var(--muted); font-size: 12px; cursor: pointer; border-radius: 0;
}
.tab:hover { color: var(--text); }
.tab.is-on { color: var(--brand); border-bottom-color: var(--brand); font-weight: 600; }

.panel-body { overflow: auto; flex: 1; min-height: 0; }
.panel-body.hidden { display: none; }

/* ---------------------------------------------------------------- Node Tree */

/*
 * 실제 화면은 노드마다 색 블록이 하나씩 떨어져 있고, ITEM 의 leaf 표가 그 블록 안에
 * 들어간다. 들여쓰기 자리는 색이 없는 여백이고 접기 화살표와 점만 거기 놓인다.
 * 그래서 셀에 배경을 바로 칠하지 않고, 블록을 따로 두고 아래쪽 흰 테두리로 간격을 만든다.
 * 미리보기 전용이라 값은 읽기만 한다.
 */
.nt { width: 100%; border-collapse: collapse; font-size: 12px; }
.nt thead th {
    position: sticky; top: 0; z-index: 2;
    background: #f4f3f8;
    text-align: left; font-weight: 500;
    padding: 8px 10px;
    border-bottom: 1px solid var(--line);
    white-space: nowrap;
}
.nt-c-node  { width: 34%; }
.nt-c-act   { width: 92px; }
.nt-c-id    { width: 160px; }
.nt-c-root  { width: 160px; }
.nt-c-const { width: 180px; }
.nt-c-code  { width: 150px; }
.nt-c-del   { width: 68px; text-align: center !important; }

/*
 * 위아래 흰 여백은 셀의 padding 으로 만들고 색은 안쪽 요소에만 칠한다.
 * 셀에 바로 칠하면 Node 칸(안쪽 블록에만 칠한다)과 어긋나서 오른쪽만 띠처럼 이어진다.
 */
.nt tbody td { padding: 3px 0; vertical-align: middle; }
/* leaf 표는 같은 블록이라 노드 줄과 붙어 있어야 한다. */
.nt tbody tr.with-leaf > td { padding-bottom: 0; }
.nt tbody tr.nt-leaf > td { padding-top: 0; }

/*
 * 칸마다 높이를 같게 못박는다. 내용(글자 / input / select)이 저마다 높이가 달라
 * 그대로 두면 색 블록의 위아래 선이 칸마다 어긋나 톱니처럼 보인다.
 * box-sizing 이 border-box 라 이 값에 패딩이 포함된다.
 */
.cellbg, .nt-block { height: 36px; padding: 6px 10px; display: flex; align-items: center; }
.nt .cellbg > input[type="text"], .nt .cellbg > select { height: 24px; }
tr.cond   .cellbg, tr.cond   .nt-block { background: var(--cond-bg); }
tr.target .cellbg, tr.target .nt-block { background: var(--target-bg); }
tr.created .nt-block { box-shadow: inset 3px 0 0 var(--good); }

.nt-line { display: flex; align-items: stretch; }
/* 들여쓰기 자리 — 색이 없다. 접기 화살표와 점이 여기 오른쪽 끝에 붙는다. */
.nt-gutter {
    flex: none; display: flex; align-items: center; justify-content: flex-end;
    gap: 6px; padding-right: 6px;
}
.nt-caret {
    width: 14px; text-align: center; color: #9a99a8;
    cursor: pointer; user-select: none; font-size: 10px;
}
.nt-caret.leaf { visibility: hidden; }
.nt-dot {
    width: 13px; height: 13px; border-radius: 50%; flex: none;
    background: #d7e7f4; border: 1px solid #a9cbe6;
}
tr.target .nt-dot { background: #f7dbe6; border-color: #e8b6cb; }

.nt-block { flex: 1; min-width: 0; gap: 8px; border-radius: 3px 0 0 3px; }
.nt-grip { color: #b9b8c6; cursor: grab; font-size: 11px; letter-spacing: -1px; }
.nt-type { color: var(--brand); text-decoration: underline; font-weight: 600; cursor: pointer; }
.nt-path { white-space: nowrap; color: var(--text); }

.nt-act { display: flex; gap: 9px; color: #8f8ea0; }
.nt-act span { cursor: pointer; font-size: 12px; }
.nt-act span:hover { color: var(--brand); }

.cellbg > input[type="text"], .cellbg > select { width: 100%; background: #fff; }
.cellbg > input[readonly] { color: var(--muted); }
.cellbg > select:disabled { color: var(--muted); background: #fff; }
.nt-del { text-align: center; }

/* Leaf Item 서브테이블 — 같은 색 블록 안에 들어간다. */
.nt-leaf .cellbg { height: auto; padding: 0 10px 9px; display: block; }
.leaf {
    width: 100%; border-collapse: collapse; background: #fff;
    border: 1px solid #dcdbe6; font-size: 11.5px;
}
.leaf th {
    text-align: left; font-weight: 500; color: var(--text);
    padding: 6px 8px; white-space: nowrap;
}
.leaf th.req::before { content: '* '; color: var(--req); }
.leaf td { padding: 0 8px 7px; }
.leaf input { width: 100%; padding: 3px 7px; font-size: 11.5px; color: var(--text); }
.leaf .no { color: var(--text); padding-left: 14px; padding-bottom: 7px; }

.nt-empty { padding: 20px; color: var(--muted); text-align: center; }

.merge {
    margin: 10px 14px 4px;
    border-radius: 3px; padding: 7px 10px; font-size: 12px; line-height: 1.65;
    background: #fdf2f4; border: 1px solid #f2ccd6; color: var(--bad);
}
.merge.info { background: var(--bg-soft); border-color: var(--line); color: var(--muted); }

/* ---------------------------------------------------------------- DvsNode 뷰어 */

.dvs-json {
    margin: 0; padding: 8px 14px 12px; overflow: auto;
    font-family: var(--mono); font-size: 11.5px; line-height: 1.7; white-space: pre-wrap;
}
.dvs-json .k { color: var(--brand); }
.dvs-json .s { color: #1a7f5a; }
.dvs-json .n { color: #b26b00; }
.dvs-json .b { color: #9b51e0; }
.dvs-json .muted { color: var(--muted); }
.dvs-json details { border-left: 1px solid var(--line-soft); }
.dvs-json summary { cursor: pointer; list-style: none; padding-left: 4px; border-radius: 3px; }
.dvs-json summary::-webkit-details-marker { display: none; }
.dvs-json summary:hover { background: rgba(107, 78, 230, .06); }
.dvs-json summary::before { content: '▾'; display: inline-block; width: 12px; color: var(--muted); }
.dvs-json details:not([open]) > summary::before { content: '▸'; }
.dvs-json .body { padding-left: 14px; }
.dvs-json .row { padding-left: 16px; display: block; }
.dvs-json .label {
    margin-left: 8px; padding: 0 5px; border-radius: 3px;
    background: var(--line-soft); color: var(--muted); font-size: 10.5px;
}
.dvs-json .name { color: #1a7f5a; font-weight: 600; }
.dvs-json .tag { margin-left: 6px; color: var(--muted); font-size: 10.5px; }

/* ---------------------------------------------------------------- 테스트 */

.test-grid {
    display: grid;
    grid-template-columns: minmax(280px, 420px) minmax(0, 1fr);
    gap: 20px; padding: 10px 14px 14px; align-items: start;
}
.test-grid h4 { margin: 0 0 6px; font-size: 11px; color: var(--muted); font-weight: 600; }
.test-inputs { display: flex; flex-direction: column; gap: 4px; margin-bottom: 8px; }
.test-input { display: grid; grid-template-columns: 110px 1fr 92px; gap: 6px; align-items: center; }
.test-input .name { font-family: var(--mono); font-size: 11.5px; color: #1a7f5a; }
.test-input .name small { color: var(--muted); }
.test-input input:disabled { background: #f6f6fa; color: #b6b5c2; }
.test-empty { color: var(--muted); font-size: 12px; }

.test-result { font-size: 12.5px; line-height: 1.7; }
.test-verdict { font-weight: 600; margin-bottom: 4px; }
.test-verdict.fired { color: var(--bad); }
.test-verdict.quiet { color: var(--good); }
.test-sub { margin: 10px 0 4px; font-size: 11px; color: var(--muted); font-weight: 600; }
.test-sub .muted { font-weight: 400; }

/* 판정 바로 아래 — 실제로 나갈 문장. 여기가 이 화면에서 확인할 것이다. */
.test-query {
    margin-top: 6px;
    background: #fdf2f4; border: 1px solid #f2ccd6;
    border-left: 3px solid var(--bad);
    border-radius: 3px; padding: 8px 12px;
}
.test-query.quiet { background: var(--bg-soft); border-color: var(--line); border-left-color: #c9c8d6; }
.test-query-label { font-size: 11px; color: var(--muted); font-weight: 600; margin-bottom: 3px; }
.test-query-label .muted { font-weight: 400; }
.test-query-text { font-size: 13px; line-height: 1.6; }
.test-query.quiet .test-query-text { color: var(--muted); }
.test-origin { margin-top: 6px; font-size: 11px; color: var(--muted); }
.test-origin code {
    font-family: var(--mono); font-size: 11px;
    background: #fff; border: 1px solid var(--line); border-radius: 2px; padding: 1px 5px;
}
.test-note {
    margin-top: 6px; padding: 7px 10px; font-size: 12px; color: var(--muted);
    background: var(--bg-soft); border: 1px solid var(--line); border-radius: 3px;
}
/* 실행 결과 — Node Tree 와 같은 표를 쓴다. 값 칸만 더한다. */
.nt.trace { margin-top: 2px; }
.nt.trace thead th { background: #f4f3f8; }
.nt.trace tr.is-null .nt-block,
.nt.trace tr.is-null .cellbg { background: #f4eefb; }
.nt.trace .v { font-family: var(--mono); color: #b26b00; }
.nt.trace .v-null { font-family: var(--mono); color: #9b51e0; }
.nt.trace .v-tag {
    margin-left: 6px; padding: 0 5px; border-radius: 3px;
    background: #ece0f8; color: #7b3fbe; font-size: 10px;
}
.nt.trace .cellbg b { font-family: var(--mono); font-weight: 600; }
