/**
 * Matrix Interactive Tooltip / Bottom-sheet Styles
 * Glassmorphism design, mobile-first
 */

/* ============================
   CURSOR & HIT AREA
   ============================ */
#matrix .matrix-value-point {
    cursor: pointer;
    pointer-events: all;
}

#matrix circle {
    cursor: pointer;
    pointer-events: all;
}

/* Active point pulse animation */
@keyframes matrixPointPulse {
    0% {
        filter: drop-shadow(0 0 4px rgba(168, 85, 247, 0.4));
    }

    50% {
        filter: drop-shadow(0 0 12px rgba(168, 85, 247, 0.8));
    }

    100% {
        filter: drop-shadow(0 0 4px rgba(168, 85, 247, 0.4));
    }
}

#matrix .matrix-point-active {
    animation: matrixPointPulse 1.5s ease-in-out infinite;
}

#matrix circle.matrix-point-active {
    stroke: #a855f7 !important;
    stroke-width: 3px !important;
}

/* ============================
   BACKDROP (mobile)
   ============================ */
.matrix-tooltip-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.4);
    backdrop-filter: blur(2px);
    -webkit-backdrop-filter: blur(2px);
    z-index: 998;
    opacity: 0;
    transition: opacity 0.25s ease;
}

.matrix-tooltip-backdrop[style*="display: none"]+.mpt-visible~.matrix-tooltip-backdrop,
.mpt-visible~.matrix-tooltip-backdrop {
    opacity: 1;
}

/* ============================
   TOOLTIP — BASE
   ============================ */
.matrix-point-tooltip {
    position: fixed;
    z-index: 999;
    background: rgba(17, 12, 34, 0.92);
    backdrop-filter: blur(20px) saturate(180%);
    -webkit-backdrop-filter: blur(20px) saturate(180%);
    border: 1px solid rgba(168, 85, 247, 0.3);
    border-radius: 16px;
    padding: 0;
    min-width: 280px;
    max-width: 360px;
    box-shadow:
        0 8px 32px rgba(0, 0, 0, 0.5),
        0 0 0 1px rgba(168, 85, 247, 0.1),
        inset 0 1px 0 rgba(255, 255, 255, 0.05);
    opacity: 0;
    transform: scale(0.95) translateY(8px);
    transition: opacity 0.2s ease, transform 0.2s ease;
    overflow: hidden;
    font-family: 'Inter', 'Segoe UI', -apple-system, sans-serif;
}

.matrix-point-tooltip.mpt-visible {
    opacity: 1;
    transform: scale(1) translateY(0);
}

/* ============================
   TOOLTIP — HEADER
   ============================ */
.mpt-header {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 16px 16px 12px;
    border-bottom: 1px solid rgba(168, 85, 247, 0.15);
}

.mpt-energy-badge {
    flex-shrink: 0;
    width: 44px;
    height: 44px;
    border-radius: 50%;
    background: linear-gradient(135deg, #7c3aed, #a855f7, #c084fc);
    color: #fff;
    font-size: 18px;
    font-weight: 800;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 2px 12px rgba(124, 58, 237, 0.4);
}

.mpt-title {
    flex: 1;
    color: #e2e0ff;
    font-size: 13px;
    font-weight: 600;
    line-height: 1.3;
}

.mpt-close {
    flex-shrink: 0;
    width: 28px;
    height: 28px;
    border-radius: 50%;
    border: none;
    background: rgba(255, 255, 255, 0.06);
    color: rgba(255, 255, 255, 0.5);
    font-size: 18px;
    line-height: 1;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.15s, color 0.15s;
}

.mpt-close:hover {
    background: rgba(255, 255, 255, 0.12);
    color: #fff;
}

/* ============================
   TOOLTIP — SECTIONS LIST
   ============================ */
.mpt-sections {
    padding: 8px;
    max-height: 260px;
    overflow-y: auto;
    scrollbar-width: thin;
    scrollbar-color: rgba(168, 85, 247, 0.3) transparent;
}

.mpt-sections::-webkit-scrollbar {
    width: 4px;
}

.mpt-sections::-webkit-scrollbar-track {
    background: transparent;
}

.mpt-sections::-webkit-scrollbar-thumb {
    background: rgba(168, 85, 247, 0.3);
    border-radius: 4px;
}

.mpt-section-item {
    display: flex;
    align-items: flex-start;
    gap: 12px;
    padding: 10px 12px;
    border-radius: 10px;
    transition: background 0.15s;
}

.mpt-section-item:hover {
    background: rgba(168, 85, 247, 0.08);
}

.mpt-section-icon {
    flex-shrink: 0;
    font-size: 20px;
    line-height: 1;
    margin-top: 1px;
}

.mpt-section-text {
    display: flex;
    flex-direction: column;
    gap: 2px;
    min-width: 0;
}

.mpt-section-title {
    color: #e2e0ff;
    font-size: 13px;
    font-weight: 600;
    line-height: 1.3;
}

.mpt-section-desc {
    color: rgba(200, 195, 230, 0.6);
    font-size: 11px;
    font-weight: 400;
    line-height: 1.4;
}

/* Edge point special style */
.mpt-edge-item .mpt-section-title {
    color: #c084fc;
}

/* ============================
   MOBILE — BOTTOM SHEET
   ============================ */
.matrix-point-tooltip.mpt-mobile {
    position: fixed;
    left: 0 !important;
    right: 0;
    bottom: 0 !important;
    top: auto !important;
    max-width: 100%;
    min-width: 100%;
    border-radius: 20px 20px 0 0;
    max-height: 50vh;
    transform: translateY(100%);
    opacity: 1;
    transition: transform 0.3s cubic-bezier(0.32, 0.72, 0, 1);
    padding-bottom: env(safe-area-inset-bottom, 16px);
}

.matrix-point-tooltip.mpt-mobile.mpt-visible {
    transform: translateY(0);
}

/* Mobile: drag handle at top */
.matrix-point-tooltip.mpt-mobile .mpt-header::before {
    content: '';
    position: absolute;
    top: 8px;
    left: 50%;
    transform: translateX(-50%);
    width: 40px;
    height: 4px;
    border-radius: 4px;
    background: rgba(255, 255, 255, 0.2);
}

.matrix-point-tooltip.mpt-mobile .mpt-header {
    padding-top: 24px;
    position: relative;
}

.matrix-point-tooltip.mpt-mobile .mpt-sections {
    max-height: calc(50vh - 100px);
    padding-bottom: 16px;
}

.matrix-point-tooltip.mpt-mobile .mpt-section-item {
    padding: 12px 16px;
}

/* Mobile: larger touch targets */
@media (max-width: 768px) {
    .mpt-close {
        width: 36px;
        height: 36px;
        font-size: 22px;
    }

    .mpt-energy-badge {
        width: 48px;
        height: 48px;
        font-size: 20px;
    }

    .mpt-section-icon {
        font-size: 24px;
    }

    .mpt-section-title {
        font-size: 14px;
    }

    .mpt-section-desc {
        font-size: 12px;
    }
}

/* Ensure backdrop shows when tooltip is visible */
body:has(.matrix-point-tooltip.mpt-mobile.mpt-visible) .matrix-tooltip-backdrop {
    opacity: 1;
}

/* ============================
   RICH CONTENT — LARGER PANEL
   ============================ */
.matrix-point-tooltip.mpt-rich {
    max-width: 480px;
    min-width: 340px;
}

.matrix-point-tooltip.mpt-rich .mpt-sections {
    max-height: 420px;
    padding: 4px;
}

/* ============================
   LOADING SPINNER
   ============================ */
.mpt-loading {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 12px;
    padding: 32px 16px;
    color: rgba(200, 195, 230, 0.7);
    font-size: 13px;
}

.mpt-loading-spinner {
    width: 20px;
    height: 20px;
    border: 2px solid rgba(168, 85, 247, 0.2);
    border-top-color: #a855f7;
    border-radius: 50%;
    animation: mptSpin 0.8s linear infinite;
}

@keyframes mptSpin {
    to {
        transform: rotate(360deg);
    }
}

/* ============================
   ACCORDION — SECTION HEADERS
   ============================ */
.mpt-accordion {
    border-radius: 10px;
    margin-bottom: 4px;
    overflow: hidden;
    transition: background 0.2s ease;
}

.mpt-accordion:hover {
    background: rgba(168, 85, 247, 0.05);
}

.mpt-accordion-header {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 12px;
    width: 100%;
    border: none;
    background: none;
    cursor: pointer;
    text-align: left;
    color: inherit;
    font-family: inherit;
    transition: background 0.15s;
    border-radius: 10px;
}

.mpt-accordion-header:hover {
    background: rgba(168, 85, 247, 0.1);
}

.mpt-accordion-header .mpt-section-icon {
    flex-shrink: 0;
    font-size: 18px;
    line-height: 1;
}

.mpt-accordion-title {
    flex: 1;
    color: #e2e0ff;
    font-size: 13px;
    font-weight: 600;
    line-height: 1.3;
    min-width: 0;
}

.mpt-accordion-energy {
    flex-shrink: 0;
    font-size: 11px;
    color: rgba(168, 85, 247, 0.7);
    font-weight: 500;
    background: rgba(168, 85, 247, 0.1);
    padding: 2px 8px;
    border-radius: 12px;
}

.mpt-accordion-chevron {
    flex-shrink: 0;
    width: 14px;
    height: 14px;
    color: rgba(200, 195, 230, 0.4);
    transition: transform 0.25s ease;
}

.mpt-accordion-open .mpt-accordion-chevron {
    transform: rotate(180deg);
}

/* ============================
   ACCORDION — BODY / CONTENT
   ============================ */
.mpt-accordion-body {
    overflow: hidden;
}

.mpt-content-html {
    padding: 4px 12px 16px 42px;
    /* indent to align with title */
    color: rgba(220, 215, 245, 0.85);
    font-size: 13px;
    line-height: 1.65;
}

.mpt-content-html p {
    margin-bottom: 10px;
}

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

.mpt-content-html h1,
.mpt-content-html h2,
.mpt-content-html h3,
.mpt-content-html h4 {
    color: #c4b5fd;
    margin-top: 12px;
    margin-bottom: 6px;
    font-weight: 600;
}

.mpt-content-html h3 {
    font-size: 14px;
}

.mpt-content-html h4 {
    font-size: 13px;
}

.mpt-content-html ul,
.mpt-content-html ol {
    padding-left: 18px;
    margin-bottom: 10px;
}

.mpt-content-html li {
    margin-bottom: 4px;
}

.mpt-content-html strong,
.mpt-content-html b {
    color: #e2e0ff;
    font-weight: 600;
}

.mpt-content-html em,
.mpt-content-html i {
    color: #c4b5fd;
    font-style: italic;
}

.mpt-content-html a {
    color: #a855f7;
    text-decoration: underline;
    text-underline-offset: 2px;
}

.mpt-content-html a:hover {
    color: #c084fc;
}

/* Scrollbar for rich content */
.mpt-rich .mpt-sections::-webkit-scrollbar {
    width: 5px;
}

.mpt-rich .mpt-sections::-webkit-scrollbar-thumb {
    background: rgba(168, 85, 247, 0.35);
    border-radius: 5px;
}

/* No content placeholder */
.mpt-no-content {
    padding: 16px;
    text-align: center;
    color: rgba(200, 195, 230, 0.5);
    font-size: 12px;
    font-style: italic;
}

/* ============================
   MOBILE — RICH CONTENT BOTTOM SHEET
   ============================ */
.matrix-point-tooltip.mpt-mobile.mpt-rich {
    max-height: 75vh;
}

.matrix-point-tooltip.mpt-mobile.mpt-rich .mpt-sections {
    max-height: calc(75vh - 100px);
}

.matrix-point-tooltip.mpt-mobile .mpt-content-html {
    padding-left: 16px;
    font-size: 14px;
    line-height: 1.7;
}

@media (max-width: 768px) {
    .mpt-accordion-header {
        padding: 12px 16px;
    }

    .mpt-accordion-title {
        font-size: 14px;
    }

    .mpt-accordion-energy {
        font-size: 12px;
    }
}