/* ═══════════════════════════════════════════════════
   Live TV Pro — Main Stylesheet
   ═══════════════════════════════════════════════════ */

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

:root {
    --bg-primary: #f0f4f8;
    --bg-secondary: #ffffff;
    --bg-card: #ffffff;
    --bg-input: #f1f5f9;
    --bg-hover: #e6f0ff;
    --text-primary: #0f172a;
    --text-secondary: #475569;
    --text-muted: #94a3b8;
    --border-color: #e2e8f0;
    --accent: #2563eb;
    --accent-light: #3b82f6;
    --accent-dark: #1d4ed8;
    --accent-glow: rgba(37, 99, 235, 0.15);
    --live: #22c55e;
    --dead: #ef4444;
    --blocked: #f59e0b;
    --shadow: 0 4px 24px rgba(0, 0, 0, 0.08);
    --radius: 12px;
    --radius-sm: 8px;
    --transition: 0.2s ease;
    --header-bg: #ffffff;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    background: var(--bg-primary);
    color: var(--text-primary);
    line-height: 1.6;
    min-height: 100vh;
}

a { text-decoration: none; color: inherit; }
button { font-family: inherit; cursor: pointer; border: none; }

::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: var(--bg-primary); }
::-webkit-scrollbar-thumb { background: var(--accent); border-radius: 10px; }

/* ── Badges ── */
.badge {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 2px 10px;
    border-radius: 20px;
    font-size: 0.7rem;
    font-weight: 600;
    white-space: nowrap;
}
.badge-live { background: #dcfce7; color: #15803d; }
.badge-dead { background: #fee2e2; color: #b91c1c; }
.badge-blocked { background: #fef3c7; color: #b45309; }
.badge-pending { background: #f1f5f9; color: #64748b; }
.badge-unchecked { background: #f1f5f9; color: #94a3b8; }

/* ── App Container ── */
.app-container {
    max-width: 1440px;
    margin: 0 auto;
    padding: 16px 20px;
}

/* ── Header ── */
.header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 16px;
    background: var(--header-bg);
    padding: 12px 24px;
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    margin-bottom: 24px;
    border: 1px solid var(--border-color);
}
.header-left {
    display: flex;
    align-items: center;
    gap: 12px;
}
.logo-icon {
    width: 42px;
    height: 42px;
    background: var(--accent);
    border-radius: var(--radius-sm);
    display: flex;
    align-items: center;
    justify-content: center;
    color: #fff;
    font-size: 1.3rem;
}
.logo-text {
    font-weight: 700;
    font-size: 1.25rem;
    color: var(--text-primary);
}
.logo-sub {
    font-size: 0.75rem;
    color: var(--text-secondary);
    font-weight: 400;
}
.header-right {
    display: flex;
    align-items: center;
    gap: 10px;
    flex-wrap: wrap;
}
.header-btn {
    background: var(--bg-input);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    padding: 6px 14px;
    font-size: 0.8rem;
    font-weight: 500;
    color: var(--text-secondary);
    display: inline-flex;
    align-items: center;
    gap: 6px;
    transition: var(--transition);
}
.header-btn:hover {
    background: var(--accent);
    color: #fff;
    border-color: var(--accent);
}
.visitor-badge {
    background: var(--bg-input);
    padding: 4px 14px;
    border-radius: 20px;
    font-size: 0.75rem;
    font-weight: 500;
    color: var(--text-secondary);
}

/* ── Grid ── */
.main-grid {
    display: grid;
    grid-template-columns: 340px 1fr;
    gap: 24px;
}
@media (max-width: 992px) {
    .main-grid { grid-template-columns: 1fr; }
}

/* ── Cards ── */
.card {
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius);
    padding: 18px 20px;
    box-shadow: var(--shadow);
}
.card-title {
    font-size: 0.8rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.03em;
    color: var(--text-secondary);
    margin-bottom: 14px;
    display: flex;
    align-items: center;
    gap: 8px;
}
.card-title i {
    color: var(--accent);
    font-size: 0.9rem;
}

/* ── Inputs ── */
input, textarea, select {
    width: 100%;
    padding: 8px 12px;
    background: var(--bg-input);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    color: var(--text-primary);
    font-size: 0.85rem;
    transition: var(--transition);
    outline: none;
    font-family: inherit;
}
input:focus, textarea:focus, select:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--accent-glow);
}
textarea { min-height: 90px; resize: vertical; }

/* ── Buttons ── */
.btn {
    border: none;
    border-radius: var(--radius-sm);
    padding: 7px 14px;
    font-size: 0.8rem;
    font-weight: 600;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    transition: var(--transition);
    background: var(--bg-input);
    color: var(--text-secondary);
    border: 1px solid transparent;
}
.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-dark); box-shadow: 0 2px 12px var(--accent-glow); }
.btn-success { background: #22c55e; color: #fff; }
.btn-success:hover { background: #16a34a; }
.btn-danger { background: #ef4444; color: #fff; }
.btn-danger:hover { background: #dc2626; }
.btn-warning { background: #f59e0b; color: #fff; }
.btn-warning:hover { background: #d97706; }
.btn-ghost { background: var(--bg-input); border: 1px solid var(--border-color); color: var(--text-secondary); }
.btn-ghost:hover { background: var(--accent); color: #fff; border-color: var(--accent); }
.btn-sm { padding: 4px 10px; font-size: 0.7rem; }
.btn-xs { padding: 2px 8px; font-size: 0.65rem; }
.btn-icon { width: 28px; height: 28px; justify-content: center; padding: 0; }
.btn-group { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }

/* ── Left Column ── */
.left-col { display: flex; flex-direction: column; gap: 20px; }

/* ── Source List ── */
.source-list {
    display: flex;
    flex-direction: column;
    gap: 6px;
    max-height: 400px;
    overflow-y: auto;
    padding-right: 4px;
}
.source-item {
    display: flex;
    align-items: center;
    gap: 10px;
    background: var(--bg-input);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    padding: 8px 12px;
    transition: var(--transition);
}
.source-item:hover {
    border-color: var(--accent);
    background: var(--bg-hover);
}
.source-item .badge-emoji {
    font-size: 1.2rem;
    width: 28px;
    text-align: center;
    flex-shrink: 0;
}
.source-item .info {
    flex: 1;
    min-width: 0;
}
.source-item .info .name {
    font-weight: 600;
    font-size: 0.82rem;
}
.source-item .info .note {
    font-size: 0.68rem;
    color: var(--text-secondary);
}
.source-item .btn { flex-shrink: 0; }

/* ── Single Result ── */
.single-result {
    display: none;
    margin-top: 12px;
    padding: 12px;
    background: var(--bg-input);
    border-radius: var(--radius-sm);
    border: 1px solid var(--border-color);
}
.single-result .grid-2 {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 6px;
    margin-top: 8px;
}
.single-result .grid-2 .item {
    background: var(--bg-secondary);
    padding: 4px 10px;
    border-radius: 6px;
    font-size: 0.75rem;
}
.single-result .grid-2 .item label {
    font-size: 0.65rem;
    text-transform: uppercase;
    color: var(--text-muted);
    margin-bottom: 0;
}

/* ── Favorites ── */
.fav-list {
    max-height: 200px;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 6px;
    margin-top: 8px;
}
.fav-item {
    display: flex;
    align-items: center;
    gap: 8px;
    background: var(--bg-input);
    border: 1px solid var(--border-color);
    border-radius: 6px;
    padding: 6px 10px;
    font-size: 0.8rem;
}
.fav-item .name {
    flex: 1;
    font-weight: 500;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* ── Player ── */
.player-wrap {
    position: relative;
    background: #0f172a;
    border-radius: var(--radius);
    overflow: hidden;
    aspect-ratio: 16/9;
    display: flex;
    align-items: center;
    justify-content: center;
}
.player-wrap video {
    width: 100%;
    height: 100%;
    object-fit: contain;
    display: block;
}
.player-overlay {
    position: absolute;
    inset: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    color: #94a3b8;
    gap: 8px;
    background: #0f172a;
}
.player-overlay.hidden { display: none; }
.player-overlay i { font-size: 3rem; opacity: 0.4; }
.player-overlay p { font-size: 0.85rem; opacity: 0.6; }

.live-dot {
    position: absolute;
    top: 12px;
    left: 12px;
    background: var(--dead);
    color: #fff;
    padding: 2px 12px;
    border-radius: 20px;
    font-size: 0.65rem;
    font-weight: 700;
    letter-spacing: 0.05em;
    display: none;
    align-items: center;
    gap: 6px;
}
.live-dot.on { display: flex; background: var(--live); }
.live-dot::before {
    content: '';
    width: 7px;
    height: 7px;
    background: #fff;
    border-radius: 50%;
    animation: blink 1.2s infinite;
}
@keyframes blink { 0%,100%{opacity:1} 50%{opacity:0.2} }

.player-controls {
    display: flex;
    align-items: center;
    gap: 12px;
    flex-wrap: wrap;
    margin-top: 10px;
}
.player-controls input[type="range"] {
    width: 100px;
    accent-color: var(--accent);
    height: 4px;
    padding: 0;
}
.player-stats {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 8px;
    margin-top: 10px;
}
.player-stats .stat {
    background: var(--bg-input);
    padding: 6px 10px;
    border-radius: var(--radius-sm);
    text-align: center;
}
.player-stats .stat .label {
    font-size: 0.6rem;
    text-transform: uppercase;
    color: var(--text-muted);
}
.player-stats .stat .value {
    font-weight: 700;
    font-size: 0.85rem;
}

/* ── Stats Bar ── */
.stats-bar {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 8px;
    margin-bottom: 12px;
}
.stats-bar .stat {
    background: var(--bg-input);
    border-radius: var(--radius-sm);
    padding: 8px 12px;
    text-align: center;
}
.stats-bar .stat .num {
    font-size: 1.4rem;
    font-weight: 700;
    line-height: 1.2;
}
.stats-bar .stat .label {
    font-size: 0.6rem;
    text-transform: uppercase;
    color: var(--text-secondary);
}
.stat-total .num { color: var(--accent); }
.stat-live .num { color: var(--live); }
.stat-blocked .num { color: var(--blocked); }
.stat-dead .num { color: var(--dead); }

/* ── Progress ── */
.progress-wrap {
    display: none;
    margin-bottom: 12px;
}
.progress-bar {
    height: 4px;
    background: var(--bg-input);
    border-radius: 4px;
    overflow: hidden;
}
.progress-fill {
    height: 100%;
    background: var(--accent);
    width: 0%;
    transition: width 0.25s;
}
.check-status {
    display: flex;
    align-items: center;
    gap: 12px;
    font-size: 0.78rem;
    color: var(--text-secondary);
    margin-top: 4px;
}

/* ── Tabs ── */
.tab-row {
    display: flex;
    gap: 2px;
    border-bottom: 1px solid var(--border-color);
    margin-bottom: 12px;
    overflow-x: auto;
    flex-wrap: nowrap;
}
.tab-btn {
    background: none;
    border: none;
    padding: 8px 14px;
    font-size: 0.8rem;
    font-weight: 500;
    color: var(--text-secondary);
    border-bottom: 2px solid transparent;
    transition: var(--transition);
    white-space: nowrap;
    cursor: pointer;
}
.tab-btn:hover { color: var(--text-primary); }
.tab-btn.on {
    color: var(--accent);
    border-bottom-color: var(--accent);
    font-weight: 600;
}
.tab-btn .count {
    background: var(--bg-input);
    border-radius: 20px;
    padding: 0 8px;
    font-size: 0.65rem;
    margin-left: 4px;
}
.tab-btn.on .count {
    background: var(--accent-glow);
    color: var(--accent);
}

/* ── Toolbar ── */
.toolbar {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    align-items: center;
    padding: 8px 12px;
    background: var(--bg-input);
    border-radius: var(--radius-sm);
    border: 1px solid var(--border-color);
    margin-bottom: 12px;
}
.toolbar .spacer { flex: 1; }
.toolbar .search-box {
    width: 160px;
    padding: 4px 10px;
    font-size: 0.75rem;
}
.toolbar .filter-select {
    padding: 4px 8px;
    font-size: 0.75rem;
    width: auto;
}

/* ── Table ── */
.table-wrap {
    overflow: auto;
    border-radius: var(--radius-sm);
    border: 1px solid var(--border-color);
    max-height: 480px;
}
table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.78rem;
    min-width: 800px;
}
thead th {
    background: var(--bg-input);
    padding: 8px 10px;
    text-align: left;
    font-size: 0.65rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-secondary);
    position: sticky;
    top: 0;
    z-index: 2;
    border-bottom: 1px solid var(--border-color);
    font-weight: 600;
    white-space: nowrap;
}
thead th input[type="checkbox"] {
    width: 14px;
    height: 14px;
    accent-color: var(--accent);
}
tbody tr {
    border-bottom: 1px solid rgba(0,0,0,0.04);
    transition: var(--transition);
}
tbody tr:hover { background: var(--bg-hover); }
tbody tr.selected { background: var(--accent-glow); }
tbody tr.fav-row { background: #fefce8; }
tbody td { padding: 6px 10px; vertical-align: middle; }

/* ── Column Widths ── */
.col-check { width: 30px; }
.col-num { width: 35px; }
.col-logo { width: 40px; }
.col-name { width: auto; min-width: 120px; }
.col-url { width: auto; min-width: 150px; }
.col-group { width: 100px; }
.col-status { width: 90px; }
.col-type { width: 70px; }
.col-code { width: 55px; }
.col-time { width: 65px; }
.col-plays { width: 70px; }
.col-actions { width: 160px; }

.cell-name {
    font-weight: 500;
    max-width: 160px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.cell-url {
    max-width: 200px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    color: var(--text-secondary);
    cursor: pointer;
    font-size: 0.7rem;
}
.cell-url:hover { color: var(--accent); }
.cell-logo img {
    width: 22px;
    height: 22px;
    object-fit: contain;
    border-radius: 4px;
    background: var(--bg-input);
}
.cell-logo .no-logo {
    width: 22px;
    height: 22px;
    background: var(--bg-input);
    border-radius: 4px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.7rem;
    color: var(--text-muted);
}
.cell-actions {
    display: flex;
    gap: 3px;
    flex-wrap: nowrap;
    align-items: center;
    white-space: nowrap;
}
.cell-actions .btn {
    flex-shrink: 0;
}
.time-badge {
    background: var(--bg-input);
    padding: 0 6px;
    border-radius: 4px;
    font-size: 0.65rem;
    color: var(--text-secondary);
}
.plays-badge {
    background: var(--bg-input);
    padding: 0 6px;
    border-radius: 4px;
    font-size: 0.65rem;
    color: var(--accent);
    font-weight: 600;
}

.empty-state {
    padding: 40px 20px;
    text-align: center;
    color: var(--text-muted);
}
.empty-state i { font-size: 2.5rem; opacity: 0.3; margin-bottom: 10px; }

/* ── Modals ── */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.6);
    backdrop-filter: blur(4px);
    z-index: 9000;
    display: none;
    align-items: center;
    justify-content: center;
    padding: 20px;
}
.modal-overlay.open { display: flex; }
.modal {
    background: var(--bg-secondary);
    border-radius: var(--radius);
    max-width: 500px;
    width: 100%;
    padding: 28px;
    box-shadow: 0 20px 60px rgba(0,0,0,0.2);
    animation: fadeUp 0.25s ease;
    position: relative;
}
@keyframes fadeUp {
    from { opacity: 0; transform: translateY(16px); }
    to { opacity: 1; transform: translateY(0); }
}
.modal-close {
    position: absolute;
    top: 12px;
    right: 16px;
    background: none;
    border: none;
    font-size: 1.2rem;
    color: var(--text-muted);
    cursor: pointer;
}
.modal-close:hover { color: var(--text-primary); }
.modal h2 {
    font-size: 1.1rem;
    margin-bottom: 12px;
    display: flex;
    align-items: center;
    gap: 8px;
}

.drop-zone {
    border: 2px dashed var(--border-color);
    border-radius: var(--radius-sm);
    padding: 24px;
    text-align: center;
    cursor: pointer;
    transition: var(--transition);
    color: var(--text-secondary);
}
.drop-zone:hover, .drop-zone.dragover {
    border-color: var(--accent);
    color: var(--accent);
    background: var(--bg-hover);
}
.drop-zone i { font-size: 2rem; opacity: 0.4; display: block; margin-bottom: 6px; }

/* ── Settings ── */
.setting-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 8px 0;
    border-bottom: 1px solid var(--border-color);
}
.setting-row:last-child { border-bottom: none; }
.setting-info { flex: 1; }
.setting-info strong { display: block; font-size: 0.85rem; }
.setting-info span { font-size: 0.72rem; color: var(--text-secondary); }

.toggle {
    position: relative;
    width: 40px;
    height: 22px;
    flex-shrink: 0;
}
.toggle input { display: none; }
.toggle-slider {
    position: absolute;
    inset: 0;
    background: var(--bg-input);
    border-radius: 11px;
    cursor: pointer;
    transition: var(--transition);
    border: 1px solid var(--border-color);
}
.toggle input:checked + .toggle-slider {
    background: var(--accent);
    border-color: var(--accent);
}
.toggle-slider::after {
    content: '';
    position: absolute;
    width: 16px;
    height: 16px;
    background: #fff;
    border-radius: 50%;
    top: 2px;
    left: 2px;
    transition: var(--transition);
}
.toggle input:checked + .toggle-slider::after { left: 20px; }

/* ── Context Menu ── */
#ctx-menu {
    position: fixed;
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    padding: 4px 0;
    z-index: 8000;
    min-width: 180px;
    box-shadow: var(--shadow);
    display: none;
}
.ctx-item {
    padding: 8px 16px;
    cursor: pointer;
    font-size: 0.8rem;
    display: flex;
    align-items: center;
    gap: 10px;
    transition: var(--transition);
}
.ctx-item:hover {
    background: var(--bg-hover);
    color: var(--accent);
}
.ctx-sep { height: 1px; background: var(--border-color); margin: 4px 0; }

/* ── Toast ── */
#toast-wrap {
    position: fixed;
    bottom: 20px;
    right: 20px;
    z-index: 9999;
    display: flex;
    flex-direction: column;
    gap: 6px;
    pointer-events: none;
}
.toast {
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    padding: 10px 18px;
    border-radius: var(--radius-sm);
    font-size: 0.82rem;
    box-shadow: var(--shadow);
    opacity: 0;
    transform: translateY(8px);
    transition: 0.25s;
    pointer-events: none;
    max-width: 300px;
}
.toast.show {
    opacity: 1;
    transform: translateY(0);
}
.toast-success { border-left: 4px solid var(--live); }
.toast-error { border-left: 4px solid var(--dead); }
.toast-warning { border-left: 4px solid var(--blocked); }

/* ── Responsive ── */
@media (max-width: 640px) {
    .app-container { padding: 10px 12px; }
    .header { padding: 10px 16px; flex-direction: column; align-items: stretch; }
    .header-right { justify-content: flex-start; }
    .stats-bar { grid-template-columns: repeat(2, 1fr); }
    .player-stats { grid-template-columns: repeat(2, 1fr); }
    .single-result .grid-2 { grid-template-columns: 1fr; }
    .toolbar { flex-direction: column; align-items: stretch; }
    .toolbar .search-box { width: 100%; }
    .toolbar .filter-select { width: 100%; }
    .tab-btn { padding: 6px 10px; font-size: 0.7rem; }
    .col-actions { width: 140px; }
    .col-group { width: 70px; }
    .col-status { width: 70px; }
    .col-plays { width: 55px; }
}
@media (max-width: 480px) {
    .header-left .logo-sub { display: none; }
    .card { padding: 12px 14px; }
    .player-stats { grid-template-columns: 1fr 1fr; }
    .col-actions { width: 120px; }
    .cell-actions .btn { padding: 2px 6px; font-size: 0.6rem; }
}