/* CSSW ShareLine 공개 채팅 전용 스타일 */
/* KCPASS 스타일 - 공공기관 톤앤매너 */

:root {
    --primary-blue: #2563eb;
    --secondary-blue: #3b82f6;
    --light-blue: #dbeafe;
    --text-dark: #1e293b;
    --text-gray: #64748b;
    --bg-light: #f8fafc;
    --border-color: #e2e8f0;
    --ai-divider-color: #c8d9ee;
    /* AI 답변 구분선 색상 */
    --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.1);
    --shadow-md: 0 4px 6px rgba(0, 0, 0, 0.1);
    --shadow-lg: 0 10px 25px rgba(0, 0, 0, 0.1);
}

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

body {
    font-family: 'Noto Sans KR', 'Malgun Gothic', sans-serif;
    background: linear-gradient(180deg, #f0f7ff 0%, #ffffff 100%);
    height: 100vh;
    overflow: hidden;
}

/* 헤더 - KCPASS 스타일 */
.public-header {
    background: #ffffff;
    padding: 20px 40px;
    box-shadow: var(--shadow-sm);
    border-bottom: 3px solid var(--primary-blue);
    display: flex;
    justify-content: space-between;
    align-items: center;
    position: relative;
    transition: padding-left 0.3s ease-in-out;
}

@media (min-width: 769px) {
    body.sidebar-open .public-header {
        padding-left: 360px;
        /* 320px sidebar width + 40px padding */
    }
}


.public-header::before {
    content: '';
    position: absolute;
    bottom: -3px;
    left: 0;
    width: 100%;
    height: 3px;
    background: linear-gradient(90deg, var(--primary-blue), var(--secondary-blue));
}

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

.brand-logo {
    height: 44px;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0;
}

.brand-logo img {
    height: 24px;
    width: auto;
    object-fit: contain;
}

.brand-divider {
    width: 1.5px;
    height: 36px;
    background: linear-gradient(180deg,
            rgba(37, 99, 235, 0.15) 0%,
            rgba(37, 99, 235, 0.4) 50%,
            rgba(37, 99, 235, 0.15) 100%);
    border-radius: 1px;
}

.brand-text h1 {
    margin: 0;
    font-size: 22px;
    color: var(--text-dark);
    font-weight: 700;
    letter-spacing: -0.5px;
}

.brand-subtitle {
    margin: 4px 0 0 0;
    font-size: 22px;
    color: var(--text-dark);
    font-weight: 700;
}

.public-notice {
    font-size: 13px;
    color: var(--text-gray);
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 16px;
    background: var(--light-blue);
    border-radius: 20px;
    font-weight: 500;
}

.public-notice i {
    color: var(--primary-blue);
    font-size: 16px;
}

/* 채팅 컨테이너 */
.chat-container {
    max-width: 1280px;
    margin: 14px auto;
    height: calc(100vh - 109px);
    background: #ffffff url('/static/images/cssw/bg.png') no-repeat center center;
    background-size: 80%;
    /* SVG scales perfectly, 80% covers nicely */
    border-radius: 20px;
    box-shadow: var(--shadow-lg);
    border: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    position: relative;
}


/* 채팅 영역 */
#chat-box,
.sheet-chat-container {
    flex: 1;
    padding: 32px 24px;
    overflow-y: auto;
    background: transparent;
}

/* 환영 메시지 */
.welcome-message {
    text-align: center;
    padding: 60px 20px;
    color: var(--text-gray);
    background: #ffffff00;
    /* backdrop-filter: blur(10px); */
    border-radius: 16px;
    margin: 40px 20px;
    display: flex;
    flex-direction: column;
    align-items: anchor-center;
}

.welcome-message h2 {
    padding: 8px 20px;
    background-color: var(--primary-blue);
    border-radius: 8px;
    color: white;
    margin-bottom: 16px;
    font-size: 28px;
    font-weight: 700;
}

.welcome-message p {
    margin: 10px 0;
    font-size: 15px;
    color: var(--text-gray);
}

.welcome-message .tip {
    font-size: 14px;
    color: #475569;
    margin-top: 24px;
    padding: 20px 24px;
    background: rgba(255, 255, 255, 0.95);
    backdrop-filter: blur(5px);
    border-radius: 16px;
    display: inline-block;
    position: relative;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.05);
    border: 1px solid rgba(37, 99, 235, 0.1);
    text-align: left;
    max-width: 100%;
}

.tip-title {
    font-weight: 700;
    color: #1e293b;
    margin-bottom: 12px;
    display: flex;
    align-items: center;
    gap: 3px;
    flex-wrap: wrap;
    word-break: keep-all;
    line-height: 1.5;
}

.tip-list {
    list-style: none;
    padding: 0;
    margin: 0;
}

.tip-list li {
    position: relative;
    padding-left: 16px;
    margin-bottom: 6px;
    line-height: 1.5;
    color: #64748b;
}

.tip-list li::before {
    content: "•";
    position: absolute;
    left: 4px;
    color: var(--primary-blue);
    font-weight: bold;
}

/* 메시지 스타일 */
.message {
    margin-bottom: 20px;
    animation: fadeIn 0.3s ease-out;
    width: 100%;
    display: flex;
}

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

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.message.user {
    justify-content: flex-end;
    text-align: right;
    align-items: end;
}

.message.assistant {
    justify-content: flex-start;
    flex-direction: column;
    align-items: flex-start;
}

.message-content {
    font-size: 14px;
    line-height: 1.6;
    word-wrap: break-word;
    word-break: break-word;
    /* white-space: pre-wrap; */
}

/* 사용자 메시지 */
#chat-box .message.user .message-content,
.sheet-chat-container .message.user .message-content {
    width: fit-content;
    color: white;
    backdrop-filter: blur(10px);
    border-radius: 18px;
    border-bottom-right-radius: 4px;
    text-align: right;
    background: var(--primary-blue);
    padding: 10px;
}

/* 출처 아바타 컨테이너 */
.source-avatars-container {
    display: flex;
    align-items: center;
    gap: 4px;
    margin-bottom: 12px;
    padding-left: 4px;
    cursor: pointer;
    width: fit-content;
}

/* AI 답변 */
.message.assistant .message-content {
    color: #727272 !important;
    border-top: 1px solid var(--ai-divider-color) !important;
    border-bottom: 1px solid var(--ai-divider-color) !important;
    padding: 18px 16px !important;
    overflow-wrap: break-word;
    width: 100% !important;
    font-size: 15.5px !important;
    font-weight: 500 !important;
    line-height: 1.7 !important;
    background: rgba(255, 255, 255, 0.85);
    backdrop-filter: blur(10px);
    border-radius: 12px;
}

.message.assistant .message-content p {
    margin: 0 0 14px 0 !important;
}

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

/* 섹션 제목처럼 보이는 p 태그 bold 처리 */
/* 리스트 바로 앞의 p 태그 */
.message.assistant .message-content p:has(+ ul),
.message.assistant .message-content p:has(+ ol) {
    font-weight: 700 !important;
    color: #686868 !important;
    margin-top: 20px !important;
    margin-bottom: 10px !important;
    font-size: 16px !important;
}

/* 리스트 바로 뒤의 p 태그 (다음 섹션 제목) */
.message.assistant .message-content ul+p,
.message.assistant .message-content ol+p {
    font-weight: 700 !important;
    color: #686868 !important;
    margin-top: 20px !important;
    margin-bottom: 10px !important;
    font-size: 16px !important;
}

/* 첫 번째 p는 항상 제목 */
.message.assistant .message-content>p:first-child {
    font-weight: 700 !important;
    color: #686868 !important;
    margin-top: 0 !important;
    margin-bottom: 10px !important;
    font-size: 16px !important;
}

/* [Fix] 첫 번째 p가 유일한 요소일 경우 여백 제거 */
.message.assistant .message-content>p:first-child:only-child {
    margin-bottom: 0 !important;
}

.message.assistant .message-content ul,
.message.assistant .message-content ol {
    margin: 10px 0 !important;
    padding-left: 24px;
}

.message.assistant .message-content li {
    margin: 6px 0;
}

/* AI 답변 내 헤더 스타일 */
.message.assistant .message-content h1,
.message.assistant .message-content h2,
.message.assistant .message-content h3,
.message.assistant .message-content h4,
.message.assistant .message-content h5,
.message.assistant .message-content h6 {
    font-weight: 700;
    color: #1e293b;
    margin-top: 18px;
    margin-bottom: 12px;
    line-height: 1.4;
}

.message.assistant .message-content h1 {
    font-size: 24px;
    border-bottom: 2px solid var(--border-color);
    padding-bottom: 8px;
}

.message.assistant .message-content h2 {
    font-size: 20px;
    border-bottom: 1px solid var(--border-color);
    padding-bottom: 6px;
}

.message.assistant .message-content h3 {
    font-size: 18px;
}

.message.assistant .message-content h4 {
    font-size: 16px;
}

.message.assistant .message-content h5 {
    font-size: 15px;
}

.message.assistant .message-content h6 {
    font-size: 14px;
}

/* AI 답변 내 테이블 스타일 */
.message.assistant .message-content table {
    width: 100%;
    border-collapse: collapse;
    margin: 16px 0;
    background: white;
    border-radius: 8px;
    overflow: hidden;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.08);
}

.message.assistant .message-content table thead {
    background: linear-gradient(135deg, #f8fafc 0%, #f1f5f9 100%);
}

.message.assistant .message-content table th {
    padding: 12px 16px;
    text-align: left;
    font-weight: 700;
    color: #1e293b;
    font-size: 14px;
    border-bottom: 2px solid var(--border-color);
    border-right: 1px solid var(--border-color);
}

.message.assistant .message-content table th:last-child {
    border-right: none;
}

.message.assistant .message-content table td {
    padding: 10px 16px;
    border-bottom: 1px solid var(--border-color);
    border-right: 1px solid #f1f5f9;
    color: #475569;
    font-size: 14px;
    line-height: 1.6;
}

.message.assistant .message-content table td:last-child {
    border-right: none;
}

.message.assistant .message-content table tbody tr {
    transition: background-color 0.2s ease;
}

.message.assistant .message-content table tbody tr:hover {
    background-color: rgba(37, 99, 235, 0.03);
}

.message.assistant .message-content table tbody tr:last-child td {
    border-bottom: none;
}

/* AI 답변 내 강조 스타일 */
.message.assistant .message-content strong,
.message.assistant .message-content b {
    font-weight: 700 !important;
    color: #686868 !important;
}

.message.assistant .message-content p strong,
.message.assistant .message-content p b {
    font-weight: 700 !important;
    color: #686868 !important;
}

.message.assistant .message-content em,
.message.assistant .message-content i {
    font-style: italic !important;
    color: #475569 !important;
}

/* 인라인 코드 스타일 */
.message.assistant .message-content code {
    background: rgba(175, 184, 193, 0.2);
    padding: 2px 6px;
    border-radius: 4px;
    font-family: 'Consolas', 'Monaco', 'Courier New', monospace;
    font-size: 14px;
    color: #e74c3c;
    font-weight: 500;
}

/* 코드 블록 내부의 코드는 위 스타일 제외 */
.message.assistant .message-content .code-block-wrapper code {
    background: transparent;
    padding: 0;
    color: inherit;
    font-weight: normal;
}

/* 인용구 스타일 */
.message.assistant .message-content blockquote {
    margin: 12px 0;
    padding: 12px 16px;
    border-left: 4px solid var(--primary-blue);
    background: rgba(37, 99, 235, 0.05);
    border-radius: 4px;
    color: #475569;
}

.message.assistant .message-content blockquote p {
    margin: 0;
}

/* 수평선 스타일 */
.message.assistant .message-content hr {
    margin: 20px 0;
    border: none;
    border-top: 2px solid var(--border-color);
}

/* 링크 스타일 */
.message.assistant .message-content a {
    color: var(--primary-blue);
    text-decoration: none;
    font-weight: 600;
    transition: all 0.2s;
    border-bottom: 1px solid transparent;
}

.message.assistant .message-content a:hover {
    color: var(--secondary-blue);
    border-bottom: 1px solid var(--secondary-blue);
}

/* 체크박스 리스트 스타일 */
.message.assistant .message-content li.task-list-item {
    list-style: none;
}

.message.assistant .message-content li.task-list-item input[type="checkbox"] {
    margin-right: 8px;
}

/* AI 답변의 코드 블록 스타일 */
.message.assistant .message-content .code-block-wrapper {
    margin: 12px 0 6px 0 !important;
    border-radius: 8px;
    overflow: hidden;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

.message.assistant .message-content .code-block-wrapper:first-child {
    margin-top: 6px !important;
}

.message.assistant .message-content .code-block-wrapper:last-child {
    margin-bottom: 0 !important;
}

.message.assistant .message-content>*:last-child {
    margin-bottom: 0 !important;
}

/* 코드 블록이 아닌 일반 pre 태그 처리 */
.message.assistant .message-content>pre {
    margin: 0 !important;
    padding: 0 !important;
}

/* 입력 영역 - llm_chat_new.html 스타일 */
.input-area {
    padding: 20px 24px 24px 24px;
    background: white;
    border-top: 2px solid var(--border-color);
}

.unified-input-container {
    background: white;
    border: 2px solid var(--border-color);
    border-radius: 20px;
    overflow: hidden;
    transition: all 0.3s ease;
    box-shadow: var(--shadow-sm);
    width: 100%;
}

.unified-input-container:focus-within {
    border-color: var(--primary-blue);
    box-shadow: 0 0 0 4px rgba(37, 99, 235, 0.1);
}

/* 상단 입력 영역 */
.input-section {
    display: flex;
    align-items: center;
    padding: 14px 18px;
    gap: 12px;
    flex: 1;
}

#user-input {
    flex: 1;
    border: none;
    outline: none;
    font-size: 15px;
    font-family: inherit;
    resize: none;
    min-height: 28px;
    max-height: 200px;
    line-height: 1.6;
    background: transparent;
    width: 100%;
}

#user-input::placeholder {
    color: #94a3b8;
}

.voice-btn {
    background: transparent;
    border: none;
    color: var(--text-gray);
    cursor: pointer;
    padding: 8px;
    border-radius: 8px;
    transition: all 0.2s;
    display: flex;
    align-items: center;
    justify-content: center;
}

.voice-btn:hover {
    background: var(--bg-light);
    color: var(--primary-blue);
}

.voice-btn i {
    font-size: 18px;
}

/* 하단 컨트롤 영역 */
.controls-area {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px 18px;
    /* background: var(--bg-light);
    border-top: 1px solid var(--border-color); */
}

.left-controls {
    display: flex;
    gap: 6px;
    align-items: center;
    flex: 1;
}

/* 전송 버튼 */
.unified-send-btn {
    background: linear-gradient(135deg, var(--primary-blue) 0%, var(--secondary-blue) 100%);
    color: white;
    border: none;
    border-radius: 25px;
    padding: 10px 15px;
    cursor: pointer;
    font-size: 16px;
    font-weight: 600;
    font-family: inherit;
    transition: all 0.3s ease;
    box-shadow: var(--shadow-md);
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
}

.unified-send-btn:hover:not(:disabled) {
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(37, 99, 235, 0.4);
}

.unified-send-btn:active:not(:disabled) {
    transform: translateY(0);
}

.unified-send-btn:disabled {
    background: linear-gradient(135deg, #cbd5e1 0%, #94a3b8 100%);
    cursor: not-allowed;
    transform: none;
    box-shadow: none;
    opacity: 0.6;
}

.unified-send-btn i {
    font-size: 16px;
}

/* 로딩 애니메이션 */
.layout-loader {
    display: none;
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    z-index: 1000;
}

.wave-container {
    display: flex;
    gap: 10px;
    padding: 20px;
    background: white;
    border-radius: 16px;
    box-shadow: var(--shadow-lg);
}

.wave {
    width: 14px;
    height: 14px;
    background: var(--primary-blue);
    border-radius: 50%;
    animation: wave 1.4s ease-in-out infinite;
}

.wave:nth-child(2) {
    animation-delay: 0.1s;
}

.wave:nth-child(3) {
    animation-delay: 0.2s;
}

.wave:nth-child(4) {
    animation-delay: 0.3s;
}

.wave:nth-child(5) {
    animation-delay: 0.4s;
}

@keyframes wave {

    0%,
    100% {
        transform: translateY(0);
        background: var(--primary-blue);
    }

    50% {
        transform: translateY(-20px);
        background: var(--secondary-blue);
    }
}

/* AI 답변 준비 중 로딩 메시지 */
.ai-loading-message {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px 16px;
    color: var(--text-gray);
    font-size: 14px;
    border-top: 1px solid var(--ai-divider-color);
    border-bottom: 1px solid var(--ai-divider-color);
    margin-bottom: 20px;
    gap: 12px;
    background: rgba(255, 255, 255, 0.85);
    backdrop-filter: blur(10px);
    border-radius: 12px;
}

.ai-loading-message .loading-text {
    font-weight: 500;
}

.ai-loading-message .loading-dots {
    display: inline-flex;
    align-items: center;
    gap: 6px;
}

.ai-loading-message .loading-dots .dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--primary-blue);
    animation: dotFlashing 1.4s infinite ease-in-out;
}

.ai-loading-message .loading-dots .dot:nth-child(1) {
    animation-delay: 0s;
}

.ai-loading-message .loading-dots .dot:nth-child(2) {
    animation-delay: 0.2s;
}

.ai-loading-message .loading-dots .dot:nth-child(3) {
    animation-delay: 0.4s;
}

@keyframes dotFlashing {

    0%,
    80%,
    100% {
        opacity: 0.3;
        transform: scale(0.8);
    }

    40% {
        opacity: 1;
        transform: scale(1.2);
    }
}

/* 페이드 아웃 애니메이션 (로딩 메시지 제거용) */
.fade-out {
    animation: fadeOut 0.5s ease-out forwards;
}

@keyframes fadeOut {
    from {
        opacity: 1;
        transform: translateY(0);
    }

    to {
        opacity: 0;
        transform: translateY(-10px);
    }
}

/* 페이드 인 애니메이션 (AI 메시지 표시용) */
.fade-in {
    animation: fadeIn 0.5s ease-out forwards;
}

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

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* 스크롤바 스타일 */
#chat-box::-webkit-scrollbar,
.sheet-chat-container::-webkit-scrollbar {
    width: 8px;
}

#chat-box::-webkit-scrollbar-track,
.sheet-chat-container::-webkit-scrollbar-track {
    background: transparent;
}

#chat-box::-webkit-scrollbar-thumb,
.sheet-chat-container::-webkit-scrollbar-thumb {
    background: #cbd5e1;
    border-radius: 4px;
}

#chat-box::-webkit-scrollbar-thumb:hover,
.sheet-chat-container::-webkit-scrollbar-thumb:hover {
    background: #94a3b8;
}

/* 코드 블록 스타일 - KCPASS 톤앤매너 */
.code-block-wrapper {
    margin: 8px 0 !important;
    /* 여백 최소화 */
    border-radius: 12px;
    overflow: hidden;
    border: 1px solid var(--border-color);
    background: #1e293b;
}

.code-block-header {
    background: linear-gradient(135deg, #334155 0%, #1e293b 100%);
    padding: 10px 16px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 1px solid #475569;
    min-height: 40px;
    /* 최소 높이 확보 */
}

.code-block-header span {
    color: #94a3b8;
    font-size: 12px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    flex: 1;
    /* 남은 공간 차지 */
}

.copy-btn {
    background: var(--primary-blue);
    color: white;
    border: none;
    padding: 6px 12px;
    border-radius: 6px;
    cursor: pointer;
    font-size: 12px;
    font-weight: 500;
    transition: all 0.3s;
    display: flex;
    align-items: center;
    justify-content: center;
    /* 텍스트 가운데 정렬 */
    gap: 6px;
    white-space: nowrap;
    /* 줄바꿈 방지 */
    flex-shrink: 0;
    /* 버튼 크기 고정 */
}

.copy-btn:hover {
    background: var(--secondary-blue);
    transform: translateY(-1px);
}

.code-block-wrapper pre {
    margin: 0 !important;
    padding: 12px 14px !important;
    overflow-x: auto;
    background: #1e293b;
}

/* AI 답변 내부의 코드 블록 pre는 패딩 유지 */
.message.assistant .message-content .code-block-wrapper pre {
    padding: 12px 14px !important;
    margin: 0 !important;
}

.code-block-wrapper code {
    font-family: 'Consolas', 'Monaco', 'Courier New', monospace;
    font-size: 13px;
    line-height: 1.5;
    /* 줄 간격 조금 줄임 */
}

/* 코드 블록 내부의 추가 여백 제거 */
.code-block-wrapper pre:first-child {
    margin-top: 0 !important;
}

.code-block-wrapper pre:last-child {
    margin-bottom: 0 !important;
}

/* 반응형 디자인 - 모바일 최적화 */
@media (max-width: 1024px) {
    .chat-container {
        max-width: 100%;
        margin: 16px;
        /* 헤더 높이 (padding 20px * 2 + 로고 44px + subtitle 17px + border 3px) + margin 16px * 2 = 136px */
        height: calc(100vh - 136px);
        border-radius: 16px;
        flex: 1;
    }

    /* 코드 블록 */
    .message.assistant .message-content .code-block-wrapper {
        margin: 10px 0 5px 0 !important;
    }

    .message.assistant .message-content .code-block-wrapper:last-child {
        margin-bottom: 0 !important;
    }

    .message.assistant .message-content .code-block-wrapper pre {
        padding: 11px 13px !important;
        margin: 0 !important;
    }
}


@media (max-width: 768px) {
    body {
        height: 100dvh;
        overflow: hidden;
        display: flex;
        flex-direction: column;
    }

    .public-header {
        padding: 12px 16px;
        flex-direction: row;
        gap: 12px;
    }

    .header-left {
        gap: 10px;
    }

    .brand-logo {
        height: 36px;
        padding: 0;
    }

    .brand-logo img {
        height: 18px;
    }

    .brand-divider {
        height: 30px;
        width: 1.5px;
    }

    .brand-text h1 {
        font-size: 16px;
        line-height: 1.3;
    }

    .brand-subtitle {
        font-size: 18px;
        margin-top: 2px;
    }

    .chat-container {
        flex: 1;
        margin: 8px;
        /* 헤더 높이 (padding 12px * 2 + 로고 36px + subtitle 14px + border 3px) + margin 8px * 2 = 93px */
        height: calc(100vh - 93px);
        height: calc(100dvh - 93px);
        /* 모바일 주소창 대응 */
        border-radius: 12px;
    }

    #chat-box,
    .sheet-chat-container {
        padding: 16px 12px;
    }

    /* 사용자 메시지 */
    #chat-box .message.user .message-content,
    .sheet-chat-container .message.user .message-content {
        width: fit-content;
        font-size: 13px;
        border-radius: 16px;
        border-bottom-right-radius: 3px;
        background: var(--primary-blue);
        padding: 10px;
    }

    /* AI 답변 */
    .message.assistant .message-content {
        font-size: 14.5px !important;
        font-weight: 500 !important;
        padding: 16px 0 !important;
        border-top: 1px solid var(--ai-divider-color) !important;
        border-bottom: 1px solid var(--ai-divider-color) !important;
    }

    .welcome-message {
        padding: 30px 16px;
    }

    .welcome-message h2 {
        font-size: 22px;
    }

    .welcome-message p {
        font-size: 14px;
    }

    .welcome-message .tip {
        font-size: 12px;
        padding: 10px 16px;
    }

    /* 로딩 메시지 */
    .ai-loading-message {
        padding: 16px 12px;
        font-size: 13px;
    }

    .ai-loading-message .loading-dots .dot {
        width: 7px;
        height: 7px;
    }

    .input-area {
        padding: 12px;
    }

    .input-area .warning {
        font-size: 10px;
    }

    .unified-input-container {
        border-radius: 16px;
    }

    .input-section {
        padding: 10px 12px;
    }

    #user-input {
        font-size: 14px;
    }

    .controls-area {
        padding: 8px 12px;
        flex-wrap: wrap;
    }

    .left-controls {
        flex: 1;
        min-width: 0;
        gap: 4px;
    }

    .unified-send-btn {
        padding: 8px 20px;
        font-size: 13px;
        border-radius: 10px;
    }

    .code-block-wrapper {
        border-radius: 10px;
        margin: 6px 0 !important;
        /* 여백 최소화 */
    }

    .message.assistant .message-content .code-block-wrapper {
        margin: 10px 0 4px 0 !important;
    }

    .message.assistant .message-content .code-block-wrapper:last-child {
        margin-bottom: 0 !important;
    }

    .code-block-header {
        padding: 8px 12px;
    }

    .code-block-wrapper pre {
        padding: 10px 12px !important;
        font-size: 12px;
        margin: 0 !important;
    }

    .message.assistant .message-content .code-block-wrapper pre {
        padding: 10px 12px !important;
        margin: 0 !important;
    }

    .copy-btn {
        padding: 4px 10px;
        font-size: 11px;
    }
}

@media (max-width: 480px) {
    body {
        height: 100dvh;
        overflow: hidden;
        display: flex;
        flex-direction: column;
    }

    .public-header {
        padding: 10px 12px;
    }

    .brand-logo {
        height: 28px;
        padding: 0;
    }

    .brand-logo img {
        height: 18px;
    }

    .brand-divider {
        height: 24px;
        width: 1px;
    }

    .brand-text h1 {
        font-size: 14px;
    }

    .brand-subtitle {
        font-size: 16px;
    }

    .chat-container {
        margin: 4px;
        /* 헤더 높이 (padding 10px * 2 + 로고 28px + subtitle 12px + border 3px) + margin 4px * 2 = 73px */
        height: calc(100vh - 73px);
        height: calc(100dvh - 73px);

        /* 모바일 주소창 대응 */
        border-radius: 10px;
    }

    #chat-box {
        padding: 12px 8px;
    }

    /* 사용자 메시지 */
    #chat-box .message.user .message-content {
        width: fit-content;
        font-size: 12px;
        border-radius: 14px;
        border-bottom-right-radius: 3px;
        background: var(--primary-blue);
        padding: 8px;
    }

    /* AI 답변 */
    .message.assistant .message-content {
        font-size: 13.5px !important;
        font-weight: 500 !important;
        padding: 14px 0 !important;
        border-top: 1px solid var(--ai-divider-color) !important;
        border-bottom: 1px solid var(--ai-divider-color) !important;
    }

    /* 로딩 메시지 */
    .ai-loading-message {
        padding: 14px 10px;
        font-size: 12px;
        gap: 8px;
    }

    .ai-loading-message .loading-dots .dot {
        width: 6px;
        height: 6px;
    }

    /* 코드 블록 */
    .message.assistant .message-content .code-block-wrapper {
        margin: 8px 0 4px 0 !important;
    }

    .message.assistant .message-content .code-block-wrapper:last-child {
        margin-bottom: 0 !important;
    }

    .message.assistant .message-content .code-block-wrapper pre {
        padding: 8px 10px !important;
        margin: 0 !important;
    }
}


/* 버튼 스타일 (Bootstrap 호환) */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-weight: 500;
    text-align: center;
    vertical-align: middle;
    user-select: none;
    border: 1px solid transparent;
    padding: 0.375rem 0.75rem;
    font-size: 1rem;
    line-height: 1.5;
    border-radius: 0.25rem;
    transition: color 0.15s ease-in-out, background-color 0.15s ease-in-out, border-color 0.15s ease-in-out, box-shadow 0.15s ease-in-out;
    cursor: pointer;
    background-color: transparent;
    font-family: inherit;
}

.btn-sm {
    padding: 0.25rem 0.5rem;
    font-size: 0.875rem;
    line-height: 1.5;
    border-radius: 0.2rem;
}

.btn-outline-primary {
    color: var(--primary-blue);
    border-color: var(--primary-blue);
}

.btn-outline-primary:hover {
    color: #fff;
    background-color: var(--primary-blue);
    border-color: var(--primary-blue);
}

.btn-outline-primary i {
    margin-right: 4px;
}

/* === Custom Confirmation Modal === */
.custom-modal-backdrop {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.4);
    z-index: 10000;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    visibility: hidden;
    transition: all 0.2s ease;
}

.custom-modal-backdrop.show {
    opacity: 1;
    visibility: visible;
}

.custom-modal {
    background: white;
    border-radius: 16px;
    width: 90%;
    max-width: 340px;
    padding: 24px;
    box-shadow: 0 10px 25px rgba(0, 0, 0, 0.1);
    transform: translateY(20px);
    transition: transform 0.2s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    text-align: center;
}

.custom-modal-backdrop.show .custom-modal {
    transform: translateY(0);
}



.custom-modal-title {
    font-size: 18px;
    font-weight: 700;
    color: #1e293b;
    margin-bottom: 8px;
}

.custom-modal-message {
    font-size: 15px;
    color: #64748b;
    margin-bottom: 24px;
    line-height: 1.5;
    word-break: keep-all;
    /* 한글 줄바꿈 교정 */
    word-wrap: break-word;
}

.custom-modal-actions {
    display: flex;
    gap: 12px;
}

.custom-modal-btn {
    flex: 1;
    padding: 12px;
    border-radius: 10px;
    font-size: 15px;
    font-weight: 600;
    border: none;
    cursor: pointer;
    transition: all 0.2s;
}

.custom-modal-btn.cancel {
    background: #f1f5f9;
    color: #64748b;
}

.custom-modal-btn.cancel:active {
    background: #e2e8f0;
}

.custom-modal-btn.confirm {
    background: #3b82f6;
    color: white;
}

.custom-modal-btn.confirm:active {
    background: #2563eb;
    transform: scale(0.98);
}

/* ==================== 수식 렌더링 스타일 ==================== */

/* KaTeX 수식 스타일 */
.katex-display {
    margin: 1em 0;
    overflow-x: auto;
    overflow-y: hidden;
}

.katex {
    font-size: 1.1em;
}

/* 수식 렌더링 중 깜빡임 방지 */
.message-content {
    min-height: 20px;
}

/* 인라인 수식 */
.katex-inline {
    display: inline-block;
    vertical-align: middle;
}

/* Display 수식 */
.katex-display>.katex {
    display: block;
    text-align: center;
}

/* 수식 에러 스타일 */
.katex-error {
    color: #cc0000;
    font-family: monospace;
    background: #ffebee;
    padding: 2px 4px;
    border-radius: 3px;
}

/* 수식 렌더링 애니메이션 */
.katex-html {
    animation: mathFadeIn 0.2s ease-in;
}

@keyframes mathFadeIn {
    from {
        opacity: 0;
    }

    to {
        opacity: 1;
    }
}

/* 모바일에서 수식 스크롤 */
@media (max-width: 768px) {
    .katex-display {
        overflow-x: scroll;
        -webkit-overflow-scrolling: touch;
    }
}

/* 캐릭터 인사 애니메이션 */
/* 캐릭터 래퍼 (애니메이션 및 위치 담당) */
.character-wrapper {
    position: absolute;
    bottom: 110px;
    /* Default for desktop */
    left: 10px;
    z-index: 10;
    width: 160px;
    height: auto;
    animation: rideLine 5s ease-in-out infinite;
    transform-origin: bottom center;
    /* Wrapper handles the layout, image fills it */
}

/* 캐릭터 이미지 */
.greeting-character {
    width: 100%;
    display: block;
    pointer-events: none;
    /* Image itself doesn't capture clicks, but wrapper might need to if we want interactions, mostly button */
}

/* 닫기 버튼 */
.char-close-btn {
    position: absolute;
    top: 25px;
    right: 20px;
    width: 24px;
    height: 24px;
    background: rgba(255, 255, 255, 0.9);
    border: 1px solid var(--border-color);
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
    color: #64748b;
    z-index: 20;
    /* Above image */
    transition: all 0.2s;
    padding: 0;
}

.char-close-btn:hover {
    background: #fff;
    color: #ef4444;
    /* Red color on hover */
    transform: scale(1.1);
}

.char-close-btn i {
    font-size: 16px;
    line-height: 1;
}

/* 모바일에*/
@media (max-width: 768px) {
    .character-wrapper {
        bottom: 80px;
        --char-scale: 0.55;
        transform-origin: bottom left;
        left: -5px;
    }
}

@keyframes rideLine {
    0% {
        transform: scale(var(--char-scale, 1)) translateX(0) translateY(0) rotate(0deg);
    }

    25% {
        transform: scale(var(--char-scale, 1)) translateX(20px) translateY(-5px) rotate(2deg);
    }

    50% {
        transform: scale(var(--char-scale, 1)) translateX(40px) translateY(0) rotate(0deg);
    }

    75% {
        transform: scale(var(--char-scale, 1)) translateX(20px) translateY(-5px) rotate(-2deg);
    }

    100% {
        transform: scale(var(--char-scale, 1)) translateX(0) translateY(0) rotate(0deg);
    }
}

/* === 사이드바 (채팅 이력) 스타일 === */
.sidebar-toggle-btn {
    background: transparent;
    border: none;
    font-size: 24px;
    color: var(--text-dark);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 8px;
    border-radius: 8px;
    transition: background 0.2s;
}

.sidebar-toggle-btn:hover {
    background: var(--bg-light);
}

.session-sidebar {
    position: fixed;
    top: 0;
    left: -320px;
    width: 320px;
    height: 100vh;
    background: #ffffff;
    box-shadow: var(--shadow-lg);
    z-index: 10000;
    transition: left 0.3s ease-in-out;
    display: flex;
    flex-direction: column;
}

.session-sidebar.open {
    left: 0;
}

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

.sidebar-header h3 {
    margin: 0;
    font-size: 18px;
    color: var(--text-dark);
}

.sidebar-close-btn {
    background: transparent;
    border: none;
    font-size: 24px;
    cursor: pointer;
    color: var(--text-gray);
    transition: color 0.2s;
}

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

.performance-indicator-btn {
    display: flex;
    align-items: center;
    gap: 6px;
    background: linear-gradient(135deg, #10b981 0%, #059669 100%);
    color: white;
    border: none;
    border-radius: 20px;
    padding: 8px 14px;
    font-size: 13.5px;
    font-weight: 700;
    cursor: pointer;
    box-shadow: 0 2px 6px rgba(16, 185, 129, 0.25);
    transition: all 0.2s ease;
}

.performance-indicator-btn:hover {
    transform: translateY(-1px);
    box-shadow: 0 4px 10px rgba(16, 185, 129, 0.35);
    background: linear-gradient(135deg, #059669 0%, #047857 100%);
}

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

.performance-indicator-btn i {
    font-size: 15px;
}

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

.session-history-list {
    list-style: none;
    padding: 0;
    margin: 0;
}

.session-history-item {
    padding: 12px 16px;
    border-radius: 12px;
    cursor: pointer;
    transition: background 0.2s;
    margin-bottom: 8px;
    border: 1px solid transparent;
}

.session-history-item:hover {
    background: var(--bg-light);
}

.session-history-item.active {
    background: var(--light-blue);
    border-color: var(--primary-blue);
}

.session-history-title {
    font-size: 14px;
    font-weight: 600;
    color: var(--text-dark);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    margin-bottom: 4px;
}

.session-history-date {
    font-size: 12px;
    color: var(--text-gray);
}

.sidebar-footer {
    padding: 16px 24px;
    border-top: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
}

.new-chat-btn,
.clear-sessions-btn {
    width: 100%;
    padding: 12px;
    border-radius: 8px;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    transition: all 0.2s;
}

.new-chat-btn {
    background: var(--primary-blue);
    color: white;
    border: none;
}

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

.clear-sessions-btn {
    background: transparent;
    border: 1px solid var(--border-color);
    color: var(--text-gray);
}

.clear-sessions-btn:hover {
    background: #fee2e2;
    color: #ef4444;
    border-color: #ef4444;
}

.sidebar-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: transparent;
    pointer-events: none;
    z-index: 9999;
    display: none;
    opacity: 0;
    transition: opacity 0.3s ease-in-out;
}

.sidebar-overlay.show {
    display: block;
    opacity: 1;
}