/* Disable context menu and callouts on mobile */
body, p, div, span, h1, h2, h3, h4, h5, h6 {
    -webkit-touch-callout: none; /* Disable iOS callout */
    -webkit-tap-highlight-color: transparent; /* Remove tap highlight */
}

/* Note Selection Tooltip */
.note-tooltip {
    position: absolute;
    background: #ffffff;
    border: 1px solid #dee2e6;
    border-radius: 6px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    z-index: 9999;
    padding: 8px;
    animation: fadeInUp 0.2s ease-out;
    max-width: 90vw;
}

.note-tooltip {
    /* NEW: Define a background color variable for reuse */
    --tooltip-bg: #ffffff;
    
    position: absolute;
    background: var(--tooltip-bg);
    border-radius: 6px;
    padding: 8px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    z-index: 10000;
}

.note-tooltip .btn {
    white-space: nowrap;
    font-size: 0.875rem;
}

/* Mobile-specific tooltip styling */
.note-tooltip.mobile {
    /* NEW: Override the background variable for mobile */
    --tooltip-bg: rgba(255, 255, 255, 0.95);

    position: fixed !important;
    padding: 12px;
    border-radius: 8px;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.25);
    z-index: 10001;
    backdrop-filter: blur(10px);
    background: var(--tooltip-bg);
}

.note-tooltip.mobile .btn {
    padding: 12px 20px;
    font-size: 1rem;
    font-weight: 500;
    border-radius: 6px;
    min-height: 44px;
    min-width: 44px;
}

/* 
 * CHANGED: Generic triangle setup.
 * The direction is now controlled by the classes below.
*/
.note-tooltip::after {
    content: '';
    position: absolute;
    left: 50%;
    transform: translateX(-50%);
    border: 6px solid transparent; /* Slightly larger for better visibility */
}

/* 
 * NEW: Style for when the tooltip is BELOW the text.
 * The triangle should point UP.
*/
.note-tooltip.tooltip-below::after {
    bottom: 100%; /* Position at the top of the tooltip */
    border-bottom-color: var(--tooltip-bg); /* Create an upward-pointing triangle */
}

/* Note Highlights */
.note-highlight {
    background-color: #fff3cd;
    border-bottom: 2px solid #ffc107;
    cursor: pointer;
    transition: all 0.2s ease;
    position: relative;
}

.note-highlight:hover {
    background-color: #ffb6c1;
    border-bottom-color: #ffb6c1;
}

.note-highlight::after {
    content: '📝';
    font-size: 0.7em;
    position: absolute;
    top: -8px;
    right: -2px;
    background: #ffc107;
    border-radius: 50%;
    width: 16px;
    height: 16px;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    transition: opacity 0.2s ease;
}

.note-highlight:hover::after {
    opacity: 1;
}

/* Note Modal */
.note-modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.5);
    z-index: 10000;
    display: flex;
    align-items: center;
    justify-content: center;
    animation: fadeIn 0.2s ease-out;
    padding: 10px;
}

.note-modal-content {
    background: #ffffff;
    border-radius: 8px;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.3);
    max-width: 500px;
    width: 100%;
    max-height: 90vh;
    overflow: auto;
    animation: slideInUp 0.3s ease-out;
}

/* Mobile modal adjustments */
@media (max-width: 576px) {
    .note-modal {
        align-items: flex-start;
        padding: 20px 10px;
    }
    
    .note-modal-content {
        margin-top: 10vh;
        border-radius: 12px;
        width: 100%;
        max-width: none;
    }
}

.note-modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1rem 1.5rem;
    border-bottom: 1px solid #dee2e6;
    background: #f8f9fa;
    border-radius: 8px 8px 0 0;
}

.note-modal-header h5 {
    margin: 0;
    color: #495057;
    font-weight: 600;
}

.note-modal-close {
    background: none;
    border: none;
    font-size: 1.5rem;
    line-height: 1;
    color: #6c757d;
    cursor: pointer;
    padding: 0;
    width: 30px;
    height: 30px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 4px;
    transition: all 0.2s ease;
}

.note-modal-close:hover {
    background: #e9ecef;
    color: #495057;
}

.note-modal-body {
    padding: 1.5rem;
}

.note-modal-footer {
    display: flex;
    justify-content: flex-end;
    gap: 0.5rem;
    padding: 1rem 1.5rem;
    border-top: 1px solid #dee2e6;
    background: #f8f9fa;
    border-radius: 0 0 8px 8px;
}

.selected-text {
    background: #e9ecef;
    padding: 0.5rem;
    border-radius: 4px;
    font-style: italic;
    color: #495057;
    border-left: 4px solid #007bff;
}

/* Note Popover */
.note-popover {
    position: absolute;
    background: #ffffff;
    border: 1px solid #dee2e6;
    border-radius: 8px;
    box-shadow: 0 6px 20px rgba(0, 0, 0, 0.15);
    z-index: 9999;
    max-width: 350px;
    animation: fadeInUp 0.2s ease-out;
}

.note-popover.mobile {
    position: fixed !important;
    max-width: 90vw;
    border-radius: 12px;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.25);
    z-index: 10001;
    backdrop-filter: blur(10px);
    background: rgba(255, 255, 255, 0.95);
}

.note-popover-content {
    padding: 0;
}

.note-popover-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.75rem 1rem;
    background: #f8f9fa;
    border-bottom: 1px solid #dee2e6;
    border-radius: 8px 8px 0 0;
}

.note-popover-header .text-muted{
    margin-right: 10px
}

.note-popover-actions {
    display: flex;
    gap: 0.25rem;
}

.note-popover-actions .btn {
    padding: 0.25rem 0.5rem;
    font-size: 0.75rem;
}

.note-popover-body {
    padding: 1rem;
}

.note-popover .selected-text {
    font-size: 0.85rem;
    margin-bottom: 0.5rem;
    background: #f8f9fa;
    border-left-color: #6c757d;
}

.note-content {
    color: #495057;
    line-height: 1.5;
}

/* Animations */
@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

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

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

/* Success Alert Positioning */
.alert.position-fixed {
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
}

/* Responsive Design */
@media (max-width: 576px) {
    .note-popover {
        max-width: 280px;
        position: fixed !important;
    }
    
    .note-modal-body,
    .note-modal-header,
    .note-modal-footer {
        padding: 1rem;
    }
    
    .note-modal-close {
        width: 40px;
        height: 40px;
        font-size: 1.2rem;
    }
    
    .note-popover-actions .btn {
        min-height: 36px;
        min-width: 36px;
        padding: 0.5rem;
    }
    
    /* Make highlighted text more touch-friendly */
    .note-highlight {
        padding: 2px 4px;
        margin: 1px;
        border-radius: 2px;
        min-height: 24px;
        display: inline-block;
    }
    
    /* Improve textarea on mobile */
    .note-modal-body textarea {
        font-size: 16px; /* Prevents zoom on iOS */
        min-height: 120px;
    }
    
    /* Better button spacing on mobile */
    .note-modal-footer {
        flex-direction: column-reverse;
        gap: 0.75rem;
    }
    
    .note-modal-footer .btn {
        width: 100%;
        padding: 12px;
        font-size: 1rem;
    }
}

/* Dark mode support */
@media (prefers-color-scheme: dark) {
    .note-tooltip,
    .note-modal-content,
    .note-popover {
        background: #343a40;
        color: #ffffff;
    }
    
    .note-modal-header,
    .note-modal-footer,
    .note-popover-header {
        background: lightblue;
        border-color: lightblue;
    }
    
    .selected-text {
        background: #495057;
        color: #ffffff;
    }
    
    .note-highlight {
        background-color: #ffb6c1;
        border-bottom-color: #ffb6c1;
    }
    
    .note-highlight:hover {
        background-color: #ffb6c1;
    }
}