/* CITAS AI Chat Widget */

/* ── Theme tokens (student = blue/indigo default; professor overrides set via JS) ── */
:root {
    --citas-grad-start:        #3b82f6;
    --citas-grad-end:          #6366f1;
    --citas-btn-shadow:        rgba(99, 102, 241, 0.45);
    --citas-btn-shadow-hover:  rgba(99, 102, 241, 0.55);
    --citas-bubble-bg:         #eef2ff;
    --citas-bubble-text:       #1e1b4b;
    --citas-bubble-shadow:     rgba(99, 102, 241, 0.08);
    --citas-user-shadow:       rgba(99, 102, 241, 0.25);
    --citas-link:              #6366f1;
    --citas-link-hover:        #4f46e5;
    --citas-chip-bg:           #f0f4ff;
    --citas-chip-border:       #6366f1;
    --citas-chip-hover-bg:     #6366f1;
    --citas-faq-hover-border:  #6366f1;
    --citas-faq-hover-color:   #6366f1;
    --citas-faq-hover-bg:      #eef2ff;
    --citas-input-focus:       #6366f1;
}

#citas-ai-btn {
    position: fixed;
    bottom: 24px;
    right: 24px;
    width: 52px;
    height: 52px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--citas-grad-start) 0%, var(--citas-grad-end) 100%);
    border: none;
    cursor: grab;
    box-shadow: 0 4px 16px var(--citas-btn-shadow);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 9998;
    transition: transform 0.2s, box-shadow 0.2s;
    user-select: none;
    touch-action: none;
}
#citas-ai-btn.dragging {
    cursor: grabbing;
    transform: scale(1.1);
    box-shadow: 0 8px 24px var(--citas-btn-shadow-hover);
}
#citas-ai-btn:hover {
    transform: scale(1.08);
    box-shadow: 0 6px 20px var(--citas-btn-shadow-hover);
}
#citas-ai-btn svg { pointer-events: none; }
.citas-btn-icon {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    object-fit: cover;
    pointer-events: none;
    display: block;
}

#citas-ai-badge {
    position: fixed;
    bottom: 66px;
    right: 22px;
    background: #ef4444;
    color: #fff;
    font-size: 10px;
    font-weight: 700;
    border-radius: 999px;
    padding: 1px 6px;
    z-index: 9999;
    display: none;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
}

#citas-ai-panel {
    position: fixed;
    bottom: 88px;
    right: 24px;
    width: 360px;
    max-width: calc(100vw - 48px);
    height: 520px;
    max-height: calc(100vh - 120px);
    background: #fff;
    border-radius: 16px;
    box-shadow: 0 8px 40px rgba(0,0,0,0.18);
    display: flex;
    flex-direction: column;
    z-index: 9997;
    overflow: hidden;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    transform: scale(0.85) translateY(20px);
    opacity: 0;
    pointer-events: none;
    transform-origin: bottom right;
    transition: transform 0.22s cubic-bezier(0.34,1.56,0.64,1), opacity 0.18s ease;
}
#citas-ai-panel.open {
    transform: scale(1) translateY(0);
    opacity: 1;
    pointer-events: all;
}

#citas-ai-header {
    background: linear-gradient(135deg, var(--citas-grad-start) 0%, var(--citas-grad-end) 100%);
    padding: 14px 16px;
    display: flex;
    align-items: center;
    gap: 10px;
    flex-shrink: 0;
}
#citas-ai-header .ai-avatar {
    width: 36px;
    height: 36px;
    background: rgba(255,255,255,0.2);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    overflow: hidden;
}
#citas-ai-header .ai-avatar img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    border-radius: 50%;
    display: block;
}
#citas-ai-header .ai-info { flex: 1; }
#citas-ai-header .ai-name {
    color: #fff;
    font-size: 14px;
    font-weight: 600;
    line-height: 1.2;
}
#citas-ai-header .ai-name .ai-subtitle {
    font-weight: 400;
    font-size: 11px;
    opacity: 0.8;
}
#citas-ai-header .ai-status {
    color: rgba(255,255,255,0.75);
    font-size: 11px;
    display: flex;
    align-items: center;
    gap: 4px;
}
#citas-ai-header .ai-status::before {
    content: '';
    display: inline-block;
    width: 6px;
    height: 6px;
    background: #4ade80;
    border-radius: 50%;
}
#citas-ai-close {
    background: none;
    border: none;
    cursor: pointer;
    color: rgba(255,255,255,0.8);
    padding: 4px;
    border-radius: 6px;
    display: flex;
    align-items: center;
    transition: color 0.15s, background 0.15s;
}
#citas-ai-close:hover { color: #fff; background: rgba(255,255,255,0.15); }

#citas-ai-messages {
    flex: 1;
    overflow-y: auto;
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 16px;
    background: #f8fafc;
    scroll-behavior: smooth;
}
#citas-ai-messages::-webkit-scrollbar { width: 4px; }
#citas-ai-messages::-webkit-scrollbar-track { background: transparent; }
#citas-ai-messages::-webkit-scrollbar-thumb { background: #d1d5db; border-radius: 4px; }

.citas-msg {
    display: flex;
    gap: 8px;
    animation: citasMsgIn 0.2s ease;
}
@keyframes citasMsgIn {
    from { opacity: 0; transform: translateY(6px); }
    to   { opacity: 1; transform: translateY(0); }
}
.citas-msg.user { flex-direction: row-reverse; }

.citas-msg-avatar {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 12px;
    font-weight: 700;
    align-self: flex-end;
}
.citas-msg.bot .citas-msg-avatar {
    background: transparent;
    overflow: hidden;
}
.citas-avatar-icon {
    border-radius: 50%;
    object-fit: cover;
    display: block;
}
.citas-msg.user .citas-msg-avatar {
    background: #e5e7eb;
    color: #374151;
}

.citas-msg-content {
    max-width: 78%;
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.citas-msg-bubble {
    padding: 12px 16px;
    border-radius: 16px;
    font-size: 13.5px;
    line-height: 1.6;
    word-break: break-word;
}
.citas-msg.bot .citas-msg-bubble {
    background: var(--citas-bubble-bg);
    color: var(--citas-bubble-text);
    border-bottom-left-radius: 4px;
    box-shadow: 0 1px 4px var(--citas-bubble-shadow);
}
.citas-msg.user .citas-msg-bubble {
    max-width: 78%;
    background: linear-gradient(135deg, var(--citas-grad-start), var(--citas-grad-end));
    color: #fff;
    border-bottom-right-radius: 4px;
    white-space: pre-wrap;
    box-shadow: 0 2px 8px var(--citas-user-shadow);
}

/* Rich text inside bot bubbles */
.citas-msg.bot .citas-msg-bubble a {
    color: var(--citas-link);
    text-decoration: underline;
    word-break: break-all;
}
.citas-msg.bot .citas-msg-bubble a:hover { color: var(--citas-link-hover); }
.citas-msg.bot .citas-msg-bubble strong { font-weight: 600; }
.citas-msg.bot .citas-msg-bubble em { font-style: italic; }
.citas-msg.bot .citas-msg-bubble ul,
.citas-msg.bot .citas-msg-bubble ol {
    margin: 4px 0;
    padding-left: 18px;
}
.citas-msg.bot .citas-msg-bubble li { margin-bottom: 3px; }

/* Quick-reply suggestion chips */
.citas-quick-replies {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
}
.citas-chip {
    background: var(--citas-chip-bg);
    border: 1.5px solid var(--citas-chip-border);
    color: var(--citas-chip-border);
    border-radius: 999px;
    padding: 5px 12px;
    font-size: 12px;
    font-family: inherit;
    cursor: pointer;
    transition: background 0.15s, color 0.15s;
    white-space: nowrap;
    line-height: 1.4;
}
.citas-chip:hover {
    background: var(--citas-chip-hover-bg);
    color: #fff;
}

/* FAQ topic chips shown on welcome */
.citas-faq-wrap {
    display: flex;
    flex-direction: column;
    gap: 8px;
}
.citas-faq-label {
    font-size: 10.5px;
    color: #9ca3af;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.06em;
}
.citas-faq-chips {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
}
.citas-faq-chip {
    background: #fff;
    border: 1.5px solid #d1d5db;
    color: #374151;
    border-radius: 999px;
    padding: 6px 13px;
    font-size: 12px;
    font-family: inherit;
    cursor: pointer;
    transition: border-color 0.15s, color 0.15s, background 0.15s;
    white-space: nowrap;
    line-height: 1.4;
}
.citas-faq-chip:hover {
    border-color: var(--citas-faq-hover-border);
    color: var(--citas-faq-hover-color);
    background: var(--citas-faq-hover-bg);
}

.citas-typing {
    display: flex;
    align-items: center;
    gap: 4px;
    padding: 10px 14px;
    background: #fff;
    border-radius: 14px;
    border-bottom-left-radius: 4px;
    width: fit-content;
    box-shadow: 0 1px 3px rgba(0,0,0,0.08);
}
.citas-typing span {
    width: 7px;
    height: 7px;
    background: #9ca3af;
    border-radius: 50%;
    animation: citasDot 1.2s infinite;
}
.citas-typing span:nth-child(2) { animation-delay: 0.2s; }
.citas-typing span:nth-child(3) { animation-delay: 0.4s; }
@keyframes citasDot {
    0%, 60%, 100% { transform: translateY(0); opacity: 0.4; }
    30% { transform: translateY(-5px); opacity: 1; }
}

#citas-ai-footer {
    padding: 12px;
    background: #fff;
    border-top: 1px solid #e5e7eb;
    flex-shrink: 0;
}
#citas-ai-form {
    display: flex;
    gap: 8px;
    align-items: flex-end;
}
#citas-ai-input {
    flex: 1;
    border: 1.5px solid #e5e7eb;
    border-radius: 10px;
    padding: 9px 12px;
    font-size: 13.5px;
    font-family: inherit;
    resize: none;
    outline: none;
    line-height: 1.4;
    max-height: 100px;
    overflow-y: auto;
    color: #1f2937;
    background: #f9fafb;
    transition: border-color 0.15s;
}
#citas-ai-input:focus { border-color: var(--citas-input-focus); background: #fff; }
#citas-ai-input::placeholder { color: #9ca3af; }

#citas-ai-send {
    width: 38px;
    height: 38px;
    border-radius: 10px;
    background: linear-gradient(135deg, var(--citas-grad-start), var(--citas-grad-end));
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: opacity 0.15s, transform 0.15s;
}
#citas-ai-send:hover { opacity: 0.9; transform: scale(1.05); }
#citas-ai-send:disabled { opacity: 0.45; cursor: not-allowed; transform: none; }

.citas-ai-hint {
    text-align: center;
    font-size: 10.5px;
    color: #9ca3af;
    margin-top: 6px;
}

/* Mobile: make panel full-width on small screens */
@media (max-width: 420px) {
    #citas-ai-panel {
        right: 12px;
        bottom: 80px;
        width: calc(100vw - 24px);
    }
    #citas-ai-btn { right: 16px; bottom: 20px; }
    #citas-ai-badge { right: 14px; bottom: 62px; }
}
