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

:root {
    --primary-color: #667eea;
    --secondary-color: #764ba2;
    --bg-dark: #0f0f1a;
    --bg-card: rgba(255, 255, 255, 0.05);
    --border-color: rgba(255, 255, 255, 0.1);
    --text-primary: #fff;
    --text-secondary: rgba(255, 255, 255, 0.5);
}

html, body {
    height: 100%;
    overflow: hidden;
}

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background: linear-gradient(135deg, var(--bg-dark) 0%, #1a1a2e 100%);
    color: var(--text-primary);
    display: flex;
    flex-direction: column;
    height: 100vh;
    height: 100dvh; /* Dynamic viewport height for mobile */
}

/* Header */
header {
    background: linear-gradient(90deg, var(--primary-color) 0%, var(--secondary-color) 100%);
    padding: 12px 20px;
    box-shadow: 0 4px 20px rgba(102, 126, 234, 0.3);
    flex-shrink: 0;
}

header h1 {
    font-size: clamp(1.1rem, 4vw, 1.6rem);
    font-weight: 600;
    display: flex;
    align-items: center;
    gap: 10px;
}

header h1 i {
    font-size: clamp(1rem, 3.5vw, 1.4rem);
}

/* Main */
main {
    flex: 1;
    padding: 15px;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    min-height: 0;
}

footer {
    background-color: #426499;
    color: #ffffff;
    text-align: center;
    padding: 0.8rem 0;
    margin-top: auto;
    width: 100%;
    font-size: 0.9em;
}

.cor-link-rodape {
    color: #ffffff;
}

.cor-nome-dev-rodape {
    color: #cccccc;
}

.texto-rodape {
    font-size: 100%;;
    color: #fff;
}

/* Playlist Config */
.playlist-config {
    background: var(--bg-card);
    border-radius: 12px;
    padding: 15px;
    margin-bottom: 15px;
    backdrop-filter: blur(10px);
    border: 1px solid var(--border-color);
    flex-shrink: 0;
}

.input-group {
    display: flex;
    gap: 10px;
}

.input-group.epg-input {
    margin-top: 10px;
}

.input-group.epg-input input {
    font-size: clamp(0.75rem, 2vw, 0.9rem);
    padding: 10px 14px;
}

.input-group.epg-input button {
    padding: 10px 16px;
    background: linear-gradient(90deg, #11998e 0%, #38ef7d 100%);
}

.input-group input {
    flex: 1;
    min-width: 0;
    padding: 12px 16px;
    border: 2px solid var(--border-color);
    border-radius: 10px;
    background: rgba(0, 0, 0, 0.3);
    color: var(--text-primary);
    font-size: clamp(0.85rem, 2.5vw, 1rem);
    transition: all 0.3s ease;
}

.input-group input:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 15px rgba(102, 126, 234, 0.3);
}

.input-group input::placeholder {
    color: rgba(255, 255, 255, 0.4);
}

.input-group button {
    padding: 12px 20px;
    background: linear-gradient(90deg, var(--primary-color) 0%, var(--secondary-color) 100%);
    border: none;
    border-radius: 10px;
    color: var(--text-primary);
    font-size: clamp(0.8rem, 2.5vw, 0.95rem);
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s ease;
    display: flex;
    align-items: center;
    gap: 8px;
    white-space: nowrap;
    flex-shrink: 0;
}

.input-group button:hover:not(:disabled) {
    transform: translateY(-2px);
    box-shadow: 0 8px 25px rgba(102, 126, 234, 0.4);
}

.input-group button:disabled {
    opacity: 0.7;
    cursor: not-allowed;
}

.hint {
    margin-top: 10px;
    font-size: clamp(0.75rem, 2vw, 0.85rem);
    color: var(--text-secondary);
    display: flex;
    align-items: center;
    gap: 8px;
}

/* Container */
.container {
    display: flex;
    gap: 15px;
    flex: 1;
    min-height: 0;
    overflow: hidden;
}

/* Sidebar */
.sidebar {
    width: 320px;
    min-width: 280px;
    max-width: 350px;
    background: var(--bg-card);
    border-radius: 12px;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    border: 1px solid var(--border-color);
    flex-shrink: 0;
}

.search-box {
    padding: 12px;
    background: rgba(0, 0, 0, 0.2);
    display: flex;
    align-items: center;
    gap: 10px;
    border-bottom: 1px solid var(--border-color);
}

.search-box i {
    color: rgba(255, 255, 255, 0.4);
}

.search-box input {
    flex: 1;
    background: transparent;
    border: none;
    color: var(--text-primary);
    font-size: 0.9rem;
    min-width: 0;
}

.search-box input:focus {
    outline: none;
}

.search-box input::placeholder {
    color: rgba(255, 255, 255, 0.3);
}

.filtro-box {
    padding: 10px 12px;
    border-bottom: 1px solid var(--border-color);
}

.filtro-box select {
    width: 100%;
    padding: 10px 12px;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    background: rgba(0, 0, 0, 0.3);
    color: var(--text-primary);
    font-size: 0.85rem;
    cursor: pointer;
    transition: all 0.3s ease;
}

.filtro-box select:focus {
    outline: none;
    border-color: var(--primary-color);
}

.filtro-box select option {
    background: #1a1a2e;
    color: var(--text-primary);
}

.canais-info {
    padding: 10px 12px;
    background: rgba(102, 126, 234, 0.1);
    border-bottom: 1px solid var(--border-color);
    font-size: 0.8rem;
    color: var(--primary-color);
    font-weight: 600;
}

#lista-canais {
    flex: 1;
    list-style: none;
    overflow-y: auto;
    padding: 8px;
    min-height: 0;
}

#lista-canais::-webkit-scrollbar {
    width: 5px;
}

#lista-canais::-webkit-scrollbar-track {
    background: rgba(255, 255, 255, 0.05);
}

#lista-canais::-webkit-scrollbar-thumb {
    background: rgba(102, 126, 234, 0.5);
    border-radius: 3px;
}

.canal-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px;
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.2s ease;
    margin-bottom: 4px;
}

.canal-item:hover {
    background: rgba(255, 255, 255, 0.1);
}

.canal-item.ativo {
    background: linear-gradient(90deg, rgba(102, 126, 234, 0.3) 0%, rgba(118, 75, 162, 0.3) 100%);
    border: 1px solid rgba(102, 126, 234, 0.5);
}

.canal-logo {
    width: 40px;
    height: 40px;
    border-radius: 8px;
    background: rgba(255, 255, 255, 0.1);
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
    flex-shrink: 0;
}

.canal-logo img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.canal-logo i {
    font-size: 1rem;
    color: rgba(255, 255, 255, 0.5);
}

.canal-info {
    flex: 1;
    min-width: 0;
}

.canal-nome {
    display: block;
    font-weight: 500;
    font-size: 0.9rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.canal-grupo {
    display: block;
    font-size: 0.7rem;
    color: rgba(255, 255, 255, 0.4);
    margin-top: 2px;
}

.empty-state {
    text-align: center;
    padding: 30px 15px;
    color: rgba(255, 255, 255, 0.4);
}

.empty-state i {
    font-size: 2.5rem;
    margin-bottom: 12px;
    opacity: 0.5;
}

.empty-state p {
    font-size: 0.9rem;
    margin-bottom: 5px;
}

.empty-state small {
    font-size: 0.75rem;
}

/* Botão Carregar Mais */
.carregar-mais {
    padding: 12px;
    text-align: center;
}

.carregar-mais button {
    width: 100%;
    padding: 10px 15px;
    background: linear-gradient(90deg, rgba(102, 126, 234, 0.2) 0%, rgba(118, 75, 162, 0.2) 100%);
    border: 1px dashed rgba(102, 126, 234, 0.5);
    border-radius: 8px;
    color: var(--primary-color);
    font-size: 0.8rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.3s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
}

.carregar-mais button:hover {
    background: linear-gradient(90deg, rgba(102, 126, 234, 0.3) 0%, rgba(118, 75, 162, 0.3) 100%);
    border-color: var(--primary-color);
}

/* Player Section */
.player-section {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 12px;
    min-width: 0;
    min-height: 0;
}

.video-container {
    flex: 1;
    background: #000;
    border-radius: 12px;
    overflow: hidden;
    position: relative;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.5);
    min-height: 200px;
}

#player {
    width: 100%;
    height: 100%;
    display: block;
    object-fit: contain;
}

.video-overlay {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.8);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    color: var(--text-secondary);
}

.video-overlay i {
    font-size: clamp(3rem, 10vw, 5rem);
    margin-bottom: 15px;
    opacity: 0.3;
}

.video-overlay p {
    font-size: clamp(0.9rem, 2.5vw, 1.1rem);
}

.now-playing {
    background: var(--bg-card);
    padding: 12px 16px;
    border-radius: 10px;
    display: flex;
    align-items: center;
    gap: 10px;
    border: 1px solid var(--border-color);
    flex-shrink: 0;
}

.now-playing i {
    color: var(--primary-color);
    font-size: 1.1rem;
}

.now-playing span {
    font-weight: 500;
    font-size: clamp(0.85rem, 2.5vw, 1rem);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* ==================== EPG (Guia de Programação) ==================== */

.epg-container {
    background: var(--bg-card);
    border-radius: 10px;
    border: 1px solid var(--border-color);
    overflow: hidden;
    flex-shrink: 0;
    max-height: 250px;
    display: flex;
    flex-direction: column;
}

.epg-header {
    background: rgba(102, 126, 234, 0.15);
    padding: 10px 14px;
    display: flex;
    align-items: center;
    gap: 10px;
    border-bottom: 1px solid var(--border-color);
    flex-shrink: 0;
}

.epg-header i {
    color: var(--primary-color);
}

.epg-header span:first-of-type {
    font-weight: 600;
    font-size: 0.9rem;
}

.epg-status {
    margin-left: auto;
    font-size: 0.75rem;
    padding: 3px 8px;
    border-radius: 10px;
    background: rgba(255, 255, 255, 0.1);
}

.epg-status.loading {
    color: #ffd700;
}

.epg-status.loaded {
    color: #38ef7d;
    background: rgba(56, 239, 125, 0.1);
}

.epg-status.error {
    color: #ff6b6b;
    background: rgba(255, 107, 107, 0.1);
}

.epg-content {
    padding: 10px;
    overflow-y: auto;
    flex: 1;
}

.epg-content::-webkit-scrollbar {
    width: 4px;
}

.epg-content::-webkit-scrollbar-thumb {
    background: rgba(102, 126, 234, 0.4);
    border-radius: 2px;
}

.epg-empty {
    text-align: center;
    padding: 20px;
    color: var(--text-secondary);
}

.epg-empty i {
    font-size: 2rem;
    margin-bottom: 10px;
    opacity: 0.4;
}

.epg-empty p {
    font-size: 0.85rem;
    margin-bottom: 4px;
}

.epg-empty small {
    font-size: 0.75rem;
    opacity: 0.7;
}

.epg-item {
    display: flex;
    align-items: flex-start;
    gap: 12px;
    padding: 10px;
    border-radius: 8px;
    margin-bottom: 6px;
    background: rgba(255, 255, 255, 0.02);
    transition: all 0.2s ease;
}

.epg-item:hover {
    background: rgba(255, 255, 255, 0.05);
}

.epg-item.atual {
    background: linear-gradient(90deg, rgba(102, 126, 234, 0.2) 0%, rgba(118, 75, 162, 0.2) 100%);
    border: 1px solid rgba(102, 126, 234, 0.3);
}

.epg-horario {
    display: flex;
    flex-direction: column;
    align-items: center;
    min-width: 50px;
    flex-shrink: 0;
}

.epg-hora-inicio {
    font-weight: 600;
    font-size: 0.85rem;
    color: var(--primary-color);
}

.epg-hora-fim {
    font-size: 0.7rem;
    color: var(--text-secondary);
}

.epg-programa {
    flex: 1;
    min-width: 0;
}

.epg-titulo {
    display: block;
    font-weight: 500;
    font-size: 0.85rem;
    margin-bottom: 3px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.epg-categoria {
    display: inline-block;
    font-size: 0.65rem;
    padding: 2px 6px;
    background: rgba(102, 126, 234, 0.2);
    color: var(--primary-color);
    border-radius: 4px;
    margin-bottom: 4px;
}

.epg-descricao {
    display: block;
    font-size: 0.75rem;
    color: var(--text-secondary);
    line-height: 1.3;
}

.epg-progresso {
    margin-top: 6px;
    height: 3px;
    background: rgba(255, 255, 255, 0.1);
    border-radius: 2px;
    overflow: hidden;
}

.epg-progresso-bar {
    height: 100%;
    background: linear-gradient(90deg, var(--primary-color) 0%, var(--secondary-color) 100%);
    border-radius: 2px;
    transition: width 0.3s ease;
}

.epg-ao-vivo {
    background: #ff4757;
    color: #fff;
    font-size: 0.6rem;
    font-weight: 700;
    padding: 3px 6px;
    border-radius: 4px;
    animation: pulse 2s infinite;
    flex-shrink: 0;
}

@keyframes pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.6; }
}

/* Footer */
footer {
    text-align: center;
    padding: 12px;
    color: rgba(255, 255, 255, 0.3);
    font-size: 0.75rem;
    border-top: 1px solid rgba(255, 255, 255, 0.05);
    flex-shrink: 0;
}

/* ==================== RESPONSIVO ==================== */

/* Tablets e telas médias */
@media (max-width: 1024px) {
    main {
        padding: 12px;
    }

    .sidebar {
        width: 280px;
        min-width: 250px;
    }
}

/* Telas menores - layout vertical */
@media (max-width: 850px) {
    body {
        overflow: auto;
    }

    main {
        overflow: visible;
        padding: 10px;
    }

    .container {
        flex-direction: column;
        overflow: visible;
        height: auto;
    }

    .sidebar {
        width: 100%;
        max-width: 100%;
        min-width: 100%;
        max-height: 45vh;
        order: 2;
    }

    .player-section {
        order: 1;
        min-height: 0;
    }

    .video-container {
        min-height: 35vh;
        aspect-ratio: 16 / 9;
        flex: none;
    }
}

/* Mobile */
@media (max-width: 600px) {
    header {
        padding: 10px 15px;
    }

    main {
        padding: 8px;
    }

    .playlist-config {
        padding: 12px;
        border-radius: 10px;
        margin-bottom: 10px;
    }

    .input-group {
        flex-direction: column;
        gap: 8px;
    }

    .input-group input {
        padding: 12px 14px;
    }

    .input-group button {
        justify-content: center;
        padding: 12px 16px;
    }

    .hint {
        display: none;
    }

    .container {
        gap: 10px;
    }

    .sidebar {
        max-height: 40vh;
        border-radius: 10px;
    }

    .search-box, .filtro-box, .canais-info {
        padding: 10px;
    }

    .canal-item {
        padding: 8px;
    }

    .canal-logo {
        width: 36px;
        height: 36px;
    }

    .canal-nome {
        font-size: 0.85rem;
    }

    .video-container {
        min-height: 30vh;
        border-radius: 10px;
    }

    .now-playing {
        padding: 10px 12px;
        border-radius: 8px;
    }
}

/* Mobile pequeno */
@media (max-width: 400px) {
    header h1 {
        font-size: 1rem;
    }

    .sidebar {
        max-height: 35vh;
    }

    .canal-logo {
        width: 32px;
        height: 32px;
    }

    .canal-nome {
        font-size: 0.8rem;
    }

    .canal-grupo {
        font-size: 0.65rem;
    }
}

/* Landscape em mobile */
@media (max-height: 500px) and (orientation: landscape) {
    header {
        padding: 8px 15px;
    }

    header h1 {
        font-size: 1rem;
    }

    main {
        padding: 8px;
    }

    .playlist-config {
        padding: 10px;
        margin-bottom: 8px;
    }

    .input-group {
        flex-direction: row;
    }

    .input-group input {
        padding: 10px 12px;
    }

    .input-group button {
        padding: 10px 16px;
    }

    .hint {
        display: none;
    }

    .container {
        flex-direction: row;
        gap: 10px;
    }

    .sidebar {
        width: 250px;
        min-width: 220px;
        max-width: 280px;
        max-height: none;
        order: 0;
    }

    .player-section {
        order: 0;
    }

    .video-container {
        min-height: 0;
    }

    footer {
        display: none;
    }
}

/* Telas muito grandes */
@media (min-width: 1600px) {
    main {
        max-width: 1800px;
        margin: 0 auto;
        padding: 20px 30px;
    }

    .sidebar {
        width: 380px;
        max-width: 400px;
    }

    .canal-logo {
        width: 48px;
        height: 48px;
    }

    .canal-nome {
        font-size: 1rem;
    }
}
