/* ===================================================================
   ai-context-styles.css — Contextual AI Study Partner
   Self-contained styles. Does NOT modify shared/style.css.
   =================================================================== */

/* ─── Trigger Button (appears below each reading subsection) ────── */

.ai-context-trigger {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    margin-top: 18px;
    padding: 10px 20px;
    background: var(--accent, #7c3aed);
    color: #fff;
    border: none;
    border-radius: 8px;
    font-size: 13px;
    font-weight: 600;
    font-family: 'Source Sans 3', 'Segoe UI', sans-serif;
    cursor: pointer;
    transition: background 0.2s, transform 0.15s, box-shadow 0.2s;
    touch-action: manipulation;
    line-height: 1.4;
    box-shadow: 0 2px 8px rgba(124, 58, 237, 0.2);
}

.ai-context-trigger:hover {
    background: var(--accent-hover, #6d28d9);
    transform: translateY(-1px);
    box-shadow: 0 4px 14px rgba(124, 58, 237, 0.3);
}

.ai-context-trigger:active {
    transform: translateY(0);
}

.ai-context-trigger .ctx-icon {
    font-size: 16px;
    line-height: 1;
}

/* ─── Modal Backdrop ────────────────────────────────────────────── */

.ai-ctx-modal {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(15, 23, 42, 0.5);
    backdrop-filter: blur(3px);
    z-index: 10000;
    justify-content: center;
    align-items: center;
    animation: ctxFadeIn 0.2s ease-out;
}

.ai-ctx-modal.open {
    display: flex;
}

@keyframes ctxFadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

/* ─── Modal Box ─────────────────────────────────────────────────── */

.ai-ctx-box {
    background: var(--bg-card, #ffffff);
    border-radius: 16px;
    width: 520px;
    max-width: 94vw;
    max-height: 80vh;
    display: flex;
    flex-direction: column;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.25);
    animation: ctxSlideUp 0.25s ease-out;
    overflow: hidden;
}

@keyframes ctxSlideUp {
    from { opacity: 0; transform: translateY(20px) scale(0.97); }
    to { opacity: 1; transform: translateY(0) scale(1); }
}

/* ─── Header ────────────────────────────────────────────────────── */

.ai-ctx-header {
    display: flex;
    align-items: flex-start;
    gap: 12px;
    padding: 18px 20px 14px;
    border-bottom: 1px solid var(--divider, #e5e7eb);
    flex-shrink: 0;
}

.ai-ctx-header-icon {
    width: 36px;
    height: 36px;
    background: linear-gradient(135deg, #7c3aed, #a78bfa);
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 18px;
    flex-shrink: 0;
    color: #fff;
}

.ai-ctx-header-text {
    flex: 1;
    min-width: 0;
}

.ai-ctx-header-title {
    font-family: 'Orbitron', sans-serif;
    font-size: 13px;
    font-weight: 700;
    color: var(--text-dark, #1e293b);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: 2px;
}

.ai-ctx-header-topic {
    font-size: 13px;
    color: var(--text-mid, #64748b);
    line-height: 1.4;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.ai-ctx-header-close {
    width: 28px;
    height: 28px;
    background: var(--bg-subtle, #f1f5f9);
    border: none;
    border-radius: 8px;
    font-size: 16px;
    line-height: 1;
    color: var(--text-mid, #64748b);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: background 0.15s;
}

.ai-ctx-header-close:hover {
    background: var(--bg-hover, #e2e8f0);
    color: var(--text-dark, #1e293b);
}

/* ─── Context Badge (below header) ──────────────────────────────── */

.ai-ctx-context-badge {
    display: none;
    padding: 8px 20px;
    background: var(--bg-subtle, #f8fafc);
    border-bottom: 1px solid var(--divider, #e5e7eb);
    font-size: 12px;
    color: var(--text-mid, #64748b);
    font-weight: 500;
    flex-shrink: 0;
}

.ai-ctx-context-badge.visible {
    display: block;
}

/* ─── Messages ──────────────────────────────────────────────────── */

.ai-ctx-messages {
    flex: 1;
    overflow-y: auto;
    padding: 16px 20px;
    display: flex;
    flex-direction: column;
    gap: 12px;
    background: var(--bg-body, #f8fafc);
    min-height: 200px;
    max-height: 50vh;
}

.ctx-msg {
    max-width: 92%;
    padding: 12px 16px;
    border-radius: 12px;
    font-size: 14px;
    line-height: 1.6;
    animation: ctxMsgIn 0.2s ease-out;
}

@keyframes ctxMsgIn {
    from { opacity: 0; transform: translateY(6px); }
    to { opacity: 1; transform: translateY(0); }
}

/* System message */
.ctx-msg.ctx-system {
    align-self: center;
    background: var(--bg-subtle, #f1f5f9);
    color: var(--text-mid, #64748b);
    font-size: 13px;
    text-align: center;
    max-width: 100%;
    border-radius: 10px;
    border: 1px solid var(--divider, #e5e7eb);
}

.ctx-msg.ctx-system strong {
    color: var(--text-dark, #1e293b);
}

/* User message */
.ctx-msg.ctx-user {
    align-self: flex-end;
    background: var(--accent, #7c3aed);
    color: #fff;
    border-bottom-right-radius: 4px;
}

.ctx-user-label {
    font-size: 10px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    opacity: 0.7;
    margin-bottom: 4px;
}

.ctx-user-text {
    word-wrap: break-word;
}

/* Bot message */
.ctx-msg.ctx-bot {
    align-self: flex-start;
    background: var(--bg-card, #ffffff);
    color: var(--text-main, #334155);
    border: 1px solid var(--divider, #e5e7eb);
    border-bottom-left-radius: 4px;
    box-shadow: 0 1px 4px rgba(0, 0, 0, 0.04);
}

.ctx-bot-bubble p {
    margin: 0 0 8px;
}

.ctx-bot-bubble p:last-child {
    margin-bottom: 0;
}

.ctx-bot-bubble strong {
    color: var(--text-dark, #1e293b);
}

/* ─── Typing Indicator ──────────────────────────────────────────── */

.ai-ctx-typing {
    display: none;
    align-self: flex-start;
    padding: 12px 16px;
    background: var(--bg-card, #ffffff);
    border: 1px solid var(--divider, #e5e7eb);
    border-radius: 12px;
    border-bottom-left-radius: 4px;
    gap: 4px;
}

.ai-ctx-typing .ctx-dot {
    width: 7px;
    height: 7px;
    background: var(--text-mid, #94a3b8);
    border-radius: 50%;
    animation: ctxBounce 1.4s infinite ease-in-out both;
}

.ai-ctx-typing .ctx-dot:nth-child(1) { animation-delay: -0.32s; }
.ai-ctx-typing .ctx-dot:nth-child(2) { animation-delay: -0.16s; }
.ai-ctx-typing .ctx-dot:nth-child(3) { animation-delay: 0s; }

@keyframes ctxBounce {
    0%, 80%, 100% { transform: scale(0); }
    40% { transform: scale(1); }
}

/* ─── Input Area ────────────────────────────────────────────────── */

.ai-ctx-input-area {
    display: flex;
    gap: 8px;
    padding: 12px 20px 16px;
    border-top: 1px solid var(--divider, #e5e7eb);
    background: var(--bg-card, #ffffff);
    flex-shrink: 0;
}

.ai-ctx-input {
    flex: 1;
    padding: 10px 14px;
    border: 1.5px solid var(--divider, #d1d5db);
    border-radius: 10px;
    font-size: 14px;
    font-family: 'Source Sans 3', 'Segoe UI', sans-serif;
    color: var(--text-main, #334155);
    background: var(--bg-body, #f8fafc);
    outline: none;
    resize: none;
    line-height: 1.5;
    max-height: 120px;
    transition: border-color 0.2s;
}

.ai-ctx-input:focus {
    border-color: var(--accent, #7c3aed);
    background: var(--bg-card, #ffffff);
}

.ai-ctx-input::placeholder {
    color: var(--text-light, #94a3b8);
}

/* ─── Send Button ───────────────────────────────────────────────── */

.ai-ctx-send-btn {
    width: 42px;
    height: 42px;
    background: var(--accent, #7c3aed);
    color: #fff;
    border: none;
    border-radius: 10px;
    font-size: 16px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: background 0.2s, transform 0.15s;
    touch-action: manipulation;
}

.ai-ctx-send-btn:hover {
    background: var(--accent-hover, #6d28d9);
    transform: scale(1.05);
}

.ai-ctx-send-btn:active {
    transform: scale(0.95);
}

.ai-ctx-send-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    transform: none;
}

/* ─── Remaining Counter ─────────────────────────────────────────── */

.ai-ctx-remaining {
    padding: 0 20px 12px;
    font-size: 11px;
    color: var(--text-light, #94a3b8);
    text-align: right;
    flex-shrink: 0;
    background: var(--bg-card, #ffffff);
}

/* ─── Subscribe Overlay ─────────────────────────────────────────── */

.ai-ctx-sub-overlay {
    display: none;
    position: absolute;
    top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(15, 23, 42, 0.7);
    backdrop-filter: blur(4px);
    z-index: 10001;
    justify-content: center;
    align-items: center;
    border-radius: 16px;
}

.ai-ctx-sub-overlay.open {
    display: flex;
}

.ai-ctx-sub-box {
    background: var(--bg-card, #ffffff);
    border-radius: 16px;
    padding: 36px 28px 28px;
    max-width: 340px;
    width: 85%;
    text-align: center;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
    animation: ctxFadeIn 0.25s ease-out;
    position: relative;
}

.ai-ctx-sub-box .ctx-sub-icon {
    font-size: 40px;
    margin-bottom: 10px;
}

.ai-ctx-sub-box h3 {
    font-size: 18px;
    color: var(--text-dark, #1e293b);
    margin: 0 0 8px;
    font-family: 'Source Sans 3', sans-serif;
}

.ai-ctx-sub-box p {
    font-size: 13px;
    color: var(--text-mid, #64748b);
    line-height: 1.5;
    margin: 0 0 18px;
    font-family: 'Source Sans 3', sans-serif;
}

.ai-ctx-sub-btn {
    background: linear-gradient(135deg, #7c3aed, #a78bfa);
    color: #fff;
    border: none;
    border-radius: 8px;
    padding: 12px 28px;
    font-size: 14px;
    font-weight: 700;
    cursor: pointer;
    display: inline-block;
    font-family: 'Source Sans 3', sans-serif;
    margin-bottom: 8px;
    transition: opacity 0.2s;
}

.ai-ctx-sub-btn:hover {
    opacity: 0.9;
}

.ai-ctx-sub-close-btn {
    background: transparent;
    border: 1px solid var(--divider, #d1d5db);
    border-radius: 8px;
    padding: 10px 20px;
    font-size: 13px;
    font-weight: 600;
    color: var(--text-mid, #6b7280);
    cursor: pointer;
    font-family: 'Source Sans 3', sans-serif;
    display: block;
    margin: 0 auto;
    transition: background 0.15s;
}

.ai-ctx-sub-close-btn:hover {
    background: var(--bg-subtle, #f3f4f6);
}

/* ─── Responsive ────────────────────────────────────────────────── */

@media (max-width: 600px) {
    .ai-ctx-box {
        max-width: 100vw;
        max-height: 90vh;
        border-radius: 12px;
    }

    .ai-ctx-messages {
        max-height: 55vh;
        padding: 12px 14px;
    }

    .ai-ctx-header {
        padding: 14px 16px 10px;
    }

    .ai-ctx-input-area {
        padding: 10px 14px 14px;
    }
}

/* ─── Dark Mode Support ─────────────────────────────────────────── */

@media (prefers-color-scheme: dark) {
    .ai-ctx-box {
        background: var(--bg-card, #1e293b);
    }

    .ai-ctx-header {
        border-bottom-color: var(--divider, #334155);
    }

    .ai-ctx-header-title {
        color: var(--text-dark, #f1f5f9);
    }

    .ai-ctx-header-topic {
        color: var(--text-mid, #94a3b8);
    }

    .ai-ctx-header-close {
        background: var(--bg-subtle, #1e293b);
        color: var(--text-mid, #94a3b8);
    }

    .ai-ctx-header-close:hover {
        background: var(--bg-hover, #334155);
        color: var(--text-dark, #f1f5f9);
    }

    .ai-ctx-context-badge {
        background: var(--bg-subtle, #1e293b);
        border-bottom-color: var(--divider, #334155);
    }

    .ai-ctx-messages {
        background: var(--bg-body, #0f172a);
    }

    .ctx-msg.ctx-system {
        background: var(--bg-subtle, #1e293b);
        color: var(--text-mid, #94a3b8);
        border-color: var(--divider, #334155);
    }

    .ctx-msg.ctx-system strong {
        color: var(--text-dark, #f1f5f9);
    }

    .ctx-msg.ctx-bot {
        background: var(--bg-card, #1e293b);
        color: var(--text-main, #cbd5e1);
        border-color: var(--divider, #334155);
    }

    .ctx-bot-bubble strong {
        color: var(--text-dark, #f1f5f9);
    }

    .ai-ctx-typing {
        background: var(--bg-card, #1e293b);
        border-color: var(--divider, #334155);
    }

    .ai-ctx-input-area {
        background: var(--bg-card, #1e293b);
        border-top-color: var(--divider, #334155);
    }

    .ai-ctx-input {
        background: var(--bg-body, #0f172a);
        color: var(--text-main, #e2e8f0);
        border-color: var(--divider, #475569);
    }

    .ai-ctx-input:focus {
        border-color: var(--accent, #a78bfa);
        background: var(--bg-card, #1e293b);
    }

    .ai-ctx-remaining {
        background: var(--bg-card, #1e293b);
        color: var(--text-light, #64748b);
    }

    .ai-ctx-sub-box {
        background: var(--bg-card, #1e293b);
    }

    .ai-ctx-sub-box h3 {
        color: var(--text-dark, #f1f5f9);
    }

    .ai-ctx-sub-box p {
        color: var(--text-mid, #94a3b8);
    }

    .ai-ctx-sub-close-btn {
        border-color: var(--divider, #475569);
        color: var(--text-mid, #94a3b8);
    }

    .ai-ctx-sub-close-btn:hover {
        background: var(--bg-subtle, #334155);
    }
}

/* Manual dark mode class on body */
.dark-mode .ai-ctx-box {
    background: var(--bg-card, #1e293b);
}

.dark-mode .ai-ctx-header {
    border-bottom-color: var(--divider, #334155);
}

.dark-mode .ai-ctx-header-title {
    color: var(--text-dark, #f1f5f9);
}

.dark-mode .ai-ctx-header-topic {
    color: var(--text-mid, #94a3b8);
}

.dark-mode .ai-ctx-header-close {
    background: var(--bg-subtle, #1e293b);
    color: var(--text-mid, #94a3b8);
}

.dark-mode .ai-ctx-header-close:hover {
    background: var(--bg-hover, #334155);
    color: var(--text-dark, #f1f5f9);
}

.dark-mode .ai-ctx-context-badge {
    background: var(--bg-subtle, #1e293b);
    border-bottom-color: var(--divider, #334155);
}

.dark-mode .ai-ctx-messages {
    background: var(--bg-body, #0f172a);
}

.dark-mode .ctx-msg.ctx-system {
    background: var(--bg-subtle, #1e293b);
    color: var(--text-mid, #94a3b8);
    border-color: var(--divider, #334155);
}

.dark-mode .ctx-msg.ctx-system strong {
    color: var(--text-dark, #f1f5f9);
}

.dark-mode .ctx-msg.ctx-bot {
    background: var(--bg-card, #1e293b);
    color: var(--text-main, #cbd5e1);
    border-color: var(--divider, #334155);
}

.dark-mode .ctx-bot-bubble strong {
    color: var(--text-dark, #f1f5f9);
}

.dark-mode .ai-ctx-typing {
    background: var(--bg-card, #1e293b);
    border-color: var(--divider, #334155);
}

.dark-mode .ai-ctx-input-area {
    background: var(--bg-card, #1e293b);
    border-top-color: var(--divider, #334155);
}

.dark-mode .ai-ctx-input {
    background: var(--bg-body, #0f172a);
    color: var(--text-main, #e2e8f0);
    border-color: var(--divider, #475569);
}

.dark-mode .ai-ctx-input:focus {
    border-color: var(--accent, #a78bfa);
    background: var(--bg-card, #1e293b);
}

.dark-mode .ai-ctx-remaining {
    background: var(--bg-card, #1e293b);
    color: var(--text-light, #64748b);
}

.dark-mode .ai-ctx-sub-box {
    background: var(--bg-card, #1e293b);
}

.dark-mode .ai-ctx-sub-box h3 {
    color: var(--text-dark, #f1f5f9);
}

.dark-mode .ai-ctx-sub-box p {
    color: var(--text-mid, #94a3b8);
}

.dark-mode .ai-ctx-sub-close-btn {
    border-color: var(--divider, #475569);
    color: var(--text-mid, #94a3b8);
}

.dark-mode .ai-ctx-sub-close-btn:hover {
    background: var(--bg-subtle, #334155);
}
