.ai-toggle-btn {
    margin-left: 8px;
    height: 32px;
    min-width: 34px;
    padding: 4px 8px;
    border: 1px solid transparent;
    background: transparent;
    box-shadow: none;
}

.ai-toggle-btn:hover {
    border-color: #c9d3e0;
    background: #f6f9ff;
}

.ai-toggle-btn.active {
    border-color: #a9bfdc;
    background: #eaf2ff;
    box-shadow: none !important;
}

.ai-toggle-brand {
    display: inline;
    color: #526173;
    font-family: "Helvetica Neue", Helvetica, Arial, sans-serif;
    font-size: 21px;
    font-weight: 600;
    line-height: 1;
}

.ai-toggle-btn.active .ai-toggle-brand {
    color: #2f4f79;
}

#bookAgentPanel.book-agent-panel {
    position: fixed;
    top: 0;
    right: 0;
    bottom: 0;
    z-index: 1350;
    display: none;
    width: 450px;
    max-width: 100vw;
    background: #fff;
    border-left: 1px solid #d9dfe7;
    box-shadow: -8px 0 20px rgba(0, 0, 0, 0.08);
    flex-direction: column;
    overflow: hidden;
    transition: width 0.2s ease, transform 0.22s ease;
}

#bookAgentPanel.book-agent-panel.open {
    display: flex;
}

#bookAgentPanel.book-agent-panel.collapsed {
    width: 40px !important;
    background: linear-gradient(165deg, #e9ecff 0%, #f0e9ff 42%, #ebe4f8 100%);
    border-left: 1px solid rgba(118, 75, 162, 0.2);
    box-shadow: -6px 0 18px rgba(102, 126, 234, 0.1);
    cursor: pointer;
}

#bookAgentPanel.book-agent-panel.collapsed::before {
    content: "✦";
    position: absolute;
    top: 12px;
    left: 50%;
    z-index: 2;
    transform: translateX(-50%);
    color: #6b5b95;
    font-size: 16px;
    font-weight: 600;
}

#bookAgentPanel.book-agent-panel.collapsed:not(.expanded) .book-agent-header,
#bookAgentPanel.book-agent-panel.collapsed:not(.expanded) .book-agent-tabs,
#bookAgentPanel.book-agent-panel.collapsed:not(.expanded) .book-agent-messages,
#bookAgentPanel.book-agent-panel.collapsed:not(.expanded) .book-agent-input {
    visibility: hidden;
}

#bookAgentPanel.book-agent-panel.collapsed.expanded {
    width: 400px !important;
    cursor: default;
    box-shadow: -12px 0 24px rgba(0, 0, 0, 0.18);
}

#bookAgentPanel.book-agent-panel.collapsed.expanded::before {
    display: none;
}

.book-agent-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    padding: 10px 14px;
    background: #f7f9fc;
    border-bottom: 1px solid #e3e7ee;
}

.book-agent-title {
    min-width: 0;
    overflow: hidden;
    color: #334155;
    font-size: 14px;
    font-weight: 600;
    line-height: 1.3;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.book-agent-close {
    flex: 0 0 auto;
}

.book-agent-tabs {
    border-bottom: 1px solid #e3e7ee;
    background: #fff;
}

.book-agent-w2tabs {
    min-width: 0;
    background: #fff;
}

.book-agent-w2tabs .w2ui-tab,
.book-agent-w2tabs .w2ui-scroll-wrapper .w2ui-tab {
    background: #fff;
}

.book-agent-w2tabs .w2ui-tab-text {
    max-width: 130px;
    overflow: hidden;
    padding: 8px 12px;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.book-agent-w2tabs .w2ui-tabs-line {
    border-bottom: none;
}

.book-agent-messages {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 12px;
    overflow-y: auto;
    padding: 14px;
    background: #fff;
    scrollbar-width: thin;
    scrollbar-color: transparent transparent;
}

.book-agent-messages::-webkit-scrollbar {
    width: 4px;
    background: transparent;
}

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

.book-agent-messages::-webkit-scrollbar-thumb {
    background: transparent;
    border-radius: 999px;
}

.book-agent-messages.is-scrolling {
    scrollbar-color: rgba(0, 0, 0, 0.38) transparent;
}

.book-agent-messages.is-scrolling::-webkit-scrollbar-thumb {
    background: rgba(0, 0, 0, 0.38);
    border-radius: 999px;
}

.book-agent-empty {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 120px;
    color: #9aa4b2;
    font-size: 14px;
}

.book-agent-empty-help {
    display: block;
    text-align: center;
    font-size: 1.2em;
    line-height: 1.8;
}

.book-agent-empty-help a {
    color: #2563eb;
    cursor: pointer;
    text-decoration: none;
}

.book-agent-empty-help a:hover,
.book-agent-empty-help a:focus {
    text-decoration: underline;
}

.book-agent-message {
    margin: 0;
    padding: 10px 12px;
    border-radius: 8px;
    line-height: 1.45;
    overflow-wrap: anywhere;
    user-select: text;
}

.book-agent-message.user-message {
    margin-left: 6%;
    background: #e9f4ff;
    border-left: 4px solid #4b9fff;
}

.ai-text-selection-highlight {
    background: rgba(255, 255, 0, 0.3);
    border-top: 1px solid #ffd700;
    border-bottom: 1px solid #ffd700;
}

#contentBody .book-agent-find-highlight {
    background-color: rgba(255, 230, 120, 0.55);
    border-bottom: 1px solid #c9a227;
    border-radius: 2px;
}

.book-agent-user-selection-block {
    margin-bottom: 6px;
}

.book-agent-user-selection-label {
    margin-bottom: 4px;
    color: #4a5a6a;
    font-size: 0.9em;
    line-height: 1.25;
}

.book-agent-user-excerpt {
    max-height: 160px;
    padding: 6px 8px;
    overflow-y: auto;
    background: rgba(255, 255, 255, 0.7);
    border: 1px solid rgba(75, 159, 255, 0.35);
    border-radius: 6px;
    line-height: 1.35;
    word-break: break-word;
}

.book-agent-user-excerpt-more {
    margin-left: 0.25em;
    color: #2563eb;
}

.book-agent-user-msg-line {
    margin-top: 4px;
}

.book-agent-message.ai-message {
    margin-right: 6%;
    background: #f5f0ff;
    border-left: 4px solid #9568f3;
}

.book-agent-message.ai-message .message-content > p:first-child {
    display: inline;
    margin: 0;
}

.book-agent-message.ai-message .message-content > p:first-child + * {
    margin-top: 0.75em;
}

.book-agent-message.ai-message .book-agent-link,
.book-agent-message.ai-message .book-agent-link.active {
    display: inline;
    margin: 0;
    padding: 0;
    background: transparent;
    border-radius: 0;
    color: #2563eb;
    cursor: pointer;
    font-size: inherit;
    font-weight: inherit;
    line-height: inherit;
    text-decoration: none;
}

.book-agent-message.ai-message .book-agent-link:hover,
.book-agent-message.ai-message .book-agent-link:focus {
    background: transparent;
    color: #1d4ed8;
    text-decoration: underline;
}

.book-agent-thinking-wait {
    color: #64748b;
}

.message-content {
    white-space: pre-wrap;
}

.book-agent-message.ai-message .message-content {
    font-size: inherit;
    white-space: normal;
}

.book-agent-message.ai-message .message-content * {
    font-size: inherit;
}

.book-agent-message.ai-message .message-content h1,
.book-agent-message.ai-message .message-content h2,
.book-agent-message.ai-message .message-content h3,
.book-agent-message.ai-message .message-content h4,
.book-agent-message.ai-message .message-content h5,
.book-agent-message.ai-message .message-content h6 {
    margin: 0.65em 0 0.35em;
    color: inherit;
    font-weight: 600;
    line-height: 1.3;
}

.book-agent-message.ai-message .message-content h1 {
    font-size: 1.25em;
}

.book-agent-message.ai-message .message-content h2 {
    font-size: 1.18em;
}

.book-agent-message.ai-message .message-content h3 {
    font-size: 1.1em;
}

.book-agent-message.ai-message .message-content h4,
.book-agent-message.ai-message .message-content h5,
.book-agent-message.ai-message .message-content h6 {
    font-size: 1em;
}

.book-agent-message.ai-message .message-content p,
.book-agent-message.ai-message .message-content ul,
.book-agent-message.ai-message .message-content ol {
    margin-top: 0.35em;
    margin-bottom: 0.6em;
}

.book-agent-message.ai-message .message-content ul,
.book-agent-message.ai-message .message-content ol {
    margin-left: 0;
    padding-left: 1.3em;
    list-style-position: outside;
}

.book-agent-message.ai-message .message-content li {
    margin-left: 0;
    padding-left: 0.15em;
}

.book-agent-command-action {
    margin-top: 8px;
}

.book-agent-find-nav,
.book-agent-speak-nav {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 10px;
    margin-top: 10px;
    padding-top: 10px;
    border-top: 1px solid rgba(15, 23, 42, 0.12);
}

.book-agent-find-prev,
.book-agent-find-next,
.book-agent-speak-prev,
.book-agent-speak-next {
    width: 34px;
    height: 30px;
    padding: 0;
    border: 1px solid #c5cad3;
    border-radius: 6px;
    background: #e9ecef;
    color: #334155;
    font-weight: 700;
    line-height: 1;
}

.book-agent-find-prev:hover:not(:disabled),
.book-agent-find-next:hover:not(:disabled),
.book-agent-speak-prev:hover:not(:disabled),
.book-agent-speak-next:hover:not(:disabled) {
    background: #dde1e6;
    border-color: #aeb5c2;
}

.book-agent-find-prev:disabled,
.book-agent-find-next:disabled,
.book-agent-speak-prev:disabled,
.book-agent-speak-next:disabled {
    opacity: 0.45;
    cursor: not-allowed;
}

.book-agent-find-count,
.book-agent-speak-count {
    min-width: 3.2em;
    text-align: center;
    font-weight: 700;
    font-variant-numeric: tabular-nums;
}

.book-agent-find-status,
.book-agent-speak-status {
    color: #b91c1c;
    font-size: 0.9em;
    font-weight: 600;
}

.book-agent-find-detail,
.book-agent-speak-detail {
    width: 100%;
    padding: 8px 10px;
    border: 1px solid rgba(75, 159, 255, 0.35);
    border-radius: 6px;
    background: rgba(255, 255, 255, 0.75);
    line-height: 1.4;
}

.book-agent-find-quote,
.book-agent-find-note,
.book-agent-speak-quote,
.book-agent-speak-note {
    white-space: pre-wrap;
    word-break: break-word;
}

.book-agent-find-note,
.book-agent-speak-note {
    margin-top: 4px;
    color: #526173;
}

.book-agent-creating {
    display: block;
    margin-top: 6px;
    font-weight: 500;
}

.book-agent-creating-text {
    color: transparent;
    background: linear-gradient(90deg, #64748b 0%, #64748b 38%, #ffffff 50%, #64748b 62%, #64748b 100%);
    background-size: 220% 100%;
    -webkit-background-clip: text;
    background-clip: text;
    animation: book-agent-spotlight 0.65s linear infinite;
}

.book-agent-creating-lines {
    color: #64748b;
    font-weight: 400;
}

@keyframes book-agent-spotlight {
    100% {
        background-position: -220% 0;
    }
}

.book-agent-input {
    padding: 12px;
    border-top: 1px solid #e3e7ee;
    background: #fafbfc;
}

.book-agent-input-row {
    display: flex;
    gap: 8px;
}

#bookAgentInput {
    flex: 1;
}

.dark-theme .ai-toggle-btn:hover {
    border-color: #3c4858;
    background: #1f2937;
}

.dark-theme .ai-toggle-btn.active {
    border-color: #4b6588;
    background: #1d2a3a;
}

.dark-theme .book-agent-find-nav,
.dark-theme .book-agent-speak-nav {
    border-top-color: rgba(255, 255, 255, 0.12);
}

.dark-theme .book-agent-find-prev,
.dark-theme .book-agent-find-next,
.dark-theme .book-agent-speak-prev,
.dark-theme .book-agent-speak-next {
    border-color: #3c4858;
    background: #1f2937;
    color: #dbeafe;
}

.dark-theme .book-agent-find-detail,
.dark-theme .book-agent-speak-detail {
    border-color: rgba(96, 165, 250, 0.35);
    background: rgba(15, 23, 42, 0.55);
}

.dark-theme .book-agent-find-note,
.dark-theme .book-agent-speak-note {
    color: #b8c3d3;
}

.dark-theme .ai-toggle-brand,
.dark-theme .ai-toggle-btn.active .ai-toggle-brand {
    color: #dbeafe;
}

.dark-theme #bookAgentPanel.book-agent-panel {
    background: #111827;
    border-left-color: #374151;
    box-shadow: -8px 0 20px rgba(0, 0, 0, 0.35);
    color: #e5e7eb;
}

.dark-theme #bookAgentPanel.book-agent-panel.collapsed {
    background: linear-gradient(165deg, #111827 0%, #1f2937 52%, #111827 100%);
    border-left-color: #374151;
}

.dark-theme #bookAgentPanel.book-agent-panel.collapsed::before {
    color: #bfdbfe;
}

.dark-theme .book-agent-header,
.dark-theme .book-agent-input {
    background: #172033;
    border-color: #374151;
}

.dark-theme .book-agent-title {
    color: #f3f4f6;
}

.dark-theme .book-agent-tabs,
.dark-theme .book-agent-w2tabs {
    background: #111827;
    border-color: #374151;
}

.dark-theme .book-agent-w2tabs .w2ui-tabs-line {
    border-bottom: 1px solid #374151 !important;
}

.dark-theme .book-agent-w2tabs .w2ui-scroll-wrapper {
    background: #111827;
}

.dark-theme .book-agent-w2tabs .w2ui-tab,
.dark-theme .book-agent-w2tabs .w2ui-scroll-wrapper .w2ui-tab {
    background: #111827 !important;
    border-color: transparent !important;
    border-bottom: 2px solid transparent !important;
    color: #cbd5e1;
}

.dark-theme .book-agent-w2tabs .w2ui-tab:hover,
.dark-theme .book-agent-w2tabs .w2ui-scroll-wrapper .w2ui-tab:hover {
    background: #1f2937 !important;
    border-color: transparent !important;
    border-bottom-color: transparent !important;
    color: #f3f4f6;
}

.dark-theme .book-agent-w2tabs .w2ui-tab.active,
.dark-theme .book-agent-w2tabs .w2ui-scroll-wrapper .w2ui-tab.active {
    background: #172033 !important;
    border-color: transparent !important;
    border-bottom: 2px solid #60a5fa !important;
}

.dark-theme .book-agent-w2tabs .w2ui-tab-text {
    color: #9ca3af !important;
}

.dark-theme .book-agent-w2tabs .w2ui-tab.active .w2ui-tab-text,
.dark-theme .book-agent-w2tabs .w2ui-scroll-wrapper .w2ui-tab.active .w2ui-tab-text,
.dark-theme .book-agent-w2tabs .w2ui-tab.active .w2ui-tab-text *,
.dark-theme .book-agent-w2tabs .w2ui-scroll-wrapper .w2ui-tab.active .w2ui-tab-text * {
    color: #f9fafb !important;
}

.dark-theme .book-agent-w2tabs .w2ui-tab .w2ui-tab-close,
.dark-theme .book-agent-w2tabs .w2ui-scroll-wrapper .w2ui-tab .w2ui-tab-close {
    color: #9ca3af !important;
}

.dark-theme .book-agent-w2tabs .w2ui-tab .w2ui-tab-close:hover,
.dark-theme .book-agent-w2tabs .w2ui-scroll-wrapper .w2ui-tab .w2ui-tab-close:hover {
    background: #374151 !important;
    color: #f3f4f6 !important;
}

.dark-theme .book-agent-messages {
    background: #0f172a;
}

.dark-theme .book-agent-empty,
.dark-theme .book-agent-thinking-wait,
.dark-theme .book-agent-creating-lines {
    color: #9ca3af;
}

.dark-theme .book-agent-empty-help a,
.dark-theme .book-agent-message.ai-message .book-agent-link,
.dark-theme .book-agent-message.ai-message .book-agent-link.active {
    color: #93c5fd;
}

.dark-theme .book-agent-empty-help a:hover,
.dark-theme .book-agent-empty-help a:focus,
.dark-theme .book-agent-message.ai-message .book-agent-link:hover,
.dark-theme .book-agent-message.ai-message .book-agent-link:focus {
    color: #bfdbfe;
}

.dark-theme .book-agent-message.user-message {
    background: #102a43;
    border-left-color: #60a5fa;
    color: #e5e7eb;
}

.dark-theme .ai-text-selection-highlight {
    background: rgba(250, 204, 21, 0.28);
    border-top-color: #facc15;
    border-bottom-color: #facc15;
}

.dark-theme #contentBody .book-agent-find-highlight {
    background-color: rgba(252, 211, 77, 0.38);
    border-bottom-color: #f59e0b;
}

.dark-theme .book-agent-user-selection-label {
    color: #cbd5e1;
}

.dark-theme .book-agent-user-excerpt {
    background: rgba(15, 23, 42, 0.65);
    border-color: rgba(96, 165, 250, 0.45);
    color: #f3f4f6;
}

.dark-theme .book-agent-user-excerpt-more {
    color: #93c5fd;
}

.dark-theme .book-agent-message.ai-message {
    background: #241b3a;
    border-left-color: #a78bfa;
    color: #f3f4f6;
}

.dark-theme .book-agent-message.ai-message .message-content,
.dark-theme .book-agent-message.ai-message .message-content p,
.dark-theme .book-agent-message.ai-message .message-content ul,
.dark-theme .book-agent-message.ai-message .message-content ol,
.dark-theme .book-agent-message.ai-message .message-content li,
.dark-theme .book-agent-message.ai-message .message-content strong,
.dark-theme .book-agent-message.ai-message .message-content em,
.dark-theme .book-agent-message.ai-message .message-content h1,
.dark-theme .book-agent-message.ai-message .message-content h2,
.dark-theme .book-agent-message.ai-message .message-content h3,
.dark-theme .book-agent-message.ai-message .message-content h4,
.dark-theme .book-agent-message.ai-message .message-content h5,
.dark-theme .book-agent-message.ai-message .message-content h6 {
    color: inherit;
}

.dark-theme .book-agent-creating-text {
    background-image: linear-gradient(90deg, #9ca3af 0%, #9ca3af 38%, #f9fafb 50%, #9ca3af 62%, #9ca3af 100%);
}

.dark-theme #bookAgentInput.form-control {
    background: #0f172a;
    border-color: #374151;
    color: #f3f4f6;
}

.dark-theme #bookAgentInput.form-control::placeholder {
    color: #9ca3af;
}

.dark-theme #bookAgentInput.form-control:focus {
    border-color: #60a5fa;
    box-shadow: 0 0 0 1px rgba(96, 165, 250, 0.45);
}

body.book-agent-open .book-header .container,
body.book-agent-open .book-container .container {
    margin-left: 0;
    margin-right: auto;
}

body.book-agent-open.book-agent-collapsed .book-header .container,
body.book-agent-open.book-agent-collapsed .book-container .container {
    margin-left: auto;
    margin-right: auto;
}

@media (max-width: 991.98px) {
    body.book-agent-open .book-header .container,
    body.book-agent-open .book-container .container,
    body.book-agent-open.book-agent-collapsed .book-header .container,
    body.book-agent-open.book-agent-collapsed .book-container .container {
        margin-left: 0;
        margin-right: 0;
    }
}

@media (max-width: 575.98px) {
    #bookAgentPanel.book-agent-panel {
        left: auto;
        right: 0;
        display: flex;
        width: 100vw !important;
        visibility: hidden;
        pointer-events: none;
        transform: translateX(100%);
        border-left: none;
    }

    #bookAgentPanel.book-agent-panel.open {
        width: 100vw !important;
        visibility: visible;
        pointer-events: auto;
        transform: translateX(0);
    }

    #bookAgentPanel.book-agent-panel.collapsed,
    #bookAgentPanel.book-agent-panel.collapsed.expanded {
        cursor: default;
    }

    #bookAgentPanel.book-agent-panel.collapsed::before {
        display: none;
    }

    #bookAgentPanel.book-agent-panel.collapsed .book-agent-header,
    #bookAgentPanel.book-agent-panel.collapsed .book-agent-tabs,
    #bookAgentPanel.book-agent-panel.collapsed .book-agent-messages,
    #bookAgentPanel.book-agent-panel.collapsed .book-agent-input {
        visibility: visible;
    }

    body.book-agent-open .book-header .container,
    body.book-agent-open .book-container .container {
        margin-left: auto;
        margin-right: auto;
    }
}
