/* Atelier · 前台在线客服（独立样式，不覆盖 app.css） */

.atelier-chat {
    --chat-ink: #1d1b18;
    --chat-ink-soft: #38332c;
    --chat-ivory: #f6efe2;
    --chat-paper: #fcfaf4;
    --chat-panel: #fbf7ee;
    --chat-gold: #a9854f;
    --chat-gold-soft: #c8ab7c;
    --chat-muted: #8d8579;
    --chat-line: rgba(29, 27, 24, 0.12);
    position: relative;
    z-index: 9000;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
    font-size: 14px;
    line-height: 1.5;
    color: var(--chat-ink);
    -webkit-font-smoothing: antialiased;
}

.atelier-chat *,
.atelier-chat *::before,
.atelier-chat *::after {
    box-sizing: border-box;
}

.atelier-chat [hidden] {
    display: none !important;
}

.atelier-chat button {
    font: inherit;
    cursor: pointer;
}

/* ---------------- 气泡按钮 ---------------- */

.atelier-chat .chat-fab {
    position: fixed;
    right: 24px;
    bottom: 24px;
    display: inline-flex;
    align-items: center;
    gap: 9px;
    padding: 12px 20px 12px 16px;
    border: 1px solid rgba(255, 255, 255, 0.14);
    border-radius: 999px;
    background: var(--chat-ink);
    color: var(--chat-ivory);
    font-size: 14px;
    letter-spacing: 0.05em;
    box-shadow: 0 16px 34px -12px rgba(24, 20, 15, 0.55), 0 2px 6px rgba(24, 20, 15, 0.18);
    transition: transform 0.25s ease, box-shadow 0.25s ease, background 0.25s ease, opacity 0.2s ease, visibility 0.2s ease;
}

.atelier-chat .chat-fab:hover {
    transform: translateY(-2px);
    background: #26221d;
    box-shadow: 0 20px 40px -12px rgba(24, 20, 15, 0.62), 0 2px 8px rgba(24, 20, 15, 0.22);
}

.atelier-chat .chat-fab:focus-visible {
    outline: 2px solid var(--chat-gold-soft);
    outline-offset: 3px;
}

/* 面板打开时收起气泡，避免遮挡与重复入口 */
.atelier-chat.is-open .chat-fab {
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
    transform: translateY(10px);
}

.atelier-chat .chat-fab__icon {
    display: inline-flex;
    color: var(--chat-gold-soft);
}

.atelier-chat .chat-fab__label {
    white-space: nowrap;
}

.atelier-chat .chat-fab__dot {
    position: absolute;
    top: 7px;
    right: 9px;
    width: 9px;
    height: 9px;
    border-radius: 50%;
    background: #c0432f;
    border: 2px solid var(--chat-ink);
}

.atelier-chat .chat-fab__count {
    position: absolute;
    top: -6px;
    right: -4px;
    min-width: 20px;
    height: 20px;
    padding: 0 6px;
    border-radius: 999px;
    background: #c0432f;
    color: #fff;
    font-size: 11px;
    line-height: 20px;
    text-align: center;
    font-weight: 600;
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.2);
}

/* ---------------- 面板 ---------------- */

.atelier-chat .chat-panel {
    position: fixed;
    right: 24px;
    bottom: 92px;
    display: flex;
    flex-direction: column;
    width: 382px;
    max-width: calc(100vw - 32px);
    height: min(620px, calc(100vh - 120px));
    height: min(620px, calc(100dvh - 120px));
    background: var(--chat-paper);
    border: 1px solid var(--chat-line);
    border-radius: 18px;
    overflow: hidden;
    box-shadow: 0 36px 70px -28px rgba(28, 24, 18, 0.5), 0 8px 24px -12px rgba(28, 24, 18, 0.24);
    animation: chat-rise 0.28s ease both;
}

@keyframes chat-rise {
    from {
        opacity: 0;
        transform: translateY(14px) scale(0.985);
    }
    to {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

.atelier-chat .chat-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 16px 18px 14px;
    background: linear-gradient(180deg, #f8f2e7 0%, #f4ecde 100%);
    border-bottom: 1px solid var(--chat-line);
}

.atelier-chat .chat-head__brand {
    display: flex;
    flex-direction: column;
    gap: 3px;
    min-width: 0;
}

.atelier-chat .chat-head__name {
    font-family: Georgia, "Times New Roman", "Songti SC", "Noto Serif SC", "STSong", serif;
    font-size: 17px;
    letter-spacing: 0.12em;
    color: var(--chat-ink);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.atelier-chat .chat-head__status {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    font-size: 12px;
    color: var(--chat-muted);
    letter-spacing: 0.04em;
}

.atelier-chat .chat-head__dot {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: #b0a89b;
    box-shadow: 0 0 0 3px rgba(176, 168, 155, 0.16);
}

.atelier-chat .chat-head__status.is-online {
    color: #5f7256;
}

.atelier-chat .chat-head__status.is-online .chat-head__dot {
    background: #6f8a62;
    box-shadow: 0 0 0 3px rgba(111, 138, 98, 0.18);
}

.atelier-chat .chat-head__close {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    border: none;
    border-radius: 50%;
    background: transparent;
    color: var(--chat-ink-soft);
    transition: background 0.2s ease;
}

.atelier-chat .chat-head__close:hover {
    background: rgba(29, 27, 24, 0.07);
}

/* ---------------- 消息区 ---------------- */

.atelier-chat .chat-body {
    flex: 1 1 auto;
    min-height: 0;
    padding: 18px 16px 10px;
    overflow-y: auto;
    overscroll-behavior: contain;
    display: flex;
    flex-direction: column;
    gap: 14px;
    background:
        radial-gradient(120% 80% at 100% 0%, rgba(201, 178, 140, 0.12), transparent 55%),
        var(--chat-panel);
    scrollbar-width: thin;
    scrollbar-color: rgba(29, 27, 24, 0.18) transparent;
}

.atelier-chat .chat-body::-webkit-scrollbar {
    width: 6px;
}

.atelier-chat .chat-body::-webkit-scrollbar-thumb {
    background: rgba(29, 27, 24, 0.16);
    border-radius: 999px;
}

.atelier-chat .chat-empty {
    margin: auto 8px;
    padding: 26px 18px;
    text-align: center;
    border: 1px dashed var(--chat-line);
    border-radius: 16px;
    background: rgba(255, 253, 247, 0.6);
}

.atelier-chat .chat-empty__title {
    margin: 0 0 8px;
    font-family: Georgia, "Songti SC", "Noto Serif SC", serif;
    font-size: 15px;
    letter-spacing: 0.06em;
    color: var(--chat-ink);
}

.atelier-chat .chat-empty__text {
    margin: 0;
    font-size: 12.5px;
    line-height: 1.7;
    color: var(--chat-muted);
}

.atelier-chat .chat-msg {
    display: flex;
    flex-direction: column;
    max-width: 84%;
    gap: 5px;
}

.atelier-chat .chat-msg--visitor {
    align-self: flex-end;
    align-items: flex-end;
}

.atelier-chat .chat-msg--staff {
    align-self: flex-start;
    align-items: flex-start;
}

.atelier-chat .chat-msg__bubble {
    padding: 10px 14px;
    border-radius: 18px;
    font-size: 14px;
    line-height: 1.65;
    word-break: break-word;
    overflow-wrap: anywhere;
}

.atelier-chat .chat-msg--visitor .chat-msg__bubble {
    background: var(--chat-ink);
    color: #f7f1e4;
    border-bottom-right-radius: 6px;
    box-shadow: 0 8px 18px -12px rgba(24, 20, 15, 0.55);
}

.atelier-chat .chat-msg--staff .chat-msg__bubble {
    background: #fffdf8;
    color: var(--chat-ink);
    border: 1px solid rgba(29, 27, 24, 0.09);
    border-bottom-left-radius: 6px;
    box-shadow: 0 8px 18px -16px rgba(24, 20, 15, 0.4);
}

.atelier-chat .chat-msg__text {
    margin: 0;
    white-space: pre-wrap;
}

.atelier-chat .chat-msg__image {
    display: block;
    margin-top: 7px;
    border-radius: 12px;
    overflow: hidden;
    cursor: zoom-in;
}

.atelier-chat .chat-msg__image img {
    display: block;
    max-width: 210px;
    max-height: 240px;
    width: auto;
    height: auto;
    object-fit: cover;
}

.atelier-chat .chat-msg__meta {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 0 4px;
    font-size: 11px;
    color: var(--chat-muted);
    letter-spacing: 0.03em;
}

.atelier-chat .chat-msg__who {
    color: var(--chat-gold);
}

/* ---------------- 商品上下文 ---------------- */

.atelier-chat .chat-product {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 16px;
    background: #f6efe3;
    border-top: 1px solid var(--chat-line);
}

.atelier-chat .chat-product__img {
    width: 44px;
    height: 52px;
    flex: 0 0 auto;
    border-radius: 8px;
    object-fit: cover;
    background: #e9e1d1;
}

.atelier-chat .chat-product__meta {
    display: flex;
    flex-direction: column;
    gap: 2px;
    min-width: 0;
    flex: 1 1 auto;
}

.atelier-chat .chat-product__label {
    font-size: 10px;
    letter-spacing: 0.16em;
    color: var(--chat-gold);
    text-transform: uppercase;
}

.atelier-chat .chat-product__title {
    font-size: 13px;
    color: var(--chat-ink);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.atelier-chat .chat-product__code {
    font-size: 11px;
    color: var(--chat-muted);
    letter-spacing: 0.05em;
}

.atelier-chat .chat-product__link {
    flex: 0 0 auto;
    font-size: 12px;
    color: var(--chat-gold);
    text-decoration: none;
    border-bottom: 1px solid rgba(169, 133, 79, 0.35);
    padding-bottom: 1px;
}

/* ---------------- 称呼 ---------------- */

.atelier-chat .chat-name {
    display: flex;
    flex-direction: column;
    gap: 4px;
    padding: 10px 18px;
    background: var(--chat-paper);
    border-top: 1px solid var(--chat-line);
}

.atelier-chat .chat-name__label {
    font-size: 11px;
    letter-spacing: 0.08em;
    color: var(--chat-muted);
}

.atelier-chat .chat-name__input {
    width: 100%;
    padding: 7px 2px;
    border: none;
    border-bottom: 1px solid var(--chat-line);
    background: transparent;
    color: var(--chat-ink);
    font-size: 14px;
    outline: none;
}

.atelier-chat .chat-name__input:focus {
    border-bottom-color: var(--chat-gold);
}

/* ---------------- 输入区 ---------------- */

.atelier-chat .chat-compose {
    padding: 10px 16px 14px;
    background: var(--chat-paper);
    border-top: 1px solid var(--chat-line);
}

.atelier-chat .chat-compose__preview {
    position: relative;
    display: inline-block;
    margin-bottom: 10px;
}

.atelier-chat .chat-compose__preview img {
    display: block;
    max-height: 84px;
    max-width: 140px;
    border-radius: 10px;
    border: 1px solid var(--chat-line);
    object-fit: cover;
}

.atelier-chat .chat-compose__preview-remove {
    position: absolute;
    top: -7px;
    right: -7px;
    width: 20px;
    height: 20px;
    border: none;
    border-radius: 50%;
    background: rgba(29, 27, 24, 0.82);
    color: #fff;
    font-size: 13px;
    line-height: 18px;
    padding: 0;
}

.atelier-chat .chat-compose__row {
    display: flex;
    align-items: flex-end;
    gap: 10px;
}

.atelier-chat .chat-compose__file {
    display: inline-flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 1px;
    flex: 0 0 auto;
    width: 44px;
    padding: 8px 0;
    border-radius: 12px;
    border: 1px solid var(--chat-line);
    color: var(--chat-muted);
    cursor: pointer;
    transition: border-color 0.2s ease, color 0.2s ease;
}

.atelier-chat .chat-compose__file:hover {
    border-color: var(--chat-gold-soft);
    color: var(--chat-gold);
}

.atelier-chat .chat-compose__file-text {
    font-size: 9px;
    letter-spacing: 0.06em;
}

.atelier-chat .chat-compose__input {
    flex: 1 1 auto;
    min-height: 42px;
    max-height: 140px;
    padding: 10px 12px;
    border: 1px solid var(--chat-line);
    border-radius: 14px;
    background: #fffdf8;
    color: var(--chat-ink);
    font-family: inherit;
    font-size: 14px;
    line-height: 1.5;
    resize: none;
    outline: none;
    transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

.atelier-chat .chat-compose__input:focus {
    border-color: var(--chat-gold-soft);
    box-shadow: 0 0 0 3px rgba(169, 133, 79, 0.12);
}

.atelier-chat .chat-compose__send {
    flex: 0 0 auto;
    padding: 11px 16px;
    border: none;
    border-radius: 999px;
    background: var(--chat-ink);
    color: var(--chat-ivory);
    font-size: 13px;
    letter-spacing: 0.06em;
    transition: opacity 0.2s ease, transform 0.2s ease;
}

.atelier-chat .chat-compose__send:hover:not(:disabled) {
    transform: translateY(-1px);
}

.atelier-chat .chat-compose__send:disabled {
    opacity: 0.55;
    cursor: default;
}

/* ---------------- 提示 ---------------- */

.atelier-chat .chat-toast {
    position: fixed;
    right: 24px;
    bottom: 100px;
    max-width: 300px;
    padding: 10px 16px;
    border-radius: 10px;
    background: rgba(29, 27, 24, 0.94);
    color: var(--chat-ivory);
    font-size: 13px;
    line-height: 1.5;
    box-shadow: 0 18px 36px -18px rgba(0, 0, 0, 0.5);
    opacity: 0;
    transform: translateY(8px);
    transition: opacity 0.2s ease, transform 0.2s ease;
    pointer-events: none;
}

.atelier-chat .chat-toast.is-visible {
    opacity: 1;
    transform: translateY(0);
}

/* ---------------- 移动端 ---------------- */

/* 商品详情页有底部固定 CTA，气泡上移避免遮挡 */
@media (max-width: 860px) {
    body.page-product .atelier-chat .chat-fab {
        bottom: calc(86px + env(safe-area-inset-bottom));
    }
}

@media (max-width: 640px) {
    .atelier-chat .chat-fab {
        right: 16px;
        bottom: 16px;
        padding: 11px 17px 11px 14px;
        font-size: 13px;
    }

    .atelier-chat .chat-panel {
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        width: 100%;
        max-width: none;
        height: 100vh;
        height: 100dvh;
        border: none;
        border-radius: 0;
        z-index: 9100;
        animation: none;
    }

    .atelier-chat .chat-head {
        padding-top: calc(14px + env(safe-area-inset-top, 0px));
    }

    .atelier-chat .chat-compose {
        padding-bottom: calc(14px + env(safe-area-inset-bottom, 0px));
    }

    .atelier-chat .chat-toast {
        left: 16px;
        right: 16px;
        bottom: calc(80px + env(safe-area-inset-bottom, 0px));
        max-width: none;
        text-align: center;
    }
}
