:root {
    --bg-color: #0f1115;
    --grid-gap: 24px;
    --container-bg: rgba(255, 255, 255, 0.02);
    --border-color: rgba(255, 255, 255, 0.06);
    --glow-color: rgba(139, 92, 246, 0.15);
    /* Sleek purple glow */
    --hover-border: rgba(139, 92, 246, 0.5);
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    background-color: var(--bg-color);
    font-family: 'Outfit', sans-serif;
    color: #fff;
    height: 100vh;
    width: 100vw;
    display: flex;
    justify-content: center;
    align-items: center;
    padding: var(--grid-gap);
    background: radial-gradient(circle at 50% 50%, #1a1b26 0%, #0f1115 100%);
    overflow: hidden;
}

.auth-gate {
    position: fixed;
    inset: 0;
    background: rgba(8, 9, 13, 0.82);
    backdrop-filter: blur(10px);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 3000;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.22s ease;
    padding: 20px;
}

.auth-gate.active {
    opacity: 1;
    pointer-events: auto;
}

.auth-card {
    width: min(440px, 100%);
    background: rgba(15, 17, 21, 0.95);
    border: 1px solid var(--border-color);
    border-radius: 16px;
    box-shadow: 0 24px 60px rgba(0, 0, 0, 0.45);
    padding: 24px;
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.auth-card h1 {
    font-size: 1.4rem;
    font-weight: 600;
}

.auth-card p {
    color: rgba(255, 255, 255, 0.65);
    font-size: 0.95rem;
}

.auth-input {
    margin-top: 4px;
}

.auth-error {
    min-height: 1.1rem;
}

/* Dynamic Grid Layouts */
.video-grid {
    display: grid;
    gap: var(--grid-gap);
    width: 100%;
    height: 100%;
    grid-auto-flow: row;
}

.video-grid.layout-1 {
    grid-template-columns: 1fr;
    grid-template-rows: 1fr;
}

.video-grid.layout-2 {
    grid-template-columns: 1fr 1fr;
    grid-template-rows: 1fr;
}

.video-grid.layout-3 {
    grid-template-columns: 1fr 1fr;
    grid-template-rows: 1fr 1fr;
}

.video-grid.layout-3 .video-container:first-child {
    grid-column: 1 / -1;
    /* First video takes full width on top row */
}

.video-grid.layout-4 {
    grid-template-columns: 1fr 1fr;
    grid-template-rows: 1fr 1fr;
}

.video-grid.layout-5,
.video-grid.layout-6 {
    grid-template-columns: repeat(3, minmax(0, 1fr));
    grid-template-rows: repeat(2, minmax(0, 1fr));
}

.video-grid.layout-7,
.video-grid.layout-8,
.video-grid.layout-9 {
    grid-template-columns: repeat(3, minmax(0, 1fr));
    grid-template-rows: repeat(3, minmax(0, 1fr));
}

/* UI Controls Overlay */
.controls-overlay {
    position: absolute;
    top: 24px;
    right: 24px;
    z-index: 100;
    display: flex;
    flex-direction: column;
    gap: 10px;
    align-items: flex-end;
}

.page-status {
    position: absolute;
    top: 84px;
    right: 24px;
    max-width: 360px;
    background: rgba(7, 9, 12, 0.86);
    border: 1px solid var(--border-color);
    color: #86efac;
    font-size: 0.84rem;
    border-radius: 10px;
    padding: 8px 12px;
    opacity: 0;
    transform: translateY(-8px);
    transition: opacity 0.2s ease, transform 0.2s ease;
    pointer-events: none;
    z-index: 99;
}

.page-status.active {
    opacity: 1;
    transform: translateY(0);
}

.page-status.error {
    color: #fca5a5;
}

.icon-btn {
    background: rgba(255, 255, 255, 0.1);
    border: 1px solid rgba(255, 255, 255, 0.2);
    color: white;
    width: 48px;
    height: 48px;
    border-radius: 50%;
    display: flex;
    justify-content: center;
    align-items: center;
    cursor: pointer;
    backdrop-filter: blur(8px);
    transition: all 0.3s ease;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
}

.icon-btn:hover {
    background: rgba(255, 255, 255, 0.2);
    transform: scale(1.1);
    border-color: rgba(255, 255, 255, 0.4);
}

.icon-btn:disabled,
.icon-btn:disabled:hover {
    opacity: 0.5;
    cursor: not-allowed;
    transform: none;
    background: rgba(255, 255, 255, 0.08);
    border-color: rgba(255, 255, 255, 0.16);
}

/* Dropdown Menu */
.dropdown-menu {
    position: absolute;
    top: 60px;
    right: 0;
    background: var(--bg-color);
    border: 1px solid var(--border-color);
    border-radius: 16px;
    width: 260px;
    padding: 8px;
    box-shadow: 0 16px 40px rgba(0, 0, 0, 0.5);
    opacity: 0;
    pointer-events: none;
    transform: translateY(-10px);
    transition: all 0.2s cubic-bezier(0.2, 0.8, 0.2, 1);
    backdrop-filter: blur(12px);
    z-index: 200;
}

.dropdown-menu.active {
    opacity: 1;
    pointer-events: auto;
    transform: translateY(0);
}

.dropdown-item {
    background: transparent;
    border: none;
    color: white;
    width: 100%;
    padding: 12px 16px;
    border-radius: 8px;
    font-family: inherit;
    font-size: 0.95rem;
    display: flex;
    align-items: center;
    gap: 12px;
    cursor: pointer;
    transition: all 0.2s ease;
    text-align: left;
}

.dropdown-item:hover {
    background: rgba(139, 92, 246, 0.2);
    color: #c4b5fd;
}

.playlist-select-btn.active {
    background: rgba(139, 92, 246, 0.26);
    color: #ddd6fe;
}

.dropdown-quick-save {
    margin-top: 6px;
    padding-top: 8px;
    border-top: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.quick-save-input {
    font-size: 0.85rem;
    padding: 10px 12px;
}

.quick-save-btn {
    justify-content: flex-start;
}

.dropdown-menu .divider {
    margin: 8px 0;
}

/* Modal Overlay Data */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.6);
    backdrop-filter: blur(8px);
    z-index: 1000;
    display: flex;
    justify-content: center;
    align-items: center;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s ease;
}

.modal-overlay.active {
    opacity: 1;
    pointer-events: auto;
}

.modal {
    background: var(--bg-color);
    border: 1px solid var(--border-color);
    border-radius: 20px;
    width: 90%;
    max-width: 560px;
    max-height: 80vh;
    display: flex;
    flex-direction: column;
    box-shadow: 0 24px 64px rgba(0, 0, 0, 0.5);
    transform: translateY(20px) scale(0.95);
    transition: all 0.3s cubic-bezier(0.2, 0.8, 0.2, 1);
}

.modal-overlay.active .modal {
    transform: translateY(0) scale(1);
}

.modal-header,
.modal-footer {
    padding: 20px 24px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 1px solid var(--border-color);
}

.modal-header h2 {
    font-size: 1.5rem;
    font-weight: 600;
}

.modal-header .icon-btn {
    width: 36px;
    height: 36px;
}

.modal-footer {
    border-top: 1px solid var(--border-color);
    border-bottom: none;
    justify-content: flex-end;
}

.modal-body {
    padding: 24px;
    overflow-y: auto;
    flex-grow: 1;
}

.modal-body h3 {
    font-size: 1.1rem;
    margin-bottom: 12px;
    color: #a0a0b0;
    font-weight: 600;
}

.modal-section {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.subtitle {
    color: rgba(255, 255, 255, 0.62);
    font-size: 0.9rem;
}

.field-stack {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.manager-list {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.manager-empty {
    color: rgba(255, 255, 255, 0.55);
    font-size: 0.88rem;
    padding: 8px 4px;
}

.manager-row {
    display: flex;
    flex-direction: column;
    gap: 6px;
    padding: 10px;
    border-radius: 10px;
    background: rgba(255, 255, 255, 0.02);
    border: 1px solid var(--border-color);
}

.manager-row-main {
    display: flex;
    align-items: center;
    gap: 10px;
}

.manager-title-input {
    padding: 10px 12px;
    font-size: 0.86rem;
}

.manager-save-btn {
    padding: 10px 14px;
    font-size: 0.82rem;
    white-space: nowrap;
}

.manager-meta {
    color: rgba(255, 255, 255, 0.56);
    font-size: 0.76rem;
    padding-left: 2px;
}

.divider {
    height: 1px;
    background: var(--border-color);
    margin: 24px 0;
}

/* Playlist Buttons */
.playlist-list {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.playlist-btn {
    background: var(--container-bg);
    border: 1px solid var(--border-color);
    color: white;
    padding: 14px 20px;
    border-radius: 12px;
    font-family: inherit;
    font-size: 1rem;
    display: flex;
    align-items: center;
    gap: 12px;
    cursor: pointer;
    transition: all 0.2s ease;
    text-align: left;
}

.playlist-btn:hover {
    background: rgba(139, 92, 246, 0.2);
    border-color: var(--hover-border);
    transform: translateX(4px);
}

.video-container {
    background: var(--container-bg);
    border: 1px solid var(--border-color);
    border-radius: 24px;
    overflow: hidden;
    position: relative;
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    transition: all 0.5s cubic-bezier(0.2, 0.8, 0.2, 1);
    display: flex;
    padding: 8px;
    /* Inner padding to show the premium glass border */
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.3);
}

.video-header {
    position: absolute;
    top: 16px;
    left: 16px;
    right: 16px;
    z-index: 24;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    pointer-events: none;
}

.video-title {
    background: rgba(7, 9, 12, 0.76);
    border: 1px solid rgba(255, 255, 255, 0.12);
    padding: 5px 10px;
    border-radius: 999px;
    font-size: 0.8rem;
    color: rgba(255, 255, 255, 0.92);
    max-width: calc(100% - 116px);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.video-actions {
    display: flex;
    gap: 6px;
    pointer-events: auto;
}

.video-action-btn {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    border: 1px solid rgba(255, 255, 255, 0.18);
    background: rgba(8, 10, 14, 0.72);
    color: rgba(255, 255, 255, 0.92);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.2s ease;
}

.video-action-btn .material-symbols-outlined {
    font-size: 20px;
}

.video-action-btn:hover:enabled {
    border-color: rgba(139, 92, 246, 0.6);
    background: rgba(139, 92, 246, 0.26);
}

.video-action-btn:disabled {
    opacity: 0.45;
    cursor: not-allowed;
}

.video-inline-editor {
    position: absolute;
    top: 58px;
    left: 16px;
    right: 16px;
    z-index: 26;
    display: flex;
    flex-direction: column;
    gap: 8px;
    padding: 12px;
    border-radius: 12px;
    border: 1px solid rgba(255, 255, 255, 0.18);
    background: rgba(9, 11, 15, 0.92);
    box-shadow: 0 12px 24px rgba(0, 0, 0, 0.35);
    opacity: 0;
    transform: translateY(-8px);
    pointer-events: none;
    transition: all 0.2s ease;
}

.video-inline-editor.active {
    opacity: 1;
    transform: translateY(0);
    pointer-events: auto;
}

.inline-video-select,
.inline-video-input {
    width: 100%;
    background: rgba(0, 0, 0, 0.38);
    border: 1px solid rgba(255, 255, 255, 0.2);
    color: white;
    border-radius: 8px;
    padding: 9px 10px;
    font-family: inherit;
    font-size: 0.82rem;
    outline: none;
}

.inline-video-select:focus,
.inline-video-input:focus {
    border-color: rgba(139, 92, 246, 0.9);
}

.inline-editor-actions {
    display: flex;
    gap: 8px;
}

.inline-editor-actions .btn {
    padding: 9px 10px;
    font-size: 0.82rem;
}

.inline-editor-actions .btn.secondary,
.inline-editor-actions .btn.ghost {
    flex: 1;
    width: auto;
}

/* Custom URL Inputs */
.custom-inputs-list {
    display: flex;
    flex-direction: column;
    gap: 16px;
    margin-top: 16px;
}

.custom-url-input {
    background: rgba(0, 0, 0, 0.4);
    border: 1px solid var(--border-color);
    color: white;
    padding: 14px 16px;
    border-radius: 8px;
    font-family: inherit;
    font-size: 0.95rem;
    width: 100%;
    outline: none;
    transition: all 0.2s ease;
}

.custom-url-input:focus {
    border-color: #8b5cf6;
    background: rgba(0, 0, 0, 0.6);
    box-shadow: 0 0 0 2px rgba(139, 92, 246, 0.3);
}

.custom-url-input::placeholder {
    color: rgba(255, 255, 255, 0.3);
}

/* Buttons */
.btn {
    border: none;
    padding: 12px 24px;
    border-radius: 8px;
    font-family: inherit;
    font-size: 0.95rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
}

.btn.primary {
    background: #8b5cf6;
    color: white;
}

.btn.primary:hover {
    background: #7c3aed;
    box-shadow: 0 4px 12px var(--glow-color);
    transform: translateY(-2px);
}

.btn.secondary {
    background: rgba(255, 255, 255, 0.08);
    border: 1px solid var(--border-color);
    color: white;
}

.btn.secondary:hover {
    background: rgba(255, 255, 255, 0.14);
    border-color: rgba(255, 255, 255, 0.28);
}

.btn.ghost {
    background: transparent;
    border: 1px solid var(--border-color);
    color: rgba(255, 255, 255, 0.88);
}

.btn.ghost:hover {
    background: rgba(255, 255, 255, 0.08);
}

.modal-footer {
    gap: 12px;
}

.slot-selectors {
    display: flex;
    flex-direction: column;
    gap: 12px;
    margin-top: 4px;
}

.slot-row {
    display: flex;
    align-items: center;
    gap: 12px;
    font-size: 0.93rem;
    color: rgba(255, 255, 255, 0.88);
}

.slot-row span {
    width: 88px;
    flex-shrink: 0;
}

.slot-select {
    width: 100%;
    background: rgba(0, 0, 0, 0.35);
    border: 1px solid var(--border-color);
    color: white;
    padding: 11px 12px;
    border-radius: 8px;
    font-family: inherit;
    font-size: 0.92rem;
    outline: none;
    transition: all 0.2s ease;
}

.slot-select:focus {
    border-color: #8b5cf6;
    box-shadow: 0 0 0 2px rgba(139, 92, 246, 0.3);
}

.status-text {
    min-height: 1.1rem;
    margin-top: 4px;
    color: #86efac;
    font-size: 0.9rem;
}

.status-text.error {
    color: #fca5a5;
}

.dropdown-empty {
    padding: 12px 16px;
    color: rgba(255, 255, 255, 0.55);
    font-size: 0.9rem;
}

.video-container::before {
    content: '';
    position: absolute;
    inset: 0;
    border-radius: inherit;
    background: linear-gradient(135deg, rgba(255, 255, 255, 0.05) 0%, rgba(255, 255, 255, 0) 100%);
    pointer-events: none;
    z-index: 10;
}

.video-container:hover {
    transform: scale(1.015) translateY(-4px);
    box-shadow: 0 20px 40px var(--glow-color), 0 0 20px rgba(0, 0, 0, 0.5);
    border-color: var(--hover-border);
    z-index: 2;
}

.video-wrapper {
    position: relative;
    width: 100%;
    height: 100%;
    z-index: 1;
    border-radius: 16px;
    overflow: hidden;
    background: #000;
    box-shadow: inset 0 0 10px rgba(0, 0, 0, 0.5);
    /* Deepens the inner container */
}

iframe {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    border: none;
    border-radius: 16px;
    /* Matches inner wrapper */
    transition: opacity 0.3s ease;
}

/* Entry animations for dynamic feel */
@keyframes fade-in {
    from {
        opacity: 0;
        transform: translateY(30px) scale(0.95);
    }

    to {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

.video-container {
    animation: fade-in 0.8s cubic-bezier(0.2, 0.8, 0.2, 1) backwards;
}

.video-container:nth-child(1) {
    animation-delay: 0.1s;
}

.video-container:nth-child(2) {
    animation-delay: 0.2s;
}

.video-container:nth-child(3) {
    animation-delay: 0.3s;
}

.video-container:nth-child(4) {
    animation-delay: 0.4s;
}

/* Responsive adjustments for smaller screens */
@media (max-width: 768px) {
    body {
        height: auto;
        min-height: 100vh;
        overflow-y: auto;
        padding: 16px;
    }

    .video-grid {
        grid-template-columns: 1fr;
        grid-template-rows: none;
        grid-auto-rows: 40vh;
        gap: 16px;
    }

    .page-status {
        left: 16px;
        right: 16px;
        max-width: none;
    }

    .slot-row {
        flex-direction: column;
        align-items: stretch;
        gap: 8px;
    }

    .slot-row span {
        width: auto;
    }

    .manager-row-main {
        flex-direction: column;
        align-items: stretch;
    }

    .manager-save-btn {
        width: 100%;
    }

    .btn {
        width: 100%;
    }

    .video-header {
        top: 12px;
        left: 12px;
        right: 12px;
    }

    .video-inline-editor {
        top: 50px;
        left: 12px;
        right: 12px;
    }

    .inline-editor-actions {
        flex-direction: column;
    }
}
