:root {
    --jet: #2d2f33;
    --prussian-blue: #07283d;
    --coyote: #d6cdbc;
    --eerie-black: #222222;
    --black: #000000;
    --libratum-text: #333333;
    --accent-color: #d6cdbc;
}

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

body {
    font-family: 'Crimson Text', serif;
    background: var(--black);
    background-size: cover;
    background-attachment: scroll;
    color: #ffffff;
    min-height: 100vh;
}

/* 챗봇 컨테이너 */
.chatbot-container {
    position: fixed;
    bottom: 30px;
    right: 30px;
    z-index: 1000;
    width: 60px;
    height: 60px;
    border-radius: 50%;
    overflow: visible;
    transition: width 0.5s cubic-bezier(0.4, 0, 0.2, 1),
        height 0.5s cubic-bezier(0.4, 0, 0.2, 1),
        border-radius 0.5s cubic-bezier(0.4, 0, 0.2, 1);
}

.chatbot-container.active {
    overflow: hidden;
}

.chatbot-container.active {
    width: 380px;
    height: 600px;
    border-radius: 20px;
    bottom: 30px;
    right: 30px;
}

/* 챗봇 아이콘 */
.chatbot-icon {
    width: 60px;
    height: 60px;
    background: #f0ede6;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    box-shadow: 0 4px 20px rgba(214, 205, 188, 0.3);
    transition: all 0.5s cubic-bezier(0.4, 0, 0.2, 1);
    color: #8b7d6b;
    position: absolute;
    bottom: 0;
    right: 0;
    z-index: 1;
    transform-origin: bottom right;
}

.chatbot-container.active .chatbot-icon {
    width: 380px;
    height: 600px;
    border-radius: 20px;
    bottom: 0;
    right: 0;
    transform: scale(1);
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.1);
    background: #ffffff;
    border: 1px solid rgba(214, 205, 188, 0.2);
    z-index: 1;
}

.chatbot-container.active .chatbot-icon svg {
    opacity: 0;
    transition: opacity 0.2s ease;
    pointer-events: none;
}

.chatbot-container:not(.active) .chatbot-icon:hover {
    transform: scale(1.08) translateY(-2px);
    box-shadow: 0 8px 30px rgba(214, 205, 188, 0.5);
    background: var(--accent-color);
}

.chatbot-icon:active {
    transform: scale(0.98) translateY(0);
    transition: all 0.1s;
}

.chatbot-icon svg {
    width: 21px;
    height: 21px;
}

.chatbot-icon-label {
    position: absolute;
    top: -25px;
    left: 50%;
    transform: translateX(-50%) translateY(10px);
    font-size: 14px;
    font-weight: 500;
    color: #8b7d6b;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s ease, transform 0.3s ease;
    white-space: nowrap;
    font-family: 'Crimson Text', serif;
    z-index: 1002;
    mix-blend-mode: difference;
    text-shadow:
        0 0 8px rgba(0, 0, 0, 0.5),
        0 0 4px rgba(0, 0, 0, 0.3),
        0 1px 2px rgba(0, 0, 0, 0.2),
        0 0 0 1px rgba(255, 255, 255, 0.3);
    -webkit-text-stroke: 0.5px rgba(255, 255, 255, 0.3);
}

.chatbot-container:not(.active) .chatbot-icon:hover .chatbot-icon-label {
    opacity: 1;
    transform: translateX(-50%) translateY(0);
}

/* 기본 상태 애니메이션 (chaotic-orbit) */
.chatbot-icon .chaotic-orbit {
    --uib-size: 12.5px;
    --uib-speed: 2.5s;
    --uib-color: var(--eerie-black);
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
    height: var(--uib-size);
    width: var(--uib-size);
    animation: rotate936 calc(var(--uib-speed) * 1.667) infinite linear;
}

.chatbot-icon .chaotic-orbit::before,
.chatbot-icon .chaotic-orbit::after {
    content: '';
    position: absolute;
    height: 60%;
    width: 60%;
    border-radius: 50%;
    background-color: var(--uib-color);
    will-change: transform;
    flex-shrink: 0;
}

.chatbot-icon .chaotic-orbit::before {
    animation: orbit var(--uib-speed) linear infinite;
}

.chatbot-icon .chaotic-orbit::after {
    animation: orbit var(--uib-speed) linear calc(var(--uib-speed) / -2) infinite;
}

@keyframes rotate936 {
    0% {
        transform: rotate(0deg);
    }

    100% {
        transform: rotate(360deg);
    }
}

@keyframes orbit {
    0% {
        transform: translate(calc(var(--uib-size) * 0.5)) scale(0.73684);
        opacity: 0.65;
    }

    5% {
        transform: translate(calc(var(--uib-size) * 0.4)) scale(0.684208);
        opacity: 0.58;
    }

    10% {
        transform: translate(calc(var(--uib-size) * 0.3)) scale(0.631576);
        opacity: 0.51;
    }

    15% {
        transform: translate(calc(var(--uib-size) * 0.2)) scale(0.578944);
        opacity: 0.44;
    }

    20% {
        transform: translate(calc(var(--uib-size) * 0.1)) scale(0.526312);
        opacity: 0.37;
    }

    25% {
        transform: translate(0%) scale(0.47368);
        opacity: 0.3;
    }

    30% {
        transform: translate(calc(var(--uib-size) * -0.1)) scale(0.526312);
        opacity: 0.37;
    }

    35% {
        transform: translate(calc(var(--uib-size) * -0.2)) scale(0.578944);
        opacity: 0.44;
    }

    40% {
        transform: translate(calc(var(--uib-size) * -0.3)) scale(0.631576);
        opacity: 0.51;
    }

    45% {
        transform: translate(calc(var(--uib-size) * -0.4)) scale(0.684208);
        opacity: 0.58;
    }

    50% {
        transform: translate(calc(var(--uib-size) * -0.5)) scale(0.73684);
        opacity: 0.65;
    }

    55% {
        transform: translate(calc(var(--uib-size) * -0.4)) scale(0.789472);
        opacity: 0.72;
    }

    60% {
        transform: translate(calc(var(--uib-size) * -0.3)) scale(0.842104);
        opacity: 0.79;
    }

    65% {
        transform: translate(calc(var(--uib-size) * -0.2)) scale(0.894736);
        opacity: 0.86;
    }

    70% {
        transform: translate(calc(var(--uib-size) * -0.1)) scale(0.947368);
        opacity: 0.93;
    }

    75% {
        transform: translate(0%) scale(1);
        opacity: 1;
    }

    80% {
        transform: translate(calc(var(--uib-size) * 0.1)) scale(0.947368);
        opacity: 0.93;
    }

    85% {
        transform: translate(calc(var(--uib-size) * 0.2)) scale(0.894736);
        opacity: 0.86;
    }

    90% {
        transform: translate(calc(var(--uib-size) * 0.3)) scale(0.842104);
        opacity: 0.79;
    }

    95% {
        transform: translate(calc(var(--uib-size) * 0.4)) scale(0.789472);
        opacity: 0.72;
    }

    100% {
        transform: translate(calc(var(--uib-size) * 0.5)) scale(0.73684);
        opacity: 0.65;
    }
}

/* 로딩 상태 애니메이션 (loader) */
.loader {
    z-index: 20;
    display: flex;
    justify-content: center;
    align-items: center;
    overflow: visible;
}

.loader span {
    width: 6.67px;
    height: 6.67px;
    margin: 0 3px;
    border-radius: 50%;
    background-color: #af9782;
    animation: dots_411 1.5s infinite ease-in-out;
}

.loader span:nth-child(1) {
    -webkit-animation-delay: -.40s;
    animation-delay: -.40s;
}

.loader span:nth-child(2) {
    -webkit-animation-delay: -.25s;
    animation-delay: -.25s;
}

.loader span:nth-child(3) {
    -webkit-animation-delay: -.10s;
    animation-delay: -.10s;
}

@keyframes dots_411 {
    5% {
        opacity: 0;
    }

    0%,
    80%,
    100% {
        -webkit-transform: scale(0);
        transform: scale(0);
    }

    40% {
        -webkit-transform: scale(.8);
        transform: scale(.8);
    }
}

/* 챗봇 윈도우 */
.chatbot-window {
    position: absolute;
    bottom: 0;
    right: 0;
    width: 380px;
    height: 600px;
    background: transparent;
    display: none;
    flex-direction: column;
    overflow: hidden;
    opacity: 0;
    transition: opacity 0.3s ease 0.2s;
    position: relative;
    z-index: 2;
    pointer-events: none;
}

.chatbot-window-bg {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    object-fit: cover;
    z-index: 0;
    filter: blur(120px);
    -webkit-filter: blur(120px);
}

.chatbot-container.active .chatbot-window {
    display: flex;
    opacity: 1;
    pointer-events: auto;
}

.chatbot-container.active .chatbot-icon {
    pointer-events: none;
}

/* 헤더 */
.chatbot-header {
    background: rgba(240, 237, 230, 0.5);
    padding: 20px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 1px solid rgba(214, 205, 188, 0.2);
    position: relative;
    z-index: 1;
}

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

.chatbot-avatar {
    width: 40px;
    height: 40px;
    background: var(--accent-color);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--eerie-black);
    overflow: hidden;
}

.chatbot-avatar img {
    width: 100%;
    height: 100%;
    object-fit: contain;
    border-radius: 50%;
}

.chatbot-header-info h3 {
    font-size: 16px;
    font-weight: 600;
    color: var(--libratum-text);
    margin-bottom: 4px;
    transform: translateY(1px);
}

.chatbot-header-info .status {
    font-size: 12px;
    color: var(--accent-color);
}

.close-btn {
    background: transparent;
    border: none;
    color: #8b7d6b;
    opacity: 0.6;
    cursor: pointer;
    padding: 5px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 5px;
    transition: all 0.2s;
}

.close-btn:hover {
    background: rgba(214, 205, 188, 0.2);
    color: #8b7d6b;
    opacity: 1;
}

/* 메시지 영역 */
.chatbot-messages {
    flex: 1;
    overflow-y: auto;
    position: relative;
    z-index: 1;
    padding: 20px 30px 20px 20px;
    display: flex;
    flex-direction: column;
    gap: 16px;
    background: transparent;
}

.chatbot-messages::-webkit-scrollbar {
    width: 6px;
}

.chatbot-messages::-webkit-scrollbar-track {
    background: transparent;
}

.chatbot-messages::-webkit-scrollbar-thumb {
    background: rgba(214, 205, 188, 0.4);
    border-radius: 3px;
}

.chatbot-messages::-webkit-scrollbar-thumb:hover {
    background: rgba(214, 205, 188, 0.6);
}

.message {
    display: flex;
    gap: 10px;
    align-items: flex-start;
    animation: fadeIn 0.3s ease-in;
}

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

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

.bot-message {
    justify-content: flex-start;
    align-self: flex-start;
    align-items: flex-start;
}

.user-message {
    justify-content: flex-end;
    align-self: flex-end;
    margin-left: auto;
    width: fit-content;
    max-width: 85%;
    margin-right: 20px;
}

.message-avatar {
    width: 32px;
    height: 32px;
    background: var(--accent-color);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--eerie-black);
    flex-shrink: 0;
    overflow: hidden;
}

.message-avatar img {
    width: 100%;
    height: 100%;
    object-fit: contain;
    border-radius: 50%;
}

.user-message .message-avatar {
    display: none;
}

.message-content {
    max-width: 70%;
    max-height: 300px;
    padding: 12px 16px;
    border-radius: 18px;
    word-wrap: break-word;
    word-break: keep-all;
    overflow-wrap: break-word;
    white-space: normal;
    transition: max-width 0.5s cubic-bezier(0.4, 0, 0.2, 1),
        padding 0.5s cubic-bezier(0.4, 0, 0.2, 1),
        max-height 0.5s cubic-bezier(0.4, 0, 0.2, 1),
        opacity 0.4s ease,
        transform 0.4s ease;
    min-height: 44px;
    overflow-y: auto;
    overflow-x: hidden;
    position: relative;
    z-index: 10;
}


.bot-message .message-content {
    background: rgba(214, 205, 188, 0.2) !important;
    color: var(--libratum-text) !important;
    border-top-left-radius: 4px;
    opacity: 1 !important;
    display: inline-block !important;
    /* Matches user message fix logic */
    width: fit-content !important;
    max-width: 85% !important;
    min-width: 20px;
    visibility: visible !important;
}

.bot-message .message-content p {
    margin: 0;
    white-space: pre-wrap;
    text-align: left;
}

.bot-message .message-content::-webkit-scrollbar {
    width: 4px;
}

.bot-message .message-content::-webkit-scrollbar-track {
    background: transparent;
}

.bot-message .message-content::-webkit-scrollbar-thumb {
    background: rgba(139, 125, 107, 0.3);
    border-radius: 2px;
}

.bot-message .message-content::-webkit-scrollbar-thumb:hover {
    background: rgba(139, 125, 107, 0.5);
}

.user-message .message-content {
    background: rgba(214, 205, 188, 0.5);
    color: var(--libratum-text);
    border-bottom-right-radius: 4px;
    display: inline-block !important;
    text-align: left !important;
    padding: 12px 16px !important;
    width: auto !important;
    max-width: 100% !important;
    min-width: 0 !important;
    margin: 0 !important;
}

.user-message .message-content p {
    white-space: pre-wrap;
    text-align: left;
    margin: 0;
}

/* Short message override */
.user-message.short-message .message-content,
.user-message.short-message .message-content p {
    white-space: nowrap !important;
}

.message-content p {
    font-size: 14px;
    line-height: 1.5;
    margin: 0;
    word-break: keep-all;
    overflow-wrap: break-word;
    white-space: normal;
}

/* 입력 영역 */
.chatbot-input-area {
    padding: 20px;
    background: transparent;
    position: relative;
    z-index: 1;
    border-top: 1px solid rgba(214, 205, 188, 0.2);
    display: flex;
    gap: 10px;
    align-items: center;
}

.attach-btn {
    width: 44px !important;
    height: 44px !important;
    min-width: 44px !important;
    min-height: 44px !important;
    padding: 0 !important;
    aspect-ratio: 1 / 1;
    background-color: rgba(214, 205, 188, 0.3);
    background-image: url("data:image/svg+xml,%3Csvg width='24' height='24' viewBox='0 0 24 24' fill='none' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath d='M21.44 11.05l-9.19 9.19a6 6 0 0 1-8.49-8.49l9.19-9.19a4 4 0 0 1 5.66 5.66l-9.2 9.19a2 2 0 0 1-2.83-2.83l8.49-8.48' stroke='%238b7d6b' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: center;
    background-size: 20px 20px;
    border: none;
    border-radius: 50% !important;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
    flex-shrink: 0 !important;
    box-sizing: border-box !important;
}

.attach-btn svg {
    display: none;
}

.attach-btn:hover {
    background-color: rgba(214, 205, 188, 0.5);
    transform: scale(1.05);
}

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

/* 파일 미리보기 영역 */
.file-preview-area {
    padding: 10px 20px;
    background: rgba(214, 205, 188, 0.1);
    border-top: 1px solid rgba(214, 205, 188, 0.2);
    display: flex;
    flex-direction: column;
    gap: 8px;
    max-height: 120px;
    overflow-y: auto;
}

.file-preview-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 12px;
    background: rgba(255, 255, 255, 0.5);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    border-radius: 12px;
    font-size: 12px;
    color: var(--libratum-text);
}

.file-preview-item svg {
    flex-shrink: 0;
    width: 16px;
    height: 16px;
}

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

.file-preview-item-remove {
    background: transparent;
    border: none;
    color: var(--libratum-text);
    cursor: pointer;
    padding: 4px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 4px;
    opacity: 0.6;
    transition: all 0.2s;
}

.file-preview-item-remove:hover {
    opacity: 1;
    background: rgba(214, 205, 188, 0.3);
}

.file-preview-area::-webkit-scrollbar {
    width: 4px;
}

.file-preview-area::-webkit-scrollbar-track {
    background: transparent;
}

.file-preview-area::-webkit-scrollbar-thumb {
    background: rgba(214, 205, 188, 0.4);
    border-radius: 2px;
}

#chatInput {
    flex: 1;
    background: rgba(255, 255, 255, 0.5);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    border: 1px solid rgba(214, 205, 188, 0.3);
    border-radius: 25px;
    padding: 12px 20px;
    color: var(--libratum-text);
    font-size: 14px;
    outline: none;
    transition: all 0.2s;
}

#chatInput:focus {
    border-color: rgba(214, 205, 188, 0.6);
    background: rgba(255, 255, 255, 0.7);
    box-shadow: 0 0 0 3px rgba(214, 205, 188, 0.1);
}

#chatInput::placeholder {
    color: rgba(51, 51, 51, 0.5);
}

.send-btn {
    width: 44px !important;
    height: 44px !important;
    min-width: 44px !important;
    min-height: 44px !important;
    padding: 0 !important;
    aspect-ratio: 1 / 1;
    background-color: rgba(214, 205, 188, 0.3);
    background-image: url("data:image/svg+xml,%3Csvg width='24' height='24' viewBox='0 0 24 24' fill='none' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath d='M22 2L11 13M22 2L15 22L11 13M22 2L2 9L11 13' stroke='%238b7d6b' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: center;
    background-size: 20px 20px;
    border: none;
    border-radius: 50% !important;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
    flex-shrink: 0 !important;
    box-sizing: border-box !important;
}

.send-btn svg {
    display: none;
}

.send-btn:hover {
    transform: scale(1.05);
    background-color: rgba(214, 205, 188, 0.5);
}

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

.send-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    transform: none;
}

/* 반응형 디자인 */
@media (max-width: 768px) {
    .chatbot-window {
        width: calc(100vw - 60px);
        height: 500px;
        right: 0;
    }

    .chatbot-container {
        right: 15px;
        bottom: 15px;
    }
}

/* CSS Updated with Base64 SVGs */