* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    height: 100vh;
    overflow: hidden;
}

.container {
    display: flex;
    height: 100vh;
    gap: 10px;
    padding: 10px;
}

/* Control Panel */
.control-panel {
    width: 280px;
    background: white;
    border-radius: 10px;
    padding: 20px;
    box-shadow: 0 4px 6px rgba(0,0,0,0.1);
    overflow-y: auto;
}

.control-panel h2 {
    color: #333;
    margin-bottom: 20px;
    font-size: 20px;
}

.input-section {
    margin-bottom: 8px;
}

.input-section label {
    display: block;
    margin-bottom: 8px;
    color: #555;
    font-size: 14px;
    font-weight: 500;
}

#nodeInput {
    width: 100%;
    height: 130px; /* 100px에서 130px로 수정 */
    padding: 10px;
    border: 2px solid #e0e0e0;
    border-radius: 5px;
    font-size: 14px;
    resize: vertical;
    margin-bottom: 10px;
}

#nodeInput:focus {
    outline: none;
    border-color: #667eea;
}

button {
    width: 100%;
    padding: 10px;
    background: #667eea;
    color: white;
    border: none;
    border-radius: 5px;
    cursor: pointer;
    font-size: 14px;
    font-weight: 600;
    transition: background 0.3s;
}

button:hover {
    background: #5568d3;
}

button:active {
    transform: scale(0.98);
}

.button-group {
    display: flex;
    flex-direction: column;
    gap: 10px; /* 버튼/그룹 간의 간격 */
    margin-bottom: 20px;
}

/* 가로 2개 버튼 그룹 */
.button-row {
    display: flex;
    gap: 8px;
}
.button-row button {
    flex: 1; /* 1:1 비율로 채움 */
}

/* 선 연결 모드 (푸른색으로 수정) */
#connectBtn {
    background: #667eea; /* '추가' 버튼과 동일한 기본 푸른색 */
}
#connectBtn:hover {
    background: #5568d3; /* '추가' 버튼과 동일한 호버 색상 */
}
#connectBtn.active {
    background: #e74c3c; /* 활성화 시에는 기존 색상 유지 */
}

#zoomFitBtn {
    /* (수정) 자동 정렬 버튼과 동일한 스타일로 변경 */
    background: #f1f3f5;
    color: #333;
    border: 1px solid #e0e0e0;
}
#zoomFitBtn:hover {
    /* (수정) 자동 정렬 버튼과 동일한 호버 스타일로 변경 */
    background: #e9ecef;
}


/* 정리 버튼 (보조) */
button[onclick="autoArrange()"] {
    background: #f1f3f5; /* 밝은 회색 */
    color: #333;
    border: 1px solid #e0e0e0;
}
button[onclick="autoArrange()"]:hover {
    background: #e9ecef;
}

/* 초기화 버튼 (경고/파괴) */
button[onclick="clearCanvas()"] {
    background: transparent;
    color: #e74c3c; /* 빨간색 텍스트 */
    border: 1px solid #e74c3c;
}
button[onclick="clearCanvas()"]:hover {
    background: #e74c3c;
    color: white;
}

/* 저장 버튼 (보조 - 회색 통일) */
#saveBtnBg,
#saveBtnTrans {
    background: #5d6d7e;
    color: white;
}
#saveBtnBg:hover,
#saveBtnTrans:hover {
    background: #4e5c6b;
}


/* Edit Section */
.edit-section {
    background: #f8f9fa;
    padding: 15px;
    border-radius: 5px;
    margin-top: 20px;
}

.edit-section h3 {
    font-size: 16px;
    margin-bottom: 15px;
    color: #333;
}

.edit-section label {
    display: block;
    margin-top: 10px;
    margin-bottom: 5px;
    font-size: 13px;
    color: #555;
    font-weight: 500;
}

#fontSizeSlider {
    width: calc(100% - 50px);
    margin-right: 10px;
}

#fontSizeValue {
    font-size: 12px;
    color: #666;
}

.color-palette {
    display: grid;
    grid-template-columns: repeat(6, 1fr); /* 4에서 6으로 변경 */
    gap: 8px;
    margin-bottom: 15px;
}

.color-option {
    width: 100%;
    aspect-ratio: 1;
    border-radius: 5px;
    cursor: pointer;
    border: 2px solid transparent;
    transition: transform 0.2s;
}

.color-option:hover {
    transform: scale(1.1);
    border-color: #333;
}

.line-edit-select {
    width: 100%;
    padding: 8px;
    border: 1px solid #e0e0e0;
    border-radius: 5px;
    font-size: 13px;
    margin-bottom: 10px;
    background: white;
}

/* Canvas Container */
.canvas-container {
    flex: 1;
    background: white;
    border-radius: 10px;
    position: relative;
    overflow: hidden;
    box-shadow: 0 4px 6px rgba(0,0,0,0.1);
    display: flex;
    flex-direction: column;
}

#canvas {
    flex: 1;
    position: relative;
    z-index: 2;
    pointer-events: none;
}

#connectionLayer {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: auto;
    z-index: 1;
    overflow: visible;
}

/* Node Styling */
.node {
    position: absolute;
    padding: 12px 20px;
    background: #3498db;
    color: white;
    border-radius: 20px;
    cursor: move;
    user-select: none;
    box-shadow: 0 2px 8px rgba(0,0,0,0.15);
    font-size: 16px;
    font-weight: 500;
    transition: transform 0.2s, box-shadow 0.2s;
    z-index: 2;
    white-space: nowrap;
    pointer-events: auto;
}

.node:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(0,0,0,0.2);
}

.node.selected {
    box-shadow: 0 0 0 3px #f39c12;
    transform: scale(1.05);
}

.node.connect-mode {
    cursor: pointer;
}

/* Notepad Panel */
.notepad-panel {
    width: 320px;
    background: white;
    border-radius: 10px;
    padding: 20px;
    box-shadow: 0 4px 6px rgba(0,0,0,0.1);
    display: flex;
    flex-direction: column;
}

.notepad-panel h2 {
    color: #333;
    margin-bottom: 0px;
    font-size: 20px;
}

.panel-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 15px; /* h2에 있던 마진을 여기로 이동 */
}

#coffeeBtn {
  display: inline-block;
  transition: transform 0.2s;
  line-height: 1;
}

#coffeeBtn:hover {
  transform: scale(1.05);
}

#coffeeBtn img {
  height: 28px;   /* 🔽 기존 30px → 24px로 축소 */
  width: auto;
  display: block;
}

.ai-buttons {
    display: flex;
    flex-direction: column;
    gap: 8px;
    margin-bottom: 15px;
}

.ai-buttons button {
    font-size: 13px;
    padding: 8px;
    background: #9b59b6;
}

.ai-buttons button:hover {
    background: #8e44ad;
}

#notepad {
    flex: 1;
    padding: 15px;
    border: 2px solid #e0e0e0;
    border-radius: 5px;
    font-size: 14px;
    resize: none;
    margin-bottom: 15px;
    font-family: inherit;
}

#notepad:focus {
    outline: none;
    border-color: #667eea;
}

.ai-output {
    background: #f8f9fa;
    border-radius: 5px;
    padding: 15px;
    max-height: 200px;
    overflow-y: auto;
    font-size: 13px;
    line-height: 1.6;
    color: #333;
    display: none;
}

.ai-output.show {
    display: block;
}

.ai-output h4 {
    margin-bottom: 10px;
    color: #9b59b6;
}

.ai-output p {
    margin-bottom: 8px;
}

.ai-output ul {
    margin-left: 20px;
}

.ai-output li {
    margin-bottom: 5px;
}

/* Chatbot Section */
#chatbotSection {
    background: #f8f9fa;
    border-radius: 5px;
    padding: 10px;
    margin-bottom: 15px;
    max-height: 400px;
    display: flex;
    flex-direction: column;
}

.chat-messages {
    flex: 1;
    overflow-y: auto;
    margin-bottom: 10px;
    max-height: 250px;
    padding: 10px;
    background: white;
    border-radius: 5px;
}

.chat-message {
    margin-bottom: 12px;
    padding: 8px 12px;
    border-radius: 8px;
    max-width: 90%;
    word-wrap: break-word;
}

.chat-message.user {
    background: #667eea;
    color: white;
    margin-left: auto;
    text-align: right;
}

.chat-message.assistant {
    background: #e9ecef;
    color: #333;
}

.chat-message.system {
    background: #fff3cd;
    color: #856404;
    font-size: 12px;
    text-align: center;
    margin: 5px auto;
}

.chat-input-container {
    display: flex;
    gap: 5px;
    margin-bottom: 10px;
}

#chatInput {
    flex: 1;
    padding: 8px;
    border: 2px solid #e0e0e0;
    border-radius: 5px;
    font-size: 13px;
}

#chatInput:focus {
    outline: none;
    border-color: #667eea;
}

.chat-input-container button {
    width: auto;
    padding: 8px 15px;
    font-size: 13px;
}

.api-config {
    display: flex;
    flex-direction: column;
    gap: 5px;
}

#apiKey {
    padding: 6px;
    border: 1px solid #e0e0e0;
    border-radius: 5px;
    font-size: 12px;
}

#modelSelect {
    padding: 6px;
    border: 1px solid #e0e0e0;
    border-radius: 5px;
    font-size: 12px;
    background: white;
}

/* Connection Lines */
line {
    /* stroke: #95a5a6; <-- 제거 */
    /* stroke-width: 2; <-- 제거 */
    transition: stroke 0.3s, stroke-width 0.3s; /* 굵기 전환 효과 추가 */
    cursor: pointer;
    pointer-events: auto;
}

line:hover {
    /* stroke: #34495e; <-- 제거 */
    /* stroke-width: 3; <-- 제거 */
    filter: brightness(1.2); /* 덮어쓰지 않고 밝기만 조절 */
}

line.selected {
    /* stroke: #e74c3c; <-- 제거 */
    /* stroke-width: 4; <-- 제거 */

    /* 선택한 스타일을 유지하면서 빛나는 효과(그림자) 추가 */
    filter: drop-shadow(0 0 3px #f39c12) brightness(1.1);
}

/* Scrollbar Styling */
::-webkit-scrollbar {
    width: 8px;
}

::-webkit-scrollbar-track {
    background: #f1f1ff;
    border-radius: 10px;
}

::-webkit-scrollbar-thumb {
    background: #888;
    border-radius: 10px;
}

::-webkit-scrollbar-thumb:hover {
    background: #555;
}

/* 캔버스와 SVG 레이어의 transform 기준점을 좌측 상단(0,0)으로 설정 */
#canvas, #connectionLayer {
    transform-origin: 0 0;
}

/* 스페이스바를 눌러 패닝 모드일 때 커서 변경 */
.canvas-container.panning {
    cursor: grab;
}
.canvas-container.panning:active {
    cursor: grabbing;
}

/* --- (신규) 입력 내용 복사 아이콘 버튼 스타일 --- */
.label-wrapper {
    display: flex;
    justify-content: space-between;
    align-items: flex-end;
    margin-bottom: 8px; /* <textarea>와의 간격 (기존 label의 margin-bottom) */
}

.label-wrapper label {
    margin-bottom: 0; /* 래퍼가 마진을 가지므로 label의 마진은 0으로 */
}

/* (신규) 복사 버튼 ID 선택자 */
#copyBtn {
    width: auto;
    padding: 2px 8px; /* (수정) 4px 10px -> 2px 8px */
    font-size: 14px; /* (수정) 16px -> 14px (아이콘 크기) */
    line-height: 1;
    margin-left: 10px;
    flex-shrink: 0;

    background: #f1f3f5;
    color: #333;
    border: 1px solid #e0e0e0;
}

#copyBtn:hover {
    background: #e9ecef;
}

/* --- (신규) 캔버스에 직접 입력하는 임시 노드 스타일 --- */
.node-temp-input {
    position: absolute;
    transform: translate(-50%, -50%);

    /* .node와 유사한 스타일 */
    padding: 12px 20px;
    font-size: 16px;
    font-weight: 500;
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;

    /* 입력창 스타일 */
    background: #ffffff;
    border: 2px dashed #3498db;
    border-radius: 20px;
    box-shadow: 0 2px 8px rgba(0,0,0,0.15);

    /* 클릭 이벤트 수신 (부모인 #canvas가 none이므로) */
    pointer-events: auto;

    /* z-index (노드와 동일) */
    z-index: 2;

    /* 테두리 포함 크기 계산 */
    box-sizing: border-box;
}

.node-temp-input:focus {
    outline: none;
    border-style: solid;
    box-shadow: 0 0 0 3px #f39c12;
}

.button-divider {
    border: none; /* 기본 테두리 제거 */
    height: 1px; /* 선 굵기 */
    background-color: #e0e0e0; /* 얇은 회색 선 */
    margin: 0; /* 갭(gap)이 간격을 관리하므로 마진 0 */
}