/* M3U Hierarchical List Frontend Styles */
.m3u-hierarchical-container {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    max-width: 1200px;
    margin: 0 auto;
    padding: 20px;
    background: #f8f9fa;
    border-radius: 12px;
    box-shadow: 0 2px 10px rgba(0,0,0,0.05);
    position: relative;
    min-height: 400px;
}

/* Views */
.m3u-view-active {
    display: block !important;
    animation: fadeIn 0.3s ease;
}

.m3u-view-hidden {
    display: none !important;
}

/* Headers */
.m3u-title {
    color: #1a1a1a;
    font-size: 24px;
    margin: 0 0 20px;
    padding-bottom: 15px;
    border-bottom: 2px solid #e0e0e0;
}

.m3u-header {
    margin-bottom: 25px;
}

.m3u-selected-country,
.m3u-selected-category {
    display: flex;
    align-items: center;
    gap: 12px;
    color: #2c3e50;
    font-size: 20px;
    margin: 10px 0 20px;
    padding: 10px 15px;
    background: white;
    border-radius: 8px;
    border-left: 4px solid #4a6fa5;
}

/* Back buttons */
.m3u-back-button {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    background: #4a6fa5;
    color: white;
    border: none;
    border-radius: 6px;
    padding: 10px 18px;
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s ease;
    margin: 0 0 15px 0;
}

.m3u-back-button:hover {
    background: #3a5a8c;
    transform: translateY(-1px);
    box-shadow: 0 3px 8px rgba(58, 90, 140, 0.2);
}

/* Grids */
.m3u-countries-grid,
.m3u-categories-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
    gap: 15px;
    margin-top: 15px;
}
.m3u-channels-grid {
    display: block;
}

@media (max-width: 768px) {
    .m3u-countries-grid,
    .m3u-categories-grid,
    .m3u-channels-grid {
        grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
        gap: 12px;
    }
}

@media (max-width: 480px) {
    .m3u-countries-grid,
    .m3u-categories-grid,
    .m3u-channels-grid {
        grid-template-columns: repeat(2, 1fr);
        gap: 10px;
    }
}

/* Items */
.m3u-country-item,
.m3u-category-item {
    background: white;
    border-radius: 10px;
    padding: 20px 15px;
    cursor: pointer;
    transition: all 0.25s ease;
    text-align: center;
    box-shadow: 0 3px 10px rgba(0,0,0,0.08);
    border: 1px solid #e8e8e8;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    min-height: 120px;
}

.m3u-country-item:hover,
.m3u-category-item:hover {
    transform: translateY(-3px);
    box-shadow: 0 6px 20px rgba(0,0,0,0.12);
    border-color: #4a6fa5;
}

.m3u-country-flag {
    width: 48px;
    height: 32px;
    background-size: contain;
    background-repeat: no-repeat;
    background-position: center;
    margin-bottom: 12px;
    border-radius: 4px;
    border: 1px solid #e0e0e0;
}

.m3u-country-name {
    font-weight: 600;
    color: #2c3e50;
    font-size: 16px;
    margin-bottom: 5px;
}

.m3u-country-count,
.m3u-category-count {
    font-size: 13px;
    color: #7f8c8d;
    background: #f8f9fa;
    padding: 3px 10px;
    border-radius: 12px;
    margin-top: 5px;
}

.m3u-category-name {
    font-weight: 600;
    color: #2c3e50;
    font-size: 16px;
    margin-bottom: 8px;
}

/* Kanal satırı */
.m3u-channel-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 12px;
    border-bottom: 1px solid #e0e0e0;
    border-radius: 0;
    box-shadow: none;
    background: #fff;
}

.m3u-channel-item:hover {
    background: #f5f7fa;
    transform: none;
    box-shadow: none;
}
.m3u-channel-logo-container {
    flex-shrink: 0;
    width: 36px;
    height: 36px;
    border-radius: 6px;
    overflow: hidden;
    background: #f8f9fa;
    display: flex;
    align-items: center;
    justify-content: center;
    border: 1px solid #e8e8e8;
}

.m3u-channel-logo {
    width: 100%;
    height: 100%;
    object-fit: contain;
    padding: 4px;
    transition: opacity 0.3s ease;
}

.m3u-channel-logo[src*="default-channel"] {
    opacity: 0.6;
    padding: 12px;
}

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

.m3u-channel-name {
    font-weight: 600;
    color: #2c3e50;
    font-size: 14px;
    margin-bottom: 4px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.m3u-channel-id {
    font-size: 13px;
    color: #7f8c8d;
    font-family: monospace;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* Search - COMPLETELY FIXED */
.m3u-search-wrapper {
    margin: 20px 0 25px 0;
    padding: 0;
    background: transparent;
    position: relative;
    width: 100%;
}

.m3u-search-container {
    position: relative;
    width: 100%;
    margin: 0;
    padding: 0;
    overflow: hidden; /* taşmayı engeller */
}

.m3u-search-input {
    width: 100%;
    height: 52px;
    padding: 0 70px 0 45px; /* SOL: 45px (ikon), SAĞ: 70px (X butonu + boşluk) */
    border: 2px solid #e0e0e0;
    border-radius: 10px;
    font-size: 16px;
    transition: all 0.3s ease;
    background: white;
    color: #333;
    box-shadow: 0 2px 8px rgba(0,0,0,0.05);
    box-sizing: border-box;
    line-height: normal;
}

.m3u-search-input:focus {
    outline: none;
    border-color: #4a6fa5;
    box-shadow: 0 4px 15px rgba(74, 111, 165, 0.15);
    background-color: #fff;
}

.m3u-search-input::placeholder {
    color: #999;
    font-weight: 400;
}



/* Search loading indicator */
.m3u-search-loading {
    position: absolute;
    right: 50px; /* Clear butonunun solunda */
    top: 50%;
    transform: translateY(-50%);
    width: 16px;
    height: 16px;
    border: 2px solid #f3f3f3;
    border-top: 2px solid #4a6fa5;
    border-radius: 50%;
    animation: spin 1s linear infinite;
    display: none;
    z-index: 5;
}

.m3u-search-loading.active {
    display: block;
}

/* Search info */
.m3u-search-info {
    text-align: left;
    color: #666;
    font-size: 14px;
    margin-top: 8px;
    font-style: italic;
    padding-left: 5px;
}

/* Search results count */
.m3u-search-results-count {
    color: #4a6fa5;
    font-size: 14px;
    margin: 10px 0 20px;
    font-weight: 500;
    background: rgba(74, 111, 165, 0.1);
    padding: 6px 12px;
    border-radius: 20px;
    display: inline-block;
}

/* Responsive adjustments for search */
@media (max-width: 768px) {
    .m3u-search-input {
        height: 48px;
        padding: 0 60px 0 40px;
        font-size: 15px;
    }
    
    .m3u-search-clear {
        width: 24px;
        height: 24px;
        right: 12px;
        font-size: 16px;
    }
    
    .m3u-search-icon {
        left: 12px;
        font-size: 14px;
    }
    
    .m3u-search-loading {
        right: 42px;
        width: 14px;
        height: 14px;
    }
}

@media (max-width: 480px) {
    .m3u-search-input {
        height: 44px;
        padding: 0 55px 0 35px;
        font-size: 14px;
    }
    
    .m3u-search-clear {
        width: 22px;
        height: 22px;
        right: 10px;
        font-size: 14px;
    }
    
    .m3u-search-icon {
        left: 10px;
        font-size: 13px;
    }
    
    .m3u-search-loading {
        right: 38px;
    }
}

/* Pagination */
.m3u-pagination {
    margin-top: 30px;
    padding-top: 20px;
    border-top: 1px solid #e8e8e8;
    width: 100%;
}

.m3u-pagination-controls {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 15px;
    flex-wrap: wrap;
    width: 100%;
}

.m3u-page-prev,
.m3u-page-next {
    background: #4a6fa5;
    color: white;
    border: none;
    border-radius: 6px;
    padding: 10px 20px;
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s ease;
    min-width: 100px;
}

.m3u-page-prev:hover,
.m3u-page-next:hover {
    background: #3a5a8c;
    transform: translateY(-1px);
    box-shadow: 0 3px 8px rgba(58, 90, 140, 0.2);
}

.m3u-page-prev:disabled,
.m3u-page-next:disabled {
    background: #cccccc;
    cursor: not-allowed;
    transform: none;
    box-shadow: none;
}

.m3u-page-info {
    color: #666;
    font-size: 14px;
    padding: 8px 16px;
    background: #f8f9fa;
    border-radius: 6px;
    min-width: 150px;
    text-align: center;
    font-weight: 500;
}

/* Loading & Error States */
.m3u-loading {
    text-align: center;
    padding: 60px 20px;
    color: #666;
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(255, 255, 255, 0.95);
    z-index: 10;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    backdrop-filter: blur(2px);
}

.m3u-spinner {
    display: inline-block;
    width: 40px;
    height: 40px;
    border: 3px solid #f3f3f3;
    border-top: 3px solid #4a6fa5;
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin-bottom: 15px;
}

.m3u-error,
.m3u-error-message {
    background: #fee;
    color: #c33;
    padding: 20px;
    border-radius: 8px;
    border-left: 4px solid #c33;
    margin: 20px 0;
    text-align: center;
}

/* Animations */
@keyframes fadeIn {
    from { opacity: 0; transform: translateY(10px); }
    to { opacity: 1; transform: translateY(0); }
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

/* Lazy loading */
.m3u-channel-logo[data-src]:not([src]) {
    opacity: 0;
}

.m3u-channel-logo.loaded {
    opacity: 1;
    animation: fadeIn 0.5s ease;
}

/* No results */
.m3u-no-results {
    grid-column: 1 / -1;
    text-align: center;
    padding: 60px 20px;
    color: #666;
    background: white;
    border-radius: 10px;
    border: 2px dashed #e0e0e0;
    font-size: 16px;
}

.m3u-no-results:before {
    content: "🔍";
    display: block;
    font-size: 48px;
    margin-bottom: 15px;
    opacity: 0.5;
}

/* Channel view specific fixes */
.m3u-channels-view {
    width: 100%;
}

.m3u-channels-view .m3u-search-wrapper {
    background: transparent;
    padding: 0;
    margin: 0 0 20px 0;
}

/* Ensure search aligns with grid */
.m3u-channels-view .m3u-search-container {
    width: 100%;
    max-width: none;
}

/* Channel grid wrapper for proper alignment */
.m3u-channels-grid-wrapper {
    width: 100%;
}

/* Grid container fix */
.m3u-channels-view > .m3u-channels-grid {
    width: 100%;
    margin-left: 0;
    margin-right: 0;
}

/* Channels header section */
.m3u-channels-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 20px;
    flex-wrap: wrap;
    gap: 15px;
}

.m3u-channels-header .m3u-back-button {
    margin: 0;
}

.m3u-channels-header .m3u-selected-category {
    margin: 0;
    flex: 1;
    min-width: 200px;
}

/* Make sure search doesn't have extra margins */
.m3u-search-wrapper:only-child {
    margin-bottom: 0;
}

/* Fix for inline elements */
.m3u-search-container {
    display: block;
}

/* Clear float issues */
.m3u-search-wrapper:after {
    content: "";
    display: table;
    clear: both;
}

/* Focus styles for accessibility */
.m3u-search-input:focus-visible {
    outline: 2px solid #4a6fa5;
    outline-offset: 2px;
}

/* Responsive adjustments */
@media (max-width: 768px) {
    .m3u-hierarchical-container {
        padding: 15px;
    }
    
    .m3u-selected-country,
    .m3u-selected-category {
        font-size: 16px;
        padding: 8px 12px;
    }
    
    .m3u-back-button {
        padding: 8px 14px;
        font-size: 13px;
    }
    
    .m3u-channel-item {
        padding: 12px;
        gap: 10px;
    }
    
    .m3u-channel-logo-container {
        width: 50px;
        height: 50px;
    }
}

@media (max-width: 480px) {
    .m3u-pagination-controls {
        flex-direction: column;
        gap: 10px;
    }
    
    .m3u-page-prev,
    .m3u-page-next {
        width: 100%;
        min-width: auto;
    }
    
    .m3u-channels-header {
        flex-direction: column;
        align-items: flex-start;
        gap: 10px;
    }
    
    .m3u-channels-header .m3u-selected-category {
        min-width: 100%;
        order: 2;
    }
    
    .m3u-channels-header .m3u-back-button {
        order: 1;
        align-self: flex-start;
    }
}