:root {
    --bg: #0a0a0a;
    --surface: #141414;
    --surface-hover: #1c1c1c;
    --border: #2a2a2a;
    --text: #ffffff;
    --text-dim: #888888;
    --accent: #e82127;
    --accent-hover: #ff3338;
    --success: #00d26a;
    --error: #ff4444;
    --radius: 8px;
    --radius-lg: 12px;
    --transition: 0.2s ease;
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; }
body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: var(--bg);
    color: var(--text);
    overflow-x: hidden;
}

.app { display: flex; flex-direction: column; min-height: 100vh; }

.header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 24px;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
}

.logo { display: flex; align-items: center; gap: 12px; }
.logo-icon {
    width: 40px; height: 40px;
    background: var(--accent);
    border-radius: var(--radius);
    display: flex; align-items: center; justify-content: center;
    font-size: 20px; font-weight: 800; color: white;
}
.logo-text { font-size: 22px; font-weight: 700; }
.logo-text span { color: var(--accent); }
.header-actions { display: flex; align-items: center; gap: 10px; }

.btn {
    display: inline-flex; align-items: center; gap: 8px;
    padding: 10px 18px; font-size: 14px; font-weight: 600;
    color: var(--text); background: var(--surface);
    border: 1px solid var(--border); border-radius: var(--radius);
    cursor: pointer; transition: all var(--transition); white-space: nowrap;
}
.btn:hover { background: var(--surface-hover); border-color: var(--text-dim); }
.btn-primary { background: var(--accent); border-color: var(--accent); }
.btn-primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); }
.btn-icon { padding: 10px; }
.btn svg { width: 18px; height: 18px; fill: currentColor; }
.btn-full { width: 100%; justify-content: center; }

.main { flex: 1; display: flex; flex-direction: column; padding: 24px; gap: 24px; }
@media (min-width: 1024px) {
    .main { flex-direction: row; }
    .player-section { flex: 2; }
    .channels-section { flex: 1; max-width: 400px; }
}

.player-section { display: flex; justify-content: center; }
.player-container {
    position: relative; width: 100%; max-width: 1000px;
    background: #000; border-radius: var(--radius-lg);
    overflow: hidden; aspect-ratio: 16/9;
}
.player-container canvas {
    position: absolute; top: 0; left: 0;
    width: 100%; height: 100%; object-fit: contain;
}

.player-overlay {
    position: absolute; top: 0; left: 0; right: 0;
    padding: 16px; display: flex;
    justify-content: space-between; align-items: flex-start;
    background: linear-gradient(to bottom, rgba(0,0,0,0.7) 0%, transparent 100%);
    opacity: 0; transition: opacity var(--transition); pointer-events: none;
}
.player-overlay.visible { opacity: 1; }

.player-loading {
    position: absolute; top: 50%; left: 50%;
    transform: translate(-50%, -50%);
    display: flex; flex-direction: column; align-items: center;
    gap: 16px; color: var(--text-dim);
}
.spinner {
    width: 48px; height: 48px;
    border: 3px solid var(--border); border-top-color: var(--accent);
    border-radius: 50%; animation: spin 1s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.player-info { display: flex; align-items: center; gap: 12px; }
.channel-name { font-size: 16px; font-weight: 600; }
.quality-badge {
    padding: 4px 10px; font-size: 12px; font-weight: 600;
    background: var(--accent); border-radius: 4px;
}

.player-controls {
    position: absolute; bottom: 0; left: 0; right: 0;
    display: flex; align-items: center; justify-content: space-between;
    padding: 12px 16px;
    background: linear-gradient(to top, rgba(0,0,0,0.9) 0%, transparent 100%);
    opacity: 0; transition: opacity var(--transition);
}
.player-controls.visible { opacity: 1; }
.player-container:hover .player-controls,
.player-container:hover .player-overlay { opacity: 1; }

.controls-left, .controls-center, .controls-right {
    display: flex; align-items: center; gap: 8px;
}

.ctrl-btn {
    width: 44px; height: 44px;
    display: flex; align-items: center; justify-content: center;
    background: transparent; border: none; color: var(--text);
    cursor: pointer; border-radius: var(--radius);
    transition: background var(--transition);
}
.ctrl-btn:hover { background: rgba(255,255,255,0.1); }
.ctrl-btn svg { width: 24px; height: 24px; fill: currentColor; }

.icon-pause { display: none; }
body.playing .icon-play { display: none; }
body.playing .icon-pause { display: block; }
.icon-mute { display: none; }
body.muted .icon-vol { display: none; }
body.muted .icon-mute { display: block; }

#volume-slider {
    width: 80px; height: 4px;
    -webkit-appearance: none; background: var(--border);
    border-radius: 2px; cursor: pointer;
}
#volume-slider::-webkit-slider-thumb {
    -webkit-appearance: none; width: 14px; height: 14px;
    background: var(--text); border-radius: 50%; cursor: pointer;
}

#quality-select {
    padding: 8px 32px 8px 12px; font-size: 13px; font-weight: 500;
    color: var(--text); background: rgba(255,255,255,0.1);
    border: none; border-radius: var(--radius); cursor: pointer;
    -webkit-appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' fill='white' viewBox='0 0 24 24'%3E%3Cpath d='M7 10l5 5 5-5z'/%3E%3C/svg%3E");
    background-repeat: no-repeat; background-position: right 10px center;
}
#quality-select option { background: var(--surface); color: var(--text); }

.channels-section {
    background: var(--surface); border-radius: var(--radius-lg);
    overflow: hidden; display: flex; flex-direction: column; max-height: 600px;
}
.channels-header {
    display: flex; align-items: center; justify-content: space-between;
    padding: 16px 20px; border-bottom: 1px solid var(--border);
}
.channels-header h2 { font-size: 16px; font-weight: 600; }

#group-filter {
    padding: 8px 32px 8px 12px; font-size: 13px;
    color: var(--text); background: var(--bg);
    border: 1px solid var(--border); border-radius: var(--radius);
    cursor: pointer; -webkit-appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' fill='%23888' viewBox='0 0 24 24'%3E%3Cpath d='M7 10l5 5 5-5z'/%3E%3C/svg%3E");
    background-repeat: no-repeat; background-position: right 10px center;
}

.search-box {
    display: flex; align-items: center; padding: 12px 20px;
    border-bottom: 1px solid var(--border); gap: 12px;
}
.search-box input {
    flex: 1; padding: 10px 14px; font-size: 14px;
    color: var(--text); background: var(--bg);
    border: 1px solid var(--border); border-radius: var(--radius);
}
.search-box input:focus { outline: none; border-color: var(--accent); }
.btn-close {
    width: 32px; height: 32px;
    display: flex; align-items: center; justify-content: center;
    background: none; border: none; color: var(--text-dim);
    font-size: 24px; cursor: pointer;
}

.channels-grid {
    flex: 1; overflow-y: auto; padding: 12px;
    display: flex; flex-direction: column; gap: 8px;
}
.channel-card {
    display: flex; align-items: center; gap: 12px; padding: 12px;
    background: var(--bg); border: 1px solid transparent;
    border-radius: var(--radius); cursor: pointer;
    transition: all var(--transition);
}
.channel-card:hover { background: var(--surface-hover); border-color: var(--border); }
.channel-card.active { border-color: var(--accent); background: rgba(232, 33, 39, 0.1); }

.channel-logo {
    width: 44px; height: 44px; background: var(--surface);
    border-radius: var(--radius); display: flex;
    align-items: center; justify-content: center;
    overflow: hidden; position: relative; flex-shrink: 0;
}
.channel-logo img { width: 100%; height: 100%; object-fit: cover; }
.channel-initial { font-size: 18px; font-weight: 700; color: var(--accent); }
.channel-logo img + .channel-initial { display: none; }

.channel-info { flex: 1; min-width: 0; }
.channel-title {
    font-size: 14px; font-weight: 500;
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.channel-group { font-size: 12px; color: var(--text-dim); margin-top: 2px; }

.channels-grid::-webkit-scrollbar { width: 6px; }
.channels-grid::-webkit-scrollbar-track { background: var(--bg); }
.channels-grid::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }

.modal {
    position: fixed; top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(0, 0, 0, 0.85);
    display: none; align-items: center; justify-content: center;
    padding: 20px; z-index: 1000;
}
.modal.active { display: flex; }
.modal-content {
    width: 100%; max-width: 480px;
    background: var(--surface); border-radius: var(--radius-lg); overflow: hidden;
}
.modal-header {
    display: flex; align-items: center; justify-content: space-between;
    padding: 20px; border-bottom: 1px solid var(--border);
}
.modal-header h3 { font-size: 18px; font-weight: 600; }
.modal-close {
    width: 32px; height: 32px;
    display: flex; align-items: center; justify-content: center;
    background: none; border: none; color: var(--text-dim);
    font-size: 24px; cursor: pointer; border-radius: var(--radius);
}
.modal-close:hover { background: var(--surface-hover); color: var(--text); }
.modal-body { padding: 20px; }
.modal-desc { color: var(--text-dim); font-size: 14px; margin-bottom: 20px; line-height: 1.5; }
.form-group { margin-bottom: 16px; }
.form-group label { display: block; font-size: 13px; font-weight: 500; color: var(--text-dim); margin-bottom: 8px; }
.form-group input {
    width: 100%; padding: 12px 14px; font-size: 14px;
    color: var(--text); background: var(--bg);
    border: 1px solid var(--border); border-radius: var(--radius);
}
.form-group input:focus { outline: none; border-color: var(--accent); }
.form-group input::placeholder { color: var(--text-dim); }
.modal-footer {
    display: flex; justify-content: flex-end; gap: 12px;
    padding: 20px; border-top: 1px solid var(--border);
}

.xtream-status { padding: 12px; border-radius: var(--radius); font-size: 13px; margin-top: 16px; }
.xtream-status.loading { display: flex; align-items: center; gap: 10px; background: var(--bg); color: var(--text-dim); }
.xtream-status.success { background: rgba(0, 210, 106, 0.1); color: var(--success); }
.xtream-status.error { background: rgba(255, 68, 68, 0.1); color: var(--error); }
.loading-small {
    width: 16px; height: 16px;
    border: 2px solid var(--border); border-top-color: var(--accent);
    border-radius: 50%; animation: spin 1s linear infinite;
}

.toast {
    position: fixed; bottom: 24px; left: 50%;
    transform: translateX(-50%) translateY(20px);
    padding: 12px 24px; background: var(--surface);
    border: 1px solid var(--border); border-radius: 50px;
    font-size: 14px; opacity: 0; transition: all var(--transition);
    z-index: 1001; pointer-events: none;
}
.toast.visible { opacity: 1; transform: translateX(-50%) translateY(0); }
.toast.error { border-color: var(--error); color: var(--error); }
.toast.success { border-color: var(--success); }

.player-container:fullscreen,
.player-container:-webkit-full-screen { max-width: none; border-radius: 0; }

@media (max-width: 768px) {
    .header { padding: 12px 16px; }
    .header-actions .btn:not(.btn-icon) span { display: none; }
    .main { padding: 16px; }
    .player-controls { padding: 8px 12px; }
    #volume-slider { display: none; }
    .channels-section { max-height: 400px; }
}
@media (pointer: coarse) {
    .ctrl-btn { width: 52px; height: 52px; }
    .channel-card { padding: 14px; }
}

/* Categories Bar */
.categories-bar {
    background: rgba(30, 30, 30, 0.98);
    padding: 0 20px;
    display: flex;
    align-items: center;
    gap: 8px;
    overflow-x: auto;
    overflow-y: hidden;
    height: 55px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.08);
    scrollbar-width: none;
}

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

.category-btn {
    padding: 10px 24px;
    background: transparent;
    border: none;
    color: rgba(255, 255, 255, 0.6);
    cursor: pointer;
    white-space: nowrap;
    font-size: 14px;
    font-weight: 400;
    transition: all 0.2s;
    border-radius: 20px;
    letter-spacing: 0.3px;
    font-family: inherit;
}

.category-btn:hover {
    background: rgba(255, 255, 255, 0.05);
    color: rgba(255, 255, 255, 0.9);
}

.category-btn.active {
    background: rgba(33, 150, 243, 0.2);
    color: #2196F3;
    font-weight: 500;
}

/* ============================================
   LOGIN SCREEN
   ============================================ */

.login-screen {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: linear-gradient(135deg, #0a0a0a 0%, #1a1a2e 100%);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 9999;
}

.login-container {
    background: var(--surface);
    border-radius: var(--radius-lg);
    padding: 40px;
    width: 100%;
    max-width: 420px;
    margin: 20px;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5);
}

.login-logo {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 12px;
    margin-bottom: 24px;
}

.login-logo .logo-icon {
    width: 50px;
    height: 50px;
    font-size: 24px;
}

.login-logo .logo-text {
    font-size: 28px;
}

.login-container h2 {
    text-align: center;
    font-size: 24px;
    font-weight: 600;
    margin-bottom: 8px;
    color: var(--text);
}

.login-desc {
    text-align: center;
    color: var(--text-dim);
    font-size: 14px;
    margin-bottom: 32px;
}

.login-form {
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.login-form .form-group {
    margin-bottom: 0;
}

.login-status {
    padding: 12px;
    border-radius: var(--radius);
    font-size: 13px;
    text-align: center;
    min-height: 20px;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
}

.login-status:empty {
    display: none;
}

.login-status.loading {
    background: var(--bg);
    color: var(--text-dim);
}

.login-status.error {
    background: rgba(255, 68, 68, 0.1);
    color: var(--error);
}

.login-status.success {
    background: rgba(0, 210, 106, 0.1);
    color: var(--success);
}

/* Logout button styling */
.btn-logout {
    color: var(--error);
    border-color: rgba(255, 68, 68, 0.3);
}

.btn-logout:hover {
    background: rgba(255, 68, 68, 0.1);
    border-color: var(--error);
}

.btn-logout svg {
    fill: var(--error);
}

/* Responsive login */
@media (max-width: 480px) {
    .login-container {
        padding: 24px;
        margin: 16px;
    }
    
    .login-container h2 {
        font-size: 20px;
    }
    
    .login-logo .logo-icon {
        width: 40px;
        height: 40px;
        font-size: 20px;
    }
    
    .login-logo .logo-text {
        font-size: 24px;
    }
}

