/* Reset and Base Styles */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

html {
    font-size: 16px;
    -webkit-text-size-adjust: 100%;
    scroll-behavior: smooth;
}

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    line-height: 1.6;
    color: #333;
    background: linear-gradient(135deg, #1a1a2e 0%, #16213e 50%, #0f3460 100%);
    min-height: 100vh;
    overflow-x: hidden;
    position: relative;
}

/* Header Styles */
header {
    background: linear-gradient(135deg, #0f3460 0%, #1a1a2e 100%);
    color: white;
    padding: 1rem;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.3);
    position: sticky;
    top: 0;
    z-index: 1000;
    width: 100%;
    max-width: 100vw;
}

.header-content {
    max-width: 100%;
    margin: 0 auto;
    text-align: center;
}

.header-content h1 {
    font-size: clamp(1.5rem, 5vw, 2.2rem);
    margin-bottom: 0.5rem;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    flex-wrap: wrap;
}

.powered-by {
    font-size: clamp(0.8rem, 3vw, 1rem);
    opacity: 0.9;
    margin-bottom: 1rem;
}

/* Search Container */
.search-container {
    max-width: 100%;
    margin: 0 auto;
    position: relative;
    padding: 0 0.5rem;
}

#search-input {
    width: 100%;
    padding: 0.875rem 1rem;
    border: none;
    border-radius: 50px;
    font-size: 1rem;
    background: rgba(255, 255, 255, 0.95);
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.1);
    transition: all 0.3s ease;
}

#search-input:focus {
    outline: none;
    background: white;
    box-shadow: 0 6px 20px rgba(0, 0, 0, 0.15);
    transform: translateY(-2px);
}

#search-btn {
    position: absolute;
    right: 0.75rem;
    top: 50%;
    transform: translateY(-50%);
    background: #0f3460;
    color: white;
    border: none;
    border-radius: 50%;
    width: 2.75rem;
    height: 2.75rem;
    cursor: pointer;
    transition: all 0.3s ease;
}

#search-btn:hover {
    background: #1a5ba3;
    transform: translateY(-50%) scale(1.05);
}

/* Main Content */
main {
    max-width: 100vw;
    margin: 0 auto;
    padding: 1rem;
}

.container {
    max-width: 100%;
    margin: 0 auto;
}

/* Welcome Section */
.welcome-section {
    background: linear-gradient(135deg, rgba(255, 255, 255, 0.1) 0%, rgba(255, 255, 255, 0.05) 100%);
    backdrop-filter: blur(10px);
    border-radius: 20px;
    padding: 1.5rem;
    margin-bottom: 1.5rem;
    border: 1px solid rgba(255, 255, 255, 0.1);
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.1);
}

.welcome-content h2 {
    color: white;
    font-size: clamp(1.3rem, 4vw, 1.8rem);
    margin-bottom: 1rem;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.welcome-content p {
    color: rgba(255, 255, 255, 0.9);
    margin-bottom: 1rem;
    font-size: clamp(0.9rem, 3vw, 1rem);
}

.welcome-features {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
    gap: 1rem;
    margin-top: 1.5rem;
}

.feature {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    color: rgba(255, 255, 255, 0.9);
    font-size: 0.9rem;
}

.feature i {
    color: #4fc3f7;
    font-size: 1.1rem;
}

/* Controls Section */
.controls-section {
    background: rgba(255, 255, 255, 0.95);
    border-radius: 15px;
    padding: 1.25rem;
    margin-bottom: 1.5rem;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.1);
}

.filter-controls {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 1rem;
    margin-bottom: 1rem;
}

.filter-group {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.filter-group label {
    font-weight: 600;
    color: #333;
    font-size: 0.9rem;
}

.filter-group select {
    padding: 0.75rem;
    border: 2px solid #e1e5e9;
    border-radius: 10px;
    font-size: 0.9rem;
    background: white;
    transition: all 0.3s ease;
}

.filter-group select:focus {
    outline: none;
    border-color: #0f3460;
    box-shadow: 0 0 0 3px rgba(15, 52, 96, 0.1);
}

.btn-toggle, .btn-secondary {
    padding: 0.75rem 1rem;
    border: none;
    border-radius: 10px;
    font-size: 0.9rem;
    cursor: pointer;
    transition: all 0.3s ease;
    font-weight: 600;
}

.btn-toggle {
    background: #ff6b6b;
    color: white;
}

.btn-toggle:hover {
    background: #ff5252;
    transform: translateY(-2px);
}

.btn-secondary {
    background: #6c757d;
    color: white;
}

.btn-secondary:hover {
    background: #5a6268;
    transform: translateY(-2px);
}

.refresh-controls {
    display: flex;
    flex-wrap: wrap;
    gap: 1rem;
    align-items: center;
    padding-top: 1rem;
    border-top: 1px solid #e1e5e9;
}

.refresh-group {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.refresh-group label {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    cursor: pointer;
    font-size: 0.9rem;
}

/* Countries Grid */
.countries-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
    gap: 1rem;
    margin-bottom: 2rem;
}

.country-card {
    background: white;
    border-radius: 15px;
    padding: 1.5rem 1rem;
    text-align: center;
    cursor: pointer;
    transition: all 0.3s ease;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.1);
    border: 2px solid transparent;
}

.country-card:hover {
    transform: translateY(-5px);
    box-shadow: 0 8px 25px rgba(0, 0, 0, 0.15);
    border-color: #0f3460;
}

.country-flag {
    font-size: 2rem;
    margin-bottom: 0.5rem;
}

.country-name {
    font-weight: 600;
    color: #333;
    margin-bottom: 0.25rem;
    font-size: 0.9rem;
}

.channel-count {
    color: #6c757d;
    font-size: 0.8rem;
}

.country-arrow {
    color: #0f3460;
    margin-top: 0.5rem;
}

/* Channels Section */
.channels-section {
    width: 100%;
}

.section-header {
    margin-bottom: 1.5rem;
}

.section-header h2 {
    color: white;
    font-size: clamp(1.5rem, 4vw, 2rem);
    text-align: center;
}

#loading {
    text-align: center;
    color: white;
    font-size: 1.1rem;
    padding: 2rem;
}

/* Channels Grid */
.channels-grid {
    width: 100%;
}

.channels-header {
    background: rgba(255, 255, 255, 0.95);
    border-radius: 15px;
    padding: 1.5rem;
    margin-bottom: 1.5rem;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.1);
}

.channels-header h2 {
    color: #333;
    margin-bottom: 0.5rem;
    font-size: clamp(1.2rem, 3vw, 1.5rem);
}

.stream-count {
    font-size: 0.9rem;
    color: #6c757d;
    font-weight: normal;
}

.active-filters {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
}

.filter-tag {
    background: #0f3460;
    color: white;
    padding: 0.25rem 0.75rem;
    border-radius: 20px;
    font-size: 0.8rem;
}

/* Category Sections */
.category-section {
    margin-bottom: 2rem;
}

.category-title {
    color: white;
    font-size: clamp(1.1rem, 3vw, 1.3rem);
    margin-bottom: 1rem;
    padding-bottom: 0.5rem;
    border-bottom: 2px solid rgba(255, 255, 255, 0.2);
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.channel-count-badge {
    background: #4fc3f7;
    color: white;
    padding: 0.25rem 0.5rem;
    border-radius: 10px;
    font-size: 0.8rem;
}

.stream-count-badge {
    background: #ffa726;
    color: white;
    padding: 0.25rem 0.5rem;
    border-radius: 10px;
    font-size: 0.7rem;
}

/* Channel Cards */
.channels-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: 1.25rem;
    width: 100%;
}

.channel-card {
    background: white;
    border-radius: 15px;
    overflow: hidden;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.1);
    transition: all 0.3s ease;
    border: 2px solid transparent;
}

.channel-card:hover {
    transform: translateY(-5px);
    box-shadow: 0 8px 25px rgba(0, 0, 0, 0.15);
    border-color: #0f3460;
}

.channel-card.no-stream {
    opacity: 0.7;
    border-color: #6c757d;
}

.channel-thumbnail {
    position: relative;
    width: 100%;
    height: 160px;
    overflow: hidden;
}

.channel-logo {
    width: 100%;
    height: 100%;
    object-fit: cover;
    transition: transform 0.3s ease;
}

.channel-card:hover .channel-logo {
    transform: scale(1.05);
}

.channel-overlay {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.3);
    display: flex;
    align-items: center;
    justify-content: center;
}

.no-stream-info {
    background: rgba(255, 107, 107, 0.9);
    color: white;
    padding: 0.5rem 1rem;
    border-radius: 10px;
    font-size: 0.8rem;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.channel-number {
    position: absolute;
    top: 0.5rem;
    left: 0.5rem;
    background: rgba(15, 52, 96, 0.9);
    color: white;
    padding: 0.25rem 0.5rem;
    border-radius: 8px;
    font-size: 0.8rem;
    font-weight: 600;
}

.channel-info {
    padding: 1.25rem;
}

.channel-name {
    font-weight: 600;
    color: #333;
    margin-bottom: 0.5rem;
    font-size: 1rem;
    line-height: 1.3;
}

.channel-meta {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1rem;
    flex-wrap: wrap;
    gap: 0.5rem;
}

.channel-category {
    background: #e3f2fd;
    color: #0f3460;
    padding: 0.25rem 0.5rem;
    border-radius: 8px;
    font-size: 0.8rem;
    font-weight: 500;
}

.no-stream-badge {
    background: #ffcdd2;
    color: #c62828;
    padding: 0.25rem 0.5rem;
    border-radius: 8px;
    font-size: 0.7rem;
    font-weight: 500;
}

.play-btn {
    width: 100%;
    padding: 0.875rem;
    background: linear-gradient(135deg, #0f3460 0%, #1a5ba3 100%);
    color: white;
    border: none;
    border-radius: 10px;
    font-size: 0.9rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
}

.play-btn:hover:not(:disabled) {
    background: linear-gradient(135deg, #1a5ba3 0%, #0f3460 100%);
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(15, 52, 96, 0.3);
}

.play-btn:disabled {
    background: #6c757d;
    cursor: not-allowed;
    opacity: 0.6;
}

/* Back Button */
.back-button {
    background: linear-gradient(135deg, #0f3460 0%, #1a5ba3 100%);
    color: white;
    border: none;
    border-radius: 50px;
    padding: 0.875rem 1.5rem;
    font-size: 0.9rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s ease;
    margin-bottom: 1.5rem;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.2);
}

.back-button:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(0, 0, 0, 0.3);
}

/* No Results */
.no-results {
    text-align: center;
    padding: 3rem 1rem;
    color: white;
}

.no-results i {
    font-size: 3rem;
    margin-bottom: 1rem;
    opacity: 0.5;
}

.no-results h3 {
    font-size: 1.5rem;
    margin-bottom: 0.5rem;
}

.no-results p {
    margin-bottom: 1.5rem;
    opacity: 0.8;
}

.reset-filters-btn {
    background: #0f3460;
    color: white;
    border: none;
    border-radius: 10px;
    padding: 0.75rem 1.5rem;
    font-size: 0.9rem;
    cursor: pointer;
    transition: all 0.3s ease;
}

.reset-filters-btn:hover {
    background: #1a5ba3;
    transform: translateY(-2px);
}

/* Footer */
footer {
    background: linear-gradient(135deg, #0f3460 0%, #1a1a2e 100%);
    color: white;
    text-align: center;
    padding: 1.5rem;
    margin-top: 2rem;
    width: 100%;
}

footer p {
    font-size: 0.9rem;
    opacity: 0.9;
}

/* Responsive Design */
@media (max-width: 768px) {
    main {
        padding: 0.75rem;
    }
    
    .welcome-section {
        padding: 1.25rem;
        margin-bottom: 1.25rem;
    }
    
    .controls-section {
        padding: 1rem;
        margin-bottom: 1.25rem;
    }
    
    .filter-controls {
        grid-template-columns: 1fr;
        gap: 0.875rem;
    }
    
    .refresh-controls {
        flex-direction: column;
        align-items: flex-start;
        gap: 0.875rem;
    }
    
    .countries-grid {
        grid-template-columns: repeat(auto-fill, minmax(130px, 1fr));
        gap: 0.875rem;
    }
    
    .country-card {
        padding: 1.25rem 0.75rem;
    }
    
    .channels-grid {
        grid-template-columns: 1fr;
        gap: 1rem;
    }
    
    .channel-thumbnail {
        height: 140px;
    }
    
    .channel-info {
        padding: 1rem;
    }
    
    .welcome-features {
        grid-template-columns: 1fr;
        gap: 0.875rem;
    }
    
    .feature {
        font-size: 0.85rem;
    }
}

@media (max-width: 480px) {
    body {
        font-size: 14px;
    }
    
    header {
        padding: 0.875rem;
    }
    
    main {
        padding: 0.5rem;
    }
    
    .welcome-section {
        padding: 1rem;
        border-radius: 15px;
    }
    
    .controls-section {
        padding: 0.875rem;
        border-radius: 12px;
    }
    
    .countries-grid {
        grid-template-columns: repeat(auto-fill, minmax(110px, 1fr));
        gap: 0.75rem;
    }
    
    .country-card {
        padding: 1rem 0.5rem;
        border-radius: 12px;
    }
    
    .country-flag {
        font-size: 1.75rem;
    }
    
    .channel-thumbnail {
        height: 120px;
    }
    
    .search-container {
        padding: 0;
    }
    
    #search-input {
        padding: 0.75rem 1rem;
        font-size: 0.9rem;
    }
    
    #search-btn {
        width: 2.5rem;
        height: 2.5rem;
    }
}

/* Safe Area Insets for Notches */
@supports(padding: max(0px)) {
    body {
        padding-left: min(0px, env(safe-area-inset-left));
        padding-right: min(0px, env(safe-area-inset-right));
    }
    
    header {
        padding-left: max(1rem, env(safe-area-inset-left));
        padding-right: max(1rem, env(safe-area-inset-right));
    }
    
    main {
        padding-left: max(0.5rem, env(safe-area-inset-left));
        padding-right: max(0.5rem, env(safe-area-inset-right));
    }
}

/* Prevent horizontal scroll */
html, body {
    max-width: 100%;
    overflow-x: hidden;
}

/* Smooth scrolling for iOS */
body {
    -webkit-overflow-scrolling: touch;
}

/* Loading animation */
#loading {
    animation: pulse 1.5s ease-in-out infinite alternate;
}

@keyframes pulse {
    from { opacity: 0.6; }
    to { opacity: 1; }
}

/* Focus styles for accessibility */
button:focus-visible,
select:focus-visible,
input:focus-visible {
    outline: 2px solid #0f3460;
    outline-offset: 2px;
}

/* High contrast mode support */
@media (prefers-contrast: high) {
    .channel-card {
        border: 2px solid #333;
    }
    
    .btn-toggle, .btn-secondary, .play-btn {
        border: 2px solid currentColor;
    }
}

/* Reduced motion support */
@media (prefers-reduced-motion: reduce) {
    * {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}