/* ========================================
   VIP Article AI Reading Companion
   Left trigger + left slide drawer + inline h2 triggers
   ======================================== */

.vip-ai-trigger {
    position: fixed;
    left: 20px;
    top: 136px;
    z-index: 900;
    display: inline-flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 4px;
    max-width: 176px;
    padding: 12px 14px;
    border-radius: 14px;
    border: 1px solid rgba(99, 102, 241, 0.24);
    background: linear-gradient(145deg, rgba(255, 255, 255, 0.96), rgba(248, 250, 252, 0.96));
    color: #0f172a;
    box-shadow: 0 10px 28px rgba(15, 23, 42, 0.10), 0 1px 3px rgba(99, 102, 241, 0.12);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    cursor: pointer;
    text-align: left;
    transition: transform 0.2s ease, box-shadow 0.2s ease, border-color 0.2s ease;
    user-select: none;
}

.vip-ai-trigger:hover {
    transform: translateY(-2px);
    border-color: rgba(99, 102, 241, 0.55);
    box-shadow: 0 14px 32px rgba(79, 70, 229, 0.18);
}

.vip-ai-trigger-top {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    font-size: 14px;
    font-weight: 700;
    line-height: 1.25;
}

.vip-ai-trigger-icon {
    width: 24px;
    height: 24px;
    border-radius: 8px;
    background: linear-gradient(135deg, #4f46e5, #7c3aed);
    color: #fff;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex: 0 0 24px;
}

.vip-ai-trigger-sub {
    font-size: 11.5px;
    line-height: 1.35;
    color: #475569;
}

.vip-ai-trigger-vip {
    display: inline-flex;
    align-items: center;
    padding: 1px 6px;
    border-radius: 999px;
    font-size: 10px;
    font-weight: 700;
    letter-spacing: 0.04em;
    background: rgba(245, 158, 11, 0.16);
    color: #b45309;
}

@media (max-width: 1320px) {
    .vip-ai-trigger {
        top: auto;
        bottom: 24px;
        left: 16px;
        flex-direction: row;
        align-items: center;
        gap: 8px;
        max-width: none;
        padding: 10px 14px;
        border-radius: 999px;
    }
    .vip-ai-trigger-sub {
        display: none;
    }
}

@media (max-width: 768px) {
    .vip-ai-trigger {
        bottom: 84px;
        left: 14px;
        padding: 9px 13px;
    }
}

/* Inline section ask button inside #articleContent h2 */
.vip-ai-sec-btn {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    margin-left: 10px;
    padding: 3px 9px;
    border-radius: 999px;
    border: 1px solid rgba(99, 102, 241, 0.28);
    background: rgba(99, 102, 241, 0.08);
    color: #4338ca;
    font-size: 12px;
    font-weight: 600;
    line-height: 1.4;
    vertical-align: middle;
    cursor: pointer;
    user-select: none;
    transition: background-color 0.15s ease, border-color 0.15s ease, transform 0.15s ease;
}

.vip-ai-sec-btn:hover {
    background: rgba(79, 70, 229, 0.16);
    border-color: rgba(79, 70, 229, 0.55);
    transform: translateY(-1px);
}

/* Backdrop & Drawer */
.vip-ai-backdrop {
    position: fixed;
    inset: 0;
    z-index: 1190;
    background: rgba(15, 23, 42, 0.36);
    backdrop-filter: blur(2px);
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.22s ease;
}

.vip-ai-backdrop.is-open {
    opacity: 1;
    pointer-events: auto;
}

.vip-ai-drawer {
    position: fixed;
    left: 0;
    top: 0;
    bottom: 0;
    width: 416px;
    max-width: 92vw;
    z-index: 1200;
    display: flex;
    flex-direction: column;
    background: #ffffff;
    color: #0f172a;
    border-right: 1px solid #e2e8f0;
    box-shadow: 12px 0 40px rgba(15, 23, 42, 0.16);
    transform: translateX(-100%);
    transition: transform 0.24s cubic-bezier(0.22, 1, 0.36, 1);
    user-select: text;
    -webkit-user-select: text;
}

.vip-ai-drawer.is-open {
    transform: translateX(0);
}

@media (max-width: 768px) {
    .vip-ai-drawer {
        top: auto;
        right: 0;
        width: 100%;
        max-width: 100%;
        height: 82vh;
        max-height: 82vh;
        border-right: none;
        border-top: 1px solid #e2e8f0;
        border-radius: 16px 16px 0 0;
        box-shadow: 0 -10px 36px rgba(15, 23, 42, 0.22);
        transform: translateY(100%);
    }
    .vip-ai-drawer.is-open {
        transform: translateY(0);
    }
}

/* Header */
.vip-ai-header {
    padding: 14px 16px;
    border-bottom: 1px solid #e2e8f0;
    display: flex;
    flex-direction: column;
    gap: 8px;
    background: linear-gradient(180deg, rgba(99, 102, 241, 0.06), rgba(99, 102, 241, 0));
}

.vip-ai-header-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
}

.vip-ai-title-wrap {
    display: flex;
    align-items: center;
    gap: 9px;
    min-width: 0;
}

.vip-ai-title {
    margin: 0;
    font-size: 15.5px;
    font-weight: 700;
    color: #0f172a;
}

.vip-ai-header-actions {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    flex-shrink: 0;
}

.vip-ai-icon-btn {
    height: 30px;
    padding: 0 9px;
    border-radius: 8px;
    border: 1px solid #e2e8f0;
    background: #f8fafc;
    color: #475569;
    font-size: 12px;
    font-weight: 500;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    gap: 4px;
    transition: background-color 0.15s ease, color 0.15s ease;
}

.vip-ai-icon-btn:hover {
    background: #eef2ff;
    color: #4338ca;
}

.vip-ai-meta-bar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    font-size: 12px;
    color: #64748b;
}

.vip-ai-quota-pill {
    display: inline-flex;
    align-items: center;
    padding: 2px 8px;
    border-radius: 999px;
    background: #f1f5f9;
    color: #334155;
    font-weight: 600;
    font-size: 11.5px;
    white-space: nowrap;
}

/* Focused section bar */
.vip-ai-context-bar {
    display: none;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    padding: 8px 16px;
    background: rgba(79, 70, 229, 0.07);
    border-bottom: 1px solid rgba(99, 102, 241, 0.16);
    font-size: 12.5px;
    color: #3730a3;
}

.vip-ai-context-bar.is-active {
    display: flex;
}

.vip-ai-context-text {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    font-weight: 600;
}

.vip-ai-context-clear {
    border: none;
    background: transparent;
    color: inherit;
    cursor: pointer;
    font-size: 14px;
    line-height: 1;
    padding: 2px 5px;
    border-radius: 4px;
}

.vip-ai-context-clear:hover {
    background: rgba(79, 70, 229, 0.12);
}

/* Messages area */
.vip-ai-messages {
    flex: 1 1 auto;
    overflow-y: auto;
    padding: 14px 16px;
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.vip-ai-welcome {
    padding: 12px 14px;
    border-radius: 12px;
    background: #f8fafc;
    border: 1px solid #e2e8f0;
    font-size: 13px;
    line-height: 1.55;
    color: #334155;
}

.vip-ai-chips {
    display: flex;
    flex-direction: column;
    gap: 7px;
    margin-top: 10px;
}

.vip-ai-chip {
    text-align: left;
    padding: 8px 11px;
    border-radius: 10px;
    border: 1px solid #dbeafe;
    background: #ffffff;
    color: #1e3a8a;
    font-size: 12.5px;
    line-height: 1.4;
    cursor: pointer;
    transition: background-color 0.15s ease, border-color 0.15s ease;
}

.vip-ai-chip:hover {
    background: #eff6ff;
    border-color: #93c5fd;
}

.vip-ai-msg {
    display: flex;
    flex-direction: column;
    max-width: 92%;
}

.vip-ai-msg-user {
    align-self: flex-end;
    background: linear-gradient(135deg, #4f46e5, #6366f1);
    color: #ffffff;
    padding: 9px 13px;
    border-radius: 14px 14px 4px 14px;
    font-size: 13.5px;
    line-height: 1.5;
    word-break: break-word;
    white-space: pre-wrap;
}

.vip-ai-msg-sec-tag {
    display: inline-block;
    font-size: 11px;
    opacity: 0.88;
    margin-bottom: 4px;
    padding-bottom: 4px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.25);
}

.vip-ai-msg-bot {
    align-self: flex-start;
    background: #f8fafc;
    color: #0f172a;
    border: 1px solid #e2e8f0;
    padding: 10px 13px;
    border-radius: 14px 14px 14px 4px;
    font-size: 13.5px;
    line-height: 1.6;
    word-break: break-word;
    overflow-wrap: anywhere;
}

.vip-ai-msg-bot.is-error {
    background: #fef2f2;
    border-color: #fecaca;
    color: #991b1b;
}

.vip-ai-msg-bot p { margin: 0 0 8px; }
.vip-ai-msg-bot p:last-child { margin-bottom: 0; }
.vip-ai-msg-bot ul, .vip-ai-msg-bot ol { margin: 4px 0 8px; padding-left: 18px; }
.vip-ai-msg-bot li { margin: 3px 0; }
.vip-ai-msg-bot pre {
    margin: 6px 0;
    padding: 8px 10px;
    border-radius: 8px;
    background: #0f172a;
    color: #f8fafc;
    font-size: 12px;
    overflow-x: auto;
}
.vip-ai-msg-bot code {
    font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
    font-size: 0.9em;
    padding: 1px 4px;
    border-radius: 4px;
    background: rgba(15, 23, 42, 0.08);
}
.vip-ai-msg-bot pre code {
    background: transparent;
    padding: 0;
}
.vip-ai-msg-bot table {
    width: 100%;
    border-collapse: collapse;
    margin: 6px 0;
    font-size: 12px;
    display: block;
    overflow-x: auto;
}
.vip-ai-msg-bot th, .vip-ai-msg-bot td {
    border: 1px solid #cbd5e1;
    padding: 4px 7px;
    text-align: left;
}

.vip-ai-cursor {
    display: inline-block;
    width: 7px;
    height: 14px;
    margin-left: 3px;
    vertical-align: text-bottom;
    background: #6366f1;
    animation: vipAiBlink 0.9s steps(1) infinite;
}

@keyframes vipAiBlink {
    0%, 50% { opacity: 1; }
    51%, 100% { opacity: 0; }
}

/* Footer composer */
.vip-ai-footer {
    padding: 10px 14px 14px;
    border-top: 1px solid #e2e8f0;
    background: #ffffff;
}

.vip-ai-input-wrap {
    display: flex;
    flex-direction: column;
    gap: 8px;
    border: 1px solid #cbd5e1;
    border-radius: 12px;
    padding: 8px 10px;
    background: #ffffff;
    transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.vip-ai-input-wrap:focus-within {
    border-color: #6366f1;
    box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.14);
}

.vip-ai-textarea {
    width: 100%;
    border: none;
    outline: none;
    resize: none;
    background: transparent;
    color: #0f172a;
    font-size: 13.5px;
    line-height: 1.45;
    max-height: 110px;
    min-height: 38px;
    font-family: inherit;
}

.vip-ai-composer-bar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
}

.vip-ai-char-count {
    font-size: 11.5px;
    color: #64748b;
}

.vip-ai-send-btn {
    padding: 6px 14px;
    border: none;
    border-radius: 8px;
    background: linear-gradient(135deg, #4f46e5, #6366f1);
    color: #ffffff;
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    transition: opacity 0.15s ease, transform 0.15s ease;
}

.vip-ai-send-btn:disabled {
    opacity: 0.45;
    cursor: not-allowed;
}

.vip-ai-send-btn.is-stop {
    background: #dc2626;
}

/* ========================================
   Dark Theme Overrides
   ======================================== */
html[data-theme="dark"] .vip-ai-trigger,
html.dark .vip-ai-trigger {
    background: linear-gradient(145deg, rgba(30, 41, 59, 0.96), rgba(15, 23, 42, 0.96));
    border-color: rgba(129, 140, 248, 0.34);
    color: #f1f5f9;
    box-shadow: 0 12px 30px rgba(0, 0, 0, 0.42);
}

html[data-theme="dark"] .vip-ai-trigger-sub,
html.dark .vip-ai-trigger-sub {
    color: #cbd5e1;
}

html[data-theme="dark"] .vip-ai-trigger-vip,
html.dark .vip-ai-trigger-vip {
    background: rgba(251, 191, 36, 0.18);
    color: #fbbf24;
}

html[data-theme="dark"] .vip-ai-sec-btn,
html.dark .vip-ai-sec-btn {
    background: rgba(129, 140, 248, 0.16);
    border-color: rgba(129, 140, 248, 0.38);
    color: #c7d2fe;
}

html[data-theme="dark"] .vip-ai-sec-btn:hover,
html.dark .vip-ai-sec-btn:hover {
    background: rgba(129, 140, 248, 0.28);
}

html[data-theme="dark"] .vip-ai-drawer,
html.dark .vip-ai-drawer {
    background: #0f172a;
    color: #e2e8f0;
    border-color: #334155;
    box-shadow: 12px 0 42px rgba(0, 0, 0, 0.55);
}

html[data-theme="dark"] .vip-ai-header,
html.dark .vip-ai-header,
html[data-theme="dark"] .vip-ai-footer,
html.dark .vip-ai-footer {
    background: #0f172a;
    border-color: #1e293b;
}

html[data-theme="dark"] .vip-ai-title,
html.dark .vip-ai-title {
    color: #f8fafc;
}

html[data-theme="dark"] .vip-ai-meta-bar,
html[data-theme="dark"] .vip-ai-char-count,
html.dark .vip-ai-meta-bar,
html.dark .vip-ai-char-count {
    color: #94a3b8;
}

html[data-theme="dark"] .vip-ai-icon-btn,
html.dark .vip-ai-icon-btn {
    background: #1e293b;
    border-color: #334155;
    color: #cbd5e1;
}

html[data-theme="dark"] .vip-ai-icon-btn:hover,
html.dark .vip-ai-icon-btn:hover {
    background: #312e81;
    color: #e0e7ff;
}

html[data-theme="dark"] .vip-ai-quota-pill,
html.dark .vip-ai-quota-pill {
    background: #1e293b;
    color: #cbd5e1;
}

html[data-theme="dark"] .vip-ai-context-bar,
html.dark .vip-ai-context-bar {
    background: rgba(99, 102, 241, 0.16);
    border-color: rgba(129, 140, 248, 0.28);
    color: #c7d2fe;
}

html[data-theme="dark"] .vip-ai-welcome,
html[data-theme="dark"] .vip-ai-msg-bot,
html.dark .vip-ai-welcome,
html.dark .vip-ai-msg-bot {
    background: #1e293b;
    border-color: #334155;
    color: #e2e8f0;
}

html[data-theme="dark"] .vip-ai-msg-bot.is-error,
html.dark .vip-ai-msg-bot.is-error {
    background: rgba(127, 29, 29, 0.38);
    border-color: rgba(248, 113, 113, 0.42);
    color: #fecaca;
}

html[data-theme="dark"] .vip-ai-msg-bot code,
html.dark .vip-ai-msg-bot code {
    background: rgba(255, 255, 255, 0.1);
}

html[data-theme="dark"] .vip-ai-msg-bot th,
html[data-theme="dark"] .vip-ai-msg-bot td,
html.dark .vip-ai-msg-bot th,
html.dark .vip-ai-msg-bot td {
    border-color: #475569;
}

html[data-theme="dark"] .vip-ai-chip,
html.dark .vip-ai-chip {
    background: #0f172a;
    border-color: #334155;
    color: #93c5fd;
}

html[data-theme="dark"] .vip-ai-chip:hover,
html.dark .vip-ai-chip:hover {
    background: #1e293b;
    border-color: #60a5fa;
}

html[data-theme="dark"] .vip-ai-input-wrap,
html.dark .vip-ai-input-wrap {
    background: #1e293b;
    border-color: #334155;
}

html[data-theme="dark"] .vip-ai-textarea,
html.dark .vip-ai-textarea {
    color: #f8fafc;
}
