/**
 * Shared market / match tooltips — hover on fine pointer, tap + bottom sheet on touch.
 */

.tooltip-container {
    position: relative;
    cursor: help;
}

/*
 * Stacking / clipping root causes (Predictions Form column):
 * 1) `.match-row:hover { transform }` creates a per-row stacking context so
 *    absolute tips paint under later rows' badges.
 * 2) `.mobile-card-details { overflow: hidden }` (expand animation) clips tips.
 * Row elevation helps (1) for in-row siblings. Form tips with match_href are
 * also portaled to #market-form-float-root (fixed) by market-tooltips.js so they
 * escape both stacking and overflow clipping. Do not "fix" with tip z-index alone.
 */
.tooltip-container:hover,
.tooltip-container:focus-within,
.tooltip-container.tooltip-open {
    z-index: 30;
}

tr.match-row:has(.tooltip-container:hover),
tr.match-row:has(.tooltip-container:focus-within),
tr.match-row:has(.tooltip-container.tooltip-open),
.match-row.mobile-card:has(.tooltip-container:hover),
.match-row.mobile-card:has(.tooltip-container:focus-within),
.match-row.mobile-card:has(.tooltip-container.tooltip-open) {
    position: relative;
    z-index: 40;
}

/* Portaled form tips — escape table/card overflow + stacking contexts */
.market-form-float-root {
    position: absolute;
    top: 0;
    left: 0;
    width: 0;
    height: 0;
    overflow: visible;
    pointer-events: none;
    z-index: 10050;
}

.market-form-float-root .tooltip-content.is-floating {
    position: fixed;
    /* JS assigns final left/top while hidden, then reveals — never animate position. */
    transition: none !important;
    transform: none !important;
    bottom: auto;
    z-index: 10051;
    pointer-events: auto;
}

.market-form-float-root .tooltip-content.is-floating.is-visible {
    visibility: visible;
    opacity: 1;
}

.market-form-float-root .tooltip-content.is-floating.is-touch-sheet {
    left: 10px;
    right: 10px;
    top: auto;
    /* Clear sticky market bottom nav — was sitting too low over content/nav */
    bottom: calc(12px + var(--bottom-nav-offset, 4.5rem));
    width: min(320px, calc(100vw - 20px));
    max-width: min(320px, calc(100vw - 20px));
    margin: 0 auto;
    max-height: min(420px, 60vh);
    overflow: auto;
}

.market-form-float-root .tooltip-content.is-floating::after {
    display: none;
}

/* In-place CSS hover tip disabled for all lazy market tips (JS portal owns display).
   Covers BTTS/Win/Corners/Cards H2H plus Recent Form — same float root. */
.lazy-market-tooltip.form-tip-floating > .tooltip-content,
.lazy-market-tooltip[data-lazy-tooltip]:hover > .tooltip-content {
    visibility: hidden !important;
    opacity: 0 !important;
    pointer-events: none !important;
}

.tooltip-container.lazy-market-tooltip[data-lazy-tooltip*='"match_href": "/'] {
    cursor: pointer;
}

.form-match-tooltip__venue {
    text-align: center;
    font-size: 11px;
    font-weight: 600;
    color: #9ca3af;
    padding: 0 12px 10px;
}

.tooltip-content {
    visibility: hidden;
    position: absolute;
    bottom: 135%;
    left: 50%;
    transform: translateX(-50%);
    width: 280px;
    background-color: #2a2a2a;
    border-radius: 8px;
    padding: 0;
    z-index: 999999;
    box-shadow: 0 8px 25px rgba(0, 0, 0, 0.4);
    opacity: 0;
    transition: all 0.2s cubic-bezier(0.165, 0.84, 0.44, 1);
    border: 1px solid #444;
    pointer-events: none;
    color: #eee;
}

@media (hover: hover) and (pointer: fine) {
    .tooltip-container:hover .tooltip-content {
        visibility: visible;
        opacity: 1;
        bottom: 145%;
    }

    #matches_table td:last-child .tooltip-content,
    #matches_table th:last-child .tooltip-content {
        left: auto;
        right: 0;
        transform: none;
    }

    #matches_table td:last-child .tooltip-content::after,
    #matches_table th:last-child .tooltip-content::after {
        left: auto;
        right: 16px;
        margin-left: 0;
    }

    #matches_table tbody tr:nth-child(-n+3) td:last-child .tooltip-content {
        top: 145%;
        bottom: auto;
    }

    #matches_table tbody tr:nth-child(-n+3) td:last-child .tooltip-content::after {
        bottom: 100%;
        top: auto;
        border-color: transparent transparent #2a2a2a transparent;
    }
}

html.tooltip-any-open::before {
    content: "";
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.45);
    /* Below .market-form-float-root (10050) so the tip is not washed dark in light mode */
    z-index: 10040;
    pointer-events: none;
}

.tooltip-overlay-backdrop {
    position: fixed;
    inset: 0;
    /* Above dimmer, below portaled tip (10051) — dismiss taps, tip stays interactive */
    z-index: 10045;
    background: transparent;
}

@media (hover: none), (pointer: coarse) {
    .tooltip-container {
        cursor: pointer;
    }

    .tooltip-container:hover .tooltip-content {
        visibility: hidden;
        opacity: 0;
    }

    .tooltip-container.tooltip-open .tooltip-content {
        visibility: visible;
        opacity: 1;
    }

    .tooltip-content {
        position: fixed;
        left: 10px;
        right: 10px;
        top: auto;
        bottom: calc(12px + var(--bottom-nav-offset, 4.5rem));
        transform: none;
        margin: 0 auto;
        width: min(320px, calc(100vw - 20px));
        max-width: min(320px, calc(100vw - 20px));
        z-index: 1000000;
        max-height: min(420px, 60vh);
        overflow: auto;
        pointer-events: auto;
        will-change: opacity;
        transition: opacity 0.14s ease;
    }

    .tooltip-content::after {
        display: none;
    }
}

@media (max-width: 768px) and ((hover: none), (pointer: coarse)) {
    .tooltip-content {
        left: 10px;
        right: 10px;
        bottom: calc(10px + var(--bottom-nav-offset, 4.5rem));
        width: min(280px, calc(100vw - 20px));
        max-width: min(280px, calc(100vw - 20px));
    }

    .tooltip-header {
        padding: 8px 12px;
    }

    .tooltip-match {
        padding: 10px 12px;
    }

    .tooltip-score {
        font-size: 12px;
        padding: 4px 8px;
    }

    .tooltip-stats {
        padding: 0 12px 10px;
    }

    .stat-row {
        font-size: 11px;
    }

    .tooltip-result {
        padding: 7px;
        font-size: 10px;
    }
}

.enhanced-table tbody tr:nth-child(-n+3) .tooltip-content {
    bottom: auto;
    top: 135%;
}

@media (hover: hover) and (pointer: fine) {
    .enhanced-table tbody tr:nth-child(-n+3) .tooltip-container:hover .tooltip-content {
        bottom: auto;
        top: 145%;
    }

    .enhanced-table tbody tr:nth-child(-n+2) .tooltip-content {
        bottom: auto;
        top: 135%;
    }

    .enhanced-table tbody tr:nth-child(-n+2) .tooltip-container:hover .tooltip-content {
        bottom: auto;
        top: 145%;
    }
}

.tooltip-content::after {
    content: "";
    position: absolute;
    left: 50%;
    margin-left: -8px;
    border-width: 8px;
    border-style: solid;
    top: 100%;
    border-color: #2a2a2a transparent transparent transparent;
}

.enhanced-table tbody tr:nth-child(-n+3) .tooltip-content::after,
.enhanced-table tbody tr:nth-child(-n+2) .tooltip-content::after {
    top: auto;
    bottom: 100%;
    border-color: transparent transparent #2a2a2a transparent;
}

.tooltip-header {
    background: #1a1a1a;
    padding: 10px 15px;
    border-bottom: 1px solid #333;
    border-radius: 8px 8px 0 0;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.tooltip-league {
    font-size: 11px;
    font-weight: 700;
    color: #aaa;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.tooltip-date {
    font-size: 11px;
    color: #888;
    background: #333;
    padding: 2px 6px;
    border-radius: 4px;
    border: 1px solid #444;
}

.tooltip-match {
    padding: 15px 10px;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.tooltip-team {
    display: flex;
    flex-direction: column;
    align-items: center;
    width: 80px;
    text-align: center;
}

.tooltip-team img {
    width: 36px;
    height: 36px;
    object-fit: contain;
    margin-bottom: 6px;
}

.tooltip-team span {
    font-size: 10px;
    line-height: 1.2;
    color: #fff;
    font-weight: 600;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.tooltip-score {
    font-size: 24px;
    font-weight: 800;
    color: #fff;
    background: #1a1a1a;
    padding: 4px 12px;
    border-radius: 8px;
    min-width: 60px;
    text-align: center;
    letter-spacing: 1px;
    border: 1px solid #333;
}

.tooltip-stats {
    padding: 0 15px 12px;
    background: #2a2a2a;
}

.stat-row {
    display: flex;
    justify-content: space-between;
    font-size: 12px;
    margin-bottom: 6px;
    color: #ccc;
    padding-bottom: 6px;
    border-bottom: 1px dashed #444;
}

.stat-row:last-child {
    border-bottom: none;
    margin-bottom: 0;
    padding-bottom: 0;
}

.stat-row span {
    color: #888;
}

.tooltip-result {
    text-align: center;
    padding: 8px;
    font-size: 11px;
    font-weight: 800;
    border-top: 1px solid #333;
    border-radius: 0 0 8px 8px;
    text-transform: uppercase;
    letter-spacing: 1px;
}

.result-W {
    background-color: rgba(21, 87, 36, 0.3);
    color: #75b798;
    border-top-color: #1e7e34;
}

.result-D {
    background-color: rgba(56, 61, 65, 0.3);
    color: #a6a7a8;
    border-top-color: #545b62;
}

.result-L {
    background-color: rgba(114, 28, 36, 0.3);
    color: #ea868f;
    border-top-color: #dc3545;
}

/* Light one-line hints (replaces title= on touch) */
.tooltip-hint-trigger {
    cursor: help;
}

@media (hover: none), (pointer: coarse) {
    .tooltip-hint-trigger {
        cursor: pointer;
    }
}

.tooltip-hint-popover {
    position: fixed;
    left: 50%;
    bottom: calc(12px + env(safe-area-inset-bottom));
    transform: translateX(-50%);
    z-index: 1000001;
    max-width: min(300px, calc(100vw - 24px));
    padding: 10px 14px;
    background: #2a2a2a;
    color: #eee;
    border: 1px solid #444;
    border-radius: 8px;
    box-shadow: 0 8px 25px rgba(0, 0, 0, 0.45);
    font-size: 12px;
    line-height: 1.45;
    display: none;
}

.tooltip-hint-popover.is-visible {
    display: block;
}

[data-theme="light"] .tooltip-hint-popover {
    background: var(--surface-1);
    color: var(--text-primary);
    border-color: var(--border-light);
}

[data-theme="light"] .form-match-tooltip__venue {
    color: #64748b;
}
