/* ==========================================================================
   1. 전역 변수 및 기본 스타일
   ========================================================================== */
:root {
    --bg-color-main: #ffffff;
    --bg-color-page: #f0f2f5;
    --text-color: #212529;
    --text-color-secondary: #5f6368;
    --link-color: #1a0dab;
    --border-color: #dfe1e5;
    --shadow-color: rgba(0, 0, 0, 0.08);
    --search-button-bg-color: #4285F4;
    --weight-text-color: #007bff;

    --card-bg-color: rgb(250, 250, 250);
    --card-shadow-color: rgba(0, 0, 0, 0.1);
    --card-border-color: #e0e0e0;
    --card-text-color-secondary: rgb(108, 117, 125);

    --meta-tag-bg-color: rgb(233, 236, 239);
    --meta-tag-text-color: rgb(108, 117, 125);

    --accuracy-tag-bg-color: rgb(232, 246, 236);
    --accuracy-tag-text-color: rgb(0, 169, 71);

    --highlight-bg-color: #FFD54F;
    --highlight-text-color: #000000;
}

body.dark-mode {
    --bg-color-main: #202124;
    --bg-color-page: #131314;
    --text-color: #e8eaed;
    --text-color-secondary: #bdc1c6;
    --link-color: #8ab4f8;
    --border-color: #3c4043;
    --search-button-bg-color: #8ab4f8;
    --weight-text-color: #8ab4f8;

    --card-bg-color: #292a2d;
    --card-shadow-color: rgba(0, 0, 0, 0.5);
    --card-border-color: #3c4043;
    --card-text-color-secondary: #bdc1c6;

    --meta-tag-bg-color: #343a40;
    --meta-tag-text-color: #adb5bd;

    --accuracy-tag-bg-color: #1c3d2f;
    --accuracy-tag-text-color: #81c995;

    --highlight-bg-color: #FBC02D;
    --highlight-text-color: #000000;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    background-color: var(--bg-color-page);
    color: var(--text-color);
    margin: 0; padding: 20px;
    transition: background-color 0.3s, color 0.3s;
}

/* [iOS 대응] 부드러운 스크롤 */
body, .ai-content-wrapper {
    -webkit-overflow-scrolling: touch;
}

/* ==========================================================================
   2. 레이아웃
   ========================================================================== */
.container {
    width: 90%; max-width: 1400px;
    margin: 0 auto; background-color: var(--bg-color-main);
    padding: 2rem 2.5rem; border-radius: 12px;
    box-shadow: 0 4px 12px var(--shadow-color);
    box-sizing: border-box;
    position: relative;
}
.search-controls, footer { max-width: 100%; margin: auto; }
main { position: relative; }

/* ==========================================================================
   3. 헤더 및 검색 컨트롤
   ========================================================================== */
header { text-align: center; margin-bottom: 2rem; }
header h1 { font-size: 28px; font-weight: 700; margin: 0; }

.search-form { flex-grow: 1; }

.search-bar-wrapper {
    display: flex;
    align-items: flex-end;
    border: 1px solid var(--border-color);
    border-radius: 24px;
    padding: 8px 10px 8px 20px;
    min-height: 48px;
    height: auto;
    flex-grow: 1;
    transition: border-color 0.2s, box-shadow 0.2s;
    box-shadow: 0 1px 6px rgba(32,33,36,0.28);
    background-color: var(--bg-color-main);
}

.search-bar-wrapper:hover, .search-bar-wrapper:focus-within {
    box-shadow: 0 1px 6px rgba(32,33,36,0.48);
    border-color: rgba(223,225,229,0);
}

#search-input {
    flex-grow: 1;
    border: none;
    outline: none;
    padding: 4px 0;
    margin-bottom: 4px;
    font-size: 16px;
    background-color: transparent;
    color: var(--text-color);
    resize: none;
    height: 24px;
    max-height: 200px;
    overflow-y: hidden;
    line-height: 1.5;
    font-family: inherit;
}

.search-bar-buttons {
    display: flex; align-items: center; gap: 4px; margin-bottom: 2px;
}

.search-bar-btn {
    background: transparent; border: none; cursor: pointer;
    padding: 6px; display: flex; align-items: center; justify-content: center;
    width: 36px; height: 36px; border-radius: 50%;
    transition: background-color 0.2s; flex-shrink: 0;
}
.search-bar-btn:hover { background-color: var(--bg-color-page); }

.search-icon, .settings-icon, .mic-icon, .stop-icon {
    width: 20px; height: 20px; fill: var(--text-color-secondary);
}
body.dark-mode .search-icon { fill: #8ab4f8; }

#mic-btn.is-listening:disabled .mic-icon,
#mic-btn.is-listening .mic-icon {
    animation: pulse 1.5s infinite; fill: #DB4437;
}
#mic-btn:disabled .mic-icon, #settings-btn:disabled .settings-icon {
    fill: var(--border-color);
}

.spinner-inline {
    display: none; width: 20px; height: 20px;
    border: 3px solid var(--border-color);
    border-top-color: var(--search-button-bg-color);
    border-radius: 50%; animation: spin 1s linear infinite;
    position: absolute; top: 50%; left: 50%;
    margin-top: -10px; margin-left: -10px;
}
#search-submit-btn.loading .spinner-inline { display: block; }
#search-submit-btn.loading .search-icon { visibility: hidden; }

#search-submit-btn.loading { background-color: var(--text-color); }
#search-submit-btn.loading svg { fill: var(--bg-color-main); }

/* ==========================================================================
   4. 고급 설정
   ========================================================================== */
.options-panel {
    position: absolute;
    top: 70px;
    left: 0; width: 100%;
    background-color: var(--bg-color-main);
    border: 1px solid var(--border-color);
    border-radius: 12px;
    box-shadow: 0 4px 16px rgba(0,0,0,0.2);
    padding: 1.5rem;
    box-sizing: border-box;
    z-index: 1000;
    opacity: 0;
    transform: translateY(-10px);
    pointer-events: none;
    transition: opacity 0.2s ease-out, transform 0.2s ease-out;
}
.options-panel.is-open { opacity: 1; transform: translateY(0); pointer-events: auto; }

.option-group { margin-bottom: 20px; }
.option-group:last-child { margin-bottom: 0; }
.option-group p { margin: 0 0 10px; font-weight: 500; font-size: 14px; }

.close-options-btn {
    position: absolute; top: 0.75rem; right: 0.75rem;
    background: transparent; border: none; font-size: 1.75rem;
    font-weight: 300; color: var(--text-color-secondary);
    cursor: pointer; line-height: 1; padding: 0.5rem; transition: color 0.2s;
}
.close-options-btn:hover { color: var(--text-color); }

.slider-wrapper { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
#weight-slider { flex-grow: 1; }
#weight-value { font-weight: 500; font-size: 14px; color: var(--text-color-secondary); }
#weight-value .accuracy { color: var(--link-color); font-weight: bold; }
#weight-value .similarity { color: #e57373; font-weight: bold; }
body.dark-mode #weight-value .similarity { color: #f28b82; }

.button-group, .theme-options { display: flex; flex-wrap: wrap; gap: 10px; }
.select-btn, .theme-btn {
    border: 1px solid var(--border-color); padding: 6px 12px; border-radius: 6px;
    font-size: 13px; font-weight: 500; cursor: pointer; transition: all 0.2s;
    background-color: var(--bg-color-page); color: var(--text-color);
}
.select-btn:hover, .theme-btn:hover { border-color: var(--text-color-secondary); filter: brightness(95%); }
body.dark-mode .select-btn:hover, body.dark-mode .theme-btn:hover { filter: brightness(120%); }

.select-btn.active, .theme-btn.active {
    background-color: var(--search-button-bg-color); color: #ffffff;
    border-color: var(--search-button-bg-color); font-weight: 500;
}
body.dark-mode .select-btn.active, body.dark-mode .theme-btn.active { color: #202124; }

.switch { position: relative; display: inline-block; width: 34px; height: 20px; vertical-align: middle; margin-right: 10px; }
.switch input { opacity: 0; width: 0; height: 0; }
.slider { position: absolute; cursor: pointer; top: 0; left: 0; right: 0; bottom: 0; background-color: #ccc; transition: .4s; border-radius: 34px; }
.slider:before { position: absolute; content: ""; height: 14px; width: 14px; left: 3px; bottom: 3px; background-color: white; transition: .4s; border-radius: 50%; }
input:checked + .slider { background-color: var(--search-button-bg-color); }
input:checked + .slider:before { transform: translateX(14px); }
.toggle-wrapper { display: flex; align-items: center; font-size: 14px; margin-bottom: 5px; }

/* ==========================================================================
   5. 검색 결과 카드
   ========================================================================== */
footer { margin-top: 40px; text-align: left; }
.result-header {
    font-size: 0.9rem; color: var(--text-color-secondary);
    margin-bottom: 15px; padding-bottom: 15px; border-bottom: 1px solid var(--border-color);
}
.result-header mark.query-highlight {
    background-color: var(--accuracy-tag-bg-color); color: var(--accuracy-tag-text-color);
    font-weight: 700; padding: 2px 4px; border-radius: 4px;
}

.result-card {
    background-color: var(--card-bg-color); border: 1px solid var(--card-border-color);
    border-radius: 8px; padding: 20px; margin-bottom: 15px; box-shadow: none;
    transition: box-shadow 0.2s ease-in-out, background-color 0.2s;
}
.result-card:hover { background-color: var(--bg-color-page); }

.result-card h3 { margin: 0 0 10px 0; font-size: 1.1rem; font-weight: 700; }
.result-card h3 a { color: var(--link-color); text-decoration: none; }
.result-card h3 a:hover { text-decoration: underline; }

.result-meta { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; font-size: 12px; margin-bottom: 12px; }
.meta-tag { padding: 4px 8px; border-radius: 4px; font-size: 12px; font-weight: 500; }
.meta-tag.info { background-color: var(--meta-tag-bg-color); color: var(--meta-tag-text-color); }
.meta-tag.accuracy { background-color: var(--accuracy-tag-bg-color); color: var(--accuracy-tag-text-color); font-weight: 700; }

.result-snippet {
    color: var(--card-text-color-secondary); line-height: 1.6; font-size: 14px; margin: 0;
    display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical;
    overflow: hidden; text-overflow: ellipsis;
}
.result-snippet mark {
    background-color: var(--highlight-bg-color); color: var(--highlight-text-color);
    font-weight: 600; padding: 0; border-radius: 2px;
}

.result-url { font-size: 14px; color: var(--link-color); word-break: break-all; text-decoration: none; margin-top: 12px; display: block; }

/* ==========================================================================
   6. 기타 (스피너, 애니메이션)
   ========================================================================== */
.spinner { border: 4px solid var(--bg-color-page); border-top: 4px solid var(--search-button-bg-color); border-radius: 50%; width: 40px; height: 40px; animation: spin 1s linear infinite; margin: 40px auto; }
@keyframes spin { 0% { transform: rotate(0deg); } 100% { transform: rotate(360deg); } }
@keyframes pulse { 0% { opacity: 1; } 50% { opacity: 0.4; } 100% { opacity: 1; } }

@media (max-width: 768px) {
    body { padding: 0; }
    .container { width: 100%; max-width: 100%; padding: 1rem; border-radius: 0; box-shadow: none; }
    .search-bar-wrapper { padding: 0 8px; }
    .options-panel { top: 60px; border-radius: 8px; }
    .result-card { padding: 15px; }
}

/* [수정] PC에서도 전송 버튼이 항상 보이도록 미디어 쿼리 삭제/수정 */
/* 기존에 있던 #search-submit-btn { display: none; } 코드를 제거함 */


/* ==========================================================================
   7. Toast 알림 (UI 개선)
   ========================================================================== */
#toast-container {
    position: fixed;
    bottom: 20px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 3000;
    display: flex;
    flex-direction: column;
    gap: 10px;
    pointer-events: none; /* 알림 뒤 클릭 가능 */
}

.toast {
    background-color: rgba(33, 37, 41, 0.9);
    color: white;
    padding: 12px 24px;
    border-radius: 8px;
    font-size: 14px;
    box-shadow: 0 4px 12px rgba(0,0,0,0.15);
    opacity: 0;
    transform: translateY(20px);
    transition: opacity 0.3s ease, transform 0.3s ease;
    pointer-events: auto;
    text-align: center;
    max-width: 80vw;
}

.toast.show {
    opacity: 1;
    transform: translateY(0);
}

.toast.error {
    background-color: rgba(220, 53, 69, 0.95);
}

.toast.success {
    background-color: rgba(25, 135, 84, 0.95);
}

.toast.info {
    background-color: rgba(13, 110, 253, 0.95);
}


/* ==========================================================================
   8. AI 요약 (RAG) 컨테이너
   ========================================================================== */
.ai-summary-container {
    background-color: var(--card-bg-color); border: 1px solid var(--card-border-color);
    border-radius: 8px; padding: 20px; margin-bottom: 25px;
    font-size: 15px; line-height: 1.7; color: var(--text-color);
    display: none;
    transition: all 0.3s ease;
}

//-- START : 신규 추가
/* 스트리밍 중 마크다운 요소 스타일 */
.ai-summary-container h1,
.ai-summary-container h2,
.ai-summary-container h3 {
    margin-top: 1em;
    margin-bottom: 0.5em;
    font-weight: 600;
}

.ai-summary-container p {
    margin-bottom: 1em;
    line-height: 1.6;
}

.ai-summary-container ul,
.ai-summary-container ol {
    margin-bottom: 1em;
    padding-left: 2em;
}

.ai-summary-container strong {
    font-weight: 700;
}

.ai-summary-container code {
    background-color: var(--meta-tag-bg-color);
    padding: 2px 4px;
    border-radius: 4px;
    font-family: monospace;
    font-size: 0.9em;
}

.ai-summary-container pre {
    background-color: var(--meta-tag-bg-color);
    padding: 1em;
    border-radius: 6px;
    overflow-x: auto;
    margin-bottom: 1em;
}
//-- END : 신규 추가

.ai-summary-container.done { animation: fadeIn 0.5s ease-in-out; }
@keyframes fadeIn { from { opacity: 0.5; } to { opacity: 1; } }

.ai-summary-container p.ai-meta {
    font-size: 13px; color: var(--text-color-secondary); font-style: italic;
    margin: 5px 0 0 0; padding: 0; line-height: 1.4; text-align: right;
}
.ai-summary-container p.ai-meta:first-of-type { font-weight: 500; }

.ai-references { margin-top: 15px; padding-top: 15px; border-top: 1px solid var(--border-color); font-size: 13px; color: var(--text-color-secondary); }
.ai-references strong { display: block; margin-bottom: 8px; color: var(--text-color); }
.ai-references ul { list-style: none; padding: 0; margin: 0; display: flex; flex-wrap: wrap; gap: 10px; }
.ai-references li {
    background-color: var(--bg-color-page); padding: 4px 10px; border-radius: 15px;
    display: flex; align-items: center; gap: 5px; transition: background-color 0.2s;
}
.ai-references li:hover { background-color: var(--border-color); }
.ai-references a {
    color: var(--link-color); text-decoration: none; max-width: 200px;
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.ai-references .ref-num { font-weight: bold; color: var(--search-button-bg-color); font-size: 11px; }
body.dark-mode .ai-references li { background-color: #333; }
body.dark-mode .ai-references li:hover { background-color: #444; }

.ai-content h1, .ai-content h2, .ai-content h3, .ai-content h4 {
    margin-top: 1.5em; margin-bottom: 0.5em; font-weight: 700; color: var(--text-color); line-height: 1.3;
}
.ai-content h3 { font-size: 1.1rem; border-bottom: 1px solid var(--border-color); padding-bottom: 5px; }
.ai-content p { margin-bottom: 1em; }
.ai-content ul, .ai-content ol { margin-bottom: 1em; padding-left: 20px; }
.ai-content strong { font-weight: 700; color: var(--search-button-bg-color); }
.ai-content pre {
    background-color: var(--meta-tag-bg-color); padding: 10px; border-radius: 5px; overflow-x: auto; font-size: 0.9em;
}

.followup-container { margin-top: 20px; display: flex; flex-direction: column; gap: 8px; }
.followup-btn {
    background-color: var(--bg-color-page); border: 1px solid var(--border-color);
    padding: 10px 15px; border-radius: 20px; text-align: left; cursor: pointer;
    font-size: 14px; color: var(--text-color); transition: all 0.2s;
    display: flex; align-items: center;
}
.followup-btn:hover { background-color: var(--border-color); }
.followup-btn::before { content: "✨"; margin-right: 8px; }

/* 음성 모달 (Script에서 사용) */
.voice-modal {
    position: fixed; top: 0; left: 0; width: 100%; height: 100%;
    background-color: rgba(0, 0, 0, 0.85); z-index: 2000;
    display: flex; justify-content: center; align-items: center; backdrop-filter: blur(5px);
}
.voice-modal[hidden] { display: none !important; }

.voice-content { text-align: center; color: white; width: 100%; max-width: 400px; }
.voice-status { font-size: 20px; margin-bottom: 30px; font-weight: 500; }
.voice-result { min-height: 40px; margin-top: 20px; font-size: 16px; opacity: 0.8; padding: 0 20px;}
.voice-visualizer { display: flex; justify-content: center; align-items: center; gap: 5px; height: 50px; }
.bar {
    width: 8px; background-color: white; border-radius: 4px;
    animation: sound 0s infinite ease-in-out alternate; height: 10px;
}
.voice-modal.listening .bar { animation-duration: 0.4s; }
.voice-modal.listening .bar:nth-child(1) { animation-delay: 0.1s; height: 15px; }
.voice-modal.listening .bar:nth-child(2) { animation-delay: 0.2s; height: 30px; }
.voice-modal.listening .bar:nth-child(3) { animation-delay: 0.3s; height: 50px; }
.voice-modal.listening .bar:nth-child(4) { animation-delay: 0.2s; height: 30px; }
.voice-modal.listening .bar:nth-child(5) { animation-delay: 0.1s; height: 15px; }
@keyframes sound { 0% { height: 10px; opacity: 0.5; } 100% { height: 60px; opacity: 1; } }

.voice-close-btn {
    margin-top: 40px; padding: 10px 30px; border-radius: 30px; border: 1px solid rgba(255,255,255,0.3);
    background: transparent; color: white; cursor: pointer; font-size: 16px; transition: background 0.2s;
}
.voice-close-btn:hover { background: rgba(255,255,255,0.2); }

/* ==========================================================================
   9. AI 답변 더보기/접기 (Expand/Collapse)
   ========================================================================== */
.ai-content-wrapper {
    position: relative;
    transition: max-height 0.3s ease;
}

.ai-content-wrapper.collapsed {
    max-height: 150px; /* 접혔을 때 높이 */
    overflow: hidden;
    mask-image: linear-gradient(to bottom, black 60%, transparent 100%);
    -webkit-mask-image: linear-gradient(to bottom, black 60%, transparent 100%);
}

.ai-content-wrapper.expanded {
    max-height: none;
    mask-image: none;
    -webkit-mask-image: none;
}

.read-more-btn {
    display: block;
    margin: 10px auto 0;
    padding: 8px 20px;
    background-color: var(--bg-color-page);
    border: 1px solid var(--border-color);
    border-radius: 20px;
    color: var(--link-color);
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    transition: background-color 0.2s;
}
.read-more-btn:hover {
    background-color: var(--border-color);
}

/* ==========================================================================
   10. AI 답변에 인용된 문서 강조 스타일
   ========================================================================== */

.result-card.cited-card {
    border: 2px solid var(--search-button-bg-color); /* 파란색 테두리 */
    background-color: rgba(66, 133, 244, 0.05); /* 아주 연한 파란 배경 */
    position: relative;
    transition: all 0.3s ease;
}

.result-card.cited-card::before {
    content: "AI 인용 문서";
    position: absolute;
    top: -10px;
    right: 20px;
    background-color: var(--search-button-bg-color);
    color: white;
    font-size: 11px;
    padding: 2px 8px;
    border-radius: 10px;
    font-weight: bold;
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
}

/* AI 답변 내의 인용 번호 링크 스타일 */
.citation-link {
    color: var(--search-button-bg-color);
    font-weight: bold;
    cursor: pointer;
    margin: 0 2px;
    text-decoration: none;
    padding: 0 2px; /* 클릭 영역 확보 */
    border-radius: 4px;
    transition: background-color 0.2s;
}
.citation-link:hover {
    text-decoration: underline;
    background-color: rgba(0,0,0,0.05);
    border-radius: 4px;
}

/* ✅ [추가] 다크모드 전용 호버 스타일 (대비 강화) */
body.dark-mode .citation-link:hover {
    background-color: rgba(255, 255, 255, 0.15); /* 더 밝은 반투명 흰색 */
    color: #8ab4f8; /* 링크 색상 유지 */
}

