/**
 * TortugaTV Responsive Styles
 * Responsive CSS for TortugaTV mobile view
 */

/* ============================================
   BASE STYLES
   ============================================ */
#tortuga-tv-country-modal .modal-content {
    border-color: #ff6600 !important;
    box-shadow: 0 0 30px rgba(255, 102, 0, 0.3), inset 0 0 20px rgba(255, 102, 0, 0.1) !important;
    background: rgba(10, 10, 20, 0.98) !important;
    border-color: #ff6600 !important;
    max-width: 1000px !important;
    width: 95% !important;
    max-height: 83vh !important;
    overflow-y: auto !important;
    z-index: 10001 !important;
    border-radius: 12px !important;
}

#close-country-selector {
    position: absolute !important;
    top: 15px !important;
    right: 15px !important;
    background: none !important;
    border: 2px solid #ff003c !important;
    color: #ff003c !important;
    font-size: 1.5rem !important;
    width: 44px !important;
    height: 44px !important;
    border-radius: 50% !important;
    cursor: pointer !important;
    transition: 0.3s !important;
    font-weight: bold !important;
    z-index: 1000 !important;
    display: flex !important;
    align-items: center !important;
    justify-content: center !important;
    -webkit-tap-highlight-color: transparent !important;
    padding: 0 !important;
    line-height: 1 !important;
}

#close-country-selector:active {
    transform: scale(0.9);
    background: rgba(255, 0, 60, 0.2) !important;
}

#tortuga-tv-country-modal h2 {
    color: #ff6600 !important;
    border-bottom: 2px solid rgba(255, 102, 0, 0.4) !important;
    padding-bottom: 15px !important;
    margin-bottom: 20px !important;
    text-align: center !important;
    text-shadow: 0 0 10px rgba(255, 102, 0, 0.5) !important;
    letter-spacing: 2px !important;
    font-family: 'Orbitron', sans-serif !important;
}

/* ============================================
   COUNTRY GRID
   ============================================ */
#country-grid {
    display: grid !important;
    grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)) !important;
    gap: 15px !important;
    padding: 10px !important;
}

/* Country Card - Touch Friendly */
.country-card {
    background: rgba(255, 255, 255, 0.05) !important;
    border: 2px solid rgba(255, 255, 255, 0.1) !important;
    border-radius: 12px !important;
    padding: 15px !important;
    text-align: center !important;
    cursor: pointer !important;
    transition: all 0.3s !important;
    display: flex !important;
    flex-direction: column !important;
    align-items: center !important;
    gap: 10px !important;
    min-height: 100px !important;
    -webkit-tap-highlight-color: rgba(255, 102, 0, 0.3) !important;
}

.country-card:hover,
.country-card:active {
    background: rgba(255, 102, 0, 0.2) !important;
    border-color: #ff6600 !important;
    transform: scale(1.02);
}

.country-card img {
    width: 80px !important;
    height: auto !important;
    border-radius: 6px !important;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3) !important;
    object-fit: cover !important;
}

.country-card .flag-emoji {
    font-size: 3rem !important;
}

.country-card .country-name {
    color: #fff !important;
    font-weight: 500 !important;
    font-size: 0.85rem !important;
}

/* ============================================
   TV PLAYER VIEW
   ============================================ */
#tortuga-tv-player-modal .modal-content {
    width: 100% !important;
    max-width: 100% !important;
    height: 100% !important;
    max-height: 100% !important;
    border-color: #ff6600 !important;
    padding: 0 !important;
    background: #000 !important;
}

#tortuga-tv-player-modal .tv-header {
    display: flex !important;
    justify-content: space-between !important;
    align-items: center !important;
    padding: 10px 15px !important;
    background: rgba(0, 0, 0, 0.9) !important;
    border-bottom: 1px solid rgba(255, 102, 0, 0.3) !important;
    position: sticky !important;
    top: 0 !important;
    z-index: 100 !important;
}

#tortuga-tv-player-modal .tv-country-name {
    color: #ff6600 !important;
    font-size: 1.1rem !important;
    font-weight: bold !important;
}

#tortuga-tv-player-modal .tv-close-btn {
    background: rgba(255, 0, 60, 0.2) !important;
    border: 1px solid #ff003c !important;
    color: #ff003c !important;
    padding: 8px 15px !important;
    border-radius: 4px !important;
    cursor: pointer !important;
    font-size: 0.9rem !important;
}

/* Video Container */
.tv-video-container {
    width: 100% !important;
    aspect-ratio: 16 / 9 !important;
    background: #000 !important;
    display: flex !important;
    align-items: center !important;
    justify-content: center !important;
    position: relative;
    -webkit-transform: translateZ(0);
    transform: translateZ(0);
    will-change: contents;
}

.tv-video-player {
    width: 100% !important;
    height: 100% !important;
    object-fit: contain !important;
}

/* TV Controls */
.tv-controls {
    position: absolute !important;
    bottom: 0 !important;
    left: 0 !important;
    right: 0 !important;
    padding: 15px !important;
    background: linear-gradient(transparent, rgba(0, 0, 0, 0.9)) !important;
    display: flex !important;
    gap: 10px !important;
    align-items: center !important;
}

.tv-control-btn {
    background: rgba(255, 102, 0, 0.3) !important;
    border: 1px solid #ff6600 !important;
    color: #ff6600 !important;
    padding: 10px 15px !important;
    border-radius: 4px !important;
    cursor: pointer !important;
    font-size: 0.9rem !important;
    min-height: 40px !important;
}

/* Channel List */
.tv-channel-list {
    display: grid !important;
    grid-template-columns: repeat(auto-fill, minmax(120px, 1fr)) !important;
    gap: 10px !important;
    padding: 15px !important;
    max-height: 50vh !important;
    overflow-y: auto !important;
}

.tv-channel-item {
    background: rgba(255, 102, 0, 0.1) !important;
    border: 1px solid rgba(255, 102, 0, 0.3) !important;
    border-radius: 8px !important;
    padding: 12px !important;
    text-align: center !important;
    cursor: pointer !important;
    transition: 0.3s !important;
    min-height: 50px !important;
    -webkit-tap-highlight-color: rgba(255, 102, 0, 0.3) !important;
}

.tv-channel-item:hover,
.tv-channel-item:active {
    background: rgba(255, 102, 0, 0.3) !important;
    border-color: #ff6600 !important;
}

.tv-channel-item.playing {
    background: rgba(255, 102, 0, 0.4) !important;
    border-color: #ff6600 !important;
    box-shadow: 0 0 15px rgba(255, 102, 0, 0.5) !important;
}

/* ============================================
   TORTUGA TV MODAL — RESET & BASE
   ============================================ */

/* Base modal override */
#tortuga-tv-modal .modal-content,
.tv-modal-content {
    max-width: 1200px !important;
    width: 98% !important;
    max-height: calc(95vh - 60px) !important;
    margin-top: 60px !important;
    padding: 0 !important;
    background: #080812 !important;
    border: 1px solid rgba(255, 102, 0, 0.5) !important;
    display: flex !important;
    flex-direction: column !important;
}


/* ============================================
   TV HEADER BAR (Task 13 + 14)
   ============================================ */
.tv-header-bar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    padding: 12px 16px;
    background: rgba(0, 0, 0, 0.8);
    border-bottom: 2px solid rgba(255, 102, 0, 0.35);
    flex-wrap: wrap;
    flex-shrink: 0;
    position: sticky;
    top: 0;
    z-index: 100;
    border-radius: 12px 12px 0 0;
}

/* X — inline nell'header, sempre prima elemento */
.tv-close-x-btn {
    display: flex !important;
    align-items: center !important;
    justify-content: center !important;
    width: 34px !important;
    height: 34px !important;
    background: rgba(255, 0, 60, 0.15) !important;
    border: 2px solid #ff003c !important;
    border-radius: 50% !important;
    color: #ff003c !important;
    font-size: 1.1rem !important;
    font-weight: bold !important;
    cursor: pointer !important;
    flex-shrink: 0 !important;
    transition: all 0.2s !important;
    padding: 0 !important;
    line-height: 1 !important;
    position: relative !important;
}

.tv-close-x-btn:hover,
.tv-close-x-btn:active {
    background: rgba(255, 0, 60, 0.35) !important;
    transform: scale(1.1) !important;
}

/* Title */
.tv-title {
    color: #ff6600;
    margin: 0;
    font-size: clamp(0.85rem, 2.5vw, 1.15rem);
    white-space: nowrap;
    letter-spacing: 2px;
}

/* Playlist badge */
.tv-playlist-badge {
    color: #00ff41;
    font-size: 0.75rem;
    background: rgba(0, 255, 65, 0.08);
    border: 1px solid rgba(0, 255, 65, 0.2);
    border-radius: 20px;
    padding: 4px 10px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 200px;
}

/* Header actions group */
.tv-header-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    align-items: center;
    justify-content: flex-end;
    flex: 1;
}

/* Action buttons */
.tv-action-btn {
    padding: 7px 12px !important;
    border-radius: 6px !important;
    font-weight: bold !important;
    font-size: 0.75rem !important;
    cursor: pointer !important;
    white-space: nowrap !important;
    transition: all 0.2s !important;
    border: 1px solid transparent !important;
}

.tv-action-btn--blue {
    background: linear-gradient(135deg, #00f2ff, #0066ff) !important;
    color: #000 !important;
}

.tv-action-btn--green {
    background: linear-gradient(135deg, #00ff41, #00cc33) !important;
    color: #000 !important;
    border: none !important;
}

/* Hamburger canali — solo mobile */
.tv-channels-hamburger {
    display: none;
    /* nascosto su desktop */
    flex-direction: row;
    align-items: center;
    gap: 6px;
    background: rgba(255, 102, 0, 0.12) !important;
    border: 1px solid rgba(255, 102, 0, 0.45) !important;
    border-radius: 6px !important;
    padding: 7px 11px !important;
    cursor: pointer !important;
    color: #ff6600 !important;
    transition: all 0.25s !important;
    flex-shrink: 0;
}

.tv-channels-hamburger span:not(.tv-hamburger-label) {
    display: block;
    width: 16px;
    height: 2px;
    background: #ff6600;
    border-radius: 2px;
}

.tv-hamburger-label {
    font-size: 0.72rem;
    font-family: 'Orbitron', sans-serif;
    font-weight: bold;
    color: #ff6600;
    white-space: nowrap;
}

.tv-channels-hamburger.active,
.tv-channels-hamburger:hover {
    background: rgba(255, 102, 0, 0.3) !important;
}

/* mobile-only utility */
.tv-mobile-only {
    display: none !important;
}

/* ============================================
   CHANNELS DRAWER (mobile overlay)
   ============================================ */
.tv-channels-drawer {
    display: none;
    position: relative;
    z-index: 50;
}

.tv-channels-drawer.open {
    display: block;
}

.tv-channels-drawer-inner {
    background: rgba(5, 5, 15, 0.96);
    border-bottom: 1px solid rgba(255, 102, 0, 0.3);
    padding: 15px 16px;
}

/* ============================================
   DESKTOP 3-COLUMN LAYOUT (Task 14) — >900px
   ============================================ */
.tv-main-layout {
    display: flex;
    flex-direction: row;
    align-items: stretch;
    justify-content: space-between;
    gap: 0;
    flex: 1;
    min-height: 0;
    overflow: hidden;
}

/* Left column: channels panel */
.tv-channels-panel {
    width: 260px;
    min-width: 260px;
    border-right: 1px solid rgba(255, 102, 0, 0.2);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    background: #000;
}

.tv-panel-header {
    color: #ff6600;
    font-size: 0.8rem;
    font-weight: bold;
    letter-spacing: 2px;
    text-transform: uppercase;
    padding: 12px 14px 8px;
    border-bottom: 1px solid rgba(255, 102, 0, 0.2);
    margin-bottom: 0;
    flex-shrink: 0;
}

.tv-channels-panel input[type="text"] {
    margin: 10px 12px 6px;
    width: calc(100% - 24px) !important;
    box-sizing: border-box !important;
}

.tv-channels-panel .channel-filters {
    padding: 0 12px 8px;
}

.channel-list-vertical {
    flex: 1;
    overflow-y: auto;
    padding: 6px 10px;
    display: flex;
    flex-direction: column;
    gap: 4px;
    scrollbar-width: thin;
    scrollbar-color: #ff6600 rgba(0, 0, 0, 0);
}

.channel-list-vertical::-webkit-scrollbar {
    width: 4px;
}

.channel-list-vertical::-webkit-scrollbar-thumb {
    background: #ff6600;
    border-radius: 4px;
}

/* Center column: video */
.tv-video-panel {
    flex: 1;
    display: flex;
    flex-direction: column;
    padding: 16px;
    min-width: 0;
    background: #000;
}

.tv-video-panel video {
    width: 100%;
    background: #000;
    display: block;
    flex-shrink: 0;
    -webkit-transform: translateZ(0);
    transform: translateZ(0);
    will-change: transform;
    backface-visibility: hidden;
}

/* Status bar */
.tv-status-bar {
    margin-top: 12px;
    padding: 10px 12px;
    background: rgba(0, 0, 0, 0.9);
    display: flex;
    flex-direction: column;
    gap: 8px;
    flex-shrink: 0;
}

.tv-status-row {
    display: flex;
    align-items: center;
    gap: 8px;
}

/* Right column: social panel */
.tv-social-panel {
    width: 270px;
    min-width: 270px;
    border-left: 1px solid rgba(0, 242, 255, 0.15);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    background: #000;
}

.tv-viewers-section {
    padding: 12px 14px;
    border-bottom: 1px solid rgba(0, 255, 65, 0.15);
    flex-shrink: 0;
}

/* TV Chat — ISOLATED */
.tv-chat-section {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-height: 0;
    padding: 12px 14px;
}

.tv-chat-messages-box {
    flex: 1;
    min-height: 120px;
    overflow-y: auto;
    background: rgba(0, 0, 0, 0.25);
    border-radius: 6px;
    padding: 10px;
    margin-bottom: 10px;
    font-size: 0.8rem;
    scrollbar-width: thin;
    scrollbar-color: #00f2ff rgba(0, 0, 0, 0);
}

.tv-chat-messages-box::-webkit-scrollbar {
    width: 4px;
}

.tv-chat-messages-box::-webkit-scrollbar-thumb {
    background: #00f2ff;
    border-radius: 4px;
}

.tv-chat-placeholder {
    color: #555;
    text-align: center;
    padding: 20px;
    font-size: 0.8rem;
}

.tv-chat-input-row {
    display: flex;
    gap: 6px;
    flex-shrink: 0;
}

.tv-chat-input-field {
    flex: 1;
    padding: 8px 12px;
    background: rgba(255, 255, 255, 0.07);
    border: 1px solid rgba(0, 242, 255, 0.3);
    border-radius: 6px;
    color: #fff;
    font-size: 0.8rem;
    outline: none;
    -webkit-transform: translateZ(0);
    transform: translateZ(0);
    will-change: transform;
}

.tv-chat-input-field:focus {
    border-color: #00f2ff;
    background: rgba(0, 242, 255, 0.06);
}

.tv-chat-send-btn {
    background: #00f2ff !important;
    border: none !important;
    color: #000 !important;
    padding: 8px 12px !important;
    cursor: pointer !important;
    border-radius: 6px !important;
    font-weight: bold !important;
    font-size: 0.85rem !important;
    flex-shrink: 0;
}

/* desktop-only utility: hide mobile elements on desktop */
.tv-desktop-only {
    display: flex;
    flex-direction: column;
}

/* ============================================
   TABLET/MOBILE — ≤900px
   ============================================ */
@media (max-width: 900px) {

    /* Show hamburger, hide desktop channel panel */
    .tv-mobile-only {
        display: flex !important;
    }

    .tv-desktop-only {
        display: none !important;
    }

    .tv-channels-hamburger {
        display: flex !important;
    }

    /* Stack layout */
    .tv-main-layout {
        display: flex !important;
        flex-direction: column !important;
        overflow: visible !important;
    }

    .tv-channels-panel {
        display: none !important;
    }

    .tv-video-panel {
        padding: 12px 12px 8px;
    }

    .tv-social-panel {
        border-left: none;
        border-top: 1px solid rgba(0, 242, 255, 0.15);
        min-height: 400px;
        flex: 1;
        display: flex;
        flex-direction: column;
        align-items: center; /* Center horizontally */
        justify-content: flex-start;
        width: 100%;
        background: #000;
    }

    .tv-chat-section {
        width: 100%;
        max-width: 600px;
        margin: 0 auto;
        display: flex;
        flex-direction: column;
        align-items: center;
    }

    .tv-chat-messages-box {
        width: 100%;
        box-sizing: border-box;
    }

    .tv-chat-input-row {
        width: 100%;
        box-sizing: border-box;
    }

    #ws-status {
        display: none !important;
    }

    .tv-channels-drawer.open {
        position: fixed !important;
        top: 0 !important;
        left: 0 !important;
        right: 0 !important;
        bottom: 0 !important;
        z-index: 9999 !important;
        overflow-y: auto !important;
        display: block !important;
    }

    .tv-channels-drawer-inner {
        min-height: 100%;
        border-bottom: none;
        border-radius: 0;
    }

    /* Playlist badge hidden on small screens to save space */
    .tv-playlist-badge {
        display: none;
    }
}

@media (max-width: 480px) {

    .tv-header-bar {
        padding: 10px;
        gap: 8px;
        flex-wrap: wrap;
        justify-content: space-between;
        background: #000;
    }

    .tv-header-actions {
        width: 100%;
        justify-content: center;
        margin-top: 8px;
        order: 10;
        gap: 6px;
        display: flex;
        flex-wrap: wrap;
    }

    .tv-close-x-btn {
        order: -1;
        width: 42px !important;
        height: 42px !important;
        font-size: 1.4rem !important;
        margin-bottom: 5px; /* Crea distacco dal resto */
    }

    .tv-title {
        font-size: 0.85rem;
    }

    .tv-action-btn {
        padding: 6px 9px !important;
        font-size: 0.65rem !important;
    }

    #tortuga-tv-modal .modal-content,
    .tv-modal-content {
        border-radius: 0 !important;
        width: 100% !important;
        max-height: 100vh !important;
        margin-top: 0 !important;
    }

    .tv-status-bar {
        padding: 12px 10px;
        background: rgba(10, 10, 20, 0.98);
        border: 1px solid rgba(255, 102, 0, 0.3);
        border-radius: 12px;
        margin: 10px 0;
        box-shadow: 0 4px 15px rgba(0, 0, 0, 0.5);
    }
    
    .tv-status-row {
        display: flex !important;
        flex-direction: row !important; /* Row, not column */
        justify-content: space-between !important;
        align-items: center !important;
        gap: 10px;
        text-align: left;
    }
    
    .tv-status-actions {
        display: flex !important;
        justify-content: flex-end !important;
        gap: 8px;
    }
}

/* Country grid */
@media (max-width: 768px) {
    #country-grid {
        grid-template-columns: repeat(3, 1fr) !important;
        padding: 10px 5px !important;
    }

    .country-card {
        min-height: 80px !important;
        padding: 10px !important;
    }

    .country-card img {
        width: 50px !important;
    }

    .country-card .flag-emoji {
        font-size: 2rem !important;
    }

    .country-card .country-name {
        font-size: 0.7rem !important;
    }

    .tv-channel-list {
        grid-template-columns: repeat(3, 1fr) !important;
    }

    .tv-channel-item {
        padding: 10px 5px !important;
        font-size: 0.8rem !important;
    }
}

@media (max-width: 480px) {
    #country-grid {
        grid-template-columns: repeat(2, 1fr) !important;
    }

    .country-card {
        min-height: 70px !important;
    }

    .country-card img {
        width: 40px !important;
    }

    .country-card .flag-emoji {
        font-size: 1.5rem !important;
    }

    .country-card .country-name {
        font-size: 0.65rem !important;
    }

    #tortuga-tv-country-modal .modal-content {
        width: 98% !important;
        padding: 15px !important;
    }

    .tv-channel-list {
        grid-template-columns: repeat(2, 1fr) !important;
    }

    .tv-channel-item {
        font-size: 0.7rem !important;
        padding: 8px 5px !important;
    }

    #playlist-info-bar {
        flex-direction: column !important;
        align-items: flex-start !important;
    }
}

/* Touch optimizations */
@media (hover: none) and (pointer: coarse) {
    .country-card {
        min-height: 90px !important;
    }

    .country-card:active {
        background: rgba(255, 102, 0, 0.3) !important;
        transform: scale(0.98);
    }

    .tv-channel-item:active {
        background: rgba(255, 102, 0, 0.4) !important;
    }

    .tv-close-x-btn {
        width: 44px !important;
        height: 44px !important;
    }
}