.lab {
    max-width: 1280px;
    margin: 0 auto;
    padding: 24px;
    font-family: "Inter", -apple-system, BlinkMacSystemFont, sans-serif;
}

.top-nav {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 13px;
    color: #64748b;
    margin-bottom: 16px;
}

.top-nav .nav-back,
.top-nav .nav-link {
    color: #2563eb;
    text-decoration: none;
}

.top-nav .nav-divider {
    color: #cbd5e1;
}

.top-nav .nav-current {
    color: #0f172a;
    font-weight: 500;
}

.lab-header h1 {
    margin: 0 0 4px 0;
    font-size: 24px;
}

.lab-header .subtitle {
    margin: 0 0 24px 0;
    color: #64748b;
}

.compare-table-wrap {
    margin-bottom: 24px;
    overflow-x: auto;
}

.compare-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 13px;
    background: #fff;
    border: 1px solid #e2e8f0;
    border-radius: 8px;
    overflow: hidden;
}

.compare-table th,
.compare-table td {
    padding: 10px 14px;
    text-align: left;
    border-bottom: 1px solid #f1f5f9;
}

.compare-table thead {
    background: #f8fafc;
    font-weight: 600;
}

.compare-table tr:last-child td {
    border-bottom: none;
}

.editor-tabs {
    background: #fff;
    border: 1px solid #e2e8f0;
    border-radius: 8px;
    overflow: hidden;
}

.tab-buttons {
    display: flex;
    border-bottom: 1px solid #e2e8f0;
    background: #f8fafc;
}

.tab-btn {
    padding: 12px 20px;
    border: none;
    background: transparent;
    font-size: 14px;
    font-weight: 500;
    color: #64748b;
    cursor: pointer;
    border-bottom: 2px solid transparent;
    transition: all 0.15s;
}

.tab-btn:hover {
    color: #0f172a;
    background: #fff;
}

.tab-btn.active {
    color: #2563eb;
    border-bottom-color: #2563eb;
    background: #fff;
}

.tab-body {
    display: grid;
    grid-template-columns: 1fr 320px;
    gap: 24px;
    padding: 20px;
}

.shared-panel {
    grid-column: 1 / -1;
    display: grid;
    grid-template-columns: 1fr auto;
    gap: 16px;
    align-items: end;
    padding-bottom: 16px;
    border-bottom: 1px solid #f1f5f9;
    margin-bottom: 16px;
}

.shared-text label {
    display: block;
    font-size: 12px;
    color: #64748b;
    margin-bottom: 4px;
    font-weight: 500;
}

.code-block {
    margin: 0;
    padding: 10px 12px;
    background: #0f172a;
    color: #e2e8f0;
    border-radius: 6px;
    font-family: "JetBrains Mono", "SF Mono", Monaco, Menlo, monospace;
    font-size: 13px;
    white-space: pre-wrap;
    word-break: break-all;
    min-height: 36px;
}

.shared-actions {
    display: flex;
    gap: 8px;
}

.btn {
    padding: 8px 14px;
    border: 1px solid #cbd5e1;
    background: #fff;
    border-radius: 6px;
    font-size: 13px;
    cursor: pointer;
    transition: all 0.15s;
}

.btn:hover {
    background: #f8fafc;
}

.btn-secondary {
    background: #fff;
}

.editor-hosts {
    display: flex;
    flex-direction: column;
}

.editor-host.hidden {
    display: none;
}

.editor-host.visible {
    display: block;
}

.editor-host h3 {
    margin: 0 0 10px 0;
    font-size: 15px;
    font-weight: 600;
}

.editor-note {
    margin: 10px 0 0 0;
    padding: 10px 12px;
    background: #f8fafc;
    border-left: 3px solid #cbd5e1;
    border-radius: 4px;
    font-size: 12px;
    color: #475569;
    line-height: 1.6;
}

/* ============= A. ContentEditable ============= */
.ce-editor {
    min-height: 120px;
    padding: 10px 12px;
    border: 1px solid #d4d4d8;
    border-radius: 6px;
    font-family: "JetBrains Mono", "SF Mono", Monaco, Menlo, monospace;
    font-size: 14px;
    background: #fff;
    white-space: pre-wrap;
    word-break: break-word;
    line-height: 1.6;
}

.ce-editor.ce-root:focus {
    outline: 2px solid #2563eb;
    outline-offset: -1px;
    border-color: transparent;
}

.ce-chip {
    display: inline;
    padding: 1px 6px;
    border-radius: 4px;
    font-weight: 500;
}

.ce-chip-var {
    background: #faf5ff;
    color: #7e22ce;
    border: 1px solid #e9d5ff;
}

.ce-chip-sys {
    background: #fff7ed;
    color: #c2410c;
    border: 1px solid #fed7aa;
}

.ce-string {
    color: #047857;
}

.ce-number {
    color: #92400e;
    font-weight: 500;
}

.ce-keyword {
    color: #2563eb;
    font-weight: 600;
}

/* ===== ContentEditable autocomplete popup ===== */
.ce-autocomplete {
    position: absolute;
    z-index: 9999;
    min-width: 280px;
    max-width: 420px;
    max-height: 260px;
    overflow-y: auto;
    background: #fff;
    border: 1px solid #cbd5e1;
    border-radius: 6px;
    box-shadow: 0 10px 28px -6px rgba(15, 23, 42, 0.25), 0 4px 12px -4px rgba(15, 23, 42, 0.1);
    font-family: "JetBrains Mono", "SF Mono", Monaco, Menlo, monospace;
    font-size: 13px;
    padding: 4px;
}

.ce-ac-item {
    display: grid;
    grid-template-columns: 1fr auto;
    grid-column-gap: 8px;
    padding: 6px 10px;
    border-radius: 4px;
    cursor: pointer;
    line-height: 1.4;
}

.ce-ac-item:hover {
    background: #f1f5f9;
}

.ce-ac-item.selected {
    background: #e0e7ff;
    outline: 1px solid #6366f1;
}

.ce-ac-label {
    grid-row: 1;
    grid-column: 1;
    font-weight: 600;
    color: #0f172a;
}

.ce-ac-var .ce-ac-label { color: #7e22ce; }
.ce-ac-sys .ce-ac-label { color: #c2410c; }
.ce-ac-kw  .ce-ac-label { color: #2563eb; }

.ce-ac-detail {
    grid-row: 1;
    grid-column: 2;
    font-size: 11px;
    color: #64748b;
    font-family: "Inter", sans-serif;
    padding: 1px 6px;
    background: #f1f5f9;
    border-radius: 3px;
    align-self: center;
}

.ce-ac-hint {
    grid-row: 2;
    grid-column: 1 / -1;
    font-size: 11px;
    color: #64748b;
    font-family: "Inter", sans-serif;
    margin-top: 2px;
}

/* nested hierarchy path: parent 색은 흐리게, leaf 는 원래 색 */
.ce-ac-parent { color: #94a3b8; font-weight: 400; }
.ce-ac-leaf { font-weight: 600; }
.ce-ac-chevron {
    position: absolute;
    margin-left: -14px;
    color: #94a3b8;
    font-size: 11px;
}
.ce-ac-item { position: relative; }

/* ============= B. CodeMirror ============= */
.cm-editor-host {
    min-height: 120px;
}

.cm-var-chip {
    background: #faf5ff;
    color: #7e22ce;
    border: 1px solid #e9d5ff;
    border-radius: 4px;
    padding: 1px 4px;
    font-weight: 500;
}

.cm-sys-chip {
    background: #fff7ed;
    color: #c2410c;
    border: 1px solid #fed7aa;
    border-radius: 4px;
    padding: 1px 4px;
    font-weight: 500;
}

/* ============= C. Monaco ============= */
.mn-editor-host {
    height: 180px;
    border: 1px solid #d4d4d8;
    border-radius: 6px;
    overflow: hidden;
}

/* ============= D. TipTap ============= */
.tt-editor-host {
    min-height: 120px;
    padding: 10px 12px;
    border: 1px solid #d4d4d8;
    border-radius: 6px;
    background: #fff;
    font-family: "JetBrains Mono", "SF Mono", Monaco, Menlo, monospace;
    font-size: 14px;
}

.tt-root {
    outline: none;
    min-height: 100px;
    line-height: 1.6;
}

.tt-root p {
    margin: 0;
}

.tt-chip {
    display: inline-block;
    padding: 2px 8px;
    border-radius: 10px;
    font-weight: 500;
    font-size: 13px;
    margin: 0 1px;
    cursor: pointer;
    user-select: none;
}

.tt-chip.ProseMirror-selectednode {
    box-shadow: 0 0 0 2px #2563eb;
}

.tt-chip-var {
    background: #faf5ff;
    color: #7e22ce;
    border: 1px solid #d8b4fe;
}

.tt-chip-sys {
    background: #fff7ed;
    color: #c2410c;
    border: 1px solid #fdba74;
}

/* ============= Vars panel ============= */
.vars-panel {
    border-left: 1px solid #f1f5f9;
    padding-left: 20px;
}

.vars-panel h4 {
    margin: 0 0 10px 0;
    font-size: 14px;
    font-weight: 600;
}

.vars-group-label {
    font-size: 11px;
    color: #64748b;
    font-weight: 500;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    margin: 16px 0 6px 0;
}

.vars-group-label:first-of-type {
    margin-top: 0;
}

.vars-list {
    list-style: none;
    padding: 0;
    margin: 0;
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.vars-list li {
    display: flex;
    align-items: center;
    gap: 8px;
}

.var-chip {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 3px 8px;
    border: 1px solid #e9d5ff;
    background: #faf5ff;
    color: #7e22ce;
    border-radius: 4px;
    font-family: "JetBrains Mono", "SF Mono", monospace;
    font-size: 12px;
    cursor: pointer;
}

.var-chip.sys {
    border-color: #fed7aa;
    background: #fff7ed;
    color: #c2410c;
}

.var-chip.rel {
    border-color: #cbd5e1;
    background: #f8fafc;
    color: #64748b;
    cursor: default;
    opacity: 0.75;
}

.var-chip.kw {
    border-color: #bfdbfe;
    background: #eff6ff;
    color: #1d4ed8;
    font-weight: 600;
}

.vars-hierarchy li {
    line-height: 1.4;
}

/* ====== Hierarchy tree (접이식) ====== */
.vars-tree {
    list-style: none;
    padding: 0;
    margin: 0;
    display: flex;
    flex-direction: column;
    gap: 1px;
}

.vars-tree .tree-row {
    display: block;
    padding: 1px 0;
}

.vars-tree .tree-toggle,
.vars-tree .tree-leaf {
    display: flex;
    width: 100%;
    align-items: center;
    gap: 6px;
    padding: 4px 8px;
    border: 1px solid transparent;
    background: transparent;
    border-radius: 4px;
    font-family: "JetBrains Mono", "SF Mono", Monaco, Menlo, monospace;
    font-size: 12px;
    cursor: pointer;
    text-align: left;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.vars-tree .tree-toggle:hover,
.vars-tree .tree-leaf:hover {
    background: #f1f5f9;
    border-color: #e2e8f0;
}

.vars-tree .tree-caret {
    display: inline-block;
    width: 12px;
    color: #64748b;
    font-size: 10px;
    flex-shrink: 0;
}

.vars-tree .tree-name {
    font-weight: 500;
    color: #0f172a;
    overflow: hidden;
    text-overflow: ellipsis;
}

.vars-tree .is-rel .tree-name {
    color: #475569;
}

.vars-tree .tree-type {
    margin-left: auto;
    font-size: 10px;
    color: #94a3b8;
    font-family: "Inter", sans-serif;
    padding: 1px 6px;
    background: #f1f5f9;
    border-radius: 3px;
    flex-shrink: 0;
}

.vars-tree .is-leaf .tree-leaf {
    color: #c2410c;
    padding-left: 20px;  /* caret 공간만큼 들여쓰기 (caret 없으므로) */
}

.vars-tree .is-leaf .tree-name {
    color: #c2410c;
}

.var-chip:hover {
    filter: brightness(0.97);
}

.var-chip .var-type {
    font-size: 10px;
    opacity: 0.7;
    padding: 1px 4px;
    background: rgba(255, 255, 255, 0.6);
    border-radius: 3px;
}

.var-hint {
    font-size: 11px;
    color: #94a3b8;
}

@media (max-width: 900px) {
    .tab-body {
        grid-template-columns: 1fr;
    }
    .vars-panel {
        border-left: none;
        border-top: 1px solid #f1f5f9;
        padding-left: 0;
        padding-top: 16px;
    }
}
