/**
 * Visual Template Builder CSS
 * 기존 webagent.css 패턴 따름
 */

/* Modal */
.builder-modal {
    display: none;
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(0,0,0,0.8);
    z-index: 10000;
    align-items: center;
    justify-content: center;
}

.builder-container {
    width: 95vw;
    height: 90vh;
    max-width: 1600px;
    background: #1a1a24;
    border-radius: 12px;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

/* Header */
.builder-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 20px;
    background: #12121a;
    border-bottom: 1px solid #2a2a3a;
}

.builder-header h3 {
    margin: 0;
    font-size: 16px;
    color: #fff;
    display: flex;
    align-items: center;
    gap: 8px;
}

.builder-phase {
    display: flex;
    gap: 4px;
}

.builder-phase .phase {
    padding: 4px 10px;
    font-size: 12px;
    color: #666;
    background: #2a2a3a;
    border-radius: 4px;
}

.builder-phase .phase.active {
    color: #fff;
    background: #22c55e;
}

.builder-header .btn-close {
    background: none;
    border: none;
    color: #888;
    font-size: 24px;
    cursor: pointer;
}

/* Body: 좌우 분할 */
.builder-body {
    flex: 1;
    display: flex;
    overflow: hidden;
}

/* 좌측: 브라우저 뷰 */
.builder-browser {
    flex: 1;
    display: flex;
    flex-direction: column;
    border-right: 1px solid #2a2a3a;
}

.browser-toolbar {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 12px;
    background: #12121a;
    border-bottom: 1px solid #2a2a3a;
}

.browser-toolbar .current-url {
    flex: 1;
    font-size: 12px;
    color: #888;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.browser-toolbar button {
    background: none;
    border: none;
    color: #888;
    cursor: pointer;
    padding: 4px;
}

.browser-toolbar button:hover {
    color: #fff;
}

.browser-viewport {
    flex: 1;
    overflow: auto;
    background: #0a0a0f;
    display: flex;
    align-items: center;
    justify-content: center;
}

.browser-viewport img {
    max-width: 100%;
    max-height: 100%;
    object-fit: contain;
}

.browser-viewport.inspector-mode {
    cursor: crosshair;
}

.browser-viewport.inspector-mode img {
    opacity: 0.9;
}

.viewport-placeholder {
    color: #666;
    font-size: 14px;
}

.selector-bar {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    padding: 10px 12px;
    background: #12121a;
    border-top: 1px solid #2a2a3a;
    min-height: 40px;
}

.sel-chip {
    padding: 4px 10px;
    font-size: 11px;
    border-radius: 4px;
    border: 1px solid;
}

/* 우측: 대화 */
.builder-chat {
    width: 400px;
    display: flex;
    flex-direction: column;
    background: #12121a;
}

.chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.chat-input {
    display: flex;
    gap: 8px;
    padding: 12px;
    border-top: 1px solid #2a2a3a;
}

.chat-input input {
    flex: 1;
    padding: 10px 14px;
    background: #1a1a24;
    border: 1px solid #2a2a3a;
    border-radius: 8px;
    color: #fff;
    font-size: 14px;
}

.chat-input button {
    padding: 10px 16px;
    background: #22c55e;
    border: none;
    border-radius: 8px;
    color: #000;
    cursor: pointer;
}

/* Messages */
.chat-msg {
    display: flex;
    gap: 10px;
    animation: fadeIn 0.2s;
}

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(5px); }
    to { opacity: 1; transform: translateY(0); }
}

.chat-msg .msg-icon {
    font-size: 16px;
    flex-shrink: 0;
}

.chat-msg .msg-content {
    flex: 1;
    font-size: 14px;
    line-height: 1.5;
    color: #e0e0e0;
}

.chat-msg.user .msg-content {
    background: #2a2a3a;
    padding: 8px 12px;
    border-radius: 8px;
    color: #fff;
}

.chat-msg.error .msg-content {
    color: #ef4444;
}

.chat-msg.success .msg-content {
    color: #22c55e;
}

.chat-msg .msg-content p {
    margin: 0 0 10px 0;
}

/* Choice buttons */
.choice-group {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.choice-btn {
    padding: 10px 16px;
    background: #1a1a24;
    border: 1px solid #2a2a3a;
    border-radius: 8px;
    color: #e0e0e0;
    cursor: pointer;
    font-size: 13px;
    transition: all 0.2s;
}

.choice-btn:hover:not(:disabled) {
    border-color: #22c55e;
}

.choice-btn.detected {
    border-color: #22c55e;
}

.choice-btn.detected .badge {
    margin-left: 6px;
    font-size: 10px;
    color: #22c55e;
}

.choice-btn.selected {
    background: #22c55e;
    color: #000;
    border-color: #22c55e;
}

.choice-btn:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}

/* Field checkboxes */
.field-list {
    display: flex;
    flex-direction: column;
    gap: 6px;
    margin-bottom: 12px;
}

.field-checkbox {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 12px;
    background: #1a1a24;
    border-radius: 6px;
    cursor: pointer;
    border-left: 3px solid #888;
}

.field-checkbox input {
    margin: 0;
}

.field-checkbox .field-name {
    flex: 1;
    font-weight: 500;
}

.field-checkbox .field-value {
    font-size: 12px;
    color: #888;
    max-width: 120px;
    overflow: hidden;
    text-overflow: ellipsis;
}

.field-checkbox .field-conf {
    font-size: 11px;
    color: #22c55e;
}

/* Candidate buttons */
.candidate-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.candidate-btn {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 12px;
    background: #1a1a24;
    border: 2px solid #2a2a3a;
    border-radius: 8px;
    cursor: pointer;
    text-align: left;
    color: #e0e0e0;
}

.candidate-btn:hover:not(:disabled) {
    background: #2a2a3a;
}

.candidate-btn.selected {
    border-width: 2px;
}

.candidate-btn:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}

.candidate-letter {
    width: 24px;
    height: 24px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 4px;
    font-weight: bold;
    font-size: 12px;
    color: #fff;
}

.candidate-btn code {
    flex: 1;
    font-size: 11px;
    color: #888;
    overflow: hidden;
    text-overflow: ellipsis;
}

.candidate-value {
    font-size: 12px;
    color: #22c55e;
}

/* Selector list */
.selector-list {
    display: flex;
    flex-direction: column;
    gap: 6px;
    margin-bottom: 12px;
}

.selector-row {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 12px;
    background: #1a1a24;
    border-radius: 6px;
    border-left: 3px solid #888;
}

.selector-row .sel-name {
    font-weight: 500;
    min-width: 80px;
}

.selector-row .sel-value {
    flex: 1;
    font-size: 11px;
    color: #888;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* Test result */
.result-data {
    background: #1a1a24;
    border-radius: 8px;
    padding: 12px;
    margin-bottom: 12px;
}

.result-row {
    display: flex;
    justify-content: space-between;
    padding: 6px 0;
    border-bottom: 1px solid #2a2a3a;
}

.result-row:last-child {
    border-bottom: none;
}

.result-key {
    font-weight: 500;
}

.result-val {
    color: #22c55e;
    max-width: 200px;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* Form */
.form-fields {
    display: flex;
    flex-direction: column;
    gap: 12px;
    margin-bottom: 12px;
}

.form-field label {
    display: block;
    font-size: 12px;
    color: #888;
    margin-bottom: 4px;
}

.form-field input,
.form-field textarea {
    width: 100%;
    padding: 10px 12px;
    background: #1a1a24;
    border: 1px solid #2a2a3a;
    border-radius: 6px;
    color: #fff;
    font-size: 14px;
}

.form-field textarea {
    resize: vertical;
}

/* Button group */
.btn-group {
    display: flex;
    gap: 8px;
}

.btn-group button {
    padding: 10px 20px;
    background: #2a2a3a;
    border: none;
    border-radius: 8px;
    color: #e0e0e0;
    cursor: pointer;
    font-size: 13px;
}

.btn-group button.primary {
    background: #22c55e;
    color: #000;
}

.btn-group button:hover:not(:disabled) {
    opacity: 0.9;
}

.btn-group button:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.submit-btn {
    width: 100%;
    padding: 12px;
    background: #22c55e;
    border: none;
    border-radius: 8px;
    color: #000;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
}

.submit-btn:disabled {
    background: #2a2a3a;
    color: #666;
    cursor: not-allowed;
}


/* ==========================================
   Template Builder V2 - 공통 CSS
   ========================================== */

/* 기본 변수 */
:root {
    --tb-bg: #1a1a24;
    --tb-bg-dark: #12121a;
    --tb-bg-darker: #0a0a0f;
    --tb-border: #2a2a3a;
    --tb-text: #e0e0e0;
    --tb-text-dim: #888;
    --tb-accent: #22c55e;
    --tb-danger: #dc3545;
}

/* 래퍼 - 기본 숨김 (popup에서만 표시) */
.tb-wrapper {
    display: none;
    flex-direction: column;
    width: 100%;
    height: 100%;
    background: var(--tb-bg);
    color: var(--tb-text);
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
}

/* popup-content 내부에서는 표시 */
.popup-content .tb-wrapper {
    display: flex;
}

/* 헤더 (탭) */
.tb-header {
    display: flex;
    align-items: center;
    padding: 8px 12px;
    background: var(--tb-bg-dark);
    border-bottom: 1px solid var(--tb-border);
}

.tb-tabs {
    display: flex;
    gap: 4px;
}

.tb-tab {
    padding: 8px 16px;
    border: none;
    background: transparent;
    border-radius: 6px;
    cursor: pointer;
    font-size: 0.9rem;
    color: var(--tb-text-dim);
    transition: all 0.2s;
    display: flex;
    align-items: center;
    gap: 6px;
}

.tb-tab:hover {
    background: var(--tb-border);
    color: var(--tb-text);
}

.tb-tab.active {
    background: var(--tb-accent);
    color: #000;
}

/* 뷰 */
.tb-view {
    flex: 1;
    display: none;  /* 기본 숨김 */
    flex-direction: column;
    overflow: hidden;
    min-height: 0; /* flex 자식 스크롤 허용 */
}

.tb-view.active {
    display: flex;
}

/* ==========================================
   공통 버튼
   ========================================== */
.tb-btn-primary {
    padding: 12px 20px;
    background: var(--tb-accent);
    border: none;
    border-radius: 8px;
    color: #000;
    font-size: 0.95rem;
    font-weight: 600;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    transition: opacity 0.2s;
}

.tb-btn-primary:hover {
    opacity: 0.9;
}

.tb-btn-secondary {
    padding: 10px 16px;
    background: var(--tb-border);
    border: none;
    border-radius: 6px;
    color: var(--tb-text);
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 6px;
}

.tb-btn-secondary:hover {
    background: var(--tb-surface);
}

/* Small 버튼 (헤더용) */
.tb-btn-sm-primary {
    padding: 6px 12px;
    background: var(--tb-accent);
    border: none;
    border-radius: 6px;
    color: #000;
    font-size: 0.8rem;
    font-weight: 600;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 4px;
    transition: opacity 0.2s;
}

.tb-btn-sm-primary:hover {
    opacity: 0.9;
}

.tb-btn-sm-secondary {
    padding: 6px 10px;
    background: transparent;
    border: 1px solid var(--tb-border);
    border-radius: 6px;
    color: var(--tb-text-dim);
    font-size: 0.8rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 4px;
    transition: all 0.2s;
}

.tb-btn-sm-secondary:hover {
    color: var(--tb-text);
    border-color: var(--tb-text-dim);
}

.tb-btn-danger {
    padding: 8px 14px;
    background: var(--tb-danger);
    border: none;
    border-radius: 6px;
    color: #fff;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 6px;
}

.tb-btn-danger-sm {
    padding: 8px 12px;
    background: transparent;
    border: 1px solid var(--tb-danger);
    border-radius: 6px;
    color: var(--tb-danger);
    cursor: pointer;
}

.tb-btn-icon {
    padding: 6px;
    background: transparent;
    border: none;
    color: var(--tb-text-dim);
    cursor: pointer;
    border-radius: 4px;
}

.tb-btn-icon:hover {
    color: var(--tb-text);
    background: var(--tb-border);
}

/* ==========================================
   공통 입력
   ========================================== */
.tb-input {
    padding: 12px 14px;
    background: var(--tb-bg-dark);
    border: 1px solid var(--tb-border);
    border-radius: 8px;
    color: var(--tb-text);
    font-size: 0.95rem;
}

.tb-input:focus {
    outline: none;
    border-color: var(--tb-accent);
}

.tb-input::placeholder {
    color: var(--tb-text-dim);
}

/* ==========================================
   분할 뷰 (스크립트/템플릿 공통)
   ========================================== */
.tb-split-view.active {
    display: flex;
    flex-direction: row;
    flex-wrap: wrap;
    min-height: 0; /* flex 자식 스크롤 허용 */
}

.tb-sidebar {
    width: 280px;
    display: flex;
    flex-direction: column;
    border-right: 1px solid var(--tb-border);
    background: var(--tb-bg-dark);
    min-height: 0; /* flex 자식 스크롤 허용 */
}

.sidebar-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 12px;
    border-bottom: 1px solid var(--tb-border);
    font-size: 0.9rem;
    font-weight: 600;
}

.sidebar-list {
    flex: 1;
    min-height: 0; /* flex 자식 스크롤 허용 */
    overflow-y: auto;
    padding: 8px;
}

.list-empty {
    text-align: center;
    padding: 20px;
    color: var(--tb-text-dim);
    font-size: 0.85rem;
}

.list-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 12px;
    border: 1px solid var(--tb-border);
    border-radius: 6px;
    margin-bottom: 6px;
    cursor: pointer;
    transition: all 0.2s;
}

.list-item:hover {
    background: var(--tb-border);
}

.list-item.active {
    border-color: var(--tb-accent);
    background: rgba(34, 197, 94, 0.1);
}

.list-item-main {
    flex: 1;
    min-width: 0;
}

.list-item-name {
    font-size: 0.85rem;
    font-weight: 500;
    margin-bottom: 4px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.list-item-meta {
    font-size: 0.75rem;
    color: var(--tb-text-dim);
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
}

/* 메타 정보 내 숫자 배지 */
.list-item-meta .meta-badge {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 2px 8px;
    background: var(--tb-bg);
    border-radius: 4px;
    font-variant-numeric: tabular-nums;
    min-width: 50px;
    justify-content: center;
}

.list-item-meta .meta-badge.action-count {
    min-width: 70px;
}

.list-item-date {
    color: var(--tb-text-dim);
    opacity: 0.7;
    font-size: 0.7rem;
    margin-left: auto;
}

/* 분석 상태 표시 */
.analysis-status {
    display: inline-flex;
    align-items: center;
    margin-left: auto;
}

.analysis-status.success i {
    color: var(--tb-accent, #22c55e);
}

.analysis-status.pending i {
    color: var(--tb-warning, #eab308);
    animation: spin 1s linear infinite;
}

.analysis-status.failed i {
    color: var(--tb-error, #ef4444);
}

@keyframes spin {
    from { transform: rotate(0deg); }
    to { transform: rotate(360deg); }
}

/* 목록 아이템 액션 버튼 */
.list-item-actions {
    display: flex;
    gap: 4px;
    opacity: 0;
    transition: opacity 0.2s;
    flex-shrink: 0;
}

.list-item:hover .list-item-actions {
    opacity: 1;
}

.list-action-btn {
    padding: 4px 6px;
    background: transparent;
    border: none;
    color: var(--tb-text-dim);
    cursor: pointer;
    border-radius: 4px;
    font-size: 0.9rem;
}

.list-action-btn:hover {
    background: var(--tb-bg);
    color: var(--tb-text);
}

.tb-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    min-height: 0; /* flex 자식 스크롤 허용 */
    height: 100%; /* 높이 제한 */
}

.content-empty {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    color: var(--tb-text-dim);
}

.content-empty i {
    font-size: 3rem;
    opacity: 0.3;
    margin-bottom: 12px;
}

.content-detail {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.detail-header {
    padding: 16px;
    border-bottom: 1px solid var(--tb-border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
}

.detail-header h3 {
    margin: 0;
    font-size: 1rem;
    font-weight: 600;
    flex: 1;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.detail-header-actions {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-shrink: 0;
}

.action-divider {
    width: 1px;
    height: 20px;
    background: var(--tb-border);
    margin: 0 4px;
}

.tb-btn-danger-icon {
    color: var(--tb-danger) !important;
}

.tb-btn-danger-icon:hover {
    background: rgba(239, 68, 68, 0.1);
}

.detail-body {
    flex: 1;
    padding: 16px;
    overflow-y: auto;
}

.detail-row {
    display: flex;
    justify-content: space-between;
    padding: 8px 0;
    border-bottom: 1px solid var(--tb-border);
}

.detail-row .label {
    color: var(--tb-text-dim);
    font-size: 0.85rem;
}

.detail-row .value {
    font-size: 0.85rem;
}

.detail-section {
    margin-top: 16px;
}

.detail-section h4 {
    margin: 0 0 10px 0;
    font-size: 0.9rem;
    color: var(--tb-text-dim);
}

.distribution-chart {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
}

.dist-tag {
    padding: 4px 10px;
    background: var(--tb-bg-dark);
    border-radius: 4px;
    font-size: 0.8rem;
    min-width: 60px;
    text-align: center;
    font-variant-numeric: tabular-nums;
}

.actions-preview {
    font-size: 0.8rem;
    font-family: monospace;
}

.detail-actions {
    padding: 12px 16px;
    border-top: 1px solid var(--tb-border);
    display: flex;
    gap: 8px;
}

/* ==========================================
   우측 로그 패널 (Right Side Panel)
   ========================================== */
.tb-with-log-panel {
    position: relative;
}

.tb-log-panel {
    position: absolute;
    top: 0;
    right: 0;
    width: 320px;
    height: 100%;
    background: var(--tb-bg);
    border-left: 1px solid var(--tb-border);
    display: flex;
    flex-direction: column;
    z-index: 100;
    transition: transform 0.25s ease;
}

.tb-log-panel.collapsed {
    transform: translateX(100%);
}

.log-panel-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 16px;
    background: var(--tb-bg-dark);
    border-bottom: 1px solid var(--tb-border);
    font-size: 0.9rem;
    font-weight: 600;
    color: var(--tb-text);
}

.log-panel-header i {
    margin-right: 8px;
    color: var(--tb-accent);
}

.log-panel-body {
    flex: 1;
    overflow-y: auto;
    padding: 12px;
    background: var(--tb-bg-darker);
    font-size: 0.8rem;
    font-family: 'Consolas', 'Monaco', monospace;
}

.log-panel-footer {
    padding: 8px 12px;
    background: var(--tb-bg-dark);
    border-top: 1px solid var(--tb-border);
    display: flex;
    justify-content: flex-end;
}

/* 로그 토글 버튼 (우측 고정 - 채팅 입력 위) */
.tb-log-toggle-btn {
    position: absolute;
    bottom: 80px;
    right: 20px;
    width: 44px;
    height: 44px;
    border-radius: 50%;
    background: var(--tb-accent);
    color: #000;
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.2rem;
    box-shadow: 0 2px 8px rgba(0,0,0,0.3);
    z-index: 99;
    transition: opacity 0.2s, transform 0.2s;
}

.tb-log-toggle-btn:hover {
    transform: scale(1.1);
}

.tb-log-toggle-btn.hidden {
    opacity: 0;
    pointer-events: none;
}

/* 로그 메시지 스타일 */
.log-entry {
    padding: 4px 0;
    border-bottom: 1px solid var(--tb-border);
    line-height: 1.4;
}

.log-entry:last-child {
    border-bottom: none;
}

.log-entry.log-info {
    color: var(--tb-text);
}

.log-entry.log-success {
    color: var(--tb-accent);
}

.log-entry.log-warning {
    color: #f59e0b;
}

.log-entry.log-error {
    color: var(--tb-danger);
}

.log-entry .log-time {
    color: var(--tb-text-dim);
    margin-right: 8px;
    font-size: 0.75rem;
}

/* ==========================================
   오버레이
   ========================================== */
.tb-overlay {
    position: absolute;
    inset: 0;
    background: rgba(10, 10, 15, 0.95);
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 100;
}

.tb-overlay.active {
    display: flex;
}

.overlay-content {
    text-align: center;
    padding: 40px;
}

.overlay-spinner {
    width: 60px;
    height: 60px;
    border: 4px solid var(--tb-border);
    border-top-color: var(--tb-accent);
    border-radius: 50%;
    margin: 0 auto 20px;
    animation: spin 1s linear infinite;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

.overlay-content h3 {
    color: var(--tb-accent);
    margin: 0 0 8px 0;
}

.overlay-progress {
    width: 200px;
    height: 8px;
    background: var(--tb-border);
    border-radius: 4px;
    margin: 16px auto 8px;
    overflow: hidden;
}

.overlay-progress .progress-bar {
    height: 100%;
    background: var(--tb-accent);
    width: 0%;
    transition: width 0.3s;
}

.progress-text {
    color: var(--tb-accent);
    font-weight: 600;
}

/* ==========================================
   다이얼로그
   ========================================== */
.tb-dialog {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.7);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 10000;
}

.dialog-content {
    background: var(--tb-bg);
    border-radius: 12px;
    width: 360px;
    max-width: 90%;
    border: 1px solid var(--tb-border);
}

.dialog-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 14px 16px;
    border-bottom: 1px solid var(--tb-border);
}

.dialog-header h4 {
    margin: 0;
    font-size: 1rem;
}

.dialog-body {
    padding: 16px;
}

.dialog-body label {
    display: block;
    font-size: 0.85rem;
    color: var(--tb-text-dim);
    margin-bottom: 6px;
}

.dialog-body input,
.dialog-body select {
    width: 100%;
    padding: 10px 12px;
    background: var(--tb-bg-dark);
    border: 1px solid var(--tb-border);
    border-radius: 6px;
    color: var(--tb-text);
    margin-bottom: 12px;
}

.dialog-footer {
    display: flex;
    justify-content: flex-end;
    gap: 8px;
    padding: 12px 16px;
    border-top: 1px solid var(--tb-border);
}

/* 미리보기 요약 */
.preview-summary {
    display: flex;
    flex-wrap: wrap;
    gap: 12px;
    padding: 10px 16px;
    background: var(--tb-bg-dark);
    border-bottom: 1px solid var(--tb-border);
    font-size: 0.8rem;
}

.preview-summary .summary-item {
    color: var(--tb-text-dim);
}

.preview-summary .summary-item strong {
    color: var(--tb-text);
    margin-right: 4px;
}

/* ==========================================
   분석 대화 패널
   ========================================== */
.analysis-chat-panel {
    flex: 1;
    display: flex;
    flex-direction: column;
    background: var(--tb-bg);
    overflow: hidden;
    min-height: 0; /* flex 자식 스크롤 허용 */
    height: 100%; /* 부모 높이 채우기 */
}

.chat-panel-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 16px;
    background: var(--tb-bg-dark);
    border-bottom: 1px solid var(--tb-border);
}

.chat-panel-title {
    display: flex;
    align-items: center;
    gap: 8px;
    font-weight: 600;
    color: var(--tb-accent);
}

.chat-panel-title i {
    font-size: 1.1rem;
}

.chat-panel-actions {
    display: flex;
    align-items: center;
    gap: 8px;
}

/* 분석 요약 */
.chat-analysis-summary {
    padding: 12px 16px;
    background: var(--tb-bg-dark);
    border-bottom: 1px solid var(--tb-border);
}

.summary-header {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 10px;
    font-size: 0.9rem;
    color: var(--tb-text);
}

.summary-header i {
    color: var(--tb-accent);
}

.summary-stats {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.summary-stats .stat-badge {
    padding: 4px 12px;
    background: var(--tb-bg);
    border-radius: 4px;
    font-size: 0.8rem;
    color: var(--tb-text-dim);
    min-width: 70px;
    text-align: center;
    font-variant-numeric: tabular-nums;
}

.summary-stats .stat-badge strong {
    color: var(--tb-text);
    margin-right: 4px;
}

.summary-stats .stat-badge.status-pending {
    background: rgba(255, 193, 7, 0.2);
    color: #ffc107;
}

.summary-stats .stat-badge.status-done {
    background: rgba(34, 197, 94, 0.2);
    color: #22c55e;
}

/* 검증 오류 */
.chat-validation-errors {
    padding: 12px 16px;
    background: rgba(220, 53, 69, 0.1);
    border-bottom: 1px solid var(--tb-danger);
}

.errors-header {
    display: flex;
    align-items: center;
    gap: 8px;
    color: var(--tb-danger);
    font-weight: 600;
    margin-bottom: 10px;
}

.errors-list {
    display: flex;
    flex-direction: column;
    gap: 6px;
    margin-bottom: 12px;
}

.error-item {
    display: flex;
    align-items: flex-start;
    gap: 8px;
    padding: 8px 12px;
    background: rgba(220, 53, 69, 0.05);
    border-radius: 6px;
    font-size: 0.85rem;
    border-left: 3px solid var(--tb-danger);
}

.error-item i {
    color: var(--tb-danger);
    margin-top: 2px;
}

.error-item .error-text {
    flex: 1;
    color: var(--tb-text);
}

.errors-actions {
    display: flex;
    gap: 8px;
}

.tb-btn-accent {
    padding: 8px 16px;
    background: var(--tb-accent);
    border: none;
    border-radius: 6px;
    color: #000;
    font-weight: 600;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 6px;
}

.tb-btn-accent:hover {
    opacity: 0.9;
}

/* 대화 메시지 영역 */
.chat-messages-container {
    flex: 1 1 0; /* grow, shrink, basis=0 */
    min-height: 0; /* flex 자식 스크롤 허용 */
    height: 0; /* basis=0과 함께 스크롤 강제 */
    overflow-y: auto;
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.chat-welcome {
    text-align: center;
    padding: 20px;
    color: var(--tb-text-dim);
    font-size: 0.9rem;
}

.chat-welcome p {
    margin: 0;
}

/* 대화 메시지 */
.analysis-chat-msg {
    display: flex;
    gap: 10px;
    animation: chatFadeIn 0.2s ease-out;
}

@keyframes chatFadeIn {
    from {
        opacity: 0;
        transform: translateY(8px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.analysis-chat-msg.user {
    flex-direction: row-reverse;
}

.msg-avatar {
    width: 32px;
    height: 32px;
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    font-size: 1rem;
}

.analysis-chat-msg.user .msg-avatar {
    background: var(--tb-accent);
    color: #000;
}

.analysis-chat-msg.assistant .msg-avatar {
    background: var(--tb-border);
    color: var(--tb-text);
}

.msg-bubble {
    max-width: 75%;
    padding: 10px 14px;
    border-radius: 12px;
    font-size: 0.9rem;
    line-height: 1.5;
}

.analysis-chat-msg.user .msg-bubble {
    background: var(--tb-accent);
    color: #000;
    border-bottom-right-radius: 4px;
}

.analysis-chat-msg.assistant .msg-bubble {
    background: var(--tb-bg-dark);
    color: var(--tb-text);
    border: 1px solid var(--tb-border);
    border-bottom-left-radius: 4px;
}

.msg-bubble code {
    background: rgba(0, 0, 0, 0.2);
    padding: 2px 6px;
    border-radius: 4px;
    font-size: 0.85em;
}

.msg-bubble pre {
    margin: 8px 0 0 0;
    padding: 10px;
    background: var(--tb-bg-darker);
    border-radius: 6px;
    overflow-x: auto;
    font-size: 0.8rem;
}

/* 타이핑 표시 */
.typing-indicator {
    display: flex;
    gap: 4px;
    padding: 8px 12px;
}

.typing-indicator span {
    width: 8px;
    height: 8px;
    background: var(--tb-text-dim);
    border-radius: 50%;
    animation: typing 1.4s infinite both;
}

.typing-indicator span:nth-child(2) {
    animation-delay: 0.2s;
}

.typing-indicator span:nth-child(3) {
    animation-delay: 0.4s;
}

@keyframes typing {
    0%, 60%, 100% {
        transform: translateY(0);
        opacity: 0.4;
    }
    30% {
        transform: translateY(-4px);
        opacity: 1;
    }
}

/* 입력 영역 */
.chat-input-container {
    display: flex;
    gap: 8px;
    padding: 12px 16px;
    border-top: 1px solid var(--tb-border);
    background: var(--tb-bg-dark);
}

.chat-input-container input {
    flex: 1;
    padding: 10px 14px;
    background: var(--tb-bg);
    border: 1px solid var(--tb-border);
    border-radius: 8px;
    color: var(--tb-text);
    font-size: 0.9rem;
}

.chat-input-container input:focus {
    outline: none;
    border-color: var(--tb-accent);
}

.chat-input-container input::placeholder {
    color: var(--tb-text-dim);
}

.chat-input-container button {
    padding: 10px 16px;
}

/* 분석 시작 버튼 (입력창 좌측) */
.chat-analyze-btn {
    padding: 8px 10px !important;
    background: var(--tb-accent) !important;
    color: #000 !important;
    border-radius: 8px;
    flex-shrink: 0;
}

.chat-analyze-btn:hover {
    opacity: 0.9;
}

.chat-analyze-btn.analyzed {
    background: var(--tb-border) !important;
    color: var(--tb-text-dim) !important;
}

/* 패널 푸터 */
.chat-panel-footer {
    display: flex;
    justify-content: flex-end;
    gap: 8px;
    padding: 12px 16px;
    border-top: 1px solid var(--tb-border);
    background: var(--tb-bg-dark);
}

/* 적용된 수정 표시 */
.correction-applied {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 10px 14px;
    background: rgba(34, 197, 94, 0.1);
    border: 1px solid var(--tb-accent);
    border-radius: 8px;
    font-size: 0.85rem;
    color: var(--tb-accent);
}

.correction-applied i {
    font-size: 1rem;
}

/* JSON 보기 모달 내부 스타일 */
.json-preview-container {
    max-height: 400px;
    overflow: auto;
    background: var(--tb-bg-darker);
    border-radius: 8px;
}

.json-preview-container pre {
    margin: 0;
    padding: 16px;
    font-size: 0.75rem;
    line-height: 1.4;
    white-space: pre-wrap;
    word-break: break-all;
    color: var(--tb-text);
}
