/* ===== IPTV FastAPI v2 — Dark Theme ===== */
:root {
    --bg-primary: #0f0f1a;
    --bg-secondary: #1a1a2e;
    --bg-card: #16162a;
    --bg-card-hover: #1e1e3a;
    --accent: #6366f1;
    --accent-hover: #818cf8;
    --text-primary: #f1f1f6;
    --text-secondary: #a1a1aa;
    --text-muted: #71717a;
    --border: #27273f;
    --shadow: 0 4px 20px rgba(0,0,0,0.4);
    --radius: 16px;
    --radius-sm: 10px;
}

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

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
    background: var(--bg-primary);
    color: var(--text-primary);
    min-height: 100vh;
    line-height: 1.5;
}

/* Header */
.header {
    background: var(--bg-secondary);
    border-bottom: 1px solid var(--border);
    position: sticky;
    top: 0;
    z-index: 100;
    backdrop-filter: blur(20px);
}

.header-inner {
    max-width: 1400px;
    margin: 0 auto;
    padding: 16px 24px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 20px;
}

.header-left {
    display: flex;
    align-items: center;
    gap: 12px;
    flex-shrink: 0;
}

.header-right {
    display: flex;
    align-items: center;
    gap: 16px;
    flex: 1;
    justify-content: flex-end;  /* ← прижимает поиск к правому краю */
}

.logo {
    display: flex;
    align-items: center;
    gap: 12px;
    text-decoration: none;
    color: var(--text-primary);
    font-weight: 700;
    font-size: 22px;
}

.logo-icon {
    width: 40px; height: 40px;
    background: linear-gradient(135deg, var(--accent), #a855f7);
    border-radius: var(--radius-sm);
    display: flex; align-items: center; justify-content: center;
    font-size: 20px;
}

.search-box {
    position: relative;
    flex: 1;
    max-width: 400px;
}

.search-box input {
    width: 100%;
    padding: 12px 16px 12px 44px;
    background: var(--bg-primary);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    color: var(--text-primary);
    font-size: 15px;
    outline: none;
    transition: all 0.2s;
    font-family: inherit;
}

.search-box input:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px rgba(99,102,241,0.15);
}

.search-box input::placeholder { color: var(--text-muted); }

.search-icon {
    position: absolute;
    left: 14px; top: 50%;
    transform: translateY(-50%);
    color: var(--text-muted);
    font-size: 18px;
}

.mobile-menu-btn {
    display: none;
    background: none;
    border: none;
    color: var(--text-primary);
    font-size: 24px;
    cursor: pointer;
}

/* Categories */
.categories-bar {
    background: var(--bg-secondary);
    border-bottom: 1px solid var(--border);
    position: sticky;
    top: 73px;
    z-index: 90;
}

.categories-inner {
    max-width: 1400px;
    margin: 0 auto;
    padding: 12px 24px;
    display: flex;
    gap: 8px;
    overflow-x: auto;
    scrollbar-width: none;
    -ms-overflow-style: none;
}

.categories-inner::-webkit-scrollbar { display: none; }

.category-btn {
    padding: 8px 18px;
    background: transparent;
    border: 1px solid var(--border);
    border-radius: 100px;
    color: var(--text-secondary);
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    white-space: nowrap;
    transition: all 0.2s;
    font-family: inherit;
    text-decoration: none;
    display: inline-flex;
    align-items: center;
}

.category-btn:hover {
    border-color: var(--accent);
    color: var(--text-primary);
}

.category-btn.active {
    background: var(--accent);
    border-color: var(--accent);
    color: #fff;
}

/* Ad Banner */
.ad-banner-top {
    max-width: 1400px;
    margin: 0 auto;
    padding: 16px 24px 0;
}

.ad-banner-box {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 12px;
    text-align: center;
}

.ad-label {
    font-size: 10px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 1px;
    color: var(--text-muted);
    margin-bottom: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
}

.ad-label::before, .ad-label::after {
    content: '';
    flex: 1;
    height: 1px;
    background: var(--border);
    max-width: 120px;
}

.ad-placeholder {
    background: linear-gradient(135deg, #1e1e3a, #16162a);
    border: 2px dashed var(--border);
    border-radius: var(--radius-sm);
    height: 90px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    color: var(--text-muted);
    font-size: 13px;
    gap: 4px;
}

.ad-placeholder .ad-icon { font-size: 22px; opacity: 0.5; }

/* Main */
.main {
    max-width: 1400px;
    margin: 0 auto;
    padding: 24px 24px 32px;
}

.section-title {
    font-size: 20px;
    font-weight: 600;
    margin-bottom: 20px;
    display: flex;
    align-items: center;
    gap: 10px;
}

.section-title .count {
    background: var(--bg-secondary);
    color: var(--text-muted);
    font-size: 13px;
    padding: 2px 10px;
    border-radius: 100px;
    font-weight: 500;
}

/* Channels Grid */
.channels-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
    gap: 20px;
}

.channel-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 10px;
    text-align: center;
    cursor: pointer;
    transition: all 0.25s ease, opacity 0.15s ease;
    position: relative;
    overflow: hidden;
    text-decoration: none;
    color: inherit;
    display: block;
}

.channel-card::before {
    content: '';
    position: absolute;
    top: 0; left: 0; right: 0; height: 3px;
    background: linear-gradient(90deg, var(--accent), #a855f7);
    opacity: 0;
    transition: opacity 0.25s;
}

.channel-card:hover {
    background: var(--bg-card-hover);
    transform: translateY(-4px);
    box-shadow: var(--shadow);
    border-color: rgba(99,102,241,0.3);
}

.channel-card:hover::before { opacity: 1; }

.channel-logo {
    width: 128px; height: 128px;
    margin: 0 auto 14px;
    border-radius: var(--radius-sm);
    object-fit: cover;
    background: var(--bg-secondary);
    display: block;
}

.channel-name {
    font-size: 14px;
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: 4px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.channel-category {
    font-size: 12px;
    color: var(--text-muted);
}

.live-badge {
    position: absolute;
    top: 10px;
    left: 10px;
    background: #ef4444;
    color: #fff;
    font-size: 10px;
    font-weight: 700;
    padding: 3px 8px;
    border-radius: 100px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    animation: pulse 2s infinite;
    white-space: nowrap;
    z-index: 2;
}

.score-badge {
    position: absolute;
    top: 10px;
    right: 10px;
    background: rgba(15, 15, 26, 0.85);
    backdrop-filter: blur(6px);
    -webkit-backdrop-filter: blur(6px);
    color: #fff;
    font-size: 10px;
    font-weight: 700;
    padding: 3px 8px;
    border-radius: 100px;
    letter-spacing: 0.5px;
    white-space: nowrap;
    z-index: 2;
    border: 1px solid rgba(255, 255, 255, 0.1);
    text-shadow: 0 1px 2px rgba(0, 0, 0, 0.4);
}

.score-badge.score-high {
    color: #4ade80;
    border-color: rgba(74, 222, 128, 0.5);
}

.score-badge.score-mid {
    color: #facc15;
    border-color: rgba(250, 204, 21, 0.5);
}

.score-badge.score-low {
    color: #f87171;
    border-color: rgba(248, 113, 113, 0.5);
}

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

/* Telegram link in header */
.tg-link {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 8px 14px;
    background: linear-gradient(135deg, #229ed9, #1a8bc4);
    color: #fff;
    text-decoration: none;
    border-radius: 10px;
    font-size: 14px;
    font-weight: 600;
    transition: all 0.2s;
    white-space: nowrap;
    margin-left: 8px;
    flex-shrink: 0;
}

.tg-link:hover {
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(34, 158, 217, 0.3);
}

.tg-icon {
    width: 18px;
    height: 18px;
    fill: currentColor;
}

/* Hide text on mobile, show only icon */
@media (max-width: 768px) {
    .tg-text {
        display: none;
    }
    .tg-link {
        padding: 8px;
        border-radius: 50%;
        width: 36px;
        height: 36px;
        justify-content: center;
    }
    .tg-icon {
        width: 20px;
        height: 20px;
    }
}

/* Empty */
.empty-state {
    text-align: center;
    padding: 80px 20px;
    color: var(--text-muted);
}

.empty-state-icon { font-size: 48px; margin-bottom: 16px; opacity: 0.5; }

.empty-state h3 {
    font-size: 18px;
    color: var(--text-secondary);
    margin-bottom: 8px;
}

/* Footer */
.footer {
    text-align: center;
    padding: 40px 24px;
    color: var(--text-muted);
    font-size: 13px;
    border-top: 1px solid var(--border);
    margin-top: 20px;
}

/* Responsive */
@media (max-width: 768px) {
    .header-inner { padding: 12px 16px; }
    .logo span { display: none; }
    .search-box { max-width: none; }
    .mobile-menu-btn { display: block; }
    .categories-inner { padding: 10px 16px; }
    .ad-banner-top { padding: 12px 16px 0; }
    .main { padding: 20px 16px 24px; }

    .channels-grid {
        grid-template-columns: repeat(3, 1fr);
        gap: 12px;
    }
    .channel-card { padding: 12px 8px; }
    .channel-logo { width: 72px; height: 72px; }
    .channel-name { font-size: 12px; }
    .channel-category { font-size: 10px; }

    .live-badge, .score-badge {
        font-size: 8px;
        padding: 2px 5px;
        top: 6px;
    }
    .live-badge { left: 6px; }
    .score-badge { right: 6px; }
}

@media (max-width: 480px) {
    .channels-grid {
        grid-template-columns: repeat(2, 1fr);
        gap: 14px;
    }
    .channel-card { padding: 14px 10px; }
    .channel-logo { width: 96px; height: 96px; }
    .channel-name { font-size: 13px; }
    .channel-category { font-size: 11px; }

    .live-badge, .score-badge {
        font-size: 9px;
        padding: 2px 6px;
        top: 8px;
    }
    .live-badge { left: 8px; }
    .score-badge { right: 8px; }
}

::-webkit-scrollbar { width: 8px; }
::-webkit-scrollbar-track { background: var(--bg-primary); }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 4px; }
::-webkit-scrollbar-thumb:hover { background: #3f3f5f; }

/* ===== Footer ===== */
.footer-inner {
    max-width: 1400px;
    margin: 0 auto;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    flex-wrap: wrap;
}

.footer-link {
    color: var(--text-muted);
    text-decoration: none;
    font-size: 13px;
    transition: color 0.2s;
    cursor: pointer;
    margin-left: 10px;
}

.footer-link:hover {
    color: var(--accent);
}

/* ===== Responsive ===== */
@media (max-width: 768px) {
    .footer-inner {
        flex-direction: column;
        gap: 8px;
        text-align: center;
    }
}