/* ============================================
   Antigravity - 전사 지식 관리 플랫폼 스타일
   ============================================ */

:root {
    /* 색상 팔레트 */
    --primary: #6366f1;
    --primary-hover: #4f46e5;
    --secondary: #475569;
    --accent: #22d3ee;

    /* 다크 테마 */
    --bg-primary: #0f172a;
    --bg-secondary: #1e293b;
    --bg-tertiary: #334155;
    --bg-card: #1e293b;

    --text-primary: #f1f5f9;
    --text-secondary: #94a3b8;
    --text-muted: #64748b;

    --border: #334155;
    --success: #22c55e;
    --warning: #f59e0b;
    --error: #ef4444;
    --info: #3b82f6;
    /* Blue-500 */

    /* 간격 */
    --sidebar-width: 280px;
    --header-height: 60px;
    --radius: 8px;
}

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

body {
    font-family: 'Inter', 'Noto Sans KR', -apple-system, BlinkMacSystemFont, sans-serif;
    background: var(--bg-primary);
    color: var(--text-primary);
    min-height: 100vh;
}

/* ============================================
   헤더
   ============================================ */
.header {
    height: var(--header-height);
    background: var(--bg-secondary);
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 24px;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    z-index: 100;
}

.header-left {
    display: flex;
    align-items: center;
    gap: 16px;
}

.logo {
    font-size: 1.5rem;
    font-weight: 700;
    background: linear-gradient(135deg, var(--primary), var(--accent));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
}

.tagline {
    color: var(--text-secondary);
    font-size: 0.875rem;
}

.header-right {
    display: flex;
    align-items: center;
    gap: 12px;
}

.header-link {
    color: var(--text-secondary);
    text-decoration: none;
    padding: 8px 12px;
    border-radius: var(--radius);
    transition: all 0.2s;
}

.header-link:hover {
    background: var(--bg-tertiary);
    color: var(--text-primary);
}

/* ============================================
   메인 레이아웃
   ============================================ */
.main-container {
    display: flex;
    margin-top: var(--header-height);
    min-height: calc(100vh - var(--header-height));
}

/* ============================================
   사이드바
   ============================================ */
.sidebar {
    width: var(--sidebar-width);
    background: var(--bg-secondary);
    border-right: 1px solid var(--border);
    padding: 16px;
    overflow-y: auto;
    position: fixed;
    top: var(--header-height);
    bottom: 0;
    left: 0;
}

.sidebar-section {
    margin-bottom: 24px;
}

.section-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 12px;
}

.section-header h3 {
    font-size: 0.875rem;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

/* 카테고리 트리 */
.category-tree {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.category-item {
    padding: 8px 12px;
    border-radius: var(--radius);
    cursor: pointer;
    transition: all 0.2s;
    display: flex;
    align-items: center;
    gap: 8px;
}

.category-item:hover {
    background: var(--bg-tertiary);
}

.category-item.active {
    background: var(--primary);
    color: white;
}

/* 레벨별 들여쓰기 및 폰트 크기 조정 */
.category-item.level-1 {
    margin-left: 16px;
    font-size: 0.9em;
}

.category-item.level-2 {
    margin-left: 32px;
    font-size: 0.85em;
}

/* 카테고리 아이템 레이아웃 */
.category-item .cat-name {
    flex: 1;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.category-item .cat-menu-wrapper {
    position: relative;
    margin-left: auto;
}

.category-item .cat-menu-btn {
    opacity: 0;
    padding: 2px 6px;
    background: transparent;
    border: none;
    color: var(--text-secondary);
    cursor: pointer;
    font-size: 1rem;
    border-radius: 4px;
    transition: all 0.2s;
}

.category-item:hover .cat-menu-btn {
    opacity: 1;
}

.category-item .cat-menu-btn:hover {
    background: var(--bg-primary);
    color: var(--text-primary);
}

.category-item.active .cat-menu-btn:hover {
    background: rgba(0, 0, 0, 0.2);
}

/* 카테고리 드롭다운 메뉴 */
.cat-menu {
    position: absolute;
    top: 100%;
    right: 0;
    background: var(--bg-tertiary);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    min-width: 150px;
    z-index: 100;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
}

.cat-menu button {
    display: block;
    width: 100%;
    padding: 10px 14px;
    text-align: left;
    background: transparent;
    border: none;
    color: var(--text-primary);
    cursor: pointer;
    font-size: 0.813rem;
    transition: background 0.2s;
}

.cat-menu button:hover {
    background: var(--bg-secondary);
}

.cat-menu button:first-child {
    border-radius: var(--radius) var(--radius) 0 0;
}

.cat-menu button:last-child {
    border-radius: 0 0 var(--radius) var(--radius);
    color: var(--error);
}

/* 파일 목록 */
.file-list {
    display: flex;
    flex-direction: column;
    gap: 4px;
    max-height: 300px;
    overflow-y: auto;
}

.file-item {
    padding: 8px 12px;
    border-radius: var(--radius);
    background: var(--bg-tertiary);
    font-size: 0.813rem;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
}

.file-item .filename {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    flex: 1;
}

.file-item .delete-btn {
    opacity: 0;
    transition: opacity 0.2s;
}

.file-item:hover .delete-btn {
    opacity: 1;
}

/* ============================================
   메인 콘텐츠
   ============================================ */
.main-content {
    flex: 1;
    margin-left: var(--sidebar-width);
    padding: 24px;
    display: flex;
    flex-direction: column;
}

/* 탭 네비게이션 */
.tab-nav {
    display: flex;
    gap: 8px;
    margin-bottom: 24px;
}

.tab-btn {
    padding: 10px 20px;
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    color: var(--text-secondary);
    cursor: pointer;
    transition: all 0.2s;
    font-size: 0.875rem;
}

.tab-btn:hover {
    background: var(--bg-tertiary);
    color: var(--text-primary);
}

.tab-btn.active {
    background: var(--primary);
    border-color: var(--primary);
    color: white;
}

.tab-content {
    display: none;
    flex: 1;
    flex-direction: column;
}

.tab-content.active {
    display: flex;
}

/* ============================================
   채팅 탭
   ============================================ */
.chat-header {
    margin-bottom: 16px;
}

.chat-messages {
    flex: 1;
    background: var(--bg-secondary);
    border-radius: var(--radius);
    padding: 24px;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 16px;
    min-height: 400px;
    max-height: calc(100vh - 320px);
}

/* 메시지가 하단부터 쌓이도록 */
.chat-messages>*:first-child {
    margin-top: auto;
}

.chat-messages>.welcome-message {
    margin: auto;
    /* 수직/수평 중앙 정렬 */
}

.welcome-message {
    text-align: center;
    padding: 48px;
    color: var(--text-secondary);
}

.welcome-icon {
    font-size: 3rem;
    margin-bottom: 16px;
}

.welcome-message h2 {
    margin-bottom: 8px;
    color: var(--text-primary);
}

.message {
    max-width: 80%;
    padding: 12px 16px;
    border-radius: var(--radius);
    line-height: 1.5;
}

.message.user {
    background: var(--primary);
    color: white;
    align-self: flex-end;
    border-bottom-right-radius: 4px;
}

.message.assistant {
    background: var(--bg-tertiary);
    align-self: flex-start;
    border-bottom-left-radius: 4px;
}

.message-sources {
    margin-top: 12px;
    padding-top: 12px;
    border-top: 1px solid var(--border);
    font-size: 0.813rem;
    color: var(--text-secondary);
}

.feedback-buttons {
    margin-top: 12px;
    display: flex;
    gap: 8px;
}

.feedback-btn {
    padding: 4px 12px;
    border-radius: 20px;
    border: 1px solid var(--border);
    background: transparent;
    color: var(--text-secondary);
    font-size: 0.75rem;
    cursor: pointer;
    transition: all 0.2s;
}

.feedback-btn:hover {
    background: var(--bg-tertiary);
}

.feedback-btn.positive:hover {
    border-color: var(--success);
    color: var(--success);
}

.feedback-btn.negative:hover {
    border-color: var(--error);
    color: var(--error);
}

/* 로딩 인디케이터 */
.loading-indicator {
    display: flex;
    align-items: center;
    gap: 12px;
}

.loading-spinner {
    width: 20px;
    height: 20px;
    border: 2px solid var(--border);
    border-top-color: var(--primary);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

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

.loading-text {
    color: var(--text-secondary);
    animation: pulse 1.5s ease-in-out infinite;
}

@keyframes pulse {

    0%,
    100% {
        opacity: 1;
    }

    50% {
        opacity: 0.5;
    }
}

.chat-input-container {
    display: flex;
    gap: 12px;
    margin-top: 16px;
}

.chat-input {
    flex: 1;
    padding: 12px 16px;
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    color: var(--text-primary);
    font-size: 1rem;
}

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

/* ============================================
   업로드 탭
   ============================================ */
.upload-area {
    border: 2px dashed var(--border);
    border-radius: var(--radius);
    padding: 48px;
    text-align: center;
    cursor: pointer;
    transition: all 0.2s;
    background: var(--bg-secondary);
}

.upload-area:hover,
.upload-area.dragover {
    border-color: var(--primary);
    background: rgba(99, 102, 241, 0.1);
}

.upload-icon {
    font-size: 3rem;
    margin-bottom: 16px;
}

.upload-form {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-top: 16px;
}

.upload-form label {
    color: var(--text-secondary);
}

.upload-progress {
    margin-top: 16px;
    display: flex;
    align-items: center;
    gap: 12px;
}

.progress-bar {
    flex: 1;
    height: 8px;
    background: var(--bg-tertiary);
    border-radius: 4px;
    overflow: hidden;
}

.progress-fill {
    height: 100%;
    background: var(--primary);
    width: 0%;
    transition: width 0.3s;
}

.upload-file-list {
    margin-top: 16px;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.upload-file-item {
    padding: 12px;
    background: var(--bg-secondary);
    border-radius: var(--radius);
    display: flex;
    align-items: center;
    justify-content: space-between;
}

/* 파일 썸네일 그리드 */
.file-thumbnails {
    display: flex;
    flex-wrap: wrap;
    gap: 16px;
    justify-content: center;
    padding: 16px;
}

.file-thumbnail {
    position: relative;
    width: 100px;
    padding: 16px 12px;
    background: var(--bg-tertiary);
    border-radius: var(--radius);
    text-align: center;
    transition: all 0.2s;
}

.file-thumbnail:hover {
    background: var(--primary);
    transform: translateY(-2px);
}

.file-thumb-icon {
    font-size: 2.5rem;
    margin-bottom: 8px;
}

.file-thumb-name {
    font-size: 0.75rem;
    font-weight: 500;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.file-thumb-size {
    font-size: 0.688rem;
    color: var(--text-muted);
    margin-top: 4px;
}

.file-thumb-remove {
    position: absolute;
    top: -8px;
    right: -8px;
    width: 22px;
    height: 22px;
    border: none;
    background: var(--error);
    color: white;
    border-radius: 50%;
    font-size: 14px;
    cursor: pointer;
    opacity: 0;
    transition: opacity 0.2s;
    display: flex;
    align-items: center;
    justify-content: center;
}

.file-thumbnail:hover .file-thumb-remove {
    opacity: 1;
}

.add-more-hint {
    color: var(--text-muted);
    font-size: 0.875rem;
    margin-top: 16px;
}

.upload-hint {
    color: var(--text-muted);
    font-size: 0.813rem;
}

/* ============================================
   피드백 탭
   ============================================ */
.feedback-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 16px;
}

.feedback-list {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.feedback-item {
    padding: 16px;
    background: var(--bg-secondary);
    border-radius: var(--radius);
    border-left: 4px solid var(--primary);
    cursor: pointer;
    transition: all 0.2s;
}

.feedback-item:hover {
    background: var(--bg-tertiary);
}

.feedback-item.pending {
    border-left-color: var(--warning);
}

.feedback-item.applied {
    border-left-color: var(--success);
}

.feedback-item.rejected {
    border-left-color: var(--error);
}

.feedback-question {
    font-weight: 500;
    margin-bottom: 8px;
}

.feedback-meta {
    font-size: 0.813rem;
    color: var(--text-secondary);
    display: flex;
    gap: 16px;
}

/* ============================================
   버튼
   ============================================ */
.btn {
    padding: 10px 20px;
    border-radius: var(--radius);
    border: none;
    cursor: pointer;
    font-size: 0.875rem;
    font-weight: 500;
    transition: all 0.2s;
}

.btn-primary {
    background: var(--primary);
    color: white;
}

.btn-primary:hover {
    background: var(--primary-hover);
}

.btn-primary:disabled {
    background: var(--bg-tertiary);
    cursor: not-allowed;
}

.btn-secondary {
    background: var(--bg-tertiary);
    color: var(--text-primary);
}

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

.btn-icon {
    width: 28px;
    height: 28px;
    padding: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--bg-tertiary);
    border: none;
    border-radius: var(--radius);
    color: var(--text-primary);
    cursor: pointer;
    font-size: 1.2rem;
    transition: all 0.2s;
}

.btn-icon:hover {
    background: var(--primary);
}

.btn-danger {
    background: var(--error);
    color: white;
}

/* ============================================
   입력 필드
   ============================================ */
input,
textarea,
button,
select {
    font-family: inherit;
}

.text-input,
.select-input,
textarea {
    padding: 10px 14px;
    background: var(--bg-tertiary);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    color: var(--text-primary);
    font-size: 0.875rem;
    font-family: inherit;
    line-height: 1.5;
}

.text-input:focus,
.select-input:focus,
textarea:focus {
    outline: none;
    border-color: var(--primary);
}

.select-input {
    min-width: 200px;
}

/* ============================================
   모달
   ============================================ */
.modal {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.7);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
}

.modal.hidden {
    display: none;
}

.modal-content {
    background: var(--bg-secondary);
    border-radius: var(--radius);
    padding: 24px;
    min-width: 400px;
    max-width: 90%;
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.modal-large {
    min-width: 600px;
    max-height: 80vh;
    overflow-y: auto;
}

.modal-content h3 {
    margin-bottom: 8px;
}

.modal-actions {
    display: flex;
    justify-content: flex-end;
    gap: 12px;
    margin-top: 8px;
}

/* ============================================
   유틸리티
   ============================================ */
.hidden {
    display: none !important;
}

.loading {
    opacity: 0.5;
    pointer-events: none;
}

/* 스크롤바 */
::-webkit-scrollbar {
    width: 8px;
}

::-webkit-scrollbar-track {
    background: var(--bg-primary);
}

::-webkit-scrollbar-thumb {
    background: var(--bg-tertiary);
    border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
    background: var(--secondary);
}

/* ============================================
   지침 모달
============================================ */
.instruction-category-name {
    font-size: 1.1rem;
    color: var(--primary);
    margin-bottom: 16px;
    font-weight: 600;
}

.instruction-content label {
    display: block;
    color: var(--text-secondary);
    margin-bottom: 8px;
}

.instruction-textarea {
    width: 100%;
    min-height: 200px;
    background: var(--bg-tertiary);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 16px;
    font-family: 'Consolas', monospace;
    font-size: 0.875rem;
    color: var(--text-primary);
    resize: vertical;
    line-height: 1.6;
}

.instruction-textarea:focus {
    outline: none;
    border-color: var(--primary);
}

.instruction-history {
    margin-top: 16px;
    border-top: 1px solid var(--border);
    padding-top: 16px;
}

.instruction-history label {
    color: var(--text-secondary);
    margin-bottom: 8px;
    display: block;
}

#historyList {
    max-height: 200px;
    overflow-y: auto;
}

.history-item {
    padding: 12px;
    background: var(--bg-tertiary);
    border-radius: var(--radius);
    margin-bottom: 8px;
    font-size: 0.875rem;
}

.history-item-header {
    display: flex;
    justify-content: space-between;
    margin-bottom: 8px;
    color: var(--text-secondary);
}

.history-item-version {
    font-weight: 600;
    color: var(--primary);
}

.category-instruction-btn {
    background: transparent;
    border: none;
    color: var(--text-secondary);
    cursor: pointer;
    padding: 4px 8px;
    font-size: 0.75rem;
    border-radius: 4px;
    transition: all 0.2s;
}

.category-instruction-btn:hover {
    background: var(--primary);
    color: white;
}

/* 카테고리 토글 아이콘 */
.toggle-icon {
    font-size: 0.625rem;
    color: var(--text-muted);
    margin-right: 4px;
    transition: transform 0.2s;
}

.btn-info {
    background: var(--info);
    color: white;
}

.btn-info:hover {
    filter: brightness(1.1);
}

/* 비교 모달 내 강조 텍스트 (변경 사항) */
#comparisonModal strong {
    color: var(--warning);
    font-weight: 800;
    text-decoration: underline;
    text-underline-offset: 4px;
}

/* 피드백 상세 모달 스타일 */
.feedback-detail-header {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 24px;
    padding-bottom: 16px;
    border-bottom: 1px solid var(--border);
}

.feedback-id {
    font-family: monospace;
    color: var(--text-muted);
}

.feedback-date {
    font-size: 0.875rem;
    color: var(--text-secondary);
    flex: 1;
}

.feedback-status-badge {
    padding: 4px 10px;
    border-radius: 12px;
    font-size: 0.75rem;
    font-weight: 600;
}

.feedback-status-badge.pending {
    background: var(--bg-tertiary);
    color: var(--text-muted);
}

.feedback-status-badge.reviewed {
    background: rgba(59, 130, 246, 0.2);
    color: #60a5fa;
}

.feedback-status-badge.applied {
    background: rgba(34, 197, 94, 0.2);
    color: #4ade80;
}

.feedback-status-badge.rejected {
    background: rgba(239, 68, 68, 0.2);
    color: #f87171;
}

.feedback-section {
    margin-bottom: 20px;
}

.section-label {
    font-size: 0.875rem;
    font-weight: 600;
    color: var(--text-muted);
    margin-bottom: 8px;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.section-content {
    background: var(--bg-secondary);
    padding: 12px 16px;
    border-radius: var(--radius);
    line-height: 1.6;
    border: 1px solid var(--border);
}

.feedback-metrics {
    display: flex;
    gap: 16px;
    margin-bottom: 8px;
    font-size: 0.9rem;
}

.metric strong {
    margin-left: 4px;
}

.user-comment {
    background: rgba(245, 158, 11, 0.1);
    color: var(--warning);
    padding: 12px;
    border-radius: var(--radius);
    border-left: 4px solid var(--warning);
    font-style: italic;
}

.text-success {
    color: var(--success);
}

.text-error {
    color: var(--error);
}

/* ============================================
   사용자 로그인 UI
   ============================================ */
.user-info {
    display: flex;
    align-items: center;
    gap: 10px;
}

.user-avatar {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    object-fit: cover;
    border: 2px solid var(--primary);
}

.user-name {
    font-size: 0.875rem;
    color: var(--text-primary);
    max-width: 150px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.btn-small {
    padding: 6px 12px;
    font-size: 0.75rem;
}