/* Base highlight styles */
.text-highlight {
    background-color: rgba(139,92,246,0.2);
    cursor: pointer;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    position: relative;
    border-radius: 2px;
    box-decoration-break: clone;
    -webkit-box-decoration-break: clone;
    /* Prevent layout shifts */
    margin: 0;
    border: 1px solid transparent;
    display: inline;
    line-height: inherit;
    text-align: inherit;
    vertical-align: baseline;
    white-space: pre-wrap;
}

/* Hover effect */
.text-highlight:hover {
    background-color: rgba(139,92,246,0.3);
}

/* Active state */
.text-highlight:active {
    background-color: rgba(139,92,246,0.4);
}

/* Animation for new highlights */
@keyframes highlightFade {
    0% { background-color: rgba(139,92,246,0.6); }
    100% { background-color: rgba(139,92,246,0.2); }
}

.text-highlight.new {
    animation: highlightFade 0.5s ease-out;
}

/* Preserve entry reference styling when inside highlights */
.text-highlight .entry-reference {
    /* Ensure entry reference maintains its original size and appearance */
    display: inline-block !important;
    padding: 0.375rem 0.5rem !important;
    font-size: 0.875rem !important;
    line-height: 1.25rem !important;
    white-space: nowrap !important;
    /* Override any inherited styles that might cause inflation */
    background-color: rgba(243, 232, 255, 1) !important; /* bg-purple-50 */
    border: 1px solid rgba(237, 233, 254, 1) !important; /* border-purple-100 */
    color: rgba(147, 51, 234, 1) !important; /* text-purple-600 */
    border-radius: 0.5rem !important;
    transition: background-color 0.15s ease-in-out !important;
    /* Prevent expansion in timeline and other views */
    max-width: fit-content !important;
    overflow: visible !important;
    height: auto !important;
    box-sizing: content-box !important;
}

/* Ensure the entry reference text itself doesn't expand */
.text-highlight .entry-reference * {
    font-size: 0.875rem !important;
    line-height: 1.25rem !important;
    white-space: nowrap !important;
}

.text-highlight .entry-reference:hover {
    background-color: rgba(237, 233, 254, 1) !important; /* bg-purple-100 */
}

/* Additional rules for timeline view */
.timeline-journal-entry-container .text-highlight .entry-reference,
.bubble-container .text-highlight .entry-reference {
    display: inline-block !important;
    padding: 0.25rem 0.5rem !important; /* Slightly smaller padding for timeline */
    margin: 0 0.25rem !important;
    vertical-align: middle !important;
    max-width: fit-content !important;
    box-sizing: content-box !important;
}

/* Highlight menu */
.highlight-menu {
    background-color: white;
    border: 1px solid rgba(139,92,246,0.2);
    border-radius: 8px;
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
    padding: 8px;
    z-index: 1000;
    display: flex;
    gap: 4px;
    transition: opacity 0.2s ease, transform 0.2s ease;
    transform-origin: top center;
    animation: menuAppear 0.2s ease-out;
}

@keyframes menuAppear {
    0% { opacity: 0; transform: scale(0.95); }
    100% { opacity: 1; transform: scale(1); }
}

/* Menu buttons */
.highlight-btn {
    background: none;
    border: 1px solid transparent;
    padding: 6px 12px;
    cursor: pointer;
    font-size: 14px;
    color: #4a5568;
    border-radius: 6px;
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
    gap: 6px;
    font-weight: 500;
}

.highlight-btn:hover {
    background-color: rgba(139,92,246,0.1);
    color: rgb(139,92,246);
}

.highlight-btn:focus {
    outline: 2px solid rgba(139,92,246,0.5);
    outline-offset: 2px;
}

/* Mobile styles */
@media (max-width: 768px) {
    .highlight-menu {
        position: fixed !important;
        bottom: 20px !important;
        left: 50% !important;
        transform: translateX(-50%);
        top: auto !important;
        width: calc(100% - 40px);
        max-width: 400px;
        justify-content: center;
    }

    .highlight-btn {
        padding: 12px 16px;
        font-size: 16px;
    }
}

/* Accessibility */
.highlight-btn:focus-visible {
    outline: 2px solid rgb(139,92,246);
    outline-offset: 2px;
}

/* Remove highlight button */
.highlight-btn.remove {
    color: #ef4444;
}

.highlight-btn.remove:hover {
    background-color: rgba(239,68,68,0.1);
}
