/**
 * Reader Tools — structural CSS only.
 * Loaded by CommonHead via ccel_add_css('reader-tools.css').
 *
 * Phase 1B: most visual styling moved to Bootstrap 4 utility classes
 * applied directly in resources/views/partials/reader-tools-*.blade.php and
 * in the JS template strings inside public/js/reader-tools/*.js. What remains
 * here is what Bootstrap 4 can't express:
 *   - off-canvas slide-in positioning (right: -500px → 0)
 *   - centered modal positioning (fixed + transform) and its flex column
 *   - keyframe animations (slideIn, modalSlideIn)
 *   - flex `gap` (Bootstrap 4 has no gap utility — Bootstrap 5 does)
 *   - !important overrides on citation links so they survive
 *     markdown-rendered link styling
 *   - reader-tools accent color (var(--ccel-red) from style.css), used
 *     instead of Bootstrap's bg-primary/text-primary so the UI matches
 *     the rest of the site rather than Bootstrap's default blue
 */

/* ----------------------------------------------------------------------------
 * Brand accent — pulls from --ccel-red defined in public/css/style.css.
 * Used by chatbot user bubbles and reader-tools modal headings.
 * ------------------------------------------------------------------------- */
.reader-tools-accent-bg {
    background-color: var(--ccel-red);
    color: #fff;
}

.reader-tools-accent-text {
    color: var(--ccel-red);
}

/* Bootstrap-style button using --ccel-red. Pair with the standard `.btn`
 * class so spacing/radius/focus-ring inherit from Bootstrap. Hover/active
 * shade is hardcoded a few stops darker than --ccel-red. */
.btn-reader-tools {
    background-color: var(--ccel-red);
    border-color: var(--ccel-red);
    color: #fff;
}

.btn-reader-tools:hover,
.btn-reader-tools:focus,
.btn-reader-tools:active,
.btn-reader-tools:not(:disabled):not(.disabled):active {
    background-color: #5d1717;
    border-color: #5d1717;
    color: #fff;
}

.btn-reader-tools:focus {
    box-shadow: 0 0 0 0.2rem rgba(122, 31, 31, 0.35);
}

/* Override Bootstrap's default blue focus ring on the chatbot input so it
 * matches the rest of the reader-tools palette. Paired with class
 * `reader-tools-input` on the input element. */
.reader-tools-input:focus {
    border-color: var(--ccel-red);
    box-shadow: 0 0 0 0.2rem rgba(122, 31, 31, 0.25);
}

/* ----------------------------------------------------------------------------
 * Sliding sidebar (off-canvas right)
 * ------------------------------------------------------------------------- */
.reader-tools-sidebar {
    position: fixed;
    top: 0;
    right: -500px;
    width: 500px;
    height: 100vh;
    z-index: 8000;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    transition: right 0.4s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.reader-tools-sidebar.active {
    right: 0;
}

/* Bootstrap 4 has no `gap` utility; reproduce it for the chat stream. */
.reader-tools-chat-messages {
    gap: 12px;
}

/* ----------------------------------------------------------------------------
 * Chat messages: slide-in animation + base layout
 * (background / color / padding are utility classes in addChatMessage)
 * ------------------------------------------------------------------------- */
.chat-message {
    max-width: 95%;
    font-size: 14px;
    line-height: 1.6;
    word-wrap: break-word;
    animation: slideIn 0.3s ease-out;
}

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

/* ----------------------------------------------------------------------------
 * markdownToHtml output, in both the chat bubbles and the result modal.
 * Bootstrap's heading sizes are meant for page copy — h2 is 2rem against 14px
 * body text. Scaled here rather than in the renderer so the markup stays
 * semantic whichever heading level the model emits.
 * ------------------------------------------------------------------------- */
.chat-content h2,
.reader-tools-output-content h2 { font-size: 1.2rem; }

.chat-content h3,
.reader-tools-output-content h3 { font-size: 1.1rem; }

.chat-content h4,
.reader-tools-output-content h4 { font-size: 1rem; }

.chat-content h2,
.chat-content h3,
.chat-content h4,
.reader-tools-output-content h2,
.reader-tools-output-content h3,
.reader-tools-output-content h4 {
    margin-bottom: 0.5rem;
}

/* Longhand rather than :is() to match this codebase's browser baseline. */
.chat-content > h2:not(:first-child),
.chat-content > h3:not(:first-child),
.chat-content > h4:not(:first-child),
.reader-tools-output-content > h2:not(:first-child),
.reader-tools-output-content > h3:not(:first-child),
.reader-tools-output-content > h4:not(:first-child) {
    margin-top: 1rem;
}

.chat-content ol,
.chat-content ul,
.reader-tools-output-content ol,
.reader-tools-output-content ul {
    padding-left: 1.5rem;
    margin-bottom: 0.75rem;
}

/* Citation links inside markdown-rendered AI responses. The !important is to
 * survive the bare <a> styling that markdownToHtml produces. */
.chat-citation-link {
    cursor: pointer !important;
    transition: color 0.2s;
}

.chat-citation-link:hover {
    color: var(--ccel-red) !important;
}

/* ----------------------------------------------------------------------------
 * Output modal (Explain / Modernize / Background result)
 * ------------------------------------------------------------------------- */
/* Flex column, and overflow deliberately not here: when the whole shell
 * scrolled, a long answer scrolled the close button out of view. Only
 * .reader-tools-output-content scrolls (flex-grow-1 overflow-auto in the Blade). */
.reader-tools-output-modal {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    z-index: 9500;
    display: none;
    flex-direction: column;
    max-width: 1000px;
    width: 90vw;
    max-height: 85vh;
    animation: modalSlideIn 0.3s ease-out;
}

.reader-tools-output-modal.active {
    display: flex;
}

@keyframes modalSlideIn {
    from { opacity: 0; transform: translate(-50%, -48%); }
    to   { opacity: 1; transform: translate(-50%, -50%); }
}

.reader-tools-output-modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.4);
    z-index: 9400;
    display: none;
}

.reader-tools-output-modal-overlay.active {
    display: block;
}

/* ----------------------------------------------------------------------------
 * Constrain Bootstrap's text-selection popover to a sensible width (it shares
 * markup with the AnnotationBar popover, which would otherwise grow when our
 * three buttons are present).
 * ------------------------------------------------------------------------- */
.selection-popup,
.popover {
    max-width: 300px !important;
    width: auto !important;
}
