/* Google Sans Mono 폰트 정의 */
@font-face {
  font-family: 'Google Sans Mono';
  src: url('../fonts/Google-Sans-Mono-Regular.ttf') format('truetype');
  font-weight: 400;
  font-style: normal;
  font-display: swap;
}

@font-face {
  font-family: 'Google Sans Mono';
  src: url('../fonts/Google-Sans-Mono-Medium.ttf') format('truetype');
  font-weight: 500;
  font-style: normal;
  font-display: swap;
}

@font-face {
  font-family: 'Google Sans Mono';
  src: url('../fonts/Google-Sans-Mono-SemiBold.ttf') format('truetype');
  font-weight: 600;
  font-style: normal;
  font-display: swap;
}

@font-face {
  font-family: 'Google Sans Mono';
  src: url('../fonts/Google-Sans-Mono-Bold.ttf') format('truetype');
  font-weight: 700;
  font-style: normal;
  font-display: swap;
}

@font-face {
  font-family: 'Google Sans Mono';
  src: url('../fonts/Google-Sans-Mono-Italic.ttf') format('truetype');
  font-weight: 400;
  font-style: italic;
  font-display: swap;
}

:root {
  /* 기본: 다크 모드 */
  --bg-main: #0f0f0f;
  --bg-sidebar: #121212;
  --bg-sidebar-header: #1f1f1f;
  --bg-conv-item: #1f1f1f;
  --bg-conv-item-hover: #262626;
  --bg-conv-item-active: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  --bg-new-chat: #2a2a2a;
  --bg-danger: #3a0f0f;
  --bg-chat-header: rgba(15,15,15,0.85);
  --bg-assistant-msg: #1e1e1e;
  --bg-user-msg: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  --bg-input: #1a1a1a;
  --bg-input-focus-border: #4a4a4a;
  --bg-send-btn: #404040;
  --bg-code: #2b2b2b;
  --bg-code-header: #1f1f1f;
  --bg-table: #1c1c1c;
  --bg-table-head: #232323;
  --bg-table-row-even: #202020;
  --text-main: #eaeaea;
  --text-light: #ffffff;
  --text-dark: #1a1a1a;
  --text-link: #667eea;
  --border-main: #3a3a3a;
  --border-code: #30363d;
  --border-table: #303030;
  --sidebar-width: 320px;
  --chat-font-size: 14px; /* 채팅 메시지 글자 크기 */
}

body.light-theme {
  --bg-main: #f0f2f5;
  --bg-sidebar: #ffffff;
  --bg-sidebar-header: #f8f9fa;
  --bg-conv-item: #f8f9fa;
  --bg-conv-item-hover: #e9ecef;
  --bg-conv-item-active: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  --bg-new-chat: #e9ecef;
  --bg-danger: #f8d7da;
  --bg-chat-header: rgba(255,255,255,0.85);
  --bg-assistant-msg: #e9ecef;
  --bg-user-msg: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  --bg-input: #ffffff;
  --bg-input-focus-border: #80bdff;
  --bg-send-btn: #007bff;
  --bg-code: #f8f9fa;
  --bg-code-header: #e9ecef;
  --bg-table: #ffffff;
  --bg-table-head: #f2f2f2;
  --bg-table-row-even: #f9f9f9;
  --text-main: #212529;
  --text-light: #ffffff;
  --text-dark: #1a1a1a;
  --text-link: #0056b3;
  --border-main: #dee2e6;
  --border-code: #dee2e6;
  --border-table: #dee2e6;
}
* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

:root { --sidebar-width: 320px; }

body {
  font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
  background: var(--bg-main);
  color: var(--text-main);
  min-height: 100vh;
  display: flex;
  gap: 10px;
  padding: 0 16px 16px 16px; /* 상단 padding 제거, 헤더를 맨 위에 붙이기 */
  padding-left: calc(var(--sidebar-width) + 16px); /* 고정 사이드바 공간 확보 */
  padding-top: 0; /* 상단 여백 제거 */
}

/* 사이드바 접기 */
body.sidebar-collapsed { --sidebar-width: 0px; }
body.sidebar-collapsed .sidebar { 
  transform: translateX(calc(-100% - 16px)); 
  /* left: 16px을 고려하여 완전히 숨김 */
}
.sidebar { transition: transform .25s ease, width .25s ease; }

.sidebar {
  width: 280px;
  background: var(--bg-sidebar);
  color: var(--text-main);
  border-radius: 16px;
  box-shadow: 0 10px 30px rgba(0,0,0,0.4);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  position: fixed; /* 스크롤 내려도 고정 */
  left: 16px;
  top: 16px;
  bottom: 16px;
  height: calc(100vh - 32px); /* top: 16px + bottom: 16px = 32px */
}

/* 사이드바 내부의 고정 요소들 */
.sidebar > div:not(.chat-section) {
  flex-shrink: 0; /* 고정 크기 유지 */
}

.sidebar-header {
  background: var(--bg-sidebar-header);
  color: var(--text-main);
  padding: 10px 16px;
  text-align: center;
  font-size: 13px;
  font-weight: bold;
  flex-shrink: 0; /* 고정 크기 유지 */
}

.conversation-list {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 4px 0;
  -webkit-overflow-scrolling: touch;
  max-height: calc(100vh - 320px);
}

.conversation-item {
  padding: 4px 12px;
  margin-bottom: 3px;
  margin-left: 12px;
  margin-right: 12px;
  background: var(--bg-conv-item);
  border-radius: 6px;
  cursor: pointer;
  transition: all 0.2s;
  display: flex;
  justify-content: space-between;
  align-items: center;
  position: relative;
  color: var(--text-main);
  box-sizing: border-box;
}

.conversation-item:hover { background: var(--bg-conv-item-hover); }

.conversation-item.active {
  background: var(--bg-conv-item-active);
  color: white;
}

.conversation-title {
  font-weight: bold;
  font-size: 12px;
  margin-bottom: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  flex: 1;
  line-height: 1.2;
  min-width: 0; /* flex 아이템이 축소될 수 있도록 */
  margin-right: 4px; /* 메뉴 버튼과 간격 확보 */
}

.conversation-menu {
  position: relative;
  margin-left: 8px;
}

.menu-button {
  background: none;
  border: none;
  color: #666;
  cursor: pointer;
  padding: 4px;
  border-radius: 4px;
  font-size: 16px;
  transition: background-color 0.2s;
  position: relative;
  z-index: 11; /* 메뉴보다 위에 표시 */
  pointer-events: auto; /* 클릭 가능하도록 명시 */
}

.menu-button:hover {
  background-color: #ddd;
}

.conversation-item.active .menu-button {
  color: #fff;
}

.conversation-item.active .menu-button:hover {
  background-color: rgba(255,255,255,0.2);
}

.menu-dropdown {
  position: fixed; /* absolute 대신 fixed로 변경하여 스크롤과 무관하게 표시 */
  background: var(--bg-sidebar);
  border: 1px solid var(--border-main);
  border-radius: 6px;
  box-shadow: 0 4px 12px rgba(0,0,0,0.3);
  z-index: 10000; /* 다른 요소 위에 표시 */
  min-width: 130px;
  white-space: nowrap;
  display: none;
}

.menu-dropdown.show {
  display: block;
}

.menu-item {
  padding: 6px 10px;
  cursor: pointer;
  color: var(--text-main);
  border-bottom: 1px solid var(--border-main);
  transition: background-color 0.2s;
  white-space: nowrap;
  font-size: 13px;
}

.menu-item:last-child {
  border-bottom: none;
}

.menu-item:hover {
  background-color: var(--bg-conv-item-hover);
}

.menu-item.delete {
  color: #ff6b6b;
}

.menu-item.delete:hover {
  background-color: #4a1a1a;
}

.conversation-date {
  font-size: 11px;
  opacity: 0.7;
}

.new-chat-btn {
  margin: 0;
  padding: 6px 12px;
  background: var(--bg-new-chat);
  color: var(--text-main);
  border: none;
  border-radius: 8px;
  font-size: 13px;
  font-weight: bold;
  cursor: pointer;
  transition: all 0.2s;
}

.new-chat-btn:hover {
  transform: scale(1.05);
}

.new-chat-btn.danger { background: var(--bg-danger); color: #fff; }
.new-chat-btn.danger:hover { background: #4a1515; }

.lock-indicator { margin-left: 6px; opacity: .9; }

/* 프로젝트 관리 섹션 */
.project-section {
  margin: 2px 10px 2px 10px;
  padding-top: 4px;
}

.chat-section {
  margin: 2px 10px 4px 10px;
  padding-top: 4px;
  display: flex;
  flex-direction: column;
  flex: 1 1 auto; /* 남은 공간을 모두 차지 */
  min-height: 0; /* flex 자식이 overflow를 제대로 처리하도록 */
  overflow: hidden; /* 내부 스크롤만 허용 */
}

.project-header,
.chat-section-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 8px 12px;
  cursor: pointer;
  border-radius: 6px;
  transition: background-color 0.2s;
  color: var(--text-main, #fff);
  font-weight: 500;
  font-size: 13px;
}

.project-header:hover,
.chat-section-header:hover {
  background-color: var(--bg-conv-item-hover, #262626);
}

.project-toggle,
.chat-section-toggle {
  font-size: 12px;
  color: var(--text-secondary, #aaa);
  transition: transform 0.2s;
}

.chat-section-content {
  margin-top: 8px;
  display: flex;
  flex-direction: column;
  flex: 1 1 auto;
  min-height: 0;
  overflow: hidden;
}

.project-list {
  margin-top: 8px;
  max-height: 300px;
  overflow-y: auto;
}

.project-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 4px 10px;
  cursor: pointer;
  border-radius: 6px;
  color: var(--text-main, #fff);
  font-size: 13px;
  transition: background-color 0.2s;
  margin-bottom: 1px;
  position: relative;
  box-sizing: border-box;
  line-height: 1.2;
}

.project-item:hover {
  background-color: var(--bg-conv-item-hover, #262626);
}

.project-item.active {
  background-color: rgba(102, 126, 234, 0.2);
  color: #667eea;
}

.project-item.new-project {
  color: var(--text-secondary, #aaa);
  font-style: italic;
}

.project-item.more-projects {
  color: var(--text-secondary, #aaa);
  font-size: 12px;
  justify-content: center;
  padding: 6px;
}

.project-name {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.project-menu-btn {
  background: transparent !important;
  border: none !important;
  outline: none !important;
  color: var(--text-secondary, #aaa);
  cursor: pointer;
  padding: 2px 6px;
  font-size: 16px;
  border-radius: 4px;
  opacity: 1;
  transition: background-color 0.2s, color 0.2s;
  margin-left: auto;
  flex-shrink: 0;
  pointer-events: auto;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 22px;
  height: 22px;
  position: relative;
  z-index: 2;
}

.project-item:hover .project-menu-btn { }

.project-menu-btn:hover {
  background: var(--bg-conv-item-hover, #262626) !important;
  color: var(--text-main, #fff);
}

.project-menu-btn:focus {
  outline: none !important;
  box-shadow: none !important;
}

.project-icon {
  font-size: 16px;
  display: inline-flex;
  align-items: center;
  flex-shrink: 0;
}

/* 대화 프로젝트 표시 */
.conversation-meta {
  display: flex;
  gap: 8px;
  margin-top: 2px;
  font-size: 11px;
  color: var(--text-secondary, #888);
}

.meta-item {
  display: inline-flex;
  align-items: center;
  gap: 4px;
}

/* 프로젝트 선택 모달 */
.project-select-item {
  color: var(--text-main, #fff);
  transition: background-color 0.2s;
}

.project-select-item:hover {
  background-color: var(--bg-conv-item-hover, #262626) !important;
}

/* 라이트 모드 프로젝트 스타일 */
body.light-theme .project-item.active {
  background-color: rgba(102, 126, 234, 0.15);
  color: #5568d3;
}

.chat-container {
  flex: 1;
  max-width: 900px;
  margin: 0 auto; /* 가운데 정렬 */
  background: transparent;
  display: flex;
  flex-direction: column;
  overflow: visible; /* 입력창 sticky가 뷰포트 기준으로 고정되도록 */
  min-height: calc(100vh - 80px);
}

.chat-header {
  background: var(--bg-chat-header);
  color: var(--text-main);
  padding: 10px 20px 10px 44px; /* 왼쪽 여백 확보(토글 버튼 자리), 오른쪽 여백 추가 */
  font-size: 22px;
  font-weight: bold;
  display: flex;
  align-items: center;
  justify-content: space-between;
  position: sticky;
  top: 0;
  z-index: 1000; /* 모달 배경 뒤에 위치 */
  backdrop-filter: blur(6px);
  border-bottom: 1px solid var(--border-main);
  /* 스크롤 시 움직임 최소화 */
  transform: translateZ(0);
  -webkit-transform: translateZ(0);
  /* 맨 위에 붙이기 */
  margin-top: 0;
}

/* 사이드바 토글 버튼 */
.sidebar-toggle { background:var(--bg-sidebar-header); color:var(--text-main); border:1px solid var(--border-main); border-radius:8px; padding:6px 10px; cursor:pointer; font-size:14px; }
.sidebar-toggle:hover { background:var(--bg-conv-item-hover); }
/* 버튼을 화면 좌측 상단에 고정, 헤더와 동일 레이어(z-index 1000)로 모달(10000+) 아래에 표시 */
.chat-header #sidebarToggle { position: fixed; left: 16px; top: 18px; z-index: 1000; }

/* 긴 들여쓰기 줄바꿈 강제 (코드 블록 제외) */
.message-content { 
  overflow-wrap:anywhere; 
  word-break:break-word; 
  font-size: var(--chat-font-size);
}
/* 코드 블록은 줄바꿈 방지 */
.message-content pre { overflow-wrap:normal !important; word-break:normal !important; }
.message-content p {
  white-space: normal;
  margin-left: 0;
  margin-top: 8px;
  margin-bottom: 8px;
}

.message-content p:first-child {
  margin-top: 0;
}

.message-content p:last-child {
  margin-bottom: 0;
}

.message-content br:last-child {
  display: none;
}
.message-content li,
.message-content h1,
.message-content h2,
.message-content h3,
.message-content h4,
.message-content h5,
.message-content h6 { white-space: normal; margin-left: 0; }
/* 인라인 코드만 줄바꿈 적용 (pre 태그는 제외) */
.message-content :not(pre) > code { white-space:pre-wrap; word-break:break-word; overflow-wrap:anywhere; }
.message-content ul, .message-content ol { padding-left: 1.25em; }
.message-content ul ul, .message-content ol ol { padding-left: 1.0em; }
.message-content ul ul ul, .message-content ol ol ol { padding-left: 0.8em; }
.message-content ul ul ul ul, .message-content ol ol ol ol { padding-left: 0.6em; }
.message-content blockquote { margin:8px 0; padding-left:12px; border-left:2px solid #444; }

/* 채팅창 내 이미지 스타일 (스크린샷 등) */
.message-content img,
.message .message-content img,
.chat-message .message-content img {
  max-width: 100% !important;
  width: auto !important;
  max-height: 500px !important;
  height: auto !important;
  object-fit: contain !important;
  border-radius: 8px;
  cursor: pointer;
  transition: opacity 0.2s, transform 0.2s;
  display: block;
  margin: 12px 0;
}

.message-content img:hover,
.message .message-content img:hover,
.chat-message .message-content img:hover {
  opacity: 0.9;
  transform: scale(1.01);
}

/* base64 이미지는 클릭 불가 */
.message-content img[src^="data:"],
.message .message-content img[src^="data:"],
.chat-message .message-content img[src^="data:"] {
  cursor: default;
}

.message-content img[src^="data:"]:hover,
.message .message-content img[src^="data:"]:hover,
.chat-message .message-content img[src^="data:"]:hover {
  opacity: 1;
  transform: none;
}

.header-title {
  flex: 1;
  text-align: center;
  display: flex;
  align-items: center;
  justify-content: center;
}

.header-title img {
  display: block;
}

.model-selector {
  position: relative;
  display: inline-block;
}

.model-dropdown {
  background: var(--bg-sidebar-header);
  color: var(--text-main);
  border: 1px solid var(--border-main);
  border-radius: 8px;
  padding: 6px 10px;
  font-size: 12px;
  cursor: pointer;
  min-width: 160px;
  transition: background-color 0.3s;
}

.model-dropdown:hover {
  background: var(--bg-conv-item-hover);
}

.model-dropdown:focus {
  outline: none;
  border-color: #667eea;
}

.model-options {
  position: absolute;
  top: 100%;
  left: 0;
  right: 0;
  background: var(--bg-sidebar);
  border: 1px solid var(--border-main);
  border-radius: 8px;
  box-shadow: 0 4px 12px rgba(0,0,0,0.3);
  z-index: 1000;
  display: none;
  max-height: 200px;
  overflow-y: auto;
}

.model-options.show {
  display: block;
}

.model-option {
  padding: 8px 12px;
  cursor: pointer;
  border-bottom: 1px solid var(--border-main);
  transition: background-color 0.2s;
}

.model-option:last-child {
  border-bottom: none;
}

.model-option:hover {
  background: var(--bg-conv-item-hover);
}

.model-option.selected {
  background: #667eea;
}

.model-name {
  font-weight: bold;
  font-size: 13px;
  margin-bottom: 2px;
}

.model-desc {
  font-size: 10px;
  color: #ccc;
}

.chat-messages {
  flex: 1;
  padding: 10px 0 48px 0;
  overflow-y: auto; /* 내용이 넘칠 때만 세로 스크롤바 표시 */
  background: transparent;
  scroll-behavior: smooth;
  scroll-padding-bottom: 120px;
}

.settings-btn {
  background: var(--bg-send-btn);
  border: 1px solid var(--border-main);
  color: var(--text-main);
  padding: 8px 12px;
  border-radius: 8px;
  cursor: pointer;
  font-size: 16px;
  transition: all 0.2s;
  display: flex;
  align-items: center;
  justify-content: center;
  height: 32px;
  min-width: 40px;
}

.settings-btn:hover {
  background: var(--bg-input-focus-border);
  transform: scale(1.05);
}

.settings-btn:active {
  transform: scale(0.95);
}

body.light-theme .settings-btn {
  background: #e0e0e0;
  color: var(--text-dark);
  border-color: #ccc;
}

body.light-theme .settings-btn:hover {
  background: #d0d0d0;
}

.theme-toggle {
  background: var(--bg-sidebar-header);
  color: var(--text-main);
  border: 1px solid var(--border-main);
  border-radius: 8px;
  padding: 6px 10px;
  cursor: pointer;
  font-size: 16px;
}

.message {
  margin-bottom: 15px;
  display: flex;
  align-items: flex-start;
  animation: fadeIn 0.3s ease-in;
  position: relative;
  scroll-margin-bottom: 140px;
}

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

.message.user {
  flex-direction: row-reverse;
}

.message-content {
  max-width: 70%;
  padding: 12px 18px;
  border-radius: 18px;
  word-wrap: break-word;
  white-space: normal;
  line-height: 1.5;
  overflow-wrap: break-word;
  word-break: break-word;
  hyphens: auto;
  color: #ffffff !important; /* 다크 모드에서 흰색 텍스트 강제 */
}

/* 라이트 모드에서는 검정색 텍스트 */
body.light-theme .message-content {
  color: #000000 !important;
}

.message-content pre {
  background: var(--bg-code);
  padding: 16px;
  border-radius: 8px;
  overflow-x: auto;
  overflow-y: visible;
  margin: 12px 0;
  border: 1px solid var(--border-code);
  font-family: 'Google Sans Mono', 'Consolas', 'Monaco', 'Courier New', monospace;
  font-size: 14px;
  line-height: 1.6;
  /* max-width 제거 - 코드가 길어도 가로 스크롤 가능하도록 */
  min-width: 0; /* flex 컨테이너 내에서 축소 허용 */
  white-space: pre !important; /* 줄바꿈 방지 강제 */
  word-wrap: normal !important;
  overflow-wrap: normal !important;
  word-break: normal !important;
  -webkit-overflow-scrolling: touch; /* iOS 부드러운 스크롤 */
  scroll-behavior: smooth;
}

/* 코드 블록 가로 스크롤바 스타일 */
.message-content pre::-webkit-scrollbar {
  height: 10px;
}

.message-content pre::-webkit-scrollbar-track {
  background: var(--bg-code-header, #1f1f1f);
  border-radius: 5px;
}

.message-content pre::-webkit-scrollbar-thumb {
  background: var(--border-code, #444);
  border-radius: 5px;
}

.message-content pre::-webkit-scrollbar-thumb:hover {
  background: var(--bg-conv-item-hover, #262626);
}

/* 인라인 코드만 스타일 */
.message-content :not(pre) > code {
  background: var(--bg-code);
  color: #ffffff !important; /* 다크 모드에서 흰색 텍스트 강제 */
  padding: 2px 6px;
  border-radius: 3px;
  font-family: 'Google Sans Mono', 'Consolas', 'Monaco', 'Courier New', monospace;
  font-size: 13px;
  border: 1px solid var(--border-code);
  word-wrap: break-word;
  overflow-wrap: break-word;
}

/* 라이트 모드에서는 인라인 코드도 검정색 */
body.light-theme .message-content :not(pre) > code {
  color: #000000 !important;
}

.message-content pre code {
  background: transparent;
  padding: 0;
  border: none;
  white-space: pre !important; /* 줄바꿈 방지 */
  word-wrap: normal !important;
  overflow-wrap: normal !important;
  word-break: normal !important;
  font-family: 'Google Sans Mono', 'Consolas', 'Monaco', 'Courier New', monospace !important;
}

/* 하이라이트.js: 배경만 투명 처리, 색상은 테마에 위임 */
.message-content pre .hljs { 
  background: transparent;
  font-family: 'Google Sans Mono', 'Consolas', 'Monaco', 'Courier New', monospace !important;
}

/* 하이라이트된 코드 내부의 모든 요소에도 폰트 적용 */
.message-content pre .hljs *,
.message-content pre code *,
.code-block pre code * {
  font-family: 'Google Sans Mono', 'Consolas', 'Monaco', 'Courier New', monospace !important;
}


/* 코드 블록 헤더 + 복사 버튼 UI */
.code-block {
  border: 1px solid var(--border-code);
  border-radius: 8px;
  overflow: hidden;
  margin: 12px 0;
  background: var(--bg-code);
}

.code-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--bg-code-header);
  color: var(--text-main);
  font-size: 12px;
  padding: 6px 10px;
  border-bottom: 1px solid var(--border-code);
}

.code-lang { opacity: 0.9; }

.copy-btn {
  background: transparent;
  color: var(--text-main);
  border: 1px solid var(--border-code);
  border-radius: 6px;
  padding: 2px 8px;
  font-size: 12px;
  cursor: pointer;
}

.copy-btn:hover { background: var(--bg-conv-item-hover); }

.code-block pre {
  margin: 0;
  border: none;
  border-radius: 0;
  overflow-x: auto;
  overflow-y: visible;
  min-width: 0; /* flex 컨테이너 내에서 축소 허용 */
  white-space: pre !important; /* 줄바꿈 방지 강제 */
  word-wrap: normal !important;
  overflow-wrap: normal !important;
  word-break: normal !important;
  font-family: 'Google Sans Mono', 'Consolas', 'Monaco', 'Courier New', monospace !important;
  -webkit-overflow-scrolling: touch;
  scroll-behavior: smooth;
}

/* 코드 블록 컨테이너에 가로 스크롤 적용 */
.code-block {
  overflow-x: auto;
  overflow-y: visible;
}

/* 코드 블록 내부 스크롤바 스타일 */
.code-block::-webkit-scrollbar,
.code-block pre::-webkit-scrollbar {
  height: 10px;
}

.code-block::-webkit-scrollbar-track,
.code-block pre::-webkit-scrollbar-track {
  background: var(--bg-code-header, #1f1f1f);
  border-radius: 5px;
}

.code-block::-webkit-scrollbar-thumb,
.code-block pre::-webkit-scrollbar-thumb {
  background: var(--border-code, #444);
  border-radius: 5px;
}

.code-block::-webkit-scrollbar-thumb:hover,
.code-block pre::-webkit-scrollbar-thumb:hover {
  background: var(--bg-conv-item-hover, #262626);
}

/* 참고 링크 (웹 검색 출처) - enhanceImages 등 다른 처리에서 제외 */
.source-links-wrap {
  margin-bottom: 12px;
}
.source-links-wrap .source-links-pills {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  align-items: center;
}
.source-links-wrap .source-link-pill {
  display: inline-flex !important;
  align-items: center;
  gap: 6px;
  padding: 4px 10px;
  font-size: 12px;
  max-width: 260px;
  flex-shrink: 0;
}
.source-links-wrap .source-link-pill img {
  width: 16px !important;
  height: 16px !important;
  max-width: 16px !important;
  max-height: 16px !important;
  margin: 0 !important;
  display: inline-block !important;
  flex-shrink: 0;
}

/* Mermaid 다이어그램 블록 (시각화 + 다운로드/편집/코드보기/미리보기) */
.mermaid-block {
  border: 1px solid var(--border-code);
  border-radius: 8px;
  overflow: visible;
  margin: 12px 0;
  background: var(--bg-code);
  max-width: 100%;
}
.mermaid-toolbar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 14px;
  background: var(--bg-code-header);
  border-bottom: 1px solid var(--border-code);
}
.mermaid-toolbar-btn {
  width: 36px;
  height: 36px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: rgba(255, 255, 255, 0.06);
  color: var(--text-main);
  border: 1px solid var(--border-code);
  border-radius: 8px;
  font-size: 15px;
  line-height: 1;
  cursor: pointer;
  padding: 0;
  transition: background 0.15s ease, border-color 0.15s ease, color 0.15s ease;
}
.mermaid-toolbar-btn:hover {
  background: rgba(255, 255, 255, 0.1);
  border-color: rgba(255, 255, 255, 0.2);
}
.mermaid-toolbar-btn.active {
  background: rgba(255, 255, 255, 0.1);
  border-color: rgba(102, 126, 234, 0.5);
  color: rgba(255, 255, 255, 0.95);
}
body.light-theme .mermaid-toolbar-btn {
  background: rgba(0, 0, 0, 0.04);
}
body.light-theme .mermaid-toolbar-btn:hover {
  background: rgba(0, 0, 0, 0.08);
  border-color: rgba(0, 0, 0, 0.12);
}
body.light-theme .mermaid-toolbar-btn.active {
  background: rgba(102, 126, 234, 0.12);
  border-color: rgba(102, 126, 234, 0.4);
  color: #333;
}
.mermaid-preview {
  padding: 20px;
  min-height: 120px;
  overflow-x: auto;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  zoom: 1.35;
  display: block;
}
.mermaid-preview .mermaid {
  display: inline-block;
  min-width: min-content;
}
.mermaid-preview svg {
  display: block;
  width: auto;
  min-width: 560px;
  max-width: none;
  height: auto;
}
.mermaid-code-wrap {
  padding: 12px;
  border-top: 1px solid var(--border-code);
  max-height: 75vh;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}
.mermaid-code-textarea {
  width: 100%;
  min-height: 420px;
  max-height: 65vh;
  padding: 12px;
  font-family: 'Consolas', 'Monaco', 'Courier New', monospace;
  font-size: 13px;
  line-height: 1.5;
  background: var(--bg-code);
  color: var(--text-main);
  border: 1px solid var(--border-code);
  border-radius: 6px;
  resize: vertical;
  box-sizing: border-box;
}
.mermaid-error {
  color: var(--text-secondary);
  font-size: 13px;
  padding: 8px 0;
  margin: 0;
}
.mermaid-error-hint {
  font-size: 12px;
  color: var(--text-secondary);
  opacity: 0.9;
  margin: 4px 0 0 0;
  padding: 0;
}
.mermaid-error-detail {
  font-size: 12px;
  font-family: 'Consolas', monospace;
  color: var(--text-secondary);
  background: rgba(0,0,0,0.15);
  padding: 8px 10px;
  border-radius: 6px;
  margin: 6px 0 0 0;
  word-break: break-word;
}
body.light-theme .mermaid-error-detail {
  background: rgba(0,0,0,0.06);
}

/* 답변 버전 컨트롤 */
.variants {
  margin-top: 6px;
  display: flex;
  align-items: center;
  gap: 8px;
}
.variant-btn {
  width: 28px; height: 28px; display: inline-flex; align-items: center; justify-content: center;
  border: 1px solid rgba(255,255,255,0.15); border-radius: 6px; background: rgba(255,255,255,0.08);
  color: #fff; cursor: pointer; font-size: 16px; line-height: 1;
}
.variant-index { font-size: 12px; opacity: .8; }

/* 테이블 스타일 - 단순 버전 */
.message-content table {
  border-collapse: collapse;
  width: 100%;
  margin: 0;
  background: var(--bg-table);
  border: none;
  color: var(--text-main);
  table-layout: auto !important; /* 자동 레이아웃으로 헤더 너비에 맞게 조정 */
  word-wrap: break-word !important;
}

.message-content table th {
  background: var(--bg-table-head);
  padding: 8px;
  text-align: left;
  border: 1px solid var(--border-table);
  font-weight: 700;
  color: var(--text-main);
  white-space: nowrap !important; /* 헤더는 한 줄로 유지 */
  word-wrap: normal !important;
  overflow-wrap: normal !important;
  min-width: max(120px, fit-content); /* 최소 120px 보장, 또는 헤더 내용에 맞게 */
}

.message-content table td {
  padding: 8px;
  border: 1px solid var(--border-table);
  color: var(--text-main);
  background: var(--bg-table);
  white-space: normal !important; /* 데이터 셀은 줄바꿈 허용 */
  word-wrap: break-word !important;
  word-break: break-word !important;
  overflow-wrap: break-word !important;
  hyphens: auto;
  min-width: 120px; /* 최소 너비 보장으로 짧은 컬럼도 충분한 공간 확보 */
  /* 헤더가 더 넓으면 헤더 너비를 따름 */
}
.message-content table tr:nth-child(even) td { background: var(--bg-table-row-even); }

/* 테이블 스크롤 컨테이너 */
.table-scroll-container {
  overflow-x: auto;
  overflow-y: visible;
  max-width: 100%;
  -webkit-overflow-scrolling: touch; /* iOS 부드러운 스크롤 */
}

.table-scroll-container::-webkit-scrollbar {
  height: 8px;
}

.table-scroll-container::-webkit-scrollbar-track {
  background: var(--bg-code-header, #1f1f1f);
  border-radius: 4px;
}

.table-scroll-container::-webkit-scrollbar-thumb {
  background: var(--border-code, #444);
  border-radius: 4px;
}

.table-scroll-container::-webkit-scrollbar-thumb:hover {
  background: var(--bg-conv-item-hover, #262626);
}

.message-content h1, .message-content h2, .message-content h3, .message-content h4 {
  margin: 12px 0 2px 0;
  color: var(--text-main);
  font-weight: 700;
}

/* 제목 다음 요소의 margin-top을 0으로 설정하여 과도한 공백 제거 */
.message-content h1 + *, 
.message-content h2 + *, 
.message-content h3 + *,
.message-content h4 + * {
  margin-top: 0 !important;
}

/* 제목 다음에 오는 p 태그의 margin-top도 제거 */
.message-content h1 + p,
.message-content h2 + p,
.message-content h3 + p,
.message-content h4 + p {
  margin-top: 0 !important;
}

/* 연속된 제목들 사이의 간격 조정 */
.message-content h1 + h2,
.message-content h2 + h3,
.message-content h3 + h4,
.message-content h1 + h3,
.message-content h2 + h4 {
  margin-top: 8px;
}

.message-content h1 {
  font-size: 1.5em;
  border-bottom: 2px solid #667eea;
  padding-bottom: 4px;
}

.message-content h2 {
  font-size: 1.3em;
  border-bottom: 1px solid var(--border-main);
  padding-bottom: 2px;
}

.message-content h3 {
  font-size: 1.1em;
}

.message-content h4 {
  font-size: 1.05em;
  color: var(--text-main);
  font-weight: 600;
  margin: 10px 0 2px 0;
}

.message-content ul, .message-content ol {
  margin: 8px 0;
  padding-left: 20px;
}

.message-content li {
  margin: 4px 0;
  line-height: 1.4;
}

.message-content a {
  color: var(--text-link);
  text-decoration: underline;
}

.message-content a:hover {
  color: #8a9cff;
}

.message-content hr {
  border: none;
  border-top: 1px solid var(--border-main);
  margin: 16px 0;
}


.message-content ul {
  margin: 8px 0;
  padding-left: 20px;
  list-style-type: disc;
}

.message-content li {
  margin: 4px 0;
  padding-left: 4px;
  line-height: 1.6;
}

.message-content strong, .message-content b {
  font-weight: 800 !important; /* 볼드 강조 */
  color: var(--text-main) !important;
}

.message-content em {
  font-style: italic;
  color: var(--text-main);
}

.message.user .message-content {
  background: var(--bg-user-msg);
  color: var(--text-light);
  border-bottom-right-radius: 4px;
  white-space: pre-line;
}

.message.assistant .message-content {
  background: var(--bg-assistant-msg);
  color: var(--text-main);
  border-bottom-left-radius: 4px;
  box-shadow: none;
}

.message-avatar {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 0 10px;
  font-size: 20px;
  flex-shrink: 0;
  position: relative;
}

/* 로딩 스피너 */
.loading-spinner {
  width: 32px;
  height: 32px;
  border: 3px solid var(--bg-assistant-msg);
  border-top: 3px solid #667eea;
  border-radius: 50%;
  animation: spin 1s linear infinite;
  position: absolute;
  top: 4px;
  left: 4px;
}

@keyframes spin {
  0% { transform: rotate(0deg); }
  100% { transform: rotate(360deg); }
}

.message.user .message-avatar {
  background: #667eea;
}

.message.assistant .message-avatar {
  background: #764ba2;
}

.message-actions {
  position: absolute;
  top: 5px;
  right: 5px;
  display: none;
  gap: 5px;
}

.message:hover .message-actions { display: flex; }
/* 어시스턴트 말풍선의 예전 재생성 버튼은 숨김 */
.message.assistant .message-actions { display: none !important; }

/* 유저 말풍선 하단 고정 재생성 아이콘 버튼 */
.regen-btn {
  position: absolute;
  right: 54px; /* 아바타 왼쪽에 위치 */
  bottom: -10px;
  width: 38px;
  height: 38px;
  border-radius: 50%;
  border: 1px solid var(--border-main);
  background: var(--bg-sidebar);
  color: var(--text-main);
  font-size: 22px;
  line-height: 1;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 2px 8px rgba(0,0,0,0.2);
  backdrop-filter: blur(2px);
}
.regen-btn:hover { background: var(--bg-conv-item-hover); }

.action-btn {
  padding: 4px 8px;
  background: rgba(0,0,0,0.1);
  border: none;
  border-radius: 4px;
  cursor: pointer;
  font-size: 12px;
}

.action-btn:hover {
  background: rgba(0,0,0,0.2);
}

.chat-input-container {
  padding: 20px;
  background: var(--bg-main);
  border-top: 1px solid var(--border-main);
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 8px;
  position: sticky;
  bottom: 0;
  z-index: 100;
  margin-top: auto;
  transition: background 0.2s ease, border-color 0.2s ease;
}

/* 드래그 오버 시 스타일 */
.chat-input-container.drag-over {
  background: rgba(102, 126, 234, 0.1);
  border-top: 2px dashed var(--text-link);
  border-color: var(--text-link);
}

.chat-input-container.drag-over::before {
  content: "📎 파일을 여기에 놓으세요";
  display: block;
  text-align: center;
  color: var(--text-link);
  font-weight: bold;
  padding: 10px;
  opacity: 0.9;
}

.chat-input.drag-over {
  border: 2px dashed var(--text-link) !important;
  background: rgba(102, 126, 234, 0.05);
}

.thinking-row { display: flex; align-items: center; gap: 8px; padding-left: 2px; }

/* 파일 첨부 UI */
.agent-btn {
  padding: 10px 12px;
  border: none;
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  color: white;
  border-radius: 12px;
  cursor: pointer;
  font-weight: bold;
  font-size: 16px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  min-width: 40px;
  transition: background 0.2s ease;
}

.agent-btn:hover {
  background: linear-gradient(135deg, #5a6fd8 0%, #6a4190 100%);
}
.file-chips { display: flex; flex-wrap: wrap; gap: 6px; padding-left: 2px; }
.file-chip { display: inline-flex; align-items: center; gap: 8px; padding: 6px 10px; border-radius: 12px; background: var(--bg-assistant-msg); color: var(--text-main); border: 1px solid var(--border-main); font-size: 12px; max-width: 100%; }
.file-chip .file-chip-label { 
  max-width: 200px; 
  overflow: hidden; 
  text-overflow: ellipsis; 
  white-space: nowrap; 
  flex-shrink: 1;
  min-width: 0; /* flexbox에서 텍스트 오버플로우를 위해 필요 */
}
.file-chip .x { cursor: pointer; opacity: .8; flex-shrink: 0; }
.file-chip .thumb { width: 24px; height: 24px; border-radius: 6px; object-fit: cover; background: var(--bg-main); display: inline-block; flex-shrink: 0; }
.file-chip .bar { width: 80px; height: 6px; background: var(--bg-main); border-radius: 4px; overflow: hidden; border: 1px solid var(--border-main); position: relative; flex-shrink: 0; }
.file-chip .bar .fill { position: absolute; left: 0; top: 0; height: 100%; width: 0%; background: linear-gradient(90deg,#667eea,#764ba2); transition: width .2s; }
.file-chip .bar.ind .fill { width: 30%; animation: indBar 1.2s infinite ease-in-out; }
.file-chip .test-btn { flex-shrink: 0; }
@keyframes indBar { 0%{ left: 0; } 50%{ left: 50%; } 100%{ left: 100%; } }

/* 메시지 내부 파일 첨부 (file-chip-inline) 스타일 */
.file-chip-inline {
  max-width: 100%;
  overflow: hidden;
}
.file-chip-inline-label {
  max-width: 250px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  flex-shrink: 1;
  min-width: 0;
}

.test-btn { padding: 2px 6px; border: 1px solid var(--border-main); background: var(--bg-input); color: #9ad3ff; border-radius: 8px; cursor: pointer; font-size: 11px; }
.test-btn:disabled { opacity: .5; cursor: not-allowed; }

/* 채팅 말풍선 내 첨부 이미지 갤러리 */
.attachments { margin-top: 10px; display: grid; grid-template-columns: repeat(auto-fill, minmax(120px, 1fr)); gap: 8px; }
.attachments img { width: 100%; height: 120px; object-fit: cover; border-radius: 8px; border: 1px solid var(--border-main); background: var(--bg-main); transition: transform 0.2s; }
.attachments img:hover { transform: scale(1.05); cursor: pointer; }

/* 이미지 모달 */
.image-modal {
  display: none;
  position: fixed;
  z-index: 21000;
  left: 0;
  top: 0;
  width: 100%;
  height: 100%;
  background-color: rgba(0, 0, 0, 0.9);
  overflow: auto;
  animation: fadeIn 0.2s;
}

.image-modal.show {
  display: flex;
  align-items: center;
  justify-content: center;
}

.image-modal-content {
  position: relative;
  max-width: 90%;
  max-height: 90%;
  margin: auto;
  display: flex;
  flex-direction: column;
  align-items: center;
  animation: zoomIn 0.3s;
}

.image-modal-close {
  position: absolute;
  top: -40px;
  right: 0;
  color: #fff;
  font-size: 40px;
  font-weight: bold;
  cursor: pointer;
  z-index: 10001;
  transition: opacity 0.2s;
}

.image-modal-close:hover {
  opacity: 0.7;
}

.image-modal-zoom-controls {
  position: absolute;
  top: -50px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  gap: 12px;
  background: rgba(0, 0, 0, 0.7);
  padding: 8px 16px;
  border-radius: 8px;
  z-index: 10001;
}

.image-modal-zoom-btn {
  width: 32px;
  height: 32px;
  background: rgba(255, 255, 255, 0.1);
  border: 1px solid rgba(255, 255, 255, 0.3);
  color: #fff;
  font-size: 20px;
  font-weight: bold;
  border-radius: 4px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.2s;
  user-select: none;
}

.image-modal-zoom-btn:hover {
  background: rgba(255, 255, 255, 0.2);
}

.image-modal-zoom-slider {
  width: 150px;
  height: 4px;
  background: rgba(255, 255, 255, 0.3);
  border-radius: 2px;
  outline: none;
  cursor: pointer;
}

.image-modal-zoom-slider::-webkit-slider-thumb {
  appearance: none;
  width: 16px;
  height: 16px;
  background: #fff;
  border-radius: 50%;
  cursor: pointer;
}

.image-modal-zoom-slider::-moz-range-thumb {
  width: 16px;
  height: 16px;
  background: #fff;
  border-radius: 50%;
  cursor: pointer;
  border: none;
}

.image-modal-zoom-value {
  color: #fff;
  font-size: 14px;
  min-width: 45px;
  text-align: center;
  font-weight: 500;
}

.image-modal-img-container {
  position: relative;
  width: 100%;
  height: calc(90vh - 120px);
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: grab;
  border-radius: 8px;
  background: transparent;
}

.image-modal-selection-canvas {
  position: absolute;
  top: 0;
  left: 0;
  cursor: crosshair;
  z-index: 10;
}

.image-modal-img-container:active {
  cursor: grabbing;
}

.image-modal-img {
  max-width: none;
  max-height: none;
  width: auto;
  height: auto;
  object-fit: contain;
  border-radius: 8px;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.5);
  transition: transform 0.1s ease-out;
  user-select: none;
  pointer-events: none;
  display: block;
  will-change: transform;
  transform: translateZ(0);
  backface-visibility: hidden;
}

.image-modal-title {
  margin-top: 15px;
  color: #fff;
  font-size: 16px;
  text-align: center;
  padding: 10px 20px;
  background: rgba(0, 0, 0, 0.7);
  border-radius: 8px;
  max-width: 90%;
  word-wrap: break-word;
}

/* 폴더 모달 */
.folder-modal {
  display: none;
  position: fixed;
  z-index: 10000;
  left: 0;
  top: 0;
  width: 100%;
  height: 100%;
  background-color: rgba(0, 0, 0, 0.8);
  overflow: auto;
  animation: fadeIn 0.2s;
}

.folder-modal.show {
  display: flex;
  align-items: center;
  justify-content: center;
}

.folder-modal-content {
  position: relative;
  width: 90%;
  max-width: 600px;
  max-height: 80vh;
  margin: auto;
  background: var(--bg-main, #1a1a1a);
  border-radius: 12px;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.5);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.folder-modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 20px;
  border-bottom: 1px solid var(--border-main, #444);
}

.folder-modal-title {
  font-size: 18px;
  font-weight: bold;
  color: var(--text-main, #fff);
}

.folder-modal-close {
  font-size: 28px;
  font-weight: bold;
  color: var(--text-secondary, #888);
  cursor: pointer;
  line-height: 1;
  transition: color 0.2s;
}

.folder-modal-close:hover {
  color: var(--text-main, #fff);
}

.folder-modal-body {
  padding: 20px;
  overflow-y: auto;
  flex: 1;
}

.folder-file-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.folder-file-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px;
  background: var(--bg-conv-item-hover, #2d2d2d);
  border-radius: 8px;
  border: 1px solid var(--border-main, #444);
  transition: background 0.2s;
}

.folder-file-item:hover {
  background: var(--bg-conv-item-active, #3a3a3a);
}

.folder-file-icon {
  font-size: 20px;
  flex-shrink: 0;
}

.folder-file-name {
  flex: 1;
  color: var(--text-main, #fff);
  font-size: 14px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.folder-file-size {
  color: var(--text-secondary, #888);
  font-size: 12px;
  flex-shrink: 0;
}

@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

@keyframes zoomIn {
  from { transform: scale(0.8); opacity: 0; }
  to { transform: scale(1); opacity: 1; }
}

/* PDF 모달 스타일 */
.pdf-modal {
  display: none;
  position: fixed;
  z-index: 10000;
  left: 0;
  top: 0;
  width: 100%;
  height: 100%;
  background-color: rgba(0, 0, 0, 0.9);
  overflow: auto;
  animation: fadeIn 0.2s;
}

.pdf-modal.show {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-start;
}

.pdf-modal-content {
  position: relative;
  width: 95%;
  height: 95%;
  margin: auto;
  display: flex;
  flex-direction: column;
  animation: zoomIn 0.3s;
  background: #fff;
  border-radius: 8px;
  overflow: hidden;
}

.pdf-modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 15px 20px;
  background: #333;
  color: #fff;
}

.pdf-modal-title {
  font-size: 18px;
  font-weight: 500;
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  margin-right: 20px;
}

.pdf-modal-close {
  color: #fff;
  font-size: 32px;
  font-weight: bold;
  cursor: pointer;
  line-height: 1;
  transition: opacity 0.2s;
  flex-shrink: 0;
}

.pdf-modal-close:hover {
  opacity: 0.7;
}

.pdf-modal-iframe {
  width: 100%;
  height: calc(100% - 60px);
  border: none;
}

/* 사이드바가 접혔을 때 표시되는 플로팅 토글 버튼 */
.sidebar-fab {
  position: fixed;
  left: 16px;
  top: 24px;
  z-index: 20000;
  display: none;
  background: var(--bg-sidebar-header);
  color: var(--text-main);
  border: 1px solid var(--border-main);
  border-radius: 8px;
  padding: 6px 10px;
  cursor: pointer;
  font-size: 14px;
}

.sidebar-fab:hover {
  background: var(--bg-conv-item-hover);
}

body.sidebar-collapsed .sidebar-fab {
  display: inline-flex;
}

.thinking-toggle-wrapper {
  display: flex;
  align-items: center;
  gap: 8px;
  user-select: none;
}

.thinking-toggle-label {
  font-size: 16px; /* 가독성↑ */
  font-weight: 700;
  color: var(--text-main);
  white-space: nowrap;
}

/* iOS 스타일 토글 스위치 */
.toggle-switch {
  position: relative;
  width: 48px;
  height: 24px;
  background-color: #ccc;
  border-radius: 24px;
  cursor: pointer;
  transition: background-color 0.3s;
}

.toggle-switch.active {
  background-color: #667eea;
}

.toggle-slider {
  position: absolute;
  top: 2px;
  left: 2px;
  width: 20px;
  height: 20px;
  background-color: white;
  border-radius: 50%;
  transition: transform 0.3s;
  box-shadow: 0 2px 4px rgba(0,0,0,0.2);
}

.toggle-switch.active .toggle-slider {
  transform: translateX(24px);
}

.rag-doc-item .rag-delete-btn {
  position: absolute;
  top: 4px;
  right: 0;
  width: 22px;
  height: 22px;
  border: none;
  border-radius: 50%;
  background: transparent;
  color: rgba(255,255,255,0.6);
  font-size: 16px;
  line-height: 22px;
  cursor: pointer;
  transition: background 0.2s, color 0.2s;
}

.rag-doc-item .rag-delete-btn:hover {
  background: rgba(255,255,255,0.15);
  color: #fff;
}

body.light-theme .rag-doc-item .rag-delete-btn {
  color: rgba(33, 37, 41, 0.55);
}

body.light-theme .rag-doc-item .rag-delete-btn:hover {
  background: rgba(33, 37, 41, 0.12);
  color: var(--text-main);
}

/* 숨겨진 체크박스 */
.thinking-toggle-checkbox {
  display: none;
}

/* 선택된 컨텍스트 표시 바 */
.selected-context-bar {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 12px;
  margin-bottom: 8px;
  background: var(--bg-conv-item-hover, #2d2d2d);
  border: 1px solid var(--border-main, #444);
  border-radius: 8px;
  font-size: 13px;
  min-height: 44px;
}

.selected-context-preview {
  flex: 1;
  color: var(--text-main, #fff);
  overflow: hidden;
  line-height: 1.5;
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  word-break: break-word;
  text-overflow: ellipsis;
  padding-right: 8px;
}

.selected-context-preview img {
  max-width: 100px;
  max-height: 40px;
  object-fit: contain;
  border-radius: 4px;
  vertical-align: middle;
  margin-right: 8px;
}

.selected-context-remove {
  background: transparent;
  border: none;
  color: var(--text-secondary, #aaa);
  cursor: pointer;
  padding: 4px;
  border-radius: 4px;
  font-size: 18px;
  line-height: 1;
  transition: color 0.2s;
  flex-shrink: 0;
  width: 24px;
  height: 24px;
  display: flex;
  align-items: center;
  justify-content: center;
  margin-top: -2px;
}

.selected-context-remove:hover {
  color: var(--text-main, #fff);
}

.input-row { 
  display: flex; 
  align-items: center; 
  gap: 10px; 
  position: relative;
}

.chat-input {
  flex: 1;
  padding: 12px 18px;
  border: 1px solid var(--border-main);
  border-radius: 16px;
  font-size: 16px;
  outline: none;
  transition: border-color 0.2s, background-color 0.2s;
  /* textarea 전용 속성 */
  min-height: 44px;
  max-height: 260px;
  line-height: 1.2;
  overflow-y: auto;
  resize: none;
  background: var(--bg-input);
  color: var(--text-main);
  /* 빈 줄바꿈 방지 */
  vertical-align: top;
  box-sizing: border-box;
}

.chat-input:focus {
  border-color: var(--bg-input-focus-border);
}

.chat-input::placeholder { color: #9aa0a6; }
.chat-input:disabled { background: var(--bg-input); color: #bdbdbd; cursor: not-allowed; opacity: .8; }

.send-button {
  padding: 12px 30px;
  background: var(--bg-send-btn);
  color: white;
  border: none;
  border-radius: 25px;
  font-size: 16px;
  font-weight: bold;
  cursor: pointer;
  transition: transform 0.2s, box-shadow 0.2s;
}

.send-button:hover {
  transform: translateY(-2px);
  box-shadow: 0 5px 15px rgba(102, 126, 234, 0.4);
}

.send-button:active {
  transform: translateY(0);
}

.send-button:disabled {
  background: #ccc;
  cursor: not-allowed;
  transform: none;
}

.stop-button {
  padding: 12px 22px;
  background: #e25555;
  color: white;
  border: none;
  border-radius: 999px;
  cursor: pointer;
  font-size: 15px;
  font-weight: 600;
  transition: all 0.2s ease;
  white-space: nowrap;
}

.stop-button:hover {
  transform: translateY(-2px);
  box-shadow: 0 5px 15px rgba(226, 85, 85, 0.35);
}

.stop-button:active {
  transform: translateY(0);
}

.stop-button:disabled {
  background: #ccc;
  cursor: not-allowed;
  transform: none;
  box-shadow: none;
}

.stop-button {
  padding: 12px 30px;
  background: #d32f2f;
  color: white;
  border: none;
  border-radius: 25px;
  font-size: 16px;
  font-weight: bold;
  cursor: pointer;
}

.typing-indicator {
  display: flex;
  gap: 5px;
  padding: 12px 18px;
}

.typing-dot {
  width: 8px;
  height: 8px;
  background: #999;
  border-radius: 50%;
  animation: typing 1.4s infinite;
}

.typing-dot:nth-child(2) { animation-delay: 0.2s; }
.typing-dot:nth-child(3) { animation-delay: 0.4s; }

@keyframes typing {
  0%, 60%, 100% { transform: translateY(0); }
  30% { transform: translateY(-10px); }
}

/* 스트리밍 중 커서 애니메이션 */
.streaming-cursor {
  display: inline-block;
  color: var(--text-main);
  font-weight: bold;
  animation: blink 1s infinite;
  margin-left: 2px;
}

@keyframes blink {
  0%, 49% { opacity: 1; }
  50%, 100% { opacity: 0; }
}

.error-message {
  color: #d32f2f;
  background: #ffebee;
  padding: 10px;
  border-radius: 8px;
  margin: 10px 0;
  text-align: center;
}

.info-badge {
  position: fixed;
  bottom: 20px;
  right: 20px;
  background: var(--bg-main);
  color: var(--text-main);
  padding: 14px 18px;
  border-radius: 10px;
  border: 1px solid var(--border-main);
  box-shadow: 0 8px 24px rgba(0,0,0,0.2);
  font-size: 12px;
  opacity: 0;
  transform: translateY(20px);
  transition: all 0.3s;
  z-index: 20000; /* 모달(z-index: 10000)보다 위에 표시 */
}

.info-badge.show {
  opacity: 1;
  transform: translateY(0);
}

/* 스크롤 맨 아래 버튼 */
.scroll-to-bottom-btn {
  position: fixed;
  left: 50%;
  bottom: 140px;
  transform: translateX(-50%) scale(0.9);
  width: 30px;
  height: 30px;
  background: rgba(40, 44, 52, 0.6);
  color: var(--text-main);
  border: 1px solid rgba(255, 255, 255, 0.18);
  border-radius: 15px;
  cursor: pointer;
  font-size: 16px;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 6px 16px rgba(0, 0, 0, 0.18);
  z-index: 1000;
  transition: opacity 0.35s ease, transform 0.18s ease;
  opacity: 1;
  backdrop-filter: blur(6px);
}

.scroll-to-bottom-btn:hover {
  background: rgba(102, 126, 234, 0.75);
  transform: translateX(-50%) scale(0.98);
}

.scroll-to-bottom-btn.hide {
  opacity: 0;
  pointer-events: none;
}

/* 로그인 관련 스타일 */
.header-right {
  display: flex;
  align-items: center;
  gap: 10px;
}

.login-btn {
  background: #2196F3; /* 푸른색 배경 */
  border: none;
  border-radius: 8px;
  padding: 8px 16px;
  color: white;
  cursor: pointer;
  font-size: 14px;
  font-weight: 500;
  transition: background 0.2s ease, transform 0.1s ease;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  min-width: 70px;
}

.login-btn:hover {
  background: #1976D2; /* 더 진한 푸른색 */
  transform: translateY(-1px);
}

.login-btn:active {
  transform: translateY(0);
}

/* 라이트 모드에서 로그인 버튼 스타일 */
body.light-theme .login-btn {
  background: #2196F3;
  color: white;
  border: none;
}

body.light-theme .login-btn:hover {
  background: #1976D2;
}

/* 로그인된 상태 버튼 스타일 (빨간색) */
.login-btn.logged-in {
  background: #f44336 !important; /* 빨간색 배경 */
  color: white !important;
  border: none !important;
}

.login-btn.logged-in:hover {
  background: #d32f2f !important; /* 더 진한 빨간색 */
  transform: translateY(-1px);
}

.login-btn.logged-in:active {
  transform: translateY(0);
}

/* 라이트 모드에서 로그인된 상태 */
body.light-theme .login-btn.logged-in {
  background: #f44336 !important;
  color: white !important;
  border: none !important;
}

body.light-theme .login-btn.logged-in:hover {
  background: #d32f2f !important;
}

/* 기능 선택 팝업 스타일 */
.function-popup {
  display: none;
  position: absolute;
  bottom: 100%;
  left: 0px;
  margin-bottom: 10px;
  z-index: 9999;
  background: var(--bg-sidebar);
  border-radius: 12px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.3);
  border: 1px solid var(--border-main);
  min-width: 280px;
}

.function-popup.show {
  display: block;
}

.function-popup-content {
  padding: 6px;
}

.function-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 12px;
  border-radius: 8px;
  cursor: pointer;
  transition: background 0.2s ease;
  line-height: 1.2;
}

.function-item:hover {
  background: var(--bg-conv-item-hover);
}

.function-icon {
  font-size: 18px;
  width: 20px;
  text-align: center;
}

.function-text {
  flex: 1;
  color: var(--text-main);
  font-size: 13px;
  font-weight: 500;
}

.function-shortcut {
  color: var(--text-main);
  font-size: 12px;
  opacity: 0.6;
  background: var(--bg-assistant-msg);
  padding: 2px 6px;
  border-radius: 4px;
}

/* 에이전트 선택 팝업 스타일 */
.agent-popup {
  display: none;
  position: absolute;
  bottom: 100%;
  left: 0px;
  margin-bottom: 10px;
  z-index: 9999;
  background: var(--bg-sidebar);
  border-radius: 12px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.3);
  border: 1px solid var(--border-main);
  min-width: 280px;
}

.agent-popup.show {
  display: block;
}

.agent-popup-content {
  padding: 6px;
}

.agent-popup-header {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border-bottom: 1px solid var(--border-main);
  margin-bottom: 6px;
}

/* 코드 가져오기 모달 스타일 */
.code-modal {
  display: none;
  position: fixed !important;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.7);
  z-index: 10000 !important; /* 헤더(z-index: 1000)보다 위에 표시하여 헤더도 음영처리 */
  align-items: center;
  justify-content: center;
}

/* 코드 가져오기 모달과 RAG 모달 모두 동일하게 적용 */
#codeModal,
#ragModal {
  z-index: 10000 !important;
  position: fixed !important;
}

.code-modal-content {
  background: var(--bg-sidebar);
  border-radius: 12px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.5);
  border: 1px solid var(--border-main);
  min-width: 500px;
  max-width: 90%;
  position: relative;
  z-index: 10001; /* 모달 배경보다 위에 표시 */
}

/* RAG 모달(여유 공간 확대) */
#ragModal .code-modal-content {
  min-width: 640px;
  max-width: 960px;
  padding: 24px;
}
#ragModal .code-modal-header {
  padding: 18px 24px;
}
#ragModal .code-modal-title {
  font-size: 20px;
  font-weight: 700;
}
#ragModal .code-modal-close {
  font-size: 22px;
}
#ragModal #ragDocList {
  max-height: 65vh;
}
#ragModal .rag-doc-item {
  padding: 12px 0;
}

/* RAG 일괄 삭제 버튼 스타일 */
#ragDeleteAllBtn {
  transition: opacity 0.2s, transform 0.2s;
}

#ragDeleteAllBtn:hover {
  opacity: 1 !important;
  transform: scale(1.05);
}

#ragDeleteAllBtn:active {
  transform: scale(0.95);
}

.code-modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border-main);
}

.code-modal-title {
  color: var(--text-main);
  font-size: 18px;
  font-weight: 600;
}

.code-modal-close {
  color: var(--text-main);
  font-size: 24px;
  cursor: pointer;
  padding: 4px;
  border-radius: 4px;
  transition: background 0.2s ease;
  line-height: 1;
}

.code-modal-close:hover {
  background: var(--bg-conv-item-hover);
}

.code-modal-body {
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

/* 탭 스타일 */
.code-modal-tabs {
  display: flex;
  gap: 8px;
  margin-bottom: 16px;
  border-bottom: 1px solid var(--border-main);
}

.code-tab-btn {
  flex: 1;
  padding: 12px 16px;
  background: transparent;
  border: none;
  border-bottom: 2px solid transparent;
  color: var(--text-main);
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s ease;
  opacity: 0.6;
}

.code-tab-btn:hover {
  opacity: 0.8;
  background: var(--bg-conv-item-hover);
}

.code-tab-btn.active {
  opacity: 1;
  border-bottom-color: #667eea;
  color: #667eea;
}

.code-tab-content {
  display: none;
  flex-direction: column;
  gap: 12px;
}

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

.code-url-input,
.code-token-input {
  width: 100%;
  padding: 12px;
  background: var(--bg-input);
  border: 1px solid var(--border-main);
  border-radius: 8px;
  color: var(--text-main);
  font-size: 14px;
  box-sizing: border-box;
}

.code-url-input:focus,
.code-token-input:focus {
  outline: none;
  border-color: var(--bg-input-focus-border);
}

.code-fetch-btn {
  padding: 12px 24px;
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  color: var(--text-light);
  border: none;
  border-radius: 8px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: opacity 0.2s ease;
}

.code-fetch-btn:hover:not(:disabled) {
  opacity: 0.9;
}

.code-fetch-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.code-info-text {
  color: var(--text-main);
  font-size: 12px;
  opacity: 0.7;
  text-align: center;
}

.code-loading {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  padding: 20px;
  color: var(--text-main);
}

.code-spinner {
  width: 32px;
  height: 32px;
  border: 3px solid var(--border-main);
  border-top-color: #667eea;
  border-radius: 50%;
  animation: spin 1s linear infinite;
}

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

/* 폴더 업로드 영역 */
.folder-upload-area {
  border: 2px dashed var(--border-main);
  border-radius: 8px;
  padding: 40px 20px;
  text-align: center;
  cursor: pointer;
  transition: all 0.2s ease;
  background: var(--bg-input);
}

.folder-upload-area:hover {
  border-color: #667eea;
  background: var(--bg-conv-item-hover);
}

.folder-upload-area.drag-over {
  border-color: #667eea;
  background: var(--bg-conv-item-hover);
}

.folder-upload-icon {
  font-size: 48px;
  margin-bottom: 12px;
}

.folder-upload-text {
  color: var(--text-main);
  font-size: 14px;
  margin-bottom: 16px;
}

.folder-select-btn {
  padding: 10px 20px;
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  color: var(--text-light);
  border: none;
  border-radius: 8px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: opacity 0.2s ease;
}

.folder-select-btn:hover {
  opacity: 0.9;
}

.back-btn {
  color: var(--text-main);
  font-size: 18px;
  cursor: pointer;
  padding: 4px;
  border-radius: 4px;
  transition: background 0.2s ease;
}

.back-btn:hover {
  background: var(--bg-conv-item-hover);
}

.popup-title {
  color: var(--text-main);
  font-size: 16px;
  font-weight: 600;
}

.agent-popup-list {
  padding: 0 8px;
}

.agent-popup-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 12px;
  border-radius: 8px;
  cursor: pointer;
  transition: background 0.2s ease;
  line-height: 1.2;
}

.agent-popup-item:hover {
  background: var(--bg-conv-item-hover);
}

.agent-popup-icon {
  font-size: 18px;
  width: 20px;
  text-align: center;
}

.agent-popup-text {
  color: var(--text-main);
  font-size: 13px;
  font-weight: 500;
}

/* 에이전트 인디케이터 스타일 */
.agent-cancel-btn {
  position: absolute;
  right: 60px; /* 전송 버튼 왼쪽에 위치 */
  top: 50%;
  transform: translateY(-50%);
  background: var(--bg-sidebar);
  border: 1px solid var(--border-main);
  border-radius: 50%;
  color: var(--text-main);
  font-size: 12px;
  cursor: pointer;
  width: 20px;
  height: 20px;
  display: none;
  align-items: center;
  justify-content: center;
  opacity: 0.7;
  transition: opacity 0.2s ease;
  z-index: 10;
}

.agent-cancel-btn:hover {
  opacity: 1;
  background: var(--bg-conv-item-hover);
}

.agent-cancel-btn.show {
  display: flex;
}

/* 에이전트 모달 스타일 - 완전히 숨김 */
.agent-modal {
  display: none !important;
  visibility: hidden !important;
  opacity: 0 !important;
  pointer-events: none !important;
}

.agent-modal.show {
  display: none !important;
  visibility: hidden !important;
  opacity: 0 !important;
  pointer-events: none !important;
}

.agent-modal-content {
  background: var(--bg-sidebar);
  border-radius: 12px;
  padding: 20px;
  width: 90%;
  max-width: 600px;
  max-height: 80vh;
  overflow-y: auto;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.3);
}

.agent-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 20px;
  padding-bottom: 15px;
  border-bottom: 1px solid var(--border-main);
}

.agent-header h2 {
  margin: 0;
  color: var(--text-main);
  font-size: 20px;
}

.agent-list {
  display: flex;
  flex-direction: column;
  gap: 15px;
}

.agent-item {
  display: flex;
  align-items: flex-start;
  gap: 15px;
  padding: 15px;
  border: 1px solid var(--border-main);
  border-radius: 8px;
  background: var(--bg-conv-item);
  cursor: pointer;
  transition: all 0.2s ease;
}

.agent-item:hover {
  background: var(--bg-conv-item-hover);
  border-color: var(--bg-user-msg);
}

.agent-icon {
  font-size: 24px;
  width: 40px;
  height: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg-assistant-msg);
  border-radius: 8px;
  flex-shrink: 0;
}

.agent-info h3 {
  margin: 0 0 8px 0;
  color: var(--text-main);
  font-size: 16px;
}

.agent-info p {
  margin: 0 0 10px 0;
  color: var(--text-main);
  font-size: 14px;
  opacity: 0.8;
}

.agent-info ul {
  margin: 0;
  padding-left: 20px;
  color: var(--text-main);
  font-size: 13px;
  opacity: 0.7;
}

.agent-info li {
  margin-bottom: 4px;
}

.login-modal {
  display: none;
  position: fixed;
  z-index: 2000;
  left: 0;
  top: 0;
  width: 100%;
  height: 100%;
  background-color: rgba(0,0,0,0.5);
}

.login-modal.show {
  display: flex;
  align-items: center;
  justify-content: center;
}

.login-modal-content {
  background: var(--bg-sidebar);
  border-radius: 12px;
  padding: 24px;
  width: 400px;
  max-width: 90%;
  box-shadow: 0 8px 32px rgba(0,0,0,0.3);
}

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

.login-header h2 {
  margin: 0;
  color: var(--text-primary);
  font-size: 24px;
}

.close-btn {
  font-size: 28px;
  font-weight: bold;
  color: var(--text-secondary);
  cursor: pointer;
  line-height: 1;
}

.close-btn:hover {
  color: var(--text-primary);
}

.login-tabs {
  display: flex;
  margin-bottom: 20px;
  border-bottom: 1px solid var(--bg-conv-item);
}

.tab-btn {
  background: none;
  border: none;
  padding: 12px 20px;
  color: var(--text-secondary);
  cursor: pointer;
  font-size: 16px;
  border-bottom: 2px solid transparent;
  transition: all 0.2s ease;
}

.tab-btn.active {
  color: var(--text-primary);
  border-bottom-color: var(--bg-user-msg);
}

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

.login-form {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.form-group {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.form-group label {
  color: var(--text-primary);
  font-size: 14px;
  font-weight: 500;
}

.form-group input {
  background: var(--bg-input);
  border: 1px solid var(--bg-conv-item);
  border-radius: 8px;
  padding: 12px;
  color: var(--text-primary);
  font-size: 16px;
  transition: border-color 0.2s ease;
}

.form-group input:focus {
  outline: none;
  border-color: var(--bg-user-msg);
}

.submit-btn {
  background: var(--bg-user-msg);
  border: none;
  border-radius: 8px;
  padding: 12px;
  color: white;
  font-size: 16px;
  font-weight: 500;
  cursor: pointer;
  transition: opacity 0.2s ease;
}

.submit-btn:hover {
  opacity: 0.9;
}

.submit-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.login-status {
  margin-top: 16px;
  padding: 12px;
  border-radius: 8px;
  font-size: 14px;
  text-align: center;
}

.login-status.success {
  background: rgba(34, 197, 94, 0.1);
  color: #22c55e;
  border: 1px solid rgba(34, 197, 94, 0.2);
}

.login-status.error {
  background: rgba(239, 68, 68, 0.1);
  color: #ef4444;
  border: 1px solid rgba(239, 68, 68, 0.2);
}

/* ==================== Collapsible Sections ==================== */
.cs-collapsible {
  position: relative;
}

.cs-collapsible .cs-toggle {
  margin-top: 0.5rem;
  padding: 0.3rem 0.6rem;
  font-size: 0.85rem;
  cursor: pointer;
  border: 1px solid rgba(127, 127, 127, 0.4);
  border-radius: 0.5rem;
  background: transparent;
  color: var(--text-main);
}

.cs-text-clamp {
  display: -webkit-box;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.cs-collapsed .cs-text-clamp {
  line-clamp: var(--cs-lines, 3);
  -webkit-line-clamp: var(--cs-lines, 3);
}

.cs-code-wrap {
  position: relative;
}

.cs-collapsed .cs-code-wrap pre {
  overflow: hidden;
  max-height: var(--cs-code-max, 360px);
}

.cs-collapsed .cs-fade {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 2.2rem;
  height: 3rem;
  pointer-events: none;
  background: linear-gradient(to bottom, rgba(0, 0, 0, 0), rgba(0, 0, 0, 0.08), rgba(0, 0, 0, 0.16));
}

.cs-sec-title {
  font-weight: 600;
  margin: 0.5rem 0 0.25rem;
  color: var(--text-main);
}


/* 에이전트 상태 바 스타일 */
.agent-status-bar {
  display: flex;
  align-items: center;
  padding: 6px 12px;
  background: var(--bg-sidebar);
  border-top: 1px solid var(--border-main);
  border-radius: 0 0 8px 8px;
  margin-top: 6px;
  animation: slideDown 0.3s ease-out;
  min-height: 32px;
  width: fit-content;
  max-width: 500px; /* Increased for two items */
  margin-left: 0;
  margin-right: auto;
}

.agent-status-items {
  display: flex;
  align-items: center;
  gap: 12px; /* Space between agent and web search items */
}

.agent-status-item,
.web-search-status-item {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 4px 8px;
  background: var(--bg-conv-item);
  border: 1px solid var(--border-main);
  border-radius: 6px;
  transition: all 0.2s ease;
}

.agent-status-item:hover,
.web-search-status-item:hover {
  background: var(--bg-conv-item-hover);
}

.agent-status-icon,
.web-search-status-icon {
  font-size: 14px;
}

.agent-status-text,
.web-search-status-text {
  color: var(--text-main);
  font-size: 12px;
  font-weight: 500;
}

.agent-status-cancel,
.web-search-status-cancel {
  background: var(--bg-conv-item-hover);
  border: 1px solid var(--border-main);
  border-radius: 50%;
  color: var(--text-main);
  font-size: 10px;
  cursor: pointer;
  width: 18px;
  height: 18px;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0.7;
  transition: all 0.2s ease;
}

.agent-status-cancel:hover,
.web-search-status-cancel:hover {
  opacity: 1;
  background: var(--bg-conv-item-hover);
  transform: scale(1.1);
}

.deep-research-indicator {
  position: fixed;
  right: 32px;
  bottom: 120px;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  border-radius: 999px;
  background: rgba(40, 36, 64, 0.92);
  border: 1px solid rgba(102, 126, 234, 0.35);
  box-shadow: 0 12px 30px rgba(20, 16, 40, 0.45);
  backdrop-filter: blur(10px);
  opacity: 0;
  pointer-events: none;
  transform: translateY(16px) scale(0.96);
  transition: opacity 0.25s ease, transform 0.25s ease;
  z-index: 1400;
}

.deep-research-indicator.active {
  opacity: 1;
  pointer-events: auto;
  transform: translateY(0) scale(1);
}

.deep-research-indicator-circle {
  --deep-research-progress: 0;
  width: 52px;
  height: 52px;
  border-radius: 50%;
  background: conic-gradient(#667eea calc(var(--deep-research-progress) * 1%), rgba(102, 126, 234, 0.12) 0);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 6px;
  transition: background 0.4s ease;
}

.deep-research-indicator-face {
  width: 100%;
  height: 100%;
  border-radius: 50%;
  background: radial-gradient(circle at 30% 30%, #8357ff 0%, #2b1f46 70%);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 26px;
  color: #f8f8ff;
  box-shadow: inset 0 4px 12px rgba(0, 0, 0, 0.35);
}

.deep-research-indicator-text {
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.deep-research-indicator-title {
  font-size: 13px;
  font-weight: 600;
  color: #f0f0ff;
  letter-spacing: 0.02em;
}

.deep-research-indicator-status {
  font-size: 12px;
  color: rgba(214, 216, 240, 0.88);
  line-height: 1.2;
  max-width: 180px;
}

.deep-research-progress-log {
  background: rgba(102, 126, 234, 0.08);
  border: 1px solid rgba(102, 126, 234, 0.25);
  border-radius: 12px;
  padding: 16px 18px;
  margin-bottom: 18px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.deep-research-progress-item {
  position: relative;
  padding-left: 28px;
  color: var(--text-secondary, #9aa0a6);
  font-size: 13px;
  line-height: 1.5;
  transition: color 0.2s ease;
}

.deep-research-progress-item::before {
  content: '';
  position: absolute;
  left: 11px;
  top: -14px;
  bottom: -14px;
  width: 2px;
  background: rgba(102, 126, 234, 0.15);
}

.deep-research-progress-item:first-child::before {
  top: 12px;
}

.deep-research-progress-item:last-child::before {
  bottom: 14px;
}

.deep-research-progress-item .dot {
  position: absolute;
  left: 4px;
  top: 4px;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: rgba(102, 126, 234, 0.2);
  border: 2px solid rgba(102, 126, 234, 0.45);
  box-sizing: border-box;
  transition: all 0.2s ease;
}

.deep-research-progress-item.active {
  color: var(--text-main);
}

.deep-research-progress-item.active .dot {
  background: #667eea;
  border-color: #8896ff;
  box-shadow: 0 0 8px rgba(102, 126, 234, 0.45);
}

.deep-research-progress-item.done .dot {
  background: #4caf6f;
  border-color: #5cd28c;
}

.deep-research-progress-item .headline {
  font-weight: 600;
  color: var(--text-main);
}

.deep-research-progress-item.done .headline {
  color: #b5ffc8;
}

.deep-research-progress-item .sub {
  margin-top: 4px;
  color: var(--text-secondary, #9aa0a6);
  font-size: 12px;
}

@media (max-width: 768px) {
  .deep-research-indicator {
      right: 16px;
      bottom: 110px;
      padding: 8px 12px;
  }
  .deep-research-indicator-circle {
      width: 46px;
      height: 46px;
  }
  .deep-research-indicator-face {
      font-size: 22px;
  }
  .deep-research-indicator-title {
      font-size: 12px;
  }
  .deep-research-indicator-status {
      font-size: 11px;
  }
  .deep-research-progress-log {
      padding: 14px;
      gap: 10px;
  }
  .deep-research-progress-item {
      padding-left: 24px;
      font-size: 12.5px;
  }
}

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

/* 반응형 레이아웃 조정 */
@media (max-width: 900px) {
  .chat-container {
      max-width: 100%;
      width: 100%;
      padding: 0 16px;
      box-sizing: border-box;
  }

  .chat-header {
      padding: 12px 16px 16px 52px;
      font-size: 20px;
  }

  .header-right {
      gap: 6px;
  }

  .model-dropdown {
      min-width: auto;
      font-size: 11px;
      padding: 6px 8px;
  }

  .message-content {
      max-width: calc(100% - 56px);
      padding: 12px 16px;
  }

  .message.user .message-content {
      margin-left: auto;
  }

  .message-avatar {
      width: 36px;
      height: 36px;
      font-size: 18px;
  }

  .scroll-to-bottom-btn {
      bottom: 120px;
  }
}

@media (max-width: 640px) {
  .chat-container {
      padding: 0 12px;
  }

  .chat-header {
      padding: 12px 14px 14px 48px;
      font-size: 18px;
  }

  .header-right {
      gap: 4px;
  }

  .model-dropdown {
      padding: 5px 7px;
      font-size: 10px;
  }

  .message {
      margin-bottom: 12px;
  }

  .message-content {
      max-width: calc(100% - 48px);
      padding: 10px 14px;
      font-size: 14px;
  }

  .message-content pre {
      font-size: 13px;
  }

  .chat-messages {
      padding: 8px 0 48px 0;
  }

  .chat-input-container {
      padding: 10px 12px 16px 12px;
  }

  .chat-input {
      font-size: 14px;
  }
}

@media (max-width: 480px) {
  .chat-container {
      padding: 0 8px;
  }

  .chat-header {
      padding: 10px 12px 12px 46px;
      font-size: 17px;
  }

  .message-content {
      max-width: calc(100% - 40px);
      padding: 9px 12px;
      font-size: 13px;
  }

  .message-content pre {
      font-size: 12px;
      padding: 12px;
  }

  .chat-input {
      font-size: 13px;
  }

  .scroll-to-bottom-btn {
      bottom: 110px;
      transform: translateX(-50%) scale(0.82);
  }
}

/* 환경설정 모달: sidebar-fab(20000)·헤더(1000) 모두 위에 표시 */
.settings-modal {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.7);
  z-index: 25000;
  align-items: center;
  justify-content: center;
}

.settings-modal-content {
  background: var(--bg-sidebar);
  border-radius: 12px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.5);
  border: 1px solid var(--border-main);
  min-width: 480px;
  max-width: 90%;
  max-height: 90vh;
  overflow-y: auto;
}

.settings-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 20px 24px;
  border-bottom: 1px solid var(--border-main);
}

.settings-header h2 {
  margin: 0;
  font-size: 20px;
  font-weight: 600;
  color: var(--text-main);
}

.settings-body {
  padding: 24px;
  padding-bottom: 24px;
}

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

.settings-label {
  font-size: 14px;
  font-weight: 500;
  color: var(--text-main);
  margin-bottom: 12px;
}

.font-size-controls {
  display: flex;
  gap: 8px;
  align-items: center;
}

.font-size-btn {
  flex: 0 0 auto;
  padding: 8px 16px;
  background: var(--bg-input);
  border: 2px solid var(--border-main);
  border-radius: 8px;
  color: var(--text-main);
  cursor: pointer;
  transition: all 0.2s;
  font-size: 14px;
  display: flex;
  align-items: center;
  justify-content: center;
  min-width: 60px;
}

.font-size-btn:hover {
  background: var(--bg-input-focus-border);
  border-color: var(--text-link);
  transform: scale(1.05);
}

.font-size-btn:active {
  transform: scale(0.95);
}

.font-size-btn.font-size-reset {
  flex: 0 0 auto;
  min-width: 70px;
  padding: 8px 12px;
}

.theme-controls {
  display: flex;
  align-items: center;
  gap: 12px;
}

.theme-label {
  font-size: 14px;
  color: var(--text-main);
  user-select: none;
}

body.light-theme .settings-modal-content {
  background: #ffffff;
  border-color: #ddd;
}

body.light-theme .settings-header {
  border-bottom-color: #ddd;
}

body.light-theme .settings-header h2 {
  color: var(--text-dark);
}

/* ==================== MCP 제안 카드 스타일 ==================== */
.mcp-proposal-card {
  background: var(--bg-sidebar, #1f1f1f);
  border: 1px solid var(--border-main, #444);
  border-radius: 12px;
  padding: 20px;
  margin: 16px 0;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2);
}

.mcp-proposal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
}

.mcp-proposal-title {
  font-size: 18px;
  font-weight: 600;
  color: var(--text-main, #fff);
  margin: 0;
}

.mcp-proposal-tool {
  display: inline-block;
  padding: 4px 12px;
  background: var(--bg-conv-item-hover, #2d2d2d);
  color: var(--text-main, #fff);
  border-radius: 6px;
  font-size: 12px;
  font-weight: 500;
}

.mcp-proposal-steps {
  margin: 16px 0;
}

.mcp-proposal-steps-title {
  font-size: 14px;
  font-weight: 500;
  color: var(--text-secondary, #aaa);
  margin-bottom: 8px;
}

.mcp-proposal-step {
  display: flex;
  align-items: center;
  padding: 8px 12px;
  margin: 4px 0;
  background: var(--bg-main, #0f0f0f);
  border-radius: 6px;
  font-size: 13px;
  color: var(--text-main, #fff);
}

.mcp-proposal-step::before {
  content: "→";
  margin-right: 8px;
  color: var(--text-secondary, #888);
}

.mcp-proposal-meta {
  display: flex;
  gap: 16px;
  margin: 16px 0;
  padding: 12px;
  background: var(--bg-main, #0f0f0f);
  border-radius: 8px;
}

.mcp-proposal-risk {
  display: flex;
  align-items: center;
  gap: 6px;
}

.mcp-proposal-risk-label {
  font-size: 12px;
  color: var(--text-secondary, #aaa);
}

.mcp-proposal-risk-badge {
  padding: 2px 8px;
  border-radius: 4px;
  font-size: 11px;
  font-weight: 500;
}

.mcp-proposal-risk-badge.low {
  background: rgba(34, 197, 94, 0.2);
  color: #22c55e;
}

.mcp-proposal-risk-badge.medium {
  background: rgba(234, 179, 8, 0.2);
  color: #eab308;
}

.mcp-proposal-risk-badge.high {
  background: rgba(239, 68, 68, 0.2);
  color: #ef4444;
}

.mcp-proposal-needs {
  margin: 16px 0;
}

.mcp-proposal-needs-title {
  font-size: 13px;
  font-weight: 500;
  color: var(--text-secondary, #aaa);
  margin-bottom: 8px;
}

.mcp-proposal-need {
  padding: 8px 12px;
  margin: 4px 0;
  background: rgba(234, 179, 8, 0.1);
  border-left: 3px solid #eab308;
  border-radius: 4px;
  font-size: 12px;
  color: var(--text-main, #fff);
}

.mcp-proposal-why {
  margin: 16px 0;
  padding: 12px;
  background: rgba(59, 130, 246, 0.1);
  border-left: 3px solid #3b82f6;
  border-radius: 4px;
  font-size: 12px;
  color: var(--text-main, #fff);
}

.mcp-proposal-permission {
  margin: 16px 0;
  padding: 12px;
  background: rgba(34, 197, 94, 0.1);
  border-left: 3px solid #22c55e;
  border-radius: 4px;
  font-size: 12px;
  color: var(--text-main, #fff);
}

.mcp-proposal-actions {
  display: flex;
  gap: 8px;
  margin-top: 20px;
  flex-wrap: wrap;
}

.mcp-proposal-btn {
  flex: 1;
  min-width: 120px;
  padding: 12px 20px;
  border: none;
  border-radius: 8px;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
}

.mcp-proposal-btn-primary {
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  color: #fff;
}

.mcp-proposal-btn-primary:hover {
  opacity: 0.9;
  transform: translateY(-1px);
}

.mcp-proposal-btn-secondary {
  background: var(--bg-conv-item-hover, #2d2d2d);
  color: var(--text-main, #fff);
  border: 1px solid var(--border-main, #444);
}

.mcp-proposal-btn-secondary:hover {
  background: var(--bg-conv-item-active, #3d3d3d);
}

.mcp-proposal-btn-tertiary {
  background: transparent;
  color: var(--text-secondary, #aaa);
  border: 1px solid var(--border-main, #444);
}

.mcp-proposal-btn-tertiary:hover {
  color: var(--text-main, #fff);
  border-color: var(--text-main, #fff);
}

.mcp-proposal-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.mcp-proposal-btn-auto-note {
  font-size: 11px;
  color: var(--text-secondary, #888);
  margin-top: 4px;
  text-align: center;
}

/* Light theme */
body.light-theme .mcp-proposal-card {
  background: #ffffff;
  border-color: #ddd;
}

body.light-theme .mcp-proposal-title {
  color: var(--text-dark, #1a1a1a);
}

body.light-theme .mcp-proposal-step {
  background: #f5f5f5;
  color: var(--text-dark, #1a1a1a);
}

body.light-theme .mcp-proposal-meta {
  background: #f5f5f5;
}

body.light-theme .settings-label {
  color: var(--text-dark);
}

body.light-theme .font-size-btn {
  background: #f5f5f5;
  border-color: #ddd;
  color: var(--text-dark);
}

body.light-theme .font-size-btn:hover {
  background: #e8e8e8;
}

body.light-theme .theme-label {
  color: var(--text-dark);
}

/* RAG 업로드 스피너 애니메이션 */
.rag-upload-spinner {
  animation: spin 1s linear infinite;
}

/* RAG 태그 필터 삭제 버튼 스타일 */
.rag-filter-tag-delete {
  transition: opacity 0.2s, background-color 0.2s;
}

.rag-filter-tag-delete:hover {
  opacity: 1 !important;
  background-color: var(--error-color, rgba(255, 0, 0, 0.2)) !important;
}

/* MCP 서버 관리 스타일 */
.mcp-server-card {
  background: var(--bg-conv-item, #1f1f1f);
  border: 1px solid var(--border-main, #444);
  border-radius: 8px;
  padding: 16px;
  margin-bottom: 12px;
  transition: border-color 0.2s, box-shadow 0.2s;
}

.mcp-server-card:hover {
  border-color: var(--accent-color, #4a90e2);
  box-shadow: 0 2px 8px rgba(74, 144, 226, 0.1);
}

.mcp-server-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: 12px;
}

.mcp-server-info {
  flex: 1;
}

.mcp-server-name {
  font-size: 15px;
  font-weight: 600;
  color: var(--text-main, #fff);
  margin-bottom: 4px;
}

.mcp-server-meta {
  display: flex;
  align-items: center;
  gap: 12px;
  font-size: 12px;
  color: var(--text-secondary, #aaa);
  margin-top: 4px;
}

.mcp-server-status {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 8px;
  border-radius: 4px;
  font-size: 11px;
  font-weight: 500;
}

.mcp-server-status.connected {
  background: rgba(76, 175, 80, 0.2);
  color: #4caf50;
}

.mcp-server-status.disconnected {
  background: rgba(158, 158, 158, 0.2);
  color: #9e9e9e;
}

.mcp-server-status.error {
  background: rgba(244, 67, 54, 0.2);
  color: #f44336;
}

.mcp-server-status-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  display: inline-block;
}

.mcp-server-status.connected .mcp-server-status-dot {
  background: #4caf50;
  box-shadow: 0 0 4px rgba(76, 175, 80, 0.6);
}

.mcp-server-status.disconnected .mcp-server-status-dot {
  background: #9e9e9e;
}

.mcp-server-status.error .mcp-server-status-dot {
  background: #f44336;
}

.mcp-server-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.mcp-server-toggle {
  display: flex;
  align-items: center;
  gap: 8px;
}

.mcp-server-toggle-label {
  font-size: 12px;
  color: var(--text-secondary, #aaa);
}

/* MCP 토글 활성화 시 파란색으로 구분 */
.mcp-server-toggle .toggle-switch.active {
  background-color: var(--accent-color, #667eea);
}
.mcp-server-toggle .toggle-switch.active .toggle-slider {
  background-color: #fff;
}

.mcp-server-tools {
  margin-top: 12px;
  padding-top: 12px;
  border-top: 1px solid var(--border-main, #444);
}

.mcp-server-tools-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 8px;
}

.mcp-server-tools-title {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-main, #fff);
}

.mcp-server-tools-count {
  font-size: 11px;
  color: var(--text-secondary, #aaa);
  background: var(--bg-main, #1e1e1e);
  padding: 2px 6px;
  border-radius: 10px;
}

.mcp-server-tools-list {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  max-height: 100px;
  overflow-y: auto;
}

.mcp-tool-badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 4px 8px;
  background: var(--bg-main, #1e1e1e);
  border: 1px solid var(--border-main, #444);
  border-radius: 4px;
  font-size: 11px;
  color: var(--text-secondary, #aaa);
}

.mcp-server-actions-btn {
  padding: 6px 12px;
  background: transparent;
  border: 1px solid var(--border-main, #444);
  border-radius: 6px;
  color: var(--text-main, #fff);
  font-size: 12px;
  cursor: pointer;
  transition: all 0.2s;
}

.mcp-server-actions-btn:hover {
  background: var(--bg-conv-item-hover, #2d2d2d);
  border-color: var(--accent-color, #4a90e2);
}

.mcp-server-actions-btn.danger:hover {
  background: rgba(244, 67, 54, 0.2);
  border-color: #f44336;
  color: #f44336;
}

.mcp-server-empty {
  text-align: center;
  padding: 40px 20px;
  color: var(--text-secondary, #aaa);
}

.mcp-server-empty-icon {
  font-size: 48px;
  margin-bottom: 12px;
  opacity: 0.5;
}

.mcp-server-empty-text {
  font-size: 14px;
  margin-bottom: 8px;
}

.mcp-server-empty-hint {
  font-size: 12px;
  opacity: 0.7;
}

/* 라이트 모드 MCP 스타일 */
body.light-theme .mcp-server-card {
  background: var(--bg-conv-item, #f8f9fa);
  border-color: var(--border-main, #dee2e6);
}

body.light-theme .mcp-server-card:hover {
  border-color: var(--accent-color, #4a90e2);
}

body.light-theme .mcp-server-name {
  color: var(--text-dark);
}

body.light-theme .mcp-server-tools-title {
  color: var(--text-dark);
}

body.light-theme .mcp-tool-badge {
  background: var(--bg-main, #f0f2f5);
  border-color: var(--border-main, #dee2e6);
  color: var(--text-dark);
}

/* 네트워크 상태 표시 */
.network-status {
  font-size: 12px;
  padding: 8px 12px;
  margin-bottom: 8px;
  border-radius: 6px;
  display: flex;
  align-items: center;
  gap: 8px;
  animation: slideIn 0.3s ease-out;
}

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

.network-status.error {
  background: rgba(239, 68, 68, 0.1);
  border-left: 3px solid #ef4444;
  color: #ef4444;
}

.network-status.reconnecting {
  background: rgba(251, 191, 36, 0.1);
  border-left: 3px solid #fbbf24;
  color: #fbbf24;
}

.network-status.success {
  background: rgba(34, 197, 94, 0.1);
  border-left: 3px solid #22c55e;
  color: #22c55e;
}

/* 라이트 모드 네트워크 상태 */
body.light-theme .network-status.error {
  background: rgba(239, 68, 68, 0.15);
  color: #dc2626;
}

body.light-theme .network-status.reconnecting {
  background: rgba(251, 191, 36, 0.15);
  color: #d97706;
}

body.light-theme .network-status.success {
  background: rgba(34, 197, 94, 0.15);
  color: #16a34a;
}

