:root {
    --bg-primary: #000000;
    --bg-secondary: #1a1a1a;
    --bg-tertiary: #2a2a2a;
    --text-primary: #ffffff;
    --text-secondary: #a0a0a0;
    --accent: #FFB62A;
    --accent-dark: #e6a426;
    --border-color: #2d2d2d;
    --font-family: 'Inter', sans-serif;
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    background-color: var(--bg-primary);
    background-size: cover;
    background-position: center;
    background-attachment: fixed;
    color: var(--text-primary);
    font-family: var(--font-family);
    font-size: 15px;
}

/* --- Header --- */
.site-header {
    background-color: rgba(26, 26, 26, 0.9);
    border-bottom: 1px solid var(--accent);
    backdrop-filter: blur(5px);
    position: sticky;
    top: 0;
    z-index: 999;
}

.header-container {
    display: grid;
    grid-template-columns: 1fr auto 1fr;
    align-items: center;
    max-width: 1800px;
    margin: 0 auto;
    padding: 0.75rem 2rem;
}

.header-container .header-left { grid-column: 1 / 2; }
.header-container .logo-container { grid-column: 2 / 3; justify-self: center; }
#brandLogo { height: 45px; }
.header-container .header-right { grid-column: 3 / 4; justify-self: end; }

.btn {
    padding: 0.6rem 1.2rem;
    border: none;
    border-radius: 6px;
    cursor: pointer;
    font-weight: 600;
    text-decoration: none;
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    transition: background-color 0.2s;
}

.btn-primary { background-color: var(--accent); color: #000; }
.btn-primary:hover { background-color: var(--accent-dark); }

/* --- Main Layout --- */
.main-container {
    display: grid;
    grid-template-columns: 260px 1fr 360px;
    gap: 1.5rem;
    max-width: 1800px;
    margin: 1.5rem auto;
    padding: 0 2rem;
}

.sidebar-left,
.sidebar-right,
.content-area {
    background-color: rgba(26, 26, 26, 0.8);
    border-radius: 8px;
    border: 1px solid var(--border-color);
    backdrop-filter: blur(5px);
}

/* --- Left Sidebar --- */
.sidebar-left { padding: 1rem; border: 1px solid var(--accent); }
.sidebar-nav a {
    display: flex; align-items: center; gap: 0.85rem;
    padding: 0.9rem 1.2rem; color: var(--text-secondary); text-decoration: none;
    border-radius: 6px; margin-bottom: 0.5rem; font-weight: 500;
    transition: background-color 0.2s, color 0.2s;
}
.sidebar-nav a:hover { background-color: var(--bg-tertiary); color: var(--text-primary); }
.sidebar-nav a.active { background-color: var(--accent); color: #000; font-weight: 600; }
.sidebar-nav a i { width: 20px; text-align: center; }
.sidebar-heading {
    text-transform: uppercase; font-size: 0.75rem; font-weight: 700;
    color: var(--text-secondary); margin: 2rem 1.2rem 1rem 1.2rem; letter-spacing: 0.8px;
}
.sidebar-widgets img {
    width: 100%; border-radius: 6px; margin-bottom: 1rem;
    cursor: pointer; transition: opacity 0.2s;
}
.sidebar-widgets img:hover { opacity: 0.85; }

/* --- Content Area --- */
.content-area { padding: 2rem; }
.content-title {
    font-size: 1.6rem; font-weight: 700; margin-bottom: 1.5rem;
    padding-bottom: 1rem; border-bottom: 1px solid var(--border-color); color: var(--accent);
}
.home-grid { display: grid; gap: 1.5rem; }
.main-channel-card {
    border-radius: 8px; overflow: hidden; cursor: pointer; display: flex;
    gap: 1.5rem; border: 1px solid var(--border-color);
    transition: border-color 0.2s, box-shadow 0.2s; background-color: var(--bg-tertiary);
}
.main-channel-card:hover { border-color: var(--accent); box-shadow: 0 0 15px rgba(255, 182, 42, 0.1); }
.main-channel-card img { width: 60%; object-fit: cover; }
.main-channel-card .info { padding: 2rem 1rem 2rem 0; }
.main-channel-card .info h3 { font-size: 1.8rem; margin-bottom: 0.5rem; color: var(--text-primary); }
.main-channel-card .info p { color: var(--text-secondary); }
.sub-channels-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(250px, 1fr)); gap: 1.5rem; }
.sub-channel-card {
    background-color: var(--bg-tertiary); border-radius: 8px; overflow: hidden;
    cursor: pointer; border: 1px solid var(--border-color); transition: transform 0.2s;
}
.sub-channel-card:hover { transform: translateY(-5px); }
.sub-channel-card img { width: 100%; aspect-ratio: 16 / 9; object-fit: cover; }
.sub-channel-card .info { padding: 1.2rem; }
.sub-channel-card .info h4 { margin-bottom: 0.25rem; color: var(--text-primary); }
.sub-channel-card .info p { font-size: 0.9rem; color: var(--text-secondary); }
.stream-player {
    position: relative; width: 100%; height: 0; padding-bottom: 56.25%;
    background-color: #000; border-radius: 8px; overflow: hidden; border: 1px solid var(--accent);
}
.stream-player iframe, .stream-player img, .stream-player div#youtube-player {
    position: absolute; top: 0; left: 0; width: 100%; height: 100%; border: 0; object-fit: cover;
}
.content-card {
    background-color: var(--bg-secondary); border-radius: 8px; padding: 1.5rem;
    margin-top: 1.5rem; border: 1px solid var(--border-color);
}
.content-card .content-title { margin-bottom: 0.5rem; border-bottom: none; padding-bottom: 0; }
.action-buttons { margin-top: 1rem; display: flex; gap: 0.75rem; }
.btn-secondary { background-color: var(--bg-tertiary); color: var(--text-primary); }
.banners { display: grid; grid-template-columns: 1fr 1fr; gap: 1.5rem; margin-top: 1.5rem; }
.banner-slot img { width: 100%; border-radius: 6px; display: block; }

/* --- Right Sidebar (Live Chat) --- */
.sidebar-right { border: 1px solid var(--accent); }
.chat-container { height: calc(100vh - 3rem); display: flex; flex-direction: column; }
.chat-header {
    display: flex; justify-content: space-between; align-items: center;
    padding: 1.2rem; border-bottom: 1px solid var(--border-color);
}
.chat-header h3 { font-size: 0.9rem; font-weight: 600; text-transform: uppercase; letter-spacing: 1px; }
.chat-header-buttons {
    display: flex; gap: 0.5rem; align-items: center;
}
.chat-header button { background: none; border: none; color: var(--text-secondary); cursor: pointer; font-size: 1.2rem; }
.chat-header button:hover { color: var(--text-primary); }
#minimize-chat-button {
    color: var(--accent) !important;
}
#minimize-chat-button:hover {
    color: var(--accent-dark) !important;
}
.chat-topic {
    padding: 1rem 1.2rem; font-size: 0.9rem; color: var(--text-secondary);
    background-color: var(--bg-primary); border-bottom: 1px solid var(--border-color); line-height: 1.6;
}
.chat-topic a { color: var(--accent); text-decoration: none; font-weight: 600; }
.chat-topic a:hover { text-decoration: underline; }
.chat-topic b { color: var(--accent); font-weight: 700; }
.chat-messages { flex-grow: 1; overflow-y: auto; padding: 1.2rem; }
.chat-message { margin-bottom: 1rem; position: relative; line-height: 1.5; }
.chat-message .nickname { font-weight: 700; display: inline-block; margin-right: 0.5rem; color: var(--text-secondary); }
.delete-msg-btn {
    position: absolute; right: 0; top: 0; color: #ef4444; display: none;
    background: none; border: none; cursor: pointer;
}
.chat-message:hover .delete-msg-btn { display: block; }
.chat-input-area { padding: 1rem; border-top: 1px solid var(--border-color); background-color: var(--bg-primary); }
.chat-input-area input, .chat-input-area textarea {
    width: 100%; background: var(--bg-primary); border: 1px solid var(--border-color);
    color: var(--text-primary); border-radius: 6px; padding: 0.75rem;
    margin-bottom: 0.5rem; font-family: var(--font-family); font-size: 1rem;
}
.chat-input-area textarea { resize: none; }
.chat-input-area input:focus, .chat-input-area textarea:focus { border-color: var(--accent); outline: none; }
.nickname-input-group { display: flex; gap: 0.5rem; margin-bottom: 0.5rem; }
.nickname-input-group input { margin-bottom: 0; }
.chat-message.admin {
    background-color: rgba(255, 182, 42, 0.05); border-left: 3px solid var(--accent);
    padding-left: 0.75rem; border-radius: 3px;
}
.chat-message.admin .nickname { color: var(--accent); }
.chat-message.admin .nickname::before {
    font-family: "Font Awesome 6 Free"; font-weight: 900;
    content: "\f3ed"; margin-right: 0.5rem; font-size: 0.9em;
}

/* --- MODAL DEFINITIVE FIX --- */
.modal-overlay {
    position: fixed; top: 0; left: 0; width: 100%; height: 100%;
    background: rgba(0, 0, 0, 0.8);
    display: flex; justify-content: center; align-items: center;
    z-index: 9999;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.2s ease, visibility 0.2s ease;
}
.modal-overlay.visible {
    opacity: 1;
    visibility: visible;
}
.modal-content {
    background: var(--bg-secondary); padding: 2rem; border-radius: 8px;
    position: relative; border: 1px solid var(--border-color);
    width: 100%; max-width: 380px;
    transform: scale(0.95);
    transition: transform 0.2s ease;
    z-index: 10000;
}
.modal-overlay.visible .modal-content {
    transform: scale(1);
}
.close-btn {
    position: absolute; top: 0.5rem; right: 1rem; font-size: 2rem;
    color: var(--text-secondary); cursor: pointer; z-index: 10;
}
.modal-content h4 { text-align: center; margin-bottom: 1.5rem; }
.modal-content input { width: 100%; margin-bottom: 1rem; }

.widget-modal .modal-content { max-width: 900px; height: 85vh; padding: 1rem; display: flex; flex-direction: column; }
.widget-modal iframe { flex-grow: 1; width: 100%; border: none; border-radius: 6px; }

/* --- Mobile --- */
.hamburger-menu { display: none; background: none; border: none; color: var(--text-primary); font-size: 1.5rem; cursor: pointer; z-index: 1101; }
.sidebar-overlay { display: none; position: fixed; top: 0; left: 0; width: 100%; height: 100%; background-color: rgba(0, 0, 0, 0.6); z-index: 1050; }
@media (max-width: 1200px) {
    .main-container { grid-template-columns: 1fr 360px; padding: 0 1rem 1rem 1rem; }
    .sidebar-left {
        position: fixed; left: 0; top: 0; height: 100%; width: 280px; z-index: 1100;
        transform: translateX(-100%); transition: transform 0.3s ease-in-out;
        border-radius: 0; overflow-y: auto;
    }
    .sidebar-left.open { transform: translateX(0); }
    .hamburger-menu { display: block; }
    .header-container { grid-template-columns: auto 1fr auto; }
    .header-container .logo-container { justify-self: center; }
    .main-channel-card { flex-direction: column; }
    .main-channel-card img { width: 100%; }
    .main-channel-card .info { padding: 1.5rem; }
}
@media (max-width: 992px) {
    .main-container { grid-template-columns: 1fr; }
    .sidebar-left, .sidebar-right { order: 3; }
    .widget-modal .modal-content { max-width: 95vw; height: 80vh; }
}

/* --- Video Controls --- */
.stream-player {
    position: relative;
    background: #000;
    border-radius: 8px;
    overflow: hidden;
    aspect-ratio: 16/9;
}

.video-controls-overlay {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    background: linear-gradient(transparent, rgba(0,0,0,0.8));
    padding: 1rem;
    opacity: 0;
    transition: opacity 0.3s ease;
    z-index: 100;
}

.stream-player:hover .video-controls-overlay,
.video-controls-overlay.show {
    opacity: 1;
}

.video-controls {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 1rem;
}

.control-group {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.control-btn {
    background: rgba(255, 255, 255, 0.2);
    border: none;
    color: white;
    padding: 0.5rem;
    border-radius: 50%;
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: background-color 0.2s;
}

.control-btn:hover {
    background: rgba(255, 255, 255, 0.3);
}

.volume-control {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.volume-slider {
    width: 80px;
    height: 4px;
    background: rgba(255, 255, 255, 0.3);
    outline: none;
    border-radius: 2px;
}

.volume-slider::-webkit-slider-thumb {
    appearance: none;
    width: 16px;
    height: 16px;
    background: var(--accent);
    border-radius: 50%;
    cursor: pointer;
}

.quality-selector {
    position: relative;
}

.quality-btn {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.5rem 1rem;
    border-radius: 20px;
    width: auto;
}

.quality-menu {
    position: absolute;
    bottom: 100%;
    right: 0;
    background: rgba(0, 0, 0, 0.9);
    border-radius: 8px;
    padding: 0.5rem;
    margin-bottom: 0.5rem;
    min-width: 100px;
}

.quality-option {
    display: block;
    width: 100%;
    background: none;
    border: none;
    color: white;
    padding: 0.5rem 1rem;
    text-align: left;
    border-radius: 4px;
    cursor: pointer;
    transition: background-color 0.2s;
}

.quality-option:hover {
    background: rgba(255, 255, 255, 0.1);
}

.quality-option.active {
    background: var(--accent);
    color: #000;
}

/* --- Mobile Chat Toggle --- */
.mobile-chat-toggle {
    display: none;
    position: fixed;
    bottom: 20px;
    right: 20px;
    width: 60px;
    height: 60px;
    border-radius: 50%;
    background: var(--accent);
    border: none;
    color: #000;
    font-size: 1.5rem;
    cursor: pointer;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
    z-index: 1000;
    transition: transform 0.2s;
}

.mobile-chat-toggle:hover {
    transform: scale(1.1);
}

.chat-badge {
    position: absolute;
    top: -5px;
    right: -5px;
    background: #ff4444;
    color: white;
    border-radius: 50%;
    width: 20px;
    height: 20px;
    font-size: 0.75rem;
    display: flex;
    align-items: center;
    justify-content: center;
}

/* --- PWA Install Prompt --- */
.pwa-install-prompt {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    background: rgba(0, 0, 0, 0.9);
    z-index: 2000;
    transform: translateY(100%);
    transition: transform 0.3s ease;
}

.pwa-install-prompt.show {
    transform: translateY(0);
}

.install-card {
    background: var(--bg-secondary);
    margin: 1rem;
    border-radius: 8px;
    border: 1px solid var(--accent);
}

.install-content {
    padding: 1.5rem;
    text-align: center;
}

.install-content h4 {
    margin-bottom: 0.5rem;
    color: var(--accent);
}

.install-content p {
    margin-bottom: 1.5rem;
    color: var(--text-secondary);
}

.install-buttons {
    display: flex;
    gap: 1rem;
    justify-content: center;
}

.btn-secondary {
    background: transparent;
    border: 1px solid var(--border-color);
    color: var(--text-secondary);
    padding: 0.6rem 1.2rem;
    border-radius: 6px;
    cursor: pointer;
    transition: background-color 0.2s;
}

.btn-secondary:hover {
    background: var(--bg-tertiary);
}

/* --- Enhanced Mobile Styles --- */
@media (max-width: 768px) {
    .header-container {
        padding: 0.5rem 1rem;
    }

    .main-container {
        margin: 1rem auto;
        padding: 0 1rem;
        gap: 1rem;
    }

    .stream-player {
        margin-bottom: 1rem;
    }

    .video-controls {
        flex-wrap: wrap;
        gap: 0.5rem;
    }

    .control-btn {
        width: 44px;
        height: 44px;
        font-size: 1.1rem;
    }

    .volume-slider {
        width: 60px;
    }

    .mobile-chat-toggle {
        display: flex;
    }

    .sidebar-right {
        position: fixed;
        bottom: 0;
        left: 0;
        right: 0;
        height: 50vh;
        transform: translateY(100%);
        transition: transform 0.3s ease;
        z-index: 1200;
        border-radius: 16px 16px 0 0;
        border: 1px solid var(--accent);
    }

    .sidebar-right.open {
        transform: translateY(0);
    }

    .chat-container {
        height: 100%;
        border-radius: 16px 16px 0 0;
    }

    .install-buttons {
        flex-direction: column;
    }

    .quality-menu {
        right: auto;
        left: 0;
    }

    /* Touch-friendly improvements */
    .sidebar-nav a {
        padding: 1rem 1.2rem;
        font-size: 1rem;
    }

    .btn {
        min-height: 44px;
        font-size: 1rem;
    }

    /* Video fullscreen on mobile */
    .stream-player.fullscreen {
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        z-index: 9999;
        border-radius: 0;
        aspect-ratio: unset;
    }
}

@media (max-width: 480px) {
    .header-container {
        grid-template-columns: auto 1fr auto;
        gap: 0.5rem;
    }

    .control-group {
        gap: 0.5rem;
    }

    .volume-control {
        display: none;
    }

    .main-container {
        padding: 0 0.5rem;
    }
}

/* --- Chat Auto Scroll Enhancement --- */
.chat-container {
    position: relative;
}

.new-message-indicator {
    position: absolute;
    bottom: 80px;
    left: 50%;
    transform: translateX(-50%);
    background: var(--accent);
    color: #000;
    padding: 0.5rem 1rem;
    border-radius: 20px;
    display: none;
    align-items: center;
    gap: 0.5rem;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
    z-index: 100;
    font-size: 0.875rem;
    font-weight: 600;
    animation: slideUp 0.3s ease;
}

.new-message-indicator button {
    background: rgba(0, 0, 0, 0.2);
    border: none;
    color: #000;
    border-radius: 50%;
    width: 24px;
    height: 24px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: background-color 0.2s;
}

.new-message-indicator button:hover {
    background: rgba(0, 0, 0, 0.3);
}

@keyframes slideUp {
    from {
        opacity: 0;
        transform: translateX(-50%) translateY(20px);
    }
    to {
        opacity: 1;
        transform: translateX(-50%) translateY(0);
    }
}

/* Chat messages styling enhancement */
#chat-messages {
    scroll-behavior: smooth;
    scrollbar-width: thin;
    scrollbar-color: var(--accent) var(--bg-tertiary);
}

#chat-messages::-webkit-scrollbar {
    width: 6px;
}

#chat-messages::-webkit-scrollbar-track {
    background: var(--bg-tertiary);
    border-radius: 3px;
}

#chat-messages::-webkit-scrollbar-thumb {
    background: var(--accent);
    border-radius: 3px;
}

#chat-messages::-webkit-scrollbar-thumb:hover {
    background: var(--accent-dark);
}

/* Mobile chat auto scroll */
@media (max-width: 768px) {
    .new-message-indicator {
        bottom: 60px;
        font-size: 0.8rem;
        padding: 0.4rem 0.8rem;
    }

    .new-message-indicator button {
        width: 20px;
        height: 20px;
        font-size: 0.75rem;
    }
}