/* static/css/chat.css */

.chat-container {
    display: flex;
    flex-direction: row;
    height: 100%; /* 부모(main)의 높이를 100% 사용 */
    max-width: 1400px;
    margin: 0 auto; /* 좌우 중앙 정렬 */
    background-color: var(--secondary-background-color);
    box-shadow: 0 0 15px rgba(0, 0, 0, 0.08);
    border-radius: 8px;
    overflow: hidden;
    width: 100%;
    box-sizing: border-box;
}

/* --- 채팅 목록 (사이드바) --- */
.chat-list {
    width: 260px;
    border-right: 1px solid var(--border-color);
    padding: 20px 15px;
    overflow-y: auto; /* 목록 길어지면 스크롤 */
    background-color: var(--chat-list-background);
    display: flex;
    flex-direction: column;
    transition: transform 0.3s ease;
    box-sizing: border-box;
    flex-shrink: 0;
}
/* 스크롤바 스타일 */
.chat-list::-webkit-scrollbar { width: 6px; }
.chat-list::-webkit-scrollbar-track { background: transparent; }
.chat-list::-webkit-scrollbar-thumb { background-color: var(--scrollbar-thumb-color); border-radius: 3px; }

.chat-list h2 {
    margin: 0 0 18px;
    font-size: 1.15em;
    color: var(--secondary-text-color);
    font-weight: 600;
    padding-left: 5px;
}
#conversation-list {
    list-style: none;
    padding: 0;
    margin: 0;
    flex-grow: 1;
    /* overflow-y: auto; */ /* 부모 .chat-list에서 스크롤 처리 */
}
#conversation-list li {
    margin-bottom: 6px;
    padding: 12px 15px;
    border-radius: 6px;
    cursor: pointer;
    transition: background-color 0.2s, color 0.2s;
    display: flex;
    justify-content: space-between;
    align-items: center;
    position: relative;
    color: var(--text-color);
}
#conversation-list li:hover {
    background-color: var(--hover-background-color);
}
#conversation-list li.active {
    background-color: var(--chat-list-item-active-bg);
    color: var(--chat-list-item-active-text);
}
#conversation-list li.active:hover {
     background-color: var(--chat-list-item-active-hover-bg);
}
#conversation-list li .conversation-title {
    flex-grow: 1;
    margin-right: 10px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    font-size: 0.95em;
}
#conversation-list li .edit-button,
#conversation-list li .delete-button {
    background: none;
    border: none;
    color: inherit;
    cursor: pointer;
    font-size: 1em;
    padding: 2px 5px;
    opacity: 0;
    transition: opacity 0.2s, color 0.2s;
    line-height: 1;
    margin-left: 4px;
}
/* 버튼 색상 테마 적용 */
body[data-theme="light"] #conversation-list li .edit-button,
body[data-theme="light"] #conversation-list li .delete-button { color: var(--secondary-text-color); }
body[data-theme="dark"] #conversation-list li .edit-button,
body[data-theme="dark"] #conversation-list li .delete-button { color: var(--text-color); }

#conversation-list li:hover .edit-button,
#conversation-list li:hover .delete-button { opacity: 0.6; }
#conversation-list li .edit-button:hover,
#conversation-list li .delete-button:hover { opacity: 1; }

/* 삭제 버튼 호버 색상 */
body[data-theme="light"] #conversation-list li .delete-button:hover { color: var(--danger-color); }
body[data-theme="dark"] #conversation-list li .delete-button:hover { color: var(--danger-color); }

/* 활성 항목 버튼 스타일 */
#conversation-list li.active .edit-button,
#conversation-list li.active .delete-button { color: var(--chat-list-item-active-text); opacity: 0; }
#conversation-list li.active:hover .edit-button,
#conversation-list li.active:hover .delete-button { opacity: 0.7; }
#conversation-list li.active .edit-button:hover { opacity: 1; }
#conversation-list li.active .delete-button:hover { opacity: 1; color: rgba(255, 255, 255, 0.8); }
body[data-theme="dark"] #conversation-list li.active .delete-button:hover { color: #ffc1c8; }

/* 이름 변경 UI */
.rename-wrapper { display: flex; align-items: center; width: 100%; }
.rename-input {
    flex-grow: 1;
    padding: 5px 8px;
    border: 1px solid var(--input-border-color);
    border-radius: 4px;
    margin-right: 5px;
    font-size: 0.9em;
    background-color: var(--input-background);
    color: var(--text-color);
}
.rename-input:focus {
    border-color: var(--input-focus-border-color);
    box-shadow: var(--input-focus-shadow);
    outline: none;
}
.save-rename-btn, .cancel-rename-btn {
    padding: 5px 9px;
    font-size: 0.9em;
    border-radius: 4px;
    cursor: pointer;
    border: 1px solid transparent;
    background: none;
    opacity: 0.8;
    line-height: 1;
}
.save-rename-btn:hover, .cancel-rename-btn:hover { opacity: 1; }
.save-rename-btn { color: var(--success-color); margin-right: 3px; }
.cancel-rename-btn { color: var(--danger-color); }

/* 로딩/정보/에러 메시지 (채팅 목록 내) */
#conversation-list li.loading, #conversation-list li.info, #conversation-list li.error {
    color: var(--info-text-color);
    font-style: italic;
    text-align: center;
    padding: 15px;
    margin: 10px 0;
    border-radius: 5px;
    background-color: transparent;
    font-size: 0.9em;
    display: block;
    cursor: default;
}
#conversation-list li.error {
    color: var(--danger-color);
    /* background-color: rgba(var(--danger-color-rgb), 0.1); */
    /* border: 1px solid rgba(var(--danger-color-rgb), 0.3); */
    font-weight: normal;
    font-style: normal;
}
#conversation-list li.loading:hover, #conversation-list li.info:hover, #conversation-list li.error:hover { background-color: transparent; }
#conversation-list li.active { background-color: var(--chat-list-item-active-bg); color: var(--chat-list-item-active-text); }

/* --- 채팅 영역 --- */
.chat-area {
    flex: 1;
    display: flex;
    flex-direction: column; /* 내부 요소를 수직으로 배치 */
    overflow: hidden; /* 중요: 내부 스크롤 제어를 위해 */
    background-color: var(--secondary-background-color);
}
#chat-title {
     margin: 0;
     padding: 18px 25px;
     font-size: 1.25em;
     font-weight: 600;
     border-bottom: 1px solid var(--border-color);
     background-color: var(--secondary-background-color);
     color: var(--text-color);
     white-space: nowrap;
     overflow: hidden;
     text-overflow: ellipsis;
     flex-shrink: 0; /* 높이 고정 */
}

/* --- 채팅 기록 (스크롤 영역) --- */
.chat-history {
    flex: 1 1 auto; /* 중요: 남은 모든 공간을 차지하고 내용 적을 때 줄어듦 */
    overflow-y: auto; /* 중요: 내용이 넘칠 경우 수직 스크롤 활성화 */
    padding: 25px;
    /* height: 0; */ /* flex 설정 시 불필요 */
}
/* 스크롤바 스타일 */
.chat-history::-webkit-scrollbar { width: 8px; }
.chat-history::-webkit-scrollbar-track { background: transparent; } /* 트랙 배경 투명 또는 연하게 */
.chat-history::-webkit-scrollbar-thumb { background-color: var(--scrollbar-thumb-color); border-radius: 4px; }

#chat-history-list {
    list-style: none;
    padding: 0;
    margin: 0;
    display: flex;
    flex-direction: column;
}
#chat-history-list li {
    margin-bottom: 15px;
    display: flex;
    flex-direction: column;
}
#chat-history-list li.user-group { align-items: flex-end; }
#chat-history-list li.gemini-group { align-items: flex-start; }

/* 채팅 기록 내 정보/오류/로딩 메시지 */
#chat-history-list li.loading, #chat-history-list li.info, #chat-history-list li.error {
     align-items: center;
     color: var(--info-text-color);
     font-style: italic;
     padding: 10px 0;
     font-size: 0.9em;
     margin-bottom: 10px;
 }
 #chat-history-list li.error {
     color: var(--danger-color);
     font-style: normal;
     font-weight: bold;
 }
 #chat-history-list li.info.clickable-info {
     cursor: pointer;
     text-decoration: underline;
     color: var(--link-color);
     font-style: normal;
 }
 #chat-history-list li.info.clickable-info:hover { color: var(--link-hover-color); }

.message-wrapper {
    display: flex;
    align-items: flex-end;
    max-width: 80%;
    gap: 8px;
}
.user-group .message-wrapper {
    align-self: flex-end;
    flex-direction: row-reverse;
}
.gemini-group .message-wrapper {
    align-self: flex-start;
    flex-direction: row;
}

.message {
    padding: 10px 14px;
    border-radius: 20px;
    word-wrap: break-word;
    overflow-wrap: break-word;
    line-height: 1.4;
    box-shadow: 0 1px 2px rgba(0,0,0,0.1);
    position: relative;
    flex-shrink: 1;
    font-size: 14px;
    max-width: 100%;
}
.message-time {
    font-size: 0.75em;
    color: var(--message-time-color);
    white-space: nowrap;
    margin-bottom: 3px;
    flex-shrink: 0;
}

.message.user {
    background-color: var(--user-message-bg);
    color: var(--user-message-text);
    border-bottom-right-radius: 5px;
}
.message.gemini {
    background-color: var(--gemini-message-bg);
    color: var(--gemini-message-text);
    border-bottom-left-radius: 5px;
}

.message.system, .message.error {
    background-color: var(--info-background-color);
    color: var(--danger-color);
    border-radius: 5px;
    font-style: normal;
    font-size: 0.9em;
    padding: 8px 12px;
    max-width: 100%;
    box-shadow: none;
    align-self: center;
    text-align: center;
}

.message.loading {
    background-color: var(--gemini-message-bg);
    color: var(--info-text-color); /* 점 색상에 영향 */
    display: inline-flex; /* 내용만큼 너비 */
    align-items: center;
    justify-content: center; /* 점 중앙 정렬 */
    gap: 5px;
    border-bottom-left-radius: 5px;
    padding: 10px 14px; /* 패딩 유지 또는 조정 */
    border-radius: 20px;
    box-shadow: 0 1px 2px rgba(0,0,0,0.1);
    min-height: 40px; /* 최소 높이 확보 */
}

/* 날짜 구분선 */
.date-separator {
    text-align: center;
    margin: 25px 0 20px;
    font-size: 0.8em;
    color: var(--info-text-color);
    align-self: center;
}
.date-separator span {
    background-color: var(--info-background-color);
    padding: 5px 14px;
    border-radius: 12px;
}

/* 코드 블록 */
pre { margin: 1em 0; }
pre code.hljs {
    display: block;
    overflow-x: auto;
    padding: 1.2em;
    background: var(--pre-background);
    color: var(--pre-text-color);
    border-radius: 6px;
    font-family: 'SFMono-Regular', Consolas, 'Liberation Mono', Menlo, Courier, monospace;
    font-size: 0.9em;
    line-height: 1.6;
}
/* 인라인 코드 */
code:not(.hljs) {
     background-color: var(--code-background);
     color: var(--code-text-color);
     padding: 0.2em 0.4em;
     margin: 0 1px;
     font-size: 85%;
     border-radius: 3px;
     font-family: 'SFMono-Regular', Consolas, 'Liberation Mono', Menlo, Courier, monospace;
     word-break: break-word;
}

/* --- 메시지 입력 영역 --- */
.chat-input-area {
    padding: 10px 20px;
    background-color: var(--chat-input-bg);
    border-top: 1px solid var(--border-color);
    flex-shrink: 0; /* 높이 고정 */
}
#message-form {
    display: flex;
    align-items: flex-end;
}
#message-form .form-group {
    flex-grow: 1;
    margin-right: 10px;
    margin-bottom: 0;
}
textarea#message-input.form-control {
    border-radius: 20px;
    padding: 12px 16px;
    line-height: 1.4;
    resize: none;
    min-height: 44px;
    max-height: 160px;
    overflow-y: auto;
    border: none;
    font-size: 14px;
    background-color: var(--chat-input-textarea-bg);
    color: var(--text-color);
    outline: none;
    box-shadow: none;
    margin-bottom: 0;
}
textarea#message-input.form-control::placeholder {
    color: var(--info-text-color);
    opacity: 0.8;
}
textarea#message-input.form-control:focus {
     background-color: var(--chat-input-textarea-focus-bg);
     border-color: transparent;
     box-shadow: none;
}

/* 전송 버튼 */
#send-button {
    background: none;
    color: var(--primary-color);
    border: none;
    border-radius: 50%;
    width: 44px;
    height: 44px;
    padding: 0;
    cursor: pointer;
    display: inline-flex;
    justify-content: center;
    align-items: center;
    flex-shrink: 0;
    transition: transform 0.2s ease, color 0.2s ease;
    font-size: 1rem;
    line-height: 1;
}
#send-button svg { width: 20px; height: 20px; fill: currentColor; }
#send-button:hover { transform: scale(1.1); }
#send-button:disabled, #send-button.disabled {
    color: var(--info-text-color);
    cursor: not-allowed;
    transform: none;
    opacity: 0.5;
}
.send-button.loading {
    opacity: 0.5;
    cursor: wait;
}

/* 컨텍스트 메뉴 */
.context-menu {
    position: absolute;
    z-index: 1500;
    background-color: var(--secondary-background-color);
    border: 1px solid var(--border-color);
    box-shadow: 0 2px 5px rgba(0,0,0,0.15);
    border-radius: 4px;
    padding: 5px 0;
    min-width: 120px;
}
.context-menu ul { list-style: none; padding: 0; margin: 0; }
.context-menu li {
    padding: 8px 15px;
    cursor: pointer;
    font-size: 0.9em;
    color: var(--text-color);
}
.context-menu li:hover { background-color: var(--hover-background-color); }
#delete-option { color: var(--danger-color); }
body[data-theme="light"] #delete-option:hover { background-color: #f8d7da; }
body[data-theme="dark"] #delete-option:hover { background-color: rgba(var(--danger-color-rgb), 0.2); }

/* 점 깜빡이는 애니메이션 */
.dot-flashing {
  position: relative;
  width: 8px; height: 8px;
  border-radius: 5px;
  background-color: var(--info-text-color);
  color: var(--info-text-color);
  animation: dotFlashing 1s infinite linear alternate;
  animation-delay: .5s;
  display: inline-block;
  vertical-align: middle;
  margin-left: 0;
}
.dot-flashing::before, .dot-flashing::after {
  content: '';
  display: inline-block;
  position: absolute;
  top: 0;
  width: 8px; height: 8px;
  border-radius: 5px;
  background-color: var(--info-text-color);
  color: var(--info-text-color);
  animation: dotFlashing 1s infinite alternate;
}
.dot-flashing::before { left: -12px; animation-delay: 0s; }
.dot-flashing::after { left: 12px; animation-delay: 1s; }

@keyframes dotFlashing {
  0% { background-color: var(--info-text-color); opacity: 1; }
  50%, 100% { background-color: var(--info-text-color); opacity: 0.2; }
}