/**
 * AI助手 · 前台悬浮面板
 * 浅色实底：圆角、留白、干净的投影，不做重色块与内嵌卡片
 */
.sqa-assistant {
    position: fixed;
    right: var(--sqa-x, 24px);
    bottom: var(--sqa-y, 24px);
    z-index: 9998;
    font-size: 14px;
    line-height: 1.65;
    color: #1b2130;
    -webkit-font-smoothing: antialiased;
}

.sqa-assistant.sqa-left {
    left: var(--sqa-x, 24px);
    right: auto;
}

/* 悬浮入口 */
.sqa-launcher {
    width: 54px;
    height: 54px;
    padding: 0;
    border: 0;
    border-radius: 50%;
    background: var(--sqa-color, #4f7cff);
    background-image: linear-gradient(135deg, rgba(255, 255, 255, 0.24), rgba(0, 0, 0, 0.12));
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    box-shadow: 0 10px 24px rgba(24, 39, 75, 0.22);
    transition: transform 0.18s ease;
}

.sqa-launcher:active {
    transform: scale(0.96);
}

.sqa-launcher svg {
    width: 24px;
    height: 24px;
}

/* 面板：一整块实底浅色面，标题与内容同处一层，不切出蓝色窗头 */
.sqa-panel {
    position: absolute;
    right: 0;
    bottom: 68px;
    width: 380px;
    max-width: calc(100vw - 32px);
    /* 正常聊天窗口的定高，屏幕再矮也不会顶出可视区 */
    height: min(560px, calc(100vh - 120px));
    max-height: calc(100vh - 120px);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    background: #fff;
    border: 1px solid rgba(15, 23, 42, 0.12);
    border-radius: 22px;
    box-shadow: 0 26px 60px -22px rgba(15, 23, 42, 0.5), 0 2px 10px rgba(15, 23, 42, 0.08);
}

.sqa-assistant.sqa-left .sqa-panel {
    left: 0;
    right: auto;
}

/* 头部：主题色实底 + 白字，面板一打开就有明确的上边界 */
.sqa-head {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 14px 10px 13px 16px;
    color: #fff;
    background: var(--sqa-color, #4f7cff);
    background-image: linear-gradient(135deg, rgba(255, 255, 255, 0.22) 0%, rgba(255, 255, 255, 0.04) 46%, rgba(0, 0, 0, 0.12) 100%);
    border-bottom: 1px solid rgba(15, 23, 42, 0.10);
}

.sqa-head-text {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: 1px;
}

.sqa-avatar {
    width: 42px;
    height: 42px;
    border-radius: 50%;
    overflow: hidden;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 15px;
    font-weight: 600;
    color: #fff;
    background: rgba(255, 255, 255, 0.24);
    box-shadow: 0 0 0 2px rgba(255, 255, 255, 0.38);
    flex: none;
}

.sqa-avatar img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.sqa-title {
    font-weight: 600;
    font-size: 14px;
    color: #fff;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.sqa-sub {
    font-size: 11px;
    line-height: 1.4;
    color: rgba(255, 255, 255, 0.78);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.sqa-actions {
    display: flex;
    align-items: center;
    gap: 1px;
    flex: none;
}

.sqa-icon {
    width: 28px;
    height: 28px;
    padding: 0;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border: 0;
    border-radius: 9px;
    background: transparent;
    color: rgba(255, 255, 255, 0.86);
    cursor: pointer;
    transition: background 0.15s ease, color 0.15s ease;
}

.sqa-icon:hover {
    background: rgba(255, 255, 255, 0.2);
    color: #fff;
}

.sqa-icon.is-on {
    background: rgba(255, 255, 255, 0.26);
    color: #fff;
}

.sqa-icon svg {
    width: 17px;
    height: 17px;
}

/* 消息区 */
.sqa-body {
    position: relative;
    flex: 1;
    display: flex;
    flex-direction: column;
    min-height: 0;
}

.sqa-msgs {
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    padding: 22px 16px 14px;
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.sqa-msg {
    display: flex;
    gap: 8px;
    align-items: flex-start;
    animation: sqa-in 0.22s ease both;
}

@keyframes sqa-in {
    from {
        opacity: 0;
        transform: translateY(6px);
    }
    to {
        opacity: 1;
        transform: none;
    }
}

.sqa-msg-user {
    justify-content: flex-end;
}

.sqa-msg-avatar {
    width: 30px;
    height: 30px;
    border-radius: 50%;
    flex: none;
    margin-top: 2px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 12px;
    color: #fff;
    background: var(--sqa-color, #4f7cff);
    overflow: hidden;
}

.sqa-msg-avatar img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.sqa-msg-body {
    display: flex;
    flex-direction: column;
    gap: 6px;
    min-width: 0;
    max-width: calc(100% - 34px);
}

.sqa-msg-user .sqa-msg-body {
    align-items: flex-end;
    max-width: 84%;
}

/* 气泡：浅灰底面，不加描边和投影，避免一层套一层 */
.sqa-msg-inner {
    padding: 10px 14px;
    border-radius: 16px 16px 16px 6px;
    background: #eaeef6;
    color: #1b2130;
    word-break: break-word;
}

.sqa-msg-user .sqa-msg-inner {
    background: var(--sqa-color, #4f7cff);
    background-image: linear-gradient(135deg, rgba(255, 255, 255, 0.16), rgba(0, 0, 0, 0.08));
    color: #fff;
    border-radius: 16px 16px 6px 16px;
}

/* 首屏欢迎语：淡淡的主题色底，比普通气泡显眼一点，但不再单独描边 */
.sqa-msg-hello .sqa-msg-inner {
    padding: 13px 15px;
    background: #f4f7ff;
    background: color-mix(in srgb, var(--sqa-color, #4f7cff) 12%, #fff);
    line-height: 1.72;
}

.sqa-msg-inner code {
    padding: 1px 5px;
    border-radius: 4px;
    background: rgba(0, 0, 0, 0.06);
    font-size: 12px;
}

.sqa-msg-user .sqa-msg-inner code {
    background: rgba(255, 255, 255, 0.22);
}

.sqa-inline-link {
    color: var(--sqa-color, #4f7cff);
    text-decoration: none;
    border-bottom: 1px solid rgba(79, 124, 255, 0.35);
}

/* 来源：只留序号和标题，不再做成一张张小卡片 */
.sqa-sources {
    display: flex;
    flex-direction: column;
    gap: 1px;
    padding: 2px 2px 0;
    counter-reset: sqa-src;
}

.sqa-sources-label {
    padding-left: 2px;
    font-size: 11px;
    letter-spacing: 0.06em;
    color: #64748b;
}

.sqa-source {
    display: flex;
    align-items: flex-start;
    gap: 6px;
    padding: 3px 2px;
    font-size: 12px;
    line-height: 1.5;
    color: #55627a;
    text-decoration: none;
}

.sqa-source::before {
    counter-increment: sqa-src;
    content: counter(sqa-src);
    flex: none;
    width: 15px;
    height: 15px;
    margin-top: 2px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 10px;
    font-weight: 600;
    color: var(--sqa-color, #4f7cff);
    background: rgba(79, 124, 255, 0.12);
    background: color-mix(in srgb, var(--sqa-color, #4f7cff) 14%, #fff);
    border-radius: 4px;
}

.sqa-source:hover {
    color: var(--sqa-color, #4f7cff);
}

/* 快捷提问 */
.sqa-quick {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    padding: 0 16px 12px;
}

.sqa-quick:not(:empty)::before {
    content: "试试这样问";
    flex-basis: 100%;
    font-size: 11px;
    letter-spacing: 0.06em;
    color: #64748b;
}

.sqa-quick-btn {
    padding: 7px 12px;
    font-size: 12px;
    color: #33415c;
    background: #fff;
    border: 1px solid #dde4f0;
    border-radius: 11px;
    cursor: pointer;
    transition: border-color 0.15s ease, color 0.15s ease, box-shadow 0.15s ease;
}

.sqa-quick-btn:hover {
    color: var(--sqa-color, #4f7cff);
    border-color: currentColor;
    box-shadow: 0 2px 8px rgba(24, 39, 75, 0.08);
}

/* 输入区：和面板同一个面，不再单独铺一条白带 */
.sqa-form {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 6px 14px 14px;
}

.sqa-input {
    flex: 1;
    box-sizing: border-box;
    min-height: 42px;
    max-height: 96px;
    padding: 10px 16px;
    font-family: inherit;
    font-size: 14px;
    line-height: 1.5;
    color: inherit;
    background: #f4f6fa;
    border: 1px solid rgba(15, 23, 42, 0.10);
    border-radius: 16px;
    resize: none;
    outline: none;
    transition: background 0.15s ease, border-color 0.15s ease, box-shadow 0.15s ease;
}

.sqa-input::placeholder {
    color: #a6aebd;
}

.sqa-input:focus {
    background: #fff;
    border-color: rgba(79, 124, 255, 0.4);
    border-color: color-mix(in srgb, var(--sqa-color, #4f7cff) 40%, #fff);
    box-shadow: 0 0 0 3px rgba(79, 124, 255, 0.1);
    box-shadow: 0 0 0 3px color-mix(in srgb, var(--sqa-color, #4f7cff) 12%, transparent);
}

.sqa-send {
    width: 42px;
    height: 42px;
    flex: none;
    padding: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #fff;
    background: var(--sqa-color, #4f7cff);
    background-image: linear-gradient(135deg, rgba(255, 255, 255, 0.2), rgba(0, 0, 0, 0.1));
    border: 0;
    border-radius: 50%;
    cursor: pointer;
    transition: opacity 0.15s ease, transform 0.15s ease;
}

.sqa-send:active {
    transform: scale(0.95);
}

.sqa-send:disabled {
    opacity: 0.45;
    cursor: default;
}

.sqa-send svg {
    width: 17px;
    height: 17px;
}

.sqa-typing {
    display: flex;
    gap: 4px;
    align-items: center;
    padding: 12px 14px;
}

.sqa-typing i {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: #b6bdcb;
    animation: sqa-blink 1.1s infinite;
}

.sqa-typing i:nth-child(2) {
    animation-delay: 0.18s;
}

.sqa-typing i:nth-child(3) {
    animation-delay: 0.36s;
}

@keyframes sqa-blink {
    0%, 80%, 100% { opacity: 0.3; }
    40% { opacity: 1; }
}

/* 会话记录 */
.sqa-drawer {
    position: absolute;
    top: 0;
    left: 0;
    bottom: 0;
    width: 262px;
    max-width: 84%;
    z-index: 3;
    display: flex;
    flex-direction: column;
    background: rgba(255, 255, 255, 0.99);
    border-right: 1px solid #eef0f4;
    box-shadow: 8px 0 28px rgba(24, 39, 75, 0.06);
}

.sqa-drawer-mask {
    position: absolute;
    top: 0;
    right: 0;
    bottom: 0;
    left: 0;
    z-index: 2;
    background: rgba(17, 24, 39, 0.2);
}

.sqa-drawer-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 8px 6px 14px;
    font-size: 12px;
    color: #64748b;
}

.sqa-drawer-close {
    width: 26px;
    height: 26px;
    padding: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    border: 0;
    border-radius: 8px;
    background: transparent;
    color: #8b93a7;
    cursor: pointer;
}

.sqa-drawer-close:hover {
    background: #f2f4f8;
    color: #1b2130;
}

.sqa-drawer-close svg {
    width: 16px;
    height: 16px;
}

.sqa-drawer-list {
    flex: 1;
    overflow-y: auto;
    padding: 0 8px 10px;
}

.sqa-drawer-item {
    display: flex;
    align-items: center;
    gap: 4px;
    padding: 8px;
    border-radius: 10px;
}

.sqa-drawer-item:hover {
    background: #f6f8fb;
}

.sqa-drawer-item.is-active {
    background: #eef2ff;
    background: color-mix(in srgb, var(--sqa-color, #4f7cff) 10%, #fff);
}

.sqa-drawer-open {
    flex: 1;
    min-width: 0;
    padding: 0;
    border: 0;
    background: transparent;
    text-align: left;
    cursor: pointer;
    color: inherit;
}

.sqa-drawer-title {
    display: block;
    font-size: 13px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.sqa-drawer-meta {
    display: block;
    font-size: 11px;
    color: #64748b;
}

.sqa-drawer-empty {
    padding: 28px 14px;
    font-size: 12px;
    color: #64748b;
    text-align: center;
}

/* 桌宠入口：悬浮球让位给角色，面板浮在她头顶；位置由 pet-entry.js 按她的实际位置写进变量 */
.sqa-assistant.sqa-pet-mode {
    z-index: 2147483001;
}

.sqa-assistant.sqa-pet-mode .sqa-launcher {
    display: none;
}

.sqa-assistant.sqa-pet-mode .sqa-panel {
    position: fixed;
    top: auto;
    right: auto;
    left: var(--sqa-pet-left, 24px);
    bottom: var(--sqa-pet-bottom, 96px);
    width: 380px;
    height: min(560px, calc(100vh - 160px));
    max-height: calc(100vh - 160px);
    max-width: calc(100vw - 24px);
}

/* 展开态在桌宠模式下同样居中：上面那套 left/bottom 同时生效会把面板拉成一条 */
.sqa-assistant.sqa-pet-mode.is-expanded .sqa-panel {
    top: 50%;
    left: 50%;
    right: auto;
    bottom: auto;
    transform: translate(-50%, -50%);
    width: min(760px, calc(100vw - 64px));
    height: min(640px, calc(100vh - 96px));
    max-width: none;
}

/* 窄屏放不下她：入口退回悬浮球，桌宠先藏起来 */
html.sqa-pet-narrow [data-dsh-live2d-pet-root],
html.sqa-pet-narrow [data-dsh-live2d-pet] {
    display: none;
}

/* 展开态：居中对话框，四周留白，不再铺满整屏 */
.sqa-assistant.is-expanded .sqa-panel {
    position: fixed;
    top: 50%;
    left: 50%;
    right: auto;
    bottom: auto;
    transform: translate(-50%, -50%);
    width: min(760px, calc(100vw - 64px));
    height: min(640px, calc(100vh - 96px));
    max-width: none;
    max-height: none;
    border-radius: 24px;
}

.sqa-assistant.is-expanded .sqa-msgs {
    padding: 18px 26px;
}

.sqa-assistant.is-expanded .sqa-quick {
    padding: 0 26px 14px;
}

@media (max-width: 480px) {
    /* 手机上贴边放，别离边太远把正文压住；底部让开 iPhone 的横条 */
    .sqa-assistant {
        right: 16px;
        bottom: calc(16px + env(safe-area-inset-bottom, 0px));
    }

    .sqa-assistant.sqa-left {
        left: 16px;
        right: auto;
    }

    .sqa-panel {
        position: fixed;
        top: auto;
        left: 12px;
        right: 12px;
        bottom: calc(12px + env(safe-area-inset-bottom, 0px));
        width: auto;
        height: min(560px, calc(100vh - 24px - env(safe-area-inset-bottom, 0px)));
        max-width: none;
        max-height: calc(100vh - 24px - env(safe-area-inset-bottom, 0px));
    }

    .sqa-assistant.is-expanded .sqa-panel {
        top: 8px;
        left: 8px;
        right: 8px;
        bottom: 8px;
        width: auto;
        height: auto;
        transform: none;
        border-radius: 18px;
    }

    .sqa-assistant.is-expanded .sqa-msgs {
        padding: 16px;
    }

    .sqa-assistant.is-expanded .sqa-quick {
        padding: 0 16px 12px;
    }

    .sqa-drawer {
        width: 78%;
    }
}

/* 面板与抽屉都声明了 display: flex，会盖掉浏览器默认的 [hidden] { display: none } */
.sqa-panel[hidden],
.sqa-drawer[hidden],
.sqa-drawer-mask[hidden] {
    display: none;
}
