/* v4.1: 자동완성 UI 개선 */

/* 전역 스타일 */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background: #f5f6fa;
    color: #2c3e50;
    line-height: 1.6;
}

.container {
    max-width: 1400px;
    margin: 0 auto;
    background: white;
    min-height: 100vh;
}

/* 헤더 스타일 (높이 축소) */
.header {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    padding: 0.8rem 2rem; /* 세로 패딩 축소 */
    display: flex;
    justify-content: space-between;
    align-items: center;
    box-shadow: 0 2px 10px rgba(0,0,0,0.1);
    position: relative;
    z-index: 100;
}

.header h1 {
    font-size: 1.5rem; /* 폰트 크기 조정 */
    font-weight: 600;
}

.header-actions {
    display: flex;
    gap: 1rem;
}

/* 버튼 스타일 */
.btn {
    padding: 0.7rem 1.3rem; /* 버튼 패딩 조정 */
    border: none;
    border-radius: 8px;
    cursor: pointer;
    font-size: 0.9rem;
    font-weight: 500;
    transition: all 0.3s ease;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.btn-primary {
    background: #3742fa;
    color: white;
}

.btn-primary:hover {
    background: #2f3542;
    transform: translateY(-2px);
}

.btn-secondary {
    background: rgba(255,255,255,0.2);
    color: white;
    border: 1px solid rgba(255,255,255,0.3);
}

.btn-secondary:hover {
    background: rgba(255,255,255,0.3);
}

.btn-small {
    padding: 0.5rem 1rem;
    font-size: 0.8rem;
}

/* 메인 콘텐츠 */
.main-content {
    display: grid;
    grid-template-columns: 250px 1fr 300px;
    grid-template-areas: "sidebar editor preview";
    min-height: calc(100vh - 74px); /* 헤더 높이 변경에 따른 조정 */
    transition: grid-template-columns 0.3s ease;
}

/* 햄버거 메뉴 버튼 */
.hamburger-btn {
    display: none;
    position: fixed;
    top: 20px;
    left: 20px;
    z-index: 1001;
    background: #3742fa;
    color: white;
    border: none;
    border-radius: 50%;
    width: 48px;
    height: 48px;
    font-size: 1.1rem;
    cursor: pointer;
    box-shadow: 0 4px 12px rgba(55, 66, 250, 0.3);
    transition: all 0.3s ease;
}

.hamburger-btn:hover {
    transform: scale(1.1);
    background: #2f3542;
}

/* 플로팅 미리보기 버튼 */
.floating-preview-btn {
    display: none;
    position: fixed;
    bottom: 30px;
    right: 30px;
    z-index: 1001;
    background: #2c3e50;
    color: white;
    border: none;
    border-radius: 50%;
    width: 56px;
    height: 56px;
    font-size: 1.2rem;
    cursor: pointer;
    box-shadow: 0 6px 16px rgba(44, 62, 80, 0.3);
    transition: all 0.3s ease;
}

.floating-preview-btn:hover {
    transform: scale(1.1);
    background: #34495e;
}

.floating-preview-btn.active {
    background: #e74c3c;
}

/* 사이드바 스타일 */
.sidebar {
    grid-area: sidebar;
    background: #f8f9fa;
    padding: 1.5rem;
    border-right: 1px solid #e9ecef;
    overflow-y: auto;
    transition: transform 0.3s ease;
    display: flex;
    flex-direction: column;
}

.sidebar h3 {
    color: #495057;
    margin-bottom: 1.5rem;
    font-size: 1.1rem;
}

.preset-divider {
    height: 1px;
    background: linear-gradient(to right, transparent, #dee2e6, transparent);
    margin: 1.5rem 0;
}

.preset-category {
    margin-bottom: 2rem;
}

.preset-category h4 {
    color: #6c757d;
    font-size: 0.9rem;
    margin-bottom: 0.8rem;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.preset-buttons {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.preset-btn {
    padding: 0.8rem;
    background: white;
    border: 1px solid #dee2e6;
    border-radius: 6px;
    cursor: pointer;
    transition: all 0.3s ease;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 0.9rem;
    text-align: left;
}

.preset-btn:hover {
    background: #e3f2fd;
    border-color: #2196f3;
    transform: translateX(5px);
}

.preset-btn i {
    color: #2196f3;
    width: 20px;
    text-align: center;
}

/* Credit 섹션 스타일 */
.credits-section {
    margin-top: auto;
    padding: 1.5rem 0 0.5rem;
    border-top: 1px solid #e9ecef;
    font-size: 0.8rem;
    color: #6c757d;
}

.credit-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 0.8rem;
}

.credit-header .license {
    font-size: 1rem;
    display: flex;
    gap: 0.2rem;
}

.credit-links {
    display: flex;
    gap: 1rem;
    margin-bottom: 0.5rem;
}

.credit-links a {
    color: #3498db;
    text-decoration: none;
    transition: color 0.2s;
    display: flex;
    align-items: center;
    gap: 0.3rem;
}

.credit-links a:hover {
    color: #2980b9;
}

.license-note {
    font-size: 0.75rem;
    color: #95a5a6;
}

/* 편집 영역 스타일 */
.editor-area {
    grid-area: editor;
    padding: 1.5rem;
    overflow-y: auto;
    background: #fafafa;
}

.editor-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1.5rem;
}

.editor-header h3 {
    color: #343a40;
    font-size: 1.2rem;
}

.block-container {
    display: flex;
    flex-direction: column;
    gap: 1rem;
    min-height: 400px;
}

/* 인라인 블록 추가 필드 */
.inline-block-add {
    background: #f8f9fa;
    border: 2px dashed #dee2e6;
    border-radius: 12px;
    padding: 1rem;
    margin-bottom: 1rem;
    display: none;
    animation: slideIn 0.3s ease-out;
}

.inline-add-container {
    display: flex;
    gap: 0.5rem;
    align-items: center;
}

.inline-add-input {
    flex: 1;
    padding: 0.8rem;
    border: 1px solid #dee2e6;
    border-radius: 6px;
    font-size: 0.9rem;
    background: white;
    transition: border-color 0.3s ease;
}

.inline-add-input:focus {
    outline: none;
    border-color: #3742fa;
    box-shadow: 0 0 0 3px rgba(55, 66, 250, 0.1);
}

.inline-add-actions {
    display: flex;
    gap: 0.3rem;
}

.inline-add-btn {
    width: 36px;
    height: 36px;
    border: none;
    border-radius: 6px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.9rem;
    transition: all 0.2s ease;
}

.inline-add-confirm {
    background: #28a745;
    color: white;
}
.inline-add-confirm:hover {
    background: #218838;
    transform: scale(1.05);
}

.inline-add-cancel {
    background: #6c757d;
    color: white;
}
.inline-add-cancel:hover {
    background: #5a6268;
    transform: scale(1.05);
}

/* 블록 스타일 (여백 조정) */
.prompt-block {
    background: white;
    border: 2px solid #e9ecef;
    border-radius: 12px;
    overflow: hidden;
    transition: all 0.3s ease;
    box-shadow: 0 2px 8px rgba(0,0,0,0.05);
    position: relative; /* 자동완성 UI 포지셔닝 기준 */
}

.prompt-block:hover {
    border-color: #764ba2;
    box-shadow: 0 4px 12px rgba(118, 75, 162, 0.15);
}

.block-header {
    background: #f8f9fa;
    padding: 0.75rem 1.25rem; /* 세로 패딩 축소 */
    border-bottom: 1px solid #e9ecef;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.block-tag {
    font-family: 'Courier New', monospace;
    font-weight: 600;
    color: #e91e63;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.block-actions {
    display: flex;
    gap: 0.5rem;
}

.block-btn {
    padding: 0.3rem 0.6rem;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    font-size: 0.8rem;
    transition: all 0.2s ease;
    background: transparent;
    color: #6c757d;
}
.block-btn:hover {
    background: #e9ecef;
}

.block-btn.delete:hover {
    background: #f44336;
    color: white;
}

.block-btn.move {
    cursor: grab;
}

.block-content {
    padding: 1rem 1.25rem;
}

.block-content textarea {
    width: 100%;
    min-height: 80px; /* 최소 높이 조정 */
    border: none;
    resize: vertical;
    font-family: inherit;
    font-size: 1rem;
    line-height: 1.6;
    background: transparent;
    padding: 0;
}

.block-content textarea:focus {
    outline: none;
}

/* ✨ 자동완성 UI 스타일 (개선됨) */
.autocomplete-suggestions {
    position: absolute;
    background-color: #34495e;
    color: white;
    border-radius: 6px; /* 모서리 둥글기 조정 */
    box-shadow: 0 4px 15px rgba(0,0,0,0.2);
    z-index: 100;
    max-height: 150px;
    overflow-y: auto;
    width: max-content; /* 너비를 내용에 맞춤 */
}

.autocomplete-suggestions div {
    padding: 0.4rem 0.8rem; /* 상하좌우 여백 축소 */
    cursor: pointer;
    transition: background-color 0.2s ease;
    font-family: 'Segoe UI', sans-serif;
    font-size: 0.85rem; /* 폰트 크기 미세 조정 */
    white-space: nowrap; /* 단어가 길어도 줄바꿈 방지 */
}

.autocomplete-suggestions div:hover,
.autocomplete-suggestions div.active {
    background-color: #667eea;
}
/* ✨ 끝 */

/* 빈 상태 스타일 */
.empty-state {
    text-align: center;
    padding: 3rem;
    color: #6c757d;
}

.empty-state i {
    font-size: 3rem;
    color: #dee2e6;
    margin-bottom: 1rem;
}

.empty-state h4 {
    margin-bottom: 0.5rem;
    font-size: 1.2rem;
}

/* 미리보기 영역 */
.preview-area {
    grid-area: preview;
    background: #2c3e50;
    color: #ecf0f1;
    padding: 1.5rem;
    border-left: 1px solid #34495e;
    overflow-y: auto;
    transition: transform 0.3s ease;
    position: relative;
}

.preview-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1rem;
}

.preview-header h3 {
    font-size: 1.1rem;
}

.preview-close-btn {
    display: none;
    background: transparent;
    border: none;
    color: #ecf0f1;
    font-size: 1.2rem;
    cursor: pointer;
    padding: 0.5rem;
    border-radius: 4px;
    transition: background 0.2s ease;
}
.preview-close-btn:hover {
    background: rgba(255,255,255,0.1);
}

.preview-content {
    background: #34495e;
    border-radius: 8px;
    padding: 1rem;
    font-family: 'Courier New', monospace;
    font-size: 0.9rem;
    line-height: 1.4;
    max-height: calc(100vh - 200px);
    overflow-y: auto;
}

.preview-content pre {
    white-space: pre-wrap;
    word-break: break-word;
}

/* 오버레이 */
.overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: 900;
    opacity: 0;
    transition: opacity 0.3s ease;
}
.overlay.active {
    opacity: 1;
}

/* ===================================
   반응형 레이아웃 (모바일 최적화)
=================================== */

/* 태블릿 (768px ~ 1024px) */
@media (max-width: 1024px) and (min-width: 769px) {
    .main-content {
        grid-template-columns: 200px 1fr 260px;
    }
    .sidebar {
        padding: 1rem;
    }
}

/* 태블릿/모바일 전환점 (768px) */
@media (max-width: 768px) {
    /* 헤더 크기 최적화 */
    .header {
        padding: 0.5rem 1rem 0.5rem 4.5rem;
        min-height: 60px;
    }
    .header h1 {
        font-size: 1.1rem;
    }
    .header-actions {
        gap: 0.5rem;
    }
    .header-actions .btn {
        padding: 0.5rem 0.8rem;
        font-size: 0.8rem;
    }
    
    /* 메인 레이아웃 */
    .main-content {
        grid-template-columns: 1fr;
        grid-template-areas: "editor";
        min-height: calc(100vh - 60px);
    }
    
    /* 햄버거 버튼 */
    .hamburger-btn {
        display: flex;
        align-items: center;
        justify-content: center;
        top: 15px;
        left: 15px;
        width: 40px;
        height: 40px;
        font-size: 1rem;
    }
    
    /* 플로팅 미리보기 버튼 */
    .floating-preview-btn {
        display: flex;
        align-items: center;
        justify-content: center;
        bottom: 20px;
        right: 20px;
        width: 48px;
        height: 48px;
        font-size: 1.1rem;
    }
    
    /* 사이드바 -> 슬라이드 패널 */
    .sidebar {
        position: fixed;
        top: 0;
        left: 0;
        transform: translateX(-100%);
        width: 280px;
        height: 100vh;
        z-index: 1000;
        background: white;
        box-shadow: 2px 0 10px rgba(0,0,0,0.15);
        padding: 1rem;
        padding-top: 60px;
    }
    .sidebar.panel-open {
        transform: translateX(0);
    }
    
    /* 미리보기 -> 슬라이드 패널 */
    .preview-area {
        position: fixed;
        top: 0;
        right: 0;
        transform: translateX(100%);
        width: 300px;
        height: 100vh;
        z-index: 1000;
        box-shadow: -2px 0 10px rgba(0,0,0,0.15);
        padding: 1rem;
        padding-top: 60px;
    }
    .preview-area.panel-open {
        transform: translateX(0);
    }
    .preview-close-btn {
        display: block;
        position: absolute;
        top: 15px;
        right: 15px;
    }
    
    /* 편집 영역 */
    .editor-area { padding: 0.8rem; }
    .editor-header { margin-bottom: 1rem; flex-wrap: wrap; gap: 0.5rem; }
    .editor-header h3 { font-size: 1rem; flex: 1; min-width: 150px; }
    .editor-actions { flex-shrink: 0; }
    
    /* 블록 */
    .prompt-block { margin-bottom: 0.8rem; }
    .block-header { padding: 0.8rem 1rem; flex-wrap: wrap; gap: 0.5rem; }
    .block-tag { font-size: 0.85rem; flex: 1; min-width: 120px; }
    .block-actions { flex-shrink: 0; gap: 0.3rem; }
    .block-btn { padding: 0.4rem 0.6rem; font-size: 0.75rem; min-width: 36px; min-height: 36px; }
    .block-content { padding: 0.8rem; }
    .block-content textarea { min-height: 80px; font-size: 16px; /* iOS zoom 방지 */ }
}

/* 애니메이션 */
@keyframes slideIn {
    from { opacity: 0; transform: translateY(-20px); }
    to { opacity: 1; transform: translateY(0); }
}

.prompt-block.dragging {
    opacity: 0.5;
    transform: rotate(2deg);
    box-shadow: 0 8px 25px rgba(0,0,0,0.3);
}

/* ===================================
   템플릿 버튼 스타일 (v2)
=================================== */

/* 템플릿 버튼들을 감싸는 컨테이너 */
.template-container {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem; /* 버튼 사이의 간격 */
    margin-bottom: 0.75rem; /* 아래 텍스트 영역과의 간격 */
}

/* 템플릿 버튼 개별 스타일 */
.template-btn {
    padding: 0.4rem 0.9rem; /* 버튼 내부 여백 */
    font-size: 0.85rem;
    font-weight: 500;
    background-color: #eef2f7; /* 부드러운 배경색 */
    color: #525f7f;
    border: 1px solid #dee2e6;
    border-radius: 16px; /* 둥근 모서리 (알약 모양) */
    cursor: pointer;
    transition: all 0.2s ease-in-out;
}

/* 마우스를 올렸을 때의 효과 */
.template-btn:hover {
    background-color: #764ba2; /* 호버 시 색상 변경 */
    color: white;
    border-color: #764ba2;
    transform: translateY(-2px); /* 살짝 떠오르는 효과 */
    box-shadow: 0 4px 8px rgba(118, 75, 162, 0.2);
}

/* ✨ 활성화된 템플릿 버튼 스타일 */
.template-btn.active {
    background-color: #667eea; /* 활성화 시 배경색 */
    color: white;
    border-color: #667eea;
    font-weight: 600;
    box-shadow: 0 2px 4px rgba(102, 126, 234, 0.3);
}
