/**
 * Rich Text Inline Formatting CSS
 *
 * Styles for inline text formatting within grid cells.
 * Supports: text color, bold, italic, background highlight, strikethrough
 *
 * Created: 2025-12-11
 * Phase 1: Core Infrastructure
 */

/* ============================================
   RICH TEXT SPANS
   ============================================ */

/* Rich text formatted spans - base class */
.rt-fmt {
    /* Inherit most properties from parent */
    font-family: inherit;
    font-size: inherit;
    line-height: inherit;
}

/* Ensure spans don't break layout in table cells */
td .rt-fmt {
    display: inline;
}

/* Ensure proper word wrapping with spans */
td .rt-fmt {
    word-wrap: break-word;
    word-break: break-word;
}

/* ============================================
   EDITING STATE
   ============================================ */

/* Visual indicator during editing (optional hover effect) */
td.editing .rt-fmt:hover {
    outline: 1px dashed #3b82f6;
    outline-offset: 1px;
}

/* Selection highlight in editable cells */
td.editing::selection,
td.editing *::selection {
    background-color: #bfdbfe;
}

/* Contenteditable cursor styling */
td[contenteditable="true"] {
    caret-color: #1f2937;
}

/* ============================================
   FORMATTING CLASSES
   ============================================ */

/* Bold */
.rt-fmt.rt-bold,
.rt-fmt[style*="font-weight: bold"],
.rt-fmt[style*="font-weight:bold"] {
    font-weight: bold;
}

/* Italic */
.rt-fmt.rt-italic,
.rt-fmt[style*="font-style: italic"],
.rt-fmt[style*="font-style:italic"] {
    font-style: italic;
}

/* Underline */
.rt-fmt.rt-underline,
.rt-fmt[style*="text-decoration: underline"],
.rt-fmt[style*="text-decoration:underline"] {
    text-decoration: underline;
}

/* Strikethrough */
.rt-fmt.rt-strike,
.rt-fmt[style*="text-decoration: line-through"],
.rt-fmt[style*="text-decoration:line-through"] {
    text-decoration: line-through;
}

/* ============================================
   NESTED FORMATTING
   ============================================ */

/* Support for nested spans (e.g., bold + italic) */
.rt-fmt .rt-fmt {
    display: inline;
}

/* Nested formatting shouldn't add extra spacing */
td .rt-fmt .rt-fmt {
    margin: 0;
    padding: 0;
}

/* ============================================
   CELL INTERACTION
   ============================================ */

/* When cell has rich content, ensure proper display */
td.has-rich-content {
    /* Marker class for cells with rich formatting */
}

/* Don't allow rich content to overflow cell boundaries */
td .rt-fmt {
    max-width: 100%;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* But allow wrapping within cells that support it */
td.wrap-text .rt-fmt {
    white-space: normal;
    overflow: visible;
    text-overflow: clip;
}

/* ============================================
   LOADING STATES
   ============================================ */

/* Placeholder for cells loading rich content */
td.loading-rich-content {
    position: relative;
}

td.loading-rich-content::after {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 12px;
    height: 12px;
    border: 2px solid #e5e7eb;
    border-top-color: #3b82f6;
    border-radius: 50%;
    animation: rt-spin 0.8s linear infinite;
}

@keyframes rt-spin {
    to {
        transform: translate(-50%, -50%) rotate(360deg);
    }
}

/* ============================================
   REAL-TIME SYNC INDICATORS
   ============================================ */

/* Cell being updated by remote user */
td.rt-remote-update {
    animation: rt-pulse 0.3s ease-out;
}

@keyframes rt-pulse {
    0% {
        background-color: rgba(59, 130, 246, 0.2);
    }
    100% {
        background-color: transparent;
    }
}

/* ============================================
   PRINT STYLES
   ============================================ */

@media print {
    /* Ensure rich text formatting is preserved in print */
    .rt-fmt {
        display: inline !important;
    }

    /* Remove editing-related styles */
    td.editing .rt-fmt:hover {
        outline: none;
    }

    /* Ensure colors print correctly */
    .rt-fmt[style*="color"] {
        -webkit-print-color-adjust: exact;
        print-color-adjust: exact;
    }

    .rt-fmt[style*="background"] {
        -webkit-print-color-adjust: exact;
        print-color-adjust: exact;
    }
}

/* ============================================
   ACCESSIBILITY
   ============================================ */

/* High contrast mode support */
@media (prefers-contrast: high) {
    .rt-fmt {
        /* Ensure sufficient contrast */
        text-shadow: none;
    }
}

/* Reduced motion preference */
@media (prefers-reduced-motion: reduce) {
    td.loading-rich-content::after {
        animation: none;
    }

    td.rt-remote-update {
        animation: none;
    }
}
