/* Genie Chat Component — Shared CSS */

/* ========================================
   COMPONENT TOKENS - GENIE CHAT (AI Assistant)
   All values use design-token fallbacks so they adapt to dark theme automatically.
   ======================================== */
:root {
    --genie-bg: #ffffff;
    --genie-bg-alt: #f9fafb;
    --genie-surface: #ffffff;
    --genie-text: #1e293b;
    --genie-text-secondary: #64748b;

    --genie-header-bg: #0d9488;
    --genie-header-text: #ffffff;
    --genie-status-online: #22c55e;
    --genie-status-offline: #ef4444;
    --genie-status-slow: #f59e0b;

    --genie-user-bubble-bg: #0d9488;
    --genie-user-bubble-text: #ffffff;
    --genie-assistant-bubble-bg: #f1f5f9;
    --genie-assistant-bubble-text: #1e293b;

    --genie-input-bg: #ffffff;
    --genie-input-border: #e2e8f0;
    --genie-input-focus-ring: #0d9488;
    --genie-send-bg: #f97316;
    --genie-send-hover: #ea580c;

    --genie-streaming-dot: #14b8a6;
    --genie-selection-bg: color-mix(in srgb, #0d9488 12%, transparent);

    --genie-math-bg: #f9fafb;
    --genie-math-border: #e2e8f0;
    --genie-code-bg: #111827;
    --genie-code-text: #f9fafb;

    --genie-sidebar-bg: #ffffff;
    --genie-sidebar-width-expanded: 320px;
    --genie-sidebar-width-collapsed: 64px;
    --genie-sidebar-item-active-bg: #fff7ed;
    --genie-sidebar-item-active-text: #ea580c;
    --genie-sidebar-item-hover-bg: #f9fafb;
}

/* ========================================
   GENIE PAGE WRAPPER (role landing pages)
   ======================================== */
.genie-page {
    max-width: 1100px;
    margin: 0 auto;
    padding: 20px;
}

.genie-page-header {
    margin-bottom: 16px;
}

.genie-page-header h2 {
    display: flex;
    align-items: center;
    gap: 10px;
    color: var(--color-teal-600, #0f766e);
    font-size: 1.5rem;
    margin: 0 0 6px;
}

.genie-page-header p {
    color: var(--genie-text-secondary, #64748b);
    margin: 0;
    font-size: 0.95rem;
}

/* Display-mode math block wrapper (rendered by KaTeX via genie-streaming.js) */
.genie-math-block {
    display: flex;
    justify-content: center;
    margin: 12px 0;
    padding: 8px;
    overflow-x: auto;
    max-width: 100%;
}

.genie-math-block .katex-display {
    margin: 0;
}

/* ========================================
   STREAMING ANIMATIONS (typewriter, thinking, send pulse)
   ======================================== */

/* Typewriter cursor — blinks at the end of streaming text (ChatGPT-style) */
.genie-cursor {
    display: inline-block;
    width: 8px;
    height: 1.1em;
    margin-left: 2px;
    vertical-align: text-bottom;
    background: var(--genie-streaming-dot, var(--color-teal-500, #0d9488));
    animation: genie-cursor-blink 1s steps(2, start) infinite;
    border-radius: 1px;
}

@keyframes genie-cursor-blink {
    0%, 50% { opacity: 1; }
    50.01%, 100% { opacity: 0; }
}

/* "Thinking" indicator — three bouncing dots while waiting for first token */
.genie-thinking {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 6px 4px;
}

.genie-thinking-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--genie-streaming-dot, var(--color-teal-500, #0d9488));
    animation: genie-thinking-bounce 1.4s infinite ease-in-out both;
}

.genie-thinking-dot:nth-child(1) { animation-delay: -0.32s; }
.genie-thinking-dot:nth-child(2) { animation-delay: -0.16s; }
.genie-thinking-dot:nth-child(3) { animation-delay: 0s; }

@keyframes genie-thinking-bounce {
    0%, 80%, 100% { transform: scale(0.6); opacity: 0.4; }
    40% { transform: scale(1); opacity: 1; }
}

/* Robot icon gentle pulse while thinking */
.genie-thinking-icon {
    animation: genie-icon-pulse 1.4s infinite ease-in-out;
}

@keyframes genie-icon-pulse {
    0%, 100% { transform: scale(1); opacity: 0.85; }
    50% { transform: scale(1.12); opacity: 1; }
}

/* Send button pulse animation when sending */
.genie-send-btn.genie-sending {
    animation: genie-send-pulse 0.4s ease-out;
}

@keyframes genie-send-pulse {
    0% { transform: scale(1); }
    40% { transform: scale(0.85) rotate(-12deg); }
    100% { transform: scale(1) rotate(0); }
}

/* User bubble slide-in animation */
.genie-bubble.genie-user.genie-anim-in {
    animation: genie-slide-in 0.35s ease-out;
}

@keyframes genie-slide-in {
    from { opacity: 0; transform: translateY(10px); }
    to { opacity: 1; transform: translateY(0); }
}

/* Assistant bubble fade-in when it appears */
.genie-bubble.genie-assistant {
    animation: genie-fade-in 0.3s ease-out;
}

@keyframes genie-fade-in {
    from { opacity: 0; }
    to { opacity: 1; }
}

/* Typewriter toggle button in the header */
.genie-toggle-btn {
    background: transparent;
    color: var(--genie-text-secondary, var(--color-text-secondary, #64748b));
    border: 1px solid transparent;
    width: 32px;
    height: 32px;
    border-radius: 8px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s, color 0.2s, border-color 0.2s;
}

.genie-toggle-btn:hover {
    background: var(--color-gray-100, #f1f5f9);
    color: var(--genie-input-focus-ring, var(--color-teal-500, #0d9488));
}

.genie-toggle-btn.active {
    color: var(--genie-input-focus-ring, var(--color-teal-500, #0d9488));
    border-color: color-mix(in srgb, var(--genie-input-focus-ring, #0d9488) 40%, transparent);
    background: color-mix(in srgb, var(--genie-input-focus-ring, #0d9488) 10%, transparent);
}

/* Markdown table styling inside chat bubbles (for cheat sheets, question lists) */
.genie-bubble-content table {
    width: 100%;
    border-collapse: collapse;
    margin: 10px 0;
    font-size: 0.92rem;
}

.genie-bubble-content th,
.genie-bubble-content td {
    border: 1px solid var(--genie-input-border, var(--color-border, #e2e8f0));
    padding: 8px 10px;
    text-align: left;
}

.genie-bubble-content th {
    background: var(--genie-bg-alt, var(--color-gray-50, #f9fafb));
    font-weight: 600;
}

.genie-bubble-content td:nth-child(2) {
    text-align: right;
    font-variant-numeric: tabular-nums;
}

/* Blockquote (used for answer lines under questions) */
.genie-bubble-content blockquote {
    margin: 6px 0;
    padding: 6px 12px;
    border-left: 3px solid var(--genie-input-focus-ring, var(--color-teal-500, #0d9488));
    background: color-mix(in srgb, var(--genie-input-focus-ring, #0d9488) 6%, transparent);
    border-radius: 0 6px 6px 0;
    color: var(--genie-text, var(--color-text, #1e293b));
}

.genie-bubble-content blockquote strong {
    color: var(--genie-input-focus-ring, var(--color-teal-600, #0f766e));
}

/* Code blocks inside chat */
.genie-bubble-content pre {
    background: var(--genie-code-bg, #111827);
    color: var(--genie-code-text, #f9fafb);
    padding: 12px;
    border-radius: 8px;
    overflow-x: auto;
    margin: 10px 0;
    font-size: 0.88rem;
}

.genie-bubble-content code {
    background: var(--genie-bg-alt, var(--color-gray-100, #f1f5f9));
    padding: 2px 5px;
    border-radius: 4px;
    font-size: 0.88rem;
}

.genie-bubble-content pre code {
    background: transparent;
    padding: 0;
}

/* ========================================
   GENIE CONTEXT SELECTOR (role-aware class/subject/chapter)
   The panel is an absolute-positioned overlay so it floats above the messages
   area without overlapping or squishing the flex layout.
   ======================================== */
.genie-sel-panel {
    max-height: 70vh;
    overflow-y: auto;
    border: 1px solid var(--genie-input-border, var(--color-border, #e2e8f0));
    border-radius: 0 0 10px 10px;
    background: var(--genie-surface, #fff);
    box-shadow: 0 8px 24px rgba(0,0,0,0.15);
    animation: genie-slide-down 0.2s ease-out;
}

@keyframes genie-slide-down {
    from { opacity: 0; transform: translateY(-8px); }
    to { opacity: 1; transform: translateY(0); }
}

.genie-sel-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 14px;
    background: var(--genie-header-bg, var(--color-teal-600, #0d9488));
    color: var(--genie-header-text, #fff);
    font-weight: 600;
    font-size: 0.9rem;
}

.genie-sel-close {
    background: transparent;
    border: none;
    color: #fff;
    cursor: pointer;
    font-size: 1rem;
    padding: 2px 6px;
    border-radius: 4px;
}

.genie-sel-close:hover { background: rgba(255,255,255,0.2); }

.genie-sel-body {
    padding: 14px;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.genie-sel-loading {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 16px;
    color: var(--genie-text-secondary, #64748b);
    font-size: 0.9rem;
}

.genie-sel-spinner {
    width: 16px;
    height: 16px;
    border: 2px solid var(--color-gray-300, #cbd5e1);
    border-top-color: var(--genie-header-bg, #0d9488);
    border-radius: 50%;
    animation: genie-spin 0.6s linear infinite;
}

@keyframes genie-spin { to { transform: rotate(360deg); } }

.genie-sel-label {
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--genie-text-secondary, #64748b);
    margin-bottom: -4px;
}

.genie-sel-optional {
    font-weight: 400;
    color: var(--color-gray-400, #94a3b8);
    font-size: 0.75rem;
}

.genie-sel-dropdown {
    width: 100%;
    padding: 8px 10px;
    border: 1px solid var(--genie-input-border, #e2e8f0);
    border-radius: 8px;
    background: var(--genie-input-bg, #fff);
    font-size: 0.9rem;
    cursor: pointer;
    outline: none;
    transition: border-color 0.2s;
}

.genie-sel-dropdown:focus {
    border-color: var(--genie-input-focus-ring, #0d9488);
    box-shadow: 0 0 0 3px color-mix(in srgb, var(--genie-input-focus-ring, #0d9488) 15%, transparent);
}

.genie-sel-chapters {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    max-height: 200px;
    overflow-y: auto;
    padding: 6px;
    border: 1px solid var(--genie-input-border, #e2e8f0);
    border-radius: 8px;
    background: var(--genie-bg-alt, #f9fafb);
}

.genie-sel-chip {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 6px 12px;
    border: 1px solid var(--genie-input-border, #e2e8f0);
    border-radius: 18px;
    font-size: 0.82rem;
    cursor: pointer;
    transition: all 0.15s;
    background: var(--genie-input-bg, #fff);
    color: var(--genie-text, #1e293b);
    user-select: none;
    min-height: 32px;
}

.genie-sel-chip:hover {
    border-color: var(--genie-input-focus-ring, #0d9488);
    background: color-mix(in srgb, var(--genie-input-focus-ring, #0d9488) 6%, transparent);
}

.genie-sel-chip.selected {
    background: var(--genie-input-focus-ring, #0d9488);
    color: #fff;
    border-color: var(--genie-input-focus-ring, #0d9488);
}

.genie-sel-chip input { display: none; }

.genie-sel-clear-chapters {
    background: transparent;
    border: none;
    color: var(--color-red-500, #ef4444);
    font-size: 0.8rem;
    cursor: pointer;
    padding: 4px 0;
    text-align: left;
}

.genie-sel-clear-chapters:hover { text-decoration: underline; }

/* ========================================
   STICKY CONFIG BAR (shows selected context on top)
   ======================================== */
.genie-config-bar {
    position: relative;
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 14px;
    background: var(--genie-bg-alt, var(--color-gray-50, #f9fafb));
    border-bottom: 1px solid var(--genie-input-border, #e2e8f0);
    font-size: 0.82rem;
    flex-wrap: wrap;
    z-index: 1001;
}

/* Overlay wrapper for the context selector — anchors to the config bar */
.genie-sel-overlay {
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    z-index: 1000;
}

.genie-config-item {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 3px 8px;
    background: var(--genie-surface, #fff);
    border: 1px solid var(--genie-input-border, #e2e8f0);
    border-radius: 12px;
    color: var(--genie-text, #1e293b);
    white-space: nowrap;
}

.genie-config-item i { color: var(--genie-input-focus-ring, #0d9488); font-size: 0.75rem; }

.genie-config-item .genie-config-value { font-weight: 600; }

.genie-config-edit {
    margin-left: auto;
    background: transparent;
    border: 1px solid var(--genie-input-border, #e2e8f0);
    border-radius: 8px;
    padding: 4px 10px;
    font-size: 0.8rem;
    cursor: pointer;
    color: var(--genie-input-focus-ring, #0d9488);
    transition: all 0.15s;
}

.genie-config-edit:hover {
    background: color-mix(in srgb, var(--genie-input-focus-ring, #0d9488) 8%, transparent);
}
