/**
 * Span Annotation Styles
 *
 * This file contains all CSS for span annotation functionality.
 * Extracted from base_template_v2.html for maintainability.
 */

/* Robust Span Annotation Styling */
.span-highlight {
    position: relative;
    display: inline;
    border-radius: 4px;
    padding: 2px 4px;
    margin: 0 1px;
    cursor: pointer;
    transition: all 0.2s;
}

.span-highlight:hover {
    filter: brightness(0.9);
}

/* Nested spans get progressively smaller padding to show hierarchy */
.span-highlight .span-highlight {
    padding: 0px 1px !important;
    margin: 2px !important;
    border-radius: 2px !important;
    box-shadow: 0 1px 1px rgba(0,0,0,0.1) !important;
}

.span-highlight .span-highlight .span-highlight {
    padding: 0px 0px !important;
    margin: 3px !important;
    border-radius: 1px !important;
    box-shadow: none !important;
}

.span-delete {
    position: absolute;
    top: -8px;
    right: -8px;
    background: #dc3545;
    color: white;
    border: none;
    border-radius: 50%;
    width: 20px;
    height: 20px;
    font-size: 12px;
    cursor: pointer;
    display: none;
    align-items: center;
    justify-content: center;
    font-weight: bold;
    z-index: 15;
}

.span-highlight:hover .span-delete {
    display: flex;
}

/* Nested span delete buttons are positioned closer */
.span-highlight .span-highlight .span-delete {
    top: -10px !important;
    right: -10px !important;
    width: 22px !important;
    height: 22px !important;
    font-size: 13px !important;
    z-index: 25 !important;
}

.span-highlight .span-highlight .span-highlight .span-delete {
    top: -8px !important;
    right: -8px !important;
    width: 20px !important;
    height: 20px !important;
    font-size: 12px !important;
    z-index: 35 !important;
}

.span-label {
    position: absolute;
    top: -25px;
    left: 0;
    background: #333;
    color: white;
    padding: 2px 6px;
    border-radius: 3px;
    font-size: 12px;
    white-space: nowrap;
}

/* Instance text height limit styles */
.instance-text-container {
    position: relative;
    overflow: hidden;
}

.instance-text-container.max-height-limited {
    max-height: var(--max-instance-height, none);
    overflow-y: auto;
    overflow-x: hidden;
}

.instance-text-container.max-height-limited::-webkit-scrollbar {
    width: 8px;
}

.instance-text-container.max-height-limited::-webkit-scrollbar-track {
    background: #f1f1f1;
    border-radius: 4px;
}

.instance-text-container.max-height-limited::-webkit-scrollbar-thumb {
    background: #c1c1c1;
    border-radius: 4px;
}

.instance-text-container.max-height-limited::-webkit-scrollbar-thumb:hover {
    background: #a8a8a8;
}

/* Span manager labels should be visible by default */
/* BUG FIX: JS creates span-overlay-pure, not span-overlay - target both */
.span-overlay .span-label,
.span-overlay-pure .span-label,
.span-overlay-ai .span-label {
    display: block !important;
}

/* Span manager delete buttons should be visible by default */
.span-overlay .span-delete-btn,
.span-overlay-pure .span-delete-btn,
.span-overlay-ai .span-delete-btn {
    display: block !important;
}

.span-tooltip {
    display: none;
    position: absolute;
    top: -30px;
    left: 0;
    background: #333;
    color: #fff;
    padding: 2px 6px;
    border-radius: 3px;
    font-size: 12px;
    white-space: nowrap;
    z-index: 100;
}

.span-highlight:hover .span-label {
    display: block;
}

/* Nested span labels are positioned higher to avoid overlap */
.span-highlight .span-highlight .span-label {
    top: -30px !important;
    z-index: 20 !important;
}

.span-highlight .span-highlight .span-highlight .span-label {
    top: -35px !important;
    z-index: 30 !important;
}

/* Text container styling for span annotation */
#instance-text {
    position: relative;
    cursor: text;
    user-select: text;
    line-height: 1.8;
    font-size: 18px;
    /* Allow span controls to render above text */
    overflow: visible;
    padding-top: 28px; /* Space for controls above first line */
}

/* Span overlays container must allow overflow for controls */
#span-overlays {
    overflow: visible !important;
}

/* Span overlay containers allow controls to render outside bounds */
.span-overlay-pure,
.span-overlay-ai {
    overflow: visible;
}

/* Span controls container styling */
.span-controls {
    white-space: nowrap;
}

/* --------------------------------------------------------------------------
   Overlapping codes

   A chip sits 22px above the line it labels, which at line-height 1.8 lands on
   the glyphs of the line above. Coding a passage with several overlapping codes
   — the normal case in qualitative work, not an edge case — then papers the
   text over with chips. Two things fix it: a gutter tall enough for a chip to
   live in, and collapsing chips that would still collide with each other.
   -------------------------------------------------------------------------- */

/* Opened only when labels are actually being drawn, so span tasks without
   labels keep the tighter setting. Set by SpanManager on the text container. */
#instance-text.span-labels-on,
.span-labels-on {
    line-height: 2.35;
}

/* The second and later chips of a collision become a colour dot. The code is
   still identifiable (colour, tooltip, accessible name) and the text stays
   readable; hovering or focusing restores the full chip. */
.span-controls.is-compact .span-label {
    width: 12px;
    height: 12px;
    min-width: 12px;
    padding: 0;
    border-radius: 50%;
    background-color: var(--span-colour, rgba(0, 0, 0, 0.85)) !important;
    border: 1px solid rgba(0, 0, 0, 0.35);
    color: transparent;
    overflow: hidden;
    text-indent: -999px;
}

.span-controls.is-compact .span-delete-btn {
    display: none;
}

.span-controls.is-compact:hover .span-label,
.span-controls.is-compact:focus-within .span-label {
    width: auto;
    height: auto;
    min-width: 0;
    padding: 2px 6px;
    border-radius: 3px;
    background-color: rgba(0, 0, 0, 0.85) !important;
    border: none;
    color: #fff;
    text-indent: 0;
}

.span-controls.is-compact:hover .span-delete-btn,
.span-controls.is-compact:focus-within .span-delete-btn {
    display: inline-flex;
}

/* A collapsed chip that is hovered has to sit above its neighbours, or it
   expands underneath them and is unreadable again. */
.span-controls.is-compact:hover,
.span-controls.is-compact:focus-within {
    z-index: 40 !important;
}

#instance-text:focus {
    outline: none;
    border-color: #007bff;
}

/* ==========================================================================
   Discontinuous Span Styles
   ========================================================================== */

/* Hint text shown when discontinuous mode is enabled */
.discontinuous-hint {
    font-size: 12px;
    color: #666;
    font-style: italic;
    margin-bottom: 8px;
    padding: 4px 8px;
    background-color: #f0f8ff;
    border-left: 3px solid #007bff;
    border-radius: 2px;
}

/* Discontinuous span parts have dashed borders */
.span-highlight.discontinuous-part {
    border-style: dashed !important;
    border-width: 2px !important;
}

/* Overlay segments for discontinuous parts */
.discontinuous-segment {
    border-style: dashed !important;
}

/* Label for additional discontinuous parts */
.span-label.discontinuous-label {
    font-size: 10px !important;
    padding: 1px 4px !important;
    background-color: rgba(0, 0, 0, 0.7) !important;
}

/* Visual indicator when span is enabled for discontinuous extension */
.span-overlay-pure.discontinuous-enabled::after {
    content: '+';
    position: absolute;
    right: -8px;
    top: -8px;
    background-color: #007bff;
    color: white;
    width: 16px;
    height: 16px;
    border-radius: 50%;
    font-size: 12px;
    font-weight: bold;
    display: flex;
    align-items: center;
    justify-content: center;
    pointer-events: none;
}

/* Hover effect for discontinuous parts - highlight all parts of same span */
.span-highlight[data-discontinuous="true"]:hover,
.span-overlay-pure.discontinuous-part:hover {
    filter: brightness(0.85);
}

/* Connected parts indicator - shows dotted line between parts */
.span-highlight.discontinuous-part::before {
    content: '';
    position: absolute;
    left: -20px;
    top: 50%;
    width: 16px;
    height: 2px;
    background: repeating-linear-gradient(
        to right,
        currentColor 0px,
        currentColor 4px,
        transparent 4px,
        transparent 8px
    );
    opacity: 0.5;
}
