/* ─────────────────────────────────────────────────────────────────────────────
   Kenny TradingView overlay — macOS Tahoe-style glassmorphism
   ───────────────────────────────────────────────────────────────────────────── */

.kenny-tv-overlay {
    position: fixed;
    z-index: 2147483600;
    display: none;
    flex-direction: column;

    background: rgba(28, 28, 30, 0.55);
    -webkit-backdrop-filter: blur(40px) saturate(180%);
    backdrop-filter: blur(40px) saturate(180%);

    border: 1px solid rgba(255, 255, 255, 0.10);
    border-radius: 14px;
    overflow: hidden;

    /* Layered shadow + inner specular highlight for depth */
    box-shadow:
        inset 0 0 0 0.5px rgba(255, 255, 255, 0.06),
        inset 0 1px 0 rgba(255, 255, 255, 0.18),
        0 12px 32px rgba(0, 0, 0, 0.45),
        0 28px 72px rgba(0, 0, 0, 0.55);

    animation: kenny-tv-spring-in 240ms cubic-bezier(0.16, 1, 0.3, 1);

    min-width: 320px;
    min-height: 240px;

    color: #ebebf0;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

.kenny-tv-overlay.is-visible {
    display: flex;
}

.kenny-tv-overlay.is-dragging,
.kenny-tv-overlay.is-resizing {
    transition: none;
    user-select: none;
}

/* ─── Title bar (drag handle) ─────────────────────────────────────────────── */
.kenny-tv-overlay__topbar {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 0 12px;
    height: 38px;

    background: linear-gradient(
        180deg,
        rgba(255, 255, 255, 0.08) 0%,
        rgba(255, 255, 255, 0.02) 100%);
    border-bottom: 1px solid rgba(255, 255, 255, 0.08);
    box-shadow: inset 0 -0.5px 0 rgba(0, 0, 0, 0.25);

    color: rgba(235, 235, 240, 0.9);
    flex: 0 0 auto;
    cursor: move;
    user-select: none;
    touch-action: none;
    position: relative;
    z-index: 1;
}

/* ─── Traffic-light dots (clickable: red=close, yellow=default size, green=maximize) ─── */
.kenny-tv-overlay__dots {
    display: inline-flex;
    gap: 8px;
    align-items: center;
}

.kenny-tv-overlay__dot {
    appearance: none;
    -webkit-appearance: none;
    width: 13px;
    height: 13px;
    border-radius: 50%;
    border: none;
    padding: 0;
    cursor: pointer;
    box-shadow:
        inset 0 0 0 0.5px rgba(0, 0, 0, 0.30),
        inset 0 0.5px 0.5px rgba(255, 255, 255, 0.45),
        0 0.5px 0 rgba(0, 0, 0, 0.18);
    position: relative;
    color: rgba(0, 0, 0, 0.55);
    font-size: 9px;
    font-weight: 700;
    line-height: 1;
    transition: filter 100ms ease, transform 80ms ease;
}

.kenny-tv-overlay__dot::before {
    content: '';
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    transition: opacity 100ms ease;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
    font-size: 9px;
    font-weight: 800;
    line-height: 1;
}

/* Show glyph hints when the user hovers over the whole dot group (mac behaviour) */
.kenny-tv-overlay__dots:hover .kenny-tv-overlay__dot::before {
    opacity: 1;
}

.kenny-tv-overlay__dot:hover {
    filter: brightness(1.05) saturate(1.10);
}

.kenny-tv-overlay__dot:active {
    transform: scale(0.92);
    filter: brightness(0.92);
}

.kenny-tv-overlay__dot:focus-visible {
    outline: 2px solid rgba(120, 180, 255, 0.85);
    outline-offset: 2px;
}

.kenny-tv-overlay__dot--close {
    background: radial-gradient(circle at 32% 30%, #ff8278 0%, #ec6259 55%, #c8443c 100%);
}
.kenny-tv-overlay__dot--close::before { content: '×'; font-size: 11px; }

.kenny-tv-overlay__dot--default {
    background: radial-gradient(circle at 32% 30%, #ffd97a 0%, #f5b934 55%, #c8941c 100%);
}
.kenny-tv-overlay__dot--default::before { content: '–'; font-size: 12px; padding-bottom: 2px; }

.kenny-tv-overlay__dot--maximize {
    background: radial-gradient(circle at 32% 30%, #6fe28b 0%, #2bc54e 55%, #1ea03b 100%);
}
.kenny-tv-overlay__dot--maximize::before { content: '⤢'; font-size: 8px; font-weight: 900; }

.kenny-tv-overlay__topbar-spacer {
    flex: 1 1 auto;
}

.kenny-tv-overlay__asset-label {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    pointer-events: none;
    cursor: inherit;
    font-size: 13px;
    font-weight: 500;
    letter-spacing: 0.2px;
    opacity: 0.85;
}

/* ─── Close button (large, macOS-circle style) ───────────────────────────── */
.kenny-tv-overlay__close {
    background: linear-gradient(
        180deg,
        rgba(255, 130, 120, 0.95) 0%,
        rgba(236, 98, 89, 0.95) 100%);
    color: #4a0500;
    border: 1px solid rgba(255, 255, 255, 0.22);
    width: 28px;
    height: 28px;
    border-radius: 50%;
    font-size: 17px;
    font-weight: 800;
    line-height: 1;
    cursor: pointer;
    padding: 0 0 1px 0;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    box-shadow:
        inset 0 0.5px 0 rgba(255, 255, 255, 0.5),
        0 1px 2px rgba(0, 0, 0, 0.35);
    transition: filter 120ms ease, transform 80ms ease;
    text-shadow: 0 0.5px 0 rgba(255, 255, 255, 0.25);
}

.kenny-tv-overlay__close:hover {
    filter: brightness(1.10) saturate(1.15);
    transform: scale(1.06);
}

.kenny-tv-overlay__close:active {
    transform: scale(0.94);
    filter: brightness(0.95);
}

.kenny-tv-overlay__close:focus-visible {
    outline: 2px solid rgba(120, 180, 255, 0.85);
    outline-offset: 2px;
}

/* ─── Chart container ─────────────────────────────────────────────────────── */
.kenny-tv-overlay__container {
    flex: 1 1 auto;
    width: 100%;
    height: 100%;
    min-height: 0;
    position: relative;
    background: rgba(0, 0, 0, 0.20);
}

/* ─── Loading skeleton (visible while tv.js + iframe boot) ────────────────── */
.kenny-tv-overlay__skeleton {
    position: absolute;
    inset: 0;
    background: var(--mud-palette-background, #191a1c); /* matches widget toolbar_bg so there's no color flash */
    overflow: hidden;
    pointer-events: none;
    z-index: 1;
}

.kenny-tv-overlay__skeleton-shimmer {
    position: absolute;
    top: 0;
    left: -40%;
    width: 40%;
    height: 100%;
    background: linear-gradient(
        90deg,
        transparent 0%,
        rgba(255, 255, 255, 0.045) 50%,
        transparent 100%);
    animation: kenny-tv-skeleton-sweep 1400ms ease-in-out infinite;
}

@keyframes kenny-tv-skeleton-sweep {
    0%   { transform: translateX(0); }
    100% { transform: translateX(350%); }
}

/* ─── Disclaimer footer ───────────────────────────────────────────────────── */
.kenny-tv-overlay__footer {
    flex: 0 0 auto;
    min-height: 26px;
    padding: 4px 28px 4px 14px; /* right padding leaves room for the SE grip */
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    text-align: center;
    font-size: 10.5px;
    line-height: 1.35;
    letter-spacing: 0.2px;
    color: rgba(235, 235, 240, 0.55);
    background: linear-gradient(
        0deg,
        rgba(255, 255, 255, 0.04) 0%,
        rgba(0, 0, 0, 0.20) 100%);
    border-top: 1px solid rgba(255, 255, 255, 0.06);
    user-select: none;
    pointer-events: none;
}

.kenny-tv-overlay__footer-icon {
    font-size: 12px;
    line-height: 1;
    flex: 0 0 auto;
    filter: drop-shadow(0 0.5px 0 rgba(0, 0, 0, 0.4));
}

/* ─── Edge resize handles (invisible hot-spots) ──────────────────────────── */
.kenny-tv-overlay__edge {
    position: absolute;
    z-index: 3;
    touch-action: none;
    background: transparent;
}

.kenny-tv-overlay__edge--n { top: 0;    left: 0;  right: 0;     height: 5px; cursor: ns-resize; }
.kenny-tv-overlay__edge--s { bottom: 0; left: 0;  right: 0;     height: 5px; cursor: ns-resize; }
.kenny-tv-overlay__edge--e { top: 0;    right: 0; bottom: 0;    width: 5px;  cursor: ew-resize; }
.kenny-tv-overlay__edge--w { top: 0;    left: 0;  bottom: 0;    width: 5px;  cursor: ew-resize; }

/* ─── Corner resize handles (sit above edges) ─────────────────────────────── */
.kenny-tv-overlay__corner {
    position: absolute;
    z-index: 4;
    width: 14px;
    height: 14px;
    touch-action: none;
}

.kenny-tv-overlay__corner--nw { top: 0;    left: 0;  cursor: nwse-resize; }
.kenny-tv-overlay__corner--ne { top: 0;    right: 0; cursor: nesw-resize; }
.kenny-tv-overlay__corner--sw { bottom: 0; left: 0;  cursor: nesw-resize; }
.kenny-tv-overlay__corner--se {
    bottom: 0;
    right: 0;
    cursor: nwse-resize;
    width: 18px;
    height: 18px;
    background:
        linear-gradient(135deg,
            transparent 0%,
            transparent 45%,
            rgba(255, 255, 255, 0.55) 45%,
            rgba(255, 255, 255, 0.55) 55%,
            transparent 55%,
            transparent 70%,
            rgba(255, 255, 255, 0.55) 70%,
            rgba(255, 255, 255, 0.55) 80%,
            transparent 80%);
    opacity: 0.65;
    transition: opacity 120ms ease;
}

.kenny-tv-overlay__corner--se:hover {
    opacity: 1;
}

/* ─── Spring entrance ─────────────────────────────────────────────────────── */
@keyframes kenny-tv-spring-in {
    0%   { opacity: 0; transform: scale(0.96) translateY(6px); }
    60%  { opacity: 1; transform: scale(1.005) translateY(0); }
    100% { opacity: 1; transform: scale(1) translateY(0); }
}

/* ─── Light-mode (auto) tweak ─────────────────────────────────────────────── */
@media (prefers-color-scheme: light) {
    .kenny-tv-overlay {
        background: rgba(245, 245, 247, 0.65);
        border-color: rgba(0, 0, 0, 0.12);
        color: #1c1c1e;
        box-shadow:
            inset 0 0 0 0.5px rgba(255, 255, 255, 0.50),
            inset 0 1px 0 rgba(255, 255, 255, 0.85),
            0 12px 32px rgba(0, 0, 0, 0.18),
            0 28px 72px rgba(0, 0, 0, 0.22);
    }

    .kenny-tv-overlay__topbar {
        background: linear-gradient(
            180deg,
            rgba(255, 255, 255, 0.55) 0%,
            rgba(255, 255, 255, 0.30) 100%);
        border-bottom-color: rgba(0, 0, 0, 0.08);
        box-shadow: inset 0 -0.5px 0 rgba(0, 0, 0, 0.05);
        color: rgba(28, 28, 30, 0.85);
    }

    .kenny-tv-overlay__footer {
        background: linear-gradient(
            0deg,
            rgba(255, 255, 255, 0.50) 0%,
            rgba(0, 0, 0, 0.04) 100%);
        border-top-color: rgba(0, 0, 0, 0.08);
        color: rgba(28, 28, 30, 0.55);
    }
}
