/* ============================================================
   Deep Research — 패널, 계획 카드, 브라우즈 칩, 보고서 뷰어
   ============================================================ */

/* ── 1. 우측 리서치 패널 (Canvas 패널과 동일한 슬라이드인 패턴) ── */
.research-panel {
    position: fixed;
    top: 0;
    right: 0;
    width: 60%;
    height: 100vh;
    background: #141414;
    border-left: 1px solid rgba(255, 255, 255, 0.08);
    display: flex;
    flex-direction: column;
    z-index: 900;
    transform: translateX(100%);
    transition: transform 0.35s cubic-bezier(0.25, 0.8, 0.25, 1);
    overflow: hidden;
}

.research-panel.active {
    transform: translateX(0);
    box-shadow: -12px 0 40px rgba(0, 0, 0, 0.6);
}

#main-content.research-open {
    margin-right: 60%;
    transition: margin-right 0.35s cubic-bezier(0.25, 0.8, 0.25, 1);
}

/* ── 2. 패널 헤더 ── */
.rp-header {
    height: 64px;
    padding: 0 20px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    background: #1a1a1a;
    border-bottom: 1px solid rgba(255, 255, 255, 0.06);
    flex-shrink: 0;
}

.rp-title {
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: 15px;
    font-weight: 600;
    color: #ececec;
}

.rp-title svg {
    width: 18px;
    height: 18px;
    color: #4b90ff;
}

.rp-header-actions {
    display: flex;
    align-items: center;
    gap: 4px;
}

/* ── 3. 패널 바디 ── */
.rp-body {
    flex: 1;
    overflow-y: auto;
    padding: 20px 24px;
    display: flex;
    flex-direction: column;
    gap: 20px;
}

.rp-body::-webkit-scrollbar { width: 6px; }
.rp-body::-webkit-scrollbar-track { background: transparent; }
.rp-body::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.1); border-radius: 3px; }

/* ── 4. 사고 과정 섹션 ── */
.rp-thinking {
    background: rgba(75, 144, 255, 0.04);
    border: 1px solid rgba(75, 144, 255, 0.12);
    border-radius: 12px;
    padding: 16px;
}

.rp-thinking-header {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 12px;
}

.rp-pulse {
    width: 10px;
    height: 10px;
    background: #4b90ff;
    border-radius: 50%;
    flex-shrink: 0;
    box-shadow: 0 0 0 0 rgba(75, 144, 255, 0.6);
    animation: rp-pulse 1.5s infinite;
}

@keyframes rp-pulse {
    0%   { box-shadow: 0 0 0 0 rgba(75, 144, 255, 0.6); }
    70%  { box-shadow: 0 0 0 10px rgba(75, 144, 255, 0); }
    100% { box-shadow: 0 0 0 0 rgba(75, 144, 255, 0); }
}

#rp-progress-text {
    font-size: 14px;
    color: #9aa0a6;
    font-style: italic;
}

.rp-thinking-log {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.rp-step {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 13px;
    color: #4b90ff;
    animation: fadeIn 0.3s ease-out;
}

.rp-step svg {
    width: 14px;
    height: 14px;
    flex-shrink: 0;
}

/* ── 5. 수집 출처 그리드 ── */
.rp-sources {
    background: rgba(255, 255, 255, 0.02);
    border: 1px solid rgba(255, 255, 255, 0.06);
    border-radius: 12px;
    padding: 14px 16px;
}

.rp-sources-title {
    font-size: 12px;
    font-weight: 600;
    color: #9aa0a6;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    margin-bottom: 0;
    display: flex;
    align-items: center;
    gap: 6px;
}

.rp-sources-count {
    background: rgba(75, 144, 255, 0.2);
    color: #4b90ff;
    font-size: 11px;
    padding: 1px 7px;
    border-radius: 10px;
}

.browse-chips-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 8px;
}

.browse-chip {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 12px;
    background: rgba(255, 255, 255, 0.03);
    border: 1px solid rgba(255, 255, 255, 0.07);
    border-radius: 10px;
    text-decoration: none;
    color: var(--text-main, #ececec);
    transition: all 0.2s ease;
    overflow: hidden;
    animation: fadeIn 0.4s ease-out;
}

.browse-chip:hover {
    background: rgba(255, 255, 255, 0.07);
    border-color: rgba(75, 144, 255, 0.3);
    transform: translateY(-2px);
}

.browse-chip .favicon {
    width: 16px;
    height: 16px;
    border-radius: 4px;
    flex-shrink: 0;
    background: rgba(255,255,255,0.1);
}

.browse-chip-body {
    display: flex;
    flex-direction: column;
    gap: 2px;
    min-width: 0;
}

.browse-chip-domain {
    font-size: 11px;
    color: #9aa0a6;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.browse-chip-title {
    font-size: 12px;
    color: #ececec;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.rp-sources-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.rp-sources .browse-chips-grid:not(.hidden) {
    margin-top: 12px;
}

.rp-sources-toggle {
    font-size: 11.5px;
    color: #4b90ff;
    background: rgba(75, 144, 255, 0.1);
    border: 1px solid rgba(75, 144, 255, 0.2);
    border-radius: 12px;
    padding: 3px 10px;
    cursor: pointer;
    transition: all 0.2s;
    white-space: nowrap;
    flex-shrink: 0;
}

.rp-sources-toggle:hover {
    background: rgba(75, 144, 255, 0.2);
    border-color: rgba(75, 144, 255, 0.4);
}

/* ── 6. 최종 보고서 뷰어 ── */
.rp-report {
    color: #d4d8df;
    font-size: 15px;
    line-height: 1.8;
    padding-bottom: 40px;
}

.rp-report h1 {
    font-size: 22px;
    font-weight: 700;
    color: #fff;
    margin: 32px 0 14px;
    line-height: 1.3;
    padding-bottom: 10px;
    border-bottom: 2px solid rgba(75, 144, 255, 0.3);
}

.rp-report h2 {
    font-size: 18px;
    font-weight: 600;
    color: #e0e4ef;
    margin: 28px 0 10px;
    line-height: 1.3;
    padding-left: 12px;
    border-left: 3px solid #4b90ff;
}

.rp-report h3 {
    font-size: 15px;
    font-weight: 600;
    color: #b8c5d4;
    margin: 20px 0 8px;
    line-height: 1.3;
}

.rp-report p       { margin-bottom: 14px; }
.rp-report strong  { color: #fff; font-weight: 600; }
.rp-report em      { color: #b0bfd0; font-style: italic; }

.rp-report ul, .rp-report ol { margin: 8px 0 16px 24px; }
.rp-report li { margin-bottom: 6px; }
.rp-report ul > li::marker { color: #4b90ff; }

.rp-report a       { color: #4b90ff; text-decoration: none; }
.rp-report a:hover { text-decoration: underline; }

.rp-report hr {
    border: none;
    border-top: 1px solid rgba(255, 255, 255, 0.08);
    margin: 28px 0;
}

.rp-report blockquote {
    background: rgba(75, 144, 255, 0.05);
    border-left: 3px solid #4b90ff;
    border-radius: 0 8px 8px 0;
    padding: 12px 16px;
    color: #9aa0a6;
    margin: 16px 0;
    font-style: italic;
}

.rp-report code {
    background: rgba(255, 255, 255, 0.07);
    color: #e8d5a3;
    padding: 2px 5px;
    border-radius: 4px;
    font-family: 'Consolas', monospace;
    font-size: 0.88em;
}

.rp-report pre {
    background: #1e1f20;
    border: 1px solid rgba(255, 255, 255, 0.08);
    border-radius: 8px;
    padding: 14px;
    overflow-x: auto;
    margin: 12px 0;
}

/* — 표 래퍼 (JS에서 주입) — */
.rp-table-wrap {
    overflow-x: auto;
    margin: 16px 0 24px;
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 10px;
    -webkit-overflow-scrolling: touch;
}

.rp-table-wrap table {
    width: 100%;
    border-collapse: collapse;
    font-size: 13.5px;
    margin: 0;
}

.rp-table-wrap thead tr {
    background: rgba(75, 144, 255, 0.12);
}

.rp-table-wrap th {
    padding: 10px 14px;
    text-align: left;
    font-weight: 600;
    color: #c8d5ef;
    font-size: 12.5px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
    white-space: nowrap;
}

.rp-table-wrap td {
    padding: 10px 14px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.05);
    color: #c8cdd5;
    vertical-align: top;
    line-height: 1.6;
}

.rp-table-wrap tr:last-child td   { border-bottom: none; }
.rp-table-wrap tbody tr:nth-child(odd) { background: rgba(255, 255, 255, 0.015); }
.rp-table-wrap tbody tr:hover     { background: rgba(75, 144, 255, 0.06); transition: background 0.15s; }

/* ── 6-1. 보고서 하단 참고자료 (Sources) 섹션 ── */
.rp-sources-section {
    opacity: 0.55;
    font-size: 12.5px;
    line-height: 1.5;
    border-top: 1px solid rgba(255, 255, 255, 0.07);
    padding-top: 16px;
    margin-top: 24px;
}

.rp-sources-section p strong {
    font-size: 11px;
    font-weight: 700;
    color: #9aa0a6;
    text-transform: uppercase;
    letter-spacing: 0.08em;
}

.rp-sources-section ol {
    margin: 8px 0 0 18px;
    padding: 0;
}

.rp-sources-section li {
    margin-bottom: 3px;
    line-height: 1.45;
}

.rp-sources-section a {
    color: #7aa8d8;
    text-decoration: none;
}

.rp-sources-section a:hover {
    text-decoration: underline;
    opacity: 1;
}

/* ── 7. Citation 뱃지 (보고서 내 인용) ── */
.citation-badge {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 18px;
    height: 18px;
    padding: 0 4px;
    background: rgba(75, 144, 255, 0.15);
    color: #4b90ff;
    font-size: 11px;
    font-weight: 600;
    border-radius: 9px;
    margin-left: 3px;
    vertical-align: super;
    cursor: pointer;
    text-decoration: none;
    transition: background 0.2s;
}

.citation-badge:hover {
    background: rgba(75, 144, 255, 0.35);
    text-decoration: none;
}

/* ── 8. TOC 드롭다운 ── */
.rp-toc-dropdown {
    position: absolute;
    top: 64px;
    right: 8px;
    background: #2a2a2a;
    border: 1px solid rgba(255,255,255,0.1);
    border-radius: 12px;
    box-shadow: 0 8px 24px rgba(0,0,0,0.4);
    z-index: 100;
    min-width: 220px;
    max-width: 300px;
    max-height: 360px;
    overflow-y: auto;
    padding: 8px;
    animation: fadeIn 0.15s ease-out;
}

.toc-list { display: flex; flex-direction: column; gap: 2px; }

.toc-item {
    display: block;
    padding: 8px 10px;
    border-radius: 7px;
    font-size: 13px;
    color: #ececec;
    text-decoration: none;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    transition: background 0.15s;
}

.toc-item:hover { background: rgba(255,255,255,0.07); }
.toc-item.toc-h2 { padding-left: 20px; font-size: 12px; color: #9aa0a6; }
.toc-item.toc-h3 { padding-left: 32px; font-size: 12px; color: #6e7681; }

/* ── 9. 조사 계획 카드 (채팅 피드 내) ── */
.research-plan-card {
    background: rgba(255, 255, 255, 0.03);
    border: 1px solid rgba(75, 144, 255, 0.2);
    border-radius: 16px;
    padding: 20px;
    margin: 4px 0;
    max-width: 560px;
}

.research-plan-card.loading {
    display: flex;
    align-items: center;
    gap: 12px;
    color: #9aa0a6;
    font-size: 14px;
}

.plan-spinner {
    width: 18px;
    height: 18px;
    border: 2px solid rgba(75,144,255,0.2);
    border-top-color: #4b90ff;
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
    flex-shrink: 0;
}

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

.plan-header {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 16px;
}

.plan-header svg {
    width: 18px;
    height: 18px;
    color: #4b90ff;
    flex-shrink: 0;
}

.plan-header h4 {
    font-size: 14px;
    font-weight: 600;
    color: #ececec;
    margin: 0;
    line-height: 1.4;
}

.plan-steps {
    list-style: none;
    padding: 0;
    margin: 0 0 14px 0;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.plan-step {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 13px;
    color: #ececec;
}

.plan-step svg {
    width: 14px;
    height: 14px;
    color: #34a853;
    flex-shrink: 0;
}

.plan-step-dur {
    margin-left: auto;
    font-size: 12px;
    color: #9aa0a6;
    white-space: nowrap;
}

.plan-meta {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 12px;
    color: #9aa0a6;
    margin-bottom: 16px;
    padding-top: 10px;
    border-top: 1px solid rgba(255,255,255,0.06);
}

.plan-meta svg {
    width: 14px;
    height: 14px;
    flex-shrink: 0;
}

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

.btn-edit-plan {
    padding: 8px 18px;
    border-radius: 20px;
    border: 1px solid rgba(255,255,255,0.15);
    background: transparent;
    color: #9aa0a6;
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s;
}

.btn-edit-plan:hover {
    background: rgba(255,255,255,0.07);
    color: #ececec;
}

.btn-start-research {
    padding: 8px 20px;
    border-radius: 20px;
    border: none;
    background: #4b90ff;
    color: white;
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
}

.btn-start-research:hover {
    background: #357ae8;
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(75,144,255,0.3);
}

.plan-starting {
    font-size: 13px;
    color: #9aa0a6;
    font-style: italic;
}

.plan-edit-textarea {
    width: 100%;
    min-height: 80px;
    background: rgba(255,255,255,0.04);
    border: 1px solid rgba(75,144,255,0.3);
    border-radius: 8px;
    color: #ececec;
    font-size: 13px;
    font-family: inherit;
    line-height: 1.6;
    padding: 10px 12px;
    resize: vertical;
    outline: none;
    margin-bottom: 8px;
}

.plan-edit-btns {
    display: flex;
    gap: 8px;
}

.btn-cancel-edit {
    padding: 7px 16px;
    border-radius: 16px;
    border: 1px solid rgba(255,255,255,0.12);
    background: transparent;
    color: #9aa0a6;
    font-size: 12px;
    cursor: pointer;
    transition: all 0.2s;
}

.btn-cancel-edit:hover { background: rgba(255,255,255,0.05); color: #ececec; }

.btn-apply-edit {
    padding: 7px 16px;
    border-radius: 16px;
    border: none;
    background: #4b90ff;
    color: white;
    font-size: 12px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s;
}

.btn-apply-edit:hover { background: #357ae8; }

/* ── 10. 레거시: research-thinking (기존 채팅 피드 내 사고 표시) ── */
.research-thinking {
    background: rgba(255, 255, 255, 0.02);
    border-radius: 12px;
    border: 1px solid rgba(255, 255, 255, 0.05);
    padding: 14px;
    margin-bottom: 16px;
}

.thinking-step {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 6px 0;
    font-size: 13px;
    color: #9aa0a6;
}

.thinking-step.completed { color: #4b90ff; }
.thinking-step.active    { color: #ececec; }

.step-icon {
    width: 16px;
    height: 16px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.step-icon .check-icon { color: #4b90ff; }

.step-icon .pulse-icon {
    width: 8px;
    height: 8px;
    background: #4b90ff;
    border-radius: 50%;
    box-shadow: 0 0 0 0 rgba(75, 144, 255, 0.7);
    animation: pulse 1.5s infinite;
}

@keyframes pulse {
    0%   { transform: scale(0.95); box-shadow: 0 0 0 0 rgba(75, 144, 255, 0.7); }
    70%  { transform: scale(1);    box-shadow: 0 0 0 10px rgba(75, 144, 255, 0); }
    100% { transform: scale(0.95); box-shadow: 0 0 0 0 rgba(75, 144, 255, 0); }
}

/* ── 11. 출처 사이드바 (레거시) ── */
#source-sidebar {
    position: fixed;
    top: 0;
    right: 0;
    width: 360px;
    height: 100vh;
    background: #1e1f20;
    border-left: 1px solid rgba(255, 255, 255, 0.1);
    z-index: 2500;
    transform: translateX(100%);
    transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    display: flex;
    flex-direction: column;
}

#source-sidebar.active { transform: translateX(0); }

.sidebar-content {
    flex: 1;
    overflow-y: auto;
    padding: 20px;
}

.source-card {
    background: rgba(255, 255, 255, 0.03);
    border-radius: 12px;
    padding: 14px;
    margin-bottom: 12px;
    border: 1px solid transparent;
    transition: border-color 0.2s;
    cursor: pointer;
}

.source-card:hover { border-color: rgba(75, 144, 255, 0.3); }

.source-meta {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 12px;
    color: #9aa0a6;
    margin-bottom: 6px;
}

.source-title {
    font-size: 14px;
    font-weight: 500;
    color: #ececec;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

/* Citation Badge in chat text */
.citation-badge {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 18px;
    height: 18px;
    background: rgba(75, 144, 255, 0.15);
    color: #4b90ff;
    font-size: 11px;
    font-weight: 600;
    border-radius: 50%;
    margin-left: 4px;
    vertical-align: super;
    cursor: pointer;
    transition: background 0.2s;
}

.citation-badge:hover { background: rgba(75, 144, 255, 0.3); }

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

/* ── 12. 인용 카드 툴팁 ── */
.citation-tooltip {
    position: fixed;
    z-index: 9999;
    display: flex;
    align-items: center;
    gap: 10px;
    background: #2a2b2d;
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 10px;
    padding: 10px 14px;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.5);
    pointer-events: none;
    max-width: 280px;
    animation: fadeIn 0.15s ease-out;
}

.citation-tooltip.hidden { display: none; }

.citation-tooltip .ct-favicon {
    width: 16px;
    height: 16px;
    border-radius: 3px;
    flex-shrink: 0;
}

.citation-tooltip .ct-body {
    display: flex;
    flex-direction: column;
    gap: 2px;
    min-width: 0;
}

.citation-tooltip .ct-domain {
    font-size: 11px;
    color: #9aa0a6;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.citation-tooltip .ct-title {
    font-size: 12px;
    color: #ececec;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* ── 13. 연구 완료 카드 (채팅 피드 내) ── */
.research-complete-card {
    display: flex;
    align-items: center;
    gap: 14px;
    background: rgba(75, 144, 255, 0.06);
    border: 1px solid rgba(75, 144, 255, 0.22);
    border-radius: 16px;
    padding: 16px 18px;
    max-width: 480px;
    cursor: pointer;
    transition: all 0.2s ease;
}

.research-complete-card:hover {
    background: rgba(75, 144, 255, 0.12);
    border-color: rgba(75, 144, 255, 0.4);
    transform: translateY(-1px);
    box-shadow: 0 4px 16px rgba(75, 144, 255, 0.15);
}

.rcc-icon-wrap {
    position: relative;
    width: 40px;
    height: 40px;
    flex-shrink: 0;
}

.rcc-icon-wrap > svg {
    width: 40px;
    height: 40px;
    color: #4b90ff;
    padding: 8px;
    background: rgba(75, 144, 255, 0.12);
    border-radius: 50%;
}

.rcc-done-badge {
    position: absolute;
    bottom: -2px;
    right: -2px;
    width: 16px;
    height: 16px;
    background: #34a853;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    border: 2px solid #141414;
}

.rcc-done-badge svg {
    width: 10px;
    height: 10px;
    color: white;
}

.rcc-body {
    flex: 1;
    min-width: 0;
}

.rcc-title {
    font-size: 14px;
    font-weight: 600;
    color: #ececec;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    margin-bottom: 3px;
}

.rcc-meta {
    font-size: 12px;
    color: #9aa0a6;
}

.rcc-arrow {
    width: 18px;
    height: 18px;
    color: #9aa0a6;
    flex-shrink: 0;
}

/* ── 14. 사이드바 리서치 진행 중 인디케이터 ── */
.research-indicator {
    display: inline-flex;
    align-items: center;
    margin-right: 4px;
    flex-shrink: 0;
}

.ri-dot {
    display: block;
    width: 7px;
    height: 7px;
    background: #4b90ff;
    border-radius: 50%;
    animation: ri-pulse 1.5s infinite;
}

@keyframes ri-pulse {
    0%, 100% { opacity: 1; transform: scale(1); }
    50%       { opacity: 0.5; transform: scale(0.8); }
}
