/*
* Telegram Feed CSS
* v1.3.5 - Animation & Sticky Fix
*/

:root {
    --tfw-primary-color: #e54d26;
    /* Deep Orange */
    --tfw-secondary-color: #2c3e50;
    /* Dark Blue */
    --tfw-bg: #ffffff;
    --tfw-text: #333333;
    --tfw-border: #eee;
    --tfw-gradient: linear-gradient(135deg, #FF512F 0%, #DD2476 100%);
    --tfw-shadow: 0 4px 15px rgba(0, 0, 0, 0.1);
}

@media (prefers-color-scheme: dark) {
    :root {
        --tfw-bg: #1a1a1a;
        --tfw-text: #f0f0f0;
        --tfw-border: #333;
    }
}

/* --- Container --- */
.tfw-widget {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen-Sans, Ubuntu, Cantarell, "Helvetica Neue", sans-serif;
    position: fixed;
    z-index: 999999;
    box-sizing: border-box;
}

.tfw-widget * {
    box-sizing: border-box;
}

/* --- Sidebar Mode (Slide Animation Only) --- */
.tfw-widget.tfw-sidebar {
    right: 0;
    top: 0;
    height: 100vh;
    display: flex;
    align-items: center;
    pointer-events: none;
}

.tfw-sidebar .tfw-container {
    background: var(--tfw-bg);
    width: 380px;
    height: 100%;
    position: fixed;
    right: -380px;
    top: 0;
    box-shadow: -5px 0 25px rgba(0, 0, 0, 0.15);
    display: flex;
    flex-direction: column;
    pointer-events: auto;
    z-index: 999999;
    overflow: hidden;
    transition: right 0.35s cubic-bezier(0.4, 0, 0.2, 1);
}

.tfw-sidebar.tfw-open .tfw-container {
    right: 0;
}

/* Sidebar Toggle Tab - Base Styles */
.tfw-sidebar .tfw-toggle-tab {
    position: fixed;
    right: 0;
    top: 50%;
    transform: translateY(-50%);
    background: var(--tfw-gradient);
    color: white;
    padding: 16px 12px;
    width: auto;
    height: auto;
    border-radius: 12px 0 0 12px;
    /* Slightly rounded edges */
    cursor: pointer;
    box-shadow: var(--tfw-shadow);
    transition: right 0.35s cubic-bezier(0.4, 0, 0.2, 1);
    pointer-events: auto;
    z-index: 10000001;
    display: flex;
    flex-direction: column;
    align-items: center;
}

/* Toggle moves with sidebar when open - stays visible */
.tfw-sidebar.tfw-open .tfw-toggle-tab {
    right: 380px;
}

.tfw-toggle-text {
    writing-mode: vertical-rl;
    text-transform: uppercase;
    font-weight: bold;
    letter-spacing: 1px;
    margin-top: 8px;
}

.tfw-telegram-icon {
    width: 24px;
    height: 24px;
}


/* --- Popup Mode --- */
.tfw-widget.tfw-popup {
    position: fixed;
    left: 0;
    top: 0;
    width: 100vw;
    height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    pointer-events: none;
    z-index: 999998;
    /* Wrapper is always visible - only backdrop changes */
}

/* Backdrop overlay - shown on open */
.tfw-widget.tfw-popup::before {
    content: '';
    position: absolute;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0);
    transition: background 0.3s ease;
    pointer-events: none;
}

.tfw-widget.tfw-popup.tfw-open::before {
    background: rgba(0, 0, 0, 0.5);
    pointer-events: auto;
}

.tfw-popup .tfw-container {
    position: relative;
    width: 90%;
    max-width: 450px;
    height: 80vh;
    max-height: 700px;
    background: var(--tfw-bg);
    border-radius: 12px;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.4);
    display: flex;
    flex-direction: column;
    transform: scale(0.9) translateY(20px);
    transition: transform 0.3s cubic-bezier(0.34, 1.56, 0.64, 1), opacity 0.3s ease, visibility 0.3s;
    overflow: hidden;
    /* Hidden when popup is closed */
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
}

.tfw-popup.tfw-open .tfw-container {
    transform: scale(1) translateY(0);
    opacity: 1;
    visibility: visible;
    pointer-events: auto;
}

/* Popup Toggle Button - Base */
.tfw-popup .tfw-toggle-tab {
    position: fixed;
    right: 20px;
    bottom: 20px;
    top: auto;
    transform: none;
    background: var(--tfw-gradient);
    color: white;
    width: 60px;
    height: 60px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    box-shadow: 0 4px 15px rgba(255, 75, 31, 0.4);
    pointer-events: auto;
    z-index: 10000001;
    animation: tfw-popup-pulse 2s ease-in-out infinite;
    transition: border-radius 0.3s ease, width 0.3s ease, padding 0.3s ease;
}

@keyframes tfw-popup-pulse {

    0%,
    100% {
        transform: scale(1);
        box-shadow: 0 4px 15px rgba(255, 75, 31, 0.4);
    }

    50% {
        transform: scale(1.05);
        box-shadow: 0 6px 20px rgba(255, 75, 31, 0.6);
    }
}

.tfw-popup .tfw-telegram-icon {
    width: 32px;
    height: 32px;
    margin: 0;
}

/* Hide text by default in popup (except pill style) */
.tfw-popup .tfw-toggle-text {
    display: none;
}

/* --- Popup Icon Styles --- */

/* Circle (Default) - already styled above */

/* Square Style */
.tfw-popup.tfw-popup-icon-square .tfw-toggle-tab {
    border-radius: 16px;
}

/* Pill with Text Style */
.tfw-popup.tfw-popup-icon-pill .tfw-toggle-tab {
    width: auto;
    border-radius: 50px;
    padding: 14px 20px;
    gap: 10px;
}

.tfw-popup.tfw-popup-icon-pill .tfw-toggle-text {
    display: block;
    writing-mode: horizontal-tb;
    margin-top: 0;
    font-size: 14px;
}

.tfw-popup.tfw-open .tfw-toggle-tab {
    display: none;
}



/* --- Header & Layout (Sticky Fixes) --- */
.tfw-header {
    padding: 15px 20px;
    border-bottom: 1px solid var(--tfw-border);
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: var(--tfw-bg);
    flex-shrink: 0;
    /* CRITICAL: Prevent shrinking in flex column */
    z-index: 200;
    min-height: 60px;
}

.tfw-title {
    margin: 0;
    font-size: 16px;
    font-weight: 600;
    display: flex;
    align-items: center;
    gap: 8px;
    color: var(--tfw-text);
}

.tfw-close {
    background: rgba(128, 128, 128, 0.15);
    border: none;
    border-radius: 50%;
    width: 32px;
    height: 32px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--tfw-text);
}

/* Channel Header Info */
.tfw-channel-info {
    display: flex;
    align-items: center;
    padding: 10px 15px;
    background: var(--tfw-bg);
    border-bottom: 1px solid #eee;
    flex-shrink: 0;
    /* CRITICAL: Prevent shrinking */
    z-index: 150;
    width: 100%;
}

.tfw-channel-logo {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    margin-right: 12px;
    object-fit: cover;
    border: 2px solid var(--tfw-primary-color);
}

.tfw-channel-details {
    flex: 1;
}

.tfw-channel-title {
    font-size: 14px;
    font-weight: 700;
    color: var(--tfw-text);
    display: block;
    line-height: 1.2;
}

.tfw-channel-subs {
    font-size: 11px;
    color: #888;
}

.tfw-subscribe-btn {
    background: var(--tfw-primary-color);
    color: #fff;
    border: none;
    border-radius: 20px;
    padding: 6px 14px;
    font-size: 12px;
    font-weight: 600;
    text-decoration: none;
    transition: opacity 0.2s;
}

.tfw-subscribe-btn:hover {
    opacity: 0.9;
    color: #fff;
}


/* Content Area - Scrolling Master */
.tfw-content {
    flex: 1;
    /* Take remaining space */
    overflow-y: auto;
    /* Scroll ONLY this area */
    min-height: 0;
    /* CRITICAL: Allows flex child to shrink properly for scrolling */
    padding: 15px;
    overscroll-behavior-y: contain;
    position: relative;
    scroll-behavior: smooth;
    width: 100%;
}

/* Posts */
.tfw-post {
    background: var(--tfw-bg);
    border: 1px solid var(--tfw-border);
    color: var(--tfw-text);
    border-radius: 8px;
    padding: 12px;
    margin-bottom: 20px;
    font-size: 14px;
    line-height: 1.5;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.05);
}

.tfw-post-images img {
    width: 100%;
    border-radius: 6px;
    margin-bottom: 10px;
    display: block;
}

.tfw-post-meta {
    font-size: 11px;
    color: #888;
    margin-top: 8px;
    text-align: right;
}

.tfw-post a {
    color: var(--tfw-primary-color);
    text-decoration: none;
}

.tfw-post a:hover {
    text-decoration: underline;
}

/* Empty & Loading */
.tfw-empty p,
.tfw-loading p {
    text-align: center;
    color: var(--tfw-text);
    opacity: 0.7;
}

.tfw-spinner {
    width: 30px;
    height: 30px;
    border: 3px solid var(--tfw-border);
    border-top-color: var(--tfw-primary-color);
    border-radius: 50%;
    animation: tfw-spin 1s linear infinite;
    margin: 0 auto 10px;
}

@keyframes tfw-spin {
    to {
        transform: rotate(360deg);
    }
}

/* Pull to Refresh */
.tfw-ptr-container {
    height: 0;
    overflow: hidden;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: height 0.2s;
}

.tfw-ptr-spinner {
    width: 20px;
    height: 20px;
    border: 2px solid var(--tfw-border);
    border-top-color: var(--tfw-primary-color);
    border-radius: 50%;
    animation: tfw-spin 0.8s linear infinite;
}

.tfw-ptr-visible {
    height: 50px;
}

/* Mobile */
@media (max-width: 600px) {
    .tfw-sidebar .tfw-container {
        width: 100vw;
        right: -100vw;
        box-shadow: none;
    }

    .tfw-sidebar.tfw-open .tfw-container {
        right: 0;
    }

    /* Toggle hidden on mobile when sidebar is open */
    .tfw-sidebar.tfw-open .tfw-toggle-tab {
        display: none;
    }

    /* Popup fullscreen on mobile */
    .tfw-popup .tfw-container {
        width: 100%;
        height: 100%;
        max-width: none;
        max-height: none;
        border-radius: 0;
    }

    .tfw-popup .tfw-toggle-tab {
        right: 15px;
        bottom: 15px;
        width: 56px;
        height: 56px;
    }

    .tfw-post {
        border: 1px solid rgba(128, 128, 128, 0.2);
    }
}

/* Features */
.tfw-toast {
    position: absolute;
    bottom: 80px;
    left: 50%;
    transform: translateX(-50%);
    background: var(--tfw-primary-color);
    color: white;
    padding: 8px 16px;
    border-radius: 20px;
    font-size: 13px;
    opacity: 0;
    transition: all 0.3s ease;
    z-index: 10000002;
    pointer-events: none;
    white-space: nowrap;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
}

.tfw-toast.show {
    opacity: 1;
    transform: translateX(-50%) translateY(0);
}

.tfw-load-more {
    display: block;
    width: 100%;
    text-align: center;
    padding: 12px;
    background: transparent;
    border: none;
    color: var(--tfw-primary-color);
    font-weight: 600;
    cursor: pointer;
    margin-top: 15px;
    margin-bottom: 30px;
    transition: opacity 0.2s;
}

.tfw-load-more:hover {
    opacity: 0.8;
}

.tfw-load-more:disabled {
    opacity: 0.5;
    cursor: default;
}

.tfw-post code {
    cursor: pointer;
    position: relative;
    border-bottom: 1px dashed rgba(0, 0, 0, 0.2);
    transition: background 0.2s;
}

.tfw-post code:hover {
    background: rgba(255, 75, 31, 0.1);
}

.tfw-post code::after {
    content: "Copy";
    position: absolute;
    top: -20px;
    left: 50%;
    transform: translateX(-50%);
    background: black;
    color: white;
    font-size: 10px;
    padding: 2px 4px;
    border-radius: 4px;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.2s;
}

.tfw-post code:hover::after {
    opacity: 1;
}

.tfw-post code.copied::after {
    content: "Copied!";
    background: #4CAF50;
    opacity: 1;
}


/* --- Tab Animations (Sidebar Mode) --- */

/* Wiggle Animation */
@keyframes tfw-wiggle {

    0%,
    85% {
        transform: translateY(-50%) rotate(0deg);
    }

    87% {
        transform: translateY(-50%) rotate(-10deg);
    }

    89% {
        transform: translateY(-50%) rotate(10deg);
    }

    91% {
        transform: translateY(-50%) rotate(-10deg);
    }

    93% {
        transform: translateY(-50%) rotate(10deg);
    }

    95%,
    100% {
        transform: translateY(-50%) rotate(0deg);
    }
}

.tfw-sidebar:not(.tfw-open) .tfw-toggle-tab.tfw-tab-anim-wiggle {
    animation: tfw-wiggle 5s ease-in-out infinite;
}

/* Pulse Animation */
@keyframes tfw-pulse {

    0%,
    100% {
        transform: translateY(-50%) scale(1);
    }

    50% {
        transform: translateY(-50%) scale(1.1);
    }
}

.tfw-sidebar:not(.tfw-open) .tfw-toggle-tab.tfw-tab-anim-pulse {
    animation: tfw-pulse 2s ease-in-out infinite;
}

/* Bounce Animation */
@keyframes tfw-bounce {

    0%,
    100% {
        transform: translateY(-50%);
    }

    25% {
        transform: translateY(-55%);
    }

    50% {
        transform: translateY(-45%);
    }

    75% {
        transform: translateY(-52%);
    }
}

.tfw-sidebar:not(.tfw-open) .tfw-toggle-tab.tfw-tab-anim-bounce {
    animation: tfw-bounce 2s ease-in-out infinite;
}

/* Stop all animations when sidebar is open */
.tfw-sidebar.tfw-open .tfw-toggle-tab {
    animation: none !important;
}


/* --- Tab Styles (Sidebar Mode Only) --- */

/* Standard - Uses default .tfw-sidebar .tfw-toggle-tab styles */

/* Pill Style - Animated: Starts collapsed, expands on hover */
.tfw-widget.tfw-sidebar .tfw-toggle-tab.tfw-tab-pill {
    flex-direction: row;
    border-radius: 50px 0 0 50px;
    padding: 12px;
    gap: 0;
    width: 48px;
    overflow: hidden;
    transition: width 0.4s cubic-bezier(0.34, 1.56, 0.64, 1), padding 0.3s ease, gap 0.3s ease;
}

.tfw-widget.tfw-sidebar .tfw-toggle-tab.tfw-tab-pill:hover {
    width: auto;
    padding: 12px 16px 12px 14px;
    gap: 10px;
}

.tfw-widget.tfw-sidebar .tfw-tab-pill .tfw-toggle-text {
    writing-mode: horizontal-tb;
    margin-top: 0;
    font-size: 12px;
    white-space: nowrap;
    max-width: 0;
    opacity: 0;
    overflow: hidden;
    transition: max-width 0.4s cubic-bezier(0.34, 1.56, 0.64, 1), opacity 0.3s ease 0.1s;
}

.tfw-widget.tfw-sidebar .tfw-toggle-tab.tfw-tab-pill:hover .tfw-toggle-text {
    max-width: 150px;
    opacity: 1;
}

/* Icon Only Style */
.tfw-widget.tfw-sidebar .tfw-toggle-tab.tfw-tab-icon {
    width: 50px;
    height: 50px;
    padding: 0;
    border-radius: 10px 0 0 10px;
    justify-content: center;
}

.tfw-widget.tfw-sidebar .tfw-tab-icon .tfw-toggle-text {
    display: none;
}


/* --- Channel Info Sticky Fix --- */
.tfw-channel-info {
    background: var(--tfw-bg);
    border-bottom: 1px solid var(--tfw-border);
    position: relative;
    z-index: 10;
}