/**
   * Tooltip Styles for Fire Safety Document
   * Provides interactive definitions for glossary terms and section references
   */

/* ===== ENRICHED SPAN STYLING ===== */

.glossary-term {
    border-bottom: 1px dotted var(--doc-secondary-color, #2563eb);
    cursor: help;
    color: inherit;
    text-decoration: none;
    position: relative;
}

.glossary-term:hover,
.glossary-term:focus {
    border-bottom-color: var(--doc-primary-color, #1d4ed8);
    background-color: color-mix(in srgb, var(--doc-secondary-color, #2563eb) 8%, transparent);
}

.section-ref {
    color: var(--doc-secondary-color, #2563eb);
    cursor: pointer;
    text-decoration: none;
    border-bottom: 1px solid transparent;
    font-weight: 500;
}

.section-ref:hover,
.section-ref:focus {
    text-decoration: underline;
    border-bottom-color: var(--doc-secondary-color, #2563eb);
    background-color: color-mix(in srgb, var(--doc-secondary-color, #2563eb) 8%, transparent);
}

/* ===== TOOLTIP CONTAINER ===== */

.tooltip-container {
    display: none; /* Hidden by default */
    position: fixed;
    z-index: 10000; /* Above all content */
    max-width: 820px;
    background: white;
    border: 1px solid #d1d5db;
    border-radius: 8px;
    box-shadow: 0 10px 25px rgba(0, 0, 0, 0.15);
    padding: 0;
    animation: tooltipFadeIn var(--duration-fast) var(--ease-out);
}

.tooltip-container.visible {
    display: block;
}

@keyframes tooltipFadeIn {
    from {
        opacity: 0;
        transform: translateY(-5px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* ===== TOOLTIP HEADER ===== */

.tooltip-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px 16px;
    background-color: #f3f4f6;
    border-bottom: 1px solid #e5e7eb;
    border-radius: 8px 8px 0 0;
}

.tooltip-title {
    font-weight: var(--font-semibold);
    font-size: 14px;
    color: #1f2937;
    margin: 0;
}

.tooltip-close {
    background: none;
    border: none;
    cursor: pointer;
    font-size: 20px;
    line-height: 1;
    color: #6b7280;
    padding: 0;
    width: 24px;
    height: 24px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 4px;
    transition: background-color var(--duration-fast) var(--ease-out);
}

.tooltip-close:hover {
    background-color: #e5e7eb;
    color: #1f2937;
}

/* ===== TOOLTIP CONTENT ===== */

.tooltip-content {
    padding: 16px;
    max-height: 400px;
    overflow-y: auto;
    font-size: 14px;
    line-height: 1.6;
    color: #374151;
}

.tooltip-content.scrollable {
    /* Indicates scrollable content */
    border-left: 3px solid #e5e7eb;
    padding-left: 13px; /* Compensate for border */
}

/* Style content within tooltips */
.tooltip-content p {
    margin: 0 0 0.75em 0;
}

.tooltip-content p:last-child {
    margin-bottom: 0;
}

.tooltip-content ul,
.tooltip-content ol {
    margin: 0.5em 0;
    padding-left: 1.5em;
}

.tooltip-content li {
    margin-bottom: 0.25em;
}

/* Constrain figure images to fit within tooltip without scrolling */
.tooltip-content img {
    max-width: 100%;
    max-height: calc(70vh - 100px); /* Viewport height minus header, padding, caption space */
    width: auto;
    height: auto;
    object-fit: contain;
    display: block;
    margin: 0 auto; /* Center images */
}

.tooltip-content table {
    width: 100%;
    border-collapse: collapse;
    margin: 0.5em 0;
    font-size: 13px;
}

.tooltip-content table th,
.tooltip-content table td {
    border: 1px solid #e5e7eb;
    padding: 6px 8px;
    text-align: left;
}

.tooltip-content table th {
    /*background-color: #f9fafb;*/
    font-weight: var(--font-semibold);
}

.tooltip-content strong {
    font-weight: var(--font-semibold);
    color: #1f2937;
}

.tooltip-content em {
    font-style: italic;
}

/* ===== TOOLTIP TYPE INDICATORS ===== */

.tooltip-type-glossary .tooltip-header {
    background-color: #eff6ff; /* Light blue for glossary */
    border-bottom-color: #dbeafe;
}

.tooltip-type-section .tooltip-header {
    background-color: #f0fdf4; /* Light green for sections */
    border-bottom-color: #dcfce7;
}

/* ===== MOBILE RESPONSIVENESS ===== */

@media (max-width: 768px) {
    .tooltip-container {
        max-width: calc(100vw - 32px); /* Full width minus margins */
        left: 16px !important;
        right: 16px !important;
        bottom: 16px !important;
        top: auto !important;
        transform: none !important;
    }

    .tooltip-content {
        max-height: 50vh; /* Limit height on mobile */
    }

    .tooltip-content img {
        max-height: calc(45vh - 80px); /* Smaller constraint for mobile 50vh tooltip */
    }
}

/* ===== ACCESSIBILITY ===== */

.glossary-term:focus-visible,
.section-ref:focus-visible {
    outline: 2px solid var(--doc-secondary-color, #2563eb);
    outline-offset: 2px;
    border-radius: 2px;
}

/* Ensure sufficient contrast */
.tooltip-container {
    color: #1f2937;
}

/* Scrollbar styling for tooltips */
.tooltip-content::-webkit-scrollbar {
    width: 8px;
}

.tooltip-content::-webkit-scrollbar-track {
    background: #f3f4f6;
    border-radius: 4px;
}

.tooltip-content::-webkit-scrollbar-thumb {
    background: #d1d5db;
    border-radius: 4px;
}

.tooltip-content::-webkit-scrollbar-thumb:hover {
    background: #9ca3af;
}
