/* ============================================
   CHAT - Widget flotante y panel de chat
   Para: todas las páginas (usuarios logueados)
   ============================================ */

/* ── Floating Action Button ── */
.chat-fab {
    position: fixed;
    bottom: 24px;
    right: 24px;
    width: 56px;
    height: 56px;
    border-radius: 50%;
    background: linear-gradient(135deg, #0077B5 0%, #005885 100%);
    color: white;
    border: none;
    font-size: 1.4rem;
    cursor: pointer;
    box-shadow: 0 4px 16px rgba(0, 119, 181, 0.4);
    z-index: 9999;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.3s ease;
}

.chat-fab:hover {
    transform: scale(1.08);
    box-shadow: 0 6px 24px rgba(0, 119, 181, 0.5);
}

.chat-fab.active {
    background: linear-gradient(135deg, #005885 0%, #003d5c 100%);
}

.chat-fab-badge {
    position: absolute;
    top: -4px;
    right: -4px;
    min-width: 20px;
    height: 20px;
    background: #ff4444;
    color: white;
    border-radius: 10px;
    font-size: 0.7rem;
    font-weight: 700;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0 5px;
    border: 2px solid white;
    animation: chat-badge-pulse 2s infinite;
}

@keyframes chat-badge-pulse {
    0%, 100% { transform: scale(1); }
    50% { transform: scale(1.1); }
}

/* ── Chat Panel ── */
.chat-panel {
    position: fixed;
    bottom: 90px;
    right: 24px;
    width: 380px;
    max-height: 520px;
    background: white;
    border-radius: 16px;
    box-shadow: 0 8px 40px rgba(0, 0, 0, 0.18);
    z-index: 9998;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    animation: chatPanelSlideIn 0.25s ease-out;
}

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

.chat-panel-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 14px 18px;
    background: linear-gradient(135deg, #0077B5 0%, #005885 100%);
    color: white;
}

.chat-panel-header h3 {
    font-size: 1rem;
    display: flex;
    align-items: center;
    gap: 8px;
    margin: 0;
}

.chat-panel-close {
    background: rgba(255, 255, 255, 0.2);
    border: none;
    color: white;
    font-size: 1.2rem;
    width: 30px;
    height: 30px;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s;
}

.chat-panel-close:hover {
    background: rgba(255, 255, 255, 0.3);
}

/* ── Chat List ── */
.chat-panel-list {
    flex: 1;
    overflow-y: auto;
    max-height: 420px;
}

.chat-list-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 16px;
    cursor: pointer;
    border-bottom: 1px solid #f0f0f0;
    transition: background 0.15s;
    position: relative;
}

.chat-list-item:hover {
    background: #f5f9ff;
}

.chat-list-item.unread {
    background: #eef6ff;
}

.chat-list-avatar {
    width: 44px;
    height: 44px;
    min-width: 44px;
    border-radius: 50%;
    background: #e8e8e8;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #999;
    font-size: 1.1rem;
    overflow: hidden;
}

.chat-list-avatar-img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    border-radius: 50%;
}

.chat-list-info {
    flex: 1;
    min-width: 0;
}

.chat-list-top {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 8px;
}

.chat-list-name {
    font-weight: 600;
    font-size: 0.92rem;
    color: #333;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.chat-list-time {
    font-size: 0.75rem;
    color: #999;
    white-space: nowrap;
}

.chat-list-bottom {
    margin-top: 2px;
}

.chat-list-job {
    font-size: 0.78rem;
    color: #0077B5;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    display: block;
}

.chat-list-preview {
    font-size: 0.82rem;
    color: #888;
    margin-top: 3px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.chat-list-item.unread .chat-list-preview {
    color: #333;
    font-weight: 500;
}

.chat-list-unread-badge {
    background: #0077B5;
    color: white;
    border-radius: 10px;
    padding: 2px 7px;
    font-size: 0.72rem;
    font-weight: 700;
    min-width: 20px;
    text-align: center;
}

/* ── Conversation View ── */
.chat-conversation {
    flex: 1;
    flex-direction: column;
    max-height: calc(520px - 52px); /* panel max-height minus header */
}

.chat-conv-header {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 14px;
    border-bottom: 1px solid #eee;
    background: #fafafa;
}

.chat-back-btn {
    background: none;
    border: none;
    font-size: 1rem;
    color: #0077B5;
    cursor: pointer;
    padding: 4px 8px;
    border-radius: 8px;
    transition: background 0.2s;
}

.chat-back-btn:hover {
    background: #e8f4fd;
}

.chat-conv-info {
    display: flex;
    flex-direction: column;
}

.chat-conv-name {
    font-weight: 600;
    font-size: 0.92rem;
    color: #333;
}

.chat-conv-job {
    font-size: 0.78rem;
    color: #0077B5;
}

/* ── Messages ── */
.chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 12px 14px;
    background: #f5f7fa;
    display: flex;
    flex-direction: column;
    gap: 6px;
    min-height: 200px;
    max-height: 320px;
}

.chat-msg {
    display: flex;
    max-width: 80%;
}

.chat-msg.mine {
    align-self: flex-end;
}

.chat-msg.theirs {
    align-self: flex-start;
}

.chat-msg-bubble {
    padding: 8px 12px;
    border-radius: 14px;
    position: relative;
    word-break: break-word;
}

.chat-msg.mine .chat-msg-bubble {
    background: linear-gradient(135deg, #0077B5, #0090d9);
    color: white;
    border-bottom-right-radius: 4px;
}

.chat-msg.theirs .chat-msg-bubble {
    background: white;
    color: #333;
    border-bottom-left-radius: 4px;
    border: 1px solid #e8e8e8;
}

.chat-msg-bubble p {
    margin: 0;
    font-size: 0.88rem;
    line-height: 1.4;
}

.chat-msg-time {
    display: block;
    font-size: 0.68rem;
    margin-top: 4px;
    opacity: 0.7;
    text-align: right;
}

.chat-msg.theirs .chat-msg-time {
    color: #999;
}

/* ── Input Bar ── */
.chat-input-bar {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 10px 14px;
    border-top: 1px solid #eee;
    background: white;
}

.chat-input-bar input {
    flex: 1;
    padding: 8px 14px;
    border: 1px solid #ddd;
    border-radius: 20px;
    font-size: 0.88rem;
    outline: none;
    transition: border-color 0.2s;
    font-family: inherit;
}

.chat-input-bar input:focus {
    border-color: #0077B5;
}

.chat-send-btn {
    width: 38px;
    height: 38px;
    border-radius: 50%;
    background: linear-gradient(135deg, #0077B5, #005885);
    color: white;
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.9rem;
    transition: all 0.2s;
}

.chat-send-btn:hover {
    transform: scale(1.05);
    box-shadow: 0 2px 8px rgba(0, 119, 181, 0.3);
}

/* ── Empty & Loading States ── */
.chat-loading {
    text-align: center;
    padding: 2rem;
    color: #999;
    font-size: 0.9rem;
}

.chat-empty {
    text-align: center;
    padding: 2.5rem 1.5rem;
    color: #999;
}

.chat-empty i {
    font-size: 2rem;
    margin-bottom: 10px;
    display: block;
    color: #ccc;
}

.chat-empty p {
    margin: 0;
    font-weight: 500;
    color: #666;
}

.chat-empty small {
    display: block;
    margin-top: 6px;
    font-size: 0.8rem;
    color: #aaa;
}

.chat-empty-messages {
    text-align: center;
    padding: 3rem 1rem;
    color: #ccc;
}

.chat-empty-messages i {
    font-size: 2rem;
    margin-bottom: 8px;
    display: block;
}

.chat-empty-messages p {
    margin: 0;
    font-size: 0.88rem;
    color: #999;
}

/* ── Toast Notification ── */
.chat-toast {
    position: fixed;
    top: 80px;
    right: 20px;
    z-index: 10001;
    animation: chatToastIn 0.3s ease-out;
}

.chat-toast.hiding {
    animation: chatToastOut 0.3s ease-in forwards;
}

@keyframes chatToastIn {
    from { opacity: 0; transform: translateX(100%); }
    to { opacity: 1; transform: translateX(0); }
}

@keyframes chatToastOut {
    from { opacity: 1; transform: translateX(0); }
    to { opacity: 0; transform: translateX(100%); }
}

.chat-toast-content {
    display: flex;
    align-items: center;
    gap: 10px;
    background: #0077B5;
    color: white;
    padding: 12px 18px;
    border-radius: 12px;
    box-shadow: 0 4px 20px rgba(0, 119, 181, 0.35);
    cursor: pointer;
    transition: transform 0.2s;
    font-size: 0.9rem;
    font-weight: 500;
}

.chat-toast-content:hover {
    transform: scale(1.02);
}

.chat-toast-close {
    background: rgba(255, 255, 255, 0.2);
    border: none;
    color: white;
    font-size: 1.1rem;
    cursor: pointer;
    padding: 0;
    width: 24px;
    height: 24px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    margin-left: 6px;
}

/* ── Chat Consent Checkbox (in apply modals) ── */
.chat-consent-wrapper {
    display: flex;
    align-items: flex-start;
    gap: 10px;
    padding: 12px 16px;
    margin-top: 12px;
    background: #f0f7ff;
    border: 1px solid #c8e1ff;
    border-radius: 10px;
}

.chat-consent-wrapper input[type="checkbox"] {
    width: 18px;
    height: 18px;
    margin-top: 2px;
    accent-color: #0077B5;
    cursor: pointer;
    flex-shrink: 0;
}

.chat-consent-wrapper label {
    font-size: 0.85rem;
    color: #444;
    line-height: 1.4;
    cursor: pointer;
}

.chat-consent-wrapper label strong {
    color: #0077B5;
}

/* ── "Abrir chat" button in candidates list ── */
.app-chat-btn {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    padding: 5px 12px;
    background: #0077B5;
    color: white;
    border: none;
    border-radius: 6px;
    font-size: 0.8rem;
    cursor: pointer;
    transition: all 0.2s;
    font-weight: 500;
}

.app-chat-btn:hover {
    background: #005885;
    transform: translateY(-1px);
}

.app-chat-btn.disabled {
    background: #ccc;
    cursor: not-allowed;
    pointer-events: none;
}

.app-chat-btn i {
    font-size: 0.85rem;
}

/* ── Responsive ── */
@media (max-width: 480px) {
    .chat-panel {
        bottom: 0;
        right: 0;
        left: 0;
        width: 100%;
        max-height: 100vh;
        border-radius: 16px 16px 0 0;
    }

    .chat-fab {
        bottom: 16px;
        right: 16px;
        width: 50px;
        height: 50px;
        font-size: 1.2rem;
    }

    .chat-messages {
        max-height: calc(100vh - 200px);
    }
}

@media (max-width: 768px) {
    .chat-panel {
        width: 340px;
    }
}

/* ══════════ FEEDBACK CHAT ══════════ */

/* ── Feedback list item ── */
.feedback-chat-item {
    border-top: 2px solid #f0f0f0;
    background: linear-gradient(135deg, #f0f7ff 0%, #faf5ff 100%);
    transition: background 0.2s;
}

.feedback-chat-item:hover {
    background: linear-gradient(135deg, #e3efff 0%, #f0e8ff 100%) !important;
}

.feedback-avatar {
    background: linear-gradient(135deg, #6C63FF 0%, #0077B5 100%) !important;
    color: white !important;
    font-size: 1.1rem !important;
}

.feedback-avatar i {
    color: white !important;
}

.feedback-arrow {
    color: #aaa;
    font-size: 0.8rem;
    display: flex;
    align-items: center;
}

/* ── Feedback buttons ── */
.feedback-buttons {
    display: flex;
    gap: 12px;
    justify-content: center;
    padding: 12px 0;
    animation: feedbackBtnsIn 0.3s ease-out;
}

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

.feedback-btn {
    padding: 10px 28px;
    border: none;
    border-radius: 24px;
    font-size: 0.92rem;
    font-weight: 600;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 8px;
    transition: all 0.2s ease;
    font-family: inherit;
}

.feedback-btn-yes {
    background: linear-gradient(135deg, #28a745 0%, #20c997 100%);
    color: white;
    box-shadow: 0 3px 12px rgba(40, 167, 69, 0.3);
}

.feedback-btn-yes:hover {
    transform: translateY(-2px);
    box-shadow: 0 5px 18px rgba(40, 167, 69, 0.4);
}

.feedback-btn-no {
    background: linear-gradient(135deg, #ff6b6b 0%, #ee5a24 100%);
    color: white;
    box-shadow: 0 3px 12px rgba(255, 107, 107, 0.3);
}

.feedback-btn-no:hover {
    transform: translateY(-2px);
    box-shadow: 0 5px 18px rgba(255, 107, 107, 0.4);
}

/* ── Feedback system bubble ── */
.feedback-system-bubble {
    background: linear-gradient(135deg, #f0f0f5 0%, #e8e8f0 100%) !important;
    color: #444 !important;
    border: none !important;
    border-bottom-left-radius: 4px;
}

.feedback-system-bubble p {
    font-size: 0.9rem !important;
    line-height: 1.5 !important;
}
