html, body {
    width: 100%;
    height: 100%;
    overflow: hidden;
}

body {
    position: relative;
    margin: 0;
}

#yarn-stage {
    position: fixed;
    top: 40%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: min(60vw, 560px);
    height: min(60vw, 520px);
    max-height: 60vh;
    pointer-events: auto;
    cursor: pointer;
    z-index: 1;
    transition:
        width 0.9s cubic-bezier(0.4, 0, 0.2, 1),
        height 0.9s cubic-bezier(0.4, 0, 0.2, 1),
        max-height 0.9s cubic-bezier(0.4, 0, 0.2, 1),
        top 0.9s cubic-bezier(0.4, 0, 0.2, 1);
}

body.popup-open #yarn-stage {
    top: calc(min(60vw, 120px) / 2);
    width: min(60vw, 120px);
    height: min(60vw, 120px);
    max-height: none;
}

#yarn-canvas {
    width: 100%;
    height: 100%;
    display: block;
    background: transparent;
    filter: drop-shadow(0 10px 18px rgba(30, 40, 90, 0.22))
            drop-shadow(0 4px 6px rgba(30, 40, 90, 0.15));
}

#chat-bar {
    position: fixed;
    left: 50%;
    bottom: 4vh;
    transform: translateX(-50%);
    display: flex;
    align-items: center;
    gap: 10px;
    width: min(90vw, 640px);
    padding: 10px 14px;
    background: rgba(255, 255, 255, 0.7);
    border: 1px solid rgba(255, 255, 255, 0.6);
    border-radius: 999px;
    box-shadow: 0 8px 28px rgba(60, 70, 130, 0.18);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    z-index: 2;
}

#chat-input {
    flex: 1;
    height: 40px;
    padding: 0 14px;
    border: none;
    outline: none;
    background: transparent;
    font-family: 'Pretendard', sans-serif;
    font-size: 16px;
    color: #2a2f55;
}

#chat-input::placeholder {
    color: rgba(42, 47, 85, 0.45);
}

#chat-enter {
    flex: 0 0 auto;
    width: 40px;
    height: 40px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border: none;
    border-radius: 50%;
    background: linear-gradient(45deg, rgba(159, 142, 219, 1) 0%, rgba(96, 198, 211, 1) 100%);
    color: #fff;
    cursor: pointer;
    transition: transform 0.15s ease-out, box-shadow 0.15s ease-out;
}

#chat-enter:hover {
    transform: scale(1.06);
    box-shadow: 0 4px 14px rgba(96, 130, 211, 0.35);
}

#chat-enter:active {
    transform: scale(0.96);
}

#welcome-message-background {
    position: fixed;
    top: 50%;
    left: 50%;
    width: min(60vw, 1100px);
    height: min(70vh, 880px);
    transform: translate(-50%, -50%) scale(0);
    transform-origin: center center;
    border-radius: 8px;
    /* background: rgba(255, 255, 255, 0.3);
    box-shadow: 0 12px 36px rgba(60, 70, 130, 0.2);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px); */
    z-index: 2;
    opacity: 0;
    pointer-events: none;
    transition:
        opacity 0.35s ease-out 0.95s,
        transform 0.6s cubic-bezier(0.2, 0.9, 0.3, 1.1) 0.95s;
    overflow: hidden;
}

/* #welcome-message-background::before {
    content: '';
    position: absolute;
    inset: 0;
    padding: 1.3px;
    border-radius: inherit;
    background: linear-gradient(90deg, rgba(103, 176, 255, 1) 0%, rgba(98, 77, 255, 1) 100%);
    -webkit-mask:
        linear-gradient(#fff 0 0) content-box,
        linear-gradient(#fff 0 0);
    mask:
        linear-gradient(#fff 0 0) content-box,
        linear-gradient(#fff 0 0);
    -webkit-mask-composite: xor;
    mask-composite: exclude;
    pointer-events: none;
} */

#welcome-message-background.show {
    opacity: 1;
    pointer-events: auto;
    transform: translate(-50%, -50%) scale(1);
}

#welcome-chat {
    width: 100%;
    height: 100%;
    box-sizing: border-box;
    padding: 22px 24px;
    display: flex;
    flex-direction: column;
    gap: 14px;
    overflow-x: hidden;
    overflow-y: auto;
    overscroll-behavior: contain;
    scroll-behavior: smooth;
}

/* 채팅 진입 애니메이션: 아래에서 fade + slide-up */
@keyframes msgIn {
    from {
        opacity: 0;
        transform: translateY(12px) scale(0.96);
    }
    to {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

.msg-enter {
    animation: msgIn 0.42s cubic-bezier(0.2, 0.85, 0.3, 1) both;
    transform-origin: bottom right;
}

.loading-enter {
    animation: msgIn 0.42s cubic-bezier(0.2, 0.85, 0.3, 1) both;
    transform-origin: bottom left;
}

#welcome-chat::-webkit-scrollbar {
    width: 6px;
}

#welcome-chat::-webkit-scrollbar-thumb {
    background: rgba(60, 70, 130, 0.25);
    border-radius: 3px;
}

.msg {
    max-width: 75%;
    min-height: 22px;
    min-width: 48px;
    padding: 10px 14px;
    border-radius: 16px;
    font-family: 'Pretendard', sans-serif;
    font-size: 15px;
    line-height: 1.5;
    word-break: break-word;
    white-space: pre-wrap;
    flex-shrink: 0;
}

.msg-user {
    align-self: flex-end;
    /* background: linear-gradient(45deg, rgba(159, 142, 219, 1), rgba(96, 198, 211, 1)); */
    /* background-color: rgba(255, 255, 255, 1);
    border: 1px solid rgba(255, 255, 255, 0.6); */
    color: #2a2f55;
    border-bottom-right-radius: 4px;
    background: rgba(255, 255, 255, 0.3);
    box-shadow: 0 12px 36px rgba(60, 70, 130, 0.2);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
}

.msg-ai {
    align-self: flex-end;
    /* background: linear-gradient(45deg, rgba(159, 142, 219, 1), rgba(96, 198, 211, 1)); */
    /* background-color: rgba(255, 255, 255, 1);
    border: 1px solid rgba(255, 255, 255, 0.6); */
    color: #2a2f55;
    border-bottom-right-radius: 4px;
    background: rgba(255, 255, 255, 0.3);
    box-shadow: 0 12px 36px rgba(60, 70, 130, 0.2);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
}

.msg-ai .dot-tail {
    display: inline-block;
    margin-left: 2px;
}

.template-response {
    align-self: flex-start;
    width: 100%;
    max-width: 100%;
    display: flex;
    flex-direction: column;
    gap: 12px;
    box-sizing: border-box;
    flex-shrink: 0;
    background: linear-gradient(135deg, rgba(220, 215, 245, 0.9), rgba(205, 230, 240, 0.9));
    border: 1px solid rgba(159, 142, 219, 0.25);
    border-radius: 16px;
    border-bottom-left-radius: 4px;
    padding: 14px;
    box-shadow: 0 4px 14px rgba(60, 70, 130, 0.08);
    overflow: hidden;
}

.template-cards {
    display: flex;
    flex-direction: row;
    gap: 12px;
    flex-wrap: wrap;
    max-width: 100%;
    min-width: 0;
}

.template-question {
    align-self: flex-start;
    font-family: 'Pretendard', sans-serif;
    font-size: 15px;
    line-height: 1.5;
    color: #2a2f55;
    clip-path: inset(0 100% 0 0);
    animation: revealText 0.7s cubic-bezier(0.4, 0, 0.2, 1) 1s forwards;
}

.template-card {
    flex: 1 1 0;
    min-width: 160px;
    max-height: 1200px;
    background: rgba(255, 255, 255, 0.95);
    border: 1px solid rgba(60, 70, 130, 0.12);
    border-radius: 16px;
    padding: 18px 18px;
    box-shadow: 0 4px 14px rgba(60, 70, 130, 0.1);
    font-family: 'Pretendard', sans-serif;
    color: #2a2f55;
    display: flex;
    flex-direction: column;
    gap: 10px;
    text-decoration: none;
    opacity: 0;
    transform: translateY(10px);
    animation: cardIn 0.5s cubic-bezier(0.2, 0.85, 0.3, 1) forwards;
    transition: transform 0.18s ease-out, box-shadow 0.18s ease-out;
}

.template-card:nth-child(1) { animation-delay: 0s; }
.template-card:nth-child(2) { animation-delay: 0.22s; }
.template-card:nth-child(3) { animation-delay: 0.44s; }

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

.template-card:hover {
    box-shadow: 0 8px 22px rgba(60, 70, 130, 0.18);
}

.template-card.fade-out {
    opacity: 0;
    transform: scale(0.7) translateY(10px);
    flex-grow: 0;
    min-width: 0;
    max-height: 0;
    padding: 0;
    border-width: 0;
    pointer-events: none;
    overflow: hidden;
    transition:
        opacity 0.45s ease-out,
        transform 0.5s ease-out,
        flex-grow 0.55s cubic-bezier(0.4, 0, 0.2, 1) 0.5s,
        min-width 0.55s cubic-bezier(0.4, 0, 0.2, 1) 0.5s,
        max-height 0.55s cubic-bezier(0.4, 0, 0.2, 1) 0.5s,
        padding 0.55s cubic-bezier(0.4, 0, 0.2, 1) 0.5s,
        border-width 0.55s cubic-bezier(0.4, 0, 0.2, 1) 0.5s;
}
ㅊ
.template-cards.selecting {
    gap: 0;
    transition: gap 0.55s cubic-bezier(0.4, 0, 0.2, 1) 0.5s;
}

.template-card.selected {
    transform: scale(1);
    cursor: progress;
}

.template-card.selected.loaded {
    cursor: pointer;
}

.template-card.selected .tc-thumb {
    height: 420px;
    transition: height 0.55s cubic-bezier(0.4, 0, 0.2, 1) 0.5s;
}

#look-in-detail {
    position: fixed;
    inset: 0;
    z-index: 100;
    background: rgba(20, 25, 60, 0.78);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.45s ease-out;
}

#look-in-detail.show {
    opacity: 1;
    pointer-events: auto;
}

#detail-iframe {
    position: absolute;
    inset: 0;
    width: 100vw;
    height: 100vh;
    border: none;
    background: #fff;
}

#detail-close-btn {
    position: fixed;
    top: 20px;
    right: 20px;
    z-index: 102;
    width: 44px;
    height: 44px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border: none;
    border-radius: 50%;
    background: rgba(20, 25, 60, 0.6);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    color: #fff;
    cursor: pointer;
    box-shadow: 0 6px 18px rgba(0, 0, 0, 0.3);
    transition: transform 0.15s ease-out, background 0.15s ease-out;
}

#detail-close-btn:hover {
    background: rgba(20, 25, 60, 0.85);
    transform: scale(1.08);
}

#detail-close-btn:active {
    transform: scale(0.94);
}

#try-customize-btn {
    position: fixed;
    right: 4vw;
    bottom: 4vh;
    z-index: 101;
    padding: 14px 26px;
    border: none;
    border-radius: 999px;
    background: linear-gradient(45deg, rgba(159, 142, 219, 1) 0%, rgba(96, 198, 211, 1) 100%);
    color: #fff;
    font-family: 'Pretendard', sans-serif;
    font-size: 15px;
    font-weight: 600;
    cursor: pointer;
    box-shadow: 0 8px 24px rgba(60, 70, 130, 0.3);
    transition: transform 0.15s ease-out, box-shadow 0.15s ease-out;
}

#try-customize-btn:hover {
    transform: scale(1.05);
    box-shadow: 0 12px 30px rgba(96, 130, 211, 0.4);
}

#try-customize-btn:active {
    transform: scale(0.97);
}

#subscribe-prompt {
    position: fixed;
    inset: 0;
    z-index: 200;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(20, 25, 60, 0.55);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.35s ease-out;
}

#subscribe-prompt.show {
    opacity: 1;
    pointer-events: auto;
}

#subscribe-prompt .sp-card {
    width: min(86vw, 420px);
    padding: 30px 32px 26px;
    background: rgba(255, 255, 255, 0.96);
    border-radius: 20px;
    box-shadow: 0 18px 48px rgba(20, 25, 60, 0.35);
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 22px;
    text-align: center;
    transform: scale(0.86);
    opacity: 0;
    transition:
        transform 0.5s cubic-bezier(0.2, 0.9, 0.3, 1.1),
        opacity 0.35s ease-out;
}

#subscribe-prompt.show .sp-card {
    transform: scale(1);
    opacity: 1;
}

#subscribe-prompt .sp-text {
    font-family: 'Pretendard', sans-serif;
    font-size: 16px;
    line-height: 1.6;
    color: #2a2f55;
    word-break: keep-all;
}

#subscribe-prompt .sp-btn {
    min-width: 120px;
    padding: 12px 28px;
    border: none;
    border-radius: 999px;
    background: linear-gradient(45deg, rgba(159, 142, 219, 1) 0%, rgba(96, 198, 211, 1) 100%);
    color: #fff;
    font-family: 'Pretendard', sans-serif;
    font-size: 15px;
    font-weight: 600;
    cursor: pointer;
    box-shadow: 0 6px 18px rgba(96, 130, 211, 0.3);
    transition: transform 0.15s ease-out, box-shadow 0.15s ease-out;
}

#subscribe-prompt .sp-btn:hover {
    transform: scale(1.04);
    box-shadow: 0 10px 24px rgba(96, 130, 211, 0.4);
}

#subscribe-prompt .sp-btn:active {
    transform: scale(0.96);
}

.loading-bubble {
    align-self: flex-start;
    background: linear-gradient(135deg, rgba(220, 215, 245, 0.9), rgba(205, 230, 240, 0.9));
    border: 1px solid rgba(159, 142, 219, 0.25);
    border-radius: 16px;
    border-bottom-left-radius: 4px;
    padding: 12px 16px;
    display: flex;
    gap: 6px;
    align-items: center;
    flex-shrink: 0;
    box-shadow: 0 4px 14px rgba(60, 70, 130, 0.08);
}

.loading-bubble .ldot {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: rgba(60, 70, 130, 0.55);
    animation: ldot 1.2s infinite ease-in-out;
}

.loading-bubble .ldot:nth-of-type(2) { animation-delay: 0.18s; }
.loading-bubble .ldot:nth-of-type(3) { animation-delay: 0.36s; }

@keyframes ldot {
    0%, 80%, 100% { transform: scale(0.55); opacity: 0.5; }
    40% { transform: scale(1.1); opacity: 1; }
}

.ldots {
    display: flex;
    gap: 6px;
}

.loading-text {
    color: rgba(60, 70, 130, 0.55);
    font-family: 'Pretendard', sans-serif;
    font-size: 14px;
    line-height: 18px;
    white-space: nowrap;
    min-height: 18px;
    clip-path: inset(0 100% 0 0);
    flex-shrink: 0;
}

.loading-text.reveal {
    animation: revealText 0.7s cubic-bezier(0.4, 0, 0.2, 1) forwards;
}

@keyframes revealText {
    from { clip-path: inset(0 100% 0 0); }
    to { clip-path: inset(0 0 0 0); }
}

.dot-tail {
    display: inline-block;
    margin-left: 2px;
    color: rgba(60, 70, 130, 0.55);
}

.dot-tail span {
    display: inline-block;
    color: rgba(60, 70, 130, 0.55);
    animation: ldot 1.2s 0.7s infinite ease-in-out;
}

.dot-tail span:nth-of-type(2) { animation-delay: 0.88s; }
.dot-tail span:nth-of-type(3) { animation-delay: 1.06s; }

.template-card .tc-thumb {
    width: 100%;
    height: 180px;
    border-radius: 10px;
    background-color: rgba(220, 215, 245, 0.4);
    background-image: linear-gradient(135deg, rgba(159, 142, 219, 0.1), rgba(96, 198, 211, 0.1));
    background-size: contain;
    background-position: center;
    background-repeat: no-repeat;
    flex-shrink: 0;
}

.template-card .tc-name {
    font-size: 18px;
    font-weight: 700;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    color: #2a2f55;
}

.template-card .tc-desc {
    font-size: 14px;
    line-height: 1.5;
    color: rgba(42, 47, 85, 0.75);
    display: -webkit-box;
    -webkit-line-clamp: 3;
    line-clamp: 3;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.template-card .tc-category {
    font-size: 12px;
    line-height: 1.4;
    color: rgba(42, 47, 85, 0.5);
    display: -webkit-box;
    -webkit-line-clamp: 2;
    line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

@media (max-width: 1280px) {
    .template-card.selected .tc-thumb {
        height: 440px;
    }
}

@media (max-width: 1024px) {
    .template-card.selected .tc-thumb {
        height: 360px;
    }
    .template-card {
        padding: 14px;
    }
    .template-response {
        padding: 12px;
    }
}

@media (max-width: 768px) {
    #yarn-stage {
        top: 6vh;
        width: min(80vw, 360px);
        height: min(80vw, 360px);
    }

    #chat-bar {
        width: 92vw;
        bottom: 4vh;
    }

    #welcome-message-background {
        width: 92vw;
        height: 84vh;
    }

    #welcome-chat {
        padding: 16px;
    }

    .template-cards {
        flex-direction: column;
        gap: 10px;
    }

    .template-card {
        min-width: 0;
        width: 100%;
        padding: 12px;
    }

    .template-card .tc-thumb {
        height: 160px;
    }

    .template-card.selected .tc-thumb {
        height: 280px;
    }

    .template-card .tc-name {
        font-size: 16px;
    }

    .template-card .tc-desc {
        font-size: 13px;
        -webkit-line-clamp: 2;
        line-clamp: 2;
    }

    .template-question {
        font-size: 14px;
    }

    .template-response {
        padding: 10px;
        gap: 10px;
    }

    .msg {
        font-size: 14px;
        max-width: 85%;
    }

    #try-customize-btn {
        right: 16px;
        bottom: 16px;
        padding: 12px 20px;
        font-size: 14px;
    }

    #detail-close-btn {
        top: 12px;
        right: 12px;
        width: 40px;
        height: 40px;
    }

    #subscribe-prompt .sp-card {
        padding: 24px 22px 22px;
        gap: 18px;
    }

    #subscribe-prompt .sp-text {
        font-size: 14px;
    }

    #subscribe-prompt .sp-btn {
        font-size: 14px;
        min-width: 100px;
        padding: 10px 22px;
    }
}

@media (max-width: 480px) {
    .template-card .tc-thumb {
        height: 140px;
    }
    .template-card.selected .tc-thumb {
        height: 220px;
    }
    #welcome-chat {
        padding: 12px;
    }
}

/* ===== 채팅 히스토리 사이드바 ===== */
#chat-sidebar {
    position: fixed;
    right: 24px;
    bottom: 4vh;
    width: 16.6vw;
    max-height: min(70vh, 880px);
    background: rgba(255, 255, 255, 0.5);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border-radius: 8px;
    box-shadow: 0 10px 28px rgba(60, 70, 130, 0.14);
    padding: 9px 12px;
    z-index: 3;
    display: flex;
    /* 헤더(+ 버튼)는 시각적 하단, 기록은 위로 쌓임 */
    flex-direction: column-reverse;
    gap: 10px;
    font-family: 'Pretendard', sans-serif;
    transform-origin: bottom right;
    transition:
        width 0.4s cubic-bezier(0.4, 0, 0.2, 1),
        max-width 0.4s cubic-bezier(0.4, 0, 0.2, 1),
        height 0.4s cubic-bezier(0.4, 0, 0.2, 1),
        max-height 0.4s cubic-bezier(0.4, 0, 0.2, 1),
        padding 0.4s cubic-bezier(0.4, 0, 0.2, 1),
        border-radius 0.4s cubic-bezier(0.4, 0, 0.2, 1),
        gap 0.4s cubic-bezier(0.4, 0, 0.2, 1),
        background 0.3s ease,
        box-shadow 0.3s ease,
        backdrop-filter 0.3s ease,
        -webkit-backdrop-filter 0.3s ease,
        transform 0.4s cubic-bezier(0.4, 0, 0.2, 1);
}

/* sidebar-list / sidebar-title 는 펼침에 따라 opacity fade — 사용자가 collapsed 에서 숨겼다 보였다 할 때 부드럽게 */
.sidebar-list,
.sidebar-title {
    transition: opacity 0.25s ease 0.12s;
}

.sidebar-list[hidden] {
    display: none;
}

/* ---- 펼침/접힘 keyframe (+ / - 버튼 클릭 시 JS 가 클래스 토글)
   clip-path inset(top right bottom left). top 을 0 → 100% 사이에서 변경:
   - top 100% = 위에서 100% 잘림 = 바닥만 보임
   - top 0   = 잘림 없음 = 전체 보임
   사이드바가 bottom 고정이라 박스는 즉시 풀사이즈, 시각만 위에서 펼침/위로 접힘. */
@keyframes sidebarExpand {
    from {
        clip-path: inset(100% 0 0 0);
        opacity: 0;
    }
    to {
        clip-path: inset(0 0 0 0);
        opacity: 1;
    }
}

@keyframes sidebarCollapse {
    from {
        clip-path: inset(0 0 0 0);
        opacity: 1;
    }
    to {
        clip-path: inset(100% 0 0 0);
        opacity: 0;
    }
}

#chat-sidebar.expanding {
    animation: sidebarExpand 0.42s cubic-bezier(0.2, 0.85, 0.3, 1) both;
}

#chat-sidebar.collapsing {
    animation: sidebarCollapse 0.42s cubic-bezier(0.4, 0, 0.6, 1) both;
    pointer-events: none;
}

/* ---- collapsed (처음엔 + 버튼만 보임) ---- */
#chat-sidebar.collapsed {
    width: auto;
    max-height: none;
    padding: 0;
    background: transparent;
    box-shadow: 0 6px 16px rgba(60, 70, 130, 0.18);
    backdrop-filter: none;
    -webkit-backdrop-filter: none;
    border-radius: 8px;
}

#chat-sidebar.collapsed .sidebar-list,
#chat-sidebar.collapsed .sidebar-title,
#chat-sidebar.collapsed .sidebar-close-btn {
    display: none;
}

/* ---- 사이드바 우상단 닫기 (-) 버튼 — 중앙이 사이드바 우상단 모서리에 위치 ---- */
.sidebar-close-btn {
    position: absolute;
    top: 0;
    right: 0;
    /* 버튼 중앙이 사이드바 corner 에 오도록 절반 밖으로 */
    transform: translate(40%, -40%);
    width: 28px;
    height: 28px;
    border: 0;
    /* 목차 배경(0.5)보다 덜 투명 → 잘 보이게 */
    background: rgba(255, 255, 255, 0.78);
    color: #4a4f6a;
    border-radius: 6px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 4; /* 사이드바(z-index:3) 보다 위 */
    transition: background 0.15s ease, color 0.15s ease, transform 0.15s ease, box-shadow 0.15s ease;
    box-shadow: 0 4px 10px rgba(60, 70, 130, 0.18);
}

.sidebar-close-btn:hover {
    background: rgba(255, 255, 255, 0.95);
    color: rgba(98, 77, 255, 1);
    box-shadow: 0 6px 14px rgba(60, 70, 130, 0.24);
}

.sidebar-close-btn:active {
    transform: translate(50%, -50%);
}

#chat-sidebar.collapsed .sidebar-head {
    border-top: none;
    padding: 0;
}

#chat-sidebar.collapsed .sidebar-new-btn {
    width: 30px;
    height: 30px;
    border-radius: 8px;
}

.sidebar-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 8px 6px;
}

.sidebar-title {
    font-size: 12px;
    font-weight: 700;
    letter-spacing: 0.6px;
    color: #6b7290;
    text-transform: uppercase;
}

.sidebar-new-btn {
    width: 28px;
    height: 28px;
    border-radius: 8px;
    border: 0;
    background: linear-gradient(45deg, rgba(159, 142, 219, 1), rgba(96, 198, 211, 1));
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: transform 0.15s ease, box-shadow 0.2s ease;
}

.sidebar-new-btn:hover {
    transform: translateY(-1px);
    box-shadow: 0 6px 14px rgba(98, 77, 255, 0.3);
}

.sidebar-list {
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 4px;
    padding: 2px;
    margin: 0 -2px;
}

.sidebar-list::-webkit-scrollbar {
    width: 4px;
}

.sidebar-list::-webkit-scrollbar-thumb {
    background: rgba(60, 70, 130, 0.2);
    border-radius: 4px;
}

.sidebar-item {
    position: relative;
    flex-shrink: 0;
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 9px 56px 9px 12px;
    border-radius: 8px;
    background: transparent;
    border: 0;
    text-align: left;
    cursor: pointer;
    color: #1a1f3a;
    font-size: 13px;
    font-weight: 500;
    line-height: 1.35;
    transition: background 0.15s ease;
}

.sidebar-item-label {
    flex: 1;
    min-width: 0;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    color: #1a1f3a;
}

.sidebar-item-input {
    flex: 1;
    min-width: 0;
    width: 100%;
    border: 0;
    outline: 0;
    background: rgba(255, 255, 255, 0.6);
    border-radius: 4px;
    padding: 3px 6px;
    margin: -2px -6px;
    font-family: inherit;
    font-size: 13px;
    font-weight: 500;
    color: inherit;
    box-shadow: inset 0 0 0 1px rgba(98, 77, 255, 0.4);
}

.sidebar-item:hover {
    background: rgba(98, 77, 255, 0.08);
}

.sidebar-item.active {
    background: rgba(98, 77, 255, 0.14);
    color: rgba(98, 77, 255, 1);
    font-weight: 600;
}

.sidebar-item-edit,
.sidebar-item-delete {
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    width: 22px;
    height: 22px;
    border-radius: 6px;
    border: 0;
    background: transparent;
    color: #b0b5c6;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    transition: opacity 0.15s ease, background 0.15s ease, color 0.15s ease;
    font-size: 14px;
    line-height: 1;
}

.sidebar-item-edit { right: 32px; }
.sidebar-item-delete { right: 6px; font-size: 16px; }

.sidebar-item:hover .sidebar-item-edit,
.sidebar-item:hover .sidebar-item-delete,
.sidebar-item.active .sidebar-item-edit,
.sidebar-item.active .sidebar-item-delete,
.sidebar-item.editing .sidebar-item-edit {
    opacity: 1;
}

.sidebar-item-edit:hover {
    background: rgba(98, 77, 255, 0.12);
    color: rgba(98, 77, 255, 1);
}

.sidebar-item-delete:hover {
    background: rgba(220, 70, 90, 0.12);
    color: rgba(220, 70, 90, 1);
}

/* 사이드바가 좌측에 겹치지 않게 작은 화면에선 숨김 */
@media (max-width: 980px) {
    #chat-sidebar {
        display: none;
    }
}
