/* ============================================
   BIBLIA BOT - OpenClaw Chat Widget
   ============================================ */

/* Chat Toggle Button */
.bot-toggle {
    position: fixed;
    bottom: 24px;
    right: 24px;
    width: 64px;
    height: 64px;
    border-radius: 50%;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    border: none;
    cursor: pointer;
    box-shadow: 0 6px 24px rgba(102, 126, 234, 0.5);
    z-index: 10000;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 28px;
    transition: transform 0.3s, box-shadow 0.3s;
    animation: bot-pulse 3s ease-in-out infinite;
}
.bot-toggle:hover {
    transform: scale(1.1);
    box-shadow: 0 8px 32px rgba(102, 126, 234, 0.7);
}
.bot-toggle.active { animation: none; }
@keyframes bot-pulse {
    0%, 100% { box-shadow: 0 6px 24px rgba(102, 126, 234, 0.5); }
    50% { box-shadow: 0 6px 32px rgba(102, 126, 234, 0.8), 0 0 48px rgba(118, 75, 162, 0.3); }
}

/* Chat Panel */
.bot-panel {
    position: fixed;
    bottom: 100px;
    right: 24px;
    width: 420px;
    height: 600px;
    min-width: 300px;
    min-height: 350px;
    background: var(--bot-bg, #ffffff);
    border-radius: 20px;
    box-shadow: 0 20px 60px rgba(0,0,0,0.2), 0 0 0 1px rgba(0,0,0,0.05);
    display: flex;
    flex-direction: column;
    z-index: 10001;
    opacity: 0;
    transform: translateY(20px) scale(0.95);
    pointer-events: none;
    transition: opacity 0.35s ease, transform 0.35s ease;
    overflow: hidden;
}
.bot-panel.open {
    opacity: 1;
    transform: translateY(0) scale(1);
    pointer-events: auto;
}
.bot-panel.maximized {
    top: 8px !important;
    left: 8px !important;
    right: 8px !important;
    bottom: 8px !important;
    width: auto !important;
    height: auto !important;
    border-radius: 12px;
}
.bot-panel.dragging { transition: none; }
.bot-panel.resizing { transition: none; }

/* Resize handle */
.bot-resize {
    position: absolute;
    top: 0;
    left: 0;
    width: 18px;
    height: 18px;
    cursor: nw-resize;
    z-index: 2;
}
.bot-resize::after {
    content: '';
    position: absolute;
    top: 3px;
    left: 3px;
    width: 10px;
    height: 10px;
    border-top: 2px solid rgba(255,255,255,0.4);
    border-left: 2px solid rgba(255,255,255,0.4);
    border-radius: 4px 0 0 0;
}
.bot-panel.maximized .bot-resize { display: none; }

/* Header */
.bot-header {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    padding: 16px 20px;
    display: flex;
    align-items: center;
    gap: 12px;
    flex-shrink: 0;
    cursor: grab;
    user-select: none;
}
.bot-header:active { cursor: grabbing; }
.bot-avatar {
    width: 42px;
    height: 42px;
    border-radius: 50%;
    background: rgba(255,255,255,0.2);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 22px;
    backdrop-filter: blur(8px);
}
.bot-header-info { flex: 1; }
.bot-header-name { font-weight: 700; font-size: 16px; }
.bot-header-status { font-size: 12px; opacity: 0.85; display: flex; align-items: center; gap: 4px; }
.bot-header-status::before {
    content: '';
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: #4ade80;
    display: inline-block;
}
.bot-header-btns { display: flex; gap: 6px; }
.bot-header-btn {
    background: rgba(255,255,255,0.15);
    border: none;
    color: white;
    width: 30px;
    height: 30px;
    border-radius: 50%;
    cursor: pointer;
    font-size: 14px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s;
}
.bot-header-btn:hover { background: rgba(255,255,255,0.3); }
.bot-close { font-size: 18px; }
.bot-header-btn.active { background: rgba(255,255,255,0.35); }

/* Now Playing Bar (fixed below header) */
.bot-nowplaying {
    display: none;
    align-items: center;
    gap: 10px;
    padding: 8px 16px;
    background: linear-gradient(90deg, #1e1b4b, #312e81);
    color: white;
    flex-shrink: 0;
}
.bot-nowplaying.active { display: flex; }
.bot-nowplaying-label {
    font-size: 12px;
    font-weight: 600;
    opacity: 0.9;
    flex: 1;
}
.bot-nowplaying-dots {
    display: flex;
    gap: 3px;
    align-items: center;
}
.bot-nowplaying-dots span {
    width: 4px;
    height: 4px;
    border-radius: 50%;
    background: #a78bfa;
    animation: np-dot 1.2s infinite;
}
.bot-nowplaying-dots span:nth-child(2) { animation-delay: 0.2s; }
.bot-nowplaying-dots span:nth-child(3) { animation-delay: 0.4s; }
@keyframes np-dot {
    0%, 60%, 100% { transform: scale(1); opacity: 0.4; }
    30% { transform: scale(1.8); opacity: 1; }
}
.bot-nowplaying-btn {
    background: rgba(255,255,255,0.15);
    border: none;
    color: white;
    width: 30px;
    height: 30px;
    border-radius: 50%;
    cursor: pointer;
    font-size: 14px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s;
}
.bot-nowplaying-btn:hover { background: rgba(255,255,255,0.3); }
.bot-np-stop { background: rgba(239, 68, 68, 0.6); }
.bot-np-stop:hover { background: rgba(239, 68, 68, 0.8); }

/* TTS Settings Panel */
.bot-tts-settings {
    max-height: 0;
    overflow: hidden;
    transition: max-height 0.3s ease, padding 0.3s ease;
    padding: 0 16px;
    background: var(--bot-msg-bg, #f3f4f6);
    border-bottom: 1px solid var(--bot-border, #e5e7eb);
}
.bot-tts-settings.open {
    max-height: 120px;
    padding: 10px 16px;
}
.bot-tts-settings-row {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 6px;
}
.bot-tts-settings-row:last-child { margin-bottom: 0; }
.bot-tts-label {
    font-size: 12px;
    font-weight: 600;
    color: var(--bot-text, #4b5563);
    min-width: 60px;
    flex-shrink: 0;
}
.bot-tts-voice-select {
    flex: 1;
    font-size: 12px;
    padding: 4px 6px;
    border-radius: 8px;
    border: 1px solid var(--bot-border, #d1d5db);
    background: var(--bot-bg, white);
    color: var(--bot-text, #1f2937);
    outline: none;
    max-width: 220px;
}
.bot-tts-voice-select:focus { border-color: #667eea; }
.bot-tts-speed-global {
    width: 100px;
    height: 4px;
    appearance: none;
    -webkit-appearance: none;
    background: var(--bot-border, #d1d5db);
    border-radius: 2px;
    outline: none;
    cursor: pointer;
}
.bot-tts-speed-global::-webkit-slider-thumb {
    -webkit-appearance: none;
    width: 16px;
    height: 16px;
    border-radius: 50%;
    background: #667eea;
    cursor: pointer;
    border: 2px solid white;
    box-shadow: 0 1px 3px rgba(0,0,0,0.2);
}
.bot-tts-speed-global::-moz-range-thumb {
    width: 16px;
    height: 16px;
    border-radius: 50%;
    background: #667eea;
    cursor: pointer;
    border: 2px solid white;
}

/* Date/Time/Weather Bar */
.bot-datetime-bar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 6px 14px;
    background: linear-gradient(135deg, rgba(102, 126, 234, 0.12) 0%, rgba(118, 75, 162, 0.08) 100%);
    border-bottom: 1px solid rgba(102, 126, 234, 0.15);
    font-size: 12px;
    color: var(--bot-text, #c4b5fd);
    font-weight: 500;
}
.bot-datetime-clock {
    opacity: 0.9;
}
.bot-datetime-weather {
    font-size: 11px;
    opacity: 0.85;
}
[data-theme="light"] .bot-datetime-bar {
    color: #555;
    background: linear-gradient(135deg, rgba(102, 126, 234, 0.06) 0%, rgba(118, 75, 162, 0.04) 100%);
}

/* Quick Actions */
.bot-actions {
    display: flex;
    gap: 6px;
    padding: 10px 16px;
    overflow-x: auto;
    flex-shrink: 0;
    border-bottom: 1px solid var(--bot-border, #e5e7eb);
    scrollbar-width: none;
}
.bot-actions::-webkit-scrollbar { display: none; }
.bot-action-btn {
    flex-shrink: 0;
    padding: 6px 12px;
    border-radius: 20px;
    border: 1px solid var(--bot-border, #e5e7eb);
    background: var(--bot-action-bg, #f9fafb);
    color: var(--bot-text, #374151);
    font-size: 12px;
    cursor: pointer;
    transition: all 0.2s;
    white-space: nowrap;
}
.bot-action-btn:hover {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    border-color: transparent;
    transform: translateY(-1px);
}

/* Messages Container */
.bot-messages {
    flex: 1;
    overflow-y: auto;
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 12px;
    scroll-behavior: smooth;
}
.bot-messages::-webkit-scrollbar { width: 4px; }
.bot-messages::-webkit-scrollbar-thumb { background: #cbd5e1; border-radius: 4px; }

/* Message Bubbles */
.bot-msg {
    max-width: 85%;
    padding: 12px 16px;
    border-radius: 18px;
    font-size: 14px;
    line-height: 1.5;
    word-wrap: break-word;
    animation: msg-in 0.3s ease;
}
@keyframes msg-in {
    from { opacity: 0; transform: translateY(8px); }
    to { opacity: 1; transform: translateY(0); }
}
.bot-msg.assistant {
    align-self: flex-start;
    background: var(--bot-msg-bg, #f3f4f6);
    color: var(--bot-text, #1f2937);
    border-bottom-left-radius: 6px;
}
.bot-msg.user {
    align-self: flex-end;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    border-bottom-right-radius: 6px;
}
.bot-msg.system {
    align-self: center;
    background: var(--bot-system-bg, #fef3c7);
    color: #92400e;
    font-size: 12px;
    border-radius: 12px;
    text-align: center;
    max-width: 95%;
}

/* Typing indicator */
.bot-typing {
    display: flex;
    gap: 4px;
    padding: 12px 16px;
    align-self: flex-start;
    background: var(--bot-msg-bg, #f3f4f6);
    border-radius: 18px;
    border-bottom-left-radius: 6px;
}
.bot-typing span {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: #9ca3af;
    animation: typing-dot 1.4s infinite;
}
.bot-typing span:nth-child(2) { animation-delay: 0.2s; }
.bot-typing span:nth-child(3) { animation-delay: 0.4s; }
@keyframes typing-dot {
    0%, 60%, 100% { transform: translateY(0); opacity: 0.4; }
    30% { transform: translateY(-6px); opacity: 1; }
}

/* TTS Controls Bar */
.bot-tts-bar {
    display: flex;
    gap: 4px;
    margin-top: 6px;
    align-items: center;
}
.bot-tts-btn {
    background: var(--bot-action-bg, #e5e7eb);
    border: none;
    cursor: pointer;
    width: 28px;
    height: 28px;
    border-radius: 50%;
    font-size: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
    color: var(--bot-text, #374151);
}
.bot-tts-btn:hover { background: #667eea; color: white; }
.bot-tts-play {}
.bot-tts-pause { background: #667eea; color: white; }
.bot-tts-stop { background: #ef4444; color: white; font-size: 10px; }
.bot-tts-stop:hover { background: #dc2626; }
.bot-tts-bar.active .bot-tts-play,
.bot-tts-bar.active .bot-tts-pause { animation: tts-glow 2s ease-in-out infinite; }
@keyframes tts-glow {
    0%, 100% { box-shadow: 0 0 0 0 rgba(102, 126, 234, 0.3); }
    50% { box-shadow: 0 0 0 4px rgba(102, 126, 234, 0); }
}
/* Speed label in TTS bar (global) */
.bot-tts-speed-label {
    font-size: 11px;
    color: var(--bot-text, #6b7280);
    min-width: 36px;
    text-align: center;
    font-weight: 600;
}

/* Attachment preview */
.bot-attachment {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 12px;
    background: var(--bot-action-bg, #f0f0f0);
    border-radius: 10px;
    font-size: 12px;
    margin-top: 6px;
}
.bot-attachment-icon { font-size: 20px; }
.bot-attachment-name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bot-attachment-remove {
    background: none;
    border: none;
    cursor: pointer;
    font-size: 16px;
    color: #ef4444;
    padding: 0 4px;
}

/* ==========================================
   KARAOKE PANEL
   ========================================== */
.bot-karaoke {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%) scale(0.9);
    width: 700px;
    max-width: calc(100vw - 40px);
    max-height: 70vh;
    background: var(--bot-bg, #1a1a2e);
    border-radius: 24px;
    box-shadow: 0 30px 80px rgba(0,0,0,0.5), 0 0 120px rgba(102, 126, 234, 0.15);
    z-index: 10010;
    display: flex;
    flex-direction: column;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.4s ease, transform 0.4s ease;
    overflow: hidden;
}
.bot-karaoke.open {
    opacity: 1;
    pointer-events: auto;
    transform: translate(-50%, -50%) scale(1);
}
.bot-karaoke-header {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    padding: 14px 20px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-shrink: 0;
}
.bot-karaoke-title {
    font-weight: 700;
    font-size: 16px;
}
.bot-karaoke-controls {
    display: flex;
    gap: 8px;
}
.bot-karaoke-btn {
    background: rgba(255,255,255,0.2);
    border: none;
    color: white;
    width: 36px;
    height: 36px;
    border-radius: 50%;
    cursor: pointer;
    font-size: 18px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s;
}
.bot-karaoke-btn:hover { background: rgba(255,255,255,0.35); }
.bot-karaoke-body {
    flex: 1;
    padding: 32px 36px;
    overflow-y: auto;
    font-size: 22px;
    line-height: 1.8;
    color: rgba(200, 200, 220, 0.4);
    scroll-behavior: smooth;
}
.bot-karaoke-body::-webkit-scrollbar { width: 4px; }
.bot-karaoke-body::-webkit-scrollbar-thumb { background: rgba(102,126,234,0.3); border-radius: 4px; }

/* Karaoke chunk states */
.karaoke-chunk {
    transition: color 0.3s ease, text-shadow 0.3s ease;
    border-radius: 4px;
    padding: 1px 0;
}
.karaoke-chunk.past {
    color: rgba(180, 180, 200, 0.6);
}
.karaoke-chunk.active {
    color: #ffffff;
    text-shadow: 0 0 20px rgba(102, 126, 234, 0.8), 0 0 40px rgba(102, 126, 234, 0.4);
    font-weight: 600;
    background: rgba(102, 126, 234, 0.15);
    border-radius: 6px;
    padding: 2px 4px;
}
.karaoke-chunk.future {
    color: rgba(200, 200, 220, 0.35);
}

/* Progress bar */
.bot-karaoke-progress {
    height: 4px;
    background: rgba(255,255,255,0.1);
    flex-shrink: 0;
}
.bot-karaoke-progress-fill {
    height: 100%;
    background: linear-gradient(90deg, #667eea, #764ba2);
    width: 0%;
    transition: width 0.5s ease;
    border-radius: 0 2px 2px 0;
}

/* Dark mode karaoke */
[data-theme="dark"] .bot-karaoke {
    background: #0f0f1e;
}
[data-theme="light"] .bot-karaoke {
    background: #1a1a2e;
}

/* Mobile karaoke */
@media (max-width: 768px) {
    .bot-karaoke {
        width: min(480px, calc(100vw - 24px));
        max-height: 65vh;
    }
}
@media (max-width: 480px) {
    .bot-karaoke {
        width: calc(100vw - 16px);
        max-height: 60vh;
        border-radius: 16px;
    }
    .bot-karaoke-body {
        font-size: 18px;
        padding: 20px 24px;
    }
}

/* Input Area */
.bot-input-area {
    padding: 12px 16px;
    border-top: 1px solid var(--bot-border, #e5e7eb);
    flex-shrink: 0;
}
.bot-input-attachments {
    display: flex;
    gap: 6px;
    flex-wrap: wrap;
    margin-bottom: 8px;
}
.bot-input-attachments:empty { display: none; }
.bot-input-row {
    display: flex;
    align-items: flex-end;
    gap: 8px;
}
.bot-input {
    flex: 1;
    border: 1px solid var(--bot-border, #e5e7eb);
    border-radius: 24px;
    padding: 10px 16px;
    font-size: 14px;
    background: var(--bot-input-bg, #f9fafb);
    color: var(--bot-text, #1f2937);
    outline: none;
    resize: none;
    max-height: 100px;
    font-family: inherit;
    line-height: 1.4;
    transition: border-color 0.2s, box-shadow 0.2s;
}
.bot-input:focus {
    border-color: #667eea;
    box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.15);
}
.bot-input::placeholder { color: #9ca3af; }

/* Input buttons */
.bot-input-btn {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 18px;
    transition: all 0.2s;
    flex-shrink: 0;
}
.bot-btn-attach {
    background: var(--bot-action-bg, #f3f4f6);
    color: var(--bot-text, #6b7280);
}
.bot-btn-attach:hover { background: #e5e7eb; }
.bot-btn-mic {
    background: var(--bot-action-bg, #f3f4f6);
    color: var(--bot-text, #6b7280);
}
.bot-btn-mic:hover { background: #e5e7eb; }
.bot-btn-mic.recording {
    background: #ef4444;
    color: white;
    animation: mic-pulse 1s infinite;
}
@keyframes mic-pulse {
    0%, 100% { box-shadow: 0 0 0 0 rgba(239, 68, 68, 0.4); }
    50% { box-shadow: 0 0 0 8px rgba(239, 68, 68, 0); }
}
.bot-btn-send {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
}
.bot-btn-send:hover { transform: scale(1.05); }
.bot-btn-send:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    transform: none;
}

/* Drop zone */
.bot-dropzone {
    position: absolute;
    inset: 0;
    background: rgba(102, 126, 234, 0.9);
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 10;
    border-radius: 20px;
    color: white;
    font-size: 18px;
    font-weight: 600;
    flex-direction: column;
    gap: 8px;
}
.bot-dropzone.active { display: flex; }
.bot-dropzone-icon { font-size: 48px; }

/* Verse highlight in messages */
.bot-verse-ref {
    color: #667eea;
    cursor: pointer;
    text-decoration: underline;
    font-weight: 500;
}
.bot-verse-ref:hover { color: #764ba2; }

/* Dark mode */
[data-theme="dark"] {
    --bot-bg: #1e1e2e;
    --bot-text: #e5e7eb;
    --bot-border: #374151;
    --bot-msg-bg: #2d2d44;
    --bot-action-bg: #2d2d44;
    --bot-input-bg: #2d2d44;
    --bot-system-bg: #3b3422;
}

/* Tablet / medium phones */
@media (max-width: 768px) {
    .bot-panel {
        width: min(420px, calc(100vw - 16px));
        height: min(600px, calc(100dvh - 120px));
        right: 8px;
        bottom: 88px;
    }
    .bot-toggle {
        bottom: calc(72px + env(safe-area-inset-bottom, 0px));
        right: 16px;
    }
}

/* Small phones — bottom sheet (no cubrir barra Chrome) */
@media (max-width: 480px) {
    .bot-panel {
        top: auto;
        bottom: 0;
        right: 0;
        left: 0;
        width: 100%;
        height: 70vh;
        height: 70dvh;
        max-height: 70vh;
        max-height: 70dvh;
        border-radius: 16px 16px 0 0;
    }
    .bot-panel .bot-input-area {
        padding-bottom: max(12px, env(safe-area-inset-bottom, 12px));
    }
    .bot-panel .bot-header {
        border-radius: 16px 16px 0 0;
    }
    .bot-toggle {
        bottom: calc(76px + env(safe-area-inset-bottom, 0px));
        right: 16px;
        width: 52px;
        height: 52px;
        font-size: 22px;
    }
    .bot-toggle.active { display: none; }
    /* Más espacio para mensajes en móvil */
    .bot-datetime-bar { display: none; }
    .bot-actions { padding: 6px 12px; gap: 4px; }
    .bot-action-btn { padding: 7px 10px; font-size: 12px; }
    .bot-header { padding: 10px 14px; gap: 8px; }
    .bot-avatar { width: 34px; height: 34px; font-size: 18px; }
    .bot-header-name { font-size: 14px; }
    .bot-header-status { font-size: 11px; }
    .bot-input-area { padding: 8px 12px; }
    .bot-input { padding: 8px 14px; font-size: 13px; }
    .bot-input-btn { width: 36px; height: 36px; font-size: 16px; }
    /* Touch targets más grandes en móvil */
    .bot-tts-btn {
        width: 44px;
        height: 44px;
        font-size: 18px;
    }
    .bot-header-btn {
        width: 34px;
        height: 34px;
        font-size: 15px;
    }
    .bot-nowplaying-btn {
        width: 38px;
        height: 38px;
        font-size: 16px;
    }
    /* Maximizado = fullscreen real */
    .bot-panel.maximized {
        top: 0 !important;
        height: 100vh !important;
        height: 100dvh !important;
        max-height: 100dvh !important;
        border-radius: 0 !important;
    }
}

/* Markdown in messages */
.bot-msg pre {
    background: rgba(0,0,0,0.1);
    padding: 8px 12px;
    border-radius: 8px;
    overflow-x: auto;
    font-size: 13px;
    margin: 6px 0;
}
.bot-msg code {
    background: rgba(0,0,0,0.08);
    padding: 1px 4px;
    border-radius: 4px;
    font-size: 13px;
}
.bot-msg strong { font-weight: 700; }
.bot-msg em { font-style: italic; }
.bot-msg ul, .bot-msg ol {
    margin: 4px 0;
    padding-left: 20px;
}
.bot-msg p { margin: 4px 0; }
.bot-msg blockquote {
    border-left: 3px solid #667eea;
    padding-left: 10px;
    margin: 6px 0;
    opacity: 0.85;
    font-style: italic;
}
.bot-msg a.bot-link,
.bot-msg a {
    color: #818cf8;
    text-decoration: underline;
    word-break: break-all;
    transition: color 0.2s;
}
.bot-msg a.bot-link:hover,
.bot-msg a:hover {
    color: #a5b4fc;
}
.bot-msg a.bot-link::before {
    content: '🔗 ';
    font-size: 11px;
}
