* {
    margin: 1px;
    padding: 1px;
    box-sizing: border-box;
}

html, body {
    width: 100%;
    height: 100vh;
    margin: 0;
    overflow: hidden;
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    font-size: clamp(14px, 2vw, 15px);
    line-height: 1.6;
    transition: background-color 0.3s ease, color 0.3s ease;
    padding-bottom: 48px; /* Make space for footer */
}

body.light {
    background-color: #f9fafb;
    color: #1e293b;
}
body.light .card {
    background-color: #ffffff;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.05);
}
body.light .btn-primary {
    background-color: #3b82f6;
    color: #ffffff;
}
body.light .btn-primary:hover {
    background-color: #2563eb;
}
body.light .btn-secondary {
    background-color: #10b981;
    color: #ffffff;
}
body.light .btn-secondary:hover {
    background-color: #059669;
}
body.light .btn-danger {
    background-color: #ef4444;
    color: #ffffff;
}
body.light .btn-danger:hover {
    background-color: #dc2626;
}
body.light .btn-neutral {
    background-color: #e5e7eb;
    color: #374151;
}
body.light .btn-neutral:hover {
    background-color: #d1d5db;
}
body.light .btn-outline {
    border: 1px solid #d1d5db;
    background-color: transparent;
    color: #374151;
}
body.light .btn-outline:hover {
    background-color: #f3f4f6;
}
body.light input, body.light select {
    border-color: #d1d5db;
    background-color: #ffffff;
}
body.light input:focus, body.light select:focus {
    border-color: #3b82f6;
    box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.1);
}
body.light .category-item {
    background-color: #f1f5f9;
}
body.light .category-item:hover {
    background-color: #e2e8f0;
}
body.light .channel-item {
    border-color: #e5e7eb;
}
body.light .channel-item.favorite {
    background-color: #fff3cd;
    border-color: #ffc107;
    position: relative;
}
body.light .channel-item.favorite::before {
    content: '★';
    position: absolute;
    top: -0.4rem;
    left: -0.4rem;
    background: #ffc107;
    color: white;
    border-radius: 50%;
    padding: 0.2rem;
    font-size: 0.9rem;
}
body.light #dropZone {
    border: 2px dashed #94a3b8;
}
body.light #dropZone.drag-over {
    border-color: #3b82f6;
    background-color: #eff6ff;
}

body.dark {
    background-color: #0f172a;
    color: #e2e8f0;
}
body.dark .card {
    background-color: #1e293b;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2);
}
body.dark .btn-primary {
    background-color: #60a5fa;
    color: #ffffff;
}
body.dark .btn-primary:hover {
    background-color: #3b82f6;
}
body.dark .btn-secondary {
    background-color: #34d399;
    color: #ffffff;
}
body.dark .btn-secondary:hover {
    background-color: #10b981;
}
body.dark .btn-danger {
    background-color: #f87171;
    color: #ffffff;
}
body.dark .btn-danger:hover {
    background-color: #ef4444;
}
body.dark .btn-neutral {
    background-color: #475569;
    color: #e2e8f0;
}
body.dark .btn-neutral:hover {
    background-color: #64748b;
}
body.dark .btn-outline {
    border: 1px solid #475569;
    background-color: transparent;
    color: #e2e8f0;
}
body.dark .btn-outline:hover {
    background-color: #1e293b;
}
body.dark input, body.dark select {
    border-color: #475569;
    background-color: #1e293b;
    color: #e2e8f0;
}
body.dark input:focus, body.dark select:focus {
    border-color: #60a5fa;
    box-shadow: 0 0 0 3px rgba(96, 165, 250, 0.1);
}
body.dark .category-item {
    background-color: #334155;
}
body.dark .category-item:hover {
    background-color: #475569;
}
body.dark .channel-item {
    border-color: #475569;
}
body.dark .channel-item.favorite {
    background-color: #332701;
    border-color: #cc9a06;
    position: relative;
}
body.dark .channel-item.favorite::before {
    content: '★';
    position: absolute;
    top: -0.4rem;
    left: -0.4rem;
    background: #cc9a06;
    color: white;
    border-radius: 50%;
    padding: 0.2rem;
    font-size: 0.9rem;
}
body.dark #dropZone {
    border: 2px dashed #64748b;
}
body.dark #dropZone.drag-over {
    border-color: #60a5fa;
    background-color: #1e40af;
}

.container {
    width: 100%;
    height: 100vh;
    max-width: 100%;
    margin: 0;
    padding: clamp(1rem, 2vw, 1.25rem);
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

h1 {
    font-size: clamp(1.6rem, 3.5vw, 2rem);
    font-weight: 700;
}
h2 {
    font-size: clamp(1.2rem, 2.5vw, 1.375rem);
    font-weight: 600;
}
h3 {
    font-size: clamp(1rem, 2vw, 1.125rem);
    font-weight: 600;
}
p {
    font-size: clamp(0.875rem, 1.8vw, 0.9375rem);
}

button {
    padding: clamp(0.5rem, 1.5vw, 0.625rem) clamp(0.75rem, 2vw, 1rem);
    border-radius: 0.375rem;
    font-size: clamp(0.8125rem, 1.8vw, 0.875rem);
    cursor: pointer;
    transition: background-color 0.2s ease, transform 0.1s ease;
    display: inline-flex;
    align-items: center;
    gap: 0.375rem;
    border: none;
}
button:hover {
    transform: translateY(-1px);
}

input[type="text"],
input[type="file"],
select {
    width: 100%;
    padding: clamp(0.5rem, 1.5vw, 0.625rem);
    border: 1px solid;
    border-radius: 0.375rem;
    font-size: clamp(0.8125rem, 1.8vw, 0.875rem);
    transition: border-color 0.2s ease, box-shadow 0.2s ease;
}
input[type="file"] {
    display: none;
}

.grid {
    display: flex;
    flex-direction: column;
    gap: clamp(1rem, 2vw, 1.25rem);
    flex: 1;
    overflow: hidden;
}

@media (min-width: 1024px) {
    .grid {
        flex-direction: row;
    }
    .sidebar {
        width: 25%;
        max-width: 300px;
    }
    .main-content {
        flex: 1;
        width: 75%;
    }
}

.card {
    border-radius: 0.5rem;
    padding: clamp(1rem, 2vw, 1.25rem);
    transition: background-color 0.3s ease, box-shadow 0.3s ease;
}

header {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    margin-bottom: clamp(1rem, 2vw, 1.5rem);
}
@media (min-width: 640px) {
    header {
        flex-direction: row;
        justify-content: space-between;
        align-items: center;
    }
}

.header-buttons {
    display: flex;
    gap: clamp(0.5rem, 1.5vw, 0.75rem);
    flex-wrap: wrap;
    align-items: center;
}

.sidebar {
    overflow-y: auto;
    max-height: calc(100vh - 120px);
    scrollbar-width: none;
    scrollbar-color: #94a3b8 #e5e7eb;
}
.sidebar::-webkit-scrollbar {
    width: 8px;
}
.sidebar::-webkit-scrollbar-track {
    background: #e5e7eb;
}
.sidebar::-webkit-scrollbar-thumb {
    background: #94a3b8;
    border-radius: 4px;
}
body.dark .sidebar::-webkit-scrollbar-track {
    background: #334155;
}
body.dark .sidebar::-webkit-scrollbar-thumb {
    background: #64748b;
}
.sidebar ul {
    display: flex;
    flex-direction: column;
    gap: 0.375rem;
    list-style: none;
}
.sidebar li {
    padding: clamp(0.5rem, 1.5vw, 0.625rem);
    border-radius: 0.375rem;
    transition: background-color 0.2s ease;
    list-style: none;
}
.sidebar li:hover {
    background-color: #e2e8f0;
}
body.dark .sidebar li:hover {
    background-color: #475569;
}

.main-content {
    overflow: hidden;
    flex: 1;
}

#channelListContainer {
    overflow-y: auto;
    max-height: calc(86vh - 250px);
    scrollbar-width: thin;
    scrollbar-color: #94a3b8 #e5e7eb;
	padding: 10px;
}
#channelListContainer::-webkit-scrollbar {
    width: 8px;
}
#channelListContainer::-webkit-scrollbar-track {
    background: #e5e7eb;
}
#channelListContainer::-webkit-scrollbar-thumb {
    background: #94a3b8;
    border-radius: 4px;
}
body.dark #channelListContainer::-webkit-scrollbar-track {
    background: #334155;
}
body.dark #channelListContainer::-webkit-scrollbar-thumb {
    background: #64748b;
}

#categoryCard[data-collapsed="true"] #categoryList {
    display: none;
}
#categoryCard[data-collapsed="true"] #toggleCategoryBtn span[data-feather="chevron-down"] {
    transform: rotate(180deg);
}
#toggleCategoryBtn {
    padding: 0.25rem;
    border-radius: 0.25rem;
}

.chart-container {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 1rem;
    margin-top: 1rem;
}
.chart-legend {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    font-size: clamp(0.75rem, 1.5vw, 0.875rem);
}
.legend-item {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}
.legend-color {
    width: 1rem;
    height: 1rem;
    border-radius: 0.25rem;
}
.category-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-radius: 0.375rem;
    padding: clamp(0.5rem, 1.5vw, 0.625rem);
    transition: background-color 0.2s ease;
}
.channel-item {
    display: flex;
    align-items: center;
    border: 1px solid;
    border-radius: 0.375rem;
    padding: clamp(0.75rem, 2vw, 1rem);
    transition: all 0.2s ease;
}
.channel-item:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
}
.channel-logo {
    width: clamp(32px, 4vw, 36px);
    height: clamp(32px, 4vw, 36px);
    object-fit: contain;
    background-color: #f1f5f9;
    border-radius: 0.25rem;
}
.empty-logo {
    width: clamp(32px, 4vw, 36px);
    height: clamp(32px, 4vw, 36px);
    background-color: #e5e7eb;
    border-radius: 0.25rem;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #94a3b8;
}
#dropZone {
    border-radius: 0.5rem;
    transition: all 0.3s ease;
    height: 53vh;
    place-content: center;
}

.modal {
    position: fixed;
    inset: 0;
    background-color: rgba(0, 0, 0, 0.5);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 50;
}
.modal-content {
    border-radius: 0.5rem;
    padding: clamp(1.25rem, 2vw, 1.5rem);
    width: 100%;
    max-width: clamp(300px, 90vw, 460px);
    transition: background-color 0.3s ease;
}
.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: clamp(0.75rem, 2vw, 1rem);
}
.channel-logo-preview {
    width: clamp(48px, 7vw, 56px);
    height: clamp(48px, 7vw, 56px);
    object-fit: contain;
    background-color: #f1f5f9;
    border-radius: 0.375rem;
}
.dragging {
    opacity: 0.5;
    border: 2px dashed #3b82f6;
}

#themeToggle {
    background: none;
    padding: 0.5rem;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
}
#themeToggle:hover {
    background-color: #e5e7eb;
}
body.dark #themeToggle:hover {
    background-color: #475569;
}
.player-modal {
    position: fixed;
    inset: 0;
    background-color: rgba(0, 0, 0, 0.7);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 100;
}
.player-content {
    background-color: #000;
    border-radius: 0.5rem;
    padding: 0.5rem;
    width: 100%;
    max-width: clamp(400px, 90vw, 1200px);
    position: relative;
    display: flex;
    justify-content: center;
    align-items: center;
}
.player-content video {
    width: 100%;
    height: auto;
    max-height: 80vh;
    object-fit: contain;
    border-radius: 0.25rem;
}
.close-player {
    position: absolute;
    top: 10px;
    right: 10px;
    color: #fff;
    background: rgba(0, 0, 0, 0.7);
    border: none;
    border-radius: 50%;
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: background-color 0.2s ease, transform 0.2s ease;
}
.close-player:hover {
    background: rgba(0, 0, 0, 0.9);
    transform: scale(1.1);
}
.close-player span {
    stroke: white;
}
.status-progress {
    margin-bottom: 1rem;
}
.progress-bar {
    width: 0%;
    height: 0.5rem;
    background-color: #3b82f6;
    border-radius: 9999px;
    transition: width 0.3s ease;
}

/* --- RESPONSIVE --- */

/* 1024px and below (small laptop/tablet) */
@media (max-width: 1024px) {
    .container {
        padding: 0.5rem;
    }
    .sidebar {
        max-width: none;
        width: 100%;
    }
    .main-content {
        width: 100%;
    }
    .card {
        padding: 0.75rem;
    }
}

/* 900px and below, landscape orientation */
@media (max-width: 900px) and (orientation: landscape) {
    html, body, .container {
        height: auto;
        min-height: 100vh;
        overflow-x: hidden;
        padding-bottom: 62px;
    }
    .container {
        padding: 0.2rem;
        min-height: 100vh;
    }
    .grid {
        flex-direction: row;
        gap: 0.5rem;
        min-height: 0;
    }
    .sidebar {
        width: 40vw;
        min-width: 150px;
        max-width: 250px;
        order: 1;
        max-height: 88vh;
        min-height: 150px;
        overflow-y: auto;
    }
    .main-content {
        width: 60vw;
        min-width: 200px;
        max-width: 100vw;
        order: 2;
        min-height: 200px;
    }
    .card {
        padding: 0.55rem;
    }
    #channelListContainer {
        max-height: 65vh;
    }
    .footer-credit {
        font-size: 0.85em;
        padding: 0.25rem 0 0.08rem 0;
        background: rgba(255,255,255,0.85);
        width: 100vw;
    }
    body.dark .footer-credit {
        background: rgba(30,41,59,0.9);
    }
    .modal-content {
        margin: 0.2rem;
        max-width: 95vw;
    }
    .player-content {
        max-width: 95vw;
        padding: 0.2rem;
    }
    .player-content video {
        max-height: 60vh;
    }
    .channel-item {
        flex-direction: row;
        align-items: center;
        gap: 0.5rem;
        padding: 0.55rem 0.4rem;
    }
    .header-buttons {
        flex-direction: row;
        gap: 0.35rem;
    }
    .header-buttons button {
        width: auto;
    }
}

/* On very narrow screens, even in landscape, fallback to column layout */
@media (max-width: 600px) and (orientation: landscape) {
    .grid {
        flex-direction: column;
    }
    .sidebar,
    .main-content {
        width: 100%;
        min-width: unset;
        max-width: unset;
    }
    #channelListContainer {
        max-height: 40vh;
    }
}

/* Tablet and mobile (portrait and landscape) */
@media (max-width: 768px) {
    .container {
        padding: 0.25rem;
    }
    .grid {
        gap: 0.75rem;
    }
    .card {
        padding: 0.65rem;
    }
    header {
        margin-bottom: 0.75rem;
    }
    #dropZone {
        height: 36vh;
    }
    .sidebar {
        max-height: 100vh;
    }
    .footer-credit {
        font-size: 0.89em;
        padding: 0.65rem 0 0.3rem 0;
    }
}

/* Phone & small tablet portrait (and all portrait up to 900px) */
@media (max-width: 640px), (orientation: portrait) and (max-width: 900px) {
    html, body, .container {
        height: auto;
        min-height: 100vh;
        overflow-x: hidden;
    }
    .container {
        padding: 0.15rem;
    }
    .grid {
        flex-direction: column;
        gap: 0.5rem;
        min-height: 0;
    }
    .sidebar {
        width: 100%;
        max-width: none;
        order: 2;
        max-height: 40vh;
        min-height: 220px;
        overflow-y: auto;
    }
    .main-content {
        width: 100%;
        order: 1;
        min-height: 320px;
    }
    .card {
        padding: 0.55rem;
    }
    #channelListContainer {
        max-height: 50vh;
    }
    .footer-credit {
        font-size: 0.85em;
        padding: 0.4rem 0 0.15rem 0;
    }
    .modal-content {
        margin: 0.2rem;
        max-width: 98vw;
    }
    .player-content {
        max-width: 98vw;
        padding: 0.2rem;
    }
    .player-content video {
        max-height: 55vh;
    }
    .channel-item {
        flex-direction: column;
        align-items: flex-start;
        gap: 0.5rem;
        padding: 0.5rem 0.4rem;
    }
    .header-buttons {
        flex-direction: column;
        gap: 0.35rem;
    }
    .header-buttons button {
        width: 100%;
    }
}

/* Smallest devices */
@media (max-width: 400px), (orientation: portrait) and (max-width: 400px) {
    h1 {
        font-size: 1.1rem;
    }
    h2 {
        font-size: 1rem;
    }
    .footer-credit {
        font-size: 0.78em;
        padding: 0.15rem 0 0.1rem 0;
    }
    .card, .modal-content {
        padding: 0.3rem;
    }
    .player-content {
        padding: 0.05rem;
    }
}

/* Mobile: footer always visible, doesn't overlap */
@media (max-width: 600px) {
    html, body {
        padding-bottom: 62px;
    }
    .footer-credit {
        position: fixed;
        left: 0;
        bottom: 0;
        width: 100vw;
        z-index: 100;
        background: rgba(255,255,255,0.85);
        backdrop-filter: blur(2px);
    }
    body.dark .footer-credit {
        background: rgba(30,41,59,0.9);
    }
}

/* --- UTILITIES, HELPERS --- */
.hidden {
    display: none;
}
.space-y-2 > * + * {
    margin-top: 0.5rem;
}
.space-y-3 > * + * {
    margin-top: 0.75rem;
}
.space-y-4 > * + * {
    margin-top: 1rem;
}
.space-x-2 > * + * {
    margin-left: 0.5rem;
}
.space-x-3 > * + * {
    margin-left: 0.75rem;
}
.space-x-4 > * + * {
    margin-left: 1rem;
}
.flex-1 {
    flex: 1 1 0%;
}
.truncate {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.text-center {
    text-align: center;
}
.inline-block {
    display: inline-block;
}
.min-w-0 {
    min-width: 0;
}
.cursor-pointer {
    cursor: pointer;
}
.status-online {
    color: #10b981;
    font-size: 0.75rem;
}
.status-offline {
    color: #ef4444;
    font-size: 0.75rem;
}
.notification-enter {
    opacity: 0;
    transform: translateY(20px);
}
.notification-enter-active {
    opacity: 1;
    transform: translateY(0);
    transition: opacity 300ms, transform 300ms;
}
.notification-exit {
    opacity: 1;
}
.notification-exit-active {
    opacity: 0;
    transform: translateY(20px);
    transition: opacity 300ms, transform 300ms;
}

/* Footer */
.footer-credit {
    width: 100%;
    text-align: center;
    padding: 1rem 0 0.5rem 0;
    font-size: 0.95em;
    color: #64748b;
    background: transparent;
    letter-spacing: 0.02em;
    position: fixed;
    left: 0;
    bottom: 0;
    z-index: 20;
    pointer-events: none;
    transition: background 0.3s, color 0.3s;
}
.footer-credit div {
    pointer-events: all;
    padding: 10px 0px 0px;
    /* background-color: #ffffff;  remove for dark mode support */
}
.footer-link {
    color: #3b82f6;
    text-decoration: none;
    transition: color 0.2s;
    pointer-events: all;
}
.footer-link:hover {
    color: #2563eb;
    text-decoration: underline;
}
body.dark .footer-credit {
    color: #aeb8c7;
    background: transparent;
}
body.dark .footer-link {
    color: #60a5fa;
}
body.dark .footer-link:hover {
    color: #3b82f6;
}
