/*
 * iptv.css — 全球电视频道（/tools/iptv）
 * ------------------------------------------------------------------
 * 1. --iptv-* 变量定义在 :root（浮层挂 body 下，不能只挂在 .iptv 上）
 * 2. 所有用 hidden 属性控制显隐的元素都补 [hidden] 兜底
 * 3. 断点体系（降序）：≥1600 / ≤1400 / ≤1180 / ≤900 / ≤700 / ≤640 / ≤420
 */

:root {
    --iptv-bg: #0d1017;
    --iptv-bg-2: #11151d;
    --iptv-card: #151a23;
    --iptv-card-2: #1b212c;
    --iptv-border: #262e3d;
    --iptv-border-2: #354054;
    --iptv-text: #e8ecf3;
    --iptv-sub: #a9b4c6;
    --iptv-faint: #7c8798;
    --iptv-hover: #1f2632;
    --iptv-accent: #5aa9e6;
    --iptv-accent-2: #3d8ccb;
    --iptv-accent-soft: rgba(90, 169, 230, .14);
    --iptv-live: #e0524a;
    --iptv-gold: #d3b071;
    --iptv-gold-soft: rgba(211, 176, 113, .12);
    --iptv-ok: #3fb950;
    --iptv-warn: #d8a11f;
    --iptv-err: #e05a4f;
    --iptv-shadow: 0 14px 34px -20px rgba(0, 0, 0, .85);
    --iptv-r: 14px;
    --iptv-r-s: 9px;
}

[data-theme="light"] {
    --iptv-bg: #f5f7fa;
    --iptv-bg-2: #ffffff;
    --iptv-card: #ffffff;
    --iptv-card-2: #f2f5f9;
    --iptv-border: #e2e7ef;
    --iptv-border-2: #cfd7e4;
    --iptv-text: #1e2633;
    --iptv-sub: #56616f;
    --iptv-faint: #6b7684;
    --iptv-hover: #eef2f8;
    --iptv-accent: #1f6f9e;
    --iptv-accent-2: #17577f;
    --iptv-accent-soft: rgba(31, 111, 158, .09);
    --iptv-live: #c0392b;
    --iptv-gold: #a9822f;
    --iptv-gold-soft: rgba(169, 130, 47, .10);
    --iptv-ok: #1a7f37;
    --iptv-warn: #9a6700;
    --iptv-err: #b03024;
    --iptv-shadow: 0 10px 26px -20px rgba(16, 24, 40, .45);
}

/* 满屏（保留左侧导航） */
body.page-iptv-full .app,
body.page-iptv-full .main-content,
body.page-iptv-full .page-container {
    max-width: 100%;
}

body.page-iptv-full .main-content {
    width: 100%;
    border-right: 0;
}

/* 站点 body{overflow-y:scroll} 会让 body 成为滚动容器，页内 sticky 全部失效 */
body.page-iptv-full {
    overflow: visible;
}

.iptv {
    color: var(--iptv-text);
    font-size: 14px;
    line-height: 1.6;
    padding: 20px 24px 64px;
}

.iptv *,
.iptv *::before,
.iptv *::after { box-sizing: border-box; }

.iptv [hidden] { display: none !important; }

.iptv button,
.iptv input,
.iptv select { font: inherit; color: inherit; }

/* ===================== Hero ===================== */
.iptv-hero {
    display: flex;
    flex-wrap: wrap;
    align-items: flex-end;
    justify-content: space-between;
    gap: 18px;
    padding: 18px 20px;
    border: 1px solid var(--iptv-border);
    border-radius: var(--iptv-r);
    background:
        radial-gradient(120% 140% at 0% 0%, var(--iptv-accent-soft) 0%, transparent 55%),
        var(--iptv-card);
    box-shadow: var(--iptv-shadow);
}

.iptv-title {
    margin: 0 0 6px;
    font-size: 22px;
    font-weight: 700;
    letter-spacing: .3px;
}

.iptv-title .iptv-live-dot {
    display: inline-block;
    width: 9px;
    height: 9px;
    margin-right: 8px;
    border-radius: 50%;
    background: var(--iptv-live);
    box-shadow: 0 0 0 4px rgba(224, 82, 74, .16);
    animation: iptv-pulse 2s ease-in-out infinite;
    vertical-align: middle;
}

@keyframes iptv-pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: .35; }
}

.iptv-sub {
    margin: 0;
    color: var(--iptv-sub);
    max-width: 78ch;
}

.iptv-sub b { color: var(--iptv-accent); }

.iptv-stats {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
}

.iptv-stat {
    min-width: 92px;
    padding: 8px 12px;
    border: 1px solid var(--iptv-border);
    border-radius: var(--iptv-r-s);
    background: var(--iptv-card-2);
    text-align: center;
}

.iptv-stat b {
    display: block;
    font-size: 18px;
    color: var(--iptv-text);
    font-variant-numeric: tabular-nums;
}

.iptv-stat span {
    font-size: 12px;
    color: var(--iptv-faint);
}

/* ===================== 工具条 ===================== */
.iptv-toolbar {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    align-items: center;
    margin: 16px 0 10px;
    padding: 12px;
    border: 1px solid var(--iptv-border);
    border-radius: var(--iptv-r);
    background: var(--iptv-card);
}

.iptv-search {
    position: relative;
    flex: 1 1 260px;
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 0 10px;
    border: 1px solid var(--iptv-border-2);
    border-radius: 999px;
    background: var(--iptv-bg-2);
    transition: border-color .15s, box-shadow .15s;
}

.iptv-search:focus-within {
    border-color: var(--iptv-accent);
    box-shadow: 0 0 0 3px var(--iptv-accent-soft);
}

.iptv-search svg { flex: 0 0 auto; opacity: .6; }

.iptv-search input {
    flex: 1 1 auto;
    min-width: 0;
    padding: 9px 0;
    border: 0;
    background: none;
    outline: none;
    font-size: 16px; /* 移动端 ≥16px 防自动放大 */
}

.iptv-search-clear {
    flex: 0 0 auto;
    border: 0;
    background: none;
    color: var(--iptv-faint);
    cursor: pointer;
    padding: 4px 6px;
    border-radius: 6px;
    line-height: 1;
}

.iptv-search-clear:hover { color: var(--iptv-text); background: var(--iptv-hover); }

.iptv-filters {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    align-items: center;
}

.iptv-select {
    padding: 8px 10px;
    border: 1px solid var(--iptv-border-2);
    border-radius: var(--iptv-r-s);
    background: var(--iptv-bg-2);
    cursor: pointer;
    max-width: 200px;
}

.iptv-select:focus-visible { outline: 2px solid var(--iptv-accent); outline-offset: 1px; }

.iptv-check {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 7px 10px;
    border: 1px solid var(--iptv-border-2);
    border-radius: 999px;
    background: var(--iptv-bg-2);
    color: var(--iptv-sub);
    cursor: pointer;
    user-select: none;
    white-space: nowrap;
}

.iptv-check input { accent-color: var(--iptv-accent); margin: 0; }
.iptv-check:hover { color: var(--iptv-text); border-color: var(--iptv-accent); }
.iptv-check.is-on {
    color: var(--iptv-accent);
    border-color: var(--iptv-accent);
    background: var(--iptv-accent-soft);
}

.iptv-btn {
    padding: 8px 13px;
    border: 1px solid var(--iptv-border-2);
    border-radius: var(--iptv-r-s);
    background: var(--iptv-bg-2);
    color: var(--iptv-sub);
    cursor: pointer;
    white-space: nowrap;
    transition: background .15s, color .15s, border-color .15s;
}

.iptv-btn:hover { color: var(--iptv-text); background: var(--iptv-hover); border-color: var(--iptv-accent); }
.iptv-btn:disabled { opacity: .5; cursor: not-allowed; }
.iptv-btn.is-primary {
    background: var(--iptv-accent);
    border-color: var(--iptv-accent);
    color: #fff;
}
.iptv-btn.is-primary:hover { background: var(--iptv-accent-2); border-color: var(--iptv-accent-2); }
.iptv-btn.is-on { color: var(--iptv-accent); border-color: var(--iptv-accent); background: var(--iptv-accent-soft); }

/* ===================== 国家快捷条 ===================== */
.iptv-chips {
    display: flex;
    flex-wrap: wrap;
    gap: 7px;
    margin-bottom: 14px;
}

.iptv-chip {
    padding: 6px 11px;
    border: 1px solid var(--iptv-border);
    border-radius: 999px;
    background: var(--iptv-card);
    color: var(--iptv-sub);
    font-size: 13px;
    cursor: pointer;
    transition: color .15s, border-color .15s, background .15s;
}

.iptv-chip:hover { color: var(--iptv-text); border-color: var(--iptv-accent); }
.iptv-chip.is-on {
    color: #fff;
    background: var(--iptv-accent);
    border-color: var(--iptv-accent);
}
.iptv-chip .iptv-chip-n { opacity: .65; font-size: 11px; margin-left: 4px; }

/* ===================== 主布局 ===================== */
.iptv-layout {
    display: grid;
    grid-template-columns: minmax(0, 1fr) 400px;
    gap: 18px;
    align-items: start;
}

.iptv-main { min-width: 0; }

.iptv-list-head {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    margin-bottom: 10px;
    color: var(--iptv-faint);
    font-size: 13px;
}

.iptv-list-head b { color: var(--iptv-text); font-variant-numeric: tabular-nums; }

.iptv-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(232px, 1fr));
    gap: 10px;
}

.iptv-card {
    position: relative;
    display: flex;
    gap: 10px;
    align-items: center;
    width: 100%;
    padding: 10px;
    border: 1px solid var(--iptv-border);
    border-radius: var(--iptv-r-s);
    background: var(--iptv-card);
    text-align: left;
    cursor: pointer;
    transition: border-color .15s, background .15s, transform .12s;
    /* 60 张卡片 + 台标：视口外的卡片跳过布局与绘制，首屏渲染更快 */
    content-visibility: auto;
    contain-intrinsic-size: auto 64px;
}

.iptv-card:hover { background: var(--iptv-hover); border-color: var(--iptv-border-2); transform: translateY(-1px); }
.iptv-card:focus-visible { outline: 2px solid var(--iptv-accent); outline-offset: 2px; }
.iptv-card.is-playing { border-color: var(--iptv-accent); background: var(--iptv-accent-soft); }

.iptv-logo {
    position: relative;
    flex: 0 0 auto;
    width: 42px;
    height: 42px;
    border-radius: 9px;
    background: var(--iptv-card-2);
    border: 1px solid var(--iptv-border);
    object-fit: contain;
    overflow: hidden;
}

.iptv-logo img {
    display: block;
    width: 100%;
    height: 100%;
    object-fit: contain;
    background: transparent;
}

.iptv-logo.is-fallback {
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: 15px;
    color: var(--iptv-accent);
    background: var(--iptv-accent-soft);
}

.iptv-card-main { min-width: 0; flex: 1 1 auto; }

.iptv-card-name {
    display: block;
    font-weight: 600;
    color: var(--iptv-text);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.iptv-card-meta {
    display: flex;
    flex-wrap: wrap;
    gap: 5px;
    margin-top: 4px;
    font-size: 12px;
    color: var(--iptv-faint);
}

.iptv-tag {
    padding: 1px 6px;
    border: 1px solid var(--iptv-border);
    border-radius: 5px;
    background: var(--iptv-bg-2);
    white-space: nowrap;
}

.iptv-tag.is-type { color: var(--iptv-accent); border-color: var(--iptv-accent); }
.iptv-tag.is-warn { color: var(--iptv-warn); border-color: var(--iptv-warn); }

.iptv-fav {
    position: absolute;
    top: 6px;
    right: 6px;
    width: 26px;
    height: 26px;
    display: flex;
    align-items: center;
    justify-content: center;
    border: 0;
    border-radius: 6px;
    background: transparent;
    color: var(--iptv-faint);
    cursor: pointer;
    font-size: 14px;
    line-height: 1;
}

.iptv-fav:hover { background: var(--iptv-hover); color: var(--iptv-gold); }
.iptv-fav.is-on { color: var(--iptv-gold); }

/* ===================== 分页 ===================== */
.iptv-pager {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: center;
    gap: 6px;
    margin-top: 16px;
}

.iptv-pg {
    min-width: 34px;
    padding: 7px 10px;
    border: 1px solid var(--iptv-border);
    border-radius: 8px;
    background: var(--iptv-card);
    color: var(--iptv-sub);
    cursor: pointer;
    font-variant-numeric: tabular-nums;
}

.iptv-pg:hover:not(:disabled) { color: var(--iptv-text); border-color: var(--iptv-accent); }
.iptv-pg:disabled { opacity: .45; cursor: not-allowed; }
.iptv-pg.is-on { background: var(--iptv-accent); border-color: var(--iptv-accent); color: #fff; }

/* ===================== 侧栏：播放器 ===================== */
.iptv-aside {
    position: sticky;
    top: 12px;
    display: flex;
    flex-direction: column;
    gap: 12px;
    min-width: 0;
}

.iptv-player {
    border: 1px solid var(--iptv-border);
    border-radius: var(--iptv-r);
    background: var(--iptv-card);
    overflow: hidden;
    box-shadow: var(--iptv-shadow);
}

.iptv-stage {
    position: relative;
    width: 100%;
    aspect-ratio: 16 / 9;
    background: #000;
}

.iptv-stage video {
    width: 100%;
    height: 100%;
    display: block;
    background: #000;
    object-fit: contain;
}

.iptv-state {
    position: absolute;
    inset: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 10px;
    padding: 16px;
    text-align: center;
    color: #cfd6e2;
    background: rgba(6, 9, 14, .82);
    font-size: 13px;
}

.iptv-state[hidden] { display: none !important; }

/* 缓冲遮罩不能挡住播放器原生控件，只有里面的按钮可点 */
.iptv-state { pointer-events: none; }
.iptv-state .iptv-btn { pointer-events: auto; }
.iptv-state p { margin: 0; max-width: 34ch; }
.iptv-state .iptv-spin {
    width: 26px;
    height: 26px;
    border: 3px solid rgba(255, 255, 255, .18);
    border-top-color: var(--iptv-accent);
    border-radius: 50%;
    animation: iptv-spin 900ms linear infinite;
}

@keyframes iptv-spin { to { transform: rotate(360deg); } }

.iptv-state.is-err { color: #ffb4ae; }
.iptv-state .iptv-btn { margin-top: 4px; }

.iptv-now {
    display: flex;
    gap: 10px;
    align-items: center;
    padding: 12px;
    border-bottom: 1px solid var(--iptv-border);
}

.iptv-now .iptv-logo { width: 40px; height: 40px; }

.iptv-now-main { min-width: 0; }

.iptv-now-name {
    display: block;
    font-weight: 600;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.iptv-now-meta { font-size: 12px; color: var(--iptv-faint); }

.iptv-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    padding: 10px 12px;
}

.iptv-actions .iptv-btn { font-size: 13px; padding: 6px 10px; }

.iptv-src {
    margin: 0;
    padding: 0 12px 10px;
    font-size: 12px;
    color: var(--iptv-faint);
    word-break: break-all;
}

.iptv-tip {
    margin: 0;
    padding: 10px 12px;
    border-top: 1px solid var(--iptv-border);
    background: var(--iptv-card-2);
    font-size: 12px;
    color: var(--iptv-faint);
}

/* ===================== 侧栏：收藏 / 最近 ===================== */
.iptv-panel {
    border: 1px solid var(--iptv-border);
    border-radius: var(--iptv-r);
    background: var(--iptv-card);
    overflow: hidden;
}

.iptv-panel-tabs {
    display: flex;
    border-bottom: 1px solid var(--iptv-border);
}

.iptv-panel-tab {
    flex: 1 1 0;
    padding: 10px 8px;
    border: 0;
    border-bottom: 2px solid transparent;
    background: none;
    color: var(--iptv-sub);
    cursor: pointer;
    font-size: 13px;
}

.iptv-panel-tab:hover { color: var(--iptv-text); }
.iptv-panel-tab.is-on { color: var(--iptv-accent); border-bottom-color: var(--iptv-accent); }

.iptv-panel-body {
    max-height: 260px;
    overflow-y: auto;
    overscroll-behavior: contain;
    padding: 8px;
}

.iptv-mini {
    display: flex;
    align-items: center;
    gap: 8px;
    width: 100%;
    padding: 7px 8px;
    border: 0;
    border-radius: 8px;
    background: none;
    color: var(--iptv-sub);
    text-align: left;
    cursor: pointer;
    font-size: 13px;
}

.iptv-mini:hover { background: var(--iptv-hover); color: var(--iptv-text); }
.iptv-mini .iptv-logo { width: 26px; height: 26px; border-radius: 6px; font-size: 11px; }
.iptv-mini span {
    flex: 1 1 auto;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.iptv-mini em {
    flex: 0 0 auto;
    font-style: normal;
    font-size: 12px;
    color: var(--iptv-faint);
}

.iptv-empty {
    padding: 18px 12px;
    text-align: center;
    color: var(--iptv-faint);
    font-size: 13px;
}

/* ===================== 状态 / 提示 ===================== */
.iptv-note {
    margin: 14px 0 0;
    padding: 12px 14px;
    border: 1px dashed var(--iptv-border-2);
    border-radius: var(--iptv-r-s);
    background: var(--iptv-card-2);
    color: var(--iptv-faint);
    font-size: 12.5px;
}

.iptv-note b { color: var(--iptv-sub); }

.iptv-load,
.iptv-error {
    padding: 40px 16px;
    text-align: center;
    color: var(--iptv-faint);
    border: 1px solid var(--iptv-border);
    border-radius: var(--iptv-r);
    background: var(--iptv-card);
}

.iptv-error { color: var(--iptv-err); }

.iptv-toast {
    position: fixed;
    left: 50%;
    bottom: 28px;
    transform: translateX(-50%) translateY(12px);
    z-index: 3000;
    max-width: 86vw;
    padding: 10px 16px;
    border-radius: 999px;
    background: rgba(20, 25, 34, .96);
    color: #eaf0f8;
    font-size: 13px;
    box-shadow: 0 12px 30px -14px rgba(0, 0, 0, .8);
    opacity: 0;
    pointer-events: none;
    transition: opacity .18s, transform .18s;
}

.iptv-toast.is-on { opacity: 1; transform: translateX(-50%) translateY(0); }

[data-theme="light"] .iptv-toast { background: rgba(28, 36, 48, .94); }

/* ===================== 响应式 ===================== */
@media (min-width: 1600px) {
    .iptv { padding: 24px 32px 72px; }
    .iptv-layout { grid-template-columns: minmax(0, 1fr) 440px; }
    .iptv-grid { grid-template-columns: repeat(auto-fill, minmax(248px, 1fr)); }
}

@media (max-width: 1400px) {
    .iptv-layout { grid-template-columns: minmax(0, 1fr) 360px; }
}

/* 平板 / 窄桌面：播放器置顶，列表在下 */
@media (max-width: 1180px) {
    .iptv-layout { grid-template-columns: minmax(0, 1fr); }
    .iptv-aside {
        position: sticky;
        top: 0;
        z-index: 20;
        order: -1;
        padding: 8px 0;
        background: var(--iptv-bg);
    }
    /* 窄屏侧栏只留吸顶播放器；收藏/最近面板由 JS 挪到列表末尾（.iptv-main 内）继续可用 */
    .iptv-aside > .iptv-panel { display: none; }
    .iptv-main > .iptv-panel { margin-top: 14px; }
    .iptv-panel-body { max-height: 200px; }
    .iptv-stage { aspect-ratio: 21 / 9; max-height: 42vh; }
    .iptv-grid { grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); }
}

@media (max-width: 900px) {
    .iptv { padding: 16px 16px 56px; }
    .iptv-hero { padding: 14px; }
    .iptv-title { font-size: 19px; }
    .iptv-stat { min-width: 78px; padding: 6px 10px; }
    .iptv-stat b { font-size: 16px; }
    .iptv-toolbar { padding: 10px; }
    .iptv-select { max-width: 150px; }
}

@media (max-width: 700px) {
    /* ≤700px 站点有 .mobile-header（sticky top:0，高约 53px，z-index 9）：
       吸顶播放器必须让位，否则会盖住站点顶栏 */
    .iptv-aside {
        top: 53px;
        z-index: 8;
        padding: 6px 0;
    }
    .iptv-hero { flex-direction: column; align-items: stretch; }
    .iptv-stats { justify-content: flex-start; }
    .iptv-search { flex: 1 1 100%; }
    .iptv-filters { width: 100%; }
    .iptv-select { flex: 1 1 120px; max-width: none; }
    .iptv-stage { aspect-ratio: 16 / 9; max-height: none; }
    .iptv-grid { grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 8px; }
    .iptv-card { padding: 8px; gap: 8px; }
    .iptv-logo { width: 34px; height: 34px; }
    .iptv-card-name { font-size: 13px; }
    .iptv-chips { max-height: 84px; overflow-y: auto; overscroll-behavior: contain; }
}

@media (max-width: 640px) {
    .iptv-actions .iptv-btn { flex: 1 1 auto; justify-content: center; }
    .iptv-now-meta { display: block; }
}

@media (max-width: 420px) {
    .iptv { padding: 12px 12px 48px; }
    .iptv-grid { grid-template-columns: 1fr; }
    .iptv-card { padding: 9px 10px; }
    .iptv-pg { min-width: 30px; padding: 6px 8px; }
    .iptv-hero { padding: 12px; }
    .iptv-stat { min-width: 68px; }
}

/* iPhone 底部安全区 */
@supports (padding-bottom: env(safe-area-inset-bottom)) {
    .iptv { padding-bottom: calc(64px + env(safe-area-inset-bottom)); }
    .iptv-toast { bottom: calc(24px + env(safe-area-inset-bottom)); }
}

@media (prefers-reduced-motion: reduce) {
    .iptv *,
    .iptv *::before,
    .iptv *::after {
        animation-duration: .001ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: .001ms !important;
    }
    .iptv-title .iptv-live-dot { animation: none; }
}
