/**
 * 电视直播TV PWA - 样式表
 * 适配 iOS Safari / Android Chrome / 全面屏
 */

/* ========== 基础重置 ========== */
*, *::before, *::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    -webkit-tap-highlight-color: transparent;
}

html, body {
    width: 100%;
    height: 100%;
    overflow: hidden;
    background: #0a0e17;
    color: #fff;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'PingFang SC', 'Microsoft YaHei', sans-serif;
    font-size: 14px;
    line-height: 1.4;
    -webkit-text-size-adjust: 100%;
    /* iOS 安全区域适配 */
    padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}

/* 禁止 iOS 橡皮筋效果 */
body {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    overscroll-behavior: none;
}

/* ========== 应用容器 ========== */
#app {
    width: 100%;
    height: 100%;
    display: flex;
    flex-direction: column;
    position: relative;
}

/* ========== 加载画面 ========== */
.loading-screen {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: #0a0e17;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    z-index: 9999;
    transition: opacity 0.5s ease;
}

.loading-screen.hide {
    opacity: 0;
    pointer-events: none;
}

.loading-spinner {
    width: 40px;
    height: 40px;
    border: 3px solid rgba(255,255,255,0.1);
    border-top-color: #1a73e8;
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

.loading-text {
    margin-top: 16px;
    color: #8899aa;
    font-size: 14px;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

/* ========== 播放器区域 ========== */
.player-container {
    flex: 1;
    position: relative;
    background: #000;
    overflow: hidden;
    min-height: 0;
}

.player-container video {
    width: 100%;
    height: 100%;
    object-fit: contain;
    display: block;
}

/* 播放器覆盖层（频道信息） */
.player-overlay {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    padding: 12px 16px;
    padding-top: calc(12px + env(safe-area-inset-top));
    background: linear-gradient(180deg, rgba(0,0,0,0.7) 0%, transparent 100%);
    opacity: 0;
    transition: opacity 0.3s ease;
    pointer-events: none;
    z-index: 10;
}

.player-overlay.show {
    opacity: 1;
    pointer-events: auto;
}

.channel-info {
    display: flex;
    align-items: center;
    gap: 10px;
}

.channel-logo {
    width: 36px;
    height: 36px;
    border-radius: 6px;
    object-fit: cover;
    background: rgba(255,255,255,0.1);
}

.channel-name {
    font-size: 18px;
    font-weight: 600;
    text-shadow: 0 1px 3px rgba(0,0,0,0.5);
}

.channel-source {
    font-size: 12px;
    color: #8899aa;
    margin-top: 2px;
}

/* 播放器中央提示 */
.player-message {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    text-align: center;
    z-index: 5;
}

.player-message .msg-icon {
    font-size: 48px;
    margin-bottom: 12px;
}

.player-message .msg-text {
    font-size: 16px;
    color: #8899aa;
}

/* ========== 底部控制栏 ========== */
.bottom-bar {
    background: #111827;
    padding: 8px 12px;
    padding-bottom: calc(8px + env(safe-area-inset-bottom));
    display: flex;
    align-items: center;
    gap: 8px;
    border-top: 1px solid rgba(255,255,255,0.05);
    z-index: 20;
    flex-shrink: 0;
}

.bottom-bar .bar-btn {
    width: 40px;
    height: 40px;
    border: none;
    background: rgba(255,255,255,0.08);
    color: #fff;
    border-radius: 10px;
    font-size: 16px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: background 0.2s;
    flex-shrink: 0;
}

.bottom-bar .bar-btn:active {
    background: rgba(255,255,255,0.2);
}

.bottom-bar .bar-btn.active {
    background: #1a73e8;
}

.bottom-bar .bar-channel-info {
    flex: 1;
    min-width: 0;
    text-align: center;
}

.bottom-bar .bar-channel-name {
    font-size: 14px;
    font-weight: 600;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.bottom-bar .bar-channel-num {
    font-size: 11px;
    color: #6b7280;
}

/* ========== 频道列表侧边栏 ========== */
.channel-sidebar {
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    width: 300px;
    max-width: 85vw;
    background: #111827;
    z-index: 1000;
    transform: translateX(-100%);
    transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    display: flex;
    flex-direction: column;
    box-shadow: 4px 0 20px rgba(0,0,0,0.5);
}

.channel-sidebar.open {
    transform: translateX(0);
}

.sidebar-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0,0,0,0.5);
    z-index: 999;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s ease;
}

.sidebar-overlay.open {
    opacity: 1;
    pointer-events: auto;
}

/* 侧边栏头部 */
.sidebar-header {
    padding: 16px;
    padding-top: calc(16px + env(safe-area-inset-top));
    border-bottom: 1px solid rgba(255,255,255,0.06);
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-shrink: 0;
}

.sidebar-title {
    font-size: 18px;
    font-weight: 700;
}

.sidebar-close {
    width: 32px;
    height: 32px;
    border: none;
    background: rgba(255,255,255,0.08);
    color: #fff;
    border-radius: 8px;
    font-size: 18px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
}

/* 源切换 */
.source-tabs {
    display: flex;
    gap: 6px;
    padding: 10px 16px;
    overflow-x: auto;
    flex-shrink: 0;
    -webkit-overflow-scrolling: touch;
}

.source-tabs::-webkit-scrollbar {
    display: none;
}

.source-tab {
    padding: 6px 14px;
    border-radius: 16px;
    font-size: 13px;
    white-space: nowrap;
    border: none;
    background: rgba(255,255,255,0.06);
    color: #9ca3af;
    cursor: pointer;
    transition: all 0.2s;
    flex-shrink: 0;
}

.source-tab.active {
    background: #1a73e8;
    color: #fff;
}

/* 分组 */
.group-header {
    padding: 10px 16px 6px;
    font-size: 12px;
    color: #6b7280;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    position: sticky;
    top: 0;
    background: #111827;
    z-index: 1;
}

/* 频道列表 */
.channel-list {
    flex: 1;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    padding-bottom: env(safe-area-inset-bottom);
}

.channel-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 16px;
    cursor: pointer;
    transition: background 0.15s;
    border-bottom: 1px solid rgba(255,255,255,0.03);
}

.channel-item:active {
    background: rgba(255,255,255,0.08);
}

.channel-item.playing {
    background: rgba(26, 115, 232, 0.15);
    border-left: 3px solid #1a73e8;
}

.channel-item .ch-logo {
    width: 32px;
    height: 32px;
    border-radius: 6px;
    object-fit: cover;
    background: rgba(255,255,255,0.06);
    flex-shrink: 0;
}

.channel-item .ch-name {
    flex: 1;
    font-size: 14px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.channel-item .ch-playing-icon {
    width: 16px;
    height: 16px;
    flex-shrink: 0;
}

/* 播放中动画条 */
.playing-bars {
    display: flex;
    align-items: flex-end;
    gap: 2px;
    height: 16px;
}

.playing-bars span {
    width: 3px;
    background: #1a73e8;
    border-radius: 1px;
    animation: bar-bounce 1s ease-in-out infinite;
}

.playing-bars span:nth-child(1) { animation-delay: 0s; height: 60%; }
.playing-bars span:nth-child(2) { animation-delay: 0.15s; height: 100%; }
.playing-bars span:nth-child(3) { animation-delay: 0.3s; height: 40%; }

@keyframes bar-bounce {
    0%, 100% { transform: scaleY(0.4); }
    50% { transform: scaleY(1); }
}

/* ========== 切换频道提示 ========== */
.channel-toast {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%) scale(0.8);
    background: rgba(0,0,0,0.85);
    color: #fff;
    padding: 20px 32px;
    border-radius: 16px;
    text-align: center;
    z-index: 500;
    opacity: 0;
    pointer-events: none;
    transition: all 0.25s ease;
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
}

.channel-toast.show {
    opacity: 1;
    transform: translate(-50%, -50%) scale(1);
}

.channel-toast .toast-name {
    font-size: 22px;
    font-weight: 700;
}

.channel-toast .toast-num {
    font-size: 13px;
    color: #8899aa;
    margin-top: 4px;
}

/* ========== 错误提示 ========== */
.error-banner {
    position: fixed;
    bottom: 80px;
    left: 16px;
    right: 16px;
    background: rgba(220, 38, 38, 0.9);
    color: #fff;
    padding: 10px 16px;
    border-radius: 10px;
    font-size: 13px;
    text-align: center;
    z-index: 500;
    opacity: 0;
    transform: translateY(10px);
    transition: all 0.3s ease;
    pointer-events: none;
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
}

.error-banner.show {
    opacity: 1;
    transform: translateY(0);
    pointer-events: auto;
}

/* ========== 横屏适配 ========== */
@media (orientation: landscape) {
    .bottom-bar {
        padding-left: calc(12px + env(safe-area-inset-left));
        padding-right: calc(12px + env(safe-area-inset-right));
    }

    .channel-sidebar {
        width: 320px;
    }
}

/* ========== 大屏适配（iPad等） ========== */
@media (min-width: 768px) {
    .channel-sidebar {
        width: 360px;
    }

    .channel-name {
        font-size: 22px;
    }

    .channel-item {
        padding: 12px 20px;
    }
}

/* ========== 进度条（直播时移/回放） ========== */
.seek-bar-wrap {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 14px 10px;
    background: linear-gradient(transparent, rgba(0,0,0,0.7));
    z-index: 15;
}
.seek-time {
    font-size: 11px;
    color: rgba(255,255,255,0.8);
    min-width: 40px;
    text-align: center;
    font-variant-numeric: tabular-nums;
    user-select: none;
    -webkit-user-select: none;
}
.seek-bar {
    flex: 1;
    height: 4px;
    background: rgba(255,255,255,0.2);
    border-radius: 2px;
    position: relative;
    cursor: pointer;
    touch-action: none;
}
.seek-bar-buffered {
    position: absolute;
    top: 0; left: 0;
    height: 100%;
    background: rgba(255,255,255,0.25);
    border-radius: 2px;
}
.seek-bar-progress {
    position: absolute;
    top: 0; left: 0;
    height: 100%;
    background: #3b82f6;
    border-radius: 2px;
    transition: width 0.1s linear;
}
.seek-bar-thumb {
    position: absolute;
    top: 50%;
    width: 14px;
    height: 14px;
    background: #fff;
    border-radius: 50%;
    transform: translate(-50%, -50%);
    box-shadow: 0 0 4px rgba(0,0,0,0.5);
    pointer-events: none;
    transition: left 0.1s linear;
}
.seek-bar-wrap.active .seek-bar {
    height: 6px;
}
.seek-bar-wrap.active .seek-bar-thumb {
    width: 18px;
    height: 18px;
}
