/* 問書 FAB + 抽屜 */
.book-ask-fab {
    position: fixed;
    right: 20px;
    bottom: 24px;
    z-index: 9990;
    width: 52px;
    height: 52px;
    border: 1px solid rgba(255, 248, 235, 0.45);
    border-radius: 50%;
    background: var(--btn-primary, #8b4513);
    color: #fffaf0;
    font-size: 1.28rem;
    font-weight: 600;
    font-family: "Source Han Serif TC", "Noto Serif TC", "Songti TC", "SimSun", serif;
    letter-spacing: 0;
    box-shadow: 0 6px 18px rgba(40, 20, 0, 0.22);
    cursor: pointer;
    overflow: visible;
    line-height: 1;
    padding: 0;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    transition: box-shadow 0.35s ease, filter 0.35s ease, border-color 0.35s ease;
}

.book-ask-fab-label {
    position: relative;
    z-index: 2;
    transition: text-shadow 0.35s ease, color 0.35s ease;
}

.book-ask-fab.is-speaking {
    border-color: rgba(255, 230, 170, 0.9);
    box-shadow:
        0 0 0 2px rgba(255, 214, 120, 0.45),
        0 0 16px 4px rgba(255, 196, 90, 0.4),
        0 6px 18px rgba(40, 20, 0, 0.22);
}

.book-ask-fab.is-speaking .book-ask-fab-label {
    animation: book-ask-speaking-pulse 1.2s ease-in-out infinite;
}

@keyframes book-ask-speaking-pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.72; }
}

/* 外圈光環（由 JS 加 .is-flaring 觸發） */
.book-ask-fab-glow {
    position: absolute;
    left: 50%;
    top: 50%;
    width: 52px;
    height: 52px;
    margin: -26px 0 0 -26px;
    border-radius: 50%;
    pointer-events: none;
    z-index: 0;
    border: 2px solid rgba(255, 220, 140, 0);
    box-shadow: none;
    opacity: 0;
    transform: scale(1);
    transition: none;
}

/* JS 觸發的一次光效：約 1.4s */
.book-ask-fab.is-flaring {
    border-color: rgba(255, 230, 170, 0.85);
    filter: brightness(1.18);
    box-shadow:
        0 0 0 3px rgba(255, 214, 120, 0.55),
        0 0 22px 8px rgba(255, 196, 90, 0.55),
        0 8px 22px rgba(40, 20, 0, 0.3);
}

.book-ask-fab.is-flaring .book-ask-fab-label {
    color: #fffef8;
    text-shadow:
        0 0 10px rgba(255, 236, 190, 1),
        0 0 20px rgba(255, 200, 100, 0.85);
}

.book-ask-fab.is-flaring .book-ask-fab-glow {
    animation: book-ask-flare-ring 1.35s ease-out forwards;
}

@keyframes book-ask-flare-ring {
    0% {
        opacity: 0.95;
        transform: scale(1);
        border-color: rgba(255, 230, 160, 0.9);
        box-shadow: 0 0 10px 2px rgba(255, 210, 120, 0.55);
    }
    100% {
        opacity: 0;
        transform: scale(1.85);
        border-color: rgba(255, 230, 160, 0);
        box-shadow: 0 0 28px 8px rgba(255, 210, 120, 0);
    }
}

.book-ask-fab:hover {
    filter: brightness(1.08);
    box-shadow:
        0 0 0 2px rgba(255, 220, 150, 0.35),
        0 0 14px 3px rgba(255, 200, 100, 0.28),
        0 8px 22px rgba(40, 20, 0, 0.28);
}

.book-ask-fab:hover .book-ask-fab-glow {
    opacity: 0.55;
    transform: scale(1.2);
    border-color: rgba(255, 220, 150, 0.4);
}

.book-ask-panel {
    position: fixed;
    right: 16px;
    bottom: 92px;
    width: min(420px, calc(100vw - 24px));
    height: min(640px, calc(100vh - 120px));
    z-index: 9991;
    display: none;
    flex-direction: column;
    background: var(--card-bg, #fffaf2);
    border: 1px solid var(--border-color, #e4d5c2);
    border-radius: 14px;
    box-shadow: 0 16px 40px rgba(40, 20, 0, 0.2);
    overflow: hidden;
}

.book-ask-panel.open {
    display: flex;
}

.book-ask-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    padding: 12px 14px;
    border-bottom: 1px solid var(--border-color, #e4d5c2);
    background: rgba(139, 69, 19, 0.06);
}

.book-ask-header h3 {
    margin: 0;
    font-size: 1rem;
    color: var(--text-primary, #3b2a1a);
}

.book-ask-header-actions {
    display: flex;
    align-items: center;
    gap: 6px;
}

.book-ask-header button {
    border: 1px solid var(--border-color, #e4d5c2);
    background: #fff;
    border-radius: 8px;
    padding: 4px 8px;
    cursor: pointer;
    font-size: 0.85rem;
}

.book-ask-tts-toggle {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    margin: 0;
    padding: 4px 8px;
    border: 1px solid var(--border-color, #e4d5c2);
    border-radius: 8px;
    background: #fff;
    font-size: 0.82rem;
    color: var(--text-primary, #3b2a1a);
    cursor: pointer;
    user-select: none;
    white-space: nowrap;
}

.book-ask-tts-toggle input {
    margin: 0;
    accent-color: var(--btn-primary, #8b4513);
    cursor: pointer;
}

.book-ask-tts-toggle:has(input:not(:checked)) {
    opacity: 0.72;
    color: #7a6a58;
}

.book-ask-meta {
    padding: 8px 14px;
    font-size: 0.82rem;
    color: var(--text-secondary, #6b553f);
    border-bottom: 1px solid var(--border-color, #e4d5c2);
}

.book-ask-messages {
    flex: 1;
    overflow-y: auto;
    padding: 12px 14px;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.book-ask-bubble {
    max-width: 92%;
    padding: 10px 12px;
    border-radius: 12px;
    white-space: pre-wrap;
    word-break: break-word;
    font-size: 0.92rem;
    line-height: 1.5;
}

.book-ask-bubble.user {
    align-self: flex-end;
    background: rgba(139, 69, 19, 0.12);
}

.book-ask-bubble.assistant {
    align-self: flex-start;
    background: #fff;
    border: 1px solid var(--border-color, #e4d5c2);
}

.book-ask-bubble.intro {
    align-self: stretch;
    max-width: 100%;
    background: transparent;
    border: none;
    border-left: 2px solid rgba(139, 69, 19, 0.35);
    border-radius: 0;
    padding: 4px 0 4px 12px;
    color: var(--text-secondary, #6b553f);
    font-family: "Noto Serif TC", "Source Han Serif TC", "Songti TC", "SimSun", serif;
    font-size: 0.95rem;
    line-height: 1.7;
}

.book-ask-charge {
    margin-top: 6px;
    font-size: 0.78rem;
    color: #8a6a45;
}

.book-ask-citations {
    margin-top: 8px;
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.book-ask-citations a {
    color: var(--text-accent, #8b4513);
    font-size: 0.82rem;
    text-decoration: underline;
}

.book-ask-citation-nolink {
    color: #6b5a48;
    font-size: 0.82rem;
}

.book-ask-composer {
    border-top: 1px solid var(--border-color, #e4d5c2);
    padding: 10px 12px;
    display: flex;
    gap: 8px;
}

.book-ask-composer textarea {
    flex: 1;
    min-height: 44px;
    max-height: 120px;
    resize: vertical;
    border: 1px solid var(--border-color, #e4d5c2);
    border-radius: 10px;
    padding: 8px 10px;
    font: inherit;
}

.book-ask-composer button {
    border: none;
    border-radius: 10px;
    background: var(--btn-primary, #8b4513);
    color: #fff;
    padding: 0 14px;
    cursor: pointer;
    white-space: nowrap;
}

.book-ask-composer button:disabled {
    opacity: 0.55;
    cursor: not-allowed;
}

.book-ask-status {
    padding: 0 14px 10px;
    font-size: 0.8rem;
    color: #a33;
    min-height: 1.2em;
}

.book-ask-bubble.assistant.error .book-ask-bubble-body {
    color: #7a2e2e;
    opacity: 0.92;
}

@media (max-width: 640px) {
    .book-ask-panel {
        right: 8px;
        left: 8px;
        width: auto;
        bottom: 84px;
        height: min(70vh, 560px);
    }

    .book-ask-fab {
        right: 14px;
        bottom: 16px;
    }
}
